duke: initial tilemap support

This commit is contained in:
Vince Weaver 2020-12-08 16:18:38 -05:00
parent 88fafd9c06
commit d7ac9dc1c6
4 changed files with 127 additions and 2 deletions

View File

@ -26,7 +26,9 @@ DUKE: duke.o
duke.o: duke.s zp.inc hardware.inc duke.s \
graphics/duke_graphics.inc \
level1_data.inc \
status_bar.s draw_duke.s gr_putsprite_crop.s \
draw_tilemap.s \
keyboard.s handle_laser.s
ca65 -o duke.o duke.s -l duke.lst

88
duke/draw_tilemap.s Normal file
View File

@ -0,0 +1,88 @@
draw_tilemap:
ldy #0 ; Y on screen currently drawing
sty tiley ; we draw two at a time
ldx #1 ; offset in current screen
stx tilemap_offset ; tilemap
lda #0 ; init odd/even
sta tile_odd
tilemap_outer_loop:
ldy tiley ; setup pointer to current Y
lda gr_offsets,Y
sta GBASL
lda gr_offsets+1,Y
clc
adc DRAW_PAGE
sta GBASH
ldy #6 ; we draw in window 6->34
tilemap_loop:
ldx tilemap_offset ; get actual tile
lda tilemap,X
asl ; *4 ; get offset in tile
asl
tax
lda tile_odd
beq not_odd_line
inx
inx
not_odd_line:
lda tiles,X ; draw two tiles
cmp #$AA ; transparency
beq skip_tile1
sta (GBASL),Y
skip_tile1:
iny
lda tiles+1,X
cmp #$AA
beq skip_tile2
sta (GBASL),Y
skip_tile2:
iny
inc tilemap_offset
cpy #34 ; until done
bne tilemap_loop
; move to next line
lda tile_odd ; toggle odd/even
eor #$1 ; (should we just add/mask?)
sta tile_odd
bne move_to_odd_line
move_to_even_line:
lda tilemap_offset
clc
adc #2
jmp done_move_to_line
move_to_odd_line:
lda tilemap_offset
sec
sbc #14
done_move_to_line:
sta tilemap_offset
ldy tiley ; move to next line
iny
iny
sty tiley
cpy #40 ; check if at end
bne tilemap_outer_loop
rts
tilemap_offset: .byte $00
tile_odd: .byte $00
tiley: .byte $00

View File

@ -38,7 +38,7 @@ duke_start:
lda #18
sta DUKE_X
lda #20
lda #18
sta DUKE_Y
lda #1
sta DUKE_DIRECTION
@ -67,6 +67,10 @@ duke_loop:
jsr gr_copy_to_current
; draw tilemap
jsr draw_tilemap
; draw laser
jsr draw_laser
@ -132,5 +136,6 @@ done_with_duke:
.include "draw_duke.s"
.include "handle_laser.s"
.include "draw_tilemap.s"
.include "level1_data.inc"

30
duke/level1_data.inc Normal file
View File

@ -0,0 +1,30 @@
tiles:
tile00: .byte $AA,$AA,$AA,$AA
tile01: .byte $55,$55,$55,$55
tile02: .byte $ff,$5f,$ff,$55
tile03: .byte $5f,$5f,$55,$55
tile04: .byte $5f,$ff,$5f,$ff
tile05: .byte $ff,$55,$ff,$f5
tile06: .byte $55,$55,$f5,$f5
tile07: .byte $55,$ff,$f5,$ff
tile08: .byte $55,$f5,$50,$f5
tile09: .byte $ff,$55,$ff,$55
tile0a: .byte $55,$ff,$55,$ff
tile0b: .byte $99,$99,$09,$09
tile0c: .byte $99,$59,$99,$88
tile0d: .byte $59,$99,$99,$99
tile0e: .byte $8f,$99,$09,$09
tile0f: .byte $00,$76,$f7,$05
tilemap:
.byte $00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$09,$08,$01,$01,$01,$01
.byte $00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$05,$06,$06,$06,$06,$06
.byte $00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$0f,$00,$00,$00,$00,$00
.byte $00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00
.byte $00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00
.byte $00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00
.byte $00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00
.byte $00,$00,$00,$00,$00,$00,$00,$0c,$0d,$00,$00,$00,$00,$00,$00,$00
.byte $00,$00,$00,$00,$00,$00,$00,$0b,$0e,$00,$00,$00,$00,$00,$00,$00
.byte $00,$00,$00,$00,$02,$03,$03,$03,$03,$03,$03,$03,$03,$03,$03,$03