Hi again. I'm back with more ignorance.
I'm attempting to make a simple horizontal side scroller. I thought I could update the name table one column at a time as the screen scrolled (inside the NMI). But alas, my column update subroutine is to slow and goes over the time limit.
So my question is, in a side scroller, should I be updating the name table in a different manner (not in the NMI) or is my code really to much and needs to be fixed.
Here's the subrountine I'm using to update the name table. This by itself takes to long so I won't post the code that updates the attribute table for a column.
map_buffer contains the actual meta-tile data.
meta_tile_patterns is a pointer to a look up table for each meta-tile's pattern numbers. Each tile has four byte for the Upper Left, Upper Right, Lower Left, Lower Right parts of it (the meta-tiles are 16x16 pixels).
There might be some typos in the comments but the code is tested and works.
So.... how bad does it look?
I'm attempting to make a simple horizontal side scroller. I thought I could update the name table one column at a time as the screen scrolled (inside the NMI). But alas, my column update subroutine is to slow and goes over the time limit.
So my question is, in a side scroller, should I be updating the name table in a different manner (not in the NMI) or is my code really to much and needs to be fixed.
Here's the subrountine I'm using to update the name table. This by itself takes to long so I won't post the code that updates the attribute table for a column.
Code:
draw_map_column subroutine ;
; curr_name_table_hi/lo should point to the top of the
; the column in the name table
; register X should be set to the name table column to draw
; Set VRAM address to current name table page
lda curr_name_table_hi
sta $2006
lda curr_name_table_lo
sta $2006
; Set VRAM address count to 32
lda ppu_reg_0
ora #%00000100
sta $2000
; Begin pattern table drawing loop (y = y counter)
lda #$00
sta y
.draw_column_loop
; Get meta-tile for current screen spot and use
; as offset to tile look up table (meta_tile_patterns)
; Find tile on map_buffer
and #%11111110 ; y/2 * 16
asl ;
asl ;
asl ;
sta main_temp_lo ; Save
txa ; Find x/2
lsr ;
clc ;
adc main_temp_lo ; Add y/2 * 16 + x/2
tay ; Transfer to index Y to use as offset to map_buffer
lda (map_buffer,y) ; Load a with tile at current meta-tile
asl ; Multiply the tile number by four
asl ; (four pattern tiles per meta-tile)
sta main_temp_lo ; Store offset
txa ; Add x%2 to offset
and #%00000001 ;
clc ;
adc main_temp_lo ;
sta main_temp_lo ;
lda y ; Add y%2 * 2
and #%00000001 ;
asl ;
clc ;
adc main_temp_lo ;
tay ; Transfer meta_tile_patterns offset to y index
lda (meta_tile_patterns,y) ; Load pattern tile for current meta-tile
sta $2007 ; Store on screen
inc y ; Increment y counter
lda y
cmp #30 ; Test if whole name table column has been drawn
bne .draw_column_loop ; If not, continue...
rts
; curr_name_table_hi/lo should point to the top of the
; the column in the name table
; register X should be set to the name table column to draw
; Set VRAM address to current name table page
lda curr_name_table_hi
sta $2006
lda curr_name_table_lo
sta $2006
; Set VRAM address count to 32
lda ppu_reg_0
ora #%00000100
sta $2000
; Begin pattern table drawing loop (y = y counter)
lda #$00
sta y
.draw_column_loop
; Get meta-tile for current screen spot and use
; as offset to tile look up table (meta_tile_patterns)
; Find tile on map_buffer
and #%11111110 ; y/2 * 16
asl ;
asl ;
asl ;
sta main_temp_lo ; Save
txa ; Find x/2
lsr ;
clc ;
adc main_temp_lo ; Add y/2 * 16 + x/2
tay ; Transfer to index Y to use as offset to map_buffer
lda (map_buffer,y) ; Load a with tile at current meta-tile
asl ; Multiply the tile number by four
asl ; (four pattern tiles per meta-tile)
sta main_temp_lo ; Store offset
txa ; Add x%2 to offset
and #%00000001 ;
clc ;
adc main_temp_lo ;
sta main_temp_lo ;
lda y ; Add y%2 * 2
and #%00000001 ;
asl ;
clc ;
adc main_temp_lo ;
tay ; Transfer meta_tile_patterns offset to y index
lda (meta_tile_patterns,y) ; Load pattern tile for current meta-tile
sta $2007 ; Store on screen
inc y ; Increment y counter
lda y
cmp #30 ; Test if whole name table column has been drawn
bne .draw_column_loop ; If not, continue...
rts
map_buffer contains the actual meta-tile data.
meta_tile_patterns is a pointer to a look up table for each meta-tile's pattern numbers. Each tile has four byte for the Upper Left, Upper Right, Lower Left, Lower Right parts of it (the meta-tiles are 16x16 pixels).
There might be some typos in the comments but the code is tested and works.
So.... how bad does it look?