diff options
Diffstat (limited to 'fmdsp/font.h')
-rw-r--r-- | fmdsp/font.h | 60 |
1 files changed, 60 insertions, 0 deletions
diff --git a/fmdsp/font.h b/fmdsp/font.h new file mode 100644 index 0000000..689df04 --- /dev/null +++ b/fmdsp/font.h @@ -0,0 +1,60 @@ +#ifndef MYON_FMDSP_FONT_H_INCLUDED +#define MYON_FMDSP_FONT_H_INCLUDED + +#include <stdint.h> +#include <stdbool.h> + +#ifdef __cplusplus +extern "C" { +#endif + +static inline bool sjis_is_mb_start(uint8_t c) { + if (0x81 <= c && c <= 0x9f) return true; + if (0xe0 <= c && c <= 0xef) return true; + return false; +} + +static inline bool jis_is_halfwidth(uint16_t jis) { + return (jis>>8) == 0x29; +} + +static inline uint16_t sjis2jis(uint8_t sjis_1st, uint8_t sjis_2nd) { + uint16_t jis; + if (sjis_1st >= 0xe0) sjis_1st -= 0x40; + sjis_1st -= 0x81; + jis = sjis_1st << 9; + if (sjis_2nd >= 0x80) sjis_2nd--; + if (sjis_2nd >= 0x9e) { + jis |= 0x100 | (sjis_2nd - 0x9e); + } else { + jis |= (sjis_2nd - 0x40); + } + jis += 0x2121; + return jis; +} + +enum fmdsp_font_type { + FMDSP_FONT_ANK, + FMDSP_FONT_JIS_LEFT, + FMDSP_FONT_JIS_RIGHT +}; + +struct fmdsp_font { + const void *(* get)(const struct fmdsp_font *font, + uint16_t addr, enum fmdsp_font_type type); + const void *data; + uint8_t width_half; + uint8_t height; +}; + +enum { + FONT_ROM_FILESIZE = 0x46800 +}; + +void fmdsp_font_from_font_rom(struct fmdsp_font *font, const void *data); + +#ifdef __cplusplus +} +#endif + +#endif // MYON_FMDSP_FONT_H_INCLUDED |