From: Lawrence S. <ljs...@us...> - 2018-10-23 14:42:10
|
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 4ca03aa04fbf6f2356fdaa2eff45075898548d47 (commit) via 9c90fad6fe27c8af7d712d619db27aa5ce393189 (commit) via 2f27f6cc06936766eca8d7d2012b9f6c560e4c72 (commit) from 11d4192b41935feead6c079cf3f81a6c1b4e41ea (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 4ca03aa04fbf6f2356fdaa2eff45075898548d47 Author: Donald Haase <qu...@gm...> Date: Mon Oct 22 23:19:16 2018 -0400 Update to BIOS font code: - Access to Dreamcast-specific font characters such as buttons. - Allows drawing BIOS font to any buffer pixel size (4,8,16, and 32 bpp). - Refactored private functions. commit 9c90fad6fe27c8af7d712d619db27aa5ce393189 Merge: 11d4192 2f27f6c Author: Lawrence Sebald <ljs...@us...> Date: Tue Oct 23 09:33:38 2018 -0400 Merge pull request #11 from sizious/git-ignore-updating Add windows binary files to the .gitignore. commit 2f27f6cc06936766eca8d7d2012b9f6c560e4c72 Author: sizious <si...@gm...> Date: Tue Oct 23 11:02:10 2018 +0200 Ignoring Microsoft Windows binaries. ----------------------------------------------------------------------- Summary of changes: .gitignore | 2 + kernel/arch/dreamcast/hardware/biosfont.c | 346 +++++++++++----------------- kernel/arch/dreamcast/include/dc/biosfont.h | 128 ++++++++-- 3 files changed, 256 insertions(+), 220 deletions(-) diff --git a/.gitignore b/.gitignore index 7e40810..8f219c2 100644 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,7 @@ *.o *.elf +*.exe +*.dll *.map *~ .*.swp diff --git a/kernel/arch/dreamcast/hardware/biosfont.c b/kernel/arch/dreamcast/hardware/biosfont.c index c6a2b61..8536b99 100644 --- a/kernel/arch/dreamcast/hardware/biosfont.c +++ b/kernel/arch/dreamcast/hardware/biosfont.c @@ -4,10 +4,13 @@ Copyright (C) 2000-2002 Dan Potter Japanese code Copyright (C) Kazuaki Matsumoto - */ + Copyright (C) 2017 Donald Haase +*/ #include <assert.h> #include <dc/biosfont.h> +#include <dc/video.h> +#include <kos/dbglog.h> /* @@ -23,10 +26,12 @@ All the Japanese code is by Kazuaki Matsumoto. Foreground/background color switching based on code by Chilly Willy. +Expansion to 4 and 8 bpp by Donald Haase. + */ /* Our current conversion mode */ -static int bfont_code_mode = BFONT_CODE_ISO8859_1; +static uint8 bfont_code_mode = BFONT_CODE_ISO8859_1; /* Current colors/pixel format. Default to white foreground, black background and 16-bit drawing, so the default behavior doesn't change from what it has @@ -36,12 +41,11 @@ static uint32 bfont_bgcolor = 0x00000000; static int bfont_32bit = 0; /* Select an encoding for Japanese (or disable) */ -void bfont_set_encoding(int enc) { - if(enc < BFONT_CODE_ISO8859_1 || enc > BFONT_CODE_SJIS) { - assert_msg(0, "Unknown bfont encoding mode"); - } - - bfont_code_mode = enc; +void bfont_set_encoding(uint8 enc) { + if(enc <= BFONT_CODE_RAW) + bfont_code_mode = enc; + else + assert_msg(0, "Unknown bfont encoding mode"); } /* Set the foreground color and return the old color */ @@ -58,7 +62,9 @@ uint32 bfont_set_background_color(uint32 c) { return rv; } -/* Set the font to draw in 32 or 16 bit mode */ +/* 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. */ int bfont_set_32bit_mode(int on) { int rv = bfont_32bit; bfont_32bit = !!on; @@ -79,9 +85,8 @@ __asm__(" .text\n" "syscall_b4:\n" " .long 0x8c0000b4\n"); - /* Shift-JIS -> JIS conversion */ -unsigned int sjis2jis(unsigned int sjis) { +uint32 sjis2jis(uint32 sjis) { unsigned int hib, lob; hib = (sjis >> 8) & 0xff; @@ -103,34 +108,31 @@ unsigned int sjis2jis(unsigned int sjis) { /* EUC -> JIS conversion */ -unsigned int euc2jis(unsigned int euc) { +uint32 euc2jis(uint32 euc) { return euc & ~0x8080; } /* Given an ASCII character, find it in the BIOS font if possible */ -uint8 *bfont_find_char(int ch) { - int index = -1; +uint8 *bfont_find_char(uint32 ch) { uint8 *fa = get_font_address(); + /* By default, map to a space */ + uint32 index = 72 << 2; /* 33-126 in ASCII are 1-94 in the font */ if(ch >= 33 && ch <= 126) index = ch - 32; /* 160-255 in ASCII are 96-161 in the font */ - if(ch >= 160 && ch <= 255) + else if(ch >= 160 && ch <= 255) index = ch - (160 - 96); - /* Map anything else to a space */ - if(index == -1) - index = 72 << 2; - - return fa + index * 36; + return fa + index * (BFONT_THIN_WIDTH*BFONT_HEIGHT/8); } /* JIS -> (kuten) -> address conversion */ -uint8 *bfont_find_char_jp(int ch) { +uint8 *bfont_find_char_jp(uint32 ch) { uint8 *fa = get_font_address(); - int ku, ten, kuten = 0; + uint32 ku, ten, kuten = 0; /* Do the requested code conversion */ switch(bfont_code_mode) { @@ -156,205 +158,136 @@ uint8 *bfont_find_char_jp(int ch) { kuten = (ku - 0x21) * 94 + ten - 0x21; } - return fa + (kuten + 144) * 72; + return fa + (kuten + 144) * (BFONT_WIDE_WIDTH*BFONT_HEIGHT/8); } /* Half-width kana -> address conversion */ -uint8 *bfont_find_char_jp_half(int ch) { +uint8 *bfont_find_char_jp_half(uint32 ch) { uint8 *fa = get_font_address(); - return fa + (32 + ch) * 36; + return fa + (32 + ch) * (BFONT_THIN_WIDTH*BFONT_HEIGHT/8); } -/* Draw half-width kana */ -void bfont_draw_thin(void *b, int bufwidth, int opaque, int c, int iskana) { - uint8 *ch; - uint16 word; - int x, y; - - if(iskana) - ch = bfont_find_char_jp_half(c); - else - ch = bfont_find_char(c); - - if(!bfont_32bit) { - uint16 *buffer = (uint16 *)b; - - for(y = 0; y < 24;) { - /* Do the first row */ - word = (((uint16)ch[0]) << 4) | ((ch[1] >> 4) & 0x0f); - - for(x = 0; x < 12; x++) { - if(word & (0x0800 >> x)) - *buffer = bfont_fgcolor; - else { - if(opaque) - *buffer = bfont_bgcolor; - } - - buffer++; +/* Draws one half-width row of a character to an output buffer of bit depth in bits per pixel */ +uint16 *bfont_draw_one_row(uint16 *b, uint16 word, uint8 opaque, uint32 fg, uint32 bg, uint8 bpp) { + uint8 x; + uint32 color = 0x0000; + uint16 write16 = 0x0000; + uint16 oldcolor = *b; + + if ((bpp == 4)||(bpp == 8)) { + /* For 4 or 8bpp we have to go 2 or 4 pixels at a time to properly write out in all cases. */ + uint8 bMask = (bpp==4) ? 0xf : 0xff; + uint8 pix = 16/bpp; + for(x = 0; x < BFONT_THIN_WIDTH; x++) { + if(x%pix == 0) { + oldcolor = *b; + write16 = 0x0000; } - - buffer += bufwidth - 12; - y++; - - /* Do the second row */ - word = ((((uint16)ch[1]) << 8) & 0xf00) | ch[2]; - - for(x = 0; x < 12; x++) { - if(word & (0x0800 >> x)) - *buffer = bfont_fgcolor; - else { - if(opaque) - *buffer = bfont_bgcolor; - } - - buffer++; + + if(word & (0x0800 >> x)) write16 |= fg<<(bpp*(x%pix)); + else { + if(opaque) write16 |= bg<<(bpp*(x%pix)); + else write16 |= oldcolor&(bMask<<(bpp*(x%pix))); } - - buffer += bufwidth - 12; - y++; - - ch += 3; - } + if(x%pix == (pix-1)) *b++ = write16; + } } - else { - uint32 *buffer = (uint32 *)b; - - for(y = 0; y < 24;) { - /* Do the first row */ - word = (((uint16)ch[0]) << 4) | ((ch[1] >> 4) & 0x0f); - - for(x = 0; x < 12; x++) { - if(word & (0x0800 >> x)) - *buffer = bfont_fgcolor; - else { - if(opaque) - *buffer = bfont_bgcolor; - } - - buffer++; - } - - buffer += bufwidth - 12; - y++; - - /* Do the second row */ - word = ((((uint16)ch[1]) << 8) & 0xf00) | ch[2]; - - for(x = 0; x < 12; x++) { - if(word & (0x0800 >> x)) - *buffer = bfont_fgcolor; - else { - if(opaque) - *buffer = bfont_bgcolor; - } - - buffer++; + else {/* 16 or 32 */ + + for(x = 0; x < BFONT_THIN_WIDTH; x++, b++) { + if(word & (0x0800 >> x)) + color = fg; + else { + if(opaque) color = bg; + else continue; } - - buffer += bufwidth - 12; - y++; - - ch += 3; + if(bpp==16) *b = color & 0xffff; + else if(bpp == 32) {*(uint32 *)b = color; b++;} } } + + return b; } -/* Compat function */ -void bfont_draw(void *buffer, int bufwidth, int opaque, int c) { - bfont_draw_thin(buffer, bufwidth, opaque, c, 0); -} - -/* Draw wide character */ -void bfont_draw_wide(void *b, int bufwidth, int opaque, int c) { - uint8 *ch = bfont_find_char_jp(c); - uint16 word; - int x, y; - - if(!bfont_32bit) { - uint16 *buffer = (uint16 *)b; - - for(y = 0; y < 24;) { - /* Do the first row */ - word = (((uint16)ch[0]) << 4) | ((ch[1] >> 4) & 0x0f); - - for(x = 0; x < 12; x++) { - if(word & (0x0800 >> x)) - *buffer = bfont_fgcolor; - else { - if(opaque) - *buffer = bfont_bgcolor; - } - - buffer++; - } - - word = ((((uint16)ch[1]) << 8) & 0xf00) | ch[2]; - - for(x = 0; x < 12; x++) { - if(word & (0x0800 >> x)) - *buffer = bfont_fgcolor; - else { - if(opaque) - *buffer = bfont_bgcolor; - } - - buffer++; - } - - buffer += bufwidth - 24; - y++; - - ch += 3; - } +unsigned char bfont_draw_ex(uint8 *buffer, uint32 bufwidth, uint32 fg, uint32 bg, uint8 bpp, uint8 opaque, uint32 c, uint8 wide, uint8 iskana) { + uint8 *ch; + uint16 word; + uint8 y; + + /* If they're requesting a wide char and in the wrong format, kick this out */ + if (wide && (bfont_code_mode == BFONT_CODE_ISO8859_1)) { + dbglog(DBG_ERROR, "bfont_draw_ex: can't draw wide in bfont mode %d\n", bfont_code_mode); + return 0; } + + /* Just making sure we can draw the character we want to */ + if (bufwidth < (uint32)(BFONT_THIN_WIDTH*(wide+1))) { + dbglog(DBG_ERROR, "bfont_draw_ex: buffer is too small to draw into\n"); + return 0; + } + + /* Translate the character */ + if (bfont_code_mode == BFONT_CODE_RAW) + ch = get_font_address() + c; + else if (wide && ((bfont_code_mode == BFONT_CODE_EUC) || (bfont_code_mode == BFONT_CODE_SJIS))) + ch = bfont_find_char_jp(c); else { - uint32 *buffer = (uint32 *)b; - - for(y = 0; y < 24;) { - /* Do the first row */ - word = (((uint16)ch[0]) << 4) | ((ch[1] >> 4) & 0x0f); - - for(x = 0; x < 12; x++) { - if(word & (0x0800 >> x)) - *buffer = bfont_fgcolor; - else { - if(opaque) - *buffer = bfont_bgcolor; - } - - buffer++; - } - - word = ((((uint16)ch[1]) << 8) & 0xf00) | ch[2]; - - for(x = 0; x < 12; x++) { - if(word & (0x0800 >> x)) - *buffer = bfont_fgcolor; - else { - if(opaque) - *buffer = bfont_bgcolor; - } - - buffer++; - } + if(iskana) + ch = bfont_find_char_jp_half(c); + else + ch = bfont_find_char(c); + } + + /* Increment over the height of the font. 3bytes at a time (2 thin or 1 wide row) */ + for(y = 0; y < BFONT_HEIGHT; y+= (2-wide),ch+=((BFONT_THIN_WIDTH*2)/8)) { + /* Do the first row, or half row */ + word = (((uint16)ch[0]) << 4) | ((ch[1] >> 4) & 0x0f); + buffer = (uint8*)bfont_draw_one_row((uint16*)buffer, word, opaque, fg, bg, bpp); + + /* If we're thin, increment to next row, otherwise continue the row */ + if(!wide) buffer += ((bufwidth - BFONT_THIN_WIDTH)*bpp)/8; + + /* Do the second row, or second half */ + word = ((((uint16)ch[1]) << 8) & 0xf00) | ch[2]; + + buffer = (uint8*)bfont_draw_one_row((uint16*)buffer, word, opaque, fg, bg, bpp); + + /* Increment to the next row. */ + if(!wide) buffer += ((bufwidth - BFONT_THIN_WIDTH)*bpp)/8; + else buffer += ((bufwidth - BFONT_WIDE_WIDTH)*bpp)/8; + } + + /* Return the horizontal distance covered in bytes */ + if (wide) + return (BFONT_WIDE_WIDTH*bpp)/8; + else + return (BFONT_THIN_WIDTH*bpp)/8; +} - buffer += bufwidth - 24; - y++; +/* Draw half-width kana */ +unsigned char bfont_draw_thin(void *b, uint32 bufwidth, uint8 opaque, uint32 c, uint8 iskana) { + return bfont_draw_ex((uint8 *)b, bufwidth, bfont_fgcolor, bfont_bgcolor, (bfont_32bit ? (sizeof (uint32)) : (sizeof (uint16))) << 3, opaque, c, 0, iskana); +} - ch += 3; - } - } +/* Compat function */ +unsigned char bfont_draw(void *buffer, uint32 bufwidth, uint8 opaque, uint32 c) { + return bfont_draw_ex((uint8 *)buffer, bufwidth, bfont_fgcolor, bfont_bgcolor, (bfont_32bit ? (sizeof (uint32)) : (sizeof (uint16))) << 3, opaque, c, 0, 0); } +/* Draw wide character */ +unsigned char bfont_draw_wide(void *b, uint32 bufwidth, uint8 opaque, uint32 c) { + return bfont_draw_ex((uint8 *)b, bufwidth, bfont_fgcolor, bfont_bgcolor, (bfont_32bit ? (sizeof (uint32)) : (sizeof (uint16))) << 3, opaque, c, 1, 0); +} /* Draw string of full-width (wide) and half-width (thin) characters Note that this handles the case of mixed encodings unless Japanese - support is disabled (BFONT_CODE_ISO8859_1). */ -void bfont_draw_str(void *b, int width, int opaque, char *str) { - uint16 nChr, nMask, nFlag; - int adv = bfont_32bit ? 48 : 24; /* Amount to advance, in bytes */ + support is disabled (BFONT_CODE_ISO8859_1). + XXX: Seems like this can be shrunk to use uint8 for nChr/Mask/Flag and + getting rid of nMask. + */ +void bfont_draw_str_ex(void *b, uint32 width, uint32 fg, uint32 bg, uint8 bpp, uint8 opaque, char *str) { + uint16 nChr, nMask, nFlag; uint8 *buffer = (uint8 *)b; while(*str) { @@ -390,20 +323,19 @@ void bfont_draw_str(void *b, int width, int opaque, char *str) { if(nFlag == 1) { str++; nChr = (nChr << 8) | (*str & 0xff); - bfont_draw_wide(buffer, width, opaque, nChr); - buffer += adv + adv; - } - else { - bfont_draw_thin(buffer, width, opaque, nChr, 1); - buffer += adv; + buffer += bfont_draw_ex(buffer, width, fg, bg, bpp, opaque, nChr, 1, 0); } + else + buffer += bfont_draw_ex(buffer, width, fg, bg, bpp, opaque, nChr, 0, 1); } - else { - bfont_draw_thin(buffer, width, opaque, nChr, 0); - buffer += adv; - } + else + buffer += bfont_draw_ex(buffer, width, fg, bg, bpp, opaque, nChr, 0, 0); str++; } } +void bfont_draw_str(void *b, uint32 width, uint8 opaque, char *str) { + bfont_draw_str_ex(b, width, bfont_fgcolor, bfont_bgcolor, (bfont_32bit ? (sizeof (uint32)) : (sizeof (uint16))) << 3, opaque, str); +} + diff --git a/kernel/arch/dreamcast/include/dc/biosfont.h b/kernel/arch/dreamcast/include/dc/biosfont.h index 7e92a10..043fb09 100644 --- a/kernel/arch/dreamcast/include/dc/biosfont.h +++ b/kernel/arch/dreamcast/include/dc/biosfont.h @@ -3,6 +3,7 @@ dc/biosfont.h (c)2000-2001 Dan Potter Japanese Functions (c)2002 Kazuaki Matsumoto + (c)2017 Donald Haase */ @@ -15,6 +16,7 @@ \author Dan Potter \author Kazuaki Matsumoto + \author Donald Haase */ #ifndef __DC_BIOSFONT_H @@ -25,6 +27,60 @@ __BEGIN_DECLS #include <arch/types.h> +/** \defgroup bfont_size Dimensions of the Bios Font + @{ +*/ +#define BFONT_THIN_WIDTH 12 /**< \brief Width of Thin Font (ISO8859_1, half-JP) */ +#define BFONT_WIDE_WIDTH BFONT_THIN_WIDTH * 2 /**< \brief Width of Wide Font (full-JP) */ +#define BFONT_HEIGHT 24 /**< \brief Height of All Fonts */ +/** @} */ + +#define JISX_0208_ROW_SIZE 94 +/** \defgroup bfont_indecies Structure of the Bios Font + @{ +*/ +#define BFONT_NARROW_START 0 /**< \brief Start of Narrow Characters in Font Block */ ...<truncated>... hooks/post-receive -- A pseudo Operating System for the Dreamcast. |