mirror of
https://github.com/dschmenk/PLASMA.git
synced 2026-04-21 22:17:15 +00:00
Convert Apple II ROM font into slim proportional font
This commit is contained in:
@@ -12,6 +12,7 @@ DHGRSHOW = dhgr.tk/utils/DHGRSHOW.REL
|
||||
DLGRCONV = dhgr.tk/utils/DLGRCONV.REL
|
||||
TTFCONV = dhgr.tk/utils/ttfconv
|
||||
IIGSCONV = dhgr.tk/utils/gsfonconv
|
||||
A2CONV = dhgr.tk/utils/a2fonconv
|
||||
DDCONV = dhgr.tk/utils/ddfonconv
|
||||
PENGUINS = dhgr.tk/demos/penguins/PENGUINS.REL
|
||||
|
||||
@@ -41,7 +42,7 @@ demos: $(PENGUINS)
|
||||
cp $(PENGUINS) prodos/dhgr.tk/demos/penguins/
|
||||
cp dhgr.tk/demos/penguins/*.BIN prodos/dhgr.tk/demos/penguins/
|
||||
|
||||
fontconv: $(TTFCONV) $(IIGSCONV) $(DDCONV)
|
||||
fontconv: $(TTFCONV) $(IIGSCONV) $(A2CONV) $(DDCONV)
|
||||
|
||||
all: libs test utils demos
|
||||
|
||||
@@ -57,6 +58,9 @@ $(TTFCONV): dhgr.tk/utils/ttfconv.c
|
||||
$(IIGSCONV): dhgr.tk/utils/gsfonconv.c
|
||||
cc dhgr.tk/utils/gsfonconv.c -o dhgr.tk/utils/gsfonconv
|
||||
|
||||
$(A2CONV): dhgr.tk/utils/a2fonconv.c
|
||||
cc dhgr.tk/utils/a2fonconv.c -o dhgr.tk/utils/a2fonconv
|
||||
|
||||
$(DDCONV): dhgr.tk/utils/ddfonconv.c
|
||||
cc dhgr.tk/utils/ddfonconv.c -o dhgr.tk/utils/ddfonconv
|
||||
|
||||
|
||||
@@ -11,18 +11,24 @@ var arg
|
||||
var xPen = 60
|
||||
var yPen = 30
|
||||
var fontWidth, fontHeight
|
||||
char msg = "Hello, world"
|
||||
char hello = "Hello, world"
|
||||
var msg = @hello
|
||||
|
||||
arg = argNext(argFirst)
|
||||
dhgrMode(DHGR_COLOR_MODE)
|
||||
screenRead("scroll.dhgr")
|
||||
while arg and ^arg
|
||||
dcgrFont(fontRead(arg))
|
||||
fontWidth, fontHeight = fontGlyphDim
|
||||
fontHeight++
|
||||
dcgrColor(CLR_BLACK)
|
||||
dcgrStr(xPen, yPen + (fontHeight * 7) / 8, @msg)
|
||||
yPen = yPen + fontHeight
|
||||
if ^(arg + 1) == '-'
|
||||
msg = arg + 1
|
||||
^msg = ^arg - 1
|
||||
else
|
||||
dcgrFont(fontRead(arg))
|
||||
fontWidth, fontHeight = fontGlyphDim
|
||||
fontHeight++
|
||||
dcgrColor(CLR_BLACK)
|
||||
dcgrStr(xPen, yPen + (fontHeight * 7) / 8, msg)
|
||||
yPen = yPen + fontHeight
|
||||
fin
|
||||
arg = argNext(arg)
|
||||
loop
|
||||
getc
|
||||
|
||||
@@ -0,0 +1,196 @@
|
||||
/*
|
||||
* Apple 2 font converter
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
//#include <stdbit.h>
|
||||
#include <stdint.h>
|
||||
#include <ctype.h>
|
||||
|
||||
#define FONT_WIDTH 32
|
||||
#define FONT_HEIGHT 12
|
||||
#define GLYPH_FIRST 32
|
||||
#define GLYPH_LAST 127
|
||||
#define GLYPH_COUNT (GLYPH_LAST-GLYPH_FIRST+1)
|
||||
#define FONT_BITMAP 0
|
||||
#define FONT_PIXMAP 1
|
||||
int fontFormat = FONT_BITMAP;
|
||||
//
|
||||
// Apple //e hires character font
|
||||
//
|
||||
uint8_t Apple2Glyphs[] = {
|
||||
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x08,0x08,0x08,0x08,0x08,0x00,0x08,0x00,
|
||||
0x14,0x14,0x14,0x00,0x00,0x00,0x00,0x00,0x14,0x14,0x3E,0x14,0x3E,0x14,0x14,0x00,
|
||||
0x08,0x3C,0x0A,0x1C,0x28,0x1E,0x08,0x00,0x06,0x26,0x10,0x08,0x04,0x32,0x30,0x00,
|
||||
0x04,0x0A,0x0A,0x04,0x2A,0x12,0x2C,0x00,0x08,0x08,0x08,0x00,0x00,0x00,0x00,0x00,
|
||||
0x08,0x04,0x02,0x02,0x02,0x04,0x08,0x00,0x08,0x10,0x20,0x20,0x20,0x10,0x08,0x00,
|
||||
0x08,0x2A,0x1C,0x08,0x1C,0x2A,0x08,0x00,0x00,0x08,0x08,0x3E,0x08,0x08,0x00,0x00,
|
||||
0x00,0x00,0x00,0x00,0x08,0x08,0x04,0x00,0x00,0x00,0x00,0x3E,0x00,0x00,0x00,0x00,
|
||||
0x00,0x00,0x00,0x00,0x00,0x00,0x08,0x00,0x00,0x20,0x10,0x08,0x04,0x02,0x00,0x00,
|
||||
0x1C,0x22,0x32,0x2A,0x26,0x22,0x1C,0x00,0x08,0x0C,0x08,0x08,0x08,0x08,0x1C,0x00,
|
||||
0x1C,0x22,0x20,0x18,0x04,0x02,0x3E,0x00,0x3E,0x20,0x10,0x18,0x20,0x22,0x1C,0x00,
|
||||
0x10,0x18,0x14,0x12,0x3E,0x10,0x10,0x00,0x3E,0x02,0x1E,0x20,0x20,0x22,0x1C,0x00,
|
||||
0x38,0x04,0x02,0x1E,0x22,0x22,0x1C,0x00,0x3E,0x20,0x10,0x08,0x04,0x04,0x04,0x00,
|
||||
0x1C,0x22,0x22,0x1C,0x22,0x22,0x1C,0x00,0x1C,0x22,0x22,0x3C,0x20,0x10,0x0E,0x00,
|
||||
0x00,0x00,0x08,0x00,0x08,0x00,0x00,0x00,0x00,0x00,0x08,0x00,0x08,0x08,0x04,0x00,
|
||||
0x10,0x08,0x04,0x02,0x04,0x08,0x10,0x00,0x00,0x00,0x3E,0x00,0x3E,0x00,0x00,0x00,
|
||||
0x04,0x08,0x10,0x20,0x10,0x08,0x04,0x00,0x1C,0x22,0x10,0x08,0x08,0x00,0x08,0x00,
|
||||
0x1C,0x22,0x2A,0x3A,0x1A,0x02,0x3C,0x00,0x08,0x14,0x22,0x22,0x3E,0x22,0x22,0x00,
|
||||
0x1E,0x22,0x22,0x1E,0x22,0x22,0x1E,0x00,0x1C,0x22,0x02,0x02,0x02,0x22,0x1C,0x00,
|
||||
0x1E,0x22,0x22,0x22,0x22,0x22,0x1E,0x00,0x3E,0x02,0x02,0x1E,0x02,0x02,0x3E,0x00,
|
||||
0x3E,0x02,0x02,0x1E,0x02,0x02,0x02,0x00,0x3C,0x02,0x02,0x02,0x32,0x22,0x3C,0x00,
|
||||
0x22,0x22,0x22,0x3E,0x22,0x22,0x22,0x00,0x1C,0x08,0x08,0x08,0x08,0x08,0x1C,0x00,
|
||||
0x20,0x20,0x20,0x20,0x20,0x22,0x1C,0x00,0x22,0x12,0x0A,0x06,0x0A,0x12,0x22,0x00,
|
||||
0x02,0x02,0x02,0x02,0x02,0x02,0x3E,0x00,0x22,0x36,0x2A,0x2A,0x22,0x22,0x22,0x00,
|
||||
0x22,0x22,0x26,0x2A,0x32,0x22,0x22,0x00,0x1C,0x22,0x22,0x22,0x22,0x22,0x1C,0x00,
|
||||
0x1E,0x22,0x22,0x1E,0x02,0x02,0x02,0x00,0x1C,0x22,0x22,0x22,0x2A,0x12,0x2C,0x00,
|
||||
0x1E,0x22,0x22,0x1E,0x0A,0x12,0x22,0x00,0x1C,0x22,0x02,0x1C,0x20,0x22,0x1C,0x00,
|
||||
0x3E,0x08,0x08,0x08,0x08,0x08,0x08,0x00,0x22,0x22,0x22,0x22,0x22,0x22,0x1C,0x00,
|
||||
0x22,0x22,0x22,0x22,0x22,0x14,0x08,0x00,0x22,0x22,0x22,0x2A,0x2A,0x36,0x22,0x00,
|
||||
0x22,0x22,0x14,0x08,0x14,0x22,0x22,0x00,0x22,0x22,0x14,0x08,0x08,0x08,0x08,0x00,
|
||||
0x3E,0x20,0x10,0x08,0x04,0x02,0x3E,0x00,0x3E,0x06,0x06,0x06,0x06,0x06,0x3E,0x00,
|
||||
0x00,0x02,0x04,0x08,0x10,0x20,0x00,0x00,0x3E,0x30,0x30,0x30,0x30,0x30,0x3E,0x00,
|
||||
0x00,0x00,0x08,0x14,0x22,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x7F,
|
||||
0x04,0x08,0x10,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x1C,0x20,0x3C,0x22,0x3C,0x00,
|
||||
0x02,0x02,0x1E,0x22,0x22,0x22,0x1E,0x00,0x00,0x00,0x3C,0x02,0x02,0x02,0x3C,0x00,
|
||||
0x20,0x20,0x3C,0x22,0x22,0x22,0x3C,0x00,0x00,0x00,0x1C,0x22,0x3E,0x02,0x3C,0x00,
|
||||
0x18,0x24,0x04,0x1E,0x04,0x04,0x04,0x00,0x00,0x00,0x1C,0x22,0x22,0x3C,0x20,0x1C,
|
||||
0x02,0x02,0x1E,0x22,0x22,0x22,0x22,0x00,0x08,0x00,0x0C,0x08,0x08,0x08,0x1C,0x00,
|
||||
0x10,0x00,0x18,0x10,0x10,0x10,0x12,0x0C,0x02,0x02,0x22,0x12,0x0E,0x12,0x22,0x00,
|
||||
0x0C,0x08,0x08,0x08,0x08,0x08,0x1C,0x00,0x00,0x00,0x36,0x2A,0x2A,0x22,0x22,0x00,
|
||||
0x00,0x00,0x1E,0x22,0x22,0x22,0x22,0x00,0x00,0x00,0x1C,0x22,0x22,0x22,0x1C,0x00,
|
||||
0x00,0x00,0x1E,0x22,0x22,0x1E,0x02,0x02,0x00,0x00,0x3C,0x22,0x22,0x3C,0x20,0x20,
|
||||
0x00,0x00,0x3A,0x06,0x02,0x02,0x02,0x00,0x00,0x00,0x3C,0x02,0x1C,0x20,0x1E,0x00,
|
||||
0x04,0x04,0x1E,0x04,0x04,0x24,0x18,0x00,0x00,0x00,0x22,0x22,0x22,0x32,0x2C,0x00,
|
||||
0x00,0x00,0x22,0x22,0x22,0x14,0x08,0x00,0x00,0x00,0x22,0x22,0x2A,0x2A,0x36,0x00,
|
||||
0x00,0x00,0x22,0x14,0x08,0x14,0x22,0x00,0x00,0x00,0x22,0x22,0x22,0x3C,0x20,0x1C,
|
||||
0x00,0x00,0x3E,0x10,0x08,0x04,0x3E,0x00,0x38,0x0C,0x0C,0x06,0x0C,0x0C,0x38,0x00,
|
||||
0x08,0x08,0x08,0x08,0x08,0x08,0x08,0x08,0x0E,0x18,0x18,0x30,0x18,0x18,0x0E,0x00,
|
||||
0x00,0x2C,0x1A,0x00,0x00,0x00,0x00,0x00,0x00,0x2A,0x14,0x2A,0x14,0x2A,0x00,0x00,
|
||||
};
|
||||
/*
|
||||
* Bit reversals
|
||||
*/
|
||||
unsigned char bitReverse[256];
|
||||
unsigned char clrSwap[256];
|
||||
unsigned char clrRot[] = {0x00,0x02,0x04,0x06,0x08,0x0A,0x0C,0x0E,
|
||||
0x01,0x03,0x05,0x07,0x09,0x0B,0x0D,0x0F};
|
||||
void write_glyph(FILE *fp, int c)
|
||||
{
|
||||
uint8_t glyphdef[5], *glyphBits;
|
||||
uint8_t strike[9];
|
||||
int i, left, top, width, height, rowOR;
|
||||
|
||||
glyphBits = (uint8_t *)Apple2Glyphs + (c - GLYPH_FIRST) * 8;
|
||||
height = 8;
|
||||
width = 4;
|
||||
left = 0;
|
||||
top = 7;
|
||||
rowOR = 0;
|
||||
for (i = 0; i < 8; i++)
|
||||
{
|
||||
strike[i] = ((*glyphBits ) & 0x02)
|
||||
| ((*glyphBits | *glyphBits >> 1 | *glyphBits >> 2) & 0x04)
|
||||
| (( *glyphBits >> 2) & 0x08);
|
||||
glyphBits++;
|
||||
rowOR |= strike[i];
|
||||
}
|
||||
if ((rowOR & 0x08) == 0)
|
||||
width--;
|
||||
if ((rowOR & 0x02) == 0)
|
||||
{
|
||||
for (i = 0; i < 8; i++)
|
||||
strike[i] >>= 1;
|
||||
width--;
|
||||
}
|
||||
for (i = 7; i >= 0; i--)
|
||||
{
|
||||
if (strike[i] == 0)
|
||||
{
|
||||
height--;
|
||||
if (i < top)
|
||||
top--;
|
||||
}
|
||||
else
|
||||
break;
|
||||
}
|
||||
while ((height > 0) && (strike[0] == 0))
|
||||
{
|
||||
height--;
|
||||
top--;
|
||||
for (i = 0; i < height; i++)
|
||||
strike[i] = strike[i + 1];
|
||||
}
|
||||
if (height <= 0)
|
||||
height = 1;
|
||||
if (top <= 0)
|
||||
top = 1;
|
||||
glyphdef[0] = left;
|
||||
glyphdef[1] = -top;
|
||||
glyphdef[2] = width;
|
||||
glyphdef[3] = height;
|
||||
glyphdef[4] = width + left;
|
||||
fwrite(glyphdef, 1, 5, fp);
|
||||
fwrite(strike, 1, height, fp);
|
||||
}
|
||||
void write_font_file(char *filename, char *fontname)
|
||||
{
|
||||
FILE *fp;
|
||||
unsigned char ch;
|
||||
char font_header[16];
|
||||
int glyph_width, glyph_height, c;
|
||||
|
||||
if ((fp = fopen(filename, "wb")))
|
||||
{
|
||||
memset(font_header, 0, 16);
|
||||
strncpy(&font_header[1], fontname, 15);
|
||||
ch = strlen(fontname);
|
||||
font_header[0] = (ch < 16 ? ch : 15) | 0x80; // FONT_PROP
|
||||
fwrite(font_header, 1, 16, fp);
|
||||
glyph_width = 4;
|
||||
glyph_height = 8;
|
||||
ch = GLYPH_FIRST;
|
||||
fwrite(&ch, 1, 1, fp);
|
||||
ch = GLYPH_LAST;
|
||||
fwrite(&ch, 1, 1, fp);
|
||||
ch = fontFormat == glyph_width;
|
||||
fwrite(&ch, 1, 1, fp);
|
||||
ch = glyph_height;
|
||||
fwrite(&ch, 1, 1, fp);
|
||||
for (c = GLYPH_FIRST; c <= GLYPH_LAST; c++)
|
||||
write_glyph(fp, c);
|
||||
fclose(fp);
|
||||
}
|
||||
}
|
||||
void die(char *str)
|
||||
{
|
||||
fprintf(stderr,"error: %s\n", str);
|
||||
exit(-1);
|
||||
}
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
char *font_file;
|
||||
int i;
|
||||
|
||||
font_file = NULL;
|
||||
while (*++argv)
|
||||
{
|
||||
if (argv[0][0] == '-')
|
||||
{
|
||||
}
|
||||
else
|
||||
{
|
||||
if (!font_file)
|
||||
font_file = *argv;
|
||||
else
|
||||
fprintf(stderr, "? %s\n", *argv);
|
||||
}
|
||||
}
|
||||
if (!font_file)
|
||||
die( "Missing font file");
|
||||
write_font_file(font_file, "Apple2");
|
||||
return 0;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user