-
Notifications
You must be signed in to change notification settings - Fork 0
/
raycasting-poc-1.s
219 lines (162 loc) · 6.61 KB
/
raycasting-poc-1.s
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
FNAME "raycasting-poc.rom" ; output file
PageSize: equ 0x4000 ; 16kB
; Compilation address
org 0x4000, 0x7fff ; 0x8000 can be also used here if Rom size is 16kB or less.
; Common
INCLUDE "Include/RomHeader.s"
INCLUDE "Include/MsxBios.s"
INCLUDE "Include/MsxConstants.s"
INCLUDE "Include/CommonRoutines.s"
; Default VRAM tables for Screen 4
NAMTBL: equ 0x1800 ; to 0x1aff (768 bytes)
PATTBL: equ 0x0000 ; to 0x17ff (6144 bytes)
COLTBL: equ 0x2000 ; to 0x37ff (6144 bytes)
SPRPAT: equ 0x3800 ; to 0x3fff (2048 bytes)
SPRCOL: equ 0x1c00 ; to 0x1dff (512 bytes)
SPRATR: equ 0x1e00 ; to 0x1e7f (128 bytes)
;SPRCOL_2: equ 0xfc00 ; to 0xfdff (512 bytes)
;SPRATR_2: equ 0xfe00 ; to 0xfe80 (128 bytes)
Execute:
; change to screen 4
ld a, 4
call BIOS_CHGMOD
call BIOS_DISSCR
call ClearVram_MSX2
call SetSprites16x16
call Set192Lines
call SetColor0ToNonTransparent
; Load tile patterns
ld a, 0000 0000 b
ld hl, PATTBL
call SetVdp_Write
ld b, TilePatterns.size
ld c, PORT_0
ld hl, TilePatterns
otir
ld a, 0000 0000 b
ld hl, PATTBL + (256 * 8)
call SetVdp_Write
ld b, TilePatterns.size
ld c, PORT_0
ld hl, TilePatterns
otir
; Load sprite colors
ld a, 0000 0000 b
ld hl, COLTBL
call SetVdp_Write
ld b, TileColors.size
ld c, PORT_0
ld hl, TileColors
otir
ld a, 0000 0000 b
ld hl, COLTBL + (256 * 8)
call SetVdp_Write
ld b, TileColors.size
ld c, PORT_0
ld hl, TileColors
otir
call BIOS_ENASCR
call BIOS_BEEP
GameLoop:
call Wait_Vblank
; ---------- Update NAMTBL
ld a, 0000 0000 b
ld hl, NAMTBL
call SetVdp_Write
;ld b, 32 * 16 ; only top 16 lines
ld c, PORT_0
ld hl, NAMTBL_Buffer
; 32 x 16 outi
outi outi outi outi outi outi outi outi outi outi outi outi outi outi outi outi outi outi outi outi outi outi outi outi outi outi outi outi outi outi outi outi
outi outi outi outi outi outi outi outi outi outi outi outi outi outi outi outi outi outi outi outi outi outi outi outi outi outi outi outi outi outi outi outi
outi outi outi outi outi outi outi outi outi outi outi outi outi outi outi outi outi outi outi outi outi outi outi outi outi outi outi outi outi outi outi outi
outi outi outi outi outi outi outi outi outi outi outi outi outi outi outi outi outi outi outi outi outi outi outi outi outi outi outi outi outi outi outi outi
outi outi outi outi outi outi outi outi outi outi outi outi outi outi outi outi outi outi outi outi outi outi outi outi outi outi outi outi outi outi outi outi
outi outi outi outi outi outi outi outi outi outi outi outi outi outi outi outi outi outi outi outi outi outi outi outi outi outi outi outi outi outi outi outi
outi outi outi outi outi outi outi outi outi outi outi outi outi outi outi outi outi outi outi outi outi outi outi outi outi outi outi outi outi outi outi outi
outi outi outi outi outi outi outi outi outi outi outi outi outi outi outi outi outi outi outi outi outi outi outi outi outi outi outi outi outi outi outi outi
outi outi outi outi outi outi outi outi outi outi outi outi outi outi outi outi outi outi outi outi outi outi outi outi outi outi outi outi outi outi outi outi
outi outi outi outi outi outi outi outi outi outi outi outi outi outi outi outi outi outi outi outi outi outi outi outi outi outi outi outi outi outi outi outi
outi outi outi outi outi outi outi outi outi outi outi outi outi outi outi outi outi outi outi outi outi outi outi outi outi outi outi outi outi outi outi outi
outi outi outi outi outi outi outi outi outi outi outi outi outi outi outi outi outi outi outi outi outi outi outi outi outi outi outi outi outi outi outi outi
outi outi outi outi outi outi outi outi outi outi outi outi outi outi outi outi outi outi outi outi outi outi outi outi outi outi outi outi outi outi outi outi
outi outi outi outi outi outi outi outi outi outi outi outi outi outi outi outi outi outi outi outi outi outi outi outi outi outi outi outi outi outi outi outi
outi outi outi outi outi outi outi outi outi outi outi outi outi outi outi outi outi outi outi outi outi outi outi outi outi outi outi outi outi outi outi outi
outi outi outi outi outi outi outi outi outi outi outi outi outi outi outi outi outi outi outi outi outi outi outi outi outi outi outi outi outi outi outi outi
; ld hl, Columns
; ld de, NAMTBL_Buffer
; ld bc, 16
; ldir
ld bc, Columns
ld hl, NAMTBL_Buffer
call DrawColumn
ld bc, Columns + (1 * 16)
ld hl, NAMTBL_Buffer + 1
call DrawColumn
ld bc, Columns + (2 * 16)
ld hl, NAMTBL_Buffer + 2
call DrawColumn
jp GameLoop
; read a seq of 16 bytes for column tile numbers and copy it to a column on NAMTBL buffer
; bc: ROM start addr of column (origin)
; hl: ROM start addr of NAMTBL buffer (destiny)
DrawColumn:
ld de, 32 ; screen width in tiles
ld ixl, 16
.loop: ; use macro to repeat 16 times (height of column)
ld a, (bc) ; 8
ld (hl), a ; 8
;inc bc ; 7
inc c ; 5 ; data should be table aligned
add hl, de ; 12
dec ixl
jp nz, .loop
ret
; ------------- Data:
Columns:
db 1, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 1
db 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0
db 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0
TilePatterns:
db 0000 0000 b
db 0000 0000 b
db 0000 0000 b
db 0000 0000 b
db 0000 0000 b
db 0000 0000 b
db 0000 0000 b
db 0000 0000 b
db 1111 1111 b
db 1111 1111 b
db 1111 1111 b
db 1111 1111 b
db 1111 1111 b
db 1111 1111 b
db 1111 1111 b
db 1111 1111 b
.size: equ $ - TilePatterns
TileColors:
db 0xf0
db 0xf0
db 0xf0
db 0xf0
db 0xf0
db 0xf0
db 0xf0
db 0xf0
db 0xf0
db 0xf0
db 0xf0
db 0xf0
db 0xf0
db 0xf0
db 0xf0
db 0xf0
.size: equ $ - TileColors
ds PageSize - ($ - 0x4000), 255 ; Fill the unused area with 0xFF
; ----------------- Variables
org 0xc000
; CAUTION: this buffer needs to be table aligned
NAMTBL_Buffer: rb 32 * 16 ; only upper 2/3 of the screen
Seed: rw 1 ; Seed for random number generator
;OldSP: rw 1