Fixed warnings and some style issues

Signed-off-by: Vegard Nossum <vegard.nossum@gmail.com>
This commit is contained in:
Vegard Nossum
2009-06-11 08:51:55 +02:00
parent b6c749ffbd
commit 3c82b1ae03
12 changed files with 569 additions and 589 deletions

View File

@@ -4,85 +4,85 @@
#include "asmy.h" #include "asmy.h"
struct sLexInitString localstrings[] = { struct sLexInitString localstrings[] = {
"adc", T_Z80_ADC, { "adc", T_Z80_ADC },
"add", T_Z80_ADD, { "add", T_Z80_ADD },
"and", T_Z80_AND, { "and", T_Z80_AND },
"bit", T_Z80_BIT, { "bit", T_Z80_BIT },
"call", T_Z80_CALL, { "call", T_Z80_CALL },
"ccf", T_Z80_CCF, { "ccf", T_Z80_CCF },
"cpl", T_Z80_CPL, { "cpl", T_Z80_CPL },
"cp", T_Z80_CP, { "cp", T_Z80_CP },
"daa", T_Z80_DAA, { "daa", T_Z80_DAA },
"dec", T_Z80_DEC, { "dec", T_Z80_DEC },
"di", T_Z80_DI, { "di", T_Z80_DI },
"ei", T_Z80_EI, { "ei", T_Z80_EI },
"ex", T_Z80_EX, { "ex", T_Z80_EX },
"halt", T_Z80_HALT, { "halt", T_Z80_HALT },
"inc", T_Z80_INC, { "inc", T_Z80_INC },
"jp", T_Z80_JP, { "jp", T_Z80_JP },
"jr", T_Z80_JR, { "jr", T_Z80_JR },
"ld", T_Z80_LD, { "ld", T_Z80_LD },
"ldi", T_Z80_LDI, { "ldi", T_Z80_LDI },
"ldd", T_Z80_LDD, { "ldd", T_Z80_LDD },
"ldio", T_Z80_LDIO, { "ldio", T_Z80_LDIO },
"ldh", T_Z80_LDIO, { "ldh", T_Z80_LDIO },
"nop", T_Z80_NOP, { "nop", T_Z80_NOP },
"or", T_Z80_OR, { "or", T_Z80_OR },
"pop", T_Z80_POP, { "pop", T_Z80_POP },
"push", T_Z80_PUSH, { "push", T_Z80_PUSH },
"res", T_Z80_RES, { "res", T_Z80_RES },
"reti", T_Z80_RETI, { "reti", T_Z80_RETI },
"ret", T_Z80_RET, { "ret", T_Z80_RET },
"rlca", T_Z80_RLCA, { "rlca", T_Z80_RLCA },
"rlc", T_Z80_RLC, { "rlc", T_Z80_RLC },
"rla", T_Z80_RLA, { "rla", T_Z80_RLA },
"rl", T_Z80_RL, { "rl", T_Z80_RL },
"rrc", T_Z80_RRC, { "rrc", T_Z80_RRC },
"rrca", T_Z80_RRCA, { "rrca", T_Z80_RRCA },
"rra", T_Z80_RRA, { "rra", T_Z80_RRA },
"rr", T_Z80_RR, { "rr", T_Z80_RR },
"rst", T_Z80_RST, { "rst", T_Z80_RST },
"sbc", T_Z80_SBC, { "sbc", T_Z80_SBC },
"scf", T_Z80_SCF, { "scf", T_Z80_SCF },
// Handled by globallex.c /* Handled by globallex.c */
// "set" , T_POP_SET, /* { "set", T_POP_SET }, */
"sla", T_Z80_SLA, { "sla", T_Z80_SLA },
"sra", T_Z80_SRA, { "sra", T_Z80_SRA },
"srl", T_Z80_SRL, { "srl", T_Z80_SRL },
"stop", T_Z80_STOP, { "stop", T_Z80_STOP },
"sub", T_Z80_SUB, { "sub", T_Z80_SUB },
"swap", T_Z80_SWAP, { "swap", T_Z80_SWAP },
"xor", T_Z80_XOR, { "xor", T_Z80_XOR },
"nz", T_CC_NZ, { "nz", T_CC_NZ },
"z", T_CC_Z, { "z", T_CC_Z },
"nc", T_CC_NC, { "nc", T_CC_NC },
// "c" , T_MODE_C /* { "c", T_MODE_C }, */
"[hl]", T_MODE_HL_IND, { "[hl]", T_MODE_HL_IND },
"[hl+]", T_MODE_HL_INDINC, { "[hl+]", T_MODE_HL_INDINC },
"[hl-]", T_MODE_HL_INDDEC, { "[hl-]", T_MODE_HL_INDDEC },
"[hli]", T_MODE_HL_INDINC, { "[hli]", T_MODE_HL_INDINC },
"[hld]", T_MODE_HL_INDDEC, { "[hld]", T_MODE_HL_INDDEC },
"hl", T_MODE_HL, { "hl", T_MODE_HL },
"af", T_MODE_AF, { "af", T_MODE_AF },
"[bc]", T_MODE_BC_IND, { "[bc]", T_MODE_BC_IND },
"bc", T_MODE_BC, { "bc", T_MODE_BC },
"[de]", T_MODE_DE_IND, { "[de]", T_MODE_DE_IND },
"de", T_MODE_DE, { "de", T_MODE_DE },
"[sp]", T_MODE_SP_IND, { "[sp]", T_MODE_SP_IND },
"sp", T_MODE_SP, { "sp", T_MODE_SP },
"a", T_MODE_A, { "a", T_MODE_A },
"b", T_MODE_B, { "b", T_MODE_B },
"[$ff00+c]", T_MODE_C_IND, { "[$ff00+c]", T_MODE_C_IND },
"[c]", T_MODE_C_IND, { "[c]", T_MODE_C_IND },
"c", T_MODE_C, { "c", T_MODE_C },
"d", T_MODE_D, { "d", T_MODE_D },
"e", T_MODE_E, { "e", T_MODE_E },
"h", T_MODE_H, { "h", T_MODE_H },
"l", T_MODE_L, { "l", T_MODE_L },
NULL, 0 { NULL, 0 }
}; };

View File

@@ -223,116 +223,119 @@ enum {
extern struct sLexInitString localstrings[]; extern struct sLexInitString localstrings[];
struct sLexInitString staticstrings[] = { struct sLexInitString staticstrings[] = {
"||", T_OP_LOGICOR, { "||", T_OP_LOGICOR },
"&&", T_OP_LOGICAND, { "&&", T_OP_LOGICAND },
"==", T_OP_LOGICEQU, { "==", T_OP_LOGICEQU },
">", T_OP_LOGICGT, { ">", T_OP_LOGICGT },
"<", T_OP_LOGICLT, { "<", T_OP_LOGICLT },
">=", T_OP_LOGICGE, { ">=", T_OP_LOGICGE },
"<=", T_OP_LOGICLE, { "<=", T_OP_LOGICLE },
"!=", T_OP_LOGICNE, { "!=", T_OP_LOGICNE },
"!", T_OP_LOGICNOT, { "!", T_OP_LOGICNOT },
"|", T_OP_OR, { "|", T_OP_OR },
"^", T_OP_XOR, { "^", T_OP_XOR },
"&", T_OP_AND, { "&", T_OP_AND },
"<<", T_OP_SHL, { "<<", T_OP_SHL },
">>", T_OP_SHR, { ">>", T_OP_SHR },
"+", T_OP_ADD, { "+", T_OP_ADD },
"-", T_OP_SUB, { "-", T_OP_SUB },
"*", T_OP_MUL, { "*", T_OP_MUL },
"/", T_OP_DIV, { "/", T_OP_DIV },
"%", T_OP_MOD, { "%", T_OP_MOD },
"~", T_OP_NOT, { "~", T_OP_NOT },
"def", T_OP_DEF, { "def", T_OP_DEF },
"bank", T_OP_BANK, { "bank", T_OP_BANK },
"div", T_OP_FDIV, { "div", T_OP_FDIV },
"mul", T_OP_FMUL, { "mul", T_OP_FMUL },
"sin", T_OP_SIN, { "sin", T_OP_SIN },
"cos", T_OP_COS, { "cos", T_OP_COS },
"tan", T_OP_TAN, { "tan", T_OP_TAN },
"asin", T_OP_ASIN, { "asin", T_OP_ASIN },
"acos", T_OP_ACOS, { "acos", T_OP_ACOS },
"atan", T_OP_ATAN, { "atan", T_OP_ATAN },
"atan2", T_OP_ATAN2, { "atan2", T_OP_ATAN2 },
"strcmp", T_OP_STRCMP, { "strcmp", T_OP_STRCMP },
"strin", T_OP_STRIN, { "strin", T_OP_STRIN },
"strsub", T_OP_STRSUB, { "strsub", T_OP_STRSUB },
"strlen", T_OP_STRLEN, { "strlen", T_OP_STRLEN },
"strcat", T_OP_STRCAT, { "strcat", T_OP_STRCAT },
"strupr", T_OP_STRUPR, { "strupr", T_OP_STRUPR },
"strlwr", T_OP_STRLWR, { "strlwr", T_OP_STRLWR },
"include", T_POP_INCLUDE, { "include", T_POP_INCLUDE },
"printt", T_POP_PRINTT, { "printt", T_POP_PRINTT },
"printv", T_POP_PRINTV, { "printv", T_POP_PRINTV },
"printf", T_POP_PRINTF, { "printf", T_POP_PRINTF },
"export", T_POP_EXPORT, { "export", T_POP_EXPORT },
"xdef", T_POP_EXPORT, { "xdef", T_POP_EXPORT },
"import", T_POP_IMPORT, { "import", T_POP_IMPORT },
"xref", T_POP_IMPORT, { "xref", T_POP_IMPORT },
"global", T_POP_GLOBAL, { "global", T_POP_GLOBAL },
"ds", T_POP_DS, { "ds", T_POP_DS },
NAME_DB, T_POP_DB, { NAME_DB, T_POP_DB },
NAME_DW, T_POP_DW, { NAME_DW, T_POP_DW },
#ifdef NAME_DL #ifdef NAME_DL
NAME_DL, T_POP_DL, { NAME_DL, T_POP_DL },
#endif #endif
"section", T_POP_SECTION, { "section", T_POP_SECTION },
"purge", T_POP_PURGE, { "purge", T_POP_PURGE },
"rsreset", T_POP_RSRESET, { "rsreset", T_POP_RSRESET },
"rsset", T_POP_RSSET, { "rsset", T_POP_RSSET },
"incbin", T_POP_INCBIN, { "incbin", T_POP_INCBIN },
"fail", T_POP_FAIL, { "fail", T_POP_FAIL },
"warn", T_POP_WARN, { "warn", T_POP_WARN },
"macro", T_POP_MACRO, { "macro", T_POP_MACRO },
"endm", T_POP_ENDM, // Not needed but we have it here just to protect the name
"shift", T_POP_SHIFT,
"rept", T_POP_REPT, /* Not needed but we have it here just to protect the name */
"endr", T_POP_ENDR, // Not needed but we have it here just to protect the name { "endm", T_POP_ENDM },
{ "shift", T_POP_SHIFT },
"if", T_POP_IF, { "rept", T_POP_REPT },
"else", T_POP_ELSE, /* Not needed but we have it here just to protect the name */
"endc", T_POP_ENDC, { "endr", T_POP_ENDR },
"bss", T_SECT_BSS, { "if", T_POP_IF },
{ "else", T_POP_ELSE },
{ "endc", T_POP_ENDC },
{ "bss", T_SECT_BSS },
#if defined(GAMEBOY) || defined(PCENGINE) #if defined(GAMEBOY) || defined(PCENGINE)
"vram", T_SECT_VRAM, { "vram", T_SECT_VRAM },
#endif #endif
"code", T_SECT_CODE, { "code", T_SECT_CODE },
"data", T_SECT_CODE, { "data", T_SECT_CODE },
#ifdef GAMEBOY #ifdef GAMEBOY
"home", T_SECT_HOME, { "home", T_SECT_HOME },
"hram", T_SECT_HRAM, { "hram", T_SECT_HRAM },
#endif #endif
NAME_RB, T_POP_RB, { NAME_RB, T_POP_RB },
NAME_RW, T_POP_RW, { NAME_RW, T_POP_RW },
#ifdef NAME_RL #ifdef NAME_RL
NAME_RL, T_POP_RL, { NAME_RL, T_POP_RL },
#endif #endif
"equ", T_POP_EQU, { "equ", T_POP_EQU },
"equs", T_POP_EQUS, { "equs", T_POP_EQUS },
"set", T_POP_SET, { "set", T_POP_SET },
"=", T_POP_SET, { "=", T_POP_SET },
"pushs", T_POP_PUSHS, { "pushs", T_POP_PUSHS },
"pops", T_POP_POPS, { "pops", T_POP_POPS },
"pusho", T_POP_PUSHO, { "pusho", T_POP_PUSHO },
"popo", T_POP_POPO, { "popo", T_POP_POPO },
"opt", T_POP_OPT, { "opt", T_POP_OPT },
NULL, 0 { NULL, 0 }
}; };
struct sLexFloat tNumberToken = { struct sLexFloat tNumberToken = {

View File

@@ -354,14 +354,14 @@ ULONG yylex(void)
s = pLexBuffer; s = pLexBuffer;
nOldFloatMask = nFloatLen = 0; nOldFloatMask = nFloatLen = 0;
nFloatMask = tFloatingFirstChar[*s++]; nFloatMask = tFloatingFirstChar[(int) *s++];
while (nFloatMask && nFloatLen < nLexBufferLeng) { while (nFloatMask && nFloatLen < nLexBufferLeng) {
nFloatLen += 1; nFloatLen += 1;
nOldFloatMask = nFloatMask; nOldFloatMask = nFloatMask;
if (nFloatLen == 1) if (nFloatLen == 1)
nFloatMask &= tFloatingSecondChar[*s++]; nFloatMask &= tFloatingSecondChar[(int) *s++];
else else
nFloatMask &= tFloatingChars[*s++]; nFloatMask &= tFloatingChars[(int) *s++];
} }
maxlen = nLexBufferLeng; maxlen = nLexBufferLeng;

View File

@@ -79,17 +79,16 @@ sLibrary *lib_ReadLib0(FILE * f, SLONG size)
while (size > 0) { while (size > 0) {
if (l == NULL) { if (l == NULL) {
if ((l = l = malloc(sizeof *l);
(sLibrary *) malloc(sizeof(sLibrary))) == if (!l)
NULL)
fatalerror("Out of memory"); fatalerror("Out of memory");
first = l; first = l;
} else { } else {
if ((l->pNext = l->pNext = malloc(sizeof *l->pNext);
(sLibrary *) malloc(sizeof(sLibrary))) == if (!l->pNext)
NULL)
fatalerror("Out of memory"); fatalerror("Out of memory");
l = l->pNext; l = l->pNext;
} }
@@ -100,7 +99,7 @@ sLibrary *lib_ReadLib0(FILE * f, SLONG size)
size -= 2; size -= 2;
l->nByteLength = file_ReadLong(f); l->nByteLength = file_ReadLong(f);
size -= 4; size -= 4;
if (l->pData = (UBYTE *) malloc(l->nByteLength)) { if ((l->pData = malloc(l->nByteLength))) {
fread(l->pData, sizeof(UBYTE), l->nByteLength, fread(l->pData, sizeof(UBYTE), l->nByteLength,
f); f);
size -= l->nByteLength; size -= l->nByteLength;
@@ -119,7 +118,7 @@ sLibrary *lib_Read(char *filename)
{ {
FILE *f; FILE *f;
if (f = fopen(filename, "rb")) { if ((f = fopen(filename, "rb"))) {
SLONG size; SLONG size;
char ID[5]; char ID[5];
@@ -157,7 +156,7 @@ BBOOL lib_Write(sLibrary * lib, char *filename)
{ {
FILE *f; FILE *f;
if (f = fopen(filename, "wb")) { if ((f = fopen(filename, "wb"))) {
fwrite("XLB0", sizeof(char), 4, f); fwrite("XLB0", sizeof(char), 4, f);
while (lib) { while (lib) {
file_WriteASCIIz(lib->tName, f); file_WriteASCIIz(lib->tName, f);
@@ -207,18 +206,19 @@ sLibrary *lib_AddReplace(sLibrary * lib, char *filename)
{ {
FILE *f; FILE *f;
if (f = fopen(filename, "rb")) { if ((f = fopen(filename, "rb"))) {
sLibrary *module; sLibrary *module;
char truncname[MAXNAMELENGTH]; char truncname[MAXNAMELENGTH];
TruncateFileName(truncname, filename); TruncateFileName(truncname, filename);
if ((module = lib_Find(lib, filename)) == NULL) { if ((module = lib_Find(lib, filename)) == NULL) {
if (module = (sLibrary *) malloc(sizeof(sLibrary))) { module = malloc(sizeof *module);
if (!module)
fatalerror("Out of memory");
module->pNext = lib; module->pNext = lib;
lib = module; lib = module;
} else
fatalerror("Out of memory");
} else { } else {
/* Module already exists */ /* Module already exists */
free(module->pData); free(module->pData);
@@ -226,10 +226,11 @@ sLibrary *lib_AddReplace(sLibrary * lib, char *filename)
module->nByteLength = file_Length(f); module->nByteLength = file_Length(f);
strcpy(module->tName, truncname); strcpy(module->tName, truncname);
if (module->pData = (UBYTE *) malloc(module->nByteLength)) { module->pData = malloc(module->nByteLength);
fread(module->pData, sizeof(UBYTE), module->nByteLength, if (!module->pData)
f); fatalerror("Out of memory");
}
fread(module->pData, sizeof(UBYTE), module->nByteLength, f);
printf("Added module '%s'\n", truncname); printf("Added module '%s'\n", truncname);

View File

@@ -88,7 +88,7 @@ int main(int argc, char *argv[])
l = lib; l = lib;
while (l) { while (l) {
printf("%10d %s\n", printf("%10ld %s\n",
l->nByteLength, l->nByteLength,
l->tName); l->tName);
l = l->pNext; l = l->pNext;
@@ -103,7 +103,7 @@ int main(int argc, char *argv[])
if (l) { if (l) {
FILE *f; FILE *f;
if (f = fopen(argv[argn], "wb")) { if ((f = fopen(argv[argn], "wb"))) {
fwrite(l->pData, fwrite(l->pData,
sizeof(UBYTE), sizeof(UBYTE),
l->nByteLength, l->nByteLength,

View File

@@ -147,7 +147,7 @@ void AssignCodeSections(void)
{ {
struct sSection *pSection; struct sSection *pSection;
while (pSection = FindLargestCode()) { while ((pSection = FindLargestCode())) {
SLONG org; SLONG org;
if ((org = area_AllocCODEAnyBank(pSection->nByteSize)) != -1) { if ((org = area_AllocCODEAnyBank(pSection->nByteSize)) != -1) {
@@ -173,8 +173,11 @@ void GBROM_AssignSections(void)
*/ */
for (i = 0; i < MAXBANKS; i += 1) { for (i = 0; i < MAXBANKS; i += 1) {
if (BankFree[i] = BankFree[i] = malloc(sizeof *BankFree[i]);
(struct sFreeArea *)malloc(sizeof(struct sFreeArea))) {
if (!BankFree[i])
fatalerror("Out of memory!");
if (i == 0) { if (i == 0) {
BankFree[i]->nOrg = 0x0000; BankFree[i]->nOrg = 0x0000;
if (options & OPT_SMALL) { if (options & OPT_SMALL) {
@@ -187,9 +190,8 @@ void GBROM_AssignSections(void)
} else if (i >= 1 && i <= 255) { } else if (i >= 1 && i <= 255) {
BankFree[i]->nOrg = 0x4000; BankFree[i]->nOrg = 0x4000;
/* /*
* Now, this shouldn't really be necessary... but for good * Now, this shouldn't really be necessary... but for
* measure we'll do it anyway * good measure we'll do it anyway.
*
*/ */
if (options & OPT_SMALL) { if (options & OPT_SMALL) {
BankFree[i]->nSize = 0; BankFree[i]->nSize = 0;
@@ -213,8 +215,6 @@ void GBROM_AssignSections(void)
} }
BankFree[i]->pPrev = NULL; BankFree[i]->pPrev = NULL;
BankFree[i]->pNext = NULL; BankFree[i]->pNext = NULL;
} else
fatalerror("Out of memory!");
} }
/* /*
@@ -235,7 +235,7 @@ void GBROM_AssignSections(void)
(&BankFree[BANK_BSS], pSection->nOrg, (&BankFree[BANK_BSS], pSection->nOrg,
pSection->nByteSize) != pSection->nOrg) { pSection->nByteSize) != pSection->nOrg) {
sprintf(temptext, sprintf(temptext,
"Unable to load fixed BSS section at $%X", "Unable to load fixed BSS section at $%lX",
pSection->nOrg); pSection->nOrg);
fatalerror(temptext); fatalerror(temptext);
} }
@@ -247,7 +247,7 @@ void GBROM_AssignSections(void)
(&BankFree[BANK_HRAM], pSection->nOrg, (&BankFree[BANK_HRAM], pSection->nOrg,
pSection->nByteSize) != pSection->nOrg) { pSection->nByteSize) != pSection->nOrg) {
sprintf(temptext, sprintf(temptext,
"Unable to load fixed HRAM section at $%X", "Unable to load fixed HRAM section at $%lX",
pSection->nOrg); pSection->nOrg);
fatalerror(temptext); fatalerror(temptext);
} }
@@ -259,7 +259,7 @@ void GBROM_AssignSections(void)
(&BankFree[BANK_VRAM], pSection->nOrg, (&BankFree[BANK_VRAM], pSection->nOrg,
pSection->nByteSize) != pSection->nOrg) { pSection->nByteSize) != pSection->nOrg) {
sprintf(temptext, sprintf(temptext,
"Unable to load fixed VRAM section at $%X", "Unable to load fixed VRAM section at $%lX",
pSection->nOrg); pSection->nOrg);
fatalerror(temptext); fatalerror(temptext);
} }
@@ -271,7 +271,7 @@ void GBROM_AssignSections(void)
(&BankFree[BANK_HOME], pSection->nOrg, (&BankFree[BANK_HOME], pSection->nOrg,
pSection->nByteSize) != pSection->nOrg) { pSection->nByteSize) != pSection->nOrg) {
sprintf(temptext, sprintf(temptext,
"Unable to load fixed HOME section at $%X", "Unable to load fixed HOME section at $%lX",
pSection->nOrg); pSection->nOrg);
fatalerror(temptext); fatalerror(temptext);
} }
@@ -320,7 +320,7 @@ void GBROM_AssignSections(void)
pSection->nOrg) { pSection->nOrg) {
sprintf sprintf
(temptext, (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-> pSection->
nOrg, nOrg,
pSection-> pSection->
@@ -333,7 +333,7 @@ void GBROM_AssignSections(void)
pSection->oAssigned = 1; pSection->oAssigned = 1;
} else { } else {
sprintf(temptext, 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->nOrg,
pSection-> pSection->
nBank); nBank);
@@ -364,7 +364,7 @@ void GBROM_AssignSections(void)
area_Alloc(&BankFree[pSection->nBank], area_Alloc(&BankFree[pSection->nBank],
pSection->nByteSize)) == -1) { pSection->nByteSize)) == -1) {
sprintf(temptext, sprintf(temptext,
"Unable to load fixed CODE/DATA section into bank $%02X", "Unable to load fixed CODE/DATA section into bank $%02lX",
pSection->nBank); pSection->nBank);
fatalerror(temptext); fatalerror(temptext);
} }
@@ -372,7 +372,7 @@ void GBROM_AssignSections(void)
DOMAXBANK(pSection->nBank); DOMAXBANK(pSection->nBank);
} else { } else {
sprintf(temptext, sprintf(temptext,
"Unable to load fixed CODE/DATA section into bank $%02X", "Unable to load fixed CODE/DATA section into bank $%02lX",
pSection->nBank); pSection->nBank);
fatalerror(temptext); fatalerror(temptext);
} }
@@ -396,7 +396,7 @@ void GBROM_AssignSections(void)
pSection->nByteSize)) == pSection->nByteSize)) ==
-1) { -1) {
sprintf(temptext, 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); pSection->nOrg);
fatalerror(temptext); fatalerror(temptext);
} }
@@ -469,7 +469,10 @@ void PSION2_AssignSections(void)
{ {
struct sSection *pSection; struct sSection *pSection;
if (BankFree[0] = (struct sFreeArea *)malloc(sizeof(struct sFreeArea))) { BankFree[0] = malloc(sizeof *BankFree[0]);
if (!BankFree[0])
fatalerror("Out of memory!");
BankFree[0]->nOrg = 0x0000; BankFree[0]->nOrg = 0x0000;
BankFree[0]->nSize = 0x10000; BankFree[0]->nSize = 0x10000;
MaxAvail[0] = 0x10000; MaxAvail[0] = 0x10000;
@@ -501,8 +504,6 @@ void PSION2_AssignSections(void)
} }
pSection = pSection->pNext; pSection = pSection->pNext;
} }
} else
fatalerror("Out of memory!");
} }
void AssignSections(void) void AssignSections(void)

View File

@@ -72,7 +72,12 @@ void ProcessLinkfile(char *tzLinkfile)
FILE *pLinkfile; FILE *pLinkfile;
enum eBlockType CurrentBlock = BLOCK_COMMENT; enum eBlockType CurrentBlock = BLOCK_COMMENT;
if (pLinkfile = fopen(tzLinkfile, "rt")) { pLinkfile = fopen(tzLinkfile, "rt");
if (!pLinkfile) {
sprintf(temptext, "Unable to find linkfile '%s'\n", tzLinkfile);
fatalerror(temptext);
}
while (!feof(pLinkfile)) { while (!feof(pLinkfile)) {
char tzLine[256]; char tzLine[256];
@@ -115,12 +120,8 @@ void ProcessLinkfile(char *tzLinkfile)
} }
} }
} }
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; int result;
result = result =
sscanf(argv[argn - 1] + 2, "%x", sscanf(argv[argn - 1] + 2, "%lx",
&fillchar); &fillchar);
if (!((result == EOF) || (result == 1))) { if (!((result == EOF) || (result == 1))) {
fatalerror fatalerror

View File

@@ -14,19 +14,20 @@ SLONG sfbank;
void SetMapfileName(char *name) void SetMapfileName(char *name)
{ {
if (mf = fopen(name, "wt")) mf = fopen(name, "wt");
return;
else if (!mf)
fatalerror("Unable to open mapfile for writing"); fatalerror("Unable to open mapfile for writing");
} }
void SetSymfileName(char *name) void SetSymfileName(char *name)
{ {
if (sf = fopen(name, "wt")) { sf = fopen(name, "wt");
fprintf(sf, ";File generated by xLink v" LINK_VERSION "\n\n");
return; if (!sf)
} else
fatalerror("Unable to open symfile for writing"); fatalerror("Unable to open symfile for writing");
fprintf(sf, ";File generated by xLink v" LINK_VERSION "\n\n");
} }
void CloseMapfile(void) void CloseMapfile(void)
@@ -48,7 +49,7 @@ void MapfileInitBank(SLONG bank)
if (bank == 0) if (bank == 0)
fprintf(mf, "Bank #0 (HOME):\n"); fprintf(mf, "Bank #0 (HOME):\n");
else if (bank <= 255) else if (bank <= 255)
fprintf(mf, "Bank #%d:\n", bank); fprintf(mf, "Bank #%ld:\n", bank);
else if (bank == BANK_BSS) else if (bank == BANK_BSS)
fprintf(mf, "BSS:\n"); fprintf(mf, "BSS:\n");
else if (bank == BANK_HRAM) else if (bank == BANK_HRAM)
@@ -64,10 +65,12 @@ void MapfileInitBank(SLONG bank)
void MapfileWriteSection(struct sSection *pSect) void MapfileWriteSection(struct sSection *pSect)
{ {
if (mf || sf) { if (!mf && !sf)
return;
SLONG i; SLONG i;
fprintf(mf, " SECTION: $%04X-$%04X ($%04X bytes)\n", fprintf(mf, " SECTION: $%04lX-$%04lX ($%04lX bytes)\n",
pSect->nOrg, pSect->nOrg + pSect->nByteSize - 1, pSect->nOrg, pSect->nOrg + pSect->nByteSize - 1,
pSect->nByteSize); pSect->nByteSize);
@@ -77,12 +80,12 @@ void MapfileWriteSection(struct sSection *pSect)
if ((pSym->pSection == pSect) if ((pSym->pSection == pSect)
&& (pSym->Type != SYM_IMPORT)) { && (pSym->Type != SYM_IMPORT)) {
if (mf) { if (mf) {
fprintf(mf, " $%04X = %s\n", fprintf(mf, " $%04lX = %s\n",
pSym->nOffset + pSect->nOrg, pSym->nOffset + pSect->nOrg,
pSym->pzName); pSym->pzName);
} }
if (sf) { if (sf) {
fprintf(sf, "%02X:%04X %s\n", sfbank, fprintf(sf, "%02lX:%04lX %s\n", sfbank,
pSym->nOffset + pSect->nOrg, pSym->nOffset + pSect->nOrg,
pSym->pzName); pSym->pzName);
} }
@@ -90,14 +93,14 @@ void MapfileWriteSection(struct sSection *pSect)
} }
} }
} }
}
void MapfileCloseBank(SLONG slack) void MapfileCloseBank(SLONG slack)
{ {
if (mf) { if (!mf)
return;
if (slack == MaxAvail[currentbank]) if (slack == MaxAvail[currentbank])
fprintf(mf, " EMPTY\n\n"); fprintf(mf, " EMPTY\n\n");
else else
fprintf(mf, " SLACK: $%04X bytes\n\n", slack); fprintf(mf, " SLACK: $%04lX bytes\n\n", slack);
}
} }

View File

@@ -75,16 +75,17 @@ struct sSection *AllocSection(void)
while (*ppSections) while (*ppSections)
ppSections = &((*ppSections)->pNext); ppSections = &((*ppSections)->pNext);
if ((*ppSections) = (struct sSection *)malloc(sizeof(struct sSection))) { *ppSections = malloc(sizeof **ppSections);
if (!*ppSections) {
fatalerror("Out of memory!");
return NULL;
}
(*ppSections)->tSymbols = tSymbols; (*ppSections)->tSymbols = tSymbols;
(*ppSections)->pNext = NULL; (*ppSections)->pNext = NULL;
(*ppSections)->pPatches = NULL; (*ppSections)->pPatches = NULL;
(*ppSections)->oAssigned = 0; (*ppSections)->oAssigned = 0;
return (*ppSections); return *ppSections;
} else {
fatalerror("Out of memory!");
return (NULL);
}
} }
/* /*
@@ -97,22 +98,22 @@ struct sSymbol *obj_ReadSymbol(FILE * f)
char s[256]; char s[256];
struct sSymbol *pSym; struct sSymbol *pSym;
if (pSym = (struct sSymbol *)malloc(sizeof(struct sSymbol))) { pSym = malloc(sizeof *pSym);
if (!pSym)
fatalerror("Out of memory!");
readasciiz(s, f); readasciiz(s, f);
if (pSym->pzName = (char *)malloc(strlen(s) + 1)) { pSym->pzName = malloc(strlen(s) + 1);
if (!pSym->pzName)
fatalerror("Out of memory!");
strcpy(pSym->pzName, s); strcpy(pSym->pzName, s);
if ((pSym->Type = if ((pSym->Type = (enum eSymbolType)fgetc(f)) != SYM_IMPORT) {
(enum eSymbolType)fgetc(f)) != SYM_IMPORT) {
pSym->nSectionID = readlong(f); pSym->nSectionID = readlong(f);
pSym->nOffset = readlong(f); pSym->nOffset = readlong(f);
} }
return (pSym);
} else
fatalerror("Out of memory!");
} else
fatalerror("Out of memory!");
return (NULL); return pSym;
} }
/* /*
@@ -143,8 +144,10 @@ struct sSection *obj_ReadRGB0Section(FILE * f)
* *
*/ */
if (pSection->nByteSize) { if (pSection->nByteSize) {
if (pSection->pData = pSection->pData = malloc(pSection->nByteSize);
(UBYTE *) malloc(pSection->nByteSize)) { if (!pSection->pData)
fatalerror("Out of memory!");
SLONG nNumberOfPatches; SLONG nNumberOfPatches;
struct sPatch **ppPatch, *pPatch; struct sPatch **ppPatch, *pPatch;
char s[256]; char s[256];
@@ -159,16 +162,19 @@ struct sSection *obj_ReadRGB0Section(FILE * f)
* *
*/ */
while (nNumberOfPatches--) { while (nNumberOfPatches--) {
if (pPatch = pPatch = malloc(sizeof *pPatch);
(struct sPatch *) if (!pPatch)
malloc(sizeof(struct sPatch))) { fatalerror("Out of memory!");
*ppPatch = pPatch; *ppPatch = pPatch;
readasciiz(s, f); readasciiz(s, f);
if (pPatch->pzFilename =
(char *)malloc(strlen(s) + pPatch->pzFilename = malloc(strlen(s) + 1);
1)) { if (!pPatch->pzFilename)
strcpy(pPatch-> fatalerror("Out of memory!");
pzFilename, s);
strcpy(pPatch->pzFilename, s);
pPatch->nLineNo = pPatch->nLineNo =
readlong(f); readlong(f);
pPatch->nOffset = pPatch->nOffset =
@@ -176,46 +182,28 @@ struct sSection *obj_ReadRGB0Section(FILE * f)
pPatch->Type = pPatch->Type =
(enum ePatchType) (enum ePatchType)
fgetc(f); fgetc(f);
if ((pPatch->nRPNSize =
readlong(f)) > 0) { if ((pPatch->nRPNSize = readlong(f)) > 0) {
if (pPatch-> pPatch->pRPN = malloc(pPatch->nRPNSize);
pRPN = if (!pPatch->pRPN)
(UBYTE *) fatalerror("Out of memory!");
malloc
(pPatch-> fread(pPatch->pRPN, sizeof(UBYTE),
nRPNSize)) pPatch->nRPNSize, f);
fread
(pPatch->
pRPN,
sizeof
(UBYTE),
pPatch->
nRPNSize,
f);
else
fatalerror
("Out of memory!");
} else } else
pPatch->pRPN = pPatch->pRPN = NULL;
NULL;
pPatch->pNext = NULL; pPatch->pNext = NULL;
ppPatch = ppPatch = &(pPatch->pNext);
&(pPatch->pNext);
} else
fatalerror
("Out of memory!");
} else
fatalerror("Out of memory!");
} }
} else
fatalerror("Out of memory!");
} else { } else {
readlong(f); // Skip number of patches /* Skip number of patches */
readlong(f);
pSection->pData = &dummymem; pSection->pData = &dummymem;
} }
} }
return (pSection); return pSection;
} }
void obj_ReadRGB0(FILE *pObjfile) void obj_ReadRGB0(FILE *pObjfile)
@@ -229,13 +217,12 @@ void obj_ReadRGB0(FILE * pObjfile)
/* First comes the symbols */ /* First comes the symbols */
if (nNumberOfSymbols) { if (nNumberOfSymbols) {
if (tSymbols = tSymbols = malloc(nNumberOfSymbols * sizeof(struct sSymbol *));
(struct sSymbol **)malloc(nNumberOfSymbols * if (!tSymbols)
sizeof(struct sSymbol *))) { fatalerror("Out of memory!");
for (i = 0; i < nNumberOfSymbols; i += 1) for (i = 0; i < nNumberOfSymbols; i += 1)
tSymbols[i] = obj_ReadSymbol(pObjfile); tSymbols[i] = obj_ReadSymbol(pObjfile);
} else
fatalerror("Out of memory!");
} else } else
tSymbols = (struct sSymbol **)&dummymem; tSymbols = (struct sSymbol **)&dummymem;
@@ -306,8 +293,10 @@ struct sSection *obj_ReadRGB1Section(FILE * f)
* *
*/ */
if (pSection->nByteSize) { if (pSection->nByteSize) {
if (pSection->pData = pSection->pData = malloc(pSection->nByteSize);
(UBYTE *) malloc(pSection->nByteSize)) { if (!pSection->pData)
fatalerror("Out of memory!");
SLONG nNumberOfPatches; SLONG nNumberOfPatches;
struct sPatch **ppPatch, *pPatch; struct sPatch **ppPatch, *pPatch;
char s[256]; char s[256];
@@ -322,63 +311,41 @@ struct sSection *obj_ReadRGB1Section(FILE * f)
* *
*/ */
while (nNumberOfPatches--) { while (nNumberOfPatches--) {
if (pPatch = pPatch = malloc(sizeof *pPatch);
(struct sPatch *) if (!pPatch)
malloc(sizeof(struct sPatch))) { fatalerror("Out of memory!");
*ppPatch = pPatch; *ppPatch = pPatch;
readasciiz(s, f); readasciiz(s, f);
if (pPatch->pzFilename = pPatch->pzFilename = malloc(strlen(s) + 1);
(char *)malloc(strlen(s) + if (!pPatch->pzFilename)
1)) { fatalerror("Out of memory!");
strcpy(pPatch->
pzFilename, s); strcpy(pPatch->pzFilename, s);
pPatch->nLineNo = pPatch->nLineNo = readlong(f);
readlong(f); pPatch->nOffset = readlong(f);
pPatch->nOffset = pPatch->Type = (enum ePatchType) fgetc(f);
readlong(f); if ((pPatch->nRPNSize = readlong(f)) > 0) {
pPatch->Type = pPatch->pRPN = malloc(pPatch->nRPNSize);
(enum ePatchType) if (!pPatch->pRPN)
fgetc(f); fatalerror ("Out of memory!");
if ((pPatch->nRPNSize =
readlong(f)) > 0) { fread(pPatch->pRPN, sizeof(UBYTE),
if (pPatch-> pPatch->nRPNSize, f);
pRPN =
(UBYTE *)
malloc
(pPatch->
nRPNSize))
fread
(pPatch->
pRPN,
sizeof
(UBYTE),
pPatch->
nRPNSize,
f);
else
fatalerror
("Out of memory!");
} else } else
pPatch->pRPN = pPatch->pRPN = NULL;
NULL;
pPatch->pNext = NULL; pPatch->pNext = NULL;
ppPatch = ppPatch = &(pPatch->pNext);
&(pPatch->pNext);
} else
fatalerror
("Out of memory!");
} else
fatalerror("Out of memory!");
} }
} else
fatalerror("Out of memory!");
} else { } else {
readlong(f); // Skip number of patches /* Skip number of patches */
readlong(f);
pSection->pData = &dummymem; pSection->pData = &dummymem;
} }
} }
return (pSection); return pSection;
} }
void obj_ReadRGB1(FILE *pObjfile) void obj_ReadRGB1(FILE *pObjfile)
@@ -392,13 +359,12 @@ void obj_ReadRGB1(FILE * pObjfile)
/* First comes the symbols */ /* First comes the symbols */
if (nNumberOfSymbols) { if (nNumberOfSymbols) {
if (tSymbols = tSymbols = malloc(nNumberOfSymbols * sizeof *tSymbols);
(struct sSymbol **)malloc(nNumberOfSymbols * if (!tSymbols)
sizeof(struct sSymbol *))) { fatalerror("Out of memory!");
for (i = 0; i < nNumberOfSymbols; i += 1) for (i = 0; i < nNumberOfSymbols; i += 1)
tSymbols[i] = obj_ReadSymbol(pObjfile); tSymbols[i] = obj_ReadSymbol(pObjfile);
} else
fatalerror("Out of memory!");
} else } else
tSymbols = (struct sSymbol **)&dummymem; tSymbols = (struct sSymbol **)&dummymem;
@@ -477,14 +443,15 @@ void obj_Readfile(char *tzObjectfile)
else else
oReadLib = 0; oReadLib = 0;
if (pObjfile = fopen(tzObjectfile, "rb")) { pObjfile = fopen(tzObjectfile, "rb");
obj_ReadOpenFile(pObjfile, tzObjectfile); if (!pObjfile) {
fclose(pObjfile);
} else {
sprintf(temptext, "Unable to open '%s'\n", tzObjectfile); sprintf(temptext, "Unable to open '%s'\n", tzObjectfile);
fatalerror(temptext); fatalerror(temptext);
} }
obj_ReadOpenFile(pObjfile, tzObjectfile);
fclose(pObjfile);
oReadLib = 0; oReadLib = 0;
} }
@@ -525,7 +492,12 @@ void lib_Readfile(char *tzLibfile)
oReadLib = 1; oReadLib = 1;
if (pObjfile = fopen(tzLibfile, "rb")) { pObjfile = fopen(tzLibfile, "rb");
if (!pObjfile) {
sprintf(temptext, "Unable to open '%s'\n", tzLibfile);
fatalerror(temptext);
}
char tzHeader[5]; char tzHeader[5];
fread(tzHeader, sizeof(char), 4, pObjfile); fread(tzHeader, sizeof(char), 4, pObjfile);
@@ -538,8 +510,4 @@ void lib_Readfile(char *tzLibfile)
fatalerror(temptext); fatalerror(temptext);
} }
fclose(pObjfile); fclose(pObjfile);
} else {
sprintf(temptext, "Unable to open '%s'\n", tzLibfile);
fatalerror(temptext);
}
} }

View File

@@ -15,7 +15,10 @@ void writehome(FILE * f)
struct sSection *pSect; struct sSection *pSect;
UBYTE *mem; UBYTE *mem;
if (mem = (UBYTE *) malloc(MaxAvail[BANK_HOME])) { mem = malloc(MaxAvail[BANK_HOME]);
if (!mem)
return;
if (fillchar != -1) { if (fillchar != -1) {
memset(mem, fillchar, MaxAvail[BANK_HOME]); memset(mem, fillchar, MaxAvail[BANK_HOME]);
} }
@@ -36,14 +39,16 @@ void writehome(FILE * f)
fwrite(mem, 1, MaxAvail[BANK_HOME], f); fwrite(mem, 1, MaxAvail[BANK_HOME], f);
free(mem); free(mem);
} }
}
void writebank(FILE *f, SLONG bank) void writebank(FILE *f, SLONG bank)
{ {
struct sSection *pSect; struct sSection *pSect;
UBYTE *mem; UBYTE *mem;
if (mem = (UBYTE *) malloc(MaxAvail[bank])) { mem = malloc(MaxAvail[bank]);
if (!mem)
return;
if (fillchar != -1) { if (fillchar != -1) {
memset(mem, fillchar, MaxAvail[bank]); memset(mem, fillchar, MaxAvail[bank]);
} }
@@ -65,7 +70,6 @@ void writebank(FILE * f, SLONG bank)
fwrite(mem, 1, MaxAvail[bank], f); fwrite(mem, 1, MaxAvail[bank], f);
free(mem); free(mem);
} }
}
void out_Setname(char *tzOutputfile) void out_Setname(char *tzOutputfile)
{ {
@@ -78,7 +82,7 @@ void GBROM_Output(void)
SLONG i; SLONG i;
FILE *f; FILE *f;
if (f = fopen(tzOutname, "wb")) { if ((f = fopen(tzOutname, "wb"))) {
writehome(f); writehome(f);
for (i = 1; i <= MaxBankUsed; i += 1) for (i = 1; i <= MaxBankUsed; i += 1)
writebank(f, i); writebank(f, i);
@@ -104,7 +108,7 @@ void PSION2_Output(void)
{ {
FILE *f; FILE *f;
if (f = fopen(tzOutname, "wb")) { if ((f = fopen(tzOutname, "wb"))) {
struct sSection *pSect; struct sSection *pSect;
UBYTE *mem; UBYTE *mem;
ULONG size = MaxAvail[0] - area_Avail(0); ULONG size = MaxAvail[0] - area_Avail(0);
@@ -115,7 +119,7 @@ void PSION2_Output(void)
fputc(size >> 8, f); fputc(size >> 8, f);
fputc(size, f); fputc(size, f);
if (mem = (UBYTE *) malloc(MaxAvail[0] - area_Avail(0))) { if ((mem = malloc(MaxAvail[0] - area_Avail(0)))) {
MapfileInitBank(0); MapfileInitBank(0);
pSect = pSections; pSect = pSections;

View File

@@ -154,7 +154,7 @@ SLONG calcrpn(struct sPatch * pPatch)
rpnpush(t & 0xFF); rpnpush(t & 0xFF);
if (t < 0 || (t > 0xFF && t < 0xFF00) || t > 0xFFFF) { if (t < 0 || (t > 0xFF && t < 0xFF00) || t > 0xFFFF) {
sprintf(temptext, sprintf(temptext,
"%s(%d) : Value must be in the HRAM area", "%s(%ld) : Value must be in the HRAM area",
pPatch->pzFilename, pPatch->nLineNo); pPatch->pzFilename, pPatch->nLineNo);
fatalerror(temptext); fatalerror(temptext);
} }
@@ -164,7 +164,7 @@ SLONG calcrpn(struct sPatch * pPatch)
rpnpush(t & 0xFF); rpnpush(t & 0xFF);
if (t < 0x2000 || t > 0x20FF) { if (t < 0x2000 || t > 0x20FF) {
sprintf(temptext, sprintf(temptext,
"%s(%d) : Value must be in the ZP area", "%s(%ld) : Value must be in the ZP area",
pPatch->pzFilename, pPatch->nLineNo); pPatch->pzFilename, pPatch->nLineNo);
fatalerror(temptext); fatalerror(temptext);
} }
@@ -212,7 +212,7 @@ SLONG calcrpn(struct sPatch * pPatch)
t = rpnpop(); t = rpnpop();
if (t < low || t > high) { if (t < low || t > high) {
sprintf(temptext, 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->pzFilename,
pPatch->nLineNo, low, high); pPatch->nLineNo, low, high);
fatalerror(temptext); fatalerror(temptext);
@@ -249,7 +249,7 @@ void Patch(void)
(UBYTE) t; (UBYTE) t;
} else { } else {
sprintf(temptext, sprintf(temptext,
"%s(%d) : Value must be 8-bit\n", "%s(%ld) : Value must be 8-bit\n",
pPatch->pzFilename, pPatch->pzFilename,
pPatch->nLineNo); pPatch->nLineNo);
fatalerror(temptext); fatalerror(temptext);
@@ -274,7 +274,7 @@ void Patch(void)
} }
} else { } else {
sprintf(temptext, sprintf(temptext,
"%s(%d) : Value must be 16-bit\n", "%s(%ld) : Value must be 16-bit\n",
pPatch->pzFilename, pPatch->pzFilename,
pPatch->nLineNo); pPatch->nLineNo);
fatalerror(temptext); fatalerror(temptext);

View File

@@ -74,8 +74,9 @@ SLONG sym_GetBank(char *tzName)
void sym_CreateSymbol(char *tzName, SLONG nValue, SBYTE nBank) void sym_CreateSymbol(char *tzName, SLONG nValue, SBYTE nBank)
{ {
if (strcmp(tzName, "@") == 0) { if (strcmp(tzName, "@") == 0)
} else { return;
struct ISymbol **ppSym; struct ISymbol **ppSym;
ppSym = &(tHash[calchash(tzName)]); ppSym = &(tHash[calchash(tzName)]);
@@ -94,9 +95,8 @@ void sym_CreateSymbol(char *tzName, SLONG nValue, SBYTE nBank)
} }
} }
if (*ppSym = (struct ISymbol *)malloc(sizeof(struct ISymbol))) { if ((*ppSym = malloc(sizeof **ppSym))) {
if ((*ppSym)->pzName = if (((*ppSym)->pzName = malloc(strlen(tzName) + 1))) {
(char *)malloc(strlen(tzName) + 1)) {
strcpy((*ppSym)->pzName, tzName); strcpy((*ppSym)->pzName, tzName);
(*ppSym)->nValue = nValue; (*ppSym)->nValue = nValue;
(*ppSym)->nBank = nBank; (*ppSym)->nBank = nBank;
@@ -104,4 +104,3 @@ void sym_CreateSymbol(char *tzName, SLONG nValue, SBYTE nBank)
} }
} }
} }
}