mirror of
https://codeberg.org/hkzlab/TK2048.git
synced 2025-12-26 09:32:32 +11:00
244 lines
No EOL
4.2 KiB
ArmAsm
244 lines
No EOL
4.2 KiB
ArmAsm
.rtmodel version,"1"
|
|
.rtmodel core,"6502"
|
|
|
|
.extern _Zp
|
|
.extern VDP_MEM, VDP_REG
|
|
|
|
.extern vdp_point_to_vram_xy
|
|
|
|
NUM_TILE_OFFSET: .equ 0x14
|
|
|
|
.section code,text
|
|
|
|
vdp_redraw_tiles:
|
|
;;; TODO
|
|
rts
|
|
|
|
vdp_draw_joystick:
|
|
T_NT_IDX$: .equ _Zp+4
|
|
P_POS$: .equ _Zp+2
|
|
T_Y$: .equ _Zp+1
|
|
T_X$: .equ _Zp+0
|
|
|
|
ldx #0
|
|
stx zp:T_NT_IDX$
|
|
pha
|
|
|
|
; Clear the table
|
|
lda #29
|
|
sta zp:T_X$
|
|
lda #16
|
|
sta zp:T_Y$
|
|
jsr vdp_point_to_vram_xy
|
|
lda #0
|
|
sta VDP_MEM
|
|
|
|
lda #29
|
|
sta zp:T_X$
|
|
lda #18
|
|
sta zp:T_Y$
|
|
jsr vdp_point_to_vram_xy
|
|
lda #0
|
|
sta VDP_MEM
|
|
|
|
lda #28
|
|
sta zp:T_X$
|
|
lda #17
|
|
sta zp:T_Y$
|
|
jsr vdp_point_to_vram_xy
|
|
lda #0
|
|
sta VDP_MEM
|
|
sta VDP_MEM
|
|
sta VDP_MEM
|
|
|
|
; Jump to the correct code to handle joystick drawing
|
|
pla
|
|
asl a
|
|
tax
|
|
lda _draw_joystick_jumptable$,x
|
|
sta zp:_Zp+0
|
|
lda _draw_joystick_jumptable$+1,x
|
|
sta zp:_Zp+1
|
|
sec
|
|
jmp (_Zp+0)
|
|
|
|
J_Center$:
|
|
ldx #29
|
|
ldy #18
|
|
bcs J_Done$
|
|
J_Up$:
|
|
ldx #29
|
|
ldy #17
|
|
bcs J_Done$
|
|
J_Down$:
|
|
ldx #29
|
|
ldy #19
|
|
bcs J_Done$
|
|
J_Left$:
|
|
ldx #28
|
|
ldy #18
|
|
bcs J_Done$
|
|
J_Right$:
|
|
ldx #30
|
|
ldy #18
|
|
J_Done$:
|
|
stx zp:T_X$
|
|
sty zp:T_Y$
|
|
jsr vdp_point_to_vram_xy
|
|
lda #120
|
|
sta VDP_MEM
|
|
|
|
rts
|
|
_draw_joystick_jumptable$:
|
|
.word J_Center$
|
|
.word J_Up$
|
|
.word J_Down$
|
|
.word J_Left$
|
|
.word J_Right$
|
|
|
|
vdp_clear_gamegrid:
|
|
T_NT_IDX$: .equ _Zp+4
|
|
T_Y$: .equ _Zp+1
|
|
T_X$: .equ _Zp+0
|
|
|
|
|
|
lda #0x00
|
|
sta zp:T_NT_IDX$
|
|
lda #0x01
|
|
sta zp:T_X$
|
|
lda #19
|
|
sta zp:T_Y$
|
|
|
|
ClearLine$:
|
|
jsr vdp_point_to_vram_xy
|
|
lda #0x00
|
|
ldx #24
|
|
ClearTile$:
|
|
sta VDP_MEM
|
|
dex
|
|
bne ClearTile$
|
|
|
|
dec zp:T_Y$
|
|
bne ClearLine$
|
|
|
|
rts
|
|
|
|
vdp_clear_dialog:
|
|
T_NT_IDX$: .equ _Zp+4
|
|
T_Y$: .equ _Zp+1
|
|
T_X$: .equ _Zp+0
|
|
|
|
|
|
lda #0x01
|
|
sta zp:T_NT_IDX$
|
|
lda #0x04
|
|
sta zp:T_X$
|
|
lda #15
|
|
sta zp:T_Y$
|
|
ldy #9
|
|
|
|
ClearLine$:
|
|
jsr vdp_point_to_vram_xy
|
|
lda #0x00
|
|
ldx #24
|
|
ClearTile$:
|
|
sta VDP_MEM
|
|
dex
|
|
bne ClearTile$
|
|
|
|
dec zp:T_Y$
|
|
dey
|
|
bne ClearLine$
|
|
|
|
rts
|
|
|
|
;;; vdp_draw_numtile:
|
|
;;; Draws the 2048 tile at specified coordinates
|
|
;;; Parameters:
|
|
;;; - Type of tile [A]
|
|
;;; - X in game grid [Zp[0]]
|
|
;;; - Y in game grid [Zp[1]]
|
|
;;;
|
|
;;; Returns: nothing
|
|
;;;
|
|
;;; Clobbers:
|
|
;;; - A, Y, X
|
|
;;; - Zp 0, 1, 2, 3, 4, 5, 6, 7
|
|
;;;
|
|
vdp_draw_numtile:
|
|
T_LINE_COUNT$:.equ _Zp+7
|
|
T_NT_IDX$: .equ _Zp+4
|
|
T_COUNTER$: .equ _Zp+3
|
|
P_TYPE$: .equ _Zp+2
|
|
P_Y$: .equ _Zp+1
|
|
P_X$: .equ _Zp+0
|
|
|
|
sta zp:P_TYPE$
|
|
lda #0
|
|
sta zp:T_NT_IDX$ ; the tiles here will be drawn only on game table
|
|
sta zp:T_COUNTER$
|
|
|
|
lda #3
|
|
sta zp:T_LINE_COUNT$
|
|
|
|
; Convert the coordinates
|
|
ldx zp:P_X$
|
|
lda TileNum_X_Map,x
|
|
sta zp:P_X$
|
|
|
|
ldx zp:P_Y$
|
|
lda TileNum_Y_Map,x
|
|
sta zp:P_Y$
|
|
|
|
; Calculate the beginning of the tile section we're interested in
|
|
clc
|
|
lda #NUM_TILE_OFFSET
|
|
adc zp:P_TYPE$
|
|
asl a
|
|
asl a
|
|
asl a
|
|
sta zp:P_TYPE$
|
|
|
|
; Draw the tile
|
|
DrawNextLine$:
|
|
jsr vdp_point_to_vram_xy
|
|
ldx zp:T_COUNTER$
|
|
|
|
ldy #4
|
|
SetTile$:
|
|
clc
|
|
lda TileNum_Offset_Map,x
|
|
adc zp:P_TYPE$
|
|
sta VDP_MEM
|
|
inx
|
|
dey
|
|
bne SetTile$
|
|
|
|
stx zp:T_COUNTER$
|
|
inc zp:P_Y$
|
|
dec zp:T_LINE_COUNT$
|
|
bne DrawNextLine$
|
|
|
|
rts
|
|
|
|
;;;;;;;;;;;;;;;;;;
|
|
.section data,data
|
|
|
|
TileNum_Offset_Map: ; Offset from the beginning of the selected tilemap section, of the tiles composing the numeric-2048 tile
|
|
.byte 0x00, 0x04, 0x04, 0x02 ; First line
|
|
.byte 0x04, 0x04, 0x04, 0x04 ; Second
|
|
.byte 0x01, 0x04, 0x04, 0x03 ; Third and last
|
|
|
|
; The following maps convert between X and Y in the game grid into the tile map grid
|
|
TileNum_X_Map:
|
|
.byte 0x01, 0x06, 0x0B, 0x10, 0x15
|
|
TileNum_Y_Map:
|
|
.byte 0x01, 0x05, 0x09, 0x0D, 0x11
|
|
|
|
;;;;;;;;;;;;;;;;;;
|
|
.public vdp_draw_numtile
|
|
.public vdp_clear_gamegrid
|
|
.public vdp_clear_dialog
|
|
.public vdp_redraw_tiles
|
|
.public vdp_draw_joystick
|
|
|