How can I keep game saves on the EEPROM?


(Grant Wiggins) #1

I have been playing Mystic Balloon, and it saves game progress on the EEPROM. I am scared to install a new game because I don’t want lose my progress. Will the EEPROM keep my progress? If not, is there a way to extract the data from the EEPROM to put back on later?


(Pharap) #2

One option is to use @crait’s Arduboy Manager in conjunction with the ‘sketch’ Arduboy Assistant.

As detailed here:


I believe there are other programs that can do this, but I can’t think of any off the top of my head.


(Scott) #3

(Molly C) #4

Is there a way to dump the EEPROM that doesn’t involve an arduboy app dumping it out serial?


(Pharap) #5

Serial or not, it would have to be done over the USB link because that’s the only way the Arduboy has of communicating with a computer.

I think it’s possible for it to be built into the bootloader somehow so you don’t need a special Arduboy program, but I don’t know if that’s been attempted before.

Maybe that’s something for @Mr.Blinky to consider adding to his custom bootloader?


There is one other possibility I can think of, which is making the screen create a QR code (or something similar) that encodes the EEPROM data, and then using a QR code reader to read and save a copy. But that still needs a custom Arduboy program, and would almost certainly take up more progmem space than code for serial transmission.


#6

It’s already in there In bootloader. However since data is transmitted in binary. You can’t use the Arduino IDE monitor. You would would need a (monitor) program for it or use a scripting language with serial support.

basically what would needed to be typed in/send to backup/read the EEPROM is:

  1. ‘A’, 0, 0 To select address 0
  2. Ignore the 1 byte response (13)
  3. ‘g’, 0, 128, ‘E’
  4. read 128 bytes of EEPROM data
  5. repeat steps 3 and 4 above 7 more times to reaad the full 1K EEPROM data

To restore/write the EEPROM :

  1. ‘A’, 0, 0 To select address 0
  2. Ignore the 1 byte response (13)
  3. ‘B’, 0, 128, ‘E’
  4. Ignore the 1 byte response (13)
  5. write 128 bytes of data
  6. repeat steps 3 to 5 above 7 more times to write the full 1K of data

You could also use the speaker to beep out the data. But in both cases it’s backup only as there is no camera /microphone to read it back. besides that it would take too much program space to implement.

Fun tip!

If you put Arduboy in bootloader mode, quickly open the Arduino IDE monitor with the right COM port selected, type capital S and press enter quickly. You will get CATERIN as response for the stock bootloader and ARDUBOY if my custom Arduboy bootloader is in use. ‘S’ is the command to request the software ID :slight_smile:


(Pharap) #7

Is there some full documentation of the different commands somewhere?

I might have a go at making a tool for this sometime.
(If only the Arduino IDE has a plugin framework. Thankfully other tools like Visual Studio Code do.)

Yeah, I thought about that.
A microphone jack would have done the job if there was one (although those can be noisy, pun intended).


(Scott) #8

It’s basically the AVR109 protocol
http://www.atmel.com/images/doc1644.pdf


#9

Here’s my almost complete list (lock/fuse bits cmds missing) supported by the Caterina bootloader:

AVR109 command list Caterina bootloader
--------------------------------------------------------------------------------
Host                    Caterina       discription
--------------------------------------------------------------------------------
'S'                     'CATARIN'      7 character software ID
'V'                     '1' '0'        Get software version. Version 1.0
'v'                     '?'            Get hardware version. Command not implemented
'p'                     'S'            get programmer type. 'S' for serial
'a'                     'Y'            Auto address increament supported. 'Y'es
'b'                     'Y' 0x00 0x80  Support block transfers. Yes 128 bytes block size
't'                     0x44 0x00      request supported device list. 0x44 is device ID, 0x00 is end of device list
'T 0x44                 0x0D           select device. Just sends response
'P'                     0x0D           select programming mode. Just sends response
's'                     0x87 0x95 0x1E get device signature. ATMEGA32U4 signature
--Write Flash/EEPROM------------------------------------------------------------
'A' MSB  LSB            0x0D           Set current address to (MSB << 8) | LSB
'B' 0x00 0x80 'F' data  0x0D           Write 128 bytes of data to flash and Resets the bootloader timeout
'B' 0x00 0x80 'E' data  0x0D           Write 128 bytes of data to EEPROM and Resets the bootloader timeout
--Read Flash/EEPROM-------------------------------------------------------------
'A' MSB  LSB            0x0D           Set current address to (MSB << 8) | LSB
'g' 0x00 0x80 'F'       data           read 128 bytes data from flash and resets the bootloader timeout
'g' 0x00 0x80 'E'       data           read 128 bytes data from EEPROM and resets the bootloader timeout
--End---------------------------------------------------------------------------
'L'                     0x0D           Leave programming mode. Just sends response
'E'                     0x0D           End of session. Sets bootloader timeout to 500 millisecs.
--------------------------------------------------------------------------------
To do:
Add lock/fuse bits commands, custom arduboy commands to this lists

Notes:
the read/write block commands supports lengths from 0 to 128 bytes.
--------------------------------------------------------------------------------

(Molly C) #10

Yeah I realize it would, I was just wondering if the command line utility we used to flash sketches had the capability.


(Molly C) #11

Looks like avrdude can erase the EEPROM.

Usage: avrdude [options]
Options:
  -p <partno>                Required. Specify AVR device.
  -b <baudrate>              Override RS-232 baud rate.
  -B <bitclock>              Specify JTAG/STK500v2 bit clock period (us).
  -C <config-file>           Specify location of configuration file.
  -c <programmer>            Specify programmer type.
  -D                         Disable auto erase for flash memory
  -i <delay>                 ISP Clock Delay [in microseconds]
  -P <port>                  Specify connection port.
  -F                         Override invalid signature check.
  -e                         Perform a chip erase.
  -O                         Perform RC oscillator calibration (see AVR053).
  -U <memtype>:r|w|v:<filename>[:format]
                            Memory operation specification.
                             Multiple -U options are allowed, each request
                             is performed in the order specified.
  -n                         Do not write anything to the device.
  -V                         Do not verify.
  -u                         Disable safemode, default when running from a script.
  -s                         Silent safemode operation, will not ask you if
                              fuses should be changed back.
  -t                         Enter terminal mode.
  -E <exitspec>[,<exitspec>] List programmer exit specifications.
  -x <extended_param>        Pass <extended_param> to programmer.
  -y                         Count # erase cycles in EEPROM.
  -Y <number>                Initialize erase cycle # in EEPROM.
  -v                         Verbose output. -v -v for more.
  -q                         Quell progress output. -q -q for less.
  -l logfile                 Use logfile rather than stderr for diagnostics.
  -?                         Display this usage.

avrdude version 6.3, URL: <http://savannah.nongnu.org/projects/avrdude/>

#12

Don’t know about other programmer implementations but the Caterina (read Arduboy) bootloader’s chip erase command does not do an actual chip erase that would wipe everything. Instead it erases only the application area.The Bootloader and EEPROM area are left unchanged.

Ah was that your question. You can use avrdude to backup and restore the EEPROM contents