-revert janderwalds change until because it breaks the gcc 4.x build
[reactos.git] / reactos / base / applications / utils / pice / module / vga_utils.asm
1 ;/*++
2 ;
3 ;Copyright (c) 1998-2001 Klaus P. Gerlicher
4 ;
5 ;Module Name:
6 ;
7 ; vga_utils.asm
8 ;
9 ;Abstract:
10 ;
11 ; assembler function for directly programming standard VGA
12 ;
13 ;Environment:
14 ;
15 ; LINUX 2.2.X
16 ; Kernel mode only
17 ;
18 ;Author:
19 ;
20 ; Klaus P. Gerlicher
21 ; Reactos Port by Eugene Ingerman
22 ;
23 ;Revision History:
24 ;
25 ; 30-Oct-2001: created
26 ;
27 ;Copyright notice:
28 ;
29 ; This file may be distributed under the terms of the GNU Public License.
30 ;
31 ;--*/
32
33 global _pice_save_current_registers
34 global _pice_restore_current_registers
35 global _pice_set_mode_3_80x50
36 global _pice_set_mode_3_80x25
37
38 ;****************************************************************************
39 ;* some assign's ************************************************************
40 ;****************************************************************************
41 %assign VGA_CRT_REGISTERS 24
42 %assign VGA_ATTRIBUTE_REGISTERS 21
43 %assign VGA_GRAPHIC_REGISTERS 9
44 %assign VGA_SEQUENCER_REGISTERS 5
45 %assign VGA_MISC_REGISTERS 1
46
47 %assign VGA_IO_BASE 03c0h
48 %assign VGA_IO_SIZE 020h
49
50 %assign VGA_ATTRIBUTE_INDEX 03c0h
51 %assign VGA_ATTRIBUTE_DATA_WRITE 03c0h
52 %assign VGA_ATTRIBUTE_DATA_READ 03c1h
53 %assign VGA_MISC_DATA_WRITE 03c2h
54 %assign VGA_SEQUENCER_INDEX 03c4h
55 %assign VGA_SEQUENCER_DATA 03c5h
56 %assign VGA_PEL_MASK 03c6h
57 %assign VGA_PEL_INDEX_READ 03c7h
58 %assign VGA_PEL_INDEX_WRITE 03c8h
59 %assign VGA_PEL_DATA 03c9h
60 %assign VGA_MISC_DATA_READ 03cch
61 %assign VGA_GRAPHIC_INDEX 03ceh
62 %assign VGA_GRAPHIC_DATA 03cfh
63 %assign VGA_CRT_INDEX 03d4h
64 %assign VGA_CRT_DATA 03d5h
65 %assign VGA_INPUT_STATUS 03dah
66
67 section .data
68 pice_mode3_80x50_registers:
69 ; offsets 0x00,0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08,0x09,0x0a,0x0b,0x0c,0x0d,0x0e,0x0f,0x10,0x11,0x12,0x13,0x14,0x15,0x16,0x17,0x18
70 .crt: db 0x5f,0x4f,0x50,0x82,0x55,0x80,0xbf,0x1f,0x00,0x67,0x06,0x07,0x00,0x00,0x00,0x00,0x9c,0x8f,0x8f,0x28,0x1f,0x96,0xb9,0xa3,0xff
71 .attribute db 0x00,0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x10,0x11,0x12,0x13,0x14,0x15,0x16,0x17,0x08,0x00,0x0f,0x00,0x00
72 .graphic: db 0x00,0x00,0x00,0x00,0x00,0x10,0x0e,0x00,0xff
73 .sequencer: db 0x03,0x00,0x03,0x00,0x02 ; 9 bits per char
74 ;.sequencer: db 0x03,0x01,0x03,0x00,0x02 ; 8 bits per char
75 .misc: db 0x67
76
77 pice_mode3_80x25_registers:
78 ; offsets 0x00,0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08,0x09,0x0a,0x0b,0x0c,0x0d,0x0e,0x0f,0x10,0x11,0x12,0x13,0x14,0x15,0x16,0x17,0x18
79 .crt: db 0x5f,0x4f,0x50,0x82,0x55,0x81,0xbf,0x1f,0x00,0x4f,0x0d,0x0e,0x00,0x00,0x30,0xe8,0x9c,0x0e,0x8f,0x28,0x1f,0x96,0xb9,0xa3
80 .attribute db 0x00,0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08,0x09,0x0a,0x0b,0x0c,0x0d,0x0e,0x0f,0x0c,0x00,0x0f,0x08,0x00
81 .graphic: db 0x00,0x00,0x00,0x00,0x00,0x10,0x0e,0x00,0xff
82 .sequencer: db 0x03,0x00,0x03,0x00,0x02
83 .misc: db 0x67
84
85
86
87 section .bss
88 pice_current_registers:
89 .crt: resb VGA_CRT_REGISTERS
90 .attribute: resb VGA_ATTRIBUTE_REGISTERS
91 .graphic: resb VGA_GRAPHIC_REGISTERS
92 .sequencer: resb VGA_SEQUENCER_REGISTERS
93 .misc: resb VGA_MISC_REGISTERS
94 align 4
95 .colormap: resd 256
96
97 ;****************************************************************************
98 ;* pice_save_current_charset ************************************************
99 ;****************************************************************************
100 section .text
101 pice_address dd 0xc00a0000
102 pice_save_current_charset:
103 xor dword ebx, ebx
104 call pice_select_read_plane
105 mov dword ecx, 04000h
106 mov dword esi, [pice_address]
107 mov dword edi, pice_charset_saved
108 cld
109 rep movsd
110 mov dword ebx, 00100h
111 call pice_select_read_plane
112 mov dword ecx, 04000h
113 mov dword esi, [pice_address]
114 mov dword edi, (pice_charset_saved + 010000h)
115 cld
116 rep movsd
117 mov dword ebx, 00200h
118 call pice_select_read_plane
119 mov dword ecx, 04000h
120 mov dword esi, [pice_address]
121 mov dword edi, (pice_charset_saved + 020000h)
122 cld
123 rep movsd
124 mov dword ebx, 00300h
125 call pice_select_read_plane
126 mov dword ecx, 04000h
127 mov dword esi, [pice_address]
128 mov dword edi, (pice_charset_saved + 030000h)
129 cld
130 rep movsd
131 .end: ret
132
133
134
135 ;****************************************************************************
136 ;* pice_restore_current_charset ****************************************************
137 ;****************************************************************************
138 section .text
139 pice_restore_current_charset:
140 mov dword ebx, 00100h
141 call pice_select_write_plane
142 mov dword ecx, 04000h
143 mov dword esi, pice_charset_saved
144 mov dword edi, [pice_address]
145 cld
146 rep movsd
147 mov dword ebx, 00200h
148 call pice_select_write_plane
149 mov dword ecx, 04000h
150 mov dword esi, (pice_charset_saved + 010000h)
151 mov dword edi, [pice_address]
152 cld
153 rep movsd
154 mov dword ebx, 00400h
155 call pice_select_write_plane
156 mov dword ecx, 04000h
157 mov dword esi, (pice_charset_saved + 020000h)
158 mov dword edi, [pice_address]
159 cld
160 rep movsd
161 mov dword ebx, 00800h
162 call pice_select_write_plane
163 mov dword ecx, 04000h
164 mov dword esi, (pice_charset_saved + 030000h)
165 mov dword edi, [pice_address]
166 cld
167 rep movsd
168 .end: ret
169
170 ;****************************************************************************
171 ;* pice_get_crt_registers **************************************************
172 ;****************************************************************************
173 ;* ebx=> pointer where to store crt registers
174 ;****************************************************************************
175 section .text
176 pice_get_crt_registers:
177 xor dword ecx, ecx
178 .loop: mov dword edx, VGA_CRT_INDEX
179 mov byte al, cl
180 out word dx, al
181 mov dword edx, VGA_CRT_DATA
182 in byte al, dx
183 mov byte [ebx + ecx], al
184 inc dword ecx
185 cmp dword ecx, VGA_CRT_REGISTERS
186 jb .loop
187 ret
188
189
190
191 ;****************************************************************************
192 ;* pice_get_attribute_registers ********************************************
193 ;****************************************************************************
194 ;* ebx=> pointer where to store attribute registers
195 ;****************************************************************************
196 section .text
197 pice_get_attribute_registers:
198 xor dword ecx, ecx
199 .loop: mov dword edx, VGA_INPUT_STATUS
200 in byte al, dx
201 mov dword edx, VGA_ATTRIBUTE_INDEX
202 mov byte al, cl
203 out word dx, al
204 mov dword edx, VGA_ATTRIBUTE_DATA_READ
205 in byte al, dx
206 mov byte [ebx + ecx], al
207 inc dword ecx
208 cmp dword ecx, VGA_ATTRIBUTE_REGISTERS
209 jb .loop
210 ret
211
212
213
214 ;****************************************************************************
215 ;* pice_get_graphic_registers **********************************************
216 ;****************************************************************************
217 ;* ebx=> pointer where to store graphics registers
218 ;****************************************************************************
219 section .text
220 pice_get_graphic_registers:
221 xor dword ecx, ecx
222 .loop: mov dword edx, VGA_GRAPHIC_INDEX
223 mov byte al, cl
224 out word dx, al
225 mov dword edx, VGA_GRAPHIC_DATA
226 in byte al, dx
227 mov byte [ebx + ecx], al
228 inc dword ecx
229 cmp dword ecx, VGA_GRAPHIC_REGISTERS
230 jb .loop
231 ret
232
233
234
235 ;****************************************************************************
236 ;* pice_get_sequencer_registers ********************************************
237 ;****************************************************************************
238 ;* ebx=> pointer where to store sequencer registers
239 ;****************************************************************************
240 section .text
241 pice_get_sequencer_registers:
242 xor dword ecx, ecx
243 .loop: mov dword edx, VGA_SEQUENCER_INDEX
244 mov byte al, cl
245 out word dx, al
246 mov dword edx, VGA_SEQUENCER_DATA
247 in byte al, dx
248 mov byte [ebx + ecx], al
249 inc dword ecx
250 cmp dword ecx, VGA_SEQUENCER_REGISTERS
251 jb .loop
252 ret
253
254
255
256 ;****************************************************************************
257 ;* pice_get_misc_registers *************************************************
258 ;****************************************************************************
259 ;* ebx=> pointer where to store misc register
260 ;****************************************************************************
261 section .text
262 pice_get_misc_registers:
263 mov dword edx, VGA_MISC_DATA_READ
264 in byte al, dx
265 mov byte [ebx], al
266 ret
267
268
269
270 ;****************************************************************************
271 ;* pice_get_colormap *******************************************************
272 ;****************************************************************************
273 ;* ebx=> pointer where to store colormap
274 ;****************************************************************************
275 section .text
276 pice_get_colormap:
277 xor dword ecx, ecx
278 xor dword eax, eax
279 mov dword edx, VGA_PEL_INDEX_READ
280 out word dx, al
281 mov dword edx, VGA_PEL_DATA
282 .loop: in byte al, dx
283 shl dword eax, 8
284 in byte al, dx
285 shl dword eax, 8
286 in byte al, dx
287 mov dword [ebx + 4 * ecx], eax
288 inc dword ecx
289 test byte cl, cl
290 jnz .loop
291 ret
292
293
294
295 ;****************************************************************************
296 ;* pice_set_crt_registers **************************************************
297 ;****************************************************************************
298 ;* ebx=> pointer to stored crt registers
299 ;****************************************************************************
300 section .text
301 pice_set_crt_registers:
302
303 ;deprotect CRT registers 0 - 7
304
305 mov dword edx, VGA_CRT_INDEX
306 mov byte al, 011h
307 out word dx, al
308 mov dword edx, VGA_CRT_DATA
309 in byte al, dx
310 and byte al, 07fh
311 out word dx, al
312
313 ;write to the registers
314
315 xor dword ecx, ecx
316 .loop: mov dword edx, VGA_CRT_INDEX
317 mov byte al, cl
318 out word dx, al
319 mov dword edx, VGA_CRT_DATA
320 mov byte al, [ebx + ecx]
321 out word dx, al
322 inc dword ecx
323 cmp dword ecx, VGA_CRT_REGISTERS
324 jb .loop
325 ret
326
327
328
329 ;****************************************************************************
330 ;* pice_set_attribute_registers ********************************************
331 ;****************************************************************************
332 ;* ebx=> pointer to stored attibute registers
333 ;****************************************************************************
334 section .text
335 pice_set_attribute_registers:
336 xor dword ecx, ecx
337 .loop: mov dword edx, VGA_INPUT_STATUS
338 in byte al, dx
339 mov dword edx, VGA_ATTRIBUTE_INDEX
340 mov byte al, cl
341 out word dx, al
342 mov dword edx, VGA_ATTRIBUTE_DATA_WRITE
343 mov byte al, [ebx + ecx]
344 out word dx, al
345 inc dword ecx
346 cmp dword ecx, VGA_ATTRIBUTE_REGISTERS
347 jb .loop
348 ret
349
350
351
352 ;****************************************************************************
353 ;* pice_set_graphic_registers **********************************************
354 ;****************************************************************************
355 ;* ebx=> pointer to stored graphic registers
356 ;****************************************************************************
357 section .text
358 pice_set_graphic_registers:
359 xor dword ecx, ecx
360 .loop: mov dword edx, VGA_GRAPHIC_INDEX
361 mov byte al, cl
362 out word dx, al
363 mov dword edx, VGA_GRAPHIC_DATA
364 mov byte al, [ebx + ecx]
365 out word dx, al
366 inc dword ecx
367 cmp dword ecx, VGA_GRAPHIC_REGISTERS
368 jb .loop
369 ret
370
371
372
373 ;****************************************************************************
374 ;* pice_set_sequencer_registers ********************************************
375 ;****************************************************************************
376 ;* ebx=> pointer to stored sequencer registers
377 ;****************************************************************************
378 section .text
379 pice_set_sequencer_registers:
380
381 ;synchronous reset on
382
383 mov dword edx, VGA_SEQUENCER_INDEX
384 xor dword eax, eax
385 out word dx, al
386 mov dword edx, VGA_SEQUENCER_DATA
387 inc dword eax
388 out word dx, al
389
390 ;write to the registers
391
392 mov dword edx, VGA_SEQUENCER_INDEX
393 out word dx, al
394 mov dword edx, VGA_SEQUENCER_DATA
395 mov byte al, [ebx + 1]
396 or byte al, 020h
397 out word dx, al
398 mov dword ecx, 2
399 .loop: mov dword edx, VGA_SEQUENCER_INDEX
400 mov byte al, cl
401 out word dx, al
402 mov dword edx, VGA_SEQUENCER_DATA
403 mov byte al, [ebx + ecx]
404 out word dx, al
405 inc dword ecx
406 cmp dword ecx, VGA_SEQUENCER_REGISTERS
407 jb .loop
408
409 ;synchronous reset off
410
411 mov dword edx, VGA_SEQUENCER_INDEX
412 xor dword eax, eax
413 out word dx, al
414 mov dword edx, VGA_SEQUENCER_DATA
415 mov byte al, 3
416 out word dx, al
417 ret
418
419
420
421 ;****************************************************************************
422 ;* pice_set_misc_registers *************************************************
423 ;****************************************************************************
424 ;* ebx=> pointer to stored misc register
425 ;****************************************************************************
426 section .text
427 pice_set_misc_registers:
428 mov dword edx, VGA_MISC_DATA_WRITE
429 mov byte al, [ebx]
430 out word dx, al
431 ret
432
433
434
435 ;****************************************************************************
436 ;* pice_set_colormap *******************************************************
437 ;****************************************************************************
438 ;* ebx=> pointer to stored colormap
439 ;****************************************************************************
440 section .text
441 pice_set_colormap:
442 xor dword ecx, ecx
443 xor dword eax, eax
444 mov dword edx, VGA_PEL_INDEX_WRITE
445 out word dx, al
446 mov dword edx, VGA_PEL_DATA
447 .loop: mov dword eax, [ebx + 4 * ecx]
448 rol dword eax, 16
449 out word dx, al
450 rol dword eax, 8
451 out word dx, al
452 rol dword eax, 8
453 out word dx, al
454 inc dword ecx
455 test byte cl, cl
456 jnz .loop
457 ret
458
459
460
461 ;****************************************************************************
462 ;* pice_screen_on **********************************************************
463 ;****************************************************************************
464 section .text
465 pice_screen_on:
466
467 ;turn on the screen
468
469 mov dword edx, VGA_SEQUENCER_INDEX
470 mov byte al, 1
471 out word dx, al
472 mov dword edx, VGA_SEQUENCER_DATA
473 in byte al, dx
474 and byte al, 0dfh
475 out word dx, al
476
477 ;enable video output
478
479 mov dword edx, VGA_INPUT_STATUS
480 in byte al, dx
481 mov dword edx, VGA_ATTRIBUTE_DATA_WRITE
482 mov byte al, 020h
483 out word dx, al
484 ret
485
486 ;****************************************************************************
487 ;* pice_select_write_plane *************************************************
488 ;****************************************************************************
489 ;* bl==> write mode
490 ;* bh==> write plane
491 ;****************************************************************************
492 section .text
493 pice_select_write_plane:
494 and dword ebx, 00f03h
495
496 ;enable set/reset = 0
497
498 mov dword edx, VGA_GRAPHIC_INDEX
499 mov byte al, 1
500 out word dx, al
501 mov dword edx, VGA_GRAPHIC_DATA
502 xor dword eax, eax
503 out word dx, al
504
505 ;logical operation = none, rotate = 0
506
507 mov dword edx, VGA_GRAPHIC_INDEX
508 mov byte al, 3
509 out word dx, al
510 mov dword edx, VGA_GRAPHIC_DATA
511 xor dword eax, eax
512 out word dx, al
513
514 ;select write mode
515
516 mov dword edx, VGA_GRAPHIC_INDEX
517 mov byte al, 5
518 out word dx, al
519 mov dword edx, VGA_GRAPHIC_DATA
520 in byte al, dx
521 and byte al, 0fch
522 or byte al, bl
523 out word dx, al
524
525 ;bitmask = 0ffh
526
527 mov dword edx, VGA_GRAPHIC_INDEX
528 mov byte al, 8
529 out word dx, al
530 mov dword edx, VGA_GRAPHIC_DATA
531 mov byte al, 0ffh
532 out word dx, al
533
534 ;select write plane
535
536 mov dword edx, VGA_SEQUENCER_INDEX
537 mov byte al, 2
538 out word dx, al
539 mov dword edx, VGA_SEQUENCER_DATA
540 mov byte al, bh
541 out word dx, al
542 ret
543
544
545
546 ;****************************************************************************
547 ;* pice_select_read_plane **************************************************
548 ;****************************************************************************
549 ;* bl==> read mode
550 ;* bh==> read plane
551 ;****************************************************************************
552 section .text
553 pice_select_read_plane:
554 and dword ebx, 00301h
555 shl byte bl, 3
556
557 ;select read mode
558
559 mov dword edx, VGA_GRAPHIC_INDEX
560 mov byte al, 5
561 out word dx, al
562 mov dword edx, VGA_GRAPHIC_DATA
563 in byte al, dx
564 and byte al, 0f7h
565 or byte al, bl
566 out word dx, al
567
568 ;select read plane
569
570 mov dword edx, VGA_GRAPHIC_INDEX
571 mov byte al, 4
572 out word dx, al
573 mov dword edx, VGA_GRAPHIC_DATA
574 mov byte al, bh
575 out word dx, al
576 ret
577
578
579
580 ;****************************************************************************
581 ;* pice_save_current_registers **********************************************
582 ;****************************************************************************
583 section .text
584 _pice_save_current_registers:
585 push esi
586 push edi
587 push ebx
588
589 ; call pice_save_current_charset
590
591 .crt: mov dword ebx, pice_current_registers.crt
592 call pice_get_crt_registers
593
594 .attribute: mov dword ebx, pice_current_registers.attribute
595 call pice_get_attribute_registers
596
597 .graphic: mov dword ebx, pice_current_registers.graphic
598 call pice_get_graphic_registers
599
600 .sequencer: mov dword ebx, pice_current_registers.sequencer
601 call pice_get_sequencer_registers
602
603 .misc: mov dword ebx, pice_current_registers.misc
604 call pice_get_misc_registers
605
606 .colormap: mov dword ebx, pice_current_registers.colormap
607 call pice_get_colormap
608
609 pop ebx
610 pop edi
611 pop esi
612 .end: ret
613
614 ;****************************************************************************
615 ;* pice_restore_current_registers *******************************************
616 ;****************************************************************************
617 section .text
618 _pice_restore_current_registers:
619 push esi
620 push edi
621 push ebx
622
623 ; call pice_restore_current_charset
624
625 .misc: mov dword ebx, pice_current_registers.misc
626 call pice_set_misc_registers
627
628 .crt: mov dword ebx, pice_current_registers.crt
629 call pice_set_crt_registers
630
631 .attribute: mov dword ebx, pice_current_registers.attribute
632 call pice_set_attribute_registers
633
634 .graphic: mov dword ebx, pice_current_registers.graphic
635 call pice_set_graphic_registers
636
637 .sequencer: mov dword ebx, pice_current_registers.sequencer
638 call pice_set_sequencer_registers
639
640 .screen_on: call pice_screen_on
641
642 .colormap: mov dword ebx, pice_current_registers.colormap
643 call pice_set_colormap
644
645 pop ebx
646 pop edi
647 pop esi
648
649 .end: ret
650
651
652 ;****************************************************************************
653 ;* pice_set_mode_3_80x50*****************************************************
654 ;****************************************************************************
655 section .text
656 _pice_set_mode_3_80x50:
657 push esi
658 push edi
659 push ebx
660
661 .crt: mov dword ebx, pice_mode3_80x50_registers.crt
662 call pice_set_crt_registers
663
664 .attribute: mov dword ebx, pice_mode3_80x50_registers.attribute
665 call pice_set_attribute_registers
666
667 .graphic: mov dword ebx, pice_mode3_80x50_registers.graphic
668 call pice_set_graphic_registers
669
670 .sequencer: mov dword ebx, pice_mode3_80x50_registers.sequencer
671 call pice_set_sequencer_registers
672
673 .misc: mov dword ebx, pice_mode3_80x50_registers.misc
674 call pice_set_misc_registers
675
676 .screen_on: call pice_screen_on
677
678 ;.colormap: mov dword ebx, pice_current_registers.colormap
679 ; call pice_set_colormap
680
681 pop ebx
682 pop edi
683 pop esi
684
685 .end: ret
686
687 ;****************************************************************************
688 ;* pice_set_mode_3_80x25*****************************************************
689 ;****************************************************************************
690 section .text
691 _pice_set_mode_3_80x25:
692 push esi
693 push edi
694 push ebx
695
696 .crt: mov dword ebx, pice_mode3_80x25_registers.crt
697 call pice_set_crt_registers
698
699 .attribute: mov dword ebx, pice_mode3_80x25_registers.attribute
700 call pice_set_attribute_registers
701
702 .graphic: mov dword ebx, pice_mode3_80x25_registers.graphic
703 call pice_set_graphic_registers
704
705 .sequencer: mov dword ebx, pice_mode3_80x25_registers.sequencer
706 call pice_set_sequencer_registers
707
708 .misc: mov dword ebx, pice_mode3_80x25_registers.misc
709 call pice_set_misc_registers
710
711 .screen_on: call pice_screen_on
712
713 ;.colormap: mov dword ebx, pice_current_registers.colormap
714 ; call pice_set_colormap
715
716 pop ebx
717 pop edi
718 pop esi
719
720 .end: ret
721
722 ;****************************************************************************
723 ;* uninitialized data *******************************************************
724 ;****************************************************************************
725 section .bss
726 alignb 4
727 pice_charset_saved: resb 040000h
728
729