arduino-boy icon indicating copy to clipboard operation
arduino-boy copied to clipboard

EEPROM Initialization

Open delipunch opened this issue 9 years ago • 7 comments

No way given, aside from normal use, to initialize EEPROM.

delipunch avatar Jun 12 '15 17:06 delipunch

This is true. What I did the first time is comment out some code so the data is read from FLASH. Then I forgot about it.

https://github.com/pepijndevos/arduino-boy/blob/master/gameboy.ino#L167

pepijndevos avatar Jun 12 '15 18:06 pepijndevos

How about this

//This sketch is a way of initializing the EEPEROM for Bill's Arduino (https://github.com/pepijndevos/arduino-boy)
//By Alex McPhail
//I don't care how you use this
#include <EEPROM.h>
#include "output.h"

void setup()
{
  for(int i=0;i<=PLAYER_LENGTH;i++)
    EEPROM.write(i,DATA_BLOCK[i]);
}

void loop() {}//nothing to do

delipunch avatar Jun 12 '15 18:06 delipunch

That would work. How would you suggest to include it in the project? Maybe the init could check if the EEPROM contains valid data and fill it in otherwise. PR welcome.

pepijndevos avatar Jun 12 '15 20:06 pepijndevos

Actualy, it's a bit more subtle. Since I only store one Pokemon, the layout in EEPROM is different from the one in FLASH.

pepijndevos avatar Jun 12 '15 20:06 pepijndevos

So what's the difference in the layouts? And you could include it as a separate .ino

delipunch avatar Jun 12 '15 21:06 delipunch

If you'll look at output.h you'll see there are 6 Pokemon, 6 trainer names, and 6 nicknames. Just the first of those are stored in EEPROM. You can see the code in the main loop. The indices start at 0, 44 and 55.

pepijndevos avatar Jun 13 '15 07:06 pepijndevos

So I've made a fork, and it mirrors your data, thus doesn't need initialization, because it's your save, "copied". All I did was remove all instances of Serial, and changed three 44's to 48's (lines 78, 86, 93). No idea why it's done what it's done :P

delipunch avatar Jul 29 '15 19:07 delipunch