Python adventure Part 1: Fun 32 bytes at a time (Atari 2600 project)

I formed an idea recently that lead down a path. Then that lead down another path followed by another path. And…well lets just say that was several paths ago and metaphor is running thin.

I’ll try to summarize: as part of another project, I want to be able to plug an Atari 2600 cartridge into a computer have that game popup on screen like I was playing a real console. That’s the basic premise: walk up to PC with 2600 edge connector, insert random cartridge from 1978 or so, game pops up on screen as if it’s a 2600 console ready to play.

I have this old Intel Atom-based board called the Latte Panda v1. It’s about the size and formfactor of your typical Raspberry Pi only it has an Arduino also built into the motherboard (a regular ATmega32u4). I’ve probably mentioned it in prior posts. Like a Pi, the whole thing – Atom SoC and Arduino – runs on 5 volts which is what the appeal has always been for me and these low end Atom boards.

Anyway, I bought it in 2019 and never did anything with it. In fact it still a copy of windows 10 from 2016 loaded on it.

First a small digression: this thing I’m describing with the Atari cartridges can also be done with one of the few if not only modern 2600 clones out there: the Atari flashback 2. It has solder points for a cartridge slot and everything. If it came to it I could actually go that route for the project this is intended for. This would involve some kind of stealth build where the cartridge slot was fitted seamlessly in next to the PC in a custom case. And it would require a separate audio, video, volume, power routing and some way for swap things things around between and the PC.

So I started searching to see if there was another solution to the flashback 2. That’s the end of the digression. Probably.

I did vaguely remember the Hyperkin SmartBoy: you connected it to your Android Phone then plugged in a legit cartridge and you can play that Gameboy game through your phone. That product disappeared rather quickly, I’m not sure why (too much input lag judging by reviews). Anyway, I remember the description said it would copy the rom over temporarily for playing the game in an emulator then the copy would disappear when you’re done. And I started to think maybe I could do something similar since the 2600 was so dead simple of a technology, I thought perhaps an Arduino could pull that off.

Well to summarize: an old thread on Atari age lead to a project on hackaday which lead to two different repositories on GitHub. This lead to multiple hours of Arduino-related research only to realize that the project described used at “stm32duino” which is arm-based and not compatible with the actual Arduino (e.g. atmega based). Which is too bad because that stm32duino/2600 cartridge stack looks really, really cool. And actually does the first part of exactly what I was looking for: dumps the rom to a temporary storage location making it ready to immediately launch into an emulator like Stella.

After still further research, I found this old blog entry for a guy using a regular Arduino to dump Atari cartridges. But, as the entry states, he only dedicated an afternoon to it and only utilized what he happened to have around the house at the time. So the project was not entirely done and still had some missing bits. The blog also mentions a Ruby script that takes the converts the binary of the ROM cart to a hexadecimal string.

Both the blog entry and the guy from the hackaday project mentioned not being 100% compatible with cartridges because of different methods of “bank switching” utilized by some games. I don’t need to know what that means, only that it results in not 100% compatibility.

I also remember a video from 2017 that used a Raspberry Pi 3, and NFC reader and a 3D printed mini-NES case to auto-load specific NES ROMs based on NFC cards with game information stored on them in an emulator.

This feels like it took a while to get there but to combine all these things together….

I decided I didn’t want to dump the entire cartridge ROM to the computer and run that in the emulator but rather identify the ROM, look the rom up from a list and based on that run that ROM.

So that’s where I ended up landing with my idea: use the ATmega32u4 on the v1 Panda to read just a few bytes of the rom. Then, based on this string, determine the matching ROM file and load that into a the emulator.

So far all I’ve done is ask ChatGPT to convert the Ruby script to Python then ask ChatGPT to re-factor the script to better in some way. Then I did some intermittent chatting with ChatGPT and ended up with a couple more scripts: convert the binary to a hex formatted text file, and convert such a text file back into a binary.

To summarize: first I’ll need to download as many 2600 ROMs as possible (assuming I don’t have the whole set already stored some place). Then use a python script to grab an arbitrary number of bytes from each ROM file – just enough to hopefully uniquely identify it. This will also now be referred to as a “unique identifier” (or UID) string with the file name of each ROM file.

With that association made I would then throw some random UID at it to make sure it can lookup and find the ROM file as quickly as possible. ChatGPT will also help with this.

That part will probably be relatively easy. The part I’ve never done before is the Arduino programming part. Can I figure out how to read some number of bytes of the ROM cartridges?


References and links of note:

Leave a comment