From e49701cb5e40ccf389501bc3e334517e6b708305 Mon Sep 17 00:00:00 2001 From: jeffman Date: Sat, 15 Apr 2017 12:47:58 -0400 Subject: [PATCH] Centralized character decoding --- compiled/vwf.c | 16 +++++++++++----- compiled/vwf.h | 1 + 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/compiled/vwf.c b/compiled/vwf.c index 3fc5422..d6847f4 100644 --- a/compiled/vwf.c +++ b/compiled/vwf.c @@ -1,6 +1,15 @@ #include "window.h" #include "vwf.h" +byte decode_character(byte chr) +{ + int c = chr - 0x50; + if ((c < 0) || ((c >= 0x60) && (c < 0x64)) || (c >= 0x6D)) + c = QUESTION_MARK; + + return c; +} + int get_tile_number(int x, int y) { x--; @@ -104,9 +113,7 @@ void weld_entry(WINDOW *window, byte *str) void weld_entry_custom(WINDOW *window, byte *str, int font, int foreground) { - int chr = *str - 0x50; - if ((chr < 0) || ((chr >= 0x60) && (chr < 0x64)) || (chr >= 0x6D)) - chr = QUESTION_MARK; + int chr = decode_character(*str); int x = window->pixel_x + (window->window_x + window->text_x) * 8; int y = (window->window_y + window->text_y) * 8; @@ -127,8 +134,7 @@ int print_string(byte *str, int x, int y) while (str[1] != 0xFF) { - chr = *str++; - x += print_character(chr - 0x50, x, y, 0, 0xF); + x += print_character(decode_character(*str++), x, y, 0, 0xF); charCount++; } diff --git a/compiled/vwf.h b/compiled/vwf.h index 67a166e..76e9fcb 100644 --- a/compiled/vwf.h +++ b/compiled/vwf.h @@ -7,6 +7,7 @@ unsigned short *palette_mask = (unsigned short*)0x3005228; unsigned short **tilemap = (unsigned short**)0x3005270; int *vram = (int*)0x6000000; +byte decode_character(byte chr); int get_tile_number(int x, int y); int expand_bit_depth(byte row, int foreground); byte reduce_bit_depth(int row, int foreground);