Software Design

By Anthony Marino and Desmond Lee

High Level Design
Hardware Design
Software Design
Code Listings

State Machines

A total of three state machines are employed to implement the entire Blackjack game.  More specifically, one is used to detect button pushes, while the other two control the menu and game states.  The AT90S8515's Timer0 overflow interrupt partially controls the timing of all state transitions.  Due to the long execution time of parts of the code, Timer0 is intentionally turned off when high-latency subroutine calls are executed.  This does not have any negative effect on the perceived timing because the game is not timing dependent.

Card Dealing Mechanism

This part of the code comprises of a random number generator, an array of card counters, and a master card counter.  The AT90S8515's Timer1 interrupt on compare match is devoted entirely for generating random numbers.  On each interrupt service routine, an integer counter is incremented to provide a pseudo-random number.  Timer1 was chosen over Timer0 because Timer0 can sometimes be disabled by the state machines.  The game implements four decks of cards by using the array of thirteen counters.  Each counter represents the number of cards of the same value that has not been dealt yet, and is initialized with the value 16.  The master counter holds the sum of all counter values.  When the deal() procedure is called, a random number between zero and the current total card count minus one is generated.  The array is then traversed, subtracting each counter value from the random number until a counter contains a higher number than what is left of the random number.  A card corresponding to that counter will be dealt, at the same time subtracting one from the counter and the total card count.

LCD Updates

To avoid redundant LCD function calls, only the needed portions of the LCD screen are refreshed when needed.  Comparing to full screen refreshes, this scheme is advantageous to our design because each part of the screen can be displaying different contents at different stages of the game.


Home | High Level Design | Hardware Design | Software Design | Results | Pictures | Schematics | Code Listings | Future

Last updated: 04/29/02.