Run `indent' on the whole tree

Can't indent the .y files yet, they need special treatment.

Signed-off-by: Vegard Nossum <vegard.nossum@gmail.com>
This commit is contained in:
Vegard Nossum
2009-06-11 07:59:46 +02:00
parent 660f5daac3
commit b6c749ffbd
47 changed files with 5105 additions and 5495 deletions

View File

@@ -43,23 +43,18 @@
in order to make unexec workable
*/
#ifndef STACK_DIRECTION
you
lose
-- must know STACK_DIRECTION at compile-time
#endif /* STACK_DIRECTION undefined */
#endif /* static */
#endif /* emacs */
you lose-- must know STACK_DIRECTION at compile - time
#endif /* STACK_DIRECTION undefined */
#endif /* static */
#endif /* emacs */
/* If your stack is a linked list of frames, you have to
provide an "address metric" ADDRESS_FUNCTION macro. */
#if defined (CRAY) && defined (CRAY_STACKSEG_END)
long i00afunc ();
long i00afunc();
#define ADDRESS_FUNCTION(arg) (char *) i00afunc (&(arg))
#else
#define ADDRESS_FUNCTION(arg) &(arg)
#endif
#if __STDC__
typedef void *pointer;
#else
@@ -104,34 +99,30 @@ extern pointer malloc ();
#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. */
#define STACK_DIR stack_dir
static void
find_stack_direction ()
static void find_stack_direction()
{
static char *addr = NULL; /* Address of first `dummy', once known. */
auto char dummy; /* To get stack address. */
static char *addr = NULL; /* Address of first `dummy', once known. */
auto char dummy; /* To get stack address. */
if (addr == NULL)
{ /* Initial entry. */
addr = ADDRESS_FUNCTION (dummy);
if (addr == NULL) { /* Initial entry. */
addr = ADDRESS_FUNCTION(dummy);
find_stack_direction (); /* Recurse once. */
}
else
{
/* Second entry. */
if (ADDRESS_FUNCTION (dummy) > addr)
stack_dir = 1; /* Stack grew upward. */
else
stack_dir = -1; /* Stack grew downward. */
}
find_stack_direction(); /* Recurse once. */
} else {
/* Second entry. */
if (ADDRESS_FUNCTION(dummy) > addr)
stack_dir = 1; /* Stack grew upward. */
else
stack_dir = -1; /* Stack grew downward. */
}
}
#endif /* STACK_DIRECTION == 0 */
#endif /* STACK_DIRECTION == 0 */
/* An "alloca header" is used to:
(a) chain together all alloca'ed blocks;
@@ -144,14 +135,12 @@ find_stack_direction ()
#define ALIGN_SIZE sizeof(double)
#endif
typedef union hdr
{
char align[ALIGN_SIZE]; /* To force sizeof(header). */
struct
{
union hdr *next; /* For chaining headers. */
char *deep; /* For stack depth measure. */
} h;
typedef union hdr {
char align[ALIGN_SIZE]; /* To force sizeof(header). */
struct {
union hdr *next; /* For chaining headers. */
char *deep; /* For stack depth measure. */
} h;
} header;
static header *last_alloca_header = NULL; /* -> last alloca header. */
@@ -163,66 +152,63 @@ static header *last_alloca_header = NULL; /* -> last alloca header. */
caller, but that method cannot be made to work for some
implementations of C, for example under Gould's UTX/32. */
pointer
alloca (size)
unsigned size;
pointer alloca(size)
unsigned size;
{
auto char probe; /* Probes stack depth: */
register char *depth = ADDRESS_FUNCTION (probe);
auto char probe; /* Probes stack depth: */
register char *depth = ADDRESS_FUNCTION(probe);
#if STACK_DIRECTION == 0
if (STACK_DIR == 0) /* Unknown growth direction. */
find_stack_direction ();
if (STACK_DIR == 0) /* Unknown growth direction. */
find_stack_direction();
#endif
/* Reclaim garbage, defined as all alloca'd storage that
was allocated from deeper in the stack than currently. */
/* Reclaim garbage, defined as all alloca'd storage that
was allocated from deeper in the stack than currently. */
{
register header *hp; /* Traverses linked list. */
#ifdef emacs
BLOCK_INPUT;
#endif
for (hp = last_alloca_header; hp != NULL;)
if ((STACK_DIR > 0 && hp->h.deep > depth)
|| (STACK_DIR < 0 && hp->h.deep < depth))
{
register header *np = hp->h.next;
free ((pointer) hp); /* Collect garbage. */
hp = np; /* -> next header. */
}
else
break; /* Rest are not deeper. */
last_alloca_header = hp; /* -> last valid storage. */
register header *hp; /* Traverses linked list. */
#ifdef emacs
UNBLOCK_INPUT;
BLOCK_INPUT;
#endif
}
if (size == 0)
return NULL; /* No allocation required. */
for (hp = last_alloca_header; hp != NULL;)
if ((STACK_DIR > 0 && hp->h.deep > depth)
|| (STACK_DIR < 0 && hp->h.deep < depth)) {
register header *np = hp->h.next;
/* Allocate combined header + user data storage. */
free((pointer) hp); /* Collect garbage. */
{
register pointer new = malloc (sizeof (header) + size);
/* Address of header. */
hp = np; /* -> next header. */
} else
break; /* Rest are not deeper. */
((header *) new)->h.next = last_alloca_header;
((header *) new)->h.deep = depth;
last_alloca_header = hp; /* -> last valid storage. */
last_alloca_header = (header *) new;
#ifdef emacs
UNBLOCK_INPUT;
#endif
}
/* User storage begins just after header. */
if (size == 0)
return NULL; /* No allocation required. */
return (pointer) ((char *) new + sizeof (header));
}
/* Allocate combined header + user data storage. */
{
register pointer new = malloc(sizeof(header) + size);
/* Address of header. */
((header *) new)->h.next = last_alloca_header;
((header *) new)->h.deep = depth;
last_alloca_header = (header *) new;
/* User storage begins just after header. */
return (pointer) ((char *)new + sizeof(header));
}
}
#if defined (CRAY) && defined (CRAY_STACKSEG_END)
@@ -235,13 +221,12 @@ alloca (size)
#define CRAY_STACK
#ifndef CRAY2
/* Stack structures for CRAY-1, CRAY X-MP, and CRAY Y-MP */
struct stack_control_header
{
long shgrow:32; /* Number of times stack has grown. */
long shaseg:32; /* Size of increments to stack. */
long shhwm:32; /* High water mark of stack. */
long shsize:32; /* Current size of stack (all segments). */
};
struct stack_control_header {
long shgrow:32; /* Number of times stack has grown. */
long shaseg:32; /* Size of increments to stack. */
long shhwm:32; /* High water mark of stack. */
long shsize:32; /* Current size of stack (all segments). */
};
/* The stack segment linkage control information occurs at
the high-address end of a stack segment. (The stack
@@ -250,248 +235,238 @@ struct stack_control_header
0200 (octal) words. This provides for register storage
for the routine which overflows the stack. */
struct stack_segment_linkage
{
long ss[0200]; /* 0200 overflow words. */
long sssize:32; /* Number of words in this segment. */
long ssbase:32; /* Offset to stack base. */
long:32;
long sspseg:32; /* Offset to linkage control of previous
struct stack_segment_linkage {
long ss[0200]; /* 0200 overflow words. */
long sssize:32; /* Number of words in this segment. */
long ssbase:32; /* Offset to stack base. */
long:32;
long sspseg:32; /* Offset to linkage control of previous
segment of stack. */
long:32;
long sstcpt:32; /* Pointer to task common address block. */
long sscsnm; /* Private control structure number for
long:32;
long sstcpt:32; /* Pointer to task common address block. */
long sscsnm; /* Private control structure number for
microtasking. */
long ssusr1; /* Reserved for user. */
long ssusr2; /* Reserved for user. */
long sstpid; /* Process ID for pid based multi-tasking. */
long ssgvup; /* Pointer to multitasking thread giveup. */
long sscray[7]; /* Reserved for Cray Research. */
long ssa0;
long ssa1;
long ssa2;
long ssa3;
long ssa4;
long ssa5;
long ssa6;
long ssa7;
long sss0;
long sss1;
long sss2;
long sss3;
long sss4;
long sss5;
long sss6;
long sss7;
};
long ssusr1; /* Reserved for user. */
long ssusr2; /* Reserved for user. */
long sstpid; /* Process ID for pid based multi-tasking. */
long ssgvup; /* Pointer to multitasking thread giveup. */
long sscray[7]; /* Reserved for Cray Research. */
long ssa0;
long ssa1;
long ssa2;
long ssa3;
long ssa4;
long ssa5;
long ssa6;
long ssa7;
long sss0;
long sss1;
long sss2;
long sss3;
long sss4;
long sss5;
long sss6;
long sss7;
};
#else /* CRAY2 */
#else /* CRAY2 */
/* The following structure defines the vector of words
returned by the STKSTAT library routine. */
struct stk_stat
{
long now; /* Current total stack size. */
long maxc; /* Amount of contiguous space which would
struct stk_stat {
long now; /* Current total stack size. */
long maxc; /* Amount of contiguous space which would
be required to satisfy the maximum
stack demand to date. */
long high_water; /* Stack high-water mark. */
long overflows; /* Number of stack overflow ($STKOFEN) calls. */
long hits; /* Number of internal buffer hits. */
long extends; /* Number of block extensions. */
long stko_mallocs; /* Block allocations by $STKOFEN. */
long underflows; /* Number of stack underflow calls ($STKRETN). */
long stko_free; /* Number of deallocations by $STKRETN. */
long stkm_free; /* Number of deallocations by $STKMRET. */
long segments; /* Current number of stack segments. */
long maxs; /* Maximum number of stack segments so far. */
long pad_size; /* Stack pad size. */
long current_address; /* Current stack segment address. */
long current_size; /* Current stack segment size. This
long high_water; /* Stack high-water mark. */
long overflows; /* Number of stack overflow ($STKOFEN) calls. */
long hits; /* Number of internal buffer hits. */
long extends; /* Number of block extensions. */
long stko_mallocs; /* Block allocations by $STKOFEN. */
long underflows; /* Number of stack underflow calls ($STKRETN). */
long stko_free; /* Number of deallocations by $STKRETN. */
long stkm_free; /* Number of deallocations by $STKMRET. */
long segments; /* Current number of stack segments. */
long maxs; /* Maximum number of stack segments so far. */
long pad_size; /* Stack pad size. */
long current_address; /* Current stack segment address. */
long current_size; /* Current stack segment size. This
number is actually corrupted by STKSTAT to
include the fifteen word trailer area. */
long initial_address; /* Address of initial segment. */
long initial_size; /* Size of initial segment. */
};
long initial_address; /* Address of initial segment. */
long initial_size; /* Size of initial segment. */
};
/* The following structure describes the data structure which trails
any stack segment. I think that the description in 'asdef' is
out of date. I only describe the parts that I am sure about. */
struct stk_trailer
{
long this_address; /* Address of this block. */
long this_size; /* Size of this block (does not include
struct stk_trailer {
long this_address; /* Address of this block. */
long this_size; /* Size of this block (does not include
this trailer). */
long unknown2;
long unknown3;
long link; /* Address of trailer block of previous
long unknown2;
long unknown3;
long link; /* Address of trailer block of previous
segment. */
long unknown5;
long unknown6;
long unknown7;
long unknown8;
long unknown9;
long unknown10;
long unknown11;
long unknown12;
long unknown13;
long unknown14;
};
long unknown5;
long unknown6;
long unknown7;
long unknown8;
long unknown9;
long unknown10;
long unknown11;
long unknown12;
long unknown13;
long unknown14;
};
#endif /* CRAY2 */
#endif /* not CRAY_STACK */
#endif /* CRAY2 */
#endif /* not CRAY_STACK */
#ifdef CRAY2
/* Determine a "stack measure" for an arbitrary ADDRESS.
I doubt that "lint" will like this much. */
static long
i00afunc (long *address)
static long i00afunc(long *address)
{
struct stk_stat status;
struct stk_trailer *trailer;
long *block, size;
long result = 0;
struct stk_stat status;
struct stk_trailer *trailer;
long *block, size;
long result = 0;
/* We want to iterate through all of the segments. The first
step is to get the stack status structure. We could do this
more quickly and more directly, perhaps, by referencing the
$LM00 common block, but I know that this works. */
/* We want to iterate through all of the segments. The first
step is to get the stack status structure. We could do this
more quickly and more directly, perhaps, by referencing the
$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
+ status.current_size
- 15);
trailer = (struct stk_trailer *)(status.current_address
+ status.current_size - 15);
/* There must be at least one stack segment. Therefore it is
a fatal error if "trailer" is null. */
/* There must be at least one stack segment. Therefore it is
a fatal error if "trailer" is null. */
if (trailer == 0)
abort ();
if (trailer == 0)
abort();
/* Discard segments that do not contain our argument address. */
/* Discard segments that do not contain our argument address. */
while (trailer != 0)
{
block = (long *) trailer->this_address;
size = trailer->this_size;
if (block == 0 || size == 0)
abort ();
trailer = (struct stk_trailer *) trailer->link;
if ((block <= address) && (address < (block + size)))
break;
}
while (trailer != 0) {
block = (long *)trailer->this_address;
size = trailer->this_size;
if (block == 0 || size == 0)
abort();
trailer = (struct stk_trailer *)trailer->link;
if ((block <= address) && (address < (block + size)))
break;
}
/* Set the result to the offset in this segment and add the sizes
of all predecessor segments. */
/* Set the result to the offset in this segment and add the sizes
of all predecessor segments. */
result = address - block;
result = address - block;
if (trailer == 0)
{
return result;
}
if (trailer == 0) {
return result;
}
do
{
if (trailer->this_size <= 0)
abort ();
result += trailer->this_size;
trailer = (struct stk_trailer *) trailer->link;
}
while (trailer != 0);
do {
if (trailer->this_size <= 0)
abort();
result += trailer->this_size;
trailer = (struct stk_trailer *)trailer->link;
}
while (trailer != 0);
/* We are done. Note that if you present a bogus address (one
not in any segment), you will get a different number back, formed
from subtracting the address of the first block. This is probably
not what you want. */
/* We are done. Note that if you present a bogus address (one
not in any segment), you will get a different number back, formed
from subtracting the address of the first block. This is probably
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.
Determine the number of the cell within the stack,
given the address of the cell. The purpose of this
routine is to linearize, in some sense, stack addresses
for alloca. */
static long
i00afunc (long address)
static long i00afunc(long address)
{
long stkl = 0;
long stkl = 0;
long size, pseg, this_segment, stack;
long result = 0;
long size, pseg, this_segment, stack;
long result = 0;
struct stack_segment_linkage *ssptr;
struct stack_segment_linkage *ssptr;
/* Register B67 contains the address of the end of the
current stack segment. If you (as a subprogram) store
your registers on the stack and find that you are past
the contents of B67, you have overflowed the segment.
/* Register B67 contains the address of the end of the
current stack segment. If you (as a subprogram) store
your registers on the stack and find that you are past
the contents of B67, you have overflowed the segment.
B67 also points to the stack segment linkage control
area, which is what we are really interested in. */
B67 also points to the stack segment linkage control
area, which is what we are really interested in. */
stkl = CRAY_STACKSEG_END ();
ssptr = (struct stack_segment_linkage *) stkl;
stkl = CRAY_STACKSEG_END();
ssptr = (struct stack_segment_linkage *)stkl;
/* If one subtracts 'size' from the end of the segment,
one has the address of the first word of the segment.
/* If one subtracts 'size' from the end of the segment,
one has the address of the first word of the segment.
If this is not the first segment, 'pseg' will be
nonzero. */
If this is not the first segment, 'pseg' will be
nonzero. */
pseg = ssptr->sspseg;
size = ssptr->sssize;
pseg = ssptr->sspseg;
size = ssptr->sssize;
this_segment = stkl - size;
this_segment = stkl - size;
/* It is possible that calling this routine itself caused
a stack overflow. Discard stack segments which do not
contain the target address. */
/* It is possible that calling this routine itself caused
a stack overflow. Discard stack segments which do not
contain the target address. */
while (!(this_segment <= address && address <= stkl))
{
while (!(this_segment <= address && address <= stkl)) {
#ifdef DEBUG_I00AFUNC
fprintf (stderr, "%011o %011o %011o\n", this_segment, address, stkl);
fprintf(stderr, "%011o %011o %011o\n", this_segment, address,
stkl);
#endif
if (pseg == 0)
break;
stkl = stkl - pseg;
ssptr = (struct stack_segment_linkage *) stkl;
size = ssptr->sssize;
pseg = ssptr->sspseg;
this_segment = stkl - size;
}
if (pseg == 0)
break;
stkl = stkl - pseg;
ssptr = (struct stack_segment_linkage *)stkl;
size = ssptr->sssize;
pseg = ssptr->sspseg;
this_segment = stkl - size;
}
result = address - this_segment;
result = address - this_segment;
/* If you subtract pseg from the current end of the stack,
you get the address of the previous stack segment's end.
This seems a little convoluted to me, but I'll bet you save
a cycle somewhere. */
/* If you subtract pseg from the current end of the stack,
you get the address of the previous stack segment's end.
This seems a little convoluted to me, but I'll bet you save
a cycle somewhere. */
while (pseg != 0)
{
while (pseg != 0) {
#ifdef DEBUG_I00AFUNC
fprintf (stderr, "%011o %011o\n", pseg, size);
fprintf(stderr, "%011o %011o\n", pseg, size);
#endif
stkl = stkl - pseg;
ssptr = (struct stack_segment_linkage *) stkl;
size = ssptr->sssize;
pseg = ssptr->sspseg;
result += size;
}
return (result);
stkl = stkl - pseg;
ssptr = (struct stack_segment_linkage *)stkl;
size = ssptr->sssize;
pseg = ssptr->sspseg;
result += size;
}
return (result);
}
#endif /* not CRAY2 */
#endif /* CRAY */
#endif /* not CRAY2 */
#endif /* CRAY */
#endif /* no alloca */
#endif /* not GCC version 2 */
#endif /* no alloca */
#endif /* not GCC version 2 */

View File

@@ -21,21 +21,21 @@
*
*/
struct sContext *pFileStack;
struct sSymbol *pCurrentMacro;
YY_BUFFER_STATE CurrentFlexHandle;
FILE *pCurrentFile;
ULONG nCurrentStatus;
char tzCurrentFileName[_MAX_PATH + 1];
char IncludePaths[MAXINCPATHS][_MAX_PATH + 1];
SLONG NextIncPath = 0;
ULONG nMacroCount;
struct sContext *pFileStack;
struct sSymbol *pCurrentMacro;
YY_BUFFER_STATE CurrentFlexHandle;
FILE *pCurrentFile;
ULONG nCurrentStatus;
char tzCurrentFileName[_MAX_PATH + 1];
char IncludePaths[MAXINCPATHS][_MAX_PATH + 1];
SLONG NextIncPath = 0;
ULONG nMacroCount;
char *pCurrentREPTBlock;
ULONG nCurrentREPTBlockSize;
ULONG nCurrentREPTBlockCount;
char *pCurrentREPTBlock;
ULONG nCurrentREPTBlockSize;
ULONG nCurrentREPTBlockCount;
ULONG ulMacroReturnValue;
ULONG ulMacroReturnValue;
/*
* defines for nCurrentStatus
@@ -45,18 +45,17 @@ ULONG ulMacroReturnValue;
#define STAT_isMacroArg 2
#define STAT_isREPTBlock 3
ULONG filesize (char *s)
ULONG filesize(char *s)
{
FILE *f;
ULONG size = 0;
FILE *f;
ULONG size = 0;
if( (f=fopen(s,"rt"))!=NULL )
{
fseek (f, 0, SEEK_END);
size = ftell (f);
fclose (f);
}
return (size);
if ((f = fopen(s, "rt")) != NULL) {
fseek(f, 0, SEEK_END);
size = ftell(f);
fclose(f);
}
return (size);
}
/*
@@ -66,115 +65,110 @@ ULONG filesize (char *s)
*
*/
void pushcontext (void)
void pushcontext(void)
{
struct sContext **ppFileStack;
struct sContext **ppFileStack;
ppFileStack = &pFileStack;
while (*ppFileStack)
ppFileStack = &((*ppFileStack)->pNext);
ppFileStack = &pFileStack;
while (*ppFileStack)
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)->pNext = NULL;
strcpy ( (char *)(*ppFileStack)->tzFileName, (char *)tzCurrentFileName);
strcpy((char *)(*ppFileStack)->tzFileName,
(char *)tzCurrentFileName);
(*ppFileStack)->nLine = nLineNo;
switch ((*ppFileStack)->nStatus = nCurrentStatus)
{
case STAT_isMacroArg:
case STAT_isMacro:
sym_SaveCurrentMacroArgs ((*ppFileStack)->tzMacroArgs);
(*ppFileStack)->pMacro = pCurrentMacro;
break;
case STAT_isInclude:
(*ppFileStack)->pFile = pCurrentFile;
break;
case STAT_isREPTBlock:
sym_SaveCurrentMacroArgs ((*ppFileStack)->tzMacroArgs);
(*ppFileStack)->pREPTBlock = pCurrentREPTBlock;
(*ppFileStack)->nREPTBlockSize = nCurrentREPTBlockSize;
(*ppFileStack)->nREPTBlockCount = nCurrentREPTBlockCount;
break;
switch ((*ppFileStack)->nStatus = nCurrentStatus) {
case STAT_isMacroArg:
case STAT_isMacro:
sym_SaveCurrentMacroArgs((*ppFileStack)->tzMacroArgs);
(*ppFileStack)->pMacro = pCurrentMacro;
break;
case STAT_isInclude:
(*ppFileStack)->pFile = pCurrentFile;
break;
case STAT_isREPTBlock:
sym_SaveCurrentMacroArgs((*ppFileStack)->tzMacroArgs);
(*ppFileStack)->pREPTBlock = pCurrentREPTBlock;
(*ppFileStack)->nREPTBlockSize = nCurrentREPTBlockSize;
(*ppFileStack)->nREPTBlockCount =
nCurrentREPTBlockCount;
break;
}
nLineNo = 0;
}
else
fatalerror ("No memory for context");
} else
fatalerror("No memory for context");
}
int popcontext (void)
int popcontext(void)
{
struct sContext *pLastFile,
**ppLastFile;
struct sContext *pLastFile, **ppLastFile;
if (nCurrentStatus == STAT_isREPTBlock)
{
if (--nCurrentREPTBlockCount)
{
yy_delete_buffer (CurrentFlexHandle);
CurrentFlexHandle = yy_scan_bytes (pCurrentREPTBlock, nCurrentREPTBlockSize);
yy_switch_to_buffer (CurrentFlexHandle);
sym_UseCurrentMacroArgs ();
sym_SetMacroArgID (nMacroCount++);
sym_UseNewMacroArgs ();
return (0);
if (nCurrentStatus == STAT_isREPTBlock) {
if (--nCurrentREPTBlockCount) {
yy_delete_buffer(CurrentFlexHandle);
CurrentFlexHandle =
yy_scan_bytes(pCurrentREPTBlock,
nCurrentREPTBlockSize);
yy_switch_to_buffer(CurrentFlexHandle);
sym_UseCurrentMacroArgs();
sym_SetMacroArgID(nMacroCount++);
sym_UseNewMacroArgs();
return (0);
}
}
}
if( (pLastFile=pFileStack)!=NULL )
{
if ((pLastFile = pFileStack) != NULL) {
ppLastFile = &pFileStack;
while (pLastFile->pNext)
{
ppLastFile = &(pLastFile->pNext);
pLastFile = *ppLastFile;
while (pLastFile->pNext) {
ppLastFile = &(pLastFile->pNext);
pLastFile = *ppLastFile;
}
yy_delete_buffer (CurrentFlexHandle);
yy_delete_buffer(CurrentFlexHandle);
nLineNo = pLastFile->nLine;
if (nCurrentStatus == STAT_isInclude)
fclose (pCurrentFile);
if (nCurrentStatus == STAT_isMacro)
{
sym_FreeCurrentMacroArgs ();
nLineNo += 1;
fclose(pCurrentFile);
if (nCurrentStatus == STAT_isMacro) {
sym_FreeCurrentMacroArgs();
nLineNo += 1;
}
if (nCurrentStatus == STAT_isREPTBlock)
nLineNo += 1;
nLineNo += 1;
CurrentFlexHandle = pLastFile->FlexHandle;
strcpy ((char *)tzCurrentFileName, (char *)pLastFile->tzFileName);
switch (nCurrentStatus = pLastFile->nStatus)
{
case STAT_isMacroArg:
case STAT_isMacro:
sym_RestoreCurrentMacroArgs (pLastFile->tzMacroArgs);
pCurrentMacro = pLastFile->pMacro;
break;
case STAT_isInclude:
pCurrentFile = pLastFile->pFile;
break;
case STAT_isREPTBlock:
sym_RestoreCurrentMacroArgs (pLastFile->tzMacroArgs);
pCurrentREPTBlock = pLastFile->pREPTBlock;
nCurrentREPTBlockSize = pLastFile->nREPTBlockSize;
nCurrentREPTBlockCount = pLastFile->nREPTBlockCount;
break;
strcpy((char *)tzCurrentFileName,
(char *)pLastFile->tzFileName);
switch (nCurrentStatus = pLastFile->nStatus) {
case STAT_isMacroArg:
case STAT_isMacro:
sym_RestoreCurrentMacroArgs(pLastFile->tzMacroArgs);
pCurrentMacro = pLastFile->pMacro;
break;
case STAT_isInclude:
pCurrentFile = pLastFile->pFile;
break;
case STAT_isREPTBlock:
sym_RestoreCurrentMacroArgs(pLastFile->tzMacroArgs);
pCurrentREPTBlock = pLastFile->pREPTBlock;
nCurrentREPTBlockSize = pLastFile->nREPTBlockSize;
nCurrentREPTBlockCount = pLastFile->nREPTBlockCount;
break;
}
free (*ppLastFile);
free(*ppLastFile);
*ppLastFile = NULL;
yy_switch_to_buffer (CurrentFlexHandle);
yy_switch_to_buffer(CurrentFlexHandle);
return (0);
}
else
} else
return (1);
}
int yywrap (void)
int yywrap(void)
{
return (popcontext ());
return (popcontext());
}
/*
@@ -184,19 +178,18 @@ int yywrap (void)
*
*/
void fstk_Dump (void)
void fstk_Dump(void)
{
struct sContext *pLastFile;
struct sContext *pLastFile;
pLastFile = pFileStack;
pLastFile = pFileStack;
while (pLastFile)
{
printf ("%s(%ld) -> ", pLastFile->tzFileName, pLastFile->nLine);
while (pLastFile) {
printf("%s(%ld) -> ", pLastFile->tzFileName, pLastFile->nLine);
pLastFile = pLastFile->pNext;
}
}
printf ("%s(%ld)", tzCurrentFileName, nLineNo);
printf("%s(%ld)", tzCurrentFileName, nLineNo);
}
/*
@@ -206,35 +199,32 @@ void fstk_Dump (void)
*
*/
void fstk_AddIncludePath (char *s)
void fstk_AddIncludePath(char *s)
{
strcpy (IncludePaths[NextIncPath++], s);
strcpy(IncludePaths[NextIncPath++], s);
}
void fstk_FindFile (char *s)
void fstk_FindFile(char *s)
{
char t[_MAX_PATH + 1];
SLONG i = -1;
char t[_MAX_PATH + 1];
SLONG i = -1;
strcpy (t, s);
strcpy(t, s);
while (i < NextIncPath)
{
FILE *f;
while (i < NextIncPath) {
FILE *f;
if( (f=fopen(t,"rb"))!=NULL )
{
fclose (f);
strcpy (s, t);
return;
if ((f = fopen(t, "rb")) != NULL) {
fclose(f);
strcpy(s, t);
return;
}
i += 1;
if (i < NextIncPath)
{
strcpy (t, IncludePaths[i]);
strcat (t, s);
if (i < NextIncPath) {
strcpy(t, IncludePaths[i]);
strcat(t, s);
}
}
}
}
/*
@@ -244,35 +234,33 @@ void fstk_FindFile (char *s)
*
*/
ULONG fstk_RunInclude (char *s)
ULONG fstk_RunInclude(char *s)
{
FILE *f;
char tzFileName[_MAX_PATH + 1];
FILE *f;
char tzFileName[_MAX_PATH + 1];
//printf( "INCLUDE: %s\n", s );
strcpy (tzFileName, s);
fstk_FindFile (tzFileName);
strcpy(tzFileName, s);
fstk_FindFile(tzFileName);
//printf( "INCLUDING: %s\n", tzFileName );
if( (f=fopen(tzFileName,"rt"))!=NULL )
{
pushcontext ();
if ((f = fopen(tzFileName, "rt")) != NULL) {
pushcontext();
nLineNo = 1;
nCurrentStatus = STAT_isInclude;
strcpy (tzCurrentFileName, tzFileName);
strcpy(tzCurrentFileName, tzFileName);
pCurrentFile = f;
CurrentFlexHandle = yy_create_buffer (pCurrentFile);
yy_switch_to_buffer (CurrentFlexHandle);
CurrentFlexHandle = yy_create_buffer(pCurrentFile);
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' );
nLineNo-=1;
yyunput('\n');
nLineNo -= 1;
return (1);
}
else
} else
return (0);
}
@@ -283,24 +271,24 @@ ULONG fstk_RunInclude (char *s)
*
*/
ULONG fstk_RunMacro (char *s)
ULONG fstk_RunMacro(char *s)
{
struct sSymbol *sym;
struct sSymbol *sym;
if( (sym=sym_FindMacro(s))!=NULL )
{
pushcontext ();
sym_SetMacroArgID (nMacroCount++);
if ((sym = sym_FindMacro(s)) != NULL) {
pushcontext();
sym_SetMacroArgID(nMacroCount++);
nLineNo = -1;
sym_UseNewMacroArgs ();
sym_UseNewMacroArgs();
nCurrentStatus = STAT_isMacro;
strcpy (tzCurrentFileName, s);
strcpy(tzCurrentFileName, s);
pCurrentMacro = sym;
CurrentFlexHandle = yy_scan_bytes (pCurrentMacro->pMacro, pCurrentMacro->ulMacroSize);
yy_switch_to_buffer (CurrentFlexHandle);
CurrentFlexHandle =
yy_scan_bytes(pCurrentMacro->pMacro,
pCurrentMacro->ulMacroSize);
yy_switch_to_buffer(CurrentFlexHandle);
return (1);
}
else
} else
return (0);
}
@@ -311,25 +299,23 @@ ULONG fstk_RunMacro (char *s)
*
*/
void fstk_RunMacroArg (SLONG s)
void fstk_RunMacroArg(SLONG s)
{
char *sym;
char *sym;
if (s == '@')
if (s == '@')
s = -1;
else
else
s -= '0';
if( (sym=sym_FindMacroArg(s))!=NULL )
{
pushcontext ();
if ((sym = sym_FindMacroArg(s)) != NULL) {
pushcontext();
nCurrentStatus = STAT_isMacroArg;
sprintf (tzCurrentFileName, "%c", (UBYTE)s);
CurrentFlexHandle = yy_scan_bytes (sym, strlen (sym));
yy_switch_to_buffer (CurrentFlexHandle);
}
else
fatalerror ("No such macroargument");
sprintf(tzCurrentFileName, "%c", (UBYTE) s);
CurrentFlexHandle = yy_scan_bytes(sym, strlen(sym));
yy_switch_to_buffer(CurrentFlexHandle);
} else
fatalerror("No such macroargument");
}
/*
@@ -339,20 +325,19 @@ void fstk_RunMacroArg (SLONG s)
*
*/
void fstk_RunString (char *s)
void fstk_RunString(char *s)
{
struct sSymbol *pSym;
struct sSymbol *pSym;
if( (pSym=sym_FindSymbol(s))!=NULL )
{
pushcontext ();
if ((pSym = sym_FindSymbol(s)) != NULL) {
pushcontext();
nCurrentStatus = STAT_isMacroArg;
strcpy (tzCurrentFileName, s);
CurrentFlexHandle = yy_scan_bytes (pSym->pMacro, strlen (pSym->pMacro));
yy_switch_to_buffer (CurrentFlexHandle);
}
else
yyerror ("No such string symbol");
strcpy(tzCurrentFileName, s);
CurrentFlexHandle =
yy_scan_bytes(pSym->pMacro, strlen(pSym->pMacro));
yy_switch_to_buffer(CurrentFlexHandle);
} else
yyerror("No such string symbol");
}
/*
@@ -362,21 +347,21 @@ void fstk_RunString (char *s)
*
*/
void fstk_RunRept (ULONG count)
void fstk_RunRept(ULONG count)
{
if (count)
{
pushcontext ();
sym_UseCurrentMacroArgs ();
sym_SetMacroArgID (nMacroCount++);
sym_UseNewMacroArgs ();
if (count) {
pushcontext();
sym_UseCurrentMacroArgs();
sym_SetMacroArgID(nMacroCount++);
sym_UseNewMacroArgs();
nCurrentREPTBlockCount = count;
nCurrentStatus = STAT_isREPTBlock;
nCurrentREPTBlockSize = ulNewMacroSize;
pCurrentREPTBlock = tzNewMacro;
CurrentFlexHandle = yy_scan_bytes (pCurrentREPTBlock, nCurrentREPTBlockSize);
yy_switch_to_buffer (CurrentFlexHandle);
}
CurrentFlexHandle =
yy_scan_bytes(pCurrentREPTBlock, nCurrentREPTBlockSize);
yy_switch_to_buffer(CurrentFlexHandle);
}
}
/*
@@ -386,26 +371,24 @@ void fstk_RunRept (ULONG count)
*
*/
ULONG fstk_Init (char *s)
ULONG fstk_Init(char *s)
{
char tzFileName[_MAX_PATH + 1];
char tzFileName[_MAX_PATH + 1];
sym_AddString ("__FILE__", s);
sym_AddString("__FILE__", s);
strcpy (tzFileName, s);
fstk_FindFile (tzFileName);
strcpy(tzFileName, s);
fstk_FindFile(tzFileName);
pFileStack = NULL;
if( (pCurrentFile=fopen(tzFileName,"rt"))!=NULL )
{
pFileStack = NULL;
if ((pCurrentFile = fopen(tzFileName, "rt")) != NULL) {
nMacroCount = 0;
nCurrentStatus = STAT_isInclude;
strcpy (tzCurrentFileName, tzFileName);
CurrentFlexHandle = yy_create_buffer (pCurrentFile);
yy_switch_to_buffer (CurrentFlexHandle);
strcpy(tzCurrentFileName, tzFileName);
CurrentFlexHandle = yy_create_buffer(pCurrentFile);
yy_switch_to_buffer(CurrentFlexHandle);
nLineNo = 1;
return (1);
}
else
} else
return (0);
}
}

View File

@@ -95,36 +95,33 @@
/* "r" defs */
enum
{
REG_B=0,
REG_C,
REG_D,
REG_E,
REG_H,
REG_L,
REG_HL_IND,
REG_A
enum {
REG_B = 0,
REG_C,
REG_D,
REG_E,
REG_H,
REG_L,
REG_HL_IND,
REG_A
};
/* "rr" defs */
enum
{
REG_BC_IND=0,
REG_DE_IND,
REG_HL_INDINC,
REG_HL_INDDEC,
enum {
REG_BC_IND = 0,
REG_DE_IND,
REG_HL_INDINC,
REG_HL_INDDEC,
};
/* "ss" defs */
enum
{
REG_BC=0,
REG_DE,
REG_HL,
REG_SP
enum {
REG_BC = 0,
REG_DE,
REG_HL,
REG_SP
};
/* "tt" defs */
@@ -138,17 +135,9 @@ enum
/* "cc" defs */
enum
{
CC_NZ=0,
CC_Z,
CC_NC,
CC_C
enum {
CC_NZ = 0,
CC_Z,
CC_NC,
CC_C
};

View File

@@ -3,87 +3,86 @@
#include "rpn.h"
#include "asmy.h"
struct sLexInitString localstrings[] =
{
"adc", T_Z80_ADC,
"add", T_Z80_ADD,
"and", T_Z80_AND,
"bit", T_Z80_BIT,
"call", T_Z80_CALL,
"ccf", T_Z80_CCF,
"cpl", T_Z80_CPL,
"cp", T_Z80_CP,
"daa", T_Z80_DAA,
"dec", T_Z80_DEC,
"di", T_Z80_DI,
"ei", T_Z80_EI,
"ex", T_Z80_EX,
"halt", T_Z80_HALT,
"inc", T_Z80_INC,
"jp", T_Z80_JP,
"jr", T_Z80_JR,
"ld", T_Z80_LD,
"ldi", T_Z80_LDI,
"ldd", T_Z80_LDD,
"ldio", T_Z80_LDIO,
"ldh", T_Z80_LDIO,
"nop", T_Z80_NOP,
"or", T_Z80_OR,
"pop", T_Z80_POP,
"push", T_Z80_PUSH,
"res", T_Z80_RES,
"reti", T_Z80_RETI,
"ret", T_Z80_RET,
"rlca", T_Z80_RLCA,
"rlc", T_Z80_RLC,
"rla", T_Z80_RLA,
"rl", T_Z80_RL,
"rrc", T_Z80_RRC,
"rrca", T_Z80_RRCA,
"rra", T_Z80_RRA,
"rr", T_Z80_RR,
"rst", T_Z80_RST,
"sbc", T_Z80_SBC,
"scf", T_Z80_SCF,
struct sLexInitString localstrings[] = {
"adc", T_Z80_ADC,
"add", T_Z80_ADD,
"and", T_Z80_AND,
"bit", T_Z80_BIT,
"call", T_Z80_CALL,
"ccf", T_Z80_CCF,
"cpl", T_Z80_CPL,
"cp", T_Z80_CP,
"daa", T_Z80_DAA,
"dec", T_Z80_DEC,
"di", T_Z80_DI,
"ei", T_Z80_EI,
"ex", T_Z80_EX,
"halt", T_Z80_HALT,
"inc", T_Z80_INC,
"jp", T_Z80_JP,
"jr", T_Z80_JR,
"ld", T_Z80_LD,
"ldi", T_Z80_LDI,
"ldd", T_Z80_LDD,
"ldio", T_Z80_LDIO,
"ldh", T_Z80_LDIO,
"nop", T_Z80_NOP,
"or", T_Z80_OR,
"pop", T_Z80_POP,
"push", T_Z80_PUSH,
"res", T_Z80_RES,
"reti", T_Z80_RETI,
"ret", T_Z80_RET,
"rlca", T_Z80_RLCA,
"rlc", T_Z80_RLC,
"rla", T_Z80_RLA,
"rl", T_Z80_RL,
"rrc", T_Z80_RRC,
"rrca", T_Z80_RRCA,
"rra", T_Z80_RRA,
"rr", T_Z80_RR,
"rst", T_Z80_RST,
"sbc", T_Z80_SBC,
"scf", T_Z80_SCF,
// Handled by globallex.c
// "set" , T_POP_SET,
"sla", T_Z80_SLA,
"sra", T_Z80_SRA,
"srl", T_Z80_SRL,
"stop", T_Z80_STOP,
"sub", T_Z80_SUB,
"swap", T_Z80_SWAP,
"xor", T_Z80_XOR,
"sla", T_Z80_SLA,
"sra", T_Z80_SRA,
"srl", T_Z80_SRL,
"stop", T_Z80_STOP,
"sub", T_Z80_SUB,
"swap", T_Z80_SWAP,
"xor", T_Z80_XOR,
"nz", T_CC_NZ,
"z", T_CC_Z,
"nc", T_CC_NC,
"nz", T_CC_NZ,
"z", T_CC_Z,
"nc", T_CC_NC,
// "c" , T_MODE_C
"[hl]", T_MODE_HL_IND,
"[hl+]", T_MODE_HL_INDINC,
"[hl-]", T_MODE_HL_INDDEC,
"[hli]", T_MODE_HL_INDINC,
"[hld]", T_MODE_HL_INDDEC,
"hl", T_MODE_HL,
"af", T_MODE_AF,
"[bc]", T_MODE_BC_IND,
"bc", T_MODE_BC,
"[de]", T_MODE_DE_IND,
"de", T_MODE_DE,
"[sp]", T_MODE_SP_IND,
"sp", T_MODE_SP,
"a", T_MODE_A,
"b", T_MODE_B,
"[$ff00+c]", T_MODE_C_IND,
"[c]", T_MODE_C_IND,
"c", T_MODE_C,
"d", T_MODE_D,
"e", T_MODE_E,
"h", T_MODE_H,
"l", T_MODE_L,
"[hl]", T_MODE_HL_IND,
"[hl+]", T_MODE_HL_INDINC,
"[hl-]", T_MODE_HL_INDDEC,
"[hli]", T_MODE_HL_INDINC,
"[hld]", T_MODE_HL_INDDEC,
"hl", T_MODE_HL,
"af", T_MODE_AF,
"[bc]", T_MODE_BC_IND,
"bc", T_MODE_BC,
"[de]", T_MODE_DE_IND,
"de", T_MODE_DE,
"[sp]", T_MODE_SP_IND,
"sp", T_MODE_SP,
"a", T_MODE_A,
"b", T_MODE_B,
"[$ff00+c]", T_MODE_C_IND,
"[c]", T_MODE_C_IND,
"c", T_MODE_C,
"d", T_MODE_D,
"e", T_MODE_E,
"h", T_MODE_H,
"l", T_MODE_L,
NULL, 0
};
NULL, 0
};

View File

@@ -10,350 +10,320 @@
#include <math.h>
#include <string.h>
UBYTE oDontExpandStrings=0;
SLONG nGBGfxID=-1;
SLONG nBinaryID=-1;
UBYTE oDontExpandStrings = 0;
SLONG nGBGfxID = -1;
SLONG nBinaryID = -1;
SLONG gbgfx2bin (char ch)
SLONG gbgfx2bin(char ch)
{
SLONG i;
SLONG i;
for( i=0; i<=3; i+=1 )
{
if( CurrentOptions.gbgfx[i]==ch )
{
return( i );
for (i = 0; i <= 3; i += 1) {
if (CurrentOptions.gbgfx[i] == ch) {
return (i);
}
}
return (0);
return (0);
}
SLONG binary2bin (char ch)
SLONG binary2bin(char ch)
{
SLONG i;
SLONG i;
for( i=0; i<=1; i+=1 )
{
if( CurrentOptions.binary[i]==ch )
{
return( i );
for (i = 0; i <= 1; i += 1) {
if (CurrentOptions.binary[i] == ch) {
return (i);
}
}
return (0);
return (0);
}
SLONG char2bin (char ch)
SLONG char2bin(char ch)
{
if (ch >= 'a' && ch <= 'f')
if (ch >= 'a' && ch <= 'f')
return (ch - 'a' + 10);
if (ch >= 'A' && ch <= 'F')
if (ch >= 'A' && ch <= 'F')
return (ch - 'A' + 10);
if (ch >= '0' && ch <= '9')
if (ch >= '0' && ch <= '9')
return (ch - '0');
return (0);
return (0);
}
typedef SLONG (*x2bin)(char ch);
typedef SLONG(*x2bin) (char ch);
SLONG ascii2bin (char *s)
SLONG ascii2bin(char *s)
{
SLONG radix = 10;
SLONG result = 0;
x2bin convertfunc=char2bin;
SLONG radix = 10;
SLONG result = 0;
x2bin convertfunc = char2bin;
switch (*s)
{
case '$':
radix = 16;
s += 1;
convertfunc=char2bin;
break;
case '&':
radix = 8;
s += 1;
convertfunc=char2bin;
break;
case '`':
radix = 4;
s += 1;
convertfunc=gbgfx2bin;
break;
case '%':
radix = 2;
s += 1;
convertfunc=binary2bin;
break;
}
switch (*s) {
case '$':
radix = 16;
s += 1;
convertfunc = char2bin;
break;
case '&':
radix = 8;
s += 1;
convertfunc = char2bin;
break;
case '`':
radix = 4;
s += 1;
convertfunc = gbgfx2bin;
break;
case '%':
radix = 2;
s += 1;
convertfunc = binary2bin;
break;
}
if (radix == 4)
{
SLONG c;
if (radix == 4) {
SLONG c;
while (*s != '\0')
{
c = convertfunc (*s++);
result = result * 2 + ((c & 1) << 8) + ((c & 2) >> 1);
while (*s != '\0') {
c = convertfunc(*s++);
result = result * 2 + ((c & 1) << 8) + ((c & 2) >> 1);
}
}
else
{
} else {
while (*s != '\0')
result = result * radix + convertfunc (*s++);
}
result = result * radix + convertfunc(*s++);
}
return (result);
return (result);
}
ULONG ParseFixedPoint (char *s, ULONG size)
ULONG ParseFixedPoint(char *s, ULONG size)
{
char dest[256];
ULONG i = 0,
dot = 0;
char dest[256];
ULONG i = 0, dot = 0;
while (size && dot != 2)
{
while (size && dot != 2) {
if (s[i] == '.')
dot += 1;
dot += 1;
if (dot < 2)
{
dest[i] = s[i];
size -= 1;
i += 1;
if (dot < 2) {
dest[i] = s[i];
size -= 1;
i += 1;
}
}
}
dest[i] = 0;
dest[i] = 0;
yyunputbytes (size);
yyunputbytes(size);
yylval.nConstValue = (SLONG) (atof (s) * 65536);
yylval.nConstValue = (SLONG) (atof(s) * 65536);
return (1);
return (1);
}
ULONG ParseNumber (char *s, ULONG size)
ULONG ParseNumber(char *s, ULONG size)
{
char dest[256];
char dest[256];
strncpy (dest, s, size);
dest[size] = 0;
yylval.nConstValue = ascii2bin (dest);
strncpy(dest, s, size);
dest[size] = 0;
yylval.nConstValue = ascii2bin(dest);
return (1);
return (1);
}
ULONG ParseSymbol (char *src, ULONG size)
ULONG ParseSymbol(char *src, ULONG size)
{
char dest[MAXSYMLEN + 1];
int copied = 0,
size_backup = size;
char dest[MAXSYMLEN + 1];
int copied = 0, size_backup = size;
while (size && copied < MAXSYMLEN)
{
if (*src == '\\')
{
char *marg;
while (size && copied < MAXSYMLEN) {
if (*src == '\\') {
char *marg;
src += 1;
size -= 1;
src += 1;
size -= 1;
if (*src == '@')
marg = sym_FindMacroArg (-1);
else if (*src >= '0' && *src <= '9')
marg = sym_FindMacroArg (*src);
else
{
fatalerror ("Malformed ID");
return(0);
if (*src == '@')
marg = sym_FindMacroArg(-1);
else if (*src >= '0' && *src <= '9')
marg = sym_FindMacroArg(*src);
else {
fatalerror("Malformed ID");
return (0);
}
src += 1;
size -= 1;
src += 1;
size -= 1;
if (marg)
{
if (marg) {
while (*marg)
dest[copied++] = *marg++;
}
dest[copied++] = *marg++;
}
} else {
dest[copied++] = *src++;
size -= 1;
}
else
{
dest[copied++] = *src++;
size -= 1;
}
}
}
if (copied > MAXSYMLEN)
fatalerror ("Symbol too long");
if (copied > MAXSYMLEN)
fatalerror("Symbol too long");
dest[copied] = 0;
dest[copied] = 0;
if( oDontExpandStrings==0
&& sym_isString(dest) )
{
char *s;
if (oDontExpandStrings == 0 && sym_isString(dest)) {
char *s;
yyskipbytes( size_backup );
yyunputstr( s=sym_GetStringValue(dest) );
yyskipbytes(size_backup);
yyunputstr(s = sym_GetStringValue(dest));
while( *s )
{
if( *s++=='\n' )
{
nLineNo-=1;
while (*s) {
if (*s++ == '\n') {
nLineNo -= 1;
}
}
return (0);
}
else
{
strcpy( yylval.tzString, dest );
} else {
strcpy(yylval.tzString, dest);
return (1);
}
}
ULONG PutMacroArg (char *src, ULONG size)
{
char *s;
yyskipbytes (size);
if( (s=sym_FindMacroArg (src[1] - '0'))!=NULL )
{
yyunputstr(s);
}
else
{
yyerror( "Macro argument not defined" );
}
ULONG PutMacroArg(char *src, ULONG size)
{
char *s;
yyskipbytes(size);
if ((s = sym_FindMacroArg(src[1] - '0')) != NULL) {
yyunputstr(s);
} else {
yyerror("Macro argument not defined");
}
return (0);
return (0);
}
ULONG PutUniqueArg (char *src, ULONG size)
ULONG PutUniqueArg(char *src, ULONG size)
{
src=src;
yyskipbytes (size);
yyunputstr (sym_FindMacroArg (-1));
return (0);
src = src;
yyskipbytes(size);
yyunputstr(sym_FindMacroArg(-1));
return (0);
}
enum
{
T_LEX_MACROARG = 3000,
T_LEX_MACROUNIQUE
enum {
T_LEX_MACROARG = 3000,
T_LEX_MACROUNIQUE
};
extern struct sLexInitString localstrings[];
struct sLexInitString staticstrings[] =
{
"||", T_OP_LOGICOR,
"&&", T_OP_LOGICAND,
"==", T_OP_LOGICEQU,
">", T_OP_LOGICGT,
"<", T_OP_LOGICLT,
">=", T_OP_LOGICGE,
"<=", T_OP_LOGICLE,
"!=", T_OP_LOGICNE,
"!", T_OP_LOGICNOT,
"|", T_OP_OR,
"^", T_OP_XOR,
"&", T_OP_AND,
"<<", T_OP_SHL,
">>", T_OP_SHR,
"+", T_OP_ADD,
"-", T_OP_SUB,
"*", T_OP_MUL,
"/", T_OP_DIV,
"%", T_OP_MOD,
"~", T_OP_NOT,
struct sLexInitString staticstrings[] = {
"||", T_OP_LOGICOR,
"&&", T_OP_LOGICAND,
"==", T_OP_LOGICEQU,
">", T_OP_LOGICGT,
"<", T_OP_LOGICLT,
">=", T_OP_LOGICGE,
"<=", T_OP_LOGICLE,
"!=", T_OP_LOGICNE,
"!", T_OP_LOGICNOT,
"|", T_OP_OR,
"^", T_OP_XOR,
"&", T_OP_AND,
"<<", T_OP_SHL,
">>", T_OP_SHR,
"+", T_OP_ADD,
"-", T_OP_SUB,
"*", T_OP_MUL,
"/", T_OP_DIV,
"%", T_OP_MOD,
"~", T_OP_NOT,
"def", T_OP_DEF,
"def", T_OP_DEF,
"bank", T_OP_BANK,
"bank", T_OP_BANK,
"div", T_OP_FDIV,
"mul", T_OP_FMUL,
"sin", T_OP_SIN,
"cos", T_OP_COS,
"tan", T_OP_TAN,
"asin", T_OP_ASIN,
"acos", T_OP_ACOS,
"atan", T_OP_ATAN,
"atan2", T_OP_ATAN2,
"div", T_OP_FDIV,
"mul", T_OP_FMUL,
"sin", T_OP_SIN,
"cos", T_OP_COS,
"tan", T_OP_TAN,
"asin", T_OP_ASIN,
"acos", T_OP_ACOS,
"atan", T_OP_ATAN,
"atan2", T_OP_ATAN2,
"strcmp", T_OP_STRCMP,
"strin", T_OP_STRIN,
"strsub", T_OP_STRSUB,
"strlen", T_OP_STRLEN,
"strcat", T_OP_STRCAT,
"strupr", T_OP_STRUPR,
"strlwr", T_OP_STRLWR,
"strcmp", T_OP_STRCMP,
"strin", T_OP_STRIN,
"strsub", T_OP_STRSUB,
"strlen", T_OP_STRLEN,
"strcat", T_OP_STRCAT,
"strupr", T_OP_STRUPR,
"strlwr", T_OP_STRLWR,
"include", T_POP_INCLUDE,
"printt", T_POP_PRINTT,
"printv", T_POP_PRINTV,
"printf", T_POP_PRINTF,
"export", T_POP_EXPORT,
"xdef", T_POP_EXPORT,
"import", T_POP_IMPORT,
"xref", T_POP_IMPORT,
"global", T_POP_GLOBAL,
"ds", T_POP_DS,
NAME_DB, T_POP_DB,
NAME_DW, T_POP_DW,
"include", T_POP_INCLUDE,
"printt", T_POP_PRINTT,
"printv", T_POP_PRINTV,
"printf", T_POP_PRINTF,
"export", T_POP_EXPORT,
"xdef", T_POP_EXPORT,
"import", T_POP_IMPORT,
"xref", T_POP_IMPORT,
"global", T_POP_GLOBAL,
"ds", T_POP_DS,
NAME_DB, T_POP_DB,
NAME_DW, T_POP_DW,
#ifdef NAME_DL
NAME_DL, T_POP_DL,
NAME_DL, T_POP_DL,
#endif
"section", T_POP_SECTION,
"section", T_POP_SECTION,
"purge", T_POP_PURGE,
"rsreset", T_POP_RSRESET,
"rsset", T_POP_RSSET,
"rsreset", T_POP_RSRESET,
"rsset", T_POP_RSSET,
"incbin", T_POP_INCBIN,
"incbin", T_POP_INCBIN,
"fail", T_POP_FAIL,
"warn", T_POP_WARN,
"fail", T_POP_FAIL,
"warn", T_POP_WARN,
"macro", T_POP_MACRO,
"endm", T_POP_ENDM, // Not needed but we have it here just to protect the name
"macro", T_POP_MACRO,
"endm", T_POP_ENDM, // Not needed but we have it here just to protect the name
"shift", T_POP_SHIFT,
"rept", T_POP_REPT,
"endr", T_POP_ENDR, // Not needed but we have it here just to protect the name
"rept", T_POP_REPT,
"endr", T_POP_ENDR, // Not needed but we have it here just to protect the name
"if", T_POP_IF,
"else", T_POP_ELSE,
"endc", T_POP_ENDC,
"if", T_POP_IF,
"else", T_POP_ELSE,
"endc", T_POP_ENDC,
"bss", T_SECT_BSS,
"bss", T_SECT_BSS,
#if defined(GAMEBOY) || defined(PCENGINE)
"vram", T_SECT_VRAM,
"vram", T_SECT_VRAM,
#endif
"code", T_SECT_CODE,
"data", T_SECT_CODE,
"code", T_SECT_CODE,
"data", T_SECT_CODE,
#ifdef GAMEBOY
"home", T_SECT_HOME,
"hram", T_SECT_HRAM,
"home", T_SECT_HOME,
"hram", T_SECT_HRAM,
#endif
NAME_RB, T_POP_RB,
NAME_RW, T_POP_RW,
NAME_RB, T_POP_RB,
NAME_RW, T_POP_RW,
#ifdef NAME_RL
NAME_RL, T_POP_RL,
NAME_RL, T_POP_RL,
#endif
"equ", T_POP_EQU,
"equs", T_POP_EQUS,
"equ", T_POP_EQU,
"equs", T_POP_EQUS,
"set", T_POP_SET,
"=", T_POP_SET,
"set", T_POP_SET,
"=", T_POP_SET,
"pushs", T_POP_PUSHS,
"pops", T_POP_POPS,
@@ -362,152 +332,155 @@ struct sLexInitString staticstrings[] =
"opt", T_POP_OPT,
NULL, 0
NULL, 0
};
struct sLexFloat tNumberToken =
{
ParseNumber,
T_NUMBER
struct sLexFloat tNumberToken = {
ParseNumber,
T_NUMBER
};
struct sLexFloat tFixedPointToken =
{
ParseFixedPoint,
T_NUMBER
struct sLexFloat tFixedPointToken = {
ParseFixedPoint,
T_NUMBER
};
struct sLexFloat tIDToken =
{
ParseSymbol,
T_ID
struct sLexFloat tIDToken = {
ParseSymbol,
T_ID
};
struct sLexFloat tMacroArgToken =
{
PutMacroArg,
T_LEX_MACROARG
struct sLexFloat tMacroArgToken = {
PutMacroArg,
T_LEX_MACROARG
};
struct sLexFloat tMacroUniqueToken =
{
PutUniqueArg,
T_LEX_MACROUNIQUE
struct sLexFloat tMacroUniqueToken = {
PutUniqueArg,
T_LEX_MACROUNIQUE
};
void setuplex (void)
void setuplex(void)
{
ULONG id;
ULONG id;
lex_Init ();
lex_AddStrings (staticstrings);
lex_AddStrings (localstrings);
lex_Init();
lex_AddStrings(staticstrings);
lex_AddStrings(localstrings);
// Macro arguments
// Macro arguments
id = lex_FloatAlloc (&tMacroArgToken);
lex_FloatAddFirstRange (id, '\\', '\\');
lex_FloatAddSecondRange (id, '0', '9');
id = lex_FloatAlloc (&tMacroUniqueToken);
lex_FloatAddFirstRange (id, '\\', '\\');
lex_FloatAddSecondRange (id, '@', '@');
id = lex_FloatAlloc(&tMacroArgToken);
lex_FloatAddFirstRange(id, '\\', '\\');
lex_FloatAddSecondRange(id, '0', '9');
id = lex_FloatAlloc(&tMacroUniqueToken);
lex_FloatAddFirstRange(id, '\\', '\\');
lex_FloatAddSecondRange(id, '@', '@');
// Decimal constants
// Decimal constants
id = lex_FloatAlloc (&tNumberToken);
lex_FloatAddFirstRange (id, '0', '9');
lex_FloatAddSecondRange (id, '0', '9');
lex_FloatAddRange (id, '0', '9');
id = lex_FloatAlloc(&tNumberToken);
lex_FloatAddFirstRange(id, '0', '9');
lex_FloatAddSecondRange(id, '0', '9');
lex_FloatAddRange(id, '0', '9');
// Binary constants
// Binary constants
nBinaryID = id = lex_FloatAlloc (&tNumberToken);
lex_FloatAddFirstRange (id, '%', '%');
lex_FloatAddSecondRange (id, CurrentOptions.binary[0], CurrentOptions.binary[0]);
lex_FloatAddSecondRange (id, CurrentOptions.binary[1], CurrentOptions.binary[1]);
lex_FloatAddRange (id, CurrentOptions.binary[0], CurrentOptions.binary[0]);
lex_FloatAddRange (id, CurrentOptions.binary[1], CurrentOptions.binary[1]);
nBinaryID = id = lex_FloatAlloc(&tNumberToken);
lex_FloatAddFirstRange(id, '%', '%');
lex_FloatAddSecondRange(id, CurrentOptions.binary[0],
CurrentOptions.binary[0]);
lex_FloatAddSecondRange(id, CurrentOptions.binary[1],
CurrentOptions.binary[1]);
lex_FloatAddRange(id, CurrentOptions.binary[0],
CurrentOptions.binary[0]);
lex_FloatAddRange(id, CurrentOptions.binary[1],
CurrentOptions.binary[1]);
// Octal constants
// Octal constants
id = lex_FloatAlloc (&tNumberToken);
lex_FloatAddFirstRange (id, '&', '&');
lex_FloatAddSecondRange (id, '0', '7');
lex_FloatAddRange (id, '0', '7');
id = lex_FloatAlloc(&tNumberToken);
lex_FloatAddFirstRange(id, '&', '&');
lex_FloatAddSecondRange(id, '0', '7');
lex_FloatAddRange(id, '0', '7');
// Gameboy gfx constants
// Gameboy gfx constants
nGBGfxID = id = lex_FloatAlloc (&tNumberToken);
lex_FloatAddFirstRange (id, '`', '`');
lex_FloatAddSecondRange (id, CurrentOptions.gbgfx[0], CurrentOptions.gbgfx[0]);
lex_FloatAddSecondRange (id, CurrentOptions.gbgfx[1], CurrentOptions.gbgfx[1]);
lex_FloatAddSecondRange (id, CurrentOptions.gbgfx[2], CurrentOptions.gbgfx[2]);
lex_FloatAddSecondRange (id, CurrentOptions.gbgfx[3], CurrentOptions.gbgfx[3]);
lex_FloatAddRange (id, CurrentOptions.gbgfx[0], CurrentOptions.gbgfx[0]);
lex_FloatAddRange (id, CurrentOptions.gbgfx[1], CurrentOptions.gbgfx[1]);
lex_FloatAddRange (id, CurrentOptions.gbgfx[2], CurrentOptions.gbgfx[2]);
lex_FloatAddRange (id, CurrentOptions.gbgfx[3], CurrentOptions.gbgfx[3]);
nGBGfxID = id = lex_FloatAlloc(&tNumberToken);
lex_FloatAddFirstRange(id, '`', '`');
lex_FloatAddSecondRange(id, CurrentOptions.gbgfx[0],
CurrentOptions.gbgfx[0]);
lex_FloatAddSecondRange(id, CurrentOptions.gbgfx[1],
CurrentOptions.gbgfx[1]);
lex_FloatAddSecondRange(id, CurrentOptions.gbgfx[2],
CurrentOptions.gbgfx[2]);
lex_FloatAddSecondRange(id, CurrentOptions.gbgfx[3],
CurrentOptions.gbgfx[3]);
lex_FloatAddRange(id, CurrentOptions.gbgfx[0], CurrentOptions.gbgfx[0]);
lex_FloatAddRange(id, CurrentOptions.gbgfx[1], CurrentOptions.gbgfx[1]);
lex_FloatAddRange(id, CurrentOptions.gbgfx[2], CurrentOptions.gbgfx[2]);
lex_FloatAddRange(id, CurrentOptions.gbgfx[3], CurrentOptions.gbgfx[3]);
// Hex constants
// Hex constants
id = lex_FloatAlloc (&tNumberToken);
lex_FloatAddFirstRange (id, '$', '$');
lex_FloatAddSecondRange (id, '0', '9');
lex_FloatAddSecondRange (id, 'A', 'F');
lex_FloatAddSecondRange (id, 'a', 'f');
lex_FloatAddRange (id, '0', '9');
lex_FloatAddRange (id, 'A', 'F');
lex_FloatAddRange (id, 'a', 'f');
id = lex_FloatAlloc(&tNumberToken);
lex_FloatAddFirstRange(id, '$', '$');
lex_FloatAddSecondRange(id, '0', '9');
lex_FloatAddSecondRange(id, 'A', 'F');
lex_FloatAddSecondRange(id, 'a', 'f');
lex_FloatAddRange(id, '0', '9');
lex_FloatAddRange(id, 'A', 'F');
lex_FloatAddRange(id, 'a', 'f');
// ID's
// ID's
id = lex_FloatAlloc (&tIDToken);
lex_FloatAddFirstRange (id, 'a', 'z');
lex_FloatAddFirstRange (id, 'A', 'Z');
lex_FloatAddFirstRange (id, '_', '_');
lex_FloatAddSecondRange (id, 'a', 'z');
lex_FloatAddSecondRange (id, 'A', 'Z');
lex_FloatAddSecondRange (id, '0', '9');
lex_FloatAddSecondRange (id, '_', '_');
lex_FloatAddSecondRange (id, '\\', '\\');
lex_FloatAddSecondRange (id, '@', '@');
lex_FloatAddSecondRange (id, '#', '#');
lex_FloatAddRange (id, 'a', 'z');
lex_FloatAddRange (id, 'A', 'Z');
lex_FloatAddRange (id, '0', '9');
lex_FloatAddRange (id, '_', '_');
lex_FloatAddRange (id, '\\', '\\');
lex_FloatAddRange (id, '@', '@');
lex_FloatAddRange (id, '#', '#');
id = lex_FloatAlloc(&tIDToken);
lex_FloatAddFirstRange(id, 'a', 'z');
lex_FloatAddFirstRange(id, 'A', 'Z');
lex_FloatAddFirstRange(id, '_', '_');
lex_FloatAddSecondRange(id, 'a', 'z');
lex_FloatAddSecondRange(id, 'A', 'Z');
lex_FloatAddSecondRange(id, '0', '9');
lex_FloatAddSecondRange(id, '_', '_');
lex_FloatAddSecondRange(id, '\\', '\\');
lex_FloatAddSecondRange(id, '@', '@');
lex_FloatAddSecondRange(id, '#', '#');
lex_FloatAddRange(id, 'a', 'z');
lex_FloatAddRange(id, 'A', 'Z');
lex_FloatAddRange(id, '0', '9');
lex_FloatAddRange(id, '_', '_');
lex_FloatAddRange(id, '\\', '\\');
lex_FloatAddRange(id, '@', '@');
lex_FloatAddRange(id, '#', '#');
// Local ID
// Local ID
id = lex_FloatAlloc (&tIDToken);
lex_FloatAddFirstRange (id, '.', '.');
lex_FloatAddSecondRange (id, 'a', 'z');
lex_FloatAddSecondRange (id, 'A', 'Z');
lex_FloatAddSecondRange (id, '_', '_');
lex_FloatAddRange (id, 'a', 'z');
lex_FloatAddRange (id, 'A', 'Z');
lex_FloatAddRange (id, '0', '9');
lex_FloatAddRange (id, '_', '_');
lex_FloatAddRange (id, '\\', '\\');
lex_FloatAddRange (id, '@', '@');
lex_FloatAddRange (id, '#', '#');
id = lex_FloatAlloc(&tIDToken);
lex_FloatAddFirstRange(id, '.', '.');
lex_FloatAddSecondRange(id, 'a', 'z');
lex_FloatAddSecondRange(id, 'A', 'Z');
lex_FloatAddSecondRange(id, '_', '_');
lex_FloatAddRange(id, 'a', 'z');
lex_FloatAddRange(id, 'A', 'Z');
lex_FloatAddRange(id, '0', '9');
lex_FloatAddRange(id, '_', '_');
lex_FloatAddRange(id, '\\', '\\');
lex_FloatAddRange(id, '@', '@');
lex_FloatAddRange(id, '#', '#');
// @ ID
// @ ID
id = lex_FloatAlloc (&tIDToken);
lex_FloatAddFirstRange (id, '@', '@');
id = lex_FloatAlloc(&tIDToken);
lex_FloatAddFirstRange(id, '@', '@');
// Fixed point constants
// Fixed point constants
id = lex_FloatAlloc (&tFixedPointToken);
lex_FloatAddFirstRange (id, '.', '.');
lex_FloatAddFirstRange (id, '0', '9');
lex_FloatAddSecondRange (id, '.', '.');
lex_FloatAddSecondRange (id, '0', '9');
lex_FloatAddRange (id, '.', '.');
lex_FloatAddRange (id, '0', '9');
id = lex_FloatAlloc(&tFixedPointToken);
lex_FloatAddFirstRange(id, '.', '.');
lex_FloatAddFirstRange(id, '0', '9');
lex_FloatAddSecondRange(id, '.', '.');
lex_FloatAddSecondRange(id, '0', '9');
lex_FloatAddRange(id, '.', '.');
lex_FloatAddRange(id, '0', '9');
}
}

View File

@@ -16,18 +16,18 @@
#include "localasm.h"
#include "asmotor.h"
extern SLONG nLineNo;
extern ULONG nTotalLines;
extern ULONG nPC;
extern ULONG nPass;
extern ULONG nIFDepth;
extern char tzCurrentFileName[_MAX_PATH+1];
extern struct Section *pCurrentSection;
extern struct sSymbol *tHashedSymbols[HASHSIZE];
extern struct sSymbol *pPCSymbol;
extern UBYTE oDontExpandStrings;
extern SLONG nLineNo;
extern ULONG nTotalLines;
extern ULONG nPC;
extern ULONG nPass;
extern ULONG nIFDepth;
extern char tzCurrentFileName[_MAX_PATH + 1];
extern struct Section *pCurrentSection;
extern struct sSymbol *tHashedSymbols[HASHSIZE];
extern struct sSymbol *pPCSymbol;
extern UBYTE oDontExpandStrings;
#define MAXMACROARGS 9
#define MAXINCPATHS 16
#endif // ASM_H
#endif // ASM_H

View File

@@ -13,30 +13,29 @@
#include "types.h"
#include "lexer.h"
struct sContext
{
YY_BUFFER_STATE FlexHandle;
struct sSymbol *pMacro;
struct sContext *pNext;
char tzFileName[_MAX_PATH+1];
char *tzMacroArgs[MAXMACROARGS+1];
SLONG nLine;
ULONG nStatus;
FILE *pFile;
char *pREPTBlock;
ULONG nREPTBlockCount;
ULONG nREPTBlockSize;
struct sContext {
YY_BUFFER_STATE FlexHandle;
struct sSymbol *pMacro;
struct sContext *pNext;
char tzFileName[_MAX_PATH + 1];
char *tzMacroArgs[MAXMACROARGS + 1];
SLONG nLine;
ULONG nStatus;
FILE *pFile;
char *pREPTBlock;
ULONG nREPTBlockCount;
ULONG nREPTBlockSize;
};
extern ULONG fstk_RunInclude( char *s );
extern void fstk_RunMacroArg( SLONG s );
extern ULONG fstk_Init( char *s );
extern void fstk_Dump( void );
extern void fstk_AddIncludePath( char *s );
extern ULONG fstk_RunMacro( char *s );
extern void fstk_RunRept( ULONG count );
extern void fstk_FindFile( char *s );
extern ULONG fstk_RunInclude(char *s);
extern void fstk_RunMacroArg(SLONG s);
extern ULONG fstk_Init(char *s);
extern void fstk_Dump(void);
extern void fstk_AddIncludePath(char *s);
extern ULONG fstk_RunMacro(char *s);
extern void fstk_RunRept(ULONG count);
extern void fstk_FindFile(char *s);
extern int yywrap( void );
extern int yywrap(void);
#endif

View File

@@ -1,9 +1,8 @@
typedef union
{
char tzSym[MAXSYMLEN+1];
char tzString[256];
struct Expression sVal;
SLONG nConstValue;
typedef union {
char tzSym[MAXSYMLEN + 1];
char tzString[256];
struct Expression sVal;
SLONG nConstValue;
} YYSTYPE;
#define T_NUMBER 258
#define T_STRING 259
@@ -149,5 +148,4 @@ typedef union
#define T_CC_Z 399
#define T_CC_NC 400
extern YYSTYPE yylval;

View File

@@ -6,28 +6,24 @@
#define LEXHASHSIZE 512
struct sLexInitString
{
char *tzName;
ULONG nToken;
struct sLexInitString {
char *tzName;
ULONG nToken;
};
struct sLexFloat
{
ULONG (*Callback)( char *s, ULONG size );
ULONG nToken;
struct sLexFloat {
ULONG(*Callback) (char *s, ULONG size);
ULONG nToken;
};
struct yy_buffer_state
{
char *pBufferStart;
char *pBuffer;
ULONG nBufferSize;
ULONG oAtLineStart;
struct yy_buffer_state {
char *pBufferStart;
char *pBuffer;
ULONG nBufferSize;
ULONG oAtLineStart;
};
enum eLexerState
{
enum eLexerState {
LEX_STATE_NORMAL,
LEX_STATE_MACROARGS
};
@@ -35,34 +31,34 @@ enum eLexerState
#define INITIAL 0
#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 YY_BUFFER_STATE yy_create_buffer( FILE *f );
extern YY_BUFFER_STATE yy_scan_bytes( char *mem, ULONG size );
extern void yy_delete_buffer( YY_BUFFER_STATE );
extern void yy_switch_to_buffer( YY_BUFFER_STATE );
extern ULONG lex_FloatAlloc( struct sLexFloat *tok );
extern void lex_FloatAddRange( ULONG id, 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_FloatDeleteFirstRange( 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_Init( void );
extern void lex_AddStrings( struct sLexInitString *lex );
extern void lex_SetBuffer( char *buffer, ULONG len );
extern ULONG yylex( void );
extern void yyunput( char c );
extern void yyunputstr( char *s );
extern void yyskipbytes( ULONG count );
extern void yyunputbytes( ULONG count );
extern void yy_set_state(enum eLexerState i);
extern YY_BUFFER_STATE yy_create_buffer(FILE * f);
extern YY_BUFFER_STATE yy_scan_bytes(char *mem, ULONG size);
extern void yy_delete_buffer(YY_BUFFER_STATE);
extern void yy_switch_to_buffer(YY_BUFFER_STATE);
extern ULONG lex_FloatAlloc(struct sLexFloat *tok);
extern void lex_FloatAddRange(ULONG id, 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_FloatDeleteFirstRange(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_Init(void);
extern void lex_AddStrings(struct sLexInitString *lex);
extern void lex_SetBuffer(char *buffer, ULONG len);
extern ULONG yylex(void);
extern void yyunput(char c);
extern void yyunputstr(char *s);
extern void yyskipbytes(ULONG count);
extern void yyunputbytes(ULONG count);
extern YY_BUFFER_STATE pCurrentBuffer;
extern YY_BUFFER_STATE pCurrentBuffer;
#ifdef __GNUC__
extern void strupr( char *s );
extern void strlwr( char *s );
extern void strupr(char *s);
extern void strlwr(char *s);
#endif
#endif
#endif

View File

@@ -1,29 +1,28 @@
#ifndef MAIN_H
#define MAIN_H
struct sOptions
{
ULONG endian;
char gbgfx[4];
char binary[2];
SLONG fillchar; // -1 == random
struct sOptions {
ULONG endian;
char gbgfx[4];
char binary[2];
SLONG fillchar; // -1 == random
};
extern char *tzNewMacro;
extern ULONG ulNewMacroSize;
extern SLONG nGBGfxID;
extern SLONG nBinaryID;
extern char *tzNewMacro;
extern ULONG ulNewMacroSize;
extern SLONG nGBGfxID;
extern SLONG nBinaryID;
extern struct sOptions DefaultOptions;
extern struct sOptions CurrentOptions;
extern void opt_Push( void );
extern void opt_Pop( void );
extern void opt_Parse( char *s );
extern struct sOptions DefaultOptions;
extern struct sOptions CurrentOptions;
extern void opt_Push(void);
extern void opt_Pop(void);
extern void opt_Parse(char *s);
void fatalerror( char *s );
void yyerror( char *s );
void fatalerror(char *s);
void yyerror(char *s);
extern char temptext[1024];
extern char temptext[1024];
#define YY_FATAL_ERROR fatalerror
@@ -32,4 +31,4 @@ extern char temptext[1024];
#endif
#define YYLMAX 65536
#endif
#endif

View File

@@ -55,9 +55,8 @@
*
*/
enum
{
RPN_ADD=0,
enum {
RPN_ADD = 0,
RPN_SUB,
RPN_MUL,
RPN_DIV,
@@ -91,33 +90,30 @@ enum
RPN_RANGECHECK,
RPN_CONST=0x80,
RPN_SYM=0x81
RPN_CONST = 0x80,
RPN_SYM = 0x81
};
enum
{
SECT_BSS=0,
enum {
SECT_BSS = 0,
SECT_VRAM,
SECT_CODE,
SECT_HOME,
SECT_HRAM
};
enum
{
SYM_LOCAL=0,
enum {
SYM_LOCAL = 0,
SYM_IMPORT,
SYM_EXPORT
};
enum
{
PATCH_BYTE=0,
enum {
PATCH_BYTE = 0,
PATCH_WORD_L,
PATCH_LONG_L,
PATCH_WORD_B,
PATCH_LONG_B
};
#endif
#endif

View File

@@ -3,16 +3,16 @@
#include "types.h"
void math_DefinePI( void );
void math_Print( SLONG i );
SLONG math_Sin( SLONG i );
SLONG math_Cos( SLONG i );
SLONG math_Tan( SLONG i );
SLONG math_ASin( SLONG i );
SLONG math_ACos( SLONG i );
SLONG math_ATan( SLONG i );
SLONG math_ATan2( SLONG i, SLONG j );
SLONG math_Mul( SLONG i, SLONG j );
SLONG math_Div( SLONG i, SLONG j );
void math_DefinePI(void);
void math_Print(SLONG i);
SLONG math_Sin(SLONG i);
SLONG math_Cos(SLONG i);
SLONG math_Tan(SLONG i);
SLONG math_ASin(SLONG i);
SLONG math_ACos(SLONG i);
SLONG math_ATan(SLONG i);
SLONG math_ATan2(SLONG i, SLONG j);
SLONG math_Mul(SLONG i, SLONG j);
SLONG math_Div(SLONG i, SLONG j);
#endif

View File

@@ -4,8 +4,7 @@
#include "rpn.h"
#include "types.h"
struct Section
{
struct Section {
char *pzName;
UBYTE nType;
ULONG nPC;
@@ -16,21 +15,21 @@ struct Section
UBYTE *tData;
};
void out_PrepPass2( void );
void out_SetFileName( char *s );
void out_NewSection (char *pzName, ULONG secttype);
void out_NewAbsSection (char *pzName, ULONG secttype, SLONG org, SLONG bank);
void out_AbsByte( int b );
void out_RelByte( struct Expression *expr );
void out_RelWord( struct Expression *expr );
void out_PCRelByte( struct Expression *expr );
void out_WriteObject( void );
void out_Skip( int skip );
void out_BinaryFile( char *s );
void out_String( char *s );
void out_AbsLong (SLONG b);
void out_RelLong (struct Expression *expr);
void out_PushSection( void );
void out_PopSection( void );
void out_PrepPass2(void);
void out_SetFileName(char *s);
void out_NewSection(char *pzName, ULONG secttype);
void out_NewAbsSection(char *pzName, ULONG secttype, SLONG org, SLONG bank);
void out_AbsByte(int b);
void out_RelByte(struct Expression *expr);
void out_RelWord(struct Expression *expr);
void out_PCRelByte(struct Expression *expr);
void out_WriteObject(void);
void out_Skip(int skip);
void out_BinaryFile(char *s);
void out_String(char *s);
void out_AbsLong(SLONG b);
void out_RelLong(struct Expression *expr);
void out_PushSection(void);
void out_PopSection(void);
#endif

View File

@@ -1,51 +1,68 @@
#ifndef RPN_H
#define RPN_H 1
struct Expression
{
SLONG nVal;
UBYTE tRPN[256];
ULONG nRPNLength;
ULONG nRPNOut;
ULONG isReloc;
ULONG isPCRel;
struct Expression {
SLONG nVal;
UBYTE tRPN[256];
ULONG nRPNLength;
ULONG nRPNOut;
ULONG isReloc;
ULONG isPCRel;
};
ULONG rpn_isReloc( struct Expression *expr );
ULONG rpn_isPCRelative( struct Expression *expr );
void rpn_Symbol( struct Expression *expr, char *tzSym );
void rpn_Number( struct Expression *expr, ULONG i );
void rpn_LOGNOT( struct Expression *expr, struct Expression *src1 );
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_LOGEQU( 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_LOGGE( 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_ADD( 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_OR( 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_SHR( struct Expression *expr, struct Expression *src1, struct Expression *src2 );
void rpn_MUL( struct Expression *expr, struct Expression *src1, struct Expression *src2 );
void rpn_DIV( struct Expression *expr, struct Expression *src1, struct Expression *src2 );
void rpn_MOD( struct Expression *expr, struct Expression *src1, struct Expression *src2 );
void rpn_UNNEG( struct Expression *expr, struct Expression *src );
void rpn_UNNOT( struct Expression *expr, struct Expression *src );
UWORD rpn_PopByte( struct Expression *expr );
void rpn_Bank( struct Expression *expr, char *tzSym );
void rpn_Reset( struct Expression *expr );
int rpn_RangeCheck( struct Expression *expr, struct Expression *src, SLONG low, SLONG high );
ULONG rpn_isReloc(struct Expression *expr);
ULONG rpn_isPCRelative(struct Expression *expr);
void rpn_Symbol(struct Expression *expr, char *tzSym);
void rpn_Number(struct Expression *expr, ULONG i);
void rpn_LOGNOT(struct Expression *expr, struct Expression *src1);
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_LOGEQU(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_LOGGE(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_ADD(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_OR(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_SHR(struct Expression *expr, struct Expression *src1,
struct Expression *src2);
void rpn_MUL(struct Expression *expr, struct Expression *src1,
struct Expression *src2);
void rpn_DIV(struct Expression *expr, struct Expression *src1,
struct Expression *src2);
void rpn_MOD(struct Expression *expr, struct Expression *src1,
struct Expression *src2);
void rpn_UNNEG(struct Expression *expr, struct Expression *src);
void rpn_UNNOT(struct Expression *expr, struct Expression *src);
UWORD rpn_PopByte(struct Expression *expr);
void rpn_Bank(struct Expression *expr, char *tzSym);
void rpn_Reset(struct Expression *expr);
int rpn_RangeCheck(struct Expression *expr, struct Expression *src, SLONG low,
SLONG high);
#ifdef GAMEBOY
void rpn_CheckHRAM( struct Expression *expr,struct Expression *src1 );
void rpn_CheckHRAM(struct Expression *expr, struct Expression *src1);
#endif
#ifdef PCENGINE
void rpn_CheckZP( struct Expression *expr,struct Expression *src );
void rpn_CheckZP(struct Expression *expr, struct Expression *src);
#endif
#endif
#endif

View File

@@ -6,63 +6,62 @@
#define HASHSIZE 73
#define MAXSYMLEN 256
struct sSymbol
{
char tzName[MAXSYMLEN+1];
SLONG nValue;
ULONG nType;
struct sSymbol *pScope;
struct sSymbol *pNext;
struct Section *pSection;
ULONG ulMacroSize;
char *pMacro;
SLONG (*Callback)(struct sSymbol *);
struct sSymbol {
char tzName[MAXSYMLEN + 1];
SLONG nValue;
ULONG nType;
struct sSymbol *pScope;
struct sSymbol *pNext;
struct Section *pSection;
ULONG ulMacroSize;
char *pMacro;
SLONG(*Callback) (struct sSymbol *);
};
#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_SET 0x004 /* symbol is (re)defined using SET, will not be changed during linking */
#define SYMF_EXPORT 0x008 /* symbol should be exported */
#define SYMF_IMPORT 0x010 /* symbol is imported, it's value is unknown */
#define SYMF_LOCAL 0x020 /* symbol is a local symbol */
#define SYMF_DEFINED 0x040 /* symbol has been defined, not only referenced */
#define SYMF_MACRO 0x080 /* symbol is a macro */
#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_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_SET 0x004 /* symbol is (re)defined using SET, will not be changed during linking */
#define SYMF_EXPORT 0x008 /* symbol should be exported */
#define SYMF_IMPORT 0x010 /* symbol is imported, it's value is unknown */
#define SYMF_LOCAL 0x020 /* symbol is a local symbol */
#define SYMF_DEFINED 0x040 /* symbol has been defined, not only referenced */
#define SYMF_MACRO 0x080 /* symbol is a macro */
#define SYMF_STRING 0x100 /* symbol is a stringsymbol */
#define SYMF_CONST 0x200 /* symbol has a constant value, will not be changed during linking */
void sym_PrepPass1( void );
void sym_PrepPass2( void );
void sym_AddLocalReloc( char *tzSym );
void sym_AddReloc( char *tzSym );
void sym_Export( char *tzSym );
void sym_PrintSymbolTable( void );
struct sSymbol *sym_FindMacro( char *s );
void sym_InitNewMacroArgs( void );
void sym_AddNewMacroArg( char *s );
void sym_SaveCurrentMacroArgs( char *save[] );
void sym_RestoreCurrentMacroArgs( char *save[] );
void sym_UseNewMacroArgs( void );
void sym_FreeCurrentMacroArgs( void );
void sym_AddEqu( char *tzSym, SLONG value );
void sym_AddSet( char *tzSym, SLONG value );
void sym_Init( void );
ULONG sym_GetConstantValue( char *s );
void sym_Import( char *tzSym );
ULONG sym_isConstant( char *s );
struct sSymbol *sym_FindSymbol( char *tzName );
void sym_Global( char *tzSym );
char *sym_FindMacroArg( SLONG i );
char *sym_GetStringValue( char *tzSym );
void sym_UseCurrentMacroArgs( void );
void sym_SetMacroArgID( ULONG nMacroCount );
ULONG sym_isString( char *tzSym );
void sym_AddMacro( char *tzSym );
void sym_ShiftCurrentMacroArgs( void );
void sym_AddString( char *tzSym, char *tzValue );
ULONG sym_GetValue( char *s );
ULONG sym_GetDefinedValue( char *s );
ULONG sym_isDefined( char *tzName );
void sym_Purge( char *tzName );
ULONG sym_isConstDefined (char *tzName);
void sym_PrepPass1(void);
void sym_PrepPass2(void);
void sym_AddLocalReloc(char *tzSym);
void sym_AddReloc(char *tzSym);
void sym_Export(char *tzSym);
void sym_PrintSymbolTable(void);
struct sSymbol *sym_FindMacro(char *s);
void sym_InitNewMacroArgs(void);
void sym_AddNewMacroArg(char *s);
void sym_SaveCurrentMacroArgs(char *save[]);
void sym_RestoreCurrentMacroArgs(char *save[]);
void sym_UseNewMacroArgs(void);
void sym_FreeCurrentMacroArgs(void);
void sym_AddEqu(char *tzSym, SLONG value);
void sym_AddSet(char *tzSym, SLONG value);
void sym_Init(void);
ULONG sym_GetConstantValue(char *s);
void sym_Import(char *tzSym);
ULONG sym_isConstant(char *s);
struct sSymbol *sym_FindSymbol(char *tzName);
void sym_Global(char *tzSym);
char *sym_FindMacroArg(SLONG i);
char *sym_GetStringValue(char *tzSym);
void sym_UseCurrentMacroArgs(void);
void sym_SetMacroArgID(ULONG nMacroCount);
ULONG sym_isString(char *tzSym);
void sym_AddMacro(char *tzSym);
void sym_ShiftCurrentMacroArgs(void);
void sym_AddString(char *tzSym, char *tzValue);
ULONG sym_GetValue(char *s);
ULONG sym_GetDefinedValue(char *s);
ULONG sym_isDefined(char *tzName);
void sym_Purge(char *tzName);
ULONG sym_isConstDefined(char *tzName);
#endif
#endif

View File

@@ -5,14 +5,14 @@
#define _MAX_PATH 512
#endif
typedef unsigned char UBYTE;
typedef signed char SBYTE;
typedef unsigned short UWORD;
typedef signed short SWORD;
typedef unsigned long ULONG;
typedef signed long SLONG;
typedef unsigned char UBYTE;
typedef signed char SBYTE;
typedef unsigned short UWORD;
typedef signed short SWORD;
typedef unsigned long ULONG;
typedef signed long SLONG;
#define ASM_LITTLE_ENDIAN 0
#define ASM_BIG_ENDIAN 1
#endif
#endif

File diff suppressed because it is too large Load Diff

View File

@@ -15,8 +15,8 @@
#include "output.h"
#include "main.h"
int yyparse (void);
void setuplex (void);
int yyparse(void);
void setuplex(void);
#ifdef AMIGA
__near long __stack = 65536L;
@@ -30,18 +30,13 @@ __near long __stack = 65536L;
*
*/
clock_t nStartClock,
nEndClock;
SLONG nLineNo;
ULONG nTotalLines,
nPass,
nPC,
nIFDepth,
nErrors;
clock_t nStartClock, nEndClock;
SLONG nLineNo;
ULONG nTotalLines, nPass, nPC, nIFDepth, nErrors;
extern int yydebug;
char temptext[1024];
char temptext[1024];
/*
* RGBAsm - MAIN.C
@@ -50,173 +45,182 @@ char temptext[1024];
*
*/
struct sOptions DefaultOptions;
struct sOptions CurrentOptions;
struct sOptions DefaultOptions;
struct sOptions CurrentOptions;
struct sOptionStackEntry
{
struct sOptions Options;
struct sOptionStackEntry *pNext;
struct sOptionStackEntry {
struct sOptions Options;
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 )
{
lex_FloatDeleteRange( nGBGfxID, CurrentOptions.gbgfx[0], CurrentOptions.gbgfx[0] );
lex_FloatDeleteRange( nGBGfxID, CurrentOptions.gbgfx[1], CurrentOptions.gbgfx[1] );
lex_FloatDeleteRange( nGBGfxID, CurrentOptions.gbgfx[2], CurrentOptions.gbgfx[2] );
lex_FloatDeleteRange( nGBGfxID, CurrentOptions.gbgfx[3], CurrentOptions.gbgfx[3] );
lex_FloatDeleteSecondRange( nGBGfxID, CurrentOptions.gbgfx[0], CurrentOptions.gbgfx[0] );
lex_FloatDeleteSecondRange( nGBGfxID, CurrentOptions.gbgfx[1], CurrentOptions.gbgfx[1] );
lex_FloatDeleteSecondRange( nGBGfxID, CurrentOptions.gbgfx[2], CurrentOptions.gbgfx[2] );
lex_FloatDeleteSecondRange( nGBGfxID, CurrentOptions.gbgfx[3], CurrentOptions.gbgfx[3] );
if (nGBGfxID != -1) {
lex_FloatDeleteRange(nGBGfxID, CurrentOptions.gbgfx[0],
CurrentOptions.gbgfx[0]);
lex_FloatDeleteRange(nGBGfxID, CurrentOptions.gbgfx[1],
CurrentOptions.gbgfx[1]);
lex_FloatDeleteRange(nGBGfxID, CurrentOptions.gbgfx[2],
CurrentOptions.gbgfx[2]);
lex_FloatDeleteRange(nGBGfxID, CurrentOptions.gbgfx[3],
CurrentOptions.gbgfx[3]);
lex_FloatDeleteSecondRange(nGBGfxID, CurrentOptions.gbgfx[0],
CurrentOptions.gbgfx[0]);
lex_FloatDeleteSecondRange(nGBGfxID, CurrentOptions.gbgfx[1],
CurrentOptions.gbgfx[1]);
lex_FloatDeleteSecondRange(nGBGfxID, CurrentOptions.gbgfx[2],
CurrentOptions.gbgfx[2]);
lex_FloatDeleteSecondRange(nGBGfxID, CurrentOptions.gbgfx[3],
CurrentOptions.gbgfx[3]);
}
if( nBinaryID!=-1 )
{
lex_FloatDeleteRange( nBinaryID, CurrentOptions.binary[0], CurrentOptions.binary[0] );
lex_FloatDeleteRange( nBinaryID, CurrentOptions.binary[1], CurrentOptions.binary[1] );
lex_FloatDeleteSecondRange( nBinaryID, CurrentOptions.binary[0], CurrentOptions.binary[0] );
lex_FloatDeleteSecondRange( nBinaryID, CurrentOptions.binary[1], CurrentOptions.binary[1] );
if (nBinaryID != -1) {
lex_FloatDeleteRange(nBinaryID, CurrentOptions.binary[0],
CurrentOptions.binary[0]);
lex_FloatDeleteRange(nBinaryID, CurrentOptions.binary[1],
CurrentOptions.binary[1]);
lex_FloatDeleteSecondRange(nBinaryID, CurrentOptions.binary[0],
CurrentOptions.binary[0]);
lex_FloatDeleteSecondRange(nBinaryID, CurrentOptions.binary[1],
CurrentOptions.binary[1]);
}
CurrentOptions = *pOpt;
if( nGBGfxID!=-1 )
{
lex_FloatAddRange( nGBGfxID, CurrentOptions.gbgfx[0], CurrentOptions.gbgfx[0] );
lex_FloatAddRange( nGBGfxID, CurrentOptions.gbgfx[1], CurrentOptions.gbgfx[1] );
lex_FloatAddRange( nGBGfxID, CurrentOptions.gbgfx[2], CurrentOptions.gbgfx[2] );
lex_FloatAddRange( nGBGfxID, CurrentOptions.gbgfx[3], CurrentOptions.gbgfx[3] );
lex_FloatAddSecondRange( nGBGfxID, CurrentOptions.gbgfx[0], CurrentOptions.gbgfx[0] );
lex_FloatAddSecondRange( nGBGfxID, CurrentOptions.gbgfx[1], CurrentOptions.gbgfx[1] );
lex_FloatAddSecondRange( nGBGfxID, CurrentOptions.gbgfx[2], CurrentOptions.gbgfx[2] );
lex_FloatAddSecondRange( nGBGfxID, CurrentOptions.gbgfx[3], CurrentOptions.gbgfx[3] );
if (nGBGfxID != -1) {
lex_FloatAddRange(nGBGfxID, CurrentOptions.gbgfx[0],
CurrentOptions.gbgfx[0]);
lex_FloatAddRange(nGBGfxID, CurrentOptions.gbgfx[1],
CurrentOptions.gbgfx[1]);
lex_FloatAddRange(nGBGfxID, CurrentOptions.gbgfx[2],
CurrentOptions.gbgfx[2]);
lex_FloatAddRange(nGBGfxID, CurrentOptions.gbgfx[3],
CurrentOptions.gbgfx[3]);
lex_FloatAddSecondRange(nGBGfxID, CurrentOptions.gbgfx[0],
CurrentOptions.gbgfx[0]);
lex_FloatAddSecondRange(nGBGfxID, CurrentOptions.gbgfx[1],
CurrentOptions.gbgfx[1]);
lex_FloatAddSecondRange(nGBGfxID, CurrentOptions.gbgfx[2],
CurrentOptions.gbgfx[2]);
lex_FloatAddSecondRange(nGBGfxID, CurrentOptions.gbgfx[3],
CurrentOptions.gbgfx[3]);
}
if( nBinaryID!=-1 )
{
lex_FloatAddRange( nBinaryID, CurrentOptions.binary[0], CurrentOptions.binary[0] );
lex_FloatAddRange( nBinaryID, CurrentOptions.binary[1], CurrentOptions.binary[1] );
lex_FloatAddSecondRange( nBinaryID, CurrentOptions.binary[0], CurrentOptions.binary[0] );
lex_FloatAddSecondRange( nBinaryID, CurrentOptions.binary[1], CurrentOptions.binary[1] );
if (nBinaryID != -1) {
lex_FloatAddRange(nBinaryID, CurrentOptions.binary[0],
CurrentOptions.binary[0]);
lex_FloatAddRange(nBinaryID, CurrentOptions.binary[1],
CurrentOptions.binary[1]);
lex_FloatAddSecondRange(nBinaryID, CurrentOptions.binary[0],
CurrentOptions.binary[0]);
lex_FloatAddSecondRange(nBinaryID, CurrentOptions.binary[1],
CurrentOptions.binary[1]);
}
}
void opt_Parse( char *s )
void opt_Parse(char *s)
{
struct sOptions newopt;
struct sOptions newopt;
newopt=CurrentOptions;
newopt = CurrentOptions;
switch( s[0] )
{
case 'e':
switch( s[1] )
{
case 'b':
newopt.endian=ASM_BIG_ENDIAN;
printf( "*WARNING*\t :\n\tEndianness forced to BIG for destination CPU\n" );
break;
case 'l':
newopt.endian=ASM_LITTLE_ENDIAN;
printf( "*WARNING*\t :\n\tEndianness forced to LITTLE for destination CPU\n" );
break;
default:
printf ("*ERROR*\t :\n\tArgument to option -e must be 'b' or 'l'\n" );
exit (5);
}
break;
case 'g':
if( strlen(&s[1])==4 )
{
newopt.gbgfx[0]=s[1];
newopt.gbgfx[1]=s[2];
newopt.gbgfx[2]=s[3];
newopt.gbgfx[3]=s[4];
}
else
{
printf ("*ERROR*\t :\n\tMust specify exactly 4 characters for option 'g'\n" );
exit( 5 );
}
break;
switch (s[0]) {
case 'e':
switch (s[1]) {
case 'b':
if( strlen(&s[1])==2 )
{
newopt.binary[0]=s[1];
newopt.binary[1]=s[2];
}
else
{
printf ("*ERROR*\t :\n\tMust specify exactly 2 characters for option 'b'\n" );
exit( 5 );
}
newopt.endian = ASM_BIG_ENDIAN;
printf
("*WARNING*\t :\n\tEndianness forced to BIG for destination CPU\n");
break;
case 'z':
if( strlen(&s[1])<=2 )
{
if( strcmp(&s[1],"?")==0 )
{
newopt.fillchar=-1;
}
else
{
int result;
result=sscanf( &s[1], "%lx", &newopt.fillchar );
if( !((result==EOF) || (result==1)) )
{
printf ("*ERROR*\t :\n\tInvalid argument for option 'z'\n" );
exit( 5 );
}
}
}
else
{
printf ("*ERROR*\t :\n\tInvalid argument for option 'z'\n" );
exit( 5 );
}
case 'l':
newopt.endian = ASM_LITTLE_ENDIAN;
printf
("*WARNING*\t :\n\tEndianness forced to LITTLE for destination CPU\n");
break;
default:
fatalerror( "Unknown option" );
break;
printf
("*ERROR*\t :\n\tArgument to option -e must be 'b' or 'l'\n");
exit(5);
}
break;
case 'g':
if (strlen(&s[1]) == 4) {
newopt.gbgfx[0] = s[1];
newopt.gbgfx[1] = s[2];
newopt.gbgfx[2] = s[3];
newopt.gbgfx[3] = s[4];
} else {
printf
("*ERROR*\t :\n\tMust specify exactly 4 characters for option 'g'\n");
exit(5);
}
break;
case 'b':
if (strlen(&s[1]) == 2) {
newopt.binary[0] = s[1];
newopt.binary[1] = s[2];
} else {
printf
("*ERROR*\t :\n\tMust specify exactly 2 characters for option 'b'\n");
exit(5);
}
break;
case 'z':
if (strlen(&s[1]) <= 2) {
if (strcmp(&s[1], "?") == 0) {
newopt.fillchar = -1;
} else {
int result;
result = sscanf(&s[1], "%lx", &newopt.fillchar);
if (!((result == EOF) || (result == 1))) {
printf
("*ERROR*\t :\n\tInvalid argument for option 'z'\n");
exit(5);
}
}
} else {
printf
("*ERROR*\t :\n\tInvalid argument for option 'z'\n");
exit(5);
}
break;
default:
fatalerror("Unknown option");
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 )
{
pOpt->Options=CurrentOptions;
pOpt->pNext=pOptionStack;
pOptionStack=pOpt;
}
else
fatalerror( "No memory for option stack" );
if ((pOpt =
(struct sOptionStackEntry *)
malloc(sizeof(struct sOptionStackEntry))) != NULL) {
pOpt->Options = CurrentOptions;
pOpt->pNext = pOptionStack;
pOptionStack = pOpt;
} else
fatalerror("No memory for option stack");
}
void opt_Pop( void )
void opt_Pop(void)
{
if( pOptionStack )
{
struct sOptionStackEntry *pOpt;
if (pOptionStack) {
struct sOptionStackEntry *pOpt;
pOpt=pOptionStack;
opt_SetCurrentOptions( &(pOpt->Options) );
pOptionStack=pOpt->pNext;
free( pOpt );
}
else
fatalerror( "No entries in the option stack" );
pOpt = pOptionStack;
opt_SetCurrentOptions(&(pOpt->Options));
pOptionStack = pOpt->pNext;
free(pOpt);
} else
fatalerror("No entries in the option stack");
}
/*
@@ -226,18 +230,18 @@ void opt_Pop( void )
*
*/
void yyerror (char *s)
void yyerror(char *s)
{
printf ("*ERROR*\t");
fstk_Dump ();
printf (" :\n\t%s\n", s);
nErrors += 1;
printf("*ERROR*\t");
fstk_Dump();
printf(" :\n\t%s\n", s);
nErrors += 1;
}
void fatalerror (char *s)
void fatalerror(char *s)
{
yyerror (s);
exit (5);
yyerror(s);
exit(5);
}
/*
@@ -247,21 +251,25 @@ void fatalerror (char *s)
*
*/
void PrintUsage (void)
void PrintUsage(void)
{
printf (APPNAME " v" ASM_VERSION " (part of ASMotor " ASMOTOR_VERSION ")\n\nUsage: " EXENAME " [options] asmfile\n");
printf ("Options:\n");
printf ("\t-h\t\tThis text\n");
printf ("\t-i<path>\tExtra include path\n");
printf ("\t-o<file>\tWrite objectoutput to <file>\n");
printf ("\t-e(l|b)\t\tChange endianness (CAUTION!)\n");
printf ("\t-g<ASCI>\tChange the four characters used for Gameboy graphics\n"
"\t\t\tconstants (default is 0123)\n" );
printf ("\t-b<AS>\t\tChange the two characters used for binary constants\n"
"\t\t\t(default is 01)\n" );
printf ("\t-z<hx>\t\tSet the byte value (hex format) used for uninitialised\n"
"\t\t\tdata (default is ? for random)\n" );
exit (0);
printf(APPNAME " v" ASM_VERSION " (part of ASMotor " ASMOTOR_VERSION
")\n\nUsage: " EXENAME " [options] asmfile\n");
printf("Options:\n");
printf("\t-h\t\tThis text\n");
printf("\t-i<path>\tExtra include path\n");
printf("\t-o<file>\tWrite objectoutput to <file>\n");
printf("\t-e(l|b)\t\tChange endianness (CAUTION!)\n");
printf
("\t-g<ASCI>\tChange the four characters used for Gameboy graphics\n"
"\t\t\tconstants (default is 0123)\n");
printf
("\t-b<AS>\t\tChange the two characters used for binary constants\n"
"\t\t\t(default is 01)\n");
printf
("\t-z<hx>\t\tSet the byte value (hex format) used for uninitialised\n"
"\t\t\tdata (default is ? for random)\n");
exit(0);
}
/*
@@ -271,136 +279,136 @@ void PrintUsage (void)
*
*/
int main (int argc, char *argv[])
int main(int argc, char *argv[])
{
char *tzMainfile;
int argn = 1;
char *tzMainfile;
int argn = 1;
argc -= 1;
argc -= 1;
if (argc == 0)
PrintUsage ();
if (argc == 0)
PrintUsage();
/* yydebug=1; */
/* yydebug=1; */
DefaultOptions.endian=ASM_DEFAULT_ENDIAN;
DefaultOptions.gbgfx[0]='0';
DefaultOptions.gbgfx[1]='1';
DefaultOptions.gbgfx[2]='2';
DefaultOptions.gbgfx[3]='3';
DefaultOptions.binary[0]='0';
DefaultOptions.binary[1]='1';
DefaultOptions.fillchar=-1; // fill uninitialised data with random values
opt_SetCurrentOptions( &DefaultOptions );
DefaultOptions.endian = ASM_DEFAULT_ENDIAN;
DefaultOptions.gbgfx[0] = '0';
DefaultOptions.gbgfx[1] = '1';
DefaultOptions.gbgfx[2] = '2';
DefaultOptions.gbgfx[3] = '3';
DefaultOptions.binary[0] = '0';
DefaultOptions.binary[1] = '1';
DefaultOptions.fillchar = -1; // fill uninitialised data with random values
opt_SetCurrentOptions(&DefaultOptions);
while (argv[argn][0] == '-' && argc)
{
switch (argv[argn][1])
{
case 'h':
PrintUsage ();
break;
case 'i':
fstk_AddIncludePath (&(argv[argn][2]));
break;
case 'o':
out_SetFileName (&(argv[argn][2]));
break;
case 'e':
case 'g':
case 'b':
case 'z':
opt_Parse( &argv[argn][1] );
break;
default:
printf ("*ERROR*\t :\n\tUnknown option '%c'\n", argv[argn][1]);
exit (5);
break;
while (argv[argn][0] == '-' && argc) {
switch (argv[argn][1]) {
case 'h':
PrintUsage();
break;
case 'i':
fstk_AddIncludePath(&(argv[argn][2]));
break;
case 'o':
out_SetFileName(&(argv[argn][2]));
break;
case 'e':
case 'g':
case 'b':
case 'z':
opt_Parse(&argv[argn][1]);
break;
default:
printf("*ERROR*\t :\n\tUnknown option '%c'\n",
argv[argn][1]);
exit(5);
break;
}
argn += 1;
argc -= 1;
}
}
DefaultOptions=CurrentOptions;
DefaultOptions = CurrentOptions;
/*tzMainfile=argv[argn++];
* argc-=1; */
tzMainfile = argv[argn];
/*tzMainfile=argv[argn++];
* argc-=1; */
tzMainfile = argv[argn];
setuplex ();
setuplex();
printf ("Assembling %s\n", tzMainfile);
printf("Assembling %s\n", tzMainfile);
nStartClock = clock ();
nStartClock = clock();
nLineNo = 1;
nTotalLines = 0;
nIFDepth = 0;
nPC = 0;
nPass = 1;
nErrors = 0;
sym_PrepPass1 ();
if (fstk_Init (tzMainfile))
{
printf ("Pass 1...\n");
nLineNo = 1;
nTotalLines = 0;
nIFDepth = 0;
nPC = 0;
nPass = 1;
nErrors = 0;
sym_PrepPass1();
if (fstk_Init(tzMainfile)) {
printf("Pass 1...\n");
yy_set_state( LEX_STATE_NORMAL );
opt_SetCurrentOptions( &DefaultOptions );
yy_set_state(LEX_STATE_NORMAL);
opt_SetCurrentOptions(&DefaultOptions);
if (yyparse () == 0 && nErrors == 0)
{
if (nIFDepth == 0)
{
if (yyparse() == 0 && nErrors == 0) {
if (nIFDepth == 0) {
nTotalLines = 0;
nLineNo = 1;
nIFDepth = 0;
nPC = 0;
nPass = 2;
nErrors = 0;
sym_PrepPass2 ();
out_PrepPass2 ();
fstk_Init (tzMainfile);
yy_set_state( LEX_STATE_NORMAL );
opt_SetCurrentOptions( &DefaultOptions );
sym_PrepPass2();
out_PrepPass2();
fstk_Init(tzMainfile);
yy_set_state(LEX_STATE_NORMAL);
opt_SetCurrentOptions(&DefaultOptions);
printf ("Pass 2...\n");
printf("Pass 2...\n");
if (yyparse () == 0 && nErrors == 0)
{
double timespent;
if (yyparse() == 0 && nErrors == 0) {
double timespent;
nEndClock = clock ();
timespent = ((double) (nEndClock - nStartClock)) / (double) CLOCKS_PER_SEC;
printf ("Success! %ld lines in %d.%02d seconds ", nTotalLines, (int) timespent, ((int) (timespent * 100.0)) % 100);
if (timespent == 0)
printf ("(INFINITY lines/minute)\n");
else
printf ("(%d lines/minute)\n", (int) (60 / timespent * nTotalLines));
out_WriteObject ();
nEndClock = clock();
timespent =
((double)(nEndClock - nStartClock))
/ (double)CLOCKS_PER_SEC;
printf
("Success! %ld lines in %d.%02d seconds ",
nTotalLines, (int)timespent,
((int)(timespent * 100.0)) % 100);
if (timespent == 0)
printf
("(INFINITY lines/minute)\n");
else
printf("(%d lines/minute)\n",
(int)(60 / timespent *
nTotalLines));
out_WriteObject();
} else {
printf
("Assembly aborted in pass 2 (%ld errors)!\n",
nErrors);
//sym_PrintSymbolTable();
exit(5);
}
else
{
printf ("Assembly aborted in pass 2 (%ld errors)!\n", nErrors);
//sym_PrintSymbolTable();
exit (5);
}
}
else
{
printf ("*ERROR*\t:\tUnterminated IF construct (%ld levels)!\n", nIFDepth);
exit (5);
}
} else {
printf
("*ERROR*\t:\tUnterminated IF construct (%ld levels)!\n",
nIFDepth);
exit(5);
}
} else {
printf("Assembly aborted in pass 1 (%ld errors)!\n",
nErrors);
exit(5);
}
else
{
printf ("Assembly aborted in pass 1 (%ld errors)!\n", nErrors);
exit (5);
}
}
else
{
printf ("File '%s' not found\n", tzMainfile);
exit (5);
}
return (0);
}
} else {
printf("File '%s' not found\n", tzMainfile);
exit(5);
}
return (0);
}

View File

@@ -24,9 +24,9 @@
*
*/
void math_DefinePI (void)
void math_DefinePI(void)
{
sym_AddEqu ("_PI", double2fix (PI));
sym_AddEqu("_PI", double2fix(PI));
}
/*
@@ -36,12 +36,14 @@ void math_DefinePI (void)
*
*/
void math_Print (SLONG i)
void math_Print(SLONG i)
{
if (i >= 0)
printf ("%ld.%05ld", i >> 16, ((SLONG) (fix2double (i) * 100000 + 0.5)) % 100000);
else
printf ("-%ld.%05ld", (-i) >> 16, ((SLONG) (fix2double (-i) * 100000 + 0.5)) % 100000);
if (i >= 0)
printf("%ld.%05ld", i >> 16,
((SLONG) (fix2double(i) * 100000 + 0.5)) % 100000);
else
printf("-%ld.%05ld", (-i) >> 16,
((SLONG) (fix2double(-i) * 100000 + 0.5)) % 100000);
}
/*
@@ -51,9 +53,9 @@ void math_Print (SLONG i)
*
*/
SLONG math_Sin (SLONG i)
SLONG math_Sin(SLONG i)
{
return (double2fix (sin (fix2double (i) * 2 * PI / 65536)));
return (double2fix(sin(fix2double(i) * 2 * PI / 65536)));
}
/*
@@ -63,9 +65,9 @@ SLONG math_Sin (SLONG i)
*
*/
SLONG math_Cos (SLONG i)
SLONG math_Cos(SLONG i)
{
return (double2fix (cos (fix2double (i) * 2 * PI / 65536)));
return (double2fix(cos(fix2double(i) * 2 * PI / 65536)));
}
/*
@@ -75,9 +77,9 @@ SLONG math_Cos (SLONG i)
*
*/
SLONG math_Tan (SLONG i)
SLONG math_Tan(SLONG i)
{
return (double2fix (tan (fix2double (i) * 2 * PI / 65536)));
return (double2fix(tan(fix2double(i) * 2 * PI / 65536)));
}
/*
@@ -87,9 +89,9 @@ SLONG math_Tan (SLONG i)
*
*/
SLONG math_ASin (SLONG i)
SLONG math_ASin(SLONG i)
{
return (double2fix (asin (fix2double (i)) / 2 / PI * 65536));
return (double2fix(asin(fix2double(i)) / 2 / PI * 65536));
}
/*
@@ -99,9 +101,9 @@ SLONG math_ASin (SLONG i)
*
*/
SLONG math_ACos (SLONG i)
SLONG math_ACos(SLONG i)
{
return (double2fix (acos (fix2double (i)) / 2 / PI * 65536));
return (double2fix(acos(fix2double(i)) / 2 / PI * 65536));
}
/*
@@ -111,9 +113,9 @@ SLONG math_ACos (SLONG i)
*
*/
SLONG math_ATan (SLONG i)
SLONG math_ATan(SLONG i)
{
return (double2fix (atan (fix2double (i)) / 2 / PI * 65536));
return (double2fix(atan(fix2double(i)) / 2 / PI * 65536));
}
/*
@@ -123,9 +125,10 @@ SLONG math_ATan (SLONG i)
*
*/
SLONG math_ATan2 (SLONG i, SLONG j)
SLONG math_ATan2(SLONG i, SLONG j)
{
return (double2fix (atan2 (fix2double (i), fix2double (j)) / 2 / PI * 65536));
return (double2fix
(atan2(fix2double(i), fix2double(j)) / 2 / PI * 65536));
}
/*
@@ -135,9 +138,9 @@ SLONG math_ATan2 (SLONG i, SLONG j)
*
*/
SLONG math_Mul (SLONG i, SLONG j)
SLONG math_Mul(SLONG i, SLONG j)
{
return (double2fix (fix2double (i) * fix2double (j)));
return (double2fix(fix2double(i) * fix2double(j)));
}
/*
@@ -147,7 +150,7 @@ SLONG math_Mul (SLONG i, SLONG j)
*
*/
SLONG math_Div (SLONG i, SLONG j)
SLONG math_Div(SLONG i, SLONG j)
{
return (double2fix (fix2double (i) / fix2double (j)));
}
return (double2fix(fix2double(i) / fix2double(j)));
}

File diff suppressed because it is too large Load Diff

View File

@@ -15,14 +15,15 @@
#include <stdio.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;
memcpy( &(expr->tRPN[expr->nRPNLength]), src2->tRPN, src2->nRPNLength );
*expr = *src1;
memcpy(&(expr->tRPN[expr->nRPNLength]), src2->tRPN, src2->nRPNLength);
expr->nRPNLength += src2->nRPNLength;
expr->isReloc |= src2->isReloc;
expr->isPCRel |= src2->isPCRel;
expr->nRPNLength += src2->nRPNLength;
expr->isReloc |= src2->isReloc;
expr->isPCRel |= src2->isPCRel;
}
#define joinexpr() mergetwoexpressions(expr,src1,src2)
@@ -47,9 +48,9 @@ void mergetwoexpressions( struct Expression *expr, struct Expression *src1, stru
*
*/
void pushbyte (struct Expression *expr, int b)
void pushbyte(struct Expression *expr, int b)
{
expr->tRPN[expr->nRPNLength++] = b & 0xFF;
expr->tRPN[expr->nRPNLength++] = b & 0xFF;
}
/*
@@ -59,9 +60,9 @@ void pushbyte (struct Expression *expr, int b)
*
*/
void rpn_Reset (struct Expression *expr)
void rpn_Reset(struct Expression *expr)
{
expr->nRPNLength = expr->nRPNOut = expr->isReloc = expr->isPCRel = 0;
expr->nRPNLength = expr->nRPNOut = expr->isReloc = expr->isPCRel = 0;
}
/*
@@ -71,14 +72,12 @@ void rpn_Reset (struct Expression *expr)
*
*/
UWORD rpn_PopByte (struct Expression *expr)
UWORD rpn_PopByte(struct Expression *expr)
{
if (expr->nRPNOut == expr->nRPNLength)
{
return (0xDEAD);
}
else
return (expr->tRPN[expr->nRPNOut++]);
if (expr->nRPNOut == expr->nRPNLength) {
return (0xDEAD);
} else
return (expr->tRPN[expr->nRPNOut++]);
}
/*
@@ -88,9 +87,9 @@ UWORD rpn_PopByte (struct Expression *expr)
*
*/
ULONG rpn_isReloc (struct Expression *expr)
ULONG rpn_isReloc(struct Expression * expr)
{
return (expr->isReloc);
return (expr->isReloc);
}
/*
@@ -100,9 +99,9 @@ ULONG rpn_isReloc (struct Expression *expr)
*
*/
ULONG rpn_isPCRelative (struct Expression *expr)
ULONG rpn_isPCRelative(struct Expression * expr)
{
return (expr->isPCRel);
return (expr->isPCRel);
}
/*
@@ -112,245 +111,256 @@ ULONG rpn_isPCRelative (struct Expression *expr)
*
*/
void rpn_Number (struct Expression *expr, ULONG i)
void rpn_Number(struct Expression *expr, ULONG i)
{
rpn_Reset (expr);
pushbyte (expr, RPN_CONST);
pushbyte (expr, i);
pushbyte (expr, i >> 8);
pushbyte (expr, i >> 16);
pushbyte (expr, i >> 24);
expr->nVal = i;
rpn_Reset(expr);
pushbyte(expr, RPN_CONST);
pushbyte(expr, i);
pushbyte(expr, i >> 8);
pushbyte(expr, i >> 16);
pushbyte(expr, i >> 24);
expr->nVal = i;
}
void rpn_Symbol (struct Expression *expr, char *tzSym)
void rpn_Symbol(struct Expression *expr, char *tzSym)
{
if (!sym_isConstant (tzSym))
{
struct sSymbol *psym;
if (!sym_isConstant(tzSym)) {
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)
expr->isPCRel = 1;
expr->isReloc = 1;
pushbyte (expr,RPN_SYM);
while (*tzSym)
pushbyte (expr,*tzSym++);
pushbyte (expr,0);
}
else
rpn_Number (expr,sym_GetConstantValue (tzSym));
if (psym == NULL || psym->pSection == pCurrentSection
|| psym->pSection == NULL)
expr->isPCRel = 1;
expr->isReloc = 1;
pushbyte(expr, RPN_SYM);
while (*tzSym)
pushbyte(expr, *tzSym++);
pushbyte(expr, 0);
} else
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))
{
struct sSymbol *psym;
if (!sym_isConstant(tzSym)) {
struct sSymbol *psym;
rpn_Reset( expr );
rpn_Reset(expr);
psym = sym_FindSymbol (tzSym);
if (nPass == 2 && psym == NULL)
{
sprintf (temptext, "'%s' not defined", tzSym);
yyerror (temptext);
}
expr->isReloc = 1;
pushbyte (expr,RPN_BANK);
while (*tzSym)
pushbyte (expr,*tzSym++);
pushbyte (expr,0);
}
else
yyerror ("BANK argument must be a relocatable identifier");
psym = sym_FindSymbol(tzSym);
if (nPass == 2 && psym == NULL) {
sprintf(temptext, "'%s' not defined", tzSym);
yyerror(temptext);
}
expr->isReloc = 1;
pushbyte(expr, RPN_BANK);
while (*tzSym)
pushbyte(expr, *tzSym++);
pushbyte(expr, 0);
} else
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) )
{
pushbyte( expr, RPN_RANGECHECK );
pushbyte( expr, low );
pushbyte( expr, low>>8 );
pushbyte( expr, low>>16 );
pushbyte( expr, low>>24 );
pushbyte( expr, high );
pushbyte( expr, high>>8 );
pushbyte( expr, high>>16 );
pushbyte( expr, high>>24 );
return( 1 );
}
else
{
return( expr->nVal>=low && expr->nVal<=high );
if (rpn_isReloc(src)) {
pushbyte(expr, RPN_RANGECHECK);
pushbyte(expr, low);
pushbyte(expr, low >> 8);
pushbyte(expr, low >> 16);
pushbyte(expr, low >> 24);
pushbyte(expr, high);
pushbyte(expr, high >> 8);
pushbyte(expr, high >> 16);
pushbyte(expr, high >> 24);
return (1);
} else {
return (expr->nVal >= low && expr->nVal <= high);
}
}
#ifdef GAMEBOY
void rpn_CheckHRAM (struct Expression *expr, struct Expression *src)
void rpn_CheckHRAM(struct Expression *expr, struct Expression *src)
{
*expr = *src;
pushbyte (expr, RPN_HRAM);
*expr = *src;
pushbyte(expr, RPN_HRAM);
}
#endif
#ifdef PCENGINE
void rpn_CheckZP (struct Expression *expr, struct Expression *src)
void rpn_CheckZP(struct Expression *expr, struct Expression *src)
{
*expr = *src;
pushbyte (expr, RPN_PCEZP);
*expr = *src;
pushbyte(expr, RPN_PCEZP);
}
#endif
void rpn_LOGNOT (struct Expression *expr, struct Expression *src)
void rpn_LOGNOT(struct Expression *expr, struct Expression *src)
{
*expr = *src;
pushbyte (expr, RPN_LOGUNNOT);
*expr = *src;
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();
expr->nVal = (expr->nVal||src2->nVal);
pushbyte (expr,RPN_LOGOR);
joinexpr();
expr->nVal = (expr->nVal || src2->nVal);
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();
expr->nVal = (expr->nVal&&src2->nVal);
pushbyte (expr,RPN_LOGAND);
joinexpr();
expr->nVal = (expr->nVal && src2->nVal);
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();
expr->nVal = (expr->nVal==src2->nVal);
pushbyte (expr,RPN_LOGEQ);
joinexpr();
expr->nVal = (expr->nVal == src2->nVal);
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();
expr->nVal = (expr->nVal>src2->nVal);
pushbyte (expr,RPN_LOGGT);
joinexpr();
expr->nVal = (expr->nVal > src2->nVal);
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();
expr->nVal = (expr->nVal<src2->nVal);
pushbyte (expr,RPN_LOGLT);
joinexpr();
expr->nVal = (expr->nVal < src2->nVal);
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();
expr->nVal = (expr->nVal>=src2->nVal);
pushbyte (expr,RPN_LOGGE);
joinexpr();
expr->nVal = (expr->nVal >= src2->nVal);
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();
expr->nVal = (expr->nVal<=src2->nVal);
pushbyte (expr,RPN_LOGLE);
joinexpr();
expr->nVal = (expr->nVal <= src2->nVal);
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();
expr->nVal = (expr->nVal!=src2->nVal);
pushbyte (expr,RPN_LOGNE);
joinexpr();
expr->nVal = (expr->nVal != src2->nVal);
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();
expr->nVal = (expr->nVal+src2->nVal);
pushbyte (expr,RPN_ADD);
joinexpr();
expr->nVal = (expr->nVal + src2->nVal);
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();
expr->nVal = (expr->nVal-src2->nVal);
pushbyte (expr,RPN_SUB);
joinexpr();
expr->nVal = (expr->nVal - src2->nVal);
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();
expr->nVal = (expr->nVal^src2->nVal);
pushbyte (expr,RPN_XOR);
joinexpr();
expr->nVal = (expr->nVal ^ src2->nVal);
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();
expr->nVal = (expr->nVal|src2->nVal);
pushbyte (expr,RPN_OR);
joinexpr();
expr->nVal = (expr->nVal | src2->nVal);
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();
expr->nVal = (expr->nVal&src2->nVal);
pushbyte (expr,RPN_AND);
joinexpr();
expr->nVal = (expr->nVal & src2->nVal);
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();
expr->nVal = (expr->nVal<<src2->nVal);
pushbyte (expr,RPN_SHL);
joinexpr();
expr->nVal = (expr->nVal << src2->nVal);
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();
expr->nVal = (expr->nVal>>src2->nVal);
pushbyte (expr,RPN_SHR);
joinexpr();
expr->nVal = (expr->nVal >> src2->nVal);
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();
expr->nVal = (expr->nVal*src2->nVal);
pushbyte (expr,RPN_MUL);
joinexpr();
expr->nVal = (expr->nVal * src2->nVal);
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();
expr->nVal = (expr->nVal/src2->nVal);
pushbyte (expr,RPN_DIV);
joinexpr();
expr->nVal = (expr->nVal / src2->nVal);
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();
expr->nVal = (expr->nVal%src2->nVal);
pushbyte (expr,RPN_MOD);
joinexpr();
expr->nVal = (expr->nVal % src2->nVal);
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->nVal = -expr->nVal;
pushbyte (expr,RPN_UNSUB);
*expr = *src;
expr->nVal = -expr->nVal;
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->nVal = expr->nVal^0xFFFFFFFF;
pushbyte (expr,RPN_UNNOT);
*expr = *src;
expr->nVal = expr->nVal ^ 0xFFFFFFFF;
pushbyte(expr, RPN_UNNOT);
}

File diff suppressed because it is too large Load Diff