Screen Memory

cbmeeks edited this page Mar 2, 2016 · 11 revisions

Defaults

The default screen location when you power on your Commodore 64 is 0400 to 07E7 (1024 to 2023 decimal).

Which is 1,000 bytes.

Video Bank

All graphics for the VIC-II are relative to the current video bank.

There are four video banks available to the Commodore 64.

Only one bank can be active at a time and each bank is 16KB in size. Which means the VIC-II can only access 16KB of graphics memory. Careful consideration should be in your design when choosing which bank(s) to use for your game or demo.

Address Mask Bank Yields
DD00 %xxxxxx11 bank0 0000 - 3FFF
DD00 %xxxxxx10 bank1 4000 - 7FFF
DD00 %xxxxxx01 bank2 8000 - BFFF
DD00 %xxxxxx00 bank3 C000 - FFFF

How to change video banks

// Video Bank 0
LDA $DD00
AND #%11111100
ORA #%00000011
STA $DD00

// Video Bank 1
LDA $DD00
AND #%11111100
ORA #%00000010
STA $DD00

// Video Bank 2
LDA $DD00
AND #%11111100
ORA #%00000001
STA $DD00

// Video Bank 3
LDA $DD00
AND #%11111100
ORA #%00000000
STA $DD00

Character Memory

All addresses are relative to the video bank. For example, using Video Bank 1 and setting D018 to 0800 yields character memory being located at 4800.

Address Mask Type Yields
D018 %xxxx000x charmem 0000
D018 %xxxx001x charmem 0800
D018 %xxxx010x charmem 1000
D018 %xxxx011x charmem 1800
D018 %xxxx100x charmem 2000
D018 %xxxx101x charmem 2800
D018 %xxxx110x charmem 3000
D018 %xxxx111x charmem 3800

Setting Character Memory and Screen Memory Location

The following KickAssembler macro makes it easy to switch banks. Just replace screen with the desired screen location and charset with the desired character set location.

LDA #[[screen & $3FFF] / 64] | [[charset & $3FFF] / 1024]
STA $D018