-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy path27 - Tutorial Twenty Seven.asm
380 lines (354 loc) · 8.26 KB
/
27 - Tutorial Twenty Seven.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
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
;*******************************************************************************
;* Tutorial Twenty-Seven Bars and Gauges *
;* *
;* Written By John C. Dale *
;* Tutorial #27 *
;* Date : 17th Dec, 2017 *
;* *
;*******************************************************************************
;* *
;*******************************************************************************
WATCH XVALUE
WATCH YVALUE
WATCH YPOS
WATCH XPOS
;*******************************************************************************
;* *
;*******************************************************************************
*=$9000
GetKey = $FFE4
XSCRNLOC = $14
YSCRNLOC = $17
YGAUGLOC = $19
jmp START
XVALUE ; X Velocity Value
BYTE 00
YVALUE ; Y Velocity Value
BYTE 00
YPOS ; Y Position (Height)
BYTE 00
XPOS ; X Position
BYTE 00
XINDEXPOS
BYTE 00
YINDEXPOS
BYTE 00
YGAUGEINDEX
BYTE 00
XBARCHARACTERS
BYTE $20,$65,$54,$47,$5D,$48,$59,$67,$67
; 0 1 2 3 4 5 6 7 8
YBARCHARACTERS
BYTE $20,$77,$45,$44,$40,$46,$52,$6F,$6F
; 0 1 2 3 4 5 6 7 8
YGAUGECHARACTERS
BYTE $20,$63,$77,$78,$E2,$F9,$EF,$E4,$E4
; 0 1 2 3 4 5 6 7 8
YSCREENOFFSETLO
BYTE $00,$28,$50,$78,$A0,$C8,$F0,$18,$40,$68,$90,$B8,$E0
BYTE $08,$30,$58,$80,$A8,$D0,$F8,$20,$48,$70,$98,$C0,$E8
YSCREENOFFSETHI
BYTE $00,$00,$00,$00,$00,$00,$00,$01,$01,$01,$01,$01,$01
BYTE $02,$02,$02,$02,$02,$02,$02,$03,$03,$03,$03,$03,$03
START
ldx#0
ldy#0
@LOOP
lda XBARCHARACTERS,x
ora #128
@SCRLOC
sta $0401,y
tya
clc
adc#40
bcc @noadd
inc @SCRLOC +2
@noadd
tay
inx
cpx #9
bne @LOOP
ldx#0
@LOOP1
lda YBARCHARACTERS,x
ora #128
sta $05E0,x
inx
cpx #9
bne @LOOP1
initYBar $044E,22
initYBar $044D,22
initXBar $0799,34
MAINLOOP
jsr $FFE4
cmp #0
beq MAINLOOP
@TEST_LEFT
cmp #"d"
bne @TEST_RIGHT
inc XPOS
jmp SHOW_ON_BAR
@TEST_RIGHT
cmp #"a"
bne @TEST_UP
dec XPOS
jmp SHOW_ON_BAR
@TEST_UP
cmp #"w"
bne @TEST_DOWN
inc YPOS
jmp SHOW_ON_BAR
@TEST_DOWN
cmp #"z"
bne @TEST_INCREASE
dec YPOS
jmp SHOW_ON_BAR
@TEST_INCREASE
cmp #"i"
bne @TEST_DECREASE
inc YValue
jmp SHOW_ON_BAR
@TEST_DECREASE
cmp #"m"
bne @TEST_EXIT
dec YValue
jmp SHOW_ON_BAR
@TEST_EXIT
cmp #"x"
bne MAINLOOP
rts
SHOW_ON_BAR
lda XPOS
showXBar $0799, $80
lda YPOS
eor #$FF
showYBar $044E, $58
lda YVALUE
eor #$FF
showYGauge $044D, $00
jmp MAINLOOP
DELAY
KT_LOOPER
ldx #255 ; Loop For 255 Y Cycles
KT_OUTERLOOP
ldy #255 ; Loop 255 times
KT_INNERLOOP
dey ; Decrease Inner Loop Index
bne KT_INNERLOOP ; Hit Zero?, No, Loop Round
dex ; Yes, Decrease Outer Loop Index
bne KT_OUTERLOOP ; Hit Zero?, No, Loop Round
rts ; Yes, Exit
defm initYBar ; Parameters STARTLOC, ITERATIONS
ldx #</1
lda #>/1
sta @SCREENLOC+2
stx @SCREENLOC+1
ldx #0
@LOOP
lda #160
@SCREENLOC
sta /1
clc
lda #40
adc @SCREENLOC+1
sta @SCREENLOC+1
lda #0
adc @SCREENLOC+2
sta @SCREENLOC+2
inx
cpx #/2
bne @LOOP
endm
defm initXBar ; Parameters STARTLOC, ITERATIONS
ldx #0
@LOOP
lda #160
sta /1,x
inx
cpx #/2
bne @LOOP
endm
defm showXCentreBar
pha ; Store Away Value Safely
bmi @NEGATIVEVALUE
lsr ; Divide By 2
lsr ; Divide By 4
lsr ; Divide By 8
cmp XINDEXPOS
beq XPOSSAME
pha
lda XBARCHARACTERS
ora #$80
ldy #0
sta (XSCRNLOC),y
pla
XPOSSAME
sta XINDEXPOS
sta $0401
clc
adc #</1
sta XSCRNLOC
lda #0
adc #>/1
sta XSCRNLOC + 1
pla
and #$07
tay
iny
jmp @END
@NEGATIVEVALUE
eor #$FF
clc
adc #1
lsr
lsr
lsr
clc
adc #01
cmp XINDEXPOS
beq XPOSSAME1
pha
lda XBARCHARACTERS
ora #$80
ldy #0
sta (XSCRNLOC),y
pla
XPOSSAME1
sta XINDEXPOS
sta $0401
lda #</1
sec
sbc XINDEXPOS
sta XSCRNLOC
lda #>/1
sbc #0
sta XSCRNLOC + 1
pla
and #$07
tay
iny
@END
sty $0400
lda XBARCHARACTERS,y
ora #128
ldy #0
sta (SCRNLOC),y
endm
defm showXBar ; Start Screen Location, Offset value
clc
adc #/2 ; Adds Centre Ofset
pha ; Store Away Value Safely
lsr ; Divide By 2
lsr ; Divide By 4
lsr ; Divide By 8
cmp XINDEXPOS
beq XPOSSAME
pha ; Store Away New XINDEXPOS Temporarily
lda XBARCHARACTERS
ora #$80
ldy #0
sta (XSCRNLOC),y ; Blank out last location
pla ; Get back New XINDEXPOS
XPOSSAME
sta XINDEXPOS
sta $0401
clc
adc #</1
sta XSCRNLOC
lda #0
adc #>/1
sta XSCRNLOC + 1
pla
and #$07
tay
iny
sty $0400
lda XBARCHARACTERS,y
ora #128
ldy #0
sta (XSCRNLOC),y
endm
defm showYBar ; Start Screen Location, Offset value
clc
adc #/2 ; Adds Centre Ofset
pha ; Store Away Value Safely
lsr ; Divide By 2
lsr ; Divide By 4
lsr ; Divide By 8
cmp YINDEXPOS
beq YPOSSAME
pha ; Store Away New XINDEXPOS Temporarily
lda YBARCHARACTERS
ora #$80
ldy #0
sta (YSCRNLOC),y ; Blank out last location
pla ; Get back New XINDEXPOS
YPOSSAME
sta YINDEXPOS
tax
sta $0401
clc
lda #0
adc YSCREENOFFSETLO,x
sta YSCRNLOC
lda #0
adc YSCREENOFFSETHI,x
sta YSCRNLOC + 1
clc
lda YSCRNLOC
adc #</1
sta YSCRNLOC
lda YSCRNLOC + 1
adc #>/1
sta YSCRNLOC + 1
pla
and #$07
tay
iny
sty $0400
lda YBARCHARACTERS,y
ora #128
ldy #0
sta (YSCRNLOC),y
endm
defm showYGauge ; Start Screen Location, Offset value
clc
adc #/2 ; Adds Centre Offset
pha ; Store Away Value Safely
lsr ; Divide By 2
lsr ; Divide By 4
lsr ; Divide By 8
cmp YGAUGEINDEX ; Is new location same as old location?
beq YSAME ; Yes, then skip the next instructions
pha ; Store Away New XINDEXPOS Temporarily
lda YGAUGECHARACTERS; Get first character from GAUGE Character Set
;ora #$80
ldy #0
sta (YGAUGLOC),y ; Blank out last location
pla ; Get back New XINDEXPOS
YSAME
sta YGAUGEINDEX ; Store New Location
tax ; transfer to index register
clc
lda #0
adc YSCREENOFFSETLO,x ; Add screen row offset (lo)
sta YGAUGLOC ; store in pointer (lo)
lda #0
adc YSCREENOFFSETHI,x ; Add screen row offset (hi)
sta YGAUGLOC + 1 ; store in pointer (hi)
clc
lda YGAUGLOC ; Get screen pointer (lo)
adc #</1 ; Add screen location (lo)
sta YGAUGLOC ; Store back to pointer (lo)
lda YGAUGLOC + 1 ; Get screen pointer (hi)
adc #>/1 ; Add screen location (hi)
sta YGAUGLOC + 1 ; Store back pointer (hi)
pla ; Get back Value from stack
and #$07 ; mask off the 3 least significant bits (value/8)
tay ; Move to index register
iny ; add 1
lda YGAUGECHARACTERS,y ; Get corresponding YGaugeCharacter From Set
eor #$80 ; invert the character
ldy #0 ; init Y
sta (YGAUGLOC),y ; store character on screen
endm