]> git.ipfire.org Git - u-boot.git/blame - board/MAI/bios_emulator/scitech/src/pm/tests/video.c
* Code cleanup:
[u-boot.git] / board / MAI / bios_emulator / scitech / src / pm / tests / video.c
CommitLineData
c7de829c
WD
1/****************************************************************************
2*
3* SciTech OS Portability Manager Library
4*
5* ========================================================================
6*
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
11*
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.
16*
17* The Original Code is Copyright (C) 1991-1998 SciTech Software, Inc.
18*
19* The Initial Developer of the Original Code is SciTech Software, Inc.
20* All Rights Reserved.
21*
22* ========================================================================
23*
24* Language: ANSI C
25* Environment: any
26*
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.
31*
32* Functions tested: PM_getBIOSSelector()
33* PM_mapPhysicalAddr()
34* PM_int86()
35*
36****************************************************************************/
37
38#include <stdlib.h>
39#include <stdio.h>
40#include "pmapi.h"
41
42uchar *bios; /* Pointer to BIOS data area */
43uchar *videoPtr; /* Pointer to VGA framebuffer */
44void *stateBuf; /* Console state save buffer */
45
46/* Routine to return the current video mode number */
47
48int getVideoMode(void)
49{
50 return PM_getByte(bios+0x49);
51}
52
53/* Routine to set a specified video mode */
54
55void setVideoMode(int mode)
56{
57 RMREGS r;
58
59 r.x.ax = mode;
60 PM_int86(0x10, &r, &r);
61}
62
63/* Routine to clear a rectangular region on the display by calling the
64 * video BIOS.
65 */
66
67void clearScreen(int startx, int starty, int endx, int endy, unsigned char attr)
68{
69 RMREGS r;
70
71 r.x.ax = 0x0600;
72 r.h.bh = attr;
73 r.h.cl = startx;
74 r.h.ch = starty;
75 r.h.dl = endx;
76 r.h.dh = endy;
77 PM_int86(0x10, &r, &r);
78}
79
80/* Routine to fill a rectangular region on the display using direct
81 * video writes.
82 */
83
84#define SCREEN(x,y) (videoPtr + ((y) * 160) + ((x) << 1))
85
86void fill(int startx, int starty, int endx, int endy, unsigned char c,
87 unsigned char attr)
88{
89 unsigned char *v;
90 int x,y;
91
92 for (y = starty; y <= endy; y++) {
8bde7f77
WD
93 v = SCREEN(startx,y);
94 for (x = startx; x <= endx; x++) {
95 *v++ = c;
96 *v++ = attr;
97 }
98 }
c7de829c
WD
99}
100
101/* Routine to display a single character using direct video writes */
102
103void writeChar(int x, int y, unsigned char c, unsigned char attr)
104{
105 unsigned char *v = SCREEN(x,y);
106 *v++ = c;
107 *v = attr;
108}
109
110/* Routine to draw a border around a rectangular area using direct video
111 * writes.
112 */
113
114static unsigned char border_chars[] = {
115 186, 205, 201, 187, 200, 188 /* double box chars */
116 };
117
118void border(int startx, int starty, int endx, int endy, unsigned char attr)
119{
120 unsigned char *v;
121 unsigned char *b;
122 int i;
123
124 b = border_chars;
125
126 for (i = starty+1; i < endy; i++) {
8bde7f77
WD
127 writeChar(startx, i, *b, attr);
128 writeChar(endx, i, *b, attr);
129 }
c7de829c
WD
130 b++;
131 for (i = startx+1, v = SCREEN(startx+1, starty); i < endx; i++) {
8bde7f77
WD
132 *v++ = *b;
133 *v++ = attr;
134 }
c7de829c 135 for (i = startx+1, v = SCREEN(startx+1, endy); i < endx; i++) {
8bde7f77
WD
136 *v++ = *b;
137 *v++ = attr;
138 }
c7de829c
WD
139 b++;
140 writeChar(startx, starty, *b++, attr);
141 writeChar(endx, starty, *b++, attr);
142 writeChar(startx, endy, *b++, attr);
143 writeChar(endx, endy, *b++, attr);
144}
145
146int main(void)
147{
148 int orgMode;
149 PM_HWND hwndConsole;
150
151 printf("Program running in ");
152 switch (PM_getModeType()) {
8bde7f77
WD
153 case PM_realMode:
154 printf("real mode.\n\n");
155 break;
156 case PM_286:
157 printf("16 bit protected mode.\n\n");
158 break;
159 case PM_386:
160 printf("32 bit protected mode.\n\n");
161 break;
162 }
c7de829c
WD
163
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");
166 PM_getch();
167
168 /* Allocate a buffer to save console state and save the state */
169 if ((stateBuf = PM_malloc(PM_getConsoleStateSize())) == NULL) {
8bde7f77
WD
170 printf("Unable to allocate console state buffer!\n");
171 exit(1);
172 }
c7de829c
WD
173 PM_saveConsoleState(stateBuf,0);
174 bios = PM_getBIOSPointer();
175 orgMode = getVideoMode();
176 setVideoMode(0x3);
177 if ((videoPtr = PM_mapPhysicalAddr(0xB8000,0xFFFF,true)) == NULL) {
8bde7f77
WD
178 printf("Unable to obtain pointer to framebuffer!\n");
179 exit(1);
180 }
c7de829c
WD
181
182 /* Draw some text on the screen */
183 fill(0, 0, 79, 24, 176, 0x1E);
184 border(0, 0, 79, 24, 0x1F);
185 PM_getch();
186 clearScreen(0, 0, 79, 24, 0x7);
187
188 /* Restore the console state on exit */
189 PM_restoreConsoleState(stateBuf,0);
190 PM_free(stateBuf);
191 PM_closeConsole(hwndConsole);
192
193 /* Display useful status information */
194 printf("\n");
195 printf("Original Video Mode = %02X\n", orgMode);
196 printf("BIOS Pointer = %08X\n", (int)bios);
197 printf("Video Memory = %08X\n", (int)videoPtr);
198 return 0;
199}