I'm working on a simple game console, and I'm planning to use a cartridge system using an EEPROM. I know that you can read and write data from an EEPROM, but can you compile the data into executable Arduino code, and vice versa? I've heard you could use Forth, a language for the Arduino. The only problem here is that I'm using a library made by Adafruit to control the LCD screen the console is running on, and I doubt Forth can convert that. So yeah. That's my dilemma.
You can make FORTH use the library, but then you have to implement the library interface and usage in FORTH. It’s easier to do it all in FORTH. It’s fun to learn to control the hardware in FORTH instead of assembler. And writing an assembler in FORTH is common practice, I’ve written such assemblers for a couple of 8 bit controllers in the 80s.
Question is whether you want to spend some time learning FORTH or you want a faster solution.
The first one is complex, but, I think, possible. Given what you have said so far, I suspect you don’t have much experience, so it will be well beyond your capabilities at this time, and probably my own also. Two Arduinos (maybe two atmega/attiny chips): one to run the game; the second to read the eeprom and upload the compiled code (Hex file) for a selected game to the first Arduino, using either serial or ISP method. I know that Crossroads (a forum member) has done something similar and built a device which can read a hex file from an sd card and upload that to an Arduino, and this is basically the same idea.
The second idea is far simpler. The cartridge contains, instead of an eeprom, the “arduino” (or an atmega chip) programmed with a game. The rest of the console system (display, buttons etc) is “dumb”, having no processor of its own, until the cartridge is inserted. To keep the number of pins in the cartridge connector down, all the components in the console need to communicate over a bus, like i2c or SPI.
Great idea, an exchangeable controller in a docking station
Eventually the docking station contains another Arduino that connects the bus to the sensors and actuators. The display most probably uses an bus already.
FORTH code can reside everywhere because it is not normally executable machine code. Primitives in machine code can reside in the controller, including the firmware for all peripherals.
Ok, I think I might have an idea. What if the EEPROM was stored with pure ASCII text? I doubt this will work, but perhaps the Arduino could decode it, and then somehow execute it?
Or, the ASCII text could contain my own simple language, containing all of the things you need to control the screen, where the Arduino can Lex and Parse it?
Is the code on the cartridge written and/or compiled for the arduino, or are you using cartridges originally made for another processor, such as a commercial game system?
david_2018:
Is the code on the cartridge written and/or compiled for the arduino, or are you using cartridges originally made for another processor, such as a commercial game system?
I'm planning to simply use an external EEPROM that you put into the hardware. I could also find a way to connect the Arduino to an external EEPROM, where you can then interchange it with others.