-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathviewhandler.asm
executable file
·373 lines (341 loc) · 5.56 KB
/
viewhandler.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
//.pc = $6200 "View handler"
.pc = characterEnd+1 "View handler"
drawView:
{
// Clear variables!
lda #00
sta variables
sta variables+1
sta variables+2
sta variables+3
sta variables+4
sta variables+5
sta variables+6
sta variables+7
sta viewRange // Null current
// Store player location to temporary variables
ldx playerX
ldy playerY
stx midX
sty midY
jsr calcLeft
jsr calcRight
lda #00
sta leftWasClear
sta rightWasClear
lda #01
sta viewBlocked
lda playerFacing
cmp #01
beq viewNorth
cmp #02
beq viewWest
cmp #03
beq viewSouth
viewEast:
dec leftY
inc rightY
inc aheadX
jmp drawCorrectView
viewNorth:
dec leftX
inc rightX
dec aheadY
jmp drawCorrectView
viewWest:
inc leftY
dec rightY
dec aheadX
jmp drawCorrectView
viewSouth:
inc leftX
dec rightX
inc aheadY
jmp drawCorrectView
drawCorrectView:
// Player's square, sides
// Calculate correct xy for left side
jsr updateScalingFactor
handleFront:
jmp drawFront // <- !!! Notice the jmp!!!
handleLeft:
jmp drawLeft
handleRight:
jmp drawRight
allDrawn:
// Move ahead
jsr middleAhead
jsr leftAhead
jsr rightAhead
inc viewRange
lda viewRange
cmp #08
beq viewDone
lda viewBlocked
beq viewDone
jmp drawCorrectView
viewDone:
rts
// Calculate initial left side coordinates
calcLeft:
clc
lda playerX
adc leftX
sta leftX
clc
lda playerY
adc leftY
sta leftY
rts
// Calculate initial right side coordinates
calcRight:
clc
lda playerX
adc rightX
sta rightX
clc
lda playerY
adc rightY
sta rightY
rts
// Advance middle coordinates by one square
middleAhead:
clc
lda midX
adc aheadX
sta midX
clc
lda midY
adc aheadY
sta midY
rts
// Advance left coordinates by one square
leftAhead:
clc
lda leftX
adc aheadX
sta leftX
clc
lda leftY
adc aheadY
sta leftY
rts
// Advance right coordinates by one square
rightAhead:
clc
lda rightX
adc aheadX
sta rightX
clc
lda rightY
adc aheadY
sta rightY
rts
drawFront:
{
:checkMiddleWall
bcc jump
cmp #03
beq laddersUp
cmp #04
beq laddersDown
ldx viewRange
beq jump
cmp #01
beq wall
cmp #02
beq door
jump: jmp handleLeft
door:
:drawScaled #frontDoor
wall:
:drawScaled #frontWall
rts
laddersUp:
:drawLaddersUp
jmp handleLeft
laddersDown:
:drawLaddersDown
end: jmp handleLeft
}
drawLeft:
{
:checkLeftWall
bcc leftClear
skip1: cmp #01
beq wall
cmp #02
beq door
cmp #03
beq leftClear
cmp #04
beq leftClear
door: :drawLeftDoor
wall: :drawLeftWall
lda #00
sta leftWasClear
jmp drawRight
leftClear:
lda leftWasClear
bne skip2
lda viewRange
cmp #00
beq skip2
:drawScaled #lineHorizontalLeft
skip2: lda #01
sta leftWasClear
:drawLeftClear
jmp handleRight
}
drawRight:
{
:checkRightWall
bcc rightClear
cmp #01
beq wall
cmp #02
beq door
cmp #03
beq rightClear
cmp #04
beq rightClear
door: :drawRightDoor
wall: :drawRightWall
// :drawRightWall
lda #00
sta rightWasClear
jmp allDrawn
rightClear:
// :drawScaled #rightClear
lda rightWasClear
bne skip3
lda viewRange
cmp #00
beq skip3
:drawScaled #lineHorizontalRight
skip3: lda #01
sta leftWasClear
:drawRightClear
jmp allDrawn
}
.pseudocommand checkMiddleWall {
ldx midX
ldy midY
jsr CheckCollision
}
.pseudocommand checkLeftWall {
ldx leftX
ldy leftY
jsr CheckCollision
}
.pseudocommand checkRightWall {
ldx rightX
ldy rightY
jsr CheckCollision
}
}
updateScalingFactor:
{
lda viewRange
beq set0
cmp #01
beq set1
cmp #02
beq set2
cmp #03
beq set3
cmp #04
beq set4
cmp #05
beq set5
cmp #06
beq set6
cmp #07
beq set7
jmp set8
set0: :setScalingFactor(100, 0, 0) // Scale 1
rts
set1: :setScalingFactor(75, 40, 20) // Scale 0.75
rts
set2: :setScalingFactor(56, 70, 35)
rts
set3: :setScalingFactor(42, 93, 46)
rts
set4: :setScalingFactor(31, 110, 55)
rts
set5: :setScalingFactor(23, 123, 62)
rts
set6: :setScalingFactor(17, 132, 66)
rts
set7: :setScalingFactor(13, 139, 69)
rts
set8: :setScalingFactor(10, 145, 71)
rts
}
//.pc = $6800
viewRange: .byte 0, 0
scalingFactor: .byte 0, 0
offsetX: .byte 0, 0
offsetY: .byte 0, 0
//.pc = $6820
variables:
midX: .byte 0
midY: .byte 0
leftX: .byte 0
leftY: .byte 0
rightX: .byte 0
rightY: .byte 0
aheadX: .byte 0
aheadY: .byte 0
viewBlocked:
.byte 0
leftWasClear:
.byte 0
rightWasClear:
.pseudocommand drawRightWall {
:drawScaled #lineNE
:drawScaled #lineSE
}
.pseudocommand drawRightClear {
:drawScaled #lineVerticalTopEast
:drawScaled #lineVerticalBottomEast
}
.pseudocommand drawRightDoor {
:drawScaled #rightDoorTop
:drawScaled #rightDoorLeftSide
:drawScaled #rightDoorRightSide
}
.pseudocommand drawLeftWall {
:drawScaled #lineNW
:drawScaled #lineSW
}
.pseudocommand drawLeftClear {
:drawScaled #lineVerticalTopWest
:drawScaled #lineVerticalBottomWest
}
.pseudocommand drawLeftDoor {
:drawScaled #leftDoorTop
:drawScaled #leftDoorLeftSide
:drawScaled #leftDoorRightSide
}
.pseudocommand drawLaddersUp {
:drawScaled #topHatch
:drawScaled #laddersLeftLine
:drawScaled #laddersRightLine
:drawScaled #laddersFirstStep
:drawScaled #laddersSecondStep
:drawScaled #laddersThirdStep
:drawScaled #laddersFourthStep
}
.pseudocommand drawLaddersDown {
:drawScaled #floorHatch
}
.macro setScalingFactor(scale, offx, offy) {
lda #scale
sta scalingFactor
lda #offx
sta offsetX
lda #offy
sta offsetY
}
viewhandlerEnd: nop