]> Shamusworld >> Repos - rmac/commitdiff
Added support for C64 .PRG output format (#194)
authorggn <ggn@atari.org>
Tue, 20 Dec 2022 21:48:39 +0000 (23:48 +0200)
committerShamus Hammons <jlhamm@acm.org>
Wed, 21 Dec 2022 22:34:54 +0000 (16:34 -0600)
6502.c

diff --git a/6502.c b/6502.c
index db6c638a621947c093f20098d4e77f85b82d0e36..131c6d8c106982d4cd70825ea5e8db5c875b2d52 100644 (file)
--- a/6502.c
+++ b/6502.c
@@ -569,3 +569,32 @@ void m6502obj(int ofd)
        }
 }
 
+
+//
+// Generate a C64 .PRG output file
+//
+void m6502c64(int ofd)
+{
+       uint8_t header[2];
+
+       CHUNK * ch = sect[M6502].scode;
+
+       // If no 6502 code was generated, bail out
+       if ((ch == NULL) || (ch->challoc == 0))
+               return;
+
+       if (currentorg != &orgmap[1][0])
+       {
+               // More than one 6502 section created, this is not allowed
+               error("when generating C64 .PRG files only one org section is allowed - aborting");
+               return;
+       }
+
+       SETLE16(header, 0, orgmap[0][0]);
+       register uint8_t * p = ch->chptr;
+
+       // Write header
+       uint32_t unused = write(ofd, header, 2);
+       // Write the data
+       unused = write(ofd, p + orgmap[0][0], orgmap[0][1] - orgmap[0][0]);
+}