[3ae31e9] | 1 | /*
|
---|
| 2 | =============================================================================
|
---|
| 3 | cgen.c -- Intel/Matra-Harris 82716 VSDD character generator translator
|
---|
| 4 | Version 5 -- 1988-10-05 -- D.N. Lynx Crowe
|
---|
| 5 |
|
---|
| 6 | Reads lines of data from stdin containing the hex specifications
|
---|
| 7 | of characters to be built for the VSDD character generator tables.
|
---|
| 8 |
|
---|
| 9 | The first line is a header containing the 1 to 7 character
|
---|
| 10 | name of the cg array to be generated, and 2 decimal fields, the
|
---|
| 11 | first of which gives the number of scan lines per character,
|
---|
| 12 | in the range 1 to 16, and the second of which is the number
|
---|
| 13 | of pixels per scan line, which must be 6, 8, 12 or 16.
|
---|
| 14 |
|
---|
| 15 | Each data line consists of 2 to 17 hex fields, the first of which is
|
---|
| 16 | the hex character code, and the remainder of which are the hex codes
|
---|
| 17 | for each scan line in the character, from bottom to top.
|
---|
| 18 |
|
---|
| 19 | The program reverses each pattern byte and stores it in the
|
---|
| 20 | appropriate slice table. When EOF is reached, the slice tables
|
---|
| 21 | are output to stdout as a c source file.
|
---|
| 22 | =============================================================================
|
---|
| 23 | */
|
---|
| 24 |
|
---|
| 25 | #define PROGID "cgen"
|
---|
| 26 |
|
---|
| 27 | #include "stdio.h"
|
---|
| 28 | #include "stddefs.h"
|
---|
| 29 | #include "memory.h"
|
---|
| 30 | #include "strings.h"
|
---|
| 31 |
|
---|
| 32 | extern char *now();
|
---|
| 33 |
|
---|
| 34 | int slice[16][256]; /* slice table */
|
---|
| 35 | int pixels;
|
---|
| 36 |
|
---|
| 37 | int nscans, npixels;
|
---|
| 38 | int i, j, k, l;
|
---|
| 39 | int cnum;
|
---|
| 40 |
|
---|
| 41 | char cgname[129];
|
---|
| 42 | char dtg[32];
|
---|
| 43 |
|
---|
| 44 | int bitmask[] = {
|
---|
| 45 |
|
---|
| 46 | 0x0001, 0x0002, 0x0004, 0x0008,
|
---|
| 47 | 0x0010, 0x0020, 0x0040, 0x0080,
|
---|
| 48 | 0x0100, 0x0200, 0x0400, 0x0800,
|
---|
| 49 | 0x1000, 0x2000, 0x4000, 0x8000
|
---|
| 50 | };
|
---|
| 51 |
|
---|
| 52 | /* |
---|
| 53 | */
|
---|
| 54 |
|
---|
| 55 | /*
|
---|
| 56 | =============================================================================
|
---|
| 57 | bitrev(bitsin, nbits) -- reverses the rightmost nbits of bitsin.
|
---|
| 58 |
|
---|
| 59 | Any bits to the left of the reversed bits in the result will be zeros.
|
---|
| 60 | =============================================================================
|
---|
| 61 | */
|
---|
| 62 |
|
---|
| 63 | int
|
---|
| 64 | bitrev(bitsin, nbits)
|
---|
| 65 | int bitsin, nbits;
|
---|
| 66 | {
|
---|
| 67 | int m, n;
|
---|
| 68 |
|
---|
| 69 | n = 0;
|
---|
| 70 |
|
---|
| 71 | for (m = 0; m < nbits; m++)
|
---|
| 72 | if (bitsin & bitmask[m])
|
---|
| 73 | n |= bitmask[nbits-1-m];
|
---|
| 74 |
|
---|
| 75 | return(n);
|
---|
| 76 | }
|
---|
| 77 |
|
---|
| 78 | /* |
---|
| 79 | */
|
---|
| 80 |
|
---|
| 81 | main()
|
---|
| 82 | {
|
---|
| 83 | memset(cgname, 0, sizeof cgname); /* clear the cg name array */
|
---|
| 84 | memset(slice, 0, sizeof slice); /* clear the slice array */
|
---|
| 85 |
|
---|
| 86 | /* read header data */
|
---|
| 87 |
|
---|
| 88 | if (3 NE scanf("%s %d %d", &cgname, &nscans, &npixels)) {
|
---|
| 89 |
|
---|
| 90 | printf("\n%s: Unable to read header data.\n",
|
---|
| 91 | PROGID);
|
---|
| 92 | exit(1);
|
---|
| 93 | }
|
---|
| 94 |
|
---|
| 95 | if (strlen(cgname) GT 7) {
|
---|
| 96 |
|
---|
| 97 | printf("%s: Character generator name too long.\n",
|
---|
| 98 | PROGID);
|
---|
| 99 | exit(1);
|
---|
| 100 | }
|
---|
| 101 |
|
---|
| 102 | if ((nscans GT 16) OR (nscans LE 0)) {
|
---|
| 103 |
|
---|
| 104 | printf("%s: Number of scan lines must be > 0 and < 17.\n",
|
---|
| 105 | PROGID);
|
---|
| 106 | exit(1);
|
---|
| 107 | }
|
---|
| 108 |
|
---|
| 109 | if ((npixels NE 6) AND (npixels NE 8) AND
|
---|
| 110 | (npixels NE 12) AND (npixels NE 16)) {
|
---|
| 111 |
|
---|
| 112 | printf("%s: Number of pixels must be 6, 8, 12, or 16.\n",
|
---|
| 113 | PROGID);
|
---|
| 114 | exit(1);
|
---|
| 115 | }
|
---|
| 116 |
|
---|
| 117 | /* |
---|
| 118 | */
|
---|
| 119 |
|
---|
| 120 | /* process each character definition */
|
---|
| 121 |
|
---|
| 122 | while (TRUE) {
|
---|
| 123 |
|
---|
| 124 | if (EOF EQ scanf("%x", &cnum)) { /* character number */
|
---|
| 125 |
|
---|
| 126 | /* all characters are in slice table, output it */
|
---|
| 127 |
|
---|
| 128 | printf("/* VSDD character generator table %s */\n",
|
---|
| 129 | cgname);
|
---|
| 130 |
|
---|
| 131 | printf("/* %dV by %dH */\n", nscans, npixels);
|
---|
| 132 |
|
---|
| 133 | printf("/* Generated: %s */\n\n", now(dtg));
|
---|
| 134 |
|
---|
| 135 | printf("int\tcg_rows = %d;\n\n", nscans);
|
---|
| 136 |
|
---|
| 137 | printf("int\t%s[%d][256] = {\n\n", cgname, nscans);
|
---|
| 138 |
|
---|
| 139 | for (i = 0; i < nscans-1; i++) {
|
---|
| 140 |
|
---|
| 141 | l = 0;
|
---|
| 142 | printf("\t{\t/* Scan line %d */\n", i);
|
---|
| 143 |
|
---|
| 144 | for (j = 0; j < 31; j++) {
|
---|
| 145 |
|
---|
| 146 | printf("\t ");
|
---|
| 147 |
|
---|
| 148 | for (k = 0; k < 8; k++) {
|
---|
| 149 |
|
---|
| 150 | printf("0x%04x, ", slice[i][l]);
|
---|
| 151 | l++;
|
---|
| 152 | }
|
---|
| 153 |
|
---|
| 154 | printf("\n");
|
---|
| 155 | }
|
---|
| 156 |
|
---|
| 157 | printf("\t ");
|
---|
| 158 |
|
---|
| 159 | for (k = 0; k < 7; k++) {
|
---|
| 160 |
|
---|
| 161 | printf("0x%04x, ", slice[i][l]);
|
---|
| 162 | l++;
|
---|
| 163 | }
|
---|
| 164 |
|
---|
| 165 | printf("0x%04x\n\t},\n\n", slice[i][l]);
|
---|
| 166 | }
|
---|
| 167 |
|
---|
| 168 | /* |
---|
| 169 | */
|
---|
| 170 |
|
---|
| 171 | l = 0;
|
---|
| 172 | printf("\t{\t/* Scan line %d */\n", i);
|
---|
| 173 |
|
---|
| 174 | for (j = 0; j < 31; j++) {
|
---|
| 175 |
|
---|
| 176 | printf("\t ");
|
---|
| 177 |
|
---|
| 178 | for (k = 0; k < 8; k++) {
|
---|
| 179 |
|
---|
| 180 | printf("0x%04x, ", slice[i][l]);
|
---|
| 181 | l++;
|
---|
| 182 | }
|
---|
| 183 |
|
---|
| 184 | printf("\n");
|
---|
| 185 | }
|
---|
| 186 |
|
---|
| 187 | printf("\t ");
|
---|
| 188 |
|
---|
| 189 | for (k = 0; k < 7; k++) {
|
---|
| 190 |
|
---|
| 191 | printf("0x%04x, ", slice[i][l]);
|
---|
| 192 | l++;
|
---|
| 193 | }
|
---|
| 194 |
|
---|
| 195 | printf("0x%04x\n\t}\n", slice[i][l]);
|
---|
| 196 | printf("};\n");
|
---|
| 197 | exit(0);
|
---|
| 198 | }
|
---|
| 199 |
|
---|
| 200 | /* |
---|
| 201 | */
|
---|
| 202 | if ((cnum < 0) OR (cnum > 255)) {
|
---|
| 203 |
|
---|
| 204 | printf("%s: Character number must be > 0 and < FF.\n",
|
---|
| 205 | PROGID);
|
---|
| 206 | exit(1);
|
---|
| 207 | }
|
---|
| 208 |
|
---|
| 209 | for (i = 0; i < nscans; i++) {
|
---|
| 210 |
|
---|
| 211 | if (1 NE scanf("%x", &pixels)) {
|
---|
| 212 |
|
---|
| 213 | printf("\n%s: Error reading slice data for %2x.\n",
|
---|
| 214 | PROGID, cnum);
|
---|
| 215 | exit(1);
|
---|
| 216 | }
|
---|
| 217 |
|
---|
| 218 | slice[i][cnum] = bitrev(pixels, npixels);
|
---|
| 219 | }
|
---|
| 220 | }
|
---|
| 221 | }
|
---|