3 ;Copyright (c) 1998-2001 Klaus P. Gerlicher
11 ; assembler function for directly programming standard VGA
21 ; Reactos Port by Eugene Ingerman
25 ; 30-Oct-2001: created
29 ; This file may be distributed under the terms of the GNU Public License.
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
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
47 %assign VGA_IO_BASE 03c0h
48 %assign VGA_IO_SIZE 020h
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
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
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
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
97 ;****************************************************************************
98 ;* pice_save_current_charset ************************************************
99 ;****************************************************************************
101 pice_address dd 0xc00a0000
102 pice_save_current_charset:
104 call pice_select_read_plane
105 mov dword ecx, 04000h
106 mov dword esi, [pice_address]
107 mov dword edi, pice_charset_saved
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)
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)
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)
135 ;****************************************************************************
136 ;* pice_restore_current_charset ****************************************************
137 ;****************************************************************************
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]
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]
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]
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]
170 ;****************************************************************************
171 ;* pice_get_crt_registers **************************************************
172 ;****************************************************************************
173 ;* ebx=> pointer where to store crt registers
174 ;****************************************************************************
176 pice_get_crt_registers:
178 .loop: mov dword edx, VGA_CRT_INDEX
181 mov dword edx, VGA_CRT_DATA
183 mov byte [ebx + ecx], al
185 cmp dword ecx, VGA_CRT_REGISTERS
191 ;****************************************************************************
192 ;* pice_get_attribute_registers ********************************************
193 ;****************************************************************************
194 ;* ebx=> pointer where to store attribute registers
195 ;****************************************************************************
197 pice_get_attribute_registers:
199 .loop: mov dword edx, VGA_INPUT_STATUS
201 mov dword edx, VGA_ATTRIBUTE_INDEX
204 mov dword edx, VGA_ATTRIBUTE_DATA_READ
206 mov byte [ebx + ecx], al
208 cmp dword ecx, VGA_ATTRIBUTE_REGISTERS
214 ;****************************************************************************
215 ;* pice_get_graphic_registers **********************************************
216 ;****************************************************************************
217 ;* ebx=> pointer where to store graphics registers
218 ;****************************************************************************
220 pice_get_graphic_registers:
222 .loop: mov dword edx, VGA_GRAPHIC_INDEX
225 mov dword edx, VGA_GRAPHIC_DATA
227 mov byte [ebx + ecx], al
229 cmp dword ecx, VGA_GRAPHIC_REGISTERS
235 ;****************************************************************************
236 ;* pice_get_sequencer_registers ********************************************
237 ;****************************************************************************
238 ;* ebx=> pointer where to store sequencer registers
239 ;****************************************************************************
241 pice_get_sequencer_registers:
243 .loop: mov dword edx, VGA_SEQUENCER_INDEX
246 mov dword edx, VGA_SEQUENCER_DATA
248 mov byte [ebx + ecx], al
250 cmp dword ecx, VGA_SEQUENCER_REGISTERS
256 ;****************************************************************************
257 ;* pice_get_misc_registers *************************************************
258 ;****************************************************************************
259 ;* ebx=> pointer where to store misc register
260 ;****************************************************************************
262 pice_get_misc_registers:
263 mov dword edx, VGA_MISC_DATA_READ
270 ;****************************************************************************
271 ;* pice_get_colormap *******************************************************
272 ;****************************************************************************
273 ;* ebx=> pointer where to store colormap
274 ;****************************************************************************
279 mov dword edx, VGA_PEL_INDEX_READ
281 mov dword edx, VGA_PEL_DATA
282 .loop: in byte al, dx
287 mov dword [ebx + 4 * ecx], eax
295 ;****************************************************************************
296 ;* pice_set_crt_registers **************************************************
297 ;****************************************************************************
298 ;* ebx=> pointer to stored crt registers
299 ;****************************************************************************
301 pice_set_crt_registers:
303 ;deprotect CRT registers 0 - 7
305 mov dword edx, VGA_CRT_INDEX
308 mov dword edx, VGA_CRT_DATA
313 ;write to the registers
316 .loop: mov dword edx, VGA_CRT_INDEX
319 mov dword edx, VGA_CRT_DATA
320 mov byte al, [ebx + ecx]
323 cmp dword ecx, VGA_CRT_REGISTERS
329 ;****************************************************************************
330 ;* pice_set_attribute_registers ********************************************
331 ;****************************************************************************
332 ;* ebx=> pointer to stored attibute registers
333 ;****************************************************************************
335 pice_set_attribute_registers:
337 .loop: mov dword edx, VGA_INPUT_STATUS
339 mov dword edx, VGA_ATTRIBUTE_INDEX
342 mov dword edx, VGA_ATTRIBUTE_DATA_WRITE
343 mov byte al, [ebx + ecx]
346 cmp dword ecx, VGA_ATTRIBUTE_REGISTERS
352 ;****************************************************************************
353 ;* pice_set_graphic_registers **********************************************
354 ;****************************************************************************
355 ;* ebx=> pointer to stored graphic registers
356 ;****************************************************************************
358 pice_set_graphic_registers:
360 .loop: mov dword edx, VGA_GRAPHIC_INDEX
363 mov dword edx, VGA_GRAPHIC_DATA
364 mov byte al, [ebx + ecx]
367 cmp dword ecx, VGA_GRAPHIC_REGISTERS
373 ;****************************************************************************
374 ;* pice_set_sequencer_registers ********************************************
375 ;****************************************************************************
376 ;* ebx=> pointer to stored sequencer registers
377 ;****************************************************************************
379 pice_set_sequencer_registers:
381 ;synchronous reset on
383 mov dword edx, VGA_SEQUENCER_INDEX
386 mov dword edx, VGA_SEQUENCER_DATA
390 ;write to the registers
392 mov dword edx, VGA_SEQUENCER_INDEX
394 mov dword edx, VGA_SEQUENCER_DATA
395 mov byte al, [ebx + 1]
399 .loop: mov dword edx, VGA_SEQUENCER_INDEX
402 mov dword edx, VGA_SEQUENCER_DATA
403 mov byte al, [ebx + ecx]
406 cmp dword ecx, VGA_SEQUENCER_REGISTERS
409 ;synchronous reset off
411 mov dword edx, VGA_SEQUENCER_INDEX
414 mov dword edx, VGA_SEQUENCER_DATA
421 ;****************************************************************************
422 ;* pice_set_misc_registers *************************************************
423 ;****************************************************************************
424 ;* ebx=> pointer to stored misc register
425 ;****************************************************************************
427 pice_set_misc_registers:
428 mov dword edx, VGA_MISC_DATA_WRITE
435 ;****************************************************************************
436 ;* pice_set_colormap *******************************************************
437 ;****************************************************************************
438 ;* ebx=> pointer to stored colormap
439 ;****************************************************************************
444 mov dword edx, VGA_PEL_INDEX_WRITE
446 mov dword edx, VGA_PEL_DATA
447 .loop: mov dword eax, [ebx + 4 * ecx]
461 ;****************************************************************************
462 ;* pice_screen_on **********************************************************
463 ;****************************************************************************
469 mov dword edx, VGA_SEQUENCER_INDEX
472 mov dword edx, VGA_SEQUENCER_DATA
479 mov dword edx, VGA_INPUT_STATUS
481 mov dword edx, VGA_ATTRIBUTE_DATA_WRITE
486 ;****************************************************************************
487 ;* pice_select_write_plane *************************************************
488 ;****************************************************************************
491 ;****************************************************************************
493 pice_select_write_plane:
494 and dword ebx, 00f03h
496 ;enable set/reset = 0
498 mov dword edx, VGA_GRAPHIC_INDEX
501 mov dword edx, VGA_GRAPHIC_DATA
505 ;logical operation = none, rotate = 0
507 mov dword edx, VGA_GRAPHIC_INDEX
510 mov dword edx, VGA_GRAPHIC_DATA
516 mov dword edx, VGA_GRAPHIC_INDEX
519 mov dword edx, VGA_GRAPHIC_DATA
527 mov dword edx, VGA_GRAPHIC_INDEX
530 mov dword edx, VGA_GRAPHIC_DATA
536 mov dword edx, VGA_SEQUENCER_INDEX
539 mov dword edx, VGA_SEQUENCER_DATA
546 ;****************************************************************************
547 ;* pice_select_read_plane **************************************************
548 ;****************************************************************************
551 ;****************************************************************************
553 pice_select_read_plane:
554 and dword ebx, 00301h
559 mov dword edx, VGA_GRAPHIC_INDEX
562 mov dword edx, VGA_GRAPHIC_DATA
570 mov dword edx, VGA_GRAPHIC_INDEX
573 mov dword edx, VGA_GRAPHIC_DATA
580 ;****************************************************************************
581 ;* pice_save_current_registers **********************************************
582 ;****************************************************************************
584 _pice_save_current_registers:
589 ; call pice_save_current_charset
591 .crt: mov dword ebx, pice_current_registers.crt
592 call pice_get_crt_registers
594 .attribute: mov dword ebx, pice_current_registers.attribute
595 call pice_get_attribute_registers
597 .graphic: mov dword ebx, pice_current_registers.graphic
598 call pice_get_graphic_registers
600 .sequencer: mov dword ebx, pice_current_registers.sequencer
601 call pice_get_sequencer_registers
603 .misc: mov dword ebx, pice_current_registers.misc
604 call pice_get_misc_registers
606 .colormap: mov dword ebx, pice_current_registers.colormap
607 call pice_get_colormap
614 ;****************************************************************************
615 ;* pice_restore_current_registers *******************************************
616 ;****************************************************************************
618 _pice_restore_current_registers:
623 ; call pice_restore_current_charset
625 .misc: mov dword ebx, pice_current_registers.misc
626 call pice_set_misc_registers
628 .crt: mov dword ebx, pice_current_registers.crt
629 call pice_set_crt_registers
631 .attribute: mov dword ebx, pice_current_registers.attribute
632 call pice_set_attribute_registers
634 .graphic: mov dword ebx, pice_current_registers.graphic
635 call pice_set_graphic_registers
637 .sequencer: mov dword ebx, pice_current_registers.sequencer
638 call pice_set_sequencer_registers
640 .screen_on: call pice_screen_on
642 .colormap: mov dword ebx, pice_current_registers.colormap
643 call pice_set_colormap
652 ;****************************************************************************
653 ;* pice_set_mode_3_80x50*****************************************************
654 ;****************************************************************************
656 _pice_set_mode_3_80x50:
661 .crt: mov dword ebx, pice_mode3_80x50_registers.crt
662 call pice_set_crt_registers
664 .attribute: mov dword ebx, pice_mode3_80x50_registers.attribute
665 call pice_set_attribute_registers
667 .graphic: mov dword ebx, pice_mode3_80x50_registers.graphic
668 call pice_set_graphic_registers
670 .sequencer: mov dword ebx, pice_mode3_80x50_registers.sequencer
671 call pice_set_sequencer_registers
673 .misc: mov dword ebx, pice_mode3_80x50_registers.misc
674 call pice_set_misc_registers
676 .screen_on: call pice_screen_on
678 ;.colormap: mov dword ebx, pice_current_registers.colormap
679 ; call pice_set_colormap
687 ;****************************************************************************
688 ;* pice_set_mode_3_80x25*****************************************************
689 ;****************************************************************************
691 _pice_set_mode_3_80x25:
696 .crt: mov dword ebx, pice_mode3_80x25_registers.crt
697 call pice_set_crt_registers
699 .attribute: mov dword ebx, pice_mode3_80x25_registers.attribute
700 call pice_set_attribute_registers
702 .graphic: mov dword ebx, pice_mode3_80x25_registers.graphic
703 call pice_set_graphic_registers
705 .sequencer: mov dword ebx, pice_mode3_80x25_registers.sequencer
706 call pice_set_sequencer_registers
708 .misc: mov dword ebx, pice_mode3_80x25_registers.misc
709 call pice_set_misc_registers
711 .screen_on: call pice_screen_on
713 ;.colormap: mov dword ebx, pice_current_registers.colormap
714 ; call pice_set_colormap
722 ;****************************************************************************
723 ;* uninitialized data *******************************************************
724 ;****************************************************************************
727 pice_charset_saved: resb 040000h