VIC bank

From C64-Wiki
Jump to: navigation, search

A VIC bank is one of four 16 kB "regions" in the 64 kB RAM available in the C-64. The VIC-II chip itself can "only" address 16 kB, and so any graphics, text etc. generated, must fit into 16 kB. To provide access for the VIC to the entire 64 kB address space, two lines, or bits, in Port A of CIA-2 directs the VIC to one of four VIC banks.

Selecting VIC banks[edit]

Bank
no.
Bit pattern in
56576/$DD00
AddressROM chars
available?
DecHex
0xxxxxx110–16383$0000–$3FFFYes, at 4096–8191
$1000–$1FFF
1xxxxxx1016384–32767$4000–$7FFFNo
2xxxxxx0132768–49151$8000–$BFFFYes, at 36864–40959
$9000–$9FFF
3xxxxxx0049152–65535$C000–$FFFFNo

Port A at CIA-2 are controlled by software through the addresses 56578/$DD02 (directional register) and 56576/$DD00 (data register): The two least significant lines/bits in this port is set up as outputs by default, but the cautious programmer may want to assert this before the actual VIC bank selection takes place using 56576.

The table shown to the right lists the four available VIC banks, along with the relevant combination to set for the two least significant bits. Notice the "inverse" connection between the "down-counting" binary patterns and the rising VIC bank memory addresses; this is caused by the inverters between the CIA port and the memory management mechanishm controlling the VIC-II.

ROM charset shadows[edit]

In two of the four VIC banks (banks no. 2 and 0 in the table), the ROM character set is "mapped into" the bank, so that the two standard character sets are directly available to the VIC (not the CPU), thus freeing the programmer from having to assign space for a character set in RAM. The disadvantage is that these "shadow images" of the ROM character sets take up space that would otherwise be vacant for custom character sets, sprite data, or other graphics: Banks 2 and 0 has room for either 192 sprite shapes, 12 text screens, or 6 custom character sets, whereas the same figures for banks 3 and 1 are 256 sprite shapes, 16 text screens or 8 character sets. Furthermore, of the two high-res graphics screens available in each bank, the lower half of one high-res screen is "scarred" by a band of text characters in banks 2 and 0.

Example[edit]

This example configures (lines 10 and 20) the VIC-II to use bank 2; the one at 32768–49151/$8000–$BFFF, and to use the charset shadow image present in this bank at 36864–40959;/$9000–$9FFF, along with the area 32768–33767/$8000–$83E7 for the character code RAM (line 30). Finally (in line 40), the KERNAL is told to use the "new" text screen location:

10 poke 56578,peek(56578) or 3
20 poke 56576,(peek(56576)and 252) or 1
30 poke 53272,4
40 poke 648,128

After RUNning this short program, you'll see a "garbled" screen full of random characters (usually a lot of @'s and checkerboard pattern), but with the familiar READY. prompt and cursor amidst the "mess": Since the KERNAL has been "notified" of the change, you may clear the screen, LIST and edit the program etc. as usual. The difference only "shows" when it comes to directly POKE'ing characters onto the screen: If you

poke 1024,42

after having the previous example reconfigure the VIC bank and screen setup, you will not get an asterisk at the upper left-hand corner of the screen, but with

poke 32768,42

you will, because this (32768) is the current start address for the text screen.

Further configuration[edit]

For further information on how to configure VIC-II "inside" one VIC-bank, see