-
Notifications
You must be signed in to change notification settings - Fork 54
/
ID_VW_AC.ASM
1485 lines (1189 loc) · 24.5 KB
/
ID_VW_AC.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
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
; Catacomb 3-D Source Code
; Copyright (C) 1993-2014 Flat Rock Software
;
; 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, write to the Free Software Foundation, Inc.,
; 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
;=================================
;
; CGA view manager routines
;
;=================================
;============================================================================
;
; All of these routines draw into a floating virtual screen segment in main
; memory. bufferofs points to the origin of the drawing page in screenseg.
; The routines that write out words must take into account buffer wrapping
; and not write a word at 0xffff (which causes an exception on 386s).
;
; The direction flag should be clear
;
;============================================================================
DATASEG
plotpixels db 0c0h,030h,0ch,03h
colorbyte db 000000b,01010101b,10101010b,11111111b
colorword dw 0,5555h,0aaaah,0ffffh
CODESEG
;============================================================================
;
; VW_Plot (int x,y,color)
;
;============================================================================
PROC VW_Plot x:WORD, y:WORD, color:WORD
PUBLIC VW_Plot
USES SI,DI
mov es,[screenseg]
mov di,[bufferofs]
mov bx,[y]
shl bx,1
add di,[ylookup+bx]
mov bx,[x]
mov ax,bx
shr ax,1
shr ax,1
add di,ax ; di = byte on screen
and bx,3
mov ah,[plotpixels+bx]
mov bx,[color]
mov cl,[colorbyte+bx]
and cl,ah
not ah
mov al,[es:di]
and al,ah ; mask off other pixels
or al,cl
stosb
ret
ENDP
;============================================================================
;
; VW_Vlin (int yl,yh,x,color)
;
;============================================================================
PROC VW_Vlin yl:WORD, yh:WORD, x:WORD, color:WORD
PUBLIC VW_Vlin
USES SI,DI
mov es,[screenseg]
mov di,[bufferofs]
mov bx,[yl]
shl bx,1
add di,[ylookup+bx]
mov bx,[x]
mov ax,bx
shr ax,1
shr ax,1
add di,ax ; di = byte on screen
and bx,3
mov ah,[plotpixels+bx]
mov bx,[color]
mov bl,[colorbyte+bx]
and bl,ah
not ah
mov cx,[yh]
sub cx,[yl]
inc cx ;number of pixels to plot
mov dx,[linewidth]
@@plot:
mov al,[es:di]
and al,ah ; mask off other pixels
or al,bl
mov [es:di],al
add di,dx
loop @@plot
ret
ret
ENDP
;============================================================================
;===================
;
; VW_DrawTile8
;
; xcoord in bytes (8 pixels), ycoord in pixels
; All Tile8s are in one grseg, so an offset is calculated inside it
;
; DONE
;
;===================
PROC VW_DrawTile8 xcoord:WORD, ycoord:WORD, tile:WORD
PUBLIC VW_DrawTile8
USES SI,DI
mov es,[screenseg]
mov di,[bufferofs]
add di,[xcoord]
mov bx,[ycoord]
shl bx,1
add di,[ylookup+bx]
mov bx,[linewidth]
sub bx,2
mov si,[tile]
shl si,1
shl si,1
shl si,1
shl si,1
mov ds,[grsegs+STARTTILE8*2] ; segment for all tile8s
;
; start drawing
;
REPT 7
movsb ;no word moves because of segment wrapping
movsb
add di,bx
ENDM
movsb
movsb
mov ax,ss
mov ds,ax ;restore turbo's data segment
ret
ENDP
;============================================================================
;
; VW_MaskBlock
;
; Draws a masked block shape to the screen. bufferofs is NOT accounted for.
; The mask comes first, then the data. Seperate unwound routines are used
; to speed drawing.
;
; Mask blocks will allways be an even width because of the way IGRAB works
;
; DONE
;
;============================================================================
DATASEG
UNWOUNDMASKS = 18
maskroutines dw mask0,mask0,mask2E,mask2O,mask4E,mask4O
dw mask6E,mask6O,mask8E,mask8O,mask10E,mask10O
dw mask12E,mask12O,mask14E,mask14O,mask16E,mask16O
dw mask18E,mask18O
routinetouse dw ?
CODESEG
PROC VW_MaskBlock segm:WORD, ofs:WORD, dest:WORD, wide:WORD, height:WORD, planesize:WORD
PUBLIC VW_MaskBlock
USES SI,DI
mov es,[screenseg]
mov di,[wide]
mov dx,[linewidth]
sub dx,di ;dx = delta to start of next line
mov bx,[planesize] ; si+bx = data location
cmp di,UNWOUNDMASKS
jbe @@unwoundroutine
;==============
;
; General purpose masked block drawing. This could be optimised into
; four routines to use words, but few play loop sprites should be this big!
;
;==============
mov [ss:linedelta],dx
mov ds,[segm]
mov si,[ofs]
mov di,[dest]
mov dx,[height] ;scan lines to draw
@@lineloopgen:
mov cx,[wide]
@@byteloop:
mov al,[es:di]
and al,[si]
or al,[bx+si]
inc si
stosb
loop @@byteloop
add di,[ss:linedelta]
dec dx
jnz @@lineloopgen
mask0:
mov ax,ss
mov ds,ax
ret ;width of 0 = no drawing
;=================
;
; use the unwound routines
;
;=================
@@unwoundroutine:
shr di,1 ;we only have even width unwound routines
mov cx,[dest]
shr cx,1
rcl di,1 ;shift a 1 in if destination is odd
shl di,1
mov ax,[maskroutines+di] ;call the right routine
mov ds,[segm]
mov si,[ofs]
mov di,[dest]
mov cx,[height] ;scan lines to draw
jmp ax ;draw it
;=================
;
; Horizontally unwound routines to draw certain masked blocks faster
;
;=================
MACRO MASKBYTE
mov al,[es:di]
and al,[si]
or al,[bx+si]
inc si
stosb
ENDM
MACRO MASKWORD
mov ax,[es:di]
and ax,[si]
or ax,[bx+si]
inc si
inc si
stosw
ENDM
MACRO SPRITELOOP addr
add di,dx
loop addr
mov ax,ss
mov ds,ax
ret
ENDM
EVEN
mask2E:
MASKWORD
SPRITELOOP mask2E
EVEN
mask2O:
MASKBYTE
MASKBYTE
SPRITELOOP mask2O
EVEN
mask4E:
MASKWORD
MASKWORD
SPRITELOOP mask4E
EVEN
mask4O:
MASKBYTE
MASKWORD
MASKBYTE
SPRITELOOP mask4O
EVEN
mask6E:
MASKWORD
MASKWORD
MASKWORD
SPRITELOOP mask6E
EVEN
mask6O:
MASKBYTE
MASKWORD
MASKWORD
MASKBYTE
SPRITELOOP mask6O
EVEN
mask8E:
MASKWORD
MASKWORD
MASKWORD
MASKWORD
SPRITELOOP mask8E
EVEN
mask8O:
MASKBYTE
MASKWORD
MASKWORD
MASKWORD
MASKBYTE
SPRITELOOP mask8O
EVEN
mask10E:
MASKWORD
MASKWORD
MASKWORD
MASKWORD
MASKWORD
SPRITELOOP mask10E
EVEN
mask10O:
MASKBYTE
MASKWORD
MASKWORD
MASKWORD
MASKWORD
MASKBYTE
SPRITELOOP mask10O
EVEN
mask12E:
MASKWORD
MASKWORD
MASKWORD
MASKWORD
MASKWORD
MASKWORD
SPRITELOOP mask12E
EVEN
mask12O:
MASKBYTE
MASKWORD
MASKWORD
MASKWORD
MASKWORD
MASKWORD
MASKBYTE
SPRITELOOP mask12O
EVEN
mask14E:
MASKWORD
MASKWORD
MASKWORD
MASKWORD
MASKWORD
MASKWORD
MASKWORD
SPRITELOOP mask14E
EVEN
mask14O:
MASKBYTE
MASKWORD
MASKWORD
MASKWORD
MASKWORD
MASKWORD
MASKWORD
MASKBYTE
SPRITELOOP mask14O
EVEN
mask16E:
MASKWORD
MASKWORD
MASKWORD
MASKWORD
MASKWORD
MASKWORD
MASKWORD
MASKWORD
SPRITELOOP mask16E
EVEN
mask16O:
MASKBYTE
MASKWORD
MASKWORD
MASKWORD
MASKWORD
MASKWORD
MASKWORD
MASKWORD
MASKBYTE
SPRITELOOP mask16O
EVEN
mask18E:
MASKWORD
MASKWORD
MASKWORD
MASKWORD
MASKWORD
MASKWORD
MASKWORD
MASKWORD
MASKWORD
SPRITELOOP mask18E
EVEN
mask18O:
MASKBYTE
MASKWORD
MASKWORD
MASKWORD
MASKWORD
MASKWORD
MASKWORD
MASKWORD
MASKWORD
MASKBYTE
SPRITELOOP mask18O
ENDP
;============================================================================
;
; VW_ScreenToScreen
;
; Basic block copy routine. Copies one block of screen memory to another,
; bufferofs is NOT accounted for.
;
; DONE
;
;============================================================================
PROC VW_ScreenToScreen source:WORD, dest:WORD, wide:WORD, height:WORD
PUBLIC VW_ScreenToScreen
USES SI,DI
mov bx,[linewidth]
sub bx,[wide]
mov ax,[screenseg]
mov es,ax
mov ds,ax
mov si,[source]
mov di,[dest] ;start at same place in all planes
mov dx,[height] ;scan lines to draw
mov ax,[wide]
;
; if the width, source, and dest are all even, use word moves
; This is allways the case in the CGA refresh
;
test ax,1
jnz @@bytelineloop
test si,1
jnz @@bytelineloop
test di,1
jnz @@bytelineloop
shr ax,1
@@wordlineloop:
mov cx,ax
rep movsw
add si,bx
add di,bx
dec dx
jnz @@wordlineloop
mov ax,ss
mov ds,ax ;restore turbo's data segment
ret
@@bytelineloop:
mov cx,ax
rep movsb
add si,bx
add di,bx
dec dx
jnz @@bytelineloop
mov ax,ss
mov ds,ax ;restore turbo's data segment
ret
ENDP
;============================================================================
;
; VW_MemToScreen
;
; Basic block drawing routine. Takes a block shape at segment pointer source
; of width by height data, and draws it to dest in the virtual screen,
; based on linewidth. bufferofs is NOT accounted for.
; There are four drawing routines to provide the best optimized code while
; accounting for odd segment wrappings due to the floating screens.
;
; DONE
;
;============================================================================
DATASEG
memtoscreentable dw eventoeven,eventoodd,oddtoeven,oddtoodd
CODESEG
PROC VW_MemToScreen source:WORD, dest:WORD, wide:WORD, height:WORD
PUBLIC VW_MemToScreen
USES SI,DI
mov es,[screenseg]
mov bx,[linewidth]
sub bx,[wide]
mov ds,[source]
xor si,si ;block is segment aligned
xor di,di
shr [wide],1 ;change wide to words, and see if carry is set
rcl di,1 ;1 if wide is odd
mov ax,[dest]
shr ax,1
rcl di,1 ;shift a 1 in if destination is odd
shl di,1 ;to index into a word width table
mov dx,[height] ;scan lines to draw
mov ax,[wide]
jmp [ss:memtoscreentable+di] ;call the right routine
;==============
;
; Copy an even width block to an even destination address
;
;==============
eventoeven:
mov di,[dest] ;start at same place in all planes
EVEN
@@lineloopEE:
mov cx,ax
rep movsw
add di,bx
dec dx
jnz @@lineloopEE
mov ax,ss
mov ds,ax ;restore turbo's data segment
ret
;==============
;
; Copy an odd width block to an even video address
;
;==============
oddtoeven:
mov di,[dest] ;start at same place in all planes
EVEN
@@lineloopOE:
mov cx,ax
rep movsw
movsb ;copy the last byte
add di,bx
dec dx
jnz @@lineloopOE
mov ax,ss
mov ds,ax ;restore turbo's data segment
ret
;==============
;
; Copy an even width block to an odd video address
;
;==============
eventoodd:
mov di,[dest] ;start at same place in all planes
dec ax ;one word has to be handled seperately
EVEN
@@lineloopEO:
movsb
mov cx,ax
rep movsw
movsb
add di,bx
dec dx
jnz @@lineloopEO
mov ax,ss
mov ds,ax ;restore turbo's data segment
ret
;==============
;
; Copy an odd width block to an odd video address
;
;==============
oddtoodd:
mov di,[dest] ;start at same place in all planes
EVEN
@@lineloopOO:
movsb
mov cx,ax
rep movsw
add di,bx
dec dx
jnz @@lineloopOO
mov ax,ss
mov ds,ax ;restore turbo's data segment
ret
ENDP
;===========================================================================
;
; VW_ScreenToMem
;
; Copies a block of video memory to main memory, in order from planes 0-3.
; This could be optimized along the lines of VW_MemToScreen to take advantage
; of word copies, but this is an infrequently called routine.
;
; DONE
;
;===========================================================================
PROC VW_ScreenToMem source:WORD, dest:WORD, wide:WORD, height:WORD
PUBLIC VW_ScreenToMem
USES SI,DI
mov es,[dest]
mov bx,[linewidth]
sub bx,[wide]
mov ds,[screenseg]
xor di,di
mov si,[source]
mov dx,[height] ;scan lines to draw
@@lineloop:
mov cx,[wide]
rep movsb
add si,bx
dec dx
jnz @@lineloop
mov ax,ss
mov ds,ax ;restore turbo's data segment
ret
ENDP
;===========================================================================
;
; MISC CGA ROUTINES
;
;===========================================================================
;==============
;
; VW_SetScreen
;
; DONE
;
;==============
PROC VW_SetScreen crtc:WORD
PUBLIC VW_SetScreen
;
; for some reason, my XT's EGA card doesn't like word outs to the CRTC
; index...
;
cli
mov cx,[crtc]
mov dx,CRTC_INDEX
mov al,0ch ;start address high register
out dx,al
inc dx
mov al,ch
out dx,al
dec dx
mov al,0dh ;start address low register
out dx,al
mov al,cl
inc dx
out dx,al
sti
ret
ENDP
if NUMFONT+NUMFONTM
;===========================================================================
;
; GENERAL FONT DRAWING ROUTINES
;
;===========================================================================
DATASEG
px dw ? ; proportional character drawing coordinates
py dw ?
pdrawmode db 11000b ; 8 = OR, 24 = XOR, put in GC_DATAROTATE
fontcolor db 15 ;0-15 mapmask value
PUBLIC px,py,pdrawmode,fontcolor
;
; offsets in font structure
;
pcharheight = 0 ;lines high
charloc = 2 ;pointers to every character
charwidth = 514 ;every character's width in pixels
propchar dw ? ; the character number to shift
stringptr dw ?,?
fontcolormask dw ? ; font color expands into this
BUFFWIDTH = 100
BUFFHEIGHT = 32 ; must be twice as high as font for masked fonts
databuffer db BUFFWIDTH*BUFFHEIGHT dup (?)
bufferwidth dw ? ; bytes with valid info / line
bufferheight dw ? ; number of lines currently used
bufferbyte dw ?
bufferbit dw ?
PUBLIC bufferwidth,bufferheight,bufferbyte,bufferbit
screenspot dw ? ; where the buffer is going
bufferextra dw ? ; add at end of a line copy
screenextra dw ?
CODESEG
;======================
;
; Macros to table shift a byte of font
;
;======================
MACRO SHIFTNOXOR
mov al,[es:bx] ; source
xor ah,ah
shl ax,1
mov si,ax
mov ax,[bp+si] ; table shift into two bytes
or [di],al ; or with first byte
inc di
mov [di],ah ; replace next byte
inc bx ; next source byte
ENDM
MACRO SHIFTWITHXOR
mov al,[es:bx] ; source
xor ah,ah
shl ax,1
mov si,ax
mov ax,[bp+si] ; table shift into two bytes
not ax
and [di],al ; and with first byte
inc di
mov [di],ah ; replace next byte
inc bx ; next source byte
ENDM
;=======================
;
; VWL_XORBuffer
;
; Pass buffer start in SI (somewhere in databuffer)
; Draws the buffer to the screen buffer
;
;========================
PROC VWL_XORBuffer NEAR
USES BP
mov bl,[fontcolor]
xor bh,bh
shl bx,1
mov ax,[colorword+bx]
mov [fontcolormask],ax
mov es,[screenseg]
mov di,[screenspot]
mov bx,[bufferwidth] ;calculate offsets for end of each line
mov [bufferwidth],bx
or bx,bx
jnz @@isthere
ret ;nothing to draw
@@isthere:
test bx,1
jnz @@odd
jmp @@even
;
; clear the last byte so word draws can be used
;
@@odd:
mov al,0
line = 0
REPT BUFFHEIGHT
mov [BYTE databuffer+BUFFWIDTH*line+bx],al
line = line+1
ENDM
inc bx
@@even:
mov ax,[linewidth]
sub ax,bx
mov [screenextra],ax
mov ax,BUFFWIDTH
sub ax,bx
mov [bufferextra],ax
mov dx,bx
shr dx,1 ;word to copy
mov bx,[bufferheight] ;lines to copy
mov bp,[fontcolormask]
@@lineloop:
mov cx,dx
@@wordloop:
lodsw ;get a word from the buffer
and ax,bp
xor [es:di],ax ;draw it
add di,2
loop @@wordloop
add si,[bufferextra]
add di,[screenextra]
dec bx
jnz @@lineloop
ret
ENDP
DATASEG
;============================================================================
;
; NON MASKED FONT DRAWING ROUTINES
;
;============================================================================
if numfont
DATASEG
shiftdrawtable dw 0,shift1wide,shift2wide,shift3wide,shift4wide
dw shift5wide,shift6wide
CODESEG
;==================
;
; ShiftPropChar
;
; Call with BX = character number (0-255)
; Draws one character to the buffer at bufferbyte/bufferbit, and adjusts
; them to the new position
;
;==================
PROC ShiftPropChar NEAR
mov es,[grsegs+STARTFONT*2] ;segment of font to use
;
; find character location, width, and height
;
mov si,[es:charwidth+bx]
and si,0ffh ;SI hold width in pixels
shl bx,1
mov bx,[es:charloc+bx] ;BX holds pointer to character data
;
; look up which shift table to use, based on bufferbit
;
mov di,[bufferbit]
shl di,1
mov bp,[shifttabletable+di] ;BP holds pointer to shift table
mov di,OFFSET databuffer
add di,[bufferbyte] ;DI holds pointer to buffer
mov cx,[bufferbit]
add cx,si ;add twice because pixel == two bits
add cx,si ;new bit position
mov ax,cx
and ax,7
mov [bufferbit],ax ;new bit position
mov ax,cx
shr ax,1