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 170 run 1000 : 1010 rem input and save 1020 input "what shall we store";a$ 1030 for i=1 to len(a$) 1040 c$=mid$(a$,i,1) 1050 poke 3000+i,asc(c$) 1060 next 1070 return 1080 : 1090 rem retrieve message 1100 print:print "retrieving..." 1110 for i=1 to 100 1120 c=peek(3000+i) 1130 b$=b$+chr$(c) 1140 next 1150 print b$ 1160 return 1200 : 1210 rem stash to reu 1220 stash 200,3000,0,0 1230 return 1300 : 1310 rem clear internal memory 1320 for i=1 to 200 1330 poke 3000+i,0 1340 next 1350 return 1400 : 1410 rem retrieve from reu 1420 fetch 200,3000,0,0 1430 return 2000 : 2010 rem the end 2020 end