I was getting ?OUT OF MEMORY ERROR
when I was trying to get directory listing of a disk after returned assembly routine.
I've prepared a simple routine just to understand what was happening, e.g:
*=$c000
lda #$00
sta $d020
rts
And my build script is:
C:\...\acme0.95.6win\acme.exe --outfile build\ROUTFILE --format cbm RSOURCEFILE
C:\...\tools\WinVICE-2.4-x64\x64.exe build\ROUTFILE
When I run the build script emulator loads the PRG file. Tries to run it but nothing happens as I didn't include the BASIC loader. Even after that point if I writre LOAD "$",8
to get directory listing. I'm getting ?OUT OF MEMORY ERROR
. So what is wrong in above scenario?
Hex dump of the PRG file is:
00 c0 a9 00 8d 20 d0 60
This appears to be just an artifact how the Commodore 64 loads programs. When you you use the LOAD command to load something in memory, the pointers to the start and end of various BASIC data areas are set to the address immediately after the loaded program. So for a 6 byte program loaded at $C000, these pointers are set to $C006. However the end of BASIC memory pointer remains at $A000. This creates an invalid situation, the as the pointers to BASIC's data areas are higher than the maximum address BASIC is allowed to use. It ends up looking like BASIC has run out of memory.
Usually this isn't a problem. You can only load assembly programs to $C000, and the so normally first thing and only thing you do after loading the program is execute the program by entering SYS 49152
, like Jester mentioned. If you want load the program but not execute it right away you can fix the invalid pointer problem by using the NEW command as given in Peter Kofler's answer, this should reset the pointers to their valid default states, while leaving the code loaded at $C000 unmodified.