From f7bc6a836d13a3e7d6604a6bddd7b2c695e4bc20 Mon Sep 17 00:00:00 2001 From: Christian Groessler Date: Wed, 21 May 2014 23:43:56 +0200 Subject: [PATCH] Set the "simple" bit in the .o65 mode word only if text, data, and bss are adjacent. --- src/ld65/o65.c | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/src/ld65/o65.c b/src/ld65/o65.c index ad793b48b..8274d6b06 100644 --- a/src/ld65/o65.c +++ b/src/ld65/o65.c @@ -1320,18 +1320,26 @@ static void O65SetupHeader (O65Desc* D) SegDesc* FirstSeg = D->ZPSeg [0]; D->Header.ZPBase = FirstSeg->Seg->PC; } +} + + - /* If we have byte wise relocation and an alignment of 1, we can set - * the "simple addressing" bit in the header. +static void O65UpdateHeader (O65Desc* D) +/* Update mode word, currently only the "simple" bit */ +{ + /* If we have byte wise relocation and an alignment of 1, and text + * and data are adjacent, we can set the "simple addressing" bit + * in the header. */ if ((D->Header.Mode & MF_RELOC_MASK) == MF_RELOC_BYTE && - (D->Header.Mode & MF_ALIGN_MASK) == MF_ALIGN_1) { + (D->Header.Mode & MF_ALIGN_MASK) == MF_ALIGN_1 && + D->Header.TextBase + D->Header.TextSize == D->Header.DataBase && + D->Header.DataBase + D->Header.DataSize == D->Header.BssBase) { D->Header.Mode = (D->Header.Mode & ~MF_ADDR_MASK) | MF_ADDR_SIMPLE; } } - void O65WriteTarget (O65Desc* D, File* F) /* Write an o65 output file */ { @@ -1411,6 +1419,9 @@ void O65WriteTarget (O65Desc* D, File* F) /* Write the list of exports */ O65WriteExports (D); + /* Update header flags */ + O65UpdateHeader (D); + /* Seek back to the start and write the updated header */ fseek (D->F, 0, SEEK_SET); O65WriteHeader (D); -- 2.39.5