-
Notifications
You must be signed in to change notification settings - Fork 1
/
planar.asm
562 lines (516 loc) · 10.2 KB
/
planar.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
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
;
; Copyright (C) 1993-1996 Id Software, Inc.
; Copyright (C) 2023 Frenkel Smeijers
;
; This program is free software; you can redistribute it and/or
; modify it under the terms of the GNU General Public License
; as published by the Free Software Foundation; either version 2
; of the License, or (at your option) any later version.
;
; This program is distributed in the hope that it will be useful,
; but WITHOUT ANY WARRANTY; without even the implied warranty of
; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
; GNU General Public License for more details.
;
; You should have received a copy of the GNU General Public License
; along with this program. If not, see <https://www.gnu.org/licenses/>.
;
cpu 386
PLANEWIDTH equ 80
SC_INDEX equ 0x3c4
extern _dc_colormap
extern _dc_x
extern _dc_yl
extern _dc_yh
extern _dc_iscale
extern _dc_texturemid
extern _dc_source
extern _ds_y
extern _ds_x1
extern _ds_x2
extern _ds_colormap
extern _ds_xfrac
extern _ds_yfrac
extern _ds_xstep
extern _ds_ystep
extern _ds_source
extern _destview
extern _centery
;============================================================================
;
; unwound vertical scaling code
;
; eax light table pointer, 0 lowbyte overwritten
; ebx all 0, low byte overwritten
; ecx fractional step value
; edx fractional scale value
; esi start of source pixels
; edi bottom pixel in screenbuffer to blit into
;
; ebx should be set to 0 0 0 dh to feed the pipeline
;
; The graphics wrap vertically at 128 pixels
;============================================================================
%ifidn __OUTPUT_FORMAT__, coff
section .bss public class=DATA USE32
%elifidn __OUTPUT_FORMAT__, obj
section _BSS public class=DATA USE32
%endif
loopcount resd 1
pixelcount resd 1
;=================================
%ifidn __OUTPUT_FORMAT__, coff
section .text public class=CODE USE32
%elifidn __OUTPUT_FORMAT__, obj
section _TEXT public class=CODE USE32
%endif
;================
;
; R_DrawColumn
;
;================
global _R_DrawColumnLow
_R_DrawColumnLow:
pushad
mov ebp,[_dc_yl]
cmp ebp,[_dc_yh]
jg done
lea edi,[ebp+ebp*4]
shl edi,4
mov ebx,[_dc_x]
mov ecx,ebx
shr ebx,1
add edi,ebx
add edi,[_destview]
and ecx,1
shl ecx,1
mov eax,3
shl eax,cl
mov edx,SC_INDEX+1
out dx,al
jmp cdraw
global _R_DrawColumn
_R_DrawColumn:
pushad
mov ebp,[_dc_yl]
cmp ebp,[_dc_yh]
jg done
lea edi,[ebp+ebp*4]
shl edi,4
mov ebx,[_dc_x]
mov ecx,ebx
shr ebx,2
add edi,ebx
add edi,[_destview]
and ecx,3
mov eax,1
shl eax,cl
mov edx,SC_INDEX+1
out dx,al
cdraw:
mov eax,[_dc_yh]
inc eax
sub eax,ebp ; pixel count
mov [pixelcount],eax ; save for final pixel
js done ; nothing to scale
shr eax,1 ; double pixel count
mov [loopcount],eax
mov ecx,[_dc_iscale]
mov eax,[_centery]
sub eax,ebp
imul ecx
mov ebp,[_dc_texturemid]
sub ebp,eax
shl ebp,9 ; 7 significant bits, 25 frac
mov esi,[_dc_source]
mov ebx,[_dc_iscale]
shl ebx,9
mov eax,patch1+2 ; convice nasm to modify code...
mov [eax],ebx
mov eax,patch2+2 ; convice nasm to modify code...
mov [eax],ebx
; eax aligned colormap
; ebx aligned colormap
; ecx,edx scratch
; esi virtual source
; edi moving destination pointer
; ebp frac
mov ecx,ebp ; begin calculating first pixel
add ebp,ebx ; advance frac pointer
shr ecx,25 ; finish calculation for first pixel
mov edx,ebp ; begin calculating second pixel
add ebp,ebx ; advance frac pointer
shr edx,25 ; finish calculation for second pixel
mov eax,[_dc_colormap]
mov ebx,eax
mov al,[esi+ecx] ; get first pixel
mov bl,[esi+edx] ; get second pixel
mov al,[eax] ; color translate first pixel
mov bl,[ebx] ; color translate second pixel
test [pixelcount],dword 0fffffffeh
jnz doubleloop ; at least two pixels to map
jmp checklast
doubleloop:
mov ecx,ebp ; begin calculating third pixel
patch1:
add ebp,12345678h ; advance frac pointer
mov [edi],al ; write first pixel
shr ecx,25 ; finish calculation for third pixel
mov edx,ebp ; begin calculating fourth pixel
patch2:
add ebp,12345678h ; advance frac pointer
mov [edi+PLANEWIDTH],bl ; write second pixel
shr edx,25 ; finish calculation for fourth pixel
mov al,[esi+ecx] ; get third pixel
add edi,PLANEWIDTH*2 ; advance to third pixel destination
mov bl,[esi+edx] ; get fourth pixel
dec dword [loopcount] ; done with loop?
mov al,[eax] ; color translate third pixel
mov bl,[ebx] ; color translate fourth pixel
jnz doubleloop
checklast:
test [pixelcount],dword 1
jz done
mov [edi],al
done:
popad
ret
;============================================================================
;
; unwound horizontal texture mapping code
;
; eax lighttable
; ebx scratch register
; ecx position 6.10 bits x, 6.10 bits y
; edx step 6.10 bits x, 6.10 bits y
; esi start of block
; edi dest
; ebp fff to mask bx
;
; ebp should by preset from ebx / ecx before calling
;============================================================================
%ifidn __OUTPUT_FORMAT__, coff
section .bss
%elifidn __OUTPUT_FORMAT__, obj
section _BSS
%endif
dest resd 1
endplane resd 1
curplane resd 1
frac resd 1
fracstep resd 1
fracpstep resd 1
curx resd 1
curpx resd 1
endpx resd 1
%ifidn __OUTPUT_FORMAT__, coff
section .text
%elifidn __OUTPUT_FORMAT__, obj
section _TEXT
%endif
;================
;
; R_DrawSpan
;
; Horizontal texture mapping
;
;================
global _R_DrawSpan
_R_DrawSpan:
pushad
mov eax,[_ds_x1]
mov [curx],eax
mov ebx,eax
and ebx,3
mov [endplane],ebx
mov [curplane],ebx
shr eax,2
mov ebp,[_ds_y]
lea edi,[ebp+ebp*4]
shl edi,4
add edi,eax
add edi,[_destview]
mov [dest],edi
mov ebx,[_ds_xfrac]
shl ebx,10
and ebx,0ffff0000h
mov eax,[_ds_yfrac]
shr eax,6
and eax,0ffffh
or ebx,eax
mov [frac],ebx
mov ebx,[_ds_xstep]
shl ebx,10
and ebx,0ffff0000h
mov eax,[_ds_ystep]
shr eax,6
and eax,0ffffh
or ebx,eax
mov [fracstep],ebx
shl ebx,2
mov [fracpstep],ebx
mov eax,hpatch1+2
mov [eax],ebx
mov eax,hpatch2+2
mov [eax],ebx
mov ecx,[curplane]
hplane:
mov eax,1
shl eax,cl
mov edx,SC_INDEX+1
out dx,al
mov eax,[_ds_x2]
cmp eax,[curx]
jb hdone
sub eax,[curplane]
js hdoneplane
shr eax,2
mov [endpx],eax
dec eax
js hfillone
shr eax,1
mov ebx,[curx]
shr ebx,2
cmp ebx,[endpx]
jz hfillone
mov [curpx],ebx
inc ebx
shr ebx,1
inc eax
sub eax,ebx
js hdoneplane
mov [loopcount],eax
mov eax,[_ds_colormap]
mov ebx,eax
mov esi,[_ds_source]
mov edi,[dest]
mov ebp,[frac]
test [curpx],dword 1
jz hfill
shld ecx,ebp,22
shld ecx,ebp,6
add ebp,[fracpstep]
and ecx,0fffh
mov al,[esi+ecx]
mov dl,[eax]
mov [edi],dl
inc edi
jz hdoneplane
hfill:
shld ecx,ebp,22
shld ecx,ebp,6
add ebp,[fracpstep]
and ecx,0fffh
shld edx,ebp,22
shld edx,ebp,6
add ebp,[fracpstep]
and edx,0fffh
mov al,[esi+ecx]
mov bl,[esi+edx]
mov dl,[eax]
test [loopcount],dword 0ffffffffh
jnz hdoubleloop
jmp hchecklast
hfillone:
mov eax,[_ds_colormap]
mov esi,[_ds_source]
mov edi,[dest]
mov ebp,[frac]
shld ecx,ebp,22
shld ecx,ebp,6
and ecx,0fffh
mov al,[esi+ecx]
mov dl,[eax]
mov [edi],dl
jmp hdoneplane
hdoubleloop:
shld ecx,ebp,22
mov dh,[ebx]
shld ecx,ebp,6
hpatch1:
add ebp,12345678h
and ecx,0fffh
mov [edi],dx
shld edx,ebp,22
add edi,2
shld edx,ebp,6
hpatch2:
add ebp,12345678h
and edx,0fffh
mov al,[esi+ecx]
mov bl,[esi+edx]
dec dword [loopcount]
mov dl,[eax]
jnz hdoubleloop
hchecklast:
test [endpx],dword 1
jnz hdoneplane
mov [edi],dl
hdoneplane:
mov ecx,[curplane]
inc ecx
and ecx,3
jnz hskip
inc dword [dest]
hskip:
cmp ecx,[endplane]
jz hdone
mov [curplane],ecx
mov ebx,[frac]
add ebx,[fracstep]
mov [frac],ebx
inc dword [curx]
jmp hplane
hdone:
popad
ret
global _R_DrawSpanLow
_R_DrawSpanLow:
pushad
mov eax,[_ds_x1]
mov [curx],eax
mov ebx,eax
and ebx,1
mov [endplane],ebx
mov [curplane],ebx
shr eax,1
mov ebp,[_ds_y]
lea edi,[ebp+ebp*4]
shl edi,4
add edi,eax
add edi,[_destview]
mov [dest],edi
mov ebx,[_ds_xfrac]
shl ebx,10
and ebx,0ffff0000h
mov eax,[_ds_yfrac]
shr eax,6
and eax,0ffffh
or ebx,eax
mov [frac],ebx
mov ebx,[_ds_xstep]
shl ebx,10
and ebx,0ffff0000h
mov eax,[_ds_ystep]
shr eax,6
and eax,0ffffh
or ebx,eax
mov [fracstep],ebx
shl ebx,1
mov [fracpstep],ebx
mov eax,lpatch1+2
mov [eax],ebx
mov eax,lpatch2+2
mov [eax],ebx
mov ecx,[curplane]
lplane:
mov eax,3
shl eax,cl
shl eax,cl
mov edx,SC_INDEX+1
out dx,al
mov eax,[_ds_x2]
cmp eax,[curx]
jb ldone
sub eax,[curplane]
js ldoneplane
shr eax,1
mov [endpx],eax
dec eax
js lfillone
shr eax,1
mov ebx,[curx]
shr ebx,1
cmp ebx,[endpx]
jz lfillone
mov [curpx],ebx
inc ebx
shr ebx,1
inc eax
sub eax,ebx
js ldoneplane
mov [loopcount],eax
mov eax,[_ds_colormap]
mov ebx,eax
mov esi,[_ds_source]
mov edi,[dest]
mov ebp,[frac]
test [curpx],dword 1
jz lfill
shld ecx,ebp,22
shld ecx,ebp,6
add ebp,[fracpstep]
and ecx,0fffh
mov al,[esi+ecx]
mov dl,[eax]
mov [edi],dl
inc edi
jz ldoneplane
lfill:
shld ecx,ebp,22
shld ecx,ebp,6
add ebp,[fracpstep]
and ecx,0fffh
shld edx,ebp,22
shld edx,ebp,6
add ebp,[fracpstep]
and edx,0fffh
mov al,[esi+ecx]
mov bl,[esi+edx]
mov dl,[eax]
test [loopcount],dword 0ffffffffh
jnz ldoubleloop
jmp lchecklast
lfillone:
mov eax,[_ds_colormap]
mov esi,[_ds_source]
mov edi,[dest]
mov ebp,[frac]
shld ecx,ebp,22
shld ecx,ebp,6
and ecx,0fffh
mov al,[esi+ecx]
mov dl,[eax]
mov [edi],dl
jmp ldoneplane
ldoubleloop:
shld ecx,ebp,22
mov dh,[ebx]
shld ecx,ebp,6
lpatch1:
add ebp,12345678h
and ecx,0fffh
mov [edi],dx
shld edx,ebp,22
add edi,2
shld edx,ebp,6
lpatch2:
add ebp,12345678h
and edx,0fffh
mov al,[esi+ecx]
mov bl,[esi+edx]
dec dword [loopcount]
mov dl,[eax]
jnz ldoubleloop
lchecklast:
test [endpx],dword 1
jnz ldoneplane
mov [edi],dl
ldoneplane:
mov ecx,[curplane]
inc ecx
and ecx,1
jnz lskip
inc dword [dest]
lskip:
cmp ecx,[endplane]
jz ldone
mov [curplane],ecx
mov ebx,[frac]
add ebx,[fracstep]
mov [frac],ebx
inc dword [curx]
jmp lplane
ldone:
popad
ret