15

I recently picked up a 1541 Ultimate II+ for my Commodore 64 and have been amazed at how this device seemingly can do every flash memory and other enhancement feature for the machine, short of CPU acceleration. One thing that I've been particularly impressed with is how you can press the 'Menu' button and the U2+ firmware takes over to allow disk image selection and other configuration, but then will seamlessly go back to where you were before without losing state. In comparison to (say) an Apple II with a CFFA3k, this is way more convenient since the CFFA doesn't support a similar feature.

I believe that the C64 supports overlays of probably every section of RAM, but I'm curious how a cartridge can do this without interrupting the machine's state? Is it DMA'ing out all of the RAM and processor states and then running its own code (and then putting it back later) or something else like just saving processor context and then masking all RAM into the cartridge?

2 Answers 2

25

There isn't any actual "swapping" of code running in the C64's main memory. Rather, it is an instantaneous switch in whether the code is running from the main memory of from the cartridge memory. Furthermore, with a more sophisticated cartridge like the C64 Ultimate II, we also switch between running native code on the 6502 and running embedded code on the cartridge's own embedded CPU.

The Ultimate II cartridge works under the same principle as the older "Freezer" cartridges that have been popular on the C64 since 1985 (I believe ISEPIC was the first). Specifically, it takes advantage of the "Ultimax" mode that a C64 cartridge can enter. This mode was present in the C64 so that it could be compatible with cartridges designed for Commodore's MAX Machine.

When in Ultimax mode, the cartridge can take over the area of the C64 memory map usually occupied by the Kernal ROM ($E000-$FFFF). This means the cartridge takes over all the interrupt handlers too ($FFFA-$FFFF). Additionally, the cartridge is able to halt the 6502 in the C64, and master the bus (using the cartidge port DMA line), including the I/O device region of the C64 memory ($D000-$DFFF). In other words, full cartridge control of execution, memory, and I/O!

The code for the Ultimate II is open source. For more information take a look at c64.cc. This is the main part of the Ultimate II's application. It is written in C++, and compiled to run on an embedded processor that is synthesized in the cartridge's FPGA. Specifically, the methods C64::freeze and C64::unfreeze are good starting points to understand what is going on. Once you understand that this C++ code running on the cartridge co-processor can reach into the C64 memory and IO space, then it is easier to imagine how it can do things like display the menus, DMA load software directly to the C64's RAM, emulate many older C64 cartridges, and do it all without disturbing the internal state of a "frozen" C64 program.

8

A partial answer, at best, but the various freezer cartridges use the C64's otherwise mostly-useless support for Commodore MAX Machine cartridges, specifically to substitute ROM over the 6502's hardware vector area. Combine that with a cartridge's ability to trigger an NMI and you have a way of starting to execute from cartridge without permanently affecting the C64's memory, other than adding a few extra bytes on the stack.

After that, it's up to the cartridge what it does to present options to the user but, as you'd expect, it means copying existing contents of RAM elsewhere and copying them back later. I don't know the specifics of the 1541 Ultimate II+.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .