Controller Stuff This file includes our current entity and a description of the states to show the game flow ----------------------------------------------------- Here is our controller entity, you may notice that it contains "skBust" and "balanceRdy" flags. These are control flags that the scoreKeeper and banker will need to set for us. skBust will be set whenever a player that is currently playing exceeds 21. This way we can instantly move on to the next player. balanceRdy is a flag we think is needed so that the player and the controller know that the balance is ready to be read during win/loss settling. Then the controller can move on to the next player instead of guessing at how many clock cycles are needed for the banker and player to adjust. ENTITY controller IS GENERIC ( nPlayers : INTEGER := 32); -- Number of Players PORT ( -- Input clock : IN STD_LOGIC; enable : IN STD_LOGIC; reset : IN STD_LOGIC; bistEnable : IN STD_LOGIC; -- Input from Player pHit : IN STD_LOGIC; pStand : IN STD_LOGIC; -- Input from Card Generator issued : IN STD_LOGIC; -- Input from Banker gameOver : IN STD_LOGIC; balanceRdy : IN STD_LOGIC; -- Input from Score Keeper skBust : IN STD_LOGIC; -- Output playerID : OUT STD_LOGIC_VECTOR(32 DOWNTO 0); globalReset : OUT STD_LOGIC; -- Output to Card Generator cgIssue : OUT STD_LOGIC; cgNewHand : OUT STD_LOGIC; cgBist : OUT STD_LOGIC); END controller; ------------------------------------------------------ State Descriptions: This is an attempt at a big picture flow of the control of a blackjack match. Controller duties written under each state in pseudocode 'Module Responsibilities' explains what others will probably need to be doing during that time Init (state == 0000) { -- occurs after a hand or global reset set cgNewHand = 1 set playerID = 1 set state = 0001 } Module Responsibilities: CardGenerator: check cgNewHand flag to reset deck BetMode (state == 0001) { set cgNewHand = 0 -- cycle through players by shifting playerID register for each player wait for stand flag from player (signifies bet ready) -- have an internal timeout to skip if player takes too long end set state = 0010 set numCards = 0 } Module Responsibilities: Player: set bet amount set stand flag (to signify bet made) Banker: accept bets from enabled player DealMode (state == 0010) { -- deal 2 cards each for numCards = 1 to 2 -- cycle through players by shifting playerID register for each player -- Note: Dealer is not dealt cards here -- ScoreKeeper may need specialized code as well for this set cgIssue = 1 to trigger a card wait for issued flag from CardGenerator end end set state = 0011; } Module Responsibilities: CardGenerator: send card on cgIssue flag set issued flag when card ready Player: read card when issued flag is asserted and enabled ScoreKeeper: read card when issued flag is asserted set to enabled player based on playerID CardCounter: read card when issued flag is asserted GameInteraction (state == 0011) { -- cycle through players by shifting playerID register for each player if(skBust or pStand or timeout) -- skip player, their turn is done else if(pHit) set issue = 1 wait for issued set issue = 0 else wait for timeout end end end set state = 0100 } Module Responsibilities: CardGenerator: send card on cgIssue flag set issued flag when card ready Player: hit for more cards if desired stand if desired read cards issued flag is asserted (after hit) ScoreKeeper: read card when issued flag is asserted set to enabled player based on playerID send bust flag for enabled player if bust occurs CardCounter read all cards when issued flags are seen Results (state == 0100) { -- cycle through players by shifting playerID register for each player wait for balanceRdy flag from Banker for enabled player end set state = 0101 } Module Responsibilities: ScoreKeeper: calculate result of game (win,loss,bj,push) send action status to Banker for the enabled player Banker: read action status for enabled player and calculate new player balance. Assert balanceRdy flag Player: read balance when enabled and balanceRdy flag asserted CheckGameOver (state == 0101) { check gameover flag from Banker if(gameOver) display results from Banker else -- play next hand set state == 0000 end Module Responsibilities: Banker: send gameOver flag to controller if gameover criteria met }