-
Notifications
You must be signed in to change notification settings - Fork 2
/
bomb.asm
164 lines (148 loc) · 2.49 KB
/
bomb.asm
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
.ifndef BOMB_INC
BOMB_INC = 1
.include "x16.inc"
.include "globals.asm"
.include "sprite.asm"
BOMB_INIT_FRAME = 33
BOMB_LIT_FRAME = 34
BOMB_BLINK_FRAME = 22
bomb: .byte 0 ; Bits 7-3 (TBD) | Bit 2: blinked | Bit 1: lit | Bit 0: placed
BOMB_PLACED = $01
BOMB_LIT = $02
BOMB_BLINKED = $04
bomb_state_ticks: .byte 0
BOMB_LIT_TICKS = 70
BOMB_BLINK_TICKS = 10
__bomb_stored_x: .byte 0
__bomb_stored_y: .byte 0
bomb_tick:
@start:
lda bomb
bit #BOMB_PLACED
bne @show
lda #BOMB_idx
jsr sprite_disable
jmp @return
@show:
bit #BOMB_LIT
bne @show_lit
bit #BOMB_BLINKED
beq @show_init_frame
jmp @show_blinked
@show_init_frame:
lda #BOMB_INIT_FRAME
ldx #BOMB_idx
ldy #0
jsr sprite_frame
jmp @return
@show_lit:
dec bomb_state_ticks
bne @show_lit_frame
jmp @blink
@show_lit_frame:
lda #BOMB_LIT_FRAME
ldx #BOMB_idx
ldy #0
jsr sprite_frame
lda frame_num
and #$06
tax
lda #BOMB_idx
jmp (@jmp_table,x)
@jmp_table:
.word @move_up
.word @move_down
.word @move_right
.word @move_left
@move_up:
ldx #1
jsr move_sprite_right
lda #BOMB_idx
ldx #1
jsr move_sprite_up
jmp @return
@move_down:
ldx #2
jsr move_sprite_down
jmp @return
@move_right:
ldx #1
jsr move_sprite_up
lda #BOMB_idx
ldx #1
jsr move_sprite_right
jmp @return
@move_left:
ldx #2
jsr move_sprite_left
jmp @return
@blink:
lda #BOMB_BLINK_TICKS
sta bomb_state_ticks
lda bomb
eor #BOMB_LIT
ora #BOMB_BLINKED
sta bomb
@show_blinked:
dec bomb_state_ticks
beq @clear
lda #BOMB_BLINK_FRAME
ldx #BOMB_idx
ldy #0
jsr sprite_frame
jmp @return
@clear:
jsr bomb_clear
@return:
rts
bomb_clear:
stz bomb
stz bomb_state_ticks
rts
bomb_place: ; A: tile layer index
; X: tile x
; Y: tile y
clc
ror
ror
ora #BOMB_idx
jsr sprite_setpos
lda bomb
ora #BOMB_PLACED
sta bomb
rts
bomb_light:
lda bomb
ora #BOMB_LIT
sta bomb
lda #BOMB_LIT_TICKS
sta bomb_state_ticks
rts
bomb_armed: ; Output: A - 0=not armed, 1=armed
lda bomb
bit #BOMB_PLACED
beq @not_armed
bit #BOMB_LIT
bne @not_armed
bit #BOMB_BLINKED
bne @not_armed
lda #1
bra @return
@not_armed:
lda #0
@return:
rts
bomb_store_pos:
lda #BOMB_idx
ldx #1
jsr sprite_getpos
stx __bomb_stored_x
sty __bomb_stored_y
rts
bomb_restore_pos:
lda #($80 | BOMB_idx)
ldx __bomb_stored_x
ldy __bomb_stored_y
jsr sprite_setpos
rts
.endif