Build Your Own Commodore 64 Cartridge

Coinbase
Build Your Own Commodore 64 Cartridge
Ledger


Have you ever thought “IEEE Spectrum is terrific, but I just wish I had a way to experience even more of it, perhaps at a local science and technology museum?” Well, I am pleased to say that your very specific wish has been granted! In collaboration with the IEEE History Center and the IEEE Global Museum and the support of generous donors, Spectrum’s Chip Hall of Fame has been adapted into a traveling exhibit that has just begun making its way around U.S. museums, and, hopefully, the world.

Our Chip Hall of Fame celebrates microchips that have had a significant impact. Six of the chips from the hall were chosen to be part of the “Chips That Shook The World” exhibit, along with artifacts embodying how each was used. One of the chosen was the 8-bit 6502 processor, so naturally we thought a Commodore 64 home computer, which used a 6502 variant, should be one of the artifacts. Which led to another thought: Why not have the C64 run a program demonstrating an 8-bit CPU in action?

That’s how I ended up, 35 years after I last programmed a C64, sitting at my office desk creating a brand-new plug-in cartridge.

The C64 supported plug-in cartridges as a way of distributing software, and our demo program needed to be put on one. Each morning, the museum curator can just turn on the exhibit and presto! The demo program instantly begins running. The alternatives would have required the curator to type in commands to load the demo manually.

Ledger

But this convenience comes with two big caveats: One, the demo has to fit into just 16 kilobytes, the maximum size of a cartridge. Even by the standards of the 1980s, this is small, as some C64 titles spanned hundreds of kilobytes by loading data in chunks from disk or tape. Two, the demo would have to be written in 6502 assembly and control the C64 video hardware directly.

Cartridges require only a few components: a printed circuit board [bottom right], programmable memory chip [bottom middle], and some resistors, diodes, and a capacitor [top middle]. They are mounted in a 3D-printed shell [top left and right]. To make the video output compatible with modern screens, we used a RetroTink-2X Pro adapter [bottom left].James Provost

Fortunately, from attending Vintage Computer Federation events over the years, I knew there were a lot of free or inexpensive resources that would make it easier than ever before to do this sort of thing.

The first step was to figure out just how much I could do in 16 KB. The C64’s graphics hardware was groundbreaking in its day, capable of displaying images of up to 320 by 200 pixels with a palette of 16 colors. It could also display eight sprites at once; each sprite is a moveable single-color 24-by-21 pixel bitmap. The price for this power was complexity. The video chip’s control registers, screen bitmaps, text-screen data, default and custom character sets, sprites, and color information all live in different locations scattered across memory, with some data actually living in separate RAM and ROM chips.

So I sat down with the detailed memory maps and video hardware programming guides available for the C64. (This abundance of information is in stark contrast to the 1980s, when documentation was scant, even from Commodore itself). I worked out that I could cram in nine screens of explanatory text, animated graphics, and sprites. Creating these screens, including the custom character sets and sprites they rely on, was greatly simplified thanks to the online C64 graphics editor at petscii.krissz.hu. The editor can output some results as stand-alone assembly programs, which I adapted as subroutines in my demo code.

I had just enough space remaining for a lucky find. I wanted to display at least one full-screen bitmapped image, but a prerendered image would have required 8 KB of data, half the cartridge’s capacity. Instead I decided to use a classic hack of programmers since the days of games like Rogue and Elite: pulling free data out of the structure of mathematics by way of procedural generation.

Here’s where I got lucky: I came across the work of Marcello M., who had published the source for a C64 assembly program that quickly created a multicolor fractal Mandelbrot set using just 3.3 KB of code. With Marcello’s blessing, I incorporated his code as another subroutine.

Modern Tools For Writing C64 Software

The coding was done using the free IDE 65xx and Kick Assembler desktop software. I was able to test the code using the popular C64 Vice emulator, which allowed me to do handy things like examining live memory contents to find runtime bugs.

A diagram showing 64 kilobytes of RAM with a Kernal ROM occupying the top 8 KB, followed by 4 KB of character ROM, and then 8 KB of Basic ROM. Another column shows I/O and color RAM mapped to the same position as the character ROM, and two shadow ROM locations in lower memory. Finally a third column shows a 16 KB cartridge ROM overlapping the Basic ROM and the memory below it. Regions of the Commodore 64’s RAM were mapped to things like the system ROMs, video-color memory, and the bitmaps of characters, the latter of which were actually mapped to multiple locations in RAM when accessed by the video hardware. Some of these mappings overlapped: Inserting a 16-KB cartridge automatically disabled the ROM storing the Basic interpreter. James Provost

The next step was to make a physical cartridge. Again, there’s modern help, this time in the form of US $5 printed circuit boards that need just a handful of components soldered in to make a cartridge. These components include a programmable ROM chip that I picked up for $3 on eBay. I burned my code to the memory chip with my trusty TL866 programmer and mounted it to the PCB, which in turn was mounted into a 3D-printed cartridge case.

Then came the moment of truth. It probably won’t come as a surprise to regular readers that I already own an original C64, which I connect to modern flat-screen displays via a RetroTink-2X Pro adapter. So I carefully pushed the cartridge into its slot and turned the machine on.

Naturally, my C64 immediately froze up. I had forgotten to remove a little bit of memory-management code that made the demo work in the Vice emulator by disabling the ROM that stores the C64’s Basic interpreter. On the real hardware, this snippet ended up disabling half the cartridge’s memory. A quick edit and a trip back to the TL866 and I was ready to try again. Success! I was finally literally ready to ship some software, all the way to Upland Exhibits, the people building our traveling display.

I hope you get a chance to see my little demo and our “Chips That Changed The World” exhibit in person: We’ll post current and upcoming locations on the Chip Hall of Fame page. But in the meantime, whether you used the C64 back in the day, or are just looking for a fun coding challenge, I recommend trying your hand at programming this 8-bit classic, now that so many of the original pain points have been reduced!

From Your Site Articles

Related Articles Around the Web



Source link

Bybit

Be the first to comment

Leave a Reply

Your email address will not be published.


*