aboutsummaryrefslogtreecommitdiff
path: root/convfont.c
blob: a2a24186e7ec5266e010f18c4b645bdc1403dd7d (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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>

#include <unistd.h>
#include <stdio.h>

/* usage:
	# extract the 1K atari ROM font:
	dd if=atariosb.rom of=romfont bs=256 skip=8 count=4

	# extract the Apple II Taipan font:
	dd if=taipan.dsk of=font bs=256 skip=54 count=3

	# create the Atari 8-bit Taipan font:
	cat romfont font | ./convfont > taifont.raw

	# or, create the Atari 8-bit Taipan font as a binary load:
	cat romfont font | ./convfont -x > taifont.xex
 */

/*
	taipan font file order:
	0-31: `a-z{|}" block
	32-63: @A-Z[\]^_
	64-95: space !"#$%&'()*+,-./0-9:;>=<?

	atari screen code order:
	0-31: space !"#$%&'()*+,-./0-9:;>=<?
	32-63: @A-Z[\]^_
	64-95 graphics chars
	96-127: `a-z and 4 graphics chars
*/

/* custom characters for ship graphics. 1st byte
	is screencode, the other 8 are the pixel data. */
char shipdata[][9] = {
	{0x02 , 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0x3f},
	{0x03 , 0x18, 0x1f, 0x1f, 0x10, 0x10, 0x10, 0xff, 0xff},
	{0x04 , 0x00, 0xf0, 0xfc, 0x3e, 0x00, 0x00, 0xfc, 0xf0},
	{0x06 , 0x00, 0x00, 0x40, 0x70, 0x7c, 0x47, 0x40, 0x40},
	{0x1b , 0x1f, 0x3f, 0xff, 0x3f, 0x1f, 0x3f, 0xff, 0x7f},
	{0x1c , 0xc0, 0xf0, 0xfc, 0xf0, 0xc0, 0xf0, 0xfc, 0xf0},
	{0x1d , 0x07, 0x03, 0x07, 0x0f, 0x07, 0x03, 0x07, 0x0f},
	{0x1e , 0xfe, 0xfc, 0xfe, 0xff, 0xfe, 0xf8, 0xfe, 0xff},
	{0x20 , 0xfe, 0xf8, 0xfe, 0xff, 0xfe, 0xfe, 0xfd, 0xf9},
	{0x3b , 0xc0, 0xfe, 0xff, 0xff, 0xff, 0xff, 0x7f, 0x1f},
	{0x3c , 0x00, 0x00, 0xc0, 0xff, 0x8f, 0x8e, 0x8e, 0xfe},
	{0x3d , 0x38, 0x38, 0x38, 0x38, 0xff, 0x38, 0x38, 0x38},
	{0x3e , 0x00, 0x00, 0x00, 0x01, 0xff, 0xe3, 0xe3, 0xe3},
	{0x3f , 0x00, 0x00, 0x00, 0xff, 0x8e, 0x8e, 0x8e, 0xff},
	{0x40 , 0xc3, 0xcf, 0xff, 0xff, 0x3f, 0x3e, 0x3c, 0xf8},
	{0x46 , 0x1f, 0x0f, 0x07, 0x07, 0x07, 0x03, 0x03, 0x03},
	{0x47 , 0xf0, 0xe0, 0xc0, 0xc0, 0xc0, 0xc0, 0x80, 0x80},
	{ 0,    0,    0,    0,    0,    0,    0,    0,    0   }
};

/* this ends up in LORCHA.DAT */
char shipshape[] = {
	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
	0x00, 0x00, 0x02, 0x03, 0x04, 0x00, 0x06,
	0x00, 0x00, 0x1b, 0x80, 0x1c, 0x1d, 0x1e,
	0x00, 0x00, 0x1b, 0x80, 0x1c, 0x1d, 0x20,
	0x00, 0x3b, 0x3c, 0x3d, 0x3e, 0x3f, 0x40,
	0x00, 0x46, 0x80, 0x80, 0x80, 0x80, 0x47,
	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
};

void bitswap(unsigned char *b, int lim) {
	unsigned char j, k;
	// fprintf(stderr, "bitswap(%x, %d)\n", b, lim);
	do {
		k = b[lim];
		j = 0;
		j |= (k & 0x01 ? 0x80 : 0);
		j |= (k & 0x02 ? 0x40 : 0);
		j |= (k & 0x04 ? 0x20 : 0);
		j |= (k & 0x08 ? 0x10 : 0);
		j |= (k & 0x10 ? 0x08 : 0);
		j |= (k & 0x20 ? 0x04 : 0);
		j |= (k & 0x40 ? 0x02 : 0);
		j |= (k & 0x80 ? 0x01 : 0);
		b[lim] = j;
	} while(--lim > 0);
}

void clear0bits(unsigned char *b, int lim) {
	do {
		*b++ &= 0xfe;
	} while(--lim > 0);
}

int main(int argc, char **argv) {
	int i, j;
	unsigned char font[1024], xex[6];

	read(0, font, 1024);
	read(0, font + (96 * 8), 32 * 8);
	bitswap(font + (96 * 8), 32 * 8);
	read(0, font + (32 * 8), 32 * 8);
	bitswap(font + (32 * 8), 32 * 8);
	read(0, font + (0 * 8), 32 * 8);
	bitswap(font + (0 * 8), 32 * 8);

	/* this stuff is from visual inspection via bitmapdump.pl */
	clear0bits(font + 0x1f8, 7);
	clear0bits(font + 0x301, 7);
	clear0bits(font + 0x308, 8);
	clear0bits(font + 0x330, 8);
	clear0bits(font + 0x3a0, 8);
	clear0bits(font + 0x3d8, 8);
	clear0bits(font + 0x3e8, 8);
	clear0bits(font + 0x040, 16);
	clear0bits(font + 0x1e8, 8);

	/* fix the vertical bar */
	font[0x3e0] =
	font[0x3e1] =
	font[0x3e2] =
	font[0x3e3] =
	font[0x3e4] =
	font[0x3e5] =
	font[0x3e6] =
	font[0x3e7] = 0x18;

	/* stick ship data where it goes */
	for(i=0; shipdata[i][0]; i++) {
		for(j=0; j<8; j++) {
			font[ shipdata[i][0] * 8 + j ] = shipdata[i][j+1];
		}
	}

	if(argc > 1) {
		xex[0] = xex[1] = 0xff;
		xex[2] = 0x00; xex[3] = 0xb8; /* load address $B800 */
		xex[4] = 0xff; xex[5] = 0xbb; /* end address $bbff */
		write(1, xex, 6);
	}
	write(1, font, 1024);

	i = open("LORCHA.DAT", O_WRONLY | O_CREAT);
	write(i, shipshape, sizeof(shipshape));
	close(i);

	return 0;
}