5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
25 #define VIDEOPORT_PALETTE_READ 0x03C7
26 #define VIDEOPORT_PALETTE_WRITE 0x03C8
27 #define VIDEOPORT_PALETTE_DATA 0x03C9
28 #define VIDEOPORT_VERTICAL_RETRACE 0x03DA
30 #define VIDEOVGA_MEM_ADDRESS 0xA0000
31 #define VIDEOTEXT_MEM_ADDRESS 0xB8000
32 #define VIDEOTEXT_MEM_SIZE 0x8000
34 #define VIDEOCARD_CGA_OR_OTHER 0
35 #define VIDEOCARD_EGA 1
36 #define VIDEOCARD_VGA 2
38 #define VIDEOMODE_NORMAL_TEXT 0
39 #define VIDEOMODE_EXTENDED_TEXT 1
40 #define VIDEOMODE_80X28 0x501C
41 #define VIDEOMODE_80X30 0x501E
42 #define VIDEOMODE_80X34 0x5022
43 #define VIDEOMODE_80X43 0x502B
44 #define VIDEOMODE_80X60 0x503C
45 #define VIDEOMODE_132X25 0x8419
46 #define VIDEOMODE_132X43 0x842B
47 #define VIDEOMODE_132X50 0x8432
48 #define VIDEOMODE_132X60 0x843C
50 #define VERTRES_200_SCANLINES 0x00
51 #define VERTRES_350_SCANLINES 0x01
52 #define VERTRES_400_SCANLINES 0x02
56 USHORT ModeAttributes
; /* mode attributes (see #00080) */
57 UCHAR WindowAttributesA
; /* window attributes, window A (see #00081) */
58 UCHAR WindowsAttributesB
; /* window attributes, window B (see #00081) */
59 USHORT WindowGranularity
; /* window granularity in KB */
60 USHORT WindowSize
; /* window size in KB */
61 USHORT WindowAStartSegment
; /* start segment of window A (0000h if not supported) */
62 USHORT WindowBStartSegment
; /* start segment of window B (0000h if not supported) */
63 ULONG WindowPositioningFunction
; /* -> FAR window positioning function (equivalent to AX=4F05h) */
64 USHORT BytesPerScanLine
; /* bytes per scan line */
65 /* ---remainder is optional for VESA modes in v1.0/1.1, needed for OEM modes--- */
66 USHORT WidthInPixels
; /* width in pixels (graphics) or characters (text) */
67 USHORT HeightInPixels
; /* height in pixels (graphics) or characters (text) */
68 UCHAR CharacterWidthInPixels
; /* width of character cell in pixels */
69 UCHAR CharacterHeightInPixels
; /* height of character cell in pixels */
70 UCHAR NumberOfMemoryPlanes
; /* number of memory planes */
71 UCHAR BitsPerPixel
; /* number of bits per pixel */
72 UCHAR NumberOfBanks
; /* number of banks */
73 UCHAR MemoryModel
; /* memory model type (see #00082) */
74 UCHAR BankSize
; /* size of bank in KB */
75 UCHAR NumberOfImagePanes
; /* number of image pages (less one) that will fit in video RAM */
76 UCHAR Reserved1
; /* reserved (00h for VBE 1.0-2.0, 01h for VBE 3.0) */
77 /* ---VBE v1.2+ --- */
78 UCHAR RedMaskSize
; /* red mask size */
79 UCHAR RedMaskPosition
; /* red field position */
80 UCHAR GreenMaskSize
; /* green mask size */
81 UCHAR GreenMaskPosition
; /* green field size */
82 UCHAR BlueMaskSize
; /* blue mask size */
83 UCHAR BlueMaskPosition
; /* blue field size */
84 UCHAR ReservedMaskSize
; /* reserved mask size */
85 UCHAR ReservedMaskPosition
; /* reserved mask position */
86 UCHAR DirectColorModeInfo
; /* direct color mode info */
87 /* bit 0:Color ramp is programmable */
88 /* bit 1:Bytes in reserved field may be used by application */
89 /* ---VBE v2.0+ --- */
90 ULONG LinearVideoBufferAddress
; /* physical address of linear video buffer */
91 ULONG OffscreenMemoryPointer
; /* pointer to start of offscreen memory */
92 USHORT OffscreenMemorySize
; /* KB of offscreen memory */
94 USHORT LinearBytesPerScanLine
; /* bytes per scan line in linear modes */
95 UCHAR BankedNumberOfImages
; /* number of images (less one) for banked video modes */
96 UCHAR LinearNumberOfImages
; /* number of images (less one) for linear video modes */
97 UCHAR LinearRedMaskSize
; /* linear modes:Size of direct color red mask (in bits) */
98 UCHAR LinearRedMaskPosition
; /* linear modes:Bit position of red mask LSB (e.g. shift count) */
99 UCHAR LinearGreenMaskSize
; /* linear modes:Size of direct color green mask (in bits) */
100 UCHAR LinearGreenMaskPosition
; /* linear modes:Bit position of green mask LSB (e.g. shift count) */
101 UCHAR LinearBlueMaskSize
; /* linear modes:Size of direct color blue mask (in bits) */
102 UCHAR LinearBlueMaskPosition
; /* linear modes:Bit position of blue mask LSB (e.g. shift count) */
103 UCHAR LinearReservedMaskSize
; /* linear modes:Size of direct color reserved mask (in bits) */
104 UCHAR LinearReservedMaskPosition
; /* linear modes:Bit position of reserved mask LSB */
105 ULONG MaximumPixelClock
; /* maximum pixel clock for graphics video mode, in Hz */
106 UCHAR Reserved2
[190]; /* 190 BYTEs reserved (0) */
107 } PACKED SVGA_MODE_INFORMATION
, *PSVGA_MODE_INFORMATION
;
109 static ULONG BiosVideoMode
; /* Current video mode as known by BIOS */
110 static ULONG ScreenWidth
= 80; /* Screen Width in characters */
111 static ULONG ScreenHeight
= 25; /* Screen Height in characters */
112 static ULONG BytesPerScanLine
= 160; /* Number of bytes per scanline (delta) */
113 static VIDEODISPLAYMODE DisplayMode
= VideoTextMode
; /* Current display mode */
114 static BOOL VesaVideoMode
= FALSE
; /* Are we using a VESA mode? */
115 static SVGA_MODE_INFORMATION VesaVideoModeInformation
; /* Only valid when in VESA mode */
116 static ULONG CurrentMemoryBank
= 0; /* Currently selected VESA bank */
119 PcVideoDetectVideoCard(VOID
)
123 /* Int 10h AH=12h BL=10h
124 * VIDEO - ALTERNATE FUNCTION SELECT (PS,EGA,VGA,MCGA) - GET EGA INFO
130 * 00h color mode in effect (I/O port 3Dxh)
131 * 01h mono mode in effect (I/O port 3Bxh)
132 * BL = installed memory (00h = 64K, 01h = 128K, 02h = 192K, 03h = 256K)
133 * CH = feature connector bits
134 * CL = switch settings
135 * AH destroyed (at least by Tseng ET4000 BIOS v8.00n)
137 * Installation check;EGA
141 Int386(0x10, &Regs
, &Regs
);
143 /* If BL is still equal to 0x10 then there is no EGA/VGA present */
144 if (0x10 == Regs
.b
.bl
)
146 return VIDEOCARD_CGA_OR_OTHER
;
150 * VIDEO - GET DISPLAY COMBINATION CODE (PS,VGA/MCGA)
154 * AL = 1Ah if function was supported
155 * BL = active display code
156 * BH = alternate display code
158 * This function is commonly used to check for the presence of a VGA.
160 * Installation check;VGA
162 * Values for display combination code:
164 * 01h monochrome adapter w/ monochrome display
165 * 02h CGA w/ color display
167 * 04h EGA w/ color display
168 * 05h EGA w/ monochrome display
169 * 06h PGA w/ color display
170 * 07h VGA w/ monochrome analog display
171 * 08h VGA w/ color analog display
173 * 0Ah MCGA w/ digital color display
174 * 0Bh MCGA w/ monochrome analog display
175 * 0Ch MCGA w/ color analog display
176 * FFh unknown display type
180 Int386(0x10, &Regs
, &Regs
);
182 if (0x1a == Regs
.b
.al
)
184 return VIDEOCARD_VGA
;
188 return VIDEOCARD_EGA
;
192 static VOID
PcVideoSetBiosMode(ULONG VideoMode
)
197 * VIDEO - SET VIDEO MODE
200 * AL = desired video mode
202 * AL = video mode flag (Phoenix, AMI BIOS)
204 * 30h modes 0-5 and 7
206 * AL = CRT controller mode byte (Phoenix 386 BIOS v1.10)
209 Regs
.b
.al
= VideoMode
;
210 Int386(0x10, &Regs
, &Regs
);
214 PcVideoSetFont8x8(VOID
)
219 * VIDEO - TEXT-MODE CHARGEN - LOAD ROM 8x8 DBL-DOT PATTERNS (PS,EGA,VGA)
228 Int386(0x10, &Regs
, &Regs
);
232 PcVideoSetFont8x14(VOID
)
237 * VIDEO - TEXT-MODE CHARGEN - LOAD ROM MONOCHROME PATTERNS (PS,EGA,VGA)
246 Int386(0x10, &Regs
, &Regs
);
250 PcVideoSelectAlternatePrintScreen(VOID
)
254 /* Int 10h AH=12h BL=20h
255 * VIDEO - ALTERNATE FUNCTION SELECT (PS,EGA,VGA,MCGA) - ALTERNATE PRTSC
258 * BL = 20h select alternate print screen routine
262 * Installs a PrtSc routine from the video card's BIOS to replace the
263 * default PrtSc handler from the ROM BIOS, which usually does not
264 * understand screen heights other than 25 lines.
266 * Some adapters disable print-screen instead of enhancing it.
270 Int386(0x10, &Regs
, &Regs
);
274 PcVideoDisableCursorEmulation(VOID
)
278 /* Int 10h AH=12h BL=34h
279 * VIDEO - ALTERNATE FUNCTION SELECT (VGA) - CURSOR EMULATION
284 * 00h enable alphanumeric cursor emulation
285 * 01h disable alphanumeric cursor emulation
287 * AL = 12h if function supported
289 * Specify whether the BIOS should automatically remap cursor start/end
290 * according to the current character height in text modes.
295 Int386(0x10, &Regs
, &Regs
);
299 PcVideoDefineCursor(ULONG StartScanLine
, ULONG EndScanLine
)
304 * VIDEO - SET TEXT-MODE CURSOR SHAPE
307 * CH = cursor start and options
308 * CL = bottom scan line containing cursor (bits 0-4)
312 * Specify the starting and ending scan lines to be occupied
313 * by the hardware cursor in text modes.
315 * AMI 386 BIOS and AST Premier 386 BIOS will lock up the
316 * system if AL is not equal to the current video mode.
318 * Bitfields for cursor start and options:
323 * (00=normal, 01=invisible, 10=erratic, 11=slow).
324 * (00=normal, other=invisible on EGA/VGA)
325 * 4-0 topmost scan line containing cursor
329 Regs
.b
.ch
= StartScanLine
;
330 Regs
.b
.cl
= EndScanLine
;
331 Int386(0x10, &Regs
, &Regs
);
335 PcVideoSetVerticalResolution(ULONG ScanLines
)
339 /* Int 10h AH=12h BL=30h
340 * VIDEO - ALTERNATE FUNCTION SELECT (VGA) - SELECT VERTICAL RESOLUTION
344 * AL = vertical resolution
349 * AL = 12h if function supported
351 * Specifiy the number of scan lines used to display text modes.
353 * The specified resolution will take effect on the next mode set.
357 Regs
.b
.al
= ScanLines
;
358 Int386(0x10, &Regs
, &Regs
);
362 PcVideoSet480ScanLines(VOID
)
367 CRTC
= READ_PORT_UCHAR((PUCHAR
)0x03CC);
378 /* Vertical sync end (also unlocks CR0-7) */
379 WRITE_PORT_UCHAR((PUCHAR
)CRTC
, 0x11);
380 WRITE_PORT_UCHAR((PUCHAR
)CRTC
+1, 0x0C);
383 WRITE_PORT_UCHAR((PUCHAR
)CRTC
, 0x06);
384 WRITE_PORT_UCHAR((PUCHAR
)CRTC
+1, 0x0B);
386 /* (vertical) overflow */
387 WRITE_PORT_UCHAR((PUCHAR
)CRTC
, 0x07);
388 WRITE_PORT_UCHAR((PUCHAR
)CRTC
+1, 0x3E);
390 /* Vertical sync start */
391 WRITE_PORT_UCHAR((PUCHAR
)CRTC
, 0x10);
392 WRITE_PORT_UCHAR((PUCHAR
)CRTC
+1, 0xEA);
394 /* Vertical display end */
395 WRITE_PORT_UCHAR((PUCHAR
)CRTC
, 0x12);
396 WRITE_PORT_UCHAR((PUCHAR
)CRTC
+1, 0xDF);
398 /* Vertical blank start */
399 WRITE_PORT_UCHAR((PUCHAR
)CRTC
, 0x15);
400 WRITE_PORT_UCHAR((PUCHAR
)CRTC
+1, 0xE7);
402 /* Vertical blank end */
403 WRITE_PORT_UCHAR((PUCHAR
)CRTC
, 0x16);
404 WRITE_PORT_UCHAR((PUCHAR
)CRTC
+1, 0x04);
406 /* Misc output register (read) */
407 CRTC
= READ_PORT_UCHAR((PUCHAR
)0x03CC);
409 /* Preserve clock select bits and color bit */
410 CRTC
= (CRTC
& 0x0D);
411 /* Set correct sync polarity */
412 CRTC
= (CRTC
| 0xE2);
415 WRITE_PORT_UCHAR((PUCHAR
)0x03C2, CRTC
);
419 PcVideoSetDisplayEnd(VOID
)
424 CRTC
= READ_PORT_UCHAR((PUCHAR
)0x03CC);
435 /* Vertical display end */
436 WRITE_PORT_UCHAR((PUCHAR
)CRTC
, 0x12);
437 WRITE_PORT_UCHAR((PUCHAR
)CRTC
+1, 0xDF);
441 PcVideoVesaGetSVGAModeInformation(USHORT Mode
, PSVGA_MODE_INFORMATION ModeInformation
)
445 RtlZeroMemory((PVOID
)BIOSCALLBUFFER
, 256);
447 /* VESA SuperVGA BIOS - GET SuperVGA MODE INFORMATION
449 * CX = SuperVGA video mode (see #04082 for bitfields)
450 * ES:DI -> 256-byte buffer for mode information (see #00079)
452 * AL = 4Fh if function supported
455 * ES:DI buffer filled
458 * Desc: Determine the attributes of the specified video mode
460 * Note: While VBE 1.1 and higher will zero out all unused bytes
461 * of the buffer, v1.0 did not, so applications that want to be
462 * backward compatible should clear the buffer before calling
466 Regs
.w
.es
= BIOSCALLBUFSEGMENT
;
467 Regs
.w
.di
= BIOSCALLBUFOFFSET
;
468 Int386(0x10, &Regs
, &Regs
);
470 if (Regs
.w
.ax
!= 0x004F)
475 RtlCopyMemory(ModeInformation
, (PVOID
)BIOSCALLBUFFER
, sizeof(SVGA_MODE_INFORMATION
));
477 DbgPrint((DPRINT_UI
, "\n"));
478 DbgPrint((DPRINT_UI
, "BiosVesaGetSVGAModeInformation() mode 0x%x\n", Mode
));
479 DbgPrint((DPRINT_UI
, "ModeAttributes = 0x%x\n", ModeInformation
->ModeAttributes
));
480 DbgPrint((DPRINT_UI
, "WindowAttributesA = 0x%x\n", ModeInformation
->WindowAttributesA
));
481 DbgPrint((DPRINT_UI
, "WindowAttributesB = 0x%x\n", ModeInformation
->WindowsAttributesB
));
482 DbgPrint((DPRINT_UI
, "WindowGranularity = %dKB\n", ModeInformation
->WindowGranularity
));
483 DbgPrint((DPRINT_UI
, "WindowSize = %dKB\n", ModeInformation
->WindowSize
));
484 DbgPrint((DPRINT_UI
, "WindowAStartSegment = 0x%x\n", ModeInformation
->WindowAStartSegment
));
485 DbgPrint((DPRINT_UI
, "WindowBStartSegment = 0x%x\n", ModeInformation
->WindowBStartSegment
));
486 DbgPrint((DPRINT_UI
, "WindowPositioningFunction = 0x%x\n", ModeInformation
->WindowPositioningFunction
));
487 DbgPrint((DPRINT_UI
, "BytesPerScanLine = %d\n", ModeInformation
->BytesPerScanLine
));
488 DbgPrint((DPRINT_UI
, "WidthInPixels = %d\n", ModeInformation
->WidthInPixels
));
489 DbgPrint((DPRINT_UI
, "HeightInPixels = %d\n", ModeInformation
->HeightInPixels
));
490 DbgPrint((DPRINT_UI
, "CharacterWidthInPixels = %d\n", ModeInformation
->CharacterWidthInPixels
));
491 DbgPrint((DPRINT_UI
, "CharacterHeightInPixels = %d\n", ModeInformation
->CharacterHeightInPixels
));
492 DbgPrint((DPRINT_UI
, "NumberOfMemoryPlanes = %d\n", ModeInformation
->NumberOfMemoryPlanes
));
493 DbgPrint((DPRINT_UI
, "BitsPerPixel = %d\n", ModeInformation
->BitsPerPixel
));
494 DbgPrint((DPRINT_UI
, "NumberOfBanks = %d\n", ModeInformation
->NumberOfBanks
));
495 DbgPrint((DPRINT_UI
, "MemoryModel = %d\n", ModeInformation
->MemoryModel
));
496 DbgPrint((DPRINT_UI
, "BankSize = %d\n", ModeInformation
->BankSize
));
497 DbgPrint((DPRINT_UI
, "NumberOfImagePlanes = %d\n", ModeInformation
->NumberOfImagePanes
));
498 DbgPrint((DPRINT_UI
, "---VBE v1.2+ ---\n"));
499 DbgPrint((DPRINT_UI
, "RedMaskSize = %d\n", ModeInformation
->RedMaskSize
));
500 DbgPrint((DPRINT_UI
, "RedMaskPosition = %d\n", ModeInformation
->RedMaskPosition
));
501 DbgPrint((DPRINT_UI
, "GreenMaskSize = %d\n", ModeInformation
->GreenMaskSize
));
502 DbgPrint((DPRINT_UI
, "GreenMaskPosition = %d\n", ModeInformation
->GreenMaskPosition
));
503 DbgPrint((DPRINT_UI
, "BlueMaskSize = %d\n", ModeInformation
->BlueMaskSize
));
504 DbgPrint((DPRINT_UI
, "BlueMaskPosition = %d\n", ModeInformation
->BlueMaskPosition
));
505 DbgPrint((DPRINT_UI
, "ReservedMaskSize = %d\n", ModeInformation
->ReservedMaskSize
));
506 DbgPrint((DPRINT_UI
, "ReservedMaskPosition = %d\n", ModeInformation
->ReservedMaskPosition
));
507 DbgPrint((DPRINT_UI
, "\n"));
513 PcVideoSetBiosVesaMode(USHORT Mode
)
518 * VESA SuperVGA BIOS - SET SuperVGA VIDEO MODE
521 * BX = new video mode
522 * ES:DI -> (VBE 3.0+) CRTC information block, bit mode bit 11 set
524 * AL = 4Fh if function supported
529 * Values for VESA video mode:
530 * 00h-FFh OEM video modes (see #00010 at AH=00h)
557 * 119h 1280x1024x32K (1:5:5:5)
558 * 11Ah 1280x1024x64K (5:6:5)
564 * 81FFh special full-memory access mode
566 * Notes: The special mode 81FFh preserves the contents of the video memory and gives
567 * access to all of the memory; VESA recommends that the special mode be a packed-pixel
568 * mode. For VBE 2.0+, it is required that the VBE implement the mode, but not place it
569 * in the list of available modes (mode information for this mode can be queried
570 * directly, however).. As of VBE 2.0, VESA will no longer define video mode numbers
574 Int386(0x10, &Regs
, &Regs
);
576 if (0x004F != Regs
.w
.ax
)
585 PcVideoSetMode80x25(VOID
)
587 PcVideoSetBiosMode(0x03);
595 PcVideoSetMode80x50_80x43(VOID
)
597 if (VIDEOCARD_VGA
== PcVideoDetectVideoCard())
599 PcVideoSetBiosMode(0x03);
601 PcVideoSelectAlternatePrintScreen();
602 PcVideoDisableCursorEmulation();
603 PcVideoDefineCursor(6, 7);
607 else if (VIDEOCARD_EGA
== PcVideoDetectVideoCard())
609 PcVideoSetBiosMode(0x03);
611 PcVideoSelectAlternatePrintScreen();
612 PcVideoDisableCursorEmulation();
613 PcVideoDefineCursor(6, 7);
617 else /* VIDEOCARD_CGA_OR_OTHER */
626 PcVideoSetMode80x28(VOID
)
628 /* FIXME: Is this VGA-only? */
629 PcVideoSetMode80x25();
630 PcVideoSetFont8x14();
631 PcVideoDefineCursor(11, 12);
639 PcVideoSetMode80x30(VOID
)
641 /* FIXME: Is this VGA-only? */
642 PcVideoSetMode80x25();
643 PcVideoSet480ScanLines();
651 PcVideoSetMode80x34(VOID
)
653 /* FIXME: Is this VGA-only? */
654 PcVideoSetMode80x25();
655 PcVideoSet480ScanLines();
656 PcVideoSetFont8x14();
657 PcVideoDefineCursor(11, 12);
658 PcVideoSetDisplayEnd();
666 PcVideoSetMode80x43(VOID
)
668 /* FIXME: Is this VGA-only? */
669 PcVideoSetVerticalResolution(VERTRES_350_SCANLINES
);
670 PcVideoSetMode80x25();
672 PcVideoSelectAlternatePrintScreen();
673 PcVideoDisableCursorEmulation();
674 PcVideoDefineCursor(6, 7);
682 PcVideoSetMode80x60(VOID
)
684 /* FIXME: Is this VGA-only? */
685 PcVideoSetMode80x25();
686 PcVideoSet480ScanLines();
688 PcVideoSelectAlternatePrintScreen();
689 PcVideoDisableCursorEmulation();
690 PcVideoDefineCursor(6, 7);
691 PcVideoSetDisplayEnd();
699 PcVideoSetMode(ULONG NewMode
)
701 CurrentMemoryBank
= 0;
703 /* Set the values for the default text modes
704 * If they are setting a graphics mode then
705 * these values will be changed.
707 BiosVideoMode
= NewMode
;
710 BytesPerScanLine
= 160;
711 DisplayMode
= VideoTextMode
;
712 VesaVideoMode
= FALSE
;
716 case VIDEOMODE_NORMAL_TEXT
:
717 case 0x03: /* BIOS 80x25 text mode number */
718 return PcVideoSetMode80x25();
719 case VIDEOMODE_EXTENDED_TEXT
:
720 return PcVideoSetMode80x50_80x43();
721 case VIDEOMODE_80X28
:
722 return PcVideoSetMode80x28();
723 case VIDEOMODE_80X30
:
724 return PcVideoSetMode80x30();
725 case VIDEOMODE_80X34
:
726 return PcVideoSetMode80x34();
727 case VIDEOMODE_80X43
:
728 return PcVideoSetMode80x43();
729 case VIDEOMODE_80X60
:
730 return PcVideoSetMode80x60();
736 PcVideoSetBiosMode(NewMode
);
737 WRITE_PORT_USHORT((USHORT
*)0x03CE, 0x0F01); /* For some reason this is necessary? */
740 BytesPerScanLine
= 80;
741 BiosVideoMode
= NewMode
;
742 DisplayMode
= VideoGraphicsMode
;
746 else if (0x13 == NewMode
)
749 PcVideoSetBiosMode(NewMode
);
752 BytesPerScanLine
= 320;
753 BiosVideoMode
= NewMode
;
754 DisplayMode
= VideoGraphicsMode
;
758 else if (0x0108 <= NewMode
&& NewMode
<= 0x010C)
761 if (! PcVideoVesaGetSVGAModeInformation(NewMode
, &VesaVideoModeInformation
))
766 if (! PcVideoSetBiosVesaMode(NewMode
))
771 ScreenWidth
= VesaVideoModeInformation
.WidthInPixels
;
772 ScreenHeight
= VesaVideoModeInformation
.HeightInPixels
;
773 BytesPerScanLine
= VesaVideoModeInformation
.BytesPerScanLine
;
774 BiosVideoMode
= NewMode
;
775 DisplayMode
= VideoTextMode
;
776 VesaVideoMode
= TRUE
;
782 /* VESA Graphics Mode */
783 if (! PcVideoVesaGetSVGAModeInformation(NewMode
, &VesaVideoModeInformation
))
788 if (! PcVideoSetBiosVesaMode(NewMode
))
793 ScreenWidth
= VesaVideoModeInformation
.WidthInPixels
;
794 ScreenHeight
= VesaVideoModeInformation
.HeightInPixels
;
795 BytesPerScanLine
= VesaVideoModeInformation
.BytesPerScanLine
;
796 BiosVideoMode
= NewMode
;
797 DisplayMode
= VideoTextMode
;
798 VesaVideoMode
= TRUE
;
807 PcVideoSetBlinkBit(BOOL Enable
)
812 * VIDEO - TOGGLE INTENSITY/BLINKING BIT (Jr, PS, TANDY 1000, EGA, VGA)
816 * 00h background intensity enabled
818 * BH = 00h to avoid problems on some adapters
822 * Note: although there is no function to get
823 * the current status, bit 5 of 0040h:0065h
824 * indicates the state.
827 Regs
.w
.bx
= Enable
? 0x0001 : 0x0000;
828 Int386(0x10, &Regs
, &Regs
);
832 PcVideoSetMemoryBank(USHORT BankNumber
)
836 if (CurrentMemoryBank
!= BankNumber
)
839 * VESA SuperVGA BIOS - CPU VIDEO MEMORY CONTROL
843 * 00h select video memory window
844 * 01h get video memory window
845 * DX = window address in video memory (in granularity units)
847 * DX = window address in video memory (in gran. units)
852 * AL = 4Fh if function supported
859 Regs
.w
.dx
= BankNumber
;
860 Int386(0x10, &Regs
, &Regs
);
862 if (0x004F == Regs
.w
.ax
)
864 CurrentMemoryBank
= BankNumber
;
870 PcVideoSetDisplayMode(char *DisplayModeName
, BOOL Init
)
872 ULONG VideoMode
= VIDEOMODE_NORMAL_TEXT
;
874 if (NULL
== DisplayModeName
|| '\0' == *DisplayModeName
)
876 PcVideoSetBlinkBit(! Init
);
880 if (VIDEOCARD_CGA_OR_OTHER
== PcVideoDetectVideoCard())
882 DbgPrint((DPRINT_UI
, "CGA or other display adapter detected.\n"));
883 printf("CGA or other display adapter detected.\n");
884 printf("Using 80x25 text mode.\n");
885 VideoMode
= VIDEOMODE_NORMAL_TEXT
;
887 else if (VIDEOCARD_EGA
== PcVideoDetectVideoCard())
889 DbgPrint((DPRINT_UI
, "EGA display adapter detected.\n"));
890 printf("EGA display adapter detected.\n");
891 printf("Using 80x25 text mode.\n");
892 VideoMode
= VIDEOMODE_NORMAL_TEXT
;
894 else /* if (VIDEOCARD_VGA == PcVideoDetectVideoCard()) */
896 DbgPrint((DPRINT_UI
, "VGA display adapter detected.\n"));
898 if (0 == stricmp(DisplayModeName
, "NORMAL_VGA"))
900 VideoMode
= VIDEOMODE_NORMAL_TEXT
;
902 else if (0 == stricmp(DisplayModeName
, "EXTENDED_VGA"))
904 VideoMode
= VIDEOMODE_EXTENDED_TEXT
;
908 VideoMode
= atoi(DisplayModeName
);
912 if (! PcVideoSetMode(VideoMode
))
914 printf("Error: unable to set video display mode 0x%x\n", (int) VideoMode
);
915 printf("Defaulting to 80x25 text mode.\n");
916 printf("Press any key to continue.\n");
919 PcVideoSetMode(VIDEOMODE_NORMAL_TEXT
);
922 PcVideoSetBlinkBit(! Init
);
929 PcVideoGetDisplaySize(PULONG Width
, PULONG Height
, PULONG Depth
)
931 *Width
= ScreenWidth
;
932 *Height
= ScreenHeight
;
933 if (VideoGraphicsMode
== DisplayMode
&& VesaVideoMode
)
935 if (16 == VesaVideoModeInformation
.BitsPerPixel
)
937 /* 16-bit color modes give green an extra bit (5:6:5)
938 * 15-bit color modes have just 5:5:5 for R:G:B */
939 *Depth
= (6 == VesaVideoModeInformation
.GreenMaskSize
? 16 : 15);
943 *Depth
= VesaVideoModeInformation
.BitsPerPixel
;
953 PcVideoGetBufferSize(VOID
)
955 return ScreenHeight
* BytesPerScanLine
;
959 PcVideoSetTextCursorPosition(ULONG X
, ULONG Y
)
964 * VIDEO - SET CURSOR POSITION
970 * 0 in graphics modes
971 * DH = row (00h is top)
972 * DL = column (00h is left)
980 Int386(0x10, &Regs
, &Regs
);
984 PcVideoHideShowTextCursor(BOOL Show
)
988 PcVideoDefineCursor(0x0D, 0x0E);
992 PcVideoDefineCursor(0x20, 0x00);
997 PcVideoCopyOffScreenBufferToVRAM(PVOID Buffer
)
1000 ULONG BytesInLastBank
;
1004 /* PcVideoWaitForVerticalRetrace(); */
1006 /* Text mode (BIOS or VESA) */
1007 if (VideoTextMode
== DisplayMode
)
1009 RtlCopyMemory((PVOID
) VIDEOTEXT_MEM_ADDRESS
, Buffer
, PcVideoGetBufferSize());
1011 /* VESA graphics mode */
1012 else if (VideoGraphicsMode
== DisplayMode
&& VesaVideoMode
)
1014 BankSize
= VesaVideoModeInformation
.WindowGranularity
<< 10;
1015 BanksToCopy
= (VesaVideoModeInformation
.HeightInPixels
* VesaVideoModeInformation
.BytesPerScanLine
) / BankSize
;
1016 BytesInLastBank
= (VesaVideoModeInformation
.HeightInPixels
* VesaVideoModeInformation
.BytesPerScanLine
) % BankSize
;
1018 /* Copy all the banks but the last one because
1019 * it is probably a partial bank */
1020 for (CurrentBank
= 0; CurrentBank
< BanksToCopy
; CurrentBank
++)
1022 PcVideoSetMemoryBank(CurrentBank
);
1023 RtlCopyMemory((PVOID
) VIDEOVGA_MEM_ADDRESS
, (char *) Buffer
+ CurrentBank
* BankSize
, BankSize
);
1026 /* Copy the remaining bytes into the last bank */
1027 PcVideoSetMemoryBank(CurrentBank
);
1028 RtlCopyMemory((PVOID
)VIDEOVGA_MEM_ADDRESS
, (char *) Buffer
+ CurrentBank
* BankSize
, BytesInLastBank
);
1030 /* BIOS graphics mode */
1038 PcVideoClearScreen(UCHAR Attr
)
1043 AttrChar
= ((USHORT
) Attr
<< 8) | ' ';
1044 for (BufPtr
= (USHORT
*) VIDEOTEXT_MEM_ADDRESS
;
1045 BufPtr
< (USHORT
*) (VIDEOTEXT_MEM_ADDRESS
+ VIDEOTEXT_MEM_SIZE
);
1053 PcVideoPutChar(int Ch
, UCHAR Attr
, unsigned X
, unsigned Y
)
1057 BufPtr
= (USHORT
*) (VIDEOTEXT_MEM_ADDRESS
+ Y
* BytesPerScanLine
+ X
* 2);
1058 *BufPtr
= ((USHORT
) Attr
<< 8) | (Ch
& 0xff);
1062 PcVideoIsPaletteFixed(VOID
)
1068 PcVideoSetPaletteColor(UCHAR Color
, UCHAR Red
, UCHAR Green
, UCHAR Blue
)
1070 WRITE_PORT_UCHAR((UCHAR
*) VIDEOPORT_PALETTE_WRITE
, Color
);
1071 WRITE_PORT_UCHAR((UCHAR
*) VIDEOPORT_PALETTE_DATA
, Red
);
1072 WRITE_PORT_UCHAR((UCHAR
*) VIDEOPORT_PALETTE_DATA
, Green
);
1073 WRITE_PORT_UCHAR((UCHAR
*) VIDEOPORT_PALETTE_DATA
, Blue
);
1077 PcVideoGetPaletteColor(UCHAR Color
, UCHAR
* Red
, UCHAR
* Green
, UCHAR
* Blue
)
1079 WRITE_PORT_UCHAR((UCHAR
*) VIDEOPORT_PALETTE_READ
, Color
);
1080 *Red
= READ_PORT_UCHAR((UCHAR
*) VIDEOPORT_PALETTE_DATA
);
1081 *Green
= READ_PORT_UCHAR((UCHAR
*) VIDEOPORT_PALETTE_DATA
);
1082 *Blue
= READ_PORT_UCHAR((UCHAR
*) VIDEOPORT_PALETTE_DATA
);
1088 while (1 == (READ_PORT_UCHAR((UCHAR
*)VIDEOPORT_VERTICAL_RETRACE
) & 0x08))
1091 * Keep reading the port until bit 3 is clear
1092 * This waits for the current retrace to end and
1093 * we can catch the next one so we know we are
1094 * getting a full retrace.
1098 while (0 == (READ_PORT_UCHAR((UCHAR
*)VIDEOPORT_VERTICAL_RETRACE
) & 0x08))
1101 * Keep reading the port until bit 3 is set
1102 * Now that we know we aren't doing a vertical
1103 * retrace we need to wait for the next one.
1109 PcVideoPrepareForReactOS(VOID
)
1111 PcVideoSetMode80x50_80x43();
1112 PcVideoHideShowTextCursor(FALSE
);