Jump to content
  • 0

Tricks for maximizing BASIC memory?


rje
 Share

Question

My latest program has more than 10K of DATA statements, which I of course read into BASIC arrays; thus, 10K of DATA becomes 20K of RAM, very roughly.

That sucks up my available space quickly.

The obvious fix is to POKE that data into RAM banks, instead of BASIC arrays.  As long as I'm careful, that should free up some memory.

But, I really wish I could load directly into banked RAM. 

Is it reasonable to write an assembly language-based data loader, then load the BASIC main program separately?  

Edited by rje
  • Like 1
Link to comment
Share on other sites

7 answers to this question

Recommended Posts

  • 1

You can load binary files directly into banked RAM using POKE and LOAD commands:

POKE $9F61,1

LOAD "DATA.BIN",8,1,$A000

This will load DATA.BIN from the SD Card (or host FS if using the emulator) into RAM banks starting with bank 1. If the file is greater than 8k, it will automatically load across multiple banks.

If you need to load directly to VRAM, you can use VLOAD:

VLOAD "GFX.BIN",8,0,$0000

This will load to 0:0000 in VRAM, also continuing into bank 1, if necessary.

  • Thanks 4
Link to comment
Share on other sites

  • 0
On 5/26/2020 at 3:34 PM, SlithyMatt said:

You can load binary files directly into banked RAM using POKE and LOAD commands:

POKE $9F61,1

LOAD "DATA.BIN",8,1,$A000

This will load DATA.BIN from the SD Card (or host FS if using the emulator) into RAM banks starting with bank 1. If the file is greater than 8k, it will automatically load across multiple banks.

Are the first two bytes of that BIN file an offset?  Or am I misremembering?

Link to comment
Share on other sites

  • 0
  • Super Administrators
7 hours ago, rje said:

Are the first two bytes of that BIN file an offset?  Or am I misremembering?

It depends on which first two bytes you mean. 😃

In a PRG file, the first two bytes are the 16-bit address the binary data gets loaded to. So if you see 01 08 in the first two bytes, that's usually a Commodore 64 BASIC program (or a machine language program with a BASIC launcher.)

Anyway, since the mapped memory on the Commander is at $A000, files loaded in to banked space should start with 00 0A. The bank number is not encoded in the file, so you'll need to determine that separately. (Usually, your program just picks a bank, although I believe there was talk about a bank reservation API.)

Anyway, the standard LOAD command has to make a decision when loading data: when you tack a ,1 at the end (ie: LOAD "*",8,1), that tells the KERNAL to honor the start address in the file. If you do not tack the ,1 on the end, the KERNAL loads the program at the start of BASIC.  Why would you ever want to load a program to a different location than from where it was saved? Turns out that basically every Commodore 8-bit used a different start address for BASIC programs, and on the VIC-20, BASIC programs can even start in a different place when memory expansions are installed. 

 

  • Like 1
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Answer this question...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

×
×
  • Create New...

Important Information

Please review our Terms of Use