mirror of
https://github.com/gbdev/rgbds.git
synced 2025-11-21 10:42:07 +00:00
Cleanup code of rbglink
Follow Linux kernel coding style. Signed-off-by: Antonio Niño Díaz <antonio_nd@outlook.com>
This commit is contained in:
@@ -34,15 +34,15 @@ static int32_t current_real_bank = -1; /* bank as seen by the GB */
|
||||
void script_InitSections(void)
|
||||
{
|
||||
int32_t i;
|
||||
|
||||
for (i = 0; i < MAXBANKS; i++) {
|
||||
if (i == BANK_ROM0) {
|
||||
/* ROM0 bank */
|
||||
bank[i].address = 0x0000;
|
||||
if (options & OPT_TINY) {
|
||||
if (options & OPT_TINY)
|
||||
bank[i].top_address = 0x8000;
|
||||
} else {
|
||||
else
|
||||
bank[i].top_address = 0x4000;
|
||||
}
|
||||
bank[i].type = SECT_ROM0;
|
||||
} else if (i >= BANK_ROMX && i < BANK_ROMX + BANK_COUNT_ROMX) {
|
||||
/* Swappable ROM bank */
|
||||
@@ -52,11 +52,10 @@ void script_InitSections(void)
|
||||
} else if (i == BANK_WRAM0) {
|
||||
/* WRAM */
|
||||
bank[i].address = 0xC000;
|
||||
if (options & OPT_CONTWRAM) {
|
||||
if (options & OPT_CONTWRAM)
|
||||
bank[i].top_address = 0xE000;
|
||||
} else {
|
||||
else
|
||||
bank[i].top_address = 0xD000;
|
||||
}
|
||||
bank[i].type = SECT_WRAM0;
|
||||
} else if (i >= BANK_SRAM && i < BANK_SRAM + BANK_COUNT_SRAM) {
|
||||
/* Swappable SRAM bank */
|
||||
@@ -105,14 +104,18 @@ void script_SetCurrentSectionType(const char *type, uint32_t bank)
|
||||
} else if (strcmp(type, "ROMX") == 0) {
|
||||
if (bank == 0)
|
||||
errx(1, "ROMX index can't be 0.\n");
|
||||
if (bank > BANK_COUNT_ROMX)
|
||||
errx(1, "ROMX index too big (%d > %d).\n", bank, BANK_COUNT_ROMX);
|
||||
if (bank > BANK_COUNT_ROMX) {
|
||||
errx(1, "ROMX index too big (%d > %d).\n", bank,
|
||||
BANK_COUNT_ROMX);
|
||||
}
|
||||
current_bank = BANK_ROMX + bank - 1;
|
||||
current_real_bank = bank;
|
||||
return;
|
||||
} else if (strcmp(type, "VRAM") == 0) {
|
||||
if (bank >= BANK_COUNT_VRAM)
|
||||
errx(1, "VRAM index too big (%d >= %d).\n", bank, BANK_COUNT_VRAM);
|
||||
if (bank >= BANK_COUNT_VRAM) {
|
||||
errx(1, "VRAM index too big (%d >= %d).\n", bank,
|
||||
BANK_COUNT_VRAM);
|
||||
}
|
||||
current_bank = BANK_VRAM + bank;
|
||||
current_real_bank = bank;
|
||||
return;
|
||||
@@ -125,14 +128,18 @@ void script_SetCurrentSectionType(const char *type, uint32_t bank)
|
||||
} else if (strcmp(type, "WRAMX") == 0) {
|
||||
if (bank == 0)
|
||||
errx(1, "WRAMX index can't be 0.\n");
|
||||
if (bank > BANK_COUNT_WRAMX)
|
||||
errx(1, "WRAMX index too big (%d > %d).\n", bank, BANK_COUNT_WRAMX);
|
||||
if (bank > BANK_COUNT_WRAMX) {
|
||||
errx(1, "WRAMX index too big (%d > %d).\n", bank,
|
||||
BANK_COUNT_WRAMX);
|
||||
}
|
||||
current_bank = BANK_WRAMX + bank - 1;
|
||||
current_real_bank = bank - 1;
|
||||
return;
|
||||
} else if (strcmp(type, "SRAM") == 0) {
|
||||
if (bank >= BANK_COUNT_SRAM)
|
||||
errx(1, "SRAM index too big (%d >= %d).\n", bank, BANK_COUNT_SRAM);
|
||||
if (bank >= BANK_COUNT_SRAM) {
|
||||
errx(1, "SRAM index too big (%d >= %d).\n", bank,
|
||||
BANK_COUNT_SRAM);
|
||||
}
|
||||
current_bank = BANK_SRAM + bank;
|
||||
current_real_bank = bank;
|
||||
return;
|
||||
@@ -155,14 +162,13 @@ void script_SetCurrentSectionType(const char *type, uint32_t bank)
|
||||
|
||||
void script_SetAddress(uint32_t addr)
|
||||
{
|
||||
if (current_bank == -1) {
|
||||
if (current_bank == -1)
|
||||
errx(1, "Trying to set an address without assigned bank\n");
|
||||
}
|
||||
|
||||
/* Make sure that we don't go back. */
|
||||
if (bank[current_bank].address > addr) {
|
||||
errx(1, "Trying to go to a previous address (0x%04X to 0x%04X)\n",
|
||||
bank[current_bank].address, addr);
|
||||
bank[current_bank].address, addr);
|
||||
}
|
||||
|
||||
bank[current_bank].address = addr;
|
||||
@@ -170,19 +176,18 @@ void script_SetAddress(uint32_t addr)
|
||||
/* Make sure we don't overflow */
|
||||
if (bank[current_bank].address >= bank[current_bank].top_address) {
|
||||
errx(1, "Bank overflowed (0x%04X >= 0x%04X)\n",
|
||||
bank[current_bank].address, bank[current_bank].top_address);
|
||||
bank[current_bank].address,
|
||||
bank[current_bank].top_address);
|
||||
}
|
||||
}
|
||||
|
||||
void script_SetAlignment(uint32_t alignment)
|
||||
{
|
||||
if (current_bank == -1) {
|
||||
if (current_bank == -1)
|
||||
errx(1, "Trying to set an alignment without assigned bank\n");
|
||||
}
|
||||
|
||||
if (alignment > 15) {
|
||||
if (alignment > 15)
|
||||
errx(1, "Trying to set an alignment too big: %d\n", alignment);
|
||||
}
|
||||
|
||||
uint32_t size = 1 << alignment;
|
||||
uint32_t mask = size - 1;
|
||||
@@ -195,25 +200,29 @@ void script_SetAlignment(uint32_t alignment)
|
||||
/* Make sure we don't overflow */
|
||||
if (bank[current_bank].address >= bank[current_bank].top_address) {
|
||||
errx(1, "Bank overflowed (0x%04X >= 0x%04X)\n",
|
||||
bank[current_bank].address, bank[current_bank].top_address);
|
||||
bank[current_bank].address,
|
||||
bank[current_bank].top_address);
|
||||
}
|
||||
}
|
||||
|
||||
void script_OutputSection(const char *section_name)
|
||||
{
|
||||
if (current_bank == -1) {
|
||||
errx(1, "Trying to place section \"%s\" without assigned bank\n", section_name);
|
||||
errx(1, "Trying to place section \"%s\" without assigned bank\n",
|
||||
section_name);
|
||||
}
|
||||
|
||||
if (!IsSectionSameTypeBankAndFloating(section_name, bank[current_bank].type,
|
||||
current_real_bank)) {
|
||||
if (!IsSectionSameTypeBankAndFloating(section_name,
|
||||
bank[current_bank].type,
|
||||
current_real_bank)) {
|
||||
errx(1, "Different attributes for \"%s\" in source and linkerscript\n",
|
||||
section_name);
|
||||
section_name);
|
||||
}
|
||||
|
||||
/* Move section to its place. */
|
||||
bank[current_bank].address +=
|
||||
AssignSectionAddressAndBankByName(section_name,
|
||||
bank[current_bank].address, current_real_bank);
|
||||
bank[current_bank].address,
|
||||
current_real_bank);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user