]> 4ch.mooo.com Git - 16.git/blob - 16/xx/mxfb.asm
wwww
[16.git] / 16 / xx / mxfb.asm
1 ;-----------------------------------------------------------\r
2 ;\r
3 ; MXFB.ASM - Fill box function\r
4 ; Copyright (c) 1993,1994 by Alessandro Scotti\r
5 ;\r
6 ;-----------------------------------------------------------\r
7 WARN    PRO\r
8 NOWARN  RES\r
9 INCLUDE MODEX.DEF\r
10 \r
11 PUBLIC  mxFillBox\r
12 \r
13 MX_TEXT         SEGMENT USE16 PARA PUBLIC 'CODE'\r
14                 ASSUME cs:MX_TEXT, ds:NOTHING, es:NOTHING\r
15 \r
16 EXTRN   mx_BytesPerLine         : WORD\r
17 EXTRN   mx_VideoSegment         : WORD\r
18 EXTRN   subClipBox              : NEAR\r
19 EXTRN   subHorizontalLineInfo   : NEAR\r
20 \r
21 ;-----------------------------------------------------------\r
22 ;\r
23 ; Raster op functions. Raster op is limited to OP_MOVE,\r
24 ; OP_AND, OP_OR and OP_XOR. The VGA hardware is used to\r
25 ; perform the selected logical functions on up to four\r
26 ; pixel at a time.\r
27 ;\r
28 subRepFill      PROC    NEAR\r
29         mov     ah, al\r
30         shr     cx, 1\r
31         rep     stosw\r
32         rcl     cx, 1\r
33         rep     stosb\r
34         ret\r
35 subRepFill      ENDP\r
36 ;\r
37 subFill         PROC    NEAR\r
38 @@Loop:\r
39         mov     ds:[bx], al\r
40         add     bx, dx\r
41         loop    @@Loop\r
42         ret\r
43 subFill         ENDP\r
44 ;\r
45 subRepMove      PROC    NEAR\r
46         mov     si, di\r
47 @@Loop:\r
48         mov     ah, ds:[si]             ; Dummy read to latch the data\r
49         mov     ds:[si], al\r
50         inc     si\r
51         loop    @@Loop\r
52         ret\r
53 subRepMove      ENDP\r
54 ;\r
55 subMove         PROC    NEAR\r
56 @@Loop:\r
57         mov     ah, ds:[bx]             ; Dummy read to latch the data\r
58         mov     ds:[bx], al\r
59         add     bx, dx\r
60         loop    @@Loop\r
61         ret\r
62 subMove         ENDP\r
63 \r
64 ;-----------------------------------------------------------\r
65 ;\r
66 ; Fills a rectangle with a specified color.\r
67 ;\r
68 ; Input:\r
69 ;       X, Y            = X, Y coordinates of rectangle\r
70 ;       Width           = width of rectangle\r
71 ;       Height          = height of rectangle\r
72 ;       Color           = fill color\r
73 ;       Op              = raster operator\r
74 ; Output:\r
75 ;       none\r
76 ;\r
77 ; Note: raster op is limited to OP_MOVE, OP_AND, OP_OR and OP_XOR.\r
78 ;\r
79 mxFillBox       PROC    FAR\r
80         ARG     Op:WORD,                \\r
81                 Color:BYTE:2,           \\r
82                 Height:WORD,            \\r
83                 Width:WORD,             \\r
84                 Y:WORD,                 \\r
85                 X:WORD                  = ARG_SIZE\r
86         LOCAL   LeftMask:BYTE,          \\r
87                 RightMask:BYTE,         \\r
88                 FillFunction:WORD,      \\r
89                 RepFillFunction:WORD    = AUTO_SIZE\r
90         .enter  AUTO_SIZE\r
91         .push   ds, si, es, di\r
92         ASSUME  ds:NOTHING\r
93 \r
94 ; Clip rectangle\r
95         mov     bx, [X]\r
96         mov     ax, [Y]\r
97         mov     cx, [Width]\r
98         mov     dx, [Height]\r
99         call    subClipBox\r
100         jc      @@Exit                  ; Full clipped\r
101 \r
102         mov     [Height], dx            ; Save clipped height\r
103         call    subHorizontalLineInfo   ; Get additional info, init DI\r
104         mov     [Width], cx\r
105         mov     [LeftMask], al\r
106         mov     [RightMask], ah\r
107 \r
108 ; Initialize segments\r
109         mov     ax, [mx_VideoSegment]\r
110         mov     es, ax                  ; ES:DI points to pixel\r
111         mov     ds, ax\r
112         cld                             ; Clear direction flag\r
113 \r
114 ; Select fill functions\r
115         mov     [FillFunction], OFFSET subFill\r
116         mov     [RepFillFunction], OFFSET subRepFill\r
117         mov     ax, [Op]                ; Get raster op\r
118         cmp     al, OP_XOR\r
119         ja      @@1                     ; Assume it's a fill\r
120         cmp     al, OP_MOVE\r
121         je      @@1\r
122         .shl    al, 3\r
123         mov     ah, al\r
124         mov     al, 03h\r
125         mov     dx, GDC\r
126         out     dx, ax                  ; Set GDC logical function\r
127         mov     [FillFunction], OFFSET subMove\r
128         mov     [RepFillFunction], OFFSET subRepMove\r
129 @@1:\r
130 \r
131 ; Fill left block\r
132 @@L0:\r
133         mov     ah, [LeftMask]\r
134         or      ah, ah\r
135         jz      @@C0                    ; Nothing to do, go to center block\r
136         mov     dx, TS\r
137         mov     al, 02h\r
138         out     dx, ax                  ; Set write plane mask\r
139         mov     dx, [mx_BytesPerLine]\r
140         mov     cx, [Height]\r
141         mov     bx, di\r
142         mov     al, [Color]\r
143         call    [FillFunction]          ; Fill this column\r
144         inc     di                      ; Update starting video offset\r
145 \r
146 ; Fill center block\r
147 @@C0:\r
148         mov     cx, [Width]\r
149         jcxz    @@R0                    ; Nothing to do, go to right block\r
150         mov     dx, TS\r
151         mov     ax, 0F02h\r
152         out     dx, ax                  ; Write to all planes\r
153         mov     al, [Color]\r
154         mov     bx, di\r
155         mov     dx, [Height]\r
156         push    di                      ; Save pixel address\r
157 @@C1:\r
158         mov     di, bx                  ; Update video offset\r
159         call    [RepFillFunction]       ; Fill current scan line\r
160         mov     cx, [Width]             ; Restore byte count\r
161         add     bx, [mx_BytesPerLine]   ; Bump to next scan line\r
162         dec     dx                      ; Done all lines?\r
163         jnz     @@C1                    ; No, continue\r
164         pop     di                      ; Restore pixel address\r
165         add     di, [Width]             ; Go to right block\r
166 \r
167 ; Fill right block\r
168 @@R0:\r
169         mov     ah, [RightMask]\r
170         or      ah, ah\r
171         jz      @@Done                  ; Nothing to do, exit\r
172         mov     dx, TS\r
173         mov     al, 02h\r
174         out     dx, ax                  ; Set write plane mask\r
175         mov     dx, [mx_BytesPerLine]\r
176         mov     cx, [Height]\r
177         mov     bx, di\r
178         mov     al, [Color]\r
179         call    [FillFunction]          ; Fill this column\r
180 \r
181 ; Restore VGA registers\r
182 @@Done:\r
183         mov     dx, GDC\r
184         mov     ax, 0003h\r
185         out     dx, ax                  ; Set logical function to "move"\r
186 \r
187 @@Exit:\r
188         xor     ax, ax\r
189         .pop    ds, si, es, di\r
190         .leave  ARG_SIZE\r
191 mxFillBox       ENDP\r
192 \r
193 MX_TEXT         ENDS\r
194 END\r