UbixOS V2 2.0

ogDisplay_UbixOS.cc
Go to the documentation of this file.
1 /*-
2 * Copyright (c) 2002-2018 The UbixOS Project.
3 * All rights reserved.
4 *
5 * This was developed by Christopher W. Olsen for the UbixOS Project.
6 *
7 * Redistribution and use in source and binary forms, with or without modification, are permitted
8 * provided that the following conditions are met:
9 *
10 * 1) Redistributions of source code must retain the above copyright notice, this list of
11 * conditions, the following disclaimer and the list of authors.
12 * 2) Redistributions in binary form must reproduce the above copyright notice, this list of
13 * conditions, the following disclaimer and the list of authors in the documentation and/or
14 * other materials provided with the distribution.
15 * 3) Neither the name of the UbixOS Project nor the names of its contributors may be used to
16 * endorse or promote products derived from this software without specific prior written
17 * permission.
18 *
19 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED
20 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
21 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
22 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
23 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
24 * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
25 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
26 * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 */
28
29 #include <objgfx40/objgfx40.h>
30 #include <objgfx40/defpal.inc>
31 #include <sde/ogDisplay_UbixOS.h>
32
33 extern "C" {
34 #include <vmm/vmm.h>
35 #include <lib/kprintf.h>
36 #include <lib/bioscall.h>
37 #include <ubixos/kpanic.h>
38 #include <sys/io.h>
39 }
40
41 /*
42 *
43 * ogDisplay methods
44 *
45 */
46
47 void initVESAMode(uint16_t mode) {
48 biosCall(0x10, 0x4F02, mode, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0);
49 return;
50 }
51
52 ogDisplay_UbixOS::ogDisplay_UbixOS(void) {
53 pages[0] = pages[1] = NULL;
54 activePage = visualPage = 0;
55 pal = new ogRGBA8[256];
56 attributes = new ogAttributes();
57
58 VESAInfo = (ogVESAInfo *) 0x11000;
59 modeInfo = (ogModeInfo *) 0x11200;
60
61 GetVESAInfo();
62 return;
63 } // ogDisplay_UbixOS::ogDisplay_UbixOS
64
65 void ogDisplay_UbixOS::GetModeInfo(uint16_t mode) {
66 biosCall(0x10, 0x4F01, 0x0, mode, 0x0, 0x0, 0x0, 0x1120, 0x0);
67 return;
68 } // ogDisplay_UbixOS::GetModeInfo
69
70 void ogDisplay_UbixOS::GetVESAInfo(void) {
71 VESAInfo->VBESignature[0] = 'V'; // First off initialize the structure.
72 VESAInfo->VBESignature[1] = 'B';
73 VESAInfo->VBESignature[2] = 'E';
74 VESAInfo->VBESignature[3] = '2';
75 biosCall(0x10, 0x4F00, 0x0, 0x0, 0x0, 0x0, 0x0, 0x1100, 0x0);
76 return;
77 } // ogDisplay_UbixOS::GetVESAInfo
78
79 uint16_t ogDisplay_UbixOS::FindMode(uint32_t _xRes, uint32_t _yRes, uint32_t _BPP) {
80 uint16_t mode;
81
82 if ((_xRes == 320) && (_yRes == 200) && (_BPP == 8))
83 return 0x13;
84
85 // if ((VESAInfo==NULL) || (VESAInfo->videoModePtr==NULL)) return 0;
86
87 if (modeInfo == NULL)
88 return 0;
89
90 for (mode = 0x100; mode < 0x1FF; mode++) {
91 GetModeInfo(mode);
92 if ((modeInfo->xRes >= _xRes) && (modeInfo->yRes >= _yRes) && (modeInfo->bitsPerPixel == _BPP))
93 return mode;
94 }
95
96 return 0;
97 } // ogDisplay_UbixOS::FindMode
98
99 void ogDisplay_UbixOS::SetMode(uint16_t mode) {
100
101 uint32_t size = 0x0, count = 0x0, i = 0x0;
102
103 if (mode == 0x13) {
104
105 xRes = 320;
106 yRes = 200;
107 maxX = 319;
108 maxY = 199;
109 BPP = 8;
110 bytesPerPix = 1;
111
112 redFieldPosition = 0;
113 greenFieldPosition = 0;
114 blueFieldPosition = 0;
115 alphaFieldPosition = 0;
116
117 redShifter = 0;
118 greenShifter = 0;
119 blueShifter = 0;
120 alphaFieldPosition = 0;
121
122 // UBU, THIS IS NULL BECAUSE WE DON'T EVER USE 320x200x256c!
123 // THIS COMMENT WILL COME BACK TO BITE YOU ON THE ASS
124 buffer = NULL;
125
126 }
127 else {
128 buffer = NULL;
129 mode |= 0x4000; // attempt lfb
130 GetModeInfo(mode);
131 if (modeInfo->physBasePtr == 0)
132 return;
133 buffer = (void *) modeInfo->physBasePtr;
134 size = (modeInfo->yRes * modeInfo->bytesPerLine + 4095);
135
136 xRes = modeInfo->bytesPerLine;
137 yRes = modeInfo->yRes;
138 maxX = modeInfo->xRes - 1;
139 maxY = yRes - 1;
140
141 BPP = modeInfo->bitsPerPixel;
142 bytesPerPix = (BPP + 7) >> 3;
143
144 redFieldPosition = modeInfo->redFieldPosition;
145 greenFieldPosition = modeInfo->greenFieldPosition;
146 blueFieldPosition = modeInfo->blueFieldPosition;
147 alphaFieldPosition = modeInfo->alphaFieldPosition;
148
149 if (bytesPerPix == 4) {
150 modeInfo->alphaMaskSize = 8;
151 while ((alphaFieldPosition == redFieldPosition) || (alphaFieldPosition == greenFieldPosition) || (alphaFieldPosition == blueFieldPosition))
152 alphaFieldPosition += 8;
153 } // if
154
155 redShifter = 8 - modeInfo->redMaskSize;
156 greenShifter = 8 - modeInfo->greenMaskSize;
157 blueShifter = 8 - modeInfo->blueMaskSize;
158 alphaShifter = 8 - modeInfo->alphaMaskSize;
159
160 if (modeInfo->alphaMaskSize != 0)
161 alphaMasker = ~(OG_MASKS[modeInfo->alphaMaskSize] << alphaFieldPosition);
162 else
163 alphaMasker = ~0;
164
165 } // else not mode 0x13
166
167 printOff = 0;
168 for (i = 0x0; i < ((size) / 4096); i++) {
169 if ((vmm_remapPage(modeInfo->physBasePtr + (i * 0x1000), modeInfo->physBasePtr + (i * 0x1000), KERNEL_PAGE_DEFAULT, -2, 0)) == 0x0)
170 kpanic("Error: vmm_remapPage failed\n");
171 } // for i
172
173 owner = this;
174 dataState = ogAliasing;
175
176 initVESAMode(mode);
177
178 if ((lineOfs != NULL) && (lSize != 0))
179 delete[] lineOfs;
180 lSize = yRes * sizeof(uint32_t);
181 lineOfs = new uint32_t[yRes];
182 ;
183 if (lineOfs == NULL)
184 return;
185
186 lineOfs[0] = 0;
187 for (count = 1; count < yRes; count++)
188 lineOfs[count] = lineOfs[count - 1] + xRes;
189
190 if (1 == bytesPerPix) {
191 pixFmtID = 0x08080808;
192 }
193 else {
194 pixFmtID = (redFieldPosition) | (greenFieldPosition << 8) | (blueFieldPosition << 16) | (alphaFieldPosition << 24);
195 } // else
196
197 ogSetAntiAliasing(BPP > 8);
198 if (pal == NULL)
199 pal = new ogRGBA8[256];
200 ogSetPalette(DEFAULT_PALETTE);
201
202 return;
203 } // ogDisplay_UbixOS::SetMode
204
205 void ogDisplay_UbixOS::ogSetPalette(const ogRGBA8 newPal[256]) {
206 ogSurface::ogSetPalette(newPal);
207 SetPal();
208 return;
209 } // ogDisplay_UbixOS::ogSetPalette
210
211 void ogDisplay_UbixOS::SetPal(void) {
212 if (bytesPerPix != 1)
213 return;
214 outportByte(0x3c8, 0);
215 for (uint32_t c = 0; c < 256; c++) {
216 outportByte(0x3c9, pal[c].red >> 2);
217 outportByte(0x3c9, pal[c].green >> 2);
218 outportByte(0x3c9, pal[c].blue >> 2);
219 } // for
220 return;
221 } // ogDisplay_UbixOS::SetPal
222
223 bool ogDisplay_UbixOS::ogAlias(ogSurface& SrcObject, uint32_t x1, uint32_t y1, uint32_t x2, uint32_t y2) {
224 ogSetLastError(ogNoAliasing);
225 return false;
226 } // ogDisplay_UbixOS::ogAlias
227
228 bool ogDisplay_UbixOS::ogCreate(uint32_t _xRes, uint32_t _yRes, ogPixelFmt _pixFormat) {
229 uint16_t mode;
230
231 //mode = 0x114; // was 0x111
232 //SetMode(mode);
233
234 mode = FindMode(_xRes, _yRes, _pixFormat.BPP);
235 if ((mode == 0) && ((_pixFormat.BPP == 24) || (_pixFormat.BPP == 32))) {
236 if (_pixFormat.BPP == 24)
237 _pixFormat.BPP = 32;
238 else
239 _pixFormat.BPP = 24;
240 mode = FindMode(_xRes, _yRes, _pixFormat.BPP);
241 } // if
242 if (mode != 0)
243 SetMode(mode);
244
245 return (mode != 0);
246 } // ogDisplay_UbixOS::ogCreate
247
248 bool ogDisplay_UbixOS::ogClone(ogSurface& SrcObject) {
249 ogSetLastError(ogNoCloning);
250 return false;
251 } // ogDisplay_UbixOS::ogClone
252
253 void ogDisplay_UbixOS::ogCopyPalette(ogSurface& SrcObject) {
254 ogSurface::ogCopyPalette(SrcObject);
255 SetPal();
256 return;
257 } // ogDisplay_UbixOS::ogCopyPalette
258
259 bool ogDisplay_UbixOS::ogLoadPalette(const char *palfile) {
260 bool result;
261 if ((result = ogSurface::ogLoadPalette(palfile)) == true)
262 SetPal();
263 return result;
264 } // ogDisplay_UbixOS::ogLoadPalette
265
266 void ogDisplay_UbixOS::ogSetPalette(uInt8 colour, uInt8 red, uInt8 green, uInt8 blue) {
267 if (pal == NULL)
268 return;
269 ogSurface::ogSetPalette(colour, red, green, blue);
270 outportByte(0x3c8, colour);
271 outportByte(0x3c9, red >> 2);
272 outportByte(0x3c9, green >> 2);
273 outportByte(0x3c9, blue >> 2);
274
275 return;
276 } // ogDisplay_UbixOS::ogSetPalette
277
278 void ogDisplay_UbixOS::ogSetPalette(uInt8 colour, uInt8 red, uInt8 green, uInt8 blue, uInt8 alpha) {
279 if (pal == NULL)
280 return;
281
282 ogSurface::ogSetPalette(colour, red, green, blue, alpha);
283 outportByte(0x3c8, colour);
284 outportByte(0x3c9, red >> 2);
285 outportByte(0x3c9, green >> 2);
286 outportByte(0x3c9, blue >> 2);
287
288 return;
289 } // ogDisplay_UbixOS::ogSetPalette
290
291 ogDisplay_UbixOS::~ogDisplay_UbixOS(void) {
292 delete attributes;
293 delete pal;
294 //mji delete VESAInfo;
295 //mji delete modeInfo;
296 return;
297 } // ogDisplay_UbixOS::~ogDisplay_UbixOS
ogModeInfo
Definition: ogDisplay_UbixOS.h:35
initVESAMode
void initVESAMode(uint16_t mode)
Definition: ogDisplay_UbixOS.cc:47
buffer
char * buffer
Definition: shell.c:47
ogDisplay_UbixOS.h
outportByte
void outportByte(unsigned int, unsigned char)
outputut one byte to specified port
Definition: io.c:72
vmm.h
ogDisplay_UbixOS::SetMode
void SetMode(uint16_t)
Definition: ogDisplay_UbixOS.cc:99
kpanic
void kpanic(const char *fmt,...)
print panic message and halt system
Definition: kpanic.c:41
ogDisplay_UbixOS::ogLoadPalette
virtual bool ogLoadPalette(const char *)
Definition: ogDisplay_UbixOS.cc:259
biosCall
void biosCall(int biosInt, int eax, int ebx, int ecx, int edx, int esi, int edi, int es, int ds)
Definition: bioscall.c:49
ogDisplay_UbixOS::GetVESAInfo
void GetVESAInfo(void)
Definition: ogDisplay_UbixOS.cc:70
ogDisplay_UbixOS::~ogDisplay_UbixOS
virtual ~ogDisplay_UbixOS(void)
Definition: ogDisplay_UbixOS.cc:291
ogVESAInfo
Definition: ogDisplay_UbixOS.h:73
uint16_t
__uint16_t uint16_t
Definition: types.h:45
kpanic.h
ogDisplay_UbixOS::ogCopyPalette
virtual void ogCopyPalette(ogSurface &)
Definition: ogDisplay_UbixOS.cc:253
ogDisplay_UbixOS::activePage
uint32_t activePage
Definition: ogDisplay_UbixOS.h:92
kprintf.h
uInt8
unsigned char uInt8
Definition: objgfx30.h:47
ogDisplay_UbixOS::ogAlias
virtual bool ogAlias(ogSurface &, uint32_t, uint32_t, uint32_t, uint32_t)
Definition: ogDisplay_UbixOS.cc:223
ogDisplay_UbixOS::visualPage
uint32_t visualPage
Definition: ogDisplay_UbixOS.h:93
vmm_remapPage
int vmm_remapPage(uint32_t, uint32_t, uint16_t, pidType, int haveLock)
Definition: paging.c:199
uint32_t
__uint32_t uint32_t
Definition: types.h:46
ogDisplay_UbixOS::ogSetPalette
virtual void ogSetPalette(const ogRGBA8[])
ogDisplay_UbixOS::SetPal
void SetPal(void)
Definition: ogDisplay_UbixOS.cc:211
ogDisplay_UbixOS::ogClone
virtual bool ogClone(ogSurface &)
Definition: ogDisplay_UbixOS.cc:248
ogDisplay_UbixOS::pages
void * pages[2]
Definition: ogDisplay_UbixOS.h:91
io.h
ogDisplay_UbixOS::FindMode
uint16_t FindMode(uint32_t, uint32_t, uint32_t)
Definition: ogDisplay_UbixOS.cc:79
ogDisplay_UbixOS::VESAInfo
ogVESAInfo * VESAInfo
Definition: ogDisplay_UbixOS.h:94
ogDisplay_UbixOS::GetModeInfo
void GetModeInfo(uint16_t)
Definition: ogDisplay_UbixOS.cc:65
KERNEL_PAGE_DEFAULT
#define KERNEL_PAGE_DEFAULT
Definition: paging.h:69
ogDisplay_UbixOS::modeInfo
ogModeInfo * modeInfo
Definition: ogDisplay_UbixOS.h:95
printOff
int printOff
Definition: kprintf.c:256
bioscall.h
ogDisplay_UbixOS::ogCreate
virtual bool ogCreate(uint32_t, uint32_t, ogPixelFmt)
Definition: ogDisplay_UbixOS.cc:228
ogDisplay_UbixOS::ogDisplay_UbixOS
ogDisplay_UbixOS(void)
Definition: ogDisplay_UbixOS.cc:52
NULL
#define NULL
Definition: fat_string.h:17