User Tools

Site Tools


base:memory_management

Without Cartridges

The low 3 bits of $01 control the mapping of specific regions of memory. When a bit is set to 0, it activates its bank, but the interplay between them is kind of fiddly:

Name Bit Region 0 1 Notes
LORAM0$A000-BFFFRAMBASICIf KERNAL isn't mapped in, then BASIC won't map in either and this region stays mapped to RAM.
HIRAM1$E000-FFFFRAMKERNAL
CHAREN2$D000-DFFFCHARROMI/OIf HIRAM and LORAM are both set to 0, then this bit is ignored and the area also maps to RAM. This allows for 3 mappings of this region: RAM, CHARROM, or I/O.
  • All other memory locations ($0002-9FFF, $C000-CFFF) always map to RAM.
  • Writes to a ROM-mapped region are applied to the underlying RAM at the same address.
  • I/O includes the registers for the VIC-II, SID, and CIA chips; color RAM; and two external I/O pages that reach out the expansion port.
  • The VIC-II always sees the CHARROM at $1000-1FFF and $9000-9FFF, and RAM everywhere else, regardless of these bits.

The mappings from combining these 3 bits are listed below. Higher bits of location $01 are used for other purposes and default to %00110xxx.

$01 value $A000-BFFF $D000-DFFF $E000-FFFF Notes
$30 +48 %000 RAM RAM RAM
$31 +49 %001 RAM CHARROM RAM
$32 +50 %010 RAM CHARROM KERNAL
$33 +51 %011 BASIC CHARROM KERNAL
$34 +52 %100 RAM RAM RAM
$35 +53 %101 RAM I/O RAM
$36 +54 %110 RAM I/O KERNAL
$37 +55 %111 BASIC I/O KERNALDefault

*WARNING*: Don't use INC $01 to switch modes from %111 to %000, as that will turn on the tape write head on the next bit up and do bad/unintentional things if there's stuff attached to the tape port.

With Cartridges

The expansion port has 2 configuration inputs (/EXROM and /GAME), and 4 chip select outputs (/IO1, /IO2, /ROML, /ROMH).

/IO1 and /IO2 lines are active on both reads & writes to their respective memory ranges, any time that I/O is banked in:

  • /IO1 = $DE00 - $DEFF
  • /IO2 = $DF00 - $DFFF

/ROML and /ROMH are active on reads depending on how the cartridge sets the configuration inputs. Normally, ROML sits right before the BASIC ROM at $8000-9FFF, while ROMH replaces BASIC itself. Writes to these areas still go to internal RAM and do not activate the external chip select lines. Ultimax mode has ROMH replacing the KERNAL and unmaps a lot of the internal RAM.

Cart pulls /EXROM low

The simplest C64-mode cartridge configuration, only using ROML. Any time the BASIC ROM is visible in at $A000, ROML is also visible in the 8kB before it.

$01 value $8000-9FFF $A000-BFFF $D000-DFFF $E000-FFFF Notes
$30 +48 %000 RAM RAM RAM RAM
$31 +49 %001 RAM RAM CHARROM RAM
$32 +50 %010 RAM RAM CHARROM KERNAL
$33 +51 %011 ROML BASIC CHARROM KERNAL
$34 +52 %100 RAM RAM RAM RAM
$35 +53 %101 RAM RAM I/O RAM
$36 +54 %110 RAM RAM I/O KERNAL
$37 +55 %111 ROML BASIC I/O KERNALDefault

Cart pulls /EXROM + /GAME low

ROML is before BASIC, and is swapped out with the LORAM bit in $01. ROMH replaces BASIC, and HIRAM swaps out both it and the KERNAL. There is no KERNAL-only mode in this configuration.

$01 value $8000-9FFF $A000-BFFF $D000-DFFF $E000-FFFF Notes
$30 +48 %000 RAM RAM RAM RAM
$31 +49 %001 RAM RAM CHARROM RAM
$32 +50 %010 RAM ROMH CHARROM KERNAL
$33 +51 %011 ROML ROMH CHARROM KERNAL
$34 +52 %100 RAM RAM RAM RAM
$35 +53 %101 RAM RAM I/O RAM
$36 +54 %110 RAM ROMH I/O KERNAL
$37 +55 %111 ROML ROMH I/O KERNALDefault

Cart pulls only /GAME low (Ultimax mode)

ROMH replaces the KERNAL at $E000, ROML is still at $8000. Only the lowest 4kB of internal RAM remains visible, and I/O cannot be swapped out. $00/01 are still used to drive the tape port, but the low 3 bits are ignored for banking in this mode.

$0002-0FFF $1000-7FFF $8000-9FFF $A000-CFFF $D000-DFFF $E000-FFFF
RAM unmapped ROML unmapped I/O ROMH

The VIC-II will also see the first 4kB of ROMH at $3000-3FFF in all of its 16kB banks, with no access to CHARROM.

- White Flame

Related: from Graham's page

In the C64/C128 series of computers, slightly modified versions of the 6502 were used. The modifications did not affect the functional part of the processor itself. Only a so-called processor port was added. This port, in combination with an external PLA, was used to map ROM and I/O areas into the 64KB RAM of the C64. Also, some bits of the port were used for the legendary Datasette.

The port can be accessed through memory adresses $0000 and $0001, while $0001 is the port itself, and $0000 is the data direction register for it.

Explanation for the bits of $0001:

7 - unused (Flash 8: 0=8MHz/1=1MHz)
6 - unused (C128: ASCII/DIN sense/switch (1=ASCII/0=DIN))
5 - Cassette motor control (0 = motor on)
4 - Cassette switch sense (0 = PLAY pressed)
3 - Cassette write line
2 - CHAREN (0=Character ROM instead of I/O area)
1 - HIRAM ($E000-$FFFF)
0 - LORAM ($A000-$BFFF)

If HIRAM or LORAM is set, the I/O area is mapped to $D000-$DFFF.

$0000 should always be set to $2F (%00101111)

Note to bit 6: This bit is used to select either the ASCII or the DIN character ROM of a C128. When data direction is set to INPUT, the charset is selected externally with the ASCII/DIN key.

base/memory_management.txt · Last modified: 2022-04-17 05:36 by white_flame