changeset 2287:631bbd451d08

Add write support for Marq's PETSCII editor PRG export format.
author Matti Hamalainen <ccr@tnsp.org>
date Thu, 20 Jun 2019 14:49:01 +0300
parents e771185db600
children a46a5d2833bb 180604abb65a
files tools/lib64fmts.c
diffstat 1 files changed, 53 insertions(+), 11 deletions(-) [+]
line wrap: on
line diff
--- a/tools/lib64fmts.c	Thu Jun 20 14:46:09 2019 +0300
+++ b/tools/lib64fmts.c	Thu Jun 20 14:49:01 2019 +0300
@@ -64,14 +64,25 @@
 static const Uint8 fmtMarqPETSCII_ID1[] =
 {
     0x01, 0x08, 0x0b, 0x08, 0xef, 0x00, 0x9e, 0x32, 0x30, 0x36,
-    0x31, 0x00, 0x00, 0x00, 0xa9, 0x0b, 0x8d, 0x11, 0xd0, 0xa9,
+    0x31, 0x00, 0x00, 0x00, 0xa9, 0x0b, 0x8d, 0x11, 0xd0,
 };
 
 static const Uint8 fmtMarqPETSCII_ID2[] =
 {
-    0x8d, 0x21, 0xd0, 0xa2, 0x00, 0xa0, 0xfa, 0xbd, 0x61, 0x08,
-    0x9d, 0x00, 0x04, 0xbd, 0x5b, 0x09, 0x9d, 0xfa, 0x04, 0xbd,
-    0x55, 0x0a, 0x9d, 0xf4,
+    0xa9, 0x00, 0x8d, 0x18, 0xd0, // lda #? : sta $d018
+    0xa9, 0x00, 0x8d, 0x20, 0xd0, // lda #? : sta $d020
+    0xa9, 0x00, 0x8d, 0x21, 0xd0, // lda #? : sta $d021
+};
+
+static const Uint8 fmtMarqPETSCII_ID3[] =
+{
+    0xa2, 0x00, 0xa0, 0xfa, 0xbd, 0x61,
+    0x08, 0x9d, 0x00, 0x04, 0xbd, 0x5b, 0x09, 0x9d, 0xfa, 0x04,
+    0xbd, 0x55, 0x0a, 0x9d, 0xf4, 0x05, 0xbd, 0x4f, 0x0b, 0x9d,
+    0xee, 0x06, 0xbd, 0x49, 0x0c, 0x9d, 0x00, 0xd8, 0xbd, 0x43,
+    0x0d, 0x9d, 0xfa, 0xd8, 0xbd, 0x3d, 0x0e, 0x9d, 0xf4, 0xd9,
+    0xbd, 0x37, 0x0f, 0x9d, 0xee, 0xda, 0xe8, 0x88, 0xd0, 0xcc,
+    0xa9, 0x1b, 0x8d, 0x11, 0xd0, 0x4c, 0x5e, 0x08,
 };
 
 
@@ -81,7 +92,8 @@
 
     if (buf->len == 2098 &&
         DM_MEMCMP_SIZE(buf->data, fmtMarqPETSCII_ID1) == 0 &&
-        DM_MEMCMP_SIZE(buf->data + 0x1f, fmtMarqPETSCII_ID2) == 0
+        DM_MEMCMP_SIZE(buf->data + sizeof(fmtMarqPETSCII_ID1) +
+            sizeof(fmtMarqPETSCII_ID2), fmtMarqPETSCII_ID3) == 0
         )
         return DM_PROBE_SCORE_MAX;
 
@@ -89,7 +101,7 @@
 }
 
 
-static int fmtSetMarqPETSCIIData(const DMC64EncDecOp *op, DMC64Image *img,
+static int fmtGetMarqPETSCIIData(const DMC64EncDecOp *op, DMC64Image *img,
     const DMGrowBuf *buf, const DMC64ImageCommonFormat *fmt)
 {
     (void) op;
@@ -111,6 +123,36 @@
 }
 
 
+static int fmtSetMarqPETSCIIData(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));
+
+    memcpy(buf->data + sizeof(fmtMarqPETSCII_ID1),
+        fmtMarqPETSCII_ID2, sizeof(fmtMarqPETSCII_ID2));
+
+    memcpy(buf->data + sizeof(fmtMarqPETSCII_ID1) + sizeof(fmtMarqPETSCII_ID2),
+        fmtMarqPETSCII_ID3, sizeof(fmtMarqPETSCII_ID3));
+
+    return DMERR_OK;
+}
+
+
 static const Uint8 fmtPetsciiKrisszHu_ID1[] =
 {
     0x01, 0x08, 0x0b, 0x08, 0x0A, 0x00, 0x9E, 0x32, 0x30, 0x36,
@@ -2545,7 +2587,7 @@
     },
 
     {
-        "mrqp", "Marq's PETSCII editor (unpacked)", 0x0801, 0, DM_FMT_RD,
+        "mrqp", "Marq's PETSCII editor (unpacked)", 0x0801, 0, DM_FMT_RDWR,
         fmtProbeMarqPETSCII,
         NULL, NULL,
         {
@@ -2556,14 +2598,14 @@
             NULL, NULL,
             NULL,
             {
-                { 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 },
-
                 // For offset values see petscii/m_c64.pde :: save_prg()
+                { DO_FUNC       , 0              , 0     , 0,  0,   0, NULL, fmtSetMarqPETSCIIData, 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, fmtSetMarqPETSCIIData, NULL, DF_NORMAL },
+                { DO_FUNC       , 0              , 0     , 0,  0,   0, fmtGetMarqPETSCIIData, NULL, DF_NORMAL },
 
                 { DO_LAST       , 0              , 0     , 0,  0,   0, NULL, NULL, DF_NORMAL },
             }