-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdisplay.asm
481 lines (344 loc) · 9.62 KB
/
display.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
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
!zone screen:
.ViewMode !byte 0 ; Game view mode (0=2D, 1=3D)
.Column !byte 0
.DrawTop !byte 0 ; Top row
.DrawBottom !byte 0 ; Bottom row
.EndRow !byte 0
.ChrBuffer !byte 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
!zone displayEvents
; ********************************************************************************
; DISPLAY EVENTS
;
; Description: Manage display events
; ********************************************************************************
displayEvents:
lda screen.ViewMode
bne .is3D
; 2D display
jsr movePlayerSpr ; Move player sprite
jsr moveDirSpr ; Move direction spriteData
lda player.Heading
sta rayHeading
lda player.Heading+1
sta rayHeading+1
jsr rayCast
jmp moveRaySpr
; 3D display
.is3D jsr rayScan
jsr drawScreen
jsr moveBackSpr
rts
!zone setViewMode
; ********************************************************************************
; SET VIEW MODE
;
; Description: Set display view mode. 0=2d, 1=3d
; ********************************************************************************
setViewMode
sta screen.ViewMode
bne .set_3D
; Set 2D mode
; Set player movement speed
lda #1
sta player.MovSpeed ; Movement speed multiplier as power of 2
lda #1
sta player.RotSpeed ; Rotation speed in Ticks
; Enable sprites
lda #%00000111 ; Enable sprites 0 to 2
sta SPRITE_ENABLE
; Set interrupt routine
lda #BLACK
sta setInterrupt.scanColor1
sta setInterrupt.scanColor2
lda #50
sta setInterrupt.scanLine1
lda #250
sta setInterrupt.scanLine2
; Show map
jmp showMap
; Set 3D mode
; Set player movement speed
.set_3D lda #6
sta player.MovSpeed ; Movement speed multiplier as power of 2
lda #32
sta player.RotSpeed ; Rotation speed in Ticks
; Enable sprites
lda #%00111000 ; Enable sprites 3 to 5
sta SPRITE_ENABLE
; Set interrupt routine
lda #CYAN
sta setInterrupt.scanColor1
lda #GREEN
sta setInterrupt.scanColor2
lda #0
sta setInterrupt.scanLine1
lda #151
sta setInterrupt.scanLine2
rts
!zone showMap
; ********************************************************************************
; SHOW MAP
;
; Description: Show map on screen
; ********************************************************************************
showMap lda #<map ; Copy map
sta CL
lda #>map
sta CH
lda #<SCREEN_RAM
sta DL
lda #>SCREEN_RAM
sta DH
lda #$e8 ; size of memory block
ldx #$03
jsr memCopy
; Copy color information
showColor lda #<colorMap
sta CL
lda #>colorMap
sta CH
lda #<COLOR_RAM
sta DL
lda #>COLOR_RAM
sta DH
lda #$e8 ; size of memory block
ldx #$03
jmp memCopy
!zone drawScreen
; ******************************************************************************
; DRAW SCREEN
; ******************************************************************************
drawScreen: ldy #0
.loop sty screen.Column
lda zBuffer.lo,y ; n = int(ZBuffer(column) * 8)
sta B
lda zBuffer.hi,y
asl B
rol
asl B
rol
tax ; drawStart = tblWallTop(n)
lda wallTop,x
sta screen.DrawTop
lda #49 ; drawEnd = 49 - drawStart
sec
sbc screen.DrawTop
sta screen.DrawBottom
; If rayCounter is odd then do the right column
lda screen.Column
lsr
bcs .right
; Draw the left column
jsr drawLeft
jmp .next
; Draw the right column
.right jsr drawRight
jsr printColumn
; Loop
.next ldy screen.Column
iny
cpy #80
bcc .loop
rts
!zone drawLeft
; ********************************************************************
; DRAW LEFT COLUMN
; ********************************************************************
drawLeft ; Fast buffer clear routine
lda #0
sta screen.ChrBuffer
sta screen.ChrBuffer+1
sta screen.ChrBuffer+2
sta screen.ChrBuffer+3
sta screen.ChrBuffer+4
sta screen.ChrBuffer+5
sta screen.ChrBuffer+6
sta screen.ChrBuffer+7
sta screen.ChrBuffer+8
sta screen.ChrBuffer+9
sta screen.ChrBuffer+10
sta screen.ChrBuffer+11
sta screen.ChrBuffer+12
sta screen.ChrBuffer+13
sta screen.ChrBuffer+14
sta screen.ChrBuffer+15
sta screen.ChrBuffer+16
sta screen.ChrBuffer+17
sta screen.ChrBuffer+18
sta screen.ChrBuffer+19
sta screen.ChrBuffer+20
sta screen.ChrBuffer+21
sta screen.ChrBuffer+22
sta screen.ChrBuffer+23
sta screen.ChrBuffer+24
; 0. Clear the column
; 1. Draw bottom break character at correct position
; 2. Draw top break character at correct psition
; 3. Fill from the top to bottom break characters with the full column character
; Prepare characters
lda screen.DrawBottom ; n = drawEnd / 2
lsr ; endRow = n
tax ; If drawEnd is odd then Carry = 1
sta screen.EndRow ; Actual screen row [0 to 24]
lda #10 ; 10 = Full left column ■□
bcs .full_btm ; If drawEnd is odd then draw a full column char. ■□
; Prepare bottom left character
lda #8 ; 8 = partial bottom char ■□
; □□
.full_btm sta screen.ChrBuffer,x
; Draw top break
lda screen.DrawTop
lsr ; If drawStart is odd then Carry = 1
tax ; Store draw start row into X register
bcc .full_top ; If drawStart is even then draw a full column char.
lda #2 ; □□
bne .not_full ; ■□
; Loop from start row to end row and fill with the full char
.full_top lda #10
.not_full sta screen.ChrBuffer,x
inx
cpx screen.EndRow
bne .full_top
rts
!zone drawRight
; ********************************************************************
; DRAW RIGHT COLUMN
; ********************************************************************
drawRight ; Draw bottom right break
lda screen.DrawBottom
lsr
tax
sta screen.EndRow
lda #5
bcs .full_btm
lda #4
.full_btm ora screen.ChrBuffer,x
sta screen.ChrBuffer,x
; Draw top right break
lda screen.DrawTop
lsr
tax // Store start row into the X register
bcc .full_top
lda #1
bne .not_full
; Draw the rest
.full_top lda #5
.not_full ora screen.ChrBuffer,x
sta screen.ChrBuffer,x
inx
cpx screen.EndRow
bne .full_top
rts
!zone printColumn
; ********************************************************************
; PRINT COLUMN
; ********************************************************************
printColumn:
lda screen.Column
lsr
tax
ldy screen.ChrBuffer
lda PETscii,y
sta SCREEN_RAM+0*40,x
ldy screen.ChrBuffer+1
lda PETscii,y
sta SCREEN_RAM+1*40,x
ldy screen.ChrBuffer+2
lda PETscii,y
sta SCREEN_RAM+2*40,x
ldy screen.ChrBuffer+3
lda PETscii,y
sta SCREEN_RAM+3*40,x
ldy screen.ChrBuffer+4
lda PETscii,y
sta SCREEN_RAM+4*40,x
ldy screen.ChrBuffer+5
lda PETscii,y
sta SCREEN_RAM+5*40,x
ldy screen.ChrBuffer+6
lda PETscii,y
sta SCREEN_RAM+6*40,x
ldy screen.ChrBuffer+7
lda PETscii,y
sta SCREEN_RAM+7*40,x
ldy screen.ChrBuffer+8
lda PETscii,y
sta SCREEN_RAM+8*40,x
ldy screen.ChrBuffer+9
lda PETscii,y
sta SCREEN_RAM+9*40,x
ldy screen.ChrBuffer+10
lda PETscii,y
sta SCREEN_RAM+10*40,x
ldy screen.ChrBuffer+11
lda PETscii,y
sta SCREEN_RAM+11*40,x
ldy screen.ChrBuffer+12
lda PETscii,y
sta SCREEN_RAM+12*40,x
ldy screen.ChrBuffer+13
lda PETscii,y
sta SCREEN_RAM+13*40,x
ldy screen.ChrBuffer+14
lda PETscii,y
sta SCREEN_RAM+14*40,x
ldy screen.ChrBuffer+15
lda PETscii,y
sta SCREEN_RAM+15*40,x
ldy screen.ChrBuffer+16
lda PETscii,y
sta SCREEN_RAM+16*40,x
ldy screen.ChrBuffer+17
lda PETscii,y
sta SCREEN_RAM+17*40,x
ldy screen.ChrBuffer+18
lda PETscii,y
sta SCREEN_RAM+18*40,x
ldy screen.ChrBuffer+19
lda PETscii,y
sta SCREEN_RAM+19*40,x
ldy screen.ChrBuffer+20
lda PETscii,y
sta SCREEN_RAM+20*40,x
ldy screen.ChrBuffer+21
lda PETscii,y
sta SCREEN_RAM+21*40,x
ldy screen.ChrBuffer+22
lda PETscii,y
sta SCREEN_RAM+22*40,x
ldy screen.ChrBuffer+23
lda PETscii,y
sta SCREEN_RAM+23*40,x
ldy screen.ChrBuffer+24
lda PETscii,y
sta SCREEN_RAM+24*40,x
; Fast Draw Color
; ldx screen.column
lda colorBuffer,x
sta COLOR_RAM+0*40,x
sta COLOR_RAM+1*40,x
sta COLOR_RAM+2*40,x
sta COLOR_RAM+3*40,x
sta COLOR_RAM+4*40,x
sta COLOR_RAM+5*40,x
sta COLOR_RAM+6*40,x
sta COLOR_RAM+7*40,x
sta COLOR_RAM+8*40,x
sta COLOR_RAM+9*40,x
sta COLOR_RAM+10*40,x
sta COLOR_RAM+11*40,x
sta COLOR_RAM+12*40,x
sta COLOR_RAM+13*40,x
sta COLOR_RAM+14*40,x
sta COLOR_RAM+15*40,x
sta COLOR_RAM+16*40,x
sta COLOR_RAM+17*40,x
sta COLOR_RAM+18*40,x
sta COLOR_RAM+19*40,x
sta COLOR_RAM+20*40,x
sta COLOR_RAM+21*40,x
sta COLOR_RAM+22*40,x
sta COLOR_RAM+23*40,x
sta COLOR_RAM+24*40,x
rts