MMIO registers: Difference between revisions

From SNESdev Wiki
Jump to navigationJump to search
(Adds joypad registers.)
(More precision regarding joypad bits.)
Line 117: Line 117:
  7  bit  0
  7  bit  0
  ---- ----
  ---- ----
  .... ...D
  .... .210
        |
      |||
        +- Joypad data output (latch)
      ||+- OUT0
      ++-- OUT2-1 (not connected)
 
OUT0 is used by standard controllers to latch the current button state. OUT2-1 are not connected in standard consoles, but may be used in the [[Super Famicom Box]] hotel system.


{{Anchor|JOYSER0}}
{{Anchor|JOYSER0}}
Line 127: Line 130:
  xxxx xxDD
  xxxx xxDD
  |||| ||||
  |||| ||||
  |||| ||++- Joypad 1 data 2-1
  |||| ||++- Joypad port 1 data 2-1
  ++++-++--- (Open bus)
  ++++-++--- (Open bus)


Line 138: Line 141:
  xxx1 11DD
  xxx1 11DD
  |||| ||||
  |||| ||||
  |||| ||++- Joypad 2 data 2-1
  |||| ||++- Joypad port 2 data 2-1
  |||+-++--- (Always 1)
  |||+-++--- Joypad 2 D4-2 (always 1)
  +++------- (Open bus)
  +++------- (Open bus)


Reading JOYSER1 clocks port 2.
Reading JOYSER1 clocks port 2.
The CPU has 5 joypad 2 inputs. Joypad port 2's data 2 and 1 pins connect to D1-0, while D4-2 are tied to ground (and thus read as 1).


===Joypad I/O interface===
===Joypad I/O interface===
Line 152: Line 157:
  21DD DDDD
  21DD DDDD
  |||| ||||
  |||| ||||
  ||++-++++- SFC/SNES: Not connected
  ||++-++++- CPU I/O D5-0 (not connected)
||        Super Famicom Box: HD64180 I/O D5-0
  |+-------- Joypad port 1 I/O
  |+-------- Joypad port 1 I/O
  +--------- Joypad port 2 I/O and
  +--------- Joypad port 2 I/O and
Line 164: Line 168:
  21DD DDDD
  21DD DDDD
  |||| ||||
  |||| ||||
  ||++-++++- SFC/SNES: Not connected
  ||++-++++- CPU I/O D5-0 (not connected)
||        Super Famicom Box: HD64180 I/O D5-0
  |+-------- Joypad port 1 I/O
  |+-------- Joypad port 1 I/O
  +--------- Joypad port 2 I/O
  +--------- Joypad port 2 I/O
Line 171: Line 174:
The I/O pins allow bidirectional communication between the CPU and joypads on a single wire per bit. Either side is able to set the bits to 0, so to read the value being sent by the other side, the reader must set its own corresponding bits to 1 before reading.
The I/O pins allow bidirectional communication between the CPU and joypads on a single wire per bit. Either side is able to set the bits to 0, so to read the value being sent by the other side, the reader must set its own corresponding bits to 1 before reading.


The not-connected bits can be used as general-purpose storage on standard consoles, but are used in the Super Famicom Box hotel system to communicate with its HD64180 CPU.
The not-connected D5-0 bits can be used as general-purpose storage on standard consoles, but are used in the [[Super Famicom Box]] hotel system to communicate with its HD64180 CPU.


Joypad port 2's I/O bit is also connected to the PPU's /EXTLATCH input, allowing the PPU's H and V counters to be latched when this bit is set to 0 by the CPU or joypad. This is intended to support a light pen or gun device. This should normally be set to 1 by the CPU to allow the counters to be latched. (See [[PPU_registers#OPHCT|PPU registers]])
Joypad port 2's I/O bit is also connected to the PPU's /EXTLATCH input, allowing the PPU's H and V counters to be latched when this bit is set to 0 by the CPU or joypad. This is intended to support a light pen or gun device. This should normally be set to 1 by the CPU to allow the counters to be latched. (See [[PPU_registers#OPHCT|PPU registers]])
Line 178: Line 181:
----
----
{{Anchor|JOY1}}
{{Anchor|JOY1}}
====JOY1L, JOY1H - Joypad 1 data 1 ($4218, $4219 read)====
====JOY1L, JOY1H - Joypad port 1 data 1 ($4218, $4219 read)====
   JOY1H      JOY1L
   JOY1H      JOY1L
   $4219      $4218
   $4219      $4218
Line 185: Line 188:
  DDDD DDDD  DDDD DDDD
  DDDD DDDD  DDDD DDDD
  |||| ||||  |||| ||||
  |||| ||||  |||| ||||
  ++++-++++---++++-++++- Joypad 1 data 1 (first read on left to last read on right)
  ++++-++++---++++-++++- Joypad port 1 data 1 (first read on left to last read on right)


{{Anchor|JOY2}}
{{Anchor|JOY2}}
====JOY2L, JOY2H - Joypad 2 data 1 ($421A, $421B read)====
====JOY2L, JOY2H - Joypad port 2 data 1 ($421A, $421B read)====
   JOY2H      JOY2L
   JOY2H      JOY2L
   $421B      $421A
   $421B      $421A
Line 195: Line 198:
  DDDD DDDD  DDDD DDDD
  DDDD DDDD  DDDD DDDD
  |||| ||||  |||| ||||
  |||| ||||  |||| ||||
  ++++-++++---++++-++++- Joypad 2 data 1 (first read on left to last read on right)
  ++++-++++---++++-++++- Joypad port 2 data 1 (first read on left to last read on right)


{{Anchor|JOY3}}
{{Anchor|JOY3}}
====JOY3L, JOY3H - Joypad 1 data 2 ($421C, $421D read)====
====JOY3L, JOY3H - Joypad port 1 data 2 ($421C, $421D read)====
   JOY3H      JOY3L
   JOY3H      JOY3L
   $421D      $421C
   $421D      $421C
Line 205: Line 208:
  DDDD DDDD  DDDD DDDD
  DDDD DDDD  DDDD DDDD
  |||| ||||  |||| ||||
  |||| ||||  |||| ||||
  ++++-++++---++++-++++- Joypad 1 data 2 (first read on left to last read on right)
  ++++-++++---++++-++++- Joypad port 1 data 2 (first read on left to last read on right)


{{Anchor|JOY4}}
{{Anchor|JOY4}}
====JOY4L, JOY4H - Joypad 2 data 2 ($421E, $421F read)====
====JOY4L, JOY4H - Joypad port 2 data 2 ($421E, $421F read)====
   JOY4H      JOY4L
   JOY4H      JOY4L
   $421F      $421E
   $421F      $421E
Line 215: Line 218:
  DDDD DDDD  DDDD DDDD
  DDDD DDDD  DDDD DDDD
  |||| ||||  |||| ||||
  |||| ||||  |||| ||||
  ++++-++++---++++-++++- Joypad 2 data 2 (first read on left to last read on right)
  ++++-++++---++++-++++- Joypad port 2 data 2 (first read on left to last read on right)


Auto-read runs at the beginning of vblank and is equivalent to writing 1 and then 0 to JOYOUT (to latch a standard controller) and then reading JOYSER0 and JOYSER1 16 times each. The controllers are then left in this state so that additional reads can be done manually from JOYSER0 and JOYSER1 to get any additional data, though this is unnecessary for standard controllers. Auto-read takes approximately 3 scanlines, during which the JOYOUT, JOYSER0, and JOYSER1 registers should not be manually accessed.
Auto-read runs at the beginning of vblank and is equivalent to writing 1 and then 0 to JOYOUT (to latch a standard controller) and then reading JOYSER0 and JOYSER1 16 times each. The controllers are then left in this state so that additional reads can be done manually from JOYSER0 and JOYSER1 to get any additional data, though this is unnecessary for standard controllers. Auto-read takes approximately 3 scanlines, during which the JOYOUT, JOYSER0, and JOYSER1 registers should not be manually accessed.

Revision as of 18:23, 22 May 2022

TODO

  • $2100-213F PPU registers
  • $2140-2413 APUIO
  • $2180 WMDATA
  • $2181-2183 WMADD
  • $4016 Legacy Gamepad 1
  • $4017 Legacy Gamepad 2
  • $4200 NMITIMEN
  • $4201 WRIO
  • $4202-4203 WRMPY
  • $4204-4206 WRDIV
  • $4207-4208 HTIME
  • $4209-420A VTIME
  • $420B MDMAEN
  • $420C HDMAEN
  • $420D MEMSEL
  • $420E-420F ?
  • $4210 RDNMI
  • $4211 TIMEUP
  • $4212 HVBJOY
  • $4213 RDIO
  • $4214-4215 RDDIV
  • $4216-4217 RDMPY
  • $4218-421F STD CNTRL1-4
  • $4300-437F DMA registers

Interrupts

NMITIMEN - Interrupts and Joypad reading ($4200 write)


7  bit  0
---- ----
N.VH ...J
| ||    |
| ||    +- Joypad auto-read enable
| ++------ H/V timer IRQ:
|           00 = Disable timer
|           01 = IRQ when H counter == HTIME
|           10 = IRQ when V counter == VTIME and H counter == 0
|           11 = IRQ when V counter == VTIME and H counter == HTIME
+--------- Vblank NMI enable

TODO: Details on the exact conditions for an NMI or IRQ.

Screen timer values


HTIMEL, HTIMEH - H timer target ($4207, $4208 write)

  HTIMEH      HTIMEL
  $4208       $4207
7  bit  0   7  bit  0
---- ----   ---- ----
.... ...H   HHHH HHHH
        |   |||| ||||
        +---++++-++++- H counter target for timer IRQ

Note that setting a value larger than the maximum H counter value of 339 will prevent the timer's H condition from being met.

VTIMEL, VTIMEH - V timer target ($4209, $420A write)

  VTIMEH      VTIMEL
  $420A       $4209
7  bit  0   7  bit  0
---- ----   ---- ----
.... ...V   VVVV VVVV
        |   |||| ||||
        +---++++-++++- V counter target for timer IRQ

Note that setting a value larger than the maximum V counter value will prevent the timer's V condition from being met. The maximum depends on the region (261 for NTSC, 311 for PAL) and interlacing (1 additional scanline every other frame).

Status


RDNMI - Vblank flag and CPU version ($4210 read)

7  bit  0
---- ----
Nxxx VVVV
|||| ||||
|||| ++++- CPU version
|+++------ (Open bus)
+--------- Vblank flag

On read: RDNMI D7 = 0

The vblank flag is set at the start of vblank and cleared at the end of vblank or on read.

TIMEUP - Timer flag ($4211 read)

7  bit  0
---- ----
Txxx xxxx
|||| ||||
|+++-++++- (Open bus)
+--------- Timer flag

On read: TIMEUP D7 = 0

The timer flag is set when the timer condition specified in NMITIMEN becomes true and is cleared on read.

HVBJOY - Screen and Joypad status ($4212 read)

7  bit  0
---- ----
VHxx xxxJ
|||| ||||
|||| |||+- Joypad auto-read in-progress flag
||++-+++-- (Open bus)
|+-------- Hblank flag
+--------- Vblank flag

Joypads

Joypad legacy interface


JOYOUT - Joypad output ($4016 write)

7  bit  0
---- ----
.... .210
      |||
      ||+- OUT0
      ++-- OUT2-1 (not connected)

OUT0 is used by standard controllers to latch the current button state. OUT2-1 are not connected in standard consoles, but may be used in the Super Famicom Box hotel system.

JOYSER0 - Joypad serial data port 1 ($4016 read)

7  bit  0
---- ----
xxxx xxDD
|||| ||||
|||| ||++- Joypad port 1 data 2-1
++++-++--- (Open bus)

Reading JOYSER0 clocks port 1.

JOYSER1 - Joypad serial data port 2 ($4017 read)

7  bit  0
---- ----
xxx1 11DD
|||| ||||
|||| ||++- Joypad port 2 data 2-1
|||+-++--- Joypad 2 D4-2 (always 1)
+++------- (Open bus)

Reading JOYSER1 clocks port 2.

The CPU has 5 joypad 2 inputs. Joypad port 2's data 2 and 1 pins connect to D1-0, while D4-2 are tied to ground (and thus read as 1).

Joypad I/O interface


WRIO - Write I/O ($4201 write)

7  bit  0
---- ----
21DD DDDD
|||| ||||
||++-++++- CPU I/O D5-0 (not connected)
|+-------- Joypad port 1 I/O
+--------- Joypad port 2 I/O and
           PPU /EXTLATCH light pen input

RDIO - Read I/O ($4213 read)

7  bit  0
---- ----
21DD DDDD
|||| ||||
||++-++++- CPU I/O D5-0 (not connected)
|+-------- Joypad port 1 I/O
+--------- Joypad port 2 I/O

The I/O pins allow bidirectional communication between the CPU and joypads on a single wire per bit. Either side is able to set the bits to 0, so to read the value being sent by the other side, the reader must set its own corresponding bits to 1 before reading.

The not-connected D5-0 bits can be used as general-purpose storage on standard consoles, but are used in the Super Famicom Box hotel system to communicate with its HD64180 CPU.

Joypad port 2's I/O bit is also connected to the PPU's /EXTLATCH input, allowing the PPU's H and V counters to be latched when this bit is set to 0 by the CPU or joypad. This is intended to support a light pen or gun device. This should normally be set to 1 by the CPU to allow the counters to be latched. (See PPU registers)

Auto-read results


JOY1L, JOY1H - Joypad port 1 data 1 ($4218, $4219 read)

  JOY1H       JOY1L
  $4219       $4218
7  bit  0   7  bit  0
---- ----   ---- ----
DDDD DDDD   DDDD DDDD
|||| ||||   |||| ||||
++++-++++---++++-++++- Joypad port 1 data 1 (first read on left to last read on right)

JOY2L, JOY2H - Joypad port 2 data 1 ($421A, $421B read)

  JOY2H       JOY2L
  $421B       $421A
7  bit  0   7  bit  0
---- ----   ---- ----
DDDD DDDD   DDDD DDDD
|||| ||||   |||| ||||
++++-++++---++++-++++- Joypad port 2 data 1 (first read on left to last read on right)

JOY3L, JOY3H - Joypad port 1 data 2 ($421C, $421D read)

  JOY3H       JOY3L
  $421D       $421C
7  bit  0   7  bit  0
---- ----   ---- ----
DDDD DDDD   DDDD DDDD
|||| ||||   |||| ||||
++++-++++---++++-++++- Joypad port 1 data 2 (first read on left to last read on right)

JOY4L, JOY4H - Joypad port 2 data 2 ($421E, $421F read)

  JOY4H       JOY4L
  $421F       $421E
7  bit  0   7  bit  0
---- ----   ---- ----
DDDD DDDD   DDDD DDDD
|||| ||||   |||| ||||
++++-++++---++++-++++- Joypad port 2 data 2 (first read on left to last read on right)

Auto-read runs at the beginning of vblank and is equivalent to writing 1 and then 0 to JOYOUT (to latch a standard controller) and then reading JOYSER0 and JOYSER1 16 times each. The controllers are then left in this state so that additional reads can be done manually from JOYSER0 and JOYSER1 to get any additional data, though this is unnecessary for standard controllers. Auto-read takes approximately 3 scanlines, during which the JOYOUT, JOYSER0, and JOYSER1 registers should not be manually accessed.