Skip to content

Commit

Permalink
textsave: Add support for the Master's extended characters (>=128).
Browse files Browse the repository at this point in the history
  • Loading branch information
Steve Fosdick committed Nov 27, 2024
1 parent 939ec55 commit 948706c
Showing 1 changed file with 288 additions and 51 deletions.
339 changes: 288 additions & 51 deletions src/textsave.c
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#define _DEBUG
#include "b-em.h"
#include "textsave.h"
#include "mem.h"
Expand Down Expand Up @@ -65,54 +66,275 @@ static void textsave_teletext(const char *filename, FILE *fp, uint_least16_t mem
*/

static const uint64_t charset[] = {
/* SPC */ 0x0000000000000000, /* ! */ 0x1818181818001800,
/* " */ 0x6c6c6c0000000000, /* # */ 0x36367f367f363600,
/* $ */ 0x0c3f683e0b7e1800, /* % */ 0x60660c1830660600,
/* & */ 0x386c6c386d663b00, /* ' */ 0x0c18300000000000,
/* ( */ 0x0c18303030180c00, /* ) */ 0x30180c0c0c183000,
/* * */ 0x00187e3c7e180000, /* + */ 0x0018187e18180000,
/* , */ 0x0000000000181830, /* - */ 0x0000007e00000000,
/* . */ 0x0000000000181800, /* / */ 0x00060c1830600000,
/* 0 */ 0x3c666e7e76663c00, /* 1 */ 0x1838181818187e00,
/* 2 */ 0x3c66060c18307e00, /* 3 */ 0x3c66061c06663c00,
/* 4 */ 0x0c1c3c6c7e0c0c00, /* 5 */ 0x7e607c0606663c00,
/* 6 */ 0x1c30607c66663c00, /* 7 */ 0x7e060c1830303000,
/* 8 */ 0x3c66663c66663c00, /* 9 */ 0x3c66663e060c3800,
/* : */ 0x0000181800181800, /* ; */ 0x0000181800181830,
/* < */ 0x0c18306030180c00, /* = */ 0x00007e007e000000,
/* > */ 0x30180c060c183000, /* ? */ 0x3c660c1818001800,
/* @ */ 0x3c666e6a6e603c00, /* A */ 0x3c66667e66666600,
/* B */ 0x7c66667c66667c00, /* C */ 0x3c66606060663c00,
/* D */ 0x786c6666666c7800, /* E */ 0x7e60607c60607e00,
/* F */ 0x7e60607c60606000, /* G */ 0x3c66606e66663c00,
/* H */ 0x6666667e66666600, /* I */ 0x7e18181818187e00,
/* J */ 0x3e0c0c0c0c6c3800, /* K */ 0x666c7870786c6600,
/* L */ 0x6060606060607e00, /* M */ 0x63777f6b6b636300,
/* N */ 0x6666767e6e666600, /* O */ 0x3c66666666663c00,
/* P */ 0x7c66667c60606000, /* Q */ 0x3c6666666a6c3600,
/* R */ 0x7c66667c6c666600, /* S */ 0x3c66603c06663c00,
/* T */ 0x7e18181818181800, /* U */ 0x6666666666663c00,
/* V */ 0x66666666663c1800, /* W */ 0x63636b6b7f776300,
/* X */ 0x66663c183c666600, /* Y */ 0x6666663c18181800,
/* Z */ 0x7e060c1830607e00, /* [ */ 0x7c60606060607c00,
/* \ */ 0x006030180c060000, /* ] */ 0x3e06060606063e00,
/* ^ */ 0x183c664200000000, /* _ */ 0x00000000000000ff,
/* ` */ 0x1c36307c30307e00, /* a */ 0x00003c063e663e00,
/* b */ 0x60607c6666667c00, /* c */ 0x00003c6660663c00,
/* d */ 0x06063e6666663e00, /* e */ 0x00003c667e603c00,
/* f */ 0x1c30307c30303000, /* g */ 0x00003e66663e063c,
/* h */ 0x60607c6666666600, /* i */ 0x1800381818183c00,
/* j */ 0x1800381818181870, /* k */ 0x6060666c786c6600,
/* l */ 0x3818181818183c00, /* m */ 0x0000367f6b6b6300,
/* n */ 0x00007c6666666600, /* o */ 0x00003c6666663c00,
/* p */ 0x00007c66667c6060, /* q */ 0x00003e66663e0607,
/* r */ 0x00006c7660606000, /* s */ 0x00003e603c067c00,
/* t */ 0x30307c3030301c00, /* u */ 0x0000666666663e00,
/* v */ 0x00006666663c1800, /* w */ 0x0000636b6b7f3600,
/* x */ 0x0000663c183c6600, /* y */ 0x00006666663e063c,
/* z */ 0x00007e0c18307e00, /* { */ 0x0c18187018180c00,
/* | */ 0x1818180018181800, /* } */ 0x3018180e18183000,
/* ~ */ 0x316b460000000000, /* DEL */ 0xffffffffffffffff,
0x0000000000000000, /* 32 20 ' ' */
0x1818181818001800, /* 33 21 '!' */
0x6c6c6c0000000000, /* 34 22 '"' */
0x36367f367f363600, /* 35 23 '#' */
0x0c3f683e0b7e1800, /* 36 24 '$' */
0x60660c1830660600, /* 37 25 '%' */
0x386c6c386d663b00, /* 38 26 '&' */
0x0c18300000000000, /* 39 27 ''' */
0x0c18303030180c00, /* 40 28 '(' */
0x30180c0c0c183000, /* 41 29 ')' */
0x00187e3c7e180000, /* 42 2A '*' */
0x0018187e18180000, /* 43 2B '+' */
0x0000000000181830, /* 44 2C ',' */
0x0000007e00000000, /* 45 2D '-' */
0x0000000000181800, /* 46 2E '.' */
0x00060c1830600000, /* 47 2F '/' */
0x3c666e7e76663c00, /* 48 30 '0' */
0x1838181818187e00, /* 49 31 '1' */
0x3c66060c18307e00, /* 50 32 '2' */
0x3c66061c06663c00, /* 51 33 '3' */
0x0c1c3c6c7e0c0c00, /* 52 34 '4' */
0x7e607c0606663c00, /* 53 35 '5' */
0x1c30607c66663c00, /* 54 36 '6' */
0x7e060c1830303000, /* 55 37 '7' */
0x3c66663c66663c00, /* 56 38 '8' */
0x3c66663e060c3800, /* 57 39 '9' */
0x0000181800181800, /* 58 3A ':' */
0x0000181800181830, /* 59 3B ';' */
0x0c18306030180c00, /* 60 3C '<' */
0x00007e007e000000, /* 61 3D '=' */
0x30180c060c183000, /* 62 3E '>' */
0x3c660c1818001800, /* 63 3F '?' */
0x3c666e6a6e603c00, /* 64 40 '@' */
0x3c66667e66666600, /* 65 41 'A' */
0x7c66667c66667c00, /* 66 42 'B' */
0x3c66606060663c00, /* 67 43 'C' */
0x786c6666666c7800, /* 68 44 'D' */
0x7e60607c60607e00, /* 69 45 'E' */
0x7e60607c60606000, /* 70 46 'F' */
0x3c66606e66663c00, /* 71 47 'G' */
0x6666667e66666600, /* 72 48 'H' */
0x7e18181818187e00, /* 73 49 'I' */
0x3e0c0c0c0c6c3800, /* 74 4A 'J' */
0x666c7870786c6600, /* 75 4B 'K' */
0x6060606060607e00, /* 76 4C 'L' */
0x63777f6b6b636300, /* 77 4D 'M' */
0x6666767e6e666600, /* 78 4E 'N' */
0x3c66666666663c00, /* 79 4F 'O' */
0x7c66667c60606000, /* 80 50 'P' */
0x3c6666666a6c3600, /* 81 51 'Q' */
0x7c66667c6c666600, /* 82 52 'R' */
0x3c66603c06663c00, /* 83 53 'S' */
0x7e18181818181800, /* 84 54 'T' */
0x6666666666663c00, /* 85 55 'U' */
0x66666666663c1800, /* 86 56 'V' */
0x63636b6b7f776300, /* 87 57 'W' */
0x66663c183c666600, /* 88 58 'X' */
0x6666663c18181800, /* 89 59 'Y' */
0x7e060c1830607e00, /* 90 5A 'Z' */
0x7c60606060607c00, /* 91 5B '[' */
0x006030180c060000, /* 92 5C '\' */
0x3e06060606063e00, /* 93 5D ']' */
0x183c664200000000, /* 94 5E '^' */
0x00000000000000ff, /* 95 5F '_' */
0x1c36307c30307e00, /* 96 60 '`' */
0x00003c063e663e00, /* 97 61 'a' */
0x60607c6666667c00, /* 98 62 'b' */
0x00003c6660663c00, /* 99 63 'c' */
0x06063e6666663e00, /* 100 64 'd' */
0x00003c667e603c00, /* 101 65 'e' */
0x1c30307c30303000, /* 102 66 'f' */
0x00003e66663e063c, /* 103 67 'g' */
0x60607c6666666600, /* 104 68 'h' */
0x1800381818183c00, /* 105 69 'i' */
0x1800381818181870, /* 106 6A 'j' */
0x6060666c786c6600, /* 107 6B 'k' */
0x3818181818183c00, /* 108 6C 'l' */
0x0000367f6b6b6300, /* 109 6D 'm' */
0x00007c6666666600, /* 110 6E 'n' */
0x00003c6666663c00, /* 111 6F 'o' */
0x00007c66667c6060, /* 112 70 'p' */
0x00003e66663e0607, /* 113 71 'q' */
0x00006c7660606000, /* 114 72 'r' */
0x00003e603c067c00, /* 115 73 's' */
0x30307c3030301c00, /* 116 74 't' */
0x0000666666663e00, /* 117 75 'u' */
0x00006666663c1800, /* 118 76 'v' */
0x0000636b6b7f3600, /* 119 77 'w' */
0x0000663c183c6600, /* 120 78 'x' */
0x00006666663e063c, /* 121 79 'y' */
0x00007e0c18307e00, /* 122 7A 'z' */
0x0c18187018180c00, /* 123 7B '{' */
0x1818180018181800, /* 124 7C '|' */
0x3018180e18183000, /* 125 7D '}' */
0x316b460000000000, /* 126 7E '~' */
0xffffffffffffffff, /* 127 7F */
0x66003c667e666600, /* 128 80 */
0x6666003c667e6600, /* 128 80 */
0x3c663c667e666600, /* 129 81 */
0x3c663c3c667e6600, /* 129 81 */
0x3f66667f66666700, /* 130 82 */
0x3c66606060663c60, /* 131 83 */
0x3c666060663c3060, /* 131 83 */
0x0c187e607c607e00, /* 132 84 */
0x663c666666663c00, /* 133 85 */
0x6600666666663c00, /* 134 86 */
0x7ec39db19dc37e00, /* 135 87 */
0x3c4299a1a199423c, /* 135 87 */
0x0018387f38180000, /* 136 88 */
0x00181cfe1c180000, /* 137 89 */
0x181818187e3c1800, /* 138 8A */
0x00183c7e18181818, /* 139 8B */
0x30183c063e663e00, /* 140 8C */
0x30183c667e603c00, /* 141 8D */
0x66003c667e603c00, /* 142 8E */
0x3c663c667e603c00, /* 143 8F */
0x66003c063e663e00, /* 144 90 */
0x3c663c063e663e00, /* 145 91 */
0x00003f0d3f6c3f00, /* 146 92 */
0x00003c6660663c60, /* 147 93 */
0x0c183c667e603c00, /* 148 94 */
0x6600003c66663c00, /* 149 95 */
0x6600666666663e00, /* 150 96 */
0x6600006666663e00, /* 150 96 */
0x3018003818183c00, /* 151 97 */
0x3c66003818183c00, /* 152 98 */
0x3018003c66663c00, /* 153 99 */
0x3c66003c66663c00, /* 154 9A */
0x3018006666663e00, /* 155 9B */
0x3c66006666663e00, /* 156 9C */
0x66006666663e063c, /* 157 9D */
0x00663c66663c6600, /* 158 9E */
0x3c603c663c063c00, /* 159 9F */
0x3c663c0000000000, /* 160 A0 */
0x0000001818181818, /* 161 A1 */
0x0000001f00000000, /* 162 A2 */
0x0000001f18181818, /* 163 A3 */
0x000000f800000000, /* 164 A4 */
0x000000f818181818, /* 165 A5 */
0x000000ff00000000, /* 166 A6 */
0x000000ff18181818, /* 167 A7 */
0x1818181800000000, /* 168 A8 */
0x1818181818181818, /* 169 A9 */
0x1818181f00000000, /* 170 AA */
0x1818181f18181818, /* 171 AB */
0x181818f800000000, /* 172 AC */
0x181818f818181818, /* 173 AD */
0x181818ff00000000, /* 174 AE */
0x181818ff18181818, /* 175 AF */
0x000000070c181818, /* 176 B0 */
0x000000e030181818, /* 177 B1 */
0x18180c0700000000, /* 178 B2 */
0x181830e000000000, /* 179 B3 */
0x1800181830663c00, /* 180 B4 */
0x1800181818181800, /* 181 B5 */
0x366c0066766e6600, /* 182 B6 */
0x366c007c66666600, /* 183 B7 */
0x187e181818181800, /* 184 B8 */
0x187e1818187e1800, /* 185 B9 */
0x1818180000000000, /* 186 BA */
0x1800000000000000, /* 186 BA */
0x30180c0000000000, /* 187 BB */
0x3018000000000000, /* 187 BB */
0x3f7b7b3b1b1b1f00, /* 188 BC */
0x033e767636363e00, /* 188 BC */
0x0000001818000000, /* 189 BD */
0x03030606761c0c00, /* 190 BE */
0xaa55aa55aa55aa55, /* 191 BF */
0x3e63676b73633e00, /* 192 C0 */
0x1c3663637f636300, /* 193 C1 */
0x7e33333e33337e00, /* 194 C2 */
0x7f63606060606000, /* 195 C3 */
0x1c1c363663637f00, /* 196 C4 */
0x7f33303e30337f00, /* 197 C5 */
0x7e660c1830667e00, /* 198 C6 */
0x7733333f33337700, /* 199 C7 */
0x3e63637f63633e00, /* 200 C8 */
0x3c18181818183c00, /* 201 C9 */
0x63666c786c666300, /* 202 CA */
0x1c1c363663636300, /* 203 CB */
0x63777f6b63636300, /* 204 CC */
0x63737b6f67636300, /* 205 CD */
0x7e00003c00007e00, /* 206 CE */
0x3e63636363633e00, /* 207 CF */
0x7f36363636363600, /* 208 D0 */
0x7e33333e30307800, /* 209 D1 */
0x7f63301830637f00, /* 210 D2 */
0x7e5a181818181800, /* 211 D3 */
0x6666663c18183c00, /* 212 D4 */
0x3e083e6b3e083e00, /* 213 D5 */
0x6363361c36636300, /* 214 D6 */
0x3e086b6b3e083e00, /* 215 D7 */
0x3e63636336366300, /* 216 D8 */
0x7f636336361c1c00, /* 217 D9 */
0x18187e1818007e00, /* 218 DA */
0x007e0018187e1818, /* 219 DB */
0x1818181818181800, /* 220 DC */
0x3636363636363600, /* 221 DD */
0x0066666666663c00, /* 222 DE */
0x003c666666666600, /* 223 DF */
0x00033e676b733e60, /* 224 E0 */
0x00023c6e7666bc00, /* 224 E0 */
0x00003b6e666e3b00, /* 225 E1 */
0x1e33333e33333e60, /* 226 E2 */
0x000066361c183030, /* 227 E3 */
0x3c60303c66663c00, /* 228 E4 */
0x00001e301c301e00, /* 229 E5 */
0x3e0c183060603e06, /* 230 E6 */
0x00007c6666660606, /* 231 E7 */
0x3c66667e66663c00, /* 232 E8 */
0x0000181818180c00, /* 233 E9 */
0x0000666c786c6600, /* 234 EA */
0x6030181c36636300, /* 235 EB */
0x0000333333333e60, /* 236 EC */
0x000063331b1e1c00, /* 237 ED */
0x3c60603c60603e06, /* 238 EE */
0x0c3e603c603e060c, /* 238 EE */
0x00003e6363633e00, /* 239 EF */
0x00007f3636363600, /* 240 F0 */
0x00003c66667c6060, /* 241 F1 */
0x00003f6666663c00, /* 242 F2 */
0x00007e1818180c00, /* 243 F3 */
0x0000733333331e00, /* 244 F4 */
0x00003e6b6b3e1818, /* 245 F5 */
0x000066361c1c3633, /* 246 F6 */
0x0000636b6b3e1818, /* 247 F7 */
0x000036636b7f3600, /* 248 F8 */
0x000063636b7f3600, /* 248 F8 */
0x380c063e66663c00, /* 249 F9 */
0x00316b46007f0000, /* 250 FA */
0x007e007e007e0000, /* 251 FB */
0x071c701c07007f00, /* 252 FC */
0x060c7e187e306000, /* 253 FD */
0x701c071c70007f00, /* 254 FE */
0xffffffffffffffff, /* 255 FF */
};

static const unsigned char charcodes[] =
{
0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27,
0x28, 0x29, 0x2a, 0x2b, 0x2c, 0x2d, 0x2e, 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
0xe0, 0xe0, 0xe1, 0xe2, 0xe3, 0xe4, 0xe5, 0xe6,
0xe7, 0xe8, 0xe9, 0xea, 0xeb, 0xec, 0xed, 0xee,
0xee, 0xef, 0xf0, 0xf1, 0xf2, 0xf3, 0xf4, 0xf5,
0xf6, 0xf7, 0xf8, 0xf8, 0xf9, 0xfa, 0xfb, 0xfc,
0xfd, 0xfe, 0xff
};

/*
Expand Down Expand Up @@ -209,13 +431,27 @@ static void textsave_bitmap(const char *filename, FILE *fp, uint_least16_t mem_a
}
}
log_debug("textsave: chbits=%016lx", chbits);
int ch = ' ';
for (int i = 0; i < 96; ++i) {
int ch = 0;
for (int i = 0; i < sizeof(charcodes); ++i) {
if (chbits == charset[i]) {
ch = i + 32;
ch = charcodes[i];
break;
}
}
if (!ch) {
if (chbits == 0x66003c6666663c00) {
/* This bit pattern is includes in both the
* MOS 3.20 and MOS 3.50 character definitions,
* but with a different code in each so we need
* to work out which version of MOS is running.
*/
uint_least8_t byte = rom[15*ROM_SIZE+0x3c29];
log_debug("textsave: byte=%02X", byte);
ch = byte ? 0x95 : 0x85;
}
else
ch = ' ';
}
log_debug("textsave: ch=%02X '%c'", ch, ch);
if (ch == ' ')
++spaces;
Expand Down Expand Up @@ -259,3 +495,4 @@ void textsave(const char *filename)
log_error("unable to open file %s: %s\n", filename, strerror(errno));
}
}

0 comments on commit 948706c

Please sign in to comment.