Dice Game Project
For a class project we are going to build a dice game which will make use of the dice generator done in Lab #3.  The dice game is based upon the ’craps’ casino game (this project in no way condones gambling of any sort -- it just makes for an interesting digital machine).   The implementation should be mapped to an ACTEL FPGA.
Rules of the Game:
1.  Initially, the player will enter a bet of between 1 and 19 (this will be entered as a five-bit BCD value).  The player will also enter his bet choice (he can bet either ’right’ or ’wrong’ -- a ’right’ bet assumes that the player will either initially roll a ’natural’ or make his point; a ’wrong’ bet assumes that the player will either roll a ’miss-out’ or not make his point).  For the remainder of these instructions we will assume the bet choice is ’right’.
2.  The player will then roll to determine his ’point’ (this first roll is called the ’come-out’ roll).  If the player rolls a 2, 3, or 12 then he has rolled a ’miss-out’. Assuming the bet type is ’right’ the player immediately loses; the current bet is subtracted from the score, and the player  restarts by entering the bet again.  If the player rolls a 7 or 11 then he has rolled a ’natural’.  Assuming the bet type is ’right’ the player immediately wins; the current bet is added to the score, and the player restarts by entering the bet again.  If the player does not roll a ’miss-out’ or a ’natural’ then the number is his ’point’ and he proceeds to step 3.
3. At this time the player will make successive rolls until he either rolls his point (makes the point) or rolls a 7.  Assuming the bet type is ’right’, then making the point is a winning decision and the current bet is added to the score.  Assuming the bet type is ’right’, then rolling a 7 is a losing decision and the current bet is subtracted from the score.  After the player either wins or loses he goes back to step 1. 
If the current total ever exceeds 99 then the player has ’broken the bank’ and a special light should be illuminated indicating that game play is over.  .  If the current total becomes less than 0 then the player ’has gone bankrupt’ and a special light should be illuminated. The only way out of either of these two conditions should be a hard reset
After a hard reset the player should be able to use the ’bet’ lines to enter an initial ’stake’ of between 0 and 19.  This will become the current score.  The player will then proceed with Step #1.  This way, if the player looses his first bet then he will not immediately become bankrupt (assuming that the first bet is less than the total stake). 
Input/Outputs
Inputs:

	clk 		system clock
	reset		reset line 
	bet_type		high is a ’right’ bet, low is a ’wrong’ bet
	pready		push button input indicating the player is ready for either
			entering his stake, bet, or ready to roll the dice
	bet_in[4:0]		5-bit BCD value to specify bet value of 0 to 19.

Outputs:

	bet_light		indicates that the user should enter his bet.
	comeout_light	indicates that the player should make his first roll
	loss_bet		indicates that the player lost the current bet
	win_bet		indicates that the player won the current bet
	loss_game		indicates that the player is bankrupt
	win_game		indicates that the player has broken the bank
	point_light		indicates that the player is rolling for his point
	score[7:0]		8-bit BCD value for current score (0 to 99).
	dice_a[2:0]	dice A value
	dice_b[2:0]	dice B value
	bet_out[4:0]	5-bit BCD value which shows the current bet
	point[4:0]		5-bit BCD value which shows the current point
Datapath
The datapath of the dice game has the following components:
Registers:  You will need an 8-bit register to hold the current score, a 5-bit register to hold the current bet, and a 5-bit register to hold the current point.  All registers should have asynchronous clears; there is probably no need for a synchronous clear.  Your dice generator block done in Lab #3 will already have registers for the two dice.
Test Block: You will need a block of logic for testing to see if the current dice roll is a ’natural’, seven, ’miss-out’ or matches the current point.  This block can also be used to test to see either the lower 4 bits or upper 4 bits of the current score exceeds 9; if this happens then you have gotten BCD overflow  on  the last addition or subtraction and you need to adjust the score (more on this later). 
ALU: This block will either add the 5-bit bet to the current score or subtract the 5-bit bet value from the current score.  The addition should be done by a ripple-carry adder.  For addition, the initial carry-in should be ’0’ and the 5-bit bet extended by three ’0’s to an 8-bit value before being added to the score. For subtraction, the initial carry-in should be a ’1’, the 5-bit bet value complemented and extended by three ’1’s to an 8-bit value before being added to the score (complementing the bet value and setting the carry-in to a ’1’ gives you the 2’s complement value of the bet).   The ALU must also have a flip-flop which keeps track of the carry value from bit #3 to bit #4 -- this carry is called the ’half-carry’ and is used by the decimal adjust operation discussed in the next paragraph.
After an addition or subtraction you must adjust the score to make it a valid BCD value.  This is called a ’decimal adjust’ operation; some microprocessors have a special decimal adjust instruction.   The rules for the decimal adjust operation is a follows:

•	If you have just done an ’add’ operation and either the lower 4-bits is greater than 9 or the half-carry flag is set then you must add a 06 to the current score to correct the value.
•	If you have just done a ’subtract’ operation and either the lower 4-bits is greater than 9 or the half-carry flag is NOT set then you must subtract 06 from the current score to correct the value.

After you have decimal adjusted the score you still have the possibility that the score is greater than 99 or less than 0.  If the upper 4-bits is greater than 9 and you have just done an addition then the score is greater than ’99’ and the player has broken the bank.  If the upper 4-bits is greater than 9 and you have just done a subtraction when the score is less than 0 and the player is bankrupt. 
Note that the ALU just does a basic binary addition or subtraction; your finite-state-machine for the dice game is responsible for using the ALU to do decimal adjust operation.
Dice Generator: This is the block you did for Lab #3; it does the dice rolling and communicates with the dice game FSM via its ’roll’ input and ’valid’ output.
Control
I have not given you the state diagram for the dice game as I did for the dice generator; it will be up to you to design your own state machine to control the operation of the dice game.  You will probably need anywhere from 15 to 25 states for the control; you MUST use ONE-HOT encoding for the state machine. 
Testing
Because of the psudeo-random nature of the dice, testing the game means that you need someway of specifying that the dice roll be a particular value.  You can do this by external input that forces particular events.

You need to be able to demonstrate the following test cases:

•	A test which shows the ’bankrupt’ case.
•	A test which shows the ’break the bank’ case.

•	A test which shows a ’winning’ bet where the score and bet are such that a  decimal adjust is needed.
•	A test which shows a ’losing’ bet where the score and bet are such that a decimal adjust is needed.
•	Tests which shows the player rolling a natural on the first roll for both bet  types of ’right’ and ’wrong’.
•	Tests which shows the player rolling a natural on the first roll for both bet types of ’right’ and ’wrong’.
•	Tests which shows the player rolling a ’miss-out’ on the first roll for both bet types of ’right’ and ’wrong’.
•	Tests which shows the player rolling his point and then subsequently making his point for both bet types of ’right’ and ’wrong’.
•	Tests which shows the player rolling his point and then subsequently missing his point for both bet types of ’right’ and ’wrong’.

For the tests, use extra internal inputs to force conditions.