-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathbitmap_scanline_renderer_320x240.s
371 lines (285 loc) · 12.4 KB
/
bitmap_scanline_renderer_320x240.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
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
/*
* P8X Game System
* Video Scanline Renderer
*
* 256 or 320 horizontal pixels lines
* 6-bits per pixels (direct palette)
* 8x8 pixels tiles
* 8x8 up to 32x32 pixels sprites
* Full-screen scrolling
*
* Copyright (c) 2015-2018 Marco Maccaferri
* MIT Licensed.
*/
.pasm
.compress off
.equ H_RES, 320
.equ V_RES, 240
.equ SBUF_OFS, 0
.section .cog_bitmap_scanline_renderer_320x240, "ax"
.org 0
mov offset, PAR
shr offset, #2
and offset, #$7
vsync
rdlong a, hub_fi wz
if_nz jmp #$-1 // wait for line counter reset (vsync)
mov sbuf_ptr, hub_palette
rdbyte palette, sbuf_ptr
add sbuf_ptr, #1
rdbyte palette+1, sbuf_ptr
add sbuf_ptr, #1
rdbyte palette+2, sbuf_ptr
add sbuf_ptr, #1
rdbyte palette+3, sbuf_ptr
add sbuf_ptr, #1
rdbyte palette+4, sbuf_ptr
add sbuf_ptr, #1
rdbyte palette+5, sbuf_ptr
add sbuf_ptr, #1
rdbyte palette+6, sbuf_ptr
add sbuf_ptr, #1
rdbyte palette+7, sbuf_ptr
mov scnt, offset
// bitmap
loop
mov loffs, scnt
mov video_ptr, loffs
shl video_ptr, #7
mov ecnt, #32
movd str0, #sbuf
movd str1, #sbuf+1
movd str2, #sbuf+2
movd str3, #sbuf+3
movd str4, #sbuf+4
_l1 rdword pixels1, video_ptr
add video_ptr, #2
mov a, pixels1
and a, #$07
add a, #palette
movs _mv4, a
shr pixels1, #3
mov a, pixels1
and a, #$07
add a, #palette
movs _mv3, a
shr pixels1, #3
mov a, pixels1
and a, #$07
add a, #palette
movs _mv2, a
shr pixels1, #3
mov a, pixels1
and a, #$07
add a, #palette
movs _mv1, a
shr pixels1, #3
mov a, pixels1
and a, #$07
add a, #palette
movs _mv8, a
rdword pixels1, video_ptr
add video_ptr, #2
mov a, pixels1
and a, #$07
add a, #palette
movs _mv7, a
shr pixels1, #3
mov a, pixels1
and a, #$07
add a, #palette
movs _mv6, a
shr pixels1, #3
mov a, pixels1
and a, #$07
add a, #palette
movs _mv5, a
shr pixels1, #3
mov a, pixels1
and a, #$07
add a, #palette
movs _mv12, a
shr pixels1, #3
mov a, pixels1
and a, #$07
add a, #palette
movs _mv11, a
rdword pixels1, video_ptr
add video_ptr, #2
mov a, pixels1
and a, #$07
add a, #palette
movs _mv10, a
shr pixels1, #3
mov a, pixels1
and a, #$07
add a, #palette
movs _mv9, a
shr pixels1, #3
mov a, pixels1
and a, #$07
add a, #palette
movs _mv16, a
shr pixels1, #3
mov a, pixels1
and a, #$07
add a, #palette
movs _mv15, a
shr pixels1, #3
mov a, pixels1
and a, #$07
add a, #palette
movs _mv14, a
rdword pixels1, video_ptr
add video_ptr, #2
mov a, pixels1
and a, #$07
add a, #palette
movs _mv13, a
shr pixels1, #3
mov a, pixels1
and a, #$07
add a, #palette
movs _mv20, a
shr pixels1, #3
mov a, pixels1
and a, #$07
add a, #palette
movs _mv19, a
shr pixels1, #3
mov a, pixels1
and a, #$07
add a, #palette
movs _mv18, a
shr pixels1, #3
mov a, pixels1
and a, #$07
add a, #palette
movs _mv17, a
_mv1 mov colors1, 0-0
shl colors1, #8
_mv2 or colors1, 0-0
shl colors1, #8
_mv3 or colors1, 0-0
shl colors1, #8
_mv4 or colors1, 0-0
str0 mov 0-0, colors1
add str0, inc_dest_5
_mv5 mov colors1, 0-0
shl colors1, #8
_mv6 or colors1, 0-0
shl colors1, #8
_mv7 or colors1, 0-0
shl colors1, #8
_mv8 or colors1, 0-0
str1 mov 0-0, colors1
add str1, inc_dest_5
_mv9 mov colors1, 0-0
shl colors1, #8
_mv10 or colors1, 0-0
shl colors1, #8
_mv11 or colors1, 0-0
shl colors1, #8
_mv12 or colors1, 0-0
str2 mov 0-0, colors1
add str2, inc_dest_5
_mv13 mov colors1, 0-0
shl colors1, #8
_mv14 or colors1, 0-0
shl colors1, #8
_mv15 or colors1, 0-0
shl colors1, #8
_mv16 or colors1, 0-0
str3 mov 0-0, colors1
add str3, inc_dest_5
_mv17 mov colors1, 0-0
shl colors1, #8
_mv18 or colors1, 0-0
shl colors1, #8
_mv19 or colors1, 0-0
shl colors1, #8
_mv20 or colors1, 0-0
str4 mov 0-0, colors1
add str4, inc_dest_5
djnz ecnt, #_l1
// scanline buffer output
emit
rdlong a, hub_fi
cmp a, scnt wz,wc
if_ne jmp #$-2 // wait for line fetch start
mov sbuf_ptr, hub_sbuf
wrlong sbuf, sbuf_ptr
add sbuf_ptr, #4
wrlong sbuf + 1, sbuf_ptr
add sbuf_ptr, #4
wrlong sbuf + 2, sbuf_ptr
add sbuf_ptr, #4
wrlong sbuf + 3, sbuf_ptr
add sbuf_ptr, #4
wrlong sbuf + 4, sbuf_ptr
add sbuf_ptr, #4
wrlong sbuf + 5, sbuf_ptr
add sbuf_ptr, #4
wrlong sbuf + 6, sbuf_ptr
add sbuf_ptr, #4
wrlong sbuf + 7, sbuf_ptr
add sbuf_ptr, #4
wrlong sbuf + 8, sbuf_ptr
add sbuf_ptr, #4
wrlong sbuf + 9, sbuf_ptr
add sbuf_ptr, #4
movd _wr0, #sbuf +(H_RES/4) -1
movd _wr1, #sbuf +(H_RES/4) -2
add sbuf_ptr, #(H_RES-40) -1
movi sbuf_ptr, #((H_RES/4)-10) -2
_wr0 wrlong 0-0, sbuf_ptr
sub _wr0, inc_dest_2
sub sbuf_ptr, i2s7 wc
_wr1 wrlong 0-0, sbuf_ptr
sub _wr1, inc_dest_2
if_nc djnz sbuf_ptr, #_wr0
add scnt, #COGS // next line to render
cmp scnt, #V_RES wc,wz
if_b jmp #loop
jmp #vsync
// driver parameters
hub_video_ram long $0000
hub_palette long $7800
hub_fi long $7EBC
hub_sbuf long $7EC0 + SBUF_OFS
// initialised data and/or presets
inc_dest long 1 << 9
inc_dest_2 long 2 << 9
inc_dest_5 long 5 << 9
i2s7 long 2 << 23 | 7
pixels1 long 0
colors1 long 0
palette long $00, $C0, $30, $F0, $0C, $CC, $3C, $FC
// uninitialised data and/or temporaries
a res 1
data1 res 1
data2 res 1
offset res 1
loffs res 1
ecnt res 1
scnt res 1
video_ptr res 1
// code and/or data repurposed for scanline buffer
sbuf_ptr res 1
sbuf
fit $1F0
/*
* TERMS OF USE: MIT License
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation
* files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy,
* modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software
* is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
* WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
* ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/