aboutsummaryrefslogtreecommitdiffstats
path: root/roms/saa5050/genrom.c
blob: 9d93bb35399fe659410bf7516950072ba3447f38 (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
#include <stdint.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>

// Characters on a 5x9 matrix.  This is padded up to 16 rows when the
// ROM is generated
static uint8_t saa5050_charset[] = {
	0,0,0,0,0,0,0,0,0,
	4,4,4,4,4,0,4,0,0,
	10,10,10,0,0,0,0,0,0,
	6,9,8,28,8,8,31,0,0,
	14,21,20,14,5,21,14,0,0,
	24,25,2,4,8,19,3,0,0,
	8,20,20,8,21,18,13,0,0,
	4,4,4,0,0,0,0,0,0,

	2,4,8,8,8,4,2,0,0,
	8,4,2,2,2,4,8,0,0,
	4,21,14,4,14,21,4,0,0,
	0,4,4,31,4,4,0,0,0,
	0,0,0,0,0,4,4,8,0,
	0,0,0,14,0,0,0,0,0,
	0,0,0,0,0,0,4,0,0,
	0,1,2,4,8,16,0,0,0,

	4,10,17,17,17,10,4,0,0,
	4,12,4,4,4,4,14,0,0,
	14,17,1,6,8,16,31,0,0,
	31,1,2,6,1,17,14,0,0,
	2,6,10,18,31,2,2,0,0,
	31,16,30,1,1,17,14,0,0,
	6,8,16,30,17,17,14,0,0,
	31,1,2,4,8,8,8,0,0,

	14,17,17,14,17,17,14,0,0,
	14,17,17,15,1,2,12,0,0,
	0,0,4,0,0,0,4,0,0,
	0,0,4,0,0,4,4,8,0,
	2,4,8,16,8,4,2,0,0,
	0,0,31,0,31,0,0,0,0,
	8,4,2,1,2,4,8,0,0,
	14,17,2,4,4,0,4,0,0,

	14,17,23,21,23,16,14,0,0,
	4,10,17,17,31,17,17,0,0,
	30,17,17,30,17,17,30,0,0,
	14,17,16,16,16,17,14,0,0,
	30,17,17,17,17,17,30,0,0,
	31,16,16,30,16,16,31,0,0,
	31,16,16,30,16,16,16,0,0,
	14,17,16,16,19,17,15,0,0,

	17,17,17,31,17,17,17,0,0,
	14,4,4,4,4,4,14,0,0,
	1,1,1,1,1,17,14,0,0,
	17,18,20,24,20,18,17,0,0,
	16,16,16,16,16,16,31,0,0,
	17,27,21,21,17,17,17,0,0,
	17,17,25,21,19,17,17,0,0,
	14,17,17,17,17,17,14,0,0,

	30,17,17,30,16,16,16,0,0,
	14,17,17,17,21,18,13,0,0,
	30,17,17,30,20,18,17,0,0,
	14,17,16,14,1,17,14,0,0,
	31,4,4,4,4,4,4,0,0,
	17,17,17,17,17,17,14,0,0,
	17,17,17,10,10,4,4,0,0,
	17,17,17,21,21,21,10,0,0,

	17,17,10,4,10,17,17,0,0,
	17,17,10,4,4,4,4,0,0,
	31,1,2,4,8,16,31,0,0,
	0,4,8,31,8,4,0,0,0,
	16,16,16,16,22,1,2,4,7,
	0,4,2,31,2,4,0,0,0,
	0,4,14,21,4,4,0,0,0,
	10,10,31,10,31,10,10,0,0,

	0,0,0,31,0,0,0,0,0,
	0,0,14,1,15,17,15,0,0,
	16,16,30,17,17,17,30,0,0,
	0,0,15,16,16,16,15,0,0,
	1,1,15,17,17,17,15,0,0,
	0,0,14,17,31,16,14,0,0,
	2,4,4,14,4,4,4,0,0,
	0,0,15,17,17,17,15,1,14,

	16,16,30,17,17,17,17,0,0,
	4,0,12,4,4,4,14,0,0,
	4,0,4,4,4,4,4,4,8,
	8,8,9,10,12,10,9,0,0,
	12,4,4,4,4,4,14,0,0,
	0,0,26,21,21,21,21,0,0,
	0,0,30,17,17,17,17,0,0,
	0,0,14,17,17,17,14,0,0,

	0,0,30,17,17,17,30,16,16,
	0,0,15,17,17,17,15,1,1,
	0,0,11,12,8,8,8,0,0,
	0,0,15,16,14,1,30,0,0,
	4,4,14,4,4,4,2,0,0,
	0,0,17,17,17,17,15,0,0,
	0,0,17,17,10,10,4,0,0,
	0,0,17,17,21,21,10,0,0,

	0,0,17,10,4,10,17,0,0,
	0,0,17,17,17,17,15,1,14,
	0,0,31,2,4,8,31,0,0,
	8,8,8,8,9,3,5,7,1,
	10,10,10,10,10,10,10,0,0,
	24,4,24,4,25,3,5,7,1,
	0,4,0,31,0,4,0,0,0,
	31,31,31,31,31,31,31,0,0,
};

/* Generates 6x10 teletext graphics symbol according to specified code */
void gen_gfx(char code,char *base)
{
	char *c;
	int r;

	for (r = 0, c = base; r < 10; r++, c++) {
		/* Set unused bit 7 to 1 to flag these characters as graphics (the
		 * implementation uses this to determine whether hold and separated
		 * modes should be applied */
		*c = 128;
		if (r < 3) {
			// 1 2
			if (code & 1) *c += 56;
			if (code & 2) *c += 7;
		} else if (r < 7) {
			// 4 8
			if (code & 4) *c += 56;
			if (code & 8) *c += 7;
		} else {
			// 16 64
			if (code & 16) *c += 56;
			if (code & 64) *c += 7;
		}
	}
}

int main(void) {
	char *outbuf;
	int ch,row;

	outbuf = malloc(256 * 16);
	if (outbuf == NULL) {
		fprintf(stderr,"Out of memory\n");
		return 1;
	}

	/* Unused locations are blank (all zero) */
	memset(outbuf,0,256 * 16);

	/* Copy character bitmaps to locations 32-127 and 160-255 */
	for (ch = 0; ch < 96; ch++) {
		for (row = 0; row < 9; row++) {
			outbuf[16 * (32 + ch) + row + 1] = saa5050_charset[9 * ch + row];
			outbuf[16 * (160 + ch) + row + 1] = saa5050_charset[9 * ch + row];
		}
	}

	/* Generate graphics in locations 160-191 and 224-255 */
	for (ch = 160; ch < 192; ch++) {
		gen_gfx(ch,&outbuf[16 * ch]);
	}
	for (ch = 224; ch < 256; ch++) {
		gen_gfx(ch,&outbuf[16 * ch]);
	}

	/* Write to stdout */
	fwrite(outbuf,256 * 16,1,stdout);

	free(outbuf);
	return 0;
}