From: Daniel Serpell Date: Mon, 18 Feb 2019 12:28:00 +0000 (-0300) Subject: Don't write INITAD if the memory area is empty. X-Git-Url: https://git.sur5r.net/?a=commitdiff_plain;h=61463e1a7051ede837ae83e377ddabc8b7cbb50a;p=cc65 Don't write INITAD if the memory area is empty. --- 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));