Merge pull request #154 from AntonioND/an/tiny-contwram

Make the options -t and -w of rgblink consistent
This commit is contained in:
AntonioND
2017-04-04 21:42:20 +01:00
committed by GitHub
14 changed files with 75 additions and 42 deletions

View File

@@ -8,7 +8,7 @@
#include "types.h" #include "types.h"
extern SLONG options; extern SLONG options;
#define OPT_SMALL 0x01 #define OPT_TINY 0x01
#define OPT_SMART_C_LINK 0x02 #define OPT_SMART_C_LINK 0x02
#define OPT_OVERLAY 0x04 #define OPT_OVERLAY 0x04
#define OPT_CONTWRAM 0x08 #define OPT_CONTWRAM 0x08

View File

@@ -390,7 +390,7 @@ AssignSections(void)
if (i == BANK_ROM0) { if (i == BANK_ROM0) {
/* ROM0 bank */ /* ROM0 bank */
BankFree[i]->nOrg = 0x0000; BankFree[i]->nOrg = 0x0000;
if (options & OPT_SMALL) { if (options & OPT_TINY) {
BankFree[i]->nSize = 0x8000; BankFree[i]->nSize = 0x8000;
} else { } else {
BankFree[i]->nSize = 0x4000; BankFree[i]->nSize = 0x4000;
@@ -398,15 +398,7 @@ AssignSections(void)
} else if (i >= BANK_ROMX && i < BANK_ROMX + BANK_COUNT_ROMX) { } else if (i >= BANK_ROMX && i < BANK_ROMX + BANK_COUNT_ROMX) {
/* Swappable ROM bank */ /* Swappable ROM bank */
BankFree[i]->nOrg = 0x4000; BankFree[i]->nOrg = 0x4000;
/* BankFree[i]->nSize = 0x4000;
* Now, this shouldn't really be necessary... but for
* good measure we'll do it anyway.
*/
if (options & OPT_SMALL) {
BankFree[i]->nSize = 0;
} else {
BankFree[i]->nSize = 0x4000;
}
} else if (i == BANK_WRAM0) { } else if (i == BANK_WRAM0) {
/* WRAM */ /* WRAM */
BankFree[i]->nOrg = 0xC000; BankFree[i]->nOrg = 0xC000;
@@ -463,10 +455,6 @@ AssignSections(void)
&& pSection->oAssigned == 0) { && pSection->oAssigned == 0) {
/* User wants to have a say... */ /* User wants to have a say... */
if (pSection->Type == SECT_WRAMX && options & OPT_CONTWRAM) {
errx(1, "WRAMX not compatible with -w!");
}
switch (pSection->Type) { switch (pSection->Type) {
case SECT_WRAM0: case SECT_WRAM0:
case SECT_HRAM: case SECT_HRAM:

View File

@@ -89,7 +89,7 @@ main(int argc, char *argv[])
smartlinkstartsymbol = optarg; smartlinkstartsymbol = optarg;
break; break;
case 't': case 't':
options |= OPT_SMALL; options |= OPT_TINY;
break; break;
case 'w': case 'w':
/* Set to set WRAM as a single continuous block as on DMG. /* Set to set WRAM as a single continuous block as on DMG.

View File

@@ -156,11 +156,13 @@ obj_ReadRGB0Section(FILE * f)
pSection->nBank = -1; pSection->nBank = -1;
pSection->nAlign = 1; pSection->nAlign = 1;
/* does the user want the -s mode? */ if ((options & OPT_TINY) && (pSection->Type == SECT_ROMX)) {
errx(1, "ROMX sections can't be used with option -t.");
if ((options & OPT_SMALL) && (pSection->Type == SECT_ROMX)) {
pSection->Type = SECT_ROM0;
} }
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)) { if ((pSection->Type == SECT_ROMX) || (pSection->Type == SECT_ROM0)) {
/* /*
* These sectiontypes contain data... * These sectiontypes contain data...
@@ -306,18 +308,20 @@ obj_ReadRGBSection(FILE * f, enum ObjectFileContents contents)
pSection->Type = (enum eSectionType) fgetc(f); pSection->Type = (enum eSectionType) fgetc(f);
pSection->nOrg = readlong(f); pSection->nOrg = readlong(f);
pSection->nBank = readlong(f); pSection->nBank = readlong(f);
if (contents & CONTAINS_SECTION_ALIGNMENT) { if (contents & CONTAINS_SECTION_ALIGNMENT) {
pSection->nAlign = readlong(f); pSection->nAlign = readlong(f);
} else { } else {
pSection->nAlign = 1; pSection->nAlign = 1;
} }
/* does the user want the -s mode? */ if ((options & OPT_TINY) && (pSection->Type == SECT_ROMX)) {
errx(1, "ROMX sections can't be used with option -t.");
if ((options & OPT_SMALL) && (pSection->Type == SECT_ROMX)) {
pSection->Type = SECT_ROM0;
} }
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)) { if ((pSection->Type == SECT_ROMX) || (pSection->Type == SECT_ROM0)) {
/* /*
* These sectiontypes contain data... * These sectiontypes contain data...

View File

@@ -29,6 +29,12 @@ If your ROM will only be 32KiB, you can use the
.Fl t .Fl t
option to override this. option to override this.
.Pp .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: The arguments are as follows:
.Bl -tag -width Ds .Bl -tag -width Ds
.It Fl m Ar mapfile .It Fl m Ar mapfile
@@ -47,14 +53,13 @@ The default is 0x00.
.It Fl s Ar symbol .It Fl s Ar symbol
??? ???
.It Fl w .It Fl w
Expand WRAM0 to the whole space assigned to WRAM and prevent the use of WRAMX Expand the WRAM0 section size from 4KiB to the full 8KiB assigned to WRAM and
sections. prohibit the use of WRAMX sections.
Useful for ROMs designed for DMG.
.It Fl t .It Fl t
Write a tiny Expand the ROM0 section size from 16KiB to the full 32KiB assigned to ROM and
.Pq 32KiB prohibit the use of ROMX sections.
ROM file. Useful for ROMs that fit in 32 KiB.
This forces all ROMX sections to be of type ROM0, and increases the ROM0
section size from 16KiB to 32KiB.
.It Fl l Ar linkerscript .It Fl l Ar linkerscript
Specify a linkerscript file that tells the linker how sections must be placed in Specify a linkerscript file that tells the linker how sections must be placed in
the ROM. the ROM.

View File

@@ -35,7 +35,7 @@ void script_InitSections(void)
if (i == BANK_ROM0) { if (i == BANK_ROM0) {
/* ROM0 bank */ /* ROM0 bank */
bank[i].address = 0x0000; bank[i].address = 0x0000;
if (options & OPT_SMALL) { if (options & OPT_TINY) {
bank[i].top_address = 0x8000; bank[i].top_address = 0x8000;
} else { } else {
bank[i].top_address = 0x4000; bank[i].top_address = 0x4000;
@@ -44,15 +44,7 @@ void script_InitSections(void)
} else if (i >= BANK_ROMX && i < BANK_ROMX + BANK_COUNT_ROMX) { } else if (i >= BANK_ROMX && i < BANK_ROMX + BANK_COUNT_ROMX) {
/* Swappable ROM bank */ /* Swappable ROM bank */
bank[i].address = 0x4000; bank[i].address = 0x4000;
/* bank[i].top_address = 0x8000;
* Now, this shouldn't really be necessary... but for
* good measure we'll do it anyway.
*/
if (options & OPT_SMALL) {
bank[i].top_address = 0x4000;
} else {
bank[i].top_address = 0x8000;
}
bank[i].type = SECT_ROMX; bank[i].type = SECT_ROMX;
} else if (i == BANK_WRAM0) { } else if (i == BANK_WRAM0) {
/* WRAM */ /* WRAM */

View File

@@ -0,0 +1 @@
rgblink:error:Unable to place 'r0b' (ROM0 section) anywhere

View File

@@ -0,0 +1 @@
rgblink:error:ROMX sections can't be used with option -t.

8
test/link/romx-tiny.asm Normal file
View File

@@ -0,0 +1,8 @@
SECTION "r0a", ROM0
DS $4000
SECTION "rx", ROMX
DS $4000
SECTION "r0b", ROM0
DS $4000

View File

@@ -10,3 +10,17 @@ $RGBLINK -o $gbtemp $otemp > $outtemp 2>&1
diff bank-numbers.out $outtemp diff bank-numbers.out $outtemp
head -c 20 $gbtemp > $otemp 2>&1 head -c 20 $gbtemp > $otemp 2>&1
diff bank-numbers.out.bin $otemp 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

View File

@@ -7,3 +7,13 @@ RGBLINK=../../rgblink
$RGBASM -o $otemp bank-numbers.asm $RGBASM -o $otemp bank-numbers.asm
$RGBLINK -o $gbtemp $otemp > bank-numbers.out 2>&1 $RGBLINK -o $gbtemp $otemp > bank-numbers.out 2>&1
head -c 20 $gbtemp > bank-numbers.out.bin 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

View File

@@ -0,0 +1 @@
rgblink:error:Unable to place 'w0b' (WRAM0 section) anywhere

View File

@@ -0,0 +1 @@
rgblink:error:WRAMX sections can't be used with option -w.

View File

@@ -0,0 +1,8 @@
SECTION "w0a", WRAM0
DS $1000
SECTION "wx", WRAMX
DS $1000
SECTION "w0b", WRAM0
DS $1000