ref: 3c82b1ae0399849835acfb5ade31dae6299ec559
parent: b6c749ffbd30138de7beef13fb9265372a461a96
author: Vegard Nossum <vegard.nossum@gmail.com>
date: Thu Jun 11 04:51:55 EDT 2009
Fixed warnings and some style issues Signed-off-by: Vegard Nossum <vegard.nossum@gmail.com>
--- a/src/asm/gameboy/locallex.c
+++ b/src/asm/gameboy/locallex.c
@@ -4,85 +4,85 @@
#include "asmy.h"
struct sLexInitString localstrings[] = {- "adc", T_Z80_ADC,
- "add", T_Z80_ADD,
- "and", T_Z80_AND,
- "bit", T_Z80_BIT,
- "call", T_Z80_CALL,
- "ccf", T_Z80_CCF,
- "cpl", T_Z80_CPL,
- "cp", T_Z80_CP,
- "daa", T_Z80_DAA,
- "dec", T_Z80_DEC,
- "di", T_Z80_DI,
- "ei", T_Z80_EI,
- "ex", T_Z80_EX,
- "halt", T_Z80_HALT,
- "inc", T_Z80_INC,
- "jp", T_Z80_JP,
- "jr", T_Z80_JR,
- "ld", T_Z80_LD,
- "ldi", T_Z80_LDI,
- "ldd", T_Z80_LDD,
- "ldio", T_Z80_LDIO,
- "ldh", T_Z80_LDIO,
- "nop", T_Z80_NOP,
- "or", T_Z80_OR,
- "pop", T_Z80_POP,
- "push", T_Z80_PUSH,
- "res", T_Z80_RES,
- "reti", T_Z80_RETI,
- "ret", T_Z80_RET,
- "rlca", T_Z80_RLCA,
- "rlc", T_Z80_RLC,
- "rla", T_Z80_RLA,
- "rl", T_Z80_RL,
- "rrc", T_Z80_RRC,
- "rrca", T_Z80_RRCA,
- "rra", T_Z80_RRA,
- "rr", T_Z80_RR,
- "rst", T_Z80_RST,
- "sbc", T_Z80_SBC,
- "scf", T_Z80_SCF,
+ { "adc", T_Z80_ADC },+ { "add", T_Z80_ADD },+ { "and", T_Z80_AND },+ { "bit", T_Z80_BIT },+ { "call", T_Z80_CALL },+ { "ccf", T_Z80_CCF },+ { "cpl", T_Z80_CPL },+ { "cp", T_Z80_CP },+ { "daa", T_Z80_DAA },+ { "dec", T_Z80_DEC },+ { "di", T_Z80_DI },+ { "ei", T_Z80_EI },+ { "ex", T_Z80_EX },+ { "halt", T_Z80_HALT },+ { "inc", T_Z80_INC },+ { "jp", T_Z80_JP },+ { "jr", T_Z80_JR },+ { "ld", T_Z80_LD },+ { "ldi", T_Z80_LDI },+ { "ldd", T_Z80_LDD },+ { "ldio", T_Z80_LDIO },+ { "ldh", T_Z80_LDIO },+ { "nop", T_Z80_NOP },+ { "or", T_Z80_OR },+ { "pop", T_Z80_POP },+ { "push", T_Z80_PUSH },+ { "res", T_Z80_RES },+ { "reti", T_Z80_RETI },+ { "ret", T_Z80_RET },+ { "rlca", T_Z80_RLCA },+ { "rlc", T_Z80_RLC },+ { "rla", T_Z80_RLA },+ { "rl", T_Z80_RL },+ { "rrc", T_Z80_RRC },+ { "rrca", T_Z80_RRCA },+ { "rra", T_Z80_RRA },+ { "rr", T_Z80_RR },+ { "rst", T_Z80_RST },+ { "sbc", T_Z80_SBC },+ { "scf", T_Z80_SCF },-// Handled by globallex.c
-// "set" , T_POP_SET,
+ /* Handled by globallex.c */
+ /* { "set", T_POP_SET }, */- "sla", T_Z80_SLA,
- "sra", T_Z80_SRA,
- "srl", T_Z80_SRL,
- "stop", T_Z80_STOP,
- "sub", T_Z80_SUB,
- "swap", T_Z80_SWAP,
- "xor", T_Z80_XOR,
+ { "sla", T_Z80_SLA },+ { "sra", T_Z80_SRA },+ { "srl", T_Z80_SRL },+ { "stop", T_Z80_STOP },+ { "sub", T_Z80_SUB },+ { "swap", T_Z80_SWAP },+ { "xor", T_Z80_XOR },- "nz", T_CC_NZ,
- "z", T_CC_Z,
- "nc", T_CC_NC,
-// "c" , T_MODE_C
+ { "nz", T_CC_NZ },+ { "z", T_CC_Z },+ { "nc", T_CC_NC },+ /* { "c", T_MODE_C }, */- "[hl]", T_MODE_HL_IND,
- "[hl+]", T_MODE_HL_INDINC,
- "[hl-]", T_MODE_HL_INDDEC,
- "[hli]", T_MODE_HL_INDINC,
- "[hld]", T_MODE_HL_INDDEC,
- "hl", T_MODE_HL,
- "af", T_MODE_AF,
- "[bc]", T_MODE_BC_IND,
- "bc", T_MODE_BC,
- "[de]", T_MODE_DE_IND,
- "de", T_MODE_DE,
- "[sp]", T_MODE_SP_IND,
- "sp", T_MODE_SP,
- "a", T_MODE_A,
- "b", T_MODE_B,
- "[$ff00+c]", T_MODE_C_IND,
- "[c]", T_MODE_C_IND,
- "c", T_MODE_C,
- "d", T_MODE_D,
- "e", T_MODE_E,
- "h", T_MODE_H,
- "l", T_MODE_L,
+ { "[hl]", T_MODE_HL_IND },+ { "[hl+]", T_MODE_HL_INDINC },+ { "[hl-]", T_MODE_HL_INDDEC },+ { "[hli]", T_MODE_HL_INDINC },+ { "[hld]", T_MODE_HL_INDDEC },+ { "hl", T_MODE_HL },+ { "af", T_MODE_AF },+ { "[bc]", T_MODE_BC_IND },+ { "bc", T_MODE_BC },+ { "[de]", T_MODE_DE_IND },+ { "de", T_MODE_DE },+ { "[sp]", T_MODE_SP_IND },+ { "sp", T_MODE_SP },+ { "a", T_MODE_A },+ { "b", T_MODE_B },+ { "[$ff00+c]", T_MODE_C_IND },+ { "[c]", T_MODE_C_IND },+ { "c", T_MODE_C },+ { "d", T_MODE_D },+ { "e", T_MODE_E },+ { "h", T_MODE_H },+ { "l", T_MODE_L },- NULL, 0
+ { NULL, 0 }};
--- a/src/asm/globlex.c
+++ b/src/asm/globlex.c
@@ -223,116 +223,119 @@
extern struct sLexInitString localstrings[];
struct sLexInitString staticstrings[] = {- "||", T_OP_LOGICOR,
- "&&", T_OP_LOGICAND,
- "==", T_OP_LOGICEQU,
- ">", T_OP_LOGICGT,
- "<", T_OP_LOGICLT,
- ">=", T_OP_LOGICGE,
- "<=", T_OP_LOGICLE,
- "!=", T_OP_LOGICNE,
- "!", T_OP_LOGICNOT,
- "|", T_OP_OR,
- "^", T_OP_XOR,
- "&", T_OP_AND,
- "<<", T_OP_SHL,
- ">>", T_OP_SHR,
- "+", T_OP_ADD,
- "-", T_OP_SUB,
- "*", T_OP_MUL,
- "/", T_OP_DIV,
- "%", T_OP_MOD,
- "~", T_OP_NOT,
+ { "||", T_OP_LOGICOR },+ { "&&", T_OP_LOGICAND },+ { "==", T_OP_LOGICEQU },+ { ">", T_OP_LOGICGT },+ { "<", T_OP_LOGICLT },+ { ">=", T_OP_LOGICGE },+ { "<=", T_OP_LOGICLE },+ { "!=", T_OP_LOGICNE },+ { "!", T_OP_LOGICNOT },+ { "|", T_OP_OR },+ { "^", T_OP_XOR },+ { "&", T_OP_AND },+ { "<<", T_OP_SHL },+ { ">>", T_OP_SHR },+ { "+", T_OP_ADD },+ { "-", T_OP_SUB },+ { "*", T_OP_MUL },+ { "/", T_OP_DIV },+ { "%", T_OP_MOD },+ { "~", T_OP_NOT },- "def", T_OP_DEF,
+ { "def", T_OP_DEF },- "bank", T_OP_BANK,
+ { "bank", T_OP_BANK },- "div", T_OP_FDIV,
- "mul", T_OP_FMUL,
- "sin", T_OP_SIN,
- "cos", T_OP_COS,
- "tan", T_OP_TAN,
- "asin", T_OP_ASIN,
- "acos", T_OP_ACOS,
- "atan", T_OP_ATAN,
- "atan2", T_OP_ATAN2,
+ { "div", T_OP_FDIV },+ { "mul", T_OP_FMUL },+ { "sin", T_OP_SIN },+ { "cos", T_OP_COS },+ { "tan", T_OP_TAN },+ { "asin", T_OP_ASIN },+ { "acos", T_OP_ACOS },+ { "atan", T_OP_ATAN },+ { "atan2", T_OP_ATAN2 },- "strcmp", T_OP_STRCMP,
- "strin", T_OP_STRIN,
- "strsub", T_OP_STRSUB,
- "strlen", T_OP_STRLEN,
- "strcat", T_OP_STRCAT,
- "strupr", T_OP_STRUPR,
- "strlwr", T_OP_STRLWR,
+ { "strcmp", T_OP_STRCMP },+ { "strin", T_OP_STRIN },+ { "strsub", T_OP_STRSUB },+ { "strlen", T_OP_STRLEN },+ { "strcat", T_OP_STRCAT },+ { "strupr", T_OP_STRUPR },+ { "strlwr", T_OP_STRLWR },- "include", T_POP_INCLUDE,
- "printt", T_POP_PRINTT,
- "printv", T_POP_PRINTV,
- "printf", T_POP_PRINTF,
- "export", T_POP_EXPORT,
- "xdef", T_POP_EXPORT,
- "import", T_POP_IMPORT,
- "xref", T_POP_IMPORT,
- "global", T_POP_GLOBAL,
- "ds", T_POP_DS,
- NAME_DB, T_POP_DB,
- NAME_DW, T_POP_DW,
+ { "include", T_POP_INCLUDE },+ { "printt", T_POP_PRINTT },+ { "printv", T_POP_PRINTV },+ { "printf", T_POP_PRINTF },+ { "export", T_POP_EXPORT },+ { "xdef", T_POP_EXPORT },+ { "import", T_POP_IMPORT },+ { "xref", T_POP_IMPORT },+ { "global", T_POP_GLOBAL },+ { "ds", T_POP_DS },+ { NAME_DB, T_POP_DB },+ { NAME_DW, T_POP_DW },#ifdef NAME_DL
- NAME_DL, T_POP_DL,
+ { NAME_DL, T_POP_DL },#endif
- "section", T_POP_SECTION,
- "purge", T_POP_PURGE,
+ { "section", T_POP_SECTION },+ { "purge", T_POP_PURGE },- "rsreset", T_POP_RSRESET,
- "rsset", T_POP_RSSET,
+ { "rsreset", T_POP_RSRESET },+ { "rsset", T_POP_RSSET },- "incbin", T_POP_INCBIN,
+ { "incbin", T_POP_INCBIN },- "fail", T_POP_FAIL,
- "warn", T_POP_WARN,
+ { "fail", T_POP_FAIL },+ { "warn", T_POP_WARN },- "macro", T_POP_MACRO,
- "endm", T_POP_ENDM, // Not needed but we have it here just to protect the name
- "shift", T_POP_SHIFT,
+ { "macro", T_POP_MACRO },- "rept", T_POP_REPT,
- "endr", T_POP_ENDR, // Not needed but we have it here just to protect the name
+ /* Not needed but we have it here just to protect the name */
+ { "endm", T_POP_ENDM },+ { "shift", T_POP_SHIFT },- "if", T_POP_IF,
- "else", T_POP_ELSE,
- "endc", T_POP_ENDC,
+ { "rept", T_POP_REPT },+ /* Not needed but we have it here just to protect the name */
+ { "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)
- "vram", T_SECT_VRAM,
+ { "vram", T_SECT_VRAM },#endif
- "code", T_SECT_CODE,
- "data", T_SECT_CODE,
+ { "code", T_SECT_CODE },+ { "data", T_SECT_CODE },#ifdef GAMEBOY
- "home", T_SECT_HOME,
- "hram", T_SECT_HRAM,
+ { "home", T_SECT_HOME },+ { "hram", T_SECT_HRAM },#endif
- NAME_RB, T_POP_RB,
- NAME_RW, T_POP_RW,
+ { NAME_RB, T_POP_RB },+ { NAME_RW, T_POP_RW },#ifdef NAME_RL
- NAME_RL, T_POP_RL,
+ { NAME_RL, T_POP_RL },#endif
- "equ", T_POP_EQU,
- "equs", T_POP_EQUS,
+ { "equ", T_POP_EQU },+ { "equs", T_POP_EQUS },- "set", T_POP_SET,
- "=", T_POP_SET,
+ { "set", T_POP_SET },+ { "=", T_POP_SET },- "pushs", T_POP_PUSHS,
- "pops", T_POP_POPS,
- "pusho", T_POP_PUSHO,
- "popo", T_POP_POPO,
+ { "pushs", T_POP_PUSHS },+ { "pops", T_POP_POPS },+ { "pusho", T_POP_PUSHO },+ { "popo", T_POP_POPO },- "opt", T_POP_OPT,
+ { "opt", T_POP_OPT },- NULL, 0
+ { NULL, 0 }};
struct sLexFloat tNumberToken = {--- a/src/asm/lexer.c
+++ b/src/asm/lexer.c
@@ -354,14 +354,14 @@
s = pLexBuffer;
nOldFloatMask = nFloatLen = 0;
- nFloatMask = tFloatingFirstChar[*s++];
+ nFloatMask = tFloatingFirstChar[(int) *s++];
while (nFloatMask && nFloatLen < nLexBufferLeng) {nFloatLen += 1;
nOldFloatMask = nFloatMask;
if (nFloatLen == 1)
- nFloatMask &= tFloatingSecondChar[*s++];
+ nFloatMask &= tFloatingSecondChar[(int) *s++];
else
- nFloatMask &= tFloatingChars[*s++];
+ nFloatMask &= tFloatingChars[(int) *s++];
}
maxlen = nLexBufferLeng;
--- a/src/lib/library.c
+++ b/src/lib/library.c
@@ -79,17 +79,16 @@
while (size > 0) { if (l == NULL) {- if ((l =
- (sLibrary *) malloc(sizeof(sLibrary))) ==
- NULL)
+ l = malloc(sizeof *l);
+ if (!l)
fatalerror("Out of memory");first = l;
} else {- if ((l->pNext =
- (sLibrary *) malloc(sizeof(sLibrary))) ==
- NULL)
+ l->pNext = malloc(sizeof *l->pNext);
+ if (!l->pNext)
fatalerror("Out of memory");+
l = l->pNext;
}
@@ -100,7 +99,7 @@
size -= 2;
l->nByteLength = file_ReadLong(f);
size -= 4;
- if (l->pData = (UBYTE *) malloc(l->nByteLength)) {+ if ((l->pData = malloc(l->nByteLength))) {fread(l->pData, sizeof(UBYTE), l->nByteLength,
f);
size -= l->nByteLength;
@@ -119,7 +118,7 @@
{FILE *f;
- if (f = fopen(filename, "rb")) {+ if ((f = fopen(filename, "rb"))) {SLONG size;
char ID[5];
@@ -157,7 +156,7 @@
{FILE *f;
- if (f = fopen(filename, "wb")) {+ if ((f = fopen(filename, "wb"))) { fwrite("XLB0", sizeof(char), 4, f); while (lib) {file_WriteASCIIz(lib->tName, f);
@@ -207,7 +206,7 @@
{FILE *f;
- if (f = fopen(filename, "rb")) {+ if ((f = fopen(filename, "rb"))) {sLibrary *module;
char truncname[MAXNAMELENGTH];
@@ -214,11 +213,12 @@
TruncateFileName(truncname, filename);
if ((module = lib_Find(lib, filename)) == NULL) {- if (module = (sLibrary *) malloc(sizeof(sLibrary))) {- module->pNext = lib;
- lib = module;
- } else
+ module = malloc(sizeof *module);
+ if (!module)
fatalerror("Out of memory");+
+ module->pNext = lib;
+ lib = module;
} else {/* Module already exists */
free(module->pData);
@@ -226,10 +226,11 @@
module->nByteLength = file_Length(f);
strcpy(module->tName, truncname);
- if (module->pData = (UBYTE *) malloc(module->nByteLength)) {- fread(module->pData, sizeof(UBYTE), module->nByteLength,
- f);
- }
+ module->pData = malloc(module->nByteLength);
+ if (!module->pData)
+ fatalerror("Out of memory");+
+ fread(module->pData, sizeof(UBYTE), module->nByteLength, f);
printf("Added module '%s'\n", truncname);--- a/src/lib/main.c
+++ b/src/lib/main.c
@@ -88,7 +88,7 @@
l = lib;
while (l) {- printf("%10d %s\n",+ printf("%10ld %s\n",l->nByteLength,
l->tName);
l = l->pNext;
@@ -103,7 +103,7 @@
if (l) {FILE *f;
- if (f = fopen(argv[argn], "wb")) {+ if ((f = fopen(argv[argn], "wb"))) {fwrite(l->pData,
sizeof(UBYTE),
l->nByteLength,
--- a/src/link/assign.c
+++ b/src/link/assign.c
@@ -147,7 +147,7 @@
{struct sSection *pSection;
- while (pSection = FindLargestCode()) {+ while ((pSection = FindLargestCode())) {SLONG org;
if ((org = area_AllocCODEAnyBank(pSection->nByteSize)) != -1) {@@ -173,48 +173,48 @@
*/
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 @@
(&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 @@
(&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 @@
(&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 @@
(&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 @@
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 @@
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 @@
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 @@
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 @@
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 @@
{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;
+ BankFree[0] = malloc(sizeof *BankFree[0]);
+ if (!BankFree[0])
+ fatalerror("Out of memory!");- 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;
+ 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;
+ 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;
}
- } else
- fatalerror("Out of memory!");+ pSection = pSection->pNext;
+ }
}
void AssignSections(void)
--- a/src/link/main.c
+++ b/src/link/main.c
@@ -72,34 +72,39 @@
FILE *pLinkfile;
enum eBlockType CurrentBlock = BLOCK_COMMENT;
- if (pLinkfile = fopen(tzLinkfile, "rt")) {- 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,
+ pLinkfile = fopen(tzLinkfile, "rt");
+ if (!pLinkfile) {+ 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] == ']') {+ 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 @@
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 result;
result =
- sscanf(argv[argn - 1] + 2, "%x",
+ sscanf(argv[argn - 1] + 2, "%lx",
&fillchar);
if (!((result == EOF) || (result == 1))) {fatalerror
--- a/src/link/mapfile.c
+++ b/src/link/mapfile.c
@@ -14,19 +14,20 @@
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 @@
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,30 +65,31 @@
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,
+ }
+ if (sf) {+ fprintf(sf, "%02lX:%04lX %s\n", sfbank,
pSym->nOffset + pSect->nOrg,
pSym->pzName);
- }
-
}
+
}
}
}
@@ -94,10 +96,11 @@
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);
}
--- a/src/link/object.c
+++ b/src/link/object.c
@@ -75,16 +75,17 @@
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 @@
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 @@
*
*/
if (pSection->nByteSize) {- if (pSection->pData =
- (UBYTE *) malloc(pSection->nByteSize)) {- SLONG nNumberOfPatches;
- struct sPatch **ppPatch, *pPatch;
- char s[256];
+ pSection->pData = malloc(pSection->nByteSize);
+ if (!pSection->pData)
+ fatalerror("Out of memory!");- fread(pSection->pData, sizeof(UBYTE),
- pSection->nByteSize, f);
- nNumberOfPatches = readlong(f);
- ppPatch = &pSection->pPatches;
+ SLONG nNumberOfPatches;
+ struct sPatch **ppPatch, *pPatch;
+ char s[256];
- /*
- * 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
+ 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!");- }
- } else
- 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 @@
/* 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 @@
*
*/
-struct sSection *obj_ReadRGB1Section(FILE * f)
+struct sSection *obj_ReadRGB1Section(FILE *f)
{struct sSection *pSection;
@@ -306,82 +293,62 @@
*
*/
if (pSection->nByteSize) {- if (pSection->pData =
- (UBYTE *) malloc(pSection->nByteSize)) {- SLONG nNumberOfPatches;
- struct sPatch **ppPatch, *pPatch;
- char s[256];
+ pSection->pData = malloc(pSection->nByteSize);
+ if (!pSection->pData)
+ fatalerror("Out of memory!");- fread(pSection->pData, sizeof(UBYTE),
- pSection->nByteSize, f);
- nNumberOfPatches = readlong(f);
- ppPatch = &pSection->pPatches;
+ SLONG nNumberOfPatches;
+ struct sPatch **ppPatch, *pPatch;
+ char s[256];
- /*
- * 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
- fatalerror("Out of memory!");+ 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 @@
/* 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 @@
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 @@
oReadLib = 1;
- if (pObjfile = fopen(tzLibfile, "rb")) {- char tzHeader[5];
+ pObjfile = fopen(tzLibfile, "rb");
+ if (!pObjfile) {+ sprintf(temptext, "Unable to open '%s'\n", tzLibfile);
+ fatalerror(temptext);
+ }
- 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",
+ 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 {- sprintf(temptext, "Unable to open '%s'\n", tzLibfile);
fatalerror(temptext);
}
+ fclose(pObjfile);
}
--- a/src/link/output.c
+++ b/src/link/output.c
@@ -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;
+ 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));
+ MapfileCloseBank(area_Avail(0));
- fwrite(mem, 1, MaxAvail[BANK_HOME], f);
- free(mem);
- }
+ 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);
+ if (fillchar != -1) {+ memset(mem, fillchar, MaxAvail[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;
+ 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));
+ MapfileCloseBank(area_Avail(bank));
- fwrite(mem, 1, MaxAvail[bank], f);
- free(mem);
- }
+ fwrite(mem, 1, MaxAvail[bank], f);
+ free(mem);
}
void out_Setname(char *tzOutputfile)
@@ -78,7 +82,7 @@
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 @@
{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 @@
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;
--- a/src/link/patch.c
+++ b/src/link/patch.c
@@ -154,7 +154,7 @@
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 @@
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 @@
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 @@
(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 @@
}
} 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);
--- a/src/link/symbol.c
+++ b/src/link/symbol.c
@@ -74,34 +74,33 @@
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;
}
}
}
--
⑨