From 1d2b0fbcd1e933ad403cb1e0a85c2758bc0c7c73 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Herm=C3=A8s=20B=C3=A9lusca-Ma=C3=AFto?= Date: Sun, 22 Dec 2019 14:09:43 +0100 Subject: [PATCH] [BOOTVID] Replace hardcoded screen and font size numbers by #define-d values. --- drivers/base/bootvid/arm/bootvid.c | 36 +++++++++--------- drivers/base/bootvid/i386/bootvid.c | 2 +- drivers/base/bootvid/i386/vga.c | 57 ++++++++++++++--------------- drivers/base/bootvid/precomp.h | 9 ++++- 4 files changed, 55 insertions(+), 49 deletions(-) diff --git a/drivers/base/bootvid/arm/bootvid.c b/drivers/base/bootvid/arm/bootvid.c index 16ba24c6a7a..5d6722fbf42 100644 --- a/drivers/base/bootvid/arm/bootvid.c +++ b/drivers/base/bootvid/arm/bootvid.c @@ -33,8 +33,8 @@ ULONG VidpScrollRegion[4] = { 0, 0, - 640 - 1, - 480 - 1 + SCREEN_WIDTH - 1, + SCREEN_HEIGHT - 1 }; typedef struct _VGA_COLOR @@ -97,7 +97,7 @@ VidpSetPixel(IN ULONG Left, // // Calculate the pixel position // - PixelPosition = &VgaArmBase[Left + (Top * 640)]; + PixelPosition = &VgaArmBase[Left + (Top * SCREEN_WIDTH)]; // // Set our color @@ -117,10 +117,10 @@ DisplayCharacter(IN CHAR Character, ULONG i, j, XOffset; /* Get the font line for this character */ - FontChar = &FontData[Character * 13 - Top]; + FontChar = &FontData[Character * BOOTCHAR_HEIGHT - Top]; /* Loop each pixel height */ - i = 13; + i = BOOTCHAR_HEIGHT; do { /* Loop each pixel width */ @@ -159,8 +159,8 @@ VgaScroll(IN ULONG Scroll) PUSHORT i, j; /* Set memory positions of the scroll */ - SourceOffset = &VgaArmBase[(VidpScrollRegion[1] * 80) + (VidpScrollRegion[0] >> 3)]; - DestOffset = &SourceOffset[Scroll * 80]; + SourceOffset = &VgaArmBase[(VidpScrollRegion[1] * (SCREEN_WIDTH / 8)) + (VidpScrollRegion[0] >> 3)]; + DestOffset = &SourceOffset[Scroll * (SCREEN_WIDTH / 8)]; /* Save top and check if it's above the bottom */ Top = VidpScrollRegion[1]; @@ -196,8 +196,8 @@ VgaScroll(IN ULONG Scroll) } /* Move to the next line */ - SourceOffset += 80; - DestOffset += 80; + SourceOffset += (SCREEN_WIDTH / 8); + DestOffset += (SCREEN_WIDTH / 8); /* Increase top */ Top++; @@ -219,18 +219,18 @@ PreserveRow(IN ULONG CurrentTop, if (Direction) { /* Calculate the position in memory for the row */ - Position1 = &VgaArmBase[CurrentTop * 80]; - Position2 = &VgaArmBase[0x9600]; + Position1 = &VgaArmBase[CurrentTop * (SCREEN_WIDTH / 8)]; + Position2 = &VgaArmBase[SCREEN_HEIGHT * (SCREEN_WIDTH / 8)]; } else { /* Calculate the position in memory for the row */ - Position1 = &VgaArmBase[0x9600]; - Position2 = &VgaArmBase[CurrentTop * 80]; + Position1 = &VgaArmBase[SCREEN_HEIGHT * (SCREEN_WIDTH / 8)]; + Position2 = &VgaArmBase[CurrentTop * (SCREEN_WIDTH / 8)]; } /* Set the count and loop every pixel */ - Count = TopDelta * 80; + Count = TopDelta * (SCREEN_WIDTH / 8); while (Count--) { /* Write the data back on the other position */ @@ -255,8 +255,8 @@ VidpInitializeDisplay(VOID) // // Initialize timings to 640x480 // - WRITE_REGISTER_ULONG(PL110_LCDTIMING0, LCDTIMING0_PPL(640)); - WRITE_REGISTER_ULONG(PL110_LCDTIMING1, LCDTIMING1_LPP(480)); + WRITE_REGISTER_ULONG(PL110_LCDTIMING0, LCDTIMING0_PPL(SCREEN_WIDTH)); + WRITE_REGISTER_ULONG(PL110_LCDTIMING1, LCDTIMING1_LPP(SCREEN_HEIGHT)); // // Enable the LCD Display @@ -327,7 +327,7 @@ VidResetDisplay(IN BOOLEAN HalReset) // Re-initialize the palette and fill the screen black // //InitializePalette(); - VidSolidColorFill(0, 0, 639, 479, 0); + VidSolidColorFill(0, 0, SCREEN_WIDTH - 1, SCREEN_HEIGHT - 1, 0); } /* @@ -424,7 +424,7 @@ VOID NTAPI VidDisplayString(IN PUCHAR String) { - ULONG TopDelta = 14; + ULONG TopDelta = BOOTCHAR_HEIGHT + 1; /* Start looping the string */ while (*String) diff --git a/drivers/base/bootvid/i386/bootvid.c b/drivers/base/bootvid/i386/bootvid.c index db81548a1ba..afc3553e344 100644 --- a/drivers/base/bootvid/i386/bootvid.c +++ b/drivers/base/bootvid/i386/bootvid.c @@ -485,5 +485,5 @@ VidResetDisplay(IN BOOLEAN HalReset) /* Re-initialize the palette and fill the screen black */ InitializePalette(); - VidSolidColorFill(0, 0, 639, 479, 0); + VidSolidColorFill(0, 0, SCREEN_WIDTH - 1, SCREEN_HEIGHT - 1, 0); } diff --git a/drivers/base/bootvid/i386/vga.c b/drivers/base/bootvid/i386/vga.c index 382e825d7ac..c2398ac40eb 100644 --- a/drivers/base/bootvid/i386/vga.c +++ b/drivers/base/bootvid/i386/vga.c @@ -6,8 +6,8 @@ static ULONG ScrollRegion[4] = { 0, 0, - 640 - 1, - 480 - 1 + SCREEN_WIDTH - 1, + SCREEN_HEIGHT - 1 }; static UCHAR lMaskTable[8] = { @@ -97,7 +97,7 @@ SetPixel(IN ULONG Left, PUCHAR PixelPosition; /* Calculate the pixel position. */ - PixelPosition = (PUCHAR)(VgaBase + (Left >> 3) + (Top * 80)); + PixelPosition = (PUCHAR)(VgaBase + (Left >> 3) + (Top * (SCREEN_WIDTH / 8))); /* Select the bitmask register and write the mask */ __outpw(VGA_BASE_IO_PORT + GRAPH_ADDRESS_PORT, (PixelMask[Left & 7] << 8) | IND_BIT_MASK); @@ -149,14 +149,14 @@ DisplayCharacter(IN CHAR Character, /* Get the font and pixel pointer */ FontChar = GetFontPtr(Character); - PixelPtr = (PUCHAR)(VgaBase + (Left >> 3) + (Top * 80)); + PixelPtr = (PUCHAR)(VgaBase + (Left >> 3) + (Top * (SCREEN_WIDTH / 8))); /* Loop all pixel rows */ Height = BOOTCHAR_HEIGHT; do { SET_PIXELS(PixelPtr, *FontChar >> Shift, TextColor); - PixelPtr += 80; + PixelPtr += (SCREEN_WIDTH / 8); FontChar += FONT_PTR_DELTA; } while (--Height); @@ -168,14 +168,14 @@ DisplayCharacter(IN CHAR Character, /* Get the font and pixel pointer (2nd byte) */ FontChar = GetFontPtr(Character); - PixelPtr = (PUCHAR)(VgaBase + (Left >> 3) + (Top * 80) + 1); + PixelPtr = (PUCHAR)(VgaBase + (Left >> 3) + (Top * (SCREEN_WIDTH / 8)) + 1); /* Loop all pixel rows */ Height = BOOTCHAR_HEIGHT; do { SET_PIXELS(PixelPtr, *FontChar << Shift, TextColor); - PixelPtr += 80; + PixelPtr += (SCREEN_WIDTH / 8); FontChar += FONT_PTR_DELTA; } while (--Height); } @@ -192,14 +192,14 @@ DisplayCharacter(IN CHAR Character, /* Get the font and pixel pointer */ FontChar = GetFontPtr(Character); - PixelPtr = (PUCHAR)(VgaBase + (Left >> 3) + (Top * 80)); + PixelPtr = (PUCHAR)(VgaBase + (Left >> 3) + (Top * (SCREEN_WIDTH / 8))); /* Loop all pixel rows */ Height = BOOTCHAR_HEIGHT; do { SET_PIXELS(PixelPtr, ~*FontChar >> Shift, BackColor); - PixelPtr += 80; + PixelPtr += (SCREEN_WIDTH / 8); FontChar += FONT_PTR_DELTA; } while (--Height); @@ -211,14 +211,14 @@ DisplayCharacter(IN CHAR Character, /* Get the font and pixel pointer (2nd byte) */ FontChar = GetFontPtr(Character); - PixelPtr = (PUCHAR)(VgaBase + (Left >> 3) + (Top * 80) + 1); + PixelPtr = (PUCHAR)(VgaBase + (Left >> 3) + (Top * (SCREEN_WIDTH / 8)) + 1); /* Loop all pixel rows */ Height = BOOTCHAR_HEIGHT; do { SET_PIXELS(PixelPtr, ~*FontChar << Shift, BackColor); - PixelPtr += 80; + PixelPtr += (SCREEN_WIDTH / 8); FontChar += FONT_PTR_DELTA; } while (--Height); } @@ -335,8 +335,8 @@ VgaScroll(IN ULONG Scroll) RowSize = (ScrollRegion[2] - ScrollRegion[0] + 1) / 8; /* Calculate the position in memory for the row */ - OldPosition = (PUCHAR)(VgaBase + (ScrollRegion[1] + Scroll) * 80 + ScrollRegion[0] / 8); - NewPosition = (PUCHAR)(VgaBase + ScrollRegion[1] * 80 + ScrollRegion[0] / 8); + OldPosition = (PUCHAR)(VgaBase + (ScrollRegion[1] + Scroll) * (SCREEN_WIDTH / 8) + ScrollRegion[0] / 8); + NewPosition = (PUCHAR)(VgaBase + ScrollRegion[1] * (SCREEN_WIDTH / 8) + ScrollRegion[0] / 8); /* Start loop */ for (Top = ScrollRegion[1]; Top <= ScrollRegion[3]; ++Top) @@ -350,8 +350,8 @@ VgaScroll(IN ULONG Scroll) for (i = 0; i < RowSize; ++i) WRITE_REGISTER_UCHAR(NewPosition + i, READ_REGISTER_UCHAR(OldPosition + i)); #endif - OldPosition += 80; - NewPosition += 80; + OldPosition += (SCREEN_WIDTH / 8); + NewPosition += (SCREEN_WIDTH / 8); } } @@ -377,19 +377,18 @@ PreserveRow(IN ULONG CurrentTop, if (Direction) { /* Calculate the position in memory for the row */ - Position1 = (PUCHAR)(VgaBase + CurrentTop * 80); - Position2 = (PUCHAR)(VgaBase + 0x9600); + Position1 = (PUCHAR)(VgaBase + CurrentTop * (SCREEN_WIDTH / 8)); + Position2 = (PUCHAR)(VgaBase + SCREEN_HEIGHT * (SCREEN_WIDTH / 8)); } else { /* Calculate the position in memory for the row */ - Position1 = (PUCHAR)(VgaBase + 0x9600); - Position2 = (PUCHAR)(VgaBase + CurrentTop * 80); + Position1 = (PUCHAR)(VgaBase + SCREEN_HEIGHT * (SCREEN_WIDTH / 8)); + Position2 = (PUCHAR)(VgaBase + CurrentTop * (SCREEN_WIDTH / 8)); } /* Set the count and loop every pixel */ - Count = TopDelta * 80; - + Count = TopDelta * (SCREEN_WIDTH / 8); #if defined(_M_IX86) || defined(_M_AMD64) __movsb(Position1, Position2, Count); #else @@ -966,7 +965,7 @@ VidScreenToBufferBlt(IN PUCHAR Buffer, RtlZeroMemory(Buffer, Delta * Height); /* Calculate the pixel offset and convert the X distance into byte form */ - PixelOffset = Top * 80 + (Left >> 3); + PixelOffset = Top * (SCREEN_WIDTH / 8) + (Left >> 3); XDistance >>= 3; /* Loop the 4 planes */ @@ -1029,7 +1028,7 @@ VidScreenToBufferBlt(IN PUCHAR Buffer, } /* Update pixel position */ - PixelPosition += 80; + PixelPosition += (SCREEN_WIDTH / 8); i += Delta; } while (--y); } @@ -1072,7 +1071,7 @@ VidSolidColorFill(IN ULONG Left, __outpw(VGA_BASE_IO_PORT + GRAPH_ADDRESS_PORT, 7); /* Calculate pixel position for the read */ - Offset = (PUCHAR)(VgaBase + (Top * 80) + LeftOffset); + Offset = (PUCHAR)(VgaBase + (Top * (SCREEN_WIDTH / 8)) + LeftOffset); /* Select the bitmask register and write the mask */ __outpw(VGA_BASE_IO_PORT + GRAPH_ADDRESS_PORT, (USHORT)lMask); @@ -1088,7 +1087,7 @@ VidSolidColorFill(IN ULONG Left, WRITE_REGISTER_UCHAR(Offset, READ_REGISTER_UCHAR(Offset) & Color); /* Move to the next line */ - Offset += 80; + Offset += (SCREEN_WIDTH / 8); } while (--i); } @@ -1096,7 +1095,7 @@ VidSolidColorFill(IN ULONG Left, if (Distance) { /* Calculate new pixel position */ - Offset = (PUCHAR)(VgaBase + (Top * 80) + RightOffset); + Offset = (PUCHAR)(VgaBase + (Top * (SCREEN_WIDTH / 8)) + RightOffset); Distance--; /* Select the bitmask register and write the mask */ @@ -1114,7 +1113,7 @@ VidSolidColorFill(IN ULONG Left, READ_REGISTER_UCHAR(Offset) & Color); /* Move to the next line */ - Offset += 80; + Offset += (SCREEN_WIDTH / 8); } while (--i); } @@ -1122,7 +1121,7 @@ VidSolidColorFill(IN ULONG Left, if (Distance) { /* Calculate new pixel position */ - Offset = (PUCHAR)(VgaBase + (Top * 80) + LeftOffset + 1); + Offset = (PUCHAR)(VgaBase + (Top * (SCREEN_WIDTH / 8)) + LeftOffset + 1); /* Set the bitmask to 0xFF for all 4 planes */ __outpw(VGA_BASE_IO_PORT + GRAPH_ADDRESS_PORT, 0xFF08); @@ -1145,7 +1144,7 @@ VidSolidColorFill(IN ULONG Left, } /* Update position in memory */ - Offset += (80 - Distance); + Offset += ((SCREEN_WIDTH / 8) - Distance); } while (--i); } } diff --git a/drivers/base/bootvid/precomp.h b/drivers/base/bootvid/precomp.h index 407447e762b..18bc611a99a 100644 --- a/drivers/base/bootvid/precomp.h +++ b/drivers/base/bootvid/precomp.h @@ -8,7 +8,14 @@ /* Define if FontData has upside down characters */ #undef CHAR_GEN_UPSIDE_DOWN -#define BOOTCHAR_HEIGHT 13 +#define BOOTCHAR_HEIGHT 13 +#define BOOTCHAR_WIDTH 8 // Each character line is encoded in a UCHAR. + +/* + * Screen resolution (for default VGA) + */ +#define SCREEN_WIDTH 640 +#define SCREEN_HEIGHT 480 #ifndef _M_ARM #include "vga.h"