Init code

From SNESdev Wiki
Revision as of 06:27, 12 May 2022 by Undisbeliever (talk | contribs) (Add list of registers to reset)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigationJump to search

Reset Registers Routine

As the console lacks a boot ROM and most of the PPU registers start in an unknown state, the programmer will need to create a Reset Registers routine. This routine should be separate from the Reset Handler code to allow the programmer to reset the PPU registers to a known good state at the start of every level or scene.


The first registers to reset should be the NMITIMEN and HDMAEN registers. This will prevent Interrupts or HDMA from erroneously changing the PPU registers in the middle of the routine.


The following is a recommended list of registers to reset along with the values to reset them to.

Must reset first
    NMITIMEN    $4200 = 0       (disable Interrupts)
    HDMAEN      $420C = 0       (disable HDMA)

    INIDISP     $2100 = $8F     (enable Force Blank, full brightness)


CPU registers
    MEMSEL      $420D = 0       (set to 1 if FastROM)

    WRIO        $4201 = $FF


Objects
    OBSEL       $2101 = 0

    OAMADDL     $2102 = 0
    OAMADDH     $2103 = 0       (disable OAM priority rotation)


Backgrounds
    BGMODE      $2105 = 0
    MOSAIC      $2106 = 0

    BG1SC       $2107 = 0
    BG2SC       $2108 = 0
    BG3SC       $2109 = 0
    BG4SC       $210A = 0

    BG12NBA     $210B = 0
    BG34NBA     $210C = 0


Scroll Registers
    BG1HOFS     $210D = 0
    BG1HOFS     $210D = 0       (set horizontal offset to 0)

    BG1VOFS     $210E = $FF
    BG1VOFS     $210E = $FF     (set vertical offset to -1)

    BG2HOFS     $210F = 0
    BG2HOFS     $210F = 0

    BG2VOFS     $2110 = $FF
    BG2VOFS     $2110 = $FF

    BG3HOFS     $2111 = 0
    BG3HOFS     $2111 = 0

    BG3VOFS     $2112 = $FF
    BG3VOFS     $2112 = $FF

    BG4HOFS     $2113 = 0
    BG4HOFS     $2113 = 0

    BG4VOFS     $2114 = $FF
    BG4VOFS     $2114 = $FF


VRAM Registers
    VMAIN       $2115 = $80     (VRAM word access, increment by 1, no remapping)


Mode 7
    M7SEL       $211A = 0       (no flipping or screen repeat)

    M7A         $211B = 0
    M7A         $211B = $01

    M7B         $211C = 0
    M7B         $211C = 0

    M7C         $211D = 0
    M7C         $211D = 0

    M7D         $211E = 0
    M7D         $211E = $01

    M7X         $211F = 0
    M7X         $211F = 0

    M7Y         $2120 = 0
    M7Y         $2120 = 0



Windows
    W12SEL      $2123 = 0
    W34SEL      $2124 = 0
    WOBJSEL     $2125 = 0
    WH0         $2126 = 0
    WH1         $2127 = 0
    WH3         $2128 = 0
    WH4         $2129 = 0
    WBGLOG      $212A = 0
    WOBJLOG     $212B = 0


Layer Enable
    TM          $212C = 0
    TS          $212D = 0
    TMW         $212E = 0
    TSW         $212F = 0


Color Math
    CGWSEL      $2130 = $30     (Color math disable region = everywhere)
    CGADSUB     $2131 = 0
    COLDATA     $2132 = $E0     (set Fixed color data to black)


Misc
    SETINI      $2133 = 0