| 1 |
/***************************************************************************** |
| 2 |
|
| 3 |
ui_font.c |
| 4 |
|
| 5 |
NMAMEĹú{ęśńđˇéÖđńľÜˇB |
| 6 |
|
| 7 |
*****************************************************************************/ |
| 8 |
|
| 9 |
#include "driver.h" |
| 10 |
#include "osd_pal.h" |
| 11 |
|
| 12 |
#ifdef JAPANESE |
| 13 |
|
| 14 |
static UINT16 _uifonttable[65536]; |
| 15 |
static UINT32 colortable[MAX_COLORTABLE]; |
| 16 |
|
| 17 |
/****************************************************************************/ |
| 18 |
|
| 19 |
static UINT16 uifont_buildtable(UINT16 code) |
| 20 |
{ |
| 21 |
UINT8 c1, c2; |
| 22 |
|
| 23 |
c1 = (code >> 8) & 0xff; |
| 24 |
c2 = code & 0xff; |
| 25 |
|
| 26 |
if (code >= 0x8140 && code <= 0x9ffc) |
| 27 |
{ |
| 28 |
code = ((c1 - 0x81) << 8) + (c2 - 0x40); |
| 29 |
} |
| 30 |
else if (code >= 0xe040 && code <= 0xfcfc) |
| 31 |
{ |
| 32 |
code = ((c1 - 0xe0 + (0xa0 - 0x81)) << 8) + (c2 - 0x40); |
| 33 |
} |
| 34 |
else |
| 35 |
return 0x60; |
| 36 |
|
| 37 |
return (code - ((code >> 8) & 0xff) * 0x40); |
| 38 |
} |
| 39 |
|
| 40 |
|
| 41 |
int uifont_buildfont(void) |
| 42 |
{ |
| 43 |
static unsigned char fontdata6x12[] = |
| 44 |
{ |
| 45 |
#include "font\h8x12.dat" |
| 46 |
}; |
| 47 |
static unsigned char fontdata12x12[] = |
| 48 |
{ |
| 49 |
#include "font\z16x12.dat" |
| 50 |
}; |
| 51 |
static struct GfxLayout fontlayout6x12 = |
| 52 |
{ |
| 53 |
6,12, /* 6*12 characters */ |
| 54 |
256, /* 128 characters */ |
| 55 |
1, /* 1 bit per pixel */ |
| 56 |
{ 0 }, |
| 57 |
{ 0, 1, 2, 3, 4, 5, 6, 7 }, /* straightforward layout */ |
| 58 |
{ 0*8, 1*8, 2*8, 3*8, 4*8, 5*8, 6*8, 7*8, 8*8, 9*8, 10*8, 11*8 }, |
| 59 |
8*12 /* every char takes 8 consecutive bytes */ |
| 60 |
}; |
| 61 |
static struct GfxLayout fontlayout12x12 = |
| 62 |
{ |
| 63 |
12,12, /* 6*12 characters */ |
| 64 |
256, /* 128 characters */ |
| 65 |
1, /* 1 bit per pixel */ |
| 66 |
{ 0 }, |
| 67 |
{ 0,0, 1,1, 2,2, 3,3, 4,4, 5,5, 6,6, 7,7 }, /* straightforward layout */ |
| 68 |
{ 0*8, 1*8, 2*8, 3*8, 4*8, 5*8, 6*8, 7*8, 8*8, 9*8, 10*8, 11*8 }, |
| 69 |
8*12 /* every char takes 8 consecutive bytes */ |
| 70 |
}; |
| 71 |
static struct GfxLayout fontlayout6x24 = |
| 72 |
{ |
| 73 |
6,24, /* 6*12 characters */ |
| 74 |
256, /* 128 characters */ |
| 75 |
1, /* 1 bit per pixel */ |
| 76 |
{ 0 }, |
| 77 |
{ 0, 1, 2, 3, 4, 5, 6, 7 }, /* straightforward layout */ |
| 78 |
{ 0*8,0*8, 1*8,1*8, 2*8,2*8, 3*8,3*8, 4*8,4*8, 5*8,5*8, |
| 79 |
6*8,6*8, 7*8,7*8, 8*8,8*8, 9*8,9*8, 10*8,10*8, 11*8,11*8 }, |
| 80 |
8*12 /* every char takes 8 consecutive bytes */ |
| 81 |
}; |
| 82 |
static struct GfxLayout fontlayout12x12z = |
| 83 |
{ |
| 84 |
12,12, |
| 85 |
(0x9fff - 0x8140) + (0xfcff - 0xe040) + 1, |
| 86 |
1, |
| 87 |
{ 0 }, |
| 88 |
{ 0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15 }, |
| 89 |
{ 0*16,1*16,2*16,3*16,4*16,5*16,6*16,7*16,8*16,9*16,10*16,11*16 }, |
| 90 |
16*12 |
| 91 |
}; |
| 92 |
static struct GfxLayout fontlayout24x12z = |
| 93 |
{ |
| 94 |
24,12, |
| 95 |
(0x9fff - 0x8140) + (0xfcff - 0xe040) + 1, |
| 96 |
1, |
| 97 |
{ 0 }, |
| 98 |
{ 0,0, 1,1, 2,2, 3,3, 4,4, 5,5, 6,6, 7,7, |
| 99 |
8,8, 9,9, 10,10, 11,11, 12,12, 13,13, 14,14, 15,15 }, |
| 100 |
{ 0*16,1*16,2*16,3*16,4*16,5*16,6*16,7*16,8*16,9*16,10*16,11*16 }, |
| 101 |
16*12 |
| 102 |
}; |
| 103 |
static struct GfxLayout fontlayout12x24z = |
| 104 |
{ |
| 105 |
12,24, |
| 106 |
(0x9fff - 0x8140) + (0xfcff - 0xe040) + 1, |
| 107 |
1, |
| 108 |
{ 0 }, |
| 109 |
{ 0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15 }, |
| 110 |
{ 0*16,0*16, 1*16,1*16, 2*16,2*16, 3*16,3*16, 4*16,4*16, 5*16,5*16, |
| 111 |
6*16,6*16, 7*16,7*16, 8*16,8*16, 9*16,9*16, 10*16,10*16, 11*16,11*16 }, |
| 112 |
16*12 |
| 113 |
}; |
| 114 |
int i; |
| 115 |
|
| 116 |
Machine->uifont = 0; |
| 117 |
Machine->uifont2 = 0; |
| 118 |
|
| 119 |
switch_ui_orientation(NULL); |
| 120 |
|
| 121 |
if ((Machine->drv->video_attributes & VIDEO_PIXEL_ASPECT_RATIO_MASK) |
| 122 |
== VIDEO_PIXEL_ASPECT_RATIO_1_2) |
| 123 |
{ |
| 124 |
if (Machine->gamedrv->flags & ORIENTATION_SWAP_XY) |
| 125 |
{ |
| 126 |
if ((Machine->uifont = decodegfx(fontdata6x12, &fontlayout6x24))) |
| 127 |
{ |
| 128 |
Machine->uifont->colortable = colortable; |
| 129 |
Machine->uifont->total_colors = 2; |
| 130 |
Machine->uifontwidth = 6; |
| 131 |
Machine->uifontheight = 24; |
| 132 |
} |
| 133 |
else |
| 134 |
return 0; |
| 135 |
|
| 136 |
if ((Machine->uifont2 = decodegfx(fontdata12x12, &fontlayout12x24z))) |
| 137 |
{ |
| 138 |
Machine->uifont2->colortable = colortable; |
| 139 |
Machine->uifont2->total_colors = 2; |
| 140 |
Machine->uifontwidth2 = 12; |
| 141 |
Machine->uifontheight2 =24; |
| 142 |
} |
| 143 |
else |
| 144 |
return 0; |
| 145 |
} |
| 146 |
else |
| 147 |
{ |
| 148 |
if ((Machine->uifont = decodegfx(fontdata6x12, &fontlayout12x12))) |
| 149 |
{ |
| 150 |
Machine->uifont->colortable = colortable; |
| 151 |
Machine->uifont->total_colors = 2; |
| 152 |
Machine->uifontwidth = 12; |
| 153 |
Machine->uifontheight = 12; |
| 154 |
} |
| 155 |
else |
| 156 |
return 0; |
| 157 |
|
| 158 |
if ((Machine->uifont2 = decodegfx(fontdata12x12, &fontlayout24x12z))) |
| 159 |
{ |
| 160 |
Machine->uifont2->colortable = colortable; |
| 161 |
Machine->uifont2->total_colors = 2; |
| 162 |
Machine->uifontwidth2 = 24; |
| 163 |
Machine->uifontheight2 =12; |
| 164 |
} |
| 165 |
else |
| 166 |
return 0; |
| 167 |
} |
| 168 |
} |
| 169 |
else |
| 170 |
{ |
| 171 |
if ((Machine->uifont = decodegfx(fontdata6x12, &fontlayout6x12))) |
| 172 |
{ |
| 173 |
Machine->uifont->colortable = colortable; |
| 174 |
Machine->uifont->total_colors = 2; |
| 175 |
Machine->uifontwidth = 6; |
| 176 |
Machine->uifontheight = 12; |
| 177 |
} |
| 178 |
else |
| 179 |
return 0; |
| 180 |
|
| 181 |
if ((Machine->uifont2 = decodegfx(fontdata12x12, &fontlayout12x12z))) |
| 182 |
{ |
| 183 |
Machine->uifont2->colortable = colortable; |
| 184 |
Machine->uifont2->total_colors = 2; |
| 185 |
Machine->uifontwidth2 = 12; |
| 186 |
Machine->uifontheight2 =12; |
| 187 |
} |
| 188 |
else |
| 189 |
return 0; |
| 190 |
} |
| 191 |
|
| 192 |
switch_true_orientation(NULL); |
| 193 |
|
| 194 |
for (i = 0x4081; i < 0xfffc; i++) |
| 195 |
_uifonttable[i] = uifont_buildtable(i) + 256; |
| 196 |
|
| 197 |
return 1; |
| 198 |
} |
| 199 |
|
| 200 |
|
| 201 |
void uifont_freefont(void) |
| 202 |
{ |
| 203 |
if (Machine->uifont2) |
| 204 |
{ |
| 205 |
freegfx(Machine->uifont2); |
| 206 |
Machine->uifont2 = 0; |
| 207 |
} |
| 208 |
if (Machine->uifont) |
| 209 |
{ |
| 210 |
freegfx(Machine->uifont); |
| 211 |
Machine->uifont = 0; |
| 212 |
} |
| 213 |
} |
| 214 |
|
| 215 |
#define ISSJIS1(c) ((c >= 0x81 && c <= 0x9f) || (c >= 0xe0 && c <= 0xfc)) |
| 216 |
#define ISSJIS2(c) ((c >= 0x40 && c <= 0xfc) && (c != 0x7f)) |
| 217 |
|
| 218 |
int uifont_decodechar(unsigned char *s, unsigned short *code) |
| 219 |
{ |
| 220 |
unsigned char c1 = *(unsigned char *)s; |
| 221 |
unsigned char c2 = *(unsigned char *)(s + 1); |
| 222 |
|
| 223 |
if (ISSJIS1(c1) && ISSJIS2(c2)) |
| 224 |
{ |
| 225 |
*code = _uifonttable[(c1 << 8) | c2]; |
| 226 |
|
| 227 |
if (*code == 0) |
| 228 |
*code = _uifonttable[0x817f]; |
| 229 |
|
| 230 |
return 2; |
| 231 |
} |
| 232 |
|
| 233 |
*code = c1; |
| 234 |
return 1; |
| 235 |
} |
| 236 |
|
| 237 |
#undef ISSJIS1 |
| 238 |
#undef ISSJIS2 |
| 239 |
|
| 240 |
#else |
| 241 |
|
| 242 |
int uifont_decodechar(unsigned char *s, unsigned short *code) |
| 243 |
{ |
| 244 |
*code = *s; |
| 245 |
return 1; |
| 246 |
} |
| 247 |
|
| 248 |
#endif |
| 249 |
|
| 250 |
int uifont_drawfont(struct mame_bitmap *bitmap, const char *s, int sx, |
| 251 |
int sy, int color) |
| 252 |
{ |
| 253 |
extern int iTrans; |
| 254 |
extern int iTransOpt; |
| 255 |
int x, y, wrapped, next_sy, increment, uifontwidth; |
| 256 |
int white = 0; |
| 257 |
unsigned short code; |
| 258 |
unsigned char *c; |
| 259 |
struct GfxElement *uifont; |
| 260 |
c = (unsigned char *)s; |
| 261 |
x = sx; |
| 262 |
y = sy; |
| 263 |
code = 0; |
| 264 |
next_sy = 0; |
| 265 |
|
| 266 |
if (color == UI_COLOR_INVERSE) |
| 267 |
{ |
| 268 |
white = Machine->uifont->colortable[FONT_COLOR_NORMAL]; |
| 269 |
Machine->uifont->colortable[FONT_COLOR_NORMAL] = Machine->uifont->colortable[BUTTON_COLOR_YELLOW]; |
| 270 |
} |
| 271 |
|
| 272 |
while (*c) |
| 273 |
{ |
| 274 |
wrapped = 0; |
| 275 |
|
| 276 |
increment = uifont_decodechar(c, &code); |
| 277 |
|
| 278 |
if (*c == '\n') |
| 279 |
{ |
| 280 |
x = sx; |
| 281 |
y += Machine->uifontheight + 1; |
| 282 |
next_sy += Machine->uifontheight; |
| 283 |
c++; |
| 284 |
continue; |
| 285 |
} |
| 286 |
else |
| 287 |
{ |
| 288 |
#ifdef JAPANESE |
| 289 |
if (code > 0x00ff) |
| 290 |
{ |
| 291 |
uifont = Machine->uifont2; |
| 292 |
uifontwidth = Machine->uifontwidth * 2; |
| 293 |
} |
| 294 |
else |
| 295 |
#endif |
| 296 |
{ |
| 297 |
uifont = Machine->uifont; |
| 298 |
uifontwidth = Machine->uifontwidth; |
| 299 |
} |
| 300 |
} |
| 301 |
|
| 302 |
if (y >= Machine->uiheight) |
| 303 |
return next_sy; |
| 304 |
|
| 305 |
if (!wrapped) |
| 306 |
{ |
| 307 |
int col = 0; |
| 308 |
|
| 309 |
#ifdef JAPANESE |
| 310 |
if (code > 0x00ff) |
| 311 |
{ |
| 312 |
code -= 256; |
| 313 |
if (code == 0x0080 || code == 0x00a9) col = BUTTON_COLOR_RED; |
| 314 |
else if (code == 0x0081 || code == 0x00aa) col = BUTTON_COLOR_YELLOW; |
| 315 |
else if (code == 0x0082 || code == 0x00ab) col = BUTTON_COLOR_GREEN; |
| 316 |
else if (code == 0x0083 || code == 0x00ac) col = BUTTON_COLOR_BLUE; |
| 317 |
else if (code == 0x0086 || code == 0x00ad) col = BUTTON_COLOR_PURPLE; |
| 318 |
else if (code == 0x0085 || code == 0x00ae) col = BUTTON_COLOR_PINK; |
| 319 |
else if (code == 0x00af) col = BUTTON_COLOR_AQUA; |
| 320 |
|
| 321 |
if (col) |
| 322 |
{ |
| 323 |
white = Machine->uifont->colortable[FONT_COLOR_NORMAL]; |
| 324 |
Machine->uifont->colortable[FONT_COLOR_NORMAL] = Machine->uifont->colortable[col]; |
| 325 |
} |
| 326 |
} |
| 327 |
#endif |
| 328 |
|
| 329 |
drawgfx(bitmap, |
| 330 |
uifont, |
| 331 |
code, |
| 332 |
UI_COLOR_NORMAL, |
| 333 |
0, |
| 334 |
0, |
| 335 |
x + Machine->uixmin, |
| 336 |
y + Machine->uiymin, |
| 337 |
0, |
| 338 |
(iTransOpt && iTrans) ? TRANSPARENCY_FONT : TRANSPARENCY_NONE, |
| 339 |
0); |
| 340 |
|
| 341 |
x += uifontwidth; |
| 342 |
|
| 343 |
while (increment) |
| 344 |
{ |
| 345 |
c++; |
| 346 |
increment--; |
| 347 |
} |
| 348 |
if (col) |
| 349 |
Machine->uifont->colortable[FONT_COLOR_NORMAL] = white; |
| 350 |
} |
| 351 |
} |
| 352 |
|
| 353 |
if (color == UI_COLOR_INVERSE) |
| 354 |
Machine->uifont->colortable[FONT_COLOR_NORMAL] = white; |
| 355 |
|
| 356 |
return next_sy; |
| 357 |
} |