Version of Robotron arcade game using LPC1768, a Gameduino shield, a serial EEPROM (for high scores), two microswitch joysticks and two buttons plus a box to put it in. 20 levels of mayhem.

Dependencies:   25LCxxx_SPI CommonTypes Gameduino mbed

Committer:
RichardE
Date:
Mon Jun 17 15:10:43 2013 +0000
Revision:
18:70190f956a24
Parent:
4:673eb9735d44
Improved response to button 1 when entering high scores (HighScoreEntry.cpp).

Who changed what in which revision?

UserRevisionLine numberNew contents of line
RichardE 4:673eb9735d44 1 /*
RichardE 4:673eb9735d44 2 * SOURCE FILE : BCDNumber.cpp
RichardE 4:673eb9735d44 3 *
RichardE 4:673eb9735d44 4 * A 4 byte unsigned BCD integer.
RichardE 4:673eb9735d44 5 *
RichardE 4:673eb9735d44 6 */
RichardE 4:673eb9735d44 7
RichardE 4:673eb9735d44 8 #include "BCDNumber.h"
RichardE 4:673eb9735d44 9
RichardE 4:673eb9735d44 10 /***********************/
RichardE 4:673eb9735d44 11 /* ADD TWO BCD NUMBERS */
RichardE 4:673eb9735d44 12 /***********************/
RichardE 4:673eb9735d44 13 // Pass first number in A.
RichardE 4:673eb9735d44 14 // Pass second number in B.
RichardE 4:673eb9735d44 15 // Pass pointer to result in result.
RichardE 4:673eb9735d44 16 // Pass carry flag in carry.
RichardE 4:673eb9735d44 17 // Remember numbers are BCD coded so 0x99999999 means 9 million,
RichardE 4:673eb9735d44 18 // 9 hundred and 99 thousand, 9 hundred and 99.
RichardE 4:673eb9735d44 19 // Returns carry flag. If this is set then overflow occurred.
RichardE 4:673eb9735d44 20 bool BCDNumber::Add( UInt32 numA, UInt32 numB, UInt32 *result, bool carry ) {
RichardE 4:673eb9735d44 21 const UInt8 *ptrA = (const UInt8*)&numA;
RichardE 4:673eb9735d44 22 const UInt8 *ptrB = (const UInt8*)&numB;
RichardE 4:673eb9735d44 23 UInt8 *ptrR = (UInt8*)result;
RichardE 4:673eb9735d44 24 UInt8 sum, digits;
RichardE 4:673eb9735d44 25 for( UInt8 b = 0; b < ByteCount; ++b ) {
RichardE 4:673eb9735d44 26 digits = 0;
RichardE 4:673eb9735d44 27 // Add together lower 4 bits.
RichardE 4:673eb9735d44 28 sum = ( *ptrA & 0xF ) + ( *ptrB & 0xF );
RichardE 4:673eb9735d44 29 // If carry flag set then add one.
RichardE 4:673eb9735d44 30 if( carry ) {
RichardE 4:673eb9735d44 31 sum++;
RichardE 4:673eb9735d44 32 }
RichardE 4:673eb9735d44 33 // If result is >= 10 then set carry and subtract 10 from sum.
RichardE 4:673eb9735d44 34 carry = ( sum >= 10 );
RichardE 4:673eb9735d44 35 if( carry ) {
RichardE 4:673eb9735d44 36 sum -= 10;
RichardE 4:673eb9735d44 37 }
RichardE 4:673eb9735d44 38 // Write lower 4 bits.
RichardE 4:673eb9735d44 39 digits |= sum;
RichardE 4:673eb9735d44 40 // Add together upper 4 bits and carry.
RichardE 4:673eb9735d44 41 sum = ( ( *ptrA & 0xF0 ) >> 4 ) + ( ( *ptrB & 0xF0 ) >> 4 );
RichardE 4:673eb9735d44 42 // If carry flag set then add one.
RichardE 4:673eb9735d44 43 if( carry ) {
RichardE 4:673eb9735d44 44 sum++;
RichardE 4:673eb9735d44 45 }
RichardE 4:673eb9735d44 46 // If result is >= 10 then set carry and subtract 10 from sum.
RichardE 4:673eb9735d44 47 carry = ( sum >= 10 );
RichardE 4:673eb9735d44 48 if( carry ) {
RichardE 4:673eb9735d44 49 sum -= 10;
RichardE 4:673eb9735d44 50 }
RichardE 4:673eb9735d44 51 // Write upper 4 bits.
RichardE 4:673eb9735d44 52 digits |= ( sum << 4 );
RichardE 4:673eb9735d44 53 // Store digits in result and skip to next byte.
RichardE 4:673eb9735d44 54 *ptrR++ = digits;
RichardE 4:673eb9735d44 55 ptrA++;
RichardE 4:673eb9735d44 56 ptrB++;
RichardE 4:673eb9735d44 57 }
RichardE 4:673eb9735d44 58 return carry;
RichardE 4:673eb9735d44 59 }
RichardE 4:673eb9735d44 60