BASIC Garbage Collection Compo

This is my entry for the BASIC Garbage Collection Compo. The goal was to write a program which causes the longest GC runtime. The rules allowed only Basic programs without commands like SYS, POKE or PEEK (which could start your own assembler program). I managed to exploit the BASIC ROM to store a return address to the string memory area on the stack, using a known bug. To be on the safe side I added a classic NOP-slide, because I was too lazy to calculate and construct the program at the exact address in the string memory.

The rest was easy: The assembler program is written relocatable, so that it runs at any place in memory (using a neat trick to get the value of the PC). It copies the BASIC ROM into the RAM, enables the RAM under the BASIC ROM, patches the fre-entry pointer and copies a part of itself to $c000. This part is called when the fre-function is called and waits for 10 hours, then calls the fre-function. A small Python script created the DATA lines from it (needed to be in reverse order because the string memory is filled from top of the Basic memory end to the bottom), which I could then paste into the VICE emulator.

In the results of the compo the organizer ssdsa created a new category for my kind of solution :-)

The documented assembler source code: challenge.asm

The Basic program:

10 read a
20 if a<0 then goto 40
30 a$=chr$(a):goto10
40 for i=1 to 100:a$=chr$(234)+a$:next
50 for i=1 to 100:a$=a$+"":next
60 print 42*(""+-42)
100 data 179,125,76,238,208,162,197
110 data 128,169,244,208,161,197,245
120 data 169,250,208,160,197,32,169
130 data 167,174,76,168,163,32,21
140 data 133,0,169,20,133,100,169
150 data 88,1,133,54,169,160,91
160 data 141,192,169,104,160,90,141
170 data 0,169,248,208,200,192,0
180 data 153,87,177,0,160,88,133
190 data 0,105,104,87,133,56,105
200 data 24,104,154,202,202,186,0
210 data 87,32,87,133,96,169,239
220 data 208,192,201,88,165,88,230
230 data 249,208,200,87,145,87,177
240 data 0,160,88,133,160,169,87
250 data 133,0,169,120,234,-1
1000 print"collecting..."
1010 ti$="000000"
1020 print fre(0)
1030 te$=ti$:print te$:end
2. October 2013