aboutsummaryrefslogtreecommitdiff
path: root/fmdsp/font.h
blob: 689df0414328635c58e661df37d41a2d9a7242a8 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
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