dos33fsprogs/games/keen/draw_tilemap.s

189 lines
3.3 KiB
ArmAsm
Raw Normal View History

2024-03-10 05:44:20 +00:00
;================================
; draw local tilemap to screen
;================================
2024-03-13 04:46:34 +00:00
; tilemap is 20x12 grid with 2x4 (well, 2x2) tiles
2024-03-10 05:44:20 +00:00
draw_tilemap:
2024-03-14 04:08:19 +00:00
ldy #0 ; current screen Ypos to draw at
2024-03-14 04:24:03 +00:00
sty TILEY ; (we draw two at a time as lores
2024-03-14 04:08:19 +00:00
; is two blocks per byte)
2024-03-10 05:44:20 +00:00
2024-03-14 04:24:03 +00:00
ldx #0 ; offset in current tilemap
stx TILEMAP_OFFSET ;
2024-03-10 05:44:20 +00:00
lda #0 ; init odd/even
2024-03-14 04:24:03 +00:00
sta TILE_ODD ; (tiles are two rows tall)
2024-03-10 05:44:20 +00:00
tilemap_outer_loop:
2024-03-14 04:24:03 +00:00
ldy TILEY ; setup output pointer to current Ypos
2024-03-14 04:08:19 +00:00
lda gr_offsets,Y ; get address of start of row
2024-03-10 05:44:20 +00:00
sta GBASL
lda gr_offsets+1,Y
clc
2024-03-14 04:08:19 +00:00
adc DRAW_PAGE ; adjust for page
2024-03-10 05:44:20 +00:00
sta GBASH
2024-03-13 04:46:34 +00:00
2024-03-14 05:21:45 +00:00
ldy #0 ; draw row from 0..39
; might be faster to count backwards
; but would have to adjust a lot
2024-03-14 04:08:19 +00:00
2024-03-10 05:44:20 +00:00
tilemap_loop:
2024-03-14 04:24:03 +00:00
ldx TILEMAP_OFFSET ; get actual tile number
2024-03-14 04:08:19 +00:00
lda tilemap,X ; from tilemap
2024-03-10 05:44:20 +00:00
2024-03-14 04:08:19 +00:00
asl ; *4 ; point to tile to draw (4 bytes each)
2024-03-10 05:44:20 +00:00
asl
tax
2024-03-14 04:32:22 +00:00
lda TILE_ODD ; check to see if top or bottom
2024-03-10 05:44:20 +00:00
beq not_odd_line
2024-03-14 04:32:22 +00:00
inx ; point to bottom half of tile
2024-03-10 05:44:20 +00:00
inx
not_odd_line:
2024-03-14 04:32:22 +00:00
; draw two blocks
2024-03-14 04:24:03 +00:00
; note we don't handle transparency in the keen engine
2024-03-14 04:08:19 +00:00
2024-03-14 04:24:03 +00:00
lda tiles,X
2024-03-14 04:08:19 +00:00
sta (GBASL),Y ; draw upper right
2024-03-10 05:44:20 +00:00
iny
2024-03-14 04:24:03 +00:00
2024-03-13 04:46:34 +00:00
lda tiles+1,X
2024-03-14 04:08:19 +00:00
sta (GBASL),Y ; draw upper left
2024-03-14 04:24:03 +00:00
2024-03-10 05:44:20 +00:00
iny
2024-03-14 04:32:22 +00:00
inc TILEMAP_OFFSET ; point to next tile
2024-03-10 05:44:20 +00:00
2024-03-13 04:46:34 +00:00
cpy #40 ; until done
2024-03-10 05:44:20 +00:00
bne tilemap_loop
2024-03-14 05:21:45 +00:00
2024-03-10 05:44:20 +00:00
2024-03-14 04:08:19 +00:00
; row is done, move to next line
2024-03-14 04:24:03 +00:00
lda TILE_ODD ; toggle odd/even
2024-03-10 05:44:20 +00:00
eor #$1 ; (should we just add/mask?)
2024-03-14 04:24:03 +00:00
sta TILE_ODD
2024-03-14 04:32:22 +00:00
beq move_to_even_line
2024-03-10 05:44:20 +00:00
2024-03-14 04:08:19 +00:00
; move ahead to next row
2024-03-14 04:24:03 +00:00
; for even line we're already pointing to next
2024-03-14 04:32:22 +00:00
;move_to_even_line:
2024-03-14 04:24:03 +00:00
; lda TILEMAP_OFFSET
; clc
; adc #0
2024-03-14 04:32:22 +00:00
; jmp done_move_to_line
2024-03-14 04:24:03 +00:00
2024-03-14 04:08:19 +00:00
; reset back to beginning of line to display it again
2024-03-10 05:44:20 +00:00
move_to_odd_line:
2024-03-14 04:24:03 +00:00
lda TILEMAP_OFFSET
2024-03-10 05:44:20 +00:00
sec
2024-03-14 04:24:03 +00:00
sbc #TILE_COLS ; subtract off length of row
sta TILEMAP_OFFSET
2024-03-10 05:44:20 +00:00
2024-03-14 04:32:22 +00:00
move_to_even_line: ; no need, already points to
; right place
2024-03-10 05:44:20 +00:00
done_move_to_line:
2024-03-14 04:24:03 +00:00
ldy TILEY ; move to next output line
2024-03-14 04:32:22 +00:00
iny ; each row is two lines
2024-03-10 05:44:20 +00:00
iny
2024-03-14 04:24:03 +00:00
sty TILEY
2024-03-10 05:44:20 +00:00
2024-03-13 04:46:34 +00:00
cpy #48 ; check if at end
2024-03-10 05:44:20 +00:00
bne tilemap_outer_loop
rts
;===================================
; copy tilemap
;===================================
2024-03-14 05:21:45 +00:00
; local tilemap subset is 20x12 tiles = 240 bytes
; nicely fits in one page
;
2024-03-13 04:46:34 +00:00
; big tilemap is 256*40
; so each row is a page
; TILEMAP_X, TILEMAP_Y specify where in big
TILEMAP_X_COPY_SIZE = 20
TILEMAP_Y_COPY_SIZE = 12
2024-03-10 05:44:20 +00:00
copy_tilemap_subset:
; set start
lda TILEMAP_Y
2024-03-13 04:46:34 +00:00
clc ; set start
adc #>big_tilemap ; each row is a page, so adding
; Y to top byte is indexing to row
2024-03-10 05:44:20 +00:00
sta cptl1_smc+2 ; set proper row in big tilemap
2024-03-13 04:46:34 +00:00
adc #TILEMAP_Y_COPY_SIZE
sta cptl3_smc+1 ; set loop limit (end)
2024-03-10 05:44:20 +00:00
; reset row
2024-03-13 04:46:34 +00:00
lda #<tilemap
2024-03-10 05:44:20 +00:00
sta cptl2_smc+1 ; set small tilemap to row0
cp_tilemap_outer_loop:
ldx TILEMAP_X
ldy #0
cp_tilemap_inner_loop:
cptl1_smc:
lda $9400,X
cptl2_smc:
sta $BC00,Y
iny
inx
2024-03-13 04:46:34 +00:00
cpy #TILEMAP_X_COPY_SIZE
2024-03-10 05:44:20 +00:00
bne cp_tilemap_inner_loop
; next line
inc cptl1_smc+2 ; incremement page
clc
lda cptl2_smc+1 ; increment row
2024-03-13 04:46:34 +00:00
adc #TILEMAP_X_COPY_SIZE
2024-03-10 05:44:20 +00:00
sta cptl2_smc+1
lda cptl1_smc+2
cptl3_smc:
2024-03-13 04:46:34 +00:00
cmp #TILEMAP_Y_COPY_SIZE
2024-03-10 05:44:20 +00:00
bne cp_tilemap_outer_loop
2024-04-06 04:22:29 +00:00
done_tilemap_subset:
; activate yorps
ldx #0
clc
lda TILEMAP_X
adc #22
sta INL
activate_yorp_loop:
; if TILEMAP_X+22>YORP_X
lda INL
cmp enemy_data_tilex,X
bcc next_yorp
lda #1
sta enemy_data_out,X
next_yorp:
inx
cpx #NUM_ENEMIES
bne activate_yorp_loop
2024-03-10 05:44:20 +00:00
rts