Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

C64 out of memory error after loading PRG file in VICE emulator

Tags:

assembly

c64

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 
like image 623
wizofwor Avatar asked Dec 01 '22 11:12

wizofwor


2 Answers

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.

like image 198
Ross Ridge Avatar answered Dec 05 '22 05:12

Ross Ridge


Sometimes after loading data into higher areas of memory, in your case $c000, the memory pointer is broken (as doynax suggests). You need to do a

NEW

to fix that. (The Basic memory pointer is updated to the end of the loaded file. If your file ends after $A000 you are out of Basic memory, resulting in OUT OF MEMORY ERROR.) After that you will be able to load $. As you have no Basic code, that will not do any harm.

I do not know the tools you are using, but as mentioned by Jester, your code needs to be loaded as ,8,1 so the load address is respected. The code you shared is correct, it starts with 00 C0 as first two bytes which are the load address.

If load "$",8 succeeds and your file is on the disk, try loading it ,8,1 and then try sys 49152 (which is 0xC000).

like image 20
Peter Kofler Avatar answered Dec 05 '22 06:12

Peter Kofler