From: quzar <qu...@us...> - 2024-10-19 06:33:28
|
This is an automated email from the git hooks/post-receive script. It was generated because a ref change was pushed to the repository containing the project "A pseudo Operating System for the Dreamcast.". The branch, master has been updated via f3be5205f542e667ff8d39cca0b9b2024276c2ce (commit) via 20f1380057375fb2b885ad4eb97d3d24fd84e99a (commit) via 6e8a811fd773d7ab64e34940a2a0f1923d6793ba (commit) from fb5168a380cac5cb99696ad38ceb4b360dedcd20 (commit) Those revisions listed above that are new to this repository have not appeared on any other notification email; so we list those revisions in full, below. - Log ----------------------------------------------------------------- commit f3be5205f542e667ff8d39cca0b9b2024276c2ce Author: Andy Barajas <and...@gm...> Date: Fri Oct 18 23:28:08 2024 -0700 Exclude system generated files from being included in romdisk generation (#824) commit 20f1380057375fb2b885ad4eb97d3d24fd84e99a Author: Stefanos Kornilios Mitsis Poiitidis <st...@sk...v> Date: Sat Oct 19 09:27:31 2024 +0300 audio: Fix makefile race condition and arm clean (#828) commit 6e8a811fd773d7ab64e34940a2a0f1923d6793ba Author: Andy Barajas <and...@gm...> Date: Fri Oct 18 23:24:20 2024 -0700 Added functionality to biosfont (#816) - Extend bfont API to take common formatted prints to the framebuffer. - Remove deprecated `32-bit mode` which was a legacy of the framebuffer being expanded to work against different bitdepths and hasn't been needed in years. ----------------------------------------------------------------------- Summary of changes: Makefile.rules | 2 +- examples/dreamcast/video/screenshot/screenshot.c | 14 +-- examples/dreamcast/vmu/vmu_game/vmu_game.c | 18 ++-- kernel/arch/dreamcast/exports-pristine.txt | 15 +++- kernel/arch/dreamcast/hardware/biosfont.c | 108 +++++++++++++++++------ kernel/arch/dreamcast/include/dc/biosfont.h | 106 +++++++++++++--------- kernel/arch/dreamcast/sound/Makefile | 4 +- kernel/arch/dreamcast/sound/arm/Makefile | 2 +- 8 files changed, 173 insertions(+), 96 deletions(-) diff --git a/Makefile.rules b/Makefile.rules index 678c882a..f8f1b16e 100644 --- a/Makefile.rules +++ b/Makefile.rules @@ -77,7 +77,7 @@ $(patsubst %, _clean_dir_%, $(SUBDIRS)): # Define KOS_ROMDISK_DIR in your Makefile if you want these two handy rules. ifdef KOS_ROMDISK_DIR romdisk.img: - $(KOS_GENROMFS) -f romdisk.img -d $(KOS_ROMDISK_DIR) -v -x .svn -x .keepme + $(KOS_GENROMFS) -f romdisk.img -d $(KOS_ROMDISK_DIR) -v -x .keepme -x .DS_Store -x Thumbs.db romdisk.o: romdisk.img $(KOS_BASE)/utils/bin2c/bin2c romdisk.img romdisk_tmp.c romdisk diff --git a/examples/dreamcast/video/screenshot/screenshot.c b/examples/dreamcast/video/screenshot/screenshot.c index 1f77d807..fab1c61e 100644 --- a/examples/dreamcast/video/screenshot/screenshot.c +++ b/examples/dreamcast/video/screenshot/screenshot.c @@ -30,7 +30,7 @@ #include <kos/thread.h> -#define SHOW_BLACK_BG 1 +#define SHOW_BLACK_BG true /* Keeps track of the amount of screenshots you have taken */ static int counter = 0; @@ -38,7 +38,6 @@ static int counter = 0; int main(int argc, char **argv) { uint8_t r, g, b; uint32_t t = 0; - int font_height_offset = 0; char filename[256]; /* Adjust frequency for faster or slower transitions */ @@ -48,7 +47,7 @@ int main(int argc, char **argv) { cont_state_t *state; /* Set the video mode */ - vid_set_mode(DM_640x480, PM_RGB565); + vid_set_mode(DM_640x480, PM_RGB565); while(1) { if((cont = maple_enum_type(0, MAPLE_FUNC_CONTROLLER)) != NULL) { @@ -82,13 +81,8 @@ int main(int argc, char **argv) { vid_clear(r, g, b); /* Draw Foreground */ - font_height_offset = (640 * (480 - (BFONT_HEIGHT * 6))) + (BFONT_THIN_WIDTH * 2); - bfont_draw_str(vram_s + font_height_offset, 640, SHOW_BLACK_BG, - "Press Start to exit"); - - font_height_offset += 640 * BFONT_HEIGHT * 2; - bfont_draw_str(vram_s + font_height_offset, 640, SHOW_BLACK_BG, - "Press A to take a screen shot"); + bfont_draw_str_vram_fmt(24, 336, SHOW_BLACK_BG, + "Press Start to exit\n\nPress A to take a screen shot"); vid_flip(-1); } diff --git a/examples/dreamcast/vmu/vmu_game/vmu_game.c b/examples/dreamcast/vmu/vmu_game/vmu_game.c index 12d5c42d..7b90b0ef 100644 --- a/examples/dreamcast/vmu/vmu_game/vmu_game.c +++ b/examples/dreamcast/vmu/vmu_game/vmu_game.c @@ -12,15 +12,14 @@ void draw_findings(void) { file_t d; - int y = 88; d = fs_open("/vmu/a1", O_RDONLY | O_DIR); if(!d) { - bfont_draw_str(vram_s + y * 640 + 10, 640, 0, "Can't read VMU"); + bfont_draw_str_vram_fmt(10, 88, false, "Can't read VMU"); } else { - bfont_draw_str(vram_s + y * 640 + 10, 640, 0, "VMU found. Press Start."); + bfont_draw_str_vram_fmt(10, 88, false, "VMU found. Press Start."); } } @@ -33,7 +32,7 @@ void new_vmu(void) { if(dev == NULL) { if(dev_checked) { memset4(vram_s + 88 * 640, 0, 640 * (480 - 64) * 2); - bfont_draw_str(vram_s + 88 * 640 + 10, 640, 0, "No VMU"); + bfont_draw_str_vram_fmt(10, 88, false, "No VMU"); dev_checked = 0; } } @@ -88,18 +87,13 @@ void write_game_entry(void) { dev = maple_enum_type(0, MAPLE_FUNC_MEMCARD); - if (dev) - { + if(dev) vmufs_write(dev, "Tetris", data, data_size, VMUFS_VMUGAME); - } } int main(int argc, char **argv) { - bfont_draw_str(vram_s + 20 * 640 + 20, 640, 0, - "Put a VMU you don't care too much about"); - bfont_draw_str(vram_s + 42 * 640 + 20, 640, 0, - "in slot A1 and press START"); - bfont_draw_str(vram_s + 88 * 640 + 10, 640, 0, "No VMU"); + bfont_draw_str_vram_fmt(20, 20, false, + "Put a VMU you don't care too much about\nin slot A1 and press START\n\nNo VMU"); if(wait_start() < 0) return 0; diff --git a/kernel/arch/dreamcast/exports-pristine.txt b/kernel/arch/dreamcast/exports-pristine.txt index bdb05bf9..89750ed6 100644 --- a/kernel/arch/dreamcast/exports-pristine.txt +++ b/kernel/arch/dreamcast/exports-pristine.txt @@ -93,11 +93,24 @@ vmu_pkg_build vmu_pkg_parse # Bios Font +bfont_set_foreground_color +bfont_set_background_color bfont_set_encoding +bfont_find_char +bfont_find_char_jp +bfont_find_char_jp_half +bfont_find_icon +bfont_draw_ex +bfont_draw bfont_draw_thin bfont_draw_wide -bfont_draw +bfont_draw_str_ex +bfont_draw_str_ex_fmt +bfont_draw_str_ex_vfmt bfont_draw_str +bfont_draw_str_fmt +bfont_draw_str_vram_vfmt +bfont_draw_str_vram_fmt # CD-Rom cdrom_reinit diff --git a/kernel/arch/dreamcast/hardware/biosfont.c b/kernel/arch/dreamcast/hardware/biosfont.c index 7ac5bfb9..0a3bd1ca 100644 --- a/kernel/arch/dreamcast/hardware/biosfont.c +++ b/kernel/arch/dreamcast/hardware/biosfont.c @@ -13,6 +13,7 @@ #include <string.h> #include <stdio.h> +#include <dc/video.h> #include <dc/biosfont.h> #include <dc/syscalls.h> @@ -44,7 +45,6 @@ static uint8_t bfont_code_mode = BFONT_CODE_ISO8859_1; been forever. */ static uint32_t bfont_fgcolor = 0xFFFFFFFF; static uint32_t bfont_bgcolor = 0x00000000; -static bool bfont_32bit = false; static uint8_t *font_address = NULL; @@ -55,6 +55,10 @@ static uint8_t *get_font_address(void) { return font_address; } +static inline uint8_t bits_per_pixel() { + return ((vid_mode->pm == PM_RGB0888) ? sizeof(uint32_t) : sizeof(uint16_t)) << 3; +} + /* Select an encoding for Japanese (or disable) */ void bfont_set_encoding(bfont_code_t enc) { if(enc <= BFONT_CODE_RAW) @@ -77,15 +81,6 @@ uint32_t bfont_set_background_color(uint32_t c) { return rv; } -/* Set the font to draw in 32 or 16 bit mode. - Deprecated: This will only impact compat functions for now. - Moving forward, the compat will be 16bit only. */ -bool bfont_set_32bit_mode(bool on) { - bool rv = bfont_32bit; - bfont_32bit = on; - return rv; -} - int lock_bfont(void) { /* Just make sure no outside system took the lock */ while(syscall_font_lock() != 0) @@ -129,7 +124,7 @@ static uint32_t euc2jis(uint32_t euc) { /* Given an ASCII character, find it in the BIOS font if possible */ uint8_t *bfont_find_char(uint32_t ch) { - uint8_t *fa = get_font_address(); + uint8_t *fa = get_font_address(); /* By default, map to a space */ uint32_t index = 72 << 2; @@ -146,7 +141,7 @@ uint8_t *bfont_find_char(uint32_t ch) { /* JIS -> (kuten) -> address conversion */ uint8_t *bfont_find_char_jp(uint32_t ch) { - uint8_t *fa = get_font_address(); + uint8_t *fa = get_font_address(); uint32_t ku, ten, kuten = 0; /* Do the requested code conversion */ @@ -293,66 +288,95 @@ size_t bfont_draw_ex(void *buf, uint32_t bufwidth, uint32_t fg, uint32_t bg, /* Draw half-width kana */ size_t bfont_draw_thin(void *b, uint32_t bufwidth, bool opaque, uint32_t c, bool iskana) { return bfont_draw_ex(b, bufwidth, bfont_fgcolor, bfont_bgcolor, - (bfont_32bit ? (sizeof (uint32_t)) : (sizeof (uint16_t))) << 3, opaque, c, 0, iskana); + bits_per_pixel(), opaque, c, false, iskana); } /* Compat function */ size_t bfont_draw(void *buffer, uint32_t bufwidth, bool opaque, uint32_t c) { return bfont_draw_ex(buffer, bufwidth, bfont_fgcolor, bfont_bgcolor, - (bfont_32bit ? (sizeof (uint32_t)) : (sizeof (uint16_t))) << 3, opaque, c, 0, 0); + bits_per_pixel(), opaque, c, false, false); } /* Draw wide character */ size_t bfont_draw_wide(void *b, uint32_t bufwidth, bool opaque, uint32_t c) { return bfont_draw_ex(b, bufwidth, bfont_fgcolor, bfont_bgcolor, - (bfont_32bit ? (sizeof (uint32_t)) : (sizeof (uint16_t))) << 3, opaque, c, 1, 0); + bits_per_pixel(), opaque, c, true, false); } -void bfont_draw_str_ex(void *b, uint32_t width, uint32_t fg, uint32_t bg, uint8_t bpp, bool opaque, - const char *str) { - uint16_t nChr, nMask, nFlag; +void bfont_draw_str_ex(void *b, uint32_t width, uint32_t fg, uint32_t bg, + uint8_t bpp, bool opaque, const char *str) { + bool wideChr; + uint16_t nChr, nMask; + uint32_t line_start = 0; uint8_t *buffer = (uint8_t *)b; while(*str) { - nFlag = 0; + wideChr = false; nChr = *str & 0xff; + if(nChr == '\n') { + /* Move to the beginning of the next line */ + buffer = (uint8_t *)b + line_start + (width * BFONT_HEIGHT * (bpp / 8)); + line_start = buffer - (uint8_t *)b; + str++; + continue; + } + else if(nChr == '\t') { + /* Draw four spaces on the current line */ + if(opaque) { + nChr = bfont_code_mode == BFONT_CODE_ISO8859_1 ? 0x20 : 0xa0; + buffer += bfont_draw_ex(buffer, width, fg, bg, bpp, opaque, nChr, false, false); + buffer += bfont_draw_ex(buffer, width, fg, bg, bpp, opaque, nChr, false, false); + buffer += bfont_draw_ex(buffer, width, fg, bg, bpp, opaque, nChr, false, false); + buffer += bfont_draw_ex(buffer, width, fg, bg, bpp, opaque, nChr, false, false); + } + else /* Spaces are always thin width characters */ + buffer += (4 * ((BFONT_THIN_WIDTH * bpp)/8)); + + str++; + continue; + } + + /* Non-western, non-ASCII character */ if(bfont_code_mode != BFONT_CODE_ISO8859_1 && (nChr & 0x80)) { switch(bfont_code_mode) { case BFONT_CODE_EUC: + /* Check if the character is the 'SS2' character in EUC-JP */ if(nChr == 0x8e) { str++; nChr = *str & 0xff; + /* Is a valid half-width katakana character? */ if((nChr < 0xa1) || (nChr > 0xdf)) nChr = 0xa0; /* Blank Space */ } else - nFlag = 1; + wideChr = true; break; case BFONT_CODE_SJIS: nMask = nChr & 0xf0; + /* Check if the character is part of the valid Shift ranges */ if((nMask == 0x80) || (nMask == 0x90) || (nMask == 0xe0)) - nFlag = 1; + wideChr = true; break; default: assert_msg(0, "Unknown bfont encoding mode"); } - if(nFlag == 1) { + if(wideChr) { str++; nChr = (nChr << 8) | (*str & 0xff); - buffer += bfont_draw_ex(buffer, width, fg, bg, bpp, opaque, nChr, 1, 0); + buffer += bfont_draw_ex(buffer, width, fg, bg, bpp, opaque, nChr, true, false); } else - buffer += bfont_draw_ex(buffer, width, fg, bg, bpp, opaque, nChr, 0, 1); + buffer += bfont_draw_ex(buffer, width, fg, bg, bpp, opaque, nChr, false, true); } else - buffer += bfont_draw_ex(buffer, width, fg, bg, bpp, opaque, nChr, 0, 0); + buffer += bfont_draw_ex(buffer, width, fg, bg, bpp, opaque, nChr, false, false); str++; } @@ -384,8 +408,7 @@ void bfont_draw_str_ex_fmt(void *b, uint32_t width, uint32_t fg, uint32_t bg, ui void bfont_draw_str(void *b, uint32_t width, bool opaque, const char *str) { bfont_draw_str_ex(b, width, bfont_fgcolor, bfont_bgcolor, - (bfont_32bit ? (sizeof (uint32_t)) : (sizeof (uint16_t))) << 3, - opaque, str); + bits_per_pixel(), opaque, str); } void bfont_draw_str_fmt(void *b, uint32_t width, bool opaque, const char *fmt, @@ -394,8 +417,34 @@ void bfont_draw_str_fmt(void *b, uint32_t width, bool opaque, const char *fmt, va_start(var_args, fmt); bfont_draw_str_ex_vfmt(b, width, bfont_fgcolor, bfont_bgcolor, - (bfont_32bit ? (sizeof (uint32_t)) : (sizeof (uint16_t))) << 3, - opaque, fmt, &var_args); + bits_per_pixel(), opaque, fmt, &var_args); + + va_end(var_args); +} + +void bfont_draw_str_vram_vfmt(uint32_t x, uint32_t y, uint32_t fg, + uint32_t bg, bool opaque, const char *fmt, + va_list *var_args) { + uint32_t bpp = bits_per_pixel(); + void *vram = vram_s; + uint32_t offset = (y * vid_mode->width + x); + + if(bpp == 16) + vram = (uint16_t *)vram + offset; + else if(bpp == 32) + vram = (uint32_t *)vram + offset; + + bfont_draw_str_ex_vfmt(vram, vid_mode->width, fg, bg, bpp, opaque, fmt, + var_args); +} + +void bfont_draw_str_vram_fmt(uint32_t x, uint32_t y, bool opaque, + const char *fmt, ...) { + va_list var_args; + va_start(var_args, fmt); + + bfont_draw_str_vram_vfmt(x, y, bfont_fgcolor, bfont_bgcolor, opaque, fmt, + &var_args); va_end(var_args); } @@ -407,5 +456,6 @@ uint8_t *bfont_find_icon(bfont_vmu_icon_t icon) { int icon_offset = BFONT_VMU_DREAMCAST_SPECIFIC + (icon * BFONT_ICON_DIMEN * BFONT_ICON_DIMEN / 8); uint8_t *fa = get_font_address(); + return fa + icon_offset; } diff --git a/kernel/arch/dreamcast/include/dc/biosfont.h b/kernel/arch/dreamcast/include/dc/biosfont.h index 520cfa47..b2a77cb3 100644 --- a/kernel/arch/dreamcast/include/dc/biosfont.h +++ b/kernel/arch/dreamcast/include/dc/biosfont.h @@ -5,6 +5,7 @@ Japanese Functions Copyright (C) 2002 Kazuaki Matsumoto Copyright (C) 2017 Donald Haase Copyright (C) 2024 Falco Girgis + Copyright (C) 2024 Andress Barajas */ @@ -286,18 +287,6 @@ uint32_t bfont_set_foreground_color(uint32_t c); */ uint32_t bfont_set_background_color(uint32_t c); -/** \brief Set the font to draw 32-bit color. - \deprecated Use the bpp parameter of the bfont_draw_ex() functions. - - This function changes whether the font draws colors as 32-bit or 16-bit. The - default is to use 16-bit. - - \param on Set to 0 to use 16-bit color, 32-bit otherwise. - \return The old state (1 = 32-bit, 0 = 16-bit). -*/ -bool bfont_set_32bit_mode(bool on) - __depr("Please use the bpp function of the the bfont_draw_ex functions"); - /** @} */ /* Constants for the function below */ @@ -391,7 +380,7 @@ uint8_t *bfont_find_icon(bfont_vmu_icon_t icon); \param fg The foreground color to use. \param bg The background color to use. \param bpp The number of bits per pixel in the buffer. - \param opaque If non-zero, overwrite background areas with black, + \param opaque If true, overwrite background areas with black, otherwise do not change them from what they are. \param c The character to draw. \param wide Draw a wide character. @@ -410,7 +399,7 @@ size_t bfont_draw_ex(void *buffer, uint32_t bufwidth, uint32_t fg, \param buffer The buffer to draw to (at least 12 x 24 pixels) \param bufwidth The width of the buffer in pixels - \param opaque If non-zero, overwrite blank areas with black, + \param opaque If true, overwrite blank areas with black, otherwise do not change them from what they are \param c The character to draw \return Amount of width covered in bytes. @@ -424,7 +413,7 @@ size_t bfont_draw(void *buffer, uint32_t bufwidth, bool opaque, uint32_t c); \param buffer The buffer to draw to (at least 12 x 24 pixels) \param bufwidth The width of the buffer in pixels - \param opaque If non-zero, overwrite blank areas with black, + \param opaque If true, overwrite blank areas with black, otherwise do not change them from what they are \param c The character to draw \param iskana Set to 1 if the character is a kana, 0 if ISO-8859-1 @@ -440,7 +429,7 @@ size_t bfont_draw_thin(void *buffer, uint32_t bufwidth, bool opaque, \param buffer The buffer to draw to (at least 24 x 24 pixels) \param bufwidth The width of the buffer in pixels - \param opaque If non-zero, overwrite blank areas with black, + \param opaque If true, overwrite blank areas with black, otherwise do not change them from what they are \param c The character to draw \return Amount of width covered in bytes. @@ -463,12 +452,12 @@ size_t bfont_draw_wide(void *buffer, uint32_t bufwidth, bool opaque, if the encoding is set to one of the Japanese encodings. Colors and bitdepth can be set. - \param b The buffer to draw to. - \param width The width of the buffer in pixels. - \param fg The foreground color to use. - \param bg The background color to use. - \param bpp The number of bits per pixel in the buffer. - \param opaque If non-zero, overwrite background areas with black, + \param b The buffer to draw to. + \param width The width of the buffer in pixels. + \param fg The foreground color to use. + \param bg The background color to use. + \param bpp The number of bits per pixel in the buffer. + \param opaque If true, overwrite background areas with black, otherwise do not change them from what they are. \param str The string to draw. @@ -482,15 +471,15 @@ void bfont_draw_str_ex(void *b, uint32_t width, uint32_t fg, uint32_t bg, This function is equivalent to bfont_draw_str_ex(), except that the string is formatted as with the `printf()` function. - \param b The buffer to draw to. - \param width The width of the buffer in pixels. - \param fg The foreground color to use. - \param bg The background color to use. - \param bpp The number of bits per pixel in the buffer. - \param opaque If non-zero, overwrite background areas with black, + \param b The buffer to draw to. + \param width The width of the buffer in pixels. + \param fg The foreground color to use. + \param bg The background color to use. + \param bpp The number of bits per pixel in the buffer. + \param opaque If true, overwrite background areas with black, otherwise do not change them from what they are. - \param fmt The printf-style format string to draw. - \param ... Additional printf-style variadic arguments + \param fmt The printf-style format string to draw. + \param ... Additional printf-style variadic arguments \sa bfont_draw_str_ex_vfmt() */ @@ -503,15 +492,15 @@ void bfont_draw_str_ex_fmt(void *b, uint32_t width, uint32_t fg, uint32_t bg, This function is equivalent to bfont_draw_str_ex_fmt(), except that the variadic argument list is passed via a pointer to a va_list. - \param b The buffer to draw to. - \param width The width of the buffer in pixels. - \param fg The foreground color to use. - \param bg The background color to use. - \param bpp The number of bits per pixel in the buffer. - \param opaque If non-zero, overwrite background areas with black, + \param b The buffer to draw to. + \param width The width of the buffer in pixels. + \param fg The foreground color to use. + \param bg The background color to use. + \param bpp The number of bits per pixel in the buffer. + \param opaque If true, overwrite background areas with black, otherwise do not change them from what they are. - \param fmt The printf-style format string to draw. - \param var_args Additional printf-style variadic arguments + \param fmt The printf-style format string to draw. + \param var_args Additional printf-style variadic arguments ...<truncated>... hooks/post-receive -- A pseudo Operating System for the Dreamcast. |