mirror of
https://github.com/gbdev/rgbds.git
synced 2025-11-24 20:12:07 +00:00
reran indent (whitespace changes)
Merging lai's source with this one is very irritating because they have different indentation styles. I couldn't find what profile vegard used for his version, so I used these flags (which should bring the source close to KNF): -bap -br -ce -ci4 -cli0 -d0 -di0 -i8 -ip -l79 -nbc -ncdb -ndj -ei -nfc1 -nlp -npcs -psl -sc -sob
This commit is contained in:
@@ -18,7 +18,8 @@ SLONG MaxBankUsed;
|
||||
|
||||
#define DOMAXBANK(x) {if( (x)>MaxBankUsed ) MaxBankUsed=(x);}
|
||||
|
||||
SLONG area_Avail(SLONG bank)
|
||||
SLONG
|
||||
area_Avail(SLONG bank)
|
||||
{
|
||||
SLONG r;
|
||||
struct sFreeArea *pArea;
|
||||
@@ -34,7 +35,8 @@ SLONG area_Avail(SLONG bank)
|
||||
return (r);
|
||||
}
|
||||
|
||||
SLONG area_AllocAbs(struct sFreeArea ** ppArea, SLONG org, SLONG size)
|
||||
SLONG
|
||||
area_AllocAbs(struct sFreeArea ** ppArea, SLONG org, SLONG size)
|
||||
{
|
||||
struct sFreeArea *pArea;
|
||||
|
||||
@@ -55,8 +57,8 @@ SLONG area_AllocAbs(struct sFreeArea ** ppArea, SLONG org, SLONG size)
|
||||
struct sFreeArea *pNewArea;
|
||||
|
||||
if ((pNewArea =
|
||||
(struct sFreeArea *)
|
||||
malloc(sizeof(struct sFreeArea)))
|
||||
(struct sFreeArea *)
|
||||
malloc(sizeof(struct sFreeArea)))
|
||||
!= NULL) {
|
||||
*pNewArea = *pArea;
|
||||
pNewArea->pPrev = pArea;
|
||||
@@ -80,7 +82,8 @@ SLONG area_AllocAbs(struct sFreeArea ** ppArea, SLONG org, SLONG size)
|
||||
return (-1);
|
||||
}
|
||||
|
||||
SLONG area_AllocAbsCODEAnyBank(SLONG org, SLONG size)
|
||||
SLONG
|
||||
area_AllocAbsCODEAnyBank(SLONG org, SLONG size)
|
||||
{
|
||||
SLONG i;
|
||||
|
||||
@@ -92,7 +95,8 @@ SLONG area_AllocAbsCODEAnyBank(SLONG org, SLONG size)
|
||||
return (-1);
|
||||
}
|
||||
|
||||
SLONG area_Alloc(struct sFreeArea ** ppArea, SLONG size)
|
||||
SLONG
|
||||
area_Alloc(struct sFreeArea ** ppArea, SLONG size)
|
||||
{
|
||||
struct sFreeArea *pArea;
|
||||
|
||||
@@ -114,7 +118,8 @@ SLONG area_Alloc(struct sFreeArea ** ppArea, SLONG size)
|
||||
return (-1);
|
||||
}
|
||||
|
||||
SLONG area_AllocCODEAnyBank(SLONG size)
|
||||
SLONG
|
||||
area_AllocCODEAnyBank(SLONG size)
|
||||
{
|
||||
SLONG i, org;
|
||||
|
||||
@@ -126,7 +131,8 @@ SLONG area_AllocCODEAnyBank(SLONG size)
|
||||
return (-1);
|
||||
}
|
||||
|
||||
struct sSection *FindLargestCode(void)
|
||||
struct sSection *
|
||||
FindLargestCode(void)
|
||||
{
|
||||
struct sSection *pSection, *r = NULL;
|
||||
SLONG nLargest = 0;
|
||||
@@ -144,7 +150,8 @@ struct sSection *FindLargestCode(void)
|
||||
return (r);
|
||||
}
|
||||
|
||||
void AssignCodeSections(void)
|
||||
void
|
||||
AssignCodeSections(void)
|
||||
{
|
||||
struct sSection *pSection;
|
||||
|
||||
@@ -161,7 +168,8 @@ void AssignCodeSections(void)
|
||||
}
|
||||
}
|
||||
|
||||
void GBROM_AssignSections(void)
|
||||
void
|
||||
GBROM_AssignSections(void)
|
||||
{
|
||||
SLONG i;
|
||||
struct sSection *pSection;
|
||||
@@ -234,10 +242,10 @@ void GBROM_AssignSections(void)
|
||||
case SECT_BSS:
|
||||
if (area_AllocAbs
|
||||
(&BankFree[BANK_BSS], pSection->nOrg,
|
||||
pSection->nByteSize) != pSection->nOrg) {
|
||||
pSection->nByteSize) != pSection->nOrg) {
|
||||
sprintf(temptext,
|
||||
"Unable to load fixed BSS section at $%lX",
|
||||
pSection->nOrg);
|
||||
"Unable to load fixed BSS section at $%lX",
|
||||
pSection->nOrg);
|
||||
fatalerror(temptext);
|
||||
}
|
||||
pSection->oAssigned = 1;
|
||||
@@ -246,10 +254,10 @@ void GBROM_AssignSections(void)
|
||||
case SECT_HRAM:
|
||||
if (area_AllocAbs
|
||||
(&BankFree[BANK_HRAM], pSection->nOrg,
|
||||
pSection->nByteSize) != pSection->nOrg) {
|
||||
pSection->nByteSize) != pSection->nOrg) {
|
||||
sprintf(temptext,
|
||||
"Unable to load fixed HRAM section at $%lX",
|
||||
pSection->nOrg);
|
||||
"Unable to load fixed HRAM section at $%lX",
|
||||
pSection->nOrg);
|
||||
fatalerror(temptext);
|
||||
}
|
||||
pSection->oAssigned = 1;
|
||||
@@ -258,10 +266,10 @@ void GBROM_AssignSections(void)
|
||||
case SECT_VRAM:
|
||||
if (area_AllocAbs
|
||||
(&BankFree[BANK_VRAM], pSection->nOrg,
|
||||
pSection->nByteSize) != pSection->nOrg) {
|
||||
pSection->nByteSize) != pSection->nOrg) {
|
||||
sprintf(temptext,
|
||||
"Unable to load fixed VRAM section at $%lX",
|
||||
pSection->nOrg);
|
||||
"Unable to load fixed VRAM section at $%lX",
|
||||
pSection->nOrg);
|
||||
fatalerror(temptext);
|
||||
}
|
||||
pSection->oAssigned = 1;
|
||||
@@ -270,10 +278,10 @@ void GBROM_AssignSections(void)
|
||||
case SECT_HOME:
|
||||
if (area_AllocAbs
|
||||
(&BankFree[BANK_HOME], pSection->nOrg,
|
||||
pSection->nByteSize) != pSection->nOrg) {
|
||||
pSection->nByteSize) != pSection->nOrg) {
|
||||
sprintf(temptext,
|
||||
"Unable to load fixed HOME section at $%lX",
|
||||
pSection->nOrg);
|
||||
"Unable to load fixed HOME section at $%lX",
|
||||
pSection->nOrg);
|
||||
fatalerror(temptext);
|
||||
}
|
||||
pSection->oAssigned = 1;
|
||||
@@ -314,30 +322,30 @@ void GBROM_AssignSections(void)
|
||||
&& pSection->nBank <= 255) {
|
||||
if (area_AllocAbs
|
||||
(&BankFree
|
||||
[pSection->nBank],
|
||||
pSection->nOrg,
|
||||
pSection->
|
||||
nByteSize) !=
|
||||
[pSection->nBank],
|
||||
pSection->nOrg,
|
||||
pSection->
|
||||
nByteSize) !=
|
||||
pSection->nOrg) {
|
||||
sprintf
|
||||
(temptext,
|
||||
"Unable to load fixed CODE/DATA section at $%lX in bank $%02lX",
|
||||
pSection->
|
||||
nOrg,
|
||||
pSection->
|
||||
nBank);
|
||||
"Unable to load fixed CODE/DATA section at $%lX in bank $%02lX",
|
||||
pSection->
|
||||
nOrg,
|
||||
pSection->
|
||||
nBank);
|
||||
fatalerror
|
||||
(temptext);
|
||||
}
|
||||
DOMAXBANK(pSection->
|
||||
nBank);
|
||||
nBank);
|
||||
pSection->oAssigned = 1;
|
||||
} else {
|
||||
sprintf(temptext,
|
||||
"Unable to load fixed CODE/DATA section at $%lX in bank $%02lX",
|
||||
pSection->nOrg,
|
||||
pSection->
|
||||
nBank);
|
||||
"Unable to load fixed CODE/DATA section at $%lX in bank $%02lX",
|
||||
pSection->nOrg,
|
||||
pSection->
|
||||
nBank);
|
||||
fatalerror(temptext);
|
||||
}
|
||||
}
|
||||
@@ -362,19 +370,19 @@ void GBROM_AssignSections(void)
|
||||
/* User wants to have a say... and he's pissed */
|
||||
if (pSection->nBank >= 1 && pSection->nBank <= 255) {
|
||||
if ((pSection->nOrg =
|
||||
area_Alloc(&BankFree[pSection->nBank],
|
||||
pSection->nByteSize)) == -1) {
|
||||
area_Alloc(&BankFree[pSection->nBank],
|
||||
pSection->nByteSize)) == -1) {
|
||||
sprintf(temptext,
|
||||
"Unable to load fixed CODE/DATA section into bank $%02lX",
|
||||
pSection->nBank);
|
||||
"Unable to load fixed CODE/DATA section into bank $%02lX",
|
||||
pSection->nBank);
|
||||
fatalerror(temptext);
|
||||
}
|
||||
pSection->oAssigned = 1;
|
||||
DOMAXBANK(pSection->nBank);
|
||||
} else {
|
||||
sprintf(temptext,
|
||||
"Unable to load fixed CODE/DATA section into bank $%02lX",
|
||||
pSection->nBank);
|
||||
"Unable to load fixed CODE/DATA section into bank $%02lX",
|
||||
pSection->nBank);
|
||||
fatalerror(temptext);
|
||||
}
|
||||
}
|
||||
@@ -391,14 +399,15 @@ void GBROM_AssignSections(void)
|
||||
if (pSection->oAssigned == 0
|
||||
&& pSection->Type == SECT_CODE
|
||||
&& pSection->nOrg != -1 && pSection->nBank == -1) {
|
||||
/* User wants to have a say... and he's back with a vengeance */
|
||||
/* User wants to have a say... and he's back with a
|
||||
* vengeance */
|
||||
if ((pSection->nBank =
|
||||
area_AllocAbsCODEAnyBank(pSection->nOrg,
|
||||
pSection->nByteSize)) ==
|
||||
area_AllocAbsCODEAnyBank(pSection->nOrg,
|
||||
pSection->nByteSize)) ==
|
||||
-1) {
|
||||
sprintf(temptext,
|
||||
"Unable to load fixed CODE/DATA section at $%lX into any bank",
|
||||
pSection->nOrg);
|
||||
"Unable to load fixed CODE/DATA section at $%lX into any bank",
|
||||
pSection->nOrg);
|
||||
fatalerror(temptext);
|
||||
}
|
||||
pSection->oAssigned = 1;
|
||||
@@ -419,8 +428,8 @@ void GBROM_AssignSections(void)
|
||||
switch (pSection->Type) {
|
||||
case SECT_BSS:
|
||||
if ((pSection->nOrg =
|
||||
area_Alloc(&BankFree[BANK_BSS],
|
||||
pSection->nByteSize)) == -1) {
|
||||
area_Alloc(&BankFree[BANK_BSS],
|
||||
pSection->nByteSize)) == -1) {
|
||||
fatalerror("BSS section too large\n");
|
||||
}
|
||||
pSection->nBank = BANK_BSS;
|
||||
@@ -428,8 +437,8 @@ void GBROM_AssignSections(void)
|
||||
break;
|
||||
case SECT_HRAM:
|
||||
if ((pSection->nOrg =
|
||||
area_Alloc(&BankFree[BANK_HRAM],
|
||||
pSection->nByteSize)) == -1) {
|
||||
area_Alloc(&BankFree[BANK_HRAM],
|
||||
pSection->nByteSize)) == -1) {
|
||||
fatalerror("HRAM section too large");
|
||||
}
|
||||
pSection->nBank = BANK_HRAM;
|
||||
@@ -437,8 +446,8 @@ void GBROM_AssignSections(void)
|
||||
break;
|
||||
case SECT_VRAM:
|
||||
if ((pSection->nOrg =
|
||||
area_Alloc(&BankFree[BANK_VRAM],
|
||||
pSection->nByteSize)) == -1) {
|
||||
area_Alloc(&BankFree[BANK_VRAM],
|
||||
pSection->nByteSize)) == -1) {
|
||||
fatalerror("VRAM section too large");
|
||||
}
|
||||
pSection->nBank = BANK_VRAM;
|
||||
@@ -446,8 +455,8 @@ void GBROM_AssignSections(void)
|
||||
break;
|
||||
case SECT_HOME:
|
||||
if ((pSection->nOrg =
|
||||
area_Alloc(&BankFree[BANK_HOME],
|
||||
pSection->nByteSize)) == -1) {
|
||||
area_Alloc(&BankFree[BANK_HOME],
|
||||
pSection->nByteSize)) == -1) {
|
||||
fatalerror("HOME section too large");
|
||||
}
|
||||
pSection->nBank = BANK_HOME;
|
||||
@@ -466,7 +475,8 @@ void GBROM_AssignSections(void)
|
||||
AssignCodeSections();
|
||||
}
|
||||
|
||||
void PSION2_AssignSections(void)
|
||||
void
|
||||
PSION2_AssignSections(void)
|
||||
{
|
||||
struct sSection *pSection;
|
||||
|
||||
@@ -483,7 +493,7 @@ void PSION2_AssignSections(void)
|
||||
pSection = pSections;
|
||||
while (pSection) {
|
||||
if (pSection->oAssigned == 0
|
||||
&& pSection->Type == SECT_CODE) {
|
||||
&& pSection->Type == SECT_CODE) {
|
||||
pSection->oAssigned = 1;
|
||||
pSection->nBank = 0;
|
||||
pSection->nOrg = BankFree[0]->nOrg;
|
||||
@@ -496,7 +506,7 @@ void PSION2_AssignSections(void)
|
||||
pSection = pSections;
|
||||
while (pSection) {
|
||||
if (pSection->oAssigned == 0
|
||||
&& pSection->Type == SECT_BSS) {
|
||||
&& pSection->Type == SECT_BSS) {
|
||||
pSection->oAssigned = 1;
|
||||
pSection->nBank = 0;
|
||||
pSection->nOrg = BankFree[0]->nOrg;
|
||||
@@ -507,10 +517,11 @@ void PSION2_AssignSections(void)
|
||||
}
|
||||
}
|
||||
|
||||
void AssignSections(void)
|
||||
void
|
||||
AssignSections(void)
|
||||
{
|
||||
switch (outputtype) {
|
||||
case OUTPUT_GBROM:
|
||||
case OUTPUT_GBROM:
|
||||
GBROM_AssignSections();
|
||||
break;
|
||||
case OUTPUT_PSION2:
|
||||
@@ -519,7 +530,8 @@ void AssignSections(void)
|
||||
}
|
||||
}
|
||||
|
||||
void CreateSymbolTable(void)
|
||||
void
|
||||
CreateSymbolTable(void)
|
||||
{
|
||||
struct sSection *pSect;
|
||||
|
||||
@@ -535,18 +547,18 @@ void CreateSymbolTable(void)
|
||||
while (i--) {
|
||||
if ((pSect->tSymbols[i]->Type == SYM_EXPORT) &&
|
||||
((pSect->tSymbols[i]->pSection == pSect) ||
|
||||
(pSect->tSymbols[i]->pSection == NULL))) {
|
||||
(pSect->tSymbols[i]->pSection == NULL))) {
|
||||
if (pSect->tSymbols[i]->pSection == NULL)
|
||||
sym_CreateSymbol(pSect->tSymbols[i]->
|
||||
pzName,
|
||||
pSect->tSymbols[i]->
|
||||
nOffset, -1);
|
||||
pzName,
|
||||
pSect->tSymbols[i]->
|
||||
nOffset, -1);
|
||||
else
|
||||
sym_CreateSymbol(pSect->tSymbols[i]->
|
||||
pzName,
|
||||
pSect->nOrg +
|
||||
pSect->tSymbols[i]->
|
||||
nOffset, pSect->nBank);
|
||||
pzName,
|
||||
pSect->nOrg +
|
||||
pSect->tSymbols[i]->
|
||||
nOffset, pSect->nBank);
|
||||
}
|
||||
}
|
||||
pSect = pSect->pNext;
|
||||
|
||||
@@ -6,7 +6,8 @@
|
||||
#include "link/mylink.h"
|
||||
#include "link/main.h"
|
||||
|
||||
static BBOOL symboldefined(char *name)
|
||||
static BBOOL
|
||||
symboldefined(char *name)
|
||||
{
|
||||
struct sSection *pSect;
|
||||
|
||||
@@ -23,14 +24,14 @@ static BBOOL symboldefined(char *name)
|
||||
0)
|
||||
return (1);
|
||||
}
|
||||
|
||||
}
|
||||
pSect = pSect->pNext;
|
||||
}
|
||||
return (0);
|
||||
}
|
||||
|
||||
static BBOOL addmodulecontaining(char *name)
|
||||
static BBOOL
|
||||
addmodulecontaining(char *name)
|
||||
{
|
||||
struct sSection **ppLSect;
|
||||
|
||||
@@ -46,7 +47,7 @@ static BBOOL addmodulecontaining(char *name)
|
||||
(*ppLSect)->tSymbols[i]->pSection))) {
|
||||
if (strcmp
|
||||
((*ppLSect)->tSymbols[i]->pzName,
|
||||
name) == 0) {
|
||||
name) == 0) {
|
||||
struct sSection **ppSect;
|
||||
ppSect = &pSections;
|
||||
while (*ppSect)
|
||||
@@ -58,14 +59,14 @@ static BBOOL addmodulecontaining(char *name)
|
||||
return (1);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
ppLSect = &((*ppLSect)->pNext);
|
||||
}
|
||||
return (0);
|
||||
}
|
||||
|
||||
void AddNeededModules(void)
|
||||
void
|
||||
AddNeededModules(void)
|
||||
{
|
||||
struct sSection *pSect;
|
||||
|
||||
@@ -84,21 +85,19 @@ void AddNeededModules(void)
|
||||
*ppLSect = (*ppLSect)->pNext;
|
||||
(*ppSect)->pNext = NULL;
|
||||
|
||||
/*ppLSect=&((*ppLSect)->pNext); */
|
||||
/* ppLSect=&((*ppLSect)->pNext); */
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
if (options & OPT_SMART_C_LINK) {
|
||||
if (!addmodulecontaining(smartlinkstartsymbol)) {
|
||||
sprintf(temptext, "Can't find start symbol '%s'",
|
||||
smartlinkstartsymbol);
|
||||
smartlinkstartsymbol);
|
||||
fatalerror(temptext);
|
||||
} else
|
||||
printf("Smart linking with symbol '%s'\n",
|
||||
smartlinkstartsymbol);
|
||||
smartlinkstartsymbol);
|
||||
}
|
||||
|
||||
pSect = pSections;
|
||||
|
||||
while (pSect) {
|
||||
@@ -109,10 +108,9 @@ void AddNeededModules(void)
|
||||
|| (pSect->tSymbols[i]->Type == SYM_LOCAL)) {
|
||||
if (!symboldefined(pSect->tSymbols[i]->pzName)) {
|
||||
addmodulecontaining(pSect->tSymbols[i]->
|
||||
pzName);
|
||||
pzName);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
pSect = pSect->pNext;
|
||||
}
|
||||
|
||||
@@ -13,7 +13,7 @@
|
||||
#include "link/main.h"
|
||||
#include "link/library.h"
|
||||
|
||||
// Quick and dirty...but it works
|
||||
// Quick and dirty...but it works
|
||||
#ifdef __GNUC__
|
||||
#define strcmpi strcasecmp
|
||||
#endif
|
||||
@@ -36,39 +36,40 @@ char smartlinkstartsymbol[256];
|
||||
*
|
||||
*/
|
||||
|
||||
void fatalerror(char *s)
|
||||
void
|
||||
fatalerror(char *s)
|
||||
{
|
||||
printf("*ERROR* : %s\n", s);
|
||||
exit(5);
|
||||
}
|
||||
|
||||
/*
|
||||
* Print the usagescreen
|
||||
*
|
||||
*/
|
||||
|
||||
void PrintUsage(void)
|
||||
void
|
||||
PrintUsage(void)
|
||||
{
|
||||
printf("xLink v" LINK_VERSION " (part of ASMotor " ASMOTOR_VERSION
|
||||
")\n\n" "Usage: xlink [options] linkfile\n"
|
||||
"Options:\n\t-h\t\tThis text\n"
|
||||
"\t-m<mapfile>\tWrite a mapfile\n"
|
||||
"\t-n<symfile>\tWrite a NO$GMB compatible symfile\n"
|
||||
"\t-z<hx>\t\tSet the byte value (hex format) used for uninitialised\n"
|
||||
"\t\t\tdata (default is ? for random)\n"
|
||||
"\t-s<symbol>\tPerform smart linking starting with <symbol>\n"
|
||||
"\t-t\t\tOutput target\n" "\t\t-tg\tGameboy ROM image(default)\n"
|
||||
"\t\t-ts\tGameboy small mode (32kB)\n"
|
||||
"\t\t-tp\tPsion2 reloc module\n");
|
||||
")\n\n" "Usage: xlink [options] linkfile\n"
|
||||
"Options:\n\t-h\t\tThis text\n"
|
||||
"\t-m<mapfile>\tWrite a mapfile\n"
|
||||
"\t-n<symfile>\tWrite a NO$GMB compatible symfile\n"
|
||||
"\t-z<hx>\t\tSet the byte value (hex format) used for uninitialised\n"
|
||||
"\t\t\tdata (default is ? for random)\n"
|
||||
"\t-s<symbol>\tPerform smart linking starting with <symbol>\n"
|
||||
"\t-t\t\tOutput target\n" "\t\t-tg\tGameboy ROM image(default)\n"
|
||||
"\t\t-ts\tGameboy small mode (32kB)\n"
|
||||
"\t\t-tp\tPsion2 reloc module\n");
|
||||
exit(0);
|
||||
}
|
||||
|
||||
/*
|
||||
* Parse the linkfile and load all the objectfiles
|
||||
*
|
||||
*/
|
||||
|
||||
void ProcessLinkfile(char *tzLinkfile)
|
||||
void
|
||||
ProcessLinkfile(char *tzLinkfile)
|
||||
{
|
||||
FILE *pLinkfile;
|
||||
enum eBlockType CurrentBlock = BLOCK_COMMENT;
|
||||
@@ -78,45 +79,44 @@ void ProcessLinkfile(char *tzLinkfile)
|
||||
sprintf(temptext, "Unable to find linkfile '%s'\n", tzLinkfile);
|
||||
fatalerror(temptext);
|
||||
}
|
||||
|
||||
while (!feof(pLinkfile)) {
|
||||
char tzLine[256];
|
||||
|
||||
fscanf(pLinkfile, "%s\n", tzLine);
|
||||
if (tzLine[0] != '#') {
|
||||
if (tzLine[0] == '['
|
||||
&& tzLine[strlen(tzLine) - 1] == ']') {
|
||||
&& tzLine[strlen(tzLine) - 1] == ']') {
|
||||
if (strcmpi("[objects]", tzLine) == 0)
|
||||
CurrentBlock = BLOCK_OBJECTS;
|
||||
else if (strcmpi("[output]", tzLine) ==
|
||||
0)
|
||||
0)
|
||||
CurrentBlock = BLOCK_OUTPUT;
|
||||
else if (strcmpi("[libraries]", tzLine)
|
||||
== 0)
|
||||
== 0)
|
||||
CurrentBlock = BLOCK_LIBRARIES;
|
||||
else if (strcmpi("[comment]", tzLine) ==
|
||||
0)
|
||||
0)
|
||||
CurrentBlock = BLOCK_COMMENT;
|
||||
else {
|
||||
fclose(pLinkfile);
|
||||
sprintf(temptext,
|
||||
"Unknown block '%s'\n",
|
||||
tzLine);
|
||||
"Unknown block '%s'\n",
|
||||
tzLine);
|
||||
fatalerror(temptext);
|
||||
}
|
||||
} else {
|
||||
switch (CurrentBlock) {
|
||||
case BLOCK_COMMENT:
|
||||
break;
|
||||
case BLOCK_OBJECTS:
|
||||
obj_Readfile(tzLine);
|
||||
break;
|
||||
case BLOCK_LIBRARIES:
|
||||
lib_Readfile(tzLine);
|
||||
break;
|
||||
case BLOCK_OUTPUT:
|
||||
out_Setname(tzLine);
|
||||
break;
|
||||
case BLOCK_COMMENT:
|
||||
break;
|
||||
case BLOCK_OBJECTS:
|
||||
obj_Readfile(tzLine);
|
||||
break;
|
||||
case BLOCK_LIBRARIES:
|
||||
lib_Readfile(tzLine);
|
||||
break;
|
||||
case BLOCK_OUTPUT:
|
||||
out_Setname(tzLine);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -124,13 +124,13 @@ void ProcessLinkfile(char *tzLinkfile)
|
||||
|
||||
fclose(pLinkfile);
|
||||
}
|
||||
|
||||
/*
|
||||
* The main routine
|
||||
*
|
||||
*/
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
int
|
||||
main(int argc, char *argv[])
|
||||
{
|
||||
SLONG argn = 0;
|
||||
|
||||
@@ -168,7 +168,7 @@ int main(int argc, char *argv[])
|
||||
break;
|
||||
default:
|
||||
sprintf(temptext, "Unknown option 't%c'\n",
|
||||
opt);
|
||||
opt);
|
||||
fatalerror(temptext);
|
||||
break;
|
||||
}
|
||||
@@ -182,7 +182,7 @@ int main(int argc, char *argv[])
|
||||
|
||||
result =
|
||||
sscanf(argv[argn - 1] + 2, "%lx",
|
||||
&fillchar);
|
||||
&fillchar);
|
||||
if (!((result == EOF) || (result == 1))) {
|
||||
fatalerror
|
||||
("Invalid argument for option 'z'\n");
|
||||
|
||||
@@ -13,7 +13,8 @@ FILE *sf = NULL;
|
||||
SLONG currentbank = 0;
|
||||
SLONG sfbank;
|
||||
|
||||
void SetMapfileName(char *name)
|
||||
void
|
||||
SetMapfileName(char *name)
|
||||
{
|
||||
mf = fopen(name, "wt");
|
||||
|
||||
@@ -21,7 +22,8 @@ void SetMapfileName(char *name)
|
||||
fatalerror("Unable to open mapfile for writing");
|
||||
}
|
||||
|
||||
void SetSymfileName(char *name)
|
||||
void
|
||||
SetSymfileName(char *name)
|
||||
{
|
||||
sf = fopen(name, "wt");
|
||||
|
||||
@@ -31,7 +33,8 @@ void SetSymfileName(char *name)
|
||||
fprintf(sf, ";File generated by xLink v" LINK_VERSION "\n\n");
|
||||
}
|
||||
|
||||
void CloseMapfile(void)
|
||||
void
|
||||
CloseMapfile(void)
|
||||
{
|
||||
if (mf) {
|
||||
fclose(mf);
|
||||
@@ -43,7 +46,8 @@ void CloseMapfile(void)
|
||||
}
|
||||
}
|
||||
|
||||
void MapfileInitBank(SLONG bank)
|
||||
void
|
||||
MapfileInitBank(SLONG bank)
|
||||
{
|
||||
if (mf) {
|
||||
currentbank = bank;
|
||||
@@ -58,13 +62,13 @@ void MapfileInitBank(SLONG bank)
|
||||
else if (bank == BANK_VRAM)
|
||||
fprintf(mf, "VRAM:\n");
|
||||
}
|
||||
|
||||
if (sf) {
|
||||
sfbank = (bank >= 1 && bank <= 255) ? bank : 0;
|
||||
}
|
||||
}
|
||||
|
||||
void MapfileWriteSection(struct sSection *pSect)
|
||||
void
|
||||
MapfileWriteSection(struct sSection * pSect)
|
||||
{
|
||||
if (!mf && !sf)
|
||||
return;
|
||||
@@ -72,30 +76,30 @@ void MapfileWriteSection(struct sSection *pSect)
|
||||
SLONG i;
|
||||
|
||||
fprintf(mf, " SECTION: $%04lX-$%04lX ($%04lX bytes)\n",
|
||||
pSect->nOrg, pSect->nOrg + pSect->nByteSize - 1,
|
||||
pSect->nByteSize);
|
||||
pSect->nOrg, pSect->nOrg + pSect->nByteSize - 1,
|
||||
pSect->nByteSize);
|
||||
|
||||
for (i = 0; i < pSect->nNumberOfSymbols; i += 1) {
|
||||
struct sSymbol *pSym;
|
||||
pSym = pSect->tSymbols[i];
|
||||
if ((pSym->pSection == pSect)
|
||||
&& (pSym->Type != SYM_IMPORT)) {
|
||||
&& (pSym->Type != SYM_IMPORT)) {
|
||||
if (mf) {
|
||||
fprintf(mf, " $%04lX = %s\n",
|
||||
pSym->nOffset + pSect->nOrg,
|
||||
pSym->pzName);
|
||||
pSym->nOffset + pSect->nOrg,
|
||||
pSym->pzName);
|
||||
}
|
||||
if (sf) {
|
||||
fprintf(sf, "%02lX:%04lX %s\n", sfbank,
|
||||
pSym->nOffset + pSect->nOrg,
|
||||
pSym->pzName);
|
||||
pSym->nOffset + pSect->nOrg,
|
||||
pSym->pzName);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void MapfileCloseBank(SLONG slack)
|
||||
void
|
||||
MapfileCloseBank(SLONG slack)
|
||||
{
|
||||
if (!mf)
|
||||
return;
|
||||
|
||||
@@ -21,7 +21,8 @@ BBOOL oReadLib = 0;
|
||||
*
|
||||
*/
|
||||
|
||||
SLONG readlong(FILE * f)
|
||||
SLONG
|
||||
readlong(FILE * f)
|
||||
{
|
||||
SLONG r;
|
||||
|
||||
@@ -33,7 +34,8 @@ SLONG readlong(FILE * f)
|
||||
return (r);
|
||||
}
|
||||
|
||||
UWORD readword(FILE * f)
|
||||
UWORD
|
||||
readword(FILE * f)
|
||||
{
|
||||
UWORD r;
|
||||
|
||||
@@ -42,13 +44,13 @@ UWORD readword(FILE * f)
|
||||
|
||||
return (r);
|
||||
}
|
||||
|
||||
/*
|
||||
* Read a NULL terminated string from a file
|
||||
*
|
||||
*/
|
||||
|
||||
SLONG readasciiz(char *s, FILE * f)
|
||||
SLONG
|
||||
readasciiz(char *s, FILE * f)
|
||||
{
|
||||
SLONG r = 0;
|
||||
|
||||
@@ -57,13 +59,13 @@ SLONG readasciiz(char *s, FILE * f)
|
||||
|
||||
return (r + 1);
|
||||
}
|
||||
|
||||
/*
|
||||
* Allocate a new section and link it into the list
|
||||
*
|
||||
*/
|
||||
|
||||
struct sSection *AllocSection(void)
|
||||
struct sSection *
|
||||
AllocSection(void)
|
||||
{
|
||||
struct sSection **ppSections;
|
||||
|
||||
@@ -80,20 +82,19 @@ struct sSection *AllocSection(void)
|
||||
fatalerror("Out of memory!");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
(*ppSections)->tSymbols = tSymbols;
|
||||
(*ppSections)->pNext = NULL;
|
||||
(*ppSections)->pPatches = NULL;
|
||||
(*ppSections)->oAssigned = 0;
|
||||
return *ppSections;
|
||||
}
|
||||
|
||||
/*
|
||||
* Read a symbol from a file
|
||||
*
|
||||
*/
|
||||
|
||||
struct sSymbol *obj_ReadSymbol(FILE * f)
|
||||
struct sSymbol *
|
||||
obj_ReadSymbol(FILE * f)
|
||||
{
|
||||
char s[256];
|
||||
struct sSymbol *pSym;
|
||||
@@ -108,27 +109,26 @@ struct sSymbol *obj_ReadSymbol(FILE * f)
|
||||
fatalerror("Out of memory!");
|
||||
|
||||
strcpy(pSym->pzName, s);
|
||||
if ((pSym->Type = (enum eSymbolType)fgetc(f)) != SYM_IMPORT) {
|
||||
if ((pSym->Type = (enum eSymbolType) fgetc(f)) != SYM_IMPORT) {
|
||||
pSym->nSectionID = readlong(f);
|
||||
pSym->nOffset = readlong(f);
|
||||
}
|
||||
|
||||
return pSym;
|
||||
}
|
||||
|
||||
/*
|
||||
* RGB0 object reader routines
|
||||
*
|
||||
*/
|
||||
|
||||
struct sSection *obj_ReadRGB0Section(FILE * f)
|
||||
struct sSection *
|
||||
obj_ReadRGB0Section(FILE * f)
|
||||
{
|
||||
struct sSection *pSection;
|
||||
|
||||
pSection = AllocSection();
|
||||
|
||||
pSection->nByteSize = readlong(f);
|
||||
pSection->Type = (enum eSectionType)fgetc(f);
|
||||
pSection->Type = (enum eSectionType) fgetc(f);
|
||||
pSection->nOrg = -1;
|
||||
pSection->nBank = -1;
|
||||
|
||||
@@ -137,7 +137,6 @@ struct sSection *obj_ReadRGB0Section(FILE * f)
|
||||
if ((options & OPT_SMALL) && (pSection->Type == SECT_CODE)) {
|
||||
pSection->Type = SECT_HOME;
|
||||
}
|
||||
|
||||
if ((pSection->Type == SECT_CODE) || (pSection->Type == SECT_HOME)) {
|
||||
/*
|
||||
* These sectiontypes contain data...
|
||||
@@ -153,7 +152,7 @@ struct sSection *obj_ReadRGB0Section(FILE * f)
|
||||
char s[256];
|
||||
|
||||
fread(pSection->pData, sizeof(UBYTE),
|
||||
pSection->nByteSize, f);
|
||||
pSection->nByteSize, f);
|
||||
nNumberOfPatches = readlong(f);
|
||||
ppPatch = &pSection->pPatches;
|
||||
|
||||
@@ -176,12 +175,12 @@ struct sSection *obj_ReadRGB0Section(FILE * f)
|
||||
strcpy(pPatch->pzFilename, s);
|
||||
|
||||
pPatch->nLineNo =
|
||||
readlong(f);
|
||||
readlong(f);
|
||||
pPatch->nOffset =
|
||||
readlong(f);
|
||||
readlong(f);
|
||||
pPatch->Type =
|
||||
(enum ePatchType)
|
||||
fgetc(f);
|
||||
(enum ePatchType)
|
||||
fgetc(f);
|
||||
|
||||
if ((pPatch->nRPNSize = readlong(f)) > 0) {
|
||||
pPatch->pRPN = malloc(pPatch->nRPNSize);
|
||||
@@ -189,7 +188,7 @@ struct sSection *obj_ReadRGB0Section(FILE * f)
|
||||
fatalerror("Out of memory!");
|
||||
|
||||
fread(pPatch->pRPN, sizeof(UBYTE),
|
||||
pPatch->nRPNSize, f);
|
||||
pPatch->nRPNSize, f);
|
||||
} else
|
||||
pPatch->pRPN = NULL;
|
||||
|
||||
@@ -202,11 +201,11 @@ struct sSection *obj_ReadRGB0Section(FILE * f)
|
||||
pSection->pData = &dummymem;
|
||||
}
|
||||
}
|
||||
|
||||
return pSection;
|
||||
}
|
||||
|
||||
void obj_ReadRGB0(FILE *pObjfile)
|
||||
void
|
||||
obj_ReadRGB0(FILE * pObjfile)
|
||||
{
|
||||
struct sSection *pFirstSection;
|
||||
SLONG nNumberOfSymbols, nNumberOfSections, i;
|
||||
@@ -224,7 +223,7 @@ void obj_ReadRGB0(FILE *pObjfile)
|
||||
for (i = 0; i < nNumberOfSymbols; i += 1)
|
||||
tSymbols[i] = obj_ReadSymbol(pObjfile);
|
||||
} else
|
||||
tSymbols = (struct sSymbol **)&dummymem;
|
||||
tSymbols = (struct sSymbol **) & dummymem;
|
||||
|
||||
/* Next we have the sections */
|
||||
|
||||
@@ -259,20 +258,20 @@ void obj_ReadRGB0(FILE *pObjfile)
|
||||
tSymbols[i]->pSection = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* RGB1 object reader routines
|
||||
*
|
||||
*/
|
||||
|
||||
struct sSection *obj_ReadRGB1Section(FILE *f)
|
||||
struct sSection *
|
||||
obj_ReadRGB1Section(FILE * f)
|
||||
{
|
||||
struct sSection *pSection;
|
||||
|
||||
pSection = AllocSection();
|
||||
|
||||
pSection->nByteSize = readlong(f);
|
||||
pSection->Type = (enum eSectionType)fgetc(f);
|
||||
pSection->Type = (enum eSectionType) fgetc(f);
|
||||
/*
|
||||
* And because of THIS new feature I'll have to rewrite loads and
|
||||
* loads of stuff... oh well it needed to be done anyway
|
||||
@@ -286,7 +285,6 @@ struct sSection *obj_ReadRGB1Section(FILE *f)
|
||||
if ((options & OPT_SMALL) && (pSection->Type == SECT_CODE)) {
|
||||
pSection->Type = SECT_HOME;
|
||||
}
|
||||
|
||||
if ((pSection->Type == SECT_CODE) || (pSection->Type == SECT_HOME)) {
|
||||
/*
|
||||
* These sectiontypes contain data...
|
||||
@@ -302,7 +300,7 @@ struct sSection *obj_ReadRGB1Section(FILE *f)
|
||||
char s[256];
|
||||
|
||||
fread(pSection->pData, sizeof(UBYTE),
|
||||
pSection->nByteSize, f);
|
||||
pSection->nByteSize, f);
|
||||
nNumberOfPatches = readlong(f);
|
||||
ppPatch = &pSection->pPatches;
|
||||
|
||||
@@ -328,10 +326,10 @@ struct sSection *obj_ReadRGB1Section(FILE *f)
|
||||
if ((pPatch->nRPNSize = readlong(f)) > 0) {
|
||||
pPatch->pRPN = malloc(pPatch->nRPNSize);
|
||||
if (!pPatch->pRPN)
|
||||
fatalerror ("Out of memory!");
|
||||
fatalerror("Out of memory!");
|
||||
|
||||
fread(pPatch->pRPN, sizeof(UBYTE),
|
||||
pPatch->nRPNSize, f);
|
||||
pPatch->nRPNSize, f);
|
||||
} else
|
||||
pPatch->pRPN = NULL;
|
||||
|
||||
@@ -344,11 +342,11 @@ struct sSection *obj_ReadRGB1Section(FILE *f)
|
||||
pSection->pData = &dummymem;
|
||||
}
|
||||
}
|
||||
|
||||
return pSection;
|
||||
}
|
||||
|
||||
void obj_ReadRGB1(FILE *pObjfile)
|
||||
void
|
||||
obj_ReadRGB1(FILE * pObjfile)
|
||||
{
|
||||
struct sSection *pFirstSection;
|
||||
SLONG nNumberOfSymbols, nNumberOfSections, i;
|
||||
@@ -366,7 +364,7 @@ void obj_ReadRGB1(FILE *pObjfile)
|
||||
for (i = 0; i < nNumberOfSymbols; i += 1)
|
||||
tSymbols[i] = obj_ReadSymbol(pObjfile);
|
||||
} else
|
||||
tSymbols = (struct sSymbol **)&dummymem;
|
||||
tSymbols = (struct sSymbol **) & dummymem;
|
||||
|
||||
/* Next we have the sections */
|
||||
|
||||
@@ -401,13 +399,13 @@ void obj_ReadRGB1(FILE *pObjfile)
|
||||
tSymbols[i]->pSection = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* The main objectfileloadroutine (phew)
|
||||
*
|
||||
*/
|
||||
|
||||
void obj_ReadOpenFile(FILE * pObjfile, char *tzObjectfile)
|
||||
void
|
||||
obj_ReadOpenFile(FILE * pObjfile, char *tzObjectfile)
|
||||
{
|
||||
char tzHeader[8];
|
||||
|
||||
@@ -419,12 +417,13 @@ void obj_ReadOpenFile(FILE * pObjfile, char *tzObjectfile)
|
||||
obj_ReadRGB0(pObjfile);
|
||||
break;
|
||||
case '1':
|
||||
case '2': // V2 is really the same but the are new patch types
|
||||
obj_ReadRGB1(pObjfile);
|
||||
case '2':
|
||||
//V2 is really the same but the are new patch types
|
||||
obj_ReadRGB1(pObjfile);
|
||||
break;
|
||||
default:
|
||||
sprintf(temptext, "'%s' is an unsupported version\n",
|
||||
tzObjectfile);
|
||||
tzObjectfile);
|
||||
fatalerror(temptext);
|
||||
break;
|
||||
}
|
||||
@@ -434,7 +433,8 @@ void obj_ReadOpenFile(FILE * pObjfile, char *tzObjectfile)
|
||||
}
|
||||
}
|
||||
|
||||
void obj_Readfile(char *tzObjectfile)
|
||||
void
|
||||
obj_Readfile(char *tzObjectfile)
|
||||
{
|
||||
FILE *pObjfile;
|
||||
|
||||
@@ -448,14 +448,14 @@ void obj_Readfile(char *tzObjectfile)
|
||||
sprintf(temptext, "Unable to open '%s'\n", tzObjectfile);
|
||||
fatalerror(temptext);
|
||||
}
|
||||
|
||||
obj_ReadOpenFile(pObjfile, tzObjectfile);
|
||||
fclose(pObjfile);
|
||||
|
||||
oReadLib = 0;
|
||||
}
|
||||
|
||||
SLONG file_Length(FILE * f)
|
||||
SLONG
|
||||
file_Length(FILE * f)
|
||||
{
|
||||
ULONG r, p;
|
||||
|
||||
@@ -467,7 +467,8 @@ SLONG file_Length(FILE * f)
|
||||
return (r);
|
||||
}
|
||||
|
||||
void lib_ReadXLB0(FILE * f)
|
||||
void
|
||||
lib_ReadXLB0(FILE * f)
|
||||
{
|
||||
SLONG size;
|
||||
|
||||
@@ -486,7 +487,8 @@ void lib_ReadXLB0(FILE * f)
|
||||
}
|
||||
}
|
||||
|
||||
void lib_Readfile(char *tzLibfile)
|
||||
void
|
||||
lib_Readfile(char *tzLibfile)
|
||||
{
|
||||
FILE *pObjfile;
|
||||
|
||||
@@ -497,7 +499,6 @@ void lib_Readfile(char *tzLibfile)
|
||||
sprintf(temptext, "Unable to open '%s'\n", tzLibfile);
|
||||
fatalerror(temptext);
|
||||
}
|
||||
|
||||
char tzHeader[5];
|
||||
|
||||
fread(tzHeader, sizeof(char), 4, pObjfile);
|
||||
@@ -506,7 +507,7 @@ void lib_Readfile(char *tzLibfile)
|
||||
lib_ReadXLB0(pObjfile);
|
||||
else {
|
||||
sprintf(temptext, "'%s' is an invalid library\n",
|
||||
tzLibfile);
|
||||
tzLibfile);
|
||||
fatalerror(temptext);
|
||||
}
|
||||
fclose(pObjfile);
|
||||
|
||||
@@ -10,7 +10,8 @@
|
||||
char tzOutname[_MAX_PATH];
|
||||
BBOOL oOutput = 0;
|
||||
|
||||
void writehome(FILE *f)
|
||||
void
|
||||
writehome(FILE * f)
|
||||
{
|
||||
struct sSection *pSect;
|
||||
UBYTE *mem;
|
||||
@@ -28,7 +29,7 @@ void writehome(FILE *f)
|
||||
while (pSect) {
|
||||
if (pSect->Type == SECT_HOME) {
|
||||
memcpy(mem + pSect->nOrg, pSect->pData,
|
||||
pSect->nByteSize);
|
||||
pSect->nByteSize);
|
||||
MapfileWriteSection(pSect);
|
||||
}
|
||||
pSect = pSect->pNext;
|
||||
@@ -40,7 +41,8 @@ void writehome(FILE *f)
|
||||
free(mem);
|
||||
}
|
||||
|
||||
void writebank(FILE *f, SLONG bank)
|
||||
void
|
||||
writebank(FILE * f, SLONG bank)
|
||||
{
|
||||
struct sSection *pSect;
|
||||
UBYTE *mem;
|
||||
@@ -52,14 +54,13 @@ void writebank(FILE *f, SLONG bank)
|
||||
if (fillchar != -1) {
|
||||
memset(mem, fillchar, MaxAvail[bank]);
|
||||
}
|
||||
|
||||
MapfileInitBank(bank);
|
||||
|
||||
pSect = pSections;
|
||||
while (pSect) {
|
||||
if (pSect->Type == SECT_CODE && pSect->nBank == bank) {
|
||||
memcpy(mem + pSect->nOrg - 0x4000, pSect->pData,
|
||||
pSect->nByteSize);
|
||||
pSect->nByteSize);
|
||||
MapfileWriteSection(pSect);
|
||||
}
|
||||
pSect = pSect->pNext;
|
||||
@@ -71,13 +72,15 @@ void writebank(FILE *f, SLONG bank)
|
||||
free(mem);
|
||||
}
|
||||
|
||||
void out_Setname(char *tzOutputfile)
|
||||
void
|
||||
out_Setname(char *tzOutputfile)
|
||||
{
|
||||
strcpy(tzOutname, tzOutputfile);
|
||||
oOutput = 1;
|
||||
}
|
||||
|
||||
void GBROM_Output(void)
|
||||
void
|
||||
GBROM_Output(void)
|
||||
{
|
||||
SLONG i;
|
||||
FILE *f;
|
||||
@@ -89,7 +92,6 @@ void GBROM_Output(void)
|
||||
|
||||
fclose(f);
|
||||
}
|
||||
|
||||
for (i = 256; i < MAXBANKS; i += 1) {
|
||||
struct sSection *pSect;
|
||||
MapfileInitBank(i);
|
||||
@@ -104,7 +106,8 @@ void GBROM_Output(void)
|
||||
}
|
||||
}
|
||||
|
||||
void PSION2_Output(void)
|
||||
void
|
||||
PSION2_Output(void)
|
||||
{
|
||||
FILE *f;
|
||||
|
||||
@@ -126,11 +129,11 @@ void PSION2_Output(void)
|
||||
while (pSect) {
|
||||
if (pSect->Type == SECT_CODE) {
|
||||
memcpy(mem + pSect->nOrg, pSect->pData,
|
||||
pSect->nByteSize);
|
||||
pSect->nByteSize);
|
||||
MapfileWriteSection(pSect);
|
||||
} else {
|
||||
memset(mem + pSect->nOrg, 0,
|
||||
pSect->nByteSize);
|
||||
pSect->nByteSize);
|
||||
}
|
||||
pSect = pSect->pNext;
|
||||
}
|
||||
@@ -140,7 +143,6 @@ void PSION2_Output(void)
|
||||
fwrite(mem, 1, MaxAvail[0] - area_Avail(0), f);
|
||||
free(mem);
|
||||
}
|
||||
|
||||
relocpatches = 0;
|
||||
pSect = pSections;
|
||||
while (pSect) {
|
||||
@@ -187,11 +189,12 @@ void PSION2_Output(void)
|
||||
}
|
||||
}
|
||||
|
||||
void Output(void)
|
||||
void
|
||||
Output(void)
|
||||
{
|
||||
if (oOutput) {
|
||||
switch (outputtype) {
|
||||
case OUTPUT_GBROM:
|
||||
case OUTPUT_GBROM:
|
||||
GBROM_Output();
|
||||
break;
|
||||
case OUTPUT_PSION2:
|
||||
|
||||
@@ -10,20 +10,23 @@ SLONG rpnstack[256];
|
||||
SLONG rpnp;
|
||||
SLONG nPC;
|
||||
|
||||
void rpnpush(SLONG i)
|
||||
void
|
||||
rpnpush(SLONG i)
|
||||
{
|
||||
rpnstack[rpnp++] = i;
|
||||
}
|
||||
|
||||
SLONG rpnpop(void)
|
||||
SLONG
|
||||
rpnpop(void)
|
||||
{
|
||||
return (rpnstack[--rpnp]);
|
||||
}
|
||||
|
||||
SLONG getsymvalue(SLONG symid)
|
||||
SLONG
|
||||
getsymvalue(SLONG symid)
|
||||
{
|
||||
switch (pCurrentSection->tSymbols[symid]->Type) {
|
||||
case SYM_IMPORT:
|
||||
case SYM_IMPORT:
|
||||
return (sym_GetValue(pCurrentSection->tSymbols[symid]->pzName));
|
||||
break;
|
||||
case SYM_EXPORT:
|
||||
@@ -31,13 +34,13 @@ SLONG getsymvalue(SLONG symid)
|
||||
{
|
||||
if (strcmp
|
||||
(pCurrentSection->tSymbols[symid]->pzName,
|
||||
"@") == 0) {
|
||||
"@") == 0) {
|
||||
return (nPC);
|
||||
} else
|
||||
return (pCurrentSection->tSymbols[symid]->
|
||||
nOffset +
|
||||
pCurrentSection->tSymbols[symid]->
|
||||
pSection->nOrg);
|
||||
nOffset +
|
||||
pCurrentSection->tSymbols[symid]->
|
||||
pSection->nOrg);
|
||||
}
|
||||
default:
|
||||
break;
|
||||
@@ -46,16 +49,17 @@ SLONG getsymvalue(SLONG symid)
|
||||
return (0);
|
||||
}
|
||||
|
||||
SLONG getsymbank(SLONG symid)
|
||||
SLONG
|
||||
getsymbank(SLONG symid)
|
||||
{
|
||||
switch (pCurrentSection->tSymbols[symid]->Type) {
|
||||
case SYM_IMPORT:
|
||||
case SYM_IMPORT:
|
||||
return (sym_GetBank(pCurrentSection->tSymbols[symid]->pzName));
|
||||
break;
|
||||
case SYM_EXPORT:
|
||||
case SYM_LOCAL:
|
||||
return (pCurrentSection->tSymbols[symid]->pSection->nBank);
|
||||
//return( pCurrentSection->nBank );
|
||||
//return (pCurrentSection->nBank);
|
||||
default:
|
||||
break;
|
||||
}
|
||||
@@ -63,7 +67,8 @@ SLONG getsymbank(SLONG symid)
|
||||
return (0);
|
||||
}
|
||||
|
||||
SLONG calcrpn(struct sPatch * pPatch)
|
||||
SLONG
|
||||
calcrpn(struct sPatch * pPatch)
|
||||
{
|
||||
SLONG t, size;
|
||||
UBYTE *rpn;
|
||||
@@ -154,8 +159,8 @@ SLONG calcrpn(struct sPatch * pPatch)
|
||||
rpnpush(t & 0xFF);
|
||||
if (t < 0 || (t > 0xFF && t < 0xFF00) || t > 0xFFFF) {
|
||||
sprintf(temptext,
|
||||
"%s(%ld) : Value must be in the HRAM area",
|
||||
pPatch->pzFilename, pPatch->nLineNo);
|
||||
"%s(%ld) : Value must be in the HRAM area",
|
||||
pPatch->pzFilename, pPatch->nLineNo);
|
||||
fatalerror(temptext);
|
||||
}
|
||||
break;
|
||||
@@ -164,8 +169,8 @@ SLONG calcrpn(struct sPatch * pPatch)
|
||||
rpnpush(t & 0xFF);
|
||||
if (t < 0x2000 || t > 0x20FF) {
|
||||
sprintf(temptext,
|
||||
"%s(%ld) : Value must be in the ZP area",
|
||||
pPatch->pzFilename, pPatch->nLineNo);
|
||||
"%s(%ld) : Value must be in the ZP area",
|
||||
pPatch->pzFilename, pPatch->nLineNo);
|
||||
fatalerror(temptext);
|
||||
}
|
||||
break;
|
||||
@@ -212,9 +217,9 @@ SLONG calcrpn(struct sPatch * pPatch)
|
||||
t = rpnpop();
|
||||
if (t < low || t > high) {
|
||||
sprintf(temptext,
|
||||
"%s(%ld) : Value must be in the range [%ld;%ld]",
|
||||
pPatch->pzFilename,
|
||||
pPatch->nLineNo, low, high);
|
||||
"%s(%ld) : Value must be in the range [%ld;%ld]",
|
||||
pPatch->pzFilename,
|
||||
pPatch->nLineNo, low, high);
|
||||
fatalerror(temptext);
|
||||
}
|
||||
rpnpush(t);
|
||||
@@ -226,7 +231,8 @@ SLONG calcrpn(struct sPatch * pPatch)
|
||||
return (rpnpop());
|
||||
}
|
||||
|
||||
void Patch(void)
|
||||
void
|
||||
Patch(void)
|
||||
{
|
||||
struct sSection *pSect;
|
||||
|
||||
@@ -249,9 +255,9 @@ void Patch(void)
|
||||
(UBYTE) t;
|
||||
} else {
|
||||
sprintf(temptext,
|
||||
"%s(%ld) : Value must be 8-bit\n",
|
||||
pPatch->pzFilename,
|
||||
pPatch->nLineNo);
|
||||
"%s(%ld) : Value must be 8-bit\n",
|
||||
pPatch->pzFilename,
|
||||
pPatch->nLineNo);
|
||||
fatalerror(temptext);
|
||||
}
|
||||
break;
|
||||
@@ -263,20 +269,20 @@ void Patch(void)
|
||||
pSect->pData[pPatch->nOffset] =
|
||||
t & 0xFF;
|
||||
pSect->pData[pPatch->nOffset +
|
||||
1] =
|
||||
1] =
|
||||
(t >> 8) & 0xFF;
|
||||
} else {
|
||||
// Assume big endian
|
||||
pSect->pData[pPatch->nOffset] =
|
||||
//Assume big endian
|
||||
pSect->pData[pPatch->nOffset] =
|
||||
(t >> 8) & 0xFF;
|
||||
pSect->pData[pPatch->nOffset +
|
||||
1] = t & 0xFF;
|
||||
1] = t & 0xFF;
|
||||
}
|
||||
} else {
|
||||
sprintf(temptext,
|
||||
"%s(%ld) : Value must be 16-bit\n",
|
||||
pPatch->pzFilename,
|
||||
pPatch->nLineNo);
|
||||
"%s(%ld) : Value must be 16-bit\n",
|
||||
pPatch->pzFilename,
|
||||
pPatch->nLineNo);
|
||||
fatalerror(temptext);
|
||||
}
|
||||
break;
|
||||
|
||||
@@ -11,13 +11,15 @@
|
||||
struct ISymbol {
|
||||
char *pzName;
|
||||
SLONG nValue;
|
||||
SLONG nBank; // -1=const
|
||||
SLONG nBank;
|
||||
//-1 = const
|
||||
struct ISymbol *pNext;
|
||||
};
|
||||
|
||||
struct ISymbol *tHash[HASHSIZE];
|
||||
|
||||
SLONG calchash(char *s)
|
||||
SLONG
|
||||
calchash(char *s)
|
||||
{
|
||||
SLONG r = 0;
|
||||
while (*s)
|
||||
@@ -26,14 +28,16 @@ SLONG calchash(char *s)
|
||||
return (r % HASHSIZE);
|
||||
}
|
||||
|
||||
void sym_Init(void)
|
||||
void
|
||||
sym_Init(void)
|
||||
{
|
||||
SLONG i;
|
||||
for (i = 0; i < HASHSIZE; i += 1)
|
||||
tHash[i] = NULL;
|
||||
}
|
||||
|
||||
SLONG sym_GetValue(char *tzName)
|
||||
SLONG
|
||||
sym_GetValue(char *tzName)
|
||||
{
|
||||
if (strcmp(tzName, "@") == 0) {
|
||||
return (nPC);
|
||||
@@ -55,7 +59,8 @@ SLONG sym_GetValue(char *tzName)
|
||||
}
|
||||
}
|
||||
|
||||
SLONG sym_GetBank(char *tzName)
|
||||
SLONG
|
||||
sym_GetBank(char *tzName)
|
||||
{
|
||||
struct ISymbol **ppSym;
|
||||
|
||||
@@ -73,7 +78,8 @@ SLONG sym_GetBank(char *tzName)
|
||||
return (0);
|
||||
}
|
||||
|
||||
void sym_CreateSymbol(char *tzName, SLONG nValue, SBYTE nBank)
|
||||
void
|
||||
sym_CreateSymbol(char *tzName, SLONG nValue, SBYTE nBank)
|
||||
{
|
||||
if (strcmp(tzName, "@") == 0)
|
||||
return;
|
||||
@@ -90,8 +96,8 @@ void sym_CreateSymbol(char *tzName, SLONG nValue, SBYTE nBank)
|
||||
return;
|
||||
|
||||
sprintf(temptext,
|
||||
"Symbol '%s' defined more than once\n",
|
||||
tzName);
|
||||
"Symbol '%s' defined more than once\n",
|
||||
tzName);
|
||||
fatalerror(temptext);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user