-
Notifications
You must be signed in to change notification settings - Fork 2
/
worm5.asm
349 lines (311 loc) · 16 KB
/
worm5.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
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
;*****************************************************
; WORM5
; draw in Random characters on the screen
; Add in border around the screen
;*****************************************************
*=$1000
Const_KBD_BUFFER = $c5 ; Keyboard matrix
Const_UP = $09 ;
Const_DOWN = $0c ;values
Const_LEFT = $0a ;for up down left right
Const_RIGHT = $0d ;
Const_WORM_INCR = $16 ; "T" pressed = increase length of worm
;*****************************************************
; Initialize worm memory areas
;*****************************************************
jsr Init_Random
ldx #00
lda #00
@init_loop lda headx
sta worm1x,x
lda heady
sta worm1y,x
dex
bne @init_loop
lda headx
sta worm1x
sta bodyx
lda heady
sta worm1y
sta bodyy
lda #$93 ; Clear the screen
jsr $ffd2
jsr draw_border
main_loop
lda offset
tax
lda worm1x,x
sta tempx
lda worm1y,x
sta tempy
clc
lda offset
adc length
tax
lda worm1x,x
sta bodyx
lda worm1y,x
sta bodyy
lda #$20 ; Erase starting position
pokeaxy tempx,tempy
jsr set_direction ; Change position of head
lda length
beq @no_body
lda #31 ; Draw body
pokeaxy bodyx,bodyy
@no_body inc offset
lda headx
clc
lda offset
adc length
tax
lda headx
sta worm1x,x
lda heady
sta worm1y,x
peekaxy headx,heady ; Hit detection
cmp #$20
@self bne @self
lda #$32 ; Draw head
pokeaxy headx,heady
jsr DRAW_RANDOM_CHAR
;*****************************************************
; finish loop
;*****************************************************
jsr get_key
jsr delay
jmp main_loop
rts
DRAW_RANDOM_CHAR
lda #38
sta RAND_MAX
jsr RAND
tax
inx
stx charx
lda #23
sta RAND_MAX
jsr RAND
tax
inx
stx chary
lda #01 ; RANDOM CHAR
pokeaxy charx,chary
rts
charx byte 00
chary byte 00
;*****************************************************
; set_direction
;*****************************************************
set_direction
lda startdir
cmp #1
beq @down
cmp #2
beq @left
cmp #3
beq @right
@up dec heady
jmp @cont
@down inc heady
jmp @cont
@left dec headx
jmp @cont
@right inc headx
@cont
rts
;*****************************************************
; get input
;*****************************************************
get_key lda Const_KBD_BUFFER ; Input a key from Keyboard
_ck_pressed
cmp #Const_DOWN ; down - z pressed
beq @down
cmp #Const_Right ; up - w pressed
beq @right
cmp #Const_LEFT ; left - a pressed
beq @left
cmp #Const_Up ; right - s pressed
beq @up
cmp #Const_WORM_INCR ;T - Pressed - advance a level - cheat
beq @make_bigger
rts
@down
lda #1
sta startdir ; Down
rts
@right
lda #3
sta startdir ; Right
rts
@up
lda #0
sta startdir ; Up
rts
@left
lda #2
sta startdir ; left
rts
@make_bigger
inc length
lda length
clc
adc offset
tax
lda headx
sta worm1x,x
lda heady
sta worm1y,x
rts
;***DELAY ***
delay txa
pha
ldx #60
@loop1 ldy #0
@loop2 dey
bne @loop2
dex
bne @loop1
pla
rts
height byte 25
width byte 40
Const_BOX_X byte 0
Const_Box_Y byte 0
Const_Box_Color byte 2
draw_border
lda #0
sta Const_Box_X
sta Const_Box_Y
lda #40
sta width
lda #25
sta height
ldy Const_BOX_Y
lda map_off_l,y
sta @left_top_edge+1
sta @left_top_edgec+1
lda map_off_h,y
sta @left_top_edge+2
lda Const_Screen_C,y
sta @left_top_edgec+2
clc
dey
tya
adc height
tay
lda map_off_l,y
sta @left_bot_edge+1
sta @left_bot_edgec+1
lda map_off_h,y
sta @left_bot_edge+2
lda Const_Screen_C,y
sta @left_bot_edgec+2
ldx Const_BOX_X
ldy #0
lda #$2
@left_top_edge sta $400,x
@left_bot_edge sta $450,x
lda Const_Box_Color
@left_top_edgec sta $d800,x
@left_bot_edgec sta $d800,x
inx
iny
@box_width cpy width
bne @left_top_edge-2
ldx #2 ; Accounts for top and bottom of box => just draw middle
ldy Const_BOX_Y
iny
@loop2 lda map_off_l,y
sta @box_top_left+1
sta @box_top_right+1
sta @box_top_leftc+1
sta @box_top_rightc+1
lda map_off_h,y
sta @box_top_left+2
sta @box_top_right+2
lda Const_Screen_C,y
sta @box_top_leftc+2
sta @box_top_rightc+2
txa
pha
ldx Const_Box_X
lda #$1
@box_top_left sta $400,x
lda Const_Box_Color
@box_top_leftc sta $d800,x
dex
txa
clc
adc width
tax
lda #1
@box_top_right sta $400,x
lda Const_Box_Color
@box_top_rightc sta $d800,x
pla
tax
inx
iny
cpx height
bne @loop2
rts
Init_Random
LDA #$FF ; maximum frequency value
STA $D40E ; voice 3 frequency low byte
STA $D40F ; voice 3 frequency high byte
LDA #$80 ; noise SIRENform, gate bit off
STA $D412 ; voice 3 control register
rts
RAND
LDA $D41B ; get random value from 0-255
CMP RAND_MAX ; narrow random result down
; to between zero - g$len
BCC @dont_crash ; ~ to 0-3
jmp RAND
@dont_crash rts
tempx byte 00
tempy byte 00
bodyx byte 00
bodyy byte 00
RAND_MAX byte 00
headx byte 06
heady byte 10
startdir byte 01,00
offset byte 00,00
length byte 10,00
map_off_l byte $00,$28,$50,$78,$A0,$C8,$F0,$18,$40,$68,$90,$b8,$E0,$08,$30,$58,$80,$a8,$d0,$f8,$20,$48,$70,$98,$c0
map_off_h byte $04,$04,$04,$04,$04,$04,$04,$05,$05,$05,$05,$05,$05,$06,$06,$06,$06,$06,$06,$06,$07,$07,$07,$07,$07
Const_Screen_C byte $d8,$d8,$d8,$d8,$d8,$d8,$d8,$d9,$d9,$d9,$d9,$d9,$d9,$da,$da,$da,$da,$da,$da,$da,$db,$db,$db,$db,$db
;*****************************************************
; Grab value of screen position located at x,y
; Store result in accumulator
;*****************************************************
defm peekaxy
ldx /2 ; X value
ldy /1 ; Y Value
lda map_off_l,x ; Load map low byte into $fb
sta $fb
lda map_off_h,x ; Load map hig byte into $fc
sta $fc
lda ($fb),y ; Load result into acc
endm
;*****************************************************
; Store value of accumulator in screen memory at position
; x, y
;*****************************************************
defm pokeaxy
pha
ldx /2 ; X value
ldy /1 ; Y value
lda map_off_l,x ; Load map low byte into $fb
sta $fb
lda map_off_h,x ; Load map high byte into $fc
sta $fc
pla
sta ($fb),y ; Store result in screen memory
endm
*=$2000
worm1x
*=$2100
worm1y