diff --git a/include/asm/asm.h b/include/asm/asm.h index b1d79a9a..10289e42 100644 --- a/include/asm/asm.h +++ b/include/asm/asm.h @@ -14,24 +14,22 @@ #include #include -#include "types.h" -#include "asm/symbol.h" - #include "asm/localasm.h" +#include "asm/symbol.h" #define MAXUNIONS 128 #define MAXMACROARGS 256 #define MAXINCPATHS 128 extern int32_t nLineNo; -extern ULONG nTotalLines; -extern ULONG nPC; -extern ULONG nPass; -extern ULONG nIFDepth; +extern uint32_t nTotalLines; +extern uint32_t nPC; +extern uint32_t nPass; +extern uint32_t nIFDepth; extern bool skipElif; -extern ULONG nUnionDepth; -extern ULONG unionStart[MAXUNIONS]; -extern ULONG unionSize[MAXUNIONS]; +extern uint32_t nUnionDepth; +extern uint32_t unionStart[MAXUNIONS]; +extern uint32_t unionSize[MAXUNIONS]; extern char tzCurrentFileName[_MAX_PATH + 1]; extern struct Section *pCurrentSection; extern struct sSymbol *tHashedSymbols[HASHSIZE]; diff --git a/include/asm/fstack.h b/include/asm/fstack.h index 65ba3cf6..585ec353 100644 --- a/include/asm/fstack.h +++ b/include/asm/fstack.h @@ -13,9 +13,10 @@ #include #include "asm/asm.h" -#include "types.h" #include "asm/lexer.h" +#include "types.h" + struct sContext { YY_BUFFER_STATE FlexHandle; struct sSymbol *pMacro; @@ -23,11 +24,11 @@ struct sContext { char tzFileName[_MAX_PATH + 1]; char *tzMacroArgs[MAXMACROARGS + 1]; int32_t nLine; - ULONG nStatus; + uint32_t nStatus; FILE *pFile; char *pREPTBlock; - ULONG nREPTBlockCount; - ULONG nREPTBlockSize; + uint32_t nREPTBlockCount; + uint32_t nREPTBlockSize; }; void @@ -37,8 +38,8 @@ void fstk_Init(char *); extern void fstk_Dump(void); extern void fstk_AddIncludePath(char *s); -extern ULONG fstk_RunMacro(char *s); -extern void fstk_RunRept(ULONG count); +extern uint32_t fstk_RunMacro(char *s); +extern void fstk_RunRept(uint32_t count); FILE * fstk_FindFile(char *); diff --git a/include/asm/lexer.h b/include/asm/lexer.h index 81cbc941..5db2329c 100644 --- a/include/asm/lexer.h +++ b/include/asm/lexer.h @@ -4,19 +4,17 @@ #include #include -#include "types.h" - #define LEXHASHSIZE (1 << 11) #define MAXSTRLEN 255 struct sLexInitString { char *tzName; - ULONG nToken; + uint32_t nToken; }; struct sLexFloat { - ULONG(*Callback) (char *s, ULONG size); - ULONG nToken; + uint32_t(*Callback) (char *s, uint32_t size); + uint32_t nToken; }; struct yy_buffer_state { @@ -24,8 +22,8 @@ struct yy_buffer_state { char *pBufferStart; // address where the data is initially written // after the "safety margin" char *pBuffer; - ULONG nBufferSize; - ULONG oAtLineStart; + uint32_t nBufferSize; + uint32_t oAtLineStart; }; enum eLexerState { @@ -39,24 +37,24 @@ typedef struct yy_buffer_state *YY_BUFFER_STATE; extern void yy_set_state(enum eLexerState i); extern YY_BUFFER_STATE yy_create_buffer(FILE * f); -extern YY_BUFFER_STATE yy_scan_bytes(char *mem, ULONG size); +extern YY_BUFFER_STATE yy_scan_bytes(char *mem, uint32_t size); extern void yy_delete_buffer(YY_BUFFER_STATE); extern void yy_switch_to_buffer(YY_BUFFER_STATE); -extern ULONG lex_FloatAlloc(struct sLexFloat * tok); -extern void lex_FloatAddRange(ULONG id, uint16_t start, uint16_t end); -extern void lex_FloatDeleteRange(ULONG id, uint16_t start, uint16_t end); -extern void lex_FloatAddFirstRange(ULONG id, uint16_t start, uint16_t end); -extern void lex_FloatDeleteFirstRange(ULONG id, uint16_t start, uint16_t end); -extern void lex_FloatAddSecondRange(ULONG id, uint16_t start, uint16_t end); -extern void lex_FloatDeleteSecondRange(ULONG id, uint16_t start, uint16_t end); +extern uint32_t lex_FloatAlloc(struct sLexFloat * tok); +extern void lex_FloatAddRange(uint32_t id, uint16_t start, uint16_t end); +extern void lex_FloatDeleteRange(uint32_t id, uint16_t start, uint16_t end); +extern void lex_FloatAddFirstRange(uint32_t id, uint16_t start, uint16_t end); +extern void lex_FloatDeleteFirstRange(uint32_t id, uint16_t start, uint16_t end); +extern void lex_FloatAddSecondRange(uint32_t id, uint16_t start, uint16_t end); +extern void lex_FloatDeleteSecondRange(uint32_t id, uint16_t start, uint16_t end); extern void lex_Init(void); extern void lex_AddStrings(struct sLexInitString * lex); -extern void lex_SetBuffer(char *buffer, ULONG len); -extern ULONG yylex(void); +extern void lex_SetBuffer(char *buffer, uint32_t len); +extern uint32_t yylex(void); extern void yyunput(char c); extern void yyunputstr(char *s); -extern void yyskipbytes(ULONG count); -extern void yyunputbytes(ULONG count); +extern void yyskipbytes(uint32_t count); +extern void yyunputbytes(uint32_t count); extern YY_BUFFER_STATE pCurrentBuffer; diff --git a/include/asm/main.h b/include/asm/main.h index 72e09850..9f62b1a8 100644 --- a/include/asm/main.h +++ b/include/asm/main.h @@ -17,7 +17,7 @@ struct sOptions { }; extern char *tzNewMacro; -extern ULONG ulNewMacroSize; +extern uint32_t ulNewMacroSize; extern int32_t nGBGfxID; extern int32_t nBinaryID; diff --git a/include/asm/output.h b/include/asm/output.h index ebf92c4b..6ee8a314 100644 --- a/include/asm/output.h +++ b/include/asm/output.h @@ -4,15 +4,14 @@ #include #include "asm/rpn.h" -#include "types.h" struct Section { char *pzName; uint8_t nType; - ULONG nPC; - ULONG nOrg; - ULONG nBank; - ULONG nAlign; + uint32_t nPC; + uint32_t nOrg; + uint32_t nBank; + uint32_t nAlign; struct Section *pNext; struct Patch *pPatches; struct Charmap *charmap; @@ -21,9 +20,9 @@ struct Section { void out_PrepPass2(void); void out_SetFileName(char *s); -void out_NewSection(char *pzName, ULONG secttype); -void out_NewAbsSection(char *pzName, ULONG secttype, int32_t org, int32_t bank); -void out_NewAlignedSection(char *pzName, ULONG secttype, int32_t alignment, int32_t bank); +void out_NewSection(char *pzName, uint32_t secttype); +void out_NewAbsSection(char *pzName, uint32_t secttype, int32_t org, int32_t bank); +void out_NewAlignedSection(char *pzName, uint32_t secttype, int32_t alignment, int32_t bank); void out_AbsByte(int b); void out_AbsByteGroup(char *s, int length); void out_RelByte(struct Expression * expr); diff --git a/include/asm/rpn.h b/include/asm/rpn.h index 7e54697a..a0e50d25 100644 --- a/include/asm/rpn.h +++ b/include/asm/rpn.h @@ -4,18 +4,18 @@ #include struct Expression { - int32_t nVal; - uint8_t tRPN[256]; - ULONG nRPNLength; - ULONG nRPNOut; - ULONG isReloc; - ULONG isPCRel; + int32_t nVal; + uint8_t tRPN[256]; + uint32_t nRPNLength; + uint32_t nRPNOut; + uint32_t isReloc; + uint32_t isPCRel; }; -ULONG rpn_isReloc(struct Expression * expr); -ULONG rpn_isPCRelative(struct Expression * expr); +uint32_t rpn_isReloc(struct Expression * expr); +uint32_t rpn_isPCRelative(struct Expression * expr); void rpn_Symbol(struct Expression * expr, char *tzSym); -void rpn_Number(struct Expression * expr, ULONG i); +void rpn_Number(struct Expression * expr, uint32_t i); void rpn_LOGNOT(struct Expression * expr, struct Expression * src1); void rpn_LOGOR(struct Expression * expr, struct Expression * src1, diff --git a/include/asm/symbol.h b/include/asm/symbol.h index 4eb6bc0d..fc046fd8 100644 --- a/include/asm/symbol.h +++ b/include/asm/symbol.h @@ -11,15 +11,15 @@ struct sSymbol { char tzName[MAXSYMLEN + 1]; int32_t nValue; - ULONG nType; + uint32_t nType; struct sSymbol *pScope; struct sSymbol *pNext; struct Section *pSection; - ULONG ulMacroSize; + uint32_t ulMacroSize; char *pMacro; int32_t(*Callback) (struct sSymbol *); char tzFileName[_MAX_PATH + 1]; /* File where the symbol was defined. */ - ULONG nFileLine; /* Line where the symbol was defined. */ + uint32_t nFileLine; /* Line where the symbol was defined. */ }; #define SYMF_RELOC 0x001 /* symbol will be reloc'ed during * linking, it's absolute value is @@ -39,7 +39,7 @@ struct sSymbol { #define SYMF_CONST 0x200 /* symbol has a constant value, will * not be changed during linking */ -ULONG calchash(char *s); +uint32_t calchash(char *s); void sym_SetExportAll(uint8_t set); void sym_PrepPass1(void); void sym_PrepPass2(void); @@ -57,23 +57,23 @@ void sym_FreeCurrentMacroArgs(void); void sym_AddEqu(char *tzSym, int32_t value); void sym_AddSet(char *tzSym, int32_t value); void sym_Init(void); -ULONG sym_GetConstantValue(char *s); -ULONG sym_isConstant(char *s); +uint32_t sym_GetConstantValue(char *s); +uint32_t sym_isConstant(char *s); struct sSymbol *sym_FindSymbol(char *tzName); void sym_Global(char *tzSym); char *sym_FindMacroArg(int32_t i); char *sym_GetStringValue(char *tzSym); void sym_UseCurrentMacroArgs(void); -void sym_SetMacroArgID(ULONG nMacroCount); -ULONG sym_isString(char *tzSym); +void sym_SetMacroArgID(uint32_t nMacroCount); +uint32_t sym_isString(char *tzSym); void sym_AddMacro(char *tzSym); void sym_ShiftCurrentMacroArgs(void); void sym_AddString(char *tzSym, char *tzValue); -ULONG sym_GetValue(char *s); -ULONG sym_GetDefinedValue(char *s); -ULONG sym_isDefined(char *tzName); +uint32_t sym_GetValue(char *s); +uint32_t sym_GetDefinedValue(char *s); +uint32_t sym_isDefined(char *tzName); void sym_Purge(char *tzName); -ULONG sym_isConstDefined(char *tzName); +uint32_t sym_isConstDefined(char *tzName); int sym_IsRelocDiffDefined(char *tzSym1, char *tzSym2); #endif diff --git a/include/link/assign.h b/include/link/assign.h index 41d7402a..4ccbb425 100644 --- a/include/link/assign.h +++ b/include/link/assign.h @@ -4,7 +4,6 @@ #include #include "mylink.h" -#include "types.h" enum eBankCount { BANK_COUNT_ROM0 = 1, diff --git a/include/link/mylink.h b/include/link/mylink.h index 034d8840..d13a99b9 100644 --- a/include/link/mylink.h +++ b/include/link/mylink.h @@ -1,15 +1,10 @@ #ifndef RGBDS_LINK_LINK_H #define RGBDS_LINK_LINK_H -#ifndef _MAX_PATH -#define _MAX_PATH 512 -#endif - #include -#include "types.h" - extern int32_t options; + #define OPT_TINY 0x01 #define OPT_SMART_C_LINK 0x02 #define OPT_OVERLAY 0x04 @@ -93,7 +88,7 @@ struct sSymbol { int32_t nOffset; char *pzObjFileName; /* Object file where the symbol is located. */ char *pzFileName; /* Source file where the symbol was defined. */ - ULONG nFileLine; /* Line where the symbol was defined. */ + uint32_t nFileLine; /* Line where the symbol was defined. */ }; enum ePatchType { diff --git a/include/link/symbol.h b/include/link/symbol.h index 9c58ff04..15b8f915 100644 --- a/include/link/symbol.h +++ b/include/link/symbol.h @@ -3,11 +3,9 @@ #include -#include "types.h" - void sym_Init(void); void sym_CreateSymbol(char *tzName, int32_t nValue, int32_t nBank, - char *tzObjFileName, char *tzFileName, ULONG nFileLine); + char *tzObjFileName, char *tzFileName, uint32_t nFileLine); int32_t sym_GetValue(char *tzName); int32_t sym_GetBank(char *tzName); diff --git a/include/types.h b/include/types.h index 4306b183..3d1f65b4 100644 --- a/include/types.h +++ b/include/types.h @@ -2,9 +2,7 @@ #define RGBDS_TYPES_H #ifndef _MAX_PATH -#define _MAX_PATH 512 +#define _MAX_PATH 512 #endif -typedef unsigned long ULONG; - #endif diff --git a/src/asm/asmy.y b/src/asm/asmy.y index bb02ae1b..b70fb1f4 100644 --- a/src/asm/asmy.y +++ b/src/asm/asmy.y @@ -18,11 +18,11 @@ #include "asm/main.h" #include "asm/lexer.h" -char *tzNewMacro; -ULONG ulNewMacroSize; +char *tzNewMacro; +uint32_t ulNewMacroSize; void -bankrangecheck(char *name, ULONG secttype, int32_t org, int32_t bank) +bankrangecheck(char *name, uint32_t secttype, int32_t org, int32_t bank) { int32_t minbank = 0, maxbank = 0; char *stype = NULL; @@ -81,8 +81,8 @@ size_t symvaluetostring(char *dest, size_t maxLength, char *sym) length = i; } else { - ULONG value = sym_GetConstantValue(sym); - int fullLength = snprintf(dest, maxLength + 1, "$%lX", value); + uint32_t value = sym_GetConstantValue(sym); + int fullLength = snprintf(dest, maxLength + 1, "$%X", value); if (fullLength < 0) { fatalerror("snprintf encoding error"); @@ -98,9 +98,9 @@ size_t symvaluetostring(char *dest, size_t maxLength, char *sym) return length; } -ULONG str2int( char *s ) +uint32_t str2int( char *s ) { - ULONG r=0; + uint32_t r=0; while( *s ) { r<<=8; @@ -109,10 +109,10 @@ ULONG str2int( char *s ) return( r ); } -ULONG str2int2( char *s, int length ) +uint32_t str2int2( char *s, int length ) { int i; - ULONG r=0; + uint32_t r=0; i = (length - 4 < 0 ? 0 : length - 4); while(i < length) { @@ -123,22 +123,22 @@ ULONG str2int2( char *s, int length ) return( r ); } -ULONG isWhiteSpace( char s ) +uint32_t isWhiteSpace( char s ) { return( s==' ' || s=='\t' || s=='\0' || s=='\n' ); } -ULONG isRept( char *s ) +uint32_t isRept( char *s ) { return( (strncasecmp(s,"REPT",4)==0) && isWhiteSpace(*(s-1)) && isWhiteSpace(s[4]) ); } -ULONG isEndr( char *s ) +uint32_t isEndr( char *s ) { return( (strncasecmp(s,"Endr",4)==0) && isWhiteSpace(*(s-1)) && isWhiteSpace(s[4]) ); } -void copyrept( void ) +void copyrept( void ) { int32_t level=1, len, instring=0; char *src=pCurrentBuffer->pBuffer; @@ -193,7 +193,7 @@ void copyrept( void ) ulNewMacroSize=len; if ((tzNewMacro = malloc(ulNewMacroSize + 1)) != NULL) { - ULONG i; + uint32_t i; tzNewMacro[ulNewMacroSize]=0; for( i=0; ipBuffer; @@ -274,7 +274,7 @@ void copymacro( void ) if( (tzNewMacro=(char *)malloc(ulNewMacroSize+2))!=NULL ) { - ULONG i; + uint32_t i; tzNewMacro[ulNewMacroSize]='\n'; tzNewMacro[ulNewMacroSize+1]=0; @@ -290,22 +290,22 @@ void copymacro( void ) yyskipbytes( ulNewMacroSize+4 ); } -ULONG isIf(char *s) +uint32_t isIf(char *s) { return((strncasecmp(s,"If",2) == 0) && isWhiteSpace(s[-1]) && isWhiteSpace(s[2])); } -ULONG isElif(char *s) +uint32_t isElif(char *s) { return((strncasecmp(s,"Elif",4) == 0) && isWhiteSpace(s[-1]) && isWhiteSpace(s[4])); } -ULONG isElse(char *s) +uint32_t isElse(char *s) { return((strncasecmp(s,"Else",4) == 0) && isWhiteSpace(s[-1]) && isWhiteSpace(s[4])); } -ULONG isEndc(char *s) +uint32_t isEndc(char *s) { return((strncasecmp(s,"Endc",4) == 0) && isWhiteSpace(s[-1]) && isWhiteSpace(s[4])); } @@ -436,25 +436,25 @@ void startUnion() { if (!pCurrentSection) { fatalerror("UNIONs must be inside a SECTION"); } - - ULONG unionIndex = nUnionDepth; + + uint32_t unionIndex = nUnionDepth; nUnionDepth++; if (nUnionDepth > MAXUNIONS) { fatalerror("Too many nested UNIONs"); } - + unionStart[unionIndex] = nPC; unionSize[unionIndex] = 0; } void updateUnion() { - ULONG unionIndex = nUnionDepth - 1; - ULONG size = nPC - unionStart[unionIndex]; - + uint32_t unionIndex = nUnionDepth - 1; + uint32_t size = nPC - unionStart[unionIndex]; + if (size > unionSize[unionIndex]) { unionSize[unionIndex] = size; } - + nPC = unionStart[unionIndex]; pCurrentSection->nPC = unionStart[unionIndex]; pPCSymbol->nValue = unionStart[unionIndex]; @@ -794,9 +794,9 @@ endu : T_POP_ENDU { if (nUnionDepth <= 0) { fatalerror("Found ENDU outside of a UNION construct"); } - + updateUnion(); - + nUnionDepth--; nPC = unionStart[nUnionDepth] + unionSize[nUnionDepth]; pCurrentSection->nPC = nPC; @@ -844,9 +844,8 @@ import_list : import_list_entry ; import_list_entry : T_ID { - /* This is done automatically if - * the label isn't found in the - * list of defined symbols. */ + /* This is done automatically if the label isn't found + * in the list of defined symbols. */ if( nPass==1 ) warning("IMPORT is a deprecated keyword with no effect: %s", $1); } @@ -1090,7 +1089,14 @@ relocconst : T_ID | T_NUMBER { rpn_Number(&$$,$1); $$.nVal = $1; } | string - { char *s; int length; ULONG r; s = $1; length = charmap_Convert(&s); r = str2int2(s, length); free(s); rpn_Number(&$$,r); $$.nVal=r; } + { + char *s = $1; + int length = charmap_Convert(&s); + uint32_t r = str2int2(s, length); + free(s); + rpn_Number(&$$,r); + $$.nVal=r; + } | T_OP_LOGICNOT relocconst %prec NEG { rpn_LOGNOT(&$$,&$2); } | relocconst T_OP_LOGICOR relocconst @@ -1792,7 +1798,6 @@ T_MODE_L : T_TOKEN_L | T_OP_LOW '(' T_MODE_HL ')' ; - ccode : T_CC_NZ { $$ = CC_NZ; } | T_CC_Z { $$ = CC_Z; } | T_CC_NC { $$ = CC_NC; } diff --git a/src/asm/fstack.c b/src/asm/fstack.c index cf4258f4..4d17c2f8 100644 --- a/src/asm/fstack.c +++ b/src/asm/fstack.c @@ -9,33 +9,31 @@ #include #include -#include "asm/symbol.h" #include "asm/fstack.h" -#include "types.h" -#include "asm/main.h" #include "asm/lexer.h" +#include "asm/main.h" +#include "asm/symbol.h" + #include "extern/err.h" #include "extern/strl.h" -#ifndef PATH_MAX -#define PATH_MAX 256 -#endif +#include "types.h" struct sContext *pFileStack; struct sSymbol *pCurrentMacro; YY_BUFFER_STATE CurrentFlexHandle; FILE *pCurrentFile; -ULONG nCurrentStatus; +uint32_t nCurrentStatus; char tzCurrentFileName[_MAX_PATH + 1]; char IncludePaths[MAXINCPATHS][_MAX_PATH + 1]; int32_t NextIncPath = 0; -ULONG nMacroCount; +uint32_t nMacroCount; char *pCurrentREPTBlock; -ULONG nCurrentREPTBlockSize; -ULONG nCurrentREPTBlockCount; +uint32_t nCurrentREPTBlockSize; +uint32_t nCurrentREPTBlockCount; -ULONG ulMacroReturnValue; +uint32_t ulMacroReturnValue; extern char *tzObjectname; extern FILE *dependfile; @@ -228,7 +226,7 @@ fstk_AddIncludePath(char *s) FILE * fstk_FindFile(char *fname) { - char path[PATH_MAX]; + char path[_MAX_PATH]; int i; FILE *f; @@ -292,7 +290,7 @@ fstk_RunInclude(char *tzFileName) /* * Set up a macro for parsing */ -ULONG +uint32_t fstk_RunMacro(char *s) { struct sSymbol *sym; @@ -362,7 +360,7 @@ fstk_RunString(char *s) * Set up a repeat block for parsing */ void -fstk_RunRept(ULONG count) +fstk_RunRept(uint32_t count) { if (count) { pushcontext(); diff --git a/src/asm/globlex.c b/src/asm/globlex.c index 55bb8f6a..a992f7c9 100644 --- a/src/asm/globlex.c +++ b/src/asm/globlex.c @@ -108,25 +108,21 @@ ascii2bin(char *s) return (result); } -ULONG -ParseFixedPoint(char *s, ULONG size) +uint32_t +ParseFixedPoint(char *s, uint32_t size) { - //char dest[256]; - ULONG i = 0, dot = 0; + uint32_t i = 0, dot = 0; while (size && dot != 2) { if (s[i] == '.') dot += 1; if (dot < 2) { - //dest[i] = s[i]; size -= 1; i += 1; } } - //dest[i] = 0; - yyunputbytes(size); yylval.nConstValue = (int32_t) (atof(s) * 65536); @@ -134,8 +130,8 @@ ParseFixedPoint(char *s, ULONG size) return (1); } -ULONG -ParseNumber(char *s, ULONG size) +uint32_t +ParseNumber(char *s, uint32_t size) { char dest[256]; @@ -146,8 +142,8 @@ ParseNumber(char *s, ULONG size) return (1); } -ULONG -ParseSymbol(char *src, ULONG size) +uint32_t +ParseSymbol(char *src, uint32_t size) { char dest[MAXSYMLEN + 1]; int copied = 0, size_backup = size; @@ -204,8 +200,8 @@ ParseSymbol(char *src, ULONG size) } } -ULONG -PutMacroArg(char *src, ULONG size) +uint32_t +PutMacroArg(char *src, uint32_t size) { char *s; @@ -222,8 +218,8 @@ PutMacroArg(char *src, ULONG size) return (0); } -ULONG -PutUniqueArg(char *src, ULONG size) +uint32_t +PutUniqueArg(char *src, uint32_t size) { char *s; @@ -399,7 +395,7 @@ struct sLexFloat tMacroUniqueToken = { void setuplex(void) { - ULONG id; + uint32_t id; lex_Init(); lex_AddStrings(staticstrings); diff --git a/src/asm/lexer.c b/src/asm/lexer.c index 75c37d95..bab19ab7 100644 --- a/src/asm/lexer.c +++ b/src/asm/lexer.c @@ -6,19 +6,19 @@ #include #include "asm/asm.h" +#include "asm/fstack.h" #include "asm/lexer.h" -#include "types.h" #include "asm/main.h" #include "asm/rpn.h" -#include "asm/fstack.h" + #include "extern/err.h" #include "asmy.h" struct sLexString { char *tzName; - ULONG nToken; - ULONG nNameLength; + uint32_t nToken; + uint32_t nNameLength; struct sLexString *pNext; }; #define pLexBufferRealStart (pCurrentBuffer->pBufferRealStart) @@ -32,12 +32,12 @@ extern size_t symvaluetostring(char *dest, size_t maxLength, char *sym); struct sLexFloat tLexFloat[32]; struct sLexString *tLexHash[LEXHASHSIZE]; YY_BUFFER_STATE pCurrentBuffer; -ULONG nLexMaxLength; // max length of all keywords and operators +uint32_t nLexMaxLength; // max length of all keywords and operators -ULONG tFloatingSecondChar[256]; -ULONG tFloatingFirstChar[256]; -ULONG tFloatingChars[256]; -ULONG nFloating; +uint32_t tFloatingSecondChar[256]; +uint32_t tFloatingFirstChar[256]; +uint32_t tFloatingChars[256]; +uint32_t nFloating; enum eLexerState lexerstate = LEX_STATE_NORMAL; void @@ -59,13 +59,13 @@ lowerstring(char *s) } void -yyskipbytes(ULONG count) +yyskipbytes(uint32_t count) { pLexBuffer += count; } void -yyunputbytes(ULONG count) +yyunputbytes(uint32_t count) { pLexBuffer -= count; } @@ -113,7 +113,7 @@ yy_delete_buffer(YY_BUFFER_STATE buf) } YY_BUFFER_STATE -yy_scan_bytes(char *mem, ULONG size) +yy_scan_bytes(char *mem, uint32_t size) { YY_BUFFER_STATE pBuffer; @@ -139,7 +139,7 @@ yy_create_buffer(FILE * f) YY_BUFFER_STATE pBuffer; if ((pBuffer = malloc(sizeof(struct yy_buffer_state))) != NULL) { - ULONG size; + uint32_t size; fseek(f, 0, SEEK_END); size = ftell(f); @@ -148,7 +148,7 @@ yy_create_buffer(FILE * f) if ((pBuffer->pBufferRealStart = malloc(size + 2 + SAFETYMARGIN)) != NULL) { char *mem; - ULONG instring = 0; + uint32_t instring = 0; pBuffer->pBufferStart = pBuffer->pBufferRealStart + SAFETYMARGIN; pBuffer->pBuffer = pBuffer->pBufferRealStart + SAFETYMARGIN; @@ -199,7 +199,7 @@ yy_create_buffer(FILE * f) return (NULL); } -ULONG +uint32_t lex_FloatAlloc(struct sLexFloat *token) { tLexFloat[nFloating] = *token; @@ -221,7 +221,7 @@ lex_CheckCharacterRange(uint16_t start, uint16_t end) } void -lex_FloatDeleteRange(ULONG id, uint16_t start, uint16_t end) +lex_FloatDeleteRange(uint32_t id, uint16_t start, uint16_t end) { lex_CheckCharacterRange(start, end); @@ -232,7 +232,7 @@ lex_FloatDeleteRange(ULONG id, uint16_t start, uint16_t end) } void -lex_FloatAddRange(ULONG id, uint16_t start, uint16_t end) +lex_FloatAddRange(uint32_t id, uint16_t start, uint16_t end) { lex_CheckCharacterRange(start, end); @@ -243,7 +243,7 @@ lex_FloatAddRange(ULONG id, uint16_t start, uint16_t end) } void -lex_FloatDeleteFirstRange(ULONG id, uint16_t start, uint16_t end) +lex_FloatDeleteFirstRange(uint32_t id, uint16_t start, uint16_t end) { lex_CheckCharacterRange(start, end); @@ -254,7 +254,7 @@ lex_FloatDeleteFirstRange(ULONG id, uint16_t start, uint16_t end) } void -lex_FloatAddFirstRange(ULONG id, uint16_t start, uint16_t end) +lex_FloatAddFirstRange(uint32_t id, uint16_t start, uint16_t end) { lex_CheckCharacterRange(start, end); @@ -265,7 +265,7 @@ lex_FloatAddFirstRange(ULONG id, uint16_t start, uint16_t end) } void -lex_FloatDeleteSecondRange(ULONG id, uint16_t start, uint16_t end) +lex_FloatDeleteSecondRange(uint32_t id, uint16_t start, uint16_t end) { lex_CheckCharacterRange(start, end); @@ -276,7 +276,7 @@ lex_FloatDeleteSecondRange(ULONG id, uint16_t start, uint16_t end) } void -lex_FloatAddSecondRange(ULONG id, uint16_t start, uint16_t end) +lex_FloatAddSecondRange(uint32_t id, uint16_t start, uint16_t end) { lex_CheckCharacterRange(start, end); @@ -287,7 +287,7 @@ lex_FloatAddSecondRange(ULONG id, uint16_t start, uint16_t end) } struct sLexFloat * -lexgetfloat(ULONG nFloatMask) +lexgetfloat(uint32_t nFloatMask) { if (nFloatMask == 0) { fatalerror("Internal error in lexgetfloat"); @@ -303,10 +303,10 @@ lexgetfloat(ULONG nFloatMask) return (&tLexFloat[i]); } -ULONG +uint32_t lexcalchash(char *s) { - ULONG hash = 0; + uint32_t hash = 0; while (*s) { hash = (hash * 283) ^ toupper(*s++); @@ -318,7 +318,7 @@ lexcalchash(char *s) void lex_Init(void) { - ULONG i; + uint32_t i; for (i = 0; i < LEXHASHSIZE; i++) { tLexHash[i] = NULL; @@ -339,7 +339,7 @@ lex_AddStrings(struct sLexInitString * lex) { while (lex->tzName) { struct sLexString **ppHash; - ULONG hash; + uint32_t hash; ppHash = &tLexHash[hash = lexcalchash(lex->tzName)]; while (*ppHash) @@ -377,14 +377,14 @@ lex_AddStrings(struct sLexInitString * lex) * buffer will have their bits set in the float mask. */ void -yylex_GetFloatMaskAndFloatLen(ULONG *pnFloatMask, ULONG *pnFloatLen) +yylex_GetFloatMaskAndFloatLen(uint32_t *pnFloatMask, uint32_t *pnFloatLen) { // Note that '\0' should always have a bit mask of 0 in the "floating" // tables, so it doesn't need to be checked for separately. char *s = pLexBuffer; - ULONG nOldFloatMask = 0; - ULONG nFloatMask = tFloatingFirstChar[(int)*s]; + uint32_t nOldFloatMask = 0; + uint32_t nFloatMask = tFloatingFirstChar[(int)*s]; if (nFloatMask != 0) { s++; @@ -399,7 +399,7 @@ yylex_GetFloatMaskAndFloatLen(ULONG *pnFloatMask, ULONG *pnFloatLen) } *pnFloatMask = nOldFloatMask; - *pnFloatLen = (ULONG)(s - pLexBuffer); + *pnFloatLen = (uint32_t)(s - pLexBuffer); } /* @@ -410,8 +410,8 @@ yylex_GetLongestFixed() { struct sLexString *pLongestFixed = NULL; char *s = pLexBuffer; - ULONG hash = 0; - ULONG length = 0; + uint32_t hash = 0; + uint32_t length = 0; while (length < nLexMaxLength && *s) { hash = (hash * 283) ^ toupper(*s); @@ -605,12 +605,12 @@ yylex_ReadQuotedString() fatalerror("Unterminated string"); } -ULONG +uint32_t yylex_NORMAL() { struct sLexString *pLongestFixed = NULL; - ULONG nFloatMask, nFloatLen; - ULONG linestart = AtLineStart; + uint32_t nFloatMask, nFloatLen; + uint32_t linestart = AtLineStart; AtLineStart = 0; @@ -682,7 +682,7 @@ scanagain: return pLongestFixed->nToken; } -ULONG +uint32_t yylex_MACROARGS() { size_t index = 0; @@ -758,7 +758,7 @@ yylex_MACROARGS() return 0; } -ULONG +uint32_t yylex(void) { switch (lexerstate) { diff --git a/src/asm/main.c b/src/asm/main.c index 99af7610..c3b81ee9 100644 --- a/src/asm/main.c +++ b/src/asm/main.c @@ -24,9 +24,9 @@ char **cldefines; clock_t nStartClock, nEndClock; int32_t nLineNo; -ULONG nTotalLines, nPass, nPC, nIFDepth, nUnionDepth, nErrors; +uint32_t nTotalLines, nPass, nPC, nIFDepth, nUnionDepth, nErrors; bool skipElif; -ULONG unionStart[128], unionSize[128]; +uint32_t unionStart[128], unionSize[128]; extern int yydebug; @@ -480,7 +480,7 @@ main(int argc, char *argv[]) timespent = ((double)(nEndClock - nStartClock)) / (double)CLOCKS_PER_SEC; if (CurrentOptions.verbose) { - printf("Success! %ld lines in %d.%02d seconds ", nTotalLines, + printf("Success! %u lines in %d.%02d seconds ", nTotalLines, (int) timespent, ((int) (timespent * 100.0)) % 100); if (timespent == 0) printf("(INFINITY lines/minute)\n"); diff --git a/src/asm/math.c b/src/asm/math.c index 8376c08f..6d4a5056 100644 --- a/src/asm/math.c +++ b/src/asm/math.c @@ -6,7 +6,6 @@ #include #include -#include "types.h" #include "asm/mymath.h" #include "asm/symbol.h" diff --git a/src/asm/output.c b/src/asm/output.c index 9e7bb7bf..dc132ca3 100644 --- a/src/asm/output.c +++ b/src/asm/output.c @@ -23,16 +23,16 @@ void out_SetCurrentSection(struct Section * pSect); struct Patch { char tzFilename[_MAX_PATH + 1]; - ULONG nLine; - ULONG nOffset; + uint32_t nLine; + uint32_t nOffset; uint8_t nType; - ULONG nRPNSize; + uint32_t nRPNSize; uint8_t *pRPN; struct Patch *pNext; }; struct PatchSymbol { - ULONG ID; + uint32_t ID; struct sSymbol *pSymbol; struct PatchSymbol *pNext; struct PatchSymbol *pBucketNext; // next symbol in hash table bucket @@ -80,8 +80,8 @@ out_PopSection(void) fatalerror("No entries in the section stack"); } -ULONG -getmaxsectionsize(ULONG secttype, char * sectname) +uint32_t +getmaxsectionsize(uint32_t secttype, char * sectname) { switch (secttype) { @@ -101,11 +101,11 @@ getmaxsectionsize(ULONG secttype, char * sectname) /* * Count the number of symbols used in this object */ -ULONG +uint32_t countsymbols(void) { struct PatchSymbol *pSym; - ULONG count = 0; + uint32_t count = 0; pSym = pPatchSymbols; @@ -120,11 +120,11 @@ countsymbols(void) /* * Count the number of sections used in this object */ -ULONG +uint32_t countsections(void) { struct Section *pSect; - ULONG count = 0; + uint32_t count = 0; pSect = pSectionList; @@ -139,11 +139,11 @@ countsections(void) /* * Count the number of patches used in this object */ -ULONG +uint32_t countpatches(struct Section * pSect) { struct Patch *pPatch; - ULONG r = 0; + uint32_t r = 0; pPatch = pSect->pPatches; while (pPatch) { @@ -158,7 +158,7 @@ countpatches(struct Section * pSect) * Write a long to a file (little-endian) */ void -fputlong(ULONG i, FILE * f) +fputlong(uint32_t i, FILE * f) { fputc(i, f); fputc(i >> 8, f); @@ -180,11 +180,11 @@ fputstring(char *s, FILE * f) /* * Return a section's ID */ -ULONG +uint32_t getsectid(struct Section * pSect) { struct Section *sec; - ULONG ID = 0; + uint32_t ID = 0; sec = pSectionList; @@ -196,7 +196,7 @@ getsectid(struct Section * pSect) } fatalerror("INTERNAL: Unknown section"); - return ((ULONG) - 1); + return ((uint32_t) - 1); } /* @@ -251,8 +251,8 @@ void writesymbol(struct sSymbol * pSym, FILE * f) { char symname[MAXSYMLEN * 2 + 1]; - ULONG type; - ULONG offset; + uint32_t type; + uint32_t offset; int32_t sectid; if (pSym->nType & SYMF_IMPORT) { @@ -295,12 +295,12 @@ writesymbol(struct sSymbol * pSym, FILE * f) /* * Add a symbol to the object */ -ULONG +uint32_t addsymbol(struct sSymbol * pSym) { struct PatchSymbol *pPSym, **ppPSym; - static ULONG nextID = 0; - ULONG hash; + static uint32_t nextID = 0; + uint32_t hash; hash = calchash(pSym->tzName); ppPSym = &(tHashedPatchSymbols[hash]); @@ -369,13 +369,13 @@ allocpatch(void) * Create a new patch (includes the rpn expr) */ void -createpatch(ULONG type, struct Expression * expr) +createpatch(uint32_t type, struct Expression * expr) { struct Patch *pPatch; uint16_t rpndata; uint8_t rpnexpr[2048]; char tzSym[512]; - ULONG rpnptr = 0, symptr; + uint32_t rpnptr = 0, symptr; pPatch = allocpatch(); pPatch->nType = type; @@ -396,7 +396,7 @@ createpatch(ULONG type, struct Expression * expr) symptr = 0; while ((tzSym[symptr++] = rpn_PopByte(expr)) != 0); if (sym_isConstant(tzSym)) { - ULONG value; + uint32_t value; value = sym_GetConstantValue(tzSym); rpnexpr[rpnptr++] = RPN_CONST; @@ -474,9 +474,9 @@ checkcodesection(void) * Check if the section has grown too much. */ void -checksectionoverflow(ULONG delta_size) +checksectionoverflow(uint32_t delta_size) { - ULONG maxsize = getmaxsectionsize(pCurrentSection->nType, + uint32_t maxsize = getmaxsectionsize(pCurrentSection->nType, pCurrentSection->pzName); if (pCurrentSection->nPC + delta_size > maxsize) { @@ -564,7 +564,7 @@ out_SetFileName(char *s) * Find a section by name and type. If it doesn't exist, create it */ struct Section * -out_FindSection(char *pzName, ULONG secttype, int32_t org, int32_t bank, int32_t alignment) +out_FindSection(char *pzName, uint32_t secttype, int32_t org, int32_t bank, int32_t alignment) { struct Section *pSect, **ppSect; @@ -574,9 +574,9 @@ out_FindSection(char *pzName, ULONG secttype, int32_t org, int32_t bank, int32_t while (pSect) { if (strcmp(pzName, pSect->pzName) == 0) { if (secttype == pSect->nType - && ((ULONG) org) == pSect->nOrg - && ((ULONG) bank) == pSect->nBank - && ((ULONG) alignment == pSect->nAlign)) { + && ((uint32_t) org) == pSect->nOrg + && ((uint32_t) bank) == pSect->nBank + && ((uint32_t) alignment == pSect->nAlign)) { return (pSect); } else fatalerror @@ -603,7 +603,7 @@ out_FindSection(char *pzName, ULONG secttype, int32_t org, int32_t bank, int32_t if (secttype == SECT_ROM0 || secttype == SECT_ROMX) { /* It is only needed to allocate memory for ROM * sections. */ - ULONG sectsize = getmaxsectionsize(secttype, pzName); + uint32_t sectsize = getmaxsectionsize(secttype, pzName); if ((pSect->tData = malloc(sectsize)) == NULL) fatalerror("Not enough memory for section"); } @@ -637,7 +637,7 @@ out_SetCurrentSection(struct Section * pSect) * Set the current section by name and type */ void -out_NewSection(char *pzName, ULONG secttype) +out_NewSection(char *pzName, uint32_t secttype) { out_SetCurrentSection(out_FindSection(pzName, secttype, -1, -1, 1)); } @@ -646,7 +646,7 @@ out_NewSection(char *pzName, ULONG secttype) * Set the current section by name and type */ void -out_NewAbsSection(char *pzName, ULONG secttype, int32_t org, int32_t bank) +out_NewAbsSection(char *pzName, uint32_t secttype, int32_t org, int32_t bank) { out_SetCurrentSection(out_FindSection(pzName, secttype, org, bank, 1)); } @@ -655,7 +655,7 @@ out_NewAbsSection(char *pzName, ULONG secttype, int32_t org, int32_t bank) * Set the current section by name and type, using a given byte alignment */ void -out_NewAlignedSection(char *pzName, ULONG secttype, int32_t alignment, int32_t bank) +out_NewAlignedSection(char *pzName, uint32_t secttype, int32_t alignment, int32_t bank) { if (alignment < 0 || alignment > 16) { yyerror("Alignment must be between 0-16 bits."); @@ -782,7 +782,7 @@ out_AbsWord(int b) void out_RelWord(struct Expression * expr) { - ULONG b; + uint32_t b; checkcodesection(); checksectionoverflow(2); diff --git a/src/asm/rpn.c b/src/asm/rpn.c index 0ee2a222..03dec7fd 100644 --- a/src/asm/rpn.c +++ b/src/asm/rpn.c @@ -6,12 +6,11 @@ #include #include -#include "asm/mylink.h" -#include "types.h" -#include "asm/symbol.h" #include "asm/asm.h" #include "asm/main.h" +#include "asm/mylink.h" #include "asm/rpn.h" +#include "asm/symbol.h" void mergetwoexpressions(struct Expression * expr, struct Expression * src1, @@ -59,7 +58,7 @@ rpn_PopByte(struct Expression * expr) /* * Determine if the current expression is relocatable */ -ULONG +uint32_t rpn_isReloc(struct Expression * expr) { return (expr->isReloc); @@ -68,7 +67,7 @@ rpn_isReloc(struct Expression * expr) /* * Determine if the current expression can be pc-relative */ -ULONG +uint32_t rpn_isPCRelative(struct Expression * expr) { return (expr->isPCRel); @@ -78,7 +77,7 @@ rpn_isPCRelative(struct Expression * expr) * Add symbols, constants and operators to expression */ void -rpn_Number(struct Expression * expr, ULONG i) +rpn_Number(struct Expression * expr, uint32_t i) { rpn_Reset(expr); pushbyte(expr, RPN_CONST); diff --git a/src/asm/symbol.c b/src/asm/symbol.c index 498b5894..2a5c534d 100644 --- a/src/asm/symbol.c +++ b/src/asm/symbol.c @@ -54,7 +54,7 @@ void helper_RemoveLeadingZeros(char * string){ int32_t Callback_NARG(struct sSymbol * sym) { - ULONG i = 0; + uint32_t i = 0; while (currentmacroargs[i] && i < MAXMACROARGS) i += 1; @@ -83,10 +83,10 @@ getvaluefield(struct sSymbol * sym) /* * Calculate the hash value for a string */ -ULONG +uint32_t calchash(char *s) { - ULONG hash = 5381; + uint32_t hash = 5381; while (*s != 0) hash = (hash * 33) ^ (*s++); @@ -101,7 +101,7 @@ struct sSymbol * createsymbol(char *s) { struct sSymbol **ppsym; - ULONG hash; + uint32_t hash; hash = calchash(s); ppsym = &(tHashedSymbols[hash]); @@ -232,7 +232,7 @@ sym_Purge(char *tzName) /* * Determine if a symbol has been defined */ -ULONG +uint32_t sym_isConstDefined(char *tzName) { struct sSymbol *psym, *pscope; @@ -256,7 +256,7 @@ sym_isConstDefined(char *tzName) return (0); } -ULONG +uint32_t sym_isDefined(char *tzName) { struct sSymbol *psym, *pscope; @@ -277,7 +277,7 @@ sym_isDefined(char *tzName) /* * Determine if the symbol is a constant */ -ULONG +uint32_t sym_isConstant(char *s) { struct sSymbol *psym, *pscope; @@ -314,7 +314,7 @@ sym_GetStringValue(char *tzSym) /* * Return a constant symbols value */ -ULONG +uint32_t sym_GetConstantValue(char *s) { struct sSymbol *psym, *pscope; @@ -340,7 +340,7 @@ sym_GetConstantValue(char *s) /* * Return a symbols value... "estimated" if not defined yet */ -ULONG +uint32_t sym_GetValue(char *s) { struct sSymbol *psym, *pscope; @@ -379,7 +379,7 @@ sym_GetValue(char *s) /* * Return a defined symbols value... aborts if not defined yet */ -ULONG +uint32_t sym_GetDefinedValue(char *s) { struct sSymbol *psym, *pscope; @@ -490,11 +490,11 @@ sym_AddNewMacroArg(char *s) } void -sym_SetMacroArgID(ULONG nMacroCount) +sym_SetMacroArgID(uint32_t nMacroCount) { char s[256]; - sprintf(s, "_%ld", nMacroCount); + sprintf(s, "_%u", nMacroCount); newmacroargs[MAXMACROARGS] = strdup(s); } @@ -582,7 +582,7 @@ sym_AddString(char *tzSym, char *tzValue) /* * check if symbol is a string equated symbol */ -ULONG +uint32_t sym_isString(char *tzSym) { struct sSymbol *pSym; diff --git a/src/link/lexer.l b/src/link/lexer.l index 424b477c..c343684b 100644 --- a/src/link/lexer.l +++ b/src/link/lexer.l @@ -22,11 +22,14 @@ #include #include "extern/err.h" + #include "link/mylink.h" #include "link/script.h" #include "parser.h" +#include "types.h" + extern int yyparse(); /* File include stack. */ diff --git a/src/link/library.c b/src/link/library.c index 8e314a5b..f54c87f2 100644 --- a/src/link/library.c +++ b/src/link/library.c @@ -4,7 +4,6 @@ #include #include "extern/err.h" -#include "types.h" #include "link/mylink.h" #include "link/main.h" diff --git a/src/link/object.c b/src/link/object.c index ac6300e5..0a8f8af7 100644 --- a/src/link/object.c +++ b/src/link/object.c @@ -384,7 +384,7 @@ obj_Readfile(char *tzObjectfile) int32_t file_Length(FILE * f) { - ULONG r, p; + uint32_t r, p; p = ftell(f); fseek(f, 0, SEEK_END); diff --git a/src/link/symbol.c b/src/link/symbol.c index 20b555ee..39e6ab05 100644 --- a/src/link/symbol.c +++ b/src/link/symbol.c @@ -4,8 +4,10 @@ #include #include "extern/err.h" + #include "link/main.h" #include "link/patch.h" + #include "types.h" #define HASHSIZE 73 @@ -16,7 +18,7 @@ struct ISymbol { int32_t nBank; /* -1 = constant */ char tzObjFileName[_MAX_PATH + 1]; /* Object file where the symbol was defined. */ char tzFileName[_MAX_PATH + 1]; /* Source file where the symbol was defined. */ - ULONG nFileLine; /* Line where the symbol was defined. */ + uint32_t nFileLine; /* Line where the symbol was defined. */ struct ISymbol *pNext; }; @@ -80,7 +82,7 @@ sym_GetBank(char *tzName) void sym_CreateSymbol(char *tzName, int32_t nValue, int32_t nBank, char *tzObjFileName, - char *tzFileName, ULONG nFileLine) + char *tzFileName, uint32_t nFileLine) { if (strcmp(tzName, "@") == 0) return;