From e9ed81074b05f59bbe08e029285480683e45a88a Mon Sep 17 00:00:00 2001 From: AntonioND Date: Sun, 2 Apr 2017 21:39:40 +0100 Subject: [PATCH 1/3] Rename OPT_SMALL to OPT_TINY This way it is easier to identify the flag passed to the binary (-t). Signed-off-by: AntonioND --- include/link/mylink.h | 2 +- src/link/assign.c | 4 ++-- src/link/main.c | 2 +- src/link/object.c | 4 ++-- src/link/script.c | 4 ++-- 5 files changed, 8 insertions(+), 8 deletions(-) diff --git a/include/link/mylink.h b/include/link/mylink.h index 6343defb..9bff627f 100644 --- a/include/link/mylink.h +++ b/include/link/mylink.h @@ -8,7 +8,7 @@ #include "types.h" extern SLONG options; -#define OPT_SMALL 0x01 +#define OPT_TINY 0x01 #define OPT_SMART_C_LINK 0x02 #define OPT_OVERLAY 0x04 #define OPT_CONTWRAM 0x08 diff --git a/src/link/assign.c b/src/link/assign.c index 3024a80d..4cabc85e 100644 --- a/src/link/assign.c +++ b/src/link/assign.c @@ -390,7 +390,7 @@ AssignSections(void) if (i == BANK_ROM0) { /* ROM0 bank */ BankFree[i]->nOrg = 0x0000; - if (options & OPT_SMALL) { + if (options & OPT_TINY) { BankFree[i]->nSize = 0x8000; } else { BankFree[i]->nSize = 0x4000; @@ -402,7 +402,7 @@ AssignSections(void) * Now, this shouldn't really be necessary... but for * good measure we'll do it anyway. */ - if (options & OPT_SMALL) { + if (options & OPT_TINY) { BankFree[i]->nSize = 0; } else { BankFree[i]->nSize = 0x4000; diff --git a/src/link/main.c b/src/link/main.c index b5c7694f..b56363d6 100644 --- a/src/link/main.c +++ b/src/link/main.c @@ -89,7 +89,7 @@ main(int argc, char *argv[]) smartlinkstartsymbol = optarg; break; case 't': - options |= OPT_SMALL; + options |= OPT_TINY; break; case 'w': /* Set to set WRAM as a single continuous block as on DMG. diff --git a/src/link/object.c b/src/link/object.c index aff815dc..4f4f7421 100644 --- a/src/link/object.c +++ b/src/link/object.c @@ -158,7 +158,7 @@ obj_ReadRGB0Section(FILE * f) /* does the user want the -s mode? */ - if ((options & OPT_SMALL) && (pSection->Type == SECT_ROMX)) { + if ((options & OPT_TINY) && (pSection->Type == SECT_ROMX)) { pSection->Type = SECT_ROM0; } if ((pSection->Type == SECT_ROMX) || (pSection->Type == SECT_ROM0)) { @@ -315,7 +315,7 @@ obj_ReadRGBSection(FILE * f, enum ObjectFileContents contents) /* does the user want the -s mode? */ - if ((options & OPT_SMALL) && (pSection->Type == SECT_ROMX)) { + if ((options & OPT_TINY) && (pSection->Type == SECT_ROMX)) { pSection->Type = SECT_ROM0; } if ((pSection->Type == SECT_ROMX) || (pSection->Type == SECT_ROM0)) { diff --git a/src/link/script.c b/src/link/script.c index fb73c92c..5336436d 100644 --- a/src/link/script.c +++ b/src/link/script.c @@ -35,7 +35,7 @@ void script_InitSections(void) if (i == BANK_ROM0) { /* ROM0 bank */ bank[i].address = 0x0000; - if (options & OPT_SMALL) { + if (options & OPT_TINY) { bank[i].top_address = 0x8000; } else { bank[i].top_address = 0x4000; @@ -48,7 +48,7 @@ void script_InitSections(void) * Now, this shouldn't really be necessary... but for * good measure we'll do it anyway. */ - if (options & OPT_SMALL) { + if (options & OPT_TINY) { bank[i].top_address = 0x4000; } else { bank[i].top_address = 0x8000; From 7e3720b62720ee467c5379a56c3af3087b6bff42 Mon Sep 17 00:00:00 2001 From: AntonioND Date: Sun, 2 Apr 2017 21:55:16 +0100 Subject: [PATCH 2/3] 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 --- src/link/assign.c | 14 +------------- src/link/object.c | 18 +++++++++++------- src/link/rgblink.1 | 19 ++++++++++++------- src/link/script.c | 10 +--------- 4 files changed, 25 insertions(+), 36 deletions(-) diff --git a/src/link/assign.c b/src/link/assign.c index 4cabc85e..e9fb67ae 100644 --- a/src/link/assign.c +++ b/src/link/assign.c @@ -398,15 +398,7 @@ AssignSections(void) } 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; @@ -463,10 +455,6 @@ AssignSections(void) && 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: case SECT_HRAM: diff --git a/src/link/object.c b/src/link/object.c index 4f4f7421..4ea180ac 100644 --- a/src/link/object.c +++ b/src/link/object.c @@ -156,11 +156,13 @@ obj_ReadRGB0Section(FILE * f) 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,18 +308,20 @@ obj_ReadRGBSection(FILE * f, enum ObjectFileContents contents) pSection->Type = (enum eSectionType) fgetc(f); pSection->nOrg = readlong(f); pSection->nBank = readlong(f); - + if (contents & CONTAINS_SECTION_ALIGNMENT) { pSection->nAlign = readlong(f); } else { 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... diff --git a/src/link/rgblink.1 b/src/link/rgblink.1 index 227e2818..6257ebeb 100644 --- a/src/link/rgblink.1 +++ b/src/link/rgblink.1 @@ -29,6 +29,12 @@ If your ROM will only be 32KiB, you can use the .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 @@ The default is 0x00. .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. diff --git a/src/link/script.c b/src/link/script.c index 5336436d..75fdf80b 100644 --- a/src/link/script.c +++ b/src/link/script.c @@ -44,15 +44,7 @@ void script_InitSections(void) } 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 */ From f431b384a2b8c1d90e5de30a270b73e1776e8cec Mon Sep 17 00:00:00 2001 From: AntonioND Date: Mon, 3 Apr 2017 20:46:18 +0100 Subject: [PATCH 3/3] Add tests for rgblink options -t and -w Signed-off-by: AntonioND --- test/link/romx-tiny-no-t.out | 1 + test/link/romx-tiny-t.out | 1 + test/link/romx-tiny.asm | 8 ++++++++ test/link/test.sh | 14 ++++++++++++++ test/link/update-refs.sh | 10 ++++++++++ test/link/wramx-contwram-no-w.out | 1 + test/link/wramx-contwram-w.out | 1 + test/link/wramx-contwram.asm | 8 ++++++++ 8 files changed, 44 insertions(+) create mode 100644 test/link/romx-tiny-no-t.out create mode 100644 test/link/romx-tiny-t.out create mode 100644 test/link/romx-tiny.asm create mode 100644 test/link/wramx-contwram-no-w.out create mode 100644 test/link/wramx-contwram-w.out create mode 100644 test/link/wramx-contwram.asm diff --git a/test/link/romx-tiny-no-t.out b/test/link/romx-tiny-no-t.out new file mode 100644 index 00000000..6537114f --- /dev/null +++ b/test/link/romx-tiny-no-t.out @@ -0,0 +1 @@ +rgblink:error:Unable to place 'r0b' (ROM0 section) anywhere diff --git a/test/link/romx-tiny-t.out b/test/link/romx-tiny-t.out new file mode 100644 index 00000000..5d02cc75 --- /dev/null +++ b/test/link/romx-tiny-t.out @@ -0,0 +1 @@ +rgblink:error:ROMX sections can't be used with option -t. diff --git a/test/link/romx-tiny.asm b/test/link/romx-tiny.asm new file mode 100644 index 00000000..1cd858ea --- /dev/null +++ b/test/link/romx-tiny.asm @@ -0,0 +1,8 @@ +SECTION "r0a", ROM0 +DS $4000 + +SECTION "rx", ROMX +DS $4000 + +SECTION "r0b", ROM0 +DS $4000 diff --git a/test/link/test.sh b/test/link/test.sh index 8cd0aeda..80cfe0a9 100644 --- a/test/link/test.sh +++ b/test/link/test.sh @@ -10,3 +10,17 @@ $RGBLINK -o $gbtemp $otemp > $outtemp 2>&1 diff bank-numbers.out $outtemp head -c 20 $gbtemp > $otemp 2>&1 diff bank-numbers.out.bin $otemp + +$RGBASM -o $otemp wramx-contwram.asm +$RGBLINK -o $gbtemp $otemp > $outtemp 2>&1 +diff wramx-contwram-no-w.out $outtemp +$RGBLINK -w -o $gbtemp $otemp > $outtemp 2>&1 +diff wramx-contwram-w.out $outtemp + +$RGBASM -o $otemp romx-tiny.asm +$RGBLINK -o $gbtemp $otemp > $outtemp 2>&1 +diff romx-tiny-no-t.out $outtemp +$RGBLINK -t -o $gbtemp $otemp > $outtemp 2>&1 +diff romx-tiny-t.out $outtemp + +exit 0 diff --git a/test/link/update-refs.sh b/test/link/update-refs.sh index 2bd0652c..1c7235d6 100644 --- a/test/link/update-refs.sh +++ b/test/link/update-refs.sh @@ -7,3 +7,13 @@ RGBLINK=../../rgblink $RGBASM -o $otemp bank-numbers.asm $RGBLINK -o $gbtemp $otemp > bank-numbers.out 2>&1 head -c 20 $gbtemp > bank-numbers.out.bin 2>&1 + +$RGBASM -o $otemp wramx-contwram.asm +$RGBLINK -o $gbtemp $otemp > wramx-contwram-no-w.out 2>&1 +$RGBLINK -w -o $gbtemp $otemp > wramx-contwram-w.out 2>&1 + +$RGBASM -o $otemp romx-tiny.asm +$RGBLINK -o $gbtemp $otemp > romx-tiny-no-t.out 2>&1 +$RGBLINK -t -o $gbtemp $otemp > romx-tiny-t.out 2>&1 + +exit 0 diff --git a/test/link/wramx-contwram-no-w.out b/test/link/wramx-contwram-no-w.out new file mode 100644 index 00000000..219db0e4 --- /dev/null +++ b/test/link/wramx-contwram-no-w.out @@ -0,0 +1 @@ +rgblink:error:Unable to place 'w0b' (WRAM0 section) anywhere diff --git a/test/link/wramx-contwram-w.out b/test/link/wramx-contwram-w.out new file mode 100644 index 00000000..51cc3c8e --- /dev/null +++ b/test/link/wramx-contwram-w.out @@ -0,0 +1 @@ +rgblink:error:WRAMX sections can't be used with option -w. diff --git a/test/link/wramx-contwram.asm b/test/link/wramx-contwram.asm new file mode 100644 index 00000000..9851de27 --- /dev/null +++ b/test/link/wramx-contwram.asm @@ -0,0 +1,8 @@ +SECTION "w0a", WRAM0 +DS $1000 + +SECTION "wx", WRAMX +DS $1000 + +SECTION "w0b", WRAM0 +DS $1000