From da806439a5852c7970334e28a78170a9a3442507 Mon Sep 17 00:00:00 2001 From: greg Date: Wed, 7 Dec 2016 01:13:29 -0800 Subject: [PATCH] SUCCESS! Have successfully written a background tile to screen! --- my_custom.asm | 7 ++++- register_notes | 2 +- test_gfx.asm | 70 +++++++++++++++++++++++++++++++++++++++++++------- 3 files changed, 68 insertions(+), 11 deletions(-) diff --git a/my_custom.asm b/my_custom.asm index 1c8da29..ac2a7b9 100644 --- a/my_custom.asm +++ b/my_custom.asm @@ -21,6 +21,11 @@ lvl3\@: bne lvl3\@ .ENDM +.MACRO Set_A_8_XY_16 +; 16-bit xy, 8-bit a +rep #%00010000 +sep #%00100000 +.ENDM .MACRO Reset_Palette_Offset stz $2121 @@ -37,6 +42,6 @@ sta $2122 .MACRO Set_Screen_Brightness lda #\1 -sta $2100 +sta $2100 ; $2100 is the screen brightness register .ENDM diff --git a/register_notes b/register_notes index 4c8273e..c356505 100644 --- a/register_notes +++ b/register_notes @@ -4,10 +4,10 @@ $2100 - screen on/off + brightness $2105 - screen format register, changes size of tiles +$2107 - set starting tilemap location $2121 - stores the index into CGRAM to write a color value via $2122 - $2122 - write a 2-byte SNES color value to the CGRAM. this auto-increments after writing, which is why $2121 needs to be written to reset this. it's common to write `stz $2121` diff --git a/test_gfx.asm b/test_gfx.asm index 314cbf6..5d6286e 100644 --- a/test_gfx.asm +++ b/test_gfx.asm @@ -15,26 +15,74 @@ VBlank: .ORG 0 .section "Main" +.MACRO Video_Port_Control + ;VRAM transfer, word-access, increment by 1 + lda #%10000000 + sta $2115 +.ENDM + +;assumes 8-bit a, 16-bit xy +.MACRO Load_Block_to_VRAM ARGS SOURCE DEST SIZE + Video_Port_Control + + ldx #DEST + stx $2116 ; $2116/2117 is 2byte address for VRAM upload/download. most significant bit must be 0 + + lda #:SOURCE ; source bank + ldx #SOURCE ; source offset + ldy #SIZE + + stx $4302 ; store data offset into DMA control register + sta $4304 ; store bank into DMA source bank + sty $4305 ; store size of block + + lda #$01 + sta $4300 ; set DMA mode (word, normal increment) + + lda #$18 + sta $4301 ; set destination register (VRAM write register) - add value to $2100 to get destination address + ; i.e. this is writing to $2118, which when written writes a byte to VRAM + + lda #$01 + sta $420b ; and start the transfer +.ENDM + Start: Snes_Init -; 16-bit xy, 8-bit a -rep #%00010000 -sep #%00100000 - -; Load palette by writing to $2122 -; .db $00, $00, $E0, $7F, $1F, $00, $FF, $03 + Set_A_8_XY_16 Load_Palette_Color $00, $00 Load_Palette_Color $00, $00 Load_Palette_Color $00, $00 Load_Palette_Color $ff, $0a -;lda #%00000 - - Set_Screen_Brightness %00001111 + lda #%00000000 ; 8x8 for all 4 backgrounds, no priority flip, Mode: 4 colors/tile w/ 32 palettes + sta $2105 ; store to screen mode register + + ; size (last argument) depends on color mode + ; location is beginning of VRAM + Load_Block_to_VRAM Face, $0000, (8*2*2), + + ; put character data at VRAM $0000, tile data at $0400 + lda #$04 + sta $2107 ; BG1 tile map location (upper 6 bits) + lda #$00 + sta $210b ; BG1 character location ($1000 word intervals - can't go over $8000 b/c size of VRAM) + + ; main screen designation + lda #%00000001 + sta $212c ; enable bkg 1, + + ldx #$0400 ; load $0400 (VRAM address of tile data) + stx $2116 ; and store it to VRAM address word-sized register + + ldx #$0001 + stx $2118 ;store tile map entry to the address specified in $2116 - this eincrements or not based on 2105 + + lda #%10000001 ; enable NMI and joypads sta $4200 @@ -65,6 +113,10 @@ mainloop: .section "TileData" Face: + + .db $00, $00, $00, $00, $00, $00, $00, $00 + .db $00, $00, $00, $00, $00, $00, $00, $00 + .db %00000000 .db %00000000