reran indent (whitespace changes)

Merging lai's source with this one is very irritating because
they have different indentation styles. I couldn't find what profile
vegard used for his version, so I used these flags (which should bring
the source close to KNF):
-bap
-br
-ce
-ci4
-cli0
-d0
-di0
-i8
-ip
-l79
-nbc
-ncdb
-ndj
-ei
-nfc1
-nlp
-npcs
-psl
-sc
-sob
This commit is contained in:
anthony
2009-12-30 12:51:32 -07:00
parent ddd7fdac01
commit a014537837
21 changed files with 1175 additions and 1091 deletions

View File

@@ -56,9 +56,9 @@ long i00afunc();
#define ADDRESS_FUNCTION(arg) &(arg) #define ADDRESS_FUNCTION(arg) &(arg)
#endif #endif
#if __STDC__ #if __STDC__
typedef void *pointer; typedef void *pointer;
#else #else
typedef char *pointer; typedef char *pointer;
#endif #endif
#define NULL 0 #define NULL 0
@@ -104,9 +104,11 @@ extern pointer malloc ();
static int stack_dir; /* 1 or -1 once known. */ static int stack_dir; /* 1 or -1 once known. */
#define STACK_DIR stack_dir #define STACK_DIR stack_dir
static void find_stack_direction() static void
find_stack_direction()
{ {
static char *addr = NULL; /* Address of first `dummy', once known. */ static char *addr = NULL; /* Address of first `dummy', once
* known. */
auto char dummy; /* To get stack address. */ auto char dummy; /* To get stack address. */
if (addr == NULL) { /* Initial entry. */ if (addr == NULL) { /* Initial entry. */
@@ -121,7 +123,6 @@ static void find_stack_direction()
stack_dir = -1; /* Stack grew downward. */ stack_dir = -1; /* Stack grew downward. */
} }
} }
#endif /* STACK_DIRECTION == 0 */ #endif /* STACK_DIRECTION == 0 */
/* An "alloca header" is used to: /* An "alloca header" is used to:
@@ -138,10 +139,10 @@ static void find_stack_direction()
typedef union hdr { typedef union hdr {
char align[ALIGN_SIZE]; /* To force sizeof(header). */ char align[ALIGN_SIZE]; /* To force sizeof(header). */
struct { struct {
union hdr *next; /* For chaining headers. */ union hdr *next;/* For chaining headers. */
char *deep; /* For stack depth measure. */ char *deep; /* For stack depth measure. */
} h; } h;
} header; } header;
static header *last_alloca_header = NULL; /* -> last alloca header. */ static header *last_alloca_header = NULL; /* -> last alloca header. */
@@ -152,8 +153,9 @@ static header *last_alloca_header = NULL; /* -> last alloca header. */
caller, but that method cannot be made to work for some caller, but that method cannot be made to work for some
implementations of C, for example under Gould's UTX/32. */ implementations of C, for example under Gould's UTX/32. */
pointer alloca(size) pointer
unsigned size; alloca(size)
unsigned size;
{ {
auto char probe; /* Probes stack depth: */ auto char probe; /* Probes stack depth: */
register char *depth = ADDRESS_FUNCTION(probe); register char *depth = ADDRESS_FUNCTION(probe);
@@ -163,8 +165,8 @@ unsigned size;
find_stack_direction(); find_stack_direction();
#endif #endif
/* Reclaim garbage, defined as all alloca'd storage that /* Reclaim garbage, defined as all alloca'd storage that was allocated
was allocated from deeper in the stack than currently. */ * from deeper in the stack than currently. */
{ {
register header *hp; /* Traverses linked list. */ register header *hp; /* Traverses linked list. */
@@ -207,10 +209,9 @@ unsigned size;
/* User storage begins just after header. */ /* User storage begins just after header. */
return (pointer) ((char *)new + sizeof(header)); return (pointer) ((char *) new + sizeof(header));
} }
} }
#if defined (CRAY) && defined (CRAY_STACKSEG_END) #if defined (CRAY) && defined (CRAY_STACKSEG_END)
#ifdef DEBUG_I00AFUNC #ifdef DEBUG_I00AFUNC
@@ -227,7 +228,6 @@ struct stack_control_header {
long shhwm:32; /* High water mark of stack. */ long shhwm:32; /* High water mark of stack. */
long shsize:32; /* Current size of stack (all segments). */ long shsize:32; /* Current size of stack (all segments). */
}; };
/* The stack segment linkage control information occurs at /* The stack segment linkage control information occurs at
the high-address end of a stack segment. (The stack the high-address end of a stack segment. (The stack
grows from low addresses to high addresses.) The initial grows from low addresses to high addresses.) The initial
@@ -241,11 +241,11 @@ struct stack_segment_linkage {
long ssbase:32; /* Offset to stack base. */ long ssbase:32; /* Offset to stack base. */
long:32; long:32;
long sspseg:32; /* Offset to linkage control of previous long sspseg:32; /* Offset to linkage control of previous
segment of stack. */ * segment of stack. */
long:32; long:32;
long sstcpt:32; /* Pointer to task common address block. */ long sstcpt:32; /* Pointer to task common address block. */
long sscsnm; /* Private control structure number for long sscsnm; /* Private control structure number for
microtasking. */ * microtasking. */
long ssusr1; /* Reserved for user. */ long ssusr1; /* Reserved for user. */
long ssusr2; /* Reserved for user. */ long ssusr2; /* Reserved for user. */
long sstpid; /* Process ID for pid based multi-tasking. */ long sstpid; /* Process ID for pid based multi-tasking. */
@@ -268,15 +268,14 @@ struct stack_segment_linkage {
long sss6; long sss6;
long sss7; long sss7;
}; };
#else /* CRAY2 */ #else /* CRAY2 */
/* The following structure defines the vector of words /* The following structure defines the vector of words
returned by the STKSTAT library routine. */ returned by the STKSTAT library routine. */
struct stk_stat { struct stk_stat {
long now; /* Current total stack size. */ long now; /* Current total stack size. */
long maxc; /* Amount of contiguous space which would long maxc; /* Amount of contiguous space which would be
be required to satisfy the maximum * required to satisfy the maximum stack
stack demand to date. */ * demand to date. */
long high_water; /* Stack high-water mark. */ long high_water; /* Stack high-water mark. */
long overflows; /* Number of stack overflow ($STKOFEN) calls. */ long overflows; /* Number of stack overflow ($STKOFEN) calls. */
long hits; /* Number of internal buffer hits. */ long hits; /* Number of internal buffer hits. */
@@ -289,25 +288,24 @@ struct stk_stat {
long maxs; /* Maximum number of stack segments so far. */ long maxs; /* Maximum number of stack segments so far. */
long pad_size; /* Stack pad size. */ long pad_size; /* Stack pad size. */
long current_address; /* Current stack segment address. */ long current_address; /* Current stack segment address. */
long current_size; /* Current stack segment size. This long current_size; /* Current stack segment size. This number is
number is actually corrupted by STKSTAT to * actually corrupted by STKSTAT to include
include the fifteen word trailer area. */ * the fifteen word trailer area. */
long initial_address; /* Address of initial segment. */ long initial_address; /* Address of initial segment. */
long initial_size; /* Size of initial segment. */ long initial_size; /* Size of initial segment. */
}; };
/* The following structure describes the data structure which trails /* The following structure describes the data structure which trails
any stack segment. I think that the description in 'asdef' is any stack segment. I think that the description in 'asdef' is
out of date. I only describe the parts that I am sure about. */ out of date. I only describe the parts that I am sure about. */
struct stk_trailer { struct stk_trailer {
long this_address; /* Address of this block. */ long this_address; /* Address of this block. */
long this_size; /* Size of this block (does not include long this_size; /* Size of this block (does not include this
this trailer). */ * trailer). */
long unknown2; long unknown2;
long unknown3; long unknown3;
long link; /* Address of trailer block of previous long link; /* Address of trailer block of previous
segment. */ * segment. */
long unknown5; long unknown5;
long unknown6; long unknown6;
long unknown7; long unknown7;
@@ -319,7 +317,6 @@ struct stk_trailer {
long unknown13; long unknown13;
long unknown14; long unknown14;
}; };
#endif /* CRAY2 */ #endif /* CRAY2 */
#endif /* not CRAY_STACK */ #endif /* not CRAY_STACK */
@@ -327,27 +324,28 @@ struct stk_trailer {
/* Determine a "stack measure" for an arbitrary ADDRESS. /* Determine a "stack measure" for an arbitrary ADDRESS.
I doubt that "lint" will like this much. */ I doubt that "lint" will like this much. */
static long i00afunc(long *address) static long
i00afunc(long *address)
{ {
struct stk_stat status; struct stk_stat status;
struct stk_trailer *trailer; struct stk_trailer *trailer;
long *block, size; long *block, size;
long result = 0; long result = 0;
/* We want to iterate through all of the segments. The first /* We want to iterate through all of the segments. The first step is
step is to get the stack status structure. We could do this * to get the stack status structure. We could do this more quickly
more quickly and more directly, perhaps, by referencing the * and more directly, perhaps, by referencing the $LM00 common block,
$LM00 common block, but I know that this works. */ * but I know that this works. */
STKSTAT(&status); STKSTAT(&status);
/* Set up the iteration. */ /* Set up the iteration. */
trailer = (struct stk_trailer *)(status.current_address trailer = (struct stk_trailer *) (status.current_address
+ status.current_size - 15); + status.current_size - 15);
/* There must be at least one stack segment. Therefore it is /* There must be at least one stack segment. Therefore it is a fatal
a fatal error if "trailer" is null. */ * error if "trailer" is null. */
if (trailer == 0) if (trailer == 0)
abort(); abort();
@@ -355,40 +353,38 @@ static long i00afunc(long *address)
/* Discard segments that do not contain our argument address. */ /* Discard segments that do not contain our argument address. */
while (trailer != 0) { while (trailer != 0) {
block = (long *)trailer->this_address; block = (long *) trailer->this_address;
size = trailer->this_size; size = trailer->this_size;
if (block == 0 || size == 0) if (block == 0 || size == 0)
abort(); abort();
trailer = (struct stk_trailer *)trailer->link; trailer = (struct stk_trailer *) trailer->link;
if ((block <= address) && (address < (block + size))) if ((block <= address) && (address < (block + size)))
break; break;
} }
/* Set the result to the offset in this segment and add the sizes /* Set the result to the offset in this segment and add the sizes of
of all predecessor segments. */ * all predecessor segments. */
result = address - block; result = address - block;
if (trailer == 0) { if (trailer == 0) {
return result; return result;
} }
do { do {
if (trailer->this_size <= 0) if (trailer->this_size <= 0)
abort(); abort();
result += trailer->this_size; result += trailer->this_size;
trailer = (struct stk_trailer *)trailer->link; trailer = (struct stk_trailer *) trailer->link;
} }
while (trailer != 0); while (trailer != 0);
/* We are done. Note that if you present a bogus address (one /* We are done. Note that if you present a bogus address (one not in
not in any segment), you will get a different number back, formed * any segment), you will get a different number back, formed from
from subtracting the address of the first block. This is probably * subtracting the address of the first block. This is probably not
not what you want. */ * what you want. */
return (result); return (result);
} }
#else /* not CRAY2 */ #else /* not CRAY2 */
/* Stack address function for a CRAY-1, CRAY X-MP, or CRAY Y-MP. /* Stack address function for a CRAY-1, CRAY X-MP, or CRAY Y-MP.
Determine the number of the cell within the stack, Determine the number of the cell within the stack,
@@ -396,7 +392,8 @@ static long i00afunc(long *address)
routine is to linearize, in some sense, stack addresses routine is to linearize, in some sense, stack addresses
for alloca. */ for alloca. */
static long i00afunc(long address) static long
i00afunc(long address)
{ {
long stkl = 0; long stkl = 0;
@@ -405,41 +402,40 @@ static long i00afunc(long address)
struct stack_segment_linkage *ssptr; struct stack_segment_linkage *ssptr;
/* Register B67 contains the address of the end of the /* Register B67 contains the address of the end of the current stack
current stack segment. If you (as a subprogram) store * segment. If you (as a subprogram) store your registers on the
your registers on the stack and find that you are past * stack and find that you are past the contents of B67, you have
the contents of B67, you have overflowed the segment. * overflowed the segment.
*
B67 also points to the stack segment linkage control * B67 also points to the stack segment linkage control area, which is
area, which is what we are really interested in. */ * what we are really interested in. */
stkl = CRAY_STACKSEG_END(); stkl = CRAY_STACKSEG_END();
ssptr = (struct stack_segment_linkage *)stkl; ssptr = (struct stack_segment_linkage *) stkl;
/* If one subtracts 'size' from the end of the segment, /* If one subtracts 'size' from the end of the segment, one has the
one has the address of the first word of the segment. * address of the first word of the segment.
*
If this is not the first segment, 'pseg' will be * If this is not the first segment, 'pseg' will be nonzero. */
nonzero. */
pseg = ssptr->sspseg; pseg = ssptr->sspseg;
size = ssptr->sssize; size = ssptr->sssize;
this_segment = stkl - size; this_segment = stkl - size;
/* It is possible that calling this routine itself caused /* It is possible that calling this routine itself caused a stack
a stack overflow. Discard stack segments which do not * overflow. Discard stack segments which do not contain the target
contain the target address. */ * address. */
while (!(this_segment <= address && address <= stkl)) { while (!(this_segment <= address && address <= stkl)) {
#ifdef DEBUG_I00AFUNC #ifdef DEBUG_I00AFUNC
fprintf(stderr, "%011o %011o %011o\n", this_segment, address, fprintf(stderr, "%011o %011o %011o\n", this_segment, address,
stkl); stkl);
#endif #endif
if (pseg == 0) if (pseg == 0)
break; break;
stkl = stkl - pseg; stkl = stkl - pseg;
ssptr = (struct stack_segment_linkage *)stkl; ssptr = (struct stack_segment_linkage *) stkl;
size = ssptr->sssize; size = ssptr->sssize;
pseg = ssptr->sspseg; pseg = ssptr->sspseg;
this_segment = stkl - size; this_segment = stkl - size;
@@ -447,24 +443,22 @@ static long i00afunc(long address)
result = address - this_segment; result = address - this_segment;
/* If you subtract pseg from the current end of the stack, /* If you subtract pseg from the current end of the stack, you get the
you get the address of the previous stack segment's end. * address of the previous stack segment's end. This seems a little
This seems a little convoluted to me, but I'll bet you save * convoluted to me, but I'll bet you save a cycle somewhere. */
a cycle somewhere. */
while (pseg != 0) { while (pseg != 0) {
#ifdef DEBUG_I00AFUNC #ifdef DEBUG_I00AFUNC
fprintf(stderr, "%011o %011o\n", pseg, size); fprintf(stderr, "%011o %011o\n", pseg, size);
#endif #endif
stkl = stkl - pseg; stkl = stkl - pseg;
ssptr = (struct stack_segment_linkage *)stkl; ssptr = (struct stack_segment_linkage *) stkl;
size = ssptr->sssize; size = ssptr->sssize;
pseg = ssptr->sspseg; pseg = ssptr->sspseg;
result += size; result += size;
} }
return (result); return (result);
} }
#endif /* not CRAY2 */ #endif /* not CRAY2 */
#endif /* CRAY */ #endif /* CRAY */

View File

@@ -46,7 +46,8 @@ ULONG ulMacroReturnValue;
#define STAT_isMacroArg 2 #define STAT_isMacroArg 2
#define STAT_isREPTBlock 3 #define STAT_isREPTBlock 3
ULONG filesize(char *s) ULONG
filesize(char *s)
{ {
FILE *f; FILE *f;
ULONG size = 0; ULONG size = 0;
@@ -58,7 +59,6 @@ ULONG filesize(char *s)
} }
return (size); return (size);
} }
/* /*
* RGBAsm - FSTACK.C (FileStack routines) * RGBAsm - FSTACK.C (FileStack routines)
* *
@@ -66,7 +66,8 @@ ULONG filesize(char *s)
* *
*/ */
void pushcontext(void) void
pushcontext(void)
{ {
struct sContext **ppFileStack; struct sContext **ppFileStack;
@@ -75,11 +76,11 @@ void pushcontext(void)
ppFileStack = &((*ppFileStack)->pNext); ppFileStack = &((*ppFileStack)->pNext);
if ((*ppFileStack = if ((*ppFileStack =
(struct sContext *)malloc(sizeof(struct sContext))) != NULL) { (struct sContext *) malloc(sizeof(struct sContext))) != NULL) {
(*ppFileStack)->FlexHandle = CurrentFlexHandle; (*ppFileStack)->FlexHandle = CurrentFlexHandle;
(*ppFileStack)->pNext = NULL; (*ppFileStack)->pNext = NULL;
strcpy((char *)(*ppFileStack)->tzFileName, strcpy((char *) (*ppFileStack)->tzFileName,
(char *)tzCurrentFileName); (char *) tzCurrentFileName);
(*ppFileStack)->nLine = nLineNo; (*ppFileStack)->nLine = nLineNo;
switch ((*ppFileStack)->nStatus = nCurrentStatus) { switch ((*ppFileStack)->nStatus = nCurrentStatus) {
case STAT_isMacroArg: case STAT_isMacroArg:
@@ -103,7 +104,8 @@ void pushcontext(void)
fatalerror("No memory for context"); fatalerror("No memory for context");
} }
int popcontext(void) int
popcontext(void)
{ {
struct sContext *pLastFile, **ppLastFile; struct sContext *pLastFile, **ppLastFile;
@@ -112,7 +114,7 @@ int popcontext(void)
yy_delete_buffer(CurrentFlexHandle); yy_delete_buffer(CurrentFlexHandle);
CurrentFlexHandle = CurrentFlexHandle =
yy_scan_bytes(pCurrentREPTBlock, yy_scan_bytes(pCurrentREPTBlock,
nCurrentREPTBlockSize); nCurrentREPTBlockSize);
yy_switch_to_buffer(CurrentFlexHandle); yy_switch_to_buffer(CurrentFlexHandle);
sym_UseCurrentMacroArgs(); sym_UseCurrentMacroArgs();
sym_SetMacroArgID(nMacroCount++); sym_SetMacroArgID(nMacroCount++);
@@ -120,7 +122,6 @@ int popcontext(void)
return (0); return (0);
} }
} }
if ((pLastFile = pFileStack) != NULL) { if ((pLastFile = pFileStack) != NULL) {
ppLastFile = &pFileStack; ppLastFile = &pFileStack;
while (pLastFile->pNext) { while (pLastFile->pNext) {
@@ -140,8 +141,8 @@ int popcontext(void)
nLineNo += 1; nLineNo += 1;
CurrentFlexHandle = pLastFile->FlexHandle; CurrentFlexHandle = pLastFile->FlexHandle;
strcpy((char *)tzCurrentFileName, strcpy((char *) tzCurrentFileName,
(char *)pLastFile->tzFileName); (char *) pLastFile->tzFileName);
switch (nCurrentStatus = pLastFile->nStatus) { switch (nCurrentStatus = pLastFile->nStatus) {
case STAT_isMacroArg: case STAT_isMacroArg:
case STAT_isMacro: case STAT_isMacro:
@@ -167,11 +168,11 @@ int popcontext(void)
return (1); return (1);
} }
int yywrap(void) int
yywrap(void)
{ {
return (popcontext()); return (popcontext());
} }
/* /*
* RGBAsm - FSTACK.C (FileStack routines) * RGBAsm - FSTACK.C (FileStack routines)
* *
@@ -179,7 +180,8 @@ int yywrap(void)
* *
*/ */
void fstk_Dump(void) void
fstk_Dump(void)
{ {
struct sContext *pLastFile; struct sContext *pLastFile;
@@ -192,7 +194,6 @@ void fstk_Dump(void)
printf("%s(%ld)", tzCurrentFileName, nLineNo); printf("%s(%ld)", tzCurrentFileName, nLineNo);
} }
/* /*
* RGBAsm - FSTACK.C (FileStack routines) * RGBAsm - FSTACK.C (FileStack routines)
* *
@@ -200,12 +201,14 @@ void fstk_Dump(void)
* *
*/ */
void fstk_AddIncludePath(char *s) void
fstk_AddIncludePath(char *s)
{ {
strcpy(IncludePaths[NextIncPath++], s); strcpy(IncludePaths[NextIncPath++], s);
} }
void fstk_FindFile(char *s) void
fstk_FindFile(char *s)
{ {
char t[_MAX_PATH + 1]; char t[_MAX_PATH + 1];
SLONG i = -1; SLONG i = -1;
@@ -227,7 +230,6 @@ void fstk_FindFile(char *s)
} }
} }
} }
/* /*
* RGBAsm - FSTACK.C (FileStack routines) * RGBAsm - FSTACK.C (FileStack routines)
* *
@@ -235,16 +237,17 @@ void fstk_FindFile(char *s)
* *
*/ */
ULONG fstk_RunInclude(char *s) ULONG
fstk_RunInclude(char *s)
{ {
FILE *f; FILE *f;
char tzFileName[_MAX_PATH + 1]; char tzFileName[_MAX_PATH + 1];
//printf( "INCLUDE: %s\n", s ); //printf("INCLUDE: %s\n", s);
strcpy(tzFileName, s); strcpy(tzFileName, s);
fstk_FindFile(tzFileName); fstk_FindFile(tzFileName);
//printf( "INCLUDING: %s\n", tzFileName ); //printf("INCLUDING: %s\n", tzFileName);
if ((f = fopen(tzFileName, "rt")) != NULL) { if ((f = fopen(tzFileName, "rt")) != NULL) {
pushcontext(); pushcontext();
@@ -255,16 +258,15 @@ ULONG fstk_RunInclude(char *s)
CurrentFlexHandle = yy_create_buffer(pCurrentFile); CurrentFlexHandle = yy_create_buffer(pCurrentFile);
yy_switch_to_buffer(CurrentFlexHandle); yy_switch_to_buffer(CurrentFlexHandle);
// Dirty hack to give the INCLUDE directive a linefeed //Dirty hack to give the INCLUDE directive a linefeed
yyunput('\n'); yyunput('\n');
nLineNo -= 1; nLineNo -= 1;
return (1); return (1);
} else } else
return (0); return (0);
} }
/* /*
* RGBAsm - FSTACK.C (FileStack routines) * RGBAsm - FSTACK.C (FileStack routines)
* *
@@ -272,7 +274,8 @@ ULONG fstk_RunInclude(char *s)
* *
*/ */
ULONG fstk_RunMacro(char *s) ULONG
fstk_RunMacro(char *s)
{ {
struct sSymbol *sym; struct sSymbol *sym;
@@ -286,13 +289,12 @@ ULONG fstk_RunMacro(char *s)
pCurrentMacro = sym; pCurrentMacro = sym;
CurrentFlexHandle = CurrentFlexHandle =
yy_scan_bytes(pCurrentMacro->pMacro, yy_scan_bytes(pCurrentMacro->pMacro,
pCurrentMacro->ulMacroSize); pCurrentMacro->ulMacroSize);
yy_switch_to_buffer(CurrentFlexHandle); yy_switch_to_buffer(CurrentFlexHandle);
return (1); return (1);
} else } else
return (0); return (0);
} }
/* /*
* RGBAsm - FSTACK.C (FileStack routines) * RGBAsm - FSTACK.C (FileStack routines)
* *
@@ -300,7 +302,8 @@ ULONG fstk_RunMacro(char *s)
* *
*/ */
void fstk_RunMacroArg(SLONG s) void
fstk_RunMacroArg(SLONG s)
{ {
char *sym; char *sym;
@@ -318,7 +321,6 @@ void fstk_RunMacroArg(SLONG s)
} else } else
fatalerror("No such macroargument"); fatalerror("No such macroargument");
} }
/* /*
* RGBAsm - FSTACK.C (FileStack routines) * RGBAsm - FSTACK.C (FileStack routines)
* *
@@ -326,7 +328,8 @@ void fstk_RunMacroArg(SLONG s)
* *
*/ */
void fstk_RunString(char *s) void
fstk_RunString(char *s)
{ {
struct sSymbol *pSym; struct sSymbol *pSym;
@@ -340,7 +343,6 @@ void fstk_RunString(char *s)
} else } else
yyerror("No such string symbol"); yyerror("No such string symbol");
} }
/* /*
* RGBAsm - FSTACK.C (FileStack routines) * RGBAsm - FSTACK.C (FileStack routines)
* *
@@ -348,7 +350,8 @@ void fstk_RunString(char *s)
* *
*/ */
void fstk_RunRept(ULONG count) void
fstk_RunRept(ULONG count)
{ {
if (count) { if (count) {
pushcontext(); pushcontext();
@@ -364,7 +367,6 @@ void fstk_RunRept(ULONG count)
yy_switch_to_buffer(CurrentFlexHandle); yy_switch_to_buffer(CurrentFlexHandle);
} }
} }
/* /*
* RGBAsm - FSTACK.C (FileStack routines) * RGBAsm - FSTACK.C (FileStack routines)
* *
@@ -372,7 +374,8 @@ void fstk_RunRept(ULONG count)
* *
*/ */
ULONG fstk_Init(char *s) ULONG
fstk_Init(char *s)
{ {
char tzFileName[_MAX_PATH + 1]; char tzFileName[_MAX_PATH + 1];

View File

@@ -5,85 +5,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

@@ -16,7 +16,8 @@ UBYTE oDontExpandStrings = 0;
SLONG nGBGfxID = -1; SLONG nGBGfxID = -1;
SLONG nBinaryID = -1; SLONG nBinaryID = -1;
SLONG gbgfx2bin(char ch) SLONG
gbgfx2bin(char ch)
{ {
SLONG i; SLONG i;
@@ -29,7 +30,8 @@ SLONG gbgfx2bin(char ch)
return (0); return (0);
} }
SLONG binary2bin(char ch) SLONG
binary2bin(char ch)
{ {
SLONG i; SLONG i;
@@ -37,13 +39,13 @@ SLONG binary2bin(char ch)
if (CurrentOptions.binary[i] == ch) { if (CurrentOptions.binary[i] == ch) {
return (i); return (i);
} }
} }
return (0); return (0);
} }
SLONG char2bin(char ch) SLONG
char2bin(char ch)
{ {
if (ch >= 'a' && ch <= 'f') if (ch >= 'a' && ch <= 'f')
return (ch - 'a' + 10); return (ch - 'a' + 10);
@@ -59,7 +61,8 @@ SLONG char2bin(char ch)
typedef SLONG(*x2bin) (char ch); typedef SLONG(*x2bin) (char ch);
SLONG ascii2bin(char *s) SLONG
ascii2bin(char *s)
{ {
SLONG radix = 10; SLONG radix = 10;
SLONG result = 0; SLONG result = 0;
@@ -103,7 +106,8 @@ SLONG ascii2bin(char *s)
return (result); return (result);
} }
ULONG ParseFixedPoint(char *s, ULONG size) ULONG
ParseFixedPoint(char *s, ULONG size)
{ {
char dest[256]; char dest[256];
ULONG i = 0, dot = 0; ULONG i = 0, dot = 0;
@@ -128,7 +132,8 @@ ULONG ParseFixedPoint(char *s, ULONG size)
return (1); return (1);
} }
ULONG ParseNumber(char *s, ULONG size) ULONG
ParseNumber(char *s, ULONG size)
{ {
char dest[256]; char dest[256];
@@ -139,7 +144,8 @@ ULONG ParseNumber(char *s, ULONG size)
return (1); return (1);
} }
ULONG ParseSymbol(char *src, ULONG size) ULONG
ParseSymbol(char *src, ULONG size)
{ {
char dest[MAXSYMLEN + 1]; char dest[MAXSYMLEN + 1];
int copied = 0, size_backup = size; int copied = 0, size_backup = size;
@@ -196,7 +202,8 @@ ULONG ParseSymbol(char *src, ULONG size)
} }
} }
ULONG PutMacroArg(char *src, ULONG size) ULONG
PutMacroArg(char *src, ULONG size)
{ {
char *s; char *s;
@@ -209,7 +216,8 @@ ULONG PutMacroArg(char *src, ULONG size)
return (0); return (0);
} }
ULONG PutUniqueArg(char *src, ULONG size) ULONG
PutUniqueArg(char *src, ULONG size)
{ {
src = src; src = src;
yyskipbytes(size); yyskipbytes(size);
@@ -225,119 +233,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},
/* 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 }, {"endm", T_POP_ENDM},
{ "shift", T_POP_SHIFT }, {"shift", T_POP_SHIFT},
{ "rept", T_POP_REPT }, {"rept", T_POP_REPT},
/* Not needed but we have it here just to protect the name */ /* Not needed but we have it here just to protect the name */
{ "endr", T_POP_ENDR }, {"endr", T_POP_ENDR},
{ "if", T_POP_IF }, {"if", T_POP_IF},
{ "else", T_POP_ELSE }, {"else", T_POP_ELSE},
{ "endc", T_POP_ENDC }, {"endc", T_POP_ENDC},
{ "bss", T_SECT_BSS }, {"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 = {
@@ -365,7 +373,8 @@ struct sLexFloat tMacroUniqueToken = {
T_LEX_MACROUNIQUE T_LEX_MACROUNIQUE
}; };
void setuplex(void) void
setuplex(void)
{ {
ULONG id; ULONG id;
@@ -373,62 +382,62 @@ void setuplex(void)
lex_AddStrings(staticstrings); lex_AddStrings(staticstrings);
lex_AddStrings(localstrings); lex_AddStrings(localstrings);
// Macro arguments //Macro arguments
id = lex_FloatAlloc(&tMacroArgToken); id = lex_FloatAlloc(&tMacroArgToken);
lex_FloatAddFirstRange(id, '\\', '\\'); lex_FloatAddFirstRange(id, '\\', '\\');
lex_FloatAddSecondRange(id, '0', '9'); lex_FloatAddSecondRange(id, '0', '9');
id = lex_FloatAlloc(&tMacroUniqueToken); id = lex_FloatAlloc(&tMacroUniqueToken);
lex_FloatAddFirstRange(id, '\\', '\\'); lex_FloatAddFirstRange(id, '\\', '\\');
lex_FloatAddSecondRange(id, '@', '@'); lex_FloatAddSecondRange(id, '@', '@');
// Decimal constants //Decimal constants
id = lex_FloatAlloc(&tNumberToken); id = lex_FloatAlloc(&tNumberToken);
lex_FloatAddFirstRange(id, '0', '9'); lex_FloatAddFirstRange(id, '0', '9');
lex_FloatAddSecondRange(id, '0', '9'); lex_FloatAddSecondRange(id, '0', '9');
lex_FloatAddRange(id, '0', '9'); lex_FloatAddRange(id, '0', '9');
// Binary constants //Binary constants
nBinaryID = id = lex_FloatAlloc(&tNumberToken); nBinaryID = id = lex_FloatAlloc(&tNumberToken);
lex_FloatAddFirstRange(id, '%', '%'); lex_FloatAddFirstRange(id, '%', '%');
lex_FloatAddSecondRange(id, CurrentOptions.binary[0], lex_FloatAddSecondRange(id, CurrentOptions.binary[0],
CurrentOptions.binary[0]); CurrentOptions.binary[0]);
lex_FloatAddSecondRange(id, CurrentOptions.binary[1], lex_FloatAddSecondRange(id, CurrentOptions.binary[1],
CurrentOptions.binary[1]); CurrentOptions.binary[1]);
lex_FloatAddRange(id, CurrentOptions.binary[0], lex_FloatAddRange(id, CurrentOptions.binary[0],
CurrentOptions.binary[0]); CurrentOptions.binary[0]);
lex_FloatAddRange(id, CurrentOptions.binary[1], lex_FloatAddRange(id, CurrentOptions.binary[1],
CurrentOptions.binary[1]); CurrentOptions.binary[1]);
// Octal constants //Octal constants
id = lex_FloatAlloc(&tNumberToken); id = lex_FloatAlloc(&tNumberToken);
lex_FloatAddFirstRange(id, '&', '&'); lex_FloatAddFirstRange(id, '&', '&');
lex_FloatAddSecondRange(id, '0', '7'); lex_FloatAddSecondRange(id, '0', '7');
lex_FloatAddRange(id, '0', '7'); lex_FloatAddRange(id, '0', '7');
// Gameboy gfx constants //Gameboy gfx constants
nGBGfxID = id = lex_FloatAlloc(&tNumberToken); nGBGfxID = id = lex_FloatAlloc(&tNumberToken);
lex_FloatAddFirstRange(id, '`', '`'); lex_FloatAddFirstRange(id, '`', '`');
lex_FloatAddSecondRange(id, CurrentOptions.gbgfx[0], lex_FloatAddSecondRange(id, CurrentOptions.gbgfx[0],
CurrentOptions.gbgfx[0]); CurrentOptions.gbgfx[0]);
lex_FloatAddSecondRange(id, CurrentOptions.gbgfx[1], lex_FloatAddSecondRange(id, CurrentOptions.gbgfx[1],
CurrentOptions.gbgfx[1]); CurrentOptions.gbgfx[1]);
lex_FloatAddSecondRange(id, CurrentOptions.gbgfx[2], lex_FloatAddSecondRange(id, CurrentOptions.gbgfx[2],
CurrentOptions.gbgfx[2]); CurrentOptions.gbgfx[2]);
lex_FloatAddSecondRange(id, CurrentOptions.gbgfx[3], lex_FloatAddSecondRange(id, CurrentOptions.gbgfx[3],
CurrentOptions.gbgfx[3]); CurrentOptions.gbgfx[3]);
lex_FloatAddRange(id, CurrentOptions.gbgfx[0], CurrentOptions.gbgfx[0]); lex_FloatAddRange(id, CurrentOptions.gbgfx[0], CurrentOptions.gbgfx[0]);
lex_FloatAddRange(id, CurrentOptions.gbgfx[1], CurrentOptions.gbgfx[1]); lex_FloatAddRange(id, CurrentOptions.gbgfx[1], CurrentOptions.gbgfx[1]);
lex_FloatAddRange(id, CurrentOptions.gbgfx[2], CurrentOptions.gbgfx[2]); lex_FloatAddRange(id, CurrentOptions.gbgfx[2], CurrentOptions.gbgfx[2]);
lex_FloatAddRange(id, CurrentOptions.gbgfx[3], CurrentOptions.gbgfx[3]); lex_FloatAddRange(id, CurrentOptions.gbgfx[3], CurrentOptions.gbgfx[3]);
// Hex constants //Hex constants
id = lex_FloatAlloc(&tNumberToken); id = lex_FloatAlloc(&tNumberToken);
lex_FloatAddFirstRange(id, '$', '$'); lex_FloatAddFirstRange(id, '$', '$');
lex_FloatAddSecondRange(id, '0', '9'); lex_FloatAddSecondRange(id, '0', '9');
lex_FloatAddSecondRange(id, 'A', 'F'); lex_FloatAddSecondRange(id, 'A', 'F');
@@ -437,9 +446,9 @@ void setuplex(void)
lex_FloatAddRange(id, 'A', 'F'); lex_FloatAddRange(id, 'A', 'F');
lex_FloatAddRange(id, 'a', 'f'); lex_FloatAddRange(id, 'a', 'f');
// ID's //ID 's
id = lex_FloatAlloc(&tIDToken); id = lex_FloatAlloc(&tIDToken);
lex_FloatAddFirstRange(id, 'a', 'z'); lex_FloatAddFirstRange(id, 'a', 'z');
lex_FloatAddFirstRange(id, 'A', 'Z'); lex_FloatAddFirstRange(id, 'A', 'Z');
lex_FloatAddFirstRange(id, '_', '_'); lex_FloatAddFirstRange(id, '_', '_');
@@ -458,9 +467,9 @@ void setuplex(void)
lex_FloatAddRange(id, '@', '@'); lex_FloatAddRange(id, '@', '@');
lex_FloatAddRange(id, '#', '#'); lex_FloatAddRange(id, '#', '#');
// Local ID //Local ID
id = lex_FloatAlloc(&tIDToken); id = lex_FloatAlloc(&tIDToken);
lex_FloatAddFirstRange(id, '.', '.'); lex_FloatAddFirstRange(id, '.', '.');
lex_FloatAddSecondRange(id, 'a', 'z'); lex_FloatAddSecondRange(id, 'a', 'z');
lex_FloatAddSecondRange(id, 'A', 'Z'); lex_FloatAddSecondRange(id, 'A', 'Z');
@@ -473,14 +482,14 @@ void setuplex(void)
lex_FloatAddRange(id, '@', '@'); lex_FloatAddRange(id, '@', '@');
lex_FloatAddRange(id, '#', '#'); lex_FloatAddRange(id, '#', '#');
// @ ID //@ID
id = lex_FloatAlloc(&tIDToken); id = lex_FloatAlloc(&tIDToken);
lex_FloatAddFirstRange(id, '@', '@'); lex_FloatAddFirstRange(id, '@', '@');
// Fixed point constants //Fixed point constants
id = lex_FloatAlloc(&tFixedPointToken); id = lex_FloatAlloc(&tFixedPointToken);
lex_FloatAddFirstRange(id, '.', '.'); lex_FloatAddFirstRange(id, '.', '.');
lex_FloatAddFirstRange(id, '0', '9'); lex_FloatAddFirstRange(id, '0', '9');
lex_FloatAddSecondRange(id, '.', '.'); lex_FloatAddSecondRange(id, '.', '.');

View File

@@ -18,7 +18,6 @@ struct sLexString {
ULONG nNameLength; ULONG nNameLength;
struct sLexString *pNext; struct sLexString *pNext;
}; };
#define pLexBuffer (pCurrentBuffer->pBuffer) #define pLexBuffer (pCurrentBuffer->pBuffer)
#define nLexBufferLeng (pCurrentBuffer->nBufferSize) #define nLexBufferLeng (pCurrentBuffer->nBufferSize)
@@ -41,7 +40,8 @@ enum eLexerState lexerstate = LEX_STATE_NORMAL;
#define AtLineStart pCurrentBuffer->oAtLineStart #define AtLineStart pCurrentBuffer->oAtLineStart
#ifdef __GNUC__ #ifdef __GNUC__
void strupr(char *s) void
strupr(char *s)
{ {
while (*s) { while (*s) {
*s = toupper(*s); *s = toupper(*s);
@@ -49,31 +49,35 @@ void strupr(char *s)
} }
} }
void strlwr(char *s) void
strlwr(char *s)
{ {
while (*s) { while (*s) {
*s = tolower(*s); *s = tolower(*s);
s += 1; s += 1;
} }
} }
#endif #endif
void yyskipbytes(ULONG count) void
yyskipbytes(ULONG count)
{ {
pLexBuffer += count; pLexBuffer += count;
} }
void yyunputbytes(ULONG count) void
yyunputbytes(ULONG count)
{ {
pLexBuffer -= count; pLexBuffer -= count;
} }
void yyunput(char c) void
yyunput(char c)
{ {
*(--pLexBuffer) = c; *(--pLexBuffer) = c;
} }
void yyunputstr(char *s) void
yyunputstr(char *s)
{ {
SLONG i; SLONG i;
@@ -83,31 +87,35 @@ void yyunputstr(char *s)
yyunput(s[i--]); yyunput(s[i--]);
} }
void yy_switch_to_buffer(YY_BUFFER_STATE buf) void
yy_switch_to_buffer(YY_BUFFER_STATE buf)
{ {
pCurrentBuffer = buf; pCurrentBuffer = buf;
} }
void yy_set_state(enum eLexerState i) void
yy_set_state(enum eLexerState i)
{ {
lexerstate = i; lexerstate = i;
} }
void yy_delete_buffer(YY_BUFFER_STATE buf) void
yy_delete_buffer(YY_BUFFER_STATE buf)
{ {
free(buf->pBufferStart - SAFETYMARGIN); free(buf->pBufferStart - SAFETYMARGIN);
free(buf); free(buf);
} }
YY_BUFFER_STATE yy_scan_bytes(char *mem, ULONG size) YY_BUFFER_STATE
yy_scan_bytes(char *mem, ULONG size)
{ {
YY_BUFFER_STATE pBuffer; YY_BUFFER_STATE pBuffer;
if ((pBuffer = if ((pBuffer =
(YY_BUFFER_STATE) malloc(sizeof(struct yy_buffer_state))) != (YY_BUFFER_STATE) malloc(sizeof(struct yy_buffer_state))) !=
NULL) { NULL) {
if ((pBuffer->pBuffer = pBuffer->pBufferStart = if ((pBuffer->pBuffer = pBuffer->pBufferStart =
(char *)malloc(size + 1 + SAFETYMARGIN)) != NULL) { (char *) malloc(size + 1 + SAFETYMARGIN)) != NULL) {
pBuffer->pBuffer += SAFETYMARGIN; pBuffer->pBuffer += SAFETYMARGIN;
pBuffer->pBufferStart += SAFETYMARGIN; pBuffer->pBufferStart += SAFETYMARGIN;
memcpy(pBuffer->pBuffer, mem, size); memcpy(pBuffer->pBuffer, mem, size);
@@ -117,17 +125,17 @@ YY_BUFFER_STATE yy_scan_bytes(char *mem, ULONG size)
return (pBuffer); return (pBuffer);
} }
} }
fatalerror("Out of memory!"); fatalerror("Out of memory!");
return (NULL); return (NULL);
} }
YY_BUFFER_STATE yy_create_buffer(FILE * f) YY_BUFFER_STATE
yy_create_buffer(FILE * f)
{ {
YY_BUFFER_STATE pBuffer; YY_BUFFER_STATE pBuffer;
if ((pBuffer = if ((pBuffer =
(YY_BUFFER_STATE) malloc(sizeof(struct yy_buffer_state))) != (YY_BUFFER_STATE) malloc(sizeof(struct yy_buffer_state))) !=
NULL) { NULL) {
ULONG size; ULONG size;
@@ -136,7 +144,7 @@ YY_BUFFER_STATE yy_create_buffer(FILE * f)
fseek(f, 0, SEEK_SET); fseek(f, 0, SEEK_SET);
if ((pBuffer->pBuffer = pBuffer->pBufferStart = if ((pBuffer->pBuffer = pBuffer->pBufferStart =
(char *)malloc(size + 2 + SAFETYMARGIN)) != NULL) { (char *) malloc(size + 2 + SAFETYMARGIN)) != NULL) {
char *mem; char *mem;
ULONG instring = 0; ULONG instring = 0;
@@ -167,15 +175,15 @@ YY_BUFFER_STATE yy_create_buffer(FILE * f)
mem[0] = '\n'; mem[0] = '\n';
mem += 1; mem += 1;
} else if (mem[0] == '\n' } else if (mem[0] == '\n'
&& mem[1] == '*') { && mem[1] == '*') {
mem += 1; mem += 1;
while (! while (!
(*mem == '\n' (*mem == '\n'
|| *mem == '\0')) || *mem == '\0'))
*mem++ = ' '; *mem++ = ' ';
} else if (*mem == ';') { } else if (*mem == ';') {
while (! while (!
(*mem == '\n' (*mem == '\n'
|| *mem == '\0')) || *mem == '\0'))
*mem++ = ' '; *mem++ = ' ';
} else } else
@@ -187,19 +195,20 @@ YY_BUFFER_STATE yy_create_buffer(FILE * f)
return (pBuffer); return (pBuffer);
} }
} }
fatalerror("Out of memory!"); fatalerror("Out of memory!");
return (NULL); return (NULL);
} }
ULONG lex_FloatAlloc(struct sLexFloat * tok) ULONG
lex_FloatAlloc(struct sLexFloat * tok)
{ {
tLexFloat[nFloating] = (*tok); tLexFloat[nFloating] = (*tok);
return (1 << (nFloating++)); return (1 << (nFloating++));
} }
void lex_FloatDeleteRange(ULONG id, UWORD start, UWORD end) void
lex_FloatDeleteRange(ULONG id, UWORD start, UWORD end)
{ {
while (start <= end) { while (start <= end) {
tFloatingChars[start] &= ~id; tFloatingChars[start] &= ~id;
@@ -207,7 +216,8 @@ void lex_FloatDeleteRange(ULONG id, UWORD start, UWORD end)
} }
} }
void lex_FloatAddRange(ULONG id, UWORD start, UWORD end) void
lex_FloatAddRange(ULONG id, UWORD start, UWORD end)
{ {
while (start <= end) { while (start <= end) {
tFloatingChars[start] |= id; tFloatingChars[start] |= id;
@@ -215,7 +225,8 @@ void lex_FloatAddRange(ULONG id, UWORD start, UWORD end)
} }
} }
void lex_FloatDeleteFirstRange(ULONG id, UWORD start, UWORD end) void
lex_FloatDeleteFirstRange(ULONG id, UWORD start, UWORD end)
{ {
while (start <= end) { while (start <= end) {
tFloatingFirstChar[start] &= ~id; tFloatingFirstChar[start] &= ~id;
@@ -223,7 +234,8 @@ void lex_FloatDeleteFirstRange(ULONG id, UWORD start, UWORD end)
} }
} }
void lex_FloatAddFirstRange(ULONG id, UWORD start, UWORD end) void
lex_FloatAddFirstRange(ULONG id, UWORD start, UWORD end)
{ {
while (start <= end) { while (start <= end) {
tFloatingFirstChar[start] |= id; tFloatingFirstChar[start] |= id;
@@ -231,7 +243,8 @@ void lex_FloatAddFirstRange(ULONG id, UWORD start, UWORD end)
} }
} }
void lex_FloatDeleteSecondRange(ULONG id, UWORD start, UWORD end) void
lex_FloatDeleteSecondRange(ULONG id, UWORD start, UWORD end)
{ {
while (start <= end) { while (start <= end) {
tFloatingSecondChar[start] &= ~id; tFloatingSecondChar[start] &= ~id;
@@ -239,7 +252,8 @@ void lex_FloatDeleteSecondRange(ULONG id, UWORD start, UWORD end)
} }
} }
void lex_FloatAddSecondRange(ULONG id, UWORD start, UWORD end) void
lex_FloatAddSecondRange(ULONG id, UWORD start, UWORD end)
{ {
while (start <= end) { while (start <= end) {
tFloatingSecondChar[start] |= id; tFloatingSecondChar[start] |= id;
@@ -247,7 +261,8 @@ void lex_FloatAddSecondRange(ULONG id, UWORD start, UWORD end)
} }
} }
struct sLexFloat *lexgetfloat(ULONG id) struct sLexFloat *
lexgetfloat(ULONG id)
{ {
ULONG r = 0, mask = 1; ULONG r = 0, mask = 1;
@@ -262,7 +277,8 @@ struct sLexFloat *lexgetfloat(ULONG id)
return (&tLexFloat[r]); return (&tLexFloat[r]);
} }
ULONG lexcalchash(char *s) ULONG
lexcalchash(char *s)
{ {
ULONG r = 0; ULONG r = 0;
@@ -274,7 +290,8 @@ ULONG lexcalchash(char *s)
return (r); return (r);
} }
void lex_Init(void) void
lex_Init(void)
{ {
ULONG i; ULONG i;
@@ -292,7 +309,8 @@ void lex_Init(void)
nFloating = 0; nFloating = 0;
} }
void lex_AddStrings(struct sLexInitString *lex) void
lex_AddStrings(struct sLexInitString * lex)
{ {
while (lex->tzName) { while (lex->tzName) {
struct sLexString **ppHash; struct sLexString **ppHash;
@@ -302,13 +320,13 @@ void lex_AddStrings(struct sLexInitString *lex)
while (*ppHash) while (*ppHash)
ppHash = &((*ppHash)->pNext); ppHash = &((*ppHash)->pNext);
// printf( "%s has hashvalue %d\n", lex->tzName, hash ); //printf("%s has hashvalue %d\n", lex->tzName, hash);
if (((*ppHash) = if (((*ppHash) =
(struct sLexString *)malloc(sizeof(struct sLexString))) != (struct sLexString *) malloc(sizeof(struct sLexString))) !=
NULL) { NULL) {
if (((*ppHash)->tzName = if (((*ppHash)->tzName =
(char *)strdup(lex->tzName)) != NULL) { (char *) strdup(lex->tzName)) != NULL) {
(*ppHash)->nNameLength = strlen(lex->tzName); (*ppHash)->nNameLength = strlen(lex->tzName);
(*ppHash)->nToken = lex->nToken; (*ppHash)->nToken = lex->nToken;
(*ppHash)->pNext = NULL; (*ppHash)->pNext = NULL;
@@ -327,7 +345,8 @@ void lex_AddStrings(struct sLexInitString *lex)
} }
} }
ULONG yylex(void) ULONG
yylex(void)
{ {
ULONG hash, maxlen; ULONG hash, maxlen;
char *s; char *s;
@@ -339,7 +358,7 @@ ULONG yylex(void)
case LEX_STATE_NORMAL: case LEX_STATE_NORMAL:
AtLineStart = 0; AtLineStart = 0;
scanagain: scanagain:
while (*pLexBuffer == ' ' || *pLexBuffer == '\t') { while (*pLexBuffer == ' ' || *pLexBuffer == '\t') {
linestart = 0; linestart = 0;
@@ -353,7 +372,6 @@ ULONG yylex(void)
goto scanagain; goto scanagain;
} }
} }
s = pLexBuffer; s = pLexBuffer;
nOldFloatMask = nFloatLen = 0; nOldFloatMask = nFloatLen = 0;
nFloatMask = tFloatingFirstChar[(int) *s++]; nFloatMask = tFloatingFirstChar[(int) *s++];
@@ -385,14 +403,13 @@ ULONG yylex(void)
if (lex->nNameLength == yyleng) { if (lex->nNameLength == yyleng) {
if (strnicmp if (strnicmp
(pLexBuffer, lex->tzName, (pLexBuffer, lex->tzName,
yyleng) == 0) { yyleng) == 0) {
pLongestFixed = lex; pLongestFixed = lex;
} }
} }
lex = lex->pNext; lex = lex->pNext;
} }
} }
} }
if (nFloatLen == 0 && pLongestFixed == NULL) { if (nFloatLen == 0 && pLongestFixed == NULL) {
@@ -401,7 +418,7 @@ ULONG yylex(void)
pLexBuffer += 1; pLexBuffer += 1;
while ((*pLexBuffer != '"') while ((*pLexBuffer != '"')
&& (*pLexBuffer != '\n')) { && (*pLexBuffer != '\n')) {
char ch, *marg; char ch, *marg;
if ((ch = *pLexBuffer++) == '\\') { if ((ch = *pLexBuffer++) == '\\') {
@@ -423,9 +440,9 @@ ULONG yylex(void)
case '8': case '8':
case '9': case '9':
if ((marg = if ((marg =
sym_FindMacroArg(ch sym_FindMacroArg(ch
- -
'0')) '0'))
!= NULL) { != NULL) {
while (*marg) while (*marg)
yylval. yylval.
@@ -438,8 +455,8 @@ ULONG yylex(void)
break; break;
case '@': case '@':
if ((marg = if ((marg =
sym_FindMacroArg sym_FindMacroArg
(-1)) != NULL) { (-1)) != NULL) {
while (*marg) while (*marg)
yylval. yylval.
tzString tzString
@@ -455,15 +472,14 @@ ULONG yylex(void)
int i = 0; int i = 0;
while ((*pLexBuffer != '}') while ((*pLexBuffer != '}')
&& (*pLexBuffer != '"') && (*pLexBuffer != '"')
&& (*pLexBuffer != && (*pLexBuffer !=
'\n')) { '\n')) {
if ((ch = if ((ch =
*pLexBuffer++) == *pLexBuffer++) ==
'\\') { '\\') {
switch (ch = switch (ch =
(*pLexBuffer++)) (*pLexBuffer++)) {
{
case '0': case '0':
case '1': case '1':
case '2': case '2':
@@ -497,16 +513,15 @@ ULONG yylex(void)
sym[i] = 0; sym[i] = 0;
index += index +=
symvaluetostring(&yylval. symvaluetostring(&yylval.
tzString tzString
[index], [index],
sym); sym);
if (*pLexBuffer == '}') if (*pLexBuffer == '}')
pLexBuffer += 1; pLexBuffer += 1;
else else
yyerror("Missing }"); yyerror("Missing }");
ch = 0; ch = 0;
} }
if (ch) if (ch)
yylval.tzString[index++] = ch; yylval.tzString[index++] = ch;
} }
@@ -526,7 +541,7 @@ ULONG yylex(void)
pLexBuffer += 1; pLexBuffer += 1;
while ((*pLexBuffer != '}') while ((*pLexBuffer != '}')
&& (*pLexBuffer != '\n')) { && (*pLexBuffer != '\n')) {
if ((ch = *pLexBuffer++) == '\\') { if ((ch = *pLexBuffer++) == '\\') {
switch (ch = (*pLexBuffer++)) { switch (ch = (*pLexBuffer++)) {
case '0': case '0':
@@ -540,9 +555,9 @@ ULONG yylex(void)
case '8': case '8':
case '9': case '9':
if ((marg = if ((marg =
sym_FindMacroArg(ch sym_FindMacroArg(ch
- -
'0')) '0'))
!= NULL) { != NULL) {
while (*marg) while (*marg)
sym[i++] sym[i++]
@@ -553,8 +568,8 @@ ULONG yylex(void)
break; break;
case '@': case '@':
if ((marg = if ((marg =
sym_FindMacroArg sym_FindMacroArg
(-1)) != NULL) { (-1)) != NULL) {
while (*marg) while (*marg)
sym[i++] sym[i++]
= =
@@ -582,13 +597,11 @@ ULONG yylex(void)
return (*pLexBuffer++); return (*pLexBuffer++);
} }
} }
if (nFloatLen == 0) { if (nFloatLen == 0) {
yyleng = pLongestFixed->nNameLength; yyleng = pLongestFixed->nNameLength;
pLexBuffer += yyleng; pLexBuffer += yyleng;
return (pLongestFixed->nToken); return (pLongestFixed->nToken);
} }
if (pLongestFixed == NULL) { if (pLongestFixed == NULL) {
struct sLexFloat *tok; struct sLexFloat *tok;
@@ -598,7 +611,6 @@ ULONG yylex(void)
if (tok->Callback(pLexBuffer, yyleng) == 0) if (tok->Callback(pLexBuffer, yyleng) == 0)
goto scanagain; goto scanagain;
} }
if (tok->nToken == T_ID && linestart) { if (tok->nToken == T_ID && linestart) {
pLexBuffer += yyleng; pLexBuffer += yyleng;
return (T_LABEL); return (T_LABEL);
@@ -607,7 +619,6 @@ ULONG yylex(void)
return (tok->nToken); return (tok->nToken);
} }
} }
if (nFloatLen > pLongestFixed->nNameLength) { if (nFloatLen > pLongestFixed->nNameLength) {
struct sLexFloat *tok; struct sLexFloat *tok;
@@ -617,7 +628,6 @@ ULONG yylex(void)
if (tok->Callback(pLexBuffer, yyleng) == 0) if (tok->Callback(pLexBuffer, yyleng) == 0)
goto scanagain; goto scanagain;
} }
if (tok->nToken == T_ID && linestart) { if (tok->nToken == T_ID && linestart) {
pLexBuffer += yyleng; pLexBuffer += yyleng;
return (T_LABEL); return (T_LABEL);
@@ -642,7 +652,7 @@ ULONG yylex(void)
} }
while ((*pLexBuffer != ',') while ((*pLexBuffer != ',')
&& (*pLexBuffer != '\n')) { && (*pLexBuffer != '\n')) {
char ch, *marg; char ch, *marg;
if ((ch = *pLexBuffer++) == '\\') { if ((ch = *pLexBuffer++) == '\\') {
@@ -664,8 +674,8 @@ ULONG yylex(void)
case '8': case '8':
case '9': case '9':
if ((marg = if ((marg =
sym_FindMacroArg(ch - sym_FindMacroArg(ch -
'0')) != '0')) !=
NULL) { NULL) {
while (*marg) while (*marg)
yylval. yylval.
@@ -677,7 +687,7 @@ ULONG yylex(void)
break; break;
case '@': case '@':
if ((marg = if ((marg =
sym_FindMacroArg(-1)) != sym_FindMacroArg(-1)) !=
NULL) { NULL) {
while (*marg) while (*marg)
yylval. yylval.
@@ -693,13 +703,12 @@ ULONG yylex(void)
int i = 0; int i = 0;
while ((*pLexBuffer != '}') while ((*pLexBuffer != '}')
&& (*pLexBuffer != '"') && (*pLexBuffer != '"')
&& (*pLexBuffer != '\n')) { && (*pLexBuffer != '\n')) {
if ((ch = if ((ch =
*pLexBuffer++) == '\\') { *pLexBuffer++) == '\\') {
switch (ch = switch (ch =
(*pLexBuffer++)) (*pLexBuffer++)) {
{
case '0': case '0':
case '1': case '1':
case '2': case '2':
@@ -711,9 +720,9 @@ ULONG yylex(void)
case '8': case '8':
case '9': case '9':
if ((marg = if ((marg =
sym_FindMacroArg sym_FindMacroArg
(ch - (ch -
'0')) != '0')) !=
NULL) { NULL) {
while while
(*marg) (*marg)
@@ -723,8 +732,8 @@ ULONG yylex(void)
break; break;
case '@': case '@':
if ((marg = if ((marg =
sym_FindMacroArg sym_FindMacroArg
(-1)) != (-1)) !=
NULL) { NULL) {
while while
(*marg) (*marg)
@@ -739,15 +748,14 @@ ULONG yylex(void)
sym[i] = 0; sym[i] = 0;
index += index +=
symvaluetostring(&yylval. symvaluetostring(&yylval.
tzString[index], tzString[index],
sym); sym);
if (*pLexBuffer == '}') if (*pLexBuffer == '}')
pLexBuffer += 1; pLexBuffer += 1;
else else
yyerror("Missing }"); yyerror("Missing }");
ch = 0; ch = 0;
} }
if (ch) if (ch)
yylval.tzString[index++] = ch; yylval.tzString[index++] = ch;
} }

View File

@@ -56,73 +56,71 @@ struct sOptionStackEntry {
struct sOptionStackEntry *pOptionStack = NULL; struct sOptionStackEntry *pOptionStack = NULL;
void opt_SetCurrentOptions(struct sOptions *pOpt) void
opt_SetCurrentOptions(struct sOptions * pOpt)
{ {
if (nGBGfxID != -1) { if (nGBGfxID != -1) {
lex_FloatDeleteRange(nGBGfxID, CurrentOptions.gbgfx[0], lex_FloatDeleteRange(nGBGfxID, CurrentOptions.gbgfx[0],
CurrentOptions.gbgfx[0]); CurrentOptions.gbgfx[0]);
lex_FloatDeleteRange(nGBGfxID, CurrentOptions.gbgfx[1], lex_FloatDeleteRange(nGBGfxID, CurrentOptions.gbgfx[1],
CurrentOptions.gbgfx[1]); CurrentOptions.gbgfx[1]);
lex_FloatDeleteRange(nGBGfxID, CurrentOptions.gbgfx[2], lex_FloatDeleteRange(nGBGfxID, CurrentOptions.gbgfx[2],
CurrentOptions.gbgfx[2]); CurrentOptions.gbgfx[2]);
lex_FloatDeleteRange(nGBGfxID, CurrentOptions.gbgfx[3], lex_FloatDeleteRange(nGBGfxID, CurrentOptions.gbgfx[3],
CurrentOptions.gbgfx[3]); CurrentOptions.gbgfx[3]);
lex_FloatDeleteSecondRange(nGBGfxID, CurrentOptions.gbgfx[0], lex_FloatDeleteSecondRange(nGBGfxID, CurrentOptions.gbgfx[0],
CurrentOptions.gbgfx[0]); CurrentOptions.gbgfx[0]);
lex_FloatDeleteSecondRange(nGBGfxID, CurrentOptions.gbgfx[1], lex_FloatDeleteSecondRange(nGBGfxID, CurrentOptions.gbgfx[1],
CurrentOptions.gbgfx[1]); CurrentOptions.gbgfx[1]);
lex_FloatDeleteSecondRange(nGBGfxID, CurrentOptions.gbgfx[2], lex_FloatDeleteSecondRange(nGBGfxID, CurrentOptions.gbgfx[2],
CurrentOptions.gbgfx[2]); CurrentOptions.gbgfx[2]);
lex_FloatDeleteSecondRange(nGBGfxID, CurrentOptions.gbgfx[3], lex_FloatDeleteSecondRange(nGBGfxID, CurrentOptions.gbgfx[3],
CurrentOptions.gbgfx[3]); CurrentOptions.gbgfx[3]);
} }
if (nBinaryID != -1) { if (nBinaryID != -1) {
lex_FloatDeleteRange(nBinaryID, CurrentOptions.binary[0], lex_FloatDeleteRange(nBinaryID, CurrentOptions.binary[0],
CurrentOptions.binary[0]); CurrentOptions.binary[0]);
lex_FloatDeleteRange(nBinaryID, CurrentOptions.binary[1], lex_FloatDeleteRange(nBinaryID, CurrentOptions.binary[1],
CurrentOptions.binary[1]); CurrentOptions.binary[1]);
lex_FloatDeleteSecondRange(nBinaryID, CurrentOptions.binary[0], lex_FloatDeleteSecondRange(nBinaryID, CurrentOptions.binary[0],
CurrentOptions.binary[0]); CurrentOptions.binary[0]);
lex_FloatDeleteSecondRange(nBinaryID, CurrentOptions.binary[1], lex_FloatDeleteSecondRange(nBinaryID, CurrentOptions.binary[1],
CurrentOptions.binary[1]); CurrentOptions.binary[1]);
} }
CurrentOptions = *pOpt; CurrentOptions = *pOpt;
if (nGBGfxID != -1) { if (nGBGfxID != -1) {
lex_FloatAddRange(nGBGfxID, CurrentOptions.gbgfx[0], lex_FloatAddRange(nGBGfxID, CurrentOptions.gbgfx[0],
CurrentOptions.gbgfx[0]); CurrentOptions.gbgfx[0]);
lex_FloatAddRange(nGBGfxID, CurrentOptions.gbgfx[1], lex_FloatAddRange(nGBGfxID, CurrentOptions.gbgfx[1],
CurrentOptions.gbgfx[1]); CurrentOptions.gbgfx[1]);
lex_FloatAddRange(nGBGfxID, CurrentOptions.gbgfx[2], lex_FloatAddRange(nGBGfxID, CurrentOptions.gbgfx[2],
CurrentOptions.gbgfx[2]); CurrentOptions.gbgfx[2]);
lex_FloatAddRange(nGBGfxID, CurrentOptions.gbgfx[3], lex_FloatAddRange(nGBGfxID, CurrentOptions.gbgfx[3],
CurrentOptions.gbgfx[3]); CurrentOptions.gbgfx[3]);
lex_FloatAddSecondRange(nGBGfxID, CurrentOptions.gbgfx[0], lex_FloatAddSecondRange(nGBGfxID, CurrentOptions.gbgfx[0],
CurrentOptions.gbgfx[0]); CurrentOptions.gbgfx[0]);
lex_FloatAddSecondRange(nGBGfxID, CurrentOptions.gbgfx[1], lex_FloatAddSecondRange(nGBGfxID, CurrentOptions.gbgfx[1],
CurrentOptions.gbgfx[1]); CurrentOptions.gbgfx[1]);
lex_FloatAddSecondRange(nGBGfxID, CurrentOptions.gbgfx[2], lex_FloatAddSecondRange(nGBGfxID, CurrentOptions.gbgfx[2],
CurrentOptions.gbgfx[2]); CurrentOptions.gbgfx[2]);
lex_FloatAddSecondRange(nGBGfxID, CurrentOptions.gbgfx[3], lex_FloatAddSecondRange(nGBGfxID, CurrentOptions.gbgfx[3],
CurrentOptions.gbgfx[3]); CurrentOptions.gbgfx[3]);
} }
if (nBinaryID != -1) { if (nBinaryID != -1) {
lex_FloatAddRange(nBinaryID, CurrentOptions.binary[0], lex_FloatAddRange(nBinaryID, CurrentOptions.binary[0],
CurrentOptions.binary[0]); CurrentOptions.binary[0]);
lex_FloatAddRange(nBinaryID, CurrentOptions.binary[1], lex_FloatAddRange(nBinaryID, CurrentOptions.binary[1],
CurrentOptions.binary[1]); CurrentOptions.binary[1]);
lex_FloatAddSecondRange(nBinaryID, CurrentOptions.binary[0], lex_FloatAddSecondRange(nBinaryID, CurrentOptions.binary[0],
CurrentOptions.binary[0]); CurrentOptions.binary[0]);
lex_FloatAddSecondRange(nBinaryID, CurrentOptions.binary[1], lex_FloatAddSecondRange(nBinaryID, CurrentOptions.binary[1],
CurrentOptions.binary[1]); CurrentOptions.binary[1]);
} }
} }
void opt_Parse(char *s) void
opt_Parse(char *s)
{ {
struct sOptions newopt; struct sOptions newopt;
@@ -197,13 +195,14 @@ void opt_Parse(char *s)
opt_SetCurrentOptions(&newopt); opt_SetCurrentOptions(&newopt);
} }
void opt_Push(void) void
opt_Push(void)
{ {
struct sOptionStackEntry *pOpt; struct sOptionStackEntry *pOpt;
if ((pOpt = if ((pOpt =
(struct sOptionStackEntry *) (struct sOptionStackEntry *)
malloc(sizeof(struct sOptionStackEntry))) != NULL) { malloc(sizeof(struct sOptionStackEntry))) != NULL) {
pOpt->Options = CurrentOptions; pOpt->Options = CurrentOptions;
pOpt->pNext = pOptionStack; pOpt->pNext = pOptionStack;
pOptionStack = pOpt; pOptionStack = pOpt;
@@ -211,7 +210,8 @@ void opt_Push(void)
fatalerror("No memory for option stack"); fatalerror("No memory for option stack");
} }
void opt_Pop(void) void
opt_Pop(void)
{ {
if (pOptionStack) { if (pOptionStack) {
struct sOptionStackEntry *pOpt; struct sOptionStackEntry *pOpt;
@@ -223,7 +223,6 @@ void opt_Pop(void)
} else } else
fatalerror("No entries in the option stack"); fatalerror("No entries in the option stack");
} }
/* /*
* RGBAsm - MAIN.C * RGBAsm - MAIN.C
* *
@@ -231,7 +230,8 @@ void opt_Pop(void)
* *
*/ */
void yyerror(char *s) void
yyerror(char *s)
{ {
printf("*ERROR*\t"); printf("*ERROR*\t");
fstk_Dump(); fstk_Dump();
@@ -239,12 +239,12 @@ void yyerror(char *s)
nErrors += 1; nErrors += 1;
} }
void fatalerror(char *s) void
fatalerror(char *s)
{ {
yyerror(s); yyerror(s);
exit(5); exit(5);
} }
/* /*
* RGBAsm - MAIN.C * RGBAsm - MAIN.C
* *
@@ -252,10 +252,11 @@ void fatalerror(char *s)
* *
*/ */
void PrintUsage(void) void
PrintUsage(void)
{ {
printf(APPNAME " v" ASM_VERSION " (part of ASMotor " ASMOTOR_VERSION printf(APPNAME " v" ASM_VERSION " (part of ASMotor " ASMOTOR_VERSION
")\n\nUsage: " EXENAME " [options] asmfile\n"); ")\n\nUsage: " EXENAME " [options] asmfile\n");
printf("Options:\n"); printf("Options:\n");
printf("\t-h\t\tThis text\n"); printf("\t-h\t\tThis text\n");
printf("\t-i<path>\tExtra include path\n"); printf("\t-i<path>\tExtra include path\n");
@@ -263,16 +264,15 @@ void PrintUsage(void)
printf("\t-e(l|b)\t\tChange endianness (CAUTION!)\n"); printf("\t-e(l|b)\t\tChange endianness (CAUTION!)\n");
printf printf
("\t-g<ASCI>\tChange the four characters used for Gameboy graphics\n" ("\t-g<ASCI>\tChange the four characters used for Gameboy graphics\n"
"\t\t\tconstants (default is 0123)\n"); "\t\t\tconstants (default is 0123)\n");
printf printf
("\t-b<AS>\t\tChange the two characters used for binary constants\n" ("\t-b<AS>\t\tChange the two characters used for binary constants\n"
"\t\t\t(default is 01)\n"); "\t\t\t(default is 01)\n");
printf printf
("\t-z<hx>\t\tSet the byte value (hex format) used for uninitialised\n" ("\t-z<hx>\t\tSet the byte value (hex format) used for uninitialised\n"
"\t\t\tdata (default is ? for random)\n"); "\t\t\tdata (default is ? for random)\n");
exit(0); exit(0);
} }
/* /*
* RGBAsm - MAIN.C * RGBAsm - MAIN.C
* *
@@ -280,7 +280,8 @@ void PrintUsage(void)
* *
*/ */
int main(int argc, char *argv[]) int
main(int argc, char *argv[])
{ {
char *tzMainfile; char *tzMainfile;
int argn = 1; int argn = 1;
@@ -299,8 +300,9 @@ int main(int argc, char *argv[])
DefaultOptions.gbgfx[3] = '3'; DefaultOptions.gbgfx[3] = '3';
DefaultOptions.binary[0] = '0'; DefaultOptions.binary[0] = '0';
DefaultOptions.binary[1] = '1'; DefaultOptions.binary[1] = '1';
DefaultOptions.fillchar = -1; // fill uninitialised data with random values DefaultOptions.fillchar = -1;
opt_SetCurrentOptions(&DefaultOptions); //fill uninitialised data with random values
opt_SetCurrentOptions(&DefaultOptions);
while (argv[argn][0] == '-' && argc) { while (argv[argn][0] == '-' && argc) {
switch (argv[argn][1]) { switch (argv[argn][1]) {
@@ -321,7 +323,7 @@ int main(int argc, char *argv[])
break; break;
default: default:
printf("*ERROR*\t :\n\tUnknown option '%c'\n", printf("*ERROR*\t :\n\tUnknown option '%c'\n",
argv[argn][1]); argv[argn][1]);
exit(5); exit(5);
break; break;
} }
@@ -331,8 +333,7 @@ int main(int argc, char *argv[])
DefaultOptions = CurrentOptions; DefaultOptions = CurrentOptions;
/*tzMainfile=argv[argn++]; /* tzMainfile=argv[argn++]; argc-=1; */
* argc-=1; */
tzMainfile = argv[argn]; tzMainfile = argv[argn];
setuplex(); setuplex();
@@ -375,36 +376,36 @@ int main(int argc, char *argv[])
nEndClock = clock(); nEndClock = clock();
timespent = timespent =
((double)(nEndClock - nStartClock)) ((double) (nEndClock - nStartClock))
/ (double)CLOCKS_PER_SEC; / (double) CLOCKS_PER_SEC;
printf printf
("Success! %ld lines in %d.%02d seconds ", ("Success! %ld lines in %d.%02d seconds ",
nTotalLines, (int)timespent, nTotalLines, (int) timespent,
((int)(timespent * 100.0)) % 100); ((int) (timespent * 100.0)) % 100);
if (timespent == 0) if (timespent == 0)
printf printf
("(INFINITY lines/minute)\n"); ("(INFINITY lines/minute)\n");
else else
printf("(%d lines/minute)\n", printf("(%d lines/minute)\n",
(int)(60 / timespent * (int) (60 / timespent *
nTotalLines)); nTotalLines));
out_WriteObject(); out_WriteObject();
} else { } else {
printf printf
("Assembly aborted in pass 2 (%ld errors)!\n", ("Assembly aborted in pass 2 (%ld errors)!\n",
nErrors); nErrors);
//sym_PrintSymbolTable(); //sym_PrintSymbolTable();
exit(5); exit(5);
} }
} else { } else {
printf printf
("*ERROR*\t:\tUnterminated IF construct (%ld levels)!\n", ("*ERROR*\t:\tUnterminated IF construct (%ld levels)!\n",
nIFDepth); nIFDepth);
exit(5); exit(5);
} }
} else { } else {
printf("Assembly aborted in pass 1 (%ld errors)!\n", printf("Assembly aborted in pass 1 (%ld errors)!\n",
nErrors); nErrors);
exit(5); exit(5);
} }
} else { } else {

View File

@@ -25,11 +25,11 @@
* *
*/ */
void math_DefinePI(void) void
math_DefinePI(void)
{ {
sym_AddEqu("_PI", double2fix(PI)); sym_AddEqu("_PI", double2fix(PI));
} }
/* /*
* RGBAsm - MATH.C (Fixedpoint math routines) * RGBAsm - MATH.C (Fixedpoint math routines)
* *
@@ -37,16 +37,16 @@ void math_DefinePI(void)
* *
*/ */
void math_Print(SLONG i) void
math_Print(SLONG i)
{ {
if (i >= 0) if (i >= 0)
printf("%ld.%05ld", i >> 16, printf("%ld.%05ld", i >> 16,
((SLONG) (fix2double(i) * 100000 + 0.5)) % 100000); ((SLONG) (fix2double(i) * 100000 + 0.5)) % 100000);
else else
printf("-%ld.%05ld", (-i) >> 16, printf("-%ld.%05ld", (-i) >> 16,
((SLONG) (fix2double(-i) * 100000 + 0.5)) % 100000); ((SLONG) (fix2double(-i) * 100000 + 0.5)) % 100000);
} }
/* /*
* RGBAsm - MATH.C (Fixedpoint math routines) * RGBAsm - MATH.C (Fixedpoint math routines)
* *
@@ -54,11 +54,11 @@ void math_Print(SLONG i)
* *
*/ */
SLONG math_Sin(SLONG i) SLONG
math_Sin(SLONG i)
{ {
return (double2fix(sin(fix2double(i) * 2 * PI / 65536))); return (double2fix(sin(fix2double(i) * 2 * PI / 65536)));
} }
/* /*
* RGBAsm - MATH.C (Fixedpoint math routines) * RGBAsm - MATH.C (Fixedpoint math routines)
* *
@@ -66,11 +66,11 @@ SLONG math_Sin(SLONG i)
* *
*/ */
SLONG math_Cos(SLONG i) SLONG
math_Cos(SLONG i)
{ {
return (double2fix(cos(fix2double(i) * 2 * PI / 65536))); return (double2fix(cos(fix2double(i) * 2 * PI / 65536)));
} }
/* /*
* RGBAsm - MATH.C (Fixedpoint math routines) * RGBAsm - MATH.C (Fixedpoint math routines)
* *
@@ -78,11 +78,11 @@ SLONG math_Cos(SLONG i)
* *
*/ */
SLONG math_Tan(SLONG i) SLONG
math_Tan(SLONG i)
{ {
return (double2fix(tan(fix2double(i) * 2 * PI / 65536))); return (double2fix(tan(fix2double(i) * 2 * PI / 65536)));
} }
/* /*
* RGBAsm - MATH.C (Fixedpoint math routines) * RGBAsm - MATH.C (Fixedpoint math routines)
* *
@@ -90,11 +90,11 @@ SLONG math_Tan(SLONG i)
* *
*/ */
SLONG math_ASin(SLONG i) SLONG
math_ASin(SLONG i)
{ {
return (double2fix(asin(fix2double(i)) / 2 / PI * 65536)); return (double2fix(asin(fix2double(i)) / 2 / PI * 65536));
} }
/* /*
* RGBAsm - MATH.C (Fixedpoint math routines) * RGBAsm - MATH.C (Fixedpoint math routines)
* *
@@ -102,11 +102,11 @@ SLONG math_ASin(SLONG i)
* *
*/ */
SLONG math_ACos(SLONG i) SLONG
math_ACos(SLONG i)
{ {
return (double2fix(acos(fix2double(i)) / 2 / PI * 65536)); return (double2fix(acos(fix2double(i)) / 2 / PI * 65536));
} }
/* /*
* RGBAsm - MATH.C (Fixedpoint math routines) * RGBAsm - MATH.C (Fixedpoint math routines)
* *
@@ -114,11 +114,11 @@ SLONG math_ACos(SLONG i)
* *
*/ */
SLONG math_ATan(SLONG i) SLONG
math_ATan(SLONG i)
{ {
return (double2fix(atan(fix2double(i)) / 2 / PI * 65536)); return (double2fix(atan(fix2double(i)) / 2 / PI * 65536));
} }
/* /*
* RGBAsm - MATH.C (Fixedpoint math routines) * RGBAsm - MATH.C (Fixedpoint math routines)
* *
@@ -126,12 +126,12 @@ SLONG math_ATan(SLONG i)
* *
*/ */
SLONG math_ATan2(SLONG i, SLONG j) SLONG
math_ATan2(SLONG i, SLONG j)
{ {
return (double2fix return (double2fix
(atan2(fix2double(i), fix2double(j)) / 2 / PI * 65536)); (atan2(fix2double(i), fix2double(j)) / 2 / PI * 65536));
} }
/* /*
* RGBAsm - MATH.C (Fixedpoint math routines) * RGBAsm - MATH.C (Fixedpoint math routines)
* *
@@ -139,11 +139,11 @@ SLONG math_ATan2(SLONG i, SLONG j)
* *
*/ */
SLONG math_Mul(SLONG i, SLONG j) SLONG
math_Mul(SLONG i, SLONG j)
{ {
return (double2fix(fix2double(i) * fix2double(j))); return (double2fix(fix2double(i) * fix2double(j)));
} }
/* /*
* RGBAsm - MATH.C (Fixedpoint math routines) * RGBAsm - MATH.C (Fixedpoint math routines)
* *
@@ -151,7 +151,8 @@ SLONG math_Mul(SLONG i, SLONG j)
* *
*/ */
SLONG math_Div(SLONG i, SLONG j) SLONG
math_Div(SLONG i, SLONG j)
{ {
return (double2fix(fix2double(i) / fix2double(j))); return (double2fix(fix2double(i) / fix2double(j)));
} }

View File

@@ -26,7 +26,7 @@
* *
*/ */
void out_SetCurrentSection(struct Section *pSect); void out_SetCurrentSection(struct Section * pSect);
struct Patch { struct Patch {
char tzFilename[_MAX_PATH + 1]; char tzFilename[_MAX_PATH + 1];
@@ -48,7 +48,6 @@ struct SectionStackEntry {
struct Section *pSection; struct Section *pSection;
struct SectionStackEntry *pNext; struct SectionStackEntry *pNext;
}; };
/* /*
* RGBAsm - OUTPUT.C - Outputs an objectfile * RGBAsm - OUTPUT.C - Outputs an objectfile
* *
@@ -68,13 +67,14 @@ struct SectionStackEntry *pSectionStack = NULL;
* *
*/ */
void out_PushSection(void) void
out_PushSection(void)
{ {
struct SectionStackEntry *pSect; struct SectionStackEntry *pSect;
if ((pSect = if ((pSect =
(struct SectionStackEntry *) (struct SectionStackEntry *)
malloc(sizeof(struct SectionStackEntry))) != NULL) { malloc(sizeof(struct SectionStackEntry))) != NULL) {
pSect->pSection = pCurrentSection; pSect->pSection = pCurrentSection;
pSect->pNext = pSectionStack; pSect->pNext = pSectionStack;
pSectionStack = pSect; pSectionStack = pSect;
@@ -82,7 +82,8 @@ void out_PushSection(void)
fatalerror("No memory for section stack"); fatalerror("No memory for section stack");
} }
void out_PopSection(void) void
out_PopSection(void)
{ {
if (pSectionStack) { if (pSectionStack) {
struct SectionStackEntry *pSect; struct SectionStackEntry *pSect;
@@ -94,7 +95,6 @@ void out_PopSection(void)
} else } else
fatalerror("No entries in the section stack"); fatalerror("No entries in the section stack");
} }
/* /*
* RGBAsm - OUTPUT.C - Outputs an objectfile * RGBAsm - OUTPUT.C - Outputs an objectfile
* *
@@ -102,7 +102,8 @@ void out_PopSection(void)
* *
*/ */
ULONG countsymbols(void) ULONG
countsymbols(void)
{ {
struct PatchSymbol *pSym; struct PatchSymbol *pSym;
ULONG count = 0; ULONG count = 0;
@@ -116,7 +117,6 @@ ULONG countsymbols(void)
return (count); return (count);
} }
/* /*
* RGBAsm - OUTPUT.C - Outputs an objectfile * RGBAsm - OUTPUT.C - Outputs an objectfile
* *
@@ -124,7 +124,8 @@ ULONG countsymbols(void)
* *
*/ */
ULONG countsections(void) ULONG
countsections(void)
{ {
struct Section *pSect; struct Section *pSect;
ULONG count = 0; ULONG count = 0;
@@ -138,7 +139,6 @@ ULONG countsections(void)
return (count); return (count);
} }
/* /*
* RGBAsm - OUTPUT.C - Outputs an objectfile * RGBAsm - OUTPUT.C - Outputs an objectfile
* *
@@ -146,7 +146,8 @@ ULONG countsections(void)
* *
*/ */
ULONG countpatches(struct Section * pSect) ULONG
countpatches(struct Section * pSect)
{ {
struct Patch *pPatch; struct Patch *pPatch;
ULONG r = 0; ULONG r = 0;
@@ -159,7 +160,6 @@ ULONG countpatches(struct Section * pSect)
return (r); return (r);
} }
/* /*
* RGBAsm - OUTPUT.C - Outputs an objectfile * RGBAsm - OUTPUT.C - Outputs an objectfile
* *
@@ -167,14 +167,14 @@ ULONG countpatches(struct Section * pSect)
* *
*/ */
void fputlong(ULONG i, FILE * f) void
fputlong(ULONG i, FILE * f)
{ {
fputc(i, f); fputc(i, f);
fputc(i >> 8, f); fputc(i >> 8, f);
fputc(i >> 16, f); fputc(i >> 16, f);
fputc(i >> 24, f); fputc(i >> 24, f);
} }
/* /*
* RGBAsm - OUTPUT.C - Outputs an objectfile * RGBAsm - OUTPUT.C - Outputs an objectfile
* *
@@ -182,13 +182,13 @@ void fputlong(ULONG i, FILE * f)
* *
*/ */
void fputstring(char *s, FILE * f) void
fputstring(char *s, FILE * f)
{ {
while (*s) while (*s)
fputc(*s++, f); fputc(*s++, f);
fputc(0, f); fputc(0, f);
} }
/* /*
* RGBAsm - OUTPUT.C - Outputs an objectfile * RGBAsm - OUTPUT.C - Outputs an objectfile
* *
@@ -196,7 +196,8 @@ void fputstring(char *s, FILE * f)
* *
*/ */
ULONG getsectid(struct Section *pSect) ULONG
getsectid(struct Section * pSect)
{ {
struct Section *sec; struct Section *sec;
ULONG ID = 0; ULONG ID = 0;
@@ -213,7 +214,6 @@ ULONG getsectid(struct Section *pSect)
fatalerror("INTERNAL: Unknown section"); fatalerror("INTERNAL: Unknown section");
return ((ULONG) - 1); return ((ULONG) - 1);
} }
/* /*
* RGBAsm - OUTPUT.C - Outputs an objectfile * RGBAsm - OUTPUT.C - Outputs an objectfile
* *
@@ -221,7 +221,8 @@ ULONG getsectid(struct Section *pSect)
* *
*/ */
void writepatch(struct Patch *pPatch, FILE * f) void
writepatch(struct Patch * pPatch, FILE * f)
{ {
fputstring(pPatch->tzFilename, f); fputstring(pPatch->tzFilename, f);
fputlong(pPatch->nLine, f); fputlong(pPatch->nLine, f);
@@ -230,7 +231,6 @@ void writepatch(struct Patch *pPatch, FILE * f)
fputlong(pPatch->nRPNSize, f); fputlong(pPatch->nRPNSize, f);
fwrite(pPatch->pRPN, 1, pPatch->nRPNSize, f); fwrite(pPatch->pRPN, 1, pPatch->nRPNSize, f);
} }
/* /*
* RGBAsm - OUTPUT.C - Outputs an objectfile * RGBAsm - OUTPUT.C - Outputs an objectfile
* *
@@ -238,17 +238,20 @@ void writepatch(struct Patch *pPatch, FILE * f)
* *
*/ */
void writesection(struct Section *pSect, FILE * f) void
writesection(struct Section * pSect, FILE * f)
{ {
//printf( "SECTION: %s, ID: %d\n", pSect->pzName, getsectid(pSect) ); //printf("SECTION: %s, ID: %d\n", pSect->pzName, getsectid(pSect));
fputlong(pSect->nPC, f); fputlong(pSect->nPC, f);
fputc(pSect->nType, f); fputc(pSect->nType, f);
fputlong(pSect->nOrg, f); // RGB1 addition fputlong(pSect->nOrg, f);
//RGB1 addition
fputlong(pSect->nBank, f); // RGB1 addition fputlong(pSect->nBank, f);
//RGB1 addition
if ((pSect->nType == SECT_HOME) if ((pSect->nType == SECT_HOME)
|| (pSect->nType == SECT_CODE)) { || (pSect->nType == SECT_CODE)) {
struct Patch *pPatch; struct Patch *pPatch;
@@ -262,7 +265,6 @@ void writesection(struct Section *pSect, FILE * f)
} }
} }
} }
/* /*
* RGBAsm - OUTPUT.C - Outputs an objectfile * RGBAsm - OUTPUT.C - Outputs an objectfile
* *
@@ -270,7 +272,8 @@ void writesection(struct Section *pSect, FILE * f)
* *
*/ */
void writesymbol(struct sSymbol *pSym, FILE * f) void
writesymbol(struct sSymbol * pSym, FILE * f)
{ {
char symname[MAXSYMLEN * 2 + 1]; char symname[MAXSYMLEN * 2 + 1];
ULONG type; ULONG type;
@@ -312,7 +315,6 @@ void writesymbol(struct sSymbol *pSym, FILE * f)
fputlong(offset, f); fputlong(offset, f);
} }
} }
/* /*
* RGBAsm - OUTPUT.C - Outputs an objectfile * RGBAsm - OUTPUT.C - Outputs an objectfile
* *
@@ -320,7 +322,8 @@ void writesymbol(struct sSymbol *pSym, FILE * f)
* *
*/ */
ULONG addsymbol(struct sSymbol *pSym) ULONG
addsymbol(struct sSymbol * pSym)
{ {
struct PatchSymbol *pPSym, **ppPSym; struct PatchSymbol *pPSym, **ppPSym;
ULONG ID = 0; ULONG ID = 0;
@@ -337,7 +340,7 @@ ULONG addsymbol(struct sSymbol *pSym)
} }
if ((*ppPSym = pPSym = if ((*ppPSym = pPSym =
(struct PatchSymbol *)malloc(sizeof(struct PatchSymbol))) != (struct PatchSymbol *) malloc(sizeof(struct PatchSymbol))) !=
NULL) { NULL) {
pPSym->pNext = NULL; pPSym->pNext = NULL;
pPSym->pSymbol = pSym; pPSym->pSymbol = pSym;
@@ -348,7 +351,6 @@ ULONG addsymbol(struct sSymbol *pSym)
return ((ULONG) - 1); return ((ULONG) - 1);
} }
/* /*
* RGBAsm - OUTPUT.C - Outputs an objectfile * RGBAsm - OUTPUT.C - Outputs an objectfile
* *
@@ -356,7 +358,8 @@ ULONG addsymbol(struct sSymbol *pSym)
* *
*/ */
void addexports(void) void
addexports(void)
{ {
int i; int i;
@@ -371,7 +374,6 @@ void addexports(void)
} }
} }
} }
/* /*
* RGBAsm - OUTPUT.C - Outputs an objectfile * RGBAsm - OUTPUT.C - Outputs an objectfile
* *
@@ -379,7 +381,8 @@ void addexports(void)
* *
*/ */
struct Patch *allocpatch(void) struct Patch *
allocpatch(void)
{ {
struct Patch *pPatch, **ppPatch; struct Patch *pPatch, **ppPatch;
@@ -392,7 +395,7 @@ struct Patch *allocpatch(void)
} }
if ((*ppPatch = pPatch = if ((*ppPatch = pPatch =
(struct Patch *)malloc(sizeof(struct Patch))) != NULL) { (struct Patch *) malloc(sizeof(struct Patch))) != NULL) {
pPatch->pNext = NULL; pPatch->pNext = NULL;
pPatch->nRPNSize = 0; pPatch->nRPNSize = 0;
pPatch->pRPN = NULL; pPatch->pRPN = NULL;
@@ -401,7 +404,6 @@ struct Patch *allocpatch(void)
return (pPatch); return (pPatch);
} }
/* /*
* RGBAsm - OUTPUT.C - Outputs an objectfile * RGBAsm - OUTPUT.C - Outputs an objectfile
* *
@@ -409,7 +411,8 @@ struct Patch *allocpatch(void)
* *
*/ */
void createpatch(ULONG type, struct Expression *expr) void
createpatch(ULONG type, struct Expression * expr)
{ {
struct Patch *pPatch; struct Patch *pPatch;
UWORD rpndata; UWORD rpndata;
@@ -434,7 +437,7 @@ void createpatch(ULONG type, struct Expression *expr)
break; break;
case RPN_SYM: case RPN_SYM:
symptr = 0; symptr = 0;
while ((tzSym[symptr++] = rpn_PopByte(expr)) != 0) ; while ((tzSym[symptr++] = rpn_PopByte(expr)) != 0);
if (sym_isConstant(tzSym)) { if (sym_isConstant(tzSym)) {
ULONG value; ULONG value;
@@ -455,7 +458,7 @@ void createpatch(ULONG type, struct Expression *expr)
break; break;
case RPN_BANK: case RPN_BANK:
symptr = 0; symptr = 0;
while ((tzSym[symptr++] = rpn_PopByte(expr)) != 0) ; while ((tzSym[symptr++] = rpn_PopByte(expr)) != 0);
symptr = addsymbol(sym_FindSymbol(tzSym)); symptr = addsymbol(sym_FindSymbol(tzSym));
rpnexpr[rpnptr++] = RPN_BANK; rpnexpr[rpnptr++] = RPN_BANK;
rpnexpr[rpnptr++] = symptr & 0xFF; rpnexpr[rpnptr++] = symptr & 0xFF;
@@ -473,7 +476,6 @@ void createpatch(ULONG type, struct Expression *expr)
pPatch->nRPNSize = rpnptr; pPatch->nRPNSize = rpnptr;
} }
} }
/* /*
* RGBAsm - OUTPUT.C - Outputs an objectfile * RGBAsm - OUTPUT.C - Outputs an objectfile
* *
@@ -481,14 +483,14 @@ void createpatch(ULONG type, struct Expression *expr)
* *
*/ */
void checksection(void) void
checksection(void)
{ {
if (pCurrentSection) if (pCurrentSection)
return; return;
else else
fatalerror("Code generation before SECTION directive"); fatalerror("Code generation before SECTION directive");
} }
/* /*
* RGBAsm - OUTPUT.C - Outputs an objectfile * RGBAsm - OUTPUT.C - Outputs an objectfile
* *
@@ -497,21 +499,22 @@ void checksection(void)
* *
*/ */
void checkcodesection(SLONG size) void
checkcodesection(SLONG size)
{ {
checksection(); checksection();
if ((pCurrentSection->nType == SECT_HOME if ((pCurrentSection->nType == SECT_HOME
|| pCurrentSection->nType == SECT_CODE) || pCurrentSection->nType == SECT_CODE)
&& (pCurrentSection->nPC + size <= MAXSECTIONSIZE)) { && (pCurrentSection->nPC + size <= MAXSECTIONSIZE)) {
if (((pCurrentSection->nPC % SECTIONCHUNK) > if (((pCurrentSection->nPC % SECTIONCHUNK) >
((pCurrentSection->nPC + size) % SECTIONCHUNK)) ((pCurrentSection->nPC + size) % SECTIONCHUNK))
&& (pCurrentSection->nType == SECT_HOME && (pCurrentSection->nType == SECT_HOME
|| pCurrentSection->nType == SECT_CODE)) { || pCurrentSection->nType == SECT_CODE)) {
if ((pCurrentSection->tData = if ((pCurrentSection->tData =
(UBYTE *) realloc(pCurrentSection->tData, (UBYTE *) realloc(pCurrentSection->tData,
((pCurrentSection->nPC + ((pCurrentSection->nPC +
size) / SECTIONCHUNK + size) / SECTIONCHUNK +
1) * SECTIONCHUNK)) != NULL) { 1) * SECTIONCHUNK)) != NULL) {
return; return;
} else } else
fatalerror fatalerror
@@ -522,7 +525,6 @@ void checkcodesection(SLONG size)
fatalerror fatalerror
("Section can't contain initialized data or section limit exceeded"); ("Section can't contain initialized data or section limit exceeded");
} }
/* /*
* RGBAsm - OUTPUT.C - Outputs an objectfile * RGBAsm - OUTPUT.C - Outputs an objectfile
* *
@@ -530,7 +532,8 @@ void checkcodesection(SLONG size)
* *
*/ */
void out_WriteObject(void) void
out_WriteObject(void)
{ {
FILE *f; FILE *f;
@@ -559,7 +562,6 @@ void out_WriteObject(void)
fclose(f); fclose(f);
} }
} }
/* /*
* RGBAsm - OUTPUT.C - Outputs an objectfile * RGBAsm - OUTPUT.C - Outputs an objectfile
* *
@@ -567,7 +569,8 @@ void out_WriteObject(void)
* *
*/ */
void out_PrepPass2(void) void
out_PrepPass2(void)
{ {
struct Section *pSect; struct Section *pSect;
@@ -579,7 +582,6 @@ void out_PrepPass2(void)
pCurrentSection = NULL; pCurrentSection = NULL;
pSectionStack = NULL; pSectionStack = NULL;
} }
/* /*
* RGBAsm - OUTPUT.C - Outputs an objectfile * RGBAsm - OUTPUT.C - Outputs an objectfile
* *
@@ -587,7 +589,8 @@ void out_PrepPass2(void)
* *
*/ */
void out_SetFileName(char *s) void
out_SetFileName(char *s)
{ {
strcpy(tzObjectname, s); strcpy(tzObjectname, s);
printf("Output filename %s\n", s); printf("Output filename %s\n", s);
@@ -595,7 +598,6 @@ void out_SetFileName(char *s)
pCurrentSection = NULL; pCurrentSection = NULL;
pPatchSymbols = NULL; pPatchSymbols = NULL;
} }
/* /*
* RGBAsm - OUTPUT.C - Outputs an objectfile * RGBAsm - OUTPUT.C - Outputs an objectfile
* *
@@ -603,8 +605,9 @@ void out_SetFileName(char *s)
* *
*/ */
struct Section *out_FindSection(char *pzName, ULONG secttype, SLONG org, struct Section *
SLONG bank) out_FindSection(char *pzName, ULONG secttype, SLONG org,
SLONG bank)
{ {
struct Section *pSect, **ppSect; struct Section *pSect, **ppSect;
@@ -626,10 +629,10 @@ struct Section *out_FindSection(char *pzName, ULONG secttype, SLONG org,
} }
if ((*ppSect = if ((*ppSect =
(pSect = (pSect =
(struct Section *)malloc(sizeof(struct Section)))) != NULL) { (struct Section *) malloc(sizeof(struct Section)))) != NULL) {
if ((pSect->pzName = if ((pSect->pzName =
(char *)malloc(strlen(pzName) + 1)) != NULL) { (char *) malloc(strlen(pzName) + 1)) != NULL) {
strcpy(pSect->pzName, pzName); strcpy(pSect->pzName, pzName);
pSect->nType = secttype; pSect->nType = secttype;
pSect->nPC = 0; pSect->nPC = 0;
@@ -640,7 +643,7 @@ struct Section *out_FindSection(char *pzName, ULONG secttype, SLONG org,
pPatchSymbols = NULL; pPatchSymbols = NULL;
if ((pSect->tData = if ((pSect->tData =
(UBYTE *) malloc(SECTIONCHUNK)) != NULL) { (UBYTE *) malloc(SECTIONCHUNK)) != NULL) {
return (pSect); return (pSect);
} else } else
fatalerror("Not enough memory for section"); fatalerror("Not enough memory for section");
@@ -651,7 +654,6 @@ struct Section *out_FindSection(char *pzName, ULONG secttype, SLONG org,
return (NULL); return (NULL);
} }
/* /*
* RGBAsm - OUTPUT.C - Outputs an objectfile * RGBAsm - OUTPUT.C - Outputs an objectfile
* *
@@ -659,7 +661,8 @@ struct Section *out_FindSection(char *pzName, ULONG secttype, SLONG org,
* *
*/ */
void out_SetCurrentSection(struct Section *pSect) void
out_SetCurrentSection(struct Section * pSect)
{ {
pCurrentSection = pSect; pCurrentSection = pSect;
nPC = pSect->nPC; nPC = pSect->nPC;
@@ -667,7 +670,6 @@ void out_SetCurrentSection(struct Section *pSect)
pPCSymbol->nValue = nPC; pPCSymbol->nValue = nPC;
pPCSymbol->pSection = pCurrentSection; pPCSymbol->pSection = pCurrentSection;
} }
/* /*
* RGBAsm - OUTPUT.C - Outputs an objectfile * RGBAsm - OUTPUT.C - Outputs an objectfile
* *
@@ -675,11 +677,11 @@ void out_SetCurrentSection(struct Section *pSect)
* *
*/ */
void out_NewSection(char *pzName, ULONG secttype) void
out_NewSection(char *pzName, ULONG secttype)
{ {
out_SetCurrentSection(out_FindSection(pzName, secttype, -1, -1)); out_SetCurrentSection(out_FindSection(pzName, secttype, -1, -1));
} }
/* /*
* RGBAsm - OUTPUT.C - Outputs an objectfile * RGBAsm - OUTPUT.C - Outputs an objectfile
* *
@@ -687,11 +689,11 @@ void out_NewSection(char *pzName, ULONG secttype)
* *
*/ */
void out_NewAbsSection(char *pzName, ULONG secttype, SLONG org, SLONG bank) void
out_NewAbsSection(char *pzName, ULONG secttype, SLONG org, SLONG bank)
{ {
out_SetCurrentSection(out_FindSection(pzName, secttype, org, bank)); out_SetCurrentSection(out_FindSection(pzName, secttype, org, bank));
} }
/* /*
* RGBAsm - OUTPUT.C - Outputs an objectfile * RGBAsm - OUTPUT.C - Outputs an objectfile
* *
@@ -699,7 +701,8 @@ void out_NewAbsSection(char *pzName, ULONG secttype, SLONG org, SLONG bank)
* *
*/ */
void out_AbsByte(int b) void
out_AbsByte(int b)
{ {
checkcodesection(1); checkcodesection(1);
b &= 0xFF; b &= 0xFF;
@@ -710,7 +713,6 @@ void out_AbsByte(int b)
nPC += 1; nPC += 1;
pPCSymbol->nValue += 1; pPCSymbol->nValue += 1;
} }
/* /*
* RGBAsm - OUTPUT.C - Outputs an objectfile * RGBAsm - OUTPUT.C - Outputs an objectfile
* *
@@ -718,12 +720,13 @@ void out_AbsByte(int b)
* *
*/ */
void out_Skip(int skip) void
out_Skip(int skip)
{ {
checksection(); checksection();
if ((CurrentOptions.fillchar == -1) if ((CurrentOptions.fillchar == -1)
|| !((pCurrentSection->nType == SECT_HOME) || !((pCurrentSection->nType == SECT_HOME)
|| (pCurrentSection->nType == SECT_CODE))) { || (pCurrentSection->nType == SECT_CODE))) {
pCurrentSection->nPC += skip; pCurrentSection->nPC += skip;
nPC += skip; nPC += skip;
pPCSymbol->nValue += skip; pPCSymbol->nValue += skip;
@@ -733,7 +736,6 @@ void out_Skip(int skip)
out_AbsByte(CurrentOptions.fillchar); out_AbsByte(CurrentOptions.fillchar);
} }
} }
/* /*
* RGBAsm - OUTPUT.C - Outputs an objectfile * RGBAsm - OUTPUT.C - Outputs an objectfile
* *
@@ -741,13 +743,13 @@ void out_Skip(int skip)
* *
*/ */
void out_String(char *s) void
out_String(char *s)
{ {
checkcodesection(strlen(s)); checkcodesection(strlen(s));
while (*s) while (*s)
out_AbsByte(*s++); out_AbsByte(*s++);
} }
/* /*
* RGBAsm - OUTPUT.C - Outputs an objectfile * RGBAsm - OUTPUT.C - Outputs an objectfile
* *
@@ -756,7 +758,8 @@ void out_String(char *s)
* *
*/ */
void out_RelByte(struct Expression *expr) void
out_RelByte(struct Expression * expr)
{ {
checkcodesection(1); checkcodesection(1);
if (rpn_isReloc(expr)) { if (rpn_isReloc(expr)) {
@@ -772,7 +775,6 @@ void out_RelByte(struct Expression *expr)
rpn_Reset(expr); rpn_Reset(expr);
} }
/* /*
* RGBAsm - OUTPUT.C - Outputs an objectfile * RGBAsm - OUTPUT.C - Outputs an objectfile
* *
@@ -780,7 +782,8 @@ void out_RelByte(struct Expression *expr)
* *
*/ */
void out_AbsWord(int b) void
out_AbsWord(int b)
{ {
checkcodesection(2); checkcodesection(2);
b &= 0xFFFF; b &= 0xFFFF;
@@ -789,8 +792,8 @@ void out_AbsWord(int b)
pCurrentSection->tData[nPC] = b & 0xFF; pCurrentSection->tData[nPC] = b & 0xFF;
pCurrentSection->tData[nPC + 1] = b >> 8; pCurrentSection->tData[nPC + 1] = b >> 8;
} else { } else {
// Assume big endian //Assume big endian
pCurrentSection->tData[nPC] = b >> 8; pCurrentSection->tData[nPC] = b >> 8;
pCurrentSection->tData[nPC + 1] = b & 0xFF; pCurrentSection->tData[nPC + 1] = b & 0xFF;
} }
} }
@@ -798,7 +801,6 @@ void out_AbsWord(int b)
nPC += 2; nPC += 2;
pPCSymbol->nValue += 2; pPCSymbol->nValue += 2;
} }
/* /*
* RGBAsm - OUTPUT.C - Outputs an objectfile * RGBAsm - OUTPUT.C - Outputs an objectfile
* *
@@ -807,7 +809,8 @@ void out_AbsWord(int b)
* *
*/ */
void out_RelWord(struct Expression *expr) void
out_RelWord(struct Expression * expr)
{ {
ULONG b; ULONG b;
@@ -820,8 +823,8 @@ void out_RelWord(struct Expression *expr)
pCurrentSection->tData[nPC + 1] = b >> 8; pCurrentSection->tData[nPC + 1] = b >> 8;
createpatch(PATCH_WORD_L, expr); createpatch(PATCH_WORD_L, expr);
} else { } else {
// Assume big endian //Assume big endian
pCurrentSection->tData[nPC] = b >> 8; pCurrentSection->tData[nPC] = b >> 8;
pCurrentSection->tData[nPC + 1] = b & 0xFF; pCurrentSection->tData[nPC + 1] = b & 0xFF;
createpatch(PATCH_WORD_B, expr); createpatch(PATCH_WORD_B, expr);
} }
@@ -833,7 +836,6 @@ void out_RelWord(struct Expression *expr)
out_AbsWord(expr->nVal); out_AbsWord(expr->nVal);
rpn_Reset(expr); rpn_Reset(expr);
} }
/* /*
* RGBAsm - OUTPUT.C - Outputs an objectfile * RGBAsm - OUTPUT.C - Outputs an objectfile
* *
@@ -841,7 +843,8 @@ void out_RelWord(struct Expression *expr)
* *
*/ */
void out_AbsLong(SLONG b) void
out_AbsLong(SLONG b)
{ {
checkcodesection(sizeof(SLONG)); checkcodesection(sizeof(SLONG));
if (nPass == 2) { if (nPass == 2) {
@@ -851,8 +854,8 @@ void out_AbsLong(SLONG b)
pCurrentSection->tData[nPC + 2] = b >> 16; pCurrentSection->tData[nPC + 2] = b >> 16;
pCurrentSection->tData[nPC + 3] = b >> 24; pCurrentSection->tData[nPC + 3] = b >> 24;
} else { } else {
// Assume big endian //Assume big endian
pCurrentSection->tData[nPC] = b >> 24; pCurrentSection->tData[nPC] = b >> 24;
pCurrentSection->tData[nPC + 1] = b >> 16; pCurrentSection->tData[nPC + 1] = b >> 16;
pCurrentSection->tData[nPC + 2] = b >> 8; pCurrentSection->tData[nPC + 2] = b >> 8;
pCurrentSection->tData[nPC + 3] = b & 0xFF; pCurrentSection->tData[nPC + 3] = b & 0xFF;
@@ -862,7 +865,6 @@ void out_AbsLong(SLONG b)
nPC += 4; nPC += 4;
pPCSymbol->nValue += 4; pPCSymbol->nValue += 4;
} }
/* /*
* RGBAsm - OUTPUT.C - Outputs an objectfile * RGBAsm - OUTPUT.C - Outputs an objectfile
* *
@@ -871,7 +873,8 @@ void out_AbsLong(SLONG b)
* *
*/ */
void out_RelLong(struct Expression *expr) void
out_RelLong(struct Expression * expr)
{ {
SLONG b; SLONG b;
@@ -886,8 +889,8 @@ void out_RelLong(struct Expression *expr)
pCurrentSection->tData[nPC + 3] = b >> 24; pCurrentSection->tData[nPC + 3] = b >> 24;
createpatch(PATCH_LONG_L, expr); createpatch(PATCH_LONG_L, expr);
} else { } else {
// Assume big endian //Assume big endian
pCurrentSection->tData[nPC] = b >> 24; pCurrentSection->tData[nPC] = b >> 24;
pCurrentSection->tData[nPC + 1] = b >> 16; pCurrentSection->tData[nPC + 1] = b >> 16;
pCurrentSection->tData[nPC + 2] = b >> 8; pCurrentSection->tData[nPC + 2] = b >> 8;
pCurrentSection->tData[nPC + 3] = b & 0xFF; pCurrentSection->tData[nPC + 3] = b & 0xFF;
@@ -901,7 +904,6 @@ void out_RelLong(struct Expression *expr)
out_AbsLong(expr->nVal); out_AbsLong(expr->nVal);
rpn_Reset(expr); rpn_Reset(expr);
} }
/* /*
* RGBAsm - OUTPUT.C - Outputs an objectfile * RGBAsm - OUTPUT.C - Outputs an objectfile
* *
@@ -909,7 +911,8 @@ void out_RelLong(struct Expression *expr)
* *
*/ */
void out_PCRelByte(struct Expression *expr) void
out_PCRelByte(struct Expression * expr)
{ {
SLONG b = expr->nVal; SLONG b = expr->nVal;
@@ -921,7 +924,6 @@ void out_PCRelByte(struct Expression *expr)
out_AbsByte(b); out_AbsByte(b);
rpn_Reset(expr); rpn_Reset(expr);
} }
/* /*
* RGBAsm - OUTPUT.C - Outputs an objectfile * RGBAsm - OUTPUT.C - Outputs an objectfile
* *
@@ -929,7 +931,8 @@ void out_PCRelByte(struct Expression *expr)
* *
*/ */
void out_BinaryFile(char *s) void
out_BinaryFile(char *s)
{ {
FILE *f; FILE *f;
@@ -951,7 +954,6 @@ void out_BinaryFile(char *s)
while (todo--) while (todo--)
pCurrentSection->tData[dest++] = fgetc(f); pCurrentSection->tData[dest++] = fgetc(f);
} }
pCurrentSection->nPC += fsize; pCurrentSection->nPC += fsize;
nPC += fsize; nPC += fsize;
pPCSymbol->nValue += fsize; pPCSymbol->nValue += fsize;
@@ -960,7 +962,8 @@ void out_BinaryFile(char *s)
fatalerror("File not found"); fatalerror("File not found");
} }
void out_BinaryFileSlice(char *s, SLONG start_pos, SLONG length) void
out_BinaryFileSlice(char *s, SLONG start_pos, SLONG length)
{ {
FILE *f; FILE *f;
@@ -970,41 +973,36 @@ void out_BinaryFileSlice(char *s, SLONG start_pos, SLONG length)
if (length < 0) if (length < 0)
fatalerror("Number of bytes to read must be greater than zero"); fatalerror("Number of bytes to read must be greater than zero");
fstk_FindFile (s); fstk_FindFile(s);
if( (f=fopen(s,"rb"))!=NULL ) if ((f = fopen(s, "rb")) != NULL) {
{ SLONG fsize;
SLONG fsize;
fseek (f, 0, SEEK_END); fseek(f, 0, SEEK_END);
fsize = ftell (f); fsize = ftell(f);
if (start_pos >= fsize) if (start_pos >= fsize)
fatalerror("Specified start position is greater than length of file"); fatalerror("Specified start position is greater than length of file");
if( (start_pos + length) > fsize ) if ((start_pos + length) > fsize)
fatalerror("Specified range in INCBIN is out of bounds"); fatalerror("Specified range in INCBIN is out of bounds");
fseek (f, start_pos, SEEK_SET); fseek(f, start_pos, SEEK_SET);
checkcodesection (length); checkcodesection(length);
if (nPass == 2) if (nPass == 2) {
{ SLONG dest = nPC;
SLONG dest = nPC; SLONG todo = length;
SLONG todo = length;
while (todo--) while (todo--)
pCurrentSection->tData[dest++] = fgetc (f); pCurrentSection->tData[dest++] = fgetc(f);
} }
pCurrentSection->nPC += length;
nPC += length;
pPCSymbol->nValue += length;
pCurrentSection->nPC += length; fclose(f);
nPC += length; } else
pPCSymbol->nValue += length; fatalerror("File not found");
fclose (f);
}
else
fatalerror ("File not found");
} }

View File

@@ -15,8 +15,9 @@
#include "asm/main.h" #include "asm/main.h"
#include "asm/rpn.h" #include "asm/rpn.h"
void mergetwoexpressions(struct Expression *expr, struct Expression *src1, void
struct Expression *src2) mergetwoexpressions(struct Expression * expr, struct Expression * src1,
struct Expression * src2)
{ {
*expr = *src1; *expr = *src1;
memcpy(&(expr->tRPN[expr->nRPNLength]), src2->tRPN, src2->nRPNLength); memcpy(&(expr->tRPN[expr->nRPNLength]), src2->tRPN, src2->nRPNLength);
@@ -25,7 +26,6 @@ void mergetwoexpressions(struct Expression *expr, struct Expression *src1,
expr->isReloc |= src2->isReloc; expr->isReloc |= src2->isReloc;
expr->isPCRel |= src2->isPCRel; expr->isPCRel |= src2->isPCRel;
} }
#define joinexpr() mergetwoexpressions(expr,src1,src2) #define joinexpr() mergetwoexpressions(expr,src1,src2)
/* /*
@@ -35,11 +35,11 @@ void mergetwoexpressions(struct Expression *expr, struct Expression *src1,
* *
*/ */
//UBYTE rpnexpr[2048]; //UBYTE rpnexpr[2048];
//ULONG rpnptr = 0; //ULONG rpnptr = 0;
//ULONG rpnoutptr = 0; //ULONG rpnoutptr = 0;
//ULONG reloc = 0; //ULONG reloc = 0;
//ULONG pcrel = 0; //ULONG pcrel = 0;
/* /*
* RGBAsm - RPN.C - Controls RPN expressions for objectfiles * RGBAsm - RPN.C - Controls RPN expressions for objectfiles
@@ -48,11 +48,11 @@ void mergetwoexpressions(struct Expression *expr, struct Expression *src1,
* *
*/ */
void pushbyte(struct Expression *expr, int b) void
pushbyte(struct Expression * expr, int b)
{ {
expr->tRPN[expr->nRPNLength++] = b & 0xFF; expr->tRPN[expr->nRPNLength++] = b & 0xFF;
} }
/* /*
* RGBAsm - RPN.C - Controls RPN expressions for objectfiles * RGBAsm - RPN.C - Controls RPN expressions for objectfiles
* *
@@ -60,11 +60,11 @@ void pushbyte(struct Expression *expr, int b)
* *
*/ */
void rpn_Reset(struct Expression *expr) void
rpn_Reset(struct Expression * expr)
{ {
expr->nRPNLength = expr->nRPNOut = expr->isReloc = expr->isPCRel = 0; expr->nRPNLength = expr->nRPNOut = expr->isReloc = expr->isPCRel = 0;
} }
/* /*
* RGBAsm - RPN.C - Controls RPN expressions for objectfiles * RGBAsm - RPN.C - Controls RPN expressions for objectfiles
* *
@@ -72,14 +72,14 @@ void rpn_Reset(struct Expression *expr)
* *
*/ */
UWORD rpn_PopByte(struct Expression *expr) UWORD
rpn_PopByte(struct Expression * expr)
{ {
if (expr->nRPNOut == expr->nRPNLength) { if (expr->nRPNOut == expr->nRPNLength) {
return (0xDEAD); return (0xDEAD);
} else } else
return (expr->tRPN[expr->nRPNOut++]); return (expr->tRPN[expr->nRPNOut++]);
} }
/* /*
* RGBAsm - RPN.C - Controls RPN expressions for objectfiles * RGBAsm - RPN.C - Controls RPN expressions for objectfiles
* *
@@ -87,11 +87,11 @@ UWORD rpn_PopByte(struct Expression *expr)
* *
*/ */
ULONG rpn_isReloc(struct Expression * expr) ULONG
rpn_isReloc(struct Expression * expr)
{ {
return (expr->isReloc); return (expr->isReloc);
} }
/* /*
* RGBAsm - RPN.C - Controls RPN expressions for objectfiles * RGBAsm - RPN.C - Controls RPN expressions for objectfiles
* *
@@ -99,11 +99,11 @@ ULONG rpn_isReloc(struct Expression * expr)
* *
*/ */
ULONG rpn_isPCRelative(struct Expression * expr) ULONG
rpn_isPCRelative(struct Expression * expr)
{ {
return (expr->isPCRel); return (expr->isPCRel);
} }
/* /*
* RGBAsm - RPN.C - Controls RPN expressions for objectfiles * RGBAsm - RPN.C - Controls RPN expressions for objectfiles
* *
@@ -111,7 +111,8 @@ ULONG rpn_isPCRelative(struct Expression * expr)
* *
*/ */
void rpn_Number(struct Expression *expr, ULONG i) void
rpn_Number(struct Expression * expr, ULONG i)
{ {
rpn_Reset(expr); rpn_Reset(expr);
pushbyte(expr, RPN_CONST); pushbyte(expr, RPN_CONST);
@@ -122,7 +123,8 @@ void rpn_Number(struct Expression *expr, ULONG i)
expr->nVal = i; expr->nVal = i;
} }
void rpn_Symbol(struct Expression *expr, char *tzSym) void
rpn_Symbol(struct Expression * expr, char *tzSym)
{ {
if (!sym_isConstant(tzSym)) { if (!sym_isConstant(tzSym)) {
struct sSymbol *psym; struct sSymbol *psym;
@@ -143,7 +145,8 @@ void rpn_Symbol(struct Expression *expr, char *tzSym)
rpn_Number(expr, sym_GetConstantValue(tzSym)); rpn_Number(expr, sym_GetConstantValue(tzSym));
} }
void rpn_Bank(struct Expression *expr, char *tzSym) void
rpn_Bank(struct Expression * expr, char *tzSym)
{ {
if (!sym_isConstant(tzSym)) { if (!sym_isConstant(tzSym)) {
struct sSymbol *psym; struct sSymbol *psym;
@@ -164,8 +167,9 @@ void rpn_Bank(struct Expression *expr, char *tzSym)
yyerror("BANK argument must be a relocatable identifier"); yyerror("BANK argument must be a relocatable identifier");
} }
int rpn_RangeCheck(struct Expression *expr, struct Expression *src, SLONG low, int
SLONG high) rpn_RangeCheck(struct Expression * expr, struct Expression * src, SLONG low,
SLONG high)
{ {
*expr = *src; *expr = *src;
@@ -184,9 +188,9 @@ int rpn_RangeCheck(struct Expression *expr, struct Expression *src, SLONG low,
return (expr->nVal >= low && expr->nVal <= high); return (expr->nVal >= low && expr->nVal <= high);
} }
} }
#ifdef GAMEBOY #ifdef GAMEBOY
void rpn_CheckHRAM(struct Expression *expr, struct Expression *src) void
rpn_CheckHRAM(struct Expression * expr, struct Expression * src)
{ {
*expr = *src; *expr = *src;
pushbyte(expr, RPN_HRAM); pushbyte(expr, RPN_HRAM);
@@ -194,171 +198,193 @@ void rpn_CheckHRAM(struct Expression *expr, struct Expression *src)
#endif #endif
#ifdef PCENGINE #ifdef PCENGINE
void rpn_CheckZP(struct Expression *expr, struct Expression *src) void
rpn_CheckZP(struct Expression * expr, struct Expression * src)
{ {
*expr = *src; *expr = *src;
pushbyte(expr, RPN_PCEZP); pushbyte(expr, RPN_PCEZP);
} }
#endif #endif
void rpn_LOGNOT(struct Expression *expr, struct Expression *src) void
rpn_LOGNOT(struct Expression * expr, struct Expression * src)
{ {
*expr = *src; *expr = *src;
pushbyte(expr, RPN_LOGUNNOT); pushbyte(expr, RPN_LOGUNNOT);
} }
void rpn_LOGOR(struct Expression *expr, struct Expression *src1, void
struct Expression *src2) rpn_LOGOR(struct Expression * expr, struct Expression * src1,
struct Expression * src2)
{ {
joinexpr(); joinexpr();
expr->nVal = (expr->nVal || src2->nVal); expr->nVal = (expr->nVal || src2->nVal);
pushbyte(expr, RPN_LOGOR); pushbyte(expr, RPN_LOGOR);
} }
void rpn_LOGAND(struct Expression *expr, struct Expression *src1, void
struct Expression *src2) rpn_LOGAND(struct Expression * expr, struct Expression * src1,
struct Expression * src2)
{ {
joinexpr(); joinexpr();
expr->nVal = (expr->nVal && src2->nVal); expr->nVal = (expr->nVal && src2->nVal);
pushbyte(expr, RPN_LOGAND); pushbyte(expr, RPN_LOGAND);
} }
void rpn_LOGEQU(struct Expression *expr, struct Expression *src1, void
struct Expression *src2) rpn_LOGEQU(struct Expression * expr, struct Expression * src1,
struct Expression * src2)
{ {
joinexpr(); joinexpr();
expr->nVal = (expr->nVal == src2->nVal); expr->nVal = (expr->nVal == src2->nVal);
pushbyte(expr, RPN_LOGEQ); pushbyte(expr, RPN_LOGEQ);
} }
void rpn_LOGGT(struct Expression *expr, struct Expression *src1, void
struct Expression *src2) rpn_LOGGT(struct Expression * expr, struct Expression * src1,
struct Expression * src2)
{ {
joinexpr(); joinexpr();
expr->nVal = (expr->nVal > src2->nVal); expr->nVal = (expr->nVal > src2->nVal);
pushbyte(expr, RPN_LOGGT); pushbyte(expr, RPN_LOGGT);
} }
void rpn_LOGLT(struct Expression *expr, struct Expression *src1, void
struct Expression *src2) rpn_LOGLT(struct Expression * expr, struct Expression * src1,
struct Expression * src2)
{ {
joinexpr(); joinexpr();
expr->nVal = (expr->nVal < src2->nVal); expr->nVal = (expr->nVal < src2->nVal);
pushbyte(expr, RPN_LOGLT); pushbyte(expr, RPN_LOGLT);
} }
void rpn_LOGGE(struct Expression *expr, struct Expression *src1, void
struct Expression *src2) rpn_LOGGE(struct Expression * expr, struct Expression * src1,
struct Expression * src2)
{ {
joinexpr(); joinexpr();
expr->nVal = (expr->nVal >= src2->nVal); expr->nVal = (expr->nVal >= src2->nVal);
pushbyte(expr, RPN_LOGGE); pushbyte(expr, RPN_LOGGE);
} }
void rpn_LOGLE(struct Expression *expr, struct Expression *src1, void
struct Expression *src2) rpn_LOGLE(struct Expression * expr, struct Expression * src1,
struct Expression * src2)
{ {
joinexpr(); joinexpr();
expr->nVal = (expr->nVal <= src2->nVal); expr->nVal = (expr->nVal <= src2->nVal);
pushbyte(expr, RPN_LOGLE); pushbyte(expr, RPN_LOGLE);
} }
void rpn_LOGNE(struct Expression *expr, struct Expression *src1, void
struct Expression *src2) rpn_LOGNE(struct Expression * expr, struct Expression * src1,
struct Expression * src2)
{ {
joinexpr(); joinexpr();
expr->nVal = (expr->nVal != src2->nVal); expr->nVal = (expr->nVal != src2->nVal);
pushbyte(expr, RPN_LOGNE); pushbyte(expr, RPN_LOGNE);
} }
void rpn_ADD(struct Expression *expr, struct Expression *src1, void
struct Expression *src2) rpn_ADD(struct Expression * expr, struct Expression * src1,
struct Expression * src2)
{ {
joinexpr(); joinexpr();
expr->nVal = (expr->nVal + src2->nVal); expr->nVal = (expr->nVal + src2->nVal);
pushbyte(expr, RPN_ADD); pushbyte(expr, RPN_ADD);
} }
void rpn_SUB(struct Expression *expr, struct Expression *src1, void
struct Expression *src2) rpn_SUB(struct Expression * expr, struct Expression * src1,
struct Expression * src2)
{ {
joinexpr(); joinexpr();
expr->nVal = (expr->nVal - src2->nVal); expr->nVal = (expr->nVal - src2->nVal);
pushbyte(expr, RPN_SUB); pushbyte(expr, RPN_SUB);
} }
void rpn_XOR(struct Expression *expr, struct Expression *src1, void
struct Expression *src2) rpn_XOR(struct Expression * expr, struct Expression * src1,
struct Expression * src2)
{ {
joinexpr(); joinexpr();
expr->nVal = (expr->nVal ^ src2->nVal); expr->nVal = (expr->nVal ^ src2->nVal);
pushbyte(expr, RPN_XOR); pushbyte(expr, RPN_XOR);
} }
void rpn_OR(struct Expression *expr, struct Expression *src1, void
struct Expression *src2) rpn_OR(struct Expression * expr, struct Expression * src1,
struct Expression * src2)
{ {
joinexpr(); joinexpr();
expr->nVal = (expr->nVal | src2->nVal); expr->nVal = (expr->nVal | src2->nVal);
pushbyte(expr, RPN_OR); pushbyte(expr, RPN_OR);
} }
void rpn_AND(struct Expression *expr, struct Expression *src1, void
struct Expression *src2) rpn_AND(struct Expression * expr, struct Expression * src1,
struct Expression * src2)
{ {
joinexpr(); joinexpr();
expr->nVal = (expr->nVal & src2->nVal); expr->nVal = (expr->nVal & src2->nVal);
pushbyte(expr, RPN_AND); pushbyte(expr, RPN_AND);
} }
void rpn_SHL(struct Expression *expr, struct Expression *src1, void
struct Expression *src2) rpn_SHL(struct Expression * expr, struct Expression * src1,
struct Expression * src2)
{ {
joinexpr(); joinexpr();
expr->nVal = (expr->nVal << src2->nVal); expr->nVal = (expr->nVal << src2->nVal);
pushbyte(expr, RPN_SHL); pushbyte(expr, RPN_SHL);
} }
void rpn_SHR(struct Expression *expr, struct Expression *src1, void
struct Expression *src2) rpn_SHR(struct Expression * expr, struct Expression * src1,
struct Expression * src2)
{ {
joinexpr(); joinexpr();
expr->nVal = (expr->nVal >> src2->nVal); expr->nVal = (expr->nVal >> src2->nVal);
pushbyte(expr, RPN_SHR); pushbyte(expr, RPN_SHR);
} }
void rpn_MUL(struct Expression *expr, struct Expression *src1, void
struct Expression *src2) rpn_MUL(struct Expression * expr, struct Expression * src1,
struct Expression * src2)
{ {
joinexpr(); joinexpr();
expr->nVal = (expr->nVal * src2->nVal); expr->nVal = (expr->nVal * src2->nVal);
pushbyte(expr, RPN_MUL); pushbyte(expr, RPN_MUL);
} }
void rpn_DIV(struct Expression *expr, struct Expression *src1, void
struct Expression *src2) rpn_DIV(struct Expression * expr, struct Expression * src1,
struct Expression * src2)
{ {
joinexpr(); joinexpr();
expr->nVal = (expr->nVal / src2->nVal); expr->nVal = (expr->nVal / src2->nVal);
pushbyte(expr, RPN_DIV); pushbyte(expr, RPN_DIV);
} }
void rpn_MOD(struct Expression *expr, struct Expression *src1, void
struct Expression *src2) rpn_MOD(struct Expression * expr, struct Expression * src1,
struct Expression * src2)
{ {
joinexpr(); joinexpr();
expr->nVal = (expr->nVal % src2->nVal); expr->nVal = (expr->nVal % src2->nVal);
pushbyte(expr, RPN_MOD); pushbyte(expr, RPN_MOD);
} }
void rpn_UNNEG(struct Expression *expr, struct Expression *src) void
rpn_UNNEG(struct Expression * expr, struct Expression * src)
{ {
*expr = *src; *expr = *src;
expr->nVal = -expr->nVal; expr->nVal = -expr->nVal;
pushbyte(expr, RPN_UNSUB); pushbyte(expr, RPN_UNSUB);
} }
void rpn_UNNOT(struct Expression *expr, struct Expression *src) void
rpn_UNNOT(struct Expression * expr, struct Expression * src)
{ {
*expr = *src; *expr = *src;
expr->nVal = expr->nVal ^ 0xFFFFFFFF; expr->nVal = expr->nVal ^ 0xFFFFFFFF;

View File

@@ -32,7 +32,8 @@ char *newmacroargs[MAXMACROARGS + 1];
char SavedTIME[256]; char SavedTIME[256];
char SavedDATE[256]; char SavedDATE[256];
SLONG Callback_NARG(struct sSymbol *sym) SLONG
Callback_NARG(struct sSymbol * sym)
{ {
ULONG i = 0; ULONG i = 0;
@@ -43,12 +44,12 @@ SLONG Callback_NARG(struct sSymbol *sym)
return (i); return (i);
} }
SLONG Callback__LINE__(struct sSymbol * sym) SLONG
Callback__LINE__(struct sSymbol * sym)
{ {
sym = sym; sym = sym;
return (nLineNo); return (nLineNo);
} }
/* /*
* RGBAsm - SYMBOL.C - Symboltable stuff * RGBAsm - SYMBOL.C - Symboltable stuff
* *
@@ -56,14 +57,14 @@ SLONG Callback__LINE__(struct sSymbol * sym)
* *
*/ */
SLONG getvaluefield(struct sSymbol * sym) SLONG
getvaluefield(struct sSymbol * sym)
{ {
if (sym->Callback) { if (sym->Callback) {
return (sym->Callback(sym)); return (sym->Callback(sym));
} else } else
return (sym->nValue); return (sym->nValue);
} }
/* /*
* RGBAsm - SYMBOL.C - Symboltable stuff * RGBAsm - SYMBOL.C - Symboltable stuff
* *
@@ -71,7 +72,8 @@ SLONG getvaluefield(struct sSymbol * sym)
* *
*/ */
ULONG calchash(char *s) ULONG
calchash(char *s)
{ {
ULONG hash = 0; ULONG hash = 0;
@@ -80,7 +82,6 @@ ULONG calchash(char *s)
return (hash % HASHSIZE); return (hash % HASHSIZE);
} }
/* /*
* RGBAsm - SYMBOL.C - Symboltable stuff * RGBAsm - SYMBOL.C - Symboltable stuff
* *
@@ -88,7 +89,8 @@ ULONG calchash(char *s)
* *
*/ */
struct sSymbol *createsymbol(char *s) struct sSymbol *
createsymbol(char *s)
{ {
struct sSymbol **ppsym; struct sSymbol **ppsym;
ULONG hash; ULONG hash;
@@ -100,7 +102,7 @@ struct sSymbol *createsymbol(char *s)
ppsym = &((*ppsym)->pNext); ppsym = &((*ppsym)->pNext);
if (((*ppsym) = if (((*ppsym) =
(struct sSymbol *)malloc(sizeof(struct sSymbol))) != NULL) { (struct sSymbol *) malloc(sizeof(struct sSymbol))) != NULL) {
strcpy((*ppsym)->tzName, s); strcpy((*ppsym)->tzName, s);
(*ppsym)->nValue = 0; (*ppsym)->nValue = 0;
(*ppsym)->nType = 0; (*ppsym)->nType = 0;
@@ -115,7 +117,6 @@ struct sSymbol *createsymbol(char *s)
return (NULL); return (NULL);
} }
} }
/* /*
* RGBAsm - SYMBOL.C - Symboltable stuff * RGBAsm - SYMBOL.C - Symboltable stuff
* *
@@ -123,7 +124,8 @@ struct sSymbol *createsymbol(char *s)
* *
*/ */
struct sSymbol *findsymbol(char *s, struct sSymbol *scope) struct sSymbol *
findsymbol(char *s, struct sSymbol * scope)
{ {
struct sSymbol **ppsym; struct sSymbol **ppsym;
SLONG hash; SLONG hash;
@@ -140,7 +142,6 @@ struct sSymbol *findsymbol(char *s, struct sSymbol *scope)
} }
return (NULL); return (NULL);
} }
/* /*
* RGBAsm - SYMBOL.C - Symboltable stuff * RGBAsm - SYMBOL.C - Symboltable stuff
* *
@@ -148,7 +149,8 @@ struct sSymbol *findsymbol(char *s, struct sSymbol *scope)
* *
*/ */
struct sSymbol **findpsymbol(char *s, struct sSymbol *scope) struct sSymbol **
findpsymbol(char *s, struct sSymbol * scope)
{ {
struct sSymbol **ppsym; struct sSymbol **ppsym;
SLONG hash; SLONG hash;
@@ -165,7 +167,6 @@ struct sSymbol **findpsymbol(char *s, struct sSymbol *scope)
} }
return (NULL); return (NULL);
} }
/* /*
* RGBAsm - SYMBOL.C - Symboltable stuff * RGBAsm - SYMBOL.C - Symboltable stuff
* *
@@ -173,7 +174,8 @@ struct sSymbol **findpsymbol(char *s, struct sSymbol *scope)
* *
*/ */
struct sSymbol *sym_FindSymbol(char *tzName) struct sSymbol *
sym_FindSymbol(char *tzName)
{ {
struct sSymbol *pscope; struct sSymbol *pscope;
@@ -184,7 +186,6 @@ struct sSymbol *sym_FindSymbol(char *tzName)
return (findsymbol(tzName, pscope)); return (findsymbol(tzName, pscope));
} }
/* /*
* RGBAsm - SYMBOL.C - Symboltable stuff * RGBAsm - SYMBOL.C - Symboltable stuff
* *
@@ -192,7 +193,8 @@ struct sSymbol *sym_FindSymbol(char *tzName)
* *
*/ */
void sym_Purge(char *tzName) void
sym_Purge(char *tzName)
{ {
struct sSymbol **ppSym; struct sSymbol **ppSym;
struct sSymbol *pscope; struct sSymbol *pscope;
@@ -219,7 +221,6 @@ void sym_Purge(char *tzName)
yyerror(temptext); yyerror(temptext);
} }
} }
/* /*
* RGBAsm - SYMBOL.C - Symboltable stuff * RGBAsm - SYMBOL.C - Symboltable stuff
* *
@@ -227,7 +228,8 @@ void sym_Purge(char *tzName)
* *
*/ */
ULONG sym_isConstDefined(char *tzName) ULONG
sym_isConstDefined(char *tzName)
{ {
struct sSymbol *psym, *pscope; struct sSymbol *psym, *pscope;
@@ -244,15 +246,16 @@ ULONG sym_isConstDefined(char *tzName)
return (1); return (1);
} else { } else {
sprintf(temptext, sprintf(temptext,
"'%s' is not allowed as argument to the DEF function", "'%s' is not allowed as argument to the DEF function",
tzName); tzName);
fatalerror(temptext); fatalerror(temptext);
} }
} }
return (0); return (0);
} }
ULONG sym_isDefined(char *tzName) ULONG
sym_isDefined(char *tzName)
{ {
struct sSymbol *psym, *pscope; struct sSymbol *psym, *pscope;
@@ -268,7 +271,6 @@ ULONG sym_isDefined(char *tzName)
else else
return (0); return (0);
} }
/* /*
* RGBAsm - SYMBOL.C - Symboltable stuff * RGBAsm - SYMBOL.C - Symboltable stuff
* *
@@ -276,7 +278,8 @@ ULONG sym_isDefined(char *tzName)
* *
*/ */
ULONG sym_isConstant(char *s) ULONG
sym_isConstant(char *s)
{ {
struct sSymbol *psym, *pscope; struct sSymbol *psym, *pscope;
@@ -289,10 +292,8 @@ ULONG sym_isConstant(char *s)
if (psym->nType & SYMF_CONST) if (psym->nType & SYMF_CONST)
return (1); return (1);
} }
return (0); return (0);
} }
/* /*
* RGBAsm - SYMBOL.C - Symboltable stuff * RGBAsm - SYMBOL.C - Symboltable stuff
* *
@@ -300,7 +301,8 @@ ULONG sym_isConstant(char *s)
* *
*/ */
char *sym_GetStringValue(char *tzSym) char *
sym_GetStringValue(char *tzSym)
{ {
struct sSymbol *pSym; struct sSymbol *pSym;
@@ -313,7 +315,6 @@ char *sym_GetStringValue(char *tzSym)
return (NULL); return (NULL);
} }
/* /*
* RGBAsm - SYMBOL.C - Symboltable stuff * RGBAsm - SYMBOL.C - Symboltable stuff
* *
@@ -321,7 +322,8 @@ char *sym_GetStringValue(char *tzSym)
* *
*/ */
ULONG sym_GetConstantValue(char *s) ULONG
sym_GetConstantValue(char *s)
{ {
struct sSymbol *psym, *pscope; struct sSymbol *psym, *pscope;
@@ -343,7 +345,6 @@ ULONG sym_GetConstantValue(char *s)
return (0); return (0);
} }
/* /*
* RGBAsm - SYMBOL.C - Symboltable stuff * RGBAsm - SYMBOL.C - Symboltable stuff
* *
@@ -351,7 +352,8 @@ ULONG sym_GetConstantValue(char *s)
* *
*/ */
ULONG sym_GetValue(char *s) ULONG
sym_GetValue(char *s)
{ {
struct sSymbol *psym, *pscope; struct sSymbol *psym, *pscope;
@@ -364,7 +366,7 @@ ULONG sym_GetValue(char *s)
if (psym->nType & SYMF_DEFINED) { if (psym->nType & SYMF_DEFINED) {
if (psym->nType & (SYMF_MACRO | SYMF_STRING)) { if (psym->nType & (SYMF_MACRO | SYMF_STRING)) {
sprintf(temptext, sprintf(temptext,
"'%s' is a macro or string symbol", s); "'%s' is a macro or string symbol", s);
yyerror(temptext); yyerror(temptext);
} }
return (getvaluefield(psym)); return (getvaluefield(psym));
@@ -389,7 +391,6 @@ ULONG sym_GetValue(char *s)
return (0); return (0);
} }
/* /*
* RGBAsm - SYMBOL.C - Symboltable stuff * RGBAsm - SYMBOL.C - Symboltable stuff
* *
@@ -397,7 +398,8 @@ ULONG sym_GetValue(char *s)
* *
*/ */
ULONG sym_GetDefinedValue(char *s) ULONG
sym_GetDefinedValue(char *s)
{ {
struct sSymbol *psym, *pscope; struct sSymbol *psym, *pscope;
@@ -410,10 +412,9 @@ ULONG sym_GetDefinedValue(char *s)
if ((psym->nType & SYMF_DEFINED)) { if ((psym->nType & SYMF_DEFINED)) {
if (psym->nType & (SYMF_MACRO | SYMF_STRING)) { if (psym->nType & (SYMF_MACRO | SYMF_STRING)) {
sprintf(temptext, sprintf(temptext,
"'%s' is a macro or string symbol", s); "'%s' is a macro or string symbol", s);
yyerror(temptext); yyerror(temptext);
} }
return (getvaluefield(psym)); return (getvaluefield(psym));
} else { } else {
sprintf(temptext, "'%s' not defined", s); sprintf(temptext, "'%s' not defined", s);
@@ -426,7 +427,6 @@ ULONG sym_GetDefinedValue(char *s)
return (0); return (0);
} }
/* /*
* RGBAsm - SYMBOL.C - Symboltable stuff * RGBAsm - SYMBOL.C - Symboltable stuff
* *
@@ -434,7 +434,8 @@ ULONG sym_GetDefinedValue(char *s)
* *
*/ */
void sym_ShiftCurrentMacroArgs(void) void
sym_ShiftCurrentMacroArgs(void)
{ {
SLONG i; SLONG i;
@@ -445,7 +446,8 @@ void sym_ShiftCurrentMacroArgs(void)
currentmacroargs[MAXMACROARGS - 1] = NULL; currentmacroargs[MAXMACROARGS - 1] = NULL;
} }
char *sym_FindMacroArg(SLONG i) char *
sym_FindMacroArg(SLONG i)
{ {
if (i == -1) if (i == -1)
i = MAXMACROARGS + 1; i = MAXMACROARGS + 1;
@@ -453,7 +455,8 @@ char *sym_FindMacroArg(SLONG i)
return (currentmacroargs[i - 1]); return (currentmacroargs[i - 1]);
} }
void sym_UseNewMacroArgs(void) void
sym_UseNewMacroArgs(void)
{ {
SLONG i; SLONG i;
@@ -463,7 +466,8 @@ void sym_UseNewMacroArgs(void)
} }
} }
void sym_SaveCurrentMacroArgs(char *save[]) void
sym_SaveCurrentMacroArgs(char *save[])
{ {
SLONG i; SLONG i;
@@ -471,7 +475,8 @@ void sym_SaveCurrentMacroArgs(char *save[])
save[i] = currentmacroargs[i]; save[i] = currentmacroargs[i];
} }
void sym_RestoreCurrentMacroArgs(char *save[]) void
sym_RestoreCurrentMacroArgs(char *save[])
{ {
SLONG i; SLONG i;
@@ -479,7 +484,8 @@ void sym_RestoreCurrentMacroArgs(char *save[])
currentmacroargs[i] = save[i]; currentmacroargs[i] = save[i];
} }
void sym_FreeCurrentMacroArgs(void) void
sym_FreeCurrentMacroArgs(void)
{ {
SLONG i; SLONG i;
@@ -489,7 +495,8 @@ void sym_FreeCurrentMacroArgs(void)
} }
} }
void sym_AddNewMacroArg(char *s) void
sym_AddNewMacroArg(char *s)
{ {
SLONG i = 0; SLONG i = 0;
@@ -505,7 +512,8 @@ void sym_AddNewMacroArg(char *s)
yyerror("A maximum of 9 arguments allowed"); yyerror("A maximum of 9 arguments allowed");
} }
void sym_SetMacroArgID(ULONG nMacroCount) void
sym_SetMacroArgID(ULONG nMacroCount)
{ {
char s[256]; char s[256];
@@ -513,14 +521,14 @@ void sym_SetMacroArgID(ULONG nMacroCount)
newmacroargs[MAXMACROARGS] = strdup(s); newmacroargs[MAXMACROARGS] = strdup(s);
} }
void sym_UseCurrentMacroArgs(void) void
sym_UseCurrentMacroArgs(void)
{ {
SLONG i; SLONG i;
for (i = 1; i <= MAXMACROARGS; i += 1) for (i = 1; i <= MAXMACROARGS; i += 1)
sym_AddNewMacroArg(sym_FindMacroArg(i)); sym_AddNewMacroArg(sym_FindMacroArg(i));
} }
/* /*
* RGBAsm - SYMBOL.C - Symboltable stuff * RGBAsm - SYMBOL.C - Symboltable stuff
* *
@@ -528,11 +536,11 @@ void sym_UseCurrentMacroArgs(void)
* *
*/ */
struct sSymbol *sym_FindMacro(char *s) struct sSymbol *
sym_FindMacro(char *s)
{ {
return (findsymbol(s, NULL)); return (findsymbol(s, NULL));
} }
/* /*
* RGBAsm - SYMBOL.C - Symboltable stuff * RGBAsm - SYMBOL.C - Symboltable stuff
* *
@@ -540,7 +548,8 @@ struct sSymbol *sym_FindMacro(char *s)
* *
*/ */
void sym_AddEqu(char *tzSym, SLONG value) void
sym_AddEqu(char *tzSym, SLONG value)
{ {
if ((nPass == 1) if ((nPass == 1)
|| ((nPass == 2) && (sym_isDefined(tzSym) == 0))) { || ((nPass == 2) && (sym_isDefined(tzSym) == 0))) {
@@ -550,7 +559,7 @@ void sym_AddEqu(char *tzSym, SLONG value)
if ((nsym = findsymbol(tzSym, NULL)) != NULL) { if ((nsym = findsymbol(tzSym, NULL)) != NULL) {
if (nsym->nType & SYMF_DEFINED) { if (nsym->nType & SYMF_DEFINED) {
sprintf(temptext, "'%s' already defined", sprintf(temptext, "'%s' already defined",
tzSym); tzSym);
yyerror(temptext); yyerror(temptext);
} }
} else } else
@@ -563,7 +572,6 @@ void sym_AddEqu(char *tzSym, SLONG value)
} }
} }
} }
/* /*
* RGBAsm - SYMBOL.C - Symboltable stuff * RGBAsm - SYMBOL.C - Symboltable stuff
* *
@@ -571,7 +579,8 @@ void sym_AddEqu(char *tzSym, SLONG value)
* *
*/ */
void sym_AddString(char *tzSym, char *tzValue) void
sym_AddString(char *tzSym, char *tzValue)
{ {
struct sSymbol *nsym; struct sSymbol *nsym;
@@ -585,7 +594,7 @@ void sym_AddString(char *tzSym, char *tzValue)
if (nsym) { if (nsym) {
if ((nsym->pMacro = if ((nsym->pMacro =
(char *)malloc(strlen(tzValue) + 1)) != NULL) (char *) malloc(strlen(tzValue) + 1)) != NULL)
strcpy(nsym->pMacro, tzValue); strcpy(nsym->pMacro, tzValue);
else else
fatalerror("No memory for stringequate"); fatalerror("No memory for stringequate");
@@ -594,7 +603,6 @@ void sym_AddString(char *tzSym, char *tzValue)
nsym->pScope = NULL; nsym->pScope = NULL;
} }
} }
/* /*
* RGBAsm - SYMBOL.C - Symboltable stuff * RGBAsm - SYMBOL.C - Symboltable stuff
* *
@@ -602,7 +610,8 @@ void sym_AddString(char *tzSym, char *tzValue)
* *
*/ */
ULONG sym_isString(char *tzSym) ULONG
sym_isString(char *tzSym)
{ {
struct sSymbol *pSym; struct sSymbol *pSym;
@@ -612,7 +621,6 @@ ULONG sym_isString(char *tzSym)
} }
return (0); return (0);
} }
/* /*
* RGBAsm - SYMBOL.C - Symboltable stuff * RGBAsm - SYMBOL.C - Symboltable stuff
* *
@@ -620,7 +628,8 @@ ULONG sym_isString(char *tzSym)
* *
*/ */
void sym_AddSet(char *tzSym, SLONG value) void
sym_AddSet(char *tzSym, SLONG value)
{ {
struct sSymbol *nsym; struct sSymbol *nsym;
@@ -634,7 +643,6 @@ void sym_AddSet(char *tzSym, SLONG value)
nsym->pScope = NULL; nsym->pScope = NULL;
} }
} }
/* /*
* RGBAsm - SYMBOL.C - Symboltable stuff * RGBAsm - SYMBOL.C - Symboltable stuff
* *
@@ -642,7 +650,8 @@ void sym_AddSet(char *tzSym, SLONG value)
* *
*/ */
void sym_AddLocalReloc(char *tzSym) void
sym_AddLocalReloc(char *tzSym)
{ {
if ((nPass == 1) if ((nPass == 1)
|| ((nPass == 2) && (sym_isDefined(tzSym) == 0))) { || ((nPass == 2) && (sym_isDefined(tzSym) == 0))) {
@@ -653,7 +662,7 @@ void sym_AddLocalReloc(char *tzSym)
if ((nsym = findsymbol(tzSym, pScope)) != NULL) { if ((nsym = findsymbol(tzSym, pScope)) != NULL) {
if (nsym->nType & SYMF_DEFINED) { if (nsym->nType & SYMF_DEFINED) {
sprintf(temptext, sprintf(temptext,
"'%s' already defined", tzSym); "'%s' already defined", tzSym);
yyerror(temptext); yyerror(temptext);
} }
} else } else
@@ -670,7 +679,6 @@ void sym_AddLocalReloc(char *tzSym)
fatalerror("Local label in main scope"); fatalerror("Local label in main scope");
} }
} }
/* /*
* RGBAsm - SYMBOL.C - Symboltable stuff * RGBAsm - SYMBOL.C - Symboltable stuff
* *
@@ -678,7 +686,8 @@ void sym_AddLocalReloc(char *tzSym)
* *
*/ */
void sym_AddReloc(char *tzSym) void
sym_AddReloc(char *tzSym)
{ {
if ((nPass == 1) if ((nPass == 1)
|| ((nPass == 2) && (sym_isDefined(tzSym) == 0))) { || ((nPass == 2) && (sym_isDefined(tzSym) == 0))) {
@@ -688,7 +697,7 @@ void sym_AddReloc(char *tzSym)
if ((nsym = findsymbol(tzSym, NULL)) != NULL) { if ((nsym = findsymbol(tzSym, NULL)) != NULL) {
if (nsym->nType & SYMF_DEFINED) { if (nsym->nType & SYMF_DEFINED) {
sprintf(temptext, "'%s' already defined", sprintf(temptext, "'%s' already defined",
tzSym); tzSym);
yyerror(temptext); yyerror(temptext);
} }
} else } else
@@ -704,7 +713,6 @@ void sym_AddReloc(char *tzSym)
pScope = findsymbol(tzSym, NULL); pScope = findsymbol(tzSym, NULL);
} }
/* /*
* RGBAsm - SYMBOL.C - Symboltable stuff * RGBAsm - SYMBOL.C - Symboltable stuff
* *
@@ -712,7 +720,8 @@ void sym_AddReloc(char *tzSym)
* *
*/ */
void sym_Export(char *tzSym) void
sym_Export(char *tzSym)
{ {
if (nPass == 1) { if (nPass == 1) {
/* only export symbols in pass 1 */ /* only export symbols in pass 1 */
@@ -735,7 +744,6 @@ void sym_Export(char *tzSym)
} }
} }
/* /*
* RGBAsm - SYMBOL.C - Symboltable stuff * RGBAsm - SYMBOL.C - Symboltable stuff
* *
@@ -743,7 +751,8 @@ void sym_Export(char *tzSym)
* *
*/ */
void sym_Import(char *tzSym) void
sym_Import(char *tzSym)
{ {
if (nPass == 1) { if (nPass == 1) {
/* only import symbols in pass 1 */ /* only import symbols in pass 1 */
@@ -753,12 +762,10 @@ void sym_Import(char *tzSym)
sprintf(temptext, "'%s' already defined", tzSym); sprintf(temptext, "'%s' already defined", tzSym);
yyerror(temptext); yyerror(temptext);
} }
if ((nsym = createsymbol(tzSym)) != NULL) if ((nsym = createsymbol(tzSym)) != NULL)
nsym->nType |= SYMF_IMPORT; nsym->nType |= SYMF_IMPORT;
} }
} }
/* /*
* RGBAsm - SYMBOL.C - Symboltable stuff * RGBAsm - SYMBOL.C - Symboltable stuff
* *
@@ -766,7 +773,8 @@ void sym_Import(char *tzSym)
* *
*/ */
void sym_Global(char *tzSym) void
sym_Global(char *tzSym)
{ {
if (nPass == 2) { if (nPass == 2) {
/* only globalize symbols in pass 2 */ /* only globalize symbols in pass 2 */
@@ -786,7 +794,6 @@ void sym_Global(char *tzSym)
} }
} }
} }
/* /*
* RGBAsm - SYMBOL.C - Symboltable stuff * RGBAsm - SYMBOL.C - Symboltable stuff
* *
@@ -794,7 +801,8 @@ void sym_Global(char *tzSym)
* *
*/ */
void sym_AddMacro(char *tzSym) void
sym_AddMacro(char *tzSym)
{ {
if ((nPass == 1) if ((nPass == 1)
|| ((nPass == 2) && (sym_isDefined(tzSym) == 0))) { || ((nPass == 2) && (sym_isDefined(tzSym) == 0))) {
@@ -804,7 +812,7 @@ void sym_AddMacro(char *tzSym)
if ((nsym = findsymbol(tzSym, NULL)) != NULL) { if ((nsym = findsymbol(tzSym, NULL)) != NULL) {
if (nsym->nType & SYMF_DEFINED) { if (nsym->nType & SYMF_DEFINED) {
sprintf(temptext, "'%s' already defined", sprintf(temptext, "'%s' already defined",
tzSym); tzSym);
yyerror(temptext); yyerror(temptext);
} }
} else } else
@@ -819,7 +827,6 @@ void sym_AddMacro(char *tzSym)
} }
} }
} }
/* /*
* RGBAsm - SYMBOL.C - Symboltable stuff * RGBAsm - SYMBOL.C - Symboltable stuff
* *
@@ -827,11 +834,11 @@ void sym_AddMacro(char *tzSym)
* *
*/ */
void sym_PrepPass1(void) void
sym_PrepPass1(void)
{ {
sym_Init(); sym_Init();
} }
/* /*
* RGBAsm - SYMBOL.C - Symboltable stuff * RGBAsm - SYMBOL.C - Symboltable stuff
* *
@@ -839,7 +846,8 @@ void sym_PrepPass1(void)
* *
*/ */
void sym_PrepPass2(void) void
sym_PrepPass2(void)
{ {
SLONG i; SLONG i;
@@ -865,7 +873,6 @@ void sym_PrepPass2(void)
sym_AddString("__DATE__", SavedDATE); sym_AddString("__DATE__", SavedDATE);
sym_AddSet("_RS", 0); sym_AddSet("_RS", 0);
} }
/* /*
* RGBAsm - SYMBOL.C - Symboltable stuff * RGBAsm - SYMBOL.C - Symboltable stuff
* *
@@ -873,7 +880,8 @@ void sym_PrepPass2(void)
* *
*/ */
void sym_Init(void) void
sym_Init(void)
{ {
SLONG i; SLONG i;
time_t tod; time_t tod;
@@ -907,13 +915,11 @@ void sym_Init(void)
sym_AddString("__TIME__", SavedTIME); sym_AddString("__TIME__", SavedTIME);
sym_AddString("__DATE__", SavedDATE); sym_AddString("__DATE__", SavedDATE);
} }
pScope = NULL; pScope = NULL;
math_DefinePI(); math_DefinePI();
} }
/* /*
* RGBAsm - SYMBOL.C - Symboltable stuff * RGBAsm - SYMBOL.C - Symboltable stuff
* *
@@ -921,7 +927,8 @@ void sym_Init(void)
* *
*/ */
void sym_PrintSymbolTable(void) void
sym_PrintSymbolTable(void)
{ {
ULONG i; ULONG i;
@@ -934,8 +941,8 @@ void sym_PrintSymbolTable(void)
while (sym != NULL) { while (sym != NULL) {
if (sym->nType & SYMF_LOCAL) if (sym->nType & SYMF_LOCAL)
printf("LOCAL : '%s%s' - %08lX\n", printf("LOCAL : '%s%s' - %08lX\n",
sym->pScope->tzName, sym->tzName, sym->pScope->tzName, sym->tzName,
getvaluefield(sym)); getvaluefield(sym));
else if (sym->nType & (SYMF_MACRO | SYMF_STRING)) { else if (sym->nType & (SYMF_MACRO | SYMF_STRING)) {
ULONG i = 0; ULONG i = 0;
@@ -950,24 +957,23 @@ void sym_PrintSymbolTable(void)
printf("\"\n"); printf("\"\n");
} else if (sym->nType & SYMF_EXPORT) } else if (sym->nType & SYMF_EXPORT)
printf("EXPORT: '%s' - %08lX\n", sym->tzName, printf("EXPORT: '%s' - %08lX\n", sym->tzName,
getvaluefield(sym)); getvaluefield(sym));
else if (sym->nType & SYMF_IMPORT) else if (sym->nType & SYMF_IMPORT)
printf("IMPORT: '%s'\n", sym->tzName); printf("IMPORT: '%s'\n", sym->tzName);
else if (sym->nType & SYMF_EQU) else if (sym->nType & SYMF_EQU)
printf("EQU : '%s' - %08lX\n", sym->tzName, printf("EQU : '%s' - %08lX\n", sym->tzName,
getvaluefield(sym)); getvaluefield(sym));
else if (sym->nType & SYMF_SET) else if (sym->nType & SYMF_SET)
printf("SET : '%s' - %08lX\n", sym->tzName, printf("SET : '%s' - %08lX\n", sym->tzName,
getvaluefield(sym)); getvaluefield(sym));
else else
printf("SYMBOL: '%s' - %08lX\n", sym->tzName, printf("SYMBOL: '%s' - %08lX\n", sym->tzName,
getvaluefield(sym)); getvaluefield(sym));
sym = sym->pNext; sym = sym->pNext;
} }
} }
} }
/* /*
* RGBAsm - SYMBOL.C - Symboltable stuff * RGBAsm - SYMBOL.C - Symboltable stuff
* *
@@ -975,7 +981,8 @@ void sym_PrintSymbolTable(void)
* *
*/ */
void sym_DumpMacroArgs(void) void
sym_DumpMacroArgs(void)
{ {
ULONG i; ULONG i;

View File

@@ -36,16 +36,16 @@ unsigned char NintendoChar[48] = {
0xBB, 0xBB, 0x67, 0x63, 0x6E, 0x0E, 0xEC, 0xCC, 0xBB, 0xBB, 0x67, 0x63, 0x6E, 0x0E, 0xEC, 0xCC,
0xDD, 0xDC, 0x99, 0x9F, 0xBB, 0xB9, 0x33, 0x3E, 0xDD, 0xDC, 0x99, 0x9F, 0xBB, 0xB9, 0x33, 0x3E,
}; };
/* /*
* Misc. routines * Misc. routines
* *
*/ */
void PrintUsage(void) void
PrintUsage(void)
{ {
printf("RGBFix v" RGBFIX_VERSION printf("RGBFix v" RGBFIX_VERSION
" (part of ASMotor " ASMOTOR_VERSION ")\n\n"); " (part of ASMotor " ASMOTOR_VERSION ")\n\n");
printf("Usage: rgbfix [options] image[.gb]\n"); printf("Usage: rgbfix [options] image[.gb]\n");
printf("Options:\n"); printf("Options:\n");
@@ -60,30 +60,34 @@ void PrintUsage(void)
exit(0); exit(0);
} }
void vFatalError(char *s, va_list ap) void
vFatalError(char *s, va_list ap)
{ {
fprintf(stderr, "*ERROR* : "); fprintf(stderr, "*ERROR* : ");
vfprintf(stderr, s, ap); vfprintf(stderr, s, ap);
fprintf(stderr, "\n"); fprintf(stderr, "\n");
} }
void FatalError(char *s, ...) void
FatalError(char *s,...)
{ {
va_list ap; va_list ap;
va_start (ap, s); va_start(ap, s);
vFatalError(s, ap); vFatalError(s, ap);
va_end(ap); va_end(ap);
exit(5); exit(5);
} }
void vWarning(char *s, va_list ap) void
vWarning(char *s, va_list ap)
{ {
fprintf(stderr, "*WARNING* : "); fprintf(stderr, "*WARNING* : ");
vfprintf(stderr, s, ap); vfprintf(stderr, s, ap);
fprintf(stderr, "\n"); fprintf(stderr, "\n");
} }
void Warning(char *s, ...) void
Warning(char *s,...)
{ {
va_list ap; va_list ap;
va_start(ap, s); va_start(ap, s);
@@ -91,7 +95,8 @@ void Warning(char *s, ...)
va_end(ap); va_end(ap);
} }
long int FileSize(FILE * f) long int
FileSize(FILE * f)
{ {
long prevpos; long prevpos;
long r; long r;
@@ -104,7 +109,8 @@ long int FileSize(FILE * f)
return (r); return (r);
} }
int FileExists(char *s) int
FileExists(char *s)
{ {
FILE *f; FILE *f;
@@ -114,13 +120,13 @@ int FileExists(char *s)
} else } else
return (0); return (0);
} }
/* /*
* Das main * Das main
* *
*/ */
int main(int argc, char *argv[]) int
main(int argc, char *argv[])
{ {
int argn = 1; int argn = 1;
char filename[512]; char filename[512];
@@ -133,7 +139,7 @@ int main(int argc, char *argv[])
PrintUsage(); PrintUsage();
while (argn < argc) { while (argn < argc) {
if(argv[argn][0] == '-') { if (argv[argn][0] == '-') {
switch (argv[argn][1]) { switch (argv[argn][1]) {
case '?': case '?':
case 'h': case 'h':
@@ -156,14 +162,14 @@ int main(int argc, char *argv[])
ulOptions |= OPTF_TITLE; ulOptions |= OPTF_TITLE;
break; break;
case 'q': case 'q':
ulOptions|=OPTF_QUIET; ulOptions |= OPTF_QUIET;
break; break;
} }
} }
argn++; argn++;
} }
if(argv[argc - 1][0] == '-') if (argv[argc - 1][0] == '-')
PrintUsage(); PrintUsage();
strcpy(filename, argv[argc - 1]); strcpy(filename, argv[argc - 1]);
@@ -172,7 +178,7 @@ int main(int argc, char *argv[])
strcat(filename, ".gb"); strcat(filename, ".gb");
f = fopen(filename, "rb+"); f = fopen(filename, "rb+");
if( (f=fopen(filename,"rb+"))!=NULL ) { if ((f = fopen(filename, "rb+")) != NULL) {
/* /*
* -d (Debug) option code * -d (Debug) option code
@@ -182,7 +188,6 @@ int main(int argc, char *argv[])
if ((ulOptions & OPTF_DEBUG) && !(ulOptions & OPTF_QUIET)) { if ((ulOptions & OPTF_DEBUG) && !(ulOptions & OPTF_QUIET)) {
printf("-d (Debug) option enabled...\n"); printf("-d (Debug) option enabled...\n");
} }
/* /*
* -p (Pad) option code * -p (Pad) option code
* *
@@ -197,10 +202,9 @@ int main(int argc, char *argv[])
while (size > padto) while (size > padto)
padto *= 2; padto *= 2;
if(!(ulOptions & OPTF_QUIET)) { if (!(ulOptions & OPTF_QUIET)) {
printf("Padding to %ldkB:\n", padto / 1024); printf("Padding to %ldkB:\n", padto / 1024);
} }
/* /*
if( padto<=0x80000L ) if( padto<=0x80000L )
{ {
@@ -217,11 +221,11 @@ int main(int argc, char *argv[])
} }
fflush(f); fflush(f);
if(!(ulOptions & OPTF_QUIET)) { if (!(ulOptions & OPTF_QUIET)) {
printf("\tAdded %ld bytes\n", bytesadded); printf("\tAdded %ld bytes\n", bytesadded);
} }
} else { } else {
if(!(ulOptions & OPTF_QUIET)) { if (!(ulOptions & OPTF_QUIET)) {
printf("\tNo padding needed\n"); printf("\tNo padding needed\n");
} }
} }
@@ -231,7 +235,6 @@ int main(int argc, char *argv[])
FatalError( "Image size exceeds 512kB" ); FatalError( "Image size exceeds 512kB" );
*/ */
} }
/* /*
* -r (Truncate) option code * -r (Truncate) option code
* *
@@ -247,10 +250,9 @@ int main(int argc, char *argv[])
while (size < padto) while (size < padto)
padto /= 2; padto /= 2;
if(!(ulOptions & OPTF_QUIET)) { if (!(ulOptions & OPTF_QUIET)) {
printf("Truncating to %ldkB:\n", padto / 1024); printf("Truncating to %ldkB:\n", padto / 1024);
} }
mkstemp(tempfile); mkstemp(tempfile);
if ((ulOptions & OPTF_DEBUG) == 0) { if ((ulOptions & OPTF_DEBUG) == 0) {
@@ -267,14 +269,13 @@ int main(int argc, char *argv[])
} }
} }
} }
/* /*
* -t (Set carttitle) option code * -t (Set carttitle) option code
* *
*/ */
if (ulOptions & OPTF_TITLE) { if (ulOptions & OPTF_TITLE) {
if(!(ulOptions & OPTF_QUIET)) { if (!(ulOptions & OPTF_QUIET)) {
printf("Setting cartridge title:\n"); printf("Setting cartridge title:\n");
} }
if ((ulOptions & OPTF_DEBUG) == 0) { if ((ulOptions & OPTF_DEBUG) == 0) {
@@ -283,11 +284,10 @@ int main(int argc, char *argv[])
fwrite(cartname, 16, 1, f); fwrite(cartname, 16, 1, f);
fflush(f); fflush(f);
} }
if(!(ulOptions & OPTF_QUIET)) { if (!(ulOptions & OPTF_QUIET)) {
printf("\tTitle set to %s\n", cartname); printf("\tTitle set to %s\n", cartname);
} }
} }
/* /*
* -v (Validate header) option code * -v (Validate header) option code
* *
@@ -299,10 +299,10 @@ int main(int argc, char *argv[])
long carttype; long carttype;
unsigned short cartchecksum = 0, calcchecksum = 0; unsigned short cartchecksum = 0, calcchecksum = 0;
unsigned char cartcompchecksum = 0, calccompchecksum = unsigned char cartcompchecksum = 0, calccompchecksum =
0; 0;
int ch; int ch;
if(!(ulOptions & OPTF_VALIDATE)) { if (!(ulOptions & OPTF_VALIDATE)) {
printf("Validating header:\n"); printf("Validating header:\n");
} }
fflush(stdout); fflush(stdout);
@@ -331,15 +331,14 @@ int main(int argc, char *argv[])
fflush(f); fflush(f);
if(!(ulOptions & OPTF_QUIET)) { if (!(ulOptions & OPTF_QUIET)) {
if (byteschanged) if (byteschanged)
printf printf
("\tChanged %ld bytes in the Nintendo Character Area\n", ("\tChanged %ld bytes in the Nintendo Character Area\n",
byteschanged); byteschanged);
else else
printf("\tNintendo Character Area is OK\n"); printf("\tNintendo Character Area is OK\n");
} }
/* ROM size */ /* ROM size */
fflush(f); fflush(f);
@@ -357,18 +356,16 @@ int main(int argc, char *argv[])
fputc(calcromsize, f); fputc(calcromsize, f);
fflush(f); fflush(f);
} }
if(!(ulOptions & OPTF_QUIET)) { if (!(ulOptions & OPTF_QUIET)) {
printf("\tChanged ROM size byte from 0x%02lX (%ldkB) to 0x%02lX (%ldkB)\n", printf("\tChanged ROM size byte from 0x%02lX (%ldkB) to 0x%02lX (%ldkB)\n",
cartromsize, cartromsize,
(0x8000L << cartromsize) / 1024, (0x8000L << cartromsize) / 1024,
calcromsize, calcromsize,
(0x8000L << calcromsize) / 1024); (0x8000L << calcromsize) / 1024);
} }
} else } else if (!(ulOptions & OPTF_QUIET)) {
if(!(ulOptions & OPTF_QUIET)) { printf("\tROM size byte is OK\n");
printf("\tROM size byte is OK\n"); }
}
/* Cartridge type */ /* Cartridge type */
fflush(f); fflush(f);
@@ -385,17 +382,16 @@ int main(int argc, char *argv[])
fputc(0x01, f); fputc(0x01, f);
fflush(f); fflush(f);
} }
if(!(ulOptions & OPTF_QUIET)) { if (!(ulOptions & OPTF_QUIET)) {
printf printf
("\tCartridge type byte changed to 0x01\n"); ("\tCartridge type byte changed to 0x01\n");
}
} else
if(!(ulOptions & OPTF_QUIET)) {
printf("\tCartridge type byte is OK\n");
} }
} else if (!(ulOptions & OPTF_QUIET)) {
printf("\tCartridge type byte is OK\n");
}
} else { } else {
/* carttype byte can be anything? */ /* carttype byte can be anything? */
if(!(ulOptions & OPTF_QUIET)) { if (!(ulOptions & OPTF_QUIET)) {
printf("\tCartridge type byte is OK\n"); printf("\tCartridge type byte is OK\n");
} }
} }
@@ -436,13 +432,13 @@ int main(int argc, char *argv[])
fputc(calcchecksum & 0xFF, f); fputc(calcchecksum & 0xFF, f);
} }
fflush(f); fflush(f);
if(!(ulOptions & OPTF_QUIET)) { if (!(ulOptions & OPTF_QUIET)) {
printf printf
("\tChecksum changed from 0x%04lX to 0x%04lX\n", ("\tChecksum changed from 0x%04lX to 0x%04lX\n",
(long)cartchecksum, (long)calcchecksum); (long) cartchecksum, (long) calcchecksum);
} }
} else { } else {
if(!(ulOptions & OPTF_QUIET)) { if (!(ulOptions & OPTF_QUIET)) {
printf("\tChecksum is OK\n"); printf("\tChecksum is OK\n");
} }
} }
@@ -453,23 +449,22 @@ int main(int argc, char *argv[])
if ((ulOptions & OPTF_DEBUG) == 0) if ((ulOptions & OPTF_DEBUG) == 0)
fputc(calccompchecksum, f); fputc(calccompchecksum, f);
fflush(f); fflush(f);
if(!(ulOptions & OPTF_QUIET)) { if (!(ulOptions & OPTF_QUIET)) {
printf printf
("\tCompChecksum changed from 0x%02lX to 0x%02lX\n", ("\tCompChecksum changed from 0x%02lX to 0x%02lX\n",
(long)cartcompchecksum, (long) cartcompchecksum,
(long)calccompchecksum); (long) calccompchecksum);
} }
} else { } else {
if(!(ulOptions & OPTF_QUIET)) { if (!(ulOptions & OPTF_QUIET)) {
printf("\tCompChecksum is OK\n"); printf("\tCompChecksum is OK\n");
} }
} }
} }
fclose(f); fclose(f);
} else { } else {
FatalError("File '%s' not found",filename); FatalError("File '%s' not found", filename);
} }
return (0); return (0);

View File

@@ -7,7 +7,8 @@
extern void fatalerror(char *s); extern void fatalerror(char *s);
SLONG file_Length(FILE * f) SLONG
file_Length(FILE * f)
{ {
ULONG r, p; ULONG r, p;
@@ -19,7 +20,8 @@ SLONG file_Length(FILE * f)
return (r); return (r);
} }
SLONG file_ReadASCIIz(char *b, FILE * f) SLONG
file_ReadASCIIz(char *b, FILE * f)
{ {
SLONG r = 0; SLONG r = 0;
@@ -29,7 +31,8 @@ SLONG file_ReadASCIIz(char *b, FILE * f)
return (r + 1); return (r + 1);
} }
void file_WriteASCIIz(char *b, FILE * f) void
file_WriteASCIIz(char *b, FILE * f)
{ {
while (*b) while (*b)
fputc(*b++, f); fputc(*b++, f);
@@ -37,7 +40,8 @@ void file_WriteASCIIz(char *b, FILE * f)
fputc(0, f); fputc(0, f);
} }
UWORD file_ReadWord(FILE * f) UWORD
file_ReadWord(FILE * f)
{ {
UWORD r; UWORD r;
@@ -47,13 +51,15 @@ UWORD file_ReadWord(FILE * f)
return (r); return (r);
} }
void file_WriteWord(UWORD w, FILE * f) void
file_WriteWord(UWORD w, FILE * f)
{ {
fputc(w, f); fputc(w, f);
fputc(w >> 8, f); fputc(w >> 8, f);
} }
ULONG file_ReadLong(FILE * f) ULONG
file_ReadLong(FILE * f)
{ {
ULONG r; ULONG r;
@@ -65,7 +71,8 @@ ULONG file_ReadLong(FILE * f)
return (r); return (r);
} }
void file_WriteLong(UWORD w, FILE * f) void
file_WriteLong(UWORD w, FILE * f)
{ {
fputc(w, f); fputc(w, f);
fputc(w >> 8, f); fputc(w >> 8, f);
@@ -73,7 +80,8 @@ void file_WriteLong(UWORD w, FILE * f)
fputc(w >> 24, f); fputc(w >> 24, f);
} }
sLibrary *lib_ReadLib0(FILE * f, SLONG size) sLibrary *
lib_ReadLib0(FILE * f, SLONG size)
{ {
if (size) { if (size) {
sLibrary *l = NULL, *first = NULL; sLibrary *l = NULL, *first = NULL;
@@ -102,7 +110,7 @@ sLibrary *lib_ReadLib0(FILE * f, SLONG size)
size -= 4; size -= 4;
if ((l->pData = 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;
} else } else
fatalerror("Out of memory"); fatalerror("Out of memory");
@@ -111,11 +119,11 @@ sLibrary *lib_ReadLib0(FILE * f, SLONG size)
} }
return (first); return (first);
} }
return (NULL); return (NULL);
} }
sLibrary *lib_Read(char *filename) sLibrary *
lib_Read(char *filename)
{ {
FILE *f; FILE *f;
@@ -128,7 +136,6 @@ sLibrary *lib_Read(char *filename)
fclose(f); fclose(f);
return (NULL); return (NULL);
} }
fread(ID, sizeof(char), 4, f); fread(ID, sizeof(char), 4, f);
ID[4] = 0; ID[4] = 0;
size -= 4; size -= 4;
@@ -148,12 +155,13 @@ sLibrary *lib_Read(char *filename)
} else { } else {
printf printf
("Library '%s' not found, it will be created if necessary\n", ("Library '%s' not found, it will be created if necessary\n",
filename); filename);
return (NULL); return (NULL);
} }
} }
BBOOL lib_Write(sLibrary * lib, char *filename) BBOOL
lib_Write(sLibrary * lib, char *filename)
{ {
FILE *f; FILE *f;
@@ -172,11 +180,11 @@ BBOOL lib_Write(sLibrary * lib, char *filename)
printf("Library '%s' closed\n", filename); printf("Library '%s' closed\n", filename);
return (1); return (1);
} }
return (0); return (0);
} }
void TruncateFileName(char *dest, char *src) void
TruncateFileName(char *dest, char *src)
{ {
SLONG l; SLONG l;
@@ -187,7 +195,8 @@ void TruncateFileName(char *dest, char *src)
strcpy(dest, &src[l + 1]); strcpy(dest, &src[l + 1]);
} }
sLibrary *lib_Find(sLibrary * lib, char *filename) sLibrary *
lib_Find(sLibrary * lib, char *filename)
{ {
char truncname[MAXNAMELENGTH]; char truncname[MAXNAMELENGTH];
@@ -203,7 +212,8 @@ sLibrary *lib_Find(sLibrary * lib, char *filename)
return (lib); return (lib);
} }
sLibrary *lib_AddReplace(sLibrary * lib, char *filename) sLibrary *
lib_AddReplace(sLibrary * lib, char *filename)
{ {
FILE *f; FILE *f;
@@ -237,11 +247,11 @@ sLibrary *lib_AddReplace(sLibrary * lib, char *filename)
fclose(f); fclose(f);
} }
return (lib); return (lib);
} }
sLibrary *lib_DeleteModule(sLibrary * lib, char *filename) sLibrary *
lib_DeleteModule(sLibrary * lib, char *filename)
{ {
char truncname[MAXNAMELENGTH]; char truncname[MAXNAMELENGTH];
sLibrary **pp, **first; sLibrary **pp, **first;
@@ -276,7 +286,8 @@ sLibrary *lib_DeleteModule(sLibrary * lib, char *filename)
return (*first); return (*first);
} }
void lib_Free(sLibrary * lib) void
lib_Free(sLibrary * lib)
{ {
while (lib) { while (lib) {
sLibrary *l; sLibrary *l;

View File

@@ -8,7 +8,7 @@
#include "lib/types.h" #include "lib/types.h"
#include "lib/library.h" #include "lib/library.h"
// Quick and dirty...but it works // Quick and dirty...but it works
#ifdef __GNUC__ #ifdef __GNUC__
#define strcmpi strcasecmp #define strcmpi strcasecmp
#endif #endif
@@ -18,34 +18,35 @@
* *
*/ */
void fatalerror(char *s) void
fatalerror(char *s)
{ {
fprintf(stderr,"*ERROR* : %s\n", s); fprintf(stderr, "*ERROR* : %s\n", s);
exit(5); exit(5);
} }
/* /*
* Print the usagescreen * Print the usagescreen
* *
*/ */
void PrintUsage(void) void
PrintUsage(void)
{ {
printf("xLib v" LIB_VERSION " (part of ASMotor " ASMOTOR_VERSION ")\n\n" printf("xLib v" LIB_VERSION " (part of ASMotor " ASMOTOR_VERSION ")\n\n"
"Usage: xlib library command [module1 module2 ... modulen]\n" "Usage: xlib library command [module1 module2 ... modulen]\n"
"Commands:\n\ta\tAdd/replace modules to library\n" "Commands:\n\ta\tAdd/replace modules to library\n"
"\td\tDelete modules from library\n" "\td\tDelete modules from library\n"
"\tl\tList library contents\n" "\tl\tList library contents\n"
"\tx\tExtract modules from library\n"); "\tx\tExtract modules from library\n");
exit(0); exit(0);
} }
/* /*
* The main routine * The main routine
* *
*/ */
int main(int argc, char *argv[]) int
main(int argc, char *argv[])
{ {
SLONG argn = 0; SLONG argn = 0;
char *libname; char *libname;
@@ -90,8 +91,8 @@ int main(int argc, char *argv[])
while (l) { while (l) {
printf("%10ld %s\n", printf("%10ld %s\n",
l->nByteLength, l->nByteLength,
l->tName); l->tName);
l = l->pNext; l = l->pNext;
} }
} }
@@ -106,13 +107,13 @@ int main(int argc, char *argv[])
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,
f); f);
fclose(f); fclose(f);
printf printf
("Extracted module '%s'\n", ("Extracted module '%s'\n",
argv[argn]); argv[argn]);
} else } else
fatalerror fatalerror
("Unable to write module"); ("Unable to write module");

View File

@@ -18,7 +18,8 @@ SLONG MaxBankUsed;
#define DOMAXBANK(x) {if( (x)>MaxBankUsed ) MaxBankUsed=(x);} #define DOMAXBANK(x) {if( (x)>MaxBankUsed ) MaxBankUsed=(x);}
SLONG area_Avail(SLONG bank) SLONG
area_Avail(SLONG bank)
{ {
SLONG r; SLONG r;
struct sFreeArea *pArea; struct sFreeArea *pArea;
@@ -34,7 +35,8 @@ SLONG area_Avail(SLONG bank)
return (r); return (r);
} }
SLONG area_AllocAbs(struct sFreeArea ** ppArea, SLONG org, SLONG size) SLONG
area_AllocAbs(struct sFreeArea ** ppArea, SLONG org, SLONG size)
{ {
struct sFreeArea *pArea; struct sFreeArea *pArea;
@@ -55,8 +57,8 @@ SLONG area_AllocAbs(struct sFreeArea ** ppArea, SLONG org, SLONG size)
struct sFreeArea *pNewArea; struct sFreeArea *pNewArea;
if ((pNewArea = if ((pNewArea =
(struct sFreeArea *) (struct sFreeArea *)
malloc(sizeof(struct sFreeArea))) malloc(sizeof(struct sFreeArea)))
!= NULL) { != NULL) {
*pNewArea = *pArea; *pNewArea = *pArea;
pNewArea->pPrev = pArea; pNewArea->pPrev = pArea;
@@ -80,7 +82,8 @@ SLONG area_AllocAbs(struct sFreeArea ** ppArea, SLONG org, SLONG size)
return (-1); return (-1);
} }
SLONG area_AllocAbsCODEAnyBank(SLONG org, SLONG size) SLONG
area_AllocAbsCODEAnyBank(SLONG org, SLONG size)
{ {
SLONG i; SLONG i;
@@ -92,7 +95,8 @@ SLONG area_AllocAbsCODEAnyBank(SLONG org, SLONG size)
return (-1); return (-1);
} }
SLONG area_Alloc(struct sFreeArea ** ppArea, SLONG size) SLONG
area_Alloc(struct sFreeArea ** ppArea, SLONG size)
{ {
struct sFreeArea *pArea; struct sFreeArea *pArea;
@@ -114,7 +118,8 @@ SLONG area_Alloc(struct sFreeArea ** ppArea, SLONG size)
return (-1); return (-1);
} }
SLONG area_AllocCODEAnyBank(SLONG size) SLONG
area_AllocCODEAnyBank(SLONG size)
{ {
SLONG i, org; SLONG i, org;
@@ -126,7 +131,8 @@ SLONG area_AllocCODEAnyBank(SLONG size)
return (-1); return (-1);
} }
struct sSection *FindLargestCode(void) struct sSection *
FindLargestCode(void)
{ {
struct sSection *pSection, *r = NULL; struct sSection *pSection, *r = NULL;
SLONG nLargest = 0; SLONG nLargest = 0;
@@ -144,7 +150,8 @@ struct sSection *FindLargestCode(void)
return (r); return (r);
} }
void AssignCodeSections(void) void
AssignCodeSections(void)
{ {
struct sSection *pSection; struct sSection *pSection;
@@ -161,7 +168,8 @@ void AssignCodeSections(void)
} }
} }
void GBROM_AssignSections(void) void
GBROM_AssignSections(void)
{ {
SLONG i; SLONG i;
struct sSection *pSection; struct sSection *pSection;
@@ -234,10 +242,10 @@ void GBROM_AssignSections(void)
case SECT_BSS: case SECT_BSS:
if (area_AllocAbs if (area_AllocAbs
(&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 $%lX", "Unable to load fixed BSS section at $%lX",
pSection->nOrg); pSection->nOrg);
fatalerror(temptext); fatalerror(temptext);
} }
pSection->oAssigned = 1; pSection->oAssigned = 1;
@@ -246,10 +254,10 @@ void GBROM_AssignSections(void)
case SECT_HRAM: case SECT_HRAM:
if (area_AllocAbs if (area_AllocAbs
(&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 $%lX", "Unable to load fixed HRAM section at $%lX",
pSection->nOrg); pSection->nOrg);
fatalerror(temptext); fatalerror(temptext);
} }
pSection->oAssigned = 1; pSection->oAssigned = 1;
@@ -258,10 +266,10 @@ void GBROM_AssignSections(void)
case SECT_VRAM: case SECT_VRAM:
if (area_AllocAbs if (area_AllocAbs
(&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 $%lX", "Unable to load fixed VRAM section at $%lX",
pSection->nOrg); pSection->nOrg);
fatalerror(temptext); fatalerror(temptext);
} }
pSection->oAssigned = 1; pSection->oAssigned = 1;
@@ -270,10 +278,10 @@ void GBROM_AssignSections(void)
case SECT_HOME: case SECT_HOME:
if (area_AllocAbs if (area_AllocAbs
(&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 $%lX", "Unable to load fixed HOME section at $%lX",
pSection->nOrg); pSection->nOrg);
fatalerror(temptext); fatalerror(temptext);
} }
pSection->oAssigned = 1; pSection->oAssigned = 1;
@@ -314,30 +322,30 @@ void GBROM_AssignSections(void)
&& pSection->nBank <= 255) { && pSection->nBank <= 255) {
if (area_AllocAbs if (area_AllocAbs
(&BankFree (&BankFree
[pSection->nBank], [pSection->nBank],
pSection->nOrg, pSection->nOrg,
pSection-> pSection->
nByteSize) != nByteSize) !=
pSection->nOrg) { pSection->nOrg) {
sprintf sprintf
(temptext, (temptext,
"Unable to load fixed CODE/DATA section at $%lX in bank $%02lX", "Unable to load fixed CODE/DATA section at $%lX in bank $%02lX",
pSection-> pSection->
nOrg, nOrg,
pSection-> pSection->
nBank); nBank);
fatalerror fatalerror
(temptext); (temptext);
} }
DOMAXBANK(pSection-> DOMAXBANK(pSection->
nBank); nBank);
pSection->oAssigned = 1; pSection->oAssigned = 1;
} else { } else {
sprintf(temptext, sprintf(temptext,
"Unable to load fixed CODE/DATA section at $%lX in bank $%02lX", "Unable to load fixed CODE/DATA section at $%lX in bank $%02lX",
pSection->nOrg, pSection->nOrg,
pSection-> pSection->
nBank); nBank);
fatalerror(temptext); fatalerror(temptext);
} }
} }
@@ -362,19 +370,19 @@ void GBROM_AssignSections(void)
/* User wants to have a say... and he's pissed */ /* User wants to have a say... and he's pissed */
if (pSection->nBank >= 1 && pSection->nBank <= 255) { if (pSection->nBank >= 1 && pSection->nBank <= 255) {
if ((pSection->nOrg = if ((pSection->nOrg =
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 $%02lX", "Unable to load fixed CODE/DATA section into bank $%02lX",
pSection->nBank); pSection->nBank);
fatalerror(temptext); fatalerror(temptext);
} }
pSection->oAssigned = 1; pSection->oAssigned = 1;
DOMAXBANK(pSection->nBank); DOMAXBANK(pSection->nBank);
} else { } else {
sprintf(temptext, sprintf(temptext,
"Unable to load fixed CODE/DATA section into bank $%02lX", "Unable to load fixed CODE/DATA section into bank $%02lX",
pSection->nBank); pSection->nBank);
fatalerror(temptext); fatalerror(temptext);
} }
} }
@@ -391,14 +399,15 @@ void GBROM_AssignSections(void)
if (pSection->oAssigned == 0 if (pSection->oAssigned == 0
&& pSection->Type == SECT_CODE && pSection->Type == SECT_CODE
&& pSection->nOrg != -1 && pSection->nBank == -1) { && pSection->nOrg != -1 && pSection->nBank == -1) {
/* User wants to have a say... and he's back with a vengeance */ /* User wants to have a say... and he's back with a
* vengeance */
if ((pSection->nBank = if ((pSection->nBank =
area_AllocAbsCODEAnyBank(pSection->nOrg, area_AllocAbsCODEAnyBank(pSection->nOrg,
pSection->nByteSize)) == pSection->nByteSize)) ==
-1) { -1) {
sprintf(temptext, sprintf(temptext,
"Unable to load fixed CODE/DATA section at $%lX into any bank", "Unable to load fixed CODE/DATA section at $%lX into any bank",
pSection->nOrg); pSection->nOrg);
fatalerror(temptext); fatalerror(temptext);
} }
pSection->oAssigned = 1; pSection->oAssigned = 1;
@@ -419,8 +428,8 @@ void GBROM_AssignSections(void)
switch (pSection->Type) { switch (pSection->Type) {
case SECT_BSS: case SECT_BSS:
if ((pSection->nOrg = if ((pSection->nOrg =
area_Alloc(&BankFree[BANK_BSS], area_Alloc(&BankFree[BANK_BSS],
pSection->nByteSize)) == -1) { pSection->nByteSize)) == -1) {
fatalerror("BSS section too large\n"); fatalerror("BSS section too large\n");
} }
pSection->nBank = BANK_BSS; pSection->nBank = BANK_BSS;
@@ -428,8 +437,8 @@ void GBROM_AssignSections(void)
break; break;
case SECT_HRAM: case SECT_HRAM:
if ((pSection->nOrg = if ((pSection->nOrg =
area_Alloc(&BankFree[BANK_HRAM], area_Alloc(&BankFree[BANK_HRAM],
pSection->nByteSize)) == -1) { pSection->nByteSize)) == -1) {
fatalerror("HRAM section too large"); fatalerror("HRAM section too large");
} }
pSection->nBank = BANK_HRAM; pSection->nBank = BANK_HRAM;
@@ -437,8 +446,8 @@ void GBROM_AssignSections(void)
break; break;
case SECT_VRAM: case SECT_VRAM:
if ((pSection->nOrg = if ((pSection->nOrg =
area_Alloc(&BankFree[BANK_VRAM], area_Alloc(&BankFree[BANK_VRAM],
pSection->nByteSize)) == -1) { pSection->nByteSize)) == -1) {
fatalerror("VRAM section too large"); fatalerror("VRAM section too large");
} }
pSection->nBank = BANK_VRAM; pSection->nBank = BANK_VRAM;
@@ -446,8 +455,8 @@ void GBROM_AssignSections(void)
break; break;
case SECT_HOME: case SECT_HOME:
if ((pSection->nOrg = if ((pSection->nOrg =
area_Alloc(&BankFree[BANK_HOME], area_Alloc(&BankFree[BANK_HOME],
pSection->nByteSize)) == -1) { pSection->nByteSize)) == -1) {
fatalerror("HOME section too large"); fatalerror("HOME section too large");
} }
pSection->nBank = BANK_HOME; pSection->nBank = BANK_HOME;
@@ -466,7 +475,8 @@ void GBROM_AssignSections(void)
AssignCodeSections(); AssignCodeSections();
} }
void PSION2_AssignSections(void) void
PSION2_AssignSections(void)
{ {
struct sSection *pSection; struct sSection *pSection;
@@ -483,7 +493,7 @@ void PSION2_AssignSections(void)
pSection = pSections; pSection = pSections;
while (pSection) { while (pSection) {
if (pSection->oAssigned == 0 if (pSection->oAssigned == 0
&& pSection->Type == SECT_CODE) { && pSection->Type == SECT_CODE) {
pSection->oAssigned = 1; pSection->oAssigned = 1;
pSection->nBank = 0; pSection->nBank = 0;
pSection->nOrg = BankFree[0]->nOrg; pSection->nOrg = BankFree[0]->nOrg;
@@ -496,7 +506,7 @@ void PSION2_AssignSections(void)
pSection = pSections; pSection = pSections;
while (pSection) { while (pSection) {
if (pSection->oAssigned == 0 if (pSection->oAssigned == 0
&& pSection->Type == SECT_BSS) { && pSection->Type == SECT_BSS) {
pSection->oAssigned = 1; pSection->oAssigned = 1;
pSection->nBank = 0; pSection->nBank = 0;
pSection->nOrg = BankFree[0]->nOrg; pSection->nOrg = BankFree[0]->nOrg;
@@ -507,10 +517,11 @@ void PSION2_AssignSections(void)
} }
} }
void AssignSections(void) void
AssignSections(void)
{ {
switch (outputtype) { switch (outputtype) {
case OUTPUT_GBROM: case OUTPUT_GBROM:
GBROM_AssignSections(); GBROM_AssignSections();
break; break;
case OUTPUT_PSION2: case OUTPUT_PSION2:
@@ -519,7 +530,8 @@ void AssignSections(void)
} }
} }
void CreateSymbolTable(void) void
CreateSymbolTable(void)
{ {
struct sSection *pSect; struct sSection *pSect;
@@ -535,18 +547,18 @@ void CreateSymbolTable(void)
while (i--) { while (i--) {
if ((pSect->tSymbols[i]->Type == SYM_EXPORT) && if ((pSect->tSymbols[i]->Type == SYM_EXPORT) &&
((pSect->tSymbols[i]->pSection == pSect) || ((pSect->tSymbols[i]->pSection == pSect) ||
(pSect->tSymbols[i]->pSection == NULL))) { (pSect->tSymbols[i]->pSection == NULL))) {
if (pSect->tSymbols[i]->pSection == NULL) if (pSect->tSymbols[i]->pSection == NULL)
sym_CreateSymbol(pSect->tSymbols[i]-> sym_CreateSymbol(pSect->tSymbols[i]->
pzName, pzName,
pSect->tSymbols[i]-> pSect->tSymbols[i]->
nOffset, -1); nOffset, -1);
else else
sym_CreateSymbol(pSect->tSymbols[i]-> sym_CreateSymbol(pSect->tSymbols[i]->
pzName, pzName,
pSect->nOrg + pSect->nOrg +
pSect->tSymbols[i]-> pSect->tSymbols[i]->
nOffset, pSect->nBank); nOffset, pSect->nBank);
} }
} }
pSect = pSect->pNext; pSect = pSect->pNext;

View File

@@ -6,7 +6,8 @@
#include "link/mylink.h" #include "link/mylink.h"
#include "link/main.h" #include "link/main.h"
static BBOOL symboldefined(char *name) static BBOOL
symboldefined(char *name)
{ {
struct sSection *pSect; struct sSection *pSect;
@@ -23,14 +24,14 @@ static BBOOL symboldefined(char *name)
0) 0)
return (1); return (1);
} }
} }
pSect = pSect->pNext; pSect = pSect->pNext;
} }
return (0); return (0);
} }
static BBOOL addmodulecontaining(char *name) static BBOOL
addmodulecontaining(char *name)
{ {
struct sSection **ppLSect; struct sSection **ppLSect;
@@ -46,7 +47,7 @@ static BBOOL addmodulecontaining(char *name)
(*ppLSect)->tSymbols[i]->pSection))) { (*ppLSect)->tSymbols[i]->pSection))) {
if (strcmp if (strcmp
((*ppLSect)->tSymbols[i]->pzName, ((*ppLSect)->tSymbols[i]->pzName,
name) == 0) { name) == 0) {
struct sSection **ppSect; struct sSection **ppSect;
ppSect = &pSections; ppSect = &pSections;
while (*ppSect) while (*ppSect)
@@ -58,14 +59,14 @@ static BBOOL addmodulecontaining(char *name)
return (1); return (1);
} }
} }
} }
ppLSect = &((*ppLSect)->pNext); ppLSect = &((*ppLSect)->pNext);
} }
return (0); return (0);
} }
void AddNeededModules(void) void
AddNeededModules(void)
{ {
struct sSection *pSect; struct sSection *pSect;
@@ -84,21 +85,19 @@ void AddNeededModules(void)
*ppLSect = (*ppLSect)->pNext; *ppLSect = (*ppLSect)->pNext;
(*ppSect)->pNext = NULL; (*ppSect)->pNext = NULL;
/*ppLSect=&((*ppLSect)->pNext); */ /* ppLSect=&((*ppLSect)->pNext); */
} }
return; return;
} }
if (options & OPT_SMART_C_LINK) { if (options & OPT_SMART_C_LINK) {
if (!addmodulecontaining(smartlinkstartsymbol)) { if (!addmodulecontaining(smartlinkstartsymbol)) {
sprintf(temptext, "Can't find start symbol '%s'", sprintf(temptext, "Can't find start symbol '%s'",
smartlinkstartsymbol); smartlinkstartsymbol);
fatalerror(temptext); fatalerror(temptext);
} else } else
printf("Smart linking with symbol '%s'\n", printf("Smart linking with symbol '%s'\n",
smartlinkstartsymbol); smartlinkstartsymbol);
} }
pSect = pSections; pSect = pSections;
while (pSect) { while (pSect) {
@@ -109,10 +108,9 @@ void AddNeededModules(void)
|| (pSect->tSymbols[i]->Type == SYM_LOCAL)) { || (pSect->tSymbols[i]->Type == SYM_LOCAL)) {
if (!symboldefined(pSect->tSymbols[i]->pzName)) { if (!symboldefined(pSect->tSymbols[i]->pzName)) {
addmodulecontaining(pSect->tSymbols[i]-> addmodulecontaining(pSect->tSymbols[i]->
pzName); pzName);
} }
} }
} }
pSect = pSect->pNext; pSect = pSect->pNext;
} }

View File

@@ -13,7 +13,7 @@
#include "link/main.h" #include "link/main.h"
#include "link/library.h" #include "link/library.h"
// Quick and dirty...but it works // Quick and dirty...but it works
#ifdef __GNUC__ #ifdef __GNUC__
#define strcmpi strcasecmp #define strcmpi strcasecmp
#endif #endif
@@ -36,39 +36,40 @@ char smartlinkstartsymbol[256];
* *
*/ */
void fatalerror(char *s) void
fatalerror(char *s)
{ {
printf("*ERROR* : %s\n", s); printf("*ERROR* : %s\n", s);
exit(5); exit(5);
} }
/* /*
* Print the usagescreen * Print the usagescreen
* *
*/ */
void PrintUsage(void) void
PrintUsage(void)
{ {
printf("xLink v" LINK_VERSION " (part of ASMotor " ASMOTOR_VERSION printf("xLink v" LINK_VERSION " (part of ASMotor " ASMOTOR_VERSION
")\n\n" "Usage: xlink [options] linkfile\n" ")\n\n" "Usage: xlink [options] linkfile\n"
"Options:\n\t-h\t\tThis text\n" "Options:\n\t-h\t\tThis text\n"
"\t-m<mapfile>\tWrite a mapfile\n" "\t-m<mapfile>\tWrite a mapfile\n"
"\t-n<symfile>\tWrite a NO$GMB compatible symfile\n" "\t-n<symfile>\tWrite a NO$GMB compatible symfile\n"
"\t-z<hx>\t\tSet the byte value (hex format) used for uninitialised\n" "\t-z<hx>\t\tSet the byte value (hex format) used for uninitialised\n"
"\t\t\tdata (default is ? for random)\n" "\t\t\tdata (default is ? for random)\n"
"\t-s<symbol>\tPerform smart linking starting with <symbol>\n" "\t-s<symbol>\tPerform smart linking starting with <symbol>\n"
"\t-t\t\tOutput target\n" "\t\t-tg\tGameboy ROM image(default)\n" "\t-t\t\tOutput target\n" "\t\t-tg\tGameboy ROM image(default)\n"
"\t\t-ts\tGameboy small mode (32kB)\n" "\t\t-ts\tGameboy small mode (32kB)\n"
"\t\t-tp\tPsion2 reloc module\n"); "\t\t-tp\tPsion2 reloc module\n");
exit(0); exit(0);
} }
/* /*
* Parse the linkfile and load all the objectfiles * Parse the linkfile and load all the objectfiles
* *
*/ */
void ProcessLinkfile(char *tzLinkfile) void
ProcessLinkfile(char *tzLinkfile)
{ {
FILE *pLinkfile; FILE *pLinkfile;
enum eBlockType CurrentBlock = BLOCK_COMMENT; enum eBlockType CurrentBlock = BLOCK_COMMENT;
@@ -78,45 +79,44 @@ void ProcessLinkfile(char *tzLinkfile)
sprintf(temptext, "Unable to find linkfile '%s'\n", tzLinkfile); sprintf(temptext, "Unable to find linkfile '%s'\n", tzLinkfile);
fatalerror(temptext); fatalerror(temptext);
} }
while (!feof(pLinkfile)) { while (!feof(pLinkfile)) {
char tzLine[256]; char tzLine[256];
fscanf(pLinkfile, "%s\n", tzLine); fscanf(pLinkfile, "%s\n", tzLine);
if (tzLine[0] != '#') { if (tzLine[0] != '#') {
if (tzLine[0] == '[' if (tzLine[0] == '['
&& tzLine[strlen(tzLine) - 1] == ']') { && tzLine[strlen(tzLine) - 1] == ']') {
if (strcmpi("[objects]", tzLine) == 0) if (strcmpi("[objects]", tzLine) == 0)
CurrentBlock = BLOCK_OBJECTS; CurrentBlock = BLOCK_OBJECTS;
else if (strcmpi("[output]", tzLine) == else if (strcmpi("[output]", tzLine) ==
0) 0)
CurrentBlock = BLOCK_OUTPUT; CurrentBlock = BLOCK_OUTPUT;
else if (strcmpi("[libraries]", tzLine) else if (strcmpi("[libraries]", tzLine)
== 0) == 0)
CurrentBlock = BLOCK_LIBRARIES; CurrentBlock = BLOCK_LIBRARIES;
else if (strcmpi("[comment]", tzLine) == else if (strcmpi("[comment]", tzLine) ==
0) 0)
CurrentBlock = BLOCK_COMMENT; CurrentBlock = BLOCK_COMMENT;
else { else {
fclose(pLinkfile); fclose(pLinkfile);
sprintf(temptext, sprintf(temptext,
"Unknown block '%s'\n", "Unknown block '%s'\n",
tzLine); tzLine);
fatalerror(temptext); fatalerror(temptext);
} }
} else { } else {
switch (CurrentBlock) { switch (CurrentBlock) {
case BLOCK_COMMENT: case BLOCK_COMMENT:
break; break;
case BLOCK_OBJECTS: case BLOCK_OBJECTS:
obj_Readfile(tzLine); obj_Readfile(tzLine);
break; break;
case BLOCK_LIBRARIES: case BLOCK_LIBRARIES:
lib_Readfile(tzLine); lib_Readfile(tzLine);
break; break;
case BLOCK_OUTPUT: case BLOCK_OUTPUT:
out_Setname(tzLine); out_Setname(tzLine);
break; break;
} }
} }
} }
@@ -124,13 +124,13 @@ void ProcessLinkfile(char *tzLinkfile)
fclose(pLinkfile); fclose(pLinkfile);
} }
/* /*
* The main routine * The main routine
* *
*/ */
int main(int argc, char *argv[]) int
main(int argc, char *argv[])
{ {
SLONG argn = 0; SLONG argn = 0;
@@ -168,7 +168,7 @@ int main(int argc, char *argv[])
break; break;
default: default:
sprintf(temptext, "Unknown option 't%c'\n", sprintf(temptext, "Unknown option 't%c'\n",
opt); opt);
fatalerror(temptext); fatalerror(temptext);
break; break;
} }
@@ -182,7 +182,7 @@ int main(int argc, char *argv[])
result = result =
sscanf(argv[argn - 1] + 2, "%lx", sscanf(argv[argn - 1] + 2, "%lx",
&fillchar); &fillchar);
if (!((result == EOF) || (result == 1))) { if (!((result == EOF) || (result == 1))) {
fatalerror fatalerror
("Invalid argument for option 'z'\n"); ("Invalid argument for option 'z'\n");

View File

@@ -13,7 +13,8 @@ FILE *sf = NULL;
SLONG currentbank = 0; SLONG currentbank = 0;
SLONG sfbank; SLONG sfbank;
void SetMapfileName(char *name) void
SetMapfileName(char *name)
{ {
mf = fopen(name, "wt"); mf = fopen(name, "wt");
@@ -21,7 +22,8 @@ void SetMapfileName(char *name)
fatalerror("Unable to open mapfile for writing"); fatalerror("Unable to open mapfile for writing");
} }
void SetSymfileName(char *name) void
SetSymfileName(char *name)
{ {
sf = fopen(name, "wt"); sf = fopen(name, "wt");
@@ -31,7 +33,8 @@ void SetSymfileName(char *name)
fprintf(sf, ";File generated by xLink v" LINK_VERSION "\n\n"); fprintf(sf, ";File generated by xLink v" LINK_VERSION "\n\n");
} }
void CloseMapfile(void) void
CloseMapfile(void)
{ {
if (mf) { if (mf) {
fclose(mf); fclose(mf);
@@ -43,7 +46,8 @@ void CloseMapfile(void)
} }
} }
void MapfileInitBank(SLONG bank) void
MapfileInitBank(SLONG bank)
{ {
if (mf) { if (mf) {
currentbank = bank; currentbank = bank;
@@ -58,13 +62,13 @@ void MapfileInitBank(SLONG bank)
else if (bank == BANK_VRAM) else if (bank == BANK_VRAM)
fprintf(mf, "VRAM:\n"); fprintf(mf, "VRAM:\n");
} }
if (sf) { if (sf) {
sfbank = (bank >= 1 && bank <= 255) ? bank : 0; sfbank = (bank >= 1 && bank <= 255) ? bank : 0;
} }
} }
void MapfileWriteSection(struct sSection *pSect) void
MapfileWriteSection(struct sSection * pSect)
{ {
if (!mf && !sf) if (!mf && !sf)
return; return;
@@ -72,30 +76,30 @@ void MapfileWriteSection(struct sSection *pSect)
SLONG i; SLONG i;
fprintf(mf, " SECTION: $%04lX-$%04lX ($%04lX 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);
for (i = 0; i < pSect->nNumberOfSymbols; i += 1) { for (i = 0; i < pSect->nNumberOfSymbols; i += 1) {
struct sSymbol *pSym; struct sSymbol *pSym;
pSym = pSect->tSymbols[i]; pSym = pSect->tSymbols[i];
if ((pSym->pSection == pSect) if ((pSym->pSection == pSect)
&& (pSym->Type != SYM_IMPORT)) { && (pSym->Type != SYM_IMPORT)) {
if (mf) { if (mf) {
fprintf(mf, " $%04lX = %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, "%02lX:%04lX %s\n", sfbank, fprintf(sf, "%02lX:%04lX %s\n", sfbank,
pSym->nOffset + pSect->nOrg, pSym->nOffset + pSect->nOrg,
pSym->pzName); pSym->pzName);
} }
} }
} }
} }
void MapfileCloseBank(SLONG slack) void
MapfileCloseBank(SLONG slack)
{ {
if (!mf) if (!mf)
return; return;

View File

@@ -21,7 +21,8 @@ BBOOL oReadLib = 0;
* *
*/ */
SLONG readlong(FILE * f) SLONG
readlong(FILE * f)
{ {
SLONG r; SLONG r;
@@ -33,7 +34,8 @@ SLONG readlong(FILE * f)
return (r); return (r);
} }
UWORD readword(FILE * f) UWORD
readword(FILE * f)
{ {
UWORD r; UWORD r;
@@ -42,13 +44,13 @@ UWORD readword(FILE * f)
return (r); return (r);
} }
/* /*
* Read a NULL terminated string from a file * Read a NULL terminated string from a file
* *
*/ */
SLONG readasciiz(char *s, FILE * f) SLONG
readasciiz(char *s, FILE * f)
{ {
SLONG r = 0; SLONG r = 0;
@@ -57,13 +59,13 @@ SLONG readasciiz(char *s, FILE * f)
return (r + 1); return (r + 1);
} }
/* /*
* Allocate a new section and link it into the list * Allocate a new section and link it into the list
* *
*/ */
struct sSection *AllocSection(void) struct sSection *
AllocSection(void)
{ {
struct sSection **ppSections; struct sSection **ppSections;
@@ -80,20 +82,19 @@ struct sSection *AllocSection(void)
fatalerror("Out of memory!"); fatalerror("Out of memory!");
return NULL; 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;
} }
/* /*
* Read a symbol from a file * Read a symbol from a file
* *
*/ */
struct sSymbol *obj_ReadSymbol(FILE * f) struct sSymbol *
obj_ReadSymbol(FILE * f)
{ {
char s[256]; char s[256];
struct sSymbol *pSym; struct sSymbol *pSym;
@@ -108,27 +109,26 @@ struct sSymbol *obj_ReadSymbol(FILE * f)
fatalerror("Out of memory!"); fatalerror("Out of memory!");
strcpy(pSym->pzName, s); strcpy(pSym->pzName, s);
if ((pSym->Type = (enum eSymbolType)fgetc(f)) != SYM_IMPORT) { if ((pSym->Type = (enum eSymbolType) fgetc(f)) != SYM_IMPORT) {
pSym->nSectionID = readlong(f); pSym->nSectionID = readlong(f);
pSym->nOffset = readlong(f); pSym->nOffset = readlong(f);
} }
return pSym; return pSym;
} }
/* /*
* RGB0 object reader routines * RGB0 object reader routines
* *
*/ */
struct sSection *obj_ReadRGB0Section(FILE * f) struct sSection *
obj_ReadRGB0Section(FILE * f)
{ {
struct sSection *pSection; struct sSection *pSection;
pSection = AllocSection(); pSection = AllocSection();
pSection->nByteSize = readlong(f); pSection->nByteSize = readlong(f);
pSection->Type = (enum eSectionType)fgetc(f); pSection->Type = (enum eSectionType) fgetc(f);
pSection->nOrg = -1; pSection->nOrg = -1;
pSection->nBank = -1; pSection->nBank = -1;
@@ -137,7 +137,6 @@ struct sSection *obj_ReadRGB0Section(FILE * f)
if ((options & OPT_SMALL) && (pSection->Type == SECT_CODE)) { if ((options & OPT_SMALL) && (pSection->Type == SECT_CODE)) {
pSection->Type = SECT_HOME; pSection->Type = SECT_HOME;
} }
if ((pSection->Type == SECT_CODE) || (pSection->Type == SECT_HOME)) { if ((pSection->Type == SECT_CODE) || (pSection->Type == SECT_HOME)) {
/* /*
* These sectiontypes contain data... * These sectiontypes contain data...
@@ -153,7 +152,7 @@ struct sSection *obj_ReadRGB0Section(FILE * f)
char s[256]; char s[256];
fread(pSection->pData, sizeof(UBYTE), fread(pSection->pData, sizeof(UBYTE),
pSection->nByteSize, f); pSection->nByteSize, f);
nNumberOfPatches = readlong(f); nNumberOfPatches = readlong(f);
ppPatch = &pSection->pPatches; ppPatch = &pSection->pPatches;
@@ -176,12 +175,12 @@ struct sSection *obj_ReadRGB0Section(FILE * f)
strcpy(pPatch->pzFilename, s); strcpy(pPatch->pzFilename, s);
pPatch->nLineNo = pPatch->nLineNo =
readlong(f); readlong(f);
pPatch->nOffset = pPatch->nOffset =
readlong(f); readlong(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) {
pPatch->pRPN = malloc(pPatch->nRPNSize); pPatch->pRPN = malloc(pPatch->nRPNSize);
@@ -189,7 +188,7 @@ struct sSection *obj_ReadRGB0Section(FILE * f)
fatalerror("Out of memory!"); fatalerror("Out of memory!");
fread(pPatch->pRPN, sizeof(UBYTE), fread(pPatch->pRPN, sizeof(UBYTE),
pPatch->nRPNSize, f); pPatch->nRPNSize, f);
} else } else
pPatch->pRPN = NULL; pPatch->pRPN = NULL;
@@ -202,11 +201,11 @@ struct sSection *obj_ReadRGB0Section(FILE * f)
pSection->pData = &dummymem; pSection->pData = &dummymem;
} }
} }
return pSection; return pSection;
} }
void obj_ReadRGB0(FILE *pObjfile) void
obj_ReadRGB0(FILE * pObjfile)
{ {
struct sSection *pFirstSection; struct sSection *pFirstSection;
SLONG nNumberOfSymbols, nNumberOfSections, i; SLONG nNumberOfSymbols, nNumberOfSections, i;
@@ -224,7 +223,7 @@ void obj_ReadRGB0(FILE *pObjfile)
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 } else
tSymbols = (struct sSymbol **)&dummymem; tSymbols = (struct sSymbol **) & dummymem;
/* Next we have the sections */ /* Next we have the sections */
@@ -259,20 +258,20 @@ void obj_ReadRGB0(FILE *pObjfile)
tSymbols[i]->pSection = NULL; tSymbols[i]->pSection = NULL;
} }
} }
/* /*
* RGB1 object reader routines * RGB1 object reader routines
* *
*/ */
struct sSection *obj_ReadRGB1Section(FILE *f) struct sSection *
obj_ReadRGB1Section(FILE * f)
{ {
struct sSection *pSection; struct sSection *pSection;
pSection = AllocSection(); pSection = AllocSection();
pSection->nByteSize = readlong(f); pSection->nByteSize = readlong(f);
pSection->Type = (enum eSectionType)fgetc(f); pSection->Type = (enum eSectionType) fgetc(f);
/* /*
* And because of THIS new feature I'll have to rewrite loads and * And because of THIS new feature I'll have to rewrite loads and
* loads of stuff... oh well it needed to be done anyway * loads of stuff... oh well it needed to be done anyway
@@ -286,7 +285,6 @@ struct sSection *obj_ReadRGB1Section(FILE *f)
if ((options & OPT_SMALL) && (pSection->Type == SECT_CODE)) { if ((options & OPT_SMALL) && (pSection->Type == SECT_CODE)) {
pSection->Type = SECT_HOME; pSection->Type = SECT_HOME;
} }
if ((pSection->Type == SECT_CODE) || (pSection->Type == SECT_HOME)) { if ((pSection->Type == SECT_CODE) || (pSection->Type == SECT_HOME)) {
/* /*
* These sectiontypes contain data... * These sectiontypes contain data...
@@ -302,7 +300,7 @@ struct sSection *obj_ReadRGB1Section(FILE *f)
char s[256]; char s[256];
fread(pSection->pData, sizeof(UBYTE), fread(pSection->pData, sizeof(UBYTE),
pSection->nByteSize, f); pSection->nByteSize, f);
nNumberOfPatches = readlong(f); nNumberOfPatches = readlong(f);
ppPatch = &pSection->pPatches; ppPatch = &pSection->pPatches;
@@ -328,10 +326,10 @@ struct sSection *obj_ReadRGB1Section(FILE *f)
if ((pPatch->nRPNSize = readlong(f)) > 0) { if ((pPatch->nRPNSize = readlong(f)) > 0) {
pPatch->pRPN = malloc(pPatch->nRPNSize); pPatch->pRPN = malloc(pPatch->nRPNSize);
if (!pPatch->pRPN) if (!pPatch->pRPN)
fatalerror ("Out of memory!"); fatalerror("Out of memory!");
fread(pPatch->pRPN, sizeof(UBYTE), fread(pPatch->pRPN, sizeof(UBYTE),
pPatch->nRPNSize, f); pPatch->nRPNSize, f);
} else } else
pPatch->pRPN = NULL; pPatch->pRPN = NULL;
@@ -344,11 +342,11 @@ struct sSection *obj_ReadRGB1Section(FILE *f)
pSection->pData = &dummymem; pSection->pData = &dummymem;
} }
} }
return pSection; return pSection;
} }
void obj_ReadRGB1(FILE *pObjfile) void
obj_ReadRGB1(FILE * pObjfile)
{ {
struct sSection *pFirstSection; struct sSection *pFirstSection;
SLONG nNumberOfSymbols, nNumberOfSections, i; SLONG nNumberOfSymbols, nNumberOfSections, i;
@@ -366,7 +364,7 @@ void obj_ReadRGB1(FILE *pObjfile)
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 } else
tSymbols = (struct sSymbol **)&dummymem; tSymbols = (struct sSymbol **) & dummymem;
/* Next we have the sections */ /* Next we have the sections */
@@ -401,13 +399,13 @@ void obj_ReadRGB1(FILE *pObjfile)
tSymbols[i]->pSection = NULL; tSymbols[i]->pSection = NULL;
} }
} }
/* /*
* The main objectfileloadroutine (phew) * The main objectfileloadroutine (phew)
* *
*/ */
void obj_ReadOpenFile(FILE * pObjfile, char *tzObjectfile) void
obj_ReadOpenFile(FILE * pObjfile, char *tzObjectfile)
{ {
char tzHeader[8]; char tzHeader[8];
@@ -419,12 +417,13 @@ void obj_ReadOpenFile(FILE * pObjfile, char *tzObjectfile)
obj_ReadRGB0(pObjfile); obj_ReadRGB0(pObjfile);
break; break;
case '1': case '1':
case '2': // V2 is really the same but the are new patch types case '2':
obj_ReadRGB1(pObjfile); //V2 is really the same but the are new patch types
obj_ReadRGB1(pObjfile);
break; break;
default: default:
sprintf(temptext, "'%s' is an unsupported version\n", sprintf(temptext, "'%s' is an unsupported version\n",
tzObjectfile); tzObjectfile);
fatalerror(temptext); fatalerror(temptext);
break; break;
} }
@@ -434,7 +433,8 @@ void obj_ReadOpenFile(FILE * pObjfile, char *tzObjectfile)
} }
} }
void obj_Readfile(char *tzObjectfile) void
obj_Readfile(char *tzObjectfile)
{ {
FILE *pObjfile; FILE *pObjfile;
@@ -448,14 +448,14 @@ void obj_Readfile(char *tzObjectfile)
sprintf(temptext, "Unable to open '%s'\n", tzObjectfile); sprintf(temptext, "Unable to open '%s'\n", tzObjectfile);
fatalerror(temptext); fatalerror(temptext);
} }
obj_ReadOpenFile(pObjfile, tzObjectfile); obj_ReadOpenFile(pObjfile, tzObjectfile);
fclose(pObjfile); fclose(pObjfile);
oReadLib = 0; oReadLib = 0;
} }
SLONG file_Length(FILE * f) SLONG
file_Length(FILE * f)
{ {
ULONG r, p; ULONG r, p;
@@ -467,7 +467,8 @@ SLONG file_Length(FILE * f)
return (r); return (r);
} }
void lib_ReadXLB0(FILE * f) void
lib_ReadXLB0(FILE * f)
{ {
SLONG size; SLONG size;
@@ -486,7 +487,8 @@ void lib_ReadXLB0(FILE * f)
} }
} }
void lib_Readfile(char *tzLibfile) void
lib_Readfile(char *tzLibfile)
{ {
FILE *pObjfile; FILE *pObjfile;
@@ -497,7 +499,6 @@ void lib_Readfile(char *tzLibfile)
sprintf(temptext, "Unable to open '%s'\n", tzLibfile); sprintf(temptext, "Unable to open '%s'\n", tzLibfile);
fatalerror(temptext); fatalerror(temptext);
} }
char tzHeader[5]; char tzHeader[5];
fread(tzHeader, sizeof(char), 4, pObjfile); fread(tzHeader, sizeof(char), 4, pObjfile);
@@ -506,7 +507,7 @@ void lib_Readfile(char *tzLibfile)
lib_ReadXLB0(pObjfile); lib_ReadXLB0(pObjfile);
else { else {
sprintf(temptext, "'%s' is an invalid library\n", sprintf(temptext, "'%s' is an invalid library\n",
tzLibfile); tzLibfile);
fatalerror(temptext); fatalerror(temptext);
} }
fclose(pObjfile); fclose(pObjfile);

View File

@@ -10,7 +10,8 @@
char tzOutname[_MAX_PATH]; char tzOutname[_MAX_PATH];
BBOOL oOutput = 0; BBOOL oOutput = 0;
void writehome(FILE *f) void
writehome(FILE * f)
{ {
struct sSection *pSect; struct sSection *pSect;
UBYTE *mem; UBYTE *mem;
@@ -28,7 +29,7 @@ void writehome(FILE *f)
while (pSect) { while (pSect) {
if (pSect->Type == SECT_HOME) { if (pSect->Type == SECT_HOME) {
memcpy(mem + pSect->nOrg, pSect->pData, memcpy(mem + pSect->nOrg, pSect->pData,
pSect->nByteSize); pSect->nByteSize);
MapfileWriteSection(pSect); MapfileWriteSection(pSect);
} }
pSect = pSect->pNext; pSect = pSect->pNext;
@@ -40,7 +41,8 @@ void writehome(FILE *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;
@@ -52,14 +54,13 @@ void writebank(FILE *f, SLONG bank)
if (fillchar != -1) { if (fillchar != -1) {
memset(mem, fillchar, MaxAvail[bank]); memset(mem, fillchar, MaxAvail[bank]);
} }
MapfileInitBank(bank); MapfileInitBank(bank);
pSect = pSections; pSect = pSections;
while (pSect) { while (pSect) {
if (pSect->Type == SECT_CODE && pSect->nBank == bank) { if (pSect->Type == SECT_CODE && pSect->nBank == bank) {
memcpy(mem + pSect->nOrg - 0x4000, pSect->pData, memcpy(mem + pSect->nOrg - 0x4000, pSect->pData,
pSect->nByteSize); pSect->nByteSize);
MapfileWriteSection(pSect); MapfileWriteSection(pSect);
} }
pSect = pSect->pNext; pSect = pSect->pNext;
@@ -71,13 +72,15 @@ void writebank(FILE *f, SLONG bank)
free(mem); free(mem);
} }
void out_Setname(char *tzOutputfile) void
out_Setname(char *tzOutputfile)
{ {
strcpy(tzOutname, tzOutputfile); strcpy(tzOutname, tzOutputfile);
oOutput = 1; oOutput = 1;
} }
void GBROM_Output(void) void
GBROM_Output(void)
{ {
SLONG i; SLONG i;
FILE *f; FILE *f;
@@ -89,7 +92,6 @@ void GBROM_Output(void)
fclose(f); fclose(f);
} }
for (i = 256; i < MAXBANKS; i += 1) { for (i = 256; i < MAXBANKS; i += 1) {
struct sSection *pSect; struct sSection *pSect;
MapfileInitBank(i); MapfileInitBank(i);
@@ -104,7 +106,8 @@ void GBROM_Output(void)
} }
} }
void PSION2_Output(void) void
PSION2_Output(void)
{ {
FILE *f; FILE *f;
@@ -126,11 +129,11 @@ void PSION2_Output(void)
while (pSect) { while (pSect) {
if (pSect->Type == SECT_CODE) { if (pSect->Type == SECT_CODE) {
memcpy(mem + pSect->nOrg, pSect->pData, memcpy(mem + pSect->nOrg, pSect->pData,
pSect->nByteSize); pSect->nByteSize);
MapfileWriteSection(pSect); MapfileWriteSection(pSect);
} else { } else {
memset(mem + pSect->nOrg, 0, memset(mem + pSect->nOrg, 0,
pSect->nByteSize); pSect->nByteSize);
} }
pSect = pSect->pNext; pSect = pSect->pNext;
} }
@@ -140,7 +143,6 @@ void PSION2_Output(void)
fwrite(mem, 1, MaxAvail[0] - area_Avail(0), f); fwrite(mem, 1, MaxAvail[0] - area_Avail(0), f);
free(mem); free(mem);
} }
relocpatches = 0; relocpatches = 0;
pSect = pSections; pSect = pSections;
while (pSect) { while (pSect) {
@@ -187,11 +189,12 @@ void PSION2_Output(void)
} }
} }
void Output(void) void
Output(void)
{ {
if (oOutput) { if (oOutput) {
switch (outputtype) { switch (outputtype) {
case OUTPUT_GBROM: case OUTPUT_GBROM:
GBROM_Output(); GBROM_Output();
break; break;
case OUTPUT_PSION2: case OUTPUT_PSION2:

View File

@@ -10,20 +10,23 @@ SLONG rpnstack[256];
SLONG rpnp; SLONG rpnp;
SLONG nPC; SLONG nPC;
void rpnpush(SLONG i) void
rpnpush(SLONG i)
{ {
rpnstack[rpnp++] = i; rpnstack[rpnp++] = i;
} }
SLONG rpnpop(void) SLONG
rpnpop(void)
{ {
return (rpnstack[--rpnp]); return (rpnstack[--rpnp]);
} }
SLONG getsymvalue(SLONG symid) SLONG
getsymvalue(SLONG symid)
{ {
switch (pCurrentSection->tSymbols[symid]->Type) { switch (pCurrentSection->tSymbols[symid]->Type) {
case SYM_IMPORT: case SYM_IMPORT:
return (sym_GetValue(pCurrentSection->tSymbols[symid]->pzName)); return (sym_GetValue(pCurrentSection->tSymbols[symid]->pzName));
break; break;
case SYM_EXPORT: case SYM_EXPORT:
@@ -31,13 +34,13 @@ SLONG getsymvalue(SLONG symid)
{ {
if (strcmp if (strcmp
(pCurrentSection->tSymbols[symid]->pzName, (pCurrentSection->tSymbols[symid]->pzName,
"@") == 0) { "@") == 0) {
return (nPC); return (nPC);
} else } else
return (pCurrentSection->tSymbols[symid]-> return (pCurrentSection->tSymbols[symid]->
nOffset + nOffset +
pCurrentSection->tSymbols[symid]-> pCurrentSection->tSymbols[symid]->
pSection->nOrg); pSection->nOrg);
} }
default: default:
break; break;
@@ -46,16 +49,17 @@ SLONG getsymvalue(SLONG symid)
return (0); return (0);
} }
SLONG getsymbank(SLONG symid) SLONG
getsymbank(SLONG symid)
{ {
switch (pCurrentSection->tSymbols[symid]->Type) { switch (pCurrentSection->tSymbols[symid]->Type) {
case SYM_IMPORT: case SYM_IMPORT:
return (sym_GetBank(pCurrentSection->tSymbols[symid]->pzName)); return (sym_GetBank(pCurrentSection->tSymbols[symid]->pzName));
break; break;
case SYM_EXPORT: case SYM_EXPORT:
case SYM_LOCAL: case SYM_LOCAL:
return (pCurrentSection->tSymbols[symid]->pSection->nBank); return (pCurrentSection->tSymbols[symid]->pSection->nBank);
//return( pCurrentSection->nBank ); //return (pCurrentSection->nBank);
default: default:
break; break;
} }
@@ -63,7 +67,8 @@ SLONG getsymbank(SLONG symid)
return (0); return (0);
} }
SLONG calcrpn(struct sPatch * pPatch) SLONG
calcrpn(struct sPatch * pPatch)
{ {
SLONG t, size; SLONG t, size;
UBYTE *rpn; UBYTE *rpn;
@@ -154,8 +159,8 @@ 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(%ld) : 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);
} }
break; break;
@@ -164,8 +169,8 @@ 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(%ld) : 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);
} }
break; break;
@@ -212,9 +217,9 @@ SLONG calcrpn(struct sPatch * pPatch)
t = rpnpop(); t = rpnpop();
if (t < low || t > high) { if (t < low || t > high) {
sprintf(temptext, sprintf(temptext,
"%s(%ld) : Value must be in the range [%ld;%ld]", "%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);
} }
rpnpush(t); rpnpush(t);
@@ -226,7 +231,8 @@ SLONG calcrpn(struct sPatch * pPatch)
return (rpnpop()); return (rpnpop());
} }
void Patch(void) void
Patch(void)
{ {
struct sSection *pSect; struct sSection *pSect;
@@ -249,9 +255,9 @@ void Patch(void)
(UBYTE) t; (UBYTE) t;
} else { } else {
sprintf(temptext, sprintf(temptext,
"%s(%ld) : 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);
} }
break; break;
@@ -263,20 +269,20 @@ void Patch(void)
pSect->pData[pPatch->nOffset] = pSect->pData[pPatch->nOffset] =
t & 0xFF; t & 0xFF;
pSect->pData[pPatch->nOffset + pSect->pData[pPatch->nOffset +
1] = 1] =
(t >> 8) & 0xFF; (t >> 8) & 0xFF;
} else { } else {
// Assume big endian //Assume big endian
pSect->pData[pPatch->nOffset] = pSect->pData[pPatch->nOffset] =
(t >> 8) & 0xFF; (t >> 8) & 0xFF;
pSect->pData[pPatch->nOffset + pSect->pData[pPatch->nOffset +
1] = t & 0xFF; 1] = t & 0xFF;
} }
} else { } else {
sprintf(temptext, sprintf(temptext,
"%s(%ld) : 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);
} }
break; break;

View File

@@ -11,13 +11,15 @@
struct ISymbol { struct ISymbol {
char *pzName; char *pzName;
SLONG nValue; SLONG nValue;
SLONG nBank; // -1=const SLONG nBank;
//-1 = const
struct ISymbol *pNext; struct ISymbol *pNext;
}; };
struct ISymbol *tHash[HASHSIZE]; struct ISymbol *tHash[HASHSIZE];
SLONG calchash(char *s) SLONG
calchash(char *s)
{ {
SLONG r = 0; SLONG r = 0;
while (*s) while (*s)
@@ -26,14 +28,16 @@ SLONG calchash(char *s)
return (r % HASHSIZE); return (r % HASHSIZE);
} }
void sym_Init(void) void
sym_Init(void)
{ {
SLONG i; SLONG i;
for (i = 0; i < HASHSIZE; i += 1) for (i = 0; i < HASHSIZE; i += 1)
tHash[i] = NULL; tHash[i] = NULL;
} }
SLONG sym_GetValue(char *tzName) SLONG
sym_GetValue(char *tzName)
{ {
if (strcmp(tzName, "@") == 0) { if (strcmp(tzName, "@") == 0) {
return (nPC); return (nPC);
@@ -55,7 +59,8 @@ SLONG sym_GetValue(char *tzName)
} }
} }
SLONG sym_GetBank(char *tzName) SLONG
sym_GetBank(char *tzName)
{ {
struct ISymbol **ppSym; struct ISymbol **ppSym;
@@ -73,7 +78,8 @@ SLONG sym_GetBank(char *tzName)
return (0); return (0);
} }
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)
return; return;
@@ -90,8 +96,8 @@ void sym_CreateSymbol(char *tzName, SLONG nValue, SBYTE nBank)
return; return;
sprintf(temptext, sprintf(temptext,
"Symbol '%s' defined more than once\n", "Symbol '%s' defined more than once\n",
tzName); tzName);
fatalerror(temptext); fatalerror(temptext);
} }
} }