From 5ed7f7150a79ed38982a6e058041480c44a2fba8 Mon Sep 17 00:00:00 2001 From: nmlgc Date: Mon, 1 Nov 2021 18:01:03 +0100 Subject: [PATCH] [Maintenance] [th01] Start a new header file for text layer functions What's most ridiculous about this is that ZUN had already reimplemented master.lib text mode functions (th01/hardware/ztext.c). He simply never used anything from there. Part of P0167, funded by Ember2528. --- th01/hardware/text.h | 27 +++++++++++++++++++++++++++ th01/main/boss/b20j.cpp | 26 +++----------------------- 2 files changed, 30 insertions(+), 23 deletions(-) create mode 100644 th01/hardware/text.h diff --git a/th01/hardware/text.h b/th01/hardware/text.h new file mode 100644 index 00000000..1cf52666 --- /dev/null +++ b/th01/hardware/text.h @@ -0,0 +1,27 @@ +// Fills the text layer with spaces. +// PORTERS: Implement better, and more consistently. +#define text_fill_space(esc_move_topleft, space, tmp_x, tmp_y) { \ + printf(esc_move_topleft); \ + for(tmp_y = 0; tmp_y < (RES_Y / GLYPH_H); tmp_y++) { \ + for(tmp_x = 0; tmp_x < (RES_X / GLYPH_HALF_W); tmp_x++) { \ + printf(space); \ + } \ + } \ +} + +// Fills the text layer with opaque black. +// MODDERS: This should maybe reset the current text mode color. +#define text_fill_black( \ + esc_color_bg_black_fg_black, esc_move_topleft, space, tmp_x, tmp_y \ +) { \ + printf(esc_color_bg_black_fg_black); \ + text_fill_space(esc_move_topleft, space, tmp_x, tmp_y); \ +} + +// Fills the text layer with transparent spaces. Yes, this overwrites the +// perfectly suitable master.lib function with the same name. +#define text_clear_sloppy(tmp_x, tmp_y) { \ + printf("\x1B[0m"); /* Reset text mode color */ \ + /* (yes, this escape sequence is actually 1-based) */ \ + text_fill_space("\x1B[1;1H", " ", tmp_x, tmp_y); \ +} diff --git a/th01/main/boss/b20j.cpp b/th01/main/boss/b20j.cpp index 9f84fb48..6dee8c19 100644 --- a/th01/main/boss/b20j.cpp +++ b/th01/main/boss/b20j.cpp @@ -20,6 +20,7 @@ extern "C" { #include "th01/hardware/egc.h" #include "th01/hardware/scrollup.hpp" #include "th01/hardware/input.hpp" +#include "th01/hardware/text.h" #include "th01/snd/mdrv2.h" #include "th01/main/playfld.hpp" #include "th01/formats/grp.h" @@ -1800,35 +1801,14 @@ void konngara_main(void) // reimplementation of the original functionality into DOSBox-X. // -------------------------------------------------------------------- - #define y i - #define x j - printf("\x1B)3"); // Enter graph mode - printf("\x1B[16;40m"); // Set black foreground and background text color - printf("\x1B[0;0H"); // Move text cursor to (0, 0) - - for(y = 0; y < (RES_Y / GLYPH_H); y++) { - for(x = 0; x < (RES_X / GLYPH_HALF_W); x++) { - printf(" "); - } - } + text_fill_black("\x1B[16;40m", "\x1B[0;0H", " ", j, i); grp_put_palette_show(SCROLL_BG_FN); z_palette_set_black(j, i); printf("\x1B)0"); // Back to regular kanji mode - printf("\x1B[0m"); // Reset text mode color - printf("\x1B[1;1H"); // Move text cursor to (0, 0) - // (yes, this escape sequence is actually 1-based) - - for(y = 0; y < (RES_Y / GLYPH_H); y++) { - for(x = 0; x < (RES_X / GLYPH_HALF_W); x++) { - printf(" "); - } - } - - #undef x - #undef y + text_clear_sloppy(j, i); // -------------------------------------------------------------------- // Final scroll