shithub: rgbds

Download patch

ref: 5679c7066b0f7365f0696fd07f539e5b9dd82a7d
parent: 4395ed893a0896e11effb79a56be8770454f6177
author: Antonio Niño Díaz <[email protected]>
date: Mon Apr 10 16:03:52 EDT 2017

Restore behaviour of option -w and add option -d

rgblink option -w has been restored to its previous behaviour: make WRAM
a continous section instead of spliting it into WRAM0 and WRAMX.

To enable DMG mode, option -d has to be used instead. This option
automatically enables -w.

Update tests.

Signed-off-by: Antonio Niño Díaz <[email protected]>

--- a/include/link/mylink.h
+++ b/include/link/mylink.h
@@ -11,7 +11,8 @@
 #define OPT_TINY		0x01
 #define OPT_SMART_C_LINK	0x02
 #define OPT_OVERLAY		0x04
-#define OPT_DMG_MODE		0x08
+#define OPT_CONTWRAM		0x08
+#define OPT_DMG_MODE		0x10
 
 enum eRpnData {
 	RPN_ADD = 0,
--- a/src/link/assign.c
+++ b/src/link/assign.c
@@ -402,7 +402,7 @@
 		} else if (i == BANK_WRAM0) {
 			/* WRAM */
 			BankFree[i]->nOrg = 0xC000;
-			if (options & OPT_DMG_MODE) {
+			if (options & OPT_CONTWRAM) {
 				BankFree[i]->nSize = 0x2000;
 			} else {
 				BankFree[i]->nSize = 0x1000;
--- a/src/link/main.c
+++ b/src/link/main.c
@@ -33,7 +33,7 @@
 usage(void)
 {
 	printf(
-"usage: rgblink [-tw] [-l linkerscript] [-m mapfile] [-n symfile] [-O overlay]\n"
+"usage: rgblink [-twd] [-l linkerscript] [-m mapfile] [-n symfile] [-O overlay]\n"
 "               [-o outfile] [-p pad_value] [-s symbol] file [...]\n");
 	exit(1);
 }
@@ -52,7 +52,7 @@
 	if (argc == 1)
 		usage();
 
-	while ((ch = getopt(argc, argv, "l:m:n:o:O:p:s:tw")) != -1) {
+	while ((ch = getopt(argc, argv, "l:m:n:o:O:p:s:twd")) != -1) {
 		switch (ch) {
 		case 'l':
 			SetLinkerscriptName(optarg);
@@ -87,7 +87,7 @@
 		case 't':
 			options |= OPT_TINY;
 			break;
-		case 'w':
+		case 'd':
 			/*
 			 * Set to set WRAM as a single continuous block as on
 			 * DMG. All WRAM sections must be WRAM0 as bankable WRAM
@@ -94,8 +94,17 @@
 			 * sections do not exist in this mode. A WRAMX section
 			 * will raise an error. VRAM bank 1 can't be used if
 			 * this option is enabled either.
+			 *
+			 * This option implies OPT_CONTWRAM.
 			 */
 			options |= OPT_DMG_MODE;
+			/* fallthrough */
+		case 'w':
+			/* Set to set WRAM as a single continuous block as on
+			 * DMG. All WRAM sections must be WRAM0 as bankable WRAM
+			 * sections do not exist in this mode. A WRAMX section
+			 * will raise an error. */
+			options |= OPT_CONTWRAM;
 			break;
 		default:
 			usage();
--- a/src/link/object.c
+++ b/src/link/object.c
@@ -159,10 +159,11 @@
 	if ((options & OPT_TINY) && (pSection->Type == SECT_ROMX)) {
 		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 (options & OPT_DMG_MODE) {
-		if (pSection->Type == SECT_WRAMX) {
-			errx(1, "WRAMX sections can't be used with option -w.");
-		}
+		/* WRAMX sections are checked for OPT_CONTWRAM */
 		if (pSection->Type == SECT_VRAM && pSection->nBank == 1) {
 			errx(1, "VRAM bank 1 can't be used with option -w.");
 		}
--- a/src/link/rgblink.1
+++ b/src/link/rgblink.1
@@ -22,6 +22,7 @@
 .Nm rgblink
 .Op Fl t
 .Op Fl w
+.Op Fl d
 .Op Fl m Ar mapfile
 .Op Fl n Ar symfile
 .Op Fl O Ar overlayfile
@@ -45,11 +46,17 @@
 .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
+If your ROM doesn't use banked WRAM you can use option
 .Fl w
 option to override this.
-It will also prohibit the use of VRAM bank 1.
 .Pp
+Also, if your ROM is designed for DMG, you can make sure that you don't use any
+prohibited section by using the option
+.Fl d ,
+which implies
+.Fl w
+but also prohibits the use of VRAM bank 1.
+.Pp
 The arguments are as follows:
 .Bl -tag -width Ds
 .It Fl m Ar mapfile
@@ -68,11 +75,14 @@
 .It Fl s Ar symbol
 ???
 .It Fl w
-Enable DMG mode.
 Expand the WRAM0 section size from 4KiB to the full 8KiB assigned to WRAM and
 prohibit the use of WRAMX sections.
-Prohibit the use of VRAM bank 1.
-Useful for ROMs designed for DMG.
+.It Fl d
+Enable DMG mode.
+Prohibit the use of sections that doesn't exist on a DMG, such as WRAMX and VRAM
+bank 1.
+This option automatically enables
+.Fl w .
 .It Fl t
 Expand the ROM0 section size from 16KiB to the full 32KiB assigned to ROM and
 prohibit the use of ROMX sections.
--- a/src/link/script.c
+++ b/src/link/script.c
@@ -49,7 +49,7 @@
 		} else if (i == BANK_WRAM0) {
 			/* WRAM */
 			bank[i].address = 0xC000;
-			if (options & OPT_DMG_MODE) {
+			if (options & OPT_CONTWRAM) {
 				bank[i].top_address = 0xE000;
 			} else {
 				bank[i].top_address = 0xD000;
--- a/test/link/test.sh
+++ b/test/link/test.sh
@@ -14,21 +14,21 @@
 
 $RGBASM -o $otemp wramx-dmg-mode.asm
 $RGBLINK -o $gbtemp $otemp > $outtemp 2>&1
-diff wramx-dmg-mode-no-w.out $outtemp
-$RGBLINK -w -o $gbtemp $otemp > $outtemp 2>&1
-diff wramx-dmg-mode-w.out $outtemp
+diff wramx-dmg-mode-no-d.out $outtemp
+$RGBLINK -d -o $gbtemp $otemp > $outtemp 2>&1
+diff wramx-dmg-mode-d.out $outtemp
 
 $RGBASM -o $otemp vram-fixed-dmg-mode.asm
 $RGBLINK -o $gbtemp $otemp > $outtemp 2>&1
-diff vram-fixed-dmg-mode-no-w.out $outtemp
-$RGBLINK -w -o $gbtemp $otemp > $outtemp 2>&1
-diff vram-fixed-dmg-mode-w.out $outtemp
+diff vram-fixed-dmg-mode-no-d.out $outtemp
+$RGBLINK -d -o $gbtemp $otemp > $outtemp 2>&1
+diff vram-fixed-dmg-mode-d.out $outtemp
 
 $RGBASM -o $otemp vram-floating-dmg-mode.asm
 $RGBLINK -o $gbtemp $otemp > $outtemp 2>&1
-diff vram-floating-dmg-mode-no-w.out $outtemp
-$RGBLINK -w -o $gbtemp $otemp > $outtemp 2>&1
-diff vram-floating-dmg-mode-w.out $outtemp
+diff vram-floating-dmg-mode-no-d.out $outtemp
+$RGBLINK -d -o $gbtemp $otemp > $outtemp 2>&1
+diff vram-floating-dmg-mode-d.out $outtemp
 
 $RGBASM -o $otemp romx-tiny.asm
 $RGBLINK -o $gbtemp $otemp > $outtemp 2>&1
--- a/test/link/update-refs.sh
+++ b/test/link/update-refs.sh
@@ -9,16 +9,16 @@
 head -c 20 $gbtemp > bank-numbers.out.bin 2>&1
 
 $RGBASM -o $otemp wramx-dmg-mode.asm
-$RGBLINK -o $gbtemp $otemp > wramx-dmg-mode-no-w.out 2>&1
-$RGBLINK -w -o $gbtemp $otemp > wramx-dmg-mode-w.out 2>&1
+$RGBLINK -o $gbtemp $otemp > wramx-dmg-mode-no-d.out 2>&1
+$RGBLINK -d -o $gbtemp $otemp > wramx-dmg-mode-d.out 2>&1
 
 $RGBASM -o $otemp vram-fixed-dmg-mode.asm
-$RGBLINK -o $gbtemp $otemp > vram-fixed-dmg-mode-no-w.out 2>&1
-$RGBLINK -w -o $gbtemp $otemp > vram-fixed-dmg-mode-w.out 2>&1
+$RGBLINK -o $gbtemp $otemp > vram-fixed-dmg-mode-no-d.out 2>&1
+$RGBLINK -d -o $gbtemp $otemp > vram-fixed-dmg-mode-d.out 2>&1
 
 $RGBASM -o $otemp vram-floating-dmg-mode.asm
-$RGBLINK -o $gbtemp $otemp > vram-floating-dmg-mode-no-w.out 2>&1
-$RGBLINK -w -o $gbtemp $otemp > vram-floating-dmg-mode-w.out 2>&1
+$RGBLINK -o $gbtemp $otemp > vram-floating-dmg-mode-no-d.out 2>&1
+$RGBLINK -d -o $gbtemp $otemp > vram-floating-dmg-mode-d.out 2>&1
 
 $RGBASM -o $otemp romx-tiny.asm
 $RGBLINK -o $gbtemp $otemp > romx-tiny-no-t.out 2>&1
--- /dev/null
+++ b/test/link/vram-fixed-dmg-mode-d.out
@@ -1,0 +1,1 @@
+error: VRAM bank 1 can't be used with option -w.
--- a/test/link/vram-fixed-dmg-mode-w.out
+++ /dev/null
@@ -1,1 +1,0 @@
-error: VRAM bank 1 can't be used with option -w.
--- /dev/null
+++ b/test/link/vram-floating-dmg-mode-d.out
@@ -1,0 +1,1 @@
+error: Unable to place 'v1' (VRAM section) in any bank
--- a/test/link/vram-floating-dmg-mode-w.out
+++ /dev/null
@@ -1,1 +1,0 @@
-error: Unable to place 'v1' (VRAM section) in any bank
--- /dev/null
+++ b/test/link/wramx-dmg-mode-d.out
@@ -1,0 +1,1 @@
+error: WRAMX sections can't be used with option -w.
--- /dev/null
+++ b/test/link/wramx-dmg-mode-no-d.out
@@ -1,0 +1,1 @@
+error: Unable to place 'w0b' (WRAM0 section) anywhere
--- a/test/link/wramx-dmg-mode-no-w.out
+++ /dev/null
@@ -1,1 +1,0 @@
-error: Unable to place 'w0b' (WRAM0 section) anywhere
--- a/test/link/wramx-dmg-mode-w.out
+++ /dev/null
@@ -1,1 +1,0 @@
-error: WRAMX sections can't be used with option -w.