From 17c55041291b0deb880cfd4f5322714fdb6a0a30 Mon Sep 17 00:00:00 2001 From: Daniel Serpell Date: Fri, 3 Jul 2020 23:03:19 -0400 Subject: [PATCH] In Atari XEX output format, join memory areas if possible. This makes executables shorter if two memory areas are consecutive. --- doc/ld65.sgml | 3 ++- src/ld65/xex.c | 6 +++--- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/doc/ld65.sgml b/doc/ld65.sgml index d8e296996..cba06fef4 100644 --- a/doc/ld65.sgml +++ b/doc/ld65.sgml @@ -932,7 +932,8 @@ the standard format used by Atari DOS 2.0 and upward file managers in the Atari In the Atari segmented file format, the linker will write each . diff --git a/src/ld65/xex.c b/src/ld65/xex.c index c57fa0a8c..94f3920b5 100644 --- a/src/ld65/xex.c +++ b/src/ld65/xex.c @@ -241,9 +241,6 @@ static unsigned long XexWriteMem (XexDesc* D, MemoryArea* M) /* Store initial position to get total file size */ unsigned long StartPos = ftell (D->F); - /* Always write a segment header for each memory area */ - D->HeadPos = 0; - /* Get the start address and size of this memory area */ unsigned long Addr = M->Start; @@ -400,6 +397,7 @@ void XexWriteTarget (XexDesc* D, struct File* F) if (D->F == 0) { Error ("Cannot open `%s': %s", D->Filename, strerror (errno)); } + D->HeadPos = 0; /* Keep the user happy */ Print (stdout, 1, "Opened `%s'...\n", D->Filename); @@ -415,6 +413,8 @@ void XexWriteTarget (XexDesc* D, struct File* F) Write16 (D->F, 0x2E2); Write16 (D->F, 0x2E3); Write16 (D->F, GetExportVal (I->InitAd->Exp)); + /* Always write a new segment header after an INITAD segment */ + D->HeadPos = 0; } }