mirror of
https://github.com/gbdev/rgbds.git
synced 2025-11-24 20:12:07 +00:00
Fixed warnings and some style issues
Signed-off-by: Vegard Nossum <vegard.nossum@gmail.com>
This commit is contained in:
@@ -147,7 +147,7 @@ void AssignCodeSections(void)
|
||||
{
|
||||
struct sSection *pSection;
|
||||
|
||||
while (pSection = FindLargestCode()) {
|
||||
while ((pSection = FindLargestCode())) {
|
||||
SLONG org;
|
||||
|
||||
if ((org = area_AllocCODEAnyBank(pSection->nByteSize)) != -1) {
|
||||
@@ -173,48 +173,48 @@ void GBROM_AssignSections(void)
|
||||
*/
|
||||
|
||||
for (i = 0; i < MAXBANKS; i += 1) {
|
||||
if (BankFree[i] =
|
||||
(struct sFreeArea *)malloc(sizeof(struct sFreeArea))) {
|
||||
if (i == 0) {
|
||||
BankFree[i]->nOrg = 0x0000;
|
||||
if (options & OPT_SMALL) {
|
||||
BankFree[i]->nSize = 0x8000;
|
||||
MaxAvail[i] = 0x8000;
|
||||
} else {
|
||||
BankFree[i]->nSize = 0x4000;
|
||||
MaxAvail[i] = 0x4000;
|
||||
}
|
||||
} else if (i >= 1 && i <= 255) {
|
||||
BankFree[i]->nOrg = 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;
|
||||
MaxAvail[i] = 0;
|
||||
} else {
|
||||
BankFree[i]->nSize = 0x4000;
|
||||
MaxAvail[i] = 0x4000;
|
||||
}
|
||||
} else if (i == BANK_BSS) {
|
||||
BankFree[i]->nOrg = 0xC000;
|
||||
BankFree[i]->nSize = 0x2000;
|
||||
MaxAvail[i] = 0x2000;
|
||||
} else if (i == BANK_VRAM) {
|
||||
BankFree[i]->nOrg = 0x8000;
|
||||
BankFree[i]->nSize = 0x2000;
|
||||
MaxAvail[i] = 0x2000;
|
||||
} else if (i == BANK_HRAM) {
|
||||
BankFree[i]->nOrg = 0xFF80;
|
||||
BankFree[i]->nSize = 0x007F;
|
||||
MaxAvail[i] = 0x007F;
|
||||
}
|
||||
BankFree[i]->pPrev = NULL;
|
||||
BankFree[i]->pNext = NULL;
|
||||
} else
|
||||
BankFree[i] = malloc(sizeof *BankFree[i]);
|
||||
|
||||
if (!BankFree[i])
|
||||
fatalerror("Out of memory!");
|
||||
|
||||
if (i == 0) {
|
||||
BankFree[i]->nOrg = 0x0000;
|
||||
if (options & OPT_SMALL) {
|
||||
BankFree[i]->nSize = 0x8000;
|
||||
MaxAvail[i] = 0x8000;
|
||||
} else {
|
||||
BankFree[i]->nSize = 0x4000;
|
||||
MaxAvail[i] = 0x4000;
|
||||
}
|
||||
} else if (i >= 1 && i <= 255) {
|
||||
BankFree[i]->nOrg = 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;
|
||||
MaxAvail[i] = 0;
|
||||
} else {
|
||||
BankFree[i]->nSize = 0x4000;
|
||||
MaxAvail[i] = 0x4000;
|
||||
}
|
||||
} else if (i == BANK_BSS) {
|
||||
BankFree[i]->nOrg = 0xC000;
|
||||
BankFree[i]->nSize = 0x2000;
|
||||
MaxAvail[i] = 0x2000;
|
||||
} else if (i == BANK_VRAM) {
|
||||
BankFree[i]->nOrg = 0x8000;
|
||||
BankFree[i]->nSize = 0x2000;
|
||||
MaxAvail[i] = 0x2000;
|
||||
} else if (i == BANK_HRAM) {
|
||||
BankFree[i]->nOrg = 0xFF80;
|
||||
BankFree[i]->nSize = 0x007F;
|
||||
MaxAvail[i] = 0x007F;
|
||||
}
|
||||
BankFree[i]->pPrev = NULL;
|
||||
BankFree[i]->pNext = NULL;
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -235,7 +235,7 @@ void GBROM_AssignSections(void)
|
||||
(&BankFree[BANK_BSS], pSection->nOrg,
|
||||
pSection->nByteSize) != pSection->nOrg) {
|
||||
sprintf(temptext,
|
||||
"Unable to load fixed BSS section at $%X",
|
||||
"Unable to load fixed BSS section at $%lX",
|
||||
pSection->nOrg);
|
||||
fatalerror(temptext);
|
||||
}
|
||||
@@ -247,7 +247,7 @@ void GBROM_AssignSections(void)
|
||||
(&BankFree[BANK_HRAM], pSection->nOrg,
|
||||
pSection->nByteSize) != pSection->nOrg) {
|
||||
sprintf(temptext,
|
||||
"Unable to load fixed HRAM section at $%X",
|
||||
"Unable to load fixed HRAM section at $%lX",
|
||||
pSection->nOrg);
|
||||
fatalerror(temptext);
|
||||
}
|
||||
@@ -259,7 +259,7 @@ void GBROM_AssignSections(void)
|
||||
(&BankFree[BANK_VRAM], pSection->nOrg,
|
||||
pSection->nByteSize) != pSection->nOrg) {
|
||||
sprintf(temptext,
|
||||
"Unable to load fixed VRAM section at $%X",
|
||||
"Unable to load fixed VRAM section at $%lX",
|
||||
pSection->nOrg);
|
||||
fatalerror(temptext);
|
||||
}
|
||||
@@ -271,7 +271,7 @@ void GBROM_AssignSections(void)
|
||||
(&BankFree[BANK_HOME], pSection->nOrg,
|
||||
pSection->nByteSize) != pSection->nOrg) {
|
||||
sprintf(temptext,
|
||||
"Unable to load fixed HOME section at $%X",
|
||||
"Unable to load fixed HOME section at $%lX",
|
||||
pSection->nOrg);
|
||||
fatalerror(temptext);
|
||||
}
|
||||
@@ -320,7 +320,7 @@ void GBROM_AssignSections(void)
|
||||
pSection->nOrg) {
|
||||
sprintf
|
||||
(temptext,
|
||||
"Unable to load fixed CODE/DATA section at $%X in bank $%02X",
|
||||
"Unable to load fixed CODE/DATA section at $%lX in bank $%02lX",
|
||||
pSection->
|
||||
nOrg,
|
||||
pSection->
|
||||
@@ -333,7 +333,7 @@ void GBROM_AssignSections(void)
|
||||
pSection->oAssigned = 1;
|
||||
} else {
|
||||
sprintf(temptext,
|
||||
"Unable to load fixed CODE/DATA section at $%X in bank $%02X",
|
||||
"Unable to load fixed CODE/DATA section at $%lX in bank $%02lX",
|
||||
pSection->nOrg,
|
||||
pSection->
|
||||
nBank);
|
||||
@@ -364,7 +364,7 @@ void GBROM_AssignSections(void)
|
||||
area_Alloc(&BankFree[pSection->nBank],
|
||||
pSection->nByteSize)) == -1) {
|
||||
sprintf(temptext,
|
||||
"Unable to load fixed CODE/DATA section into bank $%02X",
|
||||
"Unable to load fixed CODE/DATA section into bank $%02lX",
|
||||
pSection->nBank);
|
||||
fatalerror(temptext);
|
||||
}
|
||||
@@ -372,7 +372,7 @@ void GBROM_AssignSections(void)
|
||||
DOMAXBANK(pSection->nBank);
|
||||
} else {
|
||||
sprintf(temptext,
|
||||
"Unable to load fixed CODE/DATA section into bank $%02X",
|
||||
"Unable to load fixed CODE/DATA section into bank $%02lX",
|
||||
pSection->nBank);
|
||||
fatalerror(temptext);
|
||||
}
|
||||
@@ -396,7 +396,7 @@ void GBROM_AssignSections(void)
|
||||
pSection->nByteSize)) ==
|
||||
-1) {
|
||||
sprintf(temptext,
|
||||
"Unable to load fixed CODE/DATA section at $%X into any bank",
|
||||
"Unable to load fixed CODE/DATA section at $%lX into any bank",
|
||||
pSection->nOrg);
|
||||
fatalerror(temptext);
|
||||
}
|
||||
@@ -469,40 +469,41 @@ void PSION2_AssignSections(void)
|
||||
{
|
||||
struct sSection *pSection;
|
||||
|
||||
if (BankFree[0] = (struct sFreeArea *)malloc(sizeof(struct sFreeArea))) {
|
||||
BankFree[0]->nOrg = 0x0000;
|
||||
BankFree[0]->nSize = 0x10000;
|
||||
MaxAvail[0] = 0x10000;
|
||||
BankFree[0]->pPrev = NULL;
|
||||
BankFree[0]->pNext = NULL;
|
||||
|
||||
pSection = pSections;
|
||||
while (pSection) {
|
||||
if (pSection->oAssigned == 0
|
||||
&& pSection->Type == SECT_CODE) {
|
||||
pSection->oAssigned = 1;
|
||||
pSection->nBank = 0;
|
||||
pSection->nOrg = BankFree[0]->nOrg;
|
||||
BankFree[0]->nOrg += pSection->nByteSize;
|
||||
BankFree[0]->nSize -= pSection->nByteSize;
|
||||
}
|
||||
pSection = pSection->pNext;
|
||||
}
|
||||
|
||||
pSection = pSections;
|
||||
while (pSection) {
|
||||
if (pSection->oAssigned == 0
|
||||
&& pSection->Type == SECT_BSS) {
|
||||
pSection->oAssigned = 1;
|
||||
pSection->nBank = 0;
|
||||
pSection->nOrg = BankFree[0]->nOrg;
|
||||
BankFree[0]->nOrg += pSection->nByteSize;
|
||||
BankFree[0]->nSize -= pSection->nByteSize;
|
||||
}
|
||||
pSection = pSection->pNext;
|
||||
}
|
||||
} else
|
||||
BankFree[0] = malloc(sizeof *BankFree[0]);
|
||||
if (!BankFree[0])
|
||||
fatalerror("Out of memory!");
|
||||
|
||||
BankFree[0]->nOrg = 0x0000;
|
||||
BankFree[0]->nSize = 0x10000;
|
||||
MaxAvail[0] = 0x10000;
|
||||
BankFree[0]->pPrev = NULL;
|
||||
BankFree[0]->pNext = NULL;
|
||||
|
||||
pSection = pSections;
|
||||
while (pSection) {
|
||||
if (pSection->oAssigned == 0
|
||||
&& pSection->Type == SECT_CODE) {
|
||||
pSection->oAssigned = 1;
|
||||
pSection->nBank = 0;
|
||||
pSection->nOrg = BankFree[0]->nOrg;
|
||||
BankFree[0]->nOrg += pSection->nByteSize;
|
||||
BankFree[0]->nSize -= pSection->nByteSize;
|
||||
}
|
||||
pSection = pSection->pNext;
|
||||
}
|
||||
|
||||
pSection = pSections;
|
||||
while (pSection) {
|
||||
if (pSection->oAssigned == 0
|
||||
&& pSection->Type == SECT_BSS) {
|
||||
pSection->oAssigned = 1;
|
||||
pSection->nBank = 0;
|
||||
pSection->nOrg = BankFree[0]->nOrg;
|
||||
BankFree[0]->nOrg += pSection->nByteSize;
|
||||
BankFree[0]->nSize -= pSection->nByteSize;
|
||||
}
|
||||
pSection = pSection->pNext;
|
||||
}
|
||||
}
|
||||
|
||||
void AssignSections(void)
|
||||
|
||||
@@ -72,34 +72,39 @@ void ProcessLinkfile(char *tzLinkfile)
|
||||
FILE *pLinkfile;
|
||||
enum eBlockType CurrentBlock = BLOCK_COMMENT;
|
||||
|
||||
if (pLinkfile = fopen(tzLinkfile, "rt")) {
|
||||
while (!feof(pLinkfile)) {
|
||||
char tzLine[256];
|
||||
pLinkfile = fopen(tzLinkfile, "rt");
|
||||
if (!pLinkfile) {
|
||||
sprintf(temptext, "Unable to find linkfile '%s'\n", tzLinkfile);
|
||||
fatalerror(temptext);
|
||||
}
|
||||
|
||||
fscanf(pLinkfile, "%s\n", tzLine);
|
||||
if (tzLine[0] != '#') {
|
||||
if (tzLine[0] == '['
|
||||
&& tzLine[strlen(tzLine) - 1] == ']') {
|
||||
if (strcmpi("[objects]", tzLine) == 0)
|
||||
CurrentBlock = BLOCK_OBJECTS;
|
||||
else if (strcmpi("[output]", tzLine) ==
|
||||
0)
|
||||
CurrentBlock = BLOCK_OUTPUT;
|
||||
else if (strcmpi("[libraries]", tzLine)
|
||||
== 0)
|
||||
CurrentBlock = BLOCK_LIBRARIES;
|
||||
else if (strcmpi("[comment]", tzLine) ==
|
||||
0)
|
||||
CurrentBlock = BLOCK_COMMENT;
|
||||
else {
|
||||
fclose(pLinkfile);
|
||||
sprintf(temptext,
|
||||
while (!feof(pLinkfile)) {
|
||||
char tzLine[256];
|
||||
|
||||
fscanf(pLinkfile, "%s\n", tzLine);
|
||||
if (tzLine[0] != '#') {
|
||||
if (tzLine[0] == '['
|
||||
&& tzLine[strlen(tzLine) - 1] == ']') {
|
||||
if (strcmpi("[objects]", tzLine) == 0)
|
||||
CurrentBlock = BLOCK_OBJECTS;
|
||||
else if (strcmpi("[output]", tzLine) ==
|
||||
0)
|
||||
CurrentBlock = BLOCK_OUTPUT;
|
||||
else if (strcmpi("[libraries]", tzLine)
|
||||
== 0)
|
||||
CurrentBlock = BLOCK_LIBRARIES;
|
||||
else if (strcmpi("[comment]", tzLine) ==
|
||||
0)
|
||||
CurrentBlock = BLOCK_COMMENT;
|
||||
else {
|
||||
fclose(pLinkfile);
|
||||
sprintf(temptext,
|
||||
"Unknown block '%s'\n",
|
||||
tzLine);
|
||||
fatalerror(temptext);
|
||||
}
|
||||
} else {
|
||||
switch (CurrentBlock) {
|
||||
fatalerror(temptext);
|
||||
}
|
||||
} else {
|
||||
switch (CurrentBlock) {
|
||||
case BLOCK_COMMENT:
|
||||
break;
|
||||
case BLOCK_OBJECTS:
|
||||
@@ -111,16 +116,12 @@ void ProcessLinkfile(char *tzLinkfile)
|
||||
case BLOCK_OUTPUT:
|
||||
out_Setname(tzLine);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
fclose(pLinkfile);
|
||||
} else {
|
||||
sprintf(temptext, "Unable to find linkfile '%s'\n", tzLinkfile);
|
||||
fatalerror(temptext);
|
||||
}
|
||||
|
||||
fclose(pLinkfile);
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -179,7 +180,7 @@ int main(int argc, char *argv[])
|
||||
int result;
|
||||
|
||||
result =
|
||||
sscanf(argv[argn - 1] + 2, "%x",
|
||||
sscanf(argv[argn - 1] + 2, "%lx",
|
||||
&fillchar);
|
||||
if (!((result == EOF) || (result == 1))) {
|
||||
fatalerror
|
||||
|
||||
@@ -14,19 +14,20 @@ SLONG sfbank;
|
||||
|
||||
void SetMapfileName(char *name)
|
||||
{
|
||||
if (mf = fopen(name, "wt"))
|
||||
return;
|
||||
else
|
||||
mf = fopen(name, "wt");
|
||||
|
||||
if (!mf)
|
||||
fatalerror("Unable to open mapfile for writing");
|
||||
}
|
||||
|
||||
void SetSymfileName(char *name)
|
||||
{
|
||||
if (sf = fopen(name, "wt")) {
|
||||
fprintf(sf, ";File generated by xLink v" LINK_VERSION "\n\n");
|
||||
return;
|
||||
} else
|
||||
sf = fopen(name, "wt");
|
||||
|
||||
if (!sf)
|
||||
fatalerror("Unable to open symfile for writing");
|
||||
|
||||
fprintf(sf, ";File generated by xLink v" LINK_VERSION "\n\n");
|
||||
}
|
||||
|
||||
void CloseMapfile(void)
|
||||
@@ -48,7 +49,7 @@ void MapfileInitBank(SLONG bank)
|
||||
if (bank == 0)
|
||||
fprintf(mf, "Bank #0 (HOME):\n");
|
||||
else if (bank <= 255)
|
||||
fprintf(mf, "Bank #%d:\n", bank);
|
||||
fprintf(mf, "Bank #%ld:\n", bank);
|
||||
else if (bank == BANK_BSS)
|
||||
fprintf(mf, "BSS:\n");
|
||||
else if (bank == BANK_HRAM)
|
||||
@@ -64,40 +65,42 @@ void MapfileInitBank(SLONG bank)
|
||||
|
||||
void MapfileWriteSection(struct sSection *pSect)
|
||||
{
|
||||
if (mf || sf) {
|
||||
SLONG i;
|
||||
if (!mf && !sf)
|
||||
return;
|
||||
|
||||
fprintf(mf, " SECTION: $%04X-$%04X ($%04X bytes)\n",
|
||||
SLONG i;
|
||||
|
||||
fprintf(mf, " SECTION: $%04lX-$%04lX ($%04lX bytes)\n",
|
||||
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)) {
|
||||
if (mf) {
|
||||
fprintf(mf, " $%04X = %s\n",
|
||||
for (i = 0; i < pSect->nNumberOfSymbols; i += 1) {
|
||||
struct sSymbol *pSym;
|
||||
pSym = pSect->tSymbols[i];
|
||||
if ((pSym->pSection == pSect)
|
||||
&& (pSym->Type != SYM_IMPORT)) {
|
||||
if (mf) {
|
||||
fprintf(mf, " $%04lX = %s\n",
|
||||
pSym->nOffset + pSect->nOrg,
|
||||
pSym->pzName);
|
||||
}
|
||||
if (sf) {
|
||||
fprintf(sf, "%02X:%04X %s\n", sfbank,
|
||||
pSym->nOffset + pSect->nOrg,
|
||||
pSym->pzName);
|
||||
}
|
||||
|
||||
}
|
||||
if (sf) {
|
||||
fprintf(sf, "%02lX:%04lX %s\n", sfbank,
|
||||
pSym->nOffset + pSect->nOrg,
|
||||
pSym->pzName);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void MapfileCloseBank(SLONG slack)
|
||||
{
|
||||
if (mf) {
|
||||
if (slack == MaxAvail[currentbank])
|
||||
fprintf(mf, " EMPTY\n\n");
|
||||
else
|
||||
fprintf(mf, " SLACK: $%04X bytes\n\n", slack);
|
||||
}
|
||||
if (!mf)
|
||||
return;
|
||||
|
||||
if (slack == MaxAvail[currentbank])
|
||||
fprintf(mf, " EMPTY\n\n");
|
||||
else
|
||||
fprintf(mf, " SLACK: $%04lX bytes\n\n", slack);
|
||||
}
|
||||
|
||||
@@ -75,16 +75,17 @@ struct sSection *AllocSection(void)
|
||||
while (*ppSections)
|
||||
ppSections = &((*ppSections)->pNext);
|
||||
|
||||
if ((*ppSections) = (struct sSection *)malloc(sizeof(struct sSection))) {
|
||||
(*ppSections)->tSymbols = tSymbols;
|
||||
(*ppSections)->pNext = NULL;
|
||||
(*ppSections)->pPatches = NULL;
|
||||
(*ppSections)->oAssigned = 0;
|
||||
return (*ppSections);
|
||||
} else {
|
||||
*ppSections = malloc(sizeof **ppSections);
|
||||
if (!*ppSections) {
|
||||
fatalerror("Out of memory!");
|
||||
return (NULL);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
(*ppSections)->tSymbols = tSymbols;
|
||||
(*ppSections)->pNext = NULL;
|
||||
(*ppSections)->pPatches = NULL;
|
||||
(*ppSections)->oAssigned = 0;
|
||||
return *ppSections;
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -97,22 +98,22 @@ struct sSymbol *obj_ReadSymbol(FILE * f)
|
||||
char s[256];
|
||||
struct sSymbol *pSym;
|
||||
|
||||
if (pSym = (struct sSymbol *)malloc(sizeof(struct sSymbol))) {
|
||||
readasciiz(s, f);
|
||||
if (pSym->pzName = (char *)malloc(strlen(s) + 1)) {
|
||||
strcpy(pSym->pzName, s);
|
||||
if ((pSym->Type =
|
||||
(enum eSymbolType)fgetc(f)) != SYM_IMPORT) {
|
||||
pSym->nSectionID = readlong(f);
|
||||
pSym->nOffset = readlong(f);
|
||||
}
|
||||
return (pSym);
|
||||
} else
|
||||
fatalerror("Out of memory!");
|
||||
} else
|
||||
pSym = malloc(sizeof *pSym);
|
||||
if (!pSym)
|
||||
fatalerror("Out of memory!");
|
||||
|
||||
return (NULL);
|
||||
readasciiz(s, f);
|
||||
pSym->pzName = malloc(strlen(s) + 1);
|
||||
if (!pSym->pzName)
|
||||
fatalerror("Out of memory!");
|
||||
|
||||
strcpy(pSym->pzName, s);
|
||||
if ((pSym->Type = (enum eSymbolType)fgetc(f)) != SYM_IMPORT) {
|
||||
pSym->nSectionID = readlong(f);
|
||||
pSym->nOffset = readlong(f);
|
||||
}
|
||||
|
||||
return pSym;
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -143,82 +144,69 @@ struct sSection *obj_ReadRGB0Section(FILE * f)
|
||||
*
|
||||
*/
|
||||
if (pSection->nByteSize) {
|
||||
if (pSection->pData =
|
||||
(UBYTE *) malloc(pSection->nByteSize)) {
|
||||
SLONG nNumberOfPatches;
|
||||
struct sPatch **ppPatch, *pPatch;
|
||||
char s[256];
|
||||
|
||||
fread(pSection->pData, sizeof(UBYTE),
|
||||
pSection->nByteSize, f);
|
||||
nNumberOfPatches = readlong(f);
|
||||
ppPatch = &pSection->pPatches;
|
||||
|
||||
/*
|
||||
* And patches...
|
||||
*
|
||||
*/
|
||||
while (nNumberOfPatches--) {
|
||||
if (pPatch =
|
||||
(struct sPatch *)
|
||||
malloc(sizeof(struct sPatch))) {
|
||||
*ppPatch = pPatch;
|
||||
readasciiz(s, f);
|
||||
if (pPatch->pzFilename =
|
||||
(char *)malloc(strlen(s) +
|
||||
1)) {
|
||||
strcpy(pPatch->
|
||||
pzFilename, s);
|
||||
pPatch->nLineNo =
|
||||
readlong(f);
|
||||
pPatch->nOffset =
|
||||
readlong(f);
|
||||
pPatch->Type =
|
||||
(enum ePatchType)
|
||||
fgetc(f);
|
||||
if ((pPatch->nRPNSize =
|
||||
readlong(f)) > 0) {
|
||||
if (pPatch->
|
||||
pRPN =
|
||||
(UBYTE *)
|
||||
malloc
|
||||
(pPatch->
|
||||
nRPNSize))
|
||||
fread
|
||||
(pPatch->
|
||||
pRPN,
|
||||
sizeof
|
||||
(UBYTE),
|
||||
pPatch->
|
||||
nRPNSize,
|
||||
f);
|
||||
else
|
||||
fatalerror
|
||||
("Out of memory!");
|
||||
} else
|
||||
pPatch->pRPN =
|
||||
NULL;
|
||||
pPatch->pNext = NULL;
|
||||
ppPatch =
|
||||
&(pPatch->pNext);
|
||||
} else
|
||||
fatalerror
|
||||
("Out of memory!");
|
||||
} else
|
||||
fatalerror("Out of memory!");
|
||||
}
|
||||
} else
|
||||
pSection->pData = malloc(pSection->nByteSize);
|
||||
if (!pSection->pData)
|
||||
fatalerror("Out of memory!");
|
||||
|
||||
SLONG nNumberOfPatches;
|
||||
struct sPatch **ppPatch, *pPatch;
|
||||
char s[256];
|
||||
|
||||
fread(pSection->pData, sizeof(UBYTE),
|
||||
pSection->nByteSize, f);
|
||||
nNumberOfPatches = readlong(f);
|
||||
ppPatch = &pSection->pPatches;
|
||||
|
||||
/*
|
||||
* And patches...
|
||||
*
|
||||
*/
|
||||
while (nNumberOfPatches--) {
|
||||
pPatch = malloc(sizeof *pPatch);
|
||||
if (!pPatch)
|
||||
fatalerror("Out of memory!");
|
||||
|
||||
*ppPatch = pPatch;
|
||||
readasciiz(s, f);
|
||||
|
||||
pPatch->pzFilename = malloc(strlen(s) + 1);
|
||||
if (!pPatch->pzFilename)
|
||||
fatalerror("Out of memory!");
|
||||
|
||||
strcpy(pPatch->pzFilename, s);
|
||||
|
||||
pPatch->nLineNo =
|
||||
readlong(f);
|
||||
pPatch->nOffset =
|
||||
readlong(f);
|
||||
pPatch->Type =
|
||||
(enum ePatchType)
|
||||
fgetc(f);
|
||||
|
||||
if ((pPatch->nRPNSize = readlong(f)) > 0) {
|
||||
pPatch->pRPN = malloc(pPatch->nRPNSize);
|
||||
if (!pPatch->pRPN)
|
||||
fatalerror("Out of memory!");
|
||||
|
||||
fread(pPatch->pRPN, sizeof(UBYTE),
|
||||
pPatch->nRPNSize, f);
|
||||
} else
|
||||
pPatch->pRPN = NULL;
|
||||
|
||||
pPatch->pNext = NULL;
|
||||
ppPatch = &(pPatch->pNext);
|
||||
}
|
||||
} else {
|
||||
readlong(f); // Skip number of patches
|
||||
/* Skip number of patches */
|
||||
readlong(f);
|
||||
pSection->pData = &dummymem;
|
||||
}
|
||||
}
|
||||
|
||||
return (pSection);
|
||||
return pSection;
|
||||
}
|
||||
|
||||
void obj_ReadRGB0(FILE * pObjfile)
|
||||
void obj_ReadRGB0(FILE *pObjfile)
|
||||
{
|
||||
struct sSection *pFirstSection;
|
||||
SLONG nNumberOfSymbols, nNumberOfSections, i;
|
||||
@@ -229,13 +217,12 @@ void obj_ReadRGB0(FILE * pObjfile)
|
||||
/* First comes the symbols */
|
||||
|
||||
if (nNumberOfSymbols) {
|
||||
if (tSymbols =
|
||||
(struct sSymbol **)malloc(nNumberOfSymbols *
|
||||
sizeof(struct sSymbol *))) {
|
||||
for (i = 0; i < nNumberOfSymbols; i += 1)
|
||||
tSymbols[i] = obj_ReadSymbol(pObjfile);
|
||||
} else
|
||||
tSymbols = malloc(nNumberOfSymbols * sizeof(struct sSymbol *));
|
||||
if (!tSymbols)
|
||||
fatalerror("Out of memory!");
|
||||
|
||||
for (i = 0; i < nNumberOfSymbols; i += 1)
|
||||
tSymbols[i] = obj_ReadSymbol(pObjfile);
|
||||
} else
|
||||
tSymbols = (struct sSymbol **)&dummymem;
|
||||
|
||||
@@ -278,7 +265,7 @@ void obj_ReadRGB0(FILE * pObjfile)
|
||||
*
|
||||
*/
|
||||
|
||||
struct sSection *obj_ReadRGB1Section(FILE * f)
|
||||
struct sSection *obj_ReadRGB1Section(FILE *f)
|
||||
{
|
||||
struct sSection *pSection;
|
||||
|
||||
@@ -306,82 +293,62 @@ struct sSection *obj_ReadRGB1Section(FILE * f)
|
||||
*
|
||||
*/
|
||||
if (pSection->nByteSize) {
|
||||
if (pSection->pData =
|
||||
(UBYTE *) malloc(pSection->nByteSize)) {
|
||||
SLONG nNumberOfPatches;
|
||||
struct sPatch **ppPatch, *pPatch;
|
||||
char s[256];
|
||||
|
||||
fread(pSection->pData, sizeof(UBYTE),
|
||||
pSection->nByteSize, f);
|
||||
nNumberOfPatches = readlong(f);
|
||||
ppPatch = &pSection->pPatches;
|
||||
|
||||
/*
|
||||
* And patches...
|
||||
*
|
||||
*/
|
||||
while (nNumberOfPatches--) {
|
||||
if (pPatch =
|
||||
(struct sPatch *)
|
||||
malloc(sizeof(struct sPatch))) {
|
||||
*ppPatch = pPatch;
|
||||
readasciiz(s, f);
|
||||
if (pPatch->pzFilename =
|
||||
(char *)malloc(strlen(s) +
|
||||
1)) {
|
||||
strcpy(pPatch->
|
||||
pzFilename, s);
|
||||
pPatch->nLineNo =
|
||||
readlong(f);
|
||||
pPatch->nOffset =
|
||||
readlong(f);
|
||||
pPatch->Type =
|
||||
(enum ePatchType)
|
||||
fgetc(f);
|
||||
if ((pPatch->nRPNSize =
|
||||
readlong(f)) > 0) {
|
||||
if (pPatch->
|
||||
pRPN =
|
||||
(UBYTE *)
|
||||
malloc
|
||||
(pPatch->
|
||||
nRPNSize))
|
||||
fread
|
||||
(pPatch->
|
||||
pRPN,
|
||||
sizeof
|
||||
(UBYTE),
|
||||
pPatch->
|
||||
nRPNSize,
|
||||
f);
|
||||
else
|
||||
fatalerror
|
||||
("Out of memory!");
|
||||
} else
|
||||
pPatch->pRPN =
|
||||
NULL;
|
||||
pPatch->pNext = NULL;
|
||||
ppPatch =
|
||||
&(pPatch->pNext);
|
||||
} else
|
||||
fatalerror
|
||||
("Out of memory!");
|
||||
} else
|
||||
fatalerror("Out of memory!");
|
||||
}
|
||||
} else
|
||||
pSection->pData = malloc(pSection->nByteSize);
|
||||
if (!pSection->pData)
|
||||
fatalerror("Out of memory!");
|
||||
|
||||
SLONG nNumberOfPatches;
|
||||
struct sPatch **ppPatch, *pPatch;
|
||||
char s[256];
|
||||
|
||||
fread(pSection->pData, sizeof(UBYTE),
|
||||
pSection->nByteSize, f);
|
||||
nNumberOfPatches = readlong(f);
|
||||
ppPatch = &pSection->pPatches;
|
||||
|
||||
/*
|
||||
* And patches...
|
||||
*
|
||||
*/
|
||||
while (nNumberOfPatches--) {
|
||||
pPatch = malloc(sizeof *pPatch);
|
||||
if (!pPatch)
|
||||
fatalerror("Out of memory!");
|
||||
|
||||
*ppPatch = pPatch;
|
||||
readasciiz(s, f);
|
||||
pPatch->pzFilename = malloc(strlen(s) + 1);
|
||||
if (!pPatch->pzFilename)
|
||||
fatalerror("Out of memory!");
|
||||
|
||||
strcpy(pPatch->pzFilename, s);
|
||||
pPatch->nLineNo = readlong(f);
|
||||
pPatch->nOffset = readlong(f);
|
||||
pPatch->Type = (enum ePatchType) fgetc(f);
|
||||
if ((pPatch->nRPNSize = readlong(f)) > 0) {
|
||||
pPatch->pRPN = malloc(pPatch->nRPNSize);
|
||||
if (!pPatch->pRPN)
|
||||
fatalerror ("Out of memory!");
|
||||
|
||||
fread(pPatch->pRPN, sizeof(UBYTE),
|
||||
pPatch->nRPNSize, f);
|
||||
} else
|
||||
pPatch->pRPN = NULL;
|
||||
|
||||
pPatch->pNext = NULL;
|
||||
ppPatch = &(pPatch->pNext);
|
||||
}
|
||||
} else {
|
||||
readlong(f); // Skip number of patches
|
||||
/* Skip number of patches */
|
||||
readlong(f);
|
||||
pSection->pData = &dummymem;
|
||||
}
|
||||
}
|
||||
|
||||
return (pSection);
|
||||
return pSection;
|
||||
}
|
||||
|
||||
void obj_ReadRGB1(FILE * pObjfile)
|
||||
void obj_ReadRGB1(FILE *pObjfile)
|
||||
{
|
||||
struct sSection *pFirstSection;
|
||||
SLONG nNumberOfSymbols, nNumberOfSections, i;
|
||||
@@ -392,13 +359,12 @@ void obj_ReadRGB1(FILE * pObjfile)
|
||||
/* First comes the symbols */
|
||||
|
||||
if (nNumberOfSymbols) {
|
||||
if (tSymbols =
|
||||
(struct sSymbol **)malloc(nNumberOfSymbols *
|
||||
sizeof(struct sSymbol *))) {
|
||||
for (i = 0; i < nNumberOfSymbols; i += 1)
|
||||
tSymbols[i] = obj_ReadSymbol(pObjfile);
|
||||
} else
|
||||
tSymbols = malloc(nNumberOfSymbols * sizeof *tSymbols);
|
||||
if (!tSymbols)
|
||||
fatalerror("Out of memory!");
|
||||
|
||||
for (i = 0; i < nNumberOfSymbols; i += 1)
|
||||
tSymbols[i] = obj_ReadSymbol(pObjfile);
|
||||
} else
|
||||
tSymbols = (struct sSymbol **)&dummymem;
|
||||
|
||||
@@ -477,14 +443,15 @@ void obj_Readfile(char *tzObjectfile)
|
||||
else
|
||||
oReadLib = 0;
|
||||
|
||||
if (pObjfile = fopen(tzObjectfile, "rb")) {
|
||||
obj_ReadOpenFile(pObjfile, tzObjectfile);
|
||||
fclose(pObjfile);
|
||||
} else {
|
||||
pObjfile = fopen(tzObjectfile, "rb");
|
||||
if (!pObjfile) {
|
||||
sprintf(temptext, "Unable to open '%s'\n", tzObjectfile);
|
||||
fatalerror(temptext);
|
||||
}
|
||||
|
||||
obj_ReadOpenFile(pObjfile, tzObjectfile);
|
||||
fclose(pObjfile);
|
||||
|
||||
oReadLib = 0;
|
||||
}
|
||||
|
||||
@@ -525,21 +492,22 @@ void lib_Readfile(char *tzLibfile)
|
||||
|
||||
oReadLib = 1;
|
||||
|
||||
if (pObjfile = fopen(tzLibfile, "rb")) {
|
||||
char tzHeader[5];
|
||||
|
||||
fread(tzHeader, sizeof(char), 4, pObjfile);
|
||||
tzHeader[4] = 0;
|
||||
if (strcmp(tzHeader, "XLB0") == 0)
|
||||
lib_ReadXLB0(pObjfile);
|
||||
else {
|
||||
sprintf(temptext, "'%s' is an invalid library\n",
|
||||
tzLibfile);
|
||||
fatalerror(temptext);
|
||||
}
|
||||
fclose(pObjfile);
|
||||
} else {
|
||||
pObjfile = fopen(tzLibfile, "rb");
|
||||
if (!pObjfile) {
|
||||
sprintf(temptext, "Unable to open '%s'\n", tzLibfile);
|
||||
fatalerror(temptext);
|
||||
}
|
||||
|
||||
char tzHeader[5];
|
||||
|
||||
fread(tzHeader, sizeof(char), 4, pObjfile);
|
||||
tzHeader[4] = 0;
|
||||
if (strcmp(tzHeader, "XLB0") == 0)
|
||||
lib_ReadXLB0(pObjfile);
|
||||
else {
|
||||
sprintf(temptext, "'%s' is an invalid library\n",
|
||||
tzLibfile);
|
||||
fatalerror(temptext);
|
||||
}
|
||||
fclose(pObjfile);
|
||||
}
|
||||
|
||||
@@ -10,61 +10,65 @@
|
||||
char tzOutname[_MAX_PATH];
|
||||
BBOOL oOutput = 0;
|
||||
|
||||
void writehome(FILE * f)
|
||||
void writehome(FILE *f)
|
||||
{
|
||||
struct sSection *pSect;
|
||||
UBYTE *mem;
|
||||
|
||||
if (mem = (UBYTE *) malloc(MaxAvail[BANK_HOME])) {
|
||||
if (fillchar != -1) {
|
||||
memset(mem, fillchar, MaxAvail[BANK_HOME]);
|
||||
}
|
||||
MapfileInitBank(0);
|
||||
mem = malloc(MaxAvail[BANK_HOME]);
|
||||
if (!mem)
|
||||
return;
|
||||
|
||||
pSect = pSections;
|
||||
while (pSect) {
|
||||
if (pSect->Type == SECT_HOME) {
|
||||
memcpy(mem + pSect->nOrg, pSect->pData,
|
||||
pSect->nByteSize);
|
||||
MapfileWriteSection(pSect);
|
||||
}
|
||||
pSect = pSect->pNext;
|
||||
}
|
||||
|
||||
MapfileCloseBank(area_Avail(0));
|
||||
|
||||
fwrite(mem, 1, MaxAvail[BANK_HOME], f);
|
||||
free(mem);
|
||||
if (fillchar != -1) {
|
||||
memset(mem, fillchar, MaxAvail[BANK_HOME]);
|
||||
}
|
||||
MapfileInitBank(0);
|
||||
|
||||
pSect = pSections;
|
||||
while (pSect) {
|
||||
if (pSect->Type == SECT_HOME) {
|
||||
memcpy(mem + pSect->nOrg, pSect->pData,
|
||||
pSect->nByteSize);
|
||||
MapfileWriteSection(pSect);
|
||||
}
|
||||
pSect = pSect->pNext;
|
||||
}
|
||||
|
||||
MapfileCloseBank(area_Avail(0));
|
||||
|
||||
fwrite(mem, 1, MaxAvail[BANK_HOME], f);
|
||||
free(mem);
|
||||
}
|
||||
|
||||
void writebank(FILE * f, SLONG bank)
|
||||
void writebank(FILE *f, SLONG bank)
|
||||
{
|
||||
struct sSection *pSect;
|
||||
UBYTE *mem;
|
||||
|
||||
if (mem = (UBYTE *) malloc(MaxAvail[bank])) {
|
||||
if (fillchar != -1) {
|
||||
memset(mem, fillchar, MaxAvail[bank]);
|
||||
}
|
||||
mem = malloc(MaxAvail[bank]);
|
||||
if (!mem)
|
||||
return;
|
||||
|
||||
MapfileInitBank(bank);
|
||||
|
||||
pSect = pSections;
|
||||
while (pSect) {
|
||||
if (pSect->Type == SECT_CODE && pSect->nBank == bank) {
|
||||
memcpy(mem + pSect->nOrg - 0x4000, pSect->pData,
|
||||
pSect->nByteSize);
|
||||
MapfileWriteSection(pSect);
|
||||
}
|
||||
pSect = pSect->pNext;
|
||||
}
|
||||
|
||||
MapfileCloseBank(area_Avail(bank));
|
||||
|
||||
fwrite(mem, 1, MaxAvail[bank], f);
|
||||
free(mem);
|
||||
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);
|
||||
MapfileWriteSection(pSect);
|
||||
}
|
||||
pSect = pSect->pNext;
|
||||
}
|
||||
|
||||
MapfileCloseBank(area_Avail(bank));
|
||||
|
||||
fwrite(mem, 1, MaxAvail[bank], f);
|
||||
free(mem);
|
||||
}
|
||||
|
||||
void out_Setname(char *tzOutputfile)
|
||||
@@ -78,7 +82,7 @@ void GBROM_Output(void)
|
||||
SLONG i;
|
||||
FILE *f;
|
||||
|
||||
if (f = fopen(tzOutname, "wb")) {
|
||||
if ((f = fopen(tzOutname, "wb"))) {
|
||||
writehome(f);
|
||||
for (i = 1; i <= MaxBankUsed; i += 1)
|
||||
writebank(f, i);
|
||||
@@ -104,7 +108,7 @@ void PSION2_Output(void)
|
||||
{
|
||||
FILE *f;
|
||||
|
||||
if (f = fopen(tzOutname, "wb")) {
|
||||
if ((f = fopen(tzOutname, "wb"))) {
|
||||
struct sSection *pSect;
|
||||
UBYTE *mem;
|
||||
ULONG size = MaxAvail[0] - area_Avail(0);
|
||||
@@ -115,7 +119,7 @@ void PSION2_Output(void)
|
||||
fputc(size >> 8, f);
|
||||
fputc(size, f);
|
||||
|
||||
if (mem = (UBYTE *) malloc(MaxAvail[0] - area_Avail(0))) {
|
||||
if ((mem = malloc(MaxAvail[0] - area_Avail(0)))) {
|
||||
MapfileInitBank(0);
|
||||
|
||||
pSect = pSections;
|
||||
|
||||
@@ -154,7 +154,7 @@ SLONG calcrpn(struct sPatch * pPatch)
|
||||
rpnpush(t & 0xFF);
|
||||
if (t < 0 || (t > 0xFF && t < 0xFF00) || t > 0xFFFF) {
|
||||
sprintf(temptext,
|
||||
"%s(%d) : Value must be in the HRAM area",
|
||||
"%s(%ld) : Value must be in the HRAM area",
|
||||
pPatch->pzFilename, pPatch->nLineNo);
|
||||
fatalerror(temptext);
|
||||
}
|
||||
@@ -164,7 +164,7 @@ SLONG calcrpn(struct sPatch * pPatch)
|
||||
rpnpush(t & 0xFF);
|
||||
if (t < 0x2000 || t > 0x20FF) {
|
||||
sprintf(temptext,
|
||||
"%s(%d) : Value must be in the ZP area",
|
||||
"%s(%ld) : Value must be in the ZP area",
|
||||
pPatch->pzFilename, pPatch->nLineNo);
|
||||
fatalerror(temptext);
|
||||
}
|
||||
@@ -212,7 +212,7 @@ SLONG calcrpn(struct sPatch * pPatch)
|
||||
t = rpnpop();
|
||||
if (t < low || t > high) {
|
||||
sprintf(temptext,
|
||||
"%s(%d) : Value must be in the range [%d;%d]",
|
||||
"%s(%ld) : Value must be in the range [%ld;%ld]",
|
||||
pPatch->pzFilename,
|
||||
pPatch->nLineNo, low, high);
|
||||
fatalerror(temptext);
|
||||
@@ -249,7 +249,7 @@ void Patch(void)
|
||||
(UBYTE) t;
|
||||
} else {
|
||||
sprintf(temptext,
|
||||
"%s(%d) : Value must be 8-bit\n",
|
||||
"%s(%ld) : Value must be 8-bit\n",
|
||||
pPatch->pzFilename,
|
||||
pPatch->nLineNo);
|
||||
fatalerror(temptext);
|
||||
@@ -274,7 +274,7 @@ void Patch(void)
|
||||
}
|
||||
} else {
|
||||
sprintf(temptext,
|
||||
"%s(%d) : Value must be 16-bit\n",
|
||||
"%s(%ld) : Value must be 16-bit\n",
|
||||
pPatch->pzFilename,
|
||||
pPatch->nLineNo);
|
||||
fatalerror(temptext);
|
||||
|
||||
@@ -74,34 +74,33 @@ SLONG sym_GetBank(char *tzName)
|
||||
|
||||
void sym_CreateSymbol(char *tzName, SLONG nValue, SBYTE nBank)
|
||||
{
|
||||
if (strcmp(tzName, "@") == 0) {
|
||||
} else {
|
||||
struct ISymbol **ppSym;
|
||||
if (strcmp(tzName, "@") == 0)
|
||||
return;
|
||||
|
||||
ppSym = &(tHash[calchash(tzName)]);
|
||||
struct ISymbol **ppSym;
|
||||
|
||||
while (*ppSym) {
|
||||
if (strcmp(tzName, (*ppSym)->pzName)) {
|
||||
ppSym = &((*ppSym)->pNext);
|
||||
} else {
|
||||
if (nBank == -1)
|
||||
return;
|
||||
ppSym = &(tHash[calchash(tzName)]);
|
||||
|
||||
sprintf(temptext,
|
||||
while (*ppSym) {
|
||||
if (strcmp(tzName, (*ppSym)->pzName)) {
|
||||
ppSym = &((*ppSym)->pNext);
|
||||
} else {
|
||||
if (nBank == -1)
|
||||
return;
|
||||
|
||||
sprintf(temptext,
|
||||
"Symbol '%s' defined more than once\n",
|
||||
tzName);
|
||||
fatalerror(temptext);
|
||||
}
|
||||
fatalerror(temptext);
|
||||
}
|
||||
}
|
||||
|
||||
if (*ppSym = (struct ISymbol *)malloc(sizeof(struct ISymbol))) {
|
||||
if ((*ppSym)->pzName =
|
||||
(char *)malloc(strlen(tzName) + 1)) {
|
||||
strcpy((*ppSym)->pzName, tzName);
|
||||
(*ppSym)->nValue = nValue;
|
||||
(*ppSym)->nBank = nBank;
|
||||
(*ppSym)->pNext = NULL;
|
||||
}
|
||||
if ((*ppSym = malloc(sizeof **ppSym))) {
|
||||
if (((*ppSym)->pzName = malloc(strlen(tzName) + 1))) {
|
||||
strcpy((*ppSym)->pzName, tzName);
|
||||
(*ppSym)->nValue = nValue;
|
||||
(*ppSym)->nBank = nBank;
|
||||
(*ppSym)->pNext = NULL;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user