comparison tools/lib64fmts.c @ 2368:4cd67faadbd3

Fix encoding and improve decoding of character set case (upper/lower) for two PETSCII formats. Also generalize the functions a bit.
author Matti Hamalainen <ccr@tnsp.org>
date Tue, 07 Jan 2020 17:40:26 +0200
parents 36226425aac1
children 82cb32297ed2
comparison
equal deleted inserted replaced
2367:36226425aac1 2368:4cd67faadbd3
101 101
102 return DM_PROBE_SCORE_FALSE; 102 return DM_PROBE_SCORE_FALSE;
103 } 103 }
104 104
105 105
106 static int fmtDecodeMarqPETSCIIData(const DMC64EncDecOp *op, DMC64Image *img, 106 static int fmtDecodeHiresPETSCIICharsetData(const DMC64EncDecOp *op, DMC64Image *img,
107 const DMGrowBuf *buf, const DMC64ImageCommonFormat *fmt) 107 const DMGrowBuf *buf, const DMC64ImageCommonFormat *fmt)
108 { 108 {
109 (void) op;
110 (void) buf;
111 (void) fmt; 109 (void) fmt;
112 110 Uint8 val;
113 switch (img->extraData[0].data[0]) 111
114 { 112 switch (buf->data[op->offs])
115 case 20: img->extraInfo[D64_EI_CHAR_CASE] = 0; break; // upper case 113 {
116 case 23: img->extraInfo[D64_EI_CHAR_CASE] = 1; break; // lower case 114 case 0x14: val = 0; break; // upper case
115 case 0x17: val = 1; break; // lower case
117 default: 116 default:
118 return DMERR_INVALID_DATA; 117 return DMERR_INVALID_DATA;
119 } 118 }
120 119
120 img->extraInfo[D64_EI_CHAR_CASE] = val;
121 img->extraInfo[D64_EI_MODE] = D64_FMT_HIRES | D64_FMT_CHAR; 121 img->extraInfo[D64_EI_MODE] = D64_FMT_HIRES | D64_FMT_CHAR;
122 img->extraInfo[D64_EI_CHAR_CUSTOM] = 0; 122 img->extraInfo[D64_EI_CHAR_CUSTOM] = 0;
123 123
124 return DMERR_OK; 124 return DMERR_OK;
125 } 125 }
126 126
127 127
128 static int fmtEncodeHiresPETSCIICharsetData(
129 const DMC64EncDecOp *op, DMGrowBuf *buf, const DMC64Image *img)
130 {
131 Uint8 val;
132
133 switch (img->extraInfo[D64_EI_CHAR_CASE])
134 {
135 case 0: val = 0x14; break;
136 case 1: val = 0x17; break;
137 default: return DMERR_INVALID_DATA;
138 }
139
140 buf->data[op->offs + 2] = val;
141
142 return DMERR_OK;
143 }
144
145
128 static int fmtEncodeMarqPETSCIIData(const DMC64EncDecOp *op, DMGrowBuf *buf, 146 static int fmtEncodeMarqPETSCIIData(const DMC64EncDecOp *op, DMGrowBuf *buf,
129 const DMC64Image *img, const DMC64ImageCommonFormat *fmt) 147 const DMC64Image *img, const DMC64ImageCommonFormat *fmt)
130 { 148 {
131 (void) op;
132 (void) img;
133 (void) fmt; 149 (void) fmt;
134 Uint8 val;
135
136 switch (img->extraInfo[D64_EI_CHAR_CASE])
137 {
138 case 0: val = 20; break;
139 case 1: val = 23; break;
140 default: return DMERR_INVALID_DATA;
141 }
142
143 img->extraData[0].data[0] = val;
144 150
145 memcpy(buf->data, 151 memcpy(buf->data,
146 fmtMarqPETSCII_ID1, sizeof(fmtMarqPETSCII_ID1)); 152 fmtMarqPETSCII_ID1, sizeof(fmtMarqPETSCII_ID1));
147 153
148 memcpy(buf->data + sizeof(fmtMarqPETSCII_ID1), 154 memcpy(buf->data + sizeof(fmtMarqPETSCII_ID1),
149 fmtMarqPETSCII_ID2, sizeof(fmtMarqPETSCII_ID2)); 155 fmtMarqPETSCII_ID2, sizeof(fmtMarqPETSCII_ID2));
150 156
151 memcpy(buf->data + sizeof(fmtMarqPETSCII_ID1) + sizeof(fmtMarqPETSCII_ID2), 157 memcpy(buf->data + sizeof(fmtMarqPETSCII_ID1) + sizeof(fmtMarqPETSCII_ID2),
152 fmtMarqPETSCII_ID3, sizeof(fmtMarqPETSCII_ID3)); 158 fmtMarqPETSCII_ID3, sizeof(fmtMarqPETSCII_ID3));
153 159
154 return DMERR_OK; 160 return fmtEncodeHiresPETSCIICharsetData(op, buf, img);
155 } 161 }
156 162
157 163
158 static const Uint8 fmtPetsciiKrisszHu_ID1[] = 164 static const Uint8 fmtPetsciiKrisszHu_ID1[] =
159 { 165 {
254 0x5a, 0x0f, 0x9d, 0x00, 0xdb, 0xe8, 0xd0, 0xcd, 0xad, 0x42, 260 0x5a, 0x0f, 0x9d, 0x00, 0xdb, 0xe8, 0xd0, 0xcd, 0xad, 0x42,
255 0x0c, 0x8d, 0x20, 0xd0, 0xad, 0x43, 0x0c, 0x8d, 0x21, 0xd0, 261 0x0c, 0x8d, 0x20, 0xd0, 0xad, 0x43, 0x0c, 0x8d, 0x21, 0xd0,
256 0xad, 0x44, 0x0c, 0x8d, 0x18, 0xd0, 0x4c, 0x55, 0x08 262 0xad, 0x44, 0x0c, 0x8d, 0x18, 0xd0, 0x4c, 0x55, 0x08
257 }; 263 };
258 264
265
259 static int fmtProbeCocaPETSCII(const DMGrowBuf *buf, const DMC64ImageFormat *fmt) 266 static int fmtProbeCocaPETSCII(const DMGrowBuf *buf, const DMC64ImageFormat *fmt)
260 { 267 {
261 (void) fmt; 268 (void) fmt;
262 269
263 if (buf->len == 2115 && 270 if (buf->len == 2115 &&
270 277
271 278
272 static int fmtEncodeCocaPETSCIIData(const DMC64EncDecOp *op, DMGrowBuf *buf, 279 static int fmtEncodeCocaPETSCIIData(const DMC64EncDecOp *op, DMGrowBuf *buf,
273 const DMC64Image *img, const DMC64ImageCommonFormat *fmt) 280 const DMC64Image *img, const DMC64ImageCommonFormat *fmt)
274 { 281 {
275 (void) op;
276 (void) img;
277 (void) fmt; 282 (void) fmt;
278 283
279 memcpy(buf->data, 284 memcpy(buf->data,
280 fmtCocaPETSCII_ID1, sizeof(fmtCocaPETSCII_ID1)); 285 fmtCocaPETSCII_ID1, sizeof(fmtCocaPETSCII_ID1));
281 286
282 buf->data[0x0c44 - 0x0801 + 2] = 0x14; 287 return fmtEncodeHiresPETSCIICharsetData(op, buf, img);
283
284 return DMERR_OK;
285 } 288 }
286 289
287 290
288 static int fmtProbeKoalaPainter(const DMGrowBuf *buf, const DMC64ImageFormat *fmt) 291 static int fmtProbeKoalaPainter(const DMGrowBuf *buf, const DMC64ImageFormat *fmt)
289 { 292 {
2755 1, 1, 2758 1, 1,
2756 NULL, NULL, 2759 NULL, NULL,
2757 NULL, 2760 NULL,
2758 { 2761 {
2759 // For offset values see petscii/m_c64.pde :: save_prg() 2762 // For offset values see petscii/m_c64.pde :: save_prg()
2760 { DO_FUNC , 0 , 0 , 0, 0, 0, NULL, fmtEncodeMarqPETSCIIData, DF_NORMAL }, 2763 { DO_FUNC , 0 , 20 - 2, 0, 0, 0, NULL, fmtEncodeMarqPETSCIIData, DF_NORMAL },
2761 { DO_COPY , DS_SCREEN_RAM , 0x60 , 0, 0, 0, NULL, NULL, DF_NORMAL }, 2764 { DO_COPY , DS_SCREEN_RAM , 0x60 , 0, 0, 0, NULL, NULL, DF_NORMAL },
2762 { DO_COPY , DS_COLOR_RAM , 0x60 + 1000,0,0, 0, NULL, NULL, DF_NORMAL }, 2765 { DO_COPY , DS_COLOR_RAM , 0x60 + 1000,0,0, 0, NULL, NULL, DF_NORMAL },
2763 { DO_SET_MEM_LO , DS_D020 , 25 - 2, 0, 0, 0, NULL, NULL, DF_NORMAL }, 2766 { DO_SET_MEM_LO , DS_D020 , 25 - 2, 0, 0, 0, NULL, NULL, DF_NORMAL },
2764 { DO_SET_MEM_LO , DS_BGCOL , 30 - 2, 0, 0, 0, NULL, NULL, DF_NORMAL }, 2767 { DO_SET_MEM_LO , DS_BGCOL , 30 - 2, 0, 0, 0, NULL, NULL, DF_NORMAL },
2765 { DO_COPY , DS_EXTRA_DATA , 20 - 2, 0, 1, 0, NULL, NULL, DF_NORMAL }, 2768 { DO_FUNC , 0 , 20 - 2, 0, 0, 0, fmtDecodeHiresPETSCIICharsetData, NULL, DF_NORMAL },
2766 { DO_FUNC , 0 , 0 , 0, 0, 0, fmtDecodeMarqPETSCIIData, NULL, DF_NORMAL },
2767 2769
2768 { DO_LAST , 0 , 0 , 0, 0, 0, NULL, NULL, DF_NORMAL }, 2770 { DO_LAST , 0 , 0 , 0, 0, 0, NULL, NULL, DF_NORMAL },
2769 } 2771 }
2770 }, 2772 },
2771 NULL 2773 NULL
2831 D64_SCR_CH_WIDTH, D64_SCR_CH_HEIGHT, 2833 D64_SCR_CH_WIDTH, D64_SCR_CH_HEIGHT,
2832 1, 1, 2834 1, 1,
2833 NULL, NULL, 2835 NULL, NULL,
2834 NULL, 2836 NULL,
2835 { 2837 {
2836 { DO_FUNC , 0 , 0 , 0, 0, 0, NULL, fmtEncodeCocaPETSCIIData, DF_NORMAL }, 2838 { DO_FUNC , 0 , 0x0c44 - 0x0801, 0, 0, 0, NULL, fmtEncodeCocaPETSCIIData, DF_NORMAL },
2837 { DO_COPY , DS_SCREEN_RAM , 0x085a - 0x0801, 0, 0, 0, NULL, NULL, DF_NORMAL }, 2839 { DO_COPY , DS_SCREEN_RAM , 0x085a - 0x0801, 0, 0, 0, NULL, NULL, DF_NORMAL },
2838 { DO_COPY , DS_COLOR_RAM , 0x0c5a - 0x0801, 0, 0, 0, NULL, NULL, DF_NORMAL }, 2840 { DO_COPY , DS_COLOR_RAM , 0x0c5a - 0x0801, 0, 0, 0, NULL, NULL, DF_NORMAL },
2839 2841
2840 { DO_SET_MEM_LO , DS_D020 , 0x0c42 - 0x0801, 0, 0, 0, NULL, NULL, DF_NORMAL }, 2842 { DO_SET_MEM_LO , DS_D020 , 0x0c42 - 0x0801, 0, 0, 0, NULL, NULL, DF_NORMAL },
2841 { DO_SET_MEM_LO , DS_BGCOL , 0x0c43 - 0x0801, 0, 0, 0, NULL, NULL, DF_NORMAL }, 2843 { DO_SET_MEM_LO , DS_BGCOL , 0x0c43 - 0x0801, 0, 0, 0, NULL, NULL, DF_NORMAL },
2844 { DO_FUNC , 0 , 0x0c44 - 0x0801, 0, 0, 0, fmtDecodeHiresPETSCIICharsetData, NULL, DF_NORMAL },
2842 2845
2843 { DO_LAST , 0 , 0 , 0, 0, 0, NULL, NULL, DF_NORMAL }, 2846 { DO_LAST , 0 , 0 , 0, 0, 0, NULL, NULL, DF_NORMAL },
2844 } 2847 }
2845 }, 2848 },
2846 NULL 2849 NULL