1 ; Catacomb Armageddon Source Code
\r
2 ; Copyright (C) 1993-2014 Flat Rock Software
\r
4 ; This program is free software; you can redistribute it and/or modify
\r
5 ; it under the terms of the GNU General Public License as published by
\r
6 ; the Free Software Foundation; either version 2 of the License, or
\r
7 ; (at your option) any later version.
\r
9 ; This program is distributed in the hope that it will be useful,
\r
10 ; but WITHOUT ANY WARRANTY; without even the implied warranty of
\r
11 ; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
\r
12 ; GNU General Public License for more details.
\r
14 ; You should have received a copy of the GNU General Public License along
\r
15 ; with this program; if not, write to the Free Software Foundation, Inc.,
\r
16 ; 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
\r
18 ;=================================
\r
20 ; CGA view manager routines
\r
22 ;=================================
\r
24 ;============================================================================
\r
26 ; All of these routines draw into a floating virtual screen segment in main
\r
27 ; memory. bufferofs points to the origin of the drawing page in screenseg.
\r
28 ; The routines that write out words must take into account buffer wrapping
\r
29 ; and not write a word at 0xffff (which causes an exception on 386s).
\r
31 ; The direction flag should be clear
\r
33 ;============================================================================
\r
37 plotpixels db 0c0h,030h,0ch,03h
\r
38 colorbyte db 000000b,01010101b,10101010b,11111111b
\r
39 colorword dw 0,5555h,0aaaah,0ffffh
\r
43 ;============================================================================
\r
45 ; VW_Plot (int x,y,color)
\r
47 ;============================================================================
\r
50 PROC VW_Plot x:WORD, y:WORD, color:WORD
\r
64 add di,ax ; di = byte on screen
\r
67 mov ah,[plotpixels+bx]
\r
69 mov cl,[colorbyte+bx]
\r
74 and al,ah ; mask off other pixels
\r
83 ;============================================================================
\r
85 ; VW_Vlin (int yl,yh,x,color)
\r
87 ;============================================================================
\r
89 PROC VW_Vlin yl:WORD, yh:WORD, x:WORD, color:WORD
\r
103 add di,ax ; di = byte on screen
\r
106 mov ah,[plotpixels+bx]
\r
108 mov bl,[colorbyte+bx]
\r
114 inc cx ;number of pixels to plot
\r
120 and al,ah ; mask off other pixels
\r
133 ;============================================================================
\r
136 ;===================
\r
140 ; xcoord in bytes (8 pixels), ycoord in pixels
\r
141 ; All Tile8s are in one grseg, so an offset is calculated inside it
\r
145 ;===================
\r
147 PROC VW_DrawTile8 xcoord:WORD, ycoord:WORD, tile:WORD
\r
148 PUBLIC VW_DrawTile8
\r
157 add di,[ylookup+bx]
\r
168 mov ds,[grsegs+STARTTILE8*2] ; segment for all tile8s
\r
175 movsb ;no word moves because of segment wrapping
\r
183 mov ds,ax ;restore turbo's data segment
\r
190 ;============================================================================
\r
194 ; Draws a masked block shape to the screen. bufferofs is NOT accounted for.
\r
195 ; The mask comes first, then the data. Seperate unwound routines are used
\r
196 ; to speed drawing.
\r
198 ; Mask blocks will allways be an even width because of the way IGRAB works
\r
202 ;============================================================================
\r
209 maskroutines dw mask0,mask0,mask2E,mask2O,mask4E,mask4O
\r
210 dw mask6E,mask6O,mask8E,mask8O,mask10E,mask10O
\r
211 dw mask12E,mask12O,mask14E,mask14O,mask16E,mask16O
\r
219 PROC VW_MaskBlock segm:WORD, ofs:WORD, dest:WORD, wide:WORD, height:WORD, planesize:WORD
\r
220 PUBLIC VW_MaskBlock
\r
227 sub dx,di ;dx = delta to start of next line
\r
229 mov bx,[planesize] ; si+bx = data location
\r
231 cmp di,UNWOUNDMASKS
\r
232 jbe @@unwoundroutine
\r
236 ; General purpose masked block drawing. This could be optimised into
\r
237 ; four routines to use words, but few play loop sprites should be this big!
\r
241 mov [ss:linedelta],dx
\r
245 mov dx,[height] ;scan lines to draw
\r
257 add di,[ss:linedelta]
\r
264 ret ;width of 0 = no drawing
\r
269 ; use the unwound routines
\r
274 shr di,1 ;we only have even width unwound routines
\r
277 rcl di,1 ;shift a 1 in if destination is odd
\r
279 mov ax,[maskroutines+di] ;call the right routine
\r
284 mov cx,[height] ;scan lines to draw
\r
290 ; Horizontally unwound routines to draw certain masked blocks faster
\r
311 MACRO SPRITELOOP addr
\r
495 ;============================================================================
\r
497 ; VW_ScreenToScreen
\r
499 ; Basic block copy routine. Copies one block of screen memory to another,
\r
500 ; bufferofs is NOT accounted for.
\r
504 ;============================================================================
\r
506 PROC VW_ScreenToScreen source:WORD, dest:WORD, wide:WORD, height:WORD
\r
507 PUBLIC VW_ScreenToScreen
\r
518 mov di,[dest] ;start at same place in all planes
\r
519 mov dx,[height] ;scan lines to draw
\r
522 ; if the width, source, and dest are all even, use word moves
\r
523 ; This is allways the case in the CGA refresh
\r
543 mov ds,ax ;restore turbo's data segment
\r
557 mov ds,ax ;restore turbo's data segment
\r
564 ;============================================================================
\r
568 ; Basic block drawing routine. Takes a block shape at segment pointer source
\r
569 ; of width by height data, and draws it to dest in the virtual screen,
\r
570 ; based on linewidth. bufferofs is NOT accounted for.
\r
571 ; There are four drawing routines to provide the best optimized code while
\r
572 ; accounting for odd segment wrappings due to the floating screens.
\r
576 ;============================================================================
\r
580 memtoscreentable dw eventoeven,eventoodd,oddtoeven,oddtoodd
\r
585 PROC VW_MemToScreen source:WORD, dest:WORD, wide:WORD, height:WORD
\r
586 PUBLIC VW_MemToScreen
\r
596 xor si,si ;block is segment aligned
\r
599 shr [wide],1 ;change wide to words, and see if carry is set
\r
600 rcl di,1 ;1 if wide is odd
\r
603 rcl di,1 ;shift a 1 in if destination is odd
\r
604 shl di,1 ;to index into a word width table
\r
605 mov dx,[height] ;scan lines to draw
\r
607 jmp [ss:memtoscreentable+di] ;call the right routine
\r
611 ; Copy an even width block to an even destination address
\r
616 mov di,[dest] ;start at same place in all planes
\r
626 mov ds,ax ;restore turbo's data segment
\r
632 ; Copy an odd width block to an even video address
\r
637 mov di,[dest] ;start at same place in all planes
\r
642 movsb ;copy the last byte
\r
648 mov ds,ax ;restore turbo's data segment
\r
654 ; Copy an even width block to an odd video address
\r
659 mov di,[dest] ;start at same place in all planes
\r
660 dec ax ;one word has to be handled seperately
\r
672 mov ds,ax ;restore turbo's data segment
\r
678 ; Copy an odd width block to an odd video address
\r
683 mov di,[dest] ;start at same place in all planes
\r
694 mov ds,ax ;restore turbo's data segment
\r
700 ;===========================================================================
\r
704 ; Copies a block of video memory to main memory, in order from planes 0-3.
\r
705 ; This could be optimized along the lines of VW_MemToScreen to take advantage
\r
706 ; of word copies, but this is an infrequently called routine.
\r
710 ;===========================================================================
\r
712 PROC VW_ScreenToMem source:WORD, dest:WORD, wide:WORD, height:WORD
\r
713 PUBLIC VW_ScreenToMem
\r
726 mov dx,[height] ;scan lines to draw
\r
738 mov ds,ax ;restore turbo's data segment
\r
745 ;===========================================================================
\r
747 ; MISC CGA ROUTINES
\r
749 ;===========================================================================
\r
759 PROC VW_SetScreen crtc:WORD
\r
760 PUBLIC VW_SetScreen
\r
763 ; for some reason, my XT's EGA card doesn't like word outs to the CRTC
\r
770 mov al,0ch ;start address high register
\r
776 mov al,0dh ;start address low register
\r
789 if NUMFONT+NUMFONTM
\r
791 ;===========================================================================
\r
793 ; GENERAL FONT DRAWING ROUTINES
\r
795 ;===========================================================================
\r
799 px dw ? ; proportional character drawing coordinates
\r
801 pdrawmode db 11000b ; 8 = OR, 24 = XOR, put in GC_DATAROTATE
\r
802 fontcolor db 15 ;0-15 mapmask value
\r
804 PUBLIC px,py,pdrawmode,fontcolor
\r
807 ; offsets in font structure
\r
809 pcharheight = 0 ;lines high
\r
810 charloc = 2 ;pointers to every character
\r
811 charwidth = 514 ;every character's width in pixels
\r
814 propchar dw ? ; the character number to shift
\r
817 fontcolormask dw ? ; font color expands into this
\r
820 BUFFHEIGHT = 32 ; must be twice as high as font for masked fonts
\r
822 databuffer db BUFFWIDTH*BUFFHEIGHT dup (?)
\r
824 bufferwidth dw ? ; bytes with valid info / line
\r
825 bufferheight dw ? ; number of lines currently used
\r
829 PUBLIC bufferwidth,bufferheight,bufferbyte,bufferbit
\r
831 screenspot dw ? ; where the buffer is going
\r
833 bufferextra dw ? ; add at end of a line copy
\r
838 ;======================
\r
840 ; Macros to table shift a byte of font
\r
842 ;======================
\r
845 mov al,[es:bx] ; source
\r
849 mov ax,[bp+si] ; table shift into two bytes
\r
850 or [di],al ; or with first byte
\r
852 mov [di],ah ; replace next byte
\r
853 inc bx ; next source byte
\r
857 mov al,[es:bx] ; source
\r
861 mov ax,[bp+si] ; table shift into two bytes
\r
863 and [di],al ; and with first byte
\r
865 mov [di],ah ; replace next byte
\r
866 inc bx ; next source byte
\r
870 ;=======================
\r
874 ; Pass buffer start in SI (somewhere in databuffer)
\r
875 ; Draws the buffer to the screen buffer
\r
877 ;========================
\r
879 PROC VWL_XORBuffer NEAR
\r
884 mov ax,[colorword+bx]
\r
885 mov [fontcolormask],ax
\r
888 mov di,[screenspot]
\r
890 mov bx,[bufferwidth] ;calculate offsets for end of each line
\r
891 mov [bufferwidth],bx
\r
895 ret ;nothing to draw
\r
902 ; clear the last byte so word draws can be used
\r
908 mov [BYTE databuffer+BUFFWIDTH*line+bx],al
\r
916 mov [screenextra],ax
\r
919 mov [bufferextra],ax
\r
921 shr dx,1 ;word to copy
\r
923 mov bx,[bufferheight] ;lines to copy
\r
924 mov bp,[fontcolormask]
\r
928 lodsw ;get a word from the buffer
\r
930 xor [es:di],ax ;draw it
\r
934 add si,[bufferextra]
\r
935 add di,[screenextra]
\r
946 ;============================================================================
\r
948 ; NON MASKED FONT DRAWING ROUTINES
\r
950 ;============================================================================
\r
956 shiftdrawtable dw 0,shift1wide,shift2wide,shift3wide,shift4wide
\r
957 dw shift5wide,shift6wide
\r
961 ;==================
\r
965 ; Call with BX = character number (0-255)
\r
966 ; Draws one character to the buffer at bufferbyte/bufferbit, and adjusts
\r
967 ; them to the new position
\r
969 ;==================
\r
971 PROC ShiftPropChar NEAR
\r
973 mov es,[grsegs+STARTFONT*2] ;segment of font to use
\r
976 ; find character location, width, and height
\r
978 mov si,[es:charwidth+bx]
\r
979 and si,0ffh ;SI hold width in pixels
\r
981 mov bx,[es:charloc+bx] ;BX holds pointer to character data
\r
984 ; look up which shift table to use, based on bufferbit
\r
988 mov bp,[shifttabletable+di] ;BP holds pointer to shift table
\r
990 mov di,OFFSET databuffer
\r
991 add di,[bufferbyte] ;DI holds pointer to buffer
\r
994 add cx,si ;add twice because pixel == two bits
\r
995 add cx,si ;new bit position
\r
998 mov [bufferbit],ax ;new bit position
\r
1003 add [bufferbyte],ax ;new byte position
\r
1007 shr si,1 ;bytes the character is wide
\r
1008 shl si,1 ;*2 to look up in shiftdrawtable
\r
1010 mov cx,[es:pcharheight]
\r
1012 jmp [ss:shiftdrawtable+si] ;procedure to draw this width
\r
1015 ; one byte character
\r
1022 add di,dx ; next line in buffer
\r
1029 ; two byte character
\r
1038 add di,dx ; next line in buffer
\r
1045 ; three byte character
\r
1054 add di,dx ; next line in buffer
\r
1062 ; four byte character
\r
1072 add di,dx ; next line in buffer
\r
1080 ; five byte character
\r
1091 add di,dx ; next line in buffer
\r
1098 ; six byte character
\r
1110 add di,dx ; next line in buffer
\r
1120 ;============================================================================
\r
1122 ;==================
\r
1124 ; VW_DrawPropString
\r
1126 ; Draws a C string of characters at px/py and advances px
\r
1128 ;==================
\r
1132 PROC VW_DrawPropString string:DWORD
\r
1133 PUBLIC VW_DrawPropString
\r
1137 ; proportional spaceing, which clears the buffer ahead of it, so only
\r
1138 ; clear the first collumn
\r
1143 mov [BYTE databuffer+BUFFWIDTH*line],al
\r
1148 ; shift the characters into the buffer
\r
1153 shl ax,1 ;one pixel == two bits
\r
1154 mov [bufferbit],ax
\r
1155 mov [bufferbyte],0
\r
1157 mov ax,[WORD string]
\r
1158 mov [stringptr],ax
\r
1159 mov ax,[WORD string+2]
\r
1160 mov [stringptr+2],ax
\r
1163 mov es,[stringptr+2]
\r
1164 mov bx,[stringptr]
\r
1170 call ShiftPropChar
\r
1175 ; calculate position to draw buffer on screen
\r
1179 mov di,[ylookup+bx]
\r
1180 add di,[bufferofs]
\r
1181 add di,[panadjust]
\r
1185 shr ax,1 ;x location in bytes
\r
1187 mov [screenspot],di
\r
1192 mov ax,[bufferbyte]
\r
1195 mov bx,[bufferbit]
\r
1196 shr bx,1 ;two bits == one pixel
\r
1203 mov ax,[bufferbyte]
\r
1204 test [bufferbit],7
\r
1206 inc ax ;so the partial byte also gets drawn
\r
1208 mov [bufferwidth],ax
\r
1209 mov es,[grsegs+STARTFONT*2]
\r
1210 mov ax,[es:pcharheight]
\r
1211 mov [bufferheight],ax
\r
1213 mov si,OFFSET databuffer
\r
1214 call VWL_XORBuffer
\r
1222 ;============================================================================
\r
1224 ; MASKED FONT DRAWING ROUTINES
\r
1226 ;============================================================================
\r
1232 mshiftdrawtable dw 0,mshift1wide,mshift2wide,mshift3wide
\r
1237 ;==================
\r
1241 ; Call with BX = character number (0-255)
\r
1242 ; Draws one character to the buffer at bufferbyte/bufferbit, and adjusts
\r
1243 ; them to the new position
\r
1245 ;==================
\r
1247 PROC ShiftMPropChar NEAR
\r
1249 mov es,[grsegs+STARTFONTM*2] ;segment of font to use
\r
1252 ; find character location, width, and height
\r
1254 mov si,[es:charwidth+bx]
\r
1255 and si,0ffh ;SI hold width in pixels
\r
1257 mov bx,[es:charloc+bx] ;BX holds pointer to character data
\r
1260 ; look up which shift table to use, based on bufferbit
\r
1262 mov di,[bufferbit]
\r
1264 mov bp,[shifttabletable+di] ;BP holds pointer to shift table
\r
1266 mov di,OFFSET databuffer
\r
1267 add di,[bufferbyte] ;DI holds pointer to buffer
\r
1270 ; advance position by character width
\r
1272 mov cx,[bufferbit]
\r
1273 add cx,si ;new bit position
\r
1276 mov [bufferbit],ax ;new bit position
\r
1281 add [bufferbyte],ax ;new byte position
\r
1286 shr si,1 ;bytes the character is wide
\r
1287 shl si,1 ;*2 to look up in shiftdrawtable
\r
1289 mov cx,[es:pcharheight]
\r
1291 jmp [ss:mshiftdrawtable+si] ;procedure to draw this width
\r
1294 ; one byte character
\r
1302 add di,dx ; next line in buffer
\r
1306 mov cx,[es:pcharheight]
\r
1311 add di,dx ; next line in buffer
\r
1317 ; two byte character
\r
1326 add di,dx ; next line in buffer
\r
1330 mov cx,[es:pcharheight]
\r
1336 add di,dx ; next line in buffer
\r
1342 ; three byte character
\r
1351 add di,dx ; next line in buffer
\r
1355 mov cx,[es:pcharheight]
\r
1362 add di,dx ; next line in buffer
\r
1370 ;============================================================================
\r
1372 ;==================
\r
1374 ; VW_DrawMPropString
\r
1376 ; Draws a C string of characters at px/py and advances px
\r
1378 ;==================
\r
1382 PROC VW_DrawMPropString string:DWORD
\r
1383 PUBLIC VW_DrawMPropString
\r
1387 ; clear out the first byte of the buffer, the rest will automatically be
\r
1388 ; cleared as characters are drawn into it
\r
1390 mov es,[grsegs+STARTFONTM*2]
\r
1391 mov dx,[es:pcharheight]
\r
1392 mov di,OFFSET databuffer
\r
1395 mov bx,BUFFWIDTH-1
\r
1400 stosb ; fill the mask part with $ff
\r
1407 stosb ; fill the data part with $0
\r
1412 ; shift the characters into the buffer
\r
1416 mov [bufferbit],ax
\r
1417 mov [bufferbyte],0
\r
1419 mov ax,[WORD string]
\r
1420 mov [stringptr],ax
\r
1421 mov ax,[WORD string+2]
\r
1422 mov [stringptr+2],ax
\r
1425 mov es,[stringptr+2]
\r
1426 mov bx,[stringptr]
\r
1432 call ShiftMPropChar
\r
1437 ; calculate position to draw buffer on screen
\r
1441 mov di,[ylookup+bx]
\r
1442 add di,[bufferofs]
\r
1447 shr ax,1 ;x location in bytes
\r
1449 mov [screenspot],di
\r
1454 mov ax,[bufferbyte]
\r
1464 mov ax,[bufferbyte]
\r
1465 test [bufferbit],7
\r
1467 inc ax ;so the partial byte also gets drawn
\r
1469 mov [bufferwidth],ax
\r
1470 mov es,[grsegs+STARTFONTM*2]
\r
1471 mov ax,[es:pcharheight]
\r
1472 mov [bufferheight],ax
\r
1474 mov si,OFFSET databuffer
\r
1475 call BufferToScreen ; cut out mask
\r
1477 call BufferToScreen ; SI is still in the right position in buffer
\r
1483 endif ; if numfontm
\r