4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License along
15 * with this program; if not, write to the Free Software Foundation, Inc.,
16 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
24 #define VIDEOPORT_PALETTE_READ 0x03C7
25 #define VIDEOPORT_PALETTE_WRITE 0x03C8
26 #define VIDEOPORT_PALETTE_DATA 0x03C9
27 #define VIDEOPORT_VERTICAL_RETRACE 0x03DA
29 #define VIDEOVGA_MEM_ADDRESS 0xA0000
30 #define VIDEOTEXT_MEM_ADDRESS 0xB8000
31 #define VIDEOTEXT_MEM_SIZE 0x8000
33 #define VIDEOCARD_CGA_OR_OTHER 0
34 #define VIDEOCARD_EGA 1
35 #define VIDEOCARD_VGA 2
37 #define VIDEOMODE_NORMAL_TEXT 0
38 #define VIDEOMODE_EXTENDED_TEXT 1
39 #define VIDEOMODE_80X28 0x501C
40 #define VIDEOMODE_80X30 0x501E
41 #define VIDEOMODE_80X34 0x5022
42 #define VIDEOMODE_80X43 0x502B
43 #define VIDEOMODE_80X60 0x503C
44 #define VIDEOMODE_132X25 0x8419
45 #define VIDEOMODE_132X43 0x842B
46 #define VIDEOMODE_132X50 0x8432
47 #define VIDEOMODE_132X60 0x843C
49 #define VERTRES_200_SCANLINES 0x00
50 #define VERTRES_350_SCANLINES 0x01
51 #define VERTRES_400_SCANLINES 0x02
53 DBG_DEFAULT_CHANNEL(UI
);
58 USHORT ModeAttributes
; /* mode attributes (see #00080) */
59 UCHAR WindowAttributesA
; /* window attributes, window A (see #00081) */
60 UCHAR WindowsAttributesB
; /* window attributes, window B (see #00081) */
61 USHORT WindowGranularity
; /* window granularity in KB */
62 USHORT WindowSize
; /* window size in KB */
63 USHORT WindowAStartSegment
; /* start segment of window A (0000h if not supported) */
64 USHORT WindowBStartSegment
; /* start segment of window B (0000h if not supported) */
65 ULONG WindowPositioningFunction
; /* -> FAR window positioning function (equivalent to AX=4F05h) */
66 USHORT BytesPerScanLine
; /* bytes per scan line */
67 /* ---remainder is optional for VESA modes in v1.0/1.1, needed for OEM modes--- */
68 USHORT WidthInPixels
; /* width in pixels (graphics) or characters (text) */
69 USHORT HeightInPixels
; /* height in pixels (graphics) or characters (text) */
70 UCHAR CharacterWidthInPixels
; /* width of character cell in pixels */
71 UCHAR CharacterHeightInPixels
; /* height of character cell in pixels */
72 UCHAR NumberOfMemoryPlanes
; /* number of memory planes */
73 UCHAR BitsPerPixel
; /* number of bits per pixel */
74 UCHAR NumberOfBanks
; /* number of banks */
75 UCHAR MemoryModel
; /* memory model type (see #00082) */
76 UCHAR BankSize
; /* size of bank in KB */
77 UCHAR NumberOfImagePanes
; /* number of image pages (less one) that will fit in video RAM */
78 UCHAR Reserved1
; /* reserved (00h for VBE 1.0-2.0, 01h for VBE 3.0) */
79 /* ---VBE v1.2+ --- */
80 UCHAR RedMaskSize
; /* red mask size */
81 UCHAR RedMaskPosition
; /* red field position */
82 UCHAR GreenMaskSize
; /* green mask size */
83 UCHAR GreenMaskPosition
; /* green field size */
84 UCHAR BlueMaskSize
; /* blue mask size */
85 UCHAR BlueMaskPosition
; /* blue field size */
86 UCHAR ReservedMaskSize
; /* reserved mask size */
87 UCHAR ReservedMaskPosition
; /* reserved mask position */
88 UCHAR DirectColorModeInfo
; /* direct color mode info */
89 /* bit 0:Color ramp is programmable */
90 /* bit 1:Bytes in reserved field may be used by application */
91 /* ---VBE v2.0+ --- */
92 ULONG LinearVideoBufferAddress
; /* physical address of linear video buffer */
93 ULONG OffscreenMemoryPointer
; /* pointer to start of offscreen memory */
94 USHORT OffscreenMemorySize
; /* KB of offscreen memory */
96 USHORT LinearBytesPerScanLine
; /* bytes per scan line in linear modes */
97 UCHAR BankedNumberOfImages
; /* number of images (less one) for banked video modes */
98 UCHAR LinearNumberOfImages
; /* number of images (less one) for linear video modes */
99 UCHAR LinearRedMaskSize
; /* linear modes:Size of direct color red mask (in bits) */
100 UCHAR LinearRedMaskPosition
; /* linear modes:Bit position of red mask LSB (e.g. shift count) */
101 UCHAR LinearGreenMaskSize
; /* linear modes:Size of direct color green mask (in bits) */
102 UCHAR LinearGreenMaskPosition
; /* linear modes:Bit position of green mask LSB (e.g. shift count) */
103 UCHAR LinearBlueMaskSize
; /* linear modes:Size of direct color blue mask (in bits) */
104 UCHAR LinearBlueMaskPosition
; /* linear modes:Bit position of blue mask LSB (e.g. shift count) */
105 UCHAR LinearReservedMaskSize
; /* linear modes:Size of direct color reserved mask (in bits) */
106 UCHAR LinearReservedMaskPosition
; /* linear modes:Bit position of reserved mask LSB */
107 ULONG MaximumPixelClock
; /* maximum pixel clock for graphics video mode, in Hz */
108 UCHAR Reserved2
[190]; /* 190 BYTEs reserved (0) */
109 } SVGA_MODE_INFORMATION
, *PSVGA_MODE_INFORMATION
;
112 static USHORT BiosVideoMode
; /* Current video mode as known by BIOS */
113 static ULONG ScreenWidth
= 80; /* Screen Width in characters */
114 static ULONG ScreenHeight
= 25; /* Screen Height in characters */
115 static ULONG BytesPerScanLine
= 160; /* Number of bytes per scanline (delta) */
116 static VIDEODISPLAYMODE DisplayMode
= VideoTextMode
; /* Current display mode */
117 static BOOLEAN VesaVideoMode
= FALSE
; /* Are we using a VESA mode? */
118 static SVGA_MODE_INFORMATION VesaVideoModeInformation
; /* Only valid when in VESA mode */
119 static ULONG CurrentMemoryBank
= 0; /* Currently selected VESA bank */
122 PcVideoDetectVideoCard(VOID
)
126 /* Int 10h AH=12h BL=10h
127 * VIDEO - ALTERNATE FUNCTION SELECT (PS,EGA,VGA,MCGA) - GET EGA INFO
133 * 00h color mode in effect (I/O port 3Dxh)
134 * 01h mono mode in effect (I/O port 3Bxh)
135 * BL = installed memory (00h = 64K, 01h = 128K, 02h = 192K, 03h = 256K)
136 * CH = feature connector bits
137 * CL = switch settings
138 * AH destroyed (at least by Tseng ET4000 BIOS v8.00n)
140 * Installation check;EGA
144 Int386(0x10, &Regs
, &Regs
);
146 /* If BL is still equal to 0x10 then there is no EGA/VGA present */
147 if (0x10 == Regs
.b
.bl
)
149 return VIDEOCARD_CGA_OR_OTHER
;
153 * VIDEO - GET DISPLAY COMBINATION CODE (PS,VGA/MCGA)
157 * AL = 1Ah if function was supported
158 * BL = active display code
159 * BH = alternate display code
161 * This function is commonly used to check for the presence of a VGA.
163 * Installation check;VGA
165 * Values for display combination code:
167 * 01h monochrome adapter w/ monochrome display
168 * 02h CGA w/ color display
170 * 04h EGA w/ color display
171 * 05h EGA w/ monochrome display
172 * 06h PGA w/ color display
173 * 07h VGA w/ monochrome analog display
174 * 08h VGA w/ color analog display
176 * 0Ah MCGA w/ digital color display
177 * 0Bh MCGA w/ monochrome analog display
178 * 0Ch MCGA w/ color analog display
179 * FFh unknown display type
183 Int386(0x10, &Regs
, &Regs
);
185 if (0x1a == Regs
.b
.al
)
187 return VIDEOCARD_VGA
;
191 return VIDEOCARD_EGA
;
195 static VOID
PcVideoSetBiosMode(UCHAR VideoMode
)
200 * VIDEO - SET VIDEO MODE
203 * AL = desired video mode
205 * AL = video mode flag (Phoenix, AMI BIOS)
207 * 30h modes 0-5 and 7
209 * AL = CRT controller mode byte (Phoenix 386 BIOS v1.10)
212 Regs
.b
.al
= VideoMode
;
213 Int386(0x10, &Regs
, &Regs
);
217 PcVideoSetFont8x8(VOID
)
222 * VIDEO - TEXT-MODE CHARGEN - LOAD ROM 8x8 DBL-DOT PATTERNS (PS,EGA,VGA)
231 Int386(0x10, &Regs
, &Regs
);
235 PcVideoSetFont8x14(VOID
)
240 * VIDEO - TEXT-MODE CHARGEN - LOAD ROM MONOCHROME PATTERNS (PS,EGA,VGA)
249 Int386(0x10, &Regs
, &Regs
);
253 PcVideoSelectAlternatePrintScreen(VOID
)
257 /* Int 10h AH=12h BL=20h
258 * VIDEO - ALTERNATE FUNCTION SELECT (PS,EGA,VGA,MCGA) - ALTERNATE PRTSC
261 * BL = 20h select alternate print screen routine
265 * Installs a PrtSc routine from the video card's BIOS to replace the
266 * default PrtSc handler from the ROM BIOS, which usually does not
267 * understand screen heights other than 25 lines.
269 * Some adapters disable print-screen instead of enhancing it.
273 Int386(0x10, &Regs
, &Regs
);
277 PcVideoDisableCursorEmulation(VOID
)
281 /* Int 10h AH=12h BL=34h
282 * VIDEO - ALTERNATE FUNCTION SELECT (VGA) - CURSOR EMULATION
287 * 00h enable alphanumeric cursor emulation
288 * 01h disable alphanumeric cursor emulation
290 * AL = 12h if function supported
292 * Specify whether the BIOS should automatically remap cursor start/end
293 * according to the current character height in text modes.
298 Int386(0x10, &Regs
, &Regs
);
302 PcVideoDefineCursor(UCHAR StartScanLine
, UCHAR EndScanLine
)
307 * VIDEO - SET TEXT-MODE CURSOR SHAPE
310 * CH = cursor start and options
311 * CL = bottom scan line containing cursor (bits 0-4)
315 * Specify the starting and ending scan lines to be occupied
316 * by the hardware cursor in text modes.
318 * AMI 386 BIOS and AST Premier 386 BIOS will lock up the
319 * system if AL is not equal to the current video mode.
321 * Bitfields for cursor start and options:
326 * (00=normal, 01=invisible, 10=erratic, 11=slow).
327 * (00=normal, other=invisible on EGA/VGA)
328 * 4-0 topmost scan line containing cursor
332 Regs
.b
.ch
= StartScanLine
;
333 Regs
.b
.cl
= EndScanLine
;
334 Int386(0x10, &Regs
, &Regs
);
338 PcVideoSetVerticalResolution(UCHAR VerticalResolutionMode
)
342 /* Int 10h AH=12h BL=30h
343 * VIDEO - ALTERNATE FUNCTION SELECT (VGA) - SELECT VERTICAL RESOLUTION
347 * AL = vertical resolution
352 * AL = 12h if function supported
354 * Specifiy the number of scan lines used to display text modes.
356 * The specified resolution will take effect on the next mode set.
360 Regs
.b
.al
= VerticalResolutionMode
;
361 Int386(0x10, &Regs
, &Regs
);
365 PcVideoSet480ScanLines(VOID
)
370 CRTC
= READ_PORT_UCHAR((PUCHAR
)0x03CC);
381 /* Vertical sync end (also unlocks CR0-7) */
382 WRITE_PORT_UCHAR((PUCHAR
)CRTC
, 0x11);
383 WRITE_PORT_UCHAR((PUCHAR
)CRTC
+1, 0x0C);
386 WRITE_PORT_UCHAR((PUCHAR
)CRTC
, 0x06);
387 WRITE_PORT_UCHAR((PUCHAR
)CRTC
+1, 0x0B);
389 /* (vertical) overflow */
390 WRITE_PORT_UCHAR((PUCHAR
)CRTC
, 0x07);
391 WRITE_PORT_UCHAR((PUCHAR
)CRTC
+1, 0x3E);
393 /* Vertical sync start */
394 WRITE_PORT_UCHAR((PUCHAR
)CRTC
, 0x10);
395 WRITE_PORT_UCHAR((PUCHAR
)CRTC
+1, 0xEA);
397 /* Vertical display end */
398 WRITE_PORT_UCHAR((PUCHAR
)CRTC
, 0x12);
399 WRITE_PORT_UCHAR((PUCHAR
)CRTC
+1, 0xDF);
401 /* Vertical blank start */
402 WRITE_PORT_UCHAR((PUCHAR
)CRTC
, 0x15);
403 WRITE_PORT_UCHAR((PUCHAR
)CRTC
+1, 0xE7);
405 /* Vertical blank end */
406 WRITE_PORT_UCHAR((PUCHAR
)CRTC
, 0x16);
407 WRITE_PORT_UCHAR((PUCHAR
)CRTC
+1, 0x04);
409 /* Misc output register (read) */
410 CRTC
= READ_PORT_UCHAR((PUCHAR
)0x03CC);
412 /* Preserve clock select bits and color bit */
413 CRTC
= (CRTC
& 0x0D);
414 /* Set correct sync polarity */
415 CRTC
= (CRTC
| 0xE2);
418 WRITE_PORT_UCHAR((PUCHAR
)0x03C2, (UCHAR
)CRTC
);
422 PcVideoSetDisplayEnd(VOID
)
427 CRTC
= READ_PORT_UCHAR((PUCHAR
)0x03CC);
438 /* Vertical display end */
439 WRITE_PORT_UCHAR((PUCHAR
)CRTC
, 0x12);
440 WRITE_PORT_UCHAR((PUCHAR
)CRTC
+1, 0xDF);
444 PcVideoVesaGetSVGAModeInformation(USHORT Mode
, PSVGA_MODE_INFORMATION ModeInformation
)
448 RtlZeroMemory((PVOID
)BIOSCALLBUFFER
, 256);
450 /* VESA SuperVGA BIOS - GET SuperVGA MODE INFORMATION
452 * CX = SuperVGA video mode (see #04082 for bitfields)
453 * ES:DI -> 256-byte buffer for mode information (see #00079)
455 * AL = 4Fh if function supported
458 * ES:DI buffer filled
461 * Desc: Determine the attributes of the specified video mode
463 * Note: While VBE 1.1 and higher will zero out all unused bytes
464 * of the buffer, v1.0 did not, so applications that want to be
465 * backward compatible should clear the buffer before calling
469 Regs
.w
.es
= BIOSCALLBUFSEGMENT
;
470 Regs
.w
.di
= BIOSCALLBUFOFFSET
;
471 Int386(0x10, &Regs
, &Regs
);
473 if (Regs
.w
.ax
!= 0x004F)
478 RtlCopyMemory(ModeInformation
, (PVOID
)BIOSCALLBUFFER
, sizeof(SVGA_MODE_INFORMATION
));
481 TRACE("BiosVesaGetSVGAModeInformation() mode 0x%x\n", Mode
);
482 TRACE("ModeAttributes = 0x%x\n", ModeInformation
->ModeAttributes
);
483 TRACE("WindowAttributesA = 0x%x\n", ModeInformation
->WindowAttributesA
);
484 TRACE("WindowAttributesB = 0x%x\n", ModeInformation
->WindowsAttributesB
);
485 TRACE("WindowGranularity = %dKB\n", ModeInformation
->WindowGranularity
);
486 TRACE("WindowSize = %dKB\n", ModeInformation
->WindowSize
);
487 TRACE("WindowAStartSegment = 0x%x\n", ModeInformation
->WindowAStartSegment
);
488 TRACE("WindowBStartSegment = 0x%x\n", ModeInformation
->WindowBStartSegment
);
489 TRACE("WindowPositioningFunction = 0x%x\n", ModeInformation
->WindowPositioningFunction
);
490 TRACE("BytesPerScanLine = %d\n", ModeInformation
->BytesPerScanLine
);
491 TRACE("WidthInPixels = %d\n", ModeInformation
->WidthInPixels
);
492 TRACE("HeightInPixels = %d\n", ModeInformation
->HeightInPixels
);
493 TRACE("CharacterWidthInPixels = %d\n", ModeInformation
->CharacterWidthInPixels
);
494 TRACE("CharacterHeightInPixels = %d\n", ModeInformation
->CharacterHeightInPixels
);
495 TRACE("NumberOfMemoryPlanes = %d\n", ModeInformation
->NumberOfMemoryPlanes
);
496 TRACE("BitsPerPixel = %d\n", ModeInformation
->BitsPerPixel
);
497 TRACE("NumberOfBanks = %d\n", ModeInformation
->NumberOfBanks
);
498 TRACE("MemoryModel = %d\n", ModeInformation
->MemoryModel
);
499 TRACE("BankSize = %d\n", ModeInformation
->BankSize
);
500 TRACE("NumberOfImagePlanes = %d\n", ModeInformation
->NumberOfImagePanes
);
501 TRACE("---VBE v1.2+ ---\n");
502 TRACE("RedMaskSize = %d\n", ModeInformation
->RedMaskSize
);
503 TRACE("RedMaskPosition = %d\n", ModeInformation
->RedMaskPosition
);
504 TRACE("GreenMaskSize = %d\n", ModeInformation
->GreenMaskSize
);
505 TRACE("GreenMaskPosition = %d\n", ModeInformation
->GreenMaskPosition
);
506 TRACE("BlueMaskSize = %d\n", ModeInformation
->BlueMaskSize
);
507 TRACE("BlueMaskPosition = %d\n", ModeInformation
->BlueMaskPosition
);
508 TRACE("ReservedMaskSize = %d\n", ModeInformation
->ReservedMaskSize
);
509 TRACE("ReservedMaskPosition = %d\n", ModeInformation
->ReservedMaskPosition
);
516 PcVideoSetBiosVesaMode(USHORT Mode
)
521 * VESA SuperVGA BIOS - SET SuperVGA VIDEO MODE
524 * BX = new video mode
525 * ES:DI -> (VBE 3.0+) CRTC information block, bit mode bit 11 set
527 * AL = 4Fh if function supported
532 * Values for VESA video mode:
533 * 00h-FFh OEM video modes (see #00010 at AH=00h)
560 * 119h 1280x1024x32K (1:5:5:5)
561 * 11Ah 1280x1024x64K (5:6:5)
567 * 81FFh special full-memory access mode
569 * Notes: The special mode 81FFh preserves the contents of the video memory and gives
570 * access to all of the memory; VESA recommends that the special mode be a packed-pixel
571 * mode. For VBE 2.0+, it is required that the VBE implement the mode, but not place it
572 * in the list of available modes (mode information for this mode can be queried
573 * directly, however).. As of VBE 2.0, VESA will no longer define video mode numbers
577 Int386(0x10, &Regs
, &Regs
);
579 if (0x004F != Regs
.w
.ax
)
588 PcVideoSetMode80x25(VOID
)
590 PcVideoSetBiosMode(0x03);
598 PcVideoSetMode80x50_80x43(VOID
)
600 if (VIDEOCARD_VGA
== PcVideoDetectVideoCard())
602 PcVideoSetBiosMode(0x12);
604 PcVideoSelectAlternatePrintScreen();
605 PcVideoDisableCursorEmulation();
606 PcVideoDefineCursor(6, 7);
610 else if (VIDEOCARD_EGA
== PcVideoDetectVideoCard())
612 PcVideoSetBiosMode(0x03);
614 PcVideoSelectAlternatePrintScreen();
615 PcVideoDisableCursorEmulation();
616 PcVideoDefineCursor(6, 7);
620 else /* VIDEOCARD_CGA_OR_OTHER */
629 PcVideoSetMode80x28(VOID
)
631 /* FIXME: Is this VGA-only? */
632 PcVideoSetMode80x25();
633 PcVideoSetFont8x14();
634 PcVideoDefineCursor(11, 12);
642 PcVideoSetMode80x30(VOID
)
644 /* FIXME: Is this VGA-only? */
645 PcVideoSetMode80x25();
646 PcVideoSet480ScanLines();
654 PcVideoSetMode80x34(VOID
)
656 /* FIXME: Is this VGA-only? */
657 PcVideoSetMode80x25();
658 PcVideoSet480ScanLines();
659 PcVideoSetFont8x14();
660 PcVideoDefineCursor(11, 12);
661 PcVideoSetDisplayEnd();
669 PcVideoSetMode80x43(VOID
)
671 /* FIXME: Is this VGA-only? */
672 PcVideoSetVerticalResolution(VERTRES_350_SCANLINES
);
673 PcVideoSetMode80x25();
675 PcVideoSelectAlternatePrintScreen();
676 PcVideoDisableCursorEmulation();
677 PcVideoDefineCursor(6, 7);
685 PcVideoSetMode80x60(VOID
)
687 /* FIXME: Is this VGA-only? */
688 PcVideoSetMode80x25();
689 PcVideoSet480ScanLines();
691 PcVideoSelectAlternatePrintScreen();
692 PcVideoDisableCursorEmulation();
693 PcVideoDefineCursor(6, 7);
694 PcVideoSetDisplayEnd();
702 PcVideoSetMode(USHORT NewMode
)
704 CurrentMemoryBank
= 0;
706 /* Set the values for the default text modes
707 * If they are setting a graphics mode then
708 * these values will be changed.
710 BiosVideoMode
= NewMode
;
713 BytesPerScanLine
= 160;
714 DisplayMode
= VideoTextMode
;
715 VesaVideoMode
= FALSE
;
719 case VIDEOMODE_NORMAL_TEXT
:
720 case 0x03: /* BIOS 80x25 text mode number */
721 return PcVideoSetMode80x25();
722 case VIDEOMODE_EXTENDED_TEXT
:
723 return PcVideoSetMode80x50_80x43();
724 case VIDEOMODE_80X28
:
725 return PcVideoSetMode80x28();
726 case VIDEOMODE_80X30
:
727 return PcVideoSetMode80x30();
728 case VIDEOMODE_80X34
:
729 return PcVideoSetMode80x34();
730 case VIDEOMODE_80X43
:
731 return PcVideoSetMode80x43();
732 case VIDEOMODE_80X60
:
733 return PcVideoSetMode80x60();
739 PcVideoSetBiosMode((UCHAR
)NewMode
);
740 WRITE_PORT_USHORT((USHORT
*)0x03CE, 0x0F01); /* For some reason this is necessary? */
743 BytesPerScanLine
= 80;
744 BiosVideoMode
= NewMode
;
745 DisplayMode
= VideoGraphicsMode
;
749 else if (0x13 == NewMode
)
752 PcVideoSetBiosMode((UCHAR
)NewMode
);
755 BytesPerScanLine
= 320;
756 BiosVideoMode
= NewMode
;
757 DisplayMode
= VideoGraphicsMode
;
761 else if (0x0108 <= NewMode
&& NewMode
<= 0x010C)
764 if (! PcVideoVesaGetSVGAModeInformation(NewMode
, &VesaVideoModeInformation
))
769 if (! PcVideoSetBiosVesaMode(NewMode
))
774 ScreenWidth
= VesaVideoModeInformation
.WidthInPixels
;
775 ScreenHeight
= VesaVideoModeInformation
.HeightInPixels
;
776 BytesPerScanLine
= VesaVideoModeInformation
.BytesPerScanLine
;
777 BiosVideoMode
= NewMode
;
778 DisplayMode
= VideoTextMode
;
779 VesaVideoMode
= TRUE
;
785 /* VESA Graphics Mode */
786 if (! PcVideoVesaGetSVGAModeInformation(NewMode
, &VesaVideoModeInformation
))
791 if (! PcVideoSetBiosVesaMode(NewMode
))
796 ScreenWidth
= VesaVideoModeInformation
.WidthInPixels
;
797 ScreenHeight
= VesaVideoModeInformation
.HeightInPixels
;
798 BytesPerScanLine
= VesaVideoModeInformation
.BytesPerScanLine
;
799 BiosVideoMode
= NewMode
;
800 DisplayMode
= VideoGraphicsMode
;
801 VesaVideoMode
= TRUE
;
810 PcVideoSetBlinkBit(BOOLEAN Enable
)
815 * VIDEO - TOGGLE INTENSITY/BLINKING BIT (Jr, PS, TANDY 1000, EGA, VGA)
819 * 00h background intensity enabled
821 * BH = 00h to avoid problems on some adapters
825 * Note: although there is no function to get
826 * the current status, bit 5 of 0040h:0065h
827 * indicates the state.
830 Regs
.w
.bx
= Enable
? 0x0001 : 0x0000;
831 Int386(0x10, &Regs
, &Regs
);
835 PcVideoSetMemoryBank(USHORT BankNumber
)
839 if (CurrentMemoryBank
!= BankNumber
)
842 * VESA SuperVGA BIOS - CPU VIDEO MEMORY CONTROL
846 * 00h select video memory window
847 * 01h get video memory window
848 * DX = window address in video memory (in granularity units)
850 * DX = window address in video memory (in gran. units)
855 * AL = 4Fh if function supported
862 Regs
.w
.dx
= BankNumber
;
863 Int386(0x10, &Regs
, &Regs
);
865 if (0x004F == Regs
.w
.ax
)
867 CurrentMemoryBank
= BankNumber
;
873 PcVideoSetDisplayMode(char *DisplayModeName
, BOOLEAN Init
)
875 USHORT VideoMode
= VIDEOMODE_NORMAL_TEXT
;
877 if (NULL
== DisplayModeName
|| '\0' == *DisplayModeName
)
879 PcVideoSetBlinkBit(! Init
);
883 if (VIDEOCARD_CGA_OR_OTHER
== PcVideoDetectVideoCard())
885 TRACE("CGA or other display adapter detected.\n");
886 printf("CGA or other display adapter detected.\n");
887 printf("Using 80x25 text mode.\n");
888 VideoMode
= VIDEOMODE_NORMAL_TEXT
;
890 else if (VIDEOCARD_EGA
== PcVideoDetectVideoCard())
892 TRACE("EGA display adapter detected.\n");
893 printf("EGA display adapter detected.\n");
894 printf("Using 80x25 text mode.\n");
895 VideoMode
= VIDEOMODE_NORMAL_TEXT
;
897 else /* if (VIDEOCARD_VGA == PcVideoDetectVideoCard()) */
899 TRACE("VGA display adapter detected.\n");
901 if (0 == _stricmp(DisplayModeName
, "NORMAL_VGA"))
903 VideoMode
= VIDEOMODE_NORMAL_TEXT
;
905 else if (0 == _stricmp(DisplayModeName
, "EXTENDED_VGA"))
907 VideoMode
= VIDEOMODE_EXTENDED_TEXT
;
911 VideoMode
= atoi(DisplayModeName
);
915 if (! PcVideoSetMode(VideoMode
))
917 printf("Error: unable to set video display mode 0x%x\n", (int) VideoMode
);
918 printf("Defaulting to 80x25 text mode.\n");
919 printf("Press any key to continue.\n");
922 PcVideoSetMode(VIDEOMODE_NORMAL_TEXT
);
925 PcVideoSetBlinkBit(! Init
);
931 PcVideoGetDisplaySize(PULONG Width
, PULONG Height
, PULONG Depth
)
933 *Width
= ScreenWidth
;
934 *Height
= ScreenHeight
;
935 if (VideoGraphicsMode
== DisplayMode
&& VesaVideoMode
)
937 if (16 == VesaVideoModeInformation
.BitsPerPixel
)
939 /* 16-bit color modes give green an extra bit (5:6:5)
940 * 15-bit color modes have just 5:5:5 for R:G:B */
941 *Depth
= (6 == VesaVideoModeInformation
.GreenMaskSize
? 16 : 15);
945 *Depth
= VesaVideoModeInformation
.BitsPerPixel
;
955 PcVideoGetBufferSize(VOID
)
957 return ScreenHeight
* BytesPerScanLine
;
961 PcVideoSetTextCursorPosition(UCHAR X
, UCHAR Y
)
966 * VIDEO - SET CURSOR POSITION
972 * 0 in graphics modes
973 * DH = row (00h is top)
974 * DL = column (00h is left)
982 Int386(0x10, &Regs
, &Regs
);
986 PcVideoHideShowTextCursor(BOOLEAN Show
)
990 PcVideoDefineCursor(0x0D, 0x0E);
994 PcVideoDefineCursor(0x20, 0x00);
999 PcVideoCopyOffScreenBufferToVRAM(PVOID Buffer
)
1002 ULONG BytesInLastBank
;
1006 /* PcVideoWaitForVerticalRetrace(); */
1008 /* Text mode (BIOS or VESA) */
1009 if (VideoTextMode
== DisplayMode
)
1011 RtlCopyMemory((PVOID
) VIDEOTEXT_MEM_ADDRESS
, Buffer
, PcVideoGetBufferSize());
1013 /* VESA graphics mode */
1014 else if (VideoGraphicsMode
== DisplayMode
&& VesaVideoMode
)
1016 BankSize
= VesaVideoModeInformation
.WindowGranularity
<< 10;
1017 BanksToCopy
= (USHORT
)((VesaVideoModeInformation
.HeightInPixels
* VesaVideoModeInformation
.BytesPerScanLine
) / BankSize
);
1018 BytesInLastBank
= (VesaVideoModeInformation
.HeightInPixels
* VesaVideoModeInformation
.BytesPerScanLine
) % BankSize
;
1020 /* Copy all the banks but the last one because
1021 * it is probably a partial bank */
1022 for (CurrentBank
= 0; CurrentBank
< BanksToCopy
; CurrentBank
++)
1024 PcVideoSetMemoryBank(CurrentBank
);
1025 RtlCopyMemory((PVOID
) VIDEOVGA_MEM_ADDRESS
, (char *) Buffer
+ CurrentBank
* BankSize
, BankSize
);
1028 /* Copy the remaining bytes into the last bank */
1029 PcVideoSetMemoryBank(CurrentBank
);
1030 RtlCopyMemory((PVOID
)VIDEOVGA_MEM_ADDRESS
, (char *) Buffer
+ CurrentBank
* BankSize
, BytesInLastBank
);
1032 /* BIOS graphics mode */
1040 PcVideoClearScreen(UCHAR Attr
)
1045 AttrChar
= ((USHORT
) Attr
<< 8) | ' ';
1046 for (BufPtr
= (USHORT
*) VIDEOTEXT_MEM_ADDRESS
;
1047 BufPtr
< (USHORT
*) (VIDEOTEXT_MEM_ADDRESS
+ VIDEOTEXT_MEM_SIZE
);
1055 PcVideoPutChar(int Ch
, UCHAR Attr
, unsigned X
, unsigned Y
)
1059 BufPtr
= (USHORT
*) (ULONG_PTR
)(VIDEOTEXT_MEM_ADDRESS
+ Y
* BytesPerScanLine
+ X
* 2);
1060 *BufPtr
= ((USHORT
) Attr
<< 8) | (Ch
& 0xff);
1064 PcVideoIsPaletteFixed(VOID
)
1070 PcVideoSetPaletteColor(UCHAR Color
, UCHAR Red
, UCHAR Green
, UCHAR Blue
)
1072 WRITE_PORT_UCHAR((UCHAR
*) VIDEOPORT_PALETTE_WRITE
, Color
);
1073 WRITE_PORT_UCHAR((UCHAR
*) VIDEOPORT_PALETTE_DATA
, Red
);
1074 WRITE_PORT_UCHAR((UCHAR
*) VIDEOPORT_PALETTE_DATA
, Green
);
1075 WRITE_PORT_UCHAR((UCHAR
*) VIDEOPORT_PALETTE_DATA
, Blue
);
1079 PcVideoGetPaletteColor(UCHAR Color
, UCHAR
* Red
, UCHAR
* Green
, UCHAR
* Blue
)
1081 WRITE_PORT_UCHAR((UCHAR
*) VIDEOPORT_PALETTE_READ
, Color
);
1082 *Red
= READ_PORT_UCHAR((UCHAR
*) VIDEOPORT_PALETTE_DATA
);
1083 *Green
= READ_PORT_UCHAR((UCHAR
*) VIDEOPORT_PALETTE_DATA
);
1084 *Blue
= READ_PORT_UCHAR((UCHAR
*) VIDEOPORT_PALETTE_DATA
);
1090 while (1 == (READ_PORT_UCHAR((UCHAR
*)VIDEOPORT_VERTICAL_RETRACE
) & 0x08))
1093 * Keep reading the port until bit 3 is clear
1094 * This waits for the current retrace to end and
1095 * we can catch the next one so we know we are
1096 * getting a full retrace.
1100 while (0 == (READ_PORT_UCHAR((UCHAR
*)VIDEOPORT_VERTICAL_RETRACE
) & 0x08))
1103 * Keep reading the port until bit 3 is set
1104 * Now that we know we aren't doing a vertical
1105 * retrace we need to wait for the next one.
1111 PcVideoPrepareForReactOS(IN BOOLEAN Setup
)
1115 PcVideoSetMode80x50_80x43();
1119 PcVideoSetBiosMode(0x12);
1121 PcVideoHideShowTextCursor(FALSE
);