]> 4ch.mooo.com Git - 16.git/blob - src/lib/hb/c3_asm.asm
[16_ca needs huge amounts of work and I should remember what needs to be done soon...
[16.git] / src / lib / hb / c3_asm.asm
1 ; Catacomb 3-D Source Code\r
2 ; Copyright (C) 1993-2014 Flat Rock Software\r
3 ;\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
8 ;\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
13 ;\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
17 \r
18 IDEAL\r
19 \r
20 MODEL   MEDIUM,C\r
21 \r
22 VIEWWIDTH       =       (33*8)\r
23 GC_INDEX        =       03CEh\r
24 \r
25 DATASEG\r
26 EVEN\r
27 \r
28 ;=================== Tables filled in by DrawVWall ==========================\r
29 \r
30 ;\r
31 ; wallheight has the height (scale number) of that collumn of scaled wall\r
32 ; it is pre bounded to 1-MAXSCALE (the actuial height on screen is 2*height)\r
33 ;\r
34 wallheight      dw      VIEWWIDTH dup (?)\r
35 \r
36 ;\r
37 ; wallwidth has the pixel width (1-7) of that collumn\r
38 ;\r
39 wallwidth       dw      VIEWWIDTH dup (?)\r
40 \r
41 ;\r
42 ; wallseg has the segment of the wall picture\r
43 ;\r
44 wallseg         dw      VIEWWIDTH dup (?)\r
45 \r
46 ;\r
47 ; wallofs has the offset of the wall picture\r
48 ;\r
49 wallofs         dw      VIEWWIDTH dup (?)\r
50 \r
51 ;============================================================================\r
52 \r
53 ;\r
54 ; screenbyte is just position/8\r
55 ;\r
56 LABEL           screenbyte      WORD\r
57 pos     =       0\r
58 REPT            VIEWWIDTH\r
59                         dw      pos/8\r
60 pos     =       pos+1\r
61 ENDM\r
62 \r
63 ;\r
64 ; screenbit is (position&7)*16\r
65 ;\r
66 LABEL           screenbit       WORD\r
67 pos     =       0\r
68 REPT            VIEWWIDTH\r
69                         dw      (pos AND 7)*16\r
70 pos     =       pos+1\r
71 ENDM\r
72 \r
73 ;\r
74 ; Use offset: screenbit[]+pixwidth*2\r
75 ; acess from bitmasks-2+offset for one biased pixwidth\r
76 ; the low byte of bitmasks is for the first screen byte, the high byte\r
77 ; is the bitmask for the second screen byte (if non 0)\r
78 ;\r
79 \r
80 bitmasks        dw      0080h,00c0h,00e0h,00f0h,00f8h,00fch,00feh,00ffh\r
81                         dw      0040h,0060h,0070h,0078h,007ch,007eh,007fh,807fh\r
82                         dw      0020h,0030h,0038h,003ch,003eh,003fh,803fh,0c03fh\r
83                         dw      0010h,0018h,001ch,001eh,001fh,801fh,0c01fh,0e01fh\r
84                         dw      0008h,000ch,000eh,000fh,800fh,0c00fh,0e00fh,0f00fh\r
85                         dw      0004h,0006h,0007h,8007h,0c007h,0e007h,0f007h,0f807h\r
86                         dw      0002h,0003h,8003h,0c003h,0e003h,0f003h,0f803h,0fc03h\r
87                         dw      0001h,8001h,0c001h,0e001h,0f001h,0f801h,0fc01h,0fe01h\r
88 \r
89 \r
90 ;\r
91 ; wallscalecall is a far pointer to the start of a compiled scaler\r
92 ; The low word will never change, while the high word is set to\r
93 ; compscaledirectory[scale]\r
94 ;\r
95 wallscalecall   dd      (65*6)                  ; offset of t_compscale->code[0]\r
96 \r
97 \r
98 PUBLIC  wallheight,wallwidth,wallseg,wallofs,screenbyte,screenbit\r
99 PUBLIC  bitmasks,wallscalecall\r
100 \r
101 \r
102 EXTRN   scaledirectory:WORD                     ; array of MAXSCALE segment pointers to\r
103                                                                         ; compiled scalers\r
104 EXTRN   screenseg:WORD                          ; basically just 0xa000\r
105 EXTRN   bufferofs:WORD                          ; offset of the current work screen\r
106 \r
107 CODESEG\r
108 \r
109 ;============================================================================\r
110 ;\r
111 ; ScaleWalls\r
112 ;\r
113 ; AX    AL is scratched in bit mask setting and scaling\r
114 ; BX    table index\r
115 ; CX    pixwidth*2\r
116 ; DX    GC_INDEX\r
117 ; SI    offset into wall data to scale from, allways 0,64,128,...4032\r
118 ; DI    byte at top of screen that the collumn is contained in\r
119 ; BP    x pixel * 2, index into VIEWWIDTH wide tables\r
120 ; DS    segment of the wall data to texture map\r
121 ; ES    screenseg\r
122 ; SS    addressing DGROUP variables\r
123 ;\r
124 ;============================================================================\r
125 \r
126 PROC    ScaleWalls\r
127 PUBLIC  ScaleWalls\r
128 USES    SI,DI,BP\r
129 \r
130         xor     bp,bp                                           ; start at location 0 in the tables\r
131         mov     dx,GC_INDEX+1\r
132         mov     es,[screenseg]\r
133 \r
134 ;\r
135 ; scale one collumn of data, possibly across two bytes\r
136 ;\r
137 nextcollumn:\r
138 \r
139         mov     bx,[wallheight+bp]                      ; height of walls (1-MAXSCALE)\r
140         shl     bx,1\r
141         mov     ax,[ss:scaledirectory+bx]       ; segment of the compiled scaler\r
142         mov [WORD PTR ss:wallscalecall+2],ax\r
143 \r
144         mov     cx,[wallwidth+bp]\r
145         or      cx,cx\r
146         jnz     okwidth\r
147         mov     cx,2\r
148         jmp     next\r
149 \r
150 okwidth:\r
151         shl     cx,1\r
152         mov     ds,[wallseg+bp]\r
153         mov     si,[wallofs+bp]\r
154 \r
155         mov     di,[screenbyte+bp]                      ; byte at the top of the scaled collumn\r
156         add     di,[ss:bufferofs]                       ; offset of current page flip\r
157         mov     bx,[screenbit+bp]                       ; 0-7 << 4\r
158         add     bx,cx\r
159         mov     ax,[ss:bitmasks-2+bx]\r
160         out     dx,al                                           ; set bit mask register\r
161         call [DWORD PTR ss:wallscalecall]               ; scale the line of pixels\r
162         or      ah,ah                                           ; is there anything in the second byte?\r
163         jnz     secondbyte\r
164 ;\r
165 ; next\r
166 ;\r
167 next:\r
168         add     bp,cx\r
169         cmp     bp,VIEWWIDTH*2\r
170         jb      nextcollumn\r
171         jmp     done\r
172 \r
173 ;\r
174 ; draw a second byte for vertical strips that cross two bytes\r
175 ;\r
176 secondbyte:\r
177         mov     al,ah\r
178         inc     di                                                              ; next byte over\r
179         out     dx,al                                                   ; set bit mask register\r
180         call [DWORD PTR ss:wallscalecall]       ; scale the line of pixels\r
181 ;\r
182 ; next\r
183 ;\r
184         add     bp,cx\r
185         cmp     bp,VIEWWIDTH*2\r
186         jb      nextcollumn\r
187 \r
188 done:\r
189         mov     ax,ss\r
190         mov     ds,ax\r
191         ret\r
192 \r
193 ENDP\r
194 \r
195 \r
196 END\r
197 \r