ref: 24f41ef8973a464896db7123019bed96761856ad
parent: 09dff85d5be33432e5bab6e13a27b6b48727b67f
author: ISSOtm <eldredhabert0@gmail.com>
date: Mon Feb 3 09:58:25 EST 2020
Expose link def arrays to RGBASM
--- a/Makefile
+++ b/Makefile
@@ -67,7 +67,8 @@
src/asm/warning.o \
src/extern/err.o \
src/extern/getopt.o \
- src/extern/utf8decoder.o
+ src/extern/utf8decoder.o \
+ src/linkdefs.o
src/asm/globlex.o src/asm/lexer.o src/asm/constexpr.o: src/asm/asmy.h
@@ -82,7 +83,8 @@
src/link/symbol.o \
src/extern/err.o \
src/extern/getopt.o \
- src/hashmap.o
+ src/hashmap.o \
+ src/linkdefs.o
rgbfix_obj := \
src/fix/main.o \
--- a/include/link/section.h
+++ b/include/link/section.h
@@ -53,29 +53,6 @@
struct Symbol const **symbols;
};
-extern uint16_t startaddr[];
-extern uint16_t maxsize[];
-extern uint32_t bankranges[][2];
-extern char const * const typeNames[SECTTYPE_INVALID];
-
-/**
- * Computes a memory region's end address (last byte), eg. 0x7FFF
- * @return The address of the last byte in that memory region
- */
-static inline uint16_t endaddr(enum SectionType type)
-{
- return startaddr[type] + maxsize[type] - 1;
-}
-
-/**
- * Computes a memory region's number of banks
- * @return The number of banks, 1 for regions without banking
- */
-static inline uint32_t nbbanks(enum SectionType type)
-{
- return bankranges[type][1] - bankranges[type][0] + 1;
-}
-
/*
* Execute a callback for each section currently registered.
* This is to avoid exposing the data structure in which sections are stored.
--- a/include/linkdefs.h
+++ b/include/linkdefs.h
@@ -9,6 +9,9 @@
#ifndef RGBDS_LINKDEFS_H
#define RGBDS_LINKDEFS_H
+#include <stdbool.h>
+#include <stdint.h>
+
#define RGBDS_OBJECT_VERSION_STRING "RGB%1hhu"
#define RGBDS_OBJECT_VERSION_NUMBER (uint8_t)6
@@ -92,6 +95,17 @@
SECTTYPE_INVALID
};
+/**
+ * Tells whether a section has data in its object file definition,
+ * depending on type.
+ * @param type The section's type
+ * @return `true` if the section's definition includes data
+ */
+static inline bool sect_HasData(enum SectionType type)
+{
+ return type == SECTTYPE_ROM0 || type == SECTTYPE_ROMX;
+}
+
enum ExportLevel {
SYMTYPE_LOCAL,
SYMTYPE_IMPORT,
@@ -107,15 +121,28 @@
PATCHTYPE_INVALID
};
+extern uint16_t startaddr[];
+extern uint16_t maxsize[];
+extern uint32_t bankranges[][2];
+
/**
- * Tells whether a section has data in its object file definition,
- * depending on type.
- * @param type The section's type
- * @return `true` if the section's definition includes data
+ * Computes a memory region's end address (last byte), eg. 0x7FFF
+ * @return The address of the last byte in that memory region
*/
-static inline bool sect_HasData(enum SectionType type)
+static inline uint16_t endaddr(enum SectionType type)
{
- return type == SECTTYPE_ROM0 || type == SECTTYPE_ROMX;
+ return startaddr[type] + maxsize[type] - 1;
}
+
+/**
+ * Computes a memory region's number of banks
+ * @return The number of banks, 1 for regions without banking
+ */
+static inline uint32_t nbbanks(enum SectionType type)
+{
+ return bankranges[type][1] - bankranges[type][0] + 1;
+}
+
+extern char const * const typeNames[SECTTYPE_INVALID];
#endif /* RGBDS_LINKDEFS_H */
--- a/src/asm/output.c
+++ b/src/asm/output.c
@@ -509,11 +509,11 @@
*/
static void checksectionoverflow(uint32_t delta_size)
{
- uint32_t maxsize = getmaxsectionsize(pCurrentSection->nType,
- pCurrentSection->pzName);
- uint32_t new_size = pCurrentSection->nPC + delta_size;
+ uint32_t maxSize = getmaxsectionsize(pCurrentSection->nType,
+ pCurrentSection->pzName);
+ uint32_t newSize = pCurrentSection->nPC + delta_size;
- if (new_size > maxsize) {
+ if (newSize > maxSize) {
/*
* This check is here to trap broken code that generates
* sections that are too big and to prevent the assembler from
@@ -522,7 +522,7 @@
* The real check must be done at the linking stage.
*/
fatalerror("Section '%s' is too big (max size = 0x%X bytes, reached 0x%X).",
- pCurrentSection->pzName, maxsize, new_size);
+ pCurrentSection->pzName, maxSize, newSize);
}
}
--- a/src/link/section.c
+++ b/src/link/section.c
@@ -15,50 +15,6 @@
#include "hashmap.h"
-uint16_t startaddr[] = {
- [SECTTYPE_ROM0] = 0x0000,
- [SECTTYPE_ROMX] = 0x4000,
- [SECTTYPE_VRAM] = 0x8000,
- [SECTTYPE_SRAM] = 0xA000,
- [SECTTYPE_WRAM0] = 0xC000,
- [SECTTYPE_WRAMX] = 0xD000,
- [SECTTYPE_OAM] = 0xFE00,
- [SECTTYPE_HRAM] = 0xFF80
-};
-
-uint16_t maxsize[] = {
- [SECTTYPE_ROM0] = 0x4000,
- [SECTTYPE_ROMX] = 0x4000,
- [SECTTYPE_VRAM] = 0x2000,
- [SECTTYPE_SRAM] = 0x2000,
- [SECTTYPE_WRAM0] = 0x1000,
- [SECTTYPE_WRAMX] = 0x1000,
- [SECTTYPE_OAM] = 0x00A0,
- [SECTTYPE_HRAM] = 0x007F
-};
-
-uint32_t bankranges[][2] = {
- [SECTTYPE_ROM0] = {BANK_MIN_ROM0, BANK_MAX_ROM0},
- [SECTTYPE_ROMX] = {BANK_MIN_ROMX, BANK_MAX_ROMX},
- [SECTTYPE_VRAM] = {BANK_MIN_VRAM, BANK_MAX_VRAM},
- [SECTTYPE_SRAM] = {BANK_MIN_SRAM, BANK_MAX_SRAM},
- [SECTTYPE_WRAM0] = {BANK_MIN_WRAM0, BANK_MAX_WRAM0},
- [SECTTYPE_WRAMX] = {BANK_MIN_WRAMX, BANK_MAX_WRAMX},
- [SECTTYPE_OAM] = {BANK_MIN_OAM, BANK_MAX_OAM},
- [SECTTYPE_HRAM] = {BANK_MIN_HRAM, BANK_MAX_HRAM}
-};
-
-char const * const typeNames[] = {
- [SECTTYPE_ROM0] = "ROM0",
- [SECTTYPE_ROMX] = "ROMX",
- [SECTTYPE_VRAM] = "VRAM",
- [SECTTYPE_SRAM] = "SRAM",
- [SECTTYPE_WRAM0] = "WRAM0",
- [SECTTYPE_WRAMX] = "WRAMX",
- [SECTTYPE_OAM] = "OAM",
- [SECTTYPE_HRAM] = "HRAM"
-};
-
HashMap sections;
struct ForEachArg {
--- /dev/null
+++ b/src/linkdefs.c
@@ -1,0 +1,46 @@
+
+#include "linkdefs.h"
+
+uint16_t startaddr[] = {
+ [SECTTYPE_ROM0] = 0x0000,
+ [SECTTYPE_ROMX] = 0x4000,
+ [SECTTYPE_VRAM] = 0x8000,
+ [SECTTYPE_SRAM] = 0xA000,
+ [SECTTYPE_WRAM0] = 0xC000,
+ [SECTTYPE_WRAMX] = 0xD000,
+ [SECTTYPE_OAM] = 0xFE00,
+ [SECTTYPE_HRAM] = 0xFF80
+};
+
+uint16_t maxsize[] = {
+ [SECTTYPE_ROM0] = 0x4000,
+ [SECTTYPE_ROMX] = 0x4000,
+ [SECTTYPE_VRAM] = 0x2000,
+ [SECTTYPE_SRAM] = 0x2000,
+ [SECTTYPE_WRAM0] = 0x1000,
+ [SECTTYPE_WRAMX] = 0x1000,
+ [SECTTYPE_OAM] = 0x00A0,
+ [SECTTYPE_HRAM] = 0x007F
+};
+
+uint32_t bankranges[][2] = {
+ [SECTTYPE_ROM0] = {BANK_MIN_ROM0, BANK_MAX_ROM0},
+ [SECTTYPE_ROMX] = {BANK_MIN_ROMX, BANK_MAX_ROMX},
+ [SECTTYPE_VRAM] = {BANK_MIN_VRAM, BANK_MAX_VRAM},
+ [SECTTYPE_SRAM] = {BANK_MIN_SRAM, BANK_MAX_SRAM},
+ [SECTTYPE_WRAM0] = {BANK_MIN_WRAM0, BANK_MAX_WRAM0},
+ [SECTTYPE_WRAMX] = {BANK_MIN_WRAMX, BANK_MAX_WRAMX},
+ [SECTTYPE_OAM] = {BANK_MIN_OAM, BANK_MAX_OAM},
+ [SECTTYPE_HRAM] = {BANK_MIN_HRAM, BANK_MAX_HRAM}
+};
+
+char const * const typeNames[] = {
+ [SECTTYPE_ROM0] = "ROM0",
+ [SECTTYPE_ROMX] = "ROMX",
+ [SECTTYPE_VRAM] = "VRAM",
+ [SECTTYPE_SRAM] = "SRAM",
+ [SECTTYPE_WRAM0] = "WRAM0",
+ [SECTTYPE_WRAMX] = "WRAMX",
+ [SECTTYPE_OAM] = "OAM",
+ [SECTTYPE_HRAM] = "HRAM"
+};