mirror of
https://github.com/gbdev/rgbds.git
synced 2025-11-20 10:12:06 +00:00
Switch line terminators from CRLF to LF
Argh, that obnoxious platform again... ;-) Signed-off-by: Vegard Nossum <vegard.nossum@gmail.com>
This commit is contained in:
994
src/asm/alloca.c
994
src/asm/alloca.c
@@ -1,497 +1,497 @@
|
|||||||
/* alloca.c -- allocate automatically reclaimed memory
|
/* alloca.c -- allocate automatically reclaimed memory
|
||||||
(Mostly) portable public-domain implementation -- D A Gwyn
|
(Mostly) portable public-domain implementation -- D A Gwyn
|
||||||
|
|
||||||
This implementation of the PWB library alloca function,
|
This implementation of the PWB library alloca function,
|
||||||
which is used to allocate space off the run-time stack so
|
which is used to allocate space off the run-time stack so
|
||||||
that it is automatically reclaimed upon procedure exit,
|
that it is automatically reclaimed upon procedure exit,
|
||||||
was inspired by discussions with J. Q. Johnson of Cornell.
|
was inspired by discussions with J. Q. Johnson of Cornell.
|
||||||
J.Otto Tennant <jot@cray.com> contributed the Cray support.
|
J.Otto Tennant <jot@cray.com> contributed the Cray support.
|
||||||
|
|
||||||
There are some preprocessor constants that can
|
There are some preprocessor constants that can
|
||||||
be defined when compiling for your specific system, for
|
be defined when compiling for your specific system, for
|
||||||
improved efficiency; however, the defaults should be okay.
|
improved efficiency; however, the defaults should be okay.
|
||||||
|
|
||||||
The general concept of this implementation is to keep
|
The general concept of this implementation is to keep
|
||||||
track of all alloca-allocated blocks, and reclaim any
|
track of all alloca-allocated blocks, and reclaim any
|
||||||
that are found to be deeper in the stack than the current
|
that are found to be deeper in the stack than the current
|
||||||
invocation. This heuristic does not reclaim storage as
|
invocation. This heuristic does not reclaim storage as
|
||||||
soon as it becomes invalid, but it will do so eventually.
|
soon as it becomes invalid, but it will do so eventually.
|
||||||
|
|
||||||
As a special case, alloca(0) reclaims storage without
|
As a special case, alloca(0) reclaims storage without
|
||||||
allocating any. It is a good idea to use alloca(0) in
|
allocating any. It is a good idea to use alloca(0) in
|
||||||
your main control loop, etc. to force garbage collection. */
|
your main control loop, etc. to force garbage collection. */
|
||||||
|
|
||||||
#ifdef HAVE_CONFIG_H
|
#ifdef HAVE_CONFIG_H
|
||||||
#include <config.h>
|
#include <config.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef emacs
|
#ifdef emacs
|
||||||
#include "blockinput.h"
|
#include "blockinput.h"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/* If compiling with GCC 2, this file's not needed. */
|
/* If compiling with GCC 2, this file's not needed. */
|
||||||
#if !defined (__GNUC__) || __GNUC__ < 2
|
#if !defined (__GNUC__) || __GNUC__ < 2
|
||||||
|
|
||||||
/* If someone has defined alloca as a macro,
|
/* If someone has defined alloca as a macro,
|
||||||
there must be some other way alloca is supposed to work. */
|
there must be some other way alloca is supposed to work. */
|
||||||
#ifndef alloca
|
#ifndef alloca
|
||||||
|
|
||||||
#ifdef emacs
|
#ifdef emacs
|
||||||
#ifdef static
|
#ifdef static
|
||||||
/* actually, only want this if static is defined as ""
|
/* actually, only want this if static is defined as ""
|
||||||
-- this is for usg, in which emacs must undefine static
|
-- this is for usg, in which emacs must undefine static
|
||||||
in order to make unexec workable
|
in order to make unexec workable
|
||||||
*/
|
*/
|
||||||
#ifndef STACK_DIRECTION
|
#ifndef STACK_DIRECTION
|
||||||
you
|
you
|
||||||
lose
|
lose
|
||||||
-- must know STACK_DIRECTION at compile-time
|
-- 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
|
||||||
typedef char *pointer;
|
typedef char *pointer;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#define NULL 0
|
#define NULL 0
|
||||||
|
|
||||||
/* Different portions of Emacs need to call different versions of
|
/* Different portions of Emacs need to call different versions of
|
||||||
malloc. The Emacs executable needs alloca to call xmalloc, because
|
malloc. The Emacs executable needs alloca to call xmalloc, because
|
||||||
ordinary malloc isn't protected from input signals. On the other
|
ordinary malloc isn't protected from input signals. On the other
|
||||||
hand, the utilities in lib-src need alloca to call malloc; some of
|
hand, the utilities in lib-src need alloca to call malloc; some of
|
||||||
them are very simple, and don't have an xmalloc routine.
|
them are very simple, and don't have an xmalloc routine.
|
||||||
|
|
||||||
Non-Emacs programs expect this to call use xmalloc.
|
Non-Emacs programs expect this to call use xmalloc.
|
||||||
|
|
||||||
Callers below should use malloc. */
|
Callers below should use malloc. */
|
||||||
|
|
||||||
/* Carsten Sorensen 09/09/97
|
/* Carsten Sorensen 09/09/97
|
||||||
* Commented out the following, I want malloc!
|
* Commented out the following, I want malloc!
|
||||||
#ifndef emacs
|
#ifndef emacs
|
||||||
#define malloc xmalloc
|
#define malloc xmalloc
|
||||||
#endif
|
#endif
|
||||||
extern pointer malloc ();
|
extern pointer malloc ();
|
||||||
And added the following line:
|
And added the following line:
|
||||||
*/
|
*/
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
|
||||||
/* Define STACK_DIRECTION if you know the direction of stack
|
/* Define STACK_DIRECTION if you know the direction of stack
|
||||||
growth for your system; otherwise it will be automatically
|
growth for your system; otherwise it will be automatically
|
||||||
deduced at run-time.
|
deduced at run-time.
|
||||||
|
|
||||||
STACK_DIRECTION > 0 => grows toward higher addresses
|
STACK_DIRECTION > 0 => grows toward higher addresses
|
||||||
STACK_DIRECTION < 0 => grows toward lower addresses
|
STACK_DIRECTION < 0 => grows toward lower addresses
|
||||||
STACK_DIRECTION = 0 => direction of growth unknown */
|
STACK_DIRECTION = 0 => direction of growth unknown */
|
||||||
|
|
||||||
#ifndef STACK_DIRECTION
|
#ifndef STACK_DIRECTION
|
||||||
#define STACK_DIRECTION 0 /* Direction unknown. */
|
#define STACK_DIRECTION 0 /* Direction unknown. */
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if STACK_DIRECTION != 0
|
#if STACK_DIRECTION != 0
|
||||||
|
|
||||||
#define STACK_DIR STACK_DIRECTION /* Known at compile-time. */
|
#define STACK_DIR STACK_DIRECTION /* Known at compile-time. */
|
||||||
|
|
||||||
#else /* STACK_DIRECTION == 0; need run-time code. */
|
#else /* STACK_DIRECTION == 0; need run-time code. */
|
||||||
|
|
||||||
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. */
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif /* STACK_DIRECTION == 0 */
|
#endif /* STACK_DIRECTION == 0 */
|
||||||
|
|
||||||
/* An "alloca header" is used to:
|
/* An "alloca header" is used to:
|
||||||
(a) chain together all alloca'ed blocks;
|
(a) chain together all alloca'ed blocks;
|
||||||
(b) keep track of stack depth.
|
(b) keep track of stack depth.
|
||||||
|
|
||||||
It is very important that sizeof(header) agree with malloc
|
It is very important that sizeof(header) agree with malloc
|
||||||
alignment chunk size. The following default should work okay. */
|
alignment chunk size. The following default should work okay. */
|
||||||
|
|
||||||
#ifndef ALIGN_SIZE
|
#ifndef ALIGN_SIZE
|
||||||
#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;
|
||||||
} header;
|
} header;
|
||||||
|
|
||||||
static header *last_alloca_header = NULL; /* -> last alloca header. */
|
static header *last_alloca_header = NULL; /* -> last alloca header. */
|
||||||
|
|
||||||
/* Return a pointer to at least SIZE bytes of storage,
|
/* Return a pointer to at least SIZE bytes of storage,
|
||||||
which will be automatically reclaimed upon exit from
|
which will be automatically reclaimed upon exit from
|
||||||
the procedure that called alloca. Originally, this space
|
the procedure that called alloca. Originally, this space
|
||||||
was supposed to be taken from the current stack frame of the
|
was supposed to be taken from the current stack frame of the
|
||||||
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
|
||||||
was allocated from deeper in the stack than currently. */
|
was allocated from deeper in the stack than currently. */
|
||||||
|
|
||||||
{
|
{
|
||||||
register header *hp; /* Traverses linked list. */
|
register header *hp; /* Traverses linked list. */
|
||||||
|
|
||||||
#ifdef emacs
|
#ifdef emacs
|
||||||
BLOCK_INPUT;
|
BLOCK_INPUT;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
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. */
|
||||||
|
|
||||||
#ifdef emacs
|
#ifdef emacs
|
||||||
UNBLOCK_INPUT;
|
UNBLOCK_INPUT;
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
if (size == 0)
|
if (size == 0)
|
||||||
return NULL; /* No allocation required. */
|
return NULL; /* No allocation required. */
|
||||||
|
|
||||||
/* 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;
|
||||||
((header *) new)->h.deep = depth;
|
((header *) new)->h.deep = depth;
|
||||||
|
|
||||||
last_alloca_header = (header *) new;
|
last_alloca_header = (header *) new;
|
||||||
|
|
||||||
/* User storage begins just after header. */
|
/* User storage begins just after header. */
|
||||||
|
|
||||||
return (pointer) ((char *) new + sizeof (header));
|
return (pointer) ((char *) new + sizeof (header));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#if defined (CRAY) && defined (CRAY_STACKSEG_END)
|
#if defined (CRAY) && defined (CRAY_STACKSEG_END)
|
||||||
|
|
||||||
#ifdef DEBUG_I00AFUNC
|
#ifdef DEBUG_I00AFUNC
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifndef CRAY_STACK
|
#ifndef CRAY_STACK
|
||||||
#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
|
||||||
grows from low addresses to high addresses.) The initial
|
grows from low addresses to high addresses.) The initial
|
||||||
part of the stack segment linkage control information is
|
part of the stack segment linkage control information is
|
||||||
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. */
|
||||||
long:32;
|
long:32;
|
||||||
long sspseg:32; /* Offset to linkage control of previous
|
long sspseg:32; /* Offset to linkage control of previous
|
||||||
segment of stack. */
|
segment of stack. */
|
||||||
long:32;
|
long:32;
|
||||||
long sstcpt:32; /* Pointer to task common address block. */
|
long sstcpt:32; /* Pointer to task common address block. */
|
||||||
long sscsnm; /* Private control structure number for
|
long sscsnm; /* Private control structure number for
|
||||||
microtasking. */
|
microtasking. */
|
||||||
long ssusr1; /* Reserved for user. */
|
long ssusr1; /* Reserved for user. */
|
||||||
long ssusr2; /* Reserved for user. */
|
long ssusr2; /* Reserved for user. */
|
||||||
long sstpid; /* Process ID for pid based multi-tasking. */
|
long sstpid; /* Process ID for pid based multi-tasking. */
|
||||||
long ssgvup; /* Pointer to multitasking thread giveup. */
|
long ssgvup; /* Pointer to multitasking thread giveup. */
|
||||||
long sscray[7]; /* Reserved for Cray Research. */
|
long sscray[7]; /* Reserved for Cray Research. */
|
||||||
long ssa0;
|
long ssa0;
|
||||||
long ssa1;
|
long ssa1;
|
||||||
long ssa2;
|
long ssa2;
|
||||||
long ssa3;
|
long ssa3;
|
||||||
long ssa4;
|
long ssa4;
|
||||||
long ssa5;
|
long ssa5;
|
||||||
long ssa6;
|
long ssa6;
|
||||||
long ssa7;
|
long ssa7;
|
||||||
long sss0;
|
long sss0;
|
||||||
long sss1;
|
long sss1;
|
||||||
long sss2;
|
long sss2;
|
||||||
long sss3;
|
long sss3;
|
||||||
long sss4;
|
long sss4;
|
||||||
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
|
||||||
stack demand to date. */
|
stack demand to date. */
|
||||||
long high_water; /* Stack high-water mark. */
|
long high_water; /* Stack high-water mark. */
|
||||||
long overflows; /* Number of stack overflow ($STKOFEN) calls. */
|
long overflows; /* Number of stack overflow ($STKOFEN) calls. */
|
||||||
long hits; /* Number of internal buffer hits. */
|
long hits; /* Number of internal buffer hits. */
|
||||||
long extends; /* Number of block extensions. */
|
long extends; /* Number of block extensions. */
|
||||||
long stko_mallocs; /* Block allocations by $STKOFEN. */
|
long stko_mallocs; /* Block allocations by $STKOFEN. */
|
||||||
long underflows; /* Number of stack underflow calls ($STKRETN). */
|
long underflows; /* Number of stack underflow calls ($STKRETN). */
|
||||||
long stko_free; /* Number of deallocations by $STKRETN. */
|
long stko_free; /* Number of deallocations by $STKRETN. */
|
||||||
long stkm_free; /* Number of deallocations by $STKMRET. */
|
long stkm_free; /* Number of deallocations by $STKMRET. */
|
||||||
long segments; /* Current number of stack segments. */
|
long segments; /* Current number of stack segments. */
|
||||||
long maxs; /* Maximum number of stack segments so far. */
|
long maxs; /* Maximum number of stack segments so far. */
|
||||||
long pad_size; /* Stack pad size. */
|
long pad_size; /* Stack pad size. */
|
||||||
long current_address; /* Current stack segment address. */
|
long current_address; /* Current stack segment address. */
|
||||||
long current_size; /* Current stack segment size. This
|
long current_size; /* Current stack segment size. This
|
||||||
number is actually corrupted by STKSTAT to
|
number is actually corrupted by STKSTAT to
|
||||||
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). */
|
||||||
long unknown2;
|
long unknown2;
|
||||||
long unknown3;
|
long unknown3;
|
||||||
long link; /* Address of trailer block of previous
|
long link; /* Address of trailer block of previous
|
||||||
segment. */
|
segment. */
|
||||||
long unknown5;
|
long unknown5;
|
||||||
long unknown6;
|
long unknown6;
|
||||||
long unknown7;
|
long unknown7;
|
||||||
long unknown8;
|
long unknown8;
|
||||||
long unknown9;
|
long unknown9;
|
||||||
long unknown10;
|
long unknown10;
|
||||||
long unknown11;
|
long unknown11;
|
||||||
long unknown12;
|
long unknown12;
|
||||||
long unknown13;
|
long unknown13;
|
||||||
long unknown14;
|
long unknown14;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif /* CRAY2 */
|
#endif /* CRAY2 */
|
||||||
#endif /* not CRAY_STACK */
|
#endif /* not CRAY_STACK */
|
||||||
|
|
||||||
#ifdef CRAY2
|
#ifdef CRAY2
|
||||||
/* 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;
|
||||||
long *block, size;
|
long *block, size;
|
||||||
long result = 0;
|
long result = 0;
|
||||||
|
|
||||||
/* We want to iterate through all of the segments. The first
|
/* We want to iterate through all of the segments. The first
|
||||||
step is to get the stack status structure. We could do this
|
step is to get the stack status structure. We could do this
|
||||||
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;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Set the result to the offset in this segment and add the sizes
|
/* Set the result to the offset in this segment and add the sizes
|
||||||
of all predecessor segments. */
|
of all predecessor segments. */
|
||||||
|
|
||||||
result = address - block;
|
result = address - block;
|
||||||
|
|
||||||
if (trailer == 0)
|
if (trailer == 0)
|
||||||
{
|
{
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
do
|
do
|
||||||
{
|
{
|
||||||
if (trailer->this_size <= 0)
|
if (trailer->this_size <= 0)
|
||||||
abort ();
|
abort ();
|
||||||
result += trailer->this_size;
|
result += trailer->this_size;
|
||||||
trailer = (struct stk_trailer *) trailer->link;
|
trailer = (struct stk_trailer *) trailer->link;
|
||||||
}
|
}
|
||||||
while (trailer != 0);
|
while (trailer != 0);
|
||||||
|
|
||||||
/* We are done. Note that if you present a bogus address (one
|
/* We are done. Note that if you present a bogus address (one
|
||||||
not in any segment), you will get a different number back, formed
|
not in any segment), you will get a different number back, formed
|
||||||
from subtracting the address of the first block. This is probably
|
from subtracting the address of the first block. This is probably
|
||||||
not what you want. */
|
not what you want. */
|
||||||
|
|
||||||
return (result);
|
return (result);
|
||||||
}
|
}
|
||||||
|
|
||||||
#else /* not CRAY2 */
|
#else /* not CRAY2 */
|
||||||
/* Stack address function for a CRAY-1, CRAY X-MP, or CRAY Y-MP.
|
/* Stack address function for a CRAY-1, CRAY X-MP, or CRAY Y-MP.
|
||||||
Determine the number of the cell within the stack,
|
Determine the number of the cell within the stack,
|
||||||
given the address of the cell. The purpose of this
|
given the address of the cell. The purpose of this
|
||||||
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;
|
||||||
|
|
||||||
long size, pseg, this_segment, stack;
|
long size, pseg, this_segment, stack;
|
||||||
long result = 0;
|
long result = 0;
|
||||||
|
|
||||||
struct stack_segment_linkage *ssptr;
|
struct stack_segment_linkage *ssptr;
|
||||||
|
|
||||||
/* Register B67 contains the address of the end of the
|
/* Register B67 contains the address of the end of the
|
||||||
current stack segment. If you (as a subprogram) store
|
current stack segment. If you (as a subprogram) store
|
||||||
your registers on the stack and find that you are past
|
your registers on the stack and find that you are past
|
||||||
the contents of B67, you have overflowed the segment.
|
the contents of B67, you have overflowed the segment.
|
||||||
|
|
||||||
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.
|
||||||
|
|
||||||
If this is not the first segment, 'pseg' will be
|
If this is not the first segment, 'pseg' will be
|
||||||
nonzero. */
|
nonzero. */
|
||||||
|
|
||||||
pseg = ssptr->sspseg;
|
pseg = ssptr->sspseg;
|
||||||
size = ssptr->sssize;
|
size = ssptr->sssize;
|
||||||
|
|
||||||
this_segment = stkl - size;
|
this_segment = stkl - size;
|
||||||
|
|
||||||
/* It is possible that calling this routine itself caused
|
/* It is possible that calling this routine itself caused
|
||||||
a stack 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;
|
||||||
}
|
}
|
||||||
|
|
||||||
result = address - this_segment;
|
result = address - this_segment;
|
||||||
|
|
||||||
/* If you subtract pseg from the current end of the stack,
|
/* If you subtract pseg from the current end of the stack,
|
||||||
you get the address of the previous stack segment's end.
|
you get the address of the previous stack segment's end.
|
||||||
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;
|
||||||
}
|
}
|
||||||
return (result);
|
return (result);
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif /* not CRAY2 */
|
#endif /* not CRAY2 */
|
||||||
#endif /* CRAY */
|
#endif /* CRAY */
|
||||||
|
|
||||||
#endif /* no alloca */
|
#endif /* no alloca */
|
||||||
#endif /* not GCC version 2 */
|
#endif /* not GCC version 2 */
|
||||||
|
|||||||
820
src/asm/fstack.c
820
src/asm/fstack.c
@@ -1,411 +1,411 @@
|
|||||||
/*
|
/*
|
||||||
* RGBAsm - FSTACK.C (FileStack routines)
|
* RGBAsm - FSTACK.C (FileStack routines)
|
||||||
*
|
*
|
||||||
* INCLUDES
|
* INCLUDES
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include "symbol.h"
|
#include "symbol.h"
|
||||||
#include "fstack.h"
|
#include "fstack.h"
|
||||||
#include "types.h"
|
#include "types.h"
|
||||||
#include "main.h"
|
#include "main.h"
|
||||||
#include "lexer.h"
|
#include "lexer.h"
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* RGBAsm - FSTACK.C (FileStack routines)
|
* RGBAsm - FSTACK.C (FileStack routines)
|
||||||
*
|
*
|
||||||
* VARIABLES
|
* VARIABLES
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
struct sContext *pFileStack;
|
struct sContext *pFileStack;
|
||||||
struct sSymbol *pCurrentMacro;
|
struct sSymbol *pCurrentMacro;
|
||||||
YY_BUFFER_STATE CurrentFlexHandle;
|
YY_BUFFER_STATE CurrentFlexHandle;
|
||||||
FILE *pCurrentFile;
|
FILE *pCurrentFile;
|
||||||
ULONG nCurrentStatus;
|
ULONG nCurrentStatus;
|
||||||
char tzCurrentFileName[_MAX_PATH + 1];
|
char tzCurrentFileName[_MAX_PATH + 1];
|
||||||
char IncludePaths[MAXINCPATHS][_MAX_PATH + 1];
|
char IncludePaths[MAXINCPATHS][_MAX_PATH + 1];
|
||||||
SLONG NextIncPath = 0;
|
SLONG NextIncPath = 0;
|
||||||
ULONG nMacroCount;
|
ULONG nMacroCount;
|
||||||
|
|
||||||
char *pCurrentREPTBlock;
|
char *pCurrentREPTBlock;
|
||||||
ULONG nCurrentREPTBlockSize;
|
ULONG nCurrentREPTBlockSize;
|
||||||
ULONG nCurrentREPTBlockCount;
|
ULONG nCurrentREPTBlockCount;
|
||||||
|
|
||||||
ULONG ulMacroReturnValue;
|
ULONG ulMacroReturnValue;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* defines for nCurrentStatus
|
* defines for nCurrentStatus
|
||||||
*/
|
*/
|
||||||
#define STAT_isInclude 0
|
#define STAT_isInclude 0
|
||||||
#define STAT_isMacro 1
|
#define STAT_isMacro 1
|
||||||
#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);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* RGBAsm - FSTACK.C (FileStack routines)
|
* RGBAsm - FSTACK.C (FileStack routines)
|
||||||
*
|
*
|
||||||
* Context push and pop
|
* Context push and pop
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
void pushcontext (void)
|
void pushcontext (void)
|
||||||
{
|
{
|
||||||
struct sContext **ppFileStack;
|
struct sContext **ppFileStack;
|
||||||
|
|
||||||
ppFileStack = &pFileStack;
|
ppFileStack = &pFileStack;
|
||||||
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);
|
yy_delete_buffer (CurrentFlexHandle);
|
||||||
CurrentFlexHandle = yy_scan_bytes (pCurrentREPTBlock, nCurrentREPTBlockSize);
|
CurrentFlexHandle = yy_scan_bytes (pCurrentREPTBlock, 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, (char *)pLastFile->tzFileName);
|
||||||
switch (nCurrentStatus = pLastFile->nStatus)
|
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 ());
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* RGBAsm - FSTACK.C (FileStack routines)
|
* RGBAsm - FSTACK.C (FileStack routines)
|
||||||
*
|
*
|
||||||
* Dump the context stack to stdout
|
* Dump the context stack to stdout
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
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);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* RGBAsm - FSTACK.C (FileStack routines)
|
* RGBAsm - FSTACK.C (FileStack routines)
|
||||||
*
|
*
|
||||||
* Extra includepath stuff
|
* Extra includepath stuff
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
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);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* RGBAsm - FSTACK.C (FileStack routines)
|
* RGBAsm - FSTACK.C (FileStack routines)
|
||||||
*
|
*
|
||||||
* Set up an include file for parsing
|
* Set up an include file for parsing
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
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);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* RGBAsm - FSTACK.C (FileStack routines)
|
* RGBAsm - FSTACK.C (FileStack routines)
|
||||||
*
|
*
|
||||||
* Set up a macro for parsing
|
* Set up a macro for parsing
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
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_scan_bytes (pCurrentMacro->pMacro, pCurrentMacro->ulMacroSize);
|
||||||
yy_switch_to_buffer (CurrentFlexHandle);
|
yy_switch_to_buffer (CurrentFlexHandle);
|
||||||
return (1);
|
return (1);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
return (0);
|
return (0);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* RGBAsm - FSTACK.C (FileStack routines)
|
* RGBAsm - FSTACK.C (FileStack routines)
|
||||||
*
|
*
|
||||||
* Set up a macroargument for parsing
|
* Set up a macroargument for parsing
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
void fstk_RunMacroArg (SLONG s)
|
void fstk_RunMacroArg (SLONG s)
|
||||||
{
|
{
|
||||||
char *sym;
|
char *sym;
|
||||||
|
|
||||||
if (s == '@')
|
if (s == '@')
|
||||||
s = -1;
|
s = -1;
|
||||||
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");
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* RGBAsm - FSTACK.C (FileStack routines)
|
* RGBAsm - FSTACK.C (FileStack routines)
|
||||||
*
|
*
|
||||||
* Set up a stringequate for parsing
|
* Set up a stringequate for parsing
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
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_scan_bytes (pSym->pMacro, strlen (pSym->pMacro));
|
||||||
yy_switch_to_buffer (CurrentFlexHandle);
|
yy_switch_to_buffer (CurrentFlexHandle);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
yyerror ("No such string symbol");
|
yyerror ("No such string symbol");
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* RGBAsm - FSTACK.C (FileStack routines)
|
* RGBAsm - FSTACK.C (FileStack routines)
|
||||||
*
|
*
|
||||||
* Set up a repeat block for parsing
|
* Set up a repeat block for parsing
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
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_scan_bytes (pCurrentREPTBlock, nCurrentREPTBlockSize);
|
||||||
yy_switch_to_buffer (CurrentFlexHandle);
|
yy_switch_to_buffer (CurrentFlexHandle);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* RGBAsm - FSTACK.C (FileStack routines)
|
* RGBAsm - FSTACK.C (FileStack routines)
|
||||||
*
|
*
|
||||||
* Initialize the filestack routines
|
* Initialize the filestack routines
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
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);
|
||||||
}
|
}
|
||||||
@@ -1,154 +1,154 @@
|
|||||||
/* GB Z80 instruction groups
|
/* GB Z80 instruction groups
|
||||||
|
|
||||||
n3 = 3-bit
|
n3 = 3-bit
|
||||||
n = 8-bit
|
n = 8-bit
|
||||||
nn = 16-bit
|
nn = 16-bit
|
||||||
|
|
||||||
*ADC A,n : 0xCE
|
*ADC A,n : 0xCE
|
||||||
*ADC A,r : 0x88|r
|
*ADC A,r : 0x88|r
|
||||||
*ADD A,n : 0xC6
|
*ADD A,n : 0xC6
|
||||||
*ADD A,r : 0x80|r
|
*ADD A,r : 0x80|r
|
||||||
*ADD HL,ss : 0x09|(ss<<4)
|
*ADD HL,ss : 0x09|(ss<<4)
|
||||||
*ADD SP,n : 0xE8
|
*ADD SP,n : 0xE8
|
||||||
*AND A,n : 0xE6
|
*AND A,n : 0xE6
|
||||||
*AND A,r : 0xA0|r
|
*AND A,r : 0xA0|r
|
||||||
*BIT n3,r : 0xCB 0x40|(n3<<3)|r
|
*BIT n3,r : 0xCB 0x40|(n3<<3)|r
|
||||||
*CALL cc,nn : 0xC4|(cc<<3)
|
*CALL cc,nn : 0xC4|(cc<<3)
|
||||||
*CALL nn : 0xCD
|
*CALL nn : 0xCD
|
||||||
*CCF : 0x3F
|
*CCF : 0x3F
|
||||||
*CP A,n : 0xFE
|
*CP A,n : 0xFE
|
||||||
*CP A,r : 0xB8|r
|
*CP A,r : 0xB8|r
|
||||||
*CPL : 0x2F
|
*CPL : 0x2F
|
||||||
*DAA : 0x27
|
*DAA : 0x27
|
||||||
*DEC r : 0x05|(r<<3)
|
*DEC r : 0x05|(r<<3)
|
||||||
*DEC ss : 0x0B|(ss<<4)
|
*DEC ss : 0x0B|(ss<<4)
|
||||||
*DI : 0xF3
|
*DI : 0xF3
|
||||||
*EI : 0xFB
|
*EI : 0xFB
|
||||||
*EX HL,(SP) : 0xE3
|
*EX HL,(SP) : 0xE3
|
||||||
*HALT : 0x76
|
*HALT : 0x76
|
||||||
*INC r : 0x04|(r<<3)
|
*INC r : 0x04|(r<<3)
|
||||||
*INC ss : 0x03|(ss<<4)
|
*INC ss : 0x03|(ss<<4)
|
||||||
*JP (HL) : 0xE9
|
*JP (HL) : 0xE9
|
||||||
*JP cc,nn : 0xC2|(cc<<3)
|
*JP cc,nn : 0xC2|(cc<<3)
|
||||||
*JP nn : 0xC3|(cc<<3)
|
*JP nn : 0xC3|(cc<<3)
|
||||||
*JR n : 0x18
|
*JR n : 0x18
|
||||||
*JR cc,n : 0x20|(cc<<3)
|
*JR cc,n : 0x20|(cc<<3)
|
||||||
*LD (nn),SP : 0x08
|
*LD (nn),SP : 0x08
|
||||||
*LD ($FF00+C),A : 0xE2
|
*LD ($FF00+C),A : 0xE2
|
||||||
*LD ($FF00+n),A : 0xE0
|
*LD ($FF00+n),A : 0xE0
|
||||||
*LD (nn),A : 0xEA
|
*LD (nn),A : 0xEA
|
||||||
*LD (rr),A : 0x02|(rr<<4)
|
*LD (rr),A : 0x02|(rr<<4)
|
||||||
*LD A,($FF00+C) : 0xF2
|
*LD A,($FF00+C) : 0xF2
|
||||||
*LD A,($FF00+n) : 0xF0
|
*LD A,($FF00+n) : 0xF0
|
||||||
*LD A,(nn) : 0xFA
|
*LD A,(nn) : 0xFA
|
||||||
*LD A,(rr) : 0x0A|(rr<<4)
|
*LD A,(rr) : 0x0A|(rr<<4)
|
||||||
*LD HL,(SP+n) : 0xF8
|
*LD HL,(SP+n) : 0xF8
|
||||||
*LD SP,HL : 0xF9
|
*LD SP,HL : 0xF9
|
||||||
*LD r,n : 0x06|(r<<3)
|
*LD r,n : 0x06|(r<<3)
|
||||||
*LD r,r' : 0x40|(r<<3)|r' // NOTE: LD (HL),(HL) not allowed
|
*LD r,r' : 0x40|(r<<3)|r' // NOTE: LD (HL),(HL) not allowed
|
||||||
*LD ss,nn : 0x01|(ss<<4)
|
*LD ss,nn : 0x01|(ss<<4)
|
||||||
*NOP : 0x00
|
*NOP : 0x00
|
||||||
*OR A,n : 0xF6
|
*OR A,n : 0xF6
|
||||||
*OR A,r : 0xB0|r
|
*OR A,r : 0xB0|r
|
||||||
*POP tt : 0xC1|(tt<<4)
|
*POP tt : 0xC1|(tt<<4)
|
||||||
*PUSH tt : 0xC5|(tt<<4)
|
*PUSH tt : 0xC5|(tt<<4)
|
||||||
*RES n3,r : 0xCB 0x80|(n3<<3)|r
|
*RES n3,r : 0xCB 0x80|(n3<<3)|r
|
||||||
*RET : 0xC9
|
*RET : 0xC9
|
||||||
*RET cc : 0xC0|(cc<<3)
|
*RET cc : 0xC0|(cc<<3)
|
||||||
*RETI : 0xD9
|
*RETI : 0xD9
|
||||||
*RL r : 0xCB 0x10|r
|
*RL r : 0xCB 0x10|r
|
||||||
*RLA : 0x17
|
*RLA : 0x17
|
||||||
*RLC r : 0xCB 0x00|r
|
*RLC r : 0xCB 0x00|r
|
||||||
*RLCA : 0x07
|
*RLCA : 0x07
|
||||||
*RR r : 0xCB 0x18|r
|
*RR r : 0xCB 0x18|r
|
||||||
*RRA : 0x1F
|
*RRA : 0x1F
|
||||||
*RRC r : 0xCB 0x08|r
|
*RRC r : 0xCB 0x08|r
|
||||||
*RRCA : 0x0F
|
*RRCA : 0x0F
|
||||||
*RST n : 0xC7|n
|
*RST n : 0xC7|n
|
||||||
*SBC A,n : 0xDE
|
*SBC A,n : 0xDE
|
||||||
*SBC A,r : 0x98|r
|
*SBC A,r : 0x98|r
|
||||||
*SCF : 0x37
|
*SCF : 0x37
|
||||||
*SET n3,r : 0xCB 0xC0|(n8<<3)|r
|
*SET n3,r : 0xCB 0xC0|(n8<<3)|r
|
||||||
*SLA r : 0xCB 0x20|r
|
*SLA r : 0xCB 0x20|r
|
||||||
*SRA r : 0xCB 0x28|r
|
*SRA r : 0xCB 0x28|r
|
||||||
*SRL r : 0xCB 0x38|r
|
*SRL r : 0xCB 0x38|r
|
||||||
*STOP : 0x10
|
*STOP : 0x10
|
||||||
*SUB A,n : 0xD6
|
*SUB A,n : 0xD6
|
||||||
*SUB A,r : 0x90|r
|
*SUB A,r : 0x90|r
|
||||||
*SWAP r : 0xCB 0x30|r
|
*SWAP r : 0xCB 0x30|r
|
||||||
*XOR A,n : 0xEE
|
*XOR A,n : 0xEE
|
||||||
*XOR A,r : 0xA8|r
|
*XOR A,r : 0xA8|r
|
||||||
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#define MAXSECTIONSIZE 0x4000
|
#define MAXSECTIONSIZE 0x4000
|
||||||
|
|
||||||
#define ASM_DEFAULT_ENDIAN ASM_LITTLE_ENDIAN
|
#define ASM_DEFAULT_ENDIAN ASM_LITTLE_ENDIAN
|
||||||
|
|
||||||
#define APPNAME "RGBAsm"
|
#define APPNAME "RGBAsm"
|
||||||
#define EXENAME "rgbasm"
|
#define EXENAME "rgbasm"
|
||||||
|
|
||||||
#define NAME_DB "db"
|
#define NAME_DB "db"
|
||||||
#define NAME_DW "dw"
|
#define NAME_DW "dw"
|
||||||
#define NAME_RB "rb"
|
#define NAME_RB "rb"
|
||||||
#define NAME_RW "rw"
|
#define NAME_RW "rw"
|
||||||
|
|
||||||
/* "r" defs */
|
/* "r" defs */
|
||||||
|
|
||||||
enum
|
enum
|
||||||
{
|
{
|
||||||
REG_B=0,
|
REG_B=0,
|
||||||
REG_C,
|
REG_C,
|
||||||
REG_D,
|
REG_D,
|
||||||
REG_E,
|
REG_E,
|
||||||
REG_H,
|
REG_H,
|
||||||
REG_L,
|
REG_L,
|
||||||
REG_HL_IND,
|
REG_HL_IND,
|
||||||
REG_A
|
REG_A
|
||||||
};
|
};
|
||||||
|
|
||||||
/* "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,
|
||||||
};
|
};
|
||||||
|
|
||||||
/* "ss" defs */
|
/* "ss" defs */
|
||||||
|
|
||||||
enum
|
enum
|
||||||
{
|
{
|
||||||
REG_BC=0,
|
REG_BC=0,
|
||||||
REG_DE,
|
REG_DE,
|
||||||
REG_HL,
|
REG_HL,
|
||||||
REG_SP
|
REG_SP
|
||||||
};
|
};
|
||||||
|
|
||||||
/* "tt" defs */
|
/* "tt" defs */
|
||||||
|
|
||||||
/*
|
/*
|
||||||
#define REG_BC 0
|
#define REG_BC 0
|
||||||
#define REG_DE 1
|
#define REG_DE 1
|
||||||
#define REG_HL 2
|
#define REG_HL 2
|
||||||
*/
|
*/
|
||||||
#define REG_AF 3
|
#define REG_AF 3
|
||||||
|
|
||||||
/* "cc" defs */
|
/* "cc" defs */
|
||||||
|
|
||||||
enum
|
enum
|
||||||
{
|
{
|
||||||
CC_NZ=0,
|
CC_NZ=0,
|
||||||
CC_Z,
|
CC_Z,
|
||||||
CC_NC,
|
CC_NC,
|
||||||
CC_C
|
CC_C
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -1,89 +1,89 @@
|
|||||||
#include "symbol.h"
|
#include "symbol.h"
|
||||||
#include "lexer.h"
|
#include "lexer.h"
|
||||||
#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,
|
||||||
"bit", T_Z80_BIT,
|
"bit", T_Z80_BIT,
|
||||||
"call", T_Z80_CALL,
|
"call", T_Z80_CALL,
|
||||||
"ccf", T_Z80_CCF,
|
"ccf", T_Z80_CCF,
|
||||||
"cpl", T_Z80_CPL,
|
"cpl", T_Z80_CPL,
|
||||||
"cp", T_Z80_CP,
|
"cp", T_Z80_CP,
|
||||||
"daa", T_Z80_DAA,
|
"daa", T_Z80_DAA,
|
||||||
"dec", T_Z80_DEC,
|
"dec", T_Z80_DEC,
|
||||||
"di", T_Z80_DI,
|
"di", T_Z80_DI,
|
||||||
"ei", T_Z80_EI,
|
"ei", T_Z80_EI,
|
||||||
"ex", T_Z80_EX,
|
"ex", T_Z80_EX,
|
||||||
"halt", T_Z80_HALT,
|
"halt", T_Z80_HALT,
|
||||||
"inc", T_Z80_INC,
|
"inc", T_Z80_INC,
|
||||||
"jp", T_Z80_JP,
|
"jp", T_Z80_JP,
|
||||||
"jr", T_Z80_JR,
|
"jr", T_Z80_JR,
|
||||||
"ld", T_Z80_LD,
|
"ld", T_Z80_LD,
|
||||||
"ldi", T_Z80_LDI,
|
"ldi", T_Z80_LDI,
|
||||||
"ldd", T_Z80_LDD,
|
"ldd", T_Z80_LDD,
|
||||||
"ldio", T_Z80_LDIO,
|
"ldio", T_Z80_LDIO,
|
||||||
"ldh", T_Z80_LDIO,
|
"ldh", T_Z80_LDIO,
|
||||||
"nop", T_Z80_NOP,
|
"nop", T_Z80_NOP,
|
||||||
"or", T_Z80_OR,
|
"or", T_Z80_OR,
|
||||||
"pop", T_Z80_POP,
|
"pop", T_Z80_POP,
|
||||||
"push", T_Z80_PUSH,
|
"push", T_Z80_PUSH,
|
||||||
"res", T_Z80_RES,
|
"res", T_Z80_RES,
|
||||||
"reti", T_Z80_RETI,
|
"reti", T_Z80_RETI,
|
||||||
"ret", T_Z80_RET,
|
"ret", T_Z80_RET,
|
||||||
"rlca", T_Z80_RLCA,
|
"rlca", T_Z80_RLCA,
|
||||||
"rlc", T_Z80_RLC,
|
"rlc", T_Z80_RLC,
|
||||||
"rla", T_Z80_RLA,
|
"rla", T_Z80_RLA,
|
||||||
"rl", T_Z80_RL,
|
"rl", T_Z80_RL,
|
||||||
"rrc", T_Z80_RRC,
|
"rrc", T_Z80_RRC,
|
||||||
"rrca", T_Z80_RRCA,
|
"rrca", T_Z80_RRCA,
|
||||||
"rra", T_Z80_RRA,
|
"rra", T_Z80_RRA,
|
||||||
"rr", T_Z80_RR,
|
"rr", T_Z80_RR,
|
||||||
"rst", T_Z80_RST,
|
"rst", T_Z80_RST,
|
||||||
"sbc", T_Z80_SBC,
|
"sbc", T_Z80_SBC,
|
||||||
"scf", T_Z80_SCF,
|
"scf", T_Z80_SCF,
|
||||||
|
|
||||||
// Handled by globallex.c
|
// Handled by globallex.c
|
||||||
// "set" , T_POP_SET,
|
// "set" , T_POP_SET,
|
||||||
|
|
||||||
"sla", T_Z80_SLA,
|
"sla", T_Z80_SLA,
|
||||||
"sra", T_Z80_SRA,
|
"sra", T_Z80_SRA,
|
||||||
"srl", T_Z80_SRL,
|
"srl", T_Z80_SRL,
|
||||||
"stop", T_Z80_STOP,
|
"stop", T_Z80_STOP,
|
||||||
"sub", T_Z80_SUB,
|
"sub", T_Z80_SUB,
|
||||||
"swap", T_Z80_SWAP,
|
"swap", T_Z80_SWAP,
|
||||||
"xor", T_Z80_XOR,
|
"xor", T_Z80_XOR,
|
||||||
|
|
||||||
"nz", T_CC_NZ,
|
"nz", T_CC_NZ,
|
||||||
"z", T_CC_Z,
|
"z", T_CC_Z,
|
||||||
"nc", T_CC_NC,
|
"nc", T_CC_NC,
|
||||||
// "c" , T_MODE_C
|
// "c" , T_MODE_C
|
||||||
|
|
||||||
"[hl]", T_MODE_HL_IND,
|
"[hl]", T_MODE_HL_IND,
|
||||||
"[hl+]", T_MODE_HL_INDINC,
|
"[hl+]", T_MODE_HL_INDINC,
|
||||||
"[hl-]", T_MODE_HL_INDDEC,
|
"[hl-]", T_MODE_HL_INDDEC,
|
||||||
"[hli]", T_MODE_HL_INDINC,
|
"[hli]", T_MODE_HL_INDINC,
|
||||||
"[hld]", T_MODE_HL_INDDEC,
|
"[hld]", T_MODE_HL_INDDEC,
|
||||||
"hl", T_MODE_HL,
|
"hl", T_MODE_HL,
|
||||||
"af", T_MODE_AF,
|
"af", T_MODE_AF,
|
||||||
"[bc]", T_MODE_BC_IND,
|
"[bc]", T_MODE_BC_IND,
|
||||||
"bc", T_MODE_BC,
|
"bc", T_MODE_BC,
|
||||||
"[de]", T_MODE_DE_IND,
|
"[de]", T_MODE_DE_IND,
|
||||||
"de", T_MODE_DE,
|
"de", T_MODE_DE,
|
||||||
"[sp]", T_MODE_SP_IND,
|
"[sp]", T_MODE_SP_IND,
|
||||||
"sp", T_MODE_SP,
|
"sp", T_MODE_SP,
|
||||||
"a", T_MODE_A,
|
"a", T_MODE_A,
|
||||||
"b", T_MODE_B,
|
"b", T_MODE_B,
|
||||||
"[$ff00+c]", T_MODE_C_IND,
|
"[$ff00+c]", T_MODE_C_IND,
|
||||||
"[c]", T_MODE_C_IND,
|
"[c]", T_MODE_C_IND,
|
||||||
"c", T_MODE_C,
|
"c", T_MODE_C,
|
||||||
"d", T_MODE_D,
|
"d", T_MODE_D,
|
||||||
"e", T_MODE_E,
|
"e", T_MODE_E,
|
||||||
"h", T_MODE_H,
|
"h", T_MODE_H,
|
||||||
"l", T_MODE_L,
|
"l", T_MODE_L,
|
||||||
|
|
||||||
NULL, 0
|
NULL, 0
|
||||||
};
|
};
|
||||||
@@ -1,41 +1,41 @@
|
|||||||
%token T_SECT_BSS T_SECT_VRAM T_SECT_CODE T_SECT_HOME T_SECT_HRAM
|
%token T_SECT_BSS T_SECT_VRAM T_SECT_CODE T_SECT_HOME T_SECT_HRAM
|
||||||
|
|
||||||
%token T_Z80_ADC T_Z80_ADD T_Z80_AND
|
%token T_Z80_ADC T_Z80_ADD T_Z80_AND
|
||||||
%token T_Z80_BIT
|
%token T_Z80_BIT
|
||||||
%token T_Z80_CALL T_Z80_CCF T_Z80_CP T_Z80_CPL
|
%token T_Z80_CALL T_Z80_CCF T_Z80_CP T_Z80_CPL
|
||||||
%token T_Z80_DAA T_Z80_DEC T_Z80_DI
|
%token T_Z80_DAA T_Z80_DEC T_Z80_DI
|
||||||
%token T_Z80_EI T_Z80_EX
|
%token T_Z80_EI T_Z80_EX
|
||||||
%token T_Z80_HALT
|
%token T_Z80_HALT
|
||||||
%token T_Z80_INC
|
%token T_Z80_INC
|
||||||
%token T_Z80_JP T_Z80_JR
|
%token T_Z80_JP T_Z80_JR
|
||||||
%token T_Z80_LD
|
%token T_Z80_LD
|
||||||
%token T_Z80_LDI
|
%token T_Z80_LDI
|
||||||
%token T_Z80_LDD
|
%token T_Z80_LDD
|
||||||
%token T_Z80_LDIO
|
%token T_Z80_LDIO
|
||||||
%token T_Z80_NOP
|
%token T_Z80_NOP
|
||||||
%token T_Z80_OR
|
%token T_Z80_OR
|
||||||
%token T_Z80_POP T_Z80_PUSH
|
%token T_Z80_POP T_Z80_PUSH
|
||||||
%token T_Z80_RES T_Z80_RET T_Z80_RETI T_Z80_RST
|
%token T_Z80_RES T_Z80_RET T_Z80_RETI T_Z80_RST
|
||||||
%token T_Z80_RL T_Z80_RLA T_Z80_RLC T_Z80_RLCA
|
%token T_Z80_RL T_Z80_RLA T_Z80_RLC T_Z80_RLCA
|
||||||
%token T_Z80_RR T_Z80_RRA T_Z80_RRC T_Z80_RRCA
|
%token T_Z80_RR T_Z80_RRA T_Z80_RRC T_Z80_RRCA
|
||||||
%token T_Z80_SBC T_Z80_SCF T_Z80_STOP
|
%token T_Z80_SBC T_Z80_SCF T_Z80_STOP
|
||||||
%token T_Z80_SLA T_Z80_SRA T_Z80_SRL T_Z80_SUB T_Z80_SWAP
|
%token T_Z80_SLA T_Z80_SRA T_Z80_SRL T_Z80_SUB T_Z80_SWAP
|
||||||
%token T_Z80_XOR
|
%token T_Z80_XOR
|
||||||
|
|
||||||
%token T_MODE_A T_MODE_B T_MODE_C T_MODE_C_IND T_MODE_D T_MODE_E T_MODE_H T_MODE_L
|
%token T_MODE_A T_MODE_B T_MODE_C T_MODE_C_IND T_MODE_D T_MODE_E T_MODE_H T_MODE_L
|
||||||
%token T_MODE_AF
|
%token T_MODE_AF
|
||||||
%token T_MODE_BC T_MODE_BC_IND
|
%token T_MODE_BC T_MODE_BC_IND
|
||||||
%token T_MODE_DE T_MODE_DE_IND
|
%token T_MODE_DE T_MODE_DE_IND
|
||||||
%token T_MODE_SP T_MODE_SP_IND
|
%token T_MODE_SP T_MODE_SP_IND
|
||||||
%token T_MODE_HL T_MODE_HL_IND T_MODE_HL_INDDEC T_MODE_HL_INDINC
|
%token T_MODE_HL T_MODE_HL_IND T_MODE_HL_INDDEC T_MODE_HL_INDINC
|
||||||
%token T_CC_NZ T_CC_Z T_CC_NC
|
%token T_CC_NZ T_CC_Z T_CC_NC
|
||||||
|
|
||||||
%type <nConstValue> reg_r
|
%type <nConstValue> reg_r
|
||||||
%type <nConstValue> reg_ss
|
%type <nConstValue> reg_ss
|
||||||
%type <nConstValue> reg_rr
|
%type <nConstValue> reg_rr
|
||||||
%type <nConstValue> reg_tt
|
%type <nConstValue> reg_tt
|
||||||
%type <nConstValue> ccode
|
%type <nConstValue> ccode
|
||||||
%type <sVal> op_a_n
|
%type <sVal> op_a_n
|
||||||
%type <nConstValue> op_a_r
|
%type <nConstValue> op_a_r
|
||||||
%type <nConstValue> op_hl_ss
|
%type <nConstValue> op_hl_ss
|
||||||
%type <sVal> op_mem_ind
|
%type <sVal> op_mem_ind
|
||||||
|
|||||||
@@ -1,498 +1,498 @@
|
|||||||
section : T_POP_SECTION string ',' sectiontype
|
section : T_POP_SECTION string ',' sectiontype
|
||||||
{ out_NewSection($2,$4); }
|
{ out_NewSection($2,$4); }
|
||||||
| T_POP_SECTION string ',' sectiontype '[' const ']'
|
| T_POP_SECTION string ',' sectiontype '[' const ']'
|
||||||
{
|
{
|
||||||
if( $6>=0 && $6<0x10000 )
|
if( $6>=0 && $6<0x10000 )
|
||||||
out_NewAbsSection($2,$4,$6,-1);
|
out_NewAbsSection($2,$4,$6,-1);
|
||||||
else
|
else
|
||||||
yyerror( "Address must be 16-bit" );
|
yyerror( "Address must be 16-bit" );
|
||||||
}
|
}
|
||||||
| T_POP_SECTION string ',' sectiontype ',' T_OP_BANK '[' const ']'
|
| T_POP_SECTION string ',' sectiontype ',' T_OP_BANK '[' const ']'
|
||||||
{
|
{
|
||||||
if( $4==SECT_CODE )
|
if( $4==SECT_CODE )
|
||||||
{
|
{
|
||||||
if( $8>=1 && $8<=255 )
|
if( $8>=1 && $8<=255 )
|
||||||
out_NewAbsSection($2,$4,-1,$8);
|
out_NewAbsSection($2,$4,-1,$8);
|
||||||
else
|
else
|
||||||
yyerror( "BANK value out of range" );
|
yyerror( "BANK value out of range" );
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
yyerror( "BANK only allowed for CODE/DATA" );
|
yyerror( "BANK only allowed for CODE/DATA" );
|
||||||
}
|
}
|
||||||
| T_POP_SECTION string ',' sectiontype '[' const ']' ',' T_OP_BANK '[' const ']'
|
| T_POP_SECTION string ',' sectiontype '[' const ']' ',' T_OP_BANK '[' const ']'
|
||||||
{
|
{
|
||||||
if( $4==SECT_CODE )
|
if( $4==SECT_CODE )
|
||||||
{
|
{
|
||||||
if( $6>=0 && $6<0x10000 )
|
if( $6>=0 && $6<0x10000 )
|
||||||
{
|
{
|
||||||
if( $11>=1 && $11<=255 )
|
if( $11>=1 && $11<=255 )
|
||||||
out_NewAbsSection($2,$4,$6,$11);
|
out_NewAbsSection($2,$4,$6,$11);
|
||||||
else
|
else
|
||||||
yyerror( "BANK value out of range" );
|
yyerror( "BANK value out of range" );
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
yyerror( "Address must be 16-bit" );
|
yyerror( "Address must be 16-bit" );
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
yyerror( "BANK only allowed for CODE/DATA" );
|
yyerror( "BANK only allowed for CODE/DATA" );
|
||||||
}
|
}
|
||||||
;
|
;
|
||||||
|
|
||||||
sectiontype : T_SECT_BSS { $$=SECT_BSS; }
|
sectiontype : T_SECT_BSS { $$=SECT_BSS; }
|
||||||
| T_SECT_VRAM { $$=SECT_VRAM; }
|
| T_SECT_VRAM { $$=SECT_VRAM; }
|
||||||
| T_SECT_CODE { $$=SECT_CODE; }
|
| T_SECT_CODE { $$=SECT_CODE; }
|
||||||
| T_SECT_HOME { $$=SECT_HOME; }
|
| T_SECT_HOME { $$=SECT_HOME; }
|
||||||
| T_SECT_HRAM { $$=SECT_HRAM; }
|
| T_SECT_HRAM { $$=SECT_HRAM; }
|
||||||
;
|
;
|
||||||
|
|
||||||
|
|
||||||
cpu_command : z80_adc
|
cpu_command : z80_adc
|
||||||
| z80_add
|
| z80_add
|
||||||
| z80_and
|
| z80_and
|
||||||
| z80_bit
|
| z80_bit
|
||||||
| z80_call
|
| z80_call
|
||||||
| z80_ccf
|
| z80_ccf
|
||||||
| z80_cp
|
| z80_cp
|
||||||
| z80_cpl
|
| z80_cpl
|
||||||
| z80_daa
|
| z80_daa
|
||||||
| z80_dec
|
| z80_dec
|
||||||
| z80_di
|
| z80_di
|
||||||
| z80_ei
|
| z80_ei
|
||||||
| z80_ex
|
| z80_ex
|
||||||
| z80_halt
|
| z80_halt
|
||||||
| z80_inc
|
| z80_inc
|
||||||
| z80_jp
|
| z80_jp
|
||||||
| z80_jr
|
| z80_jr
|
||||||
| z80_ld
|
| z80_ld
|
||||||
| z80_ldd
|
| z80_ldd
|
||||||
| z80_ldi
|
| z80_ldi
|
||||||
| z80_ldio
|
| z80_ldio
|
||||||
| z80_nop
|
| z80_nop
|
||||||
| z80_or
|
| z80_or
|
||||||
| z80_pop
|
| z80_pop
|
||||||
| z80_push
|
| z80_push
|
||||||
| z80_res
|
| z80_res
|
||||||
| z80_ret
|
| z80_ret
|
||||||
| z80_reti
|
| z80_reti
|
||||||
| z80_rl
|
| z80_rl
|
||||||
| z80_rla
|
| z80_rla
|
||||||
| z80_rlc
|
| z80_rlc
|
||||||
| z80_rlca
|
| z80_rlca
|
||||||
| z80_rr
|
| z80_rr
|
||||||
| z80_rra
|
| z80_rra
|
||||||
| z80_rrc
|
| z80_rrc
|
||||||
| z80_rrca
|
| z80_rrca
|
||||||
| z80_rst
|
| z80_rst
|
||||||
| z80_sbc
|
| z80_sbc
|
||||||
| z80_scf
|
| z80_scf
|
||||||
| z80_set
|
| z80_set
|
||||||
| z80_sla
|
| z80_sla
|
||||||
| z80_sra
|
| z80_sra
|
||||||
| z80_srl
|
| z80_srl
|
||||||
| z80_stop
|
| z80_stop
|
||||||
| z80_sub
|
| z80_sub
|
||||||
| z80_swap
|
| z80_swap
|
||||||
| z80_xor
|
| z80_xor
|
||||||
;
|
;
|
||||||
|
|
||||||
z80_adc : T_Z80_ADC op_a_n { out_AbsByte(0xCE); out_RelByte(&$2); }
|
z80_adc : T_Z80_ADC op_a_n { out_AbsByte(0xCE); out_RelByte(&$2); }
|
||||||
| T_Z80_ADC op_a_r { out_AbsByte(0x88|$2); }
|
| T_Z80_ADC op_a_r { out_AbsByte(0x88|$2); }
|
||||||
;
|
;
|
||||||
|
|
||||||
z80_add : T_Z80_ADD op_a_n { out_AbsByte(0xC6); out_RelByte(&$2); }
|
z80_add : T_Z80_ADD op_a_n { out_AbsByte(0xC6); out_RelByte(&$2); }
|
||||||
| T_Z80_ADD op_a_r { out_AbsByte(0x80|$2); }
|
| T_Z80_ADD op_a_r { out_AbsByte(0x80|$2); }
|
||||||
| T_Z80_ADD op_hl_ss { out_AbsByte(0x09|($2<<4)); }
|
| T_Z80_ADD op_hl_ss { out_AbsByte(0x09|($2<<4)); }
|
||||||
| T_Z80_ADD T_MODE_SP comma const_8bit
|
| T_Z80_ADD T_MODE_SP comma const_8bit
|
||||||
{ out_AbsByte(0xE8); out_RelByte(&$4); }
|
{ out_AbsByte(0xE8); out_RelByte(&$4); }
|
||||||
|
|
||||||
;
|
;
|
||||||
|
|
||||||
z80_and : T_Z80_AND op_a_n { out_AbsByte(0xE6); out_RelByte(&$2); }
|
z80_and : T_Z80_AND op_a_n { out_AbsByte(0xE6); out_RelByte(&$2); }
|
||||||
| T_Z80_AND op_a_r { out_AbsByte(0xA0|$2); }
|
| T_Z80_AND op_a_r { out_AbsByte(0xA0|$2); }
|
||||||
;
|
;
|
||||||
|
|
||||||
z80_bit : T_Z80_BIT const_3bit comma reg_r
|
z80_bit : T_Z80_BIT const_3bit comma reg_r
|
||||||
{ out_AbsByte(0xCB); out_AbsByte(0x40|($2<<3)|$4); }
|
{ out_AbsByte(0xCB); out_AbsByte(0x40|($2<<3)|$4); }
|
||||||
;
|
;
|
||||||
|
|
||||||
z80_call : T_Z80_CALL const_16bit
|
z80_call : T_Z80_CALL const_16bit
|
||||||
{ out_AbsByte(0xCD); out_RelWord(&$2); }
|
{ out_AbsByte(0xCD); out_RelWord(&$2); }
|
||||||
| T_Z80_CALL ccode comma const_16bit
|
| T_Z80_CALL ccode comma const_16bit
|
||||||
{ out_AbsByte(0xC4|($2<<3)); out_RelWord(&$4); }
|
{ out_AbsByte(0xC4|($2<<3)); out_RelWord(&$4); }
|
||||||
;
|
;
|
||||||
|
|
||||||
z80_ccf : T_Z80_CCF
|
z80_ccf : T_Z80_CCF
|
||||||
{ out_AbsByte(0x3F); }
|
{ out_AbsByte(0x3F); }
|
||||||
;
|
;
|
||||||
|
|
||||||
z80_cp : T_Z80_CP op_a_n { out_AbsByte(0xFE); out_RelByte(&$2); }
|
z80_cp : T_Z80_CP op_a_n { out_AbsByte(0xFE); out_RelByte(&$2); }
|
||||||
| T_Z80_CP op_a_r { out_AbsByte(0xB8|$2); }
|
| T_Z80_CP op_a_r { out_AbsByte(0xB8|$2); }
|
||||||
;
|
;
|
||||||
|
|
||||||
z80_cpl : T_Z80_CPL { out_AbsByte(0x2F); }
|
z80_cpl : T_Z80_CPL { out_AbsByte(0x2F); }
|
||||||
;
|
;
|
||||||
|
|
||||||
z80_daa : T_Z80_DAA { out_AbsByte(0x27); }
|
z80_daa : T_Z80_DAA { out_AbsByte(0x27); }
|
||||||
;
|
;
|
||||||
|
|
||||||
z80_dec : T_Z80_DEC reg_r
|
z80_dec : T_Z80_DEC reg_r
|
||||||
{ out_AbsByte(0x05|($2<<3)); }
|
{ out_AbsByte(0x05|($2<<3)); }
|
||||||
| T_Z80_DEC reg_ss
|
| T_Z80_DEC reg_ss
|
||||||
{ out_AbsByte(0x0B|($2<<4)); }
|
{ out_AbsByte(0x0B|($2<<4)); }
|
||||||
;
|
;
|
||||||
|
|
||||||
z80_di : T_Z80_DI
|
z80_di : T_Z80_DI
|
||||||
{ out_AbsByte(0xF3); }
|
{ out_AbsByte(0xF3); }
|
||||||
;
|
;
|
||||||
|
|
||||||
z80_ei : T_Z80_EI
|
z80_ei : T_Z80_EI
|
||||||
{ out_AbsByte(0xFB); }
|
{ out_AbsByte(0xFB); }
|
||||||
;
|
;
|
||||||
|
|
||||||
z80_ex : T_Z80_EX T_MODE_HL comma T_MODE_SP_IND
|
z80_ex : T_Z80_EX T_MODE_HL comma T_MODE_SP_IND
|
||||||
{ out_AbsByte(0xE3); }
|
{ out_AbsByte(0xE3); }
|
||||||
| T_Z80_EX T_MODE_SP_IND comma T_MODE_HL
|
| T_Z80_EX T_MODE_SP_IND comma T_MODE_HL
|
||||||
{ out_AbsByte(0xE3); }
|
{ out_AbsByte(0xE3); }
|
||||||
;
|
;
|
||||||
|
|
||||||
z80_halt : T_Z80_HALT
|
z80_halt : T_Z80_HALT
|
||||||
{ out_AbsByte(0x76); out_AbsByte(0x00); }
|
{ out_AbsByte(0x76); out_AbsByte(0x00); }
|
||||||
;
|
;
|
||||||
|
|
||||||
z80_inc : T_Z80_INC reg_r
|
z80_inc : T_Z80_INC reg_r
|
||||||
{ out_AbsByte(0x04|($2<<3)); }
|
{ out_AbsByte(0x04|($2<<3)); }
|
||||||
| T_Z80_INC reg_ss
|
| T_Z80_INC reg_ss
|
||||||
{ out_AbsByte(0x03|($2<<4)); }
|
{ out_AbsByte(0x03|($2<<4)); }
|
||||||
;
|
;
|
||||||
|
|
||||||
z80_jp : T_Z80_JP const_16bit
|
z80_jp : T_Z80_JP const_16bit
|
||||||
{ out_AbsByte(0xC3); out_RelWord(&$2); }
|
{ out_AbsByte(0xC3); out_RelWord(&$2); }
|
||||||
| T_Z80_JP ccode comma const_16bit
|
| T_Z80_JP ccode comma const_16bit
|
||||||
{ out_AbsByte(0xC2|($2<<3)); out_RelWord(&$4); }
|
{ out_AbsByte(0xC2|($2<<3)); out_RelWord(&$4); }
|
||||||
| T_Z80_JP T_MODE_HL_IND
|
| T_Z80_JP T_MODE_HL_IND
|
||||||
{ out_AbsByte(0xE9); }
|
{ out_AbsByte(0xE9); }
|
||||||
;
|
;
|
||||||
|
|
||||||
z80_jr : T_Z80_JR const_PCrel
|
z80_jr : T_Z80_JR const_PCrel
|
||||||
{ out_AbsByte(0x18); out_PCRelByte(&$2); }
|
{ out_AbsByte(0x18); out_PCRelByte(&$2); }
|
||||||
| T_Z80_JR ccode comma const_PCrel
|
| T_Z80_JR ccode comma const_PCrel
|
||||||
{ out_AbsByte(0x20|($2<<3)); out_PCRelByte(&$4); }
|
{ out_AbsByte(0x20|($2<<3)); out_PCRelByte(&$4); }
|
||||||
;
|
;
|
||||||
|
|
||||||
z80_ldi : T_Z80_LDI T_MODE_HL_IND comma T_MODE_A
|
z80_ldi : T_Z80_LDI T_MODE_HL_IND comma T_MODE_A
|
||||||
{ out_AbsByte(0x02|(2<<4)); }
|
{ out_AbsByte(0x02|(2<<4)); }
|
||||||
| T_Z80_LDI T_MODE_A comma T_MODE_HL
|
| T_Z80_LDI T_MODE_A comma T_MODE_HL
|
||||||
{ out_AbsByte(0x0A|(2<<4)); }
|
{ out_AbsByte(0x0A|(2<<4)); }
|
||||||
;
|
;
|
||||||
|
|
||||||
z80_ldd : T_Z80_LDD T_MODE_HL_IND comma T_MODE_A
|
z80_ldd : T_Z80_LDD T_MODE_HL_IND comma T_MODE_A
|
||||||
{ out_AbsByte(0x02|(3<<4)); }
|
{ out_AbsByte(0x02|(3<<4)); }
|
||||||
| T_Z80_LDD T_MODE_A comma T_MODE_HL
|
| T_Z80_LDD T_MODE_A comma T_MODE_HL
|
||||||
{ out_AbsByte(0x0A|(3<<4)); }
|
{ out_AbsByte(0x0A|(3<<4)); }
|
||||||
;
|
;
|
||||||
|
|
||||||
z80_ldio : T_Z80_LDIO T_MODE_A comma op_mem_ind
|
z80_ldio : T_Z80_LDIO T_MODE_A comma op_mem_ind
|
||||||
{
|
{
|
||||||
rpn_CheckHRAM(&$4,&$4);
|
rpn_CheckHRAM(&$4,&$4);
|
||||||
|
|
||||||
if( (!rpn_isReloc(&$4))
|
if( (!rpn_isReloc(&$4))
|
||||||
&& ($4.nVal<0 || ($4.nVal>0xFF && $4.nVal<0xFF00) || $4.nVal>0xFFFF) )
|
&& ($4.nVal<0 || ($4.nVal>0xFF && $4.nVal<0xFF00) || $4.nVal>0xFFFF) )
|
||||||
{
|
{
|
||||||
yyerror( "Source must be in the IO/HRAM area" );
|
yyerror( "Source must be in the IO/HRAM area" );
|
||||||
}
|
}
|
||||||
|
|
||||||
out_AbsByte(0xF0);
|
out_AbsByte(0xF0);
|
||||||
$4.nVal&=0xFF;
|
$4.nVal&=0xFF;
|
||||||
out_RelByte(&$4);
|
out_RelByte(&$4);
|
||||||
}
|
}
|
||||||
| T_Z80_LDIO op_mem_ind comma T_MODE_A
|
| T_Z80_LDIO op_mem_ind comma T_MODE_A
|
||||||
{
|
{
|
||||||
rpn_CheckHRAM(&$2,&$2);
|
rpn_CheckHRAM(&$2,&$2);
|
||||||
|
|
||||||
if( (!rpn_isReloc(&$2))
|
if( (!rpn_isReloc(&$2))
|
||||||
&& ($2.nVal<0 || ($2.nVal>0xFF && $2.nVal<0xFF00) || $2.nVal>0xFFFF) )
|
&& ($2.nVal<0 || ($2.nVal>0xFF && $2.nVal<0xFF00) || $2.nVal>0xFFFF) )
|
||||||
{
|
{
|
||||||
yyerror( "Destination must be in the IO/HRAM area" );
|
yyerror( "Destination must be in the IO/HRAM area" );
|
||||||
}
|
}
|
||||||
|
|
||||||
out_AbsByte(0xE0);
|
out_AbsByte(0xE0);
|
||||||
$2.nVal&=0xFF;
|
$2.nVal&=0xFF;
|
||||||
out_RelByte(&$2);
|
out_RelByte(&$2);
|
||||||
}
|
}
|
||||||
;
|
;
|
||||||
|
|
||||||
z80_ld : z80_ld_mem
|
z80_ld : z80_ld_mem
|
||||||
| z80_ld_cind
|
| z80_ld_cind
|
||||||
| z80_ld_rr
|
| z80_ld_rr
|
||||||
| z80_ld_ss
|
| z80_ld_ss
|
||||||
| z80_ld_hl
|
| z80_ld_hl
|
||||||
| z80_ld_sp
|
| z80_ld_sp
|
||||||
| z80_ld_r
|
| z80_ld_r
|
||||||
| z80_ld_a
|
| z80_ld_a
|
||||||
;
|
;
|
||||||
|
|
||||||
z80_ld_hl : T_Z80_LD T_MODE_HL comma '[' T_MODE_SP const_8bit ']'
|
z80_ld_hl : T_Z80_LD T_MODE_HL comma '[' T_MODE_SP const_8bit ']'
|
||||||
{ out_AbsByte(0xF8); out_RelByte(&$6); }
|
{ out_AbsByte(0xF8); out_RelByte(&$6); }
|
||||||
| T_Z80_LD T_MODE_HL comma const_16bit
|
| T_Z80_LD T_MODE_HL comma const_16bit
|
||||||
{ out_AbsByte(0x01|(REG_HL<<4)); out_RelWord(&$4) }
|
{ out_AbsByte(0x01|(REG_HL<<4)); out_RelWord(&$4) }
|
||||||
;
|
;
|
||||||
z80_ld_sp : T_Z80_LD T_MODE_SP comma T_MODE_HL
|
z80_ld_sp : T_Z80_LD T_MODE_SP comma T_MODE_HL
|
||||||
{ out_AbsByte(0xF9); }
|
{ out_AbsByte(0xF9); }
|
||||||
| T_Z80_LD T_MODE_SP comma const_16bit
|
| T_Z80_LD T_MODE_SP comma const_16bit
|
||||||
{ out_AbsByte(0x01|(REG_SP<<4)); out_RelWord(&$4) }
|
{ out_AbsByte(0x01|(REG_SP<<4)); out_RelWord(&$4) }
|
||||||
;
|
;
|
||||||
|
|
||||||
z80_ld_mem : T_Z80_LD op_mem_ind comma T_MODE_SP
|
z80_ld_mem : T_Z80_LD op_mem_ind comma T_MODE_SP
|
||||||
{ out_AbsByte(0x08); out_RelWord(&$2); }
|
{ out_AbsByte(0x08); out_RelWord(&$2); }
|
||||||
| T_Z80_LD op_mem_ind comma T_MODE_A
|
| T_Z80_LD op_mem_ind comma T_MODE_A
|
||||||
{
|
{
|
||||||
if( (!rpn_isReloc(&$2)) && $2.nVal>=0xFF00)
|
if( (!rpn_isReloc(&$2)) && $2.nVal>=0xFF00)
|
||||||
{
|
{
|
||||||
out_AbsByte(0xE0);
|
out_AbsByte(0xE0);
|
||||||
out_AbsByte($2.nVal&0xFF);
|
out_AbsByte($2.nVal&0xFF);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
out_AbsByte(0xEA);
|
out_AbsByte(0xEA);
|
||||||
out_RelWord(&$2);
|
out_RelWord(&$2);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
;
|
;
|
||||||
|
|
||||||
z80_ld_cind : T_Z80_LD T_MODE_C_IND comma T_MODE_A
|
z80_ld_cind : T_Z80_LD T_MODE_C_IND comma T_MODE_A
|
||||||
{ out_AbsByte(0xE2); }
|
{ out_AbsByte(0xE2); }
|
||||||
;
|
;
|
||||||
|
|
||||||
z80_ld_rr : T_Z80_LD reg_rr comma T_MODE_A
|
z80_ld_rr : T_Z80_LD reg_rr comma T_MODE_A
|
||||||
{ out_AbsByte(0x02|($2<<4)); }
|
{ out_AbsByte(0x02|($2<<4)); }
|
||||||
;
|
;
|
||||||
|
|
||||||
z80_ld_r : T_Z80_LD reg_r comma const_8bit
|
z80_ld_r : T_Z80_LD reg_r comma const_8bit
|
||||||
{ out_AbsByte(0x06|($2<<3)); out_RelByte(&$4); }
|
{ out_AbsByte(0x06|($2<<3)); out_RelByte(&$4); }
|
||||||
| T_Z80_LD reg_r comma reg_r
|
| T_Z80_LD reg_r comma reg_r
|
||||||
{
|
{
|
||||||
if( ($2==REG_HL_IND) && ($4==REG_HL_IND) )
|
if( ($2==REG_HL_IND) && ($4==REG_HL_IND) )
|
||||||
{
|
{
|
||||||
yyerror( "LD (HL),(HL) not allowed" );
|
yyerror( "LD (HL),(HL) not allowed" );
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
out_AbsByte(0x40|($2<<3)|$4);
|
out_AbsByte(0x40|($2<<3)|$4);
|
||||||
}
|
}
|
||||||
;
|
;
|
||||||
|
|
||||||
z80_ld_a : T_Z80_LD reg_r comma T_MODE_C_IND
|
z80_ld_a : T_Z80_LD reg_r comma T_MODE_C_IND
|
||||||
{
|
{
|
||||||
if( $2==REG_A )
|
if( $2==REG_A )
|
||||||
out_AbsByte(0xF2);
|
out_AbsByte(0xF2);
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
yyerror( "Destination operand must be A" );
|
yyerror( "Destination operand must be A" );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
| T_Z80_LD reg_r comma reg_rr
|
| T_Z80_LD reg_r comma reg_rr
|
||||||
{
|
{
|
||||||
if( $2==REG_A )
|
if( $2==REG_A )
|
||||||
out_AbsByte(0x0A|($4<<4));
|
out_AbsByte(0x0A|($4<<4));
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
yyerror( "Destination operand must be A" );
|
yyerror( "Destination operand must be A" );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
| T_Z80_LD reg_r comma op_mem_ind
|
| T_Z80_LD reg_r comma op_mem_ind
|
||||||
{
|
{
|
||||||
if( $2==REG_A )
|
if( $2==REG_A )
|
||||||
{
|
{
|
||||||
if( (!rpn_isReloc(&$4)) && $4.nVal>=0xFF00 )
|
if( (!rpn_isReloc(&$4)) && $4.nVal>=0xFF00 )
|
||||||
{
|
{
|
||||||
out_AbsByte(0xF0);
|
out_AbsByte(0xF0);
|
||||||
out_AbsByte($4.nVal&0xFF);
|
out_AbsByte($4.nVal&0xFF);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
out_AbsByte(0xFA);
|
out_AbsByte(0xFA);
|
||||||
out_RelWord(&$4);
|
out_RelWord(&$4);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
yyerror( "Destination operand must be A" );
|
yyerror( "Destination operand must be A" );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
;
|
;
|
||||||
|
|
||||||
z80_ld_ss : T_Z80_LD reg_ss comma const_16bit
|
z80_ld_ss : T_Z80_LD reg_ss comma const_16bit
|
||||||
{ out_AbsByte(0x01|($2<<4)); out_RelWord(&$4) }
|
{ out_AbsByte(0x01|($2<<4)); out_RelWord(&$4) }
|
||||||
;
|
;
|
||||||
|
|
||||||
z80_nop : T_Z80_NOP
|
z80_nop : T_Z80_NOP
|
||||||
{ out_AbsByte(0x00); }
|
{ out_AbsByte(0x00); }
|
||||||
;
|
;
|
||||||
|
|
||||||
z80_or : T_Z80_OR op_a_n
|
z80_or : T_Z80_OR op_a_n
|
||||||
{ out_AbsByte(0xF6); out_RelByte(&$2); }
|
{ out_AbsByte(0xF6); out_RelByte(&$2); }
|
||||||
| T_Z80_OR op_a_r
|
| T_Z80_OR op_a_r
|
||||||
{ out_AbsByte(0xB0|$2); }
|
{ out_AbsByte(0xB0|$2); }
|
||||||
;
|
;
|
||||||
|
|
||||||
z80_pop : T_Z80_POP reg_tt
|
z80_pop : T_Z80_POP reg_tt
|
||||||
{ out_AbsByte(0xC1|($2<<4)); }
|
{ out_AbsByte(0xC1|($2<<4)); }
|
||||||
;
|
;
|
||||||
|
|
||||||
z80_push : T_Z80_PUSH reg_tt
|
z80_push : T_Z80_PUSH reg_tt
|
||||||
{ out_AbsByte(0xC5|($2<<4)); }
|
{ out_AbsByte(0xC5|($2<<4)); }
|
||||||
;
|
;
|
||||||
|
|
||||||
z80_res : T_Z80_RES const_3bit comma reg_r
|
z80_res : T_Z80_RES const_3bit comma reg_r
|
||||||
{ out_AbsByte(0xCB); out_AbsByte(0x80|($2<<3)|$4); }
|
{ out_AbsByte(0xCB); out_AbsByte(0x80|($2<<3)|$4); }
|
||||||
;
|
;
|
||||||
|
|
||||||
z80_ret : T_Z80_RET
|
z80_ret : T_Z80_RET
|
||||||
{ out_AbsByte(0xC9); }
|
{ out_AbsByte(0xC9); }
|
||||||
| T_Z80_RET ccode
|
| T_Z80_RET ccode
|
||||||
{ out_AbsByte(0xC0|($2<<3)); }
|
{ out_AbsByte(0xC0|($2<<3)); }
|
||||||
;
|
;
|
||||||
|
|
||||||
z80_reti : T_Z80_RETI
|
z80_reti : T_Z80_RETI
|
||||||
{ out_AbsByte(0xD9); }
|
{ out_AbsByte(0xD9); }
|
||||||
;
|
;
|
||||||
|
|
||||||
z80_rl : T_Z80_RL reg_r
|
z80_rl : T_Z80_RL reg_r
|
||||||
{ out_AbsByte(0xCB); out_AbsByte(0x10|$2); }
|
{ out_AbsByte(0xCB); out_AbsByte(0x10|$2); }
|
||||||
;
|
;
|
||||||
|
|
||||||
z80_rla : T_Z80_RLA
|
z80_rla : T_Z80_RLA
|
||||||
{ out_AbsByte(0x17); }
|
{ out_AbsByte(0x17); }
|
||||||
;
|
;
|
||||||
|
|
||||||
z80_rlc : T_Z80_RLC reg_r
|
z80_rlc : T_Z80_RLC reg_r
|
||||||
{ out_AbsByte(0xCB); out_AbsByte(0x00|$2); }
|
{ out_AbsByte(0xCB); out_AbsByte(0x00|$2); }
|
||||||
;
|
;
|
||||||
|
|
||||||
z80_rlca : T_Z80_RLCA
|
z80_rlca : T_Z80_RLCA
|
||||||
{ out_AbsByte(0x07); }
|
{ out_AbsByte(0x07); }
|
||||||
;
|
;
|
||||||
|
|
||||||
z80_rr : T_Z80_RR reg_r
|
z80_rr : T_Z80_RR reg_r
|
||||||
{ out_AbsByte(0xCB); out_AbsByte(0x18|$2); }
|
{ out_AbsByte(0xCB); out_AbsByte(0x18|$2); }
|
||||||
;
|
;
|
||||||
|
|
||||||
z80_rra : T_Z80_RRA
|
z80_rra : T_Z80_RRA
|
||||||
{ out_AbsByte(0x1F); }
|
{ out_AbsByte(0x1F); }
|
||||||
;
|
;
|
||||||
|
|
||||||
z80_rrc : T_Z80_RRC reg_r
|
z80_rrc : T_Z80_RRC reg_r
|
||||||
{ out_AbsByte(0xCB); out_AbsByte(0x08|$2); }
|
{ out_AbsByte(0xCB); out_AbsByte(0x08|$2); }
|
||||||
;
|
;
|
||||||
|
|
||||||
z80_rrca : T_Z80_RRCA
|
z80_rrca : T_Z80_RRCA
|
||||||
{ out_AbsByte(0x0F); }
|
{ out_AbsByte(0x0F); }
|
||||||
;
|
;
|
||||||
|
|
||||||
z80_rst : T_Z80_RST const_8bit
|
z80_rst : T_Z80_RST const_8bit
|
||||||
{
|
{
|
||||||
if( rpn_isReloc(&$2) )
|
if( rpn_isReloc(&$2) )
|
||||||
{
|
{
|
||||||
yyerror( "Address for RST must be absolute" );
|
yyerror( "Address for RST must be absolute" );
|
||||||
}
|
}
|
||||||
else if( ($2.nVal&0x38)!=$2.nVal )
|
else if( ($2.nVal&0x38)!=$2.nVal )
|
||||||
{
|
{
|
||||||
yyerror( "Invalid address for RST" );
|
yyerror( "Invalid address for RST" );
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
out_AbsByte(0xC7|$2.nVal);
|
out_AbsByte(0xC7|$2.nVal);
|
||||||
}
|
}
|
||||||
;
|
;
|
||||||
|
|
||||||
z80_sbc : T_Z80_SBC op_a_n { out_AbsByte(0xDE); out_RelByte(&$2); }
|
z80_sbc : T_Z80_SBC op_a_n { out_AbsByte(0xDE); out_RelByte(&$2); }
|
||||||
| T_Z80_SBC op_a_r { out_AbsByte(0x98|$2); }
|
| T_Z80_SBC op_a_r { out_AbsByte(0x98|$2); }
|
||||||
;
|
;
|
||||||
|
|
||||||
z80_scf : T_Z80_SCF
|
z80_scf : T_Z80_SCF
|
||||||
{ out_AbsByte(0x37); }
|
{ out_AbsByte(0x37); }
|
||||||
;
|
;
|
||||||
|
|
||||||
z80_set : T_POP_SET const_3bit comma reg_r
|
z80_set : T_POP_SET const_3bit comma reg_r
|
||||||
{ out_AbsByte(0xCB); out_AbsByte(0xC0|($2<<3)|$4); }
|
{ out_AbsByte(0xCB); out_AbsByte(0xC0|($2<<3)|$4); }
|
||||||
;
|
;
|
||||||
|
|
||||||
z80_sla : T_Z80_SLA reg_r
|
z80_sla : T_Z80_SLA reg_r
|
||||||
{ out_AbsByte(0xCB); out_AbsByte(0x20|$2); }
|
{ out_AbsByte(0xCB); out_AbsByte(0x20|$2); }
|
||||||
;
|
;
|
||||||
|
|
||||||
z80_sra : T_Z80_SRA reg_r
|
z80_sra : T_Z80_SRA reg_r
|
||||||
{ out_AbsByte(0xCB); out_AbsByte(0x28|$2); }
|
{ out_AbsByte(0xCB); out_AbsByte(0x28|$2); }
|
||||||
;
|
;
|
||||||
|
|
||||||
z80_srl : T_Z80_SRL reg_r
|
z80_srl : T_Z80_SRL reg_r
|
||||||
{ out_AbsByte(0xCB); out_AbsByte(0x38|$2); }
|
{ out_AbsByte(0xCB); out_AbsByte(0x38|$2); }
|
||||||
;
|
;
|
||||||
|
|
||||||
z80_stop : T_Z80_STOP
|
z80_stop : T_Z80_STOP
|
||||||
{ out_AbsByte(0x10); out_AbsByte(0x00); }
|
{ out_AbsByte(0x10); out_AbsByte(0x00); }
|
||||||
;
|
;
|
||||||
|
|
||||||
z80_sub : T_Z80_SUB op_a_n { out_AbsByte(0xD6); out_RelByte(&$2); }
|
z80_sub : T_Z80_SUB op_a_n { out_AbsByte(0xD6); out_RelByte(&$2); }
|
||||||
| T_Z80_SUB op_a_r { out_AbsByte(0x90|$2); }
|
| T_Z80_SUB op_a_r { out_AbsByte(0x90|$2); }
|
||||||
;
|
;
|
||||||
|
|
||||||
z80_swap : T_Z80_SWAP reg_r
|
z80_swap : T_Z80_SWAP reg_r
|
||||||
{ out_AbsByte(0xCB); out_AbsByte(0x30|$2); }
|
{ out_AbsByte(0xCB); out_AbsByte(0x30|$2); }
|
||||||
;
|
;
|
||||||
|
|
||||||
z80_xor : T_Z80_XOR op_a_n { out_AbsByte(0xEE); out_RelByte(&$2); }
|
z80_xor : T_Z80_XOR op_a_n { out_AbsByte(0xEE); out_RelByte(&$2); }
|
||||||
| T_Z80_XOR op_a_r { out_AbsByte(0xA8|$2); }
|
| T_Z80_XOR op_a_r { out_AbsByte(0xA8|$2); }
|
||||||
;
|
;
|
||||||
|
|
||||||
op_mem_ind : '[' const_16bit ']' { $$ = $2 }
|
op_mem_ind : '[' const_16bit ']' { $$ = $2 }
|
||||||
;
|
;
|
||||||
|
|
||||||
op_hl_ss : reg_ss { $$ = $1 }
|
op_hl_ss : reg_ss { $$ = $1 }
|
||||||
| T_MODE_HL comma reg_ss { $$ = $3 }
|
| T_MODE_HL comma reg_ss { $$ = $3 }
|
||||||
;
|
;
|
||||||
|
|
||||||
op_a_r : reg_r { $$ = $1 }
|
op_a_r : reg_r { $$ = $1 }
|
||||||
| T_MODE_A comma reg_r { $$ = $3 }
|
| T_MODE_A comma reg_r { $$ = $3 }
|
||||||
;
|
;
|
||||||
|
|
||||||
op_a_n : const_8bit { $$ = $1 }
|
op_a_n : const_8bit { $$ = $1 }
|
||||||
| T_MODE_A comma const_8bit { $$ = $3 }
|
| T_MODE_A comma const_8bit { $$ = $3 }
|
||||||
;
|
;
|
||||||
|
|
||||||
comma : ','
|
comma : ','
|
||||||
;
|
;
|
||||||
|
|
||||||
ccode : T_CC_NZ { $$ = CC_NZ }
|
ccode : T_CC_NZ { $$ = CC_NZ }
|
||||||
| T_CC_Z { $$ = CC_Z }
|
| T_CC_Z { $$ = CC_Z }
|
||||||
| T_CC_NC { $$ = CC_NC }
|
| T_CC_NC { $$ = CC_NC }
|
||||||
| T_MODE_C { $$ = CC_C }
|
| T_MODE_C { $$ = CC_C }
|
||||||
;
|
;
|
||||||
|
|
||||||
reg_r : T_MODE_B { $$ = REG_B }
|
reg_r : T_MODE_B { $$ = REG_B }
|
||||||
| T_MODE_C { $$ = REG_C }
|
| T_MODE_C { $$ = REG_C }
|
||||||
| T_MODE_D { $$ = REG_D }
|
| T_MODE_D { $$ = REG_D }
|
||||||
| T_MODE_E { $$ = REG_E }
|
| T_MODE_E { $$ = REG_E }
|
||||||
| T_MODE_H { $$ = REG_H }
|
| T_MODE_H { $$ = REG_H }
|
||||||
| T_MODE_L { $$ = REG_L }
|
| T_MODE_L { $$ = REG_L }
|
||||||
| T_MODE_HL_IND { $$ = REG_HL_IND }
|
| T_MODE_HL_IND { $$ = REG_HL_IND }
|
||||||
| T_MODE_A { $$ = REG_A }
|
| T_MODE_A { $$ = REG_A }
|
||||||
;
|
;
|
||||||
|
|
||||||
reg_tt : T_MODE_BC { $$ = REG_BC }
|
reg_tt : T_MODE_BC { $$ = REG_BC }
|
||||||
| T_MODE_DE { $$ = REG_DE }
|
| T_MODE_DE { $$ = REG_DE }
|
||||||
| T_MODE_HL { $$ = REG_HL }
|
| T_MODE_HL { $$ = REG_HL }
|
||||||
| T_MODE_AF { $$ = REG_AF }
|
| T_MODE_AF { $$ = REG_AF }
|
||||||
;
|
;
|
||||||
|
|
||||||
reg_ss : T_MODE_BC { $$ = REG_BC }
|
reg_ss : T_MODE_BC { $$ = REG_BC }
|
||||||
| T_MODE_DE { $$ = REG_DE }
|
| T_MODE_DE { $$ = REG_DE }
|
||||||
| T_MODE_HL { $$ = REG_HL }
|
| T_MODE_HL { $$ = REG_HL }
|
||||||
| T_MODE_SP { $$ = REG_SP }
|
| T_MODE_SP { $$ = REG_SP }
|
||||||
;
|
;
|
||||||
|
|
||||||
reg_rr : T_MODE_BC_IND { $$ = REG_BC_IND }
|
reg_rr : T_MODE_BC_IND { $$ = REG_BC_IND }
|
||||||
| T_MODE_DE_IND { $$ = REG_DE_IND }
|
| T_MODE_DE_IND { $$ = REG_DE_IND }
|
||||||
| T_MODE_HL_INDINC { $$ = REG_HL_INDINC }
|
| T_MODE_HL_INDINC { $$ = REG_HL_INDINC }
|
||||||
| T_MODE_HL_INDDEC { $$ = REG_HL_INDDEC }
|
| T_MODE_HL_INDDEC { $$ = REG_HL_INDDEC }
|
||||||
;
|
;
|
||||||
|
|
||||||
%%
|
%%
|
||||||
1024
src/asm/globlex.c
1024
src/asm/globlex.c
File diff suppressed because it is too large
Load Diff
@@ -1,33 +1,33 @@
|
|||||||
/* asm.h
|
/* asm.h
|
||||||
*
|
*
|
||||||
* Contains some assembler-wide defines and externs
|
* Contains some assembler-wide defines and externs
|
||||||
*
|
*
|
||||||
* Copyright 1997 Carsten Sorensen
|
* Copyright 1997 Carsten Sorensen
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#ifndef ASM_H
|
#ifndef ASM_H
|
||||||
#define ASM_H
|
#define ASM_H
|
||||||
|
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include "types.h"
|
#include "types.h"
|
||||||
#include "symbol.h"
|
#include "symbol.h"
|
||||||
#include "localasm.h"
|
#include "localasm.h"
|
||||||
#include "asmotor.h"
|
#include "asmotor.h"
|
||||||
|
|
||||||
extern SLONG nLineNo;
|
extern SLONG nLineNo;
|
||||||
extern ULONG nTotalLines;
|
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;
|
||||||
extern UBYTE oDontExpandStrings;
|
extern UBYTE oDontExpandStrings;
|
||||||
|
|
||||||
#define MAXMACROARGS 9
|
#define MAXMACROARGS 9
|
||||||
#define MAXINCPATHS 16
|
#define MAXINCPATHS 16
|
||||||
|
|
||||||
#endif // ASM_H
|
#endif // ASM_H
|
||||||
@@ -1,42 +1,42 @@
|
|||||||
/* fstack.h
|
/* fstack.h
|
||||||
*
|
*
|
||||||
* Contains some assembler-wide defines and externs
|
* Contains some assembler-wide defines and externs
|
||||||
*
|
*
|
||||||
* Copyright 1997 Carsten Sorensen
|
* Copyright 1997 Carsten Sorensen
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#ifndef FSTACK_H
|
#ifndef FSTACK_H
|
||||||
#define FSTACK_H
|
#define FSTACK_H
|
||||||
|
|
||||||
#include "asm.h"
|
#include "asm.h"
|
||||||
#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;
|
||||||
char *pREPTBlock;
|
char *pREPTBlock;
|
||||||
ULONG nREPTBlockCount;
|
ULONG nREPTBlockCount;
|
||||||
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,153 +1,153 @@
|
|||||||
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;
|
||||||
} YYSTYPE;
|
} YYSTYPE;
|
||||||
#define T_NUMBER 258
|
#define T_NUMBER 258
|
||||||
#define T_STRING 259
|
#define T_STRING 259
|
||||||
#define T_OP_LOGICNOT 260
|
#define T_OP_LOGICNOT 260
|
||||||
#define T_OP_LOGICOR 261
|
#define T_OP_LOGICOR 261
|
||||||
#define T_OP_LOGICAND 262
|
#define T_OP_LOGICAND 262
|
||||||
#define T_OP_LOGICEQU 263
|
#define T_OP_LOGICEQU 263
|
||||||
#define T_OP_LOGICGT 264
|
#define T_OP_LOGICGT 264
|
||||||
#define T_OP_LOGICLT 265
|
#define T_OP_LOGICLT 265
|
||||||
#define T_OP_LOGICGE 266
|
#define T_OP_LOGICGE 266
|
||||||
#define T_OP_LOGICLE 267
|
#define T_OP_LOGICLE 267
|
||||||
#define T_OP_LOGICNE 268
|
#define T_OP_LOGICNE 268
|
||||||
#define T_OP_ADD 269
|
#define T_OP_ADD 269
|
||||||
#define T_OP_SUB 270
|
#define T_OP_SUB 270
|
||||||
#define T_OP_OR 271
|
#define T_OP_OR 271
|
||||||
#define T_OP_XOR 272
|
#define T_OP_XOR 272
|
||||||
#define T_OP_AND 273
|
#define T_OP_AND 273
|
||||||
#define T_OP_SHL 274
|
#define T_OP_SHL 274
|
||||||
#define T_OP_SHR 275
|
#define T_OP_SHR 275
|
||||||
#define T_OP_MUL 276
|
#define T_OP_MUL 276
|
||||||
#define T_OP_DIV 277
|
#define T_OP_DIV 277
|
||||||
#define T_OP_MOD 278
|
#define T_OP_MOD 278
|
||||||
#define T_OP_NOT 279
|
#define T_OP_NOT 279
|
||||||
#define T_OP_DEF 280
|
#define T_OP_DEF 280
|
||||||
#define T_OP_BANK 281
|
#define T_OP_BANK 281
|
||||||
#define T_OP_SIN 282
|
#define T_OP_SIN 282
|
||||||
#define T_OP_COS 283
|
#define T_OP_COS 283
|
||||||
#define T_OP_TAN 284
|
#define T_OP_TAN 284
|
||||||
#define T_OP_ASIN 285
|
#define T_OP_ASIN 285
|
||||||
#define T_OP_ACOS 286
|
#define T_OP_ACOS 286
|
||||||
#define T_OP_ATAN 287
|
#define T_OP_ATAN 287
|
||||||
#define T_OP_ATAN2 288
|
#define T_OP_ATAN2 288
|
||||||
#define T_OP_FDIV 289
|
#define T_OP_FDIV 289
|
||||||
#define T_OP_FMUL 290
|
#define T_OP_FMUL 290
|
||||||
#define T_OP_STRCMP 291
|
#define T_OP_STRCMP 291
|
||||||
#define T_OP_STRIN 292
|
#define T_OP_STRIN 292
|
||||||
#define T_OP_STRSUB 293
|
#define T_OP_STRSUB 293
|
||||||
#define T_OP_STRLEN 294
|
#define T_OP_STRLEN 294
|
||||||
#define T_OP_STRCAT 295
|
#define T_OP_STRCAT 295
|
||||||
#define T_OP_STRUPR 296
|
#define T_OP_STRUPR 296
|
||||||
#define T_OP_STRLWR 297
|
#define T_OP_STRLWR 297
|
||||||
#define NEG 298
|
#define NEG 298
|
||||||
#define T_LABEL 299
|
#define T_LABEL 299
|
||||||
#define T_ID 300
|
#define T_ID 300
|
||||||
#define T_POP_EQU 301
|
#define T_POP_EQU 301
|
||||||
#define T_POP_SET 302
|
#define T_POP_SET 302
|
||||||
#define T_POP_EQUS 303
|
#define T_POP_EQUS 303
|
||||||
#define T_POP_INCLUDE 304
|
#define T_POP_INCLUDE 304
|
||||||
#define T_POP_PRINTF 305
|
#define T_POP_PRINTF 305
|
||||||
#define T_POP_PRINTT 306
|
#define T_POP_PRINTT 306
|
||||||
#define T_POP_PRINTV 307
|
#define T_POP_PRINTV 307
|
||||||
#define T_POP_IF 308
|
#define T_POP_IF 308
|
||||||
#define T_POP_ELSE 309
|
#define T_POP_ELSE 309
|
||||||
#define T_POP_ENDC 310
|
#define T_POP_ENDC 310
|
||||||
#define T_POP_IMPORT 311
|
#define T_POP_IMPORT 311
|
||||||
#define T_POP_EXPORT 312
|
#define T_POP_EXPORT 312
|
||||||
#define T_POP_GLOBAL 313
|
#define T_POP_GLOBAL 313
|
||||||
#define T_POP_DB 314
|
#define T_POP_DB 314
|
||||||
#define T_POP_DS 315
|
#define T_POP_DS 315
|
||||||
#define T_POP_DW 316
|
#define T_POP_DW 316
|
||||||
#define T_POP_SECTION 317
|
#define T_POP_SECTION 317
|
||||||
#define T_POP_RB 318
|
#define T_POP_RB 318
|
||||||
#define T_POP_RW 319
|
#define T_POP_RW 319
|
||||||
#define T_POP_MACRO 320
|
#define T_POP_MACRO 320
|
||||||
#define T_POP_ENDM 321
|
#define T_POP_ENDM 321
|
||||||
#define T_POP_RSRESET 322
|
#define T_POP_RSRESET 322
|
||||||
#define T_POP_RSSET 323
|
#define T_POP_RSSET 323
|
||||||
#define T_POP_INCBIN 324
|
#define T_POP_INCBIN 324
|
||||||
#define T_POP_REPT 325
|
#define T_POP_REPT 325
|
||||||
#define T_POP_SHIFT 326
|
#define T_POP_SHIFT 326
|
||||||
#define T_POP_ENDR 327
|
#define T_POP_ENDR 327
|
||||||
#define T_POP_FAIL 328
|
#define T_POP_FAIL 328
|
||||||
#define T_POP_WARN 329
|
#define T_POP_WARN 329
|
||||||
#define T_SECT_BSS 330
|
#define T_SECT_BSS 330
|
||||||
#define T_SECT_VRAM 331
|
#define T_SECT_VRAM 331
|
||||||
#define T_SECT_CODE 332
|
#define T_SECT_CODE 332
|
||||||
#define T_SECT_HOME 333
|
#define T_SECT_HOME 333
|
||||||
#define T_SECT_HRAM 334
|
#define T_SECT_HRAM 334
|
||||||
#define T_Z80_ADC 335
|
#define T_Z80_ADC 335
|
||||||
#define T_Z80_ADD 336
|
#define T_Z80_ADD 336
|
||||||
#define T_Z80_AND 337
|
#define T_Z80_AND 337
|
||||||
#define T_Z80_BIT 338
|
#define T_Z80_BIT 338
|
||||||
#define T_Z80_CALL 339
|
#define T_Z80_CALL 339
|
||||||
#define T_Z80_CCF 340
|
#define T_Z80_CCF 340
|
||||||
#define T_Z80_CP 341
|
#define T_Z80_CP 341
|
||||||
#define T_Z80_CPL 342
|
#define T_Z80_CPL 342
|
||||||
#define T_Z80_DAA 343
|
#define T_Z80_DAA 343
|
||||||
#define T_Z80_DEC 344
|
#define T_Z80_DEC 344
|
||||||
#define T_Z80_DI 345
|
#define T_Z80_DI 345
|
||||||
#define T_Z80_EI 346
|
#define T_Z80_EI 346
|
||||||
#define T_Z80_EX 347
|
#define T_Z80_EX 347
|
||||||
#define T_Z80_HALT 348
|
#define T_Z80_HALT 348
|
||||||
#define T_Z80_INC 349
|
#define T_Z80_INC 349
|
||||||
#define T_Z80_JP 350
|
#define T_Z80_JP 350
|
||||||
#define T_Z80_JR 351
|
#define T_Z80_JR 351
|
||||||
#define T_Z80_LD 352
|
#define T_Z80_LD 352
|
||||||
#define T_Z80_LDIO 353
|
#define T_Z80_LDIO 353
|
||||||
#define T_Z80_NOP 354
|
#define T_Z80_NOP 354
|
||||||
#define T_Z80_OR 355
|
#define T_Z80_OR 355
|
||||||
#define T_Z80_POP 356
|
#define T_Z80_POP 356
|
||||||
#define T_Z80_PUSH 357
|
#define T_Z80_PUSH 357
|
||||||
#define T_Z80_RES 358
|
#define T_Z80_RES 358
|
||||||
#define T_Z80_RET 359
|
#define T_Z80_RET 359
|
||||||
#define T_Z80_RETI 360
|
#define T_Z80_RETI 360
|
||||||
#define T_Z80_RST 361
|
#define T_Z80_RST 361
|
||||||
#define T_Z80_RL 362
|
#define T_Z80_RL 362
|
||||||
#define T_Z80_RLA 363
|
#define T_Z80_RLA 363
|
||||||
#define T_Z80_RLC 364
|
#define T_Z80_RLC 364
|
||||||
#define T_Z80_RLCA 365
|
#define T_Z80_RLCA 365
|
||||||
#define T_Z80_RR 366
|
#define T_Z80_RR 366
|
||||||
#define T_Z80_RRA 367
|
#define T_Z80_RRA 367
|
||||||
#define T_Z80_RRC 368
|
#define T_Z80_RRC 368
|
||||||
#define T_Z80_RRCA 369
|
#define T_Z80_RRCA 369
|
||||||
#define T_Z80_SBC 370
|
#define T_Z80_SBC 370
|
||||||
#define T_Z80_SCF 371
|
#define T_Z80_SCF 371
|
||||||
#define T_Z80_STOP 372
|
#define T_Z80_STOP 372
|
||||||
#define T_Z80_SLA 373
|
#define T_Z80_SLA 373
|
||||||
#define T_Z80_SRA 374
|
#define T_Z80_SRA 374
|
||||||
#define T_Z80_SRL 375
|
#define T_Z80_SRL 375
|
||||||
#define T_Z80_SUB 376
|
#define T_Z80_SUB 376
|
||||||
#define T_Z80_SWAP 377
|
#define T_Z80_SWAP 377
|
||||||
#define T_Z80_XOR 378
|
#define T_Z80_XOR 378
|
||||||
#define T_MODE_A 379
|
#define T_MODE_A 379
|
||||||
#define T_MODE_B 380
|
#define T_MODE_B 380
|
||||||
#define T_MODE_C 381
|
#define T_MODE_C 381
|
||||||
#define T_MODE_C_IND 382
|
#define T_MODE_C_IND 382
|
||||||
#define T_MODE_D 383
|
#define T_MODE_D 383
|
||||||
#define T_MODE_E 384
|
#define T_MODE_E 384
|
||||||
#define T_MODE_H 385
|
#define T_MODE_H 385
|
||||||
#define T_MODE_L 386
|
#define T_MODE_L 386
|
||||||
#define T_MODE_AF 387
|
#define T_MODE_AF 387
|
||||||
#define T_MODE_BC 388
|
#define T_MODE_BC 388
|
||||||
#define T_MODE_BC_IND 389
|
#define T_MODE_BC_IND 389
|
||||||
#define T_MODE_DE 390
|
#define T_MODE_DE 390
|
||||||
#define T_MODE_DE_IND 391
|
#define T_MODE_DE_IND 391
|
||||||
#define T_MODE_SP 392
|
#define T_MODE_SP 392
|
||||||
#define T_MODE_SP_IND 393
|
#define T_MODE_SP_IND 393
|
||||||
#define T_MODE_HL 394
|
#define T_MODE_HL 394
|
||||||
#define T_MODE_HL_IND 395
|
#define T_MODE_HL_IND 395
|
||||||
#define T_MODE_HL_INDDEC 396
|
#define T_MODE_HL_INDDEC 396
|
||||||
#define T_MODE_HL_INDINC 397
|
#define T_MODE_HL_INDINC 397
|
||||||
#define T_CC_NZ 398
|
#define T_CC_NZ 398
|
||||||
#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;
|
||||||
|
|||||||
@@ -1,68 +1,68 @@
|
|||||||
#ifndef LEXER_H
|
#ifndef LEXER_H
|
||||||
#define LEXER_H
|
#define LEXER_H
|
||||||
|
|
||||||
#include "types.h"
|
#include "types.h"
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
|
||||||
#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
|
||||||
};
|
};
|
||||||
|
|
||||||
#define INITIAL 0
|
#define INITIAL 0
|
||||||
#define macroarg 3
|
#define macroarg 3
|
||||||
|
|
||||||
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,35 +1,35 @@
|
|||||||
#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];
|
||||||
SLONG fillchar; // -1 == random
|
SLONG fillchar; // -1 == random
|
||||||
};
|
};
|
||||||
|
|
||||||
extern char *tzNewMacro;
|
extern char *tzNewMacro;
|
||||||
extern ULONG ulNewMacroSize;
|
extern ULONG ulNewMacroSize;
|
||||||
extern SLONG nGBGfxID;
|
extern SLONG nGBGfxID;
|
||||||
extern SLONG nBinaryID;
|
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];
|
||||||
|
|
||||||
#define YY_FATAL_ERROR fatalerror
|
#define YY_FATAL_ERROR fatalerror
|
||||||
|
|
||||||
#ifdef YYLMAX
|
#ifdef YYLMAX
|
||||||
#undef YYLMAX
|
#undef YYLMAX
|
||||||
#endif
|
#endif
|
||||||
#define YYLMAX 65536
|
#define YYLMAX 65536
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
@@ -1,123 +1,123 @@
|
|||||||
#ifndef LINK_H
|
#ifndef LINK_H
|
||||||
#define LINK_H 1
|
#define LINK_H 1
|
||||||
|
|
||||||
/* RGB0 .obj format:
|
/* RGB0 .obj format:
|
||||||
*
|
*
|
||||||
* Header
|
* Header
|
||||||
* Symbols
|
* Symbols
|
||||||
* Sections
|
* Sections
|
||||||
*
|
*
|
||||||
* Header:
|
* Header:
|
||||||
* "RGB0"
|
* "RGB0"
|
||||||
* LONG NumberOfSymbols
|
* LONG NumberOfSymbols
|
||||||
* LONG NumberOfSections
|
* LONG NumberOfSections
|
||||||
*
|
*
|
||||||
* Symbols:
|
* Symbols:
|
||||||
* Symbol[NumberOfSymbols]
|
* Symbol[NumberOfSymbols]
|
||||||
*
|
*
|
||||||
* Symbol:
|
* Symbol:
|
||||||
* char Name (NULL terminated)
|
* char Name (NULL terminated)
|
||||||
* char nType
|
* char nType
|
||||||
* if( nType!=SYM_IMPORT )
|
* if( nType!=SYM_IMPORT )
|
||||||
* {
|
* {
|
||||||
* LONG SectionID
|
* LONG SectionID
|
||||||
* LONG Offset
|
* LONG Offset
|
||||||
* }
|
* }
|
||||||
*
|
*
|
||||||
* Sections:
|
* Sections:
|
||||||
* Section[NumberOfSections]
|
* Section[NumberOfSections]
|
||||||
*
|
*
|
||||||
* Section:
|
* Section:
|
||||||
* LONG SizeInBytes
|
* LONG SizeInBytes
|
||||||
* char Type
|
* char Type
|
||||||
* if( Type!=BSS )
|
* if( Type!=BSS )
|
||||||
* {
|
* {
|
||||||
* char Data[SizeInBytes]
|
* char Data[SizeInBytes]
|
||||||
* Patches
|
* Patches
|
||||||
* }
|
* }
|
||||||
*
|
*
|
||||||
* Patches:
|
* Patches:
|
||||||
* LONG NumberOfPatches
|
* LONG NumberOfPatches
|
||||||
* Patch[NumberOfPatches]
|
* Patch[NumberOfPatches]
|
||||||
*
|
*
|
||||||
* Patch:
|
* Patch:
|
||||||
* char Filename NULL-terminated
|
* char Filename NULL-terminated
|
||||||
* LONG LineNo
|
* LONG LineNo
|
||||||
* LONG Offset
|
* LONG Offset
|
||||||
* char Type
|
* char Type
|
||||||
* LONG RpnByteSize
|
* LONG RpnByteSize
|
||||||
* Rpn[RpnByteSize]
|
* Rpn[RpnByteSize]
|
||||||
*
|
*
|
||||||
* Rpn:
|
* Rpn:
|
||||||
* Operators: 0x00-0x7F
|
* Operators: 0x00-0x7F
|
||||||
* Constants: 0x80 0x00000000
|
* Constants: 0x80 0x00000000
|
||||||
* Symbols : 0x81 0x00000000
|
* Symbols : 0x81 0x00000000
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
enum
|
enum
|
||||||
{
|
{
|
||||||
RPN_ADD=0,
|
RPN_ADD=0,
|
||||||
RPN_SUB,
|
RPN_SUB,
|
||||||
RPN_MUL,
|
RPN_MUL,
|
||||||
RPN_DIV,
|
RPN_DIV,
|
||||||
RPN_MOD,
|
RPN_MOD,
|
||||||
RPN_UNSUB,
|
RPN_UNSUB,
|
||||||
|
|
||||||
RPN_OR,
|
RPN_OR,
|
||||||
RPN_AND,
|
RPN_AND,
|
||||||
RPN_XOR,
|
RPN_XOR,
|
||||||
RPN_UNNOT,
|
RPN_UNNOT,
|
||||||
|
|
||||||
RPN_LOGAND,
|
RPN_LOGAND,
|
||||||
RPN_LOGOR,
|
RPN_LOGOR,
|
||||||
RPN_LOGUNNOT,
|
RPN_LOGUNNOT,
|
||||||
|
|
||||||
RPN_LOGEQ,
|
RPN_LOGEQ,
|
||||||
RPN_LOGNE,
|
RPN_LOGNE,
|
||||||
RPN_LOGGT,
|
RPN_LOGGT,
|
||||||
RPN_LOGLT,
|
RPN_LOGLT,
|
||||||
RPN_LOGGE,
|
RPN_LOGGE,
|
||||||
RPN_LOGLE,
|
RPN_LOGLE,
|
||||||
|
|
||||||
RPN_SHL,
|
RPN_SHL,
|
||||||
RPN_SHR,
|
RPN_SHR,
|
||||||
|
|
||||||
RPN_BANK,
|
RPN_BANK,
|
||||||
|
|
||||||
RPN_HRAM,
|
RPN_HRAM,
|
||||||
|
|
||||||
RPN_PCEZP,
|
RPN_PCEZP,
|
||||||
|
|
||||||
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,
|
||||||
PATCH_LONG_B
|
PATCH_LONG_B
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
@@ -1,18 +1,18 @@
|
|||||||
#ifndef MATH_H
|
#ifndef MATH_H
|
||||||
#define MATH_H
|
#define MATH_H
|
||||||
|
|
||||||
#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
|
||||||
|
|||||||
@@ -1,36 +1,36 @@
|
|||||||
#ifndef OUTPUT_H
|
#ifndef OUTPUT_H
|
||||||
#define OUTPUT_H 1
|
#define OUTPUT_H 1
|
||||||
|
|
||||||
#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;
|
||||||
ULONG nOrg;
|
ULONG nOrg;
|
||||||
ULONG nBank;
|
ULONG nBank;
|
||||||
struct Section *pNext;
|
struct Section *pNext;
|
||||||
struct Patch *pPatches;
|
struct Patch *pPatches;
|
||||||
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,51 +1,51 @@
|
|||||||
#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;
|
||||||
ULONG nRPNOut;
|
ULONG nRPNOut;
|
||||||
ULONG isReloc;
|
ULONG isReloc;
|
||||||
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, struct Expression *src2 );
|
void rpn_LOGOR( struct Expression *expr, struct Expression *src1, struct Expression *src2 );
|
||||||
void rpn_LOGAND( struct Expression *expr, struct Expression *src1, struct Expression *src2 );
|
void rpn_LOGAND( struct Expression *expr, struct Expression *src1, struct Expression *src2 );
|
||||||
void rpn_LOGEQU( struct Expression *expr, struct Expression *src1, struct Expression *src2 );
|
void rpn_LOGEQU( struct Expression *expr, struct Expression *src1, struct Expression *src2 );
|
||||||
void rpn_LOGGT( struct Expression *expr, struct Expression *src1, struct Expression *src2 );
|
void rpn_LOGGT( struct Expression *expr, struct Expression *src1, struct Expression *src2 );
|
||||||
void rpn_LOGLT( struct Expression *expr, struct Expression *src1, struct Expression *src2 );
|
void rpn_LOGLT( struct Expression *expr, struct Expression *src1, struct Expression *src2 );
|
||||||
void rpn_LOGGE( struct Expression *expr, struct Expression *src1, struct Expression *src2 );
|
void rpn_LOGGE( struct Expression *expr, struct Expression *src1, struct Expression *src2 );
|
||||||
void rpn_LOGLE( struct Expression *expr, struct Expression *src1, struct Expression *src2 );
|
void rpn_LOGLE( struct Expression *expr, struct Expression *src1, struct Expression *src2 );
|
||||||
void rpn_LOGNE( struct Expression *expr, struct Expression *src1, struct Expression *src2 );
|
void rpn_LOGNE( struct Expression *expr, struct Expression *src1, struct Expression *src2 );
|
||||||
void rpn_ADD( struct Expression *expr, struct Expression *src1, struct Expression *src2 );
|
void rpn_ADD( struct Expression *expr, struct Expression *src1, struct Expression *src2 );
|
||||||
void rpn_SUB( struct Expression *expr, struct Expression *src1, struct Expression *src2 );
|
void rpn_SUB( struct Expression *expr, struct Expression *src1, struct Expression *src2 );
|
||||||
void rpn_XOR( struct Expression *expr, struct Expression *src1, struct Expression *src2 );
|
void rpn_XOR( struct Expression *expr, struct Expression *src1, struct Expression *src2 );
|
||||||
void rpn_OR( struct Expression *expr, struct Expression *src1, struct Expression *src2 );
|
void rpn_OR( struct Expression *expr, struct Expression *src1, struct Expression *src2 );
|
||||||
void rpn_AND( struct Expression *expr, struct Expression *src1, struct Expression *src2 );
|
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_SHL( struct Expression *expr, struct Expression *src1, struct Expression *src2 );
|
||||||
void rpn_SHR( 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_MUL( struct Expression *expr, struct Expression *src1, struct Expression *src2 );
|
||||||
void rpn_DIV( 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_MOD( struct Expression *expr, struct Expression *src1, struct Expression *src2 );
|
||||||
void rpn_UNNEG( struct Expression *expr, struct Expression *src );
|
void rpn_UNNEG( struct Expression *expr, struct Expression *src );
|
||||||
void rpn_UNNOT( struct Expression *expr, struct Expression *src );
|
void rpn_UNNOT( struct Expression *expr, struct Expression *src );
|
||||||
UWORD rpn_PopByte( struct Expression *expr );
|
UWORD rpn_PopByte( struct Expression *expr );
|
||||||
void rpn_Bank( struct Expression *expr, char *tzSym );
|
void rpn_Bank( struct Expression *expr, char *tzSym );
|
||||||
void rpn_Reset( struct Expression *expr );
|
void rpn_Reset( struct Expression *expr );
|
||||||
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 );
|
||||||
#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
|
||||||
@@ -1,68 +1,68 @@
|
|||||||
#ifndef SYMBOL_H
|
#ifndef SYMBOL_H
|
||||||
#define SYMBOL_H 1
|
#define SYMBOL_H 1
|
||||||
|
|
||||||
#include "types.h"
|
#include "types.h"
|
||||||
|
|
||||||
#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;
|
||||||
struct sSymbol *pNext;
|
struct sSymbol *pNext;
|
||||||
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 */
|
||||||
#define SYMF_EQU 0x002 /* symbol is defined using EQU, will not be changed during linking */
|
#define SYMF_EQU 0x002 /* symbol is defined using EQU, will not be changed during linking */
|
||||||
#define SYMF_SET 0x004 /* symbol is (re)defined using SET, will not be changed during linking */
|
#define SYMF_SET 0x004 /* symbol is (re)defined using SET, will not be changed during linking */
|
||||||
#define SYMF_EXPORT 0x008 /* symbol should be exported */
|
#define SYMF_EXPORT 0x008 /* symbol should be exported */
|
||||||
#define SYMF_IMPORT 0x010 /* symbol is imported, it's value is unknown */
|
#define SYMF_IMPORT 0x010 /* symbol is imported, it's value is unknown */
|
||||||
#define SYMF_LOCAL 0x020 /* symbol is a local symbol */
|
#define SYMF_LOCAL 0x020 /* symbol is a local symbol */
|
||||||
#define SYMF_DEFINED 0x040 /* symbol has been defined, not only referenced */
|
#define SYMF_DEFINED 0x040 /* symbol has been defined, not only referenced */
|
||||||
#define SYMF_MACRO 0x080 /* symbol is a macro */
|
#define SYMF_MACRO 0x080 /* symbol is a macro */
|
||||||
#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
|
||||||
@@ -1,18 +1,18 @@
|
|||||||
#ifndef TYPES_H
|
#ifndef TYPES_H
|
||||||
#define TYPES_H 1
|
#define TYPES_H 1
|
||||||
|
|
||||||
#if defined(AMIGA) || defined(__GNUC__)
|
#if defined(AMIGA) || defined(__GNUC__)
|
||||||
#define _MAX_PATH 512
|
#define _MAX_PATH 512
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
typedef unsigned char UBYTE;
|
typedef unsigned char UBYTE;
|
||||||
typedef signed char SBYTE;
|
typedef signed char SBYTE;
|
||||||
typedef unsigned short UWORD;
|
typedef unsigned short UWORD;
|
||||||
typedef signed short SWORD;
|
typedef signed short SWORD;
|
||||||
typedef unsigned long ULONG;
|
typedef unsigned long ULONG;
|
||||||
typedef signed long SLONG;
|
typedef signed long SLONG;
|
||||||
|
|
||||||
#define ASM_LITTLE_ENDIAN 0
|
#define ASM_LITTLE_ENDIAN 0
|
||||||
#define ASM_BIG_ENDIAN 1
|
#define ASM_BIG_ENDIAN 1
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
1624
src/asm/lexer.c
1624
src/asm/lexer.c
File diff suppressed because it is too large
Load Diff
810
src/asm/main.c
810
src/asm/main.c
@@ -1,406 +1,406 @@
|
|||||||
/*
|
/*
|
||||||
* RGBAsm - MAIN.C
|
* RGBAsm - MAIN.C
|
||||||
*
|
*
|
||||||
* INCLUDES
|
* INCLUDES
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <time.h>
|
#include <time.h>
|
||||||
#include <math.h>
|
#include <math.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include "symbol.h"
|
#include "symbol.h"
|
||||||
#include "fstack.h"
|
#include "fstack.h"
|
||||||
#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;
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* RGBAsm - MAIN.C
|
* RGBAsm - MAIN.C
|
||||||
*
|
*
|
||||||
* VARIABLES
|
* VARIABLES
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
clock_t nStartClock,
|
clock_t nStartClock,
|
||||||
nEndClock;
|
nEndClock;
|
||||||
SLONG nLineNo;
|
SLONG nLineNo;
|
||||||
ULONG nTotalLines,
|
ULONG nTotalLines,
|
||||||
nPass,
|
nPass,
|
||||||
nPC,
|
nPC,
|
||||||
nIFDepth,
|
nIFDepth,
|
||||||
nErrors;
|
nErrors;
|
||||||
|
|
||||||
extern int yydebug;
|
extern int yydebug;
|
||||||
|
|
||||||
char temptext[1024];
|
char temptext[1024];
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* RGBAsm - MAIN.C
|
* RGBAsm - MAIN.C
|
||||||
*
|
*
|
||||||
* Option stack
|
* Option stack
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
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], CurrentOptions.gbgfx[0] );
|
lex_FloatDeleteRange( nGBGfxID, CurrentOptions.gbgfx[0], CurrentOptions.gbgfx[0] );
|
||||||
lex_FloatDeleteRange( nGBGfxID, CurrentOptions.gbgfx[1], CurrentOptions.gbgfx[1] );
|
lex_FloatDeleteRange( nGBGfxID, CurrentOptions.gbgfx[1], CurrentOptions.gbgfx[1] );
|
||||||
lex_FloatDeleteRange( nGBGfxID, CurrentOptions.gbgfx[2], CurrentOptions.gbgfx[2] );
|
lex_FloatDeleteRange( nGBGfxID, CurrentOptions.gbgfx[2], CurrentOptions.gbgfx[2] );
|
||||||
lex_FloatDeleteRange( nGBGfxID, CurrentOptions.gbgfx[3], CurrentOptions.gbgfx[3] );
|
lex_FloatDeleteRange( nGBGfxID, CurrentOptions.gbgfx[3], CurrentOptions.gbgfx[3] );
|
||||||
lex_FloatDeleteSecondRange( nGBGfxID, CurrentOptions.gbgfx[0], CurrentOptions.gbgfx[0] );
|
lex_FloatDeleteSecondRange( nGBGfxID, CurrentOptions.gbgfx[0], CurrentOptions.gbgfx[0] );
|
||||||
lex_FloatDeleteSecondRange( nGBGfxID, CurrentOptions.gbgfx[1], CurrentOptions.gbgfx[1] );
|
lex_FloatDeleteSecondRange( nGBGfxID, CurrentOptions.gbgfx[1], CurrentOptions.gbgfx[1] );
|
||||||
lex_FloatDeleteSecondRange( nGBGfxID, CurrentOptions.gbgfx[2], CurrentOptions.gbgfx[2] );
|
lex_FloatDeleteSecondRange( nGBGfxID, CurrentOptions.gbgfx[2], CurrentOptions.gbgfx[2] );
|
||||||
lex_FloatDeleteSecondRange( nGBGfxID, CurrentOptions.gbgfx[3], CurrentOptions.gbgfx[3] );
|
lex_FloatDeleteSecondRange( nGBGfxID, CurrentOptions.gbgfx[3], CurrentOptions.gbgfx[3] );
|
||||||
}
|
}
|
||||||
|
|
||||||
if( nBinaryID!=-1 )
|
if( nBinaryID!=-1 )
|
||||||
{
|
{
|
||||||
lex_FloatDeleteRange( nBinaryID, CurrentOptions.binary[0], CurrentOptions.binary[0] );
|
lex_FloatDeleteRange( nBinaryID, CurrentOptions.binary[0], CurrentOptions.binary[0] );
|
||||||
lex_FloatDeleteRange( nBinaryID, CurrentOptions.binary[1], CurrentOptions.binary[1] );
|
lex_FloatDeleteRange( nBinaryID, CurrentOptions.binary[1], CurrentOptions.binary[1] );
|
||||||
lex_FloatDeleteSecondRange( nBinaryID, CurrentOptions.binary[0], CurrentOptions.binary[0] );
|
lex_FloatDeleteSecondRange( nBinaryID, CurrentOptions.binary[0], CurrentOptions.binary[0] );
|
||||||
lex_FloatDeleteSecondRange( nBinaryID, CurrentOptions.binary[1], CurrentOptions.binary[1] );
|
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], CurrentOptions.gbgfx[0] );
|
lex_FloatAddRange( nGBGfxID, CurrentOptions.gbgfx[0], CurrentOptions.gbgfx[0] );
|
||||||
lex_FloatAddRange( nGBGfxID, CurrentOptions.gbgfx[1], CurrentOptions.gbgfx[1] );
|
lex_FloatAddRange( nGBGfxID, CurrentOptions.gbgfx[1], CurrentOptions.gbgfx[1] );
|
||||||
lex_FloatAddRange( nGBGfxID, CurrentOptions.gbgfx[2], CurrentOptions.gbgfx[2] );
|
lex_FloatAddRange( nGBGfxID, CurrentOptions.gbgfx[2], CurrentOptions.gbgfx[2] );
|
||||||
lex_FloatAddRange( nGBGfxID, CurrentOptions.gbgfx[3], CurrentOptions.gbgfx[3] );
|
lex_FloatAddRange( nGBGfxID, CurrentOptions.gbgfx[3], CurrentOptions.gbgfx[3] );
|
||||||
lex_FloatAddSecondRange( nGBGfxID, CurrentOptions.gbgfx[0], CurrentOptions.gbgfx[0] );
|
lex_FloatAddSecondRange( nGBGfxID, CurrentOptions.gbgfx[0], CurrentOptions.gbgfx[0] );
|
||||||
lex_FloatAddSecondRange( nGBGfxID, CurrentOptions.gbgfx[1], CurrentOptions.gbgfx[1] );
|
lex_FloatAddSecondRange( nGBGfxID, CurrentOptions.gbgfx[1], CurrentOptions.gbgfx[1] );
|
||||||
lex_FloatAddSecondRange( nGBGfxID, CurrentOptions.gbgfx[2], CurrentOptions.gbgfx[2] );
|
lex_FloatAddSecondRange( nGBGfxID, CurrentOptions.gbgfx[2], CurrentOptions.gbgfx[2] );
|
||||||
lex_FloatAddSecondRange( nGBGfxID, CurrentOptions.gbgfx[3], CurrentOptions.gbgfx[3] );
|
lex_FloatAddSecondRange( nGBGfxID, CurrentOptions.gbgfx[3], CurrentOptions.gbgfx[3] );
|
||||||
}
|
}
|
||||||
|
|
||||||
if( nBinaryID!=-1 )
|
if( nBinaryID!=-1 )
|
||||||
{
|
{
|
||||||
lex_FloatAddRange( nBinaryID, CurrentOptions.binary[0], CurrentOptions.binary[0] );
|
lex_FloatAddRange( nBinaryID, CurrentOptions.binary[0], CurrentOptions.binary[0] );
|
||||||
lex_FloatAddRange( nBinaryID, CurrentOptions.binary[1], CurrentOptions.binary[1] );
|
lex_FloatAddRange( nBinaryID, CurrentOptions.binary[1], CurrentOptions.binary[1] );
|
||||||
lex_FloatAddSecondRange( nBinaryID, CurrentOptions.binary[0], CurrentOptions.binary[0] );
|
lex_FloatAddSecondRange( nBinaryID, CurrentOptions.binary[0], CurrentOptions.binary[0] );
|
||||||
lex_FloatAddSecondRange( nBinaryID, CurrentOptions.binary[1], CurrentOptions.binary[1] );
|
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 ("*ERROR*\t :\n\tArgument to option -e must be 'b' or 'l'\n" );
|
||||||
exit (5);
|
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
|
else
|
||||||
{
|
{
|
||||||
printf ("*ERROR*\t :\n\tMust specify exactly 4 characters for option 'g'\n" );
|
printf ("*ERROR*\t :\n\tMust specify exactly 4 characters for option 'g'\n" );
|
||||||
exit( 5 );
|
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
|
else
|
||||||
{
|
{
|
||||||
printf ("*ERROR*\t :\n\tMust specify exactly 2 characters for option 'b'\n" );
|
printf ("*ERROR*\t :\n\tMust specify exactly 2 characters for option 'b'\n" );
|
||||||
exit( 5 );
|
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;
|
newopt.fillchar=-1;
|
||||||
}
|
}
|
||||||
else
|
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 ("*ERROR*\t :\n\tInvalid argument for option 'z'\n" );
|
printf ("*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 *)malloc(sizeof(struct sOptionStackEntry)))!=NULL )
|
||||||
{
|
{
|
||||||
pOpt->Options=CurrentOptions;
|
pOpt->Options=CurrentOptions;
|
||||||
pOpt->pNext=pOptionStack;
|
pOpt->pNext=pOptionStack;
|
||||||
pOptionStack=pOpt;
|
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" );
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* RGBAsm - MAIN.C
|
* RGBAsm - MAIN.C
|
||||||
*
|
*
|
||||||
* Error handling
|
* Error handling
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
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);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* RGBAsm - MAIN.C
|
* RGBAsm - MAIN.C
|
||||||
*
|
*
|
||||||
* Help text
|
* Help text
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
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 ")\n\nUsage: " EXENAME " [options] asmfile\n");
|
||||||
printf ("Options:\n");
|
printf ("Options:\n");
|
||||||
printf ("\t-h\t\tThis text\n");
|
printf ("\t-h\t\tThis text\n");
|
||||||
printf ("\t-i<path>\tExtra include path\n");
|
printf ("\t-i<path>\tExtra include path\n");
|
||||||
printf ("\t-o<file>\tWrite objectoutput to <file>\n");
|
printf ("\t-o<file>\tWrite objectoutput to <file>\n");
|
||||||
printf ("\t-e(l|b)\t\tChange endianness (CAUTION!)\n");
|
printf ("\t-e(l|b)\t\tChange endianness (CAUTION!)\n");
|
||||||
printf ("\t-g<ASCI>\tChange the four characters used for Gameboy graphics\n"
|
printf ("\t-g<ASCI>\tChange the four characters used for Gameboy graphics\n"
|
||||||
"\t\t\tconstants (default is 0123)\n" );
|
"\t\t\tconstants (default is 0123)\n" );
|
||||||
printf ("\t-b<AS>\t\tChange the two characters used for binary constants\n"
|
printf ("\t-b<AS>\t\tChange the two characters used for binary constants\n"
|
||||||
"\t\t\t(default is 01)\n" );
|
"\t\t\t(default is 01)\n" );
|
||||||
printf ("\t-z<hx>\t\tSet the byte value (hex format) used for uninitialised\n"
|
printf ("\t-z<hx>\t\tSet the byte value (hex format) used for uninitialised\n"
|
||||||
"\t\t\tdata (default is ? for random)\n" );
|
"\t\t\tdata (default is ? for random)\n" );
|
||||||
exit (0);
|
exit (0);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* RGBAsm - MAIN.C
|
* RGBAsm - MAIN.C
|
||||||
*
|
*
|
||||||
* main
|
* main
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
int main (int argc, char *argv[])
|
int main (int argc, char *argv[])
|
||||||
{
|
{
|
||||||
char *tzMainfile;
|
char *tzMainfile;
|
||||||
int argn = 1;
|
int argn = 1;
|
||||||
|
|
||||||
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", argv[argn][1]);
|
||||||
exit (5);
|
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;
|
||||||
nIFDepth = 0;
|
nIFDepth = 0;
|
||||||
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 = ((double) (nEndClock - nStartClock)) / (double) CLOCKS_PER_SEC;
|
||||||
printf ("Success! %ld lines in %d.%02d seconds ", nTotalLines, (int) timespent, ((int) (timespent * 100.0)) % 100);
|
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", (int) (60 / timespent * nTotalLines));
|
||||||
out_WriteObject ();
|
out_WriteObject ();
|
||||||
}
|
}
|
||||||
else
|
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
|
else
|
||||||
{
|
{
|
||||||
printf ("*ERROR*\t:\tUnterminated IF construct (%ld levels)!\n", nIFDepth);
|
printf ("*ERROR*\t:\tUnterminated IF construct (%ld levels)!\n", nIFDepth);
|
||||||
exit (5);
|
exit (5);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
printf ("Assembly aborted in pass 1 (%ld errors)!\n", nErrors);
|
printf ("Assembly aborted in pass 1 (%ld errors)!\n", nErrors);
|
||||||
exit (5);
|
exit (5);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
printf ("File '%s' not found\n", tzMainfile);
|
printf ("File '%s' not found\n", tzMainfile);
|
||||||
exit (5);
|
exit (5);
|
||||||
}
|
}
|
||||||
return (0);
|
return (0);
|
||||||
}
|
}
|
||||||
304
src/asm/math.c
304
src/asm/math.c
@@ -1,153 +1,153 @@
|
|||||||
/*
|
/*
|
||||||
* RGBAsm - MATH.C (Fixedpoint math routines)
|
* RGBAsm - MATH.C (Fixedpoint math routines)
|
||||||
*
|
*
|
||||||
* INCLUDES
|
* INCLUDES
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <math.h>
|
#include <math.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include "types.h"
|
#include "types.h"
|
||||||
#include "mymath.h"
|
#include "mymath.h"
|
||||||
#include "symbol.h"
|
#include "symbol.h"
|
||||||
|
|
||||||
#define fix2double(i) ((double)(i/65536.0))
|
#define fix2double(i) ((double)(i/65536.0))
|
||||||
#define double2fix(d) ((SLONG)(d*65536.0))
|
#define double2fix(d) ((SLONG)(d*65536.0))
|
||||||
#ifndef PI
|
#ifndef PI
|
||||||
#define PI (acos(-1))
|
#define PI (acos(-1))
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* RGBAsm - MATH.C (Fixedpoint math routines)
|
* RGBAsm - MATH.C (Fixedpoint math routines)
|
||||||
*
|
*
|
||||||
* Define the _PI symbol
|
* Define the _PI symbol
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
void math_DefinePI (void)
|
void math_DefinePI (void)
|
||||||
{
|
{
|
||||||
sym_AddEqu ("_PI", double2fix (PI));
|
sym_AddEqu ("_PI", double2fix (PI));
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* RGBAsm - MATH.C (Fixedpoint math routines)
|
* RGBAsm - MATH.C (Fixedpoint math routines)
|
||||||
*
|
*
|
||||||
* Print a fixed point value
|
* Print a fixed point value
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
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);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* RGBAsm - MATH.C (Fixedpoint math routines)
|
* RGBAsm - MATH.C (Fixedpoint math routines)
|
||||||
*
|
*
|
||||||
* Calculate sine
|
* Calculate sine
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
SLONG math_Sin (SLONG i)
|
SLONG math_Sin (SLONG i)
|
||||||
{
|
{
|
||||||
return (double2fix (sin (fix2double (i) * 2 * PI / 65536)));
|
return (double2fix (sin (fix2double (i) * 2 * PI / 65536)));
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* RGBAsm - MATH.C (Fixedpoint math routines)
|
* RGBAsm - MATH.C (Fixedpoint math routines)
|
||||||
*
|
*
|
||||||
* Calculate cosine
|
* Calculate cosine
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
SLONG math_Cos (SLONG i)
|
SLONG math_Cos (SLONG i)
|
||||||
{
|
{
|
||||||
return (double2fix (cos (fix2double (i) * 2 * PI / 65536)));
|
return (double2fix (cos (fix2double (i) * 2 * PI / 65536)));
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* RGBAsm - MATH.C (Fixedpoint math routines)
|
* RGBAsm - MATH.C (Fixedpoint math routines)
|
||||||
*
|
*
|
||||||
* Calculate tangent
|
* Calculate tangent
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
SLONG math_Tan (SLONG i)
|
SLONG math_Tan (SLONG i)
|
||||||
{
|
{
|
||||||
return (double2fix (tan (fix2double (i) * 2 * PI / 65536)));
|
return (double2fix (tan (fix2double (i) * 2 * PI / 65536)));
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* RGBAsm - MATH.C (Fixedpoint math routines)
|
* RGBAsm - MATH.C (Fixedpoint math routines)
|
||||||
*
|
*
|
||||||
* Calculate sine^-1
|
* Calculate sine^-1
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
SLONG math_ASin (SLONG i)
|
SLONG math_ASin (SLONG i)
|
||||||
{
|
{
|
||||||
return (double2fix (asin (fix2double (i)) / 2 / PI * 65536));
|
return (double2fix (asin (fix2double (i)) / 2 / PI * 65536));
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* RGBAsm - MATH.C (Fixedpoint math routines)
|
* RGBAsm - MATH.C (Fixedpoint math routines)
|
||||||
*
|
*
|
||||||
* Calculate cosine^-1
|
* Calculate cosine^-1
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
SLONG math_ACos (SLONG i)
|
SLONG math_ACos (SLONG i)
|
||||||
{
|
{
|
||||||
return (double2fix (acos (fix2double (i)) / 2 / PI * 65536));
|
return (double2fix (acos (fix2double (i)) / 2 / PI * 65536));
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* RGBAsm - MATH.C (Fixedpoint math routines)
|
* RGBAsm - MATH.C (Fixedpoint math routines)
|
||||||
*
|
*
|
||||||
* Calculate tangent^-1
|
* Calculate tangent^-1
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
SLONG math_ATan (SLONG i)
|
SLONG math_ATan (SLONG i)
|
||||||
{
|
{
|
||||||
return (double2fix (atan (fix2double (i)) / 2 / PI * 65536));
|
return (double2fix (atan (fix2double (i)) / 2 / PI * 65536));
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* RGBAsm - MATH.C (Fixedpoint math routines)
|
* RGBAsm - MATH.C (Fixedpoint math routines)
|
||||||
*
|
*
|
||||||
* Calculate atan2
|
* Calculate atan2
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
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));
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* RGBAsm - MATH.C (Fixedpoint math routines)
|
* RGBAsm - MATH.C (Fixedpoint math routines)
|
||||||
*
|
*
|
||||||
* Multiplication
|
* Multiplication
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
SLONG math_Mul (SLONG i, SLONG j)
|
SLONG math_Mul (SLONG i, SLONG j)
|
||||||
{
|
{
|
||||||
return (double2fix (fix2double (i) * fix2double (j)));
|
return (double2fix (fix2double (i) * fix2double (j)));
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* RGBAsm - MATH.C (Fixedpoint math routines)
|
* RGBAsm - MATH.C (Fixedpoint math routines)
|
||||||
*
|
*
|
||||||
* Division
|
* Division
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
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)));
|
||||||
}
|
}
|
||||||
2052
src/asm/output.c
2052
src/asm/output.c
File diff suppressed because it is too large
Load Diff
712
src/asm/rpn.c
712
src/asm/rpn.c
@@ -1,356 +1,356 @@
|
|||||||
/*
|
/*
|
||||||
* RGBAsm - RPN.C - Controls RPN expressions for objectfiles
|
* RGBAsm - RPN.C - Controls RPN expressions for objectfiles
|
||||||
*
|
*
|
||||||
* INCLUDES
|
* INCLUDES
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "mylink.h"
|
#include "mylink.h"
|
||||||
#include "types.h"
|
#include "types.h"
|
||||||
#include "symbol.h"
|
#include "symbol.h"
|
||||||
#include "asm.h"
|
#include "asm.h"
|
||||||
#include "main.h"
|
#include "main.h"
|
||||||
#include "rpn.h"
|
#include "rpn.h"
|
||||||
|
|
||||||
#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;
|
||||||
expr->isPCRel |= src2->isPCRel;
|
expr->isPCRel |= src2->isPCRel;
|
||||||
}
|
}
|
||||||
|
|
||||||
#define joinexpr() mergetwoexpressions(expr,src1,src2)
|
#define joinexpr() mergetwoexpressions(expr,src1,src2)
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* RGBAsm - RPN.C - Controls RPN expressions for objectfiles
|
* RGBAsm - RPN.C - Controls RPN expressions for objectfiles
|
||||||
*
|
*
|
||||||
* VARIABLES
|
* VARIABLES
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
//UBYTE rpnexpr[2048];
|
//UBYTE rpnexpr[2048];
|
||||||
//ULONG rpnptr = 0;
|
//ULONG rpnptr = 0;
|
||||||
//ULONG rpnoutptr = 0;
|
//ULONG rpnoutptr = 0;
|
||||||
//ULONG reloc = 0;
|
//ULONG reloc = 0;
|
||||||
//ULONG pcrel = 0;
|
//ULONG pcrel = 0;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* RGBAsm - RPN.C - Controls RPN expressions for objectfiles
|
* RGBAsm - RPN.C - Controls RPN expressions for objectfiles
|
||||||
*
|
*
|
||||||
* Add a byte to the RPN expression
|
* Add a byte to the RPN expression
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
void pushbyte (struct Expression *expr, int b)
|
void pushbyte (struct Expression *expr, int b)
|
||||||
{
|
{
|
||||||
expr->tRPN[expr->nRPNLength++] = b & 0xFF;
|
expr->tRPN[expr->nRPNLength++] = b & 0xFF;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* RGBAsm - RPN.C - Controls RPN expressions for objectfiles
|
* RGBAsm - RPN.C - Controls RPN expressions for objectfiles
|
||||||
*
|
*
|
||||||
* Reset the RPN module
|
* Reset the RPN module
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
void rpn_Reset (struct Expression *expr)
|
void rpn_Reset (struct Expression *expr)
|
||||||
{
|
{
|
||||||
expr->nRPNLength = expr->nRPNOut = expr->isReloc = expr->isPCRel = 0;
|
expr->nRPNLength = expr->nRPNOut = expr->isReloc = expr->isPCRel = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* RGBAsm - RPN.C - Controls RPN expressions for objectfiles
|
* RGBAsm - RPN.C - Controls RPN expressions for objectfiles
|
||||||
*
|
*
|
||||||
* Returns the next rpn byte in expression
|
* Returns the next rpn byte in expression
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
UWORD rpn_PopByte (struct Expression *expr)
|
UWORD rpn_PopByte (struct Expression *expr)
|
||||||
{
|
{
|
||||||
if (expr->nRPNOut == expr->nRPNLength)
|
if (expr->nRPNOut == expr->nRPNLength)
|
||||||
{
|
{
|
||||||
return (0xDEAD);
|
return (0xDEAD);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
return (expr->tRPN[expr->nRPNOut++]);
|
return (expr->tRPN[expr->nRPNOut++]);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* RGBAsm - RPN.C - Controls RPN expressions for objectfiles
|
* RGBAsm - RPN.C - Controls RPN expressions for objectfiles
|
||||||
*
|
*
|
||||||
* Determine if the current expression is relocatable
|
* Determine if the current expression is relocatable
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
ULONG rpn_isReloc (struct Expression *expr)
|
ULONG rpn_isReloc (struct Expression *expr)
|
||||||
{
|
{
|
||||||
return (expr->isReloc);
|
return (expr->isReloc);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* RGBAsm - RPN.C - Controls RPN expressions for objectfiles
|
* RGBAsm - RPN.C - Controls RPN expressions for objectfiles
|
||||||
*
|
*
|
||||||
* Determine if the current expression can be pc-relative
|
* Determine if the current expression can be pc-relative
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
ULONG rpn_isPCRelative (struct Expression *expr)
|
ULONG rpn_isPCRelative (struct Expression *expr)
|
||||||
{
|
{
|
||||||
return (expr->isPCRel);
|
return (expr->isPCRel);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* RGBAsm - RPN.C - Controls RPN expressions for objectfiles
|
* RGBAsm - RPN.C - Controls RPN expressions for objectfiles
|
||||||
*
|
*
|
||||||
* Add symbols, constants and operators to expression
|
* Add symbols, constants and operators to expression
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
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
|
else
|
||||||
{
|
{
|
||||||
return( expr->nVal>=low && expr->nVal<=high );
|
return( expr->nVal>=low && expr->nVal<=high );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef GAMEBOY
|
#ifdef GAMEBOY
|
||||||
void rpn_CheckHRAM (struct Expression *expr, struct Expression *src)
|
void rpn_CheckHRAM (struct Expression *expr, struct Expression *src)
|
||||||
{
|
{
|
||||||
*expr = *src;
|
*expr = *src;
|
||||||
pushbyte (expr, RPN_HRAM);
|
pushbyte (expr, RPN_HRAM);
|
||||||
}
|
}
|
||||||
#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);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
2144
src/asm/symbol.c
2144
src/asm/symbol.c
File diff suppressed because it is too large
Load Diff
1062
src/asm/yaccprt3.y
1062
src/asm/yaccprt3.y
File diff suppressed because it is too large
Load Diff
@@ -1,25 +1,25 @@
|
|||||||
/* asmotor.h
|
/* asmotor.h
|
||||||
*
|
*
|
||||||
* Contains defines for every program in the ASMotor package
|
* Contains defines for every program in the ASMotor package
|
||||||
*
|
*
|
||||||
* Copyright 1997 Carsten Sorensen
|
* Copyright 1997 Carsten Sorensen
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#ifndef ASMOTOR_H
|
#ifndef ASMOTOR_H
|
||||||
#define ASMOTOR_H
|
#define ASMOTOR_H
|
||||||
|
|
||||||
#define ASMOTOR
|
#define ASMOTOR
|
||||||
|
|
||||||
#define ASMOTOR_VERSION "1.10"
|
#define ASMOTOR_VERSION "1.10"
|
||||||
|
|
||||||
#define ASM_VERSION "1.08c"
|
#define ASM_VERSION "1.08c"
|
||||||
#define LINK_VERSION "1.06c"
|
#define LINK_VERSION "1.06c"
|
||||||
#define RGBFIX_VERSION "1.02"
|
#define RGBFIX_VERSION "1.02"
|
||||||
#define LIB_VERSION "1.00"
|
#define LIB_VERSION "1.00"
|
||||||
|
|
||||||
#ifdef __GNUC__
|
#ifdef __GNUC__
|
||||||
#define strnicmp strncasecmp
|
#define strnicmp strncasecmp
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#endif // ASMOTOR_H
|
#endif // ASMOTOR_H
|
||||||
@@ -1,13 +1,13 @@
|
|||||||
#ifndef LIBRARY_H
|
#ifndef LIBRARY_H
|
||||||
#define LIBRARY_H
|
#define LIBRARY_H
|
||||||
|
|
||||||
#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
|
||||||
@@ -1,20 +1,20 @@
|
|||||||
#ifndef LIBWRAP_H
|
#ifndef LIBWRAP_H
|
||||||
#define LIBWRAP_H
|
#define LIBWRAP_H
|
||||||
|
|
||||||
#include "types.h"
|
#include "types.h"
|
||||||
|
|
||||||
#define MAXNAMELENGTH 256
|
#define MAXNAMELENGTH 256
|
||||||
|
|
||||||
struct LibraryWrapper
|
struct LibraryWrapper
|
||||||
{
|
{
|
||||||
char tName[MAXNAMELENGTH];
|
char tName[MAXNAMELENGTH];
|
||||||
UWORD uwTime;
|
UWORD uwTime;
|
||||||
UWORD uwDate;
|
UWORD uwDate;
|
||||||
SLONG nByteLength;
|
SLONG nByteLength;
|
||||||
UBYTE *pData;
|
UBYTE *pData;
|
||||||
struct LibraryWrapper *pNext;
|
struct LibraryWrapper *pNext;
|
||||||
};
|
};
|
||||||
|
|
||||||
typedef struct LibraryWrapper sLibrary;
|
typedef struct LibraryWrapper sLibrary;
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
@@ -1,16 +1,16 @@
|
|||||||
#ifndef TYPES_H
|
#ifndef TYPES_H
|
||||||
#define TYPES_H 1
|
#define TYPES_H 1
|
||||||
|
|
||||||
#if defined(AMIGA) || defined(__GNUC__)
|
#if defined(AMIGA) || defined(__GNUC__)
|
||||||
#define _MAX_PATH 512
|
#define _MAX_PATH 512
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
typedef unsigned char UBYTE;
|
typedef unsigned char UBYTE;
|
||||||
typedef signed char SBYTE;
|
typedef signed char SBYTE;
|
||||||
typedef unsigned short UWORD;
|
typedef unsigned short UWORD;
|
||||||
typedef signed short SWORD;
|
typedef signed short SWORD;
|
||||||
typedef unsigned long ULONG;
|
typedef unsigned long ULONG;
|
||||||
typedef signed long SLONG;
|
typedef signed long SLONG;
|
||||||
typedef signed char BBOOL;
|
typedef signed char BBOOL;
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
@@ -1,308 +1,308 @@
|
|||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#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,
|
sLibrary *l=NULL,
|
||||||
*first=NULL;
|
*first=NULL;
|
||||||
|
|
||||||
while( size>0 )
|
while( size>0 )
|
||||||
{
|
{
|
||||||
if( l==NULL )
|
if( l==NULL )
|
||||||
{
|
{
|
||||||
if( (l=(sLibrary *)malloc(sizeof(sLibrary)))==NULL )
|
if( (l=(sLibrary *)malloc(sizeof(sLibrary)))==NULL )
|
||||||
fatalerror( "Out of memory" );
|
fatalerror( "Out of memory" );
|
||||||
|
|
||||||
first=l;
|
first=l;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
if( (l->pNext=(sLibrary *)malloc(sizeof(sLibrary)))==NULL )
|
if( (l->pNext=(sLibrary *)malloc(sizeof(sLibrary)))==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 ); size-=2;
|
||||||
l->uwDate=file_ReadWord( f ); size-=2;
|
l->uwDate=file_ReadWord( f ); size-=2;
|
||||||
l->nByteLength=file_ReadLong( f ); size-=4;
|
l->nByteLength=file_ReadLong( f ); size-=4;
|
||||||
if( l->pData=(UBYTE *)malloc(l->nByteLength) )
|
if( l->pData=(UBYTE *)malloc(l->nByteLength) )
|
||||||
{
|
{
|
||||||
fread( l->pData, sizeof(UBYTE), l->nByteLength, f );
|
fread( l->pData, sizeof(UBYTE), l->nByteLength, f );
|
||||||
size-=l->nByteLength;
|
size-=l->nByteLength;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
fatalerror( "Out of memory" );
|
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
|
else
|
||||||
{
|
{
|
||||||
fclose( f );
|
fclose( f );
|
||||||
fatalerror( "Not a valid xLib library" );
|
fatalerror( "Not a valid xLib library" );
|
||||||
return( NULL );
|
return( NULL );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
printf( "Library '%s' not found, it will be created if necessary\n", filename );
|
printf( "Library '%s' not found, it will be created if necessary\n", filename );
|
||||||
return( NULL );
|
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_WriteASCIIz( lib->tName, f );
|
||||||
file_WriteWord( lib->uwTime, f );
|
file_WriteWord( lib->uwTime, f );
|
||||||
file_WriteWord( lib->uwDate, f );
|
file_WriteWord( lib->uwDate, f );
|
||||||
file_WriteLong( lib->nByteLength, f );
|
file_WriteLong( lib->nByteLength, f );
|
||||||
fwrite( lib->pData, sizeof(UBYTE), lib->nByteLength,f );
|
fwrite( lib->pData, sizeof(UBYTE), lib->nByteLength,f );
|
||||||
lib=lib->pNext;
|
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;
|
module->pNext=lib;
|
||||||
lib=module;
|
lib=module;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
fatalerror( "Out of memory" );
|
fatalerror( "Out of memory" );
|
||||||
}
|
}
|
||||||
else
|
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, f );
|
fread( module->pData, sizeof(UBYTE), module->nByteLength, 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 );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
284
src/lib/main.c
284
src/lib/main.c
@@ -1,143 +1,143 @@
|
|||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <ctype.h>
|
#include <ctype.h>
|
||||||
|
|
||||||
#include "asmotor.h"
|
#include "asmotor.h"
|
||||||
#include "types.h"
|
#include "types.h"
|
||||||
#include "library.h"
|
#include "library.h"
|
||||||
|
|
||||||
// Quick and dirty...but it works
|
// Quick and dirty...but it works
|
||||||
#ifdef __GNUC__
|
#ifdef __GNUC__
|
||||||
#define strcmpi strcasecmp
|
#define strcmpi strcasecmp
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Print out an errormessage
|
* Print out an errormessage
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
void fatalerror( char *s )
|
void fatalerror( char *s )
|
||||||
{
|
{
|
||||||
printf( "*ERROR* : %s\n", s );
|
printf( "*ERROR* : %s\n", s );
|
||||||
exit( 5 );
|
exit( 5 );
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Print the usagescreen
|
* Print the usagescreen
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
void PrintUsage( void )
|
void PrintUsage( void )
|
||||||
{
|
{
|
||||||
printf( "xLib v" LIB_VERSION " (part of ASMotor " ASMOTOR_VERSION ")\n\n"
|
printf( "xLib v" LIB_VERSION " (part of ASMotor " ASMOTOR_VERSION ")\n\n"
|
||||||
"Usage: xlib library command [module1 module2 ... modulen]\n"
|
"Usage: xlib library command [module1 module2 ... modulen]\n"
|
||||||
"Commands:\n\ta\tAdd/replace modules to library\n"
|
"Commands:\n\ta\tAdd/replace modules to library\n"
|
||||||
"\td\tDelete modules from library\n"
|
"\td\tDelete modules from library\n"
|
||||||
"\tl\tList library contents\n"
|
"\tl\tList library contents\n"
|
||||||
"\tx\tExtract modules from library\n" );
|
"\tx\tExtract modules from library\n" );
|
||||||
exit( 0 );
|
exit( 0 );
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* The main routine
|
* The main routine
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
int main( int argc, char *argv[] )
|
int main( int argc, char *argv[] )
|
||||||
{
|
{
|
||||||
SLONG argn=0;
|
SLONG argn=0;
|
||||||
char *libname;
|
char *libname;
|
||||||
|
|
||||||
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_DeleteModule( lib, argv[argn++] );
|
lib=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", l->nByteLength, l->tName );
|
printf( "%10d %s\n", l->nByteLength, l->tName );
|
||||||
l=l->pNext;
|
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, sizeof(UBYTE), l->nByteLength, f );
|
fwrite( l->pData, sizeof(UBYTE), l->nByteLength, f );
|
||||||
fclose( f );
|
fclose( f );
|
||||||
printf( "Extracted module '%s'\n", argv[argn] );
|
printf( "Extracted module '%s'\n", argv[argn] );
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
fatalerror( "Unable to write module" );
|
fatalerror( "Unable to write module" );
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
fatalerror( "Module not found" );
|
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
|
else
|
||||||
{
|
{
|
||||||
fatalerror( "Invalid command" );
|
fatalerror( "Invalid command" );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
PrintUsage();
|
PrintUsage();
|
||||||
|
|
||||||
return( 0 );
|
return( 0 );
|
||||||
}
|
}
|
||||||
1138
src/link/assign.c
1138
src/link/assign.c
File diff suppressed because it is too large
Load Diff
@@ -1,22 +1,22 @@
|
|||||||
#ifndef ASSIGN_H
|
#ifndef ASSIGN_H
|
||||||
#define ASSIGN_H
|
#define ASSIGN_H
|
||||||
|
|
||||||
#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];
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
@@ -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
|
||||||
@@ -1,21 +1,21 @@
|
|||||||
#ifndef MAIN_H
|
#ifndef MAIN_H
|
||||||
#define MAIN_H
|
#define MAIN_H
|
||||||
|
|
||||||
#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
|
||||||
@@ -1,119 +1,119 @@
|
|||||||
#ifndef LINK_H
|
#ifndef LINK_H
|
||||||
#define LINK_H 1
|
#define LINK_H 1
|
||||||
|
|
||||||
#if defined(AMIGA) || defined(__GNUC__)
|
#if defined(AMIGA) || defined(__GNUC__)
|
||||||
#define _MAX_PATH 512
|
#define _MAX_PATH 512
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#include "types.h"
|
#include "types.h"
|
||||||
|
|
||||||
extern SLONG options;
|
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,
|
||||||
RPN_MOD,
|
RPN_MOD,
|
||||||
RPN_UNSUB,
|
RPN_UNSUB,
|
||||||
|
|
||||||
RPN_OR,
|
RPN_OR,
|
||||||
RPN_AND,
|
RPN_AND,
|
||||||
RPN_XOR,
|
RPN_XOR,
|
||||||
RPN_UNNOT,
|
RPN_UNNOT,
|
||||||
|
|
||||||
RPN_LOGAND,
|
RPN_LOGAND,
|
||||||
RPN_LOGOR,
|
RPN_LOGOR,
|
||||||
RPN_LOGUNNOT,
|
RPN_LOGUNNOT,
|
||||||
|
|
||||||
RPN_LOGEQ,
|
RPN_LOGEQ,
|
||||||
RPN_LOGNE,
|
RPN_LOGNE,
|
||||||
RPN_LOGGT,
|
RPN_LOGGT,
|
||||||
RPN_LOGLT,
|
RPN_LOGLT,
|
||||||
RPN_LOGGE,
|
RPN_LOGGE,
|
||||||
RPN_LOGLE,
|
RPN_LOGLE,
|
||||||
|
|
||||||
RPN_SHL,
|
RPN_SHL,
|
||||||
RPN_SHR,
|
RPN_SHR,
|
||||||
|
|
||||||
RPN_BANK,
|
RPN_BANK,
|
||||||
|
|
||||||
RPN_HRAM,
|
RPN_HRAM,
|
||||||
|
|
||||||
RPN_PCEZP,
|
RPN_PCEZP,
|
||||||
|
|
||||||
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,
|
||||||
SECT_HOME,
|
SECT_HOME,
|
||||||
SECT_HRAM
|
SECT_HRAM
|
||||||
};
|
};
|
||||||
|
|
||||||
struct sSection
|
struct sSection
|
||||||
{
|
{
|
||||||
SLONG nBank;
|
SLONG nBank;
|
||||||
SLONG nOrg;
|
SLONG nOrg;
|
||||||
BBOOL oAssigned;
|
BBOOL oAssigned;
|
||||||
|
|
||||||
SLONG nByteSize;
|
SLONG nByteSize;
|
||||||
enum eSectionType Type;
|
enum eSectionType Type;
|
||||||
UBYTE *pData;
|
UBYTE *pData;
|
||||||
SLONG nNumberOfSymbols;
|
SLONG nNumberOfSymbols;
|
||||||
struct sSymbol **tSymbols;
|
struct sSymbol **tSymbols;
|
||||||
struct sPatch *pPatches;
|
struct sPatch *pPatches;
|
||||||
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 */
|
||||||
SLONG nSectionID; /* internal to object.c */
|
SLONG nSectionID; /* internal to object.c */
|
||||||
struct sSection *pSection;
|
struct sSection *pSection;
|
||||||
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;
|
||||||
enum ePatchType Type;
|
enum ePatchType Type;
|
||||||
SLONG nRPNSize;
|
SLONG nRPNSize;
|
||||||
UBYTE *pRPN;
|
UBYTE *pRPN;
|
||||||
struct sPatch *pNext;
|
struct sPatch *pNext;
|
||||||
BBOOL oRelocPatch;
|
BBOOL oRelocPatch;
|
||||||
};
|
};
|
||||||
|
|
||||||
extern struct sSection *pSections;
|
extern struct sSection *pSections;
|
||||||
extern struct sSection *pLibSections;
|
extern struct sSection *pLibSections;
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
@@ -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
|
||||||
|
|||||||
@@ -1,9 +1,9 @@
|
|||||||
#ifndef PATCH_H
|
#ifndef PATCH_H
|
||||||
#define PATCH_H
|
#define PATCH_H
|
||||||
|
|
||||||
#include "types.h"
|
#include "types.h"
|
||||||
|
|
||||||
void Patch( void );
|
void Patch( void );
|
||||||
extern SLONG nPC;
|
extern SLONG nPC;
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
@@ -1,11 +1,11 @@
|
|||||||
#ifndef SYMBOL_H
|
#ifndef SYMBOL_H
|
||||||
#define SYMBOL_H
|
#define SYMBOL_H
|
||||||
|
|
||||||
#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
|
||||||
@@ -1,16 +1,16 @@
|
|||||||
#ifndef TYPES_H
|
#ifndef TYPES_H
|
||||||
#define TYPES_H 1
|
#define TYPES_H 1
|
||||||
|
|
||||||
#if defined(AMIGA) || defined(__GNUC__)
|
#if defined(AMIGA) || defined(__GNUC__)
|
||||||
#define _MAX_PATH 512
|
#define _MAX_PATH 512
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
typedef unsigned char UBYTE;
|
typedef unsigned char UBYTE;
|
||||||
typedef signed char SBYTE;
|
typedef signed char SBYTE;
|
||||||
typedef unsigned short UWORD;
|
typedef unsigned short UWORD;
|
||||||
typedef signed short SWORD;
|
typedef signed short SWORD;
|
||||||
typedef unsigned long ULONG;
|
typedef unsigned long ULONG;
|
||||||
typedef signed long SLONG;
|
typedef signed long SLONG;
|
||||||
typedef signed char BBOOL;
|
typedef signed char BBOOL;
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
@@ -1,127 +1,127 @@
|
|||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include "types.h"
|
#include "types.h"
|
||||||
#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)->tSymbols[i]->pSection) ) )
|
&& ((*ppLSect)==(*ppLSect)->tSymbols[i]->pSection) ) )
|
||||||
{
|
{
|
||||||
if( strcmp((*ppLSect)->tSymbols[i]->pzName,name)==0 )
|
if( strcmp((*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
|
else
|
||||||
printf( "Smart linking with symbol '%s'\n", 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) )
|
if( !symboldefined(pSect->tSymbols[i]->pzName) )
|
||||||
{
|
{
|
||||||
addmodulecontaining( pSect->tSymbols[i]->pzName );
|
addmodulecontaining( pSect->tSymbols[i]->pzName );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
pSect=pSect->pNext;
|
pSect=pSect->pNext;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
458
src/link/main.c
458
src/link/main.c
@@ -1,230 +1,230 @@
|
|||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
#include "object.h"
|
#include "object.h"
|
||||||
#include "output.h"
|
#include "output.h"
|
||||||
#include "assign.h"
|
#include "assign.h"
|
||||||
#include "patch.h"
|
#include "patch.h"
|
||||||
#include "asmotor.h"
|
#include "asmotor.h"
|
||||||
#include "mylink.h"
|
#include "mylink.h"
|
||||||
#include "mapfile.h"
|
#include "mapfile.h"
|
||||||
#include "main.h"
|
#include "main.h"
|
||||||
#include "library.h"
|
#include "library.h"
|
||||||
|
|
||||||
// Quick and dirty...but it works
|
// Quick and dirty...but it works
|
||||||
#ifdef __GNUC__
|
#ifdef __GNUC__
|
||||||
#define strcmpi strcasecmp
|
#define strcmpi strcasecmp
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
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];
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Print out an errormessage
|
* Print out an errormessage
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
void fatalerror( char *s )
|
void fatalerror( char *s )
|
||||||
{
|
{
|
||||||
printf( "*ERROR* : %s\n", s );
|
printf( "*ERROR* : %s\n", s );
|
||||||
exit( 5 );
|
exit( 5 );
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Print the usagescreen
|
* Print the usagescreen
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
void PrintUsage( void )
|
void PrintUsage( void )
|
||||||
{
|
{
|
||||||
printf( "xLink v" LINK_VERSION " (part of ASMotor " ASMOTOR_VERSION ")\n\n"
|
printf( "xLink v" LINK_VERSION " (part of ASMotor " ASMOTOR_VERSION ")\n\n"
|
||||||
"Usage: xlink [options] linkfile\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 );
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Parse the linkfile and load all the objectfiles
|
* Parse the linkfile and load all the objectfiles
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
void ProcessLinkfile( char *tzLinkfile )
|
void ProcessLinkfile( char *tzLinkfile )
|
||||||
{
|
{
|
||||||
FILE *pLinkfile;
|
FILE *pLinkfile;
|
||||||
enum eBlockType CurrentBlock=BLOCK_COMMENT;
|
enum eBlockType CurrentBlock=BLOCK_COMMENT;
|
||||||
|
|
||||||
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]=='[' && tzLine[strlen(tzLine)-1]==']' )
|
if( tzLine[0]=='[' && 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)==0 )
|
else if( strcmpi("[output]",tzLine)==0 )
|
||||||
CurrentBlock=BLOCK_OUTPUT;
|
CurrentBlock=BLOCK_OUTPUT;
|
||||||
else if( strcmpi("[libraries]",tzLine)==0 )
|
else if( strcmpi("[libraries]",tzLine)==0 )
|
||||||
CurrentBlock=BLOCK_LIBRARIES;
|
CurrentBlock=BLOCK_LIBRARIES;
|
||||||
else if( strcmpi("[comment]",tzLine)==0 )
|
else if( strcmpi("[comment]",tzLine)==0 )
|
||||||
CurrentBlock=BLOCK_COMMENT;
|
CurrentBlock=BLOCK_COMMENT;
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
fclose( pLinkfile );
|
fclose( pLinkfile );
|
||||||
sprintf( temptext, "Unknown block '%s'\n", tzLine );
|
sprintf( temptext, "Unknown block '%s'\n", tzLine );
|
||||||
fatalerror( temptext );
|
fatalerror( temptext );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
switch( CurrentBlock )
|
switch( CurrentBlock )
|
||||||
{
|
{
|
||||||
case BLOCK_COMMENT:
|
case BLOCK_COMMENT:
|
||||||
break;
|
break;
|
||||||
case BLOCK_OBJECTS:
|
case BLOCK_OBJECTS:
|
||||||
obj_Readfile( tzLine );
|
obj_Readfile( tzLine );
|
||||||
break;
|
break;
|
||||||
case BLOCK_LIBRARIES:
|
case BLOCK_LIBRARIES:
|
||||||
lib_Readfile( tzLine );
|
lib_Readfile( tzLine );
|
||||||
break;
|
break;
|
||||||
case BLOCK_OUTPUT:
|
case BLOCK_OUTPUT:
|
||||||
out_Setname( tzLine );
|
out_Setname( tzLine );
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
fclose( pLinkfile );
|
fclose( pLinkfile );
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
sprintf( temptext, "Unable to find linkfile '%s'\n", tzLinkfile );
|
sprintf( temptext, "Unable to find linkfile '%s'\n", tzLinkfile );
|
||||||
fatalerror( temptext );
|
fatalerror( temptext );
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* The main routine
|
* The main routine
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
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", opt );
|
||||||
fatalerror( temptext );
|
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;
|
fillchar=-1;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
int result;
|
int result;
|
||||||
|
|
||||||
result=sscanf( argv[argn-1]+2, "%x", &fillchar );
|
result=sscanf( argv[argn-1]+2, "%x", &fillchar );
|
||||||
if( !((result==EOF) || (result==1)) )
|
if( !((result==EOF) || (result==1)) )
|
||||||
{
|
{
|
||||||
fatalerror("Invalid argument for option 'z'\n" );
|
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 );
|
||||||
}
|
}
|
||||||
@@ -1,108 +1,108 @@
|
|||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
#include "asmotor.h"
|
#include "asmotor.h"
|
||||||
#include "main.h"
|
#include "main.h"
|
||||||
#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", pSym->nOffset+pSect->nOrg, pSym->pzName );
|
fprintf( mf, " $%04X = %s\n", pSym->nOffset+pSect->nOrg, pSym->pzName );
|
||||||
}
|
}
|
||||||
if( sf )
|
if( sf )
|
||||||
{
|
{
|
||||||
fprintf( sf, "%02X:%04X %s\n", sfbank, pSym->nOffset+pSect->nOrg, pSym->pzName );
|
fprintf( sf, "%02X:%04X %s\n", sfbank, pSym->nOffset+pSect->nOrg, pSym->pzName );
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
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 );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
1090
src/link/object.c
1090
src/link/object.c
File diff suppressed because it is too large
Load Diff
@@ -1,222 +1,222 @@
|
|||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
#include "mylink.h"
|
#include "mylink.h"
|
||||||
#include "mapfile.h"
|
#include "mapfile.h"
|
||||||
#include "main.h"
|
#include "main.h"
|
||||||
#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
|
else
|
||||||
{
|
{
|
||||||
memset( mem+pSect->nOrg, 0, pSect->nByteSize );
|
memset( mem+pSect->nOrg, 0, pSect->nByteSize );
|
||||||
}
|
}
|
||||||
pSect=pSect->pNext;
|
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;
|
||||||
case OUTPUT_PSION2:
|
case OUTPUT_PSION2:
|
||||||
PSION2_Output();
|
PSION2_Output();
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
598
src/link/patch.c
598
src/link/patch.c
@@ -1,300 +1,300 @@
|
|||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
#include "mylink.h"
|
#include "mylink.h"
|
||||||
#include "symbol.h"
|
#include "symbol.h"
|
||||||
#include "main.h"
|
#include "main.h"
|
||||||
|
|
||||||
struct sSection *pCurrentSection;
|
struct sSection *pCurrentSection;
|
||||||
SLONG rpnstack[256];
|
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,"@")==0 )
|
||||||
{
|
{
|
||||||
return( nPC );
|
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, "%s(%d) : Value must be in the HRAM area", pPatch->pzFilename, pPatch->nLineNo );
|
sprintf( temptext, "%s(%d) : Value must be in the HRAM area", pPatch->pzFilename, pPatch->nLineNo );
|
||||||
fatalerror( temptext );
|
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, "%s(%d) : Value must be in the ZP area", pPatch->pzFilename, pPatch->nLineNo );
|
sprintf( temptext, "%s(%d) : Value must be in the ZP area", pPatch->pzFilename, pPatch->nLineNo );
|
||||||
fatalerror( temptext );
|
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, "%s(%d) : Value must be in the range [%d;%d]", pPatch->pzFilename, pPatch->nLineNo, low, high );
|
sprintf( temptext, "%s(%d) : Value must be in the range [%d;%d]", pPatch->pzFilename, pPatch->nLineNo, low, high );
|
||||||
fatalerror( temptext );
|
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]=(UBYTE)t;
|
pSect->pData[pPatch->nOffset]=(UBYTE)t;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
sprintf( temptext, "%s(%d) : Value must be 8-bit\n", pPatch->pzFilename, pPatch->nLineNo );
|
sprintf( temptext, "%s(%d) : Value must be 8-bit\n", pPatch->pzFilename, pPatch->nLineNo );
|
||||||
fatalerror( temptext );
|
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+1]=(t>>8)&0xFF;
|
pSect->pData[pPatch->nOffset+1]=(t>>8)&0xFF;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
// Assume big endian
|
// Assume big endian
|
||||||
pSect->pData[pPatch->nOffset]=(t>>8)&0xFF;
|
pSect->pData[pPatch->nOffset]=(t>>8)&0xFF;
|
||||||
pSect->pData[pPatch->nOffset+1]=t&0xFF;
|
pSect->pData[pPatch->nOffset+1]=t&0xFF;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
sprintf( temptext, "%s(%d) : Value must be 16-bit\n", pPatch->pzFilename, pPatch->nLineNo );
|
sprintf( temptext, "%s(%d) : Value must be 16-bit\n", pPatch->pzFilename, pPatch->nLineNo );
|
||||||
fatalerror( temptext );
|
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]=(t>>8)&0xFF;
|
||||||
pSect->pData[pPatch->nOffset+2]=(t>>16)&0xFF;
|
pSect->pData[pPatch->nOffset+2]=(t>>16)&0xFF;
|
||||||
pSect->pData[pPatch->nOffset+3]=(t>>24)&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]=(t>>24)&0xFF;
|
||||||
pSect->pData[pPatch->nOffset+1]=(t>>16)&0xFF;
|
pSect->pData[pPatch->nOffset+1]=(t>>16)&0xFF;
|
||||||
pSect->pData[pPatch->nOffset+2]=(t>>8)&0xFF;
|
pSect->pData[pPatch->nOffset+2]=(t>>8)&0xFF;
|
||||||
pSect->pData[pPatch->nOffset+3]=t&0xFF;
|
pSect->pData[pPatch->nOffset+3]=t&0xFF;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
pPatch=pPatch->pNext;
|
pPatch=pPatch->pNext;
|
||||||
}
|
}
|
||||||
|
|
||||||
pSect=pSect->pNext;
|
pSect=pSect->pNext;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1,125 +1,125 @@
|
|||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include "main.h"
|
#include "main.h"
|
||||||
#include "patch.h"
|
#include "patch.h"
|
||||||
#include "types.h"
|
#include "types.h"
|
||||||
|
|
||||||
#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
|
||||||
struct ISymbol *pNext;
|
struct ISymbol *pNext;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct ISymbol *tHash[HASHSIZE];
|
struct ISymbol *tHash[HASHSIZE];
|
||||||
|
|
||||||
SLONG calchash( char *s )
|
SLONG calchash( char *s )
|
||||||
{
|
{
|
||||||
SLONG r=0;
|
SLONG r=0;
|
||||||
while( *s )
|
while( *s )
|
||||||
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);
|
ppSym=&((*ppSym)->pNext);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
return( (*ppSym)->nValue );
|
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);
|
ppSym=&((*ppSym)->pNext);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
return( (*ppSym)->nBank );
|
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);
|
ppSym=&((*ppSym)->pNext);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
if( nBank==-1 )
|
if( nBank==-1 )
|
||||||
return;
|
return;
|
||||||
|
|
||||||
sprintf( temptext, "Symbol '%s' defined more than once\n", tzName );
|
sprintf( temptext, "Symbol '%s' defined more than once\n", tzName );
|
||||||
fatalerror( temptext );
|
fatalerror( temptext );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if( *ppSym=(struct ISymbol *)malloc(sizeof(struct ISymbol)) )
|
if( *ppSym=(struct ISymbol *)malloc(sizeof(struct ISymbol)) )
|
||||||
{
|
{
|
||||||
if( (*ppSym)->pzName=(char *)malloc(strlen(tzName)+1) )
|
if( (*ppSym)->pzName=(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;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1,432 +1,432 @@
|
|||||||
/*
|
/*
|
||||||
* RGBFix : Perform various tasks on a Gameboy image-file
|
* RGBFix : Perform various tasks on a Gameboy image-file
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include "asmotor.h"
|
#include "asmotor.h"
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Option defines
|
* Option defines
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#define OPTF_DEBUG 0x01L
|
#define OPTF_DEBUG 0x01L
|
||||||
#define OPTF_PAD 0x02L
|
#define OPTF_PAD 0x02L
|
||||||
#define OPTF_VALIDATE 0x04L
|
#define OPTF_VALIDATE 0x04L
|
||||||
#define OPTF_TITLE 0x08L
|
#define OPTF_TITLE 0x08L
|
||||||
#define OPTF_TRUNCATE 0x10L
|
#define OPTF_TRUNCATE 0x10L
|
||||||
|
|
||||||
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,0x00,0x0C,0x00,0x0D,
|
0xCE,0xED,0x66,0x66,0xCC,0x0D,0x00,0x0B,0x03,0x73,0x00,0x83,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,0xDD,0xDD,0xD9,0x99,
|
||||||
0xBB,0xBB,0x67,0x63,0x6E,0x0E,0xEC,0xCC,0xDD,0xDC,0x99,0x9F,0xBB,0xB9,0x33,0x3E
|
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 ")\n\n" );
|
||||||
printf( "Usage: rgbfix [options] image[.gb]\n" );
|
printf( "Usage: rgbfix [options] image[.gb]\n" );
|
||||||
printf( "Options:\n" );
|
printf( "Options:\n" );
|
||||||
printf( "\t-h\t\tThis text\n" );
|
printf( "\t-h\t\tThis text\n" );
|
||||||
printf( "\t-d\t\tDebug: Don't change image\n" );
|
printf( "\t-d\t\tDebug: Don't change image\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-p\t\tPad image to valid size\n\t\t\tPads to 32/64/128/256/512kB as appropriate\n" );
|
||||||
printf( "\t-r\t\ttRuncate image to valid size\n\t\t\tTruncates to 32/64/128/256/512kB as appropriate\n" );
|
printf( "\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-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" );
|
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 );
|
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
|
else
|
||||||
return( 0 );
|
return( 0 );
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Das main
|
* Das main
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
int main( int argc, char *argv[] )
|
int main( int argc, char *argv[] )
|
||||||
{
|
{
|
||||||
int argn=1;
|
int argn=1;
|
||||||
char filename[512];
|
char filename[512];
|
||||||
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" );
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* -p (Pad) option code
|
* -p (Pad) option code
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
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
|
||||||
FatalError( "Image size exceeds 512kB" );
|
FatalError( "Image size exceeds 512kB" );
|
||||||
*/
|
*/
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* -r (Truncate) option code
|
* -r (Truncate) option code
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
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 );
|
fseek( f, 0, SEEK_SET );
|
||||||
while( padto-- )
|
while( padto-- )
|
||||||
{
|
{
|
||||||
fputc( fgetc(f), tf );
|
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+" );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* -t (Set carttitle) option code
|
* -t (Set carttitle) option code
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
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 );
|
fflush( f );
|
||||||
fseek( f, 0x0134L, SEEK_SET );
|
fseek( f, 0x0134L, SEEK_SET );
|
||||||
fwrite( cartname, 16, 1, f );
|
fwrite( cartname, 16, 1, f );
|
||||||
fflush( f );
|
fflush( f );
|
||||||
}
|
}
|
||||||
printf( "\tTitle set to %s\n", cartname );
|
printf( "\tTitle set to %s\n", cartname );
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* -v (Validate header) option code
|
* -v (Validate header) option code
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
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 );
|
fseek( f, -1, SEEK_CUR );
|
||||||
fputc( calcromsize, f );
|
fputc( calcromsize, f );
|
||||||
fflush( f );
|
fflush( f );
|
||||||
}
|
}
|
||||||
printf( "\tChanged ROM size byte from 0x%02lX (%ldkB) to 0x%02lX (%ldkB)\n",
|
printf( "\tChanged ROM size byte from 0x%02lX (%ldkB) to 0x%02lX (%ldkB)\n",
|
||||||
cartromsize, (0x8000L<<cartromsize)/1024,
|
cartromsize, (0x8000L<<cartromsize)/1024,
|
||||||
calcromsize, (0x8000L<<calcromsize)/1024 );
|
calcromsize, (0x8000L<<calcromsize)/1024 );
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
printf( "\tROM size byte is OK\n" );
|
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 );
|
fseek( f, -1, SEEK_CUR );
|
||||||
fputc( 0x01, f );
|
fputc( 0x01, f );
|
||||||
fflush( 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 )
|
else if( i==0x014DL )
|
||||||
cartcompchecksum=ch;
|
cartcompchecksum=ch;
|
||||||
else if( i==0x014EL )
|
else if( i==0x014EL )
|
||||||
cartchecksum=ch<<8;
|
cartchecksum=ch<<8;
|
||||||
else if( i==0x014FL )
|
else if( i==0x014FL )
|
||||||
cartchecksum|=ch;
|
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>>8, f );
|
||||||
fputc( calcchecksum&0xFF, 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", (long)cartchecksum, (long)calcchecksum );
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
printf( "\tChecksum is OK\n" );
|
printf( "\tChecksum is OK\n" );
|
||||||
|
|
||||||
|
|
||||||
if( cartcompchecksum!=calccompchecksum )
|
if( cartcompchecksum!=calccompchecksum )
|
||||||
{
|
{
|
||||||
fflush( f );
|
fflush( f );
|
||||||
fseek( f, 0x014DL, SEEK_SET );
|
fseek( f, 0x014DL, SEEK_SET );
|
||||||
if( (ulOptions&OPTF_DEBUG)==0 )
|
if( (ulOptions&OPTF_DEBUG)==0 )
|
||||||
fputc( calccompchecksum, f );
|
fputc( calccompchecksum, f );
|
||||||
fflush( f );
|
fflush( f );
|
||||||
printf( "\tCompChecksum changed from 0x%02lX to 0x%02lX\n", (long)cartcompchecksum, (long)calccompchecksum );
|
printf( "\tCompChecksum changed from 0x%02lX to 0x%02lX\n", (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