 // By Ponticelli Domenico.
+// 12NOV2020 EEPROM Fix added, modified by Zontex
 // https://github.com/pcelli85/M5Stack_FlappyBird_game
 
 #include <M5Stack.h>


void resetMaxScore()
{
  EEPROM_Write(&maxScore,0);
}



void EEPROM_Write(int *num, int MemPos)
{
 byte ByteArray[2];
 memcpy(ByteArray, num, 2);
 for(int x = 0; x < 2; x++)
 {
   EEPROM.write((MemPos * 2) + x, ByteArray[x]);
 }  
}



void EEPROM_Read(int *num, int MemPos)
{
 byte ByteArray[2];
 for(int x = 0; x < 2; x++)
 {
   ByteArray[x] = EEPROM.read((MemPos * 2) + x);    
 }
 memcpy(num, ByteArray, 2);
}




void setup() {
  // put your setup code here, to run once:
  M5.begin();
  M5.Power.begin();
  EEPROM.begin(1000);
  //resetMaxScore();
  Serial.println("last score:");
  Serial.println(EEPROM.readInt(address));
}

void loop() {
