With a RAM Expansion Unit (REU), the Commodore 128 could address up to 512k of data. That was huge in the late eighties! All you needed was one of those REUs, plug it into your cartridge port, and so much more super fast memory was at your fingertips.
But even with such a cartridge at hand, how do we actually make use of it from CBM BASIC 7.0? With three funky commands called STASH, FETCH and SWAP. Here’s how we can use them.
The REUs cannot be addressed directly, like other memory in your computer. Instead, data has to be either copied from the C128 to the REU, or vice versa, or swapped out. All three commands take the same four parameters:
- number of bytes to transfer
- location in the C128 memory to start
- REU bank (0-7, depending on the size of the REU)
- location in the REU bank memory
This sounds more cryptic than it actually is: the largest REU split 512k over 8 banks of 64k, so that the 8bit operating system could address it.
So to store 200 bytes of C128 memory, starting at location 5000, saving it inside the REU’s bank 0, location 0, we can use the STASH command like so:
To retrieve our data later and bring it back to the same C128 location as before, we can use FETCH with the same parameters:
Rather than copying, we can also exchange data in two places by literally swapping it over. Again the parameters are the same:
Enabling REUs in VICE
Although I have a physical C128, I do not have a real REU. Maybe one day I’ll find one on eBay, but until then there’s an easy way to emulate an REU using VICE.
To enable one, head over to Settings – Resource Inspector – Cartridges – REU. Pick the size you like, and even a hard disk location to make the contents of your REU survive restarts.
Here’s a quick test that allows us to store an arbitrary message in memory, then stash or retrieve it from an attached REU.
100 print "1 store message in internal memory"
110 print "2 print message"
120 print "3 stash message in reu"
130 print "4 retrieve message from reu"
140 print "5 clear internal memory"
141 print "6 quit"
150 input "your choice";m
160 on m gosub 1010,1090,1210,1410,1310,2000
1010 rem input and save
1020 input "what shall we store";a$
1030 for i=1 to len(a$)
1050 poke 3000+i,asc(c$)
1090 rem retrieve message
1100 print:print "retrieving..."
1110 for i=1 to 100
1150 print b$
1210 rem stash to reu
1220 stash 200,3000,0,0
1310 rem clear internal memory
1320 for i=1 to 200
1330 poke 3000+i,0
1410 rem retrieve from reu
1420 fetch 200,3000,0,0
2010 rem the end
We don’t see many BASIC listings these days anymore. Enjoy!