Rev 3555 | Details | Compare with Previous | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
431 | serge | 1 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
2 | ;; ;; |
||
5565 | serge | 3 | ;; Copyright (C) KolibriOS team 2004-2015. All rights reserved. ;; |
431 | serge | 4 | ;; Distributed under terms of the GNU General Public License ;; |
5 | ;; ;; |
||
6 | ;; VGA.INC ;; |
||
7 | ;; ;; |
||
8 | ;; 640x480 mode 0x12 VGA functions for MenuetOS ;; |
||
9 | ;; ;; |
||
10 | ;; Paul Butcher, paul.butcher@asa.co.uk ;; |
||
11 | ;; ;; |
||
12 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
||
1 | ha | 13 | |
593 | mikedld | 14 | $Revision: 5565 $ |
1 | ha | 15 | |
2439 | Serge | 16 | ;------------------------------------------------------------------------------ |
17 | align 4 |
||
1 | ha | 18 | paletteVGA: |
19 | |||
20 | ;16 colour palette |
||
2434 | Serge | 21 | mov dx, 0x3c8 |
22 | mov al, 0 |
||
23 | out dx, al |
||
1 | ha | 24 | |
2434 | Serge | 25 | mov ecx, 16 |
26 | mov dx, 0x3c9 |
||
27 | xor eax, eax |
||
2439 | Serge | 28 | ;-------------------------------------- |
29 | align 4 |
||
30 | palvganew: |
||
2434 | Serge | 31 | mov al, 0 |
32 | test ah, 4 |
||
33 | jz palvgalbl1 |
||
34 | add al, 31 |
||
35 | test ah, 8 |
||
36 | jz palvgalbl1 |
||
37 | add al, 32 |
||
2439 | Serge | 38 | ;-------------------------------------- |
39 | align 4 |
||
40 | palvgalbl1: |
||
2434 | Serge | 41 | out dx, al; red 0,31 or 63 |
42 | mov al, 0 |
||
43 | test ah, 2 |
||
44 | jz palvgalbl2 |
||
45 | add al, 31 |
||
46 | test ah, 8 |
||
47 | jz palvgalbl2 |
||
48 | add al, 32 |
||
2439 | Serge | 49 | ;-------------------------------------- |
50 | align 4 |
||
51 | palvgalbl2: |
||
2434 | Serge | 52 | out dx, al; blue 0,31 or 63 |
53 | mov al, 0 |
||
54 | test ah, 1 |
||
55 | jz palvgalbl3 |
||
56 | add al, 31 |
||
57 | test ah, 8 |
||
58 | jz palvgalbl3 |
||
59 | add al, 32 |
||
2439 | Serge | 60 | ;-------------------------------------- |
61 | align 4 |
||
62 | palvgalbl3: |
||
2434 | Serge | 63 | out dx, al; green 0,31 or 63 |
64 | add ah, 1 |
||
65 | loop palvganew |
||
117 | mario79 | 66 | ; mov dx, 3ceh |
379 | serge | 67 | ; mov ax, 0005h |
68 | ; out dx, ax |
||
2434 | Serge | 69 | ret |
2439 | Serge | 70 | ;------------------------------------------------------------------------------ |
71 | align 4 |
||
117 | mario79 | 72 | palette320x200: |
2434 | Serge | 73 | mov edx, 0x3c8 |
74 | xor eax, eax |
||
75 | out dx, al |
||
76 | mov ecx, 256 |
||
77 | mov edx, 0x3c9 |
||
78 | xor eax, eax |
||
2439 | Serge | 79 | ;-------------------------------------- |
80 | align 4 |
||
81 | palnew: |
||
2434 | Serge | 82 | mov al, 0 |
83 | test ah, 64 |
||
84 | jz pallbl1 |
||
85 | add al, 21 |
||
2439 | Serge | 86 | ;-------------------------------------- |
87 | align 4 |
||
88 | pallbl1: |
||
2434 | Serge | 89 | test ah, 128 |
90 | jz pallbl2 |
||
91 | add al, 42 |
||
2439 | Serge | 92 | ;-------------------------------------- |
93 | align 4 |
||
94 | pallbl2: |
||
2434 | Serge | 95 | out dx, al |
96 | mov al, 0 |
||
97 | test ah, 8 |
||
98 | jz pallbl3 |
||
99 | add al, 8 |
||
2439 | Serge | 100 | ;-------------------------------------- |
101 | align 4 |
||
102 | pallbl3: |
||
2434 | Serge | 103 | test ah, 16 |
104 | jz pallbl4 |
||
105 | add al, 15 |
||
2439 | Serge | 106 | ;-------------------------------------- |
107 | align 4 |
||
108 | pallbl4: |
||
2434 | Serge | 109 | test ah, 32 |
110 | jz pallbl5 |
||
111 | add al, 40 |
||
2439 | Serge | 112 | ;-------------------------------------- |
113 | align 4 |
||
114 | pallbl5: |
||
2434 | Serge | 115 | out dx, al |
116 | mov al, 0 |
||
117 | test ah, 1 |
||
118 | jz pallbl6 |
||
119 | add al, 8 |
||
2439 | Serge | 120 | ;-------------------------------------- |
121 | align 4 |
||
122 | pallbl6: |
||
2434 | Serge | 123 | test ah, 2 |
124 | jz pallbl7 |
||
125 | add al, 15 |
||
2439 | Serge | 126 | ;-------------------------------------- |
127 | align 4 |
||
128 | pallbl7: |
||
2434 | Serge | 129 | test ah, 4 |
130 | jz pallbl8 |
||
131 | add al, 40 |
||
2439 | Serge | 132 | ;-------------------------------------- |
133 | align 4 |
||
134 | pallbl8: |
||
2434 | Serge | 135 | out dx, al |
136 | add ah, 1 |
||
137 | loop palnew |
||
138 | ret |
||
2439 | Serge | 139 | ;------------------------------------------------------------------------------ |
1168 | Lrz | 140 | align 4 |
117 | mario79 | 141 | uglobal |
142 | novesachecksum dd 0x0 |
||
143 | EGA_counter db 0 |
||
144 | VGA_drawing_screen db 0 |
||
379 | serge | 145 | VGA_8_pixels: |
117 | mario79 | 146 | rb 16 |
147 | temp: |
||
148 | .cx dd 0 |
||
149 | endg |
||
2439 | Serge | 150 | ;------------------------------------------------------------------------------ |
1168 | Lrz | 151 | align 4 |
117 | mario79 | 152 | checkVga_N13: |
3555 | Serge | 153 | cmp [SCR_MODE], 0x13 |
2434 | Serge | 154 | jne @f |
1 | ha | 155 | |
117 | mario79 | 156 | pushad |
2434 | Serge | 157 | cmp [EGA_counter], 1 |
158 | je novesal |
||
159 | mov ecx, [MOUSE_X] |
||
160 | cmp ecx, [novesachecksum] |
||
161 | jne novesal |
||
117 | mario79 | 162 | popad |
2439 | Serge | 163 | ;-------------------------------------- |
164 | align 4 |
||
165 | @@: |
||
117 | mario79 | 166 | ret |
2439 | Serge | 167 | ;-------------------------------------- |
168 | align 4 |
||
169 | novesal: |
||
2434 | Serge | 170 | mov [novesachecksum], ecx |
171 | mov ecx, 0 |
||
172 | movzx eax, word [MOUSE_Y] |
||
173 | cmp eax, 100 |
||
174 | jge m13l3 |
||
175 | mov eax, 100 |
||
2439 | Serge | 176 | ;-------------------------------------- |
177 | align 4 |
||
178 | m13l3: |
||
2434 | Serge | 179 | cmp eax, 480-100 |
180 | jbe m13l4 |
||
181 | mov eax, 480-100 |
||
2439 | Serge | 182 | ;-------------------------------------- |
183 | align 4 |
||
184 | m13l4: |
||
2434 | Serge | 185 | sub eax, 100 |
186 | imul eax, 640*4 |
||
187 | add ecx, eax |
||
188 | movzx eax, word [MOUSE_X] |
||
189 | cmp eax, 160 |
||
190 | jge m13l1 |
||
191 | mov eax, 160 |
||
2439 | Serge | 192 | ;-------------------------------------- |
193 | align 4 |
||
194 | m13l1: |
||
2434 | Serge | 195 | cmp eax, 640-160 |
196 | jbe m13l2 |
||
197 | mov eax, 640-160 |
||
2439 | Serge | 198 | ;-------------------------------------- |
199 | align 4 |
||
200 | m13l2: |
||
2434 | Serge | 201 | sub eax, 160 |
202 | shl eax, 2 |
||
203 | add ecx, eax |
||
204 | mov esi, [LFBAddress] |
||
205 | add esi, ecx |
||
206 | mov edi, VGABasePtr |
||
207 | mov edx, 200 |
||
208 | mov ecx, 320 |
||
117 | mario79 | 209 | cld |
2439 | Serge | 210 | ;-------------------------------------- |
211 | align 4 |
||
212 | m13pix: |
||
117 | mario79 | 213 | lodsd |
2434 | Serge | 214 | test eax, eax |
215 | jz .save_pixel |
||
216 | push eax |
||
217 | mov ebx, eax |
||
218 | and eax, (128+64+32) ; blue |
||
219 | shr eax, 5 |
||
220 | and ebx, (128+64+32)*256; green |
||
221 | shr ebx, 8+2 |
||
222 | add eax, ebx |
||
223 | pop ebx |
||
224 | and ebx, (128+64)*256*256; red |
||
225 | shr ebx, 8+8 |
||
226 | add eax, ebx |
||
2439 | Serge | 227 | ;-------------------------------------- |
228 | align 4 |
||
229 | .save_pixel: |
||
117 | mario79 | 230 | stosb |
2434 | Serge | 231 | loop m13pix |
232 | mov ecx, 320 |
||
233 | add esi, 4*(640-320) |
||
234 | dec edx |
||
235 | jnz m13pix |
||
236 | mov [EGA_counter], 0 |
||
117 | mario79 | 237 | popad |
238 | ret |
||
2439 | Serge | 239 | ;------------------------------------------------------------------------------ |
240 | align 4 |
||
119 | mario79 | 241 | VGA_drawbackground: |
379 | serge | 242 | ; draw all |
117 | mario79 | 243 | pushad |
2434 | Serge | 244 | mov esi, [LFBAddress] |
245 | mov edi, VGABasePtr |
||
246 | mov ebx, 640/32; 640*480/(8*4) |
||
247 | mov edx, 480 |
||
2439 | Serge | 248 | ;-------------------------------------- |
249 | align 4 |
||
250 | @@: |
||
2434 | Serge | 251 | push ebx edx esi edi |
252 | shl edx, 9 |
||
253 | lea edx, [edx+edx*4] |
||
254 | add esi, edx |
||
255 | shr edx, 5 |
||
256 | add edi, edx |
||
257 | call VGA_draw_long_line |
||
258 | pop edi esi edx ebx |
||
259 | dec edx |
||
260 | jnz @r |
||
261 | call VGA_draw_long_line_1 |
||
117 | mario79 | 262 | popad |
263 | ret |
||
2439 | Serge | 264 | ;------------------------------------------------------------------------------ |
265 | align 4 |
||
117 | mario79 | 266 | VGA_draw_long_line: |
2434 | Serge | 267 | mov dx, 3ceh |
268 | mov ax, 0ff08h |
||
117 | mario79 | 269 | cli |
2434 | Serge | 270 | out dx, ax |
271 | mov ax, 0005h |
||
272 | out dx, ax |
||
2439 | Serge | 273 | ;-------------------------------------- |
274 | align 4 |
||
275 | m12pix: |
||
2434 | Serge | 276 | call VGA_draw_32_pixels |
277 | dec ebx |
||
278 | jnz m12pix |
||
279 | mov dx, 3c4h |
||
280 | mov ax, 0ff02h |
||
281 | out dx, ax |
||
282 | mov dx, 3ceh |
||
283 | mov ax, 0205h |
||
284 | out dx, ax |
||
285 | mov dx, 3ceh |
||
286 | mov al, 08h |
||
287 | out dx, al |
||
117 | mario79 | 288 | sti |
289 | ret |
||
2439 | Serge | 290 | ;------------------------------------------------------------------------------ |
291 | align 4 |
||
117 | mario79 | 292 | VGA_draw_32_pixels: |
2434 | Serge | 293 | xor eax, eax |
294 | mov ebp, VGA_8_pixels |
||
295 | mov [ebp], eax |
||
296 | mov [ebp+4], eax |
||
297 | mov [ebp+8], eax |
||
298 | mov [ebp+12], eax |
||
299 | mov ch, 4 |
||
2439 | Serge | 300 | ;-------------------------------------- |
301 | align 4 |
||
302 | .main_loop: |
||
2434 | Serge | 303 | mov cl, 8 |
2439 | Serge | 304 | ;-------------------------------------- |
305 | align 4 |
||
306 | .convert_pixels_to_VGA: |
||
117 | mario79 | 307 | lodsd ; eax = 24bit colour |
2434 | Serge | 308 | test eax, eax |
309 | jz .end |
||
310 | rol eax, 8 |
||
311 | mov al, ch |
||
312 | ror eax, 8 |
||
313 | mov ch, 1 |
||
314 | dec cl |
||
315 | shl ch, cl |
||
316 | cmp al, 85 |
||
119 | mario79 | 317 | jbe .p13green |
2434 | Serge | 318 | or [ebp], ch |
319 | cmp al, 170 |
||
119 | mario79 | 320 | jbe .p13green |
2434 | Serge | 321 | or [ebp+12], ch |
2439 | Serge | 322 | ;-------------------------------------- |
323 | align 4 |
||
324 | .p13green: |
||
2434 | Serge | 325 | cmp ah, 85 |
119 | mario79 | 326 | jbe .p13red |
2434 | Serge | 327 | or [ebp+4], ch |
328 | cmp ah, 170 |
||
119 | mario79 | 329 | jbe .p13red |
2434 | Serge | 330 | or [ebp+12], ch |
2439 | Serge | 331 | ;-------------------------------------- |
332 | align 4 |
||
333 | .p13red: |
||
2434 | Serge | 334 | shr eax, 8 |
335 | cmp ah, 85 |
||
119 | mario79 | 336 | jbe .p13cont |
2434 | Serge | 337 | or [ebp+8], ch |
338 | cmp ah, 170 |
||
119 | mario79 | 339 | jbe .p13cont |
2434 | Serge | 340 | or [ebp+12], ch |
2439 | Serge | 341 | ;-------------------------------------- |
342 | align 4 |
||
343 | .p13cont: |
||
2434 | Serge | 344 | ror eax, 8 |
345 | mov ch, ah |
||
346 | inc cl |
||
2439 | Serge | 347 | ;-------------------------------------- |
348 | align 4 |
||
349 | .end: |
||
2434 | Serge | 350 | dec cl |
351 | jnz .convert_pixels_to_VGA |
||
352 | inc ebp |
||
353 | dec ch |
||
354 | jnz .main_loop |
||
355 | push esi |
||
356 | sub ebp, 4 |
||
357 | mov esi, ebp |
||
358 | mov dx, 3c4h |
||
359 | mov ah, 1h |
||
2439 | Serge | 360 | ;-------------------------------------- |
361 | align 4 |
||
362 | @@: |
||
2434 | Serge | 363 | mov al, 02h |
364 | out dx, ax |
||
365 | xchg ax, bp |
||
117 | mario79 | 366 | lodsd |
2434 | Serge | 367 | mov [edi], eax |
368 | xchg ax, bp |
||
369 | shl ah, 1 |
||
370 | cmp ah, 10h |
||
371 | jnz @r |
||
372 | add edi, 4 |
||
373 | pop esi |
||
117 | mario79 | 374 | ret |
2439 | Serge | 375 | ;------------------------------------------------------------------------------ |
376 | align 4 |
||
1 | ha | 377 | VGA_putpixel: |
378 | ; eax = x |
||
379 | ; ebx = y |
||
2434 | Serge | 380 | mov ecx, eax |
117 | mario79 | 381 | mov eax, [esp+32-8+4] ; color |
2439 | Serge | 382 | ;-------------------------------------- |
2465 | Serge | 383 | ; check for hardware cursor |
384 | cmp [_display.select_cursor], select_cursor |
||
385 | je @f |
||
386 | cmp [_display.select_cursor], 0 |
||
387 | jne .no_mouseunder |
||
388 | ;-------------------------------------- |
||
389 | align 4 |
||
390 | @@: |
||
2439 | Serge | 391 | push ecx |
392 | shl ecx, 16 |
||
393 | mov cx, bx |
||
394 | ; check mouse area for putpixel |
||
395 | test eax, 0x04000000 |
||
396 | jnz @f |
||
397 | call [_display.check_mouse] |
||
398 | ;-------------------------------------- |
||
399 | align 4 |
||
400 | @@: |
||
401 | pop ecx |
||
2465 | Serge | 402 | ;-------------------------------------- |
403 | align 4 |
||
404 | .no_mouseunder: |
||
2434 | Serge | 405 | shl ebx, 9 |
3555 | Serge | 406 | lea ebx, [ebx+ebx*4] ; умножение на 5 |
117 | mario79 | 407 | lea edx, [ebx+ecx*4] ; + x*BytesPerPixel (Vesa2.0 32) |
2434 | Serge | 408 | mov edi, edx |
381 | serge | 409 | add edi, [LFBAddress] ; + LFB address |
117 | mario79 | 410 | mov [edi], eax ; write to LFB for Vesa2.0 |
2434 | Serge | 411 | shr edx, 5 ; change BytesPerPixel to 1/8 |
412 | mov edi, edx |
||
381 | serge | 413 | add edi, VGABasePtr ; address of pixel in VGA area |
2434 | Serge | 414 | and ecx, 0x07 ; bit no. (modulo 8) |
117 | mario79 | 415 | pushfd |
416 | ; edi = address, eax = 24bit colour, ecx = bit no. (modulo 8) |
||
2434 | Serge | 417 | xor edx, edx |
418 | test eax, eax |
||
419 | jz .p13cont |
||
420 | cmp al, 85 |
||
421 | jbe .p13green |
||
422 | or dl, 0x01 |
||
423 | cmp al, 170 |
||
424 | jbe .p13green |
||
425 | or dl, 0x08 |
||
2439 | Serge | 426 | ;-------------------------------------- |
427 | align 4 |
||
117 | mario79 | 428 | .p13green: |
2434 | Serge | 429 | cmp ah, 85 |
430 | jbe .p13red |
||
431 | or dl, 0x02 |
||
432 | cmp ah, 170 |
||
433 | jbe .p13red |
||
434 | or dl, 0x08 |
||
2439 | Serge | 435 | ;-------------------------------------- |
436 | align 4 |
||
379 | serge | 437 | .p13red: |
2434 | Serge | 438 | shr eax, 8 |
439 | cmp ah, 85 |
||
440 | jbe .p13cont |
||
441 | or dl, 0x04 |
||
442 | cmp ah, 170 |
||
443 | jbe .p13cont |
||
444 | or dl, 0x08 |
||
2439 | Serge | 445 | ;-------------------------------------- |
446 | align 4 |
||
117 | mario79 | 447 | .p13cont: |
2434 | Serge | 448 | ror edx, 8 |
449 | inc cl |
||
450 | xor eax, eax |
||
451 | inc ah |
||
452 | shr ax, cl |
||
453 | mov dx, 3cfh |
||
117 | mario79 | 454 | cli |
2434 | Serge | 455 | out dx, al |
456 | mov al, [edi] ; dummy read |
||
457 | rol edx, 8 |
||
458 | mov [edi], dl |
||
117 | mario79 | 459 | popfd |
460 | ret |
||
2439 | Serge | 461 | ;------------------------------------------------------------------------------ |
462 | align 4 |
||
117 | mario79 | 463 | VGA__putimage: |
464 | ; ecx = size [x|y] |
||
465 | ; edx = coordinates [x|y] |
||
2434 | Serge | 466 | pushad |
467 | rol edx, 16 |
||
468 | movzx eax, dx |
||
469 | rol edx, 16 |
||
470 | movzx ebx, dx |
||
471 | movzx edx, cx |
||
472 | rol ecx, 16 |
||
473 | movzx ecx, cx |
||
474 | call VGA_draw_bar_1 |
||
475 | popad |
||
476 | ret |
||
2439 | Serge | 477 | ;------------------------------------------------------------------------------ |
478 | align 4 |
||
117 | mario79 | 479 | VGA_draw_bar: |
480 | ; eax cx |
||
481 | ; ebx cy |
||
482 | ; ecx xe |
||
483 | ; edx ye |
||
2434 | Serge | 484 | pushad |
485 | sub ecx, eax |
||
486 | sub edx, ebx |
||
487 | and eax, 0xffff |
||
488 | and ebx, 0xffff |
||
489 | and ecx, 0xffff |
||
490 | and edx, 0xffff |
||
491 | call VGA_draw_bar_1 |
||
492 | popad |
||
493 | ret |
||
2439 | Serge | 494 | ;------------------------------------------------------------------------------ |
495 | align 4 |
||
117 | mario79 | 496 | VGA_draw_bar_1: |
2434 | Serge | 497 | mov [temp.cx], eax |
379 | serge | 498 | mov eax, [TASK_BASE] |
117 | mario79 | 499 | add ebx, [eax-twdw + 4] |
500 | mov eax, [eax-twdw + 0] |
||
501 | add eax, [temp.cx] |
||
2434 | Serge | 502 | and eax, 0xfff8 |
503 | shl ebx, 9 |
||
3555 | Serge | 504 | lea ebx, [ebx+ebx*4]; умножение на 5 |
117 | mario79 | 505 | lea ebx, [ebx+eax*4] ; + x*BytesPerPixel (Vesa2.0 32) |
2434 | Serge | 506 | mov esi, ebx |
381 | serge | 507 | add esi, [LFBAddress] ; + LFB address |
2434 | Serge | 508 | shr ebx, 5 ; change BytesPerPixel to 1/8 |
509 | mov edi, ebx |
||
381 | serge | 510 | add edi, VGABasePtr ; address of pixel in VGA area |
2434 | Serge | 511 | mov ebx, ecx |
512 | shr ebx, 5 |
||
117 | mario79 | 513 | inc ebx |
2439 | Serge | 514 | ;-------------------------------------- |
515 | align 4 |
||
117 | mario79 | 516 | .main_loop: |
2434 | Serge | 517 | call VGA_draw_long_line_1 |
518 | dec edx |
||
519 | jnz .main_loop |
||
520 | call VGA_draw_long_line_1 |
||
117 | mario79 | 521 | ret |
2439 | Serge | 522 | ;------------------------------------------------------------------------------ |
523 | align 4 |
||
117 | mario79 | 524 | VGA_draw_long_line_1: |
2434 | Serge | 525 | push ebx edx esi edi |
526 | shl edx, 9 |
||
527 | lea edx, [edx+edx*4] |
||
528 | add esi, edx |
||
529 | shr edx, 5 |
||
530 | add edi, edx |
||
531 | call VGA_draw_long_line |
||
532 | pop edi esi edx ebx |
||
117 | mario79 | 533 | ret |
2439 | Serge | 534 | ;------------------------------------------------------------------------------ |