#include "compiler.h"
#include "bmpdata.h"
#include "parts.h"
#include "dosio.h"
#include "fontmng.h"
#include "mkfnt.h"
#include "fntdat.h"
static const char fontrom[] = "FONT.ROM";
static void setank(BYTE *ptr, void *fnt, UINT from, UINT to) {
char work[2];
FNTDAT dat;
const BYTE *p;
BYTE *q;
int width;
int height;
BYTE bit;
int i;
ptr += 0x800 + (from * 16);
work[1] = '\0';
while(from < to) {
work[0] = (char)from;
dat = fontmng_get(fnt, work);
if (dat) {
width = min(dat->width, 8);
height = min(dat->height, 16);
p = (BYTE *)(dat + 1);
q = ptr;
while(height > 0) {
height--;
bit = 0;
for (i=0; i<width; i++) {
if (p[i]) {
bit |= (0x80 >> i);
}
}
*q++ = bit;
p += dat->width;
}
}
from++;
ptr += 16;
}
}
static void patchank(BYTE *ptr, const BYTE *fnt, UINT from) {
ptr += 0x800 + (from * 16);
CopyMemory(ptr, fnt, 0x20 * 16);
}
static void setjis(BYTE *ptr, void *fnt) {
char work[4];
UINT16 h;
UINT16 l;
UINT16 jis;
UINT sjis;
FNTDAT dat;
const BYTE *p;
BYTE *q;
int width;
int height;
UINT16 bit;
int i;
ptr += 0x1800;
work[2] = '\0';
for (h=0x2100; h<0x7d00; h+=0x100) {
ptr += 32;
for (l=0x21; l<0x7f; l++) {
jis = h + l;
if (isjis78(jis)) {
jis = jiscnv7890(jis);
sjis = jis2sjis(jis);
work[0] = (BYTE)(sjis >> 8);
work[1] = (BYTE)sjis;
dat = fontmng_get(fnt, work);
if (dat) {
width = min(dat->width, 16);
height = min(dat->height, 16);
p = (BYTE *)(dat + 1);
q = ptr;
while(height > 0) {
height--;
bit = 0;
for (i=0; i<width; i++) {
if (p[i]) {
bit |= (0x8000 >> i);
}
}
q[0] = (BYTE)(bit >> 8);
q[16] = (BYTE)bit;
p += dat->width;
q++;
}
}
}
ptr += 32;
}
ptr += 32;
}
}
static void patchextank(BYTE *dst, const BYTE *src,
UINT jish, UINT jisl, UINT count) {
UINT pos;
pos = (0x60 * (jish - 1)) + (jisl - 0x20);
dst += 0x1800 + (pos * 32);
do {
CopyMemory(dst, src, 16);
dst += 32;
src += 16;
} while(--count);
}
static void patchextfnt(BYTE *dst, const BYTE *src,
UINT jish, UINT jisl, UINT count) {
UINT pos;
UINT r;
pos = (0x60 * (jish - 1)) + (jisl - 0x20);
dst += 0x1800 + (pos * 32);
do {
r = 16;
do {
dst[0] = src[0];
dst[16] = src[1];
dst++;
src += 2;
} while(--r);
dst += 16;
} while(--count);
}
void makev98font(const char *dirname, const TCHAR *fontface) {
void *fnt;
BYTE *ptr;
char filename[MAX_PATH];
FILEH fh;
BOOL r;
fnt = fontmng_create(16, 0, fontface);
if (fnt == NULL) {
goto mfnt_err1;
}
ptr = (BYTE *)_MALLOC(288768, fontrom);
if (ptr == NULL) {
goto mfnt_err2;
}
ZeroMemory(ptr, 288768);
CopyMemory(ptr + 0x20*8, cmn_8 + 0x00*8, 0x60*8);
CopyMemory(ptr + 0xa0*8, cmn_8 + 0x60*8, 0x40*8);
CopyMemory(ptr + 0x00*8, pc98_8 + 0x00*8, 0x20*8);
CopyMemory(ptr + 0x80*8, pc98_8 + 0x20*8, 0x20*8);
CopyMemory(ptr + 0xe0*8, pc98_8 + 0x40*8, 0x20*8);
setank(ptr, fnt, 0x20, 0x7f);
setank(ptr, fnt, 0xa1, 0xe0);
patchank(ptr, pc98_16 + 0*32*16, 0x00);
patchank(ptr, pc98_16 + 1*32*16, 0x80);
patchank(ptr, pc98_16 + 2*32*16, 0xe0);
setjis(ptr, fnt);
patchextank(ptr, jis29xx, 0x09, 0x21, 0x5e);
patchextank(ptr, jis2axx, 0x0a, 0x21, 0x5e);
patchextank(ptr, jis2bxx, 0x0b, 0x21, 0x5e);
patchextfnt(ptr, jis2cxx, 0x0c, 0x24, 0x4c);
file_cpyname(filename, dirname, sizeof(filename));
file_setseparator(filename, sizeof(filename));
file_catname(filename, fontrom, sizeof(filename));
fh = file_create(filename);
if (fh == FILEH_INVALID) {
goto mfnt_err3;
}
r = (file_write(fh, ptr, 288768) == 288768);
file_close(fh);
if (!r) {
file_delete(filename);
}
mfnt_err3:
_MFREE(ptr);
mfnt_err2:
fontmng_destroy(fnt);
mfnt_err1:
return;
}
RetroPC.NET-CVS <cvs@retropc.net>