Home | Info | Community | Development | myReactOS | Contact Us
ReactOS Development > Doxygenbootvid.c
Go to the documentation of this file.
00001 #include "precomp.h" 00002 #define NDEBUG 00003 #include "debug.h" 00004 00005 #define LCDTIMING0_PPL(x) ((((x) / 16 - 1) & 0x3f) << 2) 00006 #define LCDTIMING1_LPP(x) (((x) & 0x3ff) - 1) 00007 #define LCDCONTROL_LCDPWR (1 << 11) 00008 #define LCDCONTROL_LCDEN (1) 00009 #define LCDCONTROL_LCDBPP(x) (((x) & 7) << 1) 00010 #define LCDCONTROL_LCDTFT (1 << 5) 00011 00012 #define PL110_LCDTIMING0 (PVOID)0xE0020000 00013 #define PL110_LCDTIMING1 (PVOID)0xE0020004 00014 #define PL110_LCDTIMING2 (PVOID)0xE0020008 00015 #define PL110_LCDUPBASE (PVOID)0xE0020010 00016 #define PL110_LCDLPBASE (PVOID)0xE0020014 00017 #define PL110_LCDCONTROL (PVOID)0xE0020018 00018 00019 #define READ_REGISTER_ULONG(r) (*(volatile ULONG * const)(r)) 00020 #define WRITE_REGISTER_ULONG(r, v) (*(volatile ULONG *)(r) = (v)) 00021 00022 #define READ_REGISTER_USHORT(r) (*(volatile USHORT * const)(r)) 00023 #define WRITE_REGISTER_USHORT(r, v) (*(volatile USHORT *)(r) = (v)) 00024 00025 PUSHORT VgaArmBase; 00026 PHYSICAL_ADDRESS VgaPhysical; 00027 BOOLEAN NextLine = FALSE; 00028 UCHAR VidpTextColor = 0xF; 00029 ULONG VidpCurrentX = 0; 00030 ULONG VidpCurrentY = 0; 00031 ULONG VidpScrollRegion[4] = 00032 { 00033 0, 00034 0, 00035 640 - 1, 00036 480 - 1 00037 }; 00038 00039 typedef struct _VGA_COLOR 00040 { 00041 UCHAR Red; 00042 UCHAR Green; 00043 UCHAR Blue; 00044 } VGA_COLOR; 00045 00046 VGA_COLOR VidpVga8To16BitTransform[16] = 00047 { 00048 {0x00, 0x00, 0x00}, // Black 00049 {0x00, 0x00, 0x08}, // Blue 00050 {0x00, 0x08, 0x00}, // Green 00051 {0x00, 0x08, 0x08}, // Cyan 00052 {0x08, 0x00, 0x00}, // Red 00053 {0x08, 0x00, 0x08}, // Magenta 00054 {0x0B, 0x0D, 0x0F}, // Brown 00055 {0x10, 0x10, 0x10}, // Light Gray 00056 {0x08, 0x08, 0x08}, // Dark Gray 00057 {0x00, 0x00, 0x1F}, // Light Blue 00058 {0x00, 0x1F, 0x00}, // Light Green 00059 {0x00, 0x1F, 0x1F}, // Light Cyan 00060 {0x1F, 0x00, 0x00}, // Light Red 00061 {0x1F, 0x00, 0x1F}, // Light Magenta 00062 {0x1F, 0x1F, 0x00}, // Yellow 00063 {0x1F, 0x1F, 0x1F}, // White 00064 }; 00065 00066 /* PRIVATE FUNCTIONS *********************************************************/ 00067 00068 USHORT 00069 FORCEINLINE 00070 VidpBuildColor(IN UCHAR Color) 00071 { 00072 UCHAR Red, Green, Blue; 00073 00074 // 00075 // Extract color components 00076 // 00077 Red = VidpVga8To16BitTransform[Color].Red; 00078 Green = VidpVga8To16BitTransform[Color].Green; 00079 Blue = VidpVga8To16BitTransform[Color].Blue; 00080 00081 // 00082 // Build the 16-bit color mask 00083 // 00084 return ((Red & 0x1F) << 11) | ((Green & 0x1F) << 6) | ((Blue & 0x1F)); 00085 } 00086 00087 00088 VOID 00089 FORCEINLINE 00090 VidpSetPixel(IN ULONG Left, 00091 IN ULONG Top, 00092 IN UCHAR Color) 00093 { 00094 PUSHORT PixelPosition; 00095 00096 // 00097 // Calculate the pixel position 00098 // 00099 PixelPosition = &VgaArmBase[Left + (Top * 640)]; 00100 00101 // 00102 // Set our color 00103 // 00104 WRITE_REGISTER_USHORT(PixelPosition, VidpBuildColor(Color)); 00105 } 00106 00107 VOID 00108 NTAPI 00109 DisplayCharacter(CHAR Character, 00110 ULONG Left, 00111 ULONG Top, 00112 ULONG TextColor, 00113 ULONG BackTextColor) 00114 { 00115 PUCHAR FontChar; 00116 ULONG i, j, XOffset; 00117 00118 /* Get the font line for this character */ 00119 FontChar = &FontData[Character * 13 - Top]; 00120 00121 /* Loop each pixel height */ 00122 i = 13; 00123 do 00124 { 00125 /* Loop each pixel width */ 00126 j = 128; 00127 XOffset = Left; 00128 do 00129 { 00130 /* Check if we should draw this pixel */ 00131 if (FontChar[Top] & (UCHAR)j) 00132 { 00133 /* We do, use the given Text Color */ 00134 VidpSetPixel(XOffset, Top, (UCHAR)TextColor); 00135 } 00136 else if (BackTextColor < 16) 00137 { 00138 /* This is a background pixel. We're drawing it unless it's */ 00139 /* transparent. */ 00140 VidpSetPixel(XOffset, Top, (UCHAR)BackTextColor); 00141 } 00142 00143 /* Increase X Offset */ 00144 XOffset++; 00145 } while (j >>= 1); 00146 00147 /* Move to the next Y ordinate */ 00148 Top++; 00149 } while (--i); 00150 } 00151 00152 VOID 00153 NTAPI 00154 VgaScroll(ULONG Scroll) 00155 { 00156 ULONG Top, Offset; 00157 PUSHORT SourceOffset, DestOffset; 00158 PUSHORT i, j; 00159 00160 /* Set memory positions of the scroll */ 00161 SourceOffset = &VgaArmBase[(VidpScrollRegion[1] * 80) + (VidpScrollRegion[0] >> 3)]; 00162 DestOffset = &SourceOffset[Scroll * 80]; 00163 00164 /* Save top and check if it's above the bottom */ 00165 Top = VidpScrollRegion[1]; 00166 if (Top > VidpScrollRegion[3]) return; 00167 00168 /* Start loop */ 00169 do 00170 { 00171 /* Set number of bytes to loop and start offset */ 00172 Offset = VidpScrollRegion[0] >> 3; 00173 j = SourceOffset; 00174 00175 /* Check if this is part of the scroll region */ 00176 if (Offset <= (VidpScrollRegion[2] >> 3)) 00177 { 00178 /* Update position */ 00179 i = (PUSHORT)(DestOffset - SourceOffset); 00180 00181 /* Loop the X axis */ 00182 do 00183 { 00184 /* Write value in the new position so that we can do the scroll */ 00185 WRITE_REGISTER_USHORT(j, READ_REGISTER_USHORT(j + (ULONG_PTR)i)); 00186 00187 /* Move to the next memory location to write to */ 00188 j++; 00189 00190 /* Move to the next byte in the region */ 00191 Offset++; 00192 00193 /* Make sure we don't go past the scroll region */ 00194 } while (Offset <= (VidpScrollRegion[2] >> 3)); 00195 } 00196 00197 /* Move to the next line */ 00198 SourceOffset += 80; 00199 DestOffset += 80; 00200 00201 /* Increase top */ 00202 Top++; 00203 00204 /* Make sure we don't go past the scroll region */ 00205 } while (Top <= VidpScrollRegion[3]); 00206 } 00207 00208 VOID 00209 NTAPI 00210 PreserveRow(IN ULONG CurrentTop, 00211 IN ULONG TopDelta, 00212 IN BOOLEAN Direction) 00213 { 00214 PUSHORT Position1, Position2; 00215 ULONG Count; 00216 00217 /* Check which way we're preserving */ 00218 if (Direction) 00219 { 00220 /* Calculate the position in memory for the row */ 00221 Position1 = &VgaArmBase[CurrentTop * 80]; 00222 Position2 = &VgaArmBase[0x9600]; 00223 } 00224 else 00225 { 00226 /* Calculate the position in memory for the row */ 00227 Position1 = &VgaArmBase[0x9600]; 00228 Position2 = &VgaArmBase[CurrentTop * 80]; 00229 } 00230 00231 /* Set the count and make sure it's above 0 */ 00232 Count = TopDelta * 80; 00233 if (Count) 00234 { 00235 /* Loop every pixel */ 00236 do 00237 { 00238 /* Write the data back on the other position */ 00239 WRITE_REGISTER_USHORT(Position1, READ_REGISTER_USHORT(Position2)); 00240 00241 /* Increase both positions */ 00242 Position2++; 00243 Position1++; 00244 } while (--Count); 00245 } 00246 } 00247 00248 VOID 00249 NTAPI 00250 VidpInitializeDisplay(VOID) 00251 { 00252 // 00253 // Set framebuffer address 00254 // 00255 WRITE_REGISTER_ULONG(PL110_LCDUPBASE, VgaPhysical.LowPart); 00256 WRITE_REGISTER_ULONG(PL110_LCDLPBASE, VgaPhysical.LowPart); 00257 00258 // 00259 // Initialize timings to 640x480 00260 // 00261 WRITE_REGISTER_ULONG(PL110_LCDTIMING0, LCDTIMING0_PPL(640)); 00262 WRITE_REGISTER_ULONG(PL110_LCDTIMING1, LCDTIMING1_LPP(480)); 00263 00264 // 00265 // Enable the LCD Display 00266 // 00267 WRITE_REGISTER_ULONG(PL110_LCDCONTROL, 00268 LCDCONTROL_LCDEN | 00269 LCDCONTROL_LCDTFT | 00270 LCDCONTROL_LCDPWR | 00271 LCDCONTROL_LCDBPP(4)); 00272 } 00273 00274 /* PUBLIC FUNCTIONS **********************************************************/ 00275 00276 /* 00277 * @implemented 00278 */ 00279 BOOLEAN 00280 NTAPI 00281 VidInitialize(IN BOOLEAN SetMode) 00282 { 00283 DPRINT1("bv-arm v0.1\n"); 00284 00285 // 00286 // Allocate framebuffer 00287 // 600kb works out to 640x480@16bpp 00288 // 00289 VgaPhysical.QuadPart = -1; 00290 VgaArmBase = MmAllocateContiguousMemory(600 * 1024, VgaPhysical); 00291 if (!VgaArmBase) return FALSE; 00292 00293 // 00294 // Get physical address 00295 // 00296 VgaPhysical = MmGetPhysicalAddress(VgaArmBase); 00297 if (!VgaPhysical.QuadPart) return FALSE; 00298 DPRINT1("[BV-ARM] Frame Buffer @ 0x%p 0p%p\n", VgaArmBase, VgaPhysical.LowPart); 00299 00300 // 00301 // Setup the display 00302 // 00303 VidpInitializeDisplay(); 00304 00305 // 00306 // We are done! 00307 // 00308 return TRUE; 00309 } 00310 00311 /* 00312 * @implemented 00313 */ 00314 VOID 00315 NTAPI 00316 VidResetDisplay(IN BOOLEAN HalReset) 00317 { 00318 // 00319 // Clear the current position 00320 // 00321 VidpCurrentX = 0; 00322 VidpCurrentY = 0; 00323 00324 // 00325 // Re-initialize the VGA Display 00326 // 00327 VidpInitializeDisplay(); 00328 00329 // 00330 // Re-initialize the palette and fill the screen black 00331 // 00332 //InitializePalette(); 00333 VidSolidColorFill(0, 0, 639, 479, 0); 00334 } 00335 00336 /* 00337 * @implemented 00338 */ 00339 ULONG 00340 NTAPI 00341 VidSetTextColor(ULONG Color) 00342 { 00343 UCHAR OldColor; 00344 00345 // 00346 // Save the old, set the new 00347 // 00348 OldColor = VidpTextColor; 00349 VidpTextColor = Color; 00350 00351 // 00352 // Return the old text color 00353 // 00354 return OldColor; 00355 } 00356 00357 /* 00358 * @implemented 00359 */ 00360 VOID 00361 NTAPI 00362 VidDisplayStringXY(PUCHAR String, 00363 ULONG Left, 00364 ULONG Top, 00365 BOOLEAN Transparent) 00366 { 00367 UNIMPLEMENTED; 00368 while (TRUE); 00369 } 00370 00371 /* 00372 * @implemented 00373 */ 00374 VOID 00375 NTAPI 00376 VidSetScrollRegion(ULONG x1, 00377 ULONG y1, 00378 ULONG x2, 00379 ULONG y2) 00380 { 00381 /* Assert alignment */ 00382 ASSERT((x1 & 0x7) == 0); 00383 ASSERT((x2 & 0x7) == 7); 00384 00385 /* Set Scroll Region */ 00386 VidpScrollRegion[0] = x1; 00387 VidpScrollRegion[1] = y1; 00388 VidpScrollRegion[2] = x2; 00389 VidpScrollRegion[3] = y2; 00390 00391 /* Set current X and Y */ 00392 VidpCurrentX = x1; 00393 VidpCurrentY = y1; 00394 } 00395 00396 /* 00397 * @implemented 00398 */ 00399 VOID 00400 NTAPI 00401 VidCleanUp(VOID) 00402 { 00403 UNIMPLEMENTED; 00404 while (TRUE); 00405 } 00406 00407 /* 00408 * @implemented 00409 */ 00410 VOID 00411 NTAPI 00412 VidBufferToScreenBlt(IN PUCHAR Buffer, 00413 IN ULONG Left, 00414 IN ULONG Top, 00415 IN ULONG Width, 00416 IN ULONG Height, 00417 IN ULONG Delta) 00418 { 00419 UNIMPLEMENTED; 00420 while (TRUE); 00421 } 00422 00423 /* 00424 * @implemented 00425 */ 00426 VOID 00427 NTAPI 00428 VidDisplayString(PUCHAR String) 00429 { 00430 ULONG TopDelta = 14; 00431 00432 /* Start looping the string */ 00433 while (*String) 00434 { 00435 /* Treat new-line separately */ 00436 if (*String == '\n') 00437 { 00438 /* Modify Y position */ 00439 VidpCurrentY += TopDelta; 00440 if (VidpCurrentY >= VidpScrollRegion[3]) 00441 { 00442 /* Scroll the view */ 00443 VgaScroll(TopDelta); 00444 VidpCurrentY -= TopDelta; 00445 00446 /* Preserve row */ 00447 PreserveRow(VidpCurrentY, TopDelta, TRUE); 00448 } 00449 00450 /* Update current X */ 00451 VidpCurrentX = VidpScrollRegion[0]; 00452 00453 /* Preseve the current row */ 00454 PreserveRow(VidpCurrentY, TopDelta, FALSE); 00455 } 00456 else if (*String == '\r') 00457 { 00458 /* Update current X */ 00459 VidpCurrentX = VidpScrollRegion[0]; 00460 00461 /* Check if we're being followed by a new line */ 00462 if (String[1] != '\n') NextLine = TRUE; 00463 } 00464 else 00465 { 00466 /* Check if we had a \n\r last time */ 00467 if (NextLine) 00468 { 00469 /* We did, preserve the current row */ 00470 PreserveRow(VidpCurrentY, TopDelta, TRUE); 00471 NextLine = FALSE; 00472 } 00473 00474 /* Display this character */ 00475 DisplayCharacter(*String, 00476 VidpCurrentX, 00477 VidpCurrentY, 00478 VidpTextColor, 00479 16); 00480 VidpCurrentX += 8; 00481 00482 /* Check if we should scroll */ 00483 if (VidpCurrentX > VidpScrollRegion[2]) 00484 { 00485 /* Update Y position and check if we should scroll it */ 00486 VidpCurrentY += TopDelta; 00487 if (VidpCurrentY > VidpScrollRegion[3]) 00488 { 00489 /* Do the scroll */ 00490 VgaScroll(TopDelta); 00491 VidpCurrentY -= TopDelta; 00492 00493 /* Save the row */ 00494 PreserveRow(VidpCurrentY, TopDelta, TRUE); 00495 } 00496 00497 /* Update X */ 00498 VidpCurrentX = VidpScrollRegion[0]; 00499 } 00500 } 00501 00502 /* Get the next character */ 00503 String++; 00504 } 00505 } 00506 00507 /* 00508 * @implemented 00509 */ 00510 VOID 00511 NTAPI 00512 VidBitBlt(PUCHAR Buffer, 00513 ULONG Left, 00514 ULONG Top) 00515 { 00516 UNIMPLEMENTED; 00517 //while (TRUE); 00518 } 00519 00520 /* 00521 * @implemented 00522 */ 00523 VOID 00524 NTAPI 00525 VidScreenToBufferBlt(PUCHAR Buffer, 00526 ULONG Left, 00527 ULONG Top, 00528 ULONG Width, 00529 ULONG Height, 00530 ULONG Delta) 00531 { 00532 UNIMPLEMENTED; 00533 while (TRUE); 00534 } 00535 00536 /* 00537 * @implemented 00538 */ 00539 VOID 00540 NTAPI 00541 VidSolidColorFill(IN ULONG Left, 00542 IN ULONG Top, 00543 IN ULONG Right, 00544 IN ULONG Bottom, 00545 IN UCHAR Color) 00546 { 00547 int y, x; 00548 00549 // 00550 // Loop along the Y-axis 00551 // 00552 for (y = Top; y <= Bottom; y++) 00553 { 00554 // 00555 // Loop along the X-axis 00556 // 00557 for (x = Left; x <= Right; x++) 00558 { 00559 // 00560 // Draw the pixel 00561 // 00562 VidpSetPixel(x, y, Color); 00563 } 00564 } 00565 } Generated on Sun May 27 2012 04:27:12 for ReactOS by
1.7.6.1
|