shithub: rgbds

Download patch

ref: 7e3720b62720ee467c5379a56c3af3087b6bff42
parent: e9ed81074b05f59bbe08e029285480683e45a88a
author: AntonioND <[email protected]>
date: Sun Apr 2 17:55:16 EDT 2017

Make options -t and -w consistent

Instead of converting from ROMX to ROM0 with -t and preventing the use
of WRAMX at all with -w, make each option prohibit the type of section
they affect.

This is a good idea because it can prevent a developer from making
mistakes when switching from using the options to not using them.
Generally, a change from using one single bank to multiple banks is
something that will take a lot of effort, and forgetting sections in
ROM0 or WRAM0 will only make the free space of those areas to be
reduced (and maybe prevent compilation), but it won't cause any problems
because of a forgotten bank swap in the code.

Signed-off-by: AntonioND <[email protected]>

--- a/src/link/assign.c
+++ b/src/link/assign.c
@@ -398,15 +398,7 @@
 		} else if (i >= BANK_ROMX && i < BANK_ROMX + BANK_COUNT_ROMX) {
 			/* Swappable ROM bank */
 			BankFree[i]->nOrg = 0x4000;
-			/*
-			 * Now, this shouldn't really be necessary... but for
-			 * good measure we'll do it anyway.
-			 */
-			if (options & OPT_TINY) {
-				BankFree[i]->nSize = 0;
-			} else {
-				BankFree[i]->nSize = 0x4000;
-			}
+			BankFree[i]->nSize = 0x4000;
 		} else if (i == BANK_WRAM0) {
 			/* WRAM */
 			BankFree[i]->nOrg = 0xC000;
@@ -462,10 +454,6 @@
 		if ((pSection->nOrg != -1 || pSection->nBank != -1)
 		    && pSection->oAssigned == 0) {
 			/* User wants to have a say... */
-
-			if (pSection->Type == SECT_WRAMX && options & OPT_CONTWRAM) {
-				errx(1, "WRAMX not compatible with -w!");
-			}
 
 			switch (pSection->Type) {
 			case SECT_WRAM0:
--- a/src/link/object.c
+++ b/src/link/object.c
@@ -156,11 +156,13 @@
 	pSection->nBank = -1;
 	pSection->nAlign = 1;
 
-	/* does the user want the -s mode? */
-
 	if ((options & OPT_TINY) && (pSection->Type == SECT_ROMX)) {
-		pSection->Type = SECT_ROM0;
+		errx(1, "ROMX sections can't be used with option -t.");
 	}
+	if ((options & OPT_CONTWRAM) && (pSection->Type == SECT_WRAMX)) {
+		errx(1, "WRAMX sections can't be used with option -w.");
+	}
+
 	if ((pSection->Type == SECT_ROMX) || (pSection->Type == SECT_ROM0)) {
 		/*
 		 * These sectiontypes contain data...
@@ -306,7 +308,7 @@
 	pSection->Type = (enum eSectionType) fgetc(f);
 	pSection->nOrg = readlong(f);
 	pSection->nBank = readlong(f);
-	
+
 	if (contents & CONTAINS_SECTION_ALIGNMENT) {
 		pSection->nAlign = readlong(f);
 	} else {
@@ -313,11 +315,13 @@
 		pSection->nAlign = 1;
 	}
 
-	/* does the user want the -s mode? */
-
 	if ((options & OPT_TINY) && (pSection->Type == SECT_ROMX)) {
-		pSection->Type = SECT_ROM0;
+		errx(1,  "ROMX sections can't be used with option -t.");
 	}
+	if ((options & OPT_CONTWRAM) && (pSection->Type == SECT_WRAMX)) {
+		errx(1, "WRAMX sections can't be used with option -w.");
+	}
+
 	if ((pSection->Type == SECT_ROMX) || (pSection->Type == SECT_ROM0)) {
 		/*
 		 * These sectiontypes contain data...
--- a/src/link/rgblink.1
+++ b/src/link/rgblink.1
@@ -29,6 +29,12 @@
 .Fl t
 option to override this.
 .Pp
+Similarly, WRAM0 sections are placed in the first 4KiB of WRAM bank 0 and WRAMX
+sections are placed in any bank except bank 0.
+If your ROM is designed for DMG, you can use the
+.Fl w
+option to override this.
+.Pp
 The arguments are as follows:
 .Bl -tag -width Ds
 .It Fl m Ar mapfile
@@ -47,14 +53,13 @@
 .It Fl s Ar symbol
 ???
 .It Fl w
-Expand WRAM0 to the whole space assigned to WRAM and prevent the use of WRAMX
-sections.
+Expand the WRAM0 section size from 4KiB to the full 8KiB assigned to WRAM and
+prohibit the use of WRAMX sections.
+Useful for ROMs designed for DMG.
 .It Fl t
-Write a tiny
-.Pq 32KiB
-ROM file.
-This forces all ROMX sections to be of type ROM0, and increases the ROM0
-section size from 16KiB to 32KiB.
+Expand the ROM0 section size from 16KiB to the full 32KiB assigned to ROM and
+prohibit the use of ROMX sections.
+Useful for ROMs that fit in 32 KiB.
 .It Fl l Ar linkerscript
 Specify a linkerscript file that tells the linker how sections must be placed in
 the ROM.
--- a/src/link/script.c
+++ b/src/link/script.c
@@ -44,15 +44,7 @@
 		} else if (i >= BANK_ROMX && i < BANK_ROMX + BANK_COUNT_ROMX) {
 			/* Swappable ROM bank */
 			bank[i].address = 0x4000;
-			/*
-			 * Now, this shouldn't really be necessary... but for
-			 * good measure we'll do it anyway.
-			 */
-			if (options & OPT_TINY) {
-				bank[i].top_address = 0x4000;
-			} else {
-				bank[i].top_address = 0x8000;
-			}
+			bank[i].top_address = 0x8000;
 			bank[i].type = SECT_ROMX;
 		} else if (i == BANK_WRAM0) {
 			/* WRAM */