A retro gaming programme, designed for use on a portable embedded system. Incorporates power saving techniques.

Dependencies:   ConfigFile N5110 PowerControl beep mbed

Revision:
79:a92239ce3b20
Parent:
78:e2fc547c6b99
Child:
80:55c724c1286c
--- a/main.cpp	Mon May 11 14:38:04 2015 +0000
+++ b/main.cpp	Mon May 11 15:11:18 2015 +0000
@@ -40,6 +40,10 @@
     char *key1 = "Open1";
     char *key2 = "Open2";
     char *key3 = "Open3";
+    
+    char a[3],b[2],c[2];
+    
+    int count=0;
 
     ///Checks Key for match, then reads Value - if read is unsuccessful it prints error message.
     if (!cfg.read("/local/towerMemory.cfg")) {
@@ -48,22 +52,59 @@
     ///check file size - if size acceptable, prints buffer to location.
     if (cfg.getValue(key1, &player1initials[0], sizeof(player1initials))) {
         serial.printf("%s\n",player1initials);
-        char a = player1initials[10];
-        highScore1 = atoi((char*)a);
+       
+        count=10;//first possible character of score
+        highScore1=0;//make sure that multiplacation works correctly
+        while(1){
+            //if first iteration/not an empty score
+            if(highScore1!=0){
+                highScore1*=10;
+            }
+            //convert ASCII to int value
+            highScore1+=player1initials[count]-48;
+            //increment
+            count++;
+            //check to see if at end of string array
+            if(player1initials[count]==NULL){
+                break;
+            }
+        }
+        serial.printf("%i\n",highScore1);
     }
     //check file size - if size acceptable, prints buffer to location.
     if (cfg.getValue(key2, &player2initials[0], sizeof(player2initials))) {
         serial.printf("%s\n",player2initials);
-        char b = player2initials[10];
-        highScore2 = atoi((char*)b);
-        serial.printf("%c\n",b);
+        count=10;
+        highScore2=0;
+        while(1){
+            if(highScore2!=0){
+                highScore2*=10;
+            }
+            highScore2+=player2initials[count]-48;
+            count++;
+            if(player2initials[count]==NULL){
+                break;
+            }
+        }
+        serial.printf("%i\n",highScore2);
     }
     //check file size - if size acceptable, prints buffer to location.
     if (cfg.getValue(key3, &player3initials[0], sizeof(player3initials))) {
         serial.printf("%s\n",player3initials);
-        char c = player3initials[10];
-        highScore3 = atoi((char*)c);
-        serial.printf("%c\n",c);
+        count=10;
+        highScore3=0;
+        while(1){
+            if(highScore3!=0){
+                highScore3*=10;
+            }
+            highScore3+=player3initials[count]-48;
+            count++;
+            if(player3initials[count]==NULL){
+                break;
+            }
+        }
+            
+        serial.printf("%i\n",highScore3);
     }
 }
 
@@ -1096,6 +1137,7 @@
         state1 = 0;
         state2 = 0;
         state3 = 0;
+        write();
     }
 }
 
@@ -1171,7 +1213,7 @@
                     wait(0.5);
                     lcd.normalMode();
                     newScore();//enter initial screen if previous scores are beaten
-                    write();
+                    //write();
                     resetGame();//reset values
                     break;
                 }