snes: use common DMA loading routines

This makes loading the compressed tilemaps a bit more streamlined.
This commit is contained in:
Vince Weaver 2013-01-22 17:40:04 -05:00
parent 011aeb54cc
commit 4941aa8cc9
6 changed files with 119 additions and 181 deletions

View File

@ -1,2 +1,2 @@
.word $5ea8 ; Complement of checksum
.word $a157 ; Unsigned 16-bit sum of ROM
.word $702f ; Complement of checksum
.word $8fd0 ; Unsigned 16-bit sum of ROM

Binary file not shown.

View File

@ -14,9 +14,49 @@ display_opening:
sep #$20 ; mem/A = 8 bit
.a8
;==========================
; Load Opening Screen Palette
;==========================
stz $2121 ; start with color 0
ldy #(128*2) ; we have 128 colors
lda #^vmw_logo_palette
ldx #.LOWORD(vmw_logo_palette)
jsr svmw_load_palette
;==========================
; Setup Backgrounds
; Load Opening Tile Data
;==========================
lda #$0000 ;
sta $2116 ; set adddress for VRAM read/write
; multiply by 2, so 0x0000
lda #^vmw_logo_tile_data
ldx #.LOWORD(vmw_logo_tile_data)
ldy #$12c0 ; Copy 75 tiles, which are 64 bytes each
; 8x8 tile with 8bpp (four bytess per pixel)
; (75*64) = 4800 = 0x12c0
jsr svmw_load_vram
;===================================
; Load Opening Tilemap
;===================================
; 6 down, 0 right = (6*32) = 96 = 0xc0
; 1111 0000 1100 0000
ldx #$78c0 ; we set tilemap to be at VRAM 0xf000 earlier
; f0c0
stx $2116
lda #^vmw_logo_tilemap
ldx #.LOWORD(vmw_logo_tilemap)
ldy #640 ; 32*10*2 = 640 tiles
jsr svmw_load_vram
; we want the BG1 Tilemap to start at VRAM $F000 (60k)
; Format is
@ -28,6 +68,7 @@ display_opening:
lda #$78 ; BG1 Tilemap starts at VRAM $F000
sta $2107 ; bg1 src
; we want the BG2 Tilemap to start at VRAM $F800
; Format is
; aaaa aass a is shifted by 10 for address
@ -50,58 +91,6 @@ display_opening:
;==============
; Load Palettes
;==============
.a8
.i16
stz $2121 ; CGRAM color-generator read/write address
ldy #$00fe ; we have 127 colors / 512 bytes
ldx #$0000 ; pointer
opening_copypal:
lda f:vmw_logo_palette, x ; load byte of palette
sta $2122 ; store to color generator
inx
dey
bne opening_copypal
; make last color white
lda #$ff
sta $2122
lda #$7f
sta $2122
;=====================
; Load Tile Data
;=====================
; replace with DMA!
rep #$20 ; set accumulator/mem to 16bit
.a16
.i16
lda #$0020 ;
sta $2116 ; set adddress for VRAM read/write
; multiply by 2, so 0x0000
ldy #$2580 ; Copy 300 tiles, which are 64 bytes each
; 8x8 tile with 8bpp (four bits per pixel)
; in 2-byte chunks, so
; (300*64)/2 = 9600 = 0x2580
ldx #$0000
opening_copy_tile_data:
lda f:vmw_logo_tile_data, x
sta $2118 ; write the data
inx ; increment by 2 (16-bits)
inx
dey ; decrement counter
bne opening_copy_tile_data
;=====================
@ -132,63 +121,8 @@ opening_copy_font_data:
bne opening_copy_font_data
;===================================
; clear background to linear tilemap
;===================================
.a16
.i16
opening_clear_linear_tilemap:
; 6 down, 1 right = (6*32)+1 = 97 = 0xc1
; 1111 0000 1100 0001
lda #$78c1 ; we set tilemap to be at VRAM 0xf000 earlier
; f0c1
sta $2116
ldy #$0001 ; clear counters
; store to VRAM
; the bottom 8 bits is the tile to use
; the top 8 bits is vhopppcc
; vert flip, horiz flip o=priority
; p = palette, c=top bits of tile#
ldx #$0001
; 8-bit color so ppp is 0
; and we have a linear tilemap
; 0000 0000
; vhop ppcc cccc cccc
.a16
.i16
opening_fill_screen_loop:
cpx #31
bne opening_not_thirty
stz $2118
stz $2118
ldx #$0000
bra opening_check_end
opening_not_thirty:
tya
sta $2118
iny
opening_check_end:
inx
cpy #$0140 ; (10*32) = 0x140
bne opening_fill_screen_loop
; Write String to Background
opening_put_string:

View File

@ -104,15 +104,6 @@ svmw_transfer_sprite:
rts
;==================================
;==================================
; Load Compressed Tilemap
; This loads a tilemap made with my pcx_to_compressed_tilemap tool
;==================================
;==================================
;==============
;==============
; Load Palette
@ -142,3 +133,35 @@ svmw_load_palette:
plp ; restore status
rts
;===================
;===================
svmw_load_vram:
;===================
;===================
; set 2116/2117 for destination in advance
; A:X = address of data
; Y = length
php ; save status on stack
rep #$10 ; 16 bit X/Y
.i16
sep #$20 ; 8 bit A
.a8
stx $4302 ; Store data offset into DMA source offset
sta $4304 ; Store data bank into DMA source bank
sty $4305 ; Store size of data block
lda #$01 ; Set DMA Mode (word, normal increment)
sta $4300 ;
lda #$18 ; Set destination register ($2118 - VRAM Write)
sta $4301
lda #$01 ; Initiate DMA transfer
sta $420b
plp ; restore status
rts

View File

@ -43,87 +43,56 @@ display_title:
lda #$00
sta $210b ; bg1 tile data starts at VRAM 0000
;==============
; Load Palettes
;==============
;==========================
; Load Title Screen Palette
;==========================
stz $2121 ; start with color 0
ldy #(256*2) ; we have 256 colors
ldy #(256*2) ; we have 256 colors
lda #^title_screen_palette
ldx #.LOWORD(title_screen_palette)
jsr svmw_load_palette
;=====================
; Load Tile Data
; Load Title Tile Data
;=====================
; replace with DMA!
rep #$20 ; set accumulator/mem to 16bit
.a16
.i16
lda #$0000 ;
sta $2116 ; set adddress for VRAM read/write
ldx #$0000 ;
stx $2116 ; set adddress for VRAM read/write
; multiply by 2, so 0x0000
ldy #$3bc0 ; Copy 478 tiles, which are 64 bytes each
; 8x8 tile with 8bpp (four bits per pixel)
; in 2-byte chunks, so
; (478*64)/2 = 15296 = 0x3bc0
lda #^title_screen_tile_data
ldx #.LOWORD(title_screen_tile_data)
ldy #$7780 ; Copy 478 tiles, which are 64 bytes each
; 8x8 tile with 8bpp
; (478*64) = 30592 = 0x7780
ldx #$0000
copy_tile_data:
lda f:title_screen_tile_data, x
sta $2118 ; write the data
inx ; increment by 2 (16-bits)
inx
dey ; decrement counter
bne copy_tile_data
jsr svmw_load_vram
;===================================
; Load Title Tile Map
;===================================
ldx #$7000 ;
stx $2116 ; set adddress for VRAM read/write
; multiply by 2, so 0xe000
lda #^title_screen_tilemap
ldx #.LOWORD(title_screen_tilemap)
ldy #$0700 ; 32x28 = 896 * 2 = 0x700
jsr svmw_load_vram
;===================================
; Load Tile Map
; Setup Video
;===================================
.a16
.i16
clear_linear_tilemap:
lda #$f000 ; we set tilemap to be at VRAM 0xf000 earlier
sta $2116
ldx #$0000 ; clear offset
fill_screen_loop:
lda f:title_screen_tilemap,X
sta $2118
inx
inx
cpx #$0700 ; 32x28 = 896 * 2 = 0x700
bne fill_screen_loop
setup_video:
title_setup_video:
sep #$20 ; set accumulator to 8 bit
; as we only want to do an 8-bit load
.a8
.i16
; Enable sprite
; sssnnbbb
; ss = size (8x8 in our case)
; nn = name
; bb = base selection, VRAM >> 14
; lda #%00000010 ; point at 0x4000 in VRAM
; sta $2101
; 000abcde
; a = object, b=BG4 c=BG3 d=BG2 e=BG1
; lda #%00010001 ; Enable BG1
lda #%00000001 ; Enable BG1
sta $212c
@ -175,5 +144,3 @@ title_joypad_read:
.include "tb1_title.tiles"

View File

@ -242,8 +242,8 @@ static int vmwLoadPCX(int pcx_fd) {
/* print tile data */
for(x=0;x<max_planes/2;x++) {
printf("\t; Tile %d %d, Plane %d Plane %d\n",xchunk,ychunk,
x*2,(x*2)+1);
printf("\t; Tile #%d %d %d, Plane %d Plane %d\n",compressed_tiles,
xchunk,ychunk,x*2,(x*2)+1);
for(y=0;y<Y_CHUNKSIZE;y++) {
printf("\t.word $%04x\n",temp_tile[y][x]);
}
@ -323,6 +323,20 @@ static int vmwLoadPCX(int pcx_fd) {
}
}
#if 0
printf("\n");
printf("%s_info:\n",symbol_name);
printf("%s_tile_data_addr:\t.word .LOWORD(%s_tile_data)\n",symbol_name,
symbol_name);
printf("%s_tile_data_len:\t.word %d\n",symbol_name,100);
printf("%s_tilemap_addr:\t.word .LOWORD(%s_tilemap)\n",symbol_name,
symbol_name);
printf("%s_tilemap_len:\t.word %d\n",symbol_name,100);
printf("%s_palette_addr:\t.word .LOWORD(%s_palette)\n",symbol_name,
symbol_name);
printf("%s_palette_len_bytes:\t.word %d\n",symbol_name,512);
#endif
return 0;
}