1 /****************************************************************************
3 * SciTech OS Portability Manager Library
5 * ========================================================================
7 * The contents of this file are subject to the SciTech MGL Public
8 * License Version 1.0 (the "License"); you may not use this file
9 * except in compliance with the License. You may obtain a copy of
10 * the License at http://www.scitechsoft.com/mgl-license.txt
12 * Software distributed under the License is distributed on an
13 * "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
14 * implied. See the License for the specific language governing
15 * rights and limitations under the License.
17 * The Original Code is Copyright (C) 1991-1998 SciTech Software, Inc.
19 * The Initial Developer of the Original Code is SciTech Software, Inc.
20 * All Rights Reserved.
22 * ========================================================================
27 * Description: Test program to check the ability to generate real mode
28 * interrupts and to be able to obtain direct access to the
29 * video memory from protected mode. Compile and link with
30 * the appropriate command line for your DOS extender.
32 * Functions tested: PM_getBIOSSelector()
33 * PM_mapPhysicalAddr()
36 ****************************************************************************/
42 uchar *bios; /* Pointer to BIOS data area */
43 uchar *videoPtr; /* Pointer to VGA framebuffer */
44 void *stateBuf; /* Console state save buffer */
46 /* Routine to return the current video mode number */
48 int getVideoMode(void)
50 return PM_getByte(bios+0x49);
53 /* Routine to set a specified video mode */
55 void setVideoMode(int mode)
60 PM_int86(0x10, &r, &r);
63 /* Routine to clear a rectangular region on the display by calling the
67 void clearScreen(int startx, int starty, int endx, int endy, unsigned char attr)
77 PM_int86(0x10, &r, &r);
80 /* Routine to fill a rectangular region on the display using direct
84 #define SCREEN(x,y) (videoPtr + ((y) * 160) + ((x) << 1))
86 void fill(int startx, int starty, int endx, int endy, unsigned char c,
92 for (y = starty; y <= endy; y++) {
94 for (x = startx; x <= endx; x++) {
101 /* Routine to display a single character using direct video writes */
103 void writeChar(int x, int y, unsigned char c, unsigned char attr)
105 unsigned char *v = SCREEN(x,y);
110 /* Routine to draw a border around a rectangular area using direct video
114 static unsigned char border_chars[] = {
115 186, 205, 201, 187, 200, 188 /* double box chars */
118 void border(int startx, int starty, int endx, int endy, unsigned char attr)
126 for (i = starty+1; i < endy; i++) {
127 writeChar(startx, i, *b, attr);
128 writeChar(endx, i, *b, attr);
131 for (i = startx+1, v = SCREEN(startx+1, starty); i < endx; i++) {
135 for (i = startx+1, v = SCREEN(startx+1, endy); i < endx; i++) {
140 writeChar(startx, starty, *b++, attr);
141 writeChar(endx, starty, *b++, attr);
142 writeChar(startx, endy, *b++, attr);
143 writeChar(endx, endy, *b++, attr);
151 printf("Program running in ");
152 switch (PM_getModeType()) {
154 printf("real mode.\n\n");
157 printf("16 bit protected mode.\n\n");
160 printf("32 bit protected mode.\n\n");
164 hwndConsole = PM_openConsole(0,0,0,0,0,true);
165 printf("Hit any key to start 80x25 text mode and perform some direct video output.\n");
168 /* Allocate a buffer to save console state and save the state */
169 if ((stateBuf = PM_malloc(PM_getConsoleStateSize())) == NULL) {
170 printf("Unable to allocate console state buffer!\n");
173 PM_saveConsoleState(stateBuf,0);
174 bios = PM_getBIOSPointer();
175 orgMode = getVideoMode();
177 if ((videoPtr = PM_mapPhysicalAddr(0xB8000,0xFFFF,true)) == NULL) {
178 printf("Unable to obtain pointer to framebuffer!\n");
182 /* Draw some text on the screen */
183 fill(0, 0, 79, 24, 176, 0x1E);
184 border(0, 0, 79, 24, 0x1F);
186 clearScreen(0, 0, 79, 24, 0x7);
188 /* Restore the console state on exit */
189 PM_restoreConsoleState(stateBuf,0);
191 PM_closeConsole(hwndConsole);
193 /* Display useful status information */
195 printf("Original Video Mode = %02X\n", orgMode);
196 printf("BIOS Pointer = %08X\n", (int)bios);
197 printf("Video Memory = %08X\n", (int)videoPtr);