File:  [RetroPC.NET] / mkfont32 / mkfnt68.c
Revision 1.1: download - view: text, annotated - select for diffs
Thu Jun 10 12:11:46 2004 JST (21 years, 4 months ago) by yui
Branches: MAIN
CVS tags: HEAD
fix x68k fonts (T.Yui)

#include	"compiler.h"
#include	"parts.h"
#include	"dosio.h"
#include	"fontmng.h"
#include	"mkfnt.h"
#include	"fntdat.h"

static const char cgromdat[] = "CGROM.DAT";

//	@SBSXEXETEQAKBLBSBTLFVTFFCASOSI
//	DED1D2D3D4WKSNEBCNEMSBEC¨©ͺ«
//	@Ih”“•fij–{C|D^
//	‚O‚P‚Q‚R‚S‚T‚U‚V‚W‚XGFƒ„H
//	—‚`‚a‚b‚c‚d‚e‚f‚g‚h‚i‚j‚k‚l‚m‚n
//	‚o‚p‚q‚r‚s‚t‚u‚v‚w‚x‚ymnOQ
//	e‚‚‚‚ƒ‚„‚…‚†‚‡‚ˆ‚‰‚Š‚‹‚Œ‚‚Ž‚
//	‚‚‘‚’‚“‚”‚•‚–‚—‚˜‚™‚šobpP@
//	_`b@@@‚π‚Ÿ‚‘‚£‚₯‚§‚α‚γ‚ε‚Α
//	@‚ ‚’‚€‚¦‚¨‚©‚«‚­‚―‚±‚³‚΅‚·‚Ή‚»
//	@BuvAEƒ’ƒ@ƒBƒDƒFƒHƒƒƒ…ƒ‡ƒb
//	[ƒAƒCƒEƒGƒIƒJƒLƒNƒPƒRƒTƒVƒXƒZƒ\
//	ƒ^ƒ`ƒcƒeƒgƒiƒjƒkƒlƒmƒnƒqƒtƒwƒzƒ}
//	ƒ~ƒ€ƒƒ‚ƒ„ƒ†ƒˆƒ‰ƒŠƒ‹ƒŒƒƒƒ“JK
//	‚½‚Ώ‚Β‚Δ‚Ζ‚Θ‚Ι‚Κ‚Λ‚Μ‚Ν‚Π‚Σ‚Φ‚Ω‚ά
//	‚έ‚ή‚ί‚ΰ‚β‚δ‚ζ‚η‚θ‚ι‚κ‚λ‚ν‚ρ@@

static const UINT16 x68kjistbl[256] = {
				0x2121,0x2121,0x2121,0x2121,0x2121,0x2121,0x2121,0x2121,
				0x2121,0x2121,0x2121,0x2121,0x2121,0x2121,0x2121,0x2121,
				0x2121,0x2121,0x2121,0x2121,0x2121,0x2121,0x2121,0x2121,
				0x2121,0x2121,0x2121,0x2121,0x222a,0x222b,0x222c,0x222d,
				0x2121,0x212a,0x2149,0x2174,0x2170,0x2173,0x2175,0x2147,
				0x214a,0x214b,0x2176,0x215c,0x2124,0x215d,0x2125,0x213f,
				0x2330,0x2331,0x2332,0x2333,0x2334,0x2335,0x2336,0x2337,
				0x2338,0x2339,0x2128,0x2127,0x2163,0x2161,0x2164,0x2129,
				0x2177,0x2341,0x2342,0x2343,0x2344,0x2345,0x2346,0x2347,
				0x2348,0x2349,0x234a,0x234b,0x234c,0x234d,0x234e,0x234f,
				0x2350,0x2351,0x2352,0x2353,0x2354,0x2355,0x2356,0x2357,
				0x2358,0x2359,0x235a,0x214e,0x216f,0x214f,0x2130,0x2132,
				0x2146,0x2361,0x2362,0x2363,0x2364,0x2365,0x2366,0x2367,
				0x2368,0x2369,0x236a,0x236b,0x236c,0x236d,0x236e,0x236f,
				0x2370,0x2371,0x2372,0x2373,0x2374,0x2375,0x2376,0x2377,
				0x2378,0x2379,0x237a,0x2150,0x2143,0x2151,0x2131,0x2121,
				0x2121,0x2121,0x2121,0x2121,0x2121,0x2121,0x2472,0x2421,
				0x2423,0x2425,0x2427,0x2429,0x2463,0x2465,0x2467,0x2443,
				0x2121,0x2422,0x2424,0x2426,0x2428,0x242a,0x242b,0x242d,
				0x242f,0x2431,0x2433,0x2435,0x2437,0x2439,0x243b,0x243d,
				0x2121,0x2123,0x2156,0x2157,0x2122,0x2126,0x2572,0x2521,
				0x2523,0x2525,0x2527,0x2529,0x2563,0x2565,0x2567,0x2543,
				0x213c,0x2522,0x2524,0x2526,0x2528,0x252a,0x252b,0x252d,
				0x252f,0x2531,0x2533,0x2535,0x2537,0x2539,0x253b,0x253d,
				0x253f,0x2541,0x2544,0x2546,0x2548,0x254a,0x254b,0x254c,
				0x254d,0x254e,0x254f,0x2552,0x2555,0x2558,0x255b,0x255e,
				0x255f,0x2560,0x2561,0x2562,0x2564,0x2566,0x2568,0x2569,
				0x256a,0x256b,0x256c,0x256d,0x256f,0x2573,0x212b,0x212c,
				0x243f,0x2441,0x2444,0x2446,0x2448,0x244a,0x244b,0x244c,
				0x244d,0x244e,0x244f,0x2452,0x2455,0x2458,0x245b,0x245e,
				0x245f,0x2460,0x2461,0x2462,0x2464,0x2466,0x2468,0x2469,
				0x246a,0x246b,0x246c,0x246d,0x246f,0x2473,0x2121,0x2121};


static void setjiscode(BYTE *ptr, void *fnt, const UINT16 *jis, UINT count,
															int sx, int sy) {

	char	work[4];
	int		align;
	UINT	blocksize;
	UINT	sjis;
	FNTDAT	dat;
const BYTE	*p;
	BYTE	*q;
	int		width;
	int		height;
	UINT32	bit;
	int		i;

	align = (sx + 7) >> 3;
	blocksize = align * sy;
	work[2] = '\0';
	while(count) {
		count--;
		if (isjis83(*jis)) {
			sjis = jis2sjis(*jis);
			work[0] = (BYTE)(sjis >> 8);
			work[1] = (BYTE)sjis;
			dat = fontmng_get(fnt, work);
			if (dat) {
				width = min(dat->width, sx);
				height = min(dat->height, sy);
				p = (BYTE *)(dat + 1);
				q = ptr;
				while(height > 0) {
					height--;
					bit = 0;
					for (i=0; i<width; i++) {
						if (p[i]) {
							bit |= (0x80000000 >> i);
						}
					}
					for (i=0; i<align; i++) {
						*q++ = (BYTE)(bit >> 24);
						bit <<= 8;
					}
					p += dat->width;
				}
			}
		}
		ptr += blocksize;
		jis++;
	}
}

static void setjiscodes(BYTE *ptr, void *fnt, UINT16 h, int size) {

	UINT16	i;
	UINT16	jis[0x5e];

	h <<= 8;
	for (i=0; i<0x5e; i++) {
		jis[i] = (UINT16)(h + i + 0x21);
	}
	setjiscode(ptr, fnt, jis, 0x5e, size, size);
}

static void setjis(BYTE *ptr, void *fnt, int size) {

	UINT	align;
	UINT16	h;

	align = (size / 8) * size;
	align *= 0x5e;
	for (h=0x21; h<0x28; h++) {
		setjiscodes(ptr + ((h - 0x21) * align), fnt, h, size);
	}
	for (h=0x30; h<0x75; h++) {
		setjiscodes(ptr + ((h - 0x28) * align), fnt, h, size);
	}
}

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 += 0x3a800 + (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 += 0x3a800 + (from * 16);
	CopyMemory(ptr, fnt, 0x20 * 16);
}


void makex68kfont(const char *dirname, const TCHAR *fontface) {

	BYTE	*ptr;
	void	*fnt;
	char	path[MAX_PATH];
	FILEH	fh;
	BOOL	r;

	ptr = (BYTE *)_MALLOC(0xc0000, cgromdat);
	if (ptr == NULL) {
		goto mfnt_err1;
	}
	ZeroMemory(ptr, 0xc0000);

	// 16x16
	fnt = fontmng_create(16, 0, fontface);
	if (fnt != NULL) {
		setjis(ptr, fnt, 16);
		fontmng_destroy(fnt);
	}
	CopyMemory(ptr + 7*0x5e*32, jis28xxa, sizeof(jis28xxa));

	CopyMemory(ptr + 0x3a000 + 0x20*8, cmn_8 + 0x00*8, 0x60*8);
	CopyMemory(ptr + 0x3a000 + 0xa0*8, cmn_8 + 0x60*8, 0x40*8);
	CopyMemory(ptr + 0x3a000 + 0x00*8, x68k_8 + 0x00*8, 0x20*8);
	CopyMemory(ptr + 0x3a000 + 0x80*8, x68k_8 + 0x20*8, 0x20*8);
	CopyMemory(ptr + 0x3a000 + 0xe0*8, x68k_8 + 0x40*8, 0x20*8);

	fnt = fontmng_create(16, 0, fontface);
	if (fnt != NULL) {
		setank(ptr, fnt, 0x20, 0x7f);
		setank(ptr, fnt, 0xa1, 0xe0);
		fontmng_destroy(fnt);
	}
	patchank(ptr, x68k_16 + 0*32*16, 0x00);
	patchank(ptr, x68k_16 + 1*32*16, 0x80);
	patchank(ptr, x68k_16 + 2*32*16, 0xe0);

	// 12x12
	fnt = fontmng_create(12, 0, fontface);
	if (fnt != NULL) {
		setjiscode(ptr + 0x3b800, fnt, x68kjistbl, 256, 12, 12);
		fontmng_destroy(fnt);
	}
	CopyMemory(ptr + 0x3b800 + 0x01*24, x68k_12 + 0x00*24, 0x1b*24);
	CopyMemory(ptr + 0x3b800 + 0x80*24, x68k_12 + 0x1b*24, 0x03*24);

	// 12x24
	fnt = fontmng_create(24, FDAT_HALFWIDTH, fontface);
	if (fnt != NULL) {
		setjiscode(ptr + 0x3d000, fnt, x68kjistbl, 256, 12, 24);
		fontmng_destroy(fnt);
	}
	CopyMemory(ptr + 0x3d000 + 0x01*48, x68k_24 + 0x00*48, 0x1b*48);
	CopyMemory(ptr + 0x3d000 + 0x80*48, x68k_24 + 0x1b*48, 0x03*48);

	// 24x24
	fnt = fontmng_create(24, 0, fontface);
	if (fnt != NULL) {
		setjis(ptr + 0x40000, fnt, 24);
		fontmng_destroy(fnt);
	}
	CopyMemory(ptr + 0x40000 + 7*0x5e*72, jis28xx2, sizeof(jis28xx2));

	file_cpyname(path, dirname, sizeof(path));
	file_setseparator(path, sizeof(path));
	file_catname(path, cgromdat, sizeof(path));
	fh = file_create(path);
	if (fh == FILEH_INVALID) {
		goto mfnt_err2;
	}
	r = (file_write(fh, ptr, 0xc0000) == 0xc0000);
	file_close(fh);
	if (!r) {
		file_delete(path);
	}

mfnt_err2:
	_MFREE(ptr);

mfnt_err1:
	return;
}


RetroPC.NET-CVS <cvs@retropc.net>