aboutsummaryrefslogtreecommitdiff
path: root/convfont.c
blob: a0ae0f4c0eba3bebf964f6bdaf85c5b663e5d959 (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
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
#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] = {
	/* healthy ship blocks */
	{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},

	/*
A, 50, 00 00 00 00 00 00 47 3e
B, 5b, 18 1f 1d 10 10 10 fb fd
E, 5e, 1f 0f 1f 3f 1f 3b ff 7f
G, 5f, 00 01 03 07 03 03 07 06
H, 60, f0 f8 fb fe fe f8 fe 7f
I, 7b, fe f8 be 97 8e be fc f8
J, 7d, 00 00 03 1d 1f 37 3b 1f
K, 7e, 00 00 00 00 80 c1 e3 e3
O, 7f, c0 c0 f0 e0 20 32 3c f1
*/
	/* damaged ship blocks */
	{ 0x50 , 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x47, 0x3e},
	{ 0x5b , 0x18, 0x1f, 0x1d, 0x10, 0x10, 0x10, 0xfb, 0xfd},
	{ 0x5e , 0x1f, 0x0f, 0x1f, 0x3f, 0x1f, 0x3b, 0xff, 0x7f},
	{ 0x5f , 0x00, 0x01, 0x03, 0x07, 0x03, 0x03, 0x07, 0x06},
	{ 0x60 , 0xf0, 0xf8, 0xfb, 0xfe, 0xfe, 0xf8, 0xfe, 0x7f},
	{ 0x7b , 0xfe, 0xf8, 0xbe, 0x97, 0x8e, 0xbe, 0xfc, 0xf8},
	{ 0x7d , 0x00, 0x00, 0x03, 0x1d, 0x1f, 0x37, 0x3b, 0x1f},
	{ 0x7e , 0x00, 0x00, 0x00, 0x00, 0x80, 0xc1, 0xe3, 0xe3},
	{ 0x7f , 0xc0, 0xc0, 0xf0, 0xe0, 0x20, 0x32, 0x3c, 0xf1},

	/* end of ship data marker */
	{ 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
};

char damaged_shipshape[] = {
	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
	0x00, 0x00, 0x50, 0x5b, 0x00, 0x00, 0x00,
	0x00, 0x00, 0x5e, 0xd4, 0x00, 0x5f, 0x1e,
	0x00, 0x00, 0x5e, 0xd4, 0x00, 0x5f, 0x60,
	0x00, 0x7d, 0x7e, 0x7c, 0x7e, 0x7e, 0x7f,
	0x00, 0x46, 0xcc, 0x87, 0xcc, 0x8e, 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] = FONT_ADDR % 256; xex[3] = FONT_ADDR / 256; /* load address $2000 */
		xex[4] = 0xff; xex[5] = 0x23; /* end address $23ff */
		write(1, xex, 6);
	}
	write(1, font, 1024);

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

	i = open("DAMAGED.DAT", O_WRONLY | O_CREAT, 0666);
	write(i, damaged_shipshape, sizeof(damaged_shipshape));
	close(i);

	return 0;
}