From 0ec8efc1be85f90bc72a7979ca6a5078f01d2eca Mon Sep 17 00:00:00 2001 From: Vince Weaver Date: Sun, 14 Apr 2024 22:35:37 -0400 Subject: [PATCH] keen: make more things use tilemap lookup only saves handful of cycles it seems --- games/keen/Makefile | 2 +- games/keen/draw_tilemap.s | 116 ++++++++++++++++++++++---------------- games/keen/level1.s | 2 + 3 files changed, 69 insertions(+), 51 deletions(-) diff --git a/games/keen/Makefile b/games/keen/Makefile index bbc9faad..c082efa5 100644 --- a/games/keen/Makefile +++ b/games/keen/Makefile @@ -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 diff --git a/games/keen/draw_tilemap.s b/games/keen/draw_tilemap.s index 02627446..a8269dd2 100644 --- a/games/keen/draw_tilemap.s +++ b/games/keen/draw_tilemap.s @@ -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 - ; is two blocks per byte) + ldx #0 ; offset in current tilemap ; 2 + stx TILEMAP_OFFSET ; ; 3 - ldx #0 ; offset in current tilemap - stx TILEMAP_OFFSET ; +; 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) - 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 - ; might be faster to count backwards - ; but would have to adjust a lot + 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 - ; Y to top byte is indexing to row +; 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 ; 4 - sta cptl1_smc+2 ; set proper row in big tilemap lda #