# HG changeset patch # User Matti Hamalainen # Date 1578411626 -7200 # Node ID 4cd67faadbd3cc1aafaacc8981f719f3175d04e8 # Parent 36226425aac136a90398287128102e9f6b1cbf77 Fix encoding and improve decoding of character set case (upper/lower) for two PETSCII formats. Also generalize the functions a bit. diff -r 36226425aac1 -r 4cd67faadbd3 tools/lib64fmts.c --- a/tools/lib64fmts.c Tue Jan 07 15:25:14 2020 +0200 +++ b/tools/lib64fmts.c Tue Jan 07 17:40:26 2020 +0200 @@ -103,21 +103,21 @@ } -static int fmtDecodeMarqPETSCIIData(const DMC64EncDecOp *op, DMC64Image *img, +static int fmtDecodeHiresPETSCIICharsetData(const DMC64EncDecOp *op, DMC64Image *img, const DMGrowBuf *buf, const DMC64ImageCommonFormat *fmt) { - (void) op; - (void) buf; (void) fmt; - - switch (img->extraData[0].data[0]) + Uint8 val; + + switch (buf->data[op->offs]) { - case 20: img->extraInfo[D64_EI_CHAR_CASE] = 0; break; // upper case - case 23: img->extraInfo[D64_EI_CHAR_CASE] = 1; break; // lower case + case 0x14: val = 0; break; // upper case + case 0x17: val = 1; break; // lower case default: return DMERR_INVALID_DATA; } + img->extraInfo[D64_EI_CHAR_CASE] = val; img->extraInfo[D64_EI_MODE] = D64_FMT_HIRES | D64_FMT_CHAR; img->extraInfo[D64_EI_CHAR_CUSTOM] = 0; @@ -125,22 +125,28 @@ } +static int fmtEncodeHiresPETSCIICharsetData( + const DMC64EncDecOp *op, DMGrowBuf *buf, const DMC64Image *img) +{ + Uint8 val; + + switch (img->extraInfo[D64_EI_CHAR_CASE]) + { + case 0: val = 0x14; break; + case 1: val = 0x17; break; + default: return DMERR_INVALID_DATA; + } + + buf->data[op->offs + 2] = val; + + return DMERR_OK; +} + + static int fmtEncodeMarqPETSCIIData(const DMC64EncDecOp *op, DMGrowBuf *buf, const DMC64Image *img, const DMC64ImageCommonFormat *fmt) { - (void) op; - (void) img; (void) fmt; - Uint8 val; - - switch (img->extraInfo[D64_EI_CHAR_CASE]) - { - case 0: val = 20; break; - case 1: val = 23; break; - default: return DMERR_INVALID_DATA; - } - - img->extraData[0].data[0] = val; memcpy(buf->data, fmtMarqPETSCII_ID1, sizeof(fmtMarqPETSCII_ID1)); @@ -151,7 +157,7 @@ memcpy(buf->data + sizeof(fmtMarqPETSCII_ID1) + sizeof(fmtMarqPETSCII_ID2), fmtMarqPETSCII_ID3, sizeof(fmtMarqPETSCII_ID3)); - return DMERR_OK; + return fmtEncodeHiresPETSCIICharsetData(op, buf, img); } @@ -256,6 +262,7 @@ 0xad, 0x44, 0x0c, 0x8d, 0x18, 0xd0, 0x4c, 0x55, 0x08 }; + static int fmtProbeCocaPETSCII(const DMGrowBuf *buf, const DMC64ImageFormat *fmt) { (void) fmt; @@ -272,16 +279,12 @@ static int fmtEncodeCocaPETSCIIData(const DMC64EncDecOp *op, DMGrowBuf *buf, const DMC64Image *img, const DMC64ImageCommonFormat *fmt) { - (void) op; - (void) img; (void) fmt; memcpy(buf->data, fmtCocaPETSCII_ID1, sizeof(fmtCocaPETSCII_ID1)); - buf->data[0x0c44 - 0x0801 + 2] = 0x14; - - return DMERR_OK; + return fmtEncodeHiresPETSCIICharsetData(op, buf, img); } @@ -2757,13 +2760,12 @@ NULL, { // For offset values see petscii/m_c64.pde :: save_prg() - { DO_FUNC , 0 , 0 , 0, 0, 0, NULL, fmtEncodeMarqPETSCIIData, DF_NORMAL }, + { DO_FUNC , 0 , 20 - 2, 0, 0, 0, NULL, fmtEncodeMarqPETSCIIData, DF_NORMAL }, { DO_COPY , DS_SCREEN_RAM , 0x60 , 0, 0, 0, NULL, NULL, DF_NORMAL }, { DO_COPY , DS_COLOR_RAM , 0x60 + 1000,0,0, 0, NULL, NULL, DF_NORMAL }, { DO_SET_MEM_LO , DS_D020 , 25 - 2, 0, 0, 0, NULL, NULL, DF_NORMAL }, { DO_SET_MEM_LO , DS_BGCOL , 30 - 2, 0, 0, 0, NULL, NULL, DF_NORMAL }, - { DO_COPY , DS_EXTRA_DATA , 20 - 2, 0, 1, 0, NULL, NULL, DF_NORMAL }, - { DO_FUNC , 0 , 0 , 0, 0, 0, fmtDecodeMarqPETSCIIData, NULL, DF_NORMAL }, + { DO_FUNC , 0 , 20 - 2, 0, 0, 0, fmtDecodeHiresPETSCIICharsetData, NULL, DF_NORMAL }, { DO_LAST , 0 , 0 , 0, 0, 0, NULL, NULL, DF_NORMAL }, } @@ -2833,12 +2835,13 @@ NULL, NULL, NULL, { - { DO_FUNC , 0 , 0 , 0, 0, 0, NULL, fmtEncodeCocaPETSCIIData, DF_NORMAL }, + { DO_FUNC , 0 , 0x0c44 - 0x0801, 0, 0, 0, NULL, fmtEncodeCocaPETSCIIData, DF_NORMAL }, { DO_COPY , DS_SCREEN_RAM , 0x085a - 0x0801, 0, 0, 0, NULL, NULL, DF_NORMAL }, { DO_COPY , DS_COLOR_RAM , 0x0c5a - 0x0801, 0, 0, 0, NULL, NULL, DF_NORMAL }, { DO_SET_MEM_LO , DS_D020 , 0x0c42 - 0x0801, 0, 0, 0, NULL, NULL, DF_NORMAL }, { DO_SET_MEM_LO , DS_BGCOL , 0x0c43 - 0x0801, 0, 0, 0, NULL, NULL, DF_NORMAL }, + { DO_FUNC , 0 , 0x0c44 - 0x0801, 0, 0, 0, fmtDecodeHiresPETSCIICharsetData, NULL, DF_NORMAL }, { DO_LAST , 0 , 0 , 0, 0, 0, NULL, NULL, DF_NORMAL }, }