From 61463e1a7051ede837ae83e377ddabc8b7cbb50a Mon Sep 17 00:00:00 2001 From: Daniel Serpell Date: Mon, 18 Feb 2019 09:28:00 -0300 Subject: [PATCH] Don't write INITAD if the memory area is empty. --- src/ld65/xex.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/src/ld65/xex.c b/src/ld65/xex.c index e7674949a..c57fa0a8c 100644 --- a/src/ld65/xex.c +++ b/src/ld65/xex.c @@ -233,11 +233,14 @@ static void XexFakeSegment (XexDesc *D, unsigned long Addr) -static void XexWriteMem (XexDesc* D, MemoryArea* M) +static unsigned long XexWriteMem (XexDesc* D, MemoryArea* M) /* Write the segments of one memory area to a file */ { unsigned I; + /* 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; @@ -355,6 +358,8 @@ static void XexWriteMem (XexDesc* D, MemoryArea* M) if (D->HeadSize == 0 && D->HeadPos) { fseek (D->F, D->HeadPos, SEEK_SET); } + + return ftell (D->F) - StartPos; } @@ -406,8 +411,7 @@ void XexWriteTarget (XexDesc* D, struct File* F) /* See if we have an init address for this area */ XexInitAd* I = XexSearchInitMem (D, M); Print (stdout, 1, " ATARI EXE Dumping `%s'\n", GetString (M->Name)); - XexWriteMem (D, M); - if (I) { + if (XexWriteMem (D, M) && I) { Write16 (D->F, 0x2E2); Write16 (D->F, 0x2E3); Write16 (D->F, GetExportVal (I->InitAd->Exp)); -- 2.39.5