mirror of
https://github.com/gbdev/rgbds.git
synced 2025-11-20 10:12:06 +00:00
Run `indent' on the whole tree
Can't indent the .y files yet, they need special treatment. Signed-off-by: Vegard Nossum <vegard.nossum@gmail.com>
This commit is contained in:
125
src/asm/alloca.c
125
src/asm/alloca.c
@@ -43,23 +43,18 @@
|
|||||||
in order to make unexec workable
|
in order to make unexec workable
|
||||||
*/
|
*/
|
||||||
#ifndef STACK_DIRECTION
|
#ifndef STACK_DIRECTION
|
||||||
you
|
you lose-- must know STACK_DIRECTION at compile - time
|
||||||
lose
|
|
||||||
-- must know STACK_DIRECTION at compile-time
|
|
||||||
#endif /* STACK_DIRECTION undefined */
|
#endif /* STACK_DIRECTION undefined */
|
||||||
#endif /* static */
|
#endif /* static */
|
||||||
#endif /* emacs */
|
#endif /* emacs */
|
||||||
|
|
||||||
/* If your stack is a linked list of frames, you have to
|
/* If your stack is a linked list of frames, you have to
|
||||||
provide an "address metric" ADDRESS_FUNCTION macro. */
|
provide an "address metric" ADDRESS_FUNCTION macro. */
|
||||||
|
|
||||||
#if defined (CRAY) && defined (CRAY_STACKSEG_END)
|
#if defined (CRAY) && defined (CRAY_STACKSEG_END)
|
||||||
long i00afunc ();
|
long i00afunc();
|
||||||
#define ADDRESS_FUNCTION(arg) (char *) i00afunc (&(arg))
|
#define ADDRESS_FUNCTION(arg) (char *) i00afunc (&(arg))
|
||||||
#else
|
#else
|
||||||
#define ADDRESS_FUNCTION(arg) &(arg)
|
#define ADDRESS_FUNCTION(arg) &(arg)
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if __STDC__
|
#if __STDC__
|
||||||
typedef void *pointer;
|
typedef void *pointer;
|
||||||
#else
|
#else
|
||||||
@@ -109,22 +104,18 @@ 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
|
static void find_stack_direction()
|
||||||
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)
|
if (addr == NULL) { /* Initial entry. */
|
||||||
{ /* Initial entry. */
|
addr = ADDRESS_FUNCTION(dummy);
|
||||||
addr = ADDRESS_FUNCTION (dummy);
|
|
||||||
|
|
||||||
find_stack_direction (); /* Recurse once. */
|
find_stack_direction(); /* Recurse once. */
|
||||||
}
|
} else {
|
||||||
else
|
|
||||||
{
|
|
||||||
/* Second entry. */
|
/* Second entry. */
|
||||||
if (ADDRESS_FUNCTION (dummy) > addr)
|
if (ADDRESS_FUNCTION(dummy) > addr)
|
||||||
stack_dir = 1; /* Stack grew upward. */
|
stack_dir = 1; /* Stack grew upward. */
|
||||||
else
|
else
|
||||||
stack_dir = -1; /* Stack grew downward. */
|
stack_dir = -1; /* Stack grew downward. */
|
||||||
@@ -144,11 +135,9 @@ find_stack_direction ()
|
|||||||
#define ALIGN_SIZE sizeof(double)
|
#define ALIGN_SIZE sizeof(double)
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
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;
|
||||||
@@ -163,16 +152,15 @@ 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
|
pointer alloca(size)
|
||||||
alloca (size)
|
unsigned 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);
|
||||||
|
|
||||||
#if STACK_DIRECTION == 0
|
#if STACK_DIRECTION == 0
|
||||||
if (STACK_DIR == 0) /* Unknown growth direction. */
|
if (STACK_DIR == 0) /* Unknown growth direction. */
|
||||||
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
|
||||||
@@ -187,15 +175,13 @@ alloca (size)
|
|||||||
|
|
||||||
for (hp = last_alloca_header; hp != NULL;)
|
for (hp = last_alloca_header; hp != NULL;)
|
||||||
if ((STACK_DIR > 0 && hp->h.deep > depth)
|
if ((STACK_DIR > 0 && hp->h.deep > depth)
|
||||||
|| (STACK_DIR < 0 && hp->h.deep < depth))
|
|| (STACK_DIR < 0 && hp->h.deep < depth)) {
|
||||||
{
|
|
||||||
register header *np = hp->h.next;
|
register header *np = hp->h.next;
|
||||||
|
|
||||||
free ((pointer) hp); /* Collect garbage. */
|
free((pointer) hp); /* Collect garbage. */
|
||||||
|
|
||||||
hp = np; /* -> next header. */
|
hp = np; /* -> next header. */
|
||||||
}
|
} else
|
||||||
else
|
|
||||||
break; /* Rest are not deeper. */
|
break; /* Rest are not deeper. */
|
||||||
|
|
||||||
last_alloca_header = hp; /* -> last valid storage. */
|
last_alloca_header = hp; /* -> last valid storage. */
|
||||||
@@ -211,7 +197,7 @@ alloca (size)
|
|||||||
/* Allocate combined header + user data storage. */
|
/* Allocate combined header + user data storage. */
|
||||||
|
|
||||||
{
|
{
|
||||||
register pointer new = malloc (sizeof (header) + size);
|
register pointer new = malloc(sizeof(header) + size);
|
||||||
/* Address of header. */
|
/* Address of header. */
|
||||||
|
|
||||||
((header *) new)->h.next = last_alloca_header;
|
((header *) new)->h.next = last_alloca_header;
|
||||||
@@ -221,7 +207,7 @@ alloca (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));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -235,13 +221,12 @@ alloca (size)
|
|||||||
#define CRAY_STACK
|
#define CRAY_STACK
|
||||||
#ifndef CRAY2
|
#ifndef CRAY2
|
||||||
/* Stack structures for CRAY-1, CRAY X-MP, and CRAY Y-MP */
|
/* Stack structures for CRAY-1, CRAY X-MP, and CRAY Y-MP */
|
||||||
struct stack_control_header
|
struct stack_control_header {
|
||||||
{
|
|
||||||
long shgrow:32; /* Number of times stack has grown. */
|
long shgrow:32; /* Number of times stack has grown. */
|
||||||
long shaseg:32; /* Size of increments to stack. */
|
long shaseg:32; /* Size of increments to stack. */
|
||||||
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
|
||||||
@@ -250,8 +235,7 @@ struct stack_control_header
|
|||||||
0200 (octal) words. This provides for register storage
|
0200 (octal) words. This provides for register storage
|
||||||
for the routine which overflows the stack. */
|
for the routine which overflows the stack. */
|
||||||
|
|
||||||
struct stack_segment_linkage
|
struct stack_segment_linkage {
|
||||||
{
|
|
||||||
long ss[0200]; /* 0200 overflow words. */
|
long ss[0200]; /* 0200 overflow words. */
|
||||||
long sssize:32; /* Number of words in this segment. */
|
long sssize:32; /* Number of words in this segment. */
|
||||||
long ssbase:32; /* Offset to stack base. */
|
long ssbase:32; /* Offset to stack base. */
|
||||||
@@ -283,13 +267,12 @@ struct stack_segment_linkage
|
|||||||
long sss5;
|
long sss5;
|
||||||
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 required to satisfy the maximum
|
be required to satisfy the maximum
|
||||||
@@ -311,14 +294,13 @@ struct stk_stat
|
|||||||
include the fifteen word trailer area. */
|
include 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 trailer). */
|
this trailer). */
|
||||||
@@ -336,7 +318,7 @@ struct stk_trailer
|
|||||||
long unknown12;
|
long unknown12;
|
||||||
long unknown13;
|
long unknown13;
|
||||||
long unknown14;
|
long unknown14;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif /* CRAY2 */
|
#endif /* CRAY2 */
|
||||||
#endif /* not CRAY_STACK */
|
#endif /* not CRAY_STACK */
|
||||||
@@ -345,8 +327,7 @@ 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
|
static long i00afunc(long *address)
|
||||||
i00afunc (long *address)
|
|
||||||
{
|
{
|
||||||
struct stk_stat status;
|
struct stk_stat status;
|
||||||
struct stk_trailer *trailer;
|
struct stk_trailer *trailer;
|
||||||
@@ -358,29 +339,27 @@ i00afunc (long *address)
|
|||||||
more quickly and more directly, perhaps, by referencing the
|
more quickly and more directly, perhaps, by referencing the
|
||||||
$LM00 common block, but I know that this works. */
|
$LM00 common block, 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
|
+ status.current_size - 15);
|
||||||
- 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 error if "trailer" is null. */
|
a fatal error if "trailer" is null. */
|
||||||
|
|
||||||
if (trailer == 0)
|
if (trailer == 0)
|
||||||
abort ();
|
abort();
|
||||||
|
|
||||||
/* 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;
|
||||||
}
|
}
|
||||||
@@ -390,17 +369,15 @@ i00afunc (long *address)
|
|||||||
|
|
||||||
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);
|
||||||
|
|
||||||
@@ -419,8 +396,7 @@ 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
|
static long i00afunc(long address)
|
||||||
i00afunc (long address)
|
|
||||||
{
|
{
|
||||||
long stkl = 0;
|
long stkl = 0;
|
||||||
|
|
||||||
@@ -437,8 +413,8 @@ i00afunc (long address)
|
|||||||
B67 also points to the stack segment linkage control
|
B67 also points to the stack segment linkage control
|
||||||
area, which is what we are really interested in. */
|
area, which is 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 address of the first word of the segment.
|
one has the address of the first word of the segment.
|
||||||
@@ -455,15 +431,15 @@ i00afunc (long address)
|
|||||||
a stack overflow. Discard stack segments which do not
|
a stack overflow. Discard stack segments which do not
|
||||||
contain the target address. */
|
contain the target 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, stkl);
|
fprintf(stderr, "%011o %011o %011o\n", this_segment, address,
|
||||||
|
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;
|
||||||
@@ -476,13 +452,12 @@ i00afunc (long address)
|
|||||||
This seems a little convoluted to me, but I'll bet you save
|
This seems a little 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;
|
||||||
|
|||||||
251
src/asm/fstack.c
251
src/asm/fstack.c
@@ -45,16 +45,15 @@ 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;
|
||||||
|
|
||||||
if( (f=fopen(s,"rt"))!=NULL )
|
if ((f = fopen(s, "rt")) != NULL) {
|
||||||
{
|
fseek(f, 0, SEEK_END);
|
||||||
fseek (f, 0, SEEK_END);
|
size = ftell(f);
|
||||||
size = ftell (f);
|
fclose(f);
|
||||||
fclose (f);
|
|
||||||
}
|
}
|
||||||
return (size);
|
return (size);
|
||||||
}
|
}
|
||||||
@@ -66,7 +65,7 @@ ULONG filesize (char *s)
|
|||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
void pushcontext (void)
|
void pushcontext(void)
|
||||||
{
|
{
|
||||||
struct sContext **ppFileStack;
|
struct sContext **ppFileStack;
|
||||||
|
|
||||||
@@ -74,107 +73,102 @@ void pushcontext (void)
|
|||||||
while (*ppFileStack)
|
while (*ppFileStack)
|
||||||
ppFileStack = &((*ppFileStack)->pNext);
|
ppFileStack = &((*ppFileStack)->pNext);
|
||||||
|
|
||||||
if( (*ppFileStack=(struct sContext *)malloc(sizeof (struct sContext)))!=NULL )
|
if ((*ppFileStack =
|
||||||
{
|
(struct sContext *)malloc(sizeof(struct sContext))) != NULL) {
|
||||||
(*ppFileStack)->FlexHandle = CurrentFlexHandle;
|
(*ppFileStack)->FlexHandle = CurrentFlexHandle;
|
||||||
(*ppFileStack)->pNext = NULL;
|
(*ppFileStack)->pNext = NULL;
|
||||||
strcpy ( (char *)(*ppFileStack)->tzFileName, (char *)tzCurrentFileName);
|
strcpy((char *)(*ppFileStack)->tzFileName,
|
||||||
|
(char *)tzCurrentFileName);
|
||||||
(*ppFileStack)->nLine = nLineNo;
|
(*ppFileStack)->nLine = nLineNo;
|
||||||
switch ((*ppFileStack)->nStatus = nCurrentStatus)
|
switch ((*ppFileStack)->nStatus = nCurrentStatus) {
|
||||||
{
|
|
||||||
case STAT_isMacroArg:
|
case STAT_isMacroArg:
|
||||||
case STAT_isMacro:
|
case STAT_isMacro:
|
||||||
sym_SaveCurrentMacroArgs ((*ppFileStack)->tzMacroArgs);
|
sym_SaveCurrentMacroArgs((*ppFileStack)->tzMacroArgs);
|
||||||
(*ppFileStack)->pMacro = pCurrentMacro;
|
(*ppFileStack)->pMacro = pCurrentMacro;
|
||||||
break;
|
break;
|
||||||
case STAT_isInclude:
|
case STAT_isInclude:
|
||||||
(*ppFileStack)->pFile = pCurrentFile;
|
(*ppFileStack)->pFile = pCurrentFile;
|
||||||
break;
|
break;
|
||||||
case STAT_isREPTBlock:
|
case STAT_isREPTBlock:
|
||||||
sym_SaveCurrentMacroArgs ((*ppFileStack)->tzMacroArgs);
|
sym_SaveCurrentMacroArgs((*ppFileStack)->tzMacroArgs);
|
||||||
(*ppFileStack)->pREPTBlock = pCurrentREPTBlock;
|
(*ppFileStack)->pREPTBlock = pCurrentREPTBlock;
|
||||||
(*ppFileStack)->nREPTBlockSize = nCurrentREPTBlockSize;
|
(*ppFileStack)->nREPTBlockSize = nCurrentREPTBlockSize;
|
||||||
(*ppFileStack)->nREPTBlockCount = nCurrentREPTBlockCount;
|
(*ppFileStack)->nREPTBlockCount =
|
||||||
|
nCurrentREPTBlockCount;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
nLineNo = 0;
|
nLineNo = 0;
|
||||||
}
|
} else
|
||||||
else
|
fatalerror("No memory for context");
|
||||||
fatalerror ("No memory for context");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int popcontext (void)
|
int popcontext(void)
|
||||||
{
|
{
|
||||||
struct sContext *pLastFile,
|
struct sContext *pLastFile, **ppLastFile;
|
||||||
**ppLastFile;
|
|
||||||
|
|
||||||
if (nCurrentStatus == STAT_isREPTBlock)
|
if (nCurrentStatus == STAT_isREPTBlock) {
|
||||||
{
|
if (--nCurrentREPTBlockCount) {
|
||||||
if (--nCurrentREPTBlockCount)
|
yy_delete_buffer(CurrentFlexHandle);
|
||||||
{
|
CurrentFlexHandle =
|
||||||
yy_delete_buffer (CurrentFlexHandle);
|
yy_scan_bytes(pCurrentREPTBlock,
|
||||||
CurrentFlexHandle = 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++);
|
||||||
sym_UseNewMacroArgs ();
|
sym_UseNewMacroArgs();
|
||||||
return (0);
|
return (0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if( (pLastFile=pFileStack)!=NULL )
|
if ((pLastFile = pFileStack) != NULL) {
|
||||||
{
|
|
||||||
ppLastFile = &pFileStack;
|
ppLastFile = &pFileStack;
|
||||||
while (pLastFile->pNext)
|
while (pLastFile->pNext) {
|
||||||
{
|
|
||||||
ppLastFile = &(pLastFile->pNext);
|
ppLastFile = &(pLastFile->pNext);
|
||||||
pLastFile = *ppLastFile;
|
pLastFile = *ppLastFile;
|
||||||
}
|
}
|
||||||
|
|
||||||
yy_delete_buffer (CurrentFlexHandle);
|
yy_delete_buffer(CurrentFlexHandle);
|
||||||
nLineNo = pLastFile->nLine;
|
nLineNo = pLastFile->nLine;
|
||||||
if (nCurrentStatus == STAT_isInclude)
|
if (nCurrentStatus == STAT_isInclude)
|
||||||
fclose (pCurrentFile);
|
fclose(pCurrentFile);
|
||||||
if (nCurrentStatus == STAT_isMacro)
|
if (nCurrentStatus == STAT_isMacro) {
|
||||||
{
|
sym_FreeCurrentMacroArgs();
|
||||||
sym_FreeCurrentMacroArgs ();
|
|
||||||
nLineNo += 1;
|
nLineNo += 1;
|
||||||
}
|
}
|
||||||
if (nCurrentStatus == STAT_isREPTBlock)
|
if (nCurrentStatus == STAT_isREPTBlock)
|
||||||
nLineNo += 1;
|
nLineNo += 1;
|
||||||
|
|
||||||
CurrentFlexHandle = pLastFile->FlexHandle;
|
CurrentFlexHandle = pLastFile->FlexHandle;
|
||||||
strcpy ((char *)tzCurrentFileName, (char *)pLastFile->tzFileName);
|
strcpy((char *)tzCurrentFileName,
|
||||||
switch (nCurrentStatus = pLastFile->nStatus)
|
(char *)pLastFile->tzFileName);
|
||||||
{
|
switch (nCurrentStatus = pLastFile->nStatus) {
|
||||||
case STAT_isMacroArg:
|
case STAT_isMacroArg:
|
||||||
case STAT_isMacro:
|
case STAT_isMacro:
|
||||||
sym_RestoreCurrentMacroArgs (pLastFile->tzMacroArgs);
|
sym_RestoreCurrentMacroArgs(pLastFile->tzMacroArgs);
|
||||||
pCurrentMacro = pLastFile->pMacro;
|
pCurrentMacro = pLastFile->pMacro;
|
||||||
break;
|
break;
|
||||||
case STAT_isInclude:
|
case STAT_isInclude:
|
||||||
pCurrentFile = pLastFile->pFile;
|
pCurrentFile = pLastFile->pFile;
|
||||||
break;
|
break;
|
||||||
case STAT_isREPTBlock:
|
case STAT_isREPTBlock:
|
||||||
sym_RestoreCurrentMacroArgs (pLastFile->tzMacroArgs);
|
sym_RestoreCurrentMacroArgs(pLastFile->tzMacroArgs);
|
||||||
pCurrentREPTBlock = pLastFile->pREPTBlock;
|
pCurrentREPTBlock = pLastFile->pREPTBlock;
|
||||||
nCurrentREPTBlockSize = pLastFile->nREPTBlockSize;
|
nCurrentREPTBlockSize = pLastFile->nREPTBlockSize;
|
||||||
nCurrentREPTBlockCount = pLastFile->nREPTBlockCount;
|
nCurrentREPTBlockCount = pLastFile->nREPTBlockCount;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
free (*ppLastFile);
|
free(*ppLastFile);
|
||||||
*ppLastFile = NULL;
|
*ppLastFile = NULL;
|
||||||
yy_switch_to_buffer (CurrentFlexHandle);
|
yy_switch_to_buffer(CurrentFlexHandle);
|
||||||
return (0);
|
return (0);
|
||||||
}
|
} else
|
||||||
else
|
|
||||||
return (1);
|
return (1);
|
||||||
}
|
}
|
||||||
|
|
||||||
int yywrap (void)
|
int yywrap(void)
|
||||||
{
|
{
|
||||||
return (popcontext ());
|
return (popcontext());
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@@ -184,19 +178,18 @@ int yywrap (void)
|
|||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
void fstk_Dump (void)
|
void fstk_Dump(void)
|
||||||
{
|
{
|
||||||
struct sContext *pLastFile;
|
struct sContext *pLastFile;
|
||||||
|
|
||||||
pLastFile = pFileStack;
|
pLastFile = pFileStack;
|
||||||
|
|
||||||
while (pLastFile)
|
while (pLastFile) {
|
||||||
{
|
printf("%s(%ld) -> ", pLastFile->tzFileName, pLastFile->nLine);
|
||||||
printf ("%s(%ld) -> ", pLastFile->tzFileName, pLastFile->nLine);
|
|
||||||
pLastFile = pLastFile->pNext;
|
pLastFile = pLastFile->pNext;
|
||||||
}
|
}
|
||||||
|
|
||||||
printf ("%s(%ld)", tzCurrentFileName, nLineNo);
|
printf("%s(%ld)", tzCurrentFileName, nLineNo);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@@ -206,33 +199,30 @@ 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;
|
||||||
|
|
||||||
strcpy (t, s);
|
strcpy(t, s);
|
||||||
|
|
||||||
while (i < NextIncPath)
|
while (i < NextIncPath) {
|
||||||
{
|
|
||||||
FILE *f;
|
FILE *f;
|
||||||
|
|
||||||
if( (f=fopen(t,"rb"))!=NULL )
|
if ((f = fopen(t, "rb")) != NULL) {
|
||||||
{
|
fclose(f);
|
||||||
fclose (f);
|
strcpy(s, t);
|
||||||
strcpy (s, t);
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
i += 1;
|
i += 1;
|
||||||
if (i < NextIncPath)
|
if (i < NextIncPath) {
|
||||||
{
|
strcpy(t, IncludePaths[i]);
|
||||||
strcpy (t, IncludePaths[i]);
|
strcat(t, s);
|
||||||
strcat (t, s);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -244,35 +234,33 @@ 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 ();
|
|
||||||
nLineNo = 1;
|
nLineNo = 1;
|
||||||
nCurrentStatus = STAT_isInclude;
|
nCurrentStatus = STAT_isInclude;
|
||||||
strcpy (tzCurrentFileName, tzFileName);
|
strcpy(tzCurrentFileName, tzFileName);
|
||||||
pCurrentFile = f;
|
pCurrentFile = f;
|
||||||
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);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -283,24 +271,24 @@ ULONG fstk_RunInclude (char *s)
|
|||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
ULONG fstk_RunMacro (char *s)
|
ULONG fstk_RunMacro(char *s)
|
||||||
{
|
{
|
||||||
struct sSymbol *sym;
|
struct sSymbol *sym;
|
||||||
|
|
||||||
if( (sym=sym_FindMacro(s))!=NULL )
|
if ((sym = sym_FindMacro(s)) != NULL) {
|
||||||
{
|
pushcontext();
|
||||||
pushcontext ();
|
sym_SetMacroArgID(nMacroCount++);
|
||||||
sym_SetMacroArgID (nMacroCount++);
|
|
||||||
nLineNo = -1;
|
nLineNo = -1;
|
||||||
sym_UseNewMacroArgs ();
|
sym_UseNewMacroArgs();
|
||||||
nCurrentStatus = STAT_isMacro;
|
nCurrentStatus = STAT_isMacro;
|
||||||
strcpy (tzCurrentFileName, s);
|
strcpy(tzCurrentFileName, s);
|
||||||
pCurrentMacro = sym;
|
pCurrentMacro = sym;
|
||||||
CurrentFlexHandle = yy_scan_bytes (pCurrentMacro->pMacro, pCurrentMacro->ulMacroSize);
|
CurrentFlexHandle =
|
||||||
yy_switch_to_buffer (CurrentFlexHandle);
|
yy_scan_bytes(pCurrentMacro->pMacro,
|
||||||
|
pCurrentMacro->ulMacroSize);
|
||||||
|
yy_switch_to_buffer(CurrentFlexHandle);
|
||||||
return (1);
|
return (1);
|
||||||
}
|
} else
|
||||||
else
|
|
||||||
return (0);
|
return (0);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -311,7 +299,7 @@ ULONG fstk_RunMacro (char *s)
|
|||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
void fstk_RunMacroArg (SLONG s)
|
void fstk_RunMacroArg(SLONG s)
|
||||||
{
|
{
|
||||||
char *sym;
|
char *sym;
|
||||||
|
|
||||||
@@ -320,16 +308,14 @@ void fstk_RunMacroArg (SLONG s)
|
|||||||
else
|
else
|
||||||
s -= '0';
|
s -= '0';
|
||||||
|
|
||||||
if( (sym=sym_FindMacroArg(s))!=NULL )
|
if ((sym = sym_FindMacroArg(s)) != NULL) {
|
||||||
{
|
pushcontext();
|
||||||
pushcontext ();
|
|
||||||
nCurrentStatus = STAT_isMacroArg;
|
nCurrentStatus = STAT_isMacroArg;
|
||||||
sprintf (tzCurrentFileName, "%c", (UBYTE)s);
|
sprintf(tzCurrentFileName, "%c", (UBYTE) s);
|
||||||
CurrentFlexHandle = yy_scan_bytes (sym, strlen (sym));
|
CurrentFlexHandle = yy_scan_bytes(sym, strlen(sym));
|
||||||
yy_switch_to_buffer (CurrentFlexHandle);
|
yy_switch_to_buffer(CurrentFlexHandle);
|
||||||
}
|
} else
|
||||||
else
|
fatalerror("No such macroargument");
|
||||||
fatalerror ("No such macroargument");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@@ -339,20 +325,19 @@ void fstk_RunMacroArg (SLONG s)
|
|||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
void fstk_RunString (char *s)
|
void fstk_RunString(char *s)
|
||||||
{
|
{
|
||||||
struct sSymbol *pSym;
|
struct sSymbol *pSym;
|
||||||
|
|
||||||
if( (pSym=sym_FindSymbol(s))!=NULL )
|
if ((pSym = sym_FindSymbol(s)) != NULL) {
|
||||||
{
|
pushcontext();
|
||||||
pushcontext ();
|
|
||||||
nCurrentStatus = STAT_isMacroArg;
|
nCurrentStatus = STAT_isMacroArg;
|
||||||
strcpy (tzCurrentFileName, s);
|
strcpy(tzCurrentFileName, s);
|
||||||
CurrentFlexHandle = yy_scan_bytes (pSym->pMacro, strlen (pSym->pMacro));
|
CurrentFlexHandle =
|
||||||
yy_switch_to_buffer (CurrentFlexHandle);
|
yy_scan_bytes(pSym->pMacro, strlen(pSym->pMacro));
|
||||||
}
|
yy_switch_to_buffer(CurrentFlexHandle);
|
||||||
else
|
} else
|
||||||
yyerror ("No such string symbol");
|
yyerror("No such string symbol");
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@@ -362,20 +347,20 @@ void fstk_RunString (char *s)
|
|||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
void fstk_RunRept (ULONG count)
|
void fstk_RunRept(ULONG count)
|
||||||
{
|
{
|
||||||
if (count)
|
if (count) {
|
||||||
{
|
pushcontext();
|
||||||
pushcontext ();
|
sym_UseCurrentMacroArgs();
|
||||||
sym_UseCurrentMacroArgs ();
|
sym_SetMacroArgID(nMacroCount++);
|
||||||
sym_SetMacroArgID (nMacroCount++);
|
sym_UseNewMacroArgs();
|
||||||
sym_UseNewMacroArgs ();
|
|
||||||
nCurrentREPTBlockCount = count;
|
nCurrentREPTBlockCount = count;
|
||||||
nCurrentStatus = STAT_isREPTBlock;
|
nCurrentStatus = STAT_isREPTBlock;
|
||||||
nCurrentREPTBlockSize = ulNewMacroSize;
|
nCurrentREPTBlockSize = ulNewMacroSize;
|
||||||
pCurrentREPTBlock = tzNewMacro;
|
pCurrentREPTBlock = tzNewMacro;
|
||||||
CurrentFlexHandle = yy_scan_bytes (pCurrentREPTBlock, nCurrentREPTBlockSize);
|
CurrentFlexHandle =
|
||||||
yy_switch_to_buffer (CurrentFlexHandle);
|
yy_scan_bytes(pCurrentREPTBlock, nCurrentREPTBlockSize);
|
||||||
|
yy_switch_to_buffer(CurrentFlexHandle);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -386,26 +371,24 @@ 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];
|
||||||
|
|
||||||
sym_AddString ("__FILE__", s);
|
sym_AddString("__FILE__", s);
|
||||||
|
|
||||||
strcpy (tzFileName, s);
|
strcpy(tzFileName, s);
|
||||||
fstk_FindFile (tzFileName);
|
fstk_FindFile(tzFileName);
|
||||||
|
|
||||||
pFileStack = NULL;
|
pFileStack = NULL;
|
||||||
if( (pCurrentFile=fopen(tzFileName,"rt"))!=NULL )
|
if ((pCurrentFile = fopen(tzFileName, "rt")) != NULL) {
|
||||||
{
|
|
||||||
nMacroCount = 0;
|
nMacroCount = 0;
|
||||||
nCurrentStatus = STAT_isInclude;
|
nCurrentStatus = STAT_isInclude;
|
||||||
strcpy (tzCurrentFileName, tzFileName);
|
strcpy(tzCurrentFileName, tzFileName);
|
||||||
CurrentFlexHandle = yy_create_buffer (pCurrentFile);
|
CurrentFlexHandle = yy_create_buffer(pCurrentFile);
|
||||||
yy_switch_to_buffer (CurrentFlexHandle);
|
yy_switch_to_buffer(CurrentFlexHandle);
|
||||||
nLineNo = 1;
|
nLineNo = 1;
|
||||||
return (1);
|
return (1);
|
||||||
}
|
} else
|
||||||
else
|
|
||||||
return (0);
|
return (0);
|
||||||
}
|
}
|
||||||
@@ -95,9 +95,8 @@
|
|||||||
|
|
||||||
/* "r" defs */
|
/* "r" defs */
|
||||||
|
|
||||||
enum
|
enum {
|
||||||
{
|
REG_B = 0,
|
||||||
REG_B=0,
|
|
||||||
REG_C,
|
REG_C,
|
||||||
REG_D,
|
REG_D,
|
||||||
REG_E,
|
REG_E,
|
||||||
@@ -109,9 +108,8 @@ enum
|
|||||||
|
|
||||||
/* "rr" defs */
|
/* "rr" defs */
|
||||||
|
|
||||||
enum
|
enum {
|
||||||
{
|
REG_BC_IND = 0,
|
||||||
REG_BC_IND=0,
|
|
||||||
REG_DE_IND,
|
REG_DE_IND,
|
||||||
REG_HL_INDINC,
|
REG_HL_INDINC,
|
||||||
REG_HL_INDDEC,
|
REG_HL_INDDEC,
|
||||||
@@ -119,9 +117,8 @@ enum
|
|||||||
|
|
||||||
/* "ss" defs */
|
/* "ss" defs */
|
||||||
|
|
||||||
enum
|
enum {
|
||||||
{
|
REG_BC = 0,
|
||||||
REG_BC=0,
|
|
||||||
REG_DE,
|
REG_DE,
|
||||||
REG_HL,
|
REG_HL,
|
||||||
REG_SP
|
REG_SP
|
||||||
@@ -138,17 +135,9 @@ enum
|
|||||||
|
|
||||||
/* "cc" defs */
|
/* "cc" defs */
|
||||||
|
|
||||||
enum
|
enum {
|
||||||
{
|
CC_NZ = 0,
|
||||||
CC_NZ=0,
|
|
||||||
CC_Z,
|
CC_Z,
|
||||||
CC_NC,
|
CC_NC,
|
||||||
CC_C
|
CC_C
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -3,8 +3,7 @@
|
|||||||
#include "rpn.h"
|
#include "rpn.h"
|
||||||
#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,
|
||||||
|
|||||||
@@ -10,34 +10,30 @@
|
|||||||
#include <math.h>
|
#include <math.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
UBYTE oDontExpandStrings=0;
|
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;
|
||||||
|
|
||||||
for( i=0; i<=3; i+=1 )
|
for (i = 0; i <= 3; i += 1) {
|
||||||
{
|
if (CurrentOptions.gbgfx[i] == ch) {
|
||||||
if( CurrentOptions.gbgfx[i]==ch )
|
return (i);
|
||||||
{
|
|
||||||
return( i );
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return (0);
|
return (0);
|
||||||
}
|
}
|
||||||
|
|
||||||
SLONG binary2bin (char ch)
|
SLONG binary2bin(char ch)
|
||||||
{
|
{
|
||||||
SLONG i;
|
SLONG i;
|
||||||
|
|
||||||
for( i=0; i<=1; i+=1 )
|
for (i = 0; i <= 1; i += 1) {
|
||||||
{
|
if (CurrentOptions.binary[i] == ch) {
|
||||||
if( CurrentOptions.binary[i]==ch )
|
return (i);
|
||||||
{
|
|
||||||
return( i );
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -45,7 +41,7 @@ SLONG binary2bin (char ch)
|
|||||||
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,70 +55,62 @@ SLONG char2bin (char ch)
|
|||||||
return (0);
|
return (0);
|
||||||
}
|
}
|
||||||
|
|
||||||
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;
|
||||||
x2bin convertfunc=char2bin;
|
x2bin convertfunc = char2bin;
|
||||||
|
|
||||||
switch (*s)
|
switch (*s) {
|
||||||
{
|
|
||||||
case '$':
|
case '$':
|
||||||
radix = 16;
|
radix = 16;
|
||||||
s += 1;
|
s += 1;
|
||||||
convertfunc=char2bin;
|
convertfunc = char2bin;
|
||||||
break;
|
break;
|
||||||
case '&':
|
case '&':
|
||||||
radix = 8;
|
radix = 8;
|
||||||
s += 1;
|
s += 1;
|
||||||
convertfunc=char2bin;
|
convertfunc = char2bin;
|
||||||
break;
|
break;
|
||||||
case '`':
|
case '`':
|
||||||
radix = 4;
|
radix = 4;
|
||||||
s += 1;
|
s += 1;
|
||||||
convertfunc=gbgfx2bin;
|
convertfunc = gbgfx2bin;
|
||||||
break;
|
break;
|
||||||
case '%':
|
case '%':
|
||||||
radix = 2;
|
radix = 2;
|
||||||
s += 1;
|
s += 1;
|
||||||
convertfunc=binary2bin;
|
convertfunc = binary2bin;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (radix == 4)
|
if (radix == 4) {
|
||||||
{
|
|
||||||
SLONG c;
|
SLONG c;
|
||||||
|
|
||||||
while (*s != '\0')
|
while (*s != '\0') {
|
||||||
{
|
c = convertfunc(*s++);
|
||||||
c = convertfunc (*s++);
|
|
||||||
result = result * 2 + ((c & 1) << 8) + ((c & 2) >> 1);
|
result = result * 2 + ((c & 1) << 8) + ((c & 2) >> 1);
|
||||||
}
|
}
|
||||||
}
|
} else {
|
||||||
else
|
|
||||||
{
|
|
||||||
while (*s != '\0')
|
while (*s != '\0')
|
||||||
result = result * radix + convertfunc (*s++);
|
result = result * radix + convertfunc(*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,
|
ULONG i = 0, dot = 0;
|
||||||
dot = 0;
|
|
||||||
|
|
||||||
while (size && dot != 2)
|
while (size && dot != 2) {
|
||||||
{
|
|
||||||
if (s[i] == '.')
|
if (s[i] == '.')
|
||||||
dot += 1;
|
dot += 1;
|
||||||
|
|
||||||
if (dot < 2)
|
if (dot < 2) {
|
||||||
{
|
|
||||||
dest[i] = s[i];
|
dest[i] = s[i];
|
||||||
size -= 1;
|
size -= 1;
|
||||||
i += 1;
|
i += 1;
|
||||||
@@ -131,128 +119,110 @@ ULONG ParseFixedPoint (char *s, ULONG size)
|
|||||||
|
|
||||||
dest[i] = 0;
|
dest[i] = 0;
|
||||||
|
|
||||||
yyunputbytes (size);
|
yyunputbytes(size);
|
||||||
|
|
||||||
yylval.nConstValue = (SLONG) (atof (s) * 65536);
|
yylval.nConstValue = (SLONG) (atof(s) * 65536);
|
||||||
|
|
||||||
return (1);
|
return (1);
|
||||||
}
|
}
|
||||||
|
|
||||||
ULONG ParseNumber (char *s, ULONG size)
|
ULONG ParseNumber(char *s, ULONG size)
|
||||||
{
|
{
|
||||||
char dest[256];
|
char dest[256];
|
||||||
|
|
||||||
strncpy (dest, s, size);
|
strncpy(dest, s, size);
|
||||||
dest[size] = 0;
|
dest[size] = 0;
|
||||||
yylval.nConstValue = ascii2bin (dest);
|
yylval.nConstValue = ascii2bin(dest);
|
||||||
|
|
||||||
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,
|
int copied = 0, size_backup = size;
|
||||||
size_backup = size;
|
|
||||||
|
|
||||||
while (size && copied < MAXSYMLEN)
|
while (size && copied < MAXSYMLEN) {
|
||||||
{
|
if (*src == '\\') {
|
||||||
if (*src == '\\')
|
|
||||||
{
|
|
||||||
char *marg;
|
char *marg;
|
||||||
|
|
||||||
src += 1;
|
src += 1;
|
||||||
size -= 1;
|
size -= 1;
|
||||||
|
|
||||||
if (*src == '@')
|
if (*src == '@')
|
||||||
marg = sym_FindMacroArg (-1);
|
marg = sym_FindMacroArg(-1);
|
||||||
else if (*src >= '0' && *src <= '9')
|
else if (*src >= '0' && *src <= '9')
|
||||||
marg = sym_FindMacroArg (*src);
|
marg = sym_FindMacroArg(*src);
|
||||||
else
|
else {
|
||||||
{
|
fatalerror("Malformed ID");
|
||||||
fatalerror ("Malformed ID");
|
return (0);
|
||||||
return(0);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
src += 1;
|
src += 1;
|
||||||
size -= 1;
|
size -= 1;
|
||||||
|
|
||||||
if (marg)
|
if (marg) {
|
||||||
{
|
|
||||||
while (*marg)
|
while (*marg)
|
||||||
dest[copied++] = *marg++;
|
dest[copied++] = *marg++;
|
||||||
}
|
}
|
||||||
}
|
} else {
|
||||||
else
|
|
||||||
{
|
|
||||||
dest[copied++] = *src++;
|
dest[copied++] = *src++;
|
||||||
size -= 1;
|
size -= 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (copied > MAXSYMLEN)
|
if (copied > MAXSYMLEN)
|
||||||
fatalerror ("Symbol too long");
|
fatalerror("Symbol too long");
|
||||||
|
|
||||||
dest[copied] = 0;
|
dest[copied] = 0;
|
||||||
|
|
||||||
if( oDontExpandStrings==0
|
if (oDontExpandStrings == 0 && sym_isString(dest)) {
|
||||||
&& sym_isString(dest) )
|
|
||||||
{
|
|
||||||
char *s;
|
char *s;
|
||||||
|
|
||||||
yyskipbytes( size_backup );
|
yyskipbytes(size_backup);
|
||||||
yyunputstr( s=sym_GetStringValue(dest) );
|
yyunputstr(s = sym_GetStringValue(dest));
|
||||||
|
|
||||||
while( *s )
|
while (*s) {
|
||||||
{
|
if (*s++ == '\n') {
|
||||||
if( *s++=='\n' )
|
nLineNo -= 1;
|
||||||
{
|
|
||||||
nLineNo-=1;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return (0);
|
return (0);
|
||||||
}
|
} else {
|
||||||
else
|
strcpy(yylval.tzString, dest);
|
||||||
{
|
|
||||||
strcpy( yylval.tzString, dest );
|
|
||||||
return (1);
|
return (1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
ULONG PutMacroArg (char *src, ULONG size)
|
ULONG PutMacroArg(char *src, ULONG size)
|
||||||
{
|
{
|
||||||
char *s;
|
char *s;
|
||||||
|
|
||||||
yyskipbytes (size);
|
yyskipbytes(size);
|
||||||
if( (s=sym_FindMacroArg (src[1] - '0'))!=NULL )
|
if ((s = sym_FindMacroArg(src[1] - '0')) != NULL) {
|
||||||
{
|
|
||||||
yyunputstr(s);
|
yyunputstr(s);
|
||||||
}
|
} else {
|
||||||
else
|
yyerror("Macro argument not defined");
|
||||||
{
|
|
||||||
yyerror( "Macro argument not defined" );
|
|
||||||
}
|
}
|
||||||
return (0);
|
return (0);
|
||||||
}
|
}
|
||||||
|
|
||||||
ULONG PutUniqueArg (char *src, ULONG size)
|
ULONG PutUniqueArg(char *src, ULONG size)
|
||||||
{
|
{
|
||||||
src=src;
|
src = src;
|
||||||
yyskipbytes (size);
|
yyskipbytes(size);
|
||||||
yyunputstr (sym_FindMacroArg (-1));
|
yyunputstr(sym_FindMacroArg(-1));
|
||||||
return (0);
|
return (0);
|
||||||
}
|
}
|
||||||
|
|
||||||
enum
|
enum {
|
||||||
{
|
|
||||||
T_LEX_MACROARG = 3000,
|
T_LEX_MACROARG = 3000,
|
||||||
T_LEX_MACROUNIQUE
|
T_LEX_MACROUNIQUE
|
||||||
};
|
};
|
||||||
|
|
||||||
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,
|
||||||
@@ -365,149 +335,152 @@ struct sLexInitString staticstrings[] =
|
|||||||
NULL, 0
|
NULL, 0
|
||||||
};
|
};
|
||||||
|
|
||||||
struct sLexFloat tNumberToken =
|
struct sLexFloat tNumberToken = {
|
||||||
{
|
|
||||||
ParseNumber,
|
ParseNumber,
|
||||||
T_NUMBER
|
T_NUMBER
|
||||||
};
|
};
|
||||||
|
|
||||||
struct sLexFloat tFixedPointToken =
|
struct sLexFloat tFixedPointToken = {
|
||||||
{
|
|
||||||
ParseFixedPoint,
|
ParseFixedPoint,
|
||||||
T_NUMBER
|
T_NUMBER
|
||||||
};
|
};
|
||||||
|
|
||||||
struct sLexFloat tIDToken =
|
struct sLexFloat tIDToken = {
|
||||||
{
|
|
||||||
ParseSymbol,
|
ParseSymbol,
|
||||||
T_ID
|
T_ID
|
||||||
};
|
};
|
||||||
|
|
||||||
struct sLexFloat tMacroArgToken =
|
struct sLexFloat tMacroArgToken = {
|
||||||
{
|
|
||||||
PutMacroArg,
|
PutMacroArg,
|
||||||
T_LEX_MACROARG
|
T_LEX_MACROARG
|
||||||
};
|
};
|
||||||
|
|
||||||
struct sLexFloat tMacroUniqueToken =
|
struct sLexFloat tMacroUniqueToken = {
|
||||||
{
|
|
||||||
PutUniqueArg,
|
PutUniqueArg,
|
||||||
T_LEX_MACROUNIQUE
|
T_LEX_MACROUNIQUE
|
||||||
};
|
};
|
||||||
|
|
||||||
void setuplex (void)
|
void setuplex(void)
|
||||||
{
|
{
|
||||||
ULONG id;
|
ULONG id;
|
||||||
|
|
||||||
lex_Init ();
|
lex_Init();
|
||||||
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], CurrentOptions.binary[0]);
|
lex_FloatAddSecondRange(id, CurrentOptions.binary[0],
|
||||||
lex_FloatAddSecondRange (id, CurrentOptions.binary[1], CurrentOptions.binary[1]);
|
CurrentOptions.binary[0]);
|
||||||
lex_FloatAddRange (id, CurrentOptions.binary[0], CurrentOptions.binary[0]);
|
lex_FloatAddSecondRange(id, CurrentOptions.binary[1],
|
||||||
lex_FloatAddRange (id, CurrentOptions.binary[1], CurrentOptions.binary[1]);
|
CurrentOptions.binary[1]);
|
||||||
|
lex_FloatAddRange(id, CurrentOptions.binary[0],
|
||||||
|
CurrentOptions.binary[0]);
|
||||||
|
lex_FloatAddRange(id, 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], CurrentOptions.gbgfx[0]);
|
lex_FloatAddSecondRange(id, CurrentOptions.gbgfx[0],
|
||||||
lex_FloatAddSecondRange (id, CurrentOptions.gbgfx[1], CurrentOptions.gbgfx[1]);
|
CurrentOptions.gbgfx[0]);
|
||||||
lex_FloatAddSecondRange (id, CurrentOptions.gbgfx[2], CurrentOptions.gbgfx[2]);
|
lex_FloatAddSecondRange(id, CurrentOptions.gbgfx[1],
|
||||||
lex_FloatAddSecondRange (id, CurrentOptions.gbgfx[3], CurrentOptions.gbgfx[3]);
|
CurrentOptions.gbgfx[1]);
|
||||||
lex_FloatAddRange (id, CurrentOptions.gbgfx[0], CurrentOptions.gbgfx[0]);
|
lex_FloatAddSecondRange(id, CurrentOptions.gbgfx[2],
|
||||||
lex_FloatAddRange (id, CurrentOptions.gbgfx[1], CurrentOptions.gbgfx[1]);
|
CurrentOptions.gbgfx[2]);
|
||||||
lex_FloatAddRange (id, CurrentOptions.gbgfx[2], CurrentOptions.gbgfx[2]);
|
lex_FloatAddSecondRange(id, CurrentOptions.gbgfx[3],
|
||||||
lex_FloatAddRange (id, CurrentOptions.gbgfx[3], CurrentOptions.gbgfx[3]);
|
CurrentOptions.gbgfx[3]);
|
||||||
|
lex_FloatAddRange(id, CurrentOptions.gbgfx[0], CurrentOptions.gbgfx[0]);
|
||||||
|
lex_FloatAddRange(id, CurrentOptions.gbgfx[1], CurrentOptions.gbgfx[1]);
|
||||||
|
lex_FloatAddRange(id, CurrentOptions.gbgfx[2], CurrentOptions.gbgfx[2]);
|
||||||
|
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');
|
||||||
lex_FloatAddSecondRange (id, 'a', 'f');
|
lex_FloatAddSecondRange(id, 'a', 'f');
|
||||||
lex_FloatAddRange (id, '0', '9');
|
lex_FloatAddRange(id, '0', '9');
|
||||||
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, '_', '_');
|
||||||
lex_FloatAddSecondRange (id, 'a', 'z');
|
lex_FloatAddSecondRange(id, 'a', 'z');
|
||||||
lex_FloatAddSecondRange (id, 'A', 'Z');
|
lex_FloatAddSecondRange(id, 'A', 'Z');
|
||||||
lex_FloatAddSecondRange (id, '0', '9');
|
lex_FloatAddSecondRange(id, '0', '9');
|
||||||
lex_FloatAddSecondRange (id, '_', '_');
|
lex_FloatAddSecondRange(id, '_', '_');
|
||||||
lex_FloatAddSecondRange (id, '\\', '\\');
|
lex_FloatAddSecondRange(id, '\\', '\\');
|
||||||
lex_FloatAddSecondRange (id, '@', '@');
|
lex_FloatAddSecondRange(id, '@', '@');
|
||||||
lex_FloatAddSecondRange (id, '#', '#');
|
lex_FloatAddSecondRange(id, '#', '#');
|
||||||
lex_FloatAddRange (id, 'a', 'z');
|
lex_FloatAddRange(id, 'a', 'z');
|
||||||
lex_FloatAddRange (id, 'A', 'Z');
|
lex_FloatAddRange(id, 'A', 'Z');
|
||||||
lex_FloatAddRange (id, '0', '9');
|
lex_FloatAddRange(id, '0', '9');
|
||||||
lex_FloatAddRange (id, '_', '_');
|
lex_FloatAddRange(id, '_', '_');
|
||||||
lex_FloatAddRange (id, '\\', '\\');
|
lex_FloatAddRange(id, '\\', '\\');
|
||||||
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');
|
||||||
lex_FloatAddSecondRange (id, '_', '_');
|
lex_FloatAddSecondRange(id, '_', '_');
|
||||||
lex_FloatAddRange (id, 'a', 'z');
|
lex_FloatAddRange(id, 'a', 'z');
|
||||||
lex_FloatAddRange (id, 'A', 'Z');
|
lex_FloatAddRange(id, 'A', 'Z');
|
||||||
lex_FloatAddRange (id, '0', '9');
|
lex_FloatAddRange(id, '0', '9');
|
||||||
lex_FloatAddRange (id, '_', '_');
|
lex_FloatAddRange(id, '_', '_');
|
||||||
lex_FloatAddRange (id, '\\', '\\');
|
lex_FloatAddRange(id, '\\', '\\');
|
||||||
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, '.', '.');
|
||||||
lex_FloatAddSecondRange (id, '0', '9');
|
lex_FloatAddSecondRange(id, '0', '9');
|
||||||
lex_FloatAddRange (id, '.', '.');
|
lex_FloatAddRange(id, '.', '.');
|
||||||
lex_FloatAddRange (id, '0', '9');
|
lex_FloatAddRange(id, '0', '9');
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -21,7 +21,7 @@ extern ULONG nTotalLines;
|
|||||||
extern ULONG nPC;
|
extern ULONG nPC;
|
||||||
extern ULONG nPass;
|
extern ULONG nPass;
|
||||||
extern ULONG nIFDepth;
|
extern ULONG nIFDepth;
|
||||||
extern char tzCurrentFileName[_MAX_PATH+1];
|
extern char tzCurrentFileName[_MAX_PATH + 1];
|
||||||
extern struct Section *pCurrentSection;
|
extern struct Section *pCurrentSection;
|
||||||
extern struct sSymbol *tHashedSymbols[HASHSIZE];
|
extern struct sSymbol *tHashedSymbols[HASHSIZE];
|
||||||
extern struct sSymbol *pPCSymbol;
|
extern struct sSymbol *pPCSymbol;
|
||||||
|
|||||||
@@ -13,13 +13,12 @@
|
|||||||
#include "types.h"
|
#include "types.h"
|
||||||
#include "lexer.h"
|
#include "lexer.h"
|
||||||
|
|
||||||
struct sContext
|
struct sContext {
|
||||||
{
|
|
||||||
YY_BUFFER_STATE FlexHandle;
|
YY_BUFFER_STATE FlexHandle;
|
||||||
struct sSymbol *pMacro;
|
struct sSymbol *pMacro;
|
||||||
struct sContext *pNext;
|
struct sContext *pNext;
|
||||||
char tzFileName[_MAX_PATH+1];
|
char tzFileName[_MAX_PATH + 1];
|
||||||
char *tzMacroArgs[MAXMACROARGS+1];
|
char *tzMacroArgs[MAXMACROARGS + 1];
|
||||||
SLONG nLine;
|
SLONG nLine;
|
||||||
ULONG nStatus;
|
ULONG nStatus;
|
||||||
FILE *pFile;
|
FILE *pFile;
|
||||||
@@ -28,15 +27,15 @@ struct sContext
|
|||||||
ULONG nREPTBlockSize;
|
ULONG nREPTBlockSize;
|
||||||
};
|
};
|
||||||
|
|
||||||
extern ULONG fstk_RunInclude( char *s );
|
extern ULONG fstk_RunInclude(char *s);
|
||||||
extern void fstk_RunMacroArg( SLONG s );
|
extern void fstk_RunMacroArg(SLONG s);
|
||||||
extern ULONG fstk_Init( char *s );
|
extern ULONG fstk_Init(char *s);
|
||||||
extern void fstk_Dump( void );
|
extern void fstk_Dump(void);
|
||||||
extern void fstk_AddIncludePath( char *s );
|
extern void fstk_AddIncludePath(char *s);
|
||||||
extern ULONG fstk_RunMacro( char *s );
|
extern ULONG fstk_RunMacro(char *s);
|
||||||
extern void fstk_RunRept( ULONG count );
|
extern void fstk_RunRept(ULONG count);
|
||||||
extern void fstk_FindFile( char *s );
|
extern void fstk_FindFile(char *s);
|
||||||
|
|
||||||
extern int yywrap( void );
|
extern int yywrap(void);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -1,6 +1,5 @@
|
|||||||
typedef union
|
typedef union {
|
||||||
{
|
char tzSym[MAXSYMLEN + 1];
|
||||||
char tzSym[MAXSYMLEN+1];
|
|
||||||
char tzString[256];
|
char tzString[256];
|
||||||
struct Expression sVal;
|
struct Expression sVal;
|
||||||
SLONG nConstValue;
|
SLONG nConstValue;
|
||||||
@@ -149,5 +148,4 @@ typedef union
|
|||||||
#define T_CC_Z 399
|
#define T_CC_Z 399
|
||||||
#define T_CC_NC 400
|
#define T_CC_NC 400
|
||||||
|
|
||||||
|
|
||||||
extern YYSTYPE yylval;
|
extern YYSTYPE yylval;
|
||||||
|
|||||||
@@ -6,28 +6,24 @@
|
|||||||
|
|
||||||
#define LEXHASHSIZE 512
|
#define LEXHASHSIZE 512
|
||||||
|
|
||||||
struct sLexInitString
|
struct sLexInitString {
|
||||||
{
|
|
||||||
char *tzName;
|
char *tzName;
|
||||||
ULONG nToken;
|
ULONG nToken;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct sLexFloat
|
struct sLexFloat {
|
||||||
{
|
ULONG(*Callback) (char *s, ULONG size);
|
||||||
ULONG (*Callback)( char *s, ULONG size );
|
|
||||||
ULONG nToken;
|
ULONG nToken;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct yy_buffer_state
|
struct yy_buffer_state {
|
||||||
{
|
|
||||||
char *pBufferStart;
|
char *pBufferStart;
|
||||||
char *pBuffer;
|
char *pBuffer;
|
||||||
ULONG nBufferSize;
|
ULONG nBufferSize;
|
||||||
ULONG oAtLineStart;
|
ULONG oAtLineStart;
|
||||||
};
|
};
|
||||||
|
|
||||||
enum eLexerState
|
enum eLexerState {
|
||||||
{
|
|
||||||
LEX_STATE_NORMAL,
|
LEX_STATE_NORMAL,
|
||||||
LEX_STATE_MACROARGS
|
LEX_STATE_MACROARGS
|
||||||
};
|
};
|
||||||
@@ -37,32 +33,32 @@ enum eLexerState
|
|||||||
|
|
||||||
typedef struct yy_buffer_state *YY_BUFFER_STATE;
|
typedef struct yy_buffer_state *YY_BUFFER_STATE;
|
||||||
|
|
||||||
extern void yy_set_state( enum eLexerState i );
|
extern void yy_set_state(enum eLexerState i);
|
||||||
extern YY_BUFFER_STATE yy_create_buffer( FILE *f );
|
extern YY_BUFFER_STATE yy_create_buffer(FILE * f);
|
||||||
extern YY_BUFFER_STATE yy_scan_bytes( char *mem, ULONG size );
|
extern YY_BUFFER_STATE yy_scan_bytes(char *mem, ULONG size);
|
||||||
extern void yy_delete_buffer( YY_BUFFER_STATE );
|
extern void yy_delete_buffer(YY_BUFFER_STATE);
|
||||||
extern void yy_switch_to_buffer( YY_BUFFER_STATE );
|
extern void yy_switch_to_buffer(YY_BUFFER_STATE);
|
||||||
extern ULONG lex_FloatAlloc( struct sLexFloat *tok );
|
extern ULONG lex_FloatAlloc(struct sLexFloat *tok);
|
||||||
extern void lex_FloatAddRange( ULONG id, UWORD start, UWORD end );
|
extern void lex_FloatAddRange(ULONG id, UWORD start, UWORD end);
|
||||||
extern void lex_FloatDeleteRange( ULONG id, UWORD start, UWORD end );
|
extern void lex_FloatDeleteRange(ULONG id, UWORD start, UWORD end);
|
||||||
extern void lex_FloatAddFirstRange( ULONG id, UWORD start, UWORD end );
|
extern void lex_FloatAddFirstRange(ULONG id, UWORD start, UWORD end);
|
||||||
extern void lex_FloatDeleteFirstRange( ULONG id, UWORD start, UWORD end );
|
extern void lex_FloatDeleteFirstRange(ULONG id, UWORD start, UWORD end);
|
||||||
extern void lex_FloatAddSecondRange( ULONG id, UWORD start, UWORD end );
|
extern void lex_FloatAddSecondRange(ULONG id, UWORD start, UWORD end);
|
||||||
extern void lex_FloatDeleteSecondRange( ULONG id, UWORD start, UWORD end );
|
extern void lex_FloatDeleteSecondRange(ULONG id, UWORD start, UWORD end);
|
||||||
extern void lex_Init( void );
|
extern void lex_Init(void);
|
||||||
extern void lex_AddStrings( struct sLexInitString *lex );
|
extern void lex_AddStrings(struct sLexInitString *lex);
|
||||||
extern void lex_SetBuffer( char *buffer, ULONG len );
|
extern void lex_SetBuffer(char *buffer, ULONG len);
|
||||||
extern ULONG yylex( void );
|
extern ULONG yylex(void);
|
||||||
extern void yyunput( char c );
|
extern void yyunput(char c);
|
||||||
extern void yyunputstr( char *s );
|
extern void yyunputstr(char *s);
|
||||||
extern void yyskipbytes( ULONG count );
|
extern void yyskipbytes(ULONG count);
|
||||||
extern void yyunputbytes( ULONG count );
|
extern void yyunputbytes(ULONG count);
|
||||||
|
|
||||||
extern YY_BUFFER_STATE pCurrentBuffer;
|
extern YY_BUFFER_STATE pCurrentBuffer;
|
||||||
|
|
||||||
#ifdef __GNUC__
|
#ifdef __GNUC__
|
||||||
extern void strupr( char *s );
|
extern void strupr(char *s);
|
||||||
extern void strlwr( char *s );
|
extern void strlwr(char *s);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
@@ -1,8 +1,7 @@
|
|||||||
#ifndef MAIN_H
|
#ifndef MAIN_H
|
||||||
#define MAIN_H
|
#define MAIN_H
|
||||||
|
|
||||||
struct sOptions
|
struct sOptions {
|
||||||
{
|
|
||||||
ULONG endian;
|
ULONG endian;
|
||||||
char gbgfx[4];
|
char gbgfx[4];
|
||||||
char binary[2];
|
char binary[2];
|
||||||
@@ -16,12 +15,12 @@ extern SLONG nBinaryID;
|
|||||||
|
|
||||||
extern struct sOptions DefaultOptions;
|
extern struct sOptions DefaultOptions;
|
||||||
extern struct sOptions CurrentOptions;
|
extern struct sOptions CurrentOptions;
|
||||||
extern void opt_Push( void );
|
extern void opt_Push(void);
|
||||||
extern void opt_Pop( void );
|
extern void opt_Pop(void);
|
||||||
extern void opt_Parse( char *s );
|
extern void opt_Parse(char *s);
|
||||||
|
|
||||||
void fatalerror( char *s );
|
void fatalerror(char *s);
|
||||||
void yyerror( char *s );
|
void yyerror(char *s);
|
||||||
|
|
||||||
extern char temptext[1024];
|
extern char temptext[1024];
|
||||||
|
|
||||||
|
|||||||
@@ -55,9 +55,8 @@
|
|||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
enum
|
enum {
|
||||||
{
|
RPN_ADD = 0,
|
||||||
RPN_ADD=0,
|
|
||||||
RPN_SUB,
|
RPN_SUB,
|
||||||
RPN_MUL,
|
RPN_MUL,
|
||||||
RPN_DIV,
|
RPN_DIV,
|
||||||
@@ -91,29 +90,26 @@ enum
|
|||||||
|
|
||||||
RPN_RANGECHECK,
|
RPN_RANGECHECK,
|
||||||
|
|
||||||
RPN_CONST=0x80,
|
RPN_CONST = 0x80,
|
||||||
RPN_SYM=0x81
|
RPN_SYM = 0x81
|
||||||
};
|
};
|
||||||
|
|
||||||
enum
|
enum {
|
||||||
{
|
SECT_BSS = 0,
|
||||||
SECT_BSS=0,
|
|
||||||
SECT_VRAM,
|
SECT_VRAM,
|
||||||
SECT_CODE,
|
SECT_CODE,
|
||||||
SECT_HOME,
|
SECT_HOME,
|
||||||
SECT_HRAM
|
SECT_HRAM
|
||||||
};
|
};
|
||||||
|
|
||||||
enum
|
enum {
|
||||||
{
|
SYM_LOCAL = 0,
|
||||||
SYM_LOCAL=0,
|
|
||||||
SYM_IMPORT,
|
SYM_IMPORT,
|
||||||
SYM_EXPORT
|
SYM_EXPORT
|
||||||
};
|
};
|
||||||
|
|
||||||
enum
|
enum {
|
||||||
{
|
PATCH_BYTE = 0,
|
||||||
PATCH_BYTE=0,
|
|
||||||
PATCH_WORD_L,
|
PATCH_WORD_L,
|
||||||
PATCH_LONG_L,
|
PATCH_LONG_L,
|
||||||
PATCH_WORD_B,
|
PATCH_WORD_B,
|
||||||
|
|||||||
@@ -3,16 +3,16 @@
|
|||||||
|
|
||||||
#include "types.h"
|
#include "types.h"
|
||||||
|
|
||||||
void math_DefinePI( void );
|
void math_DefinePI(void);
|
||||||
void math_Print( SLONG i );
|
void math_Print(SLONG i);
|
||||||
SLONG math_Sin( SLONG i );
|
SLONG math_Sin(SLONG i);
|
||||||
SLONG math_Cos( SLONG i );
|
SLONG math_Cos(SLONG i);
|
||||||
SLONG math_Tan( SLONG i );
|
SLONG math_Tan(SLONG i);
|
||||||
SLONG math_ASin( SLONG i );
|
SLONG math_ASin(SLONG i);
|
||||||
SLONG math_ACos( SLONG i );
|
SLONG math_ACos(SLONG i);
|
||||||
SLONG math_ATan( SLONG i );
|
SLONG math_ATan(SLONG i);
|
||||||
SLONG math_ATan2( SLONG i, SLONG j );
|
SLONG math_ATan2(SLONG i, SLONG j);
|
||||||
SLONG math_Mul( SLONG i, SLONG j );
|
SLONG math_Mul(SLONG i, SLONG j);
|
||||||
SLONG math_Div( SLONG i, SLONG j );
|
SLONG math_Div(SLONG i, SLONG j);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -4,8 +4,7 @@
|
|||||||
#include "rpn.h"
|
#include "rpn.h"
|
||||||
#include "types.h"
|
#include "types.h"
|
||||||
|
|
||||||
struct Section
|
struct Section {
|
||||||
{
|
|
||||||
char *pzName;
|
char *pzName;
|
||||||
UBYTE nType;
|
UBYTE nType;
|
||||||
ULONG nPC;
|
ULONG nPC;
|
||||||
@@ -16,21 +15,21 @@ struct Section
|
|||||||
UBYTE *tData;
|
UBYTE *tData;
|
||||||
};
|
};
|
||||||
|
|
||||||
void out_PrepPass2( void );
|
void out_PrepPass2(void);
|
||||||
void out_SetFileName( char *s );
|
void out_SetFileName(char *s);
|
||||||
void out_NewSection (char *pzName, ULONG secttype);
|
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);
|
||||||
void out_AbsByte( int b );
|
void out_AbsByte(int b);
|
||||||
void out_RelByte( struct Expression *expr );
|
void out_RelByte(struct Expression *expr);
|
||||||
void out_RelWord( struct Expression *expr );
|
void out_RelWord(struct Expression *expr);
|
||||||
void out_PCRelByte( struct Expression *expr );
|
void out_PCRelByte(struct Expression *expr);
|
||||||
void out_WriteObject( void );
|
void out_WriteObject(void);
|
||||||
void out_Skip( int skip );
|
void out_Skip(int skip);
|
||||||
void out_BinaryFile( char *s );
|
void out_BinaryFile(char *s);
|
||||||
void out_String( char *s );
|
void out_String(char *s);
|
||||||
void out_AbsLong (SLONG b);
|
void out_AbsLong(SLONG b);
|
||||||
void out_RelLong (struct Expression *expr);
|
void out_RelLong(struct Expression *expr);
|
||||||
void out_PushSection( void );
|
void out_PushSection(void);
|
||||||
void out_PopSection( void );
|
void out_PopSection(void);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -1,8 +1,7 @@
|
|||||||
#ifndef RPN_H
|
#ifndef RPN_H
|
||||||
#define RPN_H 1
|
#define RPN_H 1
|
||||||
|
|
||||||
struct Expression
|
struct Expression {
|
||||||
{
|
|
||||||
SLONG nVal;
|
SLONG nVal;
|
||||||
UBYTE tRPN[256];
|
UBYTE tRPN[256];
|
||||||
ULONG nRPNLength;
|
ULONG nRPNLength;
|
||||||
@@ -11,41 +10,59 @@ struct Expression
|
|||||||
ULONG isPCRel;
|
ULONG isPCRel;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
ULONG rpn_isReloc(struct Expression *expr);
|
||||||
ULONG rpn_isReloc( struct Expression *expr );
|
ULONG rpn_isPCRelative(struct Expression *expr);
|
||||||
ULONG rpn_isPCRelative( struct Expression *expr );
|
void rpn_Symbol(struct Expression *expr, char *tzSym);
|
||||||
void rpn_Symbol( struct Expression *expr, char *tzSym );
|
void rpn_Number(struct Expression *expr, ULONG i);
|
||||||
void rpn_Number( struct Expression *expr, ULONG i );
|
void rpn_LOGNOT(struct Expression *expr, struct Expression *src1);
|
||||||
void rpn_LOGNOT( struct Expression *expr, struct Expression *src1 );
|
void rpn_LOGOR(struct Expression *expr, struct Expression *src1,
|
||||||
void rpn_LOGOR( struct Expression *expr, struct Expression *src1, struct Expression *src2 );
|
struct Expression *src2);
|
||||||
void rpn_LOGAND( struct Expression *expr, struct Expression *src1, struct Expression *src2 );
|
void rpn_LOGAND(struct Expression *expr, struct Expression *src1,
|
||||||
void rpn_LOGEQU( struct Expression *expr, struct Expression *src1, struct Expression *src2 );
|
struct Expression *src2);
|
||||||
void rpn_LOGGT( struct Expression *expr, struct Expression *src1, struct Expression *src2 );
|
void rpn_LOGEQU(struct Expression *expr, struct Expression *src1,
|
||||||
void rpn_LOGLT( struct Expression *expr, struct Expression *src1, struct Expression *src2 );
|
struct Expression *src2);
|
||||||
void rpn_LOGGE( struct Expression *expr, struct Expression *src1, struct Expression *src2 );
|
void rpn_LOGGT(struct Expression *expr, struct Expression *src1,
|
||||||
void rpn_LOGLE( struct Expression *expr, struct Expression *src1, struct Expression *src2 );
|
struct Expression *src2);
|
||||||
void rpn_LOGNE( struct Expression *expr, struct Expression *src1, struct Expression *src2 );
|
void rpn_LOGLT(struct Expression *expr, struct Expression *src1,
|
||||||
void rpn_ADD( struct Expression *expr, struct Expression *src1, struct Expression *src2 );
|
struct Expression *src2);
|
||||||
void rpn_SUB( struct Expression *expr, struct Expression *src1, struct Expression *src2 );
|
void rpn_LOGGE(struct Expression *expr, struct Expression *src1,
|
||||||
void rpn_XOR( struct Expression *expr, struct Expression *src1, struct Expression *src2 );
|
struct Expression *src2);
|
||||||
void rpn_OR( struct Expression *expr, struct Expression *src1, struct Expression *src2 );
|
void rpn_LOGLE(struct Expression *expr, struct Expression *src1,
|
||||||
void rpn_AND( struct Expression *expr, struct Expression *src1, struct Expression *src2 );
|
struct Expression *src2);
|
||||||
void rpn_SHL( struct Expression *expr, struct Expression *src1, struct Expression *src2 );
|
void rpn_LOGNE(struct Expression *expr, struct Expression *src1,
|
||||||
void rpn_SHR( struct Expression *expr, struct Expression *src1, struct Expression *src2 );
|
struct Expression *src2);
|
||||||
void rpn_MUL( struct Expression *expr, struct Expression *src1, struct Expression *src2 );
|
void rpn_ADD(struct Expression *expr, struct Expression *src1,
|
||||||
void rpn_DIV( struct Expression *expr, struct Expression *src1, struct Expression *src2 );
|
struct Expression *src2);
|
||||||
void rpn_MOD( struct Expression *expr, struct Expression *src1, struct Expression *src2 );
|
void rpn_SUB(struct Expression *expr, struct Expression *src1,
|
||||||
void rpn_UNNEG( struct Expression *expr, struct Expression *src );
|
struct Expression *src2);
|
||||||
void rpn_UNNOT( struct Expression *expr, struct Expression *src );
|
void rpn_XOR(struct Expression *expr, struct Expression *src1,
|
||||||
UWORD rpn_PopByte( struct Expression *expr );
|
struct Expression *src2);
|
||||||
void rpn_Bank( struct Expression *expr, char *tzSym );
|
void rpn_OR(struct Expression *expr, struct Expression *src1,
|
||||||
void rpn_Reset( struct Expression *expr );
|
struct Expression *src2);
|
||||||
int rpn_RangeCheck( struct Expression *expr, struct Expression *src, SLONG low, SLONG high );
|
void rpn_AND(struct Expression *expr, struct Expression *src1,
|
||||||
|
struct Expression *src2);
|
||||||
|
void rpn_SHL(struct Expression *expr, struct Expression *src1,
|
||||||
|
struct Expression *src2);
|
||||||
|
void rpn_SHR(struct Expression *expr, struct Expression *src1,
|
||||||
|
struct Expression *src2);
|
||||||
|
void rpn_MUL(struct Expression *expr, struct Expression *src1,
|
||||||
|
struct Expression *src2);
|
||||||
|
void rpn_DIV(struct Expression *expr, struct Expression *src1,
|
||||||
|
struct Expression *src2);
|
||||||
|
void rpn_MOD(struct Expression *expr, struct Expression *src1,
|
||||||
|
struct Expression *src2);
|
||||||
|
void rpn_UNNEG(struct Expression *expr, struct Expression *src);
|
||||||
|
void rpn_UNNOT(struct Expression *expr, struct Expression *src);
|
||||||
|
UWORD rpn_PopByte(struct Expression *expr);
|
||||||
|
void rpn_Bank(struct Expression *expr, char *tzSym);
|
||||||
|
void rpn_Reset(struct Expression *expr);
|
||||||
|
int rpn_RangeCheck(struct Expression *expr, struct Expression *src, SLONG low,
|
||||||
|
SLONG high);
|
||||||
#ifdef GAMEBOY
|
#ifdef GAMEBOY
|
||||||
void rpn_CheckHRAM( struct Expression *expr,struct Expression *src1 );
|
void rpn_CheckHRAM(struct Expression *expr, struct Expression *src1);
|
||||||
#endif
|
#endif
|
||||||
#ifdef PCENGINE
|
#ifdef PCENGINE
|
||||||
void rpn_CheckZP( struct Expression *expr,struct Expression *src );
|
void rpn_CheckZP(struct Expression *expr, struct Expression *src);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
@@ -6,9 +6,8 @@
|
|||||||
#define HASHSIZE 73
|
#define HASHSIZE 73
|
||||||
#define MAXSYMLEN 256
|
#define MAXSYMLEN 256
|
||||||
|
|
||||||
struct sSymbol
|
struct sSymbol {
|
||||||
{
|
char tzName[MAXSYMLEN + 1];
|
||||||
char tzName[MAXSYMLEN+1];
|
|
||||||
SLONG nValue;
|
SLONG nValue;
|
||||||
ULONG nType;
|
ULONG nType;
|
||||||
struct sSymbol *pScope;
|
struct sSymbol *pScope;
|
||||||
@@ -16,7 +15,7 @@ struct sSymbol
|
|||||||
struct Section *pSection;
|
struct Section *pSection;
|
||||||
ULONG ulMacroSize;
|
ULONG ulMacroSize;
|
||||||
char *pMacro;
|
char *pMacro;
|
||||||
SLONG (*Callback)(struct sSymbol *);
|
SLONG(*Callback) (struct sSymbol *);
|
||||||
};
|
};
|
||||||
|
|
||||||
#define SYMF_RELOC 0x001 /* symbol will be reloc'ed during linking, it's absolute value is unknown */
|
#define SYMF_RELOC 0x001 /* symbol will be reloc'ed during linking, it's absolute value is unknown */
|
||||||
@@ -30,39 +29,39 @@ struct sSymbol
|
|||||||
#define SYMF_STRING 0x100 /* symbol is a stringsymbol */
|
#define SYMF_STRING 0x100 /* symbol is a stringsymbol */
|
||||||
#define SYMF_CONST 0x200 /* symbol has a constant value, will not be changed during linking */
|
#define SYMF_CONST 0x200 /* symbol has a constant value, will not be changed during linking */
|
||||||
|
|
||||||
void sym_PrepPass1( void );
|
void sym_PrepPass1(void);
|
||||||
void sym_PrepPass2( void );
|
void sym_PrepPass2(void);
|
||||||
void sym_AddLocalReloc( char *tzSym );
|
void sym_AddLocalReloc(char *tzSym);
|
||||||
void sym_AddReloc( char *tzSym );
|
void sym_AddReloc(char *tzSym);
|
||||||
void sym_Export( char *tzSym );
|
void sym_Export(char *tzSym);
|
||||||
void sym_PrintSymbolTable( void );
|
void sym_PrintSymbolTable(void);
|
||||||
struct sSymbol *sym_FindMacro( char *s );
|
struct sSymbol *sym_FindMacro(char *s);
|
||||||
void sym_InitNewMacroArgs( void );
|
void sym_InitNewMacroArgs(void);
|
||||||
void sym_AddNewMacroArg( char *s );
|
void sym_AddNewMacroArg(char *s);
|
||||||
void sym_SaveCurrentMacroArgs( char *save[] );
|
void sym_SaveCurrentMacroArgs(char *save[]);
|
||||||
void sym_RestoreCurrentMacroArgs( char *save[] );
|
void sym_RestoreCurrentMacroArgs(char *save[]);
|
||||||
void sym_UseNewMacroArgs( void );
|
void sym_UseNewMacroArgs(void);
|
||||||
void sym_FreeCurrentMacroArgs( void );
|
void sym_FreeCurrentMacroArgs(void);
|
||||||
void sym_AddEqu( char *tzSym, SLONG value );
|
void sym_AddEqu(char *tzSym, SLONG value);
|
||||||
void sym_AddSet( char *tzSym, SLONG value );
|
void sym_AddSet(char *tzSym, SLONG value);
|
||||||
void sym_Init( void );
|
void sym_Init(void);
|
||||||
ULONG sym_GetConstantValue( char *s );
|
ULONG sym_GetConstantValue(char *s);
|
||||||
void sym_Import( char *tzSym );
|
void sym_Import(char *tzSym);
|
||||||
ULONG sym_isConstant( char *s );
|
ULONG sym_isConstant(char *s);
|
||||||
struct sSymbol *sym_FindSymbol( char *tzName );
|
struct sSymbol *sym_FindSymbol(char *tzName);
|
||||||
void sym_Global( char *tzSym );
|
void sym_Global(char *tzSym);
|
||||||
char *sym_FindMacroArg( SLONG i );
|
char *sym_FindMacroArg(SLONG i);
|
||||||
char *sym_GetStringValue( char *tzSym );
|
char *sym_GetStringValue(char *tzSym);
|
||||||
void sym_UseCurrentMacroArgs( void );
|
void sym_UseCurrentMacroArgs(void);
|
||||||
void sym_SetMacroArgID( ULONG nMacroCount );
|
void sym_SetMacroArgID(ULONG nMacroCount);
|
||||||
ULONG sym_isString( char *tzSym );
|
ULONG sym_isString(char *tzSym);
|
||||||
void sym_AddMacro( char *tzSym );
|
void sym_AddMacro(char *tzSym);
|
||||||
void sym_ShiftCurrentMacroArgs( void );
|
void sym_ShiftCurrentMacroArgs(void);
|
||||||
void sym_AddString( char *tzSym, char *tzValue );
|
void sym_AddString(char *tzSym, char *tzValue);
|
||||||
ULONG sym_GetValue( char *s );
|
ULONG sym_GetValue(char *s);
|
||||||
ULONG sym_GetDefinedValue( char *s );
|
ULONG sym_GetDefinedValue(char *s);
|
||||||
ULONG sym_isDefined( char *tzName );
|
ULONG sym_isDefined(char *tzName);
|
||||||
void sym_Purge( char *tzName );
|
void sym_Purge(char *tzName);
|
||||||
ULONG sym_isConstDefined (char *tzName);
|
ULONG sym_isConstDefined(char *tzName);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
678
src/asm/lexer.c
678
src/asm/lexer.c
File diff suppressed because it is too large
Load Diff
420
src/asm/main.c
420
src/asm/main.c
@@ -15,8 +15,8 @@
|
|||||||
#include "output.h"
|
#include "output.h"
|
||||||
#include "main.h"
|
#include "main.h"
|
||||||
|
|
||||||
int yyparse (void);
|
int yyparse(void);
|
||||||
void setuplex (void);
|
void setuplex(void);
|
||||||
|
|
||||||
#ifdef AMIGA
|
#ifdef AMIGA
|
||||||
__near long __stack = 65536L;
|
__near long __stack = 65536L;
|
||||||
@@ -30,14 +30,9 @@ __near long __stack = 65536L;
|
|||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
clock_t nStartClock,
|
clock_t nStartClock, nEndClock;
|
||||||
nEndClock;
|
|
||||||
SLONG nLineNo;
|
SLONG nLineNo;
|
||||||
ULONG nTotalLines,
|
ULONG nTotalLines, nPass, nPC, nIFDepth, nErrors;
|
||||||
nPass,
|
|
||||||
nPC,
|
|
||||||
nIFDepth,
|
|
||||||
nErrors;
|
|
||||||
|
|
||||||
extern int yydebug;
|
extern int yydebug;
|
||||||
|
|
||||||
@@ -53,170 +48,179 @@ char temptext[1024];
|
|||||||
struct sOptions DefaultOptions;
|
struct sOptions DefaultOptions;
|
||||||
struct sOptions CurrentOptions;
|
struct sOptions CurrentOptions;
|
||||||
|
|
||||||
struct sOptionStackEntry
|
struct sOptionStackEntry {
|
||||||
{
|
|
||||||
struct sOptions Options;
|
struct sOptions Options;
|
||||||
struct sOptionStackEntry *pNext;
|
struct sOptionStackEntry *pNext;
|
||||||
};
|
};
|
||||||
|
|
||||||
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], CurrentOptions.gbgfx[1] );
|
lex_FloatDeleteRange(nGBGfxID, CurrentOptions.gbgfx[1],
|
||||||
lex_FloatDeleteRange( nGBGfxID, CurrentOptions.gbgfx[2], CurrentOptions.gbgfx[2] );
|
CurrentOptions.gbgfx[1]);
|
||||||
lex_FloatDeleteRange( nGBGfxID, CurrentOptions.gbgfx[3], CurrentOptions.gbgfx[3] );
|
lex_FloatDeleteRange(nGBGfxID, CurrentOptions.gbgfx[2],
|
||||||
lex_FloatDeleteSecondRange( nGBGfxID, CurrentOptions.gbgfx[0], CurrentOptions.gbgfx[0] );
|
CurrentOptions.gbgfx[2]);
|
||||||
lex_FloatDeleteSecondRange( nGBGfxID, CurrentOptions.gbgfx[1], CurrentOptions.gbgfx[1] );
|
lex_FloatDeleteRange(nGBGfxID, CurrentOptions.gbgfx[3],
|
||||||
lex_FloatDeleteSecondRange( nGBGfxID, CurrentOptions.gbgfx[2], CurrentOptions.gbgfx[2] );
|
CurrentOptions.gbgfx[3]);
|
||||||
lex_FloatDeleteSecondRange( nGBGfxID, CurrentOptions.gbgfx[3], CurrentOptions.gbgfx[3] );
|
lex_FloatDeleteSecondRange(nGBGfxID, CurrentOptions.gbgfx[0],
|
||||||
|
CurrentOptions.gbgfx[0]);
|
||||||
|
lex_FloatDeleteSecondRange(nGBGfxID, CurrentOptions.gbgfx[1],
|
||||||
|
CurrentOptions.gbgfx[1]);
|
||||||
|
lex_FloatDeleteSecondRange(nGBGfxID, CurrentOptions.gbgfx[2],
|
||||||
|
CurrentOptions.gbgfx[2]);
|
||||||
|
lex_FloatDeleteSecondRange(nGBGfxID, 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], CurrentOptions.binary[1] );
|
lex_FloatDeleteRange(nBinaryID, CurrentOptions.binary[1],
|
||||||
lex_FloatDeleteSecondRange( nBinaryID, CurrentOptions.binary[0], CurrentOptions.binary[0] );
|
CurrentOptions.binary[1]);
|
||||||
lex_FloatDeleteSecondRange( nBinaryID, CurrentOptions.binary[1], CurrentOptions.binary[1] );
|
lex_FloatDeleteSecondRange(nBinaryID, CurrentOptions.binary[0],
|
||||||
|
CurrentOptions.binary[0]);
|
||||||
|
lex_FloatDeleteSecondRange(nBinaryID, 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], CurrentOptions.gbgfx[1] );
|
lex_FloatAddRange(nGBGfxID, CurrentOptions.gbgfx[1],
|
||||||
lex_FloatAddRange( nGBGfxID, CurrentOptions.gbgfx[2], CurrentOptions.gbgfx[2] );
|
CurrentOptions.gbgfx[1]);
|
||||||
lex_FloatAddRange( nGBGfxID, CurrentOptions.gbgfx[3], CurrentOptions.gbgfx[3] );
|
lex_FloatAddRange(nGBGfxID, CurrentOptions.gbgfx[2],
|
||||||
lex_FloatAddSecondRange( nGBGfxID, CurrentOptions.gbgfx[0], CurrentOptions.gbgfx[0] );
|
CurrentOptions.gbgfx[2]);
|
||||||
lex_FloatAddSecondRange( nGBGfxID, CurrentOptions.gbgfx[1], CurrentOptions.gbgfx[1] );
|
lex_FloatAddRange(nGBGfxID, CurrentOptions.gbgfx[3],
|
||||||
lex_FloatAddSecondRange( nGBGfxID, CurrentOptions.gbgfx[2], CurrentOptions.gbgfx[2] );
|
CurrentOptions.gbgfx[3]);
|
||||||
lex_FloatAddSecondRange( nGBGfxID, CurrentOptions.gbgfx[3], CurrentOptions.gbgfx[3] );
|
lex_FloatAddSecondRange(nGBGfxID, CurrentOptions.gbgfx[0],
|
||||||
|
CurrentOptions.gbgfx[0]);
|
||||||
|
lex_FloatAddSecondRange(nGBGfxID, CurrentOptions.gbgfx[1],
|
||||||
|
CurrentOptions.gbgfx[1]);
|
||||||
|
lex_FloatAddSecondRange(nGBGfxID, CurrentOptions.gbgfx[2],
|
||||||
|
CurrentOptions.gbgfx[2]);
|
||||||
|
lex_FloatAddSecondRange(nGBGfxID, 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], CurrentOptions.binary[1] );
|
lex_FloatAddRange(nBinaryID, CurrentOptions.binary[1],
|
||||||
lex_FloatAddSecondRange( nBinaryID, CurrentOptions.binary[0], CurrentOptions.binary[0] );
|
CurrentOptions.binary[1]);
|
||||||
lex_FloatAddSecondRange( nBinaryID, CurrentOptions.binary[1], CurrentOptions.binary[1] );
|
lex_FloatAddSecondRange(nBinaryID, CurrentOptions.binary[0],
|
||||||
|
CurrentOptions.binary[0]);
|
||||||
|
lex_FloatAddSecondRange(nBinaryID, CurrentOptions.binary[1],
|
||||||
|
CurrentOptions.binary[1]);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void opt_Parse( char *s )
|
void opt_Parse(char *s)
|
||||||
{
|
{
|
||||||
struct sOptions newopt;
|
struct sOptions newopt;
|
||||||
|
|
||||||
newopt=CurrentOptions;
|
newopt = CurrentOptions;
|
||||||
|
|
||||||
switch( s[0] )
|
switch (s[0]) {
|
||||||
{
|
|
||||||
case 'e':
|
case 'e':
|
||||||
switch( s[1] )
|
switch (s[1]) {
|
||||||
{
|
|
||||||
case 'b':
|
case 'b':
|
||||||
newopt.endian=ASM_BIG_ENDIAN;
|
newopt.endian = ASM_BIG_ENDIAN;
|
||||||
printf( "*WARNING*\t :\n\tEndianness forced to BIG for destination CPU\n" );
|
printf
|
||||||
|
("*WARNING*\t :\n\tEndianness forced to BIG for destination CPU\n");
|
||||||
break;
|
break;
|
||||||
case 'l':
|
case 'l':
|
||||||
newopt.endian=ASM_LITTLE_ENDIAN;
|
newopt.endian = ASM_LITTLE_ENDIAN;
|
||||||
printf( "*WARNING*\t :\n\tEndianness forced to LITTLE for destination CPU\n" );
|
printf
|
||||||
|
("*WARNING*\t :\n\tEndianness forced to LITTLE for destination CPU\n");
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
printf ("*ERROR*\t :\n\tArgument to option -e must be 'b' or 'l'\n" );
|
printf
|
||||||
exit (5);
|
("*ERROR*\t :\n\tArgument to option -e must be 'b' or 'l'\n");
|
||||||
|
exit(5);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case 'g':
|
case 'g':
|
||||||
if( strlen(&s[1])==4 )
|
if (strlen(&s[1]) == 4) {
|
||||||
{
|
newopt.gbgfx[0] = s[1];
|
||||||
newopt.gbgfx[0]=s[1];
|
newopt.gbgfx[1] = s[2];
|
||||||
newopt.gbgfx[1]=s[2];
|
newopt.gbgfx[2] = s[3];
|
||||||
newopt.gbgfx[2]=s[3];
|
newopt.gbgfx[3] = s[4];
|
||||||
newopt.gbgfx[3]=s[4];
|
} else {
|
||||||
}
|
printf
|
||||||
else
|
("*ERROR*\t :\n\tMust specify exactly 4 characters for option 'g'\n");
|
||||||
{
|
exit(5);
|
||||||
printf ("*ERROR*\t :\n\tMust specify exactly 4 characters for option 'g'\n" );
|
|
||||||
exit( 5 );
|
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case 'b':
|
case 'b':
|
||||||
if( strlen(&s[1])==2 )
|
if (strlen(&s[1]) == 2) {
|
||||||
{
|
newopt.binary[0] = s[1];
|
||||||
newopt.binary[0]=s[1];
|
newopt.binary[1] = s[2];
|
||||||
newopt.binary[1]=s[2];
|
} else {
|
||||||
}
|
printf
|
||||||
else
|
("*ERROR*\t :\n\tMust specify exactly 2 characters for option 'b'\n");
|
||||||
{
|
exit(5);
|
||||||
printf ("*ERROR*\t :\n\tMust specify exactly 2 characters for option 'b'\n" );
|
|
||||||
exit( 5 );
|
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case 'z':
|
case 'z':
|
||||||
if( strlen(&s[1])<=2 )
|
if (strlen(&s[1]) <= 2) {
|
||||||
{
|
if (strcmp(&s[1], "?") == 0) {
|
||||||
if( strcmp(&s[1],"?")==0 )
|
newopt.fillchar = -1;
|
||||||
{
|
} else {
|
||||||
newopt.fillchar=-1;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
int result;
|
int result;
|
||||||
|
|
||||||
result=sscanf( &s[1], "%lx", &newopt.fillchar );
|
result = sscanf(&s[1], "%lx", &newopt.fillchar);
|
||||||
if( !((result==EOF) || (result==1)) )
|
if (!((result == EOF) || (result == 1))) {
|
||||||
{
|
printf
|
||||||
printf ("*ERROR*\t :\n\tInvalid argument for option 'z'\n" );
|
("*ERROR*\t :\n\tInvalid argument for option 'z'\n");
|
||||||
exit( 5 );
|
exit(5);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
} else {
|
||||||
else
|
printf
|
||||||
{
|
("*ERROR*\t :\n\tInvalid argument for option 'z'\n");
|
||||||
printf ("*ERROR*\t :\n\tInvalid argument for option 'z'\n" );
|
exit(5);
|
||||||
exit( 5 );
|
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
fatalerror( "Unknown option" );
|
fatalerror("Unknown option");
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
opt_SetCurrentOptions( &newopt );
|
opt_SetCurrentOptions(&newopt);
|
||||||
}
|
}
|
||||||
|
|
||||||
void opt_Push( void )
|
void opt_Push(void)
|
||||||
{
|
{
|
||||||
struct sOptionStackEntry *pOpt;
|
struct sOptionStackEntry *pOpt;
|
||||||
|
|
||||||
if( (pOpt=(struct sOptionStackEntry *)malloc(sizeof(struct sOptionStackEntry)))!=NULL )
|
if ((pOpt =
|
||||||
{
|
(struct sOptionStackEntry *)
|
||||||
pOpt->Options=CurrentOptions;
|
malloc(sizeof(struct sOptionStackEntry))) != NULL) {
|
||||||
pOpt->pNext=pOptionStack;
|
pOpt->Options = CurrentOptions;
|
||||||
pOptionStack=pOpt;
|
pOpt->pNext = pOptionStack;
|
||||||
}
|
pOptionStack = pOpt;
|
||||||
else
|
} else
|
||||||
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;
|
||||||
|
|
||||||
pOpt=pOptionStack;
|
pOpt = pOptionStack;
|
||||||
opt_SetCurrentOptions( &(pOpt->Options) );
|
opt_SetCurrentOptions(&(pOpt->Options));
|
||||||
pOptionStack=pOpt->pNext;
|
pOptionStack = pOpt->pNext;
|
||||||
free( pOpt );
|
free(pOpt);
|
||||||
}
|
} else
|
||||||
else
|
fatalerror("No entries in the option stack");
|
||||||
fatalerror( "No entries in the option stack" );
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@@ -226,18 +230,18 @@ void opt_Pop( void )
|
|||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
void yyerror (char *s)
|
void yyerror(char *s)
|
||||||
{
|
{
|
||||||
printf ("*ERROR*\t");
|
printf("*ERROR*\t");
|
||||||
fstk_Dump ();
|
fstk_Dump();
|
||||||
printf (" :\n\t%s\n", s);
|
printf(" :\n\t%s\n", s);
|
||||||
nErrors += 1;
|
nErrors += 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
void fatalerror (char *s)
|
void fatalerror(char *s)
|
||||||
{
|
{
|
||||||
yyerror (s);
|
yyerror(s);
|
||||||
exit (5);
|
exit(5);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@@ -247,21 +251,25 @@ void fatalerror (char *s)
|
|||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
void PrintUsage (void)
|
void PrintUsage(void)
|
||||||
{
|
{
|
||||||
printf (APPNAME " v" ASM_VERSION " (part of ASMotor " ASMOTOR_VERSION ")\n\nUsage: " EXENAME " [options] asmfile\n");
|
printf(APPNAME " v" ASM_VERSION " (part of ASMotor " ASMOTOR_VERSION
|
||||||
printf ("Options:\n");
|
")\n\nUsage: " EXENAME " [options] asmfile\n");
|
||||||
printf ("\t-h\t\tThis text\n");
|
printf("Options:\n");
|
||||||
printf ("\t-i<path>\tExtra include path\n");
|
printf("\t-h\t\tThis text\n");
|
||||||
printf ("\t-o<file>\tWrite objectoutput to <file>\n");
|
printf("\t-i<path>\tExtra include path\n");
|
||||||
printf ("\t-e(l|b)\t\tChange endianness (CAUTION!)\n");
|
printf("\t-o<file>\tWrite objectoutput to <file>\n");
|
||||||
printf ("\t-g<ASCI>\tChange the four characters used for Gameboy graphics\n"
|
printf("\t-e(l|b)\t\tChange endianness (CAUTION!)\n");
|
||||||
"\t\t\tconstants (default is 0123)\n" );
|
printf
|
||||||
printf ("\t-b<AS>\t\tChange the two characters used for binary constants\n"
|
("\t-g<ASCI>\tChange the four characters used for Gameboy graphics\n"
|
||||||
"\t\t\t(default is 01)\n" );
|
"\t\t\tconstants (default is 0123)\n");
|
||||||
printf ("\t-z<hx>\t\tSet the byte value (hex format) used for uninitialised\n"
|
printf
|
||||||
"\t\t\tdata (default is ? for random)\n" );
|
("\t-b<AS>\t\tChange the two characters used for binary constants\n"
|
||||||
exit (0);
|
"\t\t\t(default is 01)\n");
|
||||||
|
printf
|
||||||
|
("\t-z<hx>\t\tSet the byte value (hex format) used for uninitialised\n"
|
||||||
|
"\t\t\tdata (default is ? for random)\n");
|
||||||
|
exit(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@@ -271,7 +279,7 @@ 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;
|
||||||
@@ -279,59 +287,58 @@ int main (int argc, char *argv[])
|
|||||||
argc -= 1;
|
argc -= 1;
|
||||||
|
|
||||||
if (argc == 0)
|
if (argc == 0)
|
||||||
PrintUsage ();
|
PrintUsage();
|
||||||
|
|
||||||
/* yydebug=1; */
|
/* yydebug=1; */
|
||||||
|
|
||||||
DefaultOptions.endian=ASM_DEFAULT_ENDIAN;
|
DefaultOptions.endian = ASM_DEFAULT_ENDIAN;
|
||||||
DefaultOptions.gbgfx[0]='0';
|
DefaultOptions.gbgfx[0] = '0';
|
||||||
DefaultOptions.gbgfx[1]='1';
|
DefaultOptions.gbgfx[1] = '1';
|
||||||
DefaultOptions.gbgfx[2]='2';
|
DefaultOptions.gbgfx[2] = '2';
|
||||||
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; // fill uninitialised data with random values
|
||||||
opt_SetCurrentOptions( &DefaultOptions );
|
opt_SetCurrentOptions(&DefaultOptions);
|
||||||
|
|
||||||
while (argv[argn][0] == '-' && argc)
|
while (argv[argn][0] == '-' && argc) {
|
||||||
{
|
switch (argv[argn][1]) {
|
||||||
switch (argv[argn][1])
|
|
||||||
{
|
|
||||||
case 'h':
|
case 'h':
|
||||||
PrintUsage ();
|
PrintUsage();
|
||||||
break;
|
break;
|
||||||
case 'i':
|
case 'i':
|
||||||
fstk_AddIncludePath (&(argv[argn][2]));
|
fstk_AddIncludePath(&(argv[argn][2]));
|
||||||
break;
|
break;
|
||||||
case 'o':
|
case 'o':
|
||||||
out_SetFileName (&(argv[argn][2]));
|
out_SetFileName(&(argv[argn][2]));
|
||||||
break;
|
break;
|
||||||
case 'e':
|
case 'e':
|
||||||
case 'g':
|
case 'g':
|
||||||
case 'b':
|
case 'b':
|
||||||
case 'z':
|
case 'z':
|
||||||
opt_Parse( &argv[argn][1] );
|
opt_Parse(&argv[argn][1]);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
printf ("*ERROR*\t :\n\tUnknown option '%c'\n", argv[argn][1]);
|
printf("*ERROR*\t :\n\tUnknown option '%c'\n",
|
||||||
exit (5);
|
argv[argn][1]);
|
||||||
|
exit(5);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
argn += 1;
|
argn += 1;
|
||||||
argc -= 1;
|
argc -= 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
DefaultOptions=CurrentOptions;
|
DefaultOptions = CurrentOptions;
|
||||||
|
|
||||||
/*tzMainfile=argv[argn++];
|
/*tzMainfile=argv[argn++];
|
||||||
* argc-=1; */
|
* argc-=1; */
|
||||||
tzMainfile = argv[argn];
|
tzMainfile = argv[argn];
|
||||||
|
|
||||||
setuplex ();
|
setuplex();
|
||||||
|
|
||||||
printf ("Assembling %s\n", tzMainfile);
|
printf("Assembling %s\n", tzMainfile);
|
||||||
|
|
||||||
nStartClock = clock ();
|
nStartClock = clock();
|
||||||
|
|
||||||
nLineNo = 1;
|
nLineNo = 1;
|
||||||
nTotalLines = 0;
|
nTotalLines = 0;
|
||||||
@@ -339,68 +346,69 @@ int main (int argc, char *argv[])
|
|||||||
nPC = 0;
|
nPC = 0;
|
||||||
nPass = 1;
|
nPass = 1;
|
||||||
nErrors = 0;
|
nErrors = 0;
|
||||||
sym_PrepPass1 ();
|
sym_PrepPass1();
|
||||||
if (fstk_Init (tzMainfile))
|
if (fstk_Init(tzMainfile)) {
|
||||||
{
|
printf("Pass 1...\n");
|
||||||
printf ("Pass 1...\n");
|
|
||||||
|
|
||||||
yy_set_state( LEX_STATE_NORMAL );
|
yy_set_state(LEX_STATE_NORMAL);
|
||||||
opt_SetCurrentOptions( &DefaultOptions );
|
opt_SetCurrentOptions(&DefaultOptions);
|
||||||
|
|
||||||
if (yyparse () == 0 && nErrors == 0)
|
if (yyparse() == 0 && nErrors == 0) {
|
||||||
{
|
if (nIFDepth == 0) {
|
||||||
if (nIFDepth == 0)
|
|
||||||
{
|
|
||||||
nTotalLines = 0;
|
nTotalLines = 0;
|
||||||
nLineNo = 1;
|
nLineNo = 1;
|
||||||
nIFDepth = 0;
|
nIFDepth = 0;
|
||||||
nPC = 0;
|
nPC = 0;
|
||||||
nPass = 2;
|
nPass = 2;
|
||||||
nErrors = 0;
|
nErrors = 0;
|
||||||
sym_PrepPass2 ();
|
sym_PrepPass2();
|
||||||
out_PrepPass2 ();
|
out_PrepPass2();
|
||||||
fstk_Init (tzMainfile);
|
fstk_Init(tzMainfile);
|
||||||
yy_set_state( LEX_STATE_NORMAL );
|
yy_set_state(LEX_STATE_NORMAL);
|
||||||
opt_SetCurrentOptions( &DefaultOptions );
|
opt_SetCurrentOptions(&DefaultOptions);
|
||||||
|
|
||||||
printf ("Pass 2...\n");
|
printf("Pass 2...\n");
|
||||||
|
|
||||||
if (yyparse () == 0 && nErrors == 0)
|
if (yyparse() == 0 && nErrors == 0) {
|
||||||
{
|
|
||||||
double timespent;
|
double timespent;
|
||||||
|
|
||||||
nEndClock = clock ();
|
nEndClock = clock();
|
||||||
timespent = ((double) (nEndClock - nStartClock)) / (double) CLOCKS_PER_SEC;
|
timespent =
|
||||||
printf ("Success! %ld lines in %d.%02d seconds ", nTotalLines, (int) timespent, ((int) (timespent * 100.0)) % 100);
|
((double)(nEndClock - nStartClock))
|
||||||
|
/ (double)CLOCKS_PER_SEC;
|
||||||
|
printf
|
||||||
|
("Success! %ld lines in %d.%02d seconds ",
|
||||||
|
nTotalLines, (int)timespent,
|
||||||
|
((int)(timespent * 100.0)) % 100);
|
||||||
if (timespent == 0)
|
if (timespent == 0)
|
||||||
printf ("(INFINITY lines/minute)\n");
|
printf
|
||||||
|
("(INFINITY lines/minute)\n");
|
||||||
else
|
else
|
||||||
printf ("(%d lines/minute)\n", (int) (60 / timespent * nTotalLines));
|
printf("(%d lines/minute)\n",
|
||||||
out_WriteObject ();
|
(int)(60 / timespent *
|
||||||
}
|
nTotalLines));
|
||||||
else
|
out_WriteObject();
|
||||||
{
|
} else {
|
||||||
printf ("Assembly aborted in pass 2 (%ld errors)!\n", nErrors);
|
printf
|
||||||
|
("Assembly aborted in pass 2 (%ld errors)!\n",
|
||||||
|
nErrors);
|
||||||
//sym_PrintSymbolTable();
|
//sym_PrintSymbolTable();
|
||||||
exit (5);
|
exit(5);
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
printf
|
||||||
|
("*ERROR*\t:\tUnterminated IF construct (%ld levels)!\n",
|
||||||
|
nIFDepth);
|
||||||
|
exit(5);
|
||||||
}
|
}
|
||||||
else
|
} else {
|
||||||
{
|
printf("Assembly aborted in pass 1 (%ld errors)!\n",
|
||||||
printf ("*ERROR*\t:\tUnterminated IF construct (%ld levels)!\n", nIFDepth);
|
nErrors);
|
||||||
exit (5);
|
exit(5);
|
||||||
}
|
}
|
||||||
}
|
} else {
|
||||||
else
|
printf("File '%s' not found\n", tzMainfile);
|
||||||
{
|
exit(5);
|
||||||
printf ("Assembly aborted in pass 1 (%ld errors)!\n", nErrors);
|
|
||||||
exit (5);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
printf ("File '%s' not found\n", tzMainfile);
|
|
||||||
exit (5);
|
|
||||||
}
|
}
|
||||||
return (0);
|
return (0);
|
||||||
}
|
}
|
||||||
@@ -24,9 +24,9 @@
|
|||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
void math_DefinePI (void)
|
void math_DefinePI(void)
|
||||||
{
|
{
|
||||||
sym_AddEqu ("_PI", double2fix (PI));
|
sym_AddEqu("_PI", double2fix(PI));
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@@ -36,12 +36,14 @@ 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, ((SLONG) (fix2double (i) * 100000 + 0.5)) % 100000);
|
printf("%ld.%05ld", i >> 16,
|
||||||
|
((SLONG) (fix2double(i) * 100000 + 0.5)) % 100000);
|
||||||
else
|
else
|
||||||
printf ("-%ld.%05ld", (-i) >> 16, ((SLONG) (fix2double (-i) * 100000 + 0.5)) % 100000);
|
printf("-%ld.%05ld", (-i) >> 16,
|
||||||
|
((SLONG) (fix2double(-i) * 100000 + 0.5)) % 100000);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@@ -51,9 +53,9 @@ 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)));
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@@ -63,9 +65,9 @@ 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)));
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@@ -75,9 +77,9 @@ 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)));
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@@ -87,9 +89,9 @@ 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));
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@@ -99,9 +101,9 @@ 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));
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@@ -111,9 +113,9 @@ 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));
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@@ -123,9 +125,10 @@ SLONG math_ATan (SLONG i)
|
|||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
SLONG math_ATan2 (SLONG i, SLONG j)
|
SLONG math_ATan2(SLONG i, SLONG j)
|
||||||
{
|
{
|
||||||
return (double2fix (atan2 (fix2double (i), fix2double (j)) / 2 / PI * 65536));
|
return (double2fix
|
||||||
|
(atan2(fix2double(i), fix2double(j)) / 2 / PI * 65536));
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@@ -135,9 +138,9 @@ 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)));
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@@ -147,7 +150,7 @@ 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)));
|
||||||
}
|
}
|
||||||
643
src/asm/output.c
643
src/asm/output.c
File diff suppressed because it is too large
Load Diff
266
src/asm/rpn.c
266
src/asm/rpn.c
@@ -15,10 +15,11 @@
|
|||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
void mergetwoexpressions( struct Expression *expr, struct Expression *src1, struct Expression *src2 )
|
void 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);
|
||||||
|
|
||||||
expr->nRPNLength += src2->nRPNLength;
|
expr->nRPNLength += src2->nRPNLength;
|
||||||
expr->isReloc |= src2->isReloc;
|
expr->isReloc |= src2->isReloc;
|
||||||
@@ -47,7 +48,7 @@ void mergetwoexpressions( struct Expression *expr, struct Expression *src1, stru
|
|||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
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;
|
||||||
}
|
}
|
||||||
@@ -59,7 +60,7 @@ 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;
|
||||||
}
|
}
|
||||||
@@ -71,13 +72,11 @@ 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++]);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -88,7 +87,7 @@ UWORD rpn_PopByte (struct Expression *expr)
|
|||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
ULONG rpn_isReloc (struct Expression *expr)
|
ULONG rpn_isReloc(struct Expression * expr)
|
||||||
{
|
{
|
||||||
return (expr->isReloc);
|
return (expr->isReloc);
|
||||||
}
|
}
|
||||||
@@ -100,7 +99,7 @@ ULONG rpn_isReloc (struct Expression *expr)
|
|||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
ULONG rpn_isPCRelative (struct Expression *expr)
|
ULONG rpn_isPCRelative(struct Expression * expr)
|
||||||
{
|
{
|
||||||
return (expr->isPCRel);
|
return (expr->isPCRel);
|
||||||
}
|
}
|
||||||
@@ -112,245 +111,256 @@ 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);
|
||||||
pushbyte (expr, i);
|
pushbyte(expr, i);
|
||||||
pushbyte (expr, i >> 8);
|
pushbyte(expr, i >> 8);
|
||||||
pushbyte (expr, i >> 16);
|
pushbyte(expr, i >> 16);
|
||||||
pushbyte (expr, i >> 24);
|
pushbyte(expr, i >> 24);
|
||||||
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;
|
||||||
|
|
||||||
rpn_Reset(expr);
|
rpn_Reset(expr);
|
||||||
|
|
||||||
psym = sym_FindSymbol (tzSym);
|
psym = sym_FindSymbol(tzSym);
|
||||||
|
|
||||||
if (psym == NULL || psym->pSection == pCurrentSection || psym->pSection == NULL)
|
if (psym == NULL || psym->pSection == pCurrentSection
|
||||||
|
|| psym->pSection == NULL)
|
||||||
expr->isPCRel = 1;
|
expr->isPCRel = 1;
|
||||||
expr->isReloc = 1;
|
expr->isReloc = 1;
|
||||||
pushbyte (expr,RPN_SYM);
|
pushbyte(expr, RPN_SYM);
|
||||||
while (*tzSym)
|
while (*tzSym)
|
||||||
pushbyte (expr,*tzSym++);
|
pushbyte(expr, *tzSym++);
|
||||||
pushbyte (expr,0);
|
pushbyte(expr, 0);
|
||||||
}
|
} else
|
||||||
else
|
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;
|
||||||
|
|
||||||
rpn_Reset( expr );
|
rpn_Reset(expr);
|
||||||
|
|
||||||
psym = sym_FindSymbol (tzSym);
|
psym = sym_FindSymbol(tzSym);
|
||||||
if (nPass == 2 && psym == NULL)
|
if (nPass == 2 && psym == NULL) {
|
||||||
{
|
sprintf(temptext, "'%s' not defined", tzSym);
|
||||||
sprintf (temptext, "'%s' not defined", tzSym);
|
yyerror(temptext);
|
||||||
yyerror (temptext);
|
|
||||||
}
|
}
|
||||||
expr->isReloc = 1;
|
expr->isReloc = 1;
|
||||||
pushbyte (expr,RPN_BANK);
|
pushbyte(expr, RPN_BANK);
|
||||||
while (*tzSym)
|
while (*tzSym)
|
||||||
pushbyte (expr,*tzSym++);
|
pushbyte(expr, *tzSym++);
|
||||||
pushbyte (expr,0);
|
pushbyte(expr, 0);
|
||||||
}
|
} else
|
||||||
else
|
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, SLONG high )
|
int rpn_RangeCheck(struct Expression *expr, struct Expression *src, SLONG low,
|
||||||
|
SLONG high)
|
||||||
{
|
{
|
||||||
*expr=*src;
|
*expr = *src;
|
||||||
|
|
||||||
if( rpn_isReloc(src) )
|
if (rpn_isReloc(src)) {
|
||||||
{
|
pushbyte(expr, RPN_RANGECHECK);
|
||||||
pushbyte( expr, RPN_RANGECHECK );
|
pushbyte(expr, low);
|
||||||
pushbyte( expr, low );
|
pushbyte(expr, low >> 8);
|
||||||
pushbyte( expr, low>>8 );
|
pushbyte(expr, low >> 16);
|
||||||
pushbyte( expr, low>>16 );
|
pushbyte(expr, low >> 24);
|
||||||
pushbyte( expr, low>>24 );
|
pushbyte(expr, high);
|
||||||
pushbyte( expr, high );
|
pushbyte(expr, high >> 8);
|
||||||
pushbyte( expr, high>>8 );
|
pushbyte(expr, high >> 16);
|
||||||
pushbyte( expr, high>>16 );
|
pushbyte(expr, high >> 24);
|
||||||
pushbyte( expr, high>>24 );
|
return (1);
|
||||||
return( 1 );
|
} else {
|
||||||
}
|
return (expr->nVal >= low && expr->nVal <= high);
|
||||||
else
|
|
||||||
{
|
|
||||||
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);
|
||||||
}
|
}
|
||||||
#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, struct Expression *src2)
|
void 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, struct Expression *src2)
|
void 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, struct Expression *src2)
|
void 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, struct Expression *src2)
|
void 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, struct Expression *src2)
|
void 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, struct Expression *src2)
|
void 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, struct Expression *src2)
|
void 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, struct Expression *src2)
|
void 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, struct Expression *src2)
|
void 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, struct Expression *src2)
|
void 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, struct Expression *src2)
|
void 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, struct Expression *src2)
|
void 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, struct Expression *src2)
|
void 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, struct Expression *src2)
|
void 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, struct Expression *src2)
|
void 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, struct Expression *src2)
|
void 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, struct Expression *src2)
|
void 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, struct Expression *src2)
|
void 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;
|
||||||
pushbyte (expr,RPN_UNNOT);
|
pushbyte(expr, RPN_UNNOT);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
638
src/asm/symbol.c
638
src/asm/symbol.c
File diff suppressed because it is too large
Load Diff
@@ -3,11 +3,11 @@
|
|||||||
|
|
||||||
#include "libwrap.h"
|
#include "libwrap.h"
|
||||||
|
|
||||||
extern sLibrary *lib_Read( char *filename );
|
extern sLibrary *lib_Read(char *filename);
|
||||||
extern BBOOL lib_Write( sLibrary *lib, char *filename );
|
extern BBOOL lib_Write(sLibrary * lib, char *filename);
|
||||||
extern sLibrary *lib_AddReplace( sLibrary *lib, char *filename );
|
extern sLibrary *lib_AddReplace(sLibrary * lib, char *filename);
|
||||||
extern void lib_Free( sLibrary *lib );
|
extern void lib_Free(sLibrary * lib);
|
||||||
extern sLibrary *lib_DeleteModule( sLibrary *lib, char *filename );
|
extern sLibrary *lib_DeleteModule(sLibrary * lib, char *filename);
|
||||||
extern sLibrary *lib_Find( sLibrary *lib, char *filename );
|
extern sLibrary *lib_Find(sLibrary * lib, char *filename);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
@@ -5,8 +5,7 @@
|
|||||||
|
|
||||||
#define MAXNAMELENGTH 256
|
#define MAXNAMELENGTH 256
|
||||||
|
|
||||||
struct LibraryWrapper
|
struct LibraryWrapper {
|
||||||
{
|
|
||||||
char tName[MAXNAMELENGTH];
|
char tName[MAXNAMELENGTH];
|
||||||
UWORD uwTime;
|
UWORD uwTime;
|
||||||
UWORD uwDate;
|
UWORD uwDate;
|
||||||
|
|||||||
@@ -4,305 +4,286 @@
|
|||||||
#include "types.h"
|
#include "types.h"
|
||||||
#include "libwrap.h"
|
#include "libwrap.h"
|
||||||
|
|
||||||
extern void fatalerror( char *s );
|
extern void fatalerror(char *s);
|
||||||
|
|
||||||
SLONG file_Length( FILE *f )
|
SLONG file_Length(FILE * f)
|
||||||
{
|
{
|
||||||
ULONG r,
|
ULONG r, p;
|
||||||
p;
|
|
||||||
|
|
||||||
p=ftell( f );
|
p = ftell(f);
|
||||||
fseek( f, 0, SEEK_END );
|
fseek(f, 0, SEEK_END);
|
||||||
r=ftell( f );
|
r = ftell(f);
|
||||||
fseek( f, p, SEEK_SET );
|
fseek(f, p, SEEK_SET);
|
||||||
|
|
||||||
return( r );
|
return (r);
|
||||||
}
|
}
|
||||||
|
|
||||||
SLONG file_ReadASCIIz( char *b, FILE *f )
|
SLONG file_ReadASCIIz(char *b, FILE * f)
|
||||||
{
|
{
|
||||||
SLONG r=0;
|
SLONG r = 0;
|
||||||
|
|
||||||
while( (*b++ = fgetc(f))!=0 )
|
while ((*b++ = fgetc(f)) != 0)
|
||||||
r+=1;
|
r += 1;
|
||||||
|
|
||||||
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);
|
||||||
|
|
||||||
fputc( 0, f );
|
fputc(0, f);
|
||||||
}
|
}
|
||||||
|
|
||||||
UWORD file_ReadWord( FILE *f )
|
UWORD file_ReadWord(FILE * f)
|
||||||
{
|
{
|
||||||
UWORD r;
|
UWORD r;
|
||||||
|
|
||||||
r =fgetc( f );
|
r = fgetc(f);
|
||||||
r|=fgetc( f )<<8;
|
r |= fgetc(f) << 8;
|
||||||
|
|
||||||
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;
|
||||||
|
|
||||||
r =fgetc( f );
|
r = fgetc(f);
|
||||||
r|=fgetc( f )<<8;
|
r |= fgetc(f) << 8;
|
||||||
r|=fgetc( f )<<16;
|
r |= fgetc(f) << 16;
|
||||||
r|=fgetc( f )<<24;
|
r |= fgetc(f) << 24;
|
||||||
|
|
||||||
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);
|
||||||
fputc( w>>16, f );
|
fputc(w >> 16, 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;
|
|
||||||
|
|
||||||
while( size>0 )
|
while (size > 0) {
|
||||||
{
|
if (l == NULL) {
|
||||||
if( l==NULL )
|
if ((l =
|
||||||
{
|
(sLibrary *) malloc(sizeof(sLibrary))) ==
|
||||||
if( (l=(sLibrary *)malloc(sizeof(sLibrary)))==NULL )
|
NULL)
|
||||||
fatalerror( "Out of memory" );
|
fatalerror("Out of memory");
|
||||||
|
|
||||||
first=l;
|
first = l;
|
||||||
}
|
} else {
|
||||||
else
|
if ((l->pNext =
|
||||||
{
|
(sLibrary *) malloc(sizeof(sLibrary))) ==
|
||||||
if( (l->pNext=(sLibrary *)malloc(sizeof(sLibrary)))==NULL )
|
NULL)
|
||||||
fatalerror( "Out of memory" );
|
fatalerror("Out of memory");
|
||||||
l=l->pNext;
|
l = l->pNext;
|
||||||
}
|
}
|
||||||
|
|
||||||
size-=file_ReadASCIIz( l->tName, f );
|
size -= file_ReadASCIIz(l->tName, f);
|
||||||
l->uwTime=file_ReadWord( f ); size-=2;
|
l->uwTime = file_ReadWord(f);
|
||||||
l->uwDate=file_ReadWord( f ); size-=2;
|
size -= 2;
|
||||||
l->nByteLength=file_ReadLong( f ); size-=4;
|
l->uwDate = file_ReadWord(f);
|
||||||
if( l->pData=(UBYTE *)malloc(l->nByteLength) )
|
size -= 2;
|
||||||
{
|
l->nByteLength = file_ReadLong(f);
|
||||||
fread( l->pData, sizeof(UBYTE), l->nByteLength, f );
|
size -= 4;
|
||||||
size-=l->nByteLength;
|
if (l->pData = (UBYTE *) malloc(l->nByteLength)) {
|
||||||
}
|
fread(l->pData, sizeof(UBYTE), l->nByteLength,
|
||||||
else
|
f);
|
||||||
fatalerror( "Out of memory" );
|
size -= l->nByteLength;
|
||||||
|
} else
|
||||||
|
fatalerror("Out of memory");
|
||||||
|
|
||||||
l->pNext=NULL;
|
l->pNext = NULL;
|
||||||
}
|
}
|
||||||
return( first );
|
return (first);
|
||||||
}
|
}
|
||||||
|
|
||||||
return( NULL );
|
return (NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
sLibrary *lib_Read( char *filename )
|
sLibrary *lib_Read(char *filename)
|
||||||
{
|
{
|
||||||
FILE *f;
|
FILE *f;
|
||||||
|
|
||||||
if( f=fopen(filename,"rb") )
|
if (f = fopen(filename, "rb")) {
|
||||||
{
|
|
||||||
SLONG size;
|
SLONG size;
|
||||||
char ID[5];
|
char ID[5];
|
||||||
|
|
||||||
size=file_Length( f );
|
size = file_Length(f);
|
||||||
if( size==0 )
|
if (size == 0) {
|
||||||
{
|
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;
|
||||||
|
|
||||||
if( strcmp(ID,"XLB0")==0 )
|
if (strcmp(ID, "XLB0") == 0) {
|
||||||
{
|
|
||||||
sLibrary *r;
|
sLibrary *r;
|
||||||
|
|
||||||
r=lib_ReadLib0( f, size );
|
r = lib_ReadLib0(f, size);
|
||||||
fclose( f );
|
fclose(f);
|
||||||
printf( "Library '%s' opened\n", filename );
|
printf("Library '%s' opened\n", filename);
|
||||||
return( r );
|
return (r);
|
||||||
|
} else {
|
||||||
|
fclose(f);
|
||||||
|
fatalerror("Not a valid xLib library");
|
||||||
|
return (NULL);
|
||||||
}
|
}
|
||||||
else
|
} else {
|
||||||
{
|
printf
|
||||||
fclose( f );
|
("Library '%s' not found, it will be created if necessary\n",
|
||||||
fatalerror( "Not a valid xLib library" );
|
filename);
|
||||||
return( NULL );
|
return (NULL);
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
printf( "Library '%s' not found, it will be created if necessary\n", filename );
|
|
||||||
return( NULL );
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
BBOOL lib_Write( sLibrary *lib, char *filename )
|
BBOOL lib_Write(sLibrary * lib, char *filename)
|
||||||
{
|
{
|
||||||
FILE *f;
|
FILE *f;
|
||||||
|
|
||||||
if( f=fopen(filename,"wb") )
|
if (f = fopen(filename, "wb")) {
|
||||||
{
|
fwrite("XLB0", sizeof(char), 4, f);
|
||||||
fwrite( "XLB0", sizeof(char), 4, f );
|
while (lib) {
|
||||||
while( lib )
|
file_WriteASCIIz(lib->tName, f);
|
||||||
{
|
file_WriteWord(lib->uwTime, f);
|
||||||
file_WriteASCIIz( lib->tName, f );
|
file_WriteWord(lib->uwDate, f);
|
||||||
file_WriteWord( lib->uwTime, f );
|
file_WriteLong(lib->nByteLength, f);
|
||||||
file_WriteWord( lib->uwDate, f );
|
fwrite(lib->pData, sizeof(UBYTE), lib->nByteLength, f);
|
||||||
file_WriteLong( lib->nByteLength, f );
|
lib = lib->pNext;
|
||||||
fwrite( lib->pData, sizeof(UBYTE), lib->nByteLength,f );
|
|
||||||
lib=lib->pNext;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fclose( f );
|
fclose(f);
|
||||||
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;
|
||||||
|
|
||||||
l=strlen( src )-1;
|
l = strlen(src) - 1;
|
||||||
while( (l>=0) && (src[l]!='\\') && (src[l]!='/') )
|
while ((l >= 0) && (src[l] != '\\') && (src[l] != '/'))
|
||||||
l-=1;
|
l -= 1;
|
||||||
|
|
||||||
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];
|
||||||
|
|
||||||
TruncateFileName( truncname, filename );
|
TruncateFileName(truncname, filename);
|
||||||
|
|
||||||
while( lib )
|
while (lib) {
|
||||||
{
|
if (strcmp(lib->tName, truncname) == 0)
|
||||||
if( strcmp(lib->tName,truncname)==0 )
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
lib=lib->pNext;
|
lib = lib->pNext;
|
||||||
}
|
}
|
||||||
|
|
||||||
return( lib );
|
return (lib);
|
||||||
}
|
}
|
||||||
|
|
||||||
sLibrary *lib_AddReplace( sLibrary *lib, char *filename )
|
sLibrary *lib_AddReplace(sLibrary * lib, char *filename)
|
||||||
{
|
{
|
||||||
FILE *f;
|
FILE *f;
|
||||||
|
|
||||||
if( f=fopen(filename,"rb") )
|
if (f = fopen(filename, "rb")) {
|
||||||
{
|
|
||||||
sLibrary *module;
|
sLibrary *module;
|
||||||
char truncname[MAXNAMELENGTH];
|
char truncname[MAXNAMELENGTH];
|
||||||
|
|
||||||
TruncateFileName( truncname, filename );
|
TruncateFileName(truncname, filename);
|
||||||
|
|
||||||
if( (module=lib_Find(lib,filename))==NULL )
|
if ((module = lib_Find(lib, filename)) == NULL) {
|
||||||
{
|
if (module = (sLibrary *) malloc(sizeof(sLibrary))) {
|
||||||
if( module=(sLibrary *)malloc(sizeof(sLibrary)) )
|
module->pNext = lib;
|
||||||
{
|
lib = module;
|
||||||
module->pNext=lib;
|
} else
|
||||||
lib=module;
|
fatalerror("Out of memory");
|
||||||
}
|
} else {
|
||||||
else
|
|
||||||
fatalerror( "Out of memory" );
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
/* Module already exists */
|
/* Module already exists */
|
||||||
free( module->pData );
|
free(module->pData);
|
||||||
}
|
}
|
||||||
|
|
||||||
module->nByteLength=file_Length( f );
|
module->nByteLength = file_Length(f);
|
||||||
strcpy( module->tName, truncname );
|
strcpy(module->tName, truncname);
|
||||||
if( module->pData=(UBYTE *)malloc(module->nByteLength) )
|
if (module->pData = (UBYTE *) malloc(module->nByteLength)) {
|
||||||
{
|
fread(module->pData, sizeof(UBYTE), module->nByteLength,
|
||||||
fread( module->pData, sizeof(UBYTE), module->nByteLength, f );
|
f);
|
||||||
}
|
}
|
||||||
|
|
||||||
printf( "Added module '%s'\n", truncname );
|
printf("Added module '%s'\n", truncname);
|
||||||
|
|
||||||
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,
|
sLibrary **pp, **first;
|
||||||
**first;
|
BBOOL found = 0;
|
||||||
BBOOL found=0;
|
|
||||||
|
|
||||||
pp=&lib;
|
pp = &lib;
|
||||||
first=pp;
|
first = pp;
|
||||||
|
|
||||||
TruncateFileName( truncname, filename );
|
TruncateFileName(truncname, filename);
|
||||||
while( (*pp) && (!found) )
|
while ((*pp) && (!found)) {
|
||||||
{
|
if (strcmp((*pp)->tName, truncname) == 0) {
|
||||||
if( strcmp((*pp)->tName,truncname)==0 )
|
|
||||||
{
|
|
||||||
sLibrary *t;
|
sLibrary *t;
|
||||||
|
|
||||||
t=*pp;
|
t = *pp;
|
||||||
|
|
||||||
if( t->pData )
|
if (t->pData)
|
||||||
free( t->pData );
|
free(t->pData);
|
||||||
|
|
||||||
*pp = t->pNext;
|
*pp = t->pNext;
|
||||||
|
|
||||||
free( t );
|
free(t);
|
||||||
found=1;
|
found = 1;
|
||||||
}
|
}
|
||||||
pp=&((*pp)->pNext);
|
pp = &((*pp)->pNext);
|
||||||
}
|
}
|
||||||
|
|
||||||
if( !found )
|
if (!found)
|
||||||
fatalerror( "Module not found" );
|
fatalerror("Module not found");
|
||||||
else
|
else
|
||||||
printf( "Module '%s' deleted from library\n", truncname );
|
printf("Module '%s' deleted from library\n", truncname);
|
||||||
|
|
||||||
return( *first );
|
return (*first);
|
||||||
}
|
}
|
||||||
|
|
||||||
void lib_Free( sLibrary *lib )
|
void lib_Free(sLibrary * lib)
|
||||||
{
|
{
|
||||||
while( lib )
|
while (lib) {
|
||||||
{
|
|
||||||
sLibrary *l;
|
sLibrary *l;
|
||||||
|
|
||||||
if( lib->pData )
|
if (lib->pData)
|
||||||
free( lib->pData );
|
free(lib->pData);
|
||||||
|
|
||||||
l=lib;
|
l = lib;
|
||||||
lib=lib->pNext;
|
lib = lib->pNext;
|
||||||
free( l );
|
free(l);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
125
src/lib/main.c
125
src/lib/main.c
@@ -17,10 +17,10 @@
|
|||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
void fatalerror( char *s )
|
void fatalerror(char *s)
|
||||||
{
|
{
|
||||||
printf( "*ERROR* : %s\n", s );
|
printf("*ERROR* : %s\n", s);
|
||||||
exit( 5 );
|
exit(5);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@@ -28,15 +28,15 @@ void fatalerror( char *s )
|
|||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
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);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@@ -44,100 +44,95 @@ void PrintUsage( void )
|
|||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
int main( int argc, char *argv[] )
|
int main(int argc, char *argv[])
|
||||||
{
|
{
|
||||||
SLONG argn=0;
|
SLONG argn = 0;
|
||||||
char *libname;
|
char *libname;
|
||||||
|
|
||||||
argc-=1;
|
argc -= 1;
|
||||||
argn+=1;
|
argn += 1;
|
||||||
|
|
||||||
if( argc>=2 )
|
if (argc >= 2) {
|
||||||
{
|
|
||||||
UBYTE command;
|
UBYTE command;
|
||||||
sLibrary *lib;
|
sLibrary *lib;
|
||||||
|
|
||||||
lib=lib_Read( libname=argv[argn++] );
|
lib = lib_Read(libname = argv[argn++]);
|
||||||
argc-=1;
|
argc -= 1;
|
||||||
|
|
||||||
if( strlen(argv[argn])==1 )
|
if (strlen(argv[argn]) == 1) {
|
||||||
{
|
command = argv[argn++][0];
|
||||||
command=argv[argn++][0];
|
argc -= 1;
|
||||||
argc-=1;
|
|
||||||
|
|
||||||
switch( tolower(command) )
|
switch (tolower(command)) {
|
||||||
{
|
|
||||||
case 'a':
|
case 'a':
|
||||||
while( argc )
|
while (argc) {
|
||||||
{
|
lib = lib_AddReplace(lib, argv[argn++]);
|
||||||
lib=lib_AddReplace( lib, argv[argn++] );
|
argc -= 1;
|
||||||
argc-=1;
|
|
||||||
}
|
}
|
||||||
lib_Write( lib, libname );
|
lib_Write(lib, libname);
|
||||||
lib_Free( lib );
|
lib_Free(lib);
|
||||||
break;
|
break;
|
||||||
case 'd':
|
case 'd':
|
||||||
while( argc )
|
while (argc) {
|
||||||
{
|
lib =
|
||||||
lib=lib_DeleteModule( lib, argv[argn++] );
|
lib_DeleteModule(lib, argv[argn++]);
|
||||||
argc-=1;
|
argc -= 1;
|
||||||
}
|
}
|
||||||
lib_Write( lib, libname );
|
lib_Write(lib, libname);
|
||||||
lib_Free( lib );
|
lib_Free(lib);
|
||||||
break;
|
break;
|
||||||
case 'l':
|
case 'l':
|
||||||
{
|
{
|
||||||
sLibrary *l;
|
sLibrary *l;
|
||||||
|
|
||||||
l=lib;
|
l = lib;
|
||||||
|
|
||||||
while( l )
|
while (l) {
|
||||||
{
|
printf("%10d %s\n",
|
||||||
printf( "%10d %s\n", l->nByteLength, l->tName );
|
l->nByteLength,
|
||||||
l=l->pNext;
|
l->tName);
|
||||||
|
l = l->pNext;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case 'x':
|
case 'x':
|
||||||
while( argc )
|
while (argc) {
|
||||||
{
|
|
||||||
sLibrary *l;
|
sLibrary *l;
|
||||||
|
|
||||||
l=lib_Find( lib, argv[argn] );
|
l = lib_Find(lib, argv[argn]);
|
||||||
if( l )
|
if (l) {
|
||||||
{
|
|
||||||
FILE *f;
|
FILE *f;
|
||||||
|
|
||||||
if( f=fopen(argv[argn],"wb") )
|
if (f = fopen(argv[argn], "wb")) {
|
||||||
{
|
fwrite(l->pData,
|
||||||
fwrite( l->pData, sizeof(UBYTE), l->nByteLength, f );
|
sizeof(UBYTE),
|
||||||
fclose( f );
|
l->nByteLength,
|
||||||
printf( "Extracted module '%s'\n", argv[argn] );
|
f);
|
||||||
}
|
fclose(f);
|
||||||
else
|
printf
|
||||||
fatalerror( "Unable to write module" );
|
("Extracted module '%s'\n",
|
||||||
}
|
argv[argn]);
|
||||||
else
|
} else
|
||||||
fatalerror( "Module not found" );
|
fatalerror
|
||||||
|
("Unable to write module");
|
||||||
|
} else
|
||||||
|
fatalerror("Module not found");
|
||||||
|
|
||||||
argn+=1;
|
argn += 1;
|
||||||
argc-=1;
|
argc -= 1;
|
||||||
}
|
}
|
||||||
lib_Free( lib );
|
lib_Free(lib);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
fatalerror( "Invalid command" );
|
fatalerror("Invalid command");
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
} else {
|
||||||
|
fatalerror("Invalid command");
|
||||||
}
|
}
|
||||||
else
|
} else
|
||||||
{
|
|
||||||
fatalerror( "Invalid command" );
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
PrintUsage();
|
PrintUsage();
|
||||||
|
|
||||||
return( 0 );
|
return (0);
|
||||||
}
|
}
|
||||||
@@ -5,8 +5,7 @@
|
|||||||
#include "symbol.h"
|
#include "symbol.h"
|
||||||
#include "assign.h"
|
#include "assign.h"
|
||||||
|
|
||||||
struct sFreeArea
|
struct sFreeArea {
|
||||||
{
|
|
||||||
SLONG nOrg;
|
SLONG nOrg;
|
||||||
SLONG nSize;
|
SLONG nSize;
|
||||||
struct sFreeArea *pPrev, *pNext;
|
struct sFreeArea *pPrev, *pNext;
|
||||||
@@ -18,236 +17,204 @@ 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;
|
||||||
|
|
||||||
r=0;
|
r = 0;
|
||||||
pArea=BankFree[bank];
|
pArea = BankFree[bank];
|
||||||
|
|
||||||
while( pArea )
|
while (pArea) {
|
||||||
{
|
r += pArea->nSize;
|
||||||
r+=pArea->nSize;
|
pArea = pArea->pNext;
|
||||||
pArea=pArea->pNext;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
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;
|
||||||
|
|
||||||
pArea=*ppArea;
|
pArea = *ppArea;
|
||||||
while( pArea )
|
while (pArea) {
|
||||||
{
|
if (org >= pArea->nOrg
|
||||||
if( org>=pArea->nOrg && (org+size-1)<=(pArea->nOrg+pArea->nSize-1) )
|
&& (org + size - 1) <= (pArea->nOrg + pArea->nSize - 1)) {
|
||||||
{
|
if (org == pArea->nOrg) {
|
||||||
if( org==pArea->nOrg )
|
pArea->nOrg += size;
|
||||||
{
|
pArea->nSize -= size;
|
||||||
pArea->nOrg+=size;
|
return (org);
|
||||||
pArea->nSize-=size;
|
} else {
|
||||||
return( org );
|
if ((org + size - 1) ==
|
||||||
}
|
(pArea->nOrg + pArea->nSize - 1)) {
|
||||||
else
|
pArea->nSize -= size;
|
||||||
{
|
return (org);
|
||||||
if( (org+size-1)==(pArea->nOrg+pArea->nSize-1) )
|
} else {
|
||||||
{
|
|
||||||
pArea->nSize-=size;
|
|
||||||
return( org );
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
struct sFreeArea *pNewArea;
|
struct sFreeArea *pNewArea;
|
||||||
|
|
||||||
if( (pNewArea=(struct sFreeArea *)malloc(sizeof(struct sFreeArea)))!=NULL )
|
if ((pNewArea =
|
||||||
{
|
(struct sFreeArea *)
|
||||||
*pNewArea=*pArea;
|
malloc(sizeof(struct sFreeArea)))
|
||||||
pNewArea->pPrev=pArea;
|
!= NULL) {
|
||||||
pArea->pNext=pNewArea;
|
*pNewArea = *pArea;
|
||||||
pArea->nSize=org-pArea->nOrg;
|
pNewArea->pPrev = pArea;
|
||||||
pNewArea->nOrg=org+size;
|
pArea->pNext = pNewArea;
|
||||||
pNewArea->nSize-=size+pArea->nSize;
|
pArea->nSize =
|
||||||
|
org - pArea->nOrg;
|
||||||
|
pNewArea->nOrg = org + size;
|
||||||
|
pNewArea->nSize -=
|
||||||
|
size + pArea->nSize;
|
||||||
|
|
||||||
return( org );
|
return (org);
|
||||||
}
|
} else
|
||||||
else
|
fatalerror("Out of memory!");
|
||||||
fatalerror( "Out of memory!" );
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
ppArea=&(pArea->pNext);
|
ppArea = &(pArea->pNext);
|
||||||
pArea=*ppArea;
|
pArea = *ppArea;
|
||||||
}
|
}
|
||||||
|
|
||||||
return( -1 );
|
return (-1);
|
||||||
}
|
}
|
||||||
|
|
||||||
SLONG area_AllocAbsCODEAnyBank( SLONG org, SLONG size )
|
SLONG area_AllocAbsCODEAnyBank(SLONG org, SLONG size)
|
||||||
{
|
{
|
||||||
SLONG i;
|
SLONG i;
|
||||||
|
|
||||||
for( i=1; i<=255; i+=1 )
|
for (i = 1; i <= 255; i += 1) {
|
||||||
{
|
if (area_AllocAbs(&BankFree[i], org, size) == org)
|
||||||
if( area_AllocAbs( &BankFree[i], org, size )==org )
|
return (i);
|
||||||
return( i );
|
|
||||||
}
|
}
|
||||||
|
|
||||||
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;
|
||||||
|
|
||||||
pArea=*ppArea;
|
pArea = *ppArea;
|
||||||
while( pArea )
|
while (pArea) {
|
||||||
{
|
if (size <= pArea->nSize) {
|
||||||
if( size<=pArea->nSize )
|
|
||||||
{
|
|
||||||
SLONG r;
|
SLONG r;
|
||||||
|
|
||||||
r=pArea->nOrg;
|
r = pArea->nOrg;
|
||||||
pArea->nOrg+=size;
|
pArea->nOrg += size;
|
||||||
pArea->nSize-=size;
|
pArea->nSize -= size;
|
||||||
|
|
||||||
return( r );
|
return (r);
|
||||||
}
|
}
|
||||||
ppArea=&(pArea->pNext);
|
ppArea = &(pArea->pNext);
|
||||||
pArea=*ppArea;
|
pArea = *ppArea;
|
||||||
}
|
}
|
||||||
|
|
||||||
return( -1 );
|
return (-1);
|
||||||
}
|
}
|
||||||
|
|
||||||
SLONG area_AllocCODEAnyBank( SLONG size )
|
SLONG area_AllocCODEAnyBank(SLONG size)
|
||||||
{
|
{
|
||||||
SLONG i, org;
|
SLONG i, org;
|
||||||
|
|
||||||
for( i=1; i<=255; i+=1 )
|
for (i = 1; i <= 255; i += 1) {
|
||||||
{
|
if ((org = area_Alloc(&BankFree[i], size)) != -1)
|
||||||
if( (org=area_Alloc(&BankFree[i],size))!=-1 )
|
return ((i << 16) | org);
|
||||||
return( (i<<16)|org );
|
|
||||||
}
|
}
|
||||||
|
|
||||||
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;
|
||||||
|
|
||||||
pSection=pSections;
|
pSection = pSections;
|
||||||
while( pSection )
|
while (pSection) {
|
||||||
{
|
if (pSection->oAssigned == 0 && pSection->Type == SECT_CODE) {
|
||||||
if( pSection->oAssigned==0 && pSection->Type==SECT_CODE )
|
if (pSection->nByteSize > nLargest) {
|
||||||
{
|
nLargest = pSection->nByteSize;
|
||||||
if( pSection->nByteSize > nLargest )
|
r = pSection;
|
||||||
{
|
|
||||||
nLargest=pSection->nByteSize;
|
|
||||||
r=pSection;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
pSection=pSection->pNext;
|
pSection = pSection->pNext;
|
||||||
}
|
}
|
||||||
return( r );
|
return (r);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void AssignCodeSections(void)
|
||||||
void AssignCodeSections( void )
|
|
||||||
{
|
{
|
||||||
struct sSection *pSection;
|
struct sSection *pSection;
|
||||||
|
|
||||||
while( pSection=FindLargestCode() )
|
while (pSection = FindLargestCode()) {
|
||||||
{
|
|
||||||
SLONG org;
|
SLONG org;
|
||||||
|
|
||||||
if( (org=area_AllocCODEAnyBank( pSection->nByteSize ))!=-1 )
|
if ((org = area_AllocCODEAnyBank(pSection->nByteSize)) != -1) {
|
||||||
{
|
pSection->nOrg = org & 0xFFFF;
|
||||||
pSection->nOrg=org&0xFFFF;
|
pSection->nBank = org >> 16;
|
||||||
pSection->nBank=org>>16;
|
pSection->oAssigned = 1;
|
||||||
pSection->oAssigned=1;
|
|
||||||
DOMAXBANK(pSection->nBank);
|
DOMAXBANK(pSection->nBank);
|
||||||
}
|
} else
|
||||||
else
|
fatalerror("Unable to place CODE section anywhere");
|
||||||
fatalerror( "Unable to place CODE section anywhere" );
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void GBROM_AssignSections( void )
|
void GBROM_AssignSections(void)
|
||||||
{
|
{
|
||||||
SLONG i;
|
SLONG i;
|
||||||
struct sSection *pSection;
|
struct sSection *pSection;
|
||||||
|
|
||||||
MaxBankUsed=0;
|
MaxBankUsed = 0;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Initialize the memory areas
|
* Initialize the memory areas
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
for( i=0; i<MAXBANKS; i+=1 )
|
for (i = 0; i < MAXBANKS; i += 1) {
|
||||||
{
|
if (BankFree[i] =
|
||||||
if( BankFree[i]=(struct sFreeArea *)malloc(sizeof(struct sFreeArea)) )
|
(struct sFreeArea *)malloc(sizeof(struct sFreeArea))) {
|
||||||
{
|
if (i == 0) {
|
||||||
if( i==0 )
|
BankFree[i]->nOrg = 0x0000;
|
||||||
{
|
if (options & OPT_SMALL) {
|
||||||
BankFree[i]->nOrg=0x0000;
|
BankFree[i]->nSize = 0x8000;
|
||||||
if( options&OPT_SMALL )
|
MaxAvail[i] = 0x8000;
|
||||||
{
|
} else {
|
||||||
BankFree[i]->nSize=0x8000;
|
BankFree[i]->nSize = 0x4000;
|
||||||
MaxAvail[i]=0x8000;
|
MaxAvail[i] = 0x4000;
|
||||||
}
|
}
|
||||||
else
|
} else if (i >= 1 && i <= 255) {
|
||||||
{
|
BankFree[i]->nOrg = 0x4000;
|
||||||
BankFree[i]->nSize=0x4000;
|
|
||||||
MaxAvail[i]=0x4000;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else if( i>=1 && i<=255 )
|
|
||||||
{
|
|
||||||
BankFree[i]->nOrg=0x4000;
|
|
||||||
/*
|
/*
|
||||||
* Now, this shouldn't really be necessary... but for good
|
* Now, this shouldn't really be necessary... but for good
|
||||||
* measure we'll do it anyway
|
* measure we'll do it anyway
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
if( options&OPT_SMALL )
|
if (options & OPT_SMALL) {
|
||||||
{
|
BankFree[i]->nSize = 0;
|
||||||
BankFree[i]->nSize=0;
|
MaxAvail[i] = 0;
|
||||||
MaxAvail[i]=0;
|
} else {
|
||||||
|
BankFree[i]->nSize = 0x4000;
|
||||||
|
MaxAvail[i] = 0x4000;
|
||||||
}
|
}
|
||||||
else
|
} else if (i == BANK_BSS) {
|
||||||
{
|
BankFree[i]->nOrg = 0xC000;
|
||||||
BankFree[i]->nSize=0x4000;
|
BankFree[i]->nSize = 0x2000;
|
||||||
MaxAvail[i]=0x4000;
|
MaxAvail[i] = 0x2000;
|
||||||
|
} else if (i == BANK_VRAM) {
|
||||||
|
BankFree[i]->nOrg = 0x8000;
|
||||||
|
BankFree[i]->nSize = 0x2000;
|
||||||
|
MaxAvail[i] = 0x2000;
|
||||||
|
} else if (i == BANK_HRAM) {
|
||||||
|
BankFree[i]->nOrg = 0xFF80;
|
||||||
|
BankFree[i]->nSize = 0x007F;
|
||||||
|
MaxAvail[i] = 0x007F;
|
||||||
}
|
}
|
||||||
}
|
BankFree[i]->pPrev = NULL;
|
||||||
else if( i==BANK_BSS )
|
BankFree[i]->pNext = NULL;
|
||||||
{
|
} else
|
||||||
BankFree[i]->nOrg =0xC000;
|
fatalerror("Out of memory!");
|
||||||
BankFree[i]->nSize=0x2000;
|
|
||||||
MaxAvail[i]=0x2000;
|
|
||||||
}
|
|
||||||
else if( i==BANK_VRAM )
|
|
||||||
{
|
|
||||||
BankFree[i]->nOrg =0x8000;
|
|
||||||
BankFree[i]->nSize=0x2000;
|
|
||||||
MaxAvail[i]=0x2000;
|
|
||||||
}
|
|
||||||
else if( i==BANK_HRAM )
|
|
||||||
{
|
|
||||||
BankFree[i]->nOrg =0xFF80;
|
|
||||||
BankFree[i]->nSize=0x007F;
|
|
||||||
MaxAvail[i]=0x007F;
|
|
||||||
}
|
|
||||||
BankFree[i]->pPrev=NULL;
|
|
||||||
BankFree[i]->pNext=NULL;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
fatalerror( "Out of memory!" );
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@@ -256,54 +223,63 @@ void GBROM_AssignSections( void )
|
|||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
pSection=pSections;
|
pSection = pSections;
|
||||||
while( pSection )
|
while (pSection) {
|
||||||
{
|
if ((pSection->nOrg != -1 || pSection->nBank != -1)
|
||||||
if( (pSection->nOrg!=-1 || pSection->nBank!=-1) && pSection->oAssigned==0 )
|
&& pSection->oAssigned == 0) {
|
||||||
{
|
|
||||||
/* User wants to have a say... */
|
/* User wants to have a say... */
|
||||||
|
|
||||||
switch( pSection->Type )
|
switch (pSection->Type) {
|
||||||
{
|
|
||||||
case SECT_BSS:
|
case SECT_BSS:
|
||||||
if( area_AllocAbs(&BankFree[BANK_BSS],pSection->nOrg,pSection->nByteSize)!=pSection->nOrg )
|
if (area_AllocAbs
|
||||||
{
|
(&BankFree[BANK_BSS], pSection->nOrg,
|
||||||
sprintf( temptext, "Unable to load fixed BSS section at $%X", pSection->nOrg );
|
pSection->nByteSize) != pSection->nOrg) {
|
||||||
fatalerror( temptext );
|
sprintf(temptext,
|
||||||
|
"Unable to load fixed BSS section at $%X",
|
||||||
|
pSection->nOrg);
|
||||||
|
fatalerror(temptext);
|
||||||
}
|
}
|
||||||
pSection->oAssigned=1;
|
pSection->oAssigned = 1;
|
||||||
pSection->nBank=BANK_BSS;
|
pSection->nBank = BANK_BSS;
|
||||||
break;
|
break;
|
||||||
case SECT_HRAM:
|
case SECT_HRAM:
|
||||||
if( area_AllocAbs(&BankFree[BANK_HRAM],pSection->nOrg,pSection->nByteSize)!=pSection->nOrg )
|
if (area_AllocAbs
|
||||||
{
|
(&BankFree[BANK_HRAM], pSection->nOrg,
|
||||||
sprintf( temptext, "Unable to load fixed HRAM section at $%X", pSection->nOrg );
|
pSection->nByteSize) != pSection->nOrg) {
|
||||||
fatalerror( temptext );
|
sprintf(temptext,
|
||||||
|
"Unable to load fixed HRAM section at $%X",
|
||||||
|
pSection->nOrg);
|
||||||
|
fatalerror(temptext);
|
||||||
}
|
}
|
||||||
pSection->oAssigned=1;
|
pSection->oAssigned = 1;
|
||||||
pSection->nBank=BANK_HRAM;
|
pSection->nBank = BANK_HRAM;
|
||||||
break;
|
break;
|
||||||
case SECT_VRAM:
|
case SECT_VRAM:
|
||||||
if( area_AllocAbs(&BankFree[BANK_VRAM],pSection->nOrg,pSection->nByteSize)!=pSection->nOrg )
|
if (area_AllocAbs
|
||||||
{
|
(&BankFree[BANK_VRAM], pSection->nOrg,
|
||||||
sprintf( temptext, "Unable to load fixed VRAM section at $%X", pSection->nOrg );
|
pSection->nByteSize) != pSection->nOrg) {
|
||||||
fatalerror( temptext );
|
sprintf(temptext,
|
||||||
|
"Unable to load fixed VRAM section at $%X",
|
||||||
|
pSection->nOrg);
|
||||||
|
fatalerror(temptext);
|
||||||
}
|
}
|
||||||
pSection->oAssigned=1;
|
pSection->oAssigned = 1;
|
||||||
pSection->nBank=BANK_VRAM;
|
pSection->nBank = BANK_VRAM;
|
||||||
break;
|
break;
|
||||||
case SECT_HOME:
|
case SECT_HOME:
|
||||||
if( area_AllocAbs(&BankFree[BANK_HOME],pSection->nOrg,pSection->nByteSize)!=pSection->nOrg )
|
if (area_AllocAbs
|
||||||
{
|
(&BankFree[BANK_HOME], pSection->nOrg,
|
||||||
sprintf( temptext, "Unable to load fixed HOME section at $%X", pSection->nOrg );
|
pSection->nByteSize) != pSection->nOrg) {
|
||||||
fatalerror( temptext );
|
sprintf(temptext,
|
||||||
|
"Unable to load fixed HOME section at $%X",
|
||||||
|
pSection->nOrg);
|
||||||
|
fatalerror(temptext);
|
||||||
}
|
}
|
||||||
pSection->oAssigned=1;
|
pSection->oAssigned = 1;
|
||||||
pSection->nBank=BANK_HOME;
|
pSection->nBank = BANK_HOME;
|
||||||
break;
|
break;
|
||||||
case SECT_CODE:
|
case SECT_CODE:
|
||||||
if( pSection->nBank==-1 )
|
if (pSection->nBank == -1) {
|
||||||
{
|
|
||||||
/*
|
/*
|
||||||
* User doesn't care which bank, so he must want to
|
* User doesn't care which bank, so he must want to
|
||||||
* decide which position within that bank.
|
* decide which position within that bank.
|
||||||
@@ -311,25 +287,20 @@ void GBROM_AssignSections( void )
|
|||||||
* hardcoded things are allocated
|
* hardcoded things are allocated
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
}
|
} else {
|
||||||
else
|
|
||||||
{
|
|
||||||
/*
|
/*
|
||||||
* User wants to decide which bank we use
|
* User wants to decide which bank we use
|
||||||
* Does he care about the position as well?
|
* Does he care about the position as well?
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
if( pSection->nOrg==-1 )
|
if (pSection->nOrg == -1) {
|
||||||
{
|
|
||||||
/*
|
/*
|
||||||
* Nope, any position will do
|
* Nope, any position will do
|
||||||
* Again, we'll do that later
|
* Again, we'll do that later
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
}
|
} else {
|
||||||
else
|
|
||||||
{
|
|
||||||
/*
|
/*
|
||||||
* How hardcore can you possibly get? Why does
|
* How hardcore can you possibly get? Why does
|
||||||
* he even USE this package? Yeah let's just
|
* he even USE this package? Yeah let's just
|
||||||
@@ -338,20 +309,35 @@ void GBROM_AssignSections( void )
|
|||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
if( pSection->nBank>=1 && pSection->nBank<=255 )
|
if (pSection->nBank >= 1
|
||||||
{
|
&& pSection->nBank <= 255) {
|
||||||
if( area_AllocAbs(&BankFree[pSection->nBank],pSection->nOrg,pSection->nByteSize)!=pSection->nOrg )
|
if (area_AllocAbs
|
||||||
{
|
(&BankFree
|
||||||
sprintf( temptext, "Unable to load fixed CODE/DATA section at $%X in bank $%02X", pSection->nOrg, pSection->nBank );
|
[pSection->nBank],
|
||||||
fatalerror( temptext );
|
pSection->nOrg,
|
||||||
|
pSection->
|
||||||
|
nByteSize) !=
|
||||||
|
pSection->nOrg) {
|
||||||
|
sprintf
|
||||||
|
(temptext,
|
||||||
|
"Unable to load fixed CODE/DATA section at $%X in bank $%02X",
|
||||||
|
pSection->
|
||||||
|
nOrg,
|
||||||
|
pSection->
|
||||||
|
nBank);
|
||||||
|
fatalerror
|
||||||
|
(temptext);
|
||||||
}
|
}
|
||||||
DOMAXBANK(pSection->nBank);
|
DOMAXBANK(pSection->
|
||||||
pSection->oAssigned=1;
|
nBank);
|
||||||
}
|
pSection->oAssigned = 1;
|
||||||
else
|
} else {
|
||||||
{
|
sprintf(temptext,
|
||||||
sprintf( temptext, "Unable to load fixed CODE/DATA section at $%X in bank $%02X", pSection->nOrg, pSection->nBank );
|
"Unable to load fixed CODE/DATA section at $%X in bank $%02X",
|
||||||
fatalerror( temptext );
|
pSection->nOrg,
|
||||||
|
pSection->
|
||||||
|
nBank);
|
||||||
|
fatalerror(temptext);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -359,7 +345,7 @@ void GBROM_AssignSections( void )
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
pSection=pSection->pNext;
|
pSection = pSection->pNext;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@@ -367,32 +353,31 @@ void GBROM_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->nOrg == -1 && pSection->nBank != -1) {
|
||||||
&& pSection->nOrg==-1
|
|
||||||
&& pSection->nBank!=-1 )
|
|
||||||
{
|
|
||||||
/* 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],pSection->nByteSize))==-1 )
|
area_Alloc(&BankFree[pSection->nBank],
|
||||||
{
|
pSection->nByteSize)) == -1) {
|
||||||
sprintf( temptext, "Unable to load fixed CODE/DATA section into bank $%02X", pSection->nBank );
|
sprintf(temptext,
|
||||||
fatalerror( temptext );
|
"Unable to load fixed CODE/DATA section into bank $%02X",
|
||||||
|
pSection->nBank);
|
||||||
|
fatalerror(temptext);
|
||||||
}
|
}
|
||||||
pSection->oAssigned=1;
|
pSection->oAssigned = 1;
|
||||||
DOMAXBANK(pSection->nBank);
|
DOMAXBANK(pSection->nBank);
|
||||||
}
|
} else {
|
||||||
else
|
sprintf(temptext,
|
||||||
{
|
"Unable to load fixed CODE/DATA section into bank $%02X",
|
||||||
sprintf( temptext, "Unable to load fixed CODE/DATA section into bank $%02X", pSection->nBank );
|
pSection->nBank);
|
||||||
fatalerror( temptext );
|
fatalerror(temptext);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
pSection=pSection->pNext;
|
pSection = pSection->pNext;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@@ -400,24 +385,25 @@ void GBROM_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->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=area_AllocAbsCODEAnyBank(pSection->nOrg,pSection->nByteSize))==-1 )
|
if ((pSection->nBank =
|
||||||
{
|
area_AllocAbsCODEAnyBank(pSection->nOrg,
|
||||||
sprintf( temptext, "Unable to load fixed CODE/DATA section at $%X into any bank", pSection->nOrg );
|
pSection->nByteSize)) ==
|
||||||
fatalerror( temptext );
|
-1) {
|
||||||
|
sprintf(temptext,
|
||||||
|
"Unable to load fixed CODE/DATA section at $%X into any bank",
|
||||||
|
pSection->nOrg);
|
||||||
|
fatalerror(temptext);
|
||||||
}
|
}
|
||||||
pSection->oAssigned=1;
|
pSection->oAssigned = 1;
|
||||||
DOMAXBANK(pSection->nBank);
|
DOMAXBANK(pSection->nBank);
|
||||||
}
|
}
|
||||||
pSection=pSection->pNext;
|
pSection = pSection->pNext;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@@ -426,106 +412,102 @@ void GBROM_AssignSections( void )
|
|||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
pSection=pSections;
|
pSection = pSections;
|
||||||
while( pSection )
|
while (pSection) {
|
||||||
{
|
if (pSection->oAssigned == 0) {
|
||||||
if( pSection->oAssigned==0 )
|
switch (pSection->Type) {
|
||||||
{
|
|
||||||
switch( pSection->Type )
|
|
||||||
{
|
|
||||||
case SECT_BSS:
|
case SECT_BSS:
|
||||||
if( (pSection->nOrg=area_Alloc(&BankFree[BANK_BSS],pSection->nByteSize))==-1 )
|
if ((pSection->nOrg =
|
||||||
{
|
area_Alloc(&BankFree[BANK_BSS],
|
||||||
fatalerror( "BSS section too large\n" );
|
pSection->nByteSize)) == -1) {
|
||||||
|
fatalerror("BSS section too large\n");
|
||||||
}
|
}
|
||||||
pSection->nBank=BANK_BSS;
|
pSection->nBank = BANK_BSS;
|
||||||
pSection->oAssigned=1;
|
pSection->oAssigned = 1;
|
||||||
break;
|
break;
|
||||||
case SECT_HRAM:
|
case SECT_HRAM:
|
||||||
if( (pSection->nOrg=area_Alloc(&BankFree[BANK_HRAM],pSection->nByteSize))==-1 )
|
if ((pSection->nOrg =
|
||||||
{
|
area_Alloc(&BankFree[BANK_HRAM],
|
||||||
fatalerror( "HRAM section too large" );
|
pSection->nByteSize)) == -1) {
|
||||||
|
fatalerror("HRAM section too large");
|
||||||
}
|
}
|
||||||
pSection->nBank=BANK_HRAM;
|
pSection->nBank = BANK_HRAM;
|
||||||
pSection->oAssigned=1;
|
pSection->oAssigned = 1;
|
||||||
break;
|
break;
|
||||||
case SECT_VRAM:
|
case SECT_VRAM:
|
||||||
if( (pSection->nOrg=area_Alloc(&BankFree[BANK_VRAM],pSection->nByteSize))==-1 )
|
if ((pSection->nOrg =
|
||||||
{
|
area_Alloc(&BankFree[BANK_VRAM],
|
||||||
fatalerror( "VRAM section too large" );
|
pSection->nByteSize)) == -1) {
|
||||||
|
fatalerror("VRAM section too large");
|
||||||
}
|
}
|
||||||
pSection->nBank=BANK_VRAM;
|
pSection->nBank = BANK_VRAM;
|
||||||
pSection->oAssigned=1;
|
pSection->oAssigned = 1;
|
||||||
break;
|
break;
|
||||||
case SECT_HOME:
|
case SECT_HOME:
|
||||||
if( (pSection->nOrg=area_Alloc(&BankFree[BANK_HOME],pSection->nByteSize))==-1 )
|
if ((pSection->nOrg =
|
||||||
{
|
area_Alloc(&BankFree[BANK_HOME],
|
||||||
fatalerror( "HOME section too large" );
|
pSection->nByteSize)) == -1) {
|
||||||
|
fatalerror("HOME section too large");
|
||||||
}
|
}
|
||||||
pSection->nBank=BANK_HOME;
|
pSection->nBank = BANK_HOME;
|
||||||
pSection->oAssigned=1;
|
pSection->oAssigned = 1;
|
||||||
break;
|
break;
|
||||||
case SECT_CODE:
|
case SECT_CODE:
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
fatalerror( "(INTERNAL) Unknown section type!" );
|
fatalerror("(INTERNAL) Unknown section type!");
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
pSection=pSection->pNext;
|
pSection = pSection->pNext;
|
||||||
}
|
}
|
||||||
|
|
||||||
AssignCodeSections();
|
AssignCodeSections();
|
||||||
}
|
}
|
||||||
|
|
||||||
void PSION2_AssignSections( void )
|
void PSION2_AssignSections(void)
|
||||||
{
|
{
|
||||||
struct sSection *pSection;
|
struct sSection *pSection;
|
||||||
|
|
||||||
if( BankFree[0]=(struct sFreeArea *)malloc(sizeof(struct sFreeArea)) )
|
if (BankFree[0] = (struct sFreeArea *)malloc(sizeof(struct sFreeArea))) {
|
||||||
{
|
BankFree[0]->nOrg = 0x0000;
|
||||||
BankFree[0]->nOrg=0x0000;
|
BankFree[0]->nSize = 0x10000;
|
||||||
BankFree[0]->nSize=0x10000;
|
MaxAvail[0] = 0x10000;
|
||||||
MaxAvail[0]=0x10000;
|
BankFree[0]->pPrev = NULL;
|
||||||
BankFree[0]->pPrev=NULL;
|
BankFree[0]->pNext = NULL;
|
||||||
BankFree[0]->pNext=NULL;
|
|
||||||
|
|
||||||
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;
|
BankFree[0]->nOrg += pSection->nByteSize;
|
||||||
BankFree[0]->nOrg+=pSection->nByteSize;
|
BankFree[0]->nSize -= pSection->nByteSize;
|
||||||
BankFree[0]->nSize-=pSection->nByteSize;
|
|
||||||
}
|
}
|
||||||
pSection=pSection->pNext;
|
pSection = pSection->pNext;
|
||||||
}
|
}
|
||||||
|
|
||||||
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;
|
BankFree[0]->nOrg += pSection->nByteSize;
|
||||||
BankFree[0]->nOrg+=pSection->nByteSize;
|
BankFree[0]->nSize -= pSection->nByteSize;
|
||||||
BankFree[0]->nSize-=pSection->nByteSize;
|
|
||||||
}
|
}
|
||||||
pSection=pSection->pNext;
|
pSection = pSection->pNext;
|
||||||
}
|
}
|
||||||
}
|
} else
|
||||||
else
|
fatalerror("Out of memory!");
|
||||||
fatalerror( "Out of memory!" );
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void AssignSections( void )
|
void AssignSections(void)
|
||||||
{
|
{
|
||||||
switch( outputtype )
|
switch (outputtype) {
|
||||||
{
|
|
||||||
case OUTPUT_GBROM:
|
case OUTPUT_GBROM:
|
||||||
GBROM_AssignSections();
|
GBROM_AssignSections();
|
||||||
break;
|
break;
|
||||||
@@ -535,36 +517,36 @@ void AssignSections( void )
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void CreateSymbolTable( void )
|
void CreateSymbolTable(void)
|
||||||
{
|
{
|
||||||
struct sSection *pSect;
|
struct sSection *pSect;
|
||||||
|
|
||||||
sym_Init();
|
sym_Init();
|
||||||
|
|
||||||
pSect=pSections;
|
pSect = pSections;
|
||||||
|
|
||||||
while( pSect )
|
while (pSect) {
|
||||||
{
|
|
||||||
SLONG i;
|
SLONG i;
|
||||||
|
|
||||||
i=pSect->nNumberOfSymbols;
|
i = pSect->nNumberOfSymbols;
|
||||||
|
|
||||||
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)
|
||||||
{
|
sym_CreateSymbol(pSect->tSymbols[i]->
|
||||||
if( pSect->tSymbols[i]->pSection==NULL )
|
pzName,
|
||||||
sym_CreateSymbol( pSect->tSymbols[i]->pzName,
|
pSect->tSymbols[i]->
|
||||||
pSect->tSymbols[i]->nOffset,
|
nOffset, -1);
|
||||||
-1 );
|
|
||||||
else
|
else
|
||||||
sym_CreateSymbol( pSect->tSymbols[i]->pzName,
|
sym_CreateSymbol(pSect->tSymbols[i]->
|
||||||
pSect->nOrg+pSect->tSymbols[i]->nOffset,
|
pzName,
|
||||||
pSect->nBank );
|
pSect->nOrg +
|
||||||
|
pSect->tSymbols[i]->
|
||||||
|
nOffset, pSect->nBank);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
pSect=pSect->pNext;
|
pSect = pSect->pNext;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -3,19 +3,18 @@
|
|||||||
|
|
||||||
#include "types.h"
|
#include "types.h"
|
||||||
|
|
||||||
enum eBankDefine
|
enum eBankDefine {
|
||||||
{
|
BANK_HOME = 0,
|
||||||
BANK_HOME=0,
|
BANK_BSS = 256,
|
||||||
BANK_BSS=256,
|
|
||||||
BANK_VRAM,
|
BANK_VRAM,
|
||||||
BANK_HRAM
|
BANK_HRAM
|
||||||
};
|
};
|
||||||
|
|
||||||
#define MAXBANKS 259
|
#define MAXBANKS 259
|
||||||
|
|
||||||
extern SLONG area_Avail( SLONG bank );
|
extern SLONG area_Avail(SLONG bank);
|
||||||
extern void AssignSections( void );
|
extern void AssignSections(void);
|
||||||
extern void CreateSymbolTable( void );
|
extern void CreateSymbolTable(void);
|
||||||
extern SLONG MaxBankUsed;
|
extern SLONG MaxBankUsed;
|
||||||
extern SLONG MaxAvail[MAXBANKS];
|
extern SLONG MaxAvail[MAXBANKS];
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
#ifndef LIBRARY_H
|
#ifndef LIBRARY_H
|
||||||
#define LIBRARY_H
|
#define LIBRARY_H
|
||||||
|
|
||||||
extern void AddNeededModules( void );
|
extern void AddNeededModules(void);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
@@ -3,19 +3,17 @@
|
|||||||
|
|
||||||
#include "types.h"
|
#include "types.h"
|
||||||
|
|
||||||
extern void PrintUsage( void );
|
extern void PrintUsage(void);
|
||||||
extern void fatalerror( char *s );
|
extern void fatalerror(char *s);
|
||||||
extern char temptext[1024];
|
extern char temptext[1024];
|
||||||
extern SLONG fillchar;
|
extern SLONG fillchar;
|
||||||
extern char smartlinkstartsymbol[256];
|
extern char smartlinkstartsymbol[256];
|
||||||
|
|
||||||
enum eOutputType
|
enum eOutputType {
|
||||||
{
|
|
||||||
OUTPUT_GBROM,
|
OUTPUT_GBROM,
|
||||||
OUTPUT_PSION2
|
OUTPUT_PSION2
|
||||||
};
|
};
|
||||||
|
|
||||||
extern enum eOutputType outputtype;
|
extern enum eOutputType outputtype;
|
||||||
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
@@ -1,11 +1,11 @@
|
|||||||
#ifndef MAPFILE_H
|
#ifndef MAPFILE_H
|
||||||
#define MAPFILE_H
|
#define MAPFILE_H
|
||||||
|
|
||||||
extern void SetMapfileName( char *name );
|
extern void SetMapfileName(char *name);
|
||||||
extern void SetSymfileName( char *name );
|
extern void SetSymfileName(char *name);
|
||||||
extern void CloseMapfile( void );
|
extern void CloseMapfile(void);
|
||||||
extern void MapfileWriteSection( struct sSection *pSect );
|
extern void MapfileWriteSection(struct sSection *pSect);
|
||||||
extern void MapfileInitBank( SLONG bank );
|
extern void MapfileInitBank(SLONG bank);
|
||||||
extern void MapfileCloseBank( SLONG slack );
|
extern void MapfileCloseBank(SLONG slack);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
@@ -11,9 +11,8 @@ extern SLONG options;
|
|||||||
#define OPT_SMALL 0x01
|
#define OPT_SMALL 0x01
|
||||||
#define OPT_SMART_C_LINK 0x02
|
#define OPT_SMART_C_LINK 0x02
|
||||||
|
|
||||||
enum eRpnData
|
enum eRpnData {
|
||||||
{
|
RPN_ADD = 0,
|
||||||
RPN_ADD=0,
|
|
||||||
RPN_SUB,
|
RPN_SUB,
|
||||||
RPN_MUL,
|
RPN_MUL,
|
||||||
RPN_DIV,
|
RPN_DIV,
|
||||||
@@ -47,12 +46,11 @@ enum eRpnData
|
|||||||
|
|
||||||
RPN_RANGECHECK,
|
RPN_RANGECHECK,
|
||||||
|
|
||||||
RPN_CONST=0x80,
|
RPN_CONST = 0x80,
|
||||||
RPN_SYM=0x81
|
RPN_SYM = 0x81
|
||||||
};
|
};
|
||||||
|
|
||||||
enum eSectionType
|
enum eSectionType {
|
||||||
{
|
|
||||||
SECT_BSS,
|
SECT_BSS,
|
||||||
SECT_VRAM,
|
SECT_VRAM,
|
||||||
SECT_CODE,
|
SECT_CODE,
|
||||||
@@ -60,8 +58,7 @@ enum eSectionType
|
|||||||
SECT_HRAM
|
SECT_HRAM
|
||||||
};
|
};
|
||||||
|
|
||||||
struct sSection
|
struct sSection {
|
||||||
{
|
|
||||||
SLONG nBank;
|
SLONG nBank;
|
||||||
SLONG nOrg;
|
SLONG nOrg;
|
||||||
BBOOL oAssigned;
|
BBOOL oAssigned;
|
||||||
@@ -75,15 +72,13 @@ struct sSection
|
|||||||
struct sSection *pNext;
|
struct sSection *pNext;
|
||||||
};
|
};
|
||||||
|
|
||||||
enum eSymbolType
|
enum eSymbolType {
|
||||||
{
|
|
||||||
SYM_LOCAL,
|
SYM_LOCAL,
|
||||||
SYM_IMPORT,
|
SYM_IMPORT,
|
||||||
SYM_EXPORT
|
SYM_EXPORT
|
||||||
};
|
};
|
||||||
|
|
||||||
struct sSymbol
|
struct sSymbol {
|
||||||
{
|
|
||||||
char *pzName;
|
char *pzName;
|
||||||
enum eSymbolType Type;
|
enum eSymbolType Type;
|
||||||
/* the following 3 items only valid when Type!=SYM_IMPORT */
|
/* the following 3 items only valid when Type!=SYM_IMPORT */
|
||||||
@@ -92,17 +87,15 @@ struct sSymbol
|
|||||||
SLONG nOffset;
|
SLONG nOffset;
|
||||||
};
|
};
|
||||||
|
|
||||||
enum ePatchType
|
enum ePatchType {
|
||||||
{
|
PATCH_BYTE = 0,
|
||||||
PATCH_BYTE=0,
|
|
||||||
PATCH_WORD_L,
|
PATCH_WORD_L,
|
||||||
PATCH_LONG_L,
|
PATCH_LONG_L,
|
||||||
PATCH_WORD_B,
|
PATCH_WORD_B,
|
||||||
PATCH_LONG_B
|
PATCH_LONG_B
|
||||||
};
|
};
|
||||||
|
|
||||||
struct sPatch
|
struct sPatch {
|
||||||
{
|
|
||||||
char *pzFilename;
|
char *pzFilename;
|
||||||
SLONG nLineNo;
|
SLONG nLineNo;
|
||||||
SLONG nOffset;
|
SLONG nOffset;
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
#ifndef OBJECT_H
|
#ifndef OBJECT_H
|
||||||
#define OBJECT_H
|
#define OBJECT_H
|
||||||
|
|
||||||
extern void obj_Readfile( char *tzObjectfile );
|
extern void obj_Readfile(char *tzObjectfile);
|
||||||
extern void lib_Readfile( char *tzLibfile );
|
extern void lib_Readfile(char *tzLibfile);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
@@ -1,7 +1,7 @@
|
|||||||
#ifndef OUTPUT_H
|
#ifndef OUTPUT_H
|
||||||
#define OUTPUT_H
|
#define OUTPUT_H
|
||||||
|
|
||||||
void out_Setname( char *tzOutputfile );
|
void out_Setname(char *tzOutputfile);
|
||||||
void Output( void );
|
void Output(void);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -3,7 +3,7 @@
|
|||||||
|
|
||||||
#include "types.h"
|
#include "types.h"
|
||||||
|
|
||||||
void Patch( void );
|
void Patch(void);
|
||||||
extern SLONG nPC;
|
extern SLONG nPC;
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
@@ -3,9 +3,9 @@
|
|||||||
|
|
||||||
#include "types.h"
|
#include "types.h"
|
||||||
|
|
||||||
void sym_Init( void );
|
void sym_Init(void);
|
||||||
void sym_CreateSymbol( char *tzName, SLONG nValue, SBYTE nBank );
|
void sym_CreateSymbol(char *tzName, SLONG nValue, SBYTE nBank);
|
||||||
SLONG sym_GetValue( char *tzName );
|
SLONG sym_GetValue(char *tzName);
|
||||||
SLONG sym_GetBank( char *tzName );
|
SLONG sym_GetBank(char *tzName);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
@@ -5,123 +5,114 @@
|
|||||||
#include "mylink.h"
|
#include "mylink.h"
|
||||||
#include "main.h"
|
#include "main.h"
|
||||||
|
|
||||||
static BBOOL symboldefined( char *name )
|
static BBOOL symboldefined(char *name)
|
||||||
{
|
{
|
||||||
struct sSection *pSect;
|
struct sSection *pSect;
|
||||||
|
|
||||||
pSect=pSections;
|
pSect = pSections;
|
||||||
|
|
||||||
while( pSect )
|
while (pSect) {
|
||||||
{
|
|
||||||
ULONG i;
|
ULONG i;
|
||||||
|
|
||||||
for( i=0; i<pSect->nNumberOfSymbols; i+=1 )
|
for (i = 0; i < pSect->nNumberOfSymbols; i += 1) {
|
||||||
{
|
if ((pSect->tSymbols[i]->Type == SYM_EXPORT)
|
||||||
if( (pSect->tSymbols[i]->Type==SYM_EXPORT)
|
|| ((pSect->tSymbols[i]->Type == SYM_LOCAL)
|
||||||
|| ( (pSect->tSymbols[i]->Type==SYM_LOCAL)
|
&& (pSect == pSect->tSymbols[i]->pSection))) {
|
||||||
&& (pSect==pSect->tSymbols[i]->pSection) ) )
|
if (strcmp(pSect->tSymbols[i]->pzName, name) ==
|
||||||
{
|
0)
|
||||||
if( strcmp(pSect->tSymbols[i]->pzName,name)==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;
|
||||||
|
|
||||||
ppLSect=&pLibSections;
|
ppLSect = &pLibSections;
|
||||||
|
|
||||||
while( *ppLSect )
|
while (*ppLSect) {
|
||||||
{
|
|
||||||
ULONG i;
|
ULONG i;
|
||||||
|
|
||||||
for( i=0; i<(*ppLSect)->nNumberOfSymbols; i+=1 )
|
for (i = 0; i < (*ppLSect)->nNumberOfSymbols; i += 1) {
|
||||||
{
|
if (((*ppLSect)->tSymbols[i]->Type == SYM_EXPORT)
|
||||||
if( ((*ppLSect)->tSymbols[i]->Type==SYM_EXPORT)
|
|| (((*ppLSect)->tSymbols[i]->Type == SYM_LOCAL)
|
||||||
|| ( ((*ppLSect)->tSymbols[i]->Type==SYM_LOCAL)
|
&& ((*ppLSect) ==
|
||||||
&& ((*ppLSect)==(*ppLSect)->tSymbols[i]->pSection) ) )
|
(*ppLSect)->tSymbols[i]->pSection))) {
|
||||||
{
|
if (strcmp
|
||||||
if( strcmp((*ppLSect)->tSymbols[i]->pzName,name)==0 )
|
((*ppLSect)->tSymbols[i]->pzName,
|
||||||
{
|
name) == 0) {
|
||||||
struct sSection **ppSect;
|
struct sSection **ppSect;
|
||||||
ppSect=&pSections;
|
ppSect = &pSections;
|
||||||
while( *ppSect )
|
while (*ppSect)
|
||||||
ppSect=&((*ppSect)->pNext);
|
ppSect = &((*ppSect)->pNext);
|
||||||
|
|
||||||
*ppSect = *ppLSect;
|
*ppSect = *ppLSect;
|
||||||
*ppLSect = (*ppLSect)->pNext;
|
*ppLSect = (*ppLSect)->pNext;
|
||||||
(*ppSect)->pNext = NULL;
|
(*ppSect)->pNext = NULL;
|
||||||
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;
|
||||||
|
|
||||||
if( (options&OPT_SMART_C_LINK)==0 )
|
if ((options & OPT_SMART_C_LINK) == 0) {
|
||||||
{
|
|
||||||
struct sSection **ppLSect;
|
struct sSection **ppLSect;
|
||||||
|
|
||||||
ppLSect=&pLibSections;
|
ppLSect = &pLibSections;
|
||||||
|
|
||||||
while( *ppLSect )
|
while (*ppLSect) {
|
||||||
{
|
|
||||||
struct sSection **ppSect;
|
struct sSection **ppSect;
|
||||||
ppSect=&pSections;
|
ppSect = &pSections;
|
||||||
while( *ppSect )
|
while (*ppSect)
|
||||||
ppSect=&((*ppSect)->pNext);
|
ppSect = &((*ppSect)->pNext);
|
||||||
|
|
||||||
*ppSect = *ppLSect;
|
*ppSect = *ppLSect;
|
||||||
*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'",
|
||||||
{
|
smartlinkstartsymbol);
|
||||||
sprintf( temptext, "Can't find start symbol '%s'", smartlinkstartsymbol );
|
fatalerror(temptext);
|
||||||
fatalerror( temptext );
|
} else
|
||||||
}
|
printf("Smart linking with symbol '%s'\n",
|
||||||
else
|
smartlinkstartsymbol);
|
||||||
printf( "Smart linking with symbol '%s'\n", smartlinkstartsymbol );
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pSect=pSections;
|
pSect = pSections;
|
||||||
|
|
||||||
while( pSect )
|
while (pSect) {
|
||||||
{
|
|
||||||
ULONG i;
|
ULONG i;
|
||||||
|
|
||||||
for( i=0; i<pSect->nNumberOfSymbols; i+=1 )
|
for (i = 0; i < pSect->nNumberOfSymbols; i += 1) {
|
||||||
{
|
if ((pSect->tSymbols[i]->Type == SYM_IMPORT)
|
||||||
if( (pSect->tSymbols[i]->Type==SYM_IMPORT)
|
|| (pSect->tSymbols[i]->Type == SYM_LOCAL)) {
|
||||||
|| (pSect->tSymbols[i]->Type==SYM_LOCAL) )
|
if (!symboldefined(pSect->tSymbols[i]->pzName)) {
|
||||||
{
|
addmodulecontaining(pSect->tSymbols[i]->
|
||||||
if( !symboldefined(pSect->tSymbols[i]->pzName) )
|
pzName);
|
||||||
{
|
|
||||||
addmodulecontaining( pSect->tSymbols[i]->pzName );
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
pSect=pSect->pNext;
|
pSect = pSect->pNext;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
184
src/link/main.c
184
src/link/main.c
@@ -17,17 +17,16 @@
|
|||||||
#define strcmpi strcasecmp
|
#define strcmpi strcasecmp
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
enum eBlockType
|
enum eBlockType {
|
||||||
{
|
|
||||||
BLOCK_COMMENT,
|
BLOCK_COMMENT,
|
||||||
BLOCK_OBJECTS,
|
BLOCK_OBJECTS,
|
||||||
BLOCK_LIBRARIES,
|
BLOCK_LIBRARIES,
|
||||||
BLOCK_OUTPUT
|
BLOCK_OUTPUT
|
||||||
};
|
};
|
||||||
|
|
||||||
SLONG options=0;
|
SLONG options = 0;
|
||||||
SLONG fillchar=-1;
|
SLONG fillchar = -1;
|
||||||
enum eOutputType outputtype=OUTPUT_GBROM;
|
enum eOutputType outputtype = OUTPUT_GBROM;
|
||||||
char temptext[1024];
|
char temptext[1024];
|
||||||
char smartlinkstartsymbol[256];
|
char smartlinkstartsymbol[256];
|
||||||
|
|
||||||
@@ -36,10 +35,10 @@ 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);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@@ -47,21 +46,20 @@ void fatalerror( char *s )
|
|||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
void PrintUsage( void )
|
void PrintUsage(void)
|
||||||
{
|
{
|
||||||
printf( "xLink v" LINK_VERSION " (part of ASMotor " ASMOTOR_VERSION ")\n\n"
|
printf("xLink v" LINK_VERSION " (part of ASMotor " ASMOTOR_VERSION
|
||||||
"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\t\tOutput target\n" "\t\t-tg\tGameboy ROM image(default)\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);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@@ -69,62 +67,58 @@ void PrintUsage( void )
|
|||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
void ProcessLinkfile( char *tzLinkfile )
|
void ProcessLinkfile(char *tzLinkfile)
|
||||||
{
|
{
|
||||||
FILE *pLinkfile;
|
FILE *pLinkfile;
|
||||||
enum eBlockType CurrentBlock=BLOCK_COMMENT;
|
enum eBlockType CurrentBlock = BLOCK_COMMENT;
|
||||||
|
|
||||||
if( pLinkfile=fopen(tzLinkfile,"rt") )
|
if (pLinkfile = fopen(tzLinkfile, "rt")) {
|
||||||
{
|
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)==0 )
|
else if (strcmpi("[libraries]", tzLine)
|
||||||
CurrentBlock=BLOCK_LIBRARIES;
|
== 0)
|
||||||
else if( strcmpi("[comment]",tzLine)==0 )
|
CurrentBlock = BLOCK_LIBRARIES;
|
||||||
CurrentBlock=BLOCK_COMMENT;
|
else if (strcmpi("[comment]", tzLine) ==
|
||||||
else
|
0)
|
||||||
{
|
CurrentBlock = BLOCK_COMMENT;
|
||||||
fclose( pLinkfile );
|
else {
|
||||||
sprintf( temptext, "Unknown block '%s'\n", tzLine );
|
fclose(pLinkfile);
|
||||||
fatalerror( temptext );
|
sprintf(temptext,
|
||||||
|
"Unknown block '%s'\n",
|
||||||
|
tzLine);
|
||||||
|
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;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
fclose( pLinkfile );
|
fclose(pLinkfile);
|
||||||
}
|
} else {
|
||||||
else
|
sprintf(temptext, "Unable to find linkfile '%s'\n", tzLinkfile);
|
||||||
{
|
fatalerror(temptext);
|
||||||
sprintf( temptext, "Unable to find linkfile '%s'\n", tzLinkfile );
|
|
||||||
fatalerror( temptext );
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -134,97 +128,89 @@ void ProcessLinkfile( char *tzLinkfile )
|
|||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
int main( int argc, char *argv[] )
|
int main(int argc, char *argv[])
|
||||||
{
|
{
|
||||||
SLONG argn=0;
|
SLONG argn = 0;
|
||||||
|
|
||||||
argc-=1;
|
argc -= 1;
|
||||||
argn+=1;
|
argn += 1;
|
||||||
|
|
||||||
if( argc==0 )
|
if (argc == 0)
|
||||||
PrintUsage();
|
PrintUsage();
|
||||||
|
|
||||||
while( *argv[argn]=='-' )
|
while (*argv[argn] == '-') {
|
||||||
{
|
|
||||||
char opt;
|
char opt;
|
||||||
argc-=1;
|
argc -= 1;
|
||||||
switch( opt=argv[argn++][1] )
|
switch (opt = argv[argn++][1]) {
|
||||||
{
|
|
||||||
case '?':
|
case '?':
|
||||||
case 'h':
|
case 'h':
|
||||||
PrintUsage();
|
PrintUsage();
|
||||||
break;
|
break;
|
||||||
case 'm':
|
case 'm':
|
||||||
SetMapfileName( argv[argn-1]+2 );
|
SetMapfileName(argv[argn - 1] + 2);
|
||||||
break;
|
break;
|
||||||
case 'n':
|
case 'n':
|
||||||
SetSymfileName( argv[argn-1]+2 );
|
SetSymfileName(argv[argn - 1] + 2);
|
||||||
break;
|
break;
|
||||||
case 't':
|
case 't':
|
||||||
switch( opt=argv[argn-1][2] )
|
switch (opt = argv[argn - 1][2]) {
|
||||||
{
|
|
||||||
case 'g':
|
case 'g':
|
||||||
outputtype=OUTPUT_GBROM;
|
outputtype = OUTPUT_GBROM;
|
||||||
break;
|
break;
|
||||||
case 's':
|
case 's':
|
||||||
outputtype=OUTPUT_GBROM;
|
outputtype = OUTPUT_GBROM;
|
||||||
options|=OPT_SMALL;
|
options |= OPT_SMALL;
|
||||||
break;
|
break;
|
||||||
case 'p':
|
case 'p':
|
||||||
outputtype=OUTPUT_PSION2;
|
outputtype = OUTPUT_PSION2;
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
sprintf( temptext, "Unknown option 't%c'\n", opt );
|
sprintf(temptext, "Unknown option 't%c'\n",
|
||||||
fatalerror( temptext );
|
opt);
|
||||||
|
fatalerror(temptext);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case 'z':
|
case 'z':
|
||||||
if( strlen(argv[argn-1]+2)<=2 )
|
if (strlen(argv[argn - 1] + 2) <= 2) {
|
||||||
{
|
if (strcmp(argv[argn - 1] + 2, "?") == 0) {
|
||||||
if( strcmp(argv[argn-1]+2,"?")==0 )
|
fillchar = -1;
|
||||||
{
|
} else {
|
||||||
fillchar=-1;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
int result;
|
int result;
|
||||||
|
|
||||||
result=sscanf( argv[argn-1]+2, "%x", &fillchar );
|
result =
|
||||||
if( !((result==EOF) || (result==1)) )
|
sscanf(argv[argn - 1] + 2, "%x",
|
||||||
{
|
&fillchar);
|
||||||
fatalerror("Invalid argument for option 'z'\n" );
|
if (!((result == EOF) || (result == 1))) {
|
||||||
|
fatalerror
|
||||||
|
("Invalid argument for option 'z'\n");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
} else {
|
||||||
else
|
fatalerror("Invalid argument for option 'z'\n");
|
||||||
{
|
|
||||||
fatalerror("Invalid argument for option 'z'\n" );
|
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case 's':
|
case 's':
|
||||||
options|=OPT_SMART_C_LINK;
|
options |= OPT_SMART_C_LINK;
|
||||||
strcpy( smartlinkstartsymbol, argv[argn-1]+2 );
|
strcpy(smartlinkstartsymbol, argv[argn - 1] + 2);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
sprintf( temptext, "Unknown option '%c'\n", opt );
|
sprintf(temptext, "Unknown option '%c'\n", opt);
|
||||||
fatalerror( temptext );
|
fatalerror(temptext);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if( argc==1 )
|
if (argc == 1) {
|
||||||
{
|
ProcessLinkfile(argv[argn++]);
|
||||||
ProcessLinkfile( argv[argn++] );
|
|
||||||
AddNeededModules();
|
AddNeededModules();
|
||||||
AssignSections();
|
AssignSections();
|
||||||
CreateSymbolTable();
|
CreateSymbolTable();
|
||||||
Patch();
|
Patch();
|
||||||
Output();
|
Output();
|
||||||
CloseMapfile();
|
CloseMapfile();
|
||||||
}
|
} else
|
||||||
else
|
|
||||||
PrintUsage();
|
PrintUsage();
|
||||||
|
|
||||||
return( 0 );
|
return (0);
|
||||||
}
|
}
|
||||||
@@ -7,88 +7,84 @@
|
|||||||
#include "mylink.h"
|
#include "mylink.h"
|
||||||
#include "assign.h"
|
#include "assign.h"
|
||||||
|
|
||||||
FILE *mf=NULL;
|
FILE *mf = NULL;
|
||||||
FILE *sf=NULL;
|
FILE *sf = NULL;
|
||||||
SLONG currentbank=0;
|
SLONG currentbank = 0;
|
||||||
SLONG sfbank;
|
SLONG sfbank;
|
||||||
|
|
||||||
void SetMapfileName( char *name )
|
void SetMapfileName(char *name)
|
||||||
{
|
{
|
||||||
if( mf=fopen(name,"wt") )
|
if (mf = fopen(name, "wt"))
|
||||||
return;
|
return;
|
||||||
else
|
else
|
||||||
fatalerror( "Unable to open mapfile for writing" );
|
fatalerror("Unable to open mapfile for writing");
|
||||||
}
|
}
|
||||||
|
|
||||||
void SetSymfileName( char *name )
|
void SetSymfileName(char *name)
|
||||||
{
|
{
|
||||||
if( sf=fopen(name,"wt") )
|
if (sf = fopen(name, "wt")) {
|
||||||
{
|
fprintf(sf, ";File generated by xLink v" LINK_VERSION "\n\n");
|
||||||
fprintf( sf, ";File generated by xLink v" LINK_VERSION "\n\n" );
|
|
||||||
return;
|
return;
|
||||||
}
|
} else
|
||||||
else
|
fatalerror("Unable to open symfile for writing");
|
||||||
fatalerror( "Unable to open symfile for writing" );
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void CloseMapfile( void )
|
void CloseMapfile(void)
|
||||||
{
|
{
|
||||||
if( mf )
|
if (mf) {
|
||||||
{
|
fclose(mf);
|
||||||
fclose( mf );
|
mf = NULL;
|
||||||
mf=NULL;
|
|
||||||
}
|
}
|
||||||
if( sf )
|
if (sf) {
|
||||||
{
|
fclose(sf);
|
||||||
fclose( sf );
|
sf = NULL;
|
||||||
sf=NULL;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void MapfileInitBank( SLONG bank )
|
void MapfileInitBank(SLONG bank)
|
||||||
{
|
{
|
||||||
if( mf )
|
if (mf) {
|
||||||
{
|
currentbank = bank;
|
||||||
currentbank=bank;
|
if (bank == 0)
|
||||||
if( bank==0 )
|
fprintf(mf, "Bank #0 (HOME):\n");
|
||||||
fprintf( mf, "Bank #0 (HOME):\n" );
|
else if (bank <= 255)
|
||||||
else if( bank<=255 )
|
fprintf(mf, "Bank #%d:\n", bank);
|
||||||
fprintf( mf, "Bank #%d:\n", bank );
|
else if (bank == BANK_BSS)
|
||||||
else if( bank==BANK_BSS )
|
fprintf(mf, "BSS:\n");
|
||||||
fprintf( mf, "BSS:\n" );
|
else if (bank == BANK_HRAM)
|
||||||
else if( bank==BANK_HRAM )
|
fprintf(mf, "HRAM:\n");
|
||||||
fprintf( mf, "HRAM:\n" );
|
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) {
|
||||||
{
|
|
||||||
SLONG i;
|
SLONG i;
|
||||||
|
|
||||||
fprintf( mf, " SECTION: $%04X-$%04X ($%04X bytes)\n", pSect->nOrg, pSect->nOrg+pSect->nByteSize-1, pSect->nByteSize );
|
fprintf(mf, " SECTION: $%04X-$%04X ($%04X bytes)\n",
|
||||||
|
pSect->nOrg, pSect->nOrg + pSect->nByteSize - 1,
|
||||||
|
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) && (pSym->Type!=SYM_IMPORT) )
|
if ((pSym->pSection == pSect)
|
||||||
{
|
&& (pSym->Type != SYM_IMPORT)) {
|
||||||
if( mf )
|
if (mf) {
|
||||||
{
|
fprintf(mf, " $%04X = %s\n",
|
||||||
fprintf( mf, " $%04X = %s\n", pSym->nOffset+pSect->nOrg, pSym->pzName );
|
pSym->nOffset + pSect->nOrg,
|
||||||
|
pSym->pzName);
|
||||||
}
|
}
|
||||||
if( sf )
|
if (sf) {
|
||||||
{
|
fprintf(sf, "%02X:%04X %s\n", sfbank,
|
||||||
fprintf( sf, "%02X:%04X %s\n", sfbank, pSym->nOffset+pSect->nOrg, pSym->pzName );
|
pSym->nOffset + pSect->nOrg,
|
||||||
|
pSym->pzName);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -96,13 +92,12 @@ void MapfileWriteSection( struct sSection *pSect )
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void MapfileCloseBank( SLONG slack )
|
void MapfileCloseBank(SLONG slack)
|
||||||
{
|
{
|
||||||
if( mf )
|
if (mf) {
|
||||||
{
|
if (slack == MaxAvail[currentbank])
|
||||||
if( slack==MaxAvail[currentbank] )
|
fprintf(mf, " EMPTY\n\n");
|
||||||
fprintf( mf, " EMPTY\n\n" );
|
|
||||||
else
|
else
|
||||||
fprintf( mf, " SLACK: $%04X bytes\n\n", slack );
|
fprintf(mf, " SLACK: $%04X bytes\n\n", slack);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -11,37 +11,36 @@
|
|||||||
#include "main.h"
|
#include "main.h"
|
||||||
|
|
||||||
struct sSymbol **tSymbols;
|
struct sSymbol **tSymbols;
|
||||||
struct sSection *pSections=NULL;
|
struct sSection *pSections = NULL;
|
||||||
struct sSection *pLibSections=NULL;
|
struct sSection *pLibSections = NULL;
|
||||||
UBYTE dummymem;
|
UBYTE dummymem;
|
||||||
BBOOL oReadLib=0;
|
BBOOL oReadLib = 0;
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* The usual byte order stuff
|
* The usual byte order stuff
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
SLONG readlong( FILE *f )
|
SLONG readlong(FILE * f)
|
||||||
{
|
{
|
||||||
SLONG r;
|
SLONG r;
|
||||||
|
|
||||||
r =fgetc(f);
|
r = fgetc(f);
|
||||||
r|=fgetc(f)<<8;
|
r |= fgetc(f) << 8;
|
||||||
r|=fgetc(f)<<16;
|
r |= fgetc(f) << 16;
|
||||||
r|=fgetc(f)<<24;
|
r |= fgetc(f) << 24;
|
||||||
|
|
||||||
return( r );
|
return (r);
|
||||||
}
|
}
|
||||||
|
|
||||||
UWORD readword( FILE *f )
|
UWORD readword(FILE * f)
|
||||||
{
|
{
|
||||||
UWORD r;
|
UWORD r;
|
||||||
|
|
||||||
r =fgetc(f);
|
r = fgetc(f);
|
||||||
r|=fgetc(f)<<8;
|
r |= fgetc(f) << 8;
|
||||||
|
|
||||||
return( r );
|
return (r);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@@ -49,46 +48,42 @@ UWORD readword( FILE *f )
|
|||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
SLONG readasciiz( char *s, FILE *f )
|
SLONG readasciiz(char *s, FILE * f)
|
||||||
{
|
{
|
||||||
SLONG r=0;
|
SLONG r = 0;
|
||||||
|
|
||||||
while( ((*s++)=fgetc(f))!=0 )
|
while (((*s++) = fgetc(f)) != 0)
|
||||||
r+=1;
|
r += 1;
|
||||||
|
|
||||||
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;
|
||||||
|
|
||||||
if( oReadLib==1 )
|
if (oReadLib == 1)
|
||||||
ppSections=&pLibSections;
|
ppSections = &pLibSections;
|
||||||
else
|
else
|
||||||
ppSections=&pSections;
|
ppSections = &pSections;
|
||||||
|
|
||||||
while( *ppSections )
|
while (*ppSections)
|
||||||
ppSections=&((*ppSections)->pNext);
|
ppSections = &((*ppSections)->pNext);
|
||||||
|
|
||||||
if( (*ppSections)=(struct sSection *)malloc(sizeof(struct sSection)) )
|
if ((*ppSections) = (struct sSection *)malloc(sizeof(struct sSection))) {
|
||||||
{
|
(*ppSections)->tSymbols = tSymbols;
|
||||||
(*ppSections)->tSymbols=tSymbols;
|
(*ppSections)->pNext = NULL;
|
||||||
(*ppSections)->pNext=NULL;
|
(*ppSections)->pPatches = NULL;
|
||||||
(*ppSections)->pPatches=NULL;
|
(*ppSections)->oAssigned = 0;
|
||||||
(*ppSections)->oAssigned=0;
|
return (*ppSections);
|
||||||
return( *ppSections );
|
} else {
|
||||||
}
|
fatalerror("Out of memory!");
|
||||||
else
|
return (NULL);
|
||||||
{
|
|
||||||
fatalerror( "Out of memory!" );
|
|
||||||
return( NULL );
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -97,31 +92,27 @@ struct sSection *AllocSection( void )
|
|||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
struct sSymbol *obj_ReadSymbol( FILE *f )
|
struct sSymbol *obj_ReadSymbol(FILE * f)
|
||||||
{
|
{
|
||||||
char s[256];
|
char s[256];
|
||||||
struct sSymbol *pSym;
|
struct sSymbol *pSym;
|
||||||
|
|
||||||
if( pSym=(struct sSymbol *)malloc(sizeof(struct sSymbol)) )
|
if (pSym = (struct sSymbol *)malloc(sizeof(struct sSymbol))) {
|
||||||
{
|
readasciiz(s, f);
|
||||||
readasciiz( s, f );
|
if (pSym->pzName = (char *)malloc(strlen(s) + 1)) {
|
||||||
if( pSym->pzName=(char *)malloc(strlen(s)+1) )
|
strcpy(pSym->pzName, s);
|
||||||
{
|
if ((pSym->Type =
|
||||||
strcpy( pSym->pzName, s );
|
(enum eSymbolType)fgetc(f)) != SYM_IMPORT) {
|
||||||
if( (pSym->Type=(enum eSymbolType)fgetc(f))!=SYM_IMPORT )
|
pSym->nSectionID = readlong(f);
|
||||||
{
|
pSym->nOffset = readlong(f);
|
||||||
pSym->nSectionID=readlong(f);
|
|
||||||
pSym->nOffset=readlong(f);
|
|
||||||
}
|
}
|
||||||
return( pSym );
|
return (pSym);
|
||||||
}
|
} else
|
||||||
else
|
fatalerror("Out of memory!");
|
||||||
fatalerror( "Out of memory!" );
|
} else
|
||||||
}
|
fatalerror("Out of memory!");
|
||||||
else
|
|
||||||
fatalerror( "Out of memory!" );
|
|
||||||
|
|
||||||
return( NULL );
|
return (NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@@ -129,124 +120,135 @@ struct sSymbol *obj_ReadSymbol( FILE *f )
|
|||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
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;
|
||||||
|
|
||||||
/* does the user want the -s mode? */
|
/* does the user want the -s mode? */
|
||||||
|
|
||||||
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...
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
if( pSection->nByteSize )
|
if (pSection->nByteSize) {
|
||||||
{
|
if (pSection->pData =
|
||||||
if( pSection->pData=(UBYTE *)malloc(pSection->nByteSize) )
|
(UBYTE *) malloc(pSection->nByteSize)) {
|
||||||
{
|
|
||||||
SLONG nNumberOfPatches;
|
SLONG nNumberOfPatches;
|
||||||
struct sPatch **ppPatch, *pPatch;
|
struct sPatch **ppPatch, *pPatch;
|
||||||
char s[256];
|
char s[256];
|
||||||
|
|
||||||
fread( pSection->pData, sizeof(UBYTE), pSection->nByteSize, f );
|
fread(pSection->pData, sizeof(UBYTE),
|
||||||
nNumberOfPatches=readlong(f);
|
pSection->nByteSize, f);
|
||||||
ppPatch=&pSection->pPatches;
|
nNumberOfPatches = readlong(f);
|
||||||
|
ppPatch = &pSection->pPatches;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* And patches...
|
* And patches...
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
while( nNumberOfPatches-- )
|
while (nNumberOfPatches--) {
|
||||||
{
|
if (pPatch =
|
||||||
if( pPatch=(struct sPatch *)malloc(sizeof(struct sPatch)) )
|
(struct sPatch *)
|
||||||
{
|
malloc(sizeof(struct sPatch))) {
|
||||||
*ppPatch=pPatch;
|
*ppPatch = pPatch;
|
||||||
readasciiz( s, f );
|
readasciiz(s, f);
|
||||||
if( pPatch->pzFilename=(char *)malloc(strlen(s)+1) )
|
if (pPatch->pzFilename =
|
||||||
{
|
(char *)malloc(strlen(s) +
|
||||||
strcpy( pPatch->pzFilename, s );
|
1)) {
|
||||||
pPatch->nLineNo=readlong( f );
|
strcpy(pPatch->
|
||||||
pPatch->nOffset=readlong( f );
|
pzFilename, s);
|
||||||
pPatch->Type=(enum ePatchType)fgetc( f );
|
pPatch->nLineNo =
|
||||||
if( (pPatch->nRPNSize=readlong(f))>0 )
|
readlong(f);
|
||||||
{
|
pPatch->nOffset =
|
||||||
if( pPatch->pRPN=(UBYTE *)malloc(pPatch->nRPNSize) )
|
readlong(f);
|
||||||
fread( pPatch->pRPN, sizeof(UBYTE), pPatch->nRPNSize, f );
|
pPatch->Type =
|
||||||
|
(enum ePatchType)
|
||||||
|
fgetc(f);
|
||||||
|
if ((pPatch->nRPNSize =
|
||||||
|
readlong(f)) > 0) {
|
||||||
|
if (pPatch->
|
||||||
|
pRPN =
|
||||||
|
(UBYTE *)
|
||||||
|
malloc
|
||||||
|
(pPatch->
|
||||||
|
nRPNSize))
|
||||||
|
fread
|
||||||
|
(pPatch->
|
||||||
|
pRPN,
|
||||||
|
sizeof
|
||||||
|
(UBYTE),
|
||||||
|
pPatch->
|
||||||
|
nRPNSize,
|
||||||
|
f);
|
||||||
else
|
else
|
||||||
fatalerror( "Out of memory!" );
|
fatalerror
|
||||||
|
("Out of memory!");
|
||||||
|
} else
|
||||||
|
pPatch->pRPN =
|
||||||
|
NULL;
|
||||||
|
pPatch->pNext = NULL;
|
||||||
|
ppPatch =
|
||||||
|
&(pPatch->pNext);
|
||||||
|
} else
|
||||||
|
fatalerror
|
||||||
|
("Out of memory!");
|
||||||
|
} else
|
||||||
|
fatalerror("Out of memory!");
|
||||||
}
|
}
|
||||||
else
|
} else
|
||||||
pPatch->pRPN=NULL;
|
fatalerror("Out of memory!");
|
||||||
pPatch->pNext=NULL;
|
} else {
|
||||||
ppPatch=&(pPatch->pNext);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
fatalerror( "Out of memory!" );
|
|
||||||
}
|
|
||||||
else
|
|
||||||
fatalerror( "Out of memory!" );
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
fatalerror( "Out of memory!" );
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
readlong(f); // Skip number of patches
|
readlong(f); // Skip number of patches
|
||||||
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;
|
||||||
|
|
||||||
nNumberOfSymbols=readlong( pObjfile );
|
nNumberOfSymbols = readlong(pObjfile);
|
||||||
nNumberOfSections=readlong( pObjfile );
|
nNumberOfSections = readlong(pObjfile);
|
||||||
|
|
||||||
/* First comes the symbols */
|
/* First comes the symbols */
|
||||||
|
|
||||||
if( nNumberOfSymbols )
|
if (nNumberOfSymbols) {
|
||||||
{
|
if (tSymbols =
|
||||||
if( tSymbols=(struct sSymbol **)malloc(nNumberOfSymbols*sizeof(struct sSymbol *)) )
|
(struct sSymbol **)malloc(nNumberOfSymbols *
|
||||||
{
|
sizeof(struct sSymbol *))) {
|
||||||
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
|
fatalerror("Out of memory!");
|
||||||
fatalerror( "Out of memory!" );
|
} else
|
||||||
}
|
tSymbols = (struct sSymbol **)&dummymem;
|
||||||
else
|
|
||||||
tSymbols=(struct sSymbol **)&dummymem;
|
|
||||||
|
|
||||||
/* Next we have the sections */
|
/* Next we have the sections */
|
||||||
|
|
||||||
pFirstSection=NULL;
|
pFirstSection = NULL;
|
||||||
while( nNumberOfSections-- )
|
while (nNumberOfSections--) {
|
||||||
{
|
|
||||||
struct sSection *pNewSection;
|
struct sSection *pNewSection;
|
||||||
|
|
||||||
pNewSection=obj_ReadRGB0Section( pObjfile );
|
pNewSection = obj_ReadRGB0Section(pObjfile);
|
||||||
pNewSection->nNumberOfSymbols=nNumberOfSymbols;
|
pNewSection->nNumberOfSymbols = nNumberOfSymbols;
|
||||||
if( pFirstSection==NULL )
|
if (pFirstSection == NULL)
|
||||||
pFirstSection=pNewSection;
|
pFirstSection = pNewSection;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@@ -255,22 +257,19 @@ void obj_ReadRGB0( FILE *pObjfile )
|
|||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
for( i=0; i<nNumberOfSymbols; i+=1 )
|
for (i = 0; i < nNumberOfSymbols; i += 1) {
|
||||||
{
|
struct sSection *pConvSect = pFirstSection;
|
||||||
struct sSection *pConvSect=pFirstSection;
|
|
||||||
|
|
||||||
if( tSymbols[i]->Type!=SYM_IMPORT && tSymbols[i]->nSectionID!=-1 )
|
if (tSymbols[i]->Type != SYM_IMPORT
|
||||||
{
|
&& tSymbols[i]->nSectionID != -1) {
|
||||||
SLONG j=0;
|
SLONG j = 0;
|
||||||
while( j != tSymbols[i]->nSectionID )
|
while (j != tSymbols[i]->nSectionID) {
|
||||||
{
|
j += 1;
|
||||||
j+=1;
|
pConvSect = pConvSect->pNext;
|
||||||
pConvSect=pConvSect->pNext;
|
|
||||||
}
|
}
|
||||||
tSymbols[i]->pSection=pConvSect;
|
tSymbols[i]->pSection = pConvSect;
|
||||||
}
|
} else
|
||||||
else
|
tSymbols[i]->pSection = NULL;
|
||||||
tSymbols[i]->pSection=NULL;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -279,129 +278,140 @@ void obj_ReadRGB0( FILE *pObjfile )
|
|||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
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
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
pSection->nOrg=readlong( f );
|
pSection->nOrg = readlong(f);
|
||||||
pSection->nBank=readlong( f );
|
pSection->nBank = readlong(f);
|
||||||
|
|
||||||
/* does the user want the -s mode? */
|
/* does the user want the -s mode? */
|
||||||
|
|
||||||
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...
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
if( pSection->nByteSize )
|
if (pSection->nByteSize) {
|
||||||
{
|
if (pSection->pData =
|
||||||
if( pSection->pData=(UBYTE *)malloc(pSection->nByteSize) )
|
(UBYTE *) malloc(pSection->nByteSize)) {
|
||||||
{
|
|
||||||
SLONG nNumberOfPatches;
|
SLONG nNumberOfPatches;
|
||||||
struct sPatch **ppPatch, *pPatch;
|
struct sPatch **ppPatch, *pPatch;
|
||||||
char s[256];
|
char s[256];
|
||||||
|
|
||||||
fread( pSection->pData, sizeof(UBYTE), pSection->nByteSize, f );
|
fread(pSection->pData, sizeof(UBYTE),
|
||||||
nNumberOfPatches=readlong(f);
|
pSection->nByteSize, f);
|
||||||
ppPatch=&pSection->pPatches;
|
nNumberOfPatches = readlong(f);
|
||||||
|
ppPatch = &pSection->pPatches;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* And patches...
|
* And patches...
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
while( nNumberOfPatches-- )
|
while (nNumberOfPatches--) {
|
||||||
{
|
if (pPatch =
|
||||||
if( pPatch=(struct sPatch *)malloc(sizeof(struct sPatch)) )
|
(struct sPatch *)
|
||||||
{
|
malloc(sizeof(struct sPatch))) {
|
||||||
*ppPatch=pPatch;
|
*ppPatch = pPatch;
|
||||||
readasciiz( s, f );
|
readasciiz(s, f);
|
||||||
if( pPatch->pzFilename=(char *)malloc(strlen(s)+1) )
|
if (pPatch->pzFilename =
|
||||||
{
|
(char *)malloc(strlen(s) +
|
||||||
strcpy( pPatch->pzFilename, s );
|
1)) {
|
||||||
pPatch->nLineNo=readlong( f );
|
strcpy(pPatch->
|
||||||
pPatch->nOffset=readlong( f );
|
pzFilename, s);
|
||||||
pPatch->Type=(enum ePatchType)fgetc( f );
|
pPatch->nLineNo =
|
||||||
if( (pPatch->nRPNSize=readlong(f))>0 )
|
readlong(f);
|
||||||
{
|
pPatch->nOffset =
|
||||||
if( pPatch->pRPN=(UBYTE *)malloc(pPatch->nRPNSize) )
|
readlong(f);
|
||||||
fread( pPatch->pRPN, sizeof(UBYTE), pPatch->nRPNSize, f );
|
pPatch->Type =
|
||||||
|
(enum ePatchType)
|
||||||
|
fgetc(f);
|
||||||
|
if ((pPatch->nRPNSize =
|
||||||
|
readlong(f)) > 0) {
|
||||||
|
if (pPatch->
|
||||||
|
pRPN =
|
||||||
|
(UBYTE *)
|
||||||
|
malloc
|
||||||
|
(pPatch->
|
||||||
|
nRPNSize))
|
||||||
|
fread
|
||||||
|
(pPatch->
|
||||||
|
pRPN,
|
||||||
|
sizeof
|
||||||
|
(UBYTE),
|
||||||
|
pPatch->
|
||||||
|
nRPNSize,
|
||||||
|
f);
|
||||||
else
|
else
|
||||||
fatalerror( "Out of memory!" );
|
fatalerror
|
||||||
|
("Out of memory!");
|
||||||
|
} else
|
||||||
|
pPatch->pRPN =
|
||||||
|
NULL;
|
||||||
|
pPatch->pNext = NULL;
|
||||||
|
ppPatch =
|
||||||
|
&(pPatch->pNext);
|
||||||
|
} else
|
||||||
|
fatalerror
|
||||||
|
("Out of memory!");
|
||||||
|
} else
|
||||||
|
fatalerror("Out of memory!");
|
||||||
}
|
}
|
||||||
else
|
} else
|
||||||
pPatch->pRPN=NULL;
|
fatalerror("Out of memory!");
|
||||||
pPatch->pNext=NULL;
|
} else {
|
||||||
ppPatch=&(pPatch->pNext);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
fatalerror( "Out of memory!" );
|
|
||||||
}
|
|
||||||
else
|
|
||||||
fatalerror( "Out of memory!" );
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
fatalerror( "Out of memory!" );
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
readlong(f); // Skip number of patches
|
readlong(f); // Skip number of patches
|
||||||
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;
|
||||||
|
|
||||||
nNumberOfSymbols=readlong( pObjfile );
|
nNumberOfSymbols = readlong(pObjfile);
|
||||||
nNumberOfSections=readlong( pObjfile );
|
nNumberOfSections = readlong(pObjfile);
|
||||||
|
|
||||||
/* First comes the symbols */
|
/* First comes the symbols */
|
||||||
|
|
||||||
if( nNumberOfSymbols )
|
if (nNumberOfSymbols) {
|
||||||
{
|
if (tSymbols =
|
||||||
if( tSymbols=(struct sSymbol **)malloc(nNumberOfSymbols*sizeof(struct sSymbol *)) )
|
(struct sSymbol **)malloc(nNumberOfSymbols *
|
||||||
{
|
sizeof(struct sSymbol *))) {
|
||||||
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
|
fatalerror("Out of memory!");
|
||||||
fatalerror( "Out of memory!" );
|
} else
|
||||||
}
|
tSymbols = (struct sSymbol **)&dummymem;
|
||||||
else
|
|
||||||
tSymbols=(struct sSymbol **)&dummymem;
|
|
||||||
|
|
||||||
/* Next we have the sections */
|
/* Next we have the sections */
|
||||||
|
|
||||||
pFirstSection=NULL;
|
pFirstSection = NULL;
|
||||||
while( nNumberOfSections-- )
|
while (nNumberOfSections--) {
|
||||||
{
|
|
||||||
struct sSection *pNewSection;
|
struct sSection *pNewSection;
|
||||||
|
|
||||||
pNewSection=obj_ReadRGB1Section( pObjfile );
|
pNewSection = obj_ReadRGB1Section(pObjfile);
|
||||||
pNewSection->nNumberOfSymbols=nNumberOfSymbols;
|
pNewSection->nNumberOfSymbols = nNumberOfSymbols;
|
||||||
if( pFirstSection==NULL )
|
if (pFirstSection == NULL)
|
||||||
pFirstSection=pNewSection;
|
pFirstSection = pNewSection;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@@ -410,22 +420,19 @@ void obj_ReadRGB1( FILE *pObjfile )
|
|||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
for( i=0; i<nNumberOfSymbols; i+=1 )
|
for (i = 0; i < nNumberOfSymbols; i += 1) {
|
||||||
{
|
struct sSection *pConvSect = pFirstSection;
|
||||||
struct sSection *pConvSect=pFirstSection;
|
|
||||||
|
|
||||||
if( tSymbols[i]->Type!=SYM_IMPORT && tSymbols[i]->nSectionID!=-1 )
|
if (tSymbols[i]->Type != SYM_IMPORT
|
||||||
{
|
&& tSymbols[i]->nSectionID != -1) {
|
||||||
SLONG j=0;
|
SLONG j = 0;
|
||||||
while( j != tSymbols[i]->nSectionID )
|
while (j != tSymbols[i]->nSectionID) {
|
||||||
{
|
j += 1;
|
||||||
j+=1;
|
pConvSect = pConvSect->pNext;
|
||||||
pConvSect=pConvSect->pNext;
|
|
||||||
}
|
}
|
||||||
tSymbols[i]->pSection=pConvSect;
|
tSymbols[i]->pSection = pConvSect;
|
||||||
}
|
} else
|
||||||
else
|
tSymbols[i]->pSection = NULL;
|
||||||
tSymbols[i]->pSection=NULL;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -434,113 +441,105 @@ void obj_ReadRGB1( FILE *pObjfile )
|
|||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
void obj_ReadOpenFile( FILE *pObjfile, char *tzObjectfile )
|
void obj_ReadOpenFile(FILE * pObjfile, char *tzObjectfile)
|
||||||
{
|
{
|
||||||
char tzHeader[8];
|
char tzHeader[8];
|
||||||
|
|
||||||
fread( tzHeader, sizeof(char), 4, pObjfile );
|
fread(tzHeader, sizeof(char), 4, pObjfile);
|
||||||
tzHeader[4]=0;
|
tzHeader[4] = 0;
|
||||||
if( strncmp(tzHeader,"RGB", 3)==0 )
|
if (strncmp(tzHeader, "RGB", 3) == 0) {
|
||||||
{
|
switch (tzHeader[3]) {
|
||||||
switch( tzHeader[3] )
|
|
||||||
{
|
|
||||||
case '0':
|
case '0':
|
||||||
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': // V2 is really the same but the are new patch types
|
||||||
obj_ReadRGB1( pObjfile );
|
obj_ReadRGB1(pObjfile);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
sprintf( temptext, "'%s' is an unsupported version\n", tzObjectfile );
|
sprintf(temptext, "'%s' is an unsupported version\n",
|
||||||
fatalerror( temptext );
|
tzObjectfile);
|
||||||
|
fatalerror(temptext);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
} else {
|
||||||
else
|
sprintf(temptext, "'%s' is not a valid object\n", tzObjectfile);
|
||||||
{
|
fatalerror(temptext);
|
||||||
sprintf( temptext, "'%s' is not a valid object\n", tzObjectfile );
|
|
||||||
fatalerror( temptext );
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void obj_Readfile( char *tzObjectfile )
|
void obj_Readfile(char *tzObjectfile)
|
||||||
{
|
{
|
||||||
FILE *pObjfile;
|
FILE *pObjfile;
|
||||||
|
|
||||||
if( options&OPT_SMART_C_LINK )
|
if (options & OPT_SMART_C_LINK)
|
||||||
oReadLib=1;
|
oReadLib = 1;
|
||||||
else
|
else
|
||||||
oReadLib=0;
|
oReadLib = 0;
|
||||||
|
|
||||||
if( pObjfile=fopen(tzObjectfile,"rb") )
|
if (pObjfile = fopen(tzObjectfile, "rb")) {
|
||||||
{
|
obj_ReadOpenFile(pObjfile, tzObjectfile);
|
||||||
obj_ReadOpenFile( pObjfile, tzObjectfile );
|
fclose(pObjfile);
|
||||||
fclose( pObjfile );
|
} else {
|
||||||
}
|
sprintf(temptext, "Unable to open '%s'\n", tzObjectfile);
|
||||||
else
|
fatalerror(temptext);
|
||||||
{
|
|
||||||
sprintf( temptext, "Unable to open '%s'\n", tzObjectfile );
|
|
||||||
fatalerror( temptext );
|
|
||||||
}
|
}
|
||||||
|
|
||||||
oReadLib=0;
|
oReadLib = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
SLONG file_Length( FILE *f )
|
SLONG file_Length(FILE * f)
|
||||||
{
|
{
|
||||||
ULONG r,
|
ULONG r, p;
|
||||||
p;
|
|
||||||
|
|
||||||
p=ftell( f );
|
p = ftell(f);
|
||||||
fseek( f, 0, SEEK_END );
|
fseek(f, 0, SEEK_END);
|
||||||
r=ftell( f );
|
r = ftell(f);
|
||||||
fseek( f, p, SEEK_SET );
|
fseek(f, p, SEEK_SET);
|
||||||
|
|
||||||
return( r );
|
return (r);
|
||||||
}
|
}
|
||||||
|
|
||||||
void lib_ReadXLB0( FILE *f )
|
void lib_ReadXLB0(FILE * f)
|
||||||
{
|
{
|
||||||
SLONG size;
|
SLONG size;
|
||||||
|
|
||||||
size=file_Length( f )-4;
|
size = file_Length(f) - 4;
|
||||||
while( size )
|
while (size) {
|
||||||
{
|
|
||||||
char name[256];
|
char name[256];
|
||||||
|
|
||||||
size-=readasciiz( name, f );
|
size -= readasciiz(name, f);
|
||||||
readword( f ); size-=2;
|
readword(f);
|
||||||
readword( f ); size-=2;
|
size -= 2;
|
||||||
size-=readlong( f ); size-=4;
|
readword(f);
|
||||||
obj_ReadOpenFile( f, name );
|
size -= 2;
|
||||||
|
size -= readlong(f);
|
||||||
|
size -= 4;
|
||||||
|
obj_ReadOpenFile(f, name);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void lib_Readfile( char *tzLibfile )
|
void lib_Readfile(char *tzLibfile)
|
||||||
{
|
{
|
||||||
FILE *pObjfile;
|
FILE *pObjfile;
|
||||||
|
|
||||||
oReadLib=1;
|
oReadLib = 1;
|
||||||
|
|
||||||
if( pObjfile=fopen(tzLibfile,"rb") )
|
if (pObjfile = fopen(tzLibfile, "rb")) {
|
||||||
{
|
|
||||||
char tzHeader[5];
|
char tzHeader[5];
|
||||||
|
|
||||||
fread( tzHeader, sizeof(char), 4, pObjfile );
|
fread(tzHeader, sizeof(char), 4, pObjfile);
|
||||||
tzHeader[4]=0;
|
tzHeader[4] = 0;
|
||||||
if( strcmp(tzHeader,"XLB0")==0 )
|
if (strcmp(tzHeader, "XLB0") == 0)
|
||||||
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);
|
||||||
}
|
} else {
|
||||||
else
|
sprintf(temptext, "Unable to open '%s'\n", tzLibfile);
|
||||||
{
|
fatalerror(temptext);
|
||||||
sprintf( temptext, "Unable to open '%s'\n", tzLibfile );
|
|
||||||
fatalerror( temptext );
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -8,209 +8,185 @@
|
|||||||
#include "assign.h"
|
#include "assign.h"
|
||||||
|
|
||||||
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;
|
||||||
|
|
||||||
if( mem=(UBYTE *)malloc(MaxAvail[BANK_HOME]) )
|
if (mem = (UBYTE *) malloc(MaxAvail[BANK_HOME])) {
|
||||||
{
|
if (fillchar != -1) {
|
||||||
if( fillchar!=-1 )
|
memset(mem, fillchar, MaxAvail[BANK_HOME]);
|
||||||
{
|
|
||||||
memset( mem, fillchar, MaxAvail[BANK_HOME] );
|
|
||||||
}
|
}
|
||||||
MapfileInitBank( 0 );
|
MapfileInitBank(0);
|
||||||
|
|
||||||
pSect=pSections;
|
pSect = pSections;
|
||||||
while( pSect )
|
while (pSect) {
|
||||||
{
|
if (pSect->Type == SECT_HOME) {
|
||||||
if( pSect->Type==SECT_HOME )
|
memcpy(mem + pSect->nOrg, pSect->pData,
|
||||||
{
|
pSect->nByteSize);
|
||||||
memcpy( mem+pSect->nOrg, pSect->pData, pSect->nByteSize );
|
MapfileWriteSection(pSect);
|
||||||
MapfileWriteSection( pSect );
|
|
||||||
}
|
}
|
||||||
pSect=pSect->pNext;
|
pSect = pSect->pNext;
|
||||||
}
|
}
|
||||||
|
|
||||||
MapfileCloseBank( area_Avail(0) );
|
MapfileCloseBank(area_Avail(0));
|
||||||
|
|
||||||
fwrite( mem, 1, MaxAvail[BANK_HOME], f );
|
fwrite(mem, 1, MaxAvail[BANK_HOME], f);
|
||||||
free( mem );
|
free(mem);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void writebank( FILE *f, SLONG bank )
|
void writebank(FILE * f, SLONG bank)
|
||||||
{
|
{
|
||||||
struct sSection *pSect;
|
struct sSection *pSect;
|
||||||
UBYTE *mem;
|
UBYTE *mem;
|
||||||
|
|
||||||
if( mem=(UBYTE *)malloc(MaxAvail[bank]) )
|
if (mem = (UBYTE *) malloc(MaxAvail[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,
|
||||||
{
|
pSect->nByteSize);
|
||||||
memcpy( mem+pSect->nOrg-0x4000, pSect->pData, pSect->nByteSize );
|
MapfileWriteSection(pSect);
|
||||||
MapfileWriteSection( pSect );
|
|
||||||
}
|
}
|
||||||
pSect=pSect->pNext;
|
pSect = pSect->pNext;
|
||||||
}
|
}
|
||||||
|
|
||||||
MapfileCloseBank( area_Avail(bank) );
|
MapfileCloseBank(area_Avail(bank));
|
||||||
|
|
||||||
fwrite( mem, 1, MaxAvail[bank], f );
|
fwrite(mem, 1, MaxAvail[bank], f);
|
||||||
free( mem );
|
free(mem);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void out_Setname( char *tzOutputfile )
|
void out_Setname(char *tzOutputfile)
|
||||||
{
|
{
|
||||||
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;
|
||||||
|
|
||||||
if( f=fopen(tzOutname,"wb") )
|
if (f = fopen(tzOutname, "wb")) {
|
||||||
{
|
writehome(f);
|
||||||
writehome( f );
|
for (i = 1; i <= MaxBankUsed; i += 1)
|
||||||
for( i=1; i<=MaxBankUsed; i+=1 )
|
writebank(f, i);
|
||||||
writebank( f, i );
|
|
||||||
|
|
||||||
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);
|
||||||
pSect=pSections;
|
pSect = pSections;
|
||||||
while( pSect )
|
while (pSect) {
|
||||||
{
|
if (pSect->nBank == i) {
|
||||||
if( pSect->nBank==i )
|
MapfileWriteSection(pSect);
|
||||||
{
|
|
||||||
MapfileWriteSection( pSect );
|
|
||||||
}
|
}
|
||||||
pSect=pSect->pNext;
|
pSect = pSect->pNext;
|
||||||
}
|
}
|
||||||
MapfileCloseBank( area_Avail(i) );
|
MapfileCloseBank(area_Avail(i));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void PSION2_Output( void )
|
void PSION2_Output(void)
|
||||||
{
|
{
|
||||||
FILE *f;
|
FILE *f;
|
||||||
|
|
||||||
if( f=fopen(tzOutname,"wb") )
|
if (f = fopen(tzOutname, "wb")) {
|
||||||
{
|
|
||||||
struct sSection *pSect;
|
struct sSection *pSect;
|
||||||
UBYTE *mem;
|
UBYTE *mem;
|
||||||
ULONG size=MaxAvail[0]-area_Avail(0);
|
ULONG size = MaxAvail[0] - area_Avail(0);
|
||||||
ULONG relocpatches;
|
ULONG relocpatches;
|
||||||
|
|
||||||
fputc( size>>24, f );
|
fputc(size >> 24, f);
|
||||||
fputc( size>>16, f );
|
fputc(size >> 16, f);
|
||||||
fputc( size>>8, f );
|
fputc(size >> 8, f);
|
||||||
fputc( size, f );
|
fputc(size, f);
|
||||||
|
|
||||||
if( mem=(UBYTE *)malloc(MaxAvail[0]-area_Avail(0)) )
|
if (mem = (UBYTE *) malloc(MaxAvail[0] - area_Avail(0))) {
|
||||||
{
|
MapfileInitBank(0);
|
||||||
MapfileInitBank( 0 );
|
|
||||||
|
|
||||||
pSect=pSections;
|
pSect = pSections;
|
||||||
while( pSect )
|
while (pSect) {
|
||||||
{
|
if (pSect->Type == SECT_CODE) {
|
||||||
if( pSect->Type==SECT_CODE )
|
memcpy(mem + pSect->nOrg, pSect->pData,
|
||||||
{
|
pSect->nByteSize);
|
||||||
memcpy( mem+pSect->nOrg, pSect->pData, pSect->nByteSize );
|
MapfileWriteSection(pSect);
|
||||||
MapfileWriteSection( pSect );
|
} else {
|
||||||
|
memset(mem + pSect->nOrg, 0,
|
||||||
|
pSect->nByteSize);
|
||||||
}
|
}
|
||||||
else
|
pSect = pSect->pNext;
|
||||||
{
|
|
||||||
memset( mem+pSect->nOrg, 0, pSect->nByteSize );
|
|
||||||
}
|
|
||||||
pSect=pSect->pNext;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
MapfileCloseBank( area_Avail(0) );
|
MapfileCloseBank(area_Avail(0));
|
||||||
|
|
||||||
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) {
|
||||||
{
|
|
||||||
struct sPatch *pPatch;
|
struct sPatch *pPatch;
|
||||||
|
|
||||||
pPatch=pSect->pPatches;
|
pPatch = pSect->pPatches;
|
||||||
|
|
||||||
while( pPatch )
|
while (pPatch) {
|
||||||
{
|
if (pPatch->oRelocPatch) {
|
||||||
if( pPatch->oRelocPatch )
|
relocpatches += 1;
|
||||||
{
|
|
||||||
relocpatches+=1;
|
|
||||||
}
|
}
|
||||||
pPatch=pPatch->pNext;
|
pPatch = pPatch->pNext;
|
||||||
}
|
}
|
||||||
pSect=pSect->pNext;
|
pSect = pSect->pNext;
|
||||||
}
|
}
|
||||||
|
|
||||||
fputc( relocpatches>>24, f );
|
fputc(relocpatches >> 24, f);
|
||||||
fputc( relocpatches>>16, f );
|
fputc(relocpatches >> 16, f);
|
||||||
fputc( relocpatches>>8, f );
|
fputc(relocpatches >> 8, f);
|
||||||
fputc( relocpatches, f );
|
fputc(relocpatches, f);
|
||||||
|
|
||||||
pSect=pSections;
|
pSect = pSections;
|
||||||
while( pSect )
|
while (pSect) {
|
||||||
{
|
|
||||||
struct sPatch *pPatch;
|
struct sPatch *pPatch;
|
||||||
|
|
||||||
pPatch=pSect->pPatches;
|
pPatch = pSect->pPatches;
|
||||||
|
|
||||||
while( pPatch )
|
while (pPatch) {
|
||||||
{
|
if (pPatch->oRelocPatch) {
|
||||||
if( pPatch->oRelocPatch )
|
|
||||||
{
|
|
||||||
ULONG address;
|
ULONG address;
|
||||||
|
|
||||||
address=pPatch->nOffset+pSect->nOrg;
|
address = pPatch->nOffset + pSect->nOrg;
|
||||||
fputc( address>>24, f );
|
fputc(address >> 24, f);
|
||||||
fputc( address>>16, f );
|
fputc(address >> 16, f);
|
||||||
fputc( address>>8, f );
|
fputc(address >> 8, f);
|
||||||
fputc( address, f );
|
fputc(address, f);
|
||||||
}
|
}
|
||||||
pPatch=pPatch->pNext;
|
pPatch = pPatch->pNext;
|
||||||
}
|
}
|
||||||
pSect=pSect->pNext;
|
pSect = pSect->pNext;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fclose(f);
|
||||||
|
|
||||||
fclose( f );
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
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;
|
||||||
|
|||||||
326
src/link/patch.c
326
src/link/patch.c
@@ -10,291 +10,299 @@ 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:
|
||||||
case SYM_LOCAL:
|
case SYM_LOCAL:
|
||||||
{
|
{
|
||||||
if( strcmp(pCurrentSection->tSymbols[symid]->pzName,"@")==0 )
|
if (strcmp
|
||||||
{
|
(pCurrentSection->tSymbols[symid]->pzName,
|
||||||
return( nPC );
|
"@") == 0) {
|
||||||
}
|
return (nPC);
|
||||||
else
|
} else
|
||||||
return( pCurrentSection->tSymbols[symid]->nOffset+pCurrentSection->tSymbols[symid]->pSection->nOrg );
|
return (pCurrentSection->tSymbols[symid]->
|
||||||
|
nOffset +
|
||||||
|
pCurrentSection->tSymbols[symid]->
|
||||||
|
pSection->nOrg);
|
||||||
}
|
}
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
fatalerror( "*INTERNAL* UNKNOWN SYMBOL TYPE" );
|
fatalerror("*INTERNAL* UNKNOWN SYMBOL TYPE");
|
||||||
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;
|
||||||
}
|
}
|
||||||
fatalerror( "*INTERNAL* UNKNOWN SYMBOL TYPE" );
|
fatalerror("*INTERNAL* UNKNOWN SYMBOL TYPE");
|
||||||
return( 0 );
|
return (0);
|
||||||
}
|
}
|
||||||
|
|
||||||
SLONG calcrpn( struct sPatch *pPatch )
|
SLONG calcrpn(struct sPatch * pPatch)
|
||||||
{
|
{
|
||||||
SLONG t, size;
|
SLONG t, size;
|
||||||
UBYTE *rpn;
|
UBYTE *rpn;
|
||||||
|
|
||||||
rpnp=0;
|
rpnp = 0;
|
||||||
|
|
||||||
size=pPatch->nRPNSize;
|
size = pPatch->nRPNSize;
|
||||||
rpn=pPatch->pRPN;
|
rpn = pPatch->pRPN;
|
||||||
pPatch->oRelocPatch=0;
|
pPatch->oRelocPatch = 0;
|
||||||
|
|
||||||
while( size>0 )
|
while (size > 0) {
|
||||||
{
|
size -= 1;
|
||||||
size-=1;
|
switch (*rpn++) {
|
||||||
switch( *rpn++ )
|
|
||||||
{
|
|
||||||
case RPN_ADD:
|
case RPN_ADD:
|
||||||
rpnpush( rpnpop()+rpnpop() );
|
rpnpush(rpnpop() + rpnpop());
|
||||||
break;
|
break;
|
||||||
case RPN_SUB:
|
case RPN_SUB:
|
||||||
t=rpnpop();
|
t = rpnpop();
|
||||||
rpnpush( rpnpop()-t );
|
rpnpush(rpnpop() - t);
|
||||||
break;
|
break;
|
||||||
case RPN_MUL:
|
case RPN_MUL:
|
||||||
rpnpush( rpnpop()*rpnpop() );
|
rpnpush(rpnpop() * rpnpop());
|
||||||
break;
|
break;
|
||||||
case RPN_DIV:
|
case RPN_DIV:
|
||||||
t=rpnpop();
|
t = rpnpop();
|
||||||
rpnpush( rpnpop()/t );
|
rpnpush(rpnpop() / t);
|
||||||
break;
|
break;
|
||||||
case RPN_MOD:
|
case RPN_MOD:
|
||||||
t=rpnpop();
|
t = rpnpop();
|
||||||
rpnpush( rpnpop()%t );
|
rpnpush(rpnpop() % t);
|
||||||
break;
|
break;
|
||||||
case RPN_UNSUB:
|
case RPN_UNSUB:
|
||||||
rpnpush( -rpnpop() );
|
rpnpush(-rpnpop());
|
||||||
break;
|
break;
|
||||||
case RPN_OR:
|
case RPN_OR:
|
||||||
rpnpush( rpnpop()|rpnpop() );
|
rpnpush(rpnpop() | rpnpop());
|
||||||
break;
|
break;
|
||||||
case RPN_AND:
|
case RPN_AND:
|
||||||
rpnpush( rpnpop()&rpnpop() );
|
rpnpush(rpnpop() & rpnpop());
|
||||||
break;
|
break;
|
||||||
case RPN_XOR:
|
case RPN_XOR:
|
||||||
rpnpush( rpnpop()^rpnpop() );
|
rpnpush(rpnpop() ^ rpnpop());
|
||||||
break;
|
break;
|
||||||
case RPN_UNNOT:
|
case RPN_UNNOT:
|
||||||
rpnpush( rpnpop()^0xFFFFFFFF );
|
rpnpush(rpnpop() ^ 0xFFFFFFFF);
|
||||||
break;
|
break;
|
||||||
case RPN_LOGAND:
|
case RPN_LOGAND:
|
||||||
rpnpush( rpnpop()&&rpnpop() );
|
rpnpush(rpnpop() && rpnpop());
|
||||||
break;
|
break;
|
||||||
case RPN_LOGOR:
|
case RPN_LOGOR:
|
||||||
rpnpush( rpnpop()||rpnpop() );
|
rpnpush(rpnpop() || rpnpop());
|
||||||
break;
|
break;
|
||||||
case RPN_LOGUNNOT:
|
case RPN_LOGUNNOT:
|
||||||
rpnpush( !rpnpop() );
|
rpnpush(!rpnpop());
|
||||||
break;
|
break;
|
||||||
case RPN_LOGEQ:
|
case RPN_LOGEQ:
|
||||||
rpnpush( rpnpop()==rpnpop() );
|
rpnpush(rpnpop() == rpnpop());
|
||||||
break;
|
break;
|
||||||
case RPN_LOGNE:
|
case RPN_LOGNE:
|
||||||
rpnpush( rpnpop()!=rpnpop() );
|
rpnpush(rpnpop() != rpnpop());
|
||||||
break;
|
break;
|
||||||
case RPN_LOGGT:
|
case RPN_LOGGT:
|
||||||
t=rpnpop();
|
t = rpnpop();
|
||||||
rpnpush( rpnpop()>t );
|
rpnpush(rpnpop() > t);
|
||||||
break;
|
break;
|
||||||
case RPN_LOGLT:
|
case RPN_LOGLT:
|
||||||
t=rpnpop();
|
t = rpnpop();
|
||||||
rpnpush( rpnpop()<t );
|
rpnpush(rpnpop() < t);
|
||||||
break;
|
break;
|
||||||
case RPN_LOGGE:
|
case RPN_LOGGE:
|
||||||
t=rpnpop();
|
t = rpnpop();
|
||||||
rpnpush( rpnpop()>=t );
|
rpnpush(rpnpop() >= t);
|
||||||
break;
|
break;
|
||||||
case RPN_LOGLE:
|
case RPN_LOGLE:
|
||||||
t=rpnpop();
|
t = rpnpop();
|
||||||
rpnpush( rpnpop()<=t );
|
rpnpush(rpnpop() <= t);
|
||||||
break;
|
break;
|
||||||
case RPN_SHL:
|
case RPN_SHL:
|
||||||
t=rpnpop();
|
t = rpnpop();
|
||||||
rpnpush( rpnpop()<<t );
|
rpnpush(rpnpop() << t);
|
||||||
break;
|
break;
|
||||||
case RPN_SHR:
|
case RPN_SHR:
|
||||||
t=rpnpop();
|
t = rpnpop();
|
||||||
rpnpush( rpnpop()>>t );
|
rpnpush(rpnpop() >> t);
|
||||||
break;
|
break;
|
||||||
case RPN_HRAM:
|
case RPN_HRAM:
|
||||||
t=rpnpop();
|
t = rpnpop();
|
||||||
rpnpush(t&0xFF);
|
rpnpush(t & 0xFF);
|
||||||
if( t<0 || (t>0xFF && t<0xFF00) || t>0xFFFF )
|
if (t < 0 || (t > 0xFF && t < 0xFF00) || t > 0xFFFF) {
|
||||||
{
|
sprintf(temptext,
|
||||||
sprintf( temptext, "%s(%d) : Value must be in the HRAM area", pPatch->pzFilename, pPatch->nLineNo );
|
"%s(%d) : Value must be in the HRAM area",
|
||||||
fatalerror( temptext );
|
pPatch->pzFilename, pPatch->nLineNo);
|
||||||
|
fatalerror(temptext);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case RPN_PCEZP:
|
case RPN_PCEZP:
|
||||||
t=rpnpop();
|
t = rpnpop();
|
||||||
rpnpush(t&0xFF);
|
rpnpush(t & 0xFF);
|
||||||
if( t<0x2000 || t>0x20FF )
|
if (t < 0x2000 || t > 0x20FF) {
|
||||||
{
|
sprintf(temptext,
|
||||||
sprintf( temptext, "%s(%d) : Value must be in the ZP area", pPatch->pzFilename, pPatch->nLineNo );
|
"%s(%d) : Value must be in the ZP area",
|
||||||
fatalerror( temptext );
|
pPatch->pzFilename, pPatch->nLineNo);
|
||||||
|
fatalerror(temptext);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case RPN_CONST:
|
case RPN_CONST:
|
||||||
/* constant */
|
/* constant */
|
||||||
t=(*rpn++);
|
t = (*rpn++);
|
||||||
t|=(*rpn++)<<8;
|
t |= (*rpn++) << 8;
|
||||||
t|=(*rpn++)<<16;
|
t |= (*rpn++) << 16;
|
||||||
t|=(*rpn++)<<24;
|
t |= (*rpn++) << 24;
|
||||||
rpnpush( t );
|
rpnpush(t);
|
||||||
size-=4;
|
size -= 4;
|
||||||
break;
|
break;
|
||||||
case RPN_SYM:
|
case RPN_SYM:
|
||||||
/* symbol */
|
/* symbol */
|
||||||
t=(*rpn++);
|
t = (*rpn++);
|
||||||
t|=(*rpn++)<<8;
|
t |= (*rpn++) << 8;
|
||||||
t|=(*rpn++)<<16;
|
t |= (*rpn++) << 16;
|
||||||
t|=(*rpn++)<<24;
|
t |= (*rpn++) << 24;
|
||||||
rpnpush( getsymvalue(t) );
|
rpnpush(getsymvalue(t));
|
||||||
pPatch->oRelocPatch|=(getsymbank(t)!=-1);
|
pPatch->oRelocPatch |= (getsymbank(t) != -1);
|
||||||
size-=4;
|
size -= 4;
|
||||||
break;
|
break;
|
||||||
case RPN_BANK:
|
case RPN_BANK:
|
||||||
/* symbol */
|
/* symbol */
|
||||||
t=(*rpn++);
|
t = (*rpn++);
|
||||||
t|=(*rpn++)<<8;
|
t |= (*rpn++) << 8;
|
||||||
t|=(*rpn++)<<16;
|
t |= (*rpn++) << 16;
|
||||||
t|=(*rpn++)<<24;
|
t |= (*rpn++) << 24;
|
||||||
rpnpush( getsymbank(t) );
|
rpnpush(getsymbank(t));
|
||||||
size-=4;
|
size -= 4;
|
||||||
break;
|
break;
|
||||||
case RPN_RANGECHECK:
|
case RPN_RANGECHECK:
|
||||||
{
|
{
|
||||||
SLONG low,
|
SLONG low, high;
|
||||||
high;
|
|
||||||
|
|
||||||
low =(*rpn++);
|
low = (*rpn++);
|
||||||
low|=(*rpn++)<<8;
|
low |= (*rpn++) << 8;
|
||||||
low|=(*rpn++)<<16;
|
low |= (*rpn++) << 16;
|
||||||
low|=(*rpn++)<<24;
|
low |= (*rpn++) << 24;
|
||||||
high =(*rpn++);
|
high = (*rpn++);
|
||||||
high|=(*rpn++)<<8;
|
high |= (*rpn++) << 8;
|
||||||
high|=(*rpn++)<<16;
|
high |= (*rpn++) << 16;
|
||||||
high|=(*rpn++)<<24;
|
high |= (*rpn++) << 24;
|
||||||
t=rpnpop();
|
t = rpnpop();
|
||||||
if( t<low || t>high )
|
if (t < low || t > high) {
|
||||||
{
|
sprintf(temptext,
|
||||||
sprintf( temptext, "%s(%d) : Value must be in the range [%d;%d]", pPatch->pzFilename, pPatch->nLineNo, low, high );
|
"%s(%d) : Value must be in the range [%d;%d]",
|
||||||
fatalerror( temptext );
|
pPatch->pzFilename,
|
||||||
|
pPatch->nLineNo, low, high);
|
||||||
|
fatalerror(temptext);
|
||||||
}
|
}
|
||||||
rpnpush(t);
|
rpnpush(t);
|
||||||
size-=8;
|
size -= 8;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return( rpnpop() );
|
return (rpnpop());
|
||||||
}
|
}
|
||||||
|
|
||||||
void Patch( void )
|
void Patch(void)
|
||||||
{
|
{
|
||||||
struct sSection *pSect;
|
struct sSection *pSect;
|
||||||
|
|
||||||
pSect=pSections;
|
pSect = pSections;
|
||||||
while( pSect )
|
while (pSect) {
|
||||||
{
|
|
||||||
struct sPatch *pPatch;
|
struct sPatch *pPatch;
|
||||||
|
|
||||||
pCurrentSection=pSect;
|
pCurrentSection = pSect;
|
||||||
pPatch=pSect->pPatches;
|
pPatch = pSect->pPatches;
|
||||||
while( pPatch )
|
while (pPatch) {
|
||||||
{
|
|
||||||
SLONG t;
|
SLONG t;
|
||||||
|
|
||||||
nPC=pSect->nOrg+pPatch->nOffset;
|
nPC = pSect->nOrg + pPatch->nOffset;
|
||||||
t=calcrpn( pPatch );
|
t = calcrpn(pPatch);
|
||||||
switch( pPatch->Type )
|
switch (pPatch->Type) {
|
||||||
{
|
|
||||||
case PATCH_BYTE:
|
case PATCH_BYTE:
|
||||||
if( t>=-128 && t<=255 )
|
if (t >= -128 && t <= 255) {
|
||||||
{
|
t &= 0xFF;
|
||||||
t&=0xFF;
|
pSect->pData[pPatch->nOffset] =
|
||||||
pSect->pData[pPatch->nOffset]=(UBYTE)t;
|
(UBYTE) t;
|
||||||
}
|
} else {
|
||||||
else
|
sprintf(temptext,
|
||||||
{
|
"%s(%d) : Value must be 8-bit\n",
|
||||||
sprintf( temptext, "%s(%d) : Value must be 8-bit\n", pPatch->pzFilename, pPatch->nLineNo );
|
pPatch->pzFilename,
|
||||||
fatalerror( temptext );
|
pPatch->nLineNo);
|
||||||
|
fatalerror(temptext);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case PATCH_WORD_L:
|
case PATCH_WORD_L:
|
||||||
case PATCH_WORD_B:
|
case PATCH_WORD_B:
|
||||||
if( t>=-32768 && t<=65535 )
|
if (t >= -32768 && t <= 65535) {
|
||||||
{
|
t &= 0xFFFF;
|
||||||
t&=0xFFFF;
|
if (pPatch->Type == PATCH_WORD_L) {
|
||||||
if( pPatch->Type==PATCH_WORD_L )
|
pSect->pData[pPatch->nOffset] =
|
||||||
{
|
t & 0xFF;
|
||||||
pSect->pData[pPatch->nOffset]=t&0xFF;
|
pSect->pData[pPatch->nOffset +
|
||||||
pSect->pData[pPatch->nOffset+1]=(t>>8)&0xFF;
|
1] =
|
||||||
}
|
(t >> 8) & 0xFF;
|
||||||
else
|
} else {
|
||||||
{
|
|
||||||
// Assume big endian
|
// Assume big endian
|
||||||
pSect->pData[pPatch->nOffset]=(t>>8)&0xFF;
|
pSect->pData[pPatch->nOffset] =
|
||||||
pSect->pData[pPatch->nOffset+1]=t&0xFF;
|
(t >> 8) & 0xFF;
|
||||||
|
pSect->pData[pPatch->nOffset +
|
||||||
|
1] = t & 0xFF;
|
||||||
}
|
}
|
||||||
}
|
} else {
|
||||||
else
|
sprintf(temptext,
|
||||||
{
|
"%s(%d) : Value must be 16-bit\n",
|
||||||
sprintf( temptext, "%s(%d) : Value must be 16-bit\n", pPatch->pzFilename, pPatch->nLineNo );
|
pPatch->pzFilename,
|
||||||
fatalerror( temptext );
|
pPatch->nLineNo);
|
||||||
|
fatalerror(temptext);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case PATCH_LONG_L:
|
case PATCH_LONG_L:
|
||||||
pSect->pData[pPatch->nOffset+0]=t&0xFF;
|
pSect->pData[pPatch->nOffset + 0] = t & 0xFF;
|
||||||
pSect->pData[pPatch->nOffset+1]=(t>>8)&0xFF;
|
pSect->pData[pPatch->nOffset + 1] =
|
||||||
pSect->pData[pPatch->nOffset+2]=(t>>16)&0xFF;
|
(t >> 8) & 0xFF;
|
||||||
pSect->pData[pPatch->nOffset+3]=(t>>24)&0xFF;
|
pSect->pData[pPatch->nOffset + 2] =
|
||||||
|
(t >> 16) & 0xFF;
|
||||||
|
pSect->pData[pPatch->nOffset + 3] =
|
||||||
|
(t >> 24) & 0xFF;
|
||||||
break;
|
break;
|
||||||
case PATCH_LONG_B:
|
case PATCH_LONG_B:
|
||||||
pSect->pData[pPatch->nOffset+0]=(t>>24)&0xFF;
|
pSect->pData[pPatch->nOffset + 0] =
|
||||||
pSect->pData[pPatch->nOffset+1]=(t>>16)&0xFF;
|
(t >> 24) & 0xFF;
|
||||||
pSect->pData[pPatch->nOffset+2]=(t>>8)&0xFF;
|
pSect->pData[pPatch->nOffset + 1] =
|
||||||
pSect->pData[pPatch->nOffset+3]=t&0xFF;
|
(t >> 16) & 0xFF;
|
||||||
|
pSect->pData[pPatch->nOffset + 2] =
|
||||||
|
(t >> 8) & 0xFF;
|
||||||
|
pSect->pData[pPatch->nOffset + 3] = t & 0xFF;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
pPatch=pPatch->pNext;
|
pPatch = pPatch->pNext;
|
||||||
}
|
}
|
||||||
|
|
||||||
pSect=pSect->pNext;
|
pSect = pSect->pNext;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -7,8 +7,7 @@
|
|||||||
|
|
||||||
#define HASHSIZE 73
|
#define HASHSIZE 73
|
||||||
|
|
||||||
struct ISymbol
|
struct ISymbol {
|
||||||
{
|
|
||||||
char *pzName;
|
char *pzName;
|
||||||
SLONG nValue;
|
SLONG nValue;
|
||||||
SLONG nBank; // -1=const
|
SLONG nBank; // -1=const
|
||||||
@@ -17,108 +16,91 @@ struct ISymbol
|
|||||||
|
|
||||||
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)
|
||||||
r+=*s++;
|
r += *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 );
|
} else {
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
struct ISymbol **ppSym;
|
struct ISymbol **ppSym;
|
||||||
|
|
||||||
ppSym=&(tHash[calchash(tzName)]);
|
ppSym = &(tHash[calchash(tzName)]);
|
||||||
while( *ppSym )
|
while (*ppSym) {
|
||||||
{
|
if (strcmp(tzName, (*ppSym)->pzName)) {
|
||||||
if( strcmp(tzName,(*ppSym)->pzName) )
|
ppSym = &((*ppSym)->pNext);
|
||||||
{
|
} else {
|
||||||
ppSym=&((*ppSym)->pNext);
|
return ((*ppSym)->nValue);
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
return( (*ppSym)->nValue );
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
sprintf( temptext, "Unknown symbol '%s'", tzName );
|
sprintf(temptext, "Unknown symbol '%s'", tzName);
|
||||||
fatalerror( temptext );
|
fatalerror(temptext);
|
||||||
return( 0 );
|
return (0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
SLONG sym_GetBank( char *tzName )
|
SLONG sym_GetBank(char *tzName)
|
||||||
{
|
{
|
||||||
struct ISymbol **ppSym;
|
struct ISymbol **ppSym;
|
||||||
|
|
||||||
ppSym=&(tHash[calchash(tzName)]);
|
ppSym = &(tHash[calchash(tzName)]);
|
||||||
while( *ppSym )
|
while (*ppSym) {
|
||||||
{
|
if (strcmp(tzName, (*ppSym)->pzName)) {
|
||||||
if( strcmp(tzName,(*ppSym)->pzName) )
|
ppSym = &((*ppSym)->pNext);
|
||||||
{
|
} else {
|
||||||
ppSym=&((*ppSym)->pNext);
|
return ((*ppSym)->nBank);
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
return( (*ppSym)->nBank );
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
sprintf( temptext, "Unknown symbol '%s'" );
|
sprintf(temptext, "Unknown symbol '%s'");
|
||||||
fatalerror( temptext );
|
fatalerror(temptext);
|
||||||
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) {
|
||||||
{
|
} else {
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
struct ISymbol **ppSym;
|
struct ISymbol **ppSym;
|
||||||
|
|
||||||
ppSym=&(tHash[calchash(tzName)]);
|
ppSym = &(tHash[calchash(tzName)]);
|
||||||
|
|
||||||
while( *ppSym )
|
while (*ppSym) {
|
||||||
{
|
if (strcmp(tzName, (*ppSym)->pzName)) {
|
||||||
if( strcmp(tzName,(*ppSym)->pzName) )
|
ppSym = &((*ppSym)->pNext);
|
||||||
{
|
} else {
|
||||||
ppSym=&((*ppSym)->pNext);
|
if (nBank == -1)
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
if( nBank==-1 )
|
|
||||||
return;
|
return;
|
||||||
|
|
||||||
sprintf( temptext, "Symbol '%s' defined more than once\n", tzName );
|
sprintf(temptext,
|
||||||
fatalerror( temptext );
|
"Symbol '%s' defined more than once\n",
|
||||||
|
tzName);
|
||||||
|
fatalerror(temptext);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if( *ppSym=(struct ISymbol *)malloc(sizeof(struct ISymbol)) )
|
if (*ppSym = (struct ISymbol *)malloc(sizeof(struct ISymbol))) {
|
||||||
{
|
if ((*ppSym)->pzName =
|
||||||
if( (*ppSym)->pzName=(char *)malloc(strlen(tzName)+1) )
|
(char *)malloc(strlen(tzName) + 1)) {
|
||||||
{
|
strcpy((*ppSym)->pzName, tzName);
|
||||||
strcpy( (*ppSym)->pzName, tzName );
|
(*ppSym)->nValue = nValue;
|
||||||
(*ppSym)->nValue=nValue;
|
(*ppSym)->nBank = nBank;
|
||||||
(*ppSym)->nBank=nBank;
|
(*ppSym)->pNext = NULL;
|
||||||
(*ppSym)->pNext=NULL;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -8,8 +8,6 @@
|
|||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include "asmotor.h"
|
#include "asmotor.h"
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Option defines
|
* Option defines
|
||||||
*
|
*
|
||||||
@@ -23,73 +21,71 @@
|
|||||||
|
|
||||||
unsigned long ulOptions;
|
unsigned long ulOptions;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Misc. variables
|
* Misc. variables
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
unsigned char NintendoChar[48]=
|
unsigned char NintendoChar[48] = {
|
||||||
{
|
0xCE, 0xED, 0x66, 0x66, 0xCC, 0x0D, 0x00, 0x0B, 0x03, 0x73, 0x00, 0x83,
|
||||||
0xCE,0xED,0x66,0x66,0xCC,0x0D,0x00,0x0B,0x03,0x73,0x00,0x83,0x00,0x0C,0x00,0x0D,
|
0x00, 0x0C, 0x00, 0x0D,
|
||||||
0x00,0x08,0x11,0x1F,0x88,0x89,0x00,0x0E,0xDC,0xCC,0x6E,0xE6,0xDD,0xDD,0xD9,0x99,
|
0x00, 0x08, 0x11, 0x1F, 0x88, 0x89, 0x00, 0x0E, 0xDC, 0xCC, 0x6E, 0xE6,
|
||||||
0xBB,0xBB,0x67,0x63,0x6E,0x0E,0xEC,0xCC,0xDD,0xDC,0x99,0x9F,0xBB,0xB9,0x33,0x3E
|
0xDD, 0xDD, 0xD9, 0x99,
|
||||||
|
0xBB, 0xBB, 0x67, 0x63, 0x6E, 0x0E, 0xEC, 0xCC, 0xDD, 0xDC, 0x99, 0x9F,
|
||||||
|
0xBB, 0xB9, 0x33, 0x3E
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Misc. routines
|
* Misc. routines
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
void PrintUsage( void )
|
void PrintUsage(void)
|
||||||
{
|
{
|
||||||
printf( "RGBFix v" RGBFIX_VERSION " (part of ASMotor " ASMOTOR_VERSION ")\n\n" );
|
printf("RGBFix v" RGBFIX_VERSION " (part of ASMotor " ASMOTOR_VERSION
|
||||||
printf( "Usage: rgbfix [options] image[.gb]\n" );
|
")\n\n");
|
||||||
printf( "Options:\n" );
|
printf("Usage: rgbfix [options] image[.gb]\n");
|
||||||
printf( "\t-h\t\tThis text\n" );
|
printf("Options:\n");
|
||||||
printf( "\t-d\t\tDebug: Don't change image\n" );
|
printf("\t-h\t\tThis text\n");
|
||||||
printf( "\t-p\t\tPad image to valid size\n\t\t\tPads to 32/64/128/256/512kB as appropriate\n" );
|
printf("\t-d\t\tDebug: Don't change image\n");
|
||||||
printf( "\t-r\t\ttRuncate image to valid size\n\t\t\tTruncates to 32/64/128/256/512kB as appropriate\n" );
|
printf
|
||||||
printf( "\t-t<name>\tChange cartridge title field (16 characters)\n" );
|
("\t-p\t\tPad image to valid size\n\t\t\tPads to 32/64/128/256/512kB as appropriate\n");
|
||||||
printf( "\t-v\t\tValidate header\n\t\t\tCorrects - Nintendo Character Area (0x0104)\n\t\t\t\t - ROM type (0x0147)\n\t\t\t\t - ROM size (0x0148)\n\t\t\t\t - Checksums (0x014D-0x014F)\n" );
|
printf
|
||||||
exit( 0 );
|
("\t-r\t\ttRuncate image to valid size\n\t\t\tTruncates to 32/64/128/256/512kB as appropriate\n");
|
||||||
|
printf("\t-t<name>\tChange cartridge title field (16 characters)\n");
|
||||||
|
printf
|
||||||
|
("\t-v\t\tValidate header\n\t\t\tCorrects - Nintendo Character Area (0x0104)\n\t\t\t\t - ROM type (0x0147)\n\t\t\t\t - ROM size (0x0148)\n\t\t\t\t - Checksums (0x014D-0x014F)\n");
|
||||||
|
exit(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
void FatalError( char *s )
|
void FatalError(char *s)
|
||||||
{
|
{
|
||||||
printf( "\n***ERROR: %s\n\n", s );
|
printf("\n***ERROR: %s\n\n", s);
|
||||||
PrintUsage();
|
PrintUsage();
|
||||||
}
|
}
|
||||||
|
|
||||||
long int FileSize( FILE *f )
|
long int FileSize(FILE * f)
|
||||||
{
|
{
|
||||||
long prevpos;
|
long prevpos;
|
||||||
long r;
|
long r;
|
||||||
|
|
||||||
fflush( f );
|
fflush(f);
|
||||||
prevpos=ftell( f );
|
prevpos = ftell(f);
|
||||||
fseek( f, 0, SEEK_END );
|
fseek(f, 0, SEEK_END);
|
||||||
r=ftell( f );
|
r = ftell(f);
|
||||||
fseek( f, prevpos, SEEK_SET );
|
fseek(f, prevpos, SEEK_SET);
|
||||||
return( r );
|
return (r);
|
||||||
}
|
}
|
||||||
|
|
||||||
int FileExists( char *s )
|
int FileExists(char *s)
|
||||||
{
|
{
|
||||||
FILE *f;
|
FILE *f;
|
||||||
|
|
||||||
if( (f=fopen(s,"rb"))!=NULL )
|
if ((f = fopen(s, "rb")) != NULL) {
|
||||||
{
|
fclose(f);
|
||||||
fclose( f );
|
return (1);
|
||||||
return( 1 );
|
} else
|
||||||
}
|
return (0);
|
||||||
else
|
|
||||||
return( 0 );
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@@ -97,61 +93,57 @@ int FileExists( char *s )
|
|||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
int main( int argc, char *argv[] )
|
int main(int argc, char *argv[])
|
||||||
{
|
{
|
||||||
int argn=1;
|
int argn = 1;
|
||||||
char filename[512];
|
char filename[512];
|
||||||
char cartname[32];
|
char cartname[32];
|
||||||
FILE *f;
|
FILE *f;
|
||||||
|
|
||||||
ulOptions=0;
|
ulOptions = 0;
|
||||||
|
|
||||||
if( (--argc)==0 )
|
if ((--argc) == 0)
|
||||||
PrintUsage();
|
PrintUsage();
|
||||||
|
|
||||||
while( *argv[argn]=='-' )
|
while (*argv[argn] == '-') {
|
||||||
{
|
argc -= 1;
|
||||||
argc-=1;
|
switch (argv[argn++][1]) {
|
||||||
switch( argv[argn++][1] )
|
|
||||||
{
|
|
||||||
case '?':
|
case '?':
|
||||||
case 'h':
|
case 'h':
|
||||||
PrintUsage();
|
PrintUsage();
|
||||||
break;
|
break;
|
||||||
case 'd':
|
case 'd':
|
||||||
ulOptions|=OPTF_DEBUG;
|
ulOptions |= OPTF_DEBUG;
|
||||||
break;
|
break;
|
||||||
case 'p':
|
case 'p':
|
||||||
ulOptions|=OPTF_PAD;
|
ulOptions |= OPTF_PAD;
|
||||||
break;
|
break;
|
||||||
case 'r':
|
case 'r':
|
||||||
ulOptions|=OPTF_TRUNCATE;
|
ulOptions |= OPTF_TRUNCATE;
|
||||||
break;
|
break;
|
||||||
case 'v':
|
case 'v':
|
||||||
ulOptions|=OPTF_VALIDATE;
|
ulOptions |= OPTF_VALIDATE;
|
||||||
break;
|
break;
|
||||||
case 't':
|
case 't':
|
||||||
strncpy( cartname, argv[argn-1]+2, 16 );
|
strncpy(cartname, argv[argn - 1] + 2, 16);
|
||||||
ulOptions|=OPTF_TITLE;
|
ulOptions |= OPTF_TITLE;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
strcpy( filename, argv[argn++] );
|
strcpy(filename, argv[argn++]);
|
||||||
|
|
||||||
if( !FileExists(filename) )
|
if (!FileExists(filename))
|
||||||
strcat( filename, ".gb" );
|
strcat(filename, ".gb");
|
||||||
|
|
||||||
if( (f=fopen(filename,"rb+"))!=NULL )
|
if ((f = fopen(filename, "rb+")) != NULL) {
|
||||||
{
|
|
||||||
/*
|
/*
|
||||||
* -d (Debug) option code
|
* -d (Debug) option code
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
if( ulOptions&OPTF_DEBUG )
|
if (ulOptions & OPTF_DEBUG) {
|
||||||
{
|
printf("-d (Debug) option enabled...\n");
|
||||||
printf( "-d (Debug) option enabled...\n" );
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@@ -159,40 +151,36 @@ int main( int argc, char *argv[] )
|
|||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
if( ulOptions&OPTF_PAD )
|
if (ulOptions & OPTF_PAD) {
|
||||||
{
|
|
||||||
long size, padto;
|
long size, padto;
|
||||||
long bytesadded=0;
|
long bytesadded = 0;
|
||||||
|
|
||||||
size=FileSize( f );
|
size = FileSize(f);
|
||||||
padto=0x8000L;
|
padto = 0x8000L;
|
||||||
while( size>padto )
|
while (size > padto)
|
||||||
padto*=2;
|
padto *= 2;
|
||||||
|
|
||||||
printf( "Padding to %ldkB:\n", padto/1024 );
|
printf("Padding to %ldkB:\n", padto / 1024);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
if( padto<=0x80000L )
|
if( padto<=0x80000L )
|
||||||
{
|
{
|
||||||
*/
|
*/
|
||||||
if( size!=padto )
|
if (size != padto) {
|
||||||
{
|
fflush(stdout);
|
||||||
fflush( stdout );
|
|
||||||
|
|
||||||
fseek( f, 0, SEEK_END );
|
fseek(f, 0, SEEK_END);
|
||||||
while( size<padto )
|
while (size < padto) {
|
||||||
{
|
size += 1;
|
||||||
size+=1;
|
if ((ulOptions & OPTF_DEBUG) == 0)
|
||||||
if( (ulOptions&OPTF_DEBUG)==0 )
|
fputc(0, f);
|
||||||
fputc( 0, f );
|
bytesadded += 1;
|
||||||
bytesadded+=1;
|
|
||||||
}
|
}
|
||||||
fflush( f );
|
fflush(f);
|
||||||
|
|
||||||
printf( "\tAdded %ld bytes\n", bytesadded );
|
printf("\tAdded %ld bytes\n", bytesadded);
|
||||||
}
|
} else
|
||||||
else
|
printf("\tNo padding needed\n");
|
||||||
printf( "\tNo padding needed\n" );
|
|
||||||
/*
|
/*
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@@ -205,35 +193,31 @@ int main( int argc, char *argv[] )
|
|||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
if( ulOptions&OPTF_TRUNCATE )
|
if (ulOptions & OPTF_TRUNCATE) {
|
||||||
{
|
|
||||||
long size, padto;
|
long size, padto;
|
||||||
char tempfile[512];
|
char tempfile[512];
|
||||||
FILE *tf;
|
FILE *tf;
|
||||||
|
|
||||||
size=FileSize( f );
|
size = FileSize(f);
|
||||||
padto=256*32768;
|
padto = 256 * 32768;
|
||||||
while( size<padto )
|
while (size < padto)
|
||||||
padto/=2;
|
padto /= 2;
|
||||||
|
|
||||||
printf( "Truncating to %ldkB:\n", padto/1024 );
|
printf("Truncating to %ldkB:\n", padto / 1024);
|
||||||
|
|
||||||
tmpnam( tempfile );
|
tmpnam(tempfile);
|
||||||
|
|
||||||
if( (ulOptions&OPTF_DEBUG)==0 )
|
if ((ulOptions & OPTF_DEBUG) == 0) {
|
||||||
{
|
if ((tf = fopen(tempfile, "wb")) != NULL) {
|
||||||
if( (tf=fopen(tempfile,"wb"))!=NULL )
|
fseek(f, 0, SEEK_SET);
|
||||||
{
|
while (padto--) {
|
||||||
fseek( f, 0, SEEK_SET );
|
fputc(fgetc(f), tf);
|
||||||
while( padto-- )
|
|
||||||
{
|
|
||||||
fputc( fgetc(f), tf );
|
|
||||||
}
|
}
|
||||||
fclose( f );
|
fclose(f);
|
||||||
fclose( tf );
|
fclose(tf);
|
||||||
remove( filename );
|
remove(filename);
|
||||||
rename( tempfile, filename );
|
rename(tempfile, filename);
|
||||||
f=fopen( filename, "rb+" );
|
f = fopen(filename, "rb+");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -243,17 +227,15 @@ int main( int argc, char *argv[] )
|
|||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
if( ulOptions&OPTF_TITLE )
|
if (ulOptions & OPTF_TITLE) {
|
||||||
{
|
printf("Setting cartridge title:\n");
|
||||||
printf( "Setting cartridge title:\n" );
|
if ((ulOptions & OPTF_DEBUG) == 0) {
|
||||||
if( (ulOptions&OPTF_DEBUG)==0 )
|
fflush(f);
|
||||||
{
|
fseek(f, 0x0134L, SEEK_SET);
|
||||||
fflush( f );
|
fwrite(cartname, 16, 1, f);
|
||||||
fseek( f, 0x0134L, SEEK_SET );
|
fflush(f);
|
||||||
fwrite( cartname, 16, 1, f );
|
|
||||||
fflush( f );
|
|
||||||
}
|
}
|
||||||
printf( "\tTitle set to %s\n", cartname );
|
printf("\tTitle set to %s\n", cartname);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@@ -261,172 +243,160 @@ int main( int argc, char *argv[] )
|
|||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
if( ulOptions&OPTF_VALIDATE )
|
if (ulOptions & OPTF_VALIDATE) {
|
||||||
{
|
long i, byteschanged = 0;
|
||||||
long i, byteschanged=0;
|
long cartromsize, calcromsize = 0, filesize;
|
||||||
long cartromsize, calcromsize=0, filesize;
|
|
||||||
long carttype;
|
long carttype;
|
||||||
unsigned short cartchecksum=0, calcchecksum=0;
|
unsigned short cartchecksum = 0, calcchecksum = 0;
|
||||||
unsigned char cartcompchecksum=0, calccompchecksum=0;
|
unsigned char cartcompchecksum = 0, calccompchecksum =
|
||||||
|
0;
|
||||||
int ch;
|
int ch;
|
||||||
|
|
||||||
printf( "Validating header:\n" );
|
printf("Validating header:\n");
|
||||||
fflush( stdout );
|
fflush(stdout);
|
||||||
|
|
||||||
/* Nintendo Character Area */
|
/* Nintendo Character Area */
|
||||||
|
|
||||||
fflush( f );
|
fflush(f);
|
||||||
fseek( f, 0x0104L, SEEK_SET );
|
fseek(f, 0x0104L, SEEK_SET);
|
||||||
|
|
||||||
for( i=0; i<48; i+=1 )
|
for (i = 0; i < 48; i += 1) {
|
||||||
{
|
|
||||||
int ch;
|
int ch;
|
||||||
|
|
||||||
ch=fgetc( f );
|
ch = fgetc(f);
|
||||||
if( ch==EOF )
|
if (ch == EOF)
|
||||||
ch=0x00;
|
ch = 0x00;
|
||||||
if( ch!=NintendoChar[i] )
|
if (ch != NintendoChar[i]) {
|
||||||
{
|
byteschanged += 1;
|
||||||
byteschanged+=1;
|
|
||||||
|
|
||||||
if( (ulOptions&OPTF_DEBUG)==0 )
|
if ((ulOptions & OPTF_DEBUG) == 0) {
|
||||||
{
|
fseek(f, -1, SEEK_CUR);
|
||||||
fseek( f, -1, SEEK_CUR );
|
fputc(NintendoChar[i], f);
|
||||||
fputc( NintendoChar[i], f );
|
fflush(f);
|
||||||
fflush( f );
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fflush( f );
|
fflush(f);
|
||||||
|
|
||||||
if( byteschanged )
|
if (byteschanged)
|
||||||
printf( "\tChanged %ld bytes in the Nintendo Character Area\n", byteschanged );
|
printf
|
||||||
|
("\tChanged %ld bytes in the Nintendo Character Area\n",
|
||||||
|
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);
|
||||||
fseek( f, 0x0148L, SEEK_SET );
|
fseek(f, 0x0148L, SEEK_SET);
|
||||||
cartromsize=fgetc( f );
|
cartromsize = fgetc(f);
|
||||||
if( cartromsize==EOF )
|
if (cartromsize == EOF)
|
||||||
cartromsize=0x00;
|
cartromsize = 0x00;
|
||||||
filesize=FileSize( f );
|
filesize = FileSize(f);
|
||||||
while( filesize>(0x8000L<<calcromsize) )
|
while (filesize > (0x8000L << calcromsize))
|
||||||
calcromsize+=1;
|
calcromsize += 1;
|
||||||
|
|
||||||
if( calcromsize!=cartromsize )
|
if (calcromsize != cartromsize) {
|
||||||
{
|
if ((ulOptions & OPTF_DEBUG) == 0) {
|
||||||
if( (ulOptions&OPTF_DEBUG)==0 )
|
fseek(f, -1, SEEK_CUR);
|
||||||
{
|
fputc(calcromsize, f);
|
||||||
fseek( f, -1, SEEK_CUR );
|
fflush(f);
|
||||||
fputc( calcromsize, f );
|
|
||||||
fflush( f );
|
|
||||||
}
|
}
|
||||||
printf( "\tChanged ROM size byte from 0x%02lX (%ldkB) to 0x%02lX (%ldkB)\n",
|
printf
|
||||||
cartromsize, (0x8000L<<cartromsize)/1024,
|
("\tChanged ROM size byte from 0x%02lX (%ldkB) to 0x%02lX (%ldkB)\n",
|
||||||
calcromsize, (0x8000L<<calcromsize)/1024 );
|
cartromsize,
|
||||||
}
|
(0x8000L << cartromsize) / 1024,
|
||||||
else
|
calcromsize,
|
||||||
printf( "\tROM size byte is OK\n" );
|
(0x8000L << calcromsize) / 1024);
|
||||||
|
} else
|
||||||
|
printf("\tROM size byte is OK\n");
|
||||||
|
|
||||||
/* Cartridge type */
|
/* Cartridge type */
|
||||||
|
|
||||||
fflush( f );
|
fflush(f);
|
||||||
fseek( f, 0x0147L, SEEK_SET );
|
fseek(f, 0x0147L, SEEK_SET);
|
||||||
carttype=fgetc( f );
|
carttype = fgetc(f);
|
||||||
if( carttype==EOF )
|
if (carttype == EOF)
|
||||||
carttype=0x00;
|
carttype = 0x00;
|
||||||
|
|
||||||
if( FileSize(f)>0x8000L )
|
if (FileSize(f) > 0x8000L) {
|
||||||
{
|
|
||||||
/* carttype byte must != 0x00 */
|
/* carttype byte must != 0x00 */
|
||||||
if( carttype==0x00 )
|
if (carttype == 0x00) {
|
||||||
{
|
if ((ulOptions & OPTF_DEBUG) == 0) {
|
||||||
if( (ulOptions&OPTF_DEBUG)==0 )
|
fseek(f, -1, SEEK_CUR);
|
||||||
{
|
fputc(0x01, f);
|
||||||
fseek( f, -1, SEEK_CUR );
|
fflush(f);
|
||||||
fputc( 0x01, f );
|
|
||||||
fflush( f );
|
|
||||||
}
|
}
|
||||||
printf( "\tCartridge type byte changed to 0x01\n" );
|
printf
|
||||||
}
|
("\tCartridge type byte changed to 0x01\n");
|
||||||
else
|
} else
|
||||||
printf( "\tCartridge type byte is OK\n" );
|
printf("\tCartridge type byte is OK\n");
|
||||||
}
|
} else {
|
||||||
else
|
|
||||||
{
|
|
||||||
/* carttype byte can be anything? */
|
/* carttype byte can be anything? */
|
||||||
printf( "\tCartridge type byte is OK\n" );
|
printf("\tCartridge type byte is OK\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Checksum */
|
/* Checksum */
|
||||||
|
|
||||||
fflush( f );
|
fflush(f);
|
||||||
fseek( f, 0, SEEK_SET );
|
fseek(f, 0, SEEK_SET);
|
||||||
|
|
||||||
for( i=0; i<(0x8000L<<calcromsize); i+=1 )
|
for (i = 0; i < (0x8000L << calcromsize); i += 1) {
|
||||||
{
|
ch = fgetc(f);
|
||||||
ch=fgetc( f );
|
if (ch == EOF)
|
||||||
if( ch==EOF )
|
ch = 0;
|
||||||
ch=0;
|
|
||||||
|
|
||||||
if( i<0x0134L )
|
if (i < 0x0134L)
|
||||||
calcchecksum+=ch;
|
calcchecksum += ch;
|
||||||
else if( i<0x014DL )
|
else if (i < 0x014DL) {
|
||||||
{
|
calccompchecksum += ch;
|
||||||
calccompchecksum+=ch;
|
calcchecksum += ch;
|
||||||
calcchecksum+=ch;
|
} else if (i == 0x014DL)
|
||||||
}
|
cartcompchecksum = ch;
|
||||||
else if( i==0x014DL )
|
else if (i == 0x014EL)
|
||||||
cartcompchecksum=ch;
|
cartchecksum = ch << 8;
|
||||||
else if( i==0x014EL )
|
else if (i == 0x014FL)
|
||||||
cartchecksum=ch<<8;
|
cartchecksum |= ch;
|
||||||
else if( i==0x014FL )
|
|
||||||
cartchecksum|=ch;
|
|
||||||
else
|
else
|
||||||
calcchecksum+=ch;
|
calcchecksum += ch;
|
||||||
}
|
}
|
||||||
|
|
||||||
calccompchecksum=0xE7-calccompchecksum;
|
calccompchecksum = 0xE7 - calccompchecksum;
|
||||||
calcchecksum+=calccompchecksum;
|
calcchecksum += calccompchecksum;
|
||||||
|
|
||||||
if( cartchecksum!=calcchecksum )
|
if (cartchecksum != calcchecksum) {
|
||||||
{
|
fflush(f);
|
||||||
fflush( f );
|
fseek(f, 0x014EL, SEEK_SET);
|
||||||
fseek( f, 0x014EL, SEEK_SET );
|
if ((ulOptions & OPTF_DEBUG) == 0) {
|
||||||
if( (ulOptions&OPTF_DEBUG)==0 )
|
fputc(calcchecksum >> 8, f);
|
||||||
{
|
fputc(calcchecksum & 0xFF, f);
|
||||||
fputc( calcchecksum>>8, f );
|
|
||||||
fputc( calcchecksum&0xFF, f );
|
|
||||||
}
|
}
|
||||||
fflush( f );
|
fflush(f);
|
||||||
printf( "\tChecksum changed from 0x%04lX to 0x%04lX\n", (long)cartchecksum, (long)calcchecksum );
|
printf
|
||||||
}
|
("\tChecksum changed from 0x%04lX to 0x%04lX\n",
|
||||||
else
|
(long)cartchecksum, (long)calcchecksum);
|
||||||
printf( "\tChecksum is OK\n" );
|
} else
|
||||||
|
printf("\tChecksum is OK\n");
|
||||||
|
|
||||||
|
if (cartcompchecksum != calccompchecksum) {
|
||||||
if( cartcompchecksum!=calccompchecksum )
|
fflush(f);
|
||||||
{
|
fseek(f, 0x014DL, SEEK_SET);
|
||||||
fflush( f );
|
if ((ulOptions & OPTF_DEBUG) == 0)
|
||||||
fseek( f, 0x014DL, SEEK_SET );
|
fputc(calccompchecksum, f);
|
||||||
if( (ulOptions&OPTF_DEBUG)==0 )
|
fflush(f);
|
||||||
fputc( calccompchecksum, f );
|
printf
|
||||||
fflush( f );
|
("\tCompChecksum changed from 0x%02lX to 0x%02lX\n",
|
||||||
printf( "\tCompChecksum changed from 0x%02lX to 0x%02lX\n", (long)cartcompchecksum, (long)calccompchecksum );
|
(long)cartcompchecksum,
|
||||||
}
|
(long)calccompchecksum);
|
||||||
else
|
} else
|
||||||
printf( "\tCompChecksum is OK\n" );
|
printf("\tCompChecksum is OK\n");
|
||||||
|
|
||||||
}
|
}
|
||||||
fclose( f );
|
fclose(f);
|
||||||
}
|
} else {
|
||||||
else
|
FatalError("Unable to open file");
|
||||||
{
|
|
||||||
FatalError( "Unable to open file" );
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return( 0 );
|
return (0);
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user