11

TL;DR: With what values are the I/O port registers (locations $00 and $01) on the 6510 initialised when it is powered on?

I'm writing a Commodore 64 emulation. The Commodore 64 uses a 6510 microprocessor which has an I/O port built in. The I/O port is accessed at locations $00 (data direction) and $01 (data). I found lots of documents explaining how the thing works, but nothing so far on how it is initialised.

The I/O port is the main means of controlling the RAM bank switching, so how it is initialised is critical. For example, if bit 1 of the data direction register is 1 (for output), the ROM between $E000 and $FFFF is controlled by bit 1 of the port (1 = ROM, 0 = RAM).

So on the Commodore 64, unless the data direction register is set for output and the I/O port bit 1 is set to 1, there is RAM at the top of the address map and crucially the reset and interrupt vectors are not accessible. However, the designers of the 6510 probably would not do this because they wouldn't have known what I/O devices are connected to the port.

The I/O port doesn't drive the RAM bank switching directly, but via a PLA so I'm guessing that the DDR and the port are initialised to 0 when the processor switches on and the PLA keeps the ROM selected until the C64 has set the direction and port data correctly. (Maybe there's some sort of tri-state thing going on with a pull up resistor or something.)

Is my assumption correct?

JeremyP
  • 11,631
  • 1
  • 37
  • 53

2 Answers2

16

Yes, your assumption is correct.

Like in any microcontroller design I know of, I/O lines with programmable direction are set to input on reset. The 6510 is no exception, its data direction register at address 0 is set to 0 on reset, all 6 I/O lines become inputs. The circuitry outside the processor includes a pullup resistor on the I/O lines controlling banking, so that they are in a known stable state even if the data direction is set to input.

4

yes ddr register is set to input on reset and because of the pullup lines for charen loram and hiram its a logical 1.

take a look at the Pitfall 2 cartdrige. it works with vice 3.1 but not in 3.2. The init value of the data port register was changed from 0x3f to zero between both versions.

whats happening in 3.2: the game changes ddr to output but not the data register at address 0x1. The cart sets a zero for game and exrom line. means all 5 pla pins become zero. that results in a ram only memory configuration. the game maps out by itself and can not write the data port anymore which results in an empty screen.

it seems the data register at address 0x1 is not inited with zeros OR a input direction overwrites the data register with the external value for the appropriate pins. in case of charen, loram and hiram with a one because of the pullup resistors.

EDIT: maybe a ddr change from input to ouput doesn't update the io lines with the current contents of the the data port register. by disabling this in vice the game works with zero initialized port register, because it writes the port register after it seted ddr to output.

PiCiJi
  • 41
  • 2