]> 4ch.mooo.com Git - 16.git/blob - src/lib/hb/c3_sca_a.asm
[16_ca needs huge amounts of work and I should remember what needs to be done soon...
[16.git] / src / lib / hb / c3_sca_a.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 MODEL   MEDIUM,C\r
20 \r
21 include "ID_ASM.EQU"\r
22 \r
23 ;===========================================================================\r
24 ;\r
25 ;                    SCALING GRAPHICS\r
26 ;\r
27 ;===========================================================================\r
28 \r
29 \r
30 \r
31 MACRO   MAKELAB NUM\r
32 \r
33 lab&NUM:\r
34 \r
35 ENDM\r
36 \r
37 MACRO   MAKEREF NUM\r
38 \r
39 dw OFFSET lab&NUM\r
40 \r
41 ENDM\r
42 \r
43 \r
44 ;=========================================================================\r
45 \r
46 MAXSCALES equ 256\r
47 \r
48         DATASEG\r
49 \r
50 EXTRN   screenseg:WORD\r
51 EXTRN   linewidth:WORD\r
52 \r
53 LABEL endtable WORD\r
54 labcount = 0\r
55 REPT MAXSCALES\r
56 MAKEREF %labcount\r
57 labcount = labcount + 1\r
58 ENDM\r
59 \r
60 \r
61         CODESEG\r
62 \r
63 ;==================================================\r
64 ;\r
65 ; void scaleline (int scale, unsigned picseg, unsigned maskseg,\r
66 ;                 unsigned screen, unsigned width)\r
67 ;\r
68 ;==================================================\r
69 \r
70 PROC    ScaleLine pixels:word, scaleptr:dword, picptr:dword, screen:word\r
71 USES    si,di\r
72 PUBLIC  ScaleLine\r
73 \r
74 ;\r
75 ; modify doline procedure for proper width\r
76 ;\r
77         mov     bx,[pixels]\r
78         cmp     bx,MAXSCALES\r
79         jbe     @@scaleok\r
80         mov     bx,MAXSCALES\r
81 @@scaleok:\r
82         shl     bx,1\r
83         mov     bx,[endtable+bx]\r
84         push    [cs:bx]                 ;save the code that will be modified over\r
85         mov     [WORD cs:bx],0d18eh     ;mov ss,cx\r
86         push    [cs:bx+2]               ;save the code that will be modified over\r
87         mov     [WORD cs:bx+2],90c3h    ;ret / nop\r
88         push    bx\r
89 \r
90         mov     dx,[linewidth]\r
91 \r
92         mov     di,[WORD screen]\r
93         mov     es,[screenseg]\r
94 \r
95         mov     si,[WORD scaleptr]\r
96         mov     ds,[WORD scaleptr+2]\r
97 \r
98         mov     bx,[WORD picptr]\r
99         mov     ax,[WORD picptr+2]      ;will be moved into ss after call\r
100 \r
101         mov     bp,bx\r
102 \r
103         cli\r
104         call    doline\r
105         sti\r
106 ;\r
107 ; restore doline to regular state\r
108 ;\r
109         pop     bx              ;address of modified code\r
110         pop     [cs:bx+2]\r
111         pop     [cs:bx]\r
112 \r
113         mov     ax,ss\r
114         mov     ds,ax\r
115         ret\r
116 \r
117 ;================\r
118 ;\r
119 ; doline\r
120 ;\r
121 ; Big unwound scaling routine\r
122 ;\r
123 ; ds:si = scale table\r
124 ; ss:bx = pic data\r
125 ; es:di = screen location\r
126 ;\r
127 ;================\r
128 \r
129 doline:\r
130 \r
131         mov     cx,ss\r
132         mov     ss,ax           ;can't call a routine with ss used...\r
133 \r
134 labcount = 0\r
135 \r
136 REPT MAXSCALES\r
137 \r
138 MAKELAB %labcount\r
139 labcount = labcount + 1\r
140 \r
141         lodsb                   ; get scaled pixel number\r
142         xlat    [ss:bx]         ; look it up in the picture\r
143         xchg    [es:di],al      ; load latches and write pixel to screen\r
144         add     di,dx           ; down to next line\r
145 \r
146 ENDM\r
147 \r
148         mov     ss,cx\r
149         ret\r
150 \r
151 ENDP\r
152 \r
153 END