Merge branch 'feature/handle-quit-event'
[jumpnbump.git] / dos / gfx.S
blob1b895afb24acc21e466394bae7648d5cbdfc4d3d
1 [GLOBAL _get_block]
2 [GLOBAL _put_block]
4 [EXTERN ___djgpp_base_address]
7 [SECTION .text]
10 ; void get_block(char page, long x, long y, long width, long height, char *buffer);
12 _get_block
13         push    ebp
14         mov     ebp,esp
15         pusha
17         mov     eax,[ebp+12]
18         mov     [.x],eax
19         mov     eax,[ebp+16]
20         mov     [.y],eax
21         mov     eax,[ebp+20]
22         mov     [.draw_width],eax
23         mov     eax,[ebp+24]
24         mov     [.draw_height],eax
25         mov     eax,[ebp+28]
26         mov     [.buf_ptr],eax
28         mov     eax,[.x]
29         or      eax,eax
30         jns     .11
32         neg     eax
33         cmp     eax,[ebp+20]
34         jge     near .exit
36         mov     dword [.x],0
37         sub     [.draw_width],eax
38         add     [.buf_ptr],eax
40 .11
41         cmp     dword [.x],400
42         jge     near .exit
44         mov     eax,[.y]
45         or      eax,eax
46         jns     .12
48         neg     eax
49         cmp     eax,[ebp+24]
50         jge     near .exit
52         mov     dword [.y],0
53         sub     [.draw_height],eax
54         imul    dword [ebp+20]
55         add     [.buf_ptr],eax
57 .12
58         cmp     eax,256
59         jge     near .exit
61         mov     edi,0xa0000
62         sub     edi,[___djgpp_base_address]
63         xor     eax,eax
64         mov     al,[ebp+8]
65         shl     eax,15
66         add     edi,eax
67         mov     eax,100
68         imul    dword [.y]
69         add     edi,eax
70         mov     [.vga_ptr],edi
72         mov     dword [.c1],0
75         mov     edx,0x3ce
76         mov     eax,[.x]
77         add     eax,[.c1]
78         shl     eax,8
79         and     ah,3
80         mov     al,4
81         out     dx,ax
83         mov     esi,[.vga_ptr]
84         mov     eax,[.x]
85         add     eax,[.c1]
86         sar     eax,2
87         add     esi,eax
89         mov     edi,[.buf_ptr]
90         add     edi,[.c1]
92         mov     ebx,[.draw_height]
95         mov     ecx,[.draw_width]
96         add     ecx,3
97         sub     ecx,[.c1]
98         shr     ecx,2
99         mov     edx,ecx
100         cmp     ecx,0
101         jle     .4
104         mov     al,[esi]
105         mov     [edi],al
106         inc     esi
107         add     edi,4
108         dec     cx
109         jnz     .3
112         add     esi,100
113         sub     esi,edx
115         add     edi,[ebp+20]
116         mov     eax,edx
117         shl     eax,2
118         sub     edi,eax
120         dec     ebx
121         jnz     .2
123         inc     byte [.c1]
124         cmp     byte [.c1],4
125         jl      near .1
127 .exit
128         popa
129         pop     ebp
130         ret
132 .c1             dd      0
133 .vga_ptr        dd      0
134 .x              dd      0
135 .y              dd      0
136 .draw_width     dd      0
137 .draw_height    dd      0
138 .buf_ptr        dd      0
141 ; void put_block(char page, long x, long y, long width, long height, char *buffer);
143 _put_block
144         push    ebp
145         mov     ebp,esp
146         pusha
148         mov     eax,[ebp+12]
149         mov     [.x],eax
150         mov     eax,[ebp+16]
151         mov     [.y],eax
152         mov     eax,[ebp+20]
153         mov     [.draw_width],eax
154         mov     eax,[ebp+24]
155         mov     [.draw_height],eax
156         mov     eax,[ebp+28]
157         mov     [.buf_ptr],eax
159         mov     eax,[.x]
160         or      eax,eax
161         jns     .11
163         neg     eax
164         cmp     eax,[ebp+20]
165         jge     near .exit
167         mov     dword [.x],0
168         sub     [.draw_width],eax
169         add     [.buf_ptr],eax
172         cmp     dword [.x],400
173         jge     near .exit
175         mov     eax,[.y]
176         or      eax,eax
177         jns     .12
179         neg     eax
180         cmp     eax,[ebp+24]
181         jge     near .exit
183         mov     dword [.y],0
184         sub     [.draw_height],eax
185         imul    dword [ebp+20]
186         add     [.buf_ptr],eax
189         cmp     eax,256
190         jge     near .exit
192         mov     edi,0xa0000
193         sub     edi,[___djgpp_base_address]
194         xor     eax,eax
195         mov     al,[ebp+8]
196         shl     eax,15
197         add     edi,eax
198         mov     eax,100
199         imul    dword [.y]
200         add     edi,eax
201         mov     [.vga_ptr],edi
203         mov     dword [.c1],0
206         mov     edx,0x3c4
207         mov     eax,0x100
208         mov     ecx,[.x]
209         add     ecx,[.c1]
210         and     ecx,3
211         shl     eax,cl
212         mov     al,2
213         out     dx,ax
215         mov     esi,[.buf_ptr]
216         add     esi,[.c1]
218         mov     edi,[.vga_ptr]
219         mov     eax,[.x]
220         add     eax,[.c1]
221         sar     eax,2
222         add     edi,eax
224         mov     ebx,[.draw_height]
227         mov     ecx,[.draw_width]
228         add     ecx,3
229         sub     ecx,[.c1]
230         shr     ecx,2
231         mov     edx,ecx
232         cmp     ecx,0
233         jle     .4
236         mov     al,[esi]
237         mov     [edi],al
238         add     esi,4
239         inc     edi
240         dec     ecx
241         jnz     .3
244         add     esi,[ebp+20]
245         mov     eax,edx
246         shl     eax,2
247         sub     esi,eax
249         add     edi,100
250         sub     edi,edx
252         dec     ebx
253         jnz     .2
255         inc     byte [.c1]
256         cmp     byte [.c1],4
257         jl      near .1
259 .exit
260         popa
261         pop     ebp
262         ret
264 .c1             dd      0
265 .vga_ptr        dd      0
266 .x              dd      0
267 .y              dd      0
268 .draw_width     dd      0
269 .draw_height    dd      0
270 .buf_ptr        dd      0