diff --git a/src/common/engine/st_start.h b/src/common/engine/st_start.h index 09eb6ae67..bba7d55e4 100644 --- a/src/common/engine/st_start.h +++ b/src/common/engine/st_start.h @@ -182,12 +182,10 @@ BitmapInfo* ST_Util_CreateBitmap(int width, int height, int color_bits); uint8_t* ST_Util_BitsForBitmap(BitmapInfo* bitmap_info); void ST_Util_FreeBitmap(BitmapInfo* bitmap_info); void ST_Util_BitmapColorsFromPlaypal(BitmapInfo* bitmap_info); -uint8_t* ST_Util_LoadFont(const char* filename); -void ST_Util_FreeFont(uint8_t* font); -BitmapInfo* ST_Util_AllocTextBitmap(const uint8_t* font); -void ST_Util_DrawTextScreen(BitmapInfo* bitmap_info, const uint8_t* text_screen, const uint8_t* font); -void ST_Util_DrawChar(BitmapInfo* screen, const uint8_t* font, int x, int y, uint8_t charnum, uint8_t attrib); -void ST_Util_UpdateTextBlink(BitmapInfo* bitmap_info, const uint8_t* text_screen, const uint8_t* font, bool on); +BitmapInfo* ST_Util_AllocTextBitmap(); +void ST_Util_DrawTextScreen(BitmapInfo* bitmap_info, const uint8_t* text_screen); +int ST_Util_DrawChar(BitmapInfo* screen, int x, int y, unsigned charnum, uint8_t attrib); +void ST_Util_UpdateTextBlink(BitmapInfo* bitmap_info, const uint8_t* text_screen, bool on); //=========================================================================== diff --git a/src/common/fonts/hexfont.cpp b/src/common/fonts/hexfont.cpp index 3b985619e..e2bdbff7a 100644 --- a/src/common/fonts/hexfont.cpp +++ b/src/common/fonts/hexfont.cpp @@ -415,3 +415,22 @@ FFont *CreateHexLumpFont2(const char *fontname, int lump) if (hexdata.FirstChar == INT_MAX) hexdata.ParseDefinition(lump); return new FHexFont2(fontname, lump); } + +//========================================================================== +// +// +// +//========================================================================== + +uint8_t* GetHexChar(int codepoint) +{ + auto lump = fileSystem.CheckNumForFullName("newconsolefont.hex", 0); // This is always loaded from gzdoom.pk3 to prevent overriding it with incomplete replacements. + if (hexdata.FirstChar == INT_MAX) hexdata.ParseDefinition(lump); + + if (hexdata.glyphmap[codepoint] > 0) + { + auto offset = hexdata.glyphmap[codepoint]; + return &hexdata.glyphdata[offset]; + } + return nullptr; +} \ No newline at end of file diff --git a/src/common/platform/win32/st_start.cpp b/src/common/platform/win32/st_start.cpp index 3e67c795c..53f701885 100644 --- a/src/common/platform/win32/st_start.cpp +++ b/src/common/platform/win32/st_start.cpp @@ -61,7 +61,6 @@ // The number here therefore corresponds roughly to the blink rate on a // 60 Hz display. #define BLINK_PERIOD 267 -#define TEXT_FONT_NAME "vga-rom-font.16" // TYPES ------------------------------------------------------------------- @@ -517,7 +516,6 @@ int RunEndoom() int endoom_lump = fileSystem.CheckNumForFullName (endoomName, true); uint8_t endoom_screen[4000]; - uint8_t *font; MSG mess; BOOL bRet; bool blinking = false, blinkstate = false; @@ -534,15 +532,8 @@ int RunEndoom() return 0; } - font = ST_Util_LoadFont (TEXT_FONT_NAME); - if (font == NULL) - { - return 0; - } - if (!ST_Util_CreateStartupWindow()) { - ST_Util_FreeFont (font); return 0; } @@ -553,8 +544,8 @@ int RunEndoom() fileSystem.ReadFile (endoom_lump, endoom_screen); // Draw the loading screen to a bitmap. - StartupBitmap = ST_Util_AllocTextBitmap (font); - ST_Util_DrawTextScreen (StartupBitmap, endoom_screen, font); + StartupBitmap = ST_Util_AllocTextBitmap(); + ST_Util_DrawTextScreen (StartupBitmap, endoom_screen); // Make the title banner go away. if (GameTitleWindow != NULL) @@ -593,12 +584,11 @@ int RunEndoom() KillTimer (Window, 0x5A15A); } ST_Util_FreeBitmap (StartupBitmap); - ST_Util_FreeFont (font); return int(bRet == 0 ? mess.wParam : 0); } else if (blinking && mess.message == WM_TIMER && mess.hwnd == Window && mess.wParam == 0x5A15A) { - ST_Util_UpdateTextBlink (StartupBitmap, endoom_screen, font, blinkstate); + ST_Util_UpdateTextBlink (StartupBitmap, endoom_screen, blinkstate); blinkstate = !blinkstate; } TranslateMessage (&mess); diff --git a/src/common/platform/win32/st_start_util.cpp b/src/common/platform/win32/st_start_util.cpp index ec9da4677..b23db71a9 100644 --- a/src/common/platform/win32/st_start_util.cpp +++ b/src/common/platform/win32/st_start_util.cpp @@ -44,6 +44,8 @@ #include "palutil.h" #include "i_interface.h" +uint8_t* GetHexChar(int codepoint); + void I_GetEvent(); // i_input.h pulls in too much garbage. void ST_Util_InvalidateRect(BitmapInfo* bitmap_info, int left, int top, int right, int bottom); @@ -331,8 +333,6 @@ BitmapInfo* StartupBitmap; #define THERM_LEN 51 #define THERM_COLOR 0xAA // light green -#define TEXT_FONT_NAME "vga-rom-font.16" - // Strife startup screen #define PEASANT_INDEX 0 #define LASER_INDEX 4 @@ -583,7 +583,6 @@ FHereticStartupScreen::FHereticStartupScreen(int max_progress, long& hr) { int loading_lump = fileSystem.CheckNumForName("LOADING"); uint8_t loading_screen[4000]; - uint8_t* font; hr = -1; if (loading_lump < 0 || fileSystem.FileLength(loading_lump) != 4000 || !ST_Util_CreateStartupWindow()) @@ -591,12 +590,6 @@ FHereticStartupScreen::FHereticStartupScreen(int max_progress, long& hr) return; } - font = ST_Util_LoadFont(TEXT_FONT_NAME); - if (font == NULL) - { - return; - } - fileSystem.ReadFile(loading_lump, loading_screen); // Slap the Heretic minor version on the loading screen. Heretic @@ -605,17 +598,16 @@ FHereticStartupScreen::FHereticStartupScreen(int max_progress, long& hr) loading_screen[2 * 160 + 49 * 2] = HERETIC_MINOR_VERSION; // Draw the loading screen to a bitmap. - StartupBitmap = ST_Util_AllocTextBitmap(font); - ST_Util_DrawTextScreen(StartupBitmap, loading_screen, font); + StartupBitmap = ST_Util_AllocTextBitmap(); + ST_Util_DrawTextScreen(StartupBitmap, loading_screen); ThermX = THERM_X * 8; - ThermY = THERM_Y * font[0]; + ThermY = THERM_Y * 16; ThermWidth = THERM_LEN * 8 - 4; - ThermHeight = font[0]; + ThermHeight = 16; HMsgY = 7; SMsgX = 1; - ST_Util_FreeFont(font); SetWindowSize(); hr = 0; } @@ -659,20 +651,15 @@ void FHereticStartupScreen::Progress() void FHereticStartupScreen::LoadingStatus(const char* message, int colors) { - uint8_t* font = ST_Util_LoadFont(TEXT_FONT_NAME); - if (font != NULL) - { - int x; + int x; - for (x = 0; message[x] != '\0'; ++x) - { - ST_Util_DrawChar(StartupBitmap, font, 17 + x, HMsgY, message[x], colors); - } - ST_Util_InvalidateRect(StartupBitmap, 17 * 8, HMsgY * font[0], (17 + x) * 8, HMsgY * font[0] + font[0]); - ST_Util_FreeFont(font); - HMsgY++; - I_GetEvent(); + for (x = 0; message[x] != '\0'; ++x) + { + ST_Util_DrawChar(StartupBitmap, 17 + x, HMsgY, message[x], colors); } + ST_Util_InvalidateRect(StartupBitmap, 17 * 8, HMsgY * 16, (17 + x) * 8, HMsgY * 16 + 16); + HMsgY++; + I_GetEvent(); } //========================================================================== @@ -685,20 +672,15 @@ void FHereticStartupScreen::LoadingStatus(const char* message, int colors) void FHereticStartupScreen::AppendStatusLine(const char* status) { - uint8_t* font = ST_Util_LoadFont(TEXT_FONT_NAME); - if (font != NULL) - { - int x; + int x; - for (x = 0; status[x] != '\0'; ++x) - { - ST_Util_DrawChar(StartupBitmap, font, SMsgX + x, 24, status[x], 0x1f); - } - ST_Util_InvalidateRect(StartupBitmap, SMsgX * 8, 24 * font[0], (SMsgX + x) * 8, 25 * font[0]); - ST_Util_FreeFont(font); - SMsgX += x; - I_GetEvent(); + for (x = 0; status[x] != '\0'; ++x) + { + ST_Util_DrawChar(StartupBitmap, SMsgX + x, 24, status[x], 0x1f); } + ST_Util_InvalidateRect(StartupBitmap, SMsgX * 8, 24 * 16, (SMsgX + x) * 8, 25 * 16); + SMsgX += x; + I_GetEvent(); } //========================================================================== @@ -1048,47 +1030,6 @@ void ST_Util_BitmapColorsFromPlaypal(BitmapInfo* bitmap_info) } } -//========================================================================== -// -// ST_Util_LoadFont -// -// Loads a monochrome fixed-width font. Every character is one byte -// (eight pixels) wide, so we can deduce the height of each character -// by looking at the size of the font data. -// -//========================================================================== - -uint8_t* ST_Util_LoadFont(const char* filename) -{ - int lumpnum, lumplen, height; - uint8_t* font; - - lumpnum = fileSystem.CheckNumForFullName(filename); - if (lumpnum < 0) - { // font not found - return NULL; - } - lumplen = fileSystem.FileLength(lumpnum); - height = lumplen / 256; - if (height * 256 != lumplen) - { // font is a bad size - return NULL; - } - if (height < 6 || height > 36) - { // let's be reasonable here - return NULL; - } - font = new uint8_t[lumplen + 1]; - font[0] = height; // Store font height in the first byte. - fileSystem.ReadFile(lumpnum, font + 1); - return font; -} - -void ST_Util_FreeFont(uint8_t* font) -{ - delete[] font; -} - //========================================================================== // // ST_Util_AllocTextBitmap @@ -1098,9 +1039,9 @@ void ST_Util_FreeFont(uint8_t* font) // //========================================================================== -BitmapInfo* ST_Util_AllocTextBitmap(const uint8_t* font) +BitmapInfo* ST_Util_AllocTextBitmap() { - BitmapInfo* bitmap = ST_Util_CreateBitmap(80 * 8, 25 * font[0], 4); + BitmapInfo* bitmap = ST_Util_CreateBitmap(80 * 8, 25 * 16, 4); memcpy(bitmap->bmiColors, TextModePalette, sizeof(TextModePalette)); return bitmap; } @@ -1114,7 +1055,7 @@ BitmapInfo* ST_Util_AllocTextBitmap(const uint8_t* font) // //========================================================================== -void ST_Util_DrawTextScreen(BitmapInfo* bitmap_info, const uint8_t* text_screen, const uint8_t* font) +void ST_Util_DrawTextScreen(BitmapInfo* bitmap_info, const uint8_t* text_screen) { int x, y; @@ -1122,7 +1063,7 @@ void ST_Util_DrawTextScreen(BitmapInfo* bitmap_info, const uint8_t* text_screen, { for (x = 0; x < 80; ++x) { - ST_Util_DrawChar(bitmap_info, font, x, y, text_screen[0], text_screen[1]); + ST_Util_DrawChar(bitmap_info, x, y, IBM437ToUnicode[text_screen[0]], text_screen[1]); text_screen += 2; } } @@ -1137,18 +1078,21 @@ void ST_Util_DrawTextScreen(BitmapInfo* bitmap_info, const uint8_t* text_screen, // //========================================================================== -void ST_Util_DrawChar(BitmapInfo* screen, const uint8_t* font, int x, int y, uint8_t charnum, uint8_t attrib) +int ST_Util_DrawChar(BitmapInfo* screen, int x, int y, unsigned charnum, uint8_t attrib) { + static const uint8_t space[17] = { 16 }; const uint8_t bg_left = attrib & 0x70; const uint8_t fg = attrib & 0x0F; const uint8_t fg_left = fg << 4; const uint8_t bg = bg_left >> 4; const uint8_t color_array[4] = { (uint8_t)(bg_left | bg), (uint8_t)(attrib & 0x7F), (uint8_t)(fg_left | bg), (uint8_t)(fg_left | fg) }; - const uint8_t* src = font + 1 + charnum * font[0]; + const uint8_t* src = GetHexChar(charnum); + if (!src) src = space; + int size = *src++; int pitch = screen->bmiHeader.biWidth >> 1; - uint8_t* dest = ST_Util_BitsForBitmap(screen) + x * 4 + y * font[0] * pitch; + uint8_t* dest = ST_Util_BitsForBitmap(screen) + x * 4 + y * 16 * pitch; - for (y = font[0]; y > 0; --y) + for (y = 0; y <16; ++y) { uint8_t srcbyte = *src++; @@ -1160,8 +1104,22 @@ void ST_Util_DrawChar(BitmapInfo* screen, const uint8_t* font, int x, int y, uin dest[2] = color_array[(srcbyte >> 2) & 3]; // Pixels 6 and 7 dest[3] = color_array[(srcbyte) & 3]; + if (size == 32) + { + srcbyte = *src++; + + // Pixels 0 and 1 + dest[4] = color_array[(srcbyte >> 6) & 3]; + // Pixels 2 and 3 + dest[5] = color_array[(srcbyte >> 4) & 3]; + // Pixels 4 and 5 + dest[6] = color_array[(srcbyte >> 2) & 3]; + // Pixels 6 and 7 + dest[7] = color_array[(srcbyte) & 3]; + } dest += pitch; } + return size; } //========================================================================== @@ -1173,7 +1131,7 @@ void ST_Util_DrawChar(BitmapInfo* screen, const uint8_t* font, int x, int y, uin // //========================================================================== -void ST_Util_UpdateTextBlink(BitmapInfo* bitmap_info, const uint8_t* text_screen, const uint8_t* font, bool on) +void ST_Util_UpdateTextBlink(BitmapInfo* bitmap_info, const uint8_t* text_screen, bool on) { int x, y; @@ -1183,8 +1141,8 @@ void ST_Util_UpdateTextBlink(BitmapInfo* bitmap_info, const uint8_t* text_screen { if (text_screen[1] & 0x80) { - ST_Util_DrawChar(bitmap_info, font, x, y, on ? text_screen[0] : ' ', text_screen[1]); - ST_Util_InvalidateRect(bitmap_info, x * 8, y * font[0], x * 8 + 8, y * font[0] + font[0]); + ST_Util_DrawChar(bitmap_info, x, y, on ? IBM437ToUnicode[text_screen[0]] : ' ', text_screen[1]); + ST_Util_InvalidateRect(bitmap_info, x * 8, y * 16, x * 8 + 8, y * 16 + 16); } text_screen += 2; } diff --git a/wadsrc/static/vga-rom-font.16 b/wadsrc/static/vga-rom-font.16 deleted file mode 100644 index 672d0e1a9..000000000 Binary files a/wadsrc/static/vga-rom-font.16 and /dev/null differ