mirror of
https://github.com/deater/dos33fsprogs.git
synced 2024-10-31 10:13:35 +00:00
keen: make more things use tilemap lookup
only saves handful of cycles it seems
This commit is contained in:
parent
ed5053bb1e
commit
0ec8efc1be
@ -69,7 +69,7 @@ level1.o: level1.s zp.inc hardware.inc \
|
||||
graphics/keen_graphics.inc sprites/keen_sprites.inc \
|
||||
maps/level1_map.lzsa \
|
||||
status_bar.s draw_keen.s move_keen.s gr_putsprite_crop.s \
|
||||
draw_tilemap.s \
|
||||
draw_tilemap.s tilemap_lookup.s \
|
||||
level1_sfx.s longer_sound.s \
|
||||
keyboard.s handle_laser.s
|
||||
ca65 -o level1.o level1.s -l level1.lst
|
||||
|
@ -4,62 +4,64 @@
|
||||
; tilemap is 20x12 grid with 2x4 (well, 2x2) tiles
|
||||
|
||||
draw_tilemap:
|
||||
ldy #0 ; current screen Ypos to draw at
|
||||
sty TILEY ; (we draw two at a time as lores
|
||||
ldx #0 ; offset in current tilemap ; 2
|
||||
stx TILEMAP_OFFSET ; ; 3
|
||||
|
||||
; ldy #0 ; current screen Ypos to draw at ; 2
|
||||
stx TILEY ; (we draw two at a time as lores ; 3
|
||||
; is two blocks per byte)
|
||||
|
||||
ldx #0 ; offset in current tilemap
|
||||
stx TILEMAP_OFFSET ;
|
||||
|
||||
lda #0 ; init odd/even
|
||||
sta TILE_ODD ; (tiles are two rows tall)
|
||||
|
||||
; lda #0 ; init odd/even ; 2
|
||||
stx TILE_ODD ; (tiles are two rows tall) ; 3
|
||||
|
||||
tilemap_outer_loop:
|
||||
ldy TILEY ; setup output pointer to current Ypos
|
||||
ldy TILEY ; setup output pointer to current Ypos ; 3
|
||||
|
||||
lda gr_offsets,Y ; get address of start of row
|
||||
sta GBASL
|
||||
lda gr_offsets+1,Y
|
||||
clc
|
||||
adc DRAW_PAGE ; adjust for page
|
||||
sta GBASH
|
||||
lda gr_offsets,Y ; get address of start of row ; 4+
|
||||
sta GBASL ; 3
|
||||
lda gr_offsets+1,Y ; 4+
|
||||
clc ; 2
|
||||
adc DRAW_PAGE ; adjust for page ; 3
|
||||
sta GBASH ; 3
|
||||
|
||||
|
||||
ldy #0 ; draw row from 0..39
|
||||
ldy #0 ; draw row from 0..39 ; 2
|
||||
; might be faster to count backwards
|
||||
; but would have to adjust a lot
|
||||
|
||||
tilemap_loop:
|
||||
ldx TILEMAP_OFFSET ; get actual tile number
|
||||
lda small_tilemap,X ; from tilemap
|
||||
ldx TILEMAP_OFFSET ; get actual tile number ; 3
|
||||
lda small_tilemap,X ; from tilemap ; 4
|
||||
|
||||
asl ; *4 ; point to tile to draw (4 bytes each)
|
||||
asl
|
||||
tax
|
||||
asl ; *4 ; point to tile to draw (4 bytes each) ; 2
|
||||
asl ; 2
|
||||
tax ; 2
|
||||
|
||||
lda TILE_ODD ; check to see if top or bottom
|
||||
beq not_odd_line
|
||||
inx ; point to bottom half of tile
|
||||
inx
|
||||
lda TILE_ODD ; check to see if top or bottom ; 3
|
||||
beq not_odd_line ; 2/3
|
||||
inx ; point to bottom half of tile ; 2
|
||||
inx ; 2
|
||||
not_odd_line:
|
||||
|
||||
; draw two blocks
|
||||
; note we don't handle transparency in the keen engine
|
||||
|
||||
lda tiles,X
|
||||
sta (GBASL),Y ; draw upper right
|
||||
lda tiles,X ; 4
|
||||
sta (GBASL),Y ; draw upper right ; 6
|
||||
|
||||
iny
|
||||
iny ; 2
|
||||
|
||||
lda tiles+1,X
|
||||
sta (GBASL),Y ; draw upper left
|
||||
lda tiles+1,X ; 4
|
||||
sta (GBASL),Y ; draw upper left ; 6
|
||||
|
||||
iny
|
||||
iny ; 2
|
||||
|
||||
inc TILEMAP_OFFSET ; point to next tile
|
||||
inc TILEMAP_OFFSET ; point to next tile ; 5
|
||||
|
||||
cpy #40 ; until done
|
||||
bne tilemap_loop
|
||||
cpy #40 ; until done ; 2
|
||||
bne tilemap_loop ; 2/3
|
||||
|
||||
|
||||
|
||||
@ -126,22 +128,35 @@ copy_tilemap_subset:
|
||||
lda #0
|
||||
sta tilemap_count_smc+1
|
||||
|
||||
; original worse case: 23 cycles
|
||||
; lookup table: 19 cycles
|
||||
|
||||
; set start
|
||||
lda TILEMAP_Y
|
||||
lsr
|
||||
|
||||
ldx TILEMAP_Y ; 3
|
||||
lda tilemap_lookup_high,X ; 4
|
||||
sta cptl1_smc+2 ; set proper row in big tilemap ; 4
|
||||
lda tilemap_lookup_low,X ; 4
|
||||
sta cptl1_smc+1 ; set proper row in big tilemap ; 4
|
||||
|
||||
|
||||
; set start
|
||||
; lda TILEMAP_Y ; 3
|
||||
; lsr ; 2
|
||||
|
||||
; set odd/even
|
||||
ldx #0
|
||||
bcc skip_odd_row
|
||||
ldx #$80
|
||||
skip_odd_row:
|
||||
stx cptl1_smc+1
|
||||
; ldx #0 ; 2
|
||||
; bcc skip_odd_row ; 2/3
|
||||
; ldx #$80 ; 2
|
||||
;skip_odd_row:
|
||||
; stx cptl1_smc+1 ; 4
|
||||
|
||||
clc ; set start
|
||||
adc #>big_tilemap ; each even row is a page, so adding
|
||||
; clc ; set start ; 2
|
||||
; adc #>big_tilemap ; each even row is a page, so adding ; 2
|
||||
; Y to top byte is indexing to row
|
||||
|
||||
sta cptl1_smc+2 ; set proper row in big tilemap
|
||||
; sta cptl1_smc+2 ; set proper row in big tilemap ; 4
|
||||
|
||||
|
||||
|
||||
lda #<small_tilemap
|
||||
@ -153,14 +168,15 @@ cp_tilemap_outer_loop:
|
||||
ldy #0
|
||||
cp_tilemap_inner_loop:
|
||||
|
||||
; FIXME: make cptl1 take into account X offset and use one index?
|
||||
; TODO: optimize, totally unroll?
|
||||
|
||||
cptl1_smc:
|
||||
lda $9400,X
|
||||
lda $9400,X ; 4
|
||||
cptl2_smc:
|
||||
sta $BC00,Y
|
||||
iny
|
||||
inx
|
||||
sta $BC00,Y ; 5
|
||||
iny ; 2
|
||||
inx ; 2
|
||||
cpy #TILEMAP_X_COPY_SIZE
|
||||
bne cp_tilemap_inner_loop
|
||||
|
||||
|
@ -302,5 +302,7 @@ level1_levelover:
|
||||
|
||||
.include "random16.s"
|
||||
|
||||
.include "tilemap_lookup.s"
|
||||
|
||||
level1_data_zx02:
|
||||
.incbin "maps/level1_map.zx02"
|
||||
|
Loading…
Reference in New Issue
Block a user