-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathr_phase6.gas
1331 lines (1111 loc) · 22.5 KB
/
r_phase6.gas
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
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
.long
.dc.l codeend - _ref6_start
_ref6_start::
.gpu
.org $f03100
DIVCONTROL .equ $f0211c
S_LE .ccdef $14 ; PL
U_LE .ccdef $04 ; CC
S_GT .ccdef $18 ; MI
U_GT .ccdef $08 ; CS
S_LT .ccdef $15 ; PL+NE
U_LT .ccdef $05 ; CC+NE
FP .equr r14
scratch .equr r10
scratch2 .equr r11
RETURNVALUE .equr r29
RETURNPOINT .equr r28
MATH_A .equr r27
MATH_B .equr r26
MATH_C .equr r25
MATH_RTS .equr r24
MATH_SIGN .equr r23
;
; offsets in viswall_t
;
VS_seg .equ 0
VS_start .equ 1
VS_stop .equ 2
VS_angle .equ 3
VS_floorpic .equ 4
VS_ceilingpic .equ 5
VS_actionbits .equ 6
VS_t_topheight .equ 7
VS_t_bottomheight .equ 8
VS_t_texturemid .equ 9
VS_t_texture .equ 10
VS_b_topheight .equ 11
VS_b_bottomheight .equ 12
VS_b_texturemid .equ 13
VS_b_texture .equ 14
VS_floorheight .equ 15
VS_floornewheight .equ 16
VS_ceilingheight .equ 17
VS_ceilingnewheight .equ 18
VS_topsil .equ 19
VS_bottomsil .equ 20
VS_scalefrac .equ 21
VS_scale2 .equ 22
VS_scalestep .equ 23
VS_centerangle .equ 24
VS_offset .equ 25
VS_distance .equ 26
VS_seglightlevel .equ 27
;
; alternate register bank
;
VR_seg .equr r4
VR_start .equr r5
VR_stop .equr r6
VR_angle .equr r7
VR_floorpic .equr r8
VR_ceilingpic .equr r9
VR_actionbits .equr r10
VR_floorheight .equr r11
VR_floornewheight .equr r12
VR_ceilingheight .equr r13
VR_ceilingnewheight .equr r14
VR_topsil .equr r15
VR_bottomsil .equr r16
VR_scalefrac .equr r17
VR_scale2 .equr r18
VR_scalestep .equr r19
VR_centerangle .equr r20
VR_offset .equr r21
VR_distance .equr r22
VR_seglightlevel .equr r23
;==============================================================================
_R_SegCommands::
;4 dag registers 3 register variables
;localoffset:0 regoffset:0 argoffset:32
;==============================================================================
subq #32,FP
movei #_clipbounds,r0
movei #180,r1 ; SCREENHEIGHT
movei #160,r2 ; SCREENWIDTH
movei #clearclipbounds,r3
clearclipbounds:
store r1,(r0)
addq #4,r0
store r1,(r0)
addq #4,r0
store r1,(r0)
addq #4,r0
subq #4,r2
store r1,(r0)
jump NE,(r3)
addq #4,r0
;
; setup blitter
;
movei #15737348,r0
movei #145440,r1
store r1,(r0)
movei #15737384,r0
movei #145952,r1
store r1,(r0)
movei #_viswalls,r0
move r0,r16 ;(segl)
movei #L61,r0
jump T,(r0)
nop
L58:
;
; copy viswall to local memory
;
move r16,r15
load (r15+VS_start),r0
moveta r0,VR_start
load (r15+VS_stop),r0
moveta r0,VR_stop
load (r15+VS_floorpic),r0
moveta r0,VR_floorpic
load (r15+VS_ceilingpic),r0
moveta r0,VR_ceilingpic
load (r15+VS_actionbits),r0
moveta r0,VR_actionbits
load (r15+VS_floorheight),r0
moveta r0,VR_floorheight
load (r15+VS_floornewheight),r0
moveta r0,VR_floornewheight
load (r15+VS_ceilingheight),r0
moveta r0,VR_ceilingheight
load (r15+VS_ceilingnewheight),r0
moveta r0,VR_ceilingnewheight
load (r15+VS_topsil),r0
moveta r0,VR_topsil
load (r15+VS_bottomsil),r0
moveta r0,VR_bottomsil
load (r15+VS_scalefrac),r0
moveta r0,VR_scalefrac
load (r15+VS_scalestep),r0
moveta r0,VR_scalestep
load (r15+VS_centerangle),r0
moveta r0,VR_centerangle
load (r15+VS_offset),r0
moveta r0,VR_offset
load (r15+VS_distance),r0
moveta r0,VR_distance
load (r15+VS_seglightlevel),r0
moveta r0,VR_seglightlevel
; lightmin = wl.seglightlevel - (255-wl.seglightlevel)*2;
; if (lightmin < 0)
; lightmin = 0;
sc_lightmin .equr r5
sc_lightmax .equr r6
movefa VR_seglightlevel,sc_lightmin
movei #255,r2
movefa VR_seglightlevel,r3
sub r3,r2
shlq #1,r2
sub r2,sc_lightmin
jr PL,minnotneg
nop
moveq #0,sc_lightmin
minnotneg:
movei #_lightmin,r0
store sc_lightmin,(r0)
; lightmax = wl.seglightlevel;
movei #_lightmax,r0
movefa VR_seglightlevel,sc_lightmax
store sc_lightmax,(r0)
; lightsub = 160*(lightmax-lightmin)/(800-160);
; lightcoef = ((lightmax-lightmin)<<16)/(800-160);
sub sc_lightmin,sc_lightmax
move sc_lightmax,r1
movei #160,r2
mult r1,r2
movei #640,r4
div r4,r2
movei #_lightsub,r0
move sc_lightmax,r3
shlq #16,r3
store r2,(r0) ; div hit
div r4,r3
movei #_lightcoef,r0
store r3,(r0) ; div hit
movefa VR_actionbits,r0
btst #2,r0
movei #L71,scratch
jump EQ,(scratch)
nop
movei #_toptex+12,r0
load (r15+7),r1
store r1,(r0)
movei #_toptex+16,r0
load (r15+8),r1
store r1,(r0)
movei #_toptex+20,r0
load (r15+9),r1
store r1,(r0)
load (r15+10),r0
move r0,r17 ;(tex)
movei #_toptex+4,r0
move r17,r1 ;(tex)
addq #8,r1
load (r1),r1
store r1,(r0)
movei #_toptex+8,r0
move r17,r1 ;(tex)
addq #12,r1
load (r1),r1
store r1,(r0)
movei #_toptex,r0
move r17,r1 ;(tex)
addq #16,r1
load (r1),r1
store r1,(r0)
L71:
movefa VR_actionbits,r0
btst #3,r0
movei #L83,scratch
jump EQ,(scratch)
nop
movei #_bottomtex+12,r0
load (r15+11),r1
store r1,(r0)
movei #_bottomtex+16,r0
load (r15+12),r1
store r1,(r0)
movei #_bottomtex+20,r0
load (r15+13),r1
store r1,(r0)
load (r15+14),r0
move r0,r17 ;(tex)
movei #_bottomtex+4,r0
move r17,r1 ;(tex)
addq #8,r1
load (r1),r1
store r1,(r0)
movei #_bottomtex+8,r0
move r17,r1 ;(tex)
addq #12,r1
load (r1),r1
store r1,(r0)
movei #_bottomtex,r0
move r17,r1 ;(tex)
addq #16,r1
load (r1),r1
store r1,(r0)
L83:
movei #_R_SegLoop,r0
store r28,(FP) ; psuh ;(RETURNPOINT)
store r17,(FP+1) ; push ;(tex)
store r16,(FP+2) ; push ;(segl)
movei #L99,RETURNPOINT
jump T,(r0)
store r15,(FP+3) ; delay slot push ;(i)
L99:
load (FP+1),r17 ; pop ;(tex)
load (FP+2),r16 ; pop ;(segl)
load (FP+3),r15 ; pop ;(i)
load (FP),RETURNPOINT ; pop
L59:
movei #112,r0
move r16,r1 ;(segl)
add r0,r1
move r1,r16 ;(segl)
L61:
move r16,r0 ;(segl)
movei #_lastwallcmd,r1
load (r1),r1
cmp r0,r1
movei #L58,scratch
jump U_LT,(scratch)
nop
movei #_phasetime+24,r0
movei #_samplecount,r1
load (r1),r1
store r1,(r0)
movei #_gpucodestart,r0
movei #_ref7_start,r1
store r1,(r0)
L53:
jump T,(RETURNPOINT)
addq #32,FP ; delay slot
;=============================================================================
;====================
_R_FindPlane::
;====================
;
; parms
;
fp_check .equr r15
fp_height .equr r7
fp_picnum .equr r6
fp_lightlevel .equr r5
fp_start .equr r21 ; common with sl_x
fp_stop .equr r4
;
; locals
;
fp_set .equr r10
fp_lastvisplane .equr r9
fp_jump .equr r8
movei #_lastvisplane,fp_lastvisplane
load (fp_lastvisplane),fp_lastvisplane
movei #L105,fp_jump
movei #L104,r0
jump T,(r0)
nop
L101:
load (fp_check),r0
cmp fp_height,r0
jump NE,(fp_jump)
nop
load (fp_check+1),r0
cmp fp_picnum,r0
jump NE,(fp_jump)
nop
load (fp_check+2),r0
cmp fp_lightlevel,r0
jump NE,(fp_jump)
nop
; if check->open[start]
move fp_start,r0
shlq #1,r0
add fp_check,r0
addq #24,r0
loadw (r0),r0
movei #65280,r1
cmp r0,r1
jump NE,(fp_jump)
nop
; found a plane, so adjust bounds and return it
load (fp_check+3),r0
cmp r0,fp_start
jr U_LE,startok
nop
store fp_start,(fp_check+3)
startok:
load (fp_check+4),r0
cmp r0,fp_stop
jr U_GT,stopok
nop
store fp_stop,(fp_check+4)
stopok:
; return check
jump T,(RETURNPOINT)
move fp_check,RETURNVALUE
;
; next plane
;
L105:
movei #348,r0
add r0,fp_check
L104:
cmp fp_check,fp_lastvisplane
movei #L101,scratch
jump U_LT,(scratch)
nop
;
; make a new plane
;
move fp_lastvisplane,fp_check
movei #348,r3
add r3,fp_lastvisplane
movei #_lastvisplane,scratch
store fp_lastvisplane,(scratch) ; visplane++
store fp_height,(fp_check)
store fp_picnum,(fp_check+1)
store fp_lightlevel,(fp_check+2)
store fp_start,(fp_check+3)
store fp_stop,(fp_check+4)
;
; for i=0 ; i<80 ; i++
; (int)check->open[i] = 0xff00ff00
;
move fp_check,fp_set
addq #24,fp_set
movei #$ff00ff00,r0
movei #40,r1
fillloop:
store r0,(fp_set)
addq #4,fp_set
store r0,(fp_set)
subq #1,r1
addqt #4,fp_set
jr NE,fillloop
nop
jump T,(RETURNPOINT)
move fp_check,RETURNVALUE
;=============================================================================
;====================
_R_DrawTexture::
; call with dt_tex pointing to the texture parms
;====================
dt_tex .equr r15
dt_blitter .equr r15
dt_top .equr r16
dt_bottom .equr r17
dt_colnum .equr r18
dt_frac .equr r5
dt_centery .equr r7
dt_scratch .equr r10
dt_scratch2 .equr r11
dt_MATHA .equr r0
dt_MATHB .equr r1
dtb_base .equr r0
dtb_a1pix .equr r1
dtb_a1frac .equr r2
dtb_a1inc .equr r3
dtb_a1incfrac .equr r4
dtb_count .equr r7
dtb_command .equr r8
;
; common to draw texture
;
dt_floorclipx .equr r19
dt_ceilingclipx .equr r20
dt_x .equr r21
dt_scale .equr r22
dt_iscale .equr r23
dt_texturecol .equr r24
dt_texturelight .equr r25
load (dt_tex+3),dt_scratch ; tex->topheight
imult dt_scale,dt_scratch
sharq #15,dt_scratch
movei #90,dt_centery
move dt_centery,dt_top
sub dt_scratch,dt_top ;top=CENTERY-((scale*tex->topheight)>>(15))
cmp dt_top,dt_ceilingclipx
jr S_GT,dt_topok ; if (top > ceilingclipx)
nop
move dt_ceilingclipx,dt_top
addq #1,dt_top
dt_topok:
load (dt_tex+4),dt_scratch ; tex->bottomheight
imult dt_scale,dt_scratch
sharq #15,dt_scratch
move dt_centery,dt_bottom
subq #1,dt_bottom
sub dt_scratch,dt_bottom ;bottom=CENTERY-1-((scale*tex->botheight)>>15)
cmp dt_bottom,dt_floorclipx
jr S_LT,dt_bottomok ; if (bottom < clipbottom)
nop
move dt_floorclipx,dt_bottom
subqt #1,dt_bottom
dt_bottomok:
cmp dt_top,dt_bottom
jump S_GT,(RETURNPOINT) ; if (top>bottom) return
nop
;===========
move dt_texturecol,dt_colnum
;
; frac = tex->texturemid - (CENTERY-top)*tx_iscale
;
move dt_centery,dt_MATHB
sub dt_top,dt_MATHB
move dt_MATHB,dt_scratch
move dt_iscale,dt_MATHA
abs dt_MATHB
move dt_MATHA,dt_scratch2
shrq #16,dt_scratch2
mult dt_MATHB,dt_MATHA
mult dt_MATHB,dt_scratch2
shlq #16,dt_scratch2
btst #31,dt_scratch
jr EQ,dt_notneg
add dt_scratch2,dt_MATHA ; delay slot
neg dt_MATHA
dt_notneg:
load (dt_tex+5),dt_frac ; tex->texturemid
sub dt_MATHA,dt_frac
; while frac < 0 colnum--,frac += tex->height<<16
jr PL,fracpos
nop
subagain:
load (dt_tex+2),dt_scratch ; tex->height
shlq #16,dt_scratch
add dt_scratch,dt_frac
jr MI,subagain
subq #1,dt_colnum
fracpos:
; colnum = colnum - tex->width*(colnum/tex->width)
load (dt_tex+1),dt_scratch ; tex->width
subq #1,scratch
and scratch,dt_colnum
; a1inc
move dt_iscale,dtb_a1inc
shrq #16,dtb_a1inc
; a1incfrac
movei #$ffff,dtb_a1incfrac
and dt_iscale,dtb_a1incfrac
; count
move dt_bottom,dtb_count
sub dt_top,dtb_count
addq #1,dtb_count
shlq #16,dtb_count
addq #1,dtb_count
; a2pix
shlq #16,dt_top
or dt_x,dt_top ; screen x
;
;frac += (colnum*tex->height)<<16
;
load (dt_tex+2),dt_scratch ; tex->height
mult dt_colnum,dt_scratch
shlq #16,dt_scratch
add dt_scratch,dt_frac
; a1pix
move dt_frac,dtb_a1pix
shrq #16,dtb_a1pix
; a1pix frac
movei #$ffff,dtb_a1frac
and dt_frac,dtb_a1frac
;===========
; base
load (dt_tex),dtb_base ; dt->data
; command
movei #1+(1<<8)+(1<<9)+(1<<10)+(1<<11)+(1<<13)+(1<<30)+(12<<21),dtb_command
movei #$f02200,dt_blitter
movei #$f02270,dt_scratch2 ; iinc blitter register
dt_wait:
load (dt_blitter+14),dt_scratch
btst #0,dt_scratch
jr EQ,dt_wait
nop
store dtb_base,(dt_blitter)
store dtb_a1pix,(dt_blitter+3)
store dtb_a1frac,(dt_blitter+6)
store dtb_a1inc,(dt_blitter+4)
store dtb_a1incfrac,(dt_blitter+5)
store dt_top,(dt_blitter+12)
store dt_texturelight,(dt_scratch2)
store dtb_count,(dt_blitter+15)
jump T,(RETURNPOINT)
store dtb_command,(dt_blitter+14) ; delay slot
;==============================================================================
_R_SegLoop::
;5 dag registers 8 register variables
;localoffset:24 regoffset:40 argoffset:96
;
; calls R_DrawTexture often
; calls R_FindPlane rarely
;==============================================================================
.extern _visplanes, _xtoviewangle, _finetangent, _viewangle, _skytexturep
BIT_ADDFLOOR .equ 0
BIT_ADDCEILING .equ 1
BIT_TOPTEXTURE .equ 2
BIT_BOTTOMTEXTURE .equ 3
BIT_NEWCEILING .equ 4
BIT_NEWFLOOR .equ 5
BIT_ADDSKY .equ 6
BIT_CALCTEXTURE .equ 7
BIT_TOPSIL .equ 8
BIT_BOTTOMSIL .equ 9
BIT_SOLIDSIL .equ 10
; r15 stays free for subfunctions to use
sl_colnum .equr r16
sl_top .equr r17
sl_bottom .equr r18
sl_actionbits .equr r9
sl_high .equr r30
sl_low .equr r31
;
; common to draw texture
;
sl_floorclipx .equr r19
sl_ceilingclipx .equr r20
sl_x .equr r21 ; also common to find plane
sl_scale .equr r22
sl_iscale .equr r23
sl_texturecol .equr r24
sl_texturelight .equr r25
movei #96,scratch
sub scratch,FP
store RETURNPOINT,(FP+10) ; only store once
movefa VR_actionbits,sl_actionbits
movefa VR_scalefrac,r1
movefa VR_start,sl_x
btst #0,r1 ; scoreboard bug
store r1,(FP+6) ; scalefrac
;
; force R_FindPlane for both planes
;
movei #_visplanes,r1
store r1,(FP+8) ; &ceiling
store r1,(FP+7) ; &floor
movei #L121,r0
jump T,(r0)
nop
L118:
load (FP+6),r1 ; scalefrac
move r1,sl_scale
sharq #7,sl_scale
movefa VR_scalestep,r2
add r2,r1
movei #$7fff,scratch
store r1,(FP+6)
cmp scratch,sl_scale
jr U_GT,scaleok ; if scale>0x7fff scale = 0x7fff
nop
move scratch,sl_scale
scaleok:
L125:
;
; get ceilingclipx and floorclipx from clipbounds
;
move sl_x,r0 ;(x)
shlq #2,r0
movei #_clipbounds,r1
add r1,r0
load (r0),sl_floorclipx
move sl_floorclipx,sl_ceilingclipx
shrq #8,sl_ceilingclipx
shlq #24,sl_floorclipx
subq #1,sl_ceilingclipx
shrq #24,sl_floorclipx ; mask off top 24 bits
;
; texture only stuff
;
btst #BIT_CALCTEXTURE,sl_actionbits
movei #L129,scratch
jump EQ,(scratch)
nop
;
; calculate texture offset
;
movefa VR_centerangle,r1
move sl_x,r3 ;(x)
shlq #2,r3
movei #_xtoviewangle,r4
add r4,r3
load (r3),r3
add r3,r1
shrq #19,r1
shlq #2,r1
movei #_finetangent,r0
add r1,r0
load (r0),MATH_A
movefa VR_distance,MATH_B
;---------------------------------------
;========== FixedMul r0,
move MATH_A,MATH_SIGN
xor MATH_B,MATH_SIGN
abs MATH_A
abs MATH_B
move MATH_A,RETURNVALUE
mult MATH_B,RETURNVALUE ; al*bl
shrq #16,RETURNVALUE
move MATH_B,scratch2
shrq #16,scratch2
mult MATH_A,scratch2 ; al*bh
add scratch2,RETURNVALUE
move MATH_A,scratch2
shrq #16,scratch2
mult MATH_B,scratch2 ; bl*ah
add scratch2, RETURNVALUE
move MATH_A,scratch2
shrq #16,scratch2
move MATH_B,scratch
shrq #16,scratch
mult scratch,scratch2 ; bh*ah
shlq #16,scratch2
add scratch2, RETURNVALUE
btst #31,MATH_SIGN
jr EQ,notneg
nop
neg RETURNVALUE
notneg:
;---------------------------------------
movefa VR_offset,sl_texturecol
sub RETURNVALUE,sl_texturecol
shrq #16,sl_texturecol
;
; other texture drawing info
;
movei #33554432,sl_iscale
div sl_scale,sl_iscale ; let this div complete in background
;
; calc light level
;
movei #_lightcoef,r1
load (r1),r1
mult sl_scale,r1
shrq #16,r1
movei #_lightsub,r2
load (r2),r2
sub r2,r1
movei #_lightmin,r0
load (r0),r0
cmp r0,r1
jr S_LT,lightovermin
nop
move r0,r1
lightovermin:
movei #_lightmax,r0
load (r0),r0
cmp r0,r1
jr S_GT,lightundermax
nop
move r0,r1
lightundermax:
; convert to a hardware value
movei #255,r0
sub r1,r0
shlq #14,r0
neg r0
movei #$ffffff,sl_texturelight
and r0,sl_texturelight
;
; draw textures
;
btst #BIT_TOPTEXTURE,sl_actionbits
jr EQ,L137
btst #BIT_BOTTOMTEXTURE,sl_actionbits ; harmless delay slot
movei #_toptex,dt_tex ; parameter
movei #_R_DrawTexture,r0
move PC,RETURNPOINT
jump T,(r0)
addq #6,RETURNPOINT
movefa VR_actionbits,sl_actionbits
btst #BIT_BOTTOMTEXTURE,sl_actionbits
L137:
jr EQ,L139
nop
movei #_bottomtex,dt_tex ; parameter
movei #_R_DrawTexture,r0
move PC,RETURNPOINT
jump T,(r0)
addq #6,RETURNPOINT
movefa VR_actionbits,sl_actionbits
L139:
L129:
;-----------------------
;
; floor
;
;-----------------------
btst #BIT_ADDFLOOR,sl_actionbits
movei #L143,scratch
jump EQ,(scratch)
nop
movefa VR_floorheight,r0
imult sl_scale,r0
sharq #15,r0
movei #90,sl_top
sub r0,sl_top
cmp sl_top,sl_ceilingclipx ;(top)(ceilingclipx)
jr S_GT,nocliptop
nop
move sl_ceilingclipx,sl_top
addq #1,sl_top
nocliptop:
move sl_floorclipx,sl_bottom
subq #1,sl_bottom
cmp sl_top,sl_bottom ;(top)(bottom)
movei #L147,scratch
jump S_GT,(scratch)
nop
move sl_x,r0 ;(x)
load (FP+7),r3 ; local floor
shlq #1,r0
addq #24,r0
add r3,r0
loadw (r0),r0 ; floor->open[x]
movei #65280,r1
cmp r0,r1
movei #L149,scratch
jump EQ,(scratch)
nop
movefa VR_floorheight,fp_height
movefa VR_floorpic,fp_picnum
movefa VR_seglightlevel,fp_lightlevel
movefa VR_stop,fp_stop
movei #348,fp_check
add r3,fp_check ; fp_check = floor+1
movei #_R_FindPlane,r1
move PC,RETURNPOINT
jump T,(r1)
addq #6,RETURNPOINT
movefa VR_actionbits,sl_actionbits
store RETURNVALUE,(FP+7) ; floor
L149:
move sl_x,r0 ;(x)
shlq #1,r0
load (FP+7),r1 ; local floor
addq #24,r1
add r1,r0
move sl_top,r1 ;(top)
shlq #8,r1
add sl_bottom,r1 ;(bottom)
storew r1,(r0) ; floor->open[x] = (top<<8)+bottom
L147:
L143:
;-----------------------
;
; ceiling
;
;-----------------------
btst #BIT_ADDCEILING,sl_actionbits
movei #L157,scratch
jump EQ,(scratch)
nop
move sl_ceilingclipx,sl_top
addq #1,sl_top ; top = ceilingclipx+1
movei #89,sl_bottom
movefa VR_ceilingheight,r1
imult sl_scale,r1
sharq #15,r1
sub r1,sl_bottom
cmp sl_bottom,sl_floorclipx ;(bottom)(floorclipx)
jr S_LT,noclipbottom
nop
move sl_floorclipx,sl_bottom
subq #1,sl_bottom
noclipbottom:
cmp sl_top,sl_bottom ;(top)(bottom)
movei #L161,scratch
jump S_GT,(scratch)
nop
move sl_x,r0 ;(x)
shlq #1,r0
load (FP+8),r3 ; local ceiling
addq #24,r0
add r3,r0
loadw (r0),r0 ; ceiling->open[x]
movei #65280,r1
cmp r0,r1
movei #L163,scratch
jump EQ,(scratch)
nop
movefa VR_ceilingheight,fp_height
movefa VR_ceilingpic,fp_picnum
movefa VR_seglightlevel,fp_lightlevel
movefa VR_stop,fp_stop
movei #348,fp_check
add r3,fp_check ; fp_check = ceiling+1
movei #_R_FindPlane,r1
move PC,RETURNPOINT
jump T,(r1)
addq #6,RETURNPOINT