comparison tools/lib64fmts.c @ 2139:84780a9d8d17

Improve and fix charmap format decoding.
author Matti Hamalainen <ccr@tnsp.org>
date Wed, 29 May 2019 13:11:00 +0300
parents fdd0fd7dc0e6
children 009ee261704c
comparison
equal deleted inserted replaced
2138:fdd0fd7dc0e6 2139:84780a9d8d17
87 87
88 return DM_PROBE_SCORE_FALSE; 88 return DM_PROBE_SCORE_FALSE;
89 } 89 }
90 90
91 91
92 static int fmtSetMarqPETSCIIData(const DMC64EncDecOp *op, DMC64Image *img,
93 const DMGrowBuf *buf, const DMC64ImageCommonFormat *fmt)
94 {
95 (void) op;
96 (void) buf;
97 (void) fmt;
98
99 switch (img->extraData[0].data[0])
100 {
101 case 20: img->extraInfo[D64_EI_CHAR_CASE] = 0; break; // upper case
102 case 23: img->extraInfo[D64_EI_CHAR_CASE] = 1; break; // lower case
103 default:
104 return DMERR_INVALID_DATA;
105 }
106
107 img->extraInfo[D64_EI_CHAR_MODE] = D64_FMT_HIRES;
108 img->extraInfo[D64_EI_CHAR_CUSTOM] = 0;
109
110 return DMERR_OK;
111 }
112
113
92 static int fmtGetPixelPETSCII(Uint8 *col, 114 static int fmtGetPixelPETSCII(Uint8 *col,
93 const DMC64Image *img, const int rasterX, const int rasterY) 115 const DMC64Image *img, const int rasterX, const int rasterY)
94 { 116 {
95 DM_C64_GENERIC_CHAR_PIXEL(img) 117 DM_C64_GENERIC_CHAR_PIXEL(img)
96 int chr = img->screen[0].data[scroffs]; 118 int chr = img->screen[0].data[scroffs];
97 119
98 if (img->extraData[0].data != NULL) 120 if (!img->extraInfo[D64_EI_CHAR_CUSTOM] &&
99 { 121 img->extraInfo[D64_EI_CHAR_CASE])
100 // Marq's PETSCII editor 122 chr += 256; // lower case, so add 256 to char ROM offset
101 // d018 has been copied to extraData[0].data[0] 123
102 switch (img->extraData[0].data[0]) 124 switch (img->extraInfo[D64_EI_CHAR_MODE])
103 { 125 {
104 case 23: chr += 256; break; // lower case, so add 256 to char ROM offset 126 case D64_FMT_HIRES:
105 case 20: break; // upper case 127 return dmC64GetGenericCharSCPixel(
106 default: 128 col, img,
107 return DMERR_INVALID_DATA; 129 scroffs, rasterX,
108 } 130 0, (chr * D64_CHR_SIZE) + (rasterY & 7), chr,
109 } 131 0, img->bgcolor);
110 else 132
111 if (img->extraData[1].data != NULL) 133 case D64_FMT_MC:
112 {
113 // petscii.krissz.hu editor
114 if (img->extraData[1].data[0x0028 - 2] == 0xd8)
115 {
116 return dmC64GetGenericCharMCPixel( 134 return dmC64GetGenericCharMCPixel(
117 col, img, 135 col, img,
118 scroffs, rasterX, 136 scroffs, rasterX,
119 0, (chr * D64_CHR_SIZE) + (rasterY & 7), chr, 137 0, (chr * D64_CHR_SIZE) + (rasterY & 7), chr,
120 0, img->bgcolor, img->d022, img->d023); 138 0, img->bgcolor, img->d022, img->d023);
121 } 139
122 else 140 case D64_FMT_ECM:
123 if (img->extraData[1].data[0x0028 - 2] == 0x01)
124 {
125 return dmC64GetGenericCharECMPixel( 141 return dmC64GetGenericCharECMPixel(
126 col, img, 142 col, img,
127 scroffs, rasterX, 143 scroffs, rasterX,
128 0, ((chr & 0x3f) * D64_CHR_SIZE) + (rasterY & 7), chr, 144 0, ((chr & 0x3f) * D64_CHR_SIZE) + (rasterY & 7), chr,
129 0, img->bgcolor, img->d022, img->d023, img->d024); 145 0, img->bgcolor, img->d022, img->d023, img->d024);
130 } 146
147 default:
148 return DMERR_INVALID_DATA;
131 } 149 }
132
133 return dmC64GetGenericCharSCPixel(
134 col, img,
135 scroffs, rasterX,
136 0, (chr * D64_CHR_SIZE) + (rasterY & 7), chr,
137 0, img->bgcolor);
138 } 150 }
139 151
140 152
141 static const Uint8 fmtPetsciiKrisszHu_ID1[] = 153 static const Uint8 fmtPetsciiKrisszHu_ID1[] =
142 { 154 {
159 DM_MEMCMP_SIZE(buf->data + 0x10, fmtPetsciiKrisszHu_ID2) == 0 171 DM_MEMCMP_SIZE(buf->data + 0x10, fmtPetsciiKrisszHu_ID2) == 0
160 ) 172 )
161 return DM_PROBE_SCORE_MAX; 173 return DM_PROBE_SCORE_MAX;
162 174
163 return DM_PROBE_SCORE_FALSE; 175 return DM_PROBE_SCORE_FALSE;
176 }
177
178
179 static int fmtSetPetsciiKrisszHuData(const DMC64EncDecOp *op, DMC64Image *img,
180 const DMGrowBuf *buf, const DMC64ImageCommonFormat *fmt)
181 {
182 (void) op;
183 (void) buf;
184 (void) fmt;
185
186 const Uint8 *data = img->extraData[0].data;
187 switch (data[0x0028 - 2])
188 {
189 case 0x00:
190 img->extraInfo[D64_EI_CHAR_MODE] = D64_FMT_HIRES;
191 img->d020 = data[0x001e - 2];
192 img->bgcolor = data[0x0023 - 2];
193 break;
194
195 case 0xd8:
196 img->extraInfo[D64_EI_CHAR_MODE] = D64_FMT_MC;
197 img->d020 = data[0x001e - 2];
198 img->bgcolor = data[0x0023 - 2];
199 img->d022 = data[0x002d - 2];
200 img->d023 = data[0x0032 - 2];
201 break;
202
203 case 0x01:
204 img->extraInfo[D64_EI_CHAR_MODE] = D64_FMT_ECM;
205 img->d020 = data[0x001e - 2];
206 img->bgcolor = data[0x0023 - 2];
207 img->d022 = data[0x0028 - 2];
208 img->d023 = data[0x002d - 2];
209 img->d024 = data[0x0032 - 2];
210 break;
211
212 default:
213 return DMERR_INVALID_DATA;
214 }
215
216 // XXX TODO this format saves the charset data (for 256 chars)
217 // in the PRG and there is no direct indication whether it is
218 // a customized one or copy of C64 ROM charset .. we could
219 // implement a hash-based detection at some point.
220 img->extraInfo[D64_EI_CHAR_CASE] = 0;
221 img->extraInfo[D64_EI_CHAR_CUSTOM] = 1;
222
223 return DMERR_OK;
164 } 224 }
165 225
166 226
167 static int fmtProbeKoalaPainter(const DMGrowBuf *buf, const DMC64ImageFormat *fmt) 227 static int fmtProbeKoalaPainter(const DMGrowBuf *buf, const DMC64ImageFormat *fmt)
168 { 228 {
2139 { DO_COPY , DS_COLOR_RAM , 0x60 + 1000, 0, 0, 0, NULL, NULL }, 2199 { DO_COPY , DS_COLOR_RAM , 0x60 + 1000, 0, 0, 0, NULL, NULL },
2140 2200
2141 // For offset values see petscii/m_c64.pde :: save_prg() 2201 // For offset values see petscii/m_c64.pde :: save_prg()
2142 { DO_SET_MEM_LO , DS_D020 , 25 - 2, 0, 0, 0, NULL, NULL }, 2202 { DO_SET_MEM_LO , DS_D020 , 25 - 2, 0, 0, 0, NULL, NULL },
2143 { DO_SET_MEM_LO , DS_BGCOL , 30 - 2, 0, 0, 0, NULL, NULL }, 2203 { DO_SET_MEM_LO , DS_BGCOL , 30 - 2, 0, 0, 0, NULL, NULL },
2144 { DO_COPY , DS_EXTRA_DATA , 20 - 2, 0, 1, 0, NULL, NULL }, // upper/lower 2204 { DO_COPY , DS_EXTRA_DATA , 20 - 2, 0, 1, 0, NULL, NULL },
2205 { DO_FUNC , 0 , 0 , 0, 0, 0, fmtSetMarqPETSCIIData, NULL },
2145 2206
2146 { DO_LAST , 0 , 0 , 0, 0, 0, NULL, NULL }, 2207 { DO_LAST , 0 , 0 , 0, 0, 0, NULL, NULL },
2147 } 2208 }
2148 }, 2209 },
2149 NULL 2210 NULL
2152 { 2213 {
2153 "pkhu", "petscii.krissz.hu editor (unpacked)", 0x0801, 0, DM_FMT_RD, 2214 "pkhu", "petscii.krissz.hu editor (unpacked)", 0x0801, 0, DM_FMT_RD,
2154 fmtProbePetsciiKrisszHu, 2215 fmtProbePetsciiKrisszHu,
2155 NULL, NULL, 2216 NULL, NULL,
2156 { 2217 {
2157 D64_FMT_HIRES | D64_FMT_CHAR, 2218 D64_FMT_CHAR,
2158 D64_SCR_WIDTH , D64_SCR_HEIGHT, 2219 D64_SCR_WIDTH , D64_SCR_HEIGHT,
2159 D64_SCR_CH_WIDTH, D64_SCR_CH_HEIGHT, 2220 D64_SCR_CH_WIDTH, D64_SCR_CH_HEIGHT,
2160 1, 1, 2221 1, 1,
2161 NULL, NULL, 2222 NULL, NULL,
2162 fmtGetPixelPETSCII, 2223 fmtGetPixelPETSCII,
2163 { 2224 {
2164 { DO_COPY , DS_SCREEN_RAM , 0x2001 - 2, 0, 0, 0, NULL, NULL }, 2225 { DO_COPY , DS_SCREEN_RAM , 0x2001 - 2, 0, 0, 0, NULL, NULL },
2165 { DO_COPY , DS_COLOR_RAM , 0x23e9 - 2, 0, 0, 0, NULL, NULL }, 2226 { DO_COPY , DS_COLOR_RAM , 0x23e9 - 2, 0, 0, 0, NULL, NULL },
2166 2227
2167 { DO_SET_MEM_LO , DS_D020 , 0x001e - 2, 0, 0, 0, NULL, NULL }, 2228 { DO_COPY , DS_EXTRA_DATA , 0x0000 , 0, 0x0100, 0, NULL, NULL },
2168 { DO_SET_MEM_LO , DS_BGCOL , 0x0023 - 2, 0, 0, 0, NULL, NULL }, 2229 { DO_COPY , DS_CHAR_DATA , 0x1801 - 2, 0, 0x0800, 0, NULL, NULL },
2169 2230 { DO_FUNC , 0 , 0 , 0, 0 , 0, fmtSetPetsciiKrisszHuData, NULL },
2170 { DO_SET_MEM_LO , DS_D022 , 0x0028 - 2, 0, 0, 0, NULL, NULL },
2171 { DO_SET_MEM_LO , DS_D023 , 0x002d - 2, 0, 0, 0, NULL, NULL },
2172 { DO_SET_MEM_LO , DS_D024 , 0x0032 - 2, 0, 0, 0, NULL, NULL },
2173
2174 { DO_COPY , DS_EXTRA_DATA , 0x0000 , 1, 0x0100, 0, NULL, NULL },
2175
2176 { DO_COPY , DS_CHAR_DATA , 0x1801 - 2, 0, 0x0800, 0, NULL, NULL },
2177 2231
2178 { DO_LAST , 0 , 0 , 0, 0, 0, NULL, NULL }, 2232 { DO_LAST , 0 , 0 , 0, 0, 0, NULL, NULL },
2179 } 2233 }
2180 }, 2234 },
2181 NULL 2235 NULL