Wednesday, November 09, 2016

Building the Memory Map.

Normally when I try to program something, I just dig right in and start typing up some code.  The same is true when I started this project.  I sat down and just started typing away.  After a short while, things started to feel a bit hap-hazard.  I needed a plan, especially if I was going to use the hi-res screen.  There was 8k of memory that needed to be placed.  There are only 8 possible locations that the computer can use, and some of those were not possible because the memory was allocated for the function of the computer.

Below is a chart of the default memory map on the left and my proposed memory map for the Lunar Lander game on the right:

memmap

The default location for the bitmap screen is in the first 16k of memory (bank 0). The VIC II chip can only see a 16K block of memory at a time.  Being set to the first 16K puts it on Zero Page of the processor where a lot of things are going on.  Also, the chip can only allocate the hi-res bitmap to either the first half or the last half of the 16K of memory.  In the case of default, that means the addressing for the hi-res screen can start at memory location 0 or memory location 8192.  The first is in the middle of memory used by the computer to work, the second puts it in the middle of  program RAM.  If I left things at default, I’d have to program around the graphics screen.  There also isn’t much room to put sprite data.  

I’ve decided to use bank 3.  The memory locations 32768 to 49151 will be exclusively used for video data.  As you can see from the chart, the screen memory will now start at 32768, the custom characters will start at location 34816 and the sprite data will be stored from 38912 to 40959.  After that, I have 8k of memory free for the hi-res bitmap screen.  I can do this by turning off the BASIC rom giving the processor access to all the ram underneath it.

This configuration will give me 30k of continuous memory for programming, 12K of available memory for display functions, plus the default character set if I want to use it for any reason.  There is also a free bank of 4k of memory available from 49152 to 53247 as well as 1K of memory from 1024 to 2023 that used to be screen memory but was freed when I change banks on the VIC II chip from 0 to 2.

Next time I’ll talk about how I set up the C64 for this new memory map.