User:Banshaku/CA65 Constants
From NESdev Wiki
Jump to navigationJump to search
; NES registers: PPU releated ;-------------------------------------------------------- ; PPU Controler (write) ; Various flags controlling PPU operation ; ;Input: ;======== ;76543210 ;|||||||| ;||||||++- Base nametable address ;|||||| (0 = $2000; 1 = $2400; 2 = $2800; 3 = $2C00) ;|||||+--- VRAM address increment per CPU read/write of PPUDATA ;||||| (0: increment by 1, going across; 1: increment by 32, going down) ;||||+---- Sprite pattern table address for 8x8 sprites (0: $0000; 1: $1000) ;|||+----- Background pattern table address (0: $0000; 1: $1000) ;||+------ Sprite size (0: 8x8; 1: 8x16) ;|+------- PPU master/slave select (has no effect on the NES) ;+-------- Generate an NMI at the start of the vertical blanking interval (0: off; 1: on) ;-------------------------------------------------------- PPU_CTRL = $2000 ; Flags for PPU PPU_CTRL_ADR_NT0 = %00000000 ; Select name table 0 PPU_CTRL_ADR_NT1 = %00000001 ; Select name table 1 PPU_CTRL_ADR_NT2 = %00000010 ; Select name table 2 PPU_CTRL_ADR_NT3 = %00000011 ; Select name table 3 PPU_CTRL_INC32 = %00000100 ; Increment PPU address by 32 bytes, going down PPU_CTRL_SPR_PT1 = %00001000 ; Sprite pattern table 1 PPU_CTRL_BG_PT1 = %00010000 ; Background pattern table 1 PPU_CTRL_SPR_8x16 = %00100000 ; Sprites are 8x16 PPU_CTRL_NMI = %10000000 ; write this value to PPUCTRL to enable NMI ;-------------------------------------------------------- ; PPU Mask (write) ; Screen enable, masking, and intensity ; ;Input: ;======== ;76543210 ;|||||||| ;|||||||+- Grayscale (0: normal color; 1: AND all palette entries ;||||||| with 0x30, effectively producing a monochrome display; ;||||||| note that colour emphasis STILL works when this is on!) ;||||||+-- Enable background in leftmost 8 pixels of screen (0: clip; 1: display) ;|||||+--- Enable sprite in leftmost 8 pixels of screen (0: clip; 1: display) ;||||+---- Enable background rendering ;|||+----- Enable sprite rendering ;||+------ Intensify reds (and darken other colors) ;|+------- Intensify greens (and darken other colors) ;+-------- Intensify blues (and darken other colors) ;-------------------------------------------------------- PPU_MASK = $2001 PPU_MASK_GREYSCALE = %00000001 ; All colors becomes grey scales PPU_MASK_BG_NOCLIP = %00000010 ; enables background no clip PPU_MASK_SPR_NOCLIP = %00000100 ; enables sprite no clip PPU_MASK_BG_ON = %00001000 ; enables background rendering PPU_MASK_SPR_ON = %00010000 ; enables sprite rendering PPU_MASK_INT_RED = %00100000 ; Intensify red PPU_MASK_INT_GREEN = %01000000 ; Intensify green PPU_MASK_INT_BLUE = %10000000 ; Intensify blue ;-------------------------------------------------------- ; PPU status (read) ; ; ; Caution: Reading PPUSTATUS at the exact start of vertical blank will return a 0 ; in D7 but clear the latch anyway, causing the program to miss frames. See ; NMI for details. ; ;output: ;======== ;76543210 ;|||||||| ;|||+++++- Unimplemented ;||+------ Sprite overflow. The PPU can handle only eight sprites on one ;|| scanline and sets this bit if it starts dropping sprites. ;|| Normally, this triggers when there are 9 sprites on a scanline, ;|| but the actual behavior is significantly more complicated. ;|+------- Sprite 0 Hit. Set when a nonzero pixel of sprite 0 'hits' ;| a nonzero background pixel. Used for raster timing. ;+-------- Vertical blank has started (0: not in VBLANK; 1: in VBLANK) ;-------------------------------------------------------- PPU_STATUS = $2002 ; Can be read to get current PPU status PPU_STATUS_SPR_OVERFLOW = %00100000 ; More than 8 sprites per scanline PPU_STATUS_SPRITE0 = %01000000 ; Sprite 0 was hit PPU_STATUS_IN_VBLANK = %10000000 ; The vlbank as started ;-------------------------------------------------------- ; OAM address (write) ; ; Write the address of OAM you want to access here. Most games just ; write $00 here and then use OAM_DMA ($4014). ; ; This register also seems to affect Sprite 0 Hit, though it is not ; yet understood exactly how it does. The upper 5 bits of this register ; seem to select which SPR-RAM data is used for sprites 0 and 1 (instead ; of the first 8 bytes of SPR-RAM), though actual behavior varies between resets. ;-------------------------------------------------------- PPU_OAM_ADDR = $2003 ; OAM address. Rarerly used (why?) ;-------------------------------------------------------- ; OAM data port (r/w) ; ; Write OAM data here. Writes will increment OAMADDR; reads won't. ; ; Most games access this register through $4014 instead. Reading ; OAMDATA while the PPU is rendering will expose internal OAM accesses ; during sprite evaluation and loading; Micro Machines does this. ;-------------------------------------------------------- PPU_OAM_DATA = $2004 ; OAM data port ;-------------------------------------------------------- ; Scroll register (2x write) ; ; After reading PPUSTATUS to reset the address latch, write the horizontal ; and vertical scroll offsets here just before turning on the screen: ; ; Example: ; bit PPUSTATUS ; ; possibly other code goes here ; lda cam_position_x ; sta PPUSCROLL ; lda cam_position_y ; sta PPUSCROLL ; ; Horizontal offsets range from 0 to 255. "Normal" vertical offsets range from ; 0 to 239. (Values of 240 to 255 are treated as -16 through -1 in a way, pulling ; tile data from the attribute table.) ;-------------------------------------------------------- PPU_SCROLL = $2005 ; Sets X/Y scrolling of background ;-------------------------------------------------------- ; VRAM address register (2x write) ; ; After reading PPUSTATUS to reset the address latch, write the ; 16-bit address of VRAM you want to access here, upper byte first. ; Valid addresses are $0000-$3FFF. ; ; Access to PPUSCROLL and PPUADDR during screen refresh produces ; interesting raster effects; the starting position of each scanline ; can be set to any pixel position in nametable memory. For more information, ; see "The Skinny on NES Scrolling" by loopy, available from the main site. ;-------------------------------------------------------- PPU_ADDR = $2006 ; Sets VRAM address in PPU ;-------------------------------------------------------- ; VRAM data register (r/w) ; ; When the screen is turned off in PPUMASK or during vertical blank, ; read or write data from VRAM through this port. ; ; Reads are delayed by one cycle; discard the first byte read. Do not ; attempt to access this register while the PPU is rendering; if you do, ; Bad Things^(TM) will happen (i.e. graphical glitches and RAM corruption). ;-------------------------------------------------------- PPU_DATA = $2007 ; Writes data to current VRAM address ;-------------------------------------------------------- ; MMC3 registers ; ; No doc yet, must check wiki ;-------------------------------------------------------- MMC3_CTRL = $8000 MMC3_PAGE = $8001 MMC3_MIRROR = $A000 MMC3_SRAM = $A001 MMC3_IRQ_COUNTER = $C000 MMC3_IRQ_RELOAD = $C001 MMC3_IRQ_DISABLE = $E000 MMC3_IRQ_ENABLE = $E001 MMC3_MIRROR_V = 0 MMC3_MIRROR_H = 1 MMC3_SRAM_DISABLE = 0 MMC3_SRAM_ENABLE = 1 ;------------------------ ; Common memory addresses OAM = $0400 ; Sprite DMA SPR_DMA = $4014 ; Joypads related JOYPAD_PORT1 = $4016 JOYPAD_PORT2 = $4017 BTN_A = %10000000 BTN_B = %01000000 BTN_SELECT = %00100000 BTN_START = %00010000 BTN_UP = %00001000 BTN_DOWN = %00000100 BTN_LEFT = %00000010 BTN_RIGHT = %00000001 ; Sound related APU_REGISTER = $4000 APU_SQUARE1 = $4000 APU_SQUARE2 = $4004 APU_TRIANGLE = $4008 APU_NOISE = $400C APU_DELTA = $4010 APU_MASTERCTRL = $4015 APU_FRAMECOUNTER = $4017 ; Note: same as joy 2 ; flags APU_FRAMECOUNTER_IRQ_CLEAR = %01000000 ;-------------------------------------------------------- ; Sprites attributes: ;76543210 ;|||||||| ;||||||++- Palette (4 to 7) of sprite ;|||+++--- Unimplemented, reads back as 0 ;||+------ Priority (0: in front of background; 1: behind background) ;|+------- Flip sprite horizontally ;+-------- Flip sprite vertically ;-------------------------------------------------------- SPR_PRIORITY_BACK = %00100000 ; The sprite priority is behind background SPR_PRIORITY_FRONT = %00000000 ; The sprite priority is in front of background SPR_FLIP_HORIZONTAL = %01000000 ; The sprite is flipped horizontally SPR_FLIP_VERTIAL = %10000000 ; The sprite is flipped vertically