mirror of
https://github.com/gbdev/rgbds.git
synced 2025-11-20 18:22:07 +00:00
Run `indent' on the whole tree
Can't indent the .y files yet, they need special treatment. Signed-off-by: Vegard Nossum <vegard.nossum@gmail.com>
This commit is contained in:
@@ -43,23 +43,18 @@
|
||||
in order to make unexec workable
|
||||
*/
|
||||
#ifndef STACK_DIRECTION
|
||||
you
|
||||
lose
|
||||
-- must know STACK_DIRECTION at compile-time
|
||||
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();
|
||||
#define ADDRESS_FUNCTION(arg) (char *) i00afunc (&(arg))
|
||||
#else
|
||||
#define ADDRESS_FUNCTION(arg) &(arg)
|
||||
#endif
|
||||
|
||||
#if __STDC__
|
||||
typedef void *pointer;
|
||||
#else
|
||||
@@ -109,20 +104,16 @@ extern pointer malloc ();
|
||||
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. */
|
||||
|
||||
if (addr == NULL)
|
||||
{ /* Initial entry. */
|
||||
if (addr == NULL) { /* Initial entry. */
|
||||
addr = ADDRESS_FUNCTION(dummy);
|
||||
|
||||
find_stack_direction(); /* Recurse once. */
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
/* Second entry. */
|
||||
if (ADDRESS_FUNCTION(dummy) > addr)
|
||||
stack_dir = 1; /* Stack grew upward. */
|
||||
@@ -144,11 +135,9 @@ find_stack_direction ()
|
||||
#define ALIGN_SIZE sizeof(double)
|
||||
#endif
|
||||
|
||||
typedef union hdr
|
||||
{
|
||||
typedef union hdr {
|
||||
char align[ALIGN_SIZE]; /* To force sizeof(header). */
|
||||
struct
|
||||
{
|
||||
struct {
|
||||
union hdr *next; /* For chaining headers. */
|
||||
char *deep; /* For stack depth measure. */
|
||||
} h;
|
||||
@@ -163,8 +152,7 @@ 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)
|
||||
pointer alloca(size)
|
||||
unsigned size;
|
||||
{
|
||||
auto char probe; /* Probes stack depth: */
|
||||
@@ -187,15 +175,13 @@ alloca (size)
|
||||
|
||||
for (hp = last_alloca_header; hp != NULL;)
|
||||
if ((STACK_DIR > 0 && hp->h.deep > depth)
|
||||
|| (STACK_DIR < 0 && hp->h.deep < depth))
|
||||
{
|
||||
|| (STACK_DIR < 0 && hp->h.deep < depth)) {
|
||||
register header *np = hp->h.next;
|
||||
|
||||
free((pointer) hp); /* Collect garbage. */
|
||||
|
||||
hp = np; /* -> next header. */
|
||||
}
|
||||
else
|
||||
} else
|
||||
break; /* Rest are not deeper. */
|
||||
|
||||
last_alloca_header = hp; /* -> last valid storage. */
|
||||
@@ -235,8 +221,7 @@ alloca (size)
|
||||
#define CRAY_STACK
|
||||
#ifndef CRAY2
|
||||
/* Stack structures for CRAY-1, CRAY X-MP, and CRAY Y-MP */
|
||||
struct stack_control_header
|
||||
{
|
||||
struct stack_control_header {
|
||||
long shgrow:32; /* Number of times stack has grown. */
|
||||
long shaseg:32; /* Size of increments to stack. */
|
||||
long shhwm:32; /* High water mark of stack. */
|
||||
@@ -250,8 +235,7 @@ struct stack_control_header
|
||||
0200 (octal) words. This provides for register storage
|
||||
for the routine which overflows the stack. */
|
||||
|
||||
struct stack_segment_linkage
|
||||
{
|
||||
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. */
|
||||
@@ -288,8 +272,7 @@ struct stack_segment_linkage
|
||||
#else /* CRAY2 */
|
||||
/* The following structure defines the vector of words
|
||||
returned by the STKSTAT library routine. */
|
||||
struct stk_stat
|
||||
{
|
||||
struct stk_stat {
|
||||
long now; /* Current total stack size. */
|
||||
long maxc; /* Amount of contiguous space which would
|
||||
be required to satisfy the maximum
|
||||
@@ -317,8 +300,7 @@ struct stk_stat
|
||||
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
|
||||
{
|
||||
struct stk_trailer {
|
||||
long this_address; /* Address of this block. */
|
||||
long this_size; /* Size of this block (does not include
|
||||
this trailer). */
|
||||
@@ -345,8 +327,7 @@ struct stk_trailer
|
||||
/* 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;
|
||||
@@ -363,8 +344,7 @@ i00afunc (long *address)
|
||||
/* Set up the iteration. */
|
||||
|
||||
trailer = (struct stk_trailer *)(status.current_address
|
||||
+ status.current_size
|
||||
- 15);
|
||||
+ status.current_size - 15);
|
||||
|
||||
/* There must be at least one stack segment. Therefore it is
|
||||
a fatal error if "trailer" is null. */
|
||||
@@ -374,8 +354,7 @@ i00afunc (long *address)
|
||||
|
||||
/* Discard segments that do not contain our argument address. */
|
||||
|
||||
while (trailer != 0)
|
||||
{
|
||||
while (trailer != 0) {
|
||||
block = (long *)trailer->this_address;
|
||||
size = trailer->this_size;
|
||||
if (block == 0 || size == 0)
|
||||
@@ -390,13 +369,11 @@ i00afunc (long *address)
|
||||
|
||||
result = address - block;
|
||||
|
||||
if (trailer == 0)
|
||||
{
|
||||
if (trailer == 0) {
|
||||
return result;
|
||||
}
|
||||
|
||||
do
|
||||
{
|
||||
do {
|
||||
if (trailer->this_size <= 0)
|
||||
abort();
|
||||
result += trailer->this_size;
|
||||
@@ -419,8 +396,7 @@ i00afunc (long *address)
|
||||
routine is to linearize, in some sense, stack addresses
|
||||
for alloca. */
|
||||
|
||||
static long
|
||||
i00afunc (long address)
|
||||
static long i00afunc(long address)
|
||||
{
|
||||
long stkl = 0;
|
||||
|
||||
@@ -455,10 +431,10 @@ i00afunc (long address)
|
||||
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;
|
||||
@@ -476,8 +452,7 @@ i00afunc (long address)
|
||||
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);
|
||||
#endif
|
||||
|
||||
105
src/asm/fstack.c
105
src/asm/fstack.c
@@ -50,8 +50,7 @@ ULONG filesize (char *s)
|
||||
FILE *f;
|
||||
ULONG size = 0;
|
||||
|
||||
if( (f=fopen(s,"rt"))!=NULL )
|
||||
{
|
||||
if ((f = fopen(s, "rt")) != NULL) {
|
||||
fseek(f, 0, SEEK_END);
|
||||
size = ftell(f);
|
||||
fclose(f);
|
||||
@@ -74,14 +73,14 @@ void pushcontext (void)
|
||||
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)
|
||||
{
|
||||
switch ((*ppFileStack)->nStatus = nCurrentStatus) {
|
||||
case STAT_isMacroArg:
|
||||
case STAT_isMacro:
|
||||
sym_SaveCurrentMacroArgs((*ppFileStack)->tzMacroArgs);
|
||||
@@ -94,26 +93,25 @@ void pushcontext (void)
|
||||
sym_SaveCurrentMacroArgs((*ppFileStack)->tzMacroArgs);
|
||||
(*ppFileStack)->pREPTBlock = pCurrentREPTBlock;
|
||||
(*ppFileStack)->nREPTBlockSize = nCurrentREPTBlockSize;
|
||||
(*ppFileStack)->nREPTBlockCount = nCurrentREPTBlockCount;
|
||||
(*ppFileStack)->nREPTBlockCount =
|
||||
nCurrentREPTBlockCount;
|
||||
break;
|
||||
}
|
||||
nLineNo = 0;
|
||||
}
|
||||
else
|
||||
} else
|
||||
fatalerror("No memory for context");
|
||||
}
|
||||
|
||||
int popcontext(void)
|
||||
{
|
||||
struct sContext *pLastFile,
|
||||
**ppLastFile;
|
||||
struct sContext *pLastFile, **ppLastFile;
|
||||
|
||||
if (nCurrentStatus == STAT_isREPTBlock)
|
||||
{
|
||||
if (--nCurrentREPTBlockCount)
|
||||
{
|
||||
if (nCurrentStatus == STAT_isREPTBlock) {
|
||||
if (--nCurrentREPTBlockCount) {
|
||||
yy_delete_buffer(CurrentFlexHandle);
|
||||
CurrentFlexHandle = yy_scan_bytes (pCurrentREPTBlock, nCurrentREPTBlockSize);
|
||||
CurrentFlexHandle =
|
||||
yy_scan_bytes(pCurrentREPTBlock,
|
||||
nCurrentREPTBlockSize);
|
||||
yy_switch_to_buffer(CurrentFlexHandle);
|
||||
sym_UseCurrentMacroArgs();
|
||||
sym_SetMacroArgID(nMacroCount++);
|
||||
@@ -122,11 +120,9 @@ int popcontext (void)
|
||||
}
|
||||
}
|
||||
|
||||
if( (pLastFile=pFileStack)!=NULL )
|
||||
{
|
||||
if ((pLastFile = pFileStack) != NULL) {
|
||||
ppLastFile = &pFileStack;
|
||||
while (pLastFile->pNext)
|
||||
{
|
||||
while (pLastFile->pNext) {
|
||||
ppLastFile = &(pLastFile->pNext);
|
||||
pLastFile = *ppLastFile;
|
||||
}
|
||||
@@ -135,8 +131,7 @@ int popcontext (void)
|
||||
nLineNo = pLastFile->nLine;
|
||||
if (nCurrentStatus == STAT_isInclude)
|
||||
fclose(pCurrentFile);
|
||||
if (nCurrentStatus == STAT_isMacro)
|
||||
{
|
||||
if (nCurrentStatus == STAT_isMacro) {
|
||||
sym_FreeCurrentMacroArgs();
|
||||
nLineNo += 1;
|
||||
}
|
||||
@@ -144,9 +139,9 @@ int popcontext (void)
|
||||
nLineNo += 1;
|
||||
|
||||
CurrentFlexHandle = pLastFile->FlexHandle;
|
||||
strcpy ((char *)tzCurrentFileName, (char *)pLastFile->tzFileName);
|
||||
switch (nCurrentStatus = pLastFile->nStatus)
|
||||
{
|
||||
strcpy((char *)tzCurrentFileName,
|
||||
(char *)pLastFile->tzFileName);
|
||||
switch (nCurrentStatus = pLastFile->nStatus) {
|
||||
case STAT_isMacroArg:
|
||||
case STAT_isMacro:
|
||||
sym_RestoreCurrentMacroArgs(pLastFile->tzMacroArgs);
|
||||
@@ -167,8 +162,7 @@ int popcontext (void)
|
||||
*ppLastFile = NULL;
|
||||
yy_switch_to_buffer(CurrentFlexHandle);
|
||||
return (0);
|
||||
}
|
||||
else
|
||||
} else
|
||||
return (1);
|
||||
}
|
||||
|
||||
@@ -190,8 +184,7 @@ void fstk_Dump (void)
|
||||
|
||||
pLastFile = pFileStack;
|
||||
|
||||
while (pLastFile)
|
||||
{
|
||||
while (pLastFile) {
|
||||
printf("%s(%ld) -> ", pLastFile->tzFileName, pLastFile->nLine);
|
||||
pLastFile = pLastFile->pNext;
|
||||
}
|
||||
@@ -218,19 +211,16 @@ void fstk_FindFile (char *s)
|
||||
|
||||
strcpy(t, s);
|
||||
|
||||
while (i < NextIncPath)
|
||||
{
|
||||
while (i < NextIncPath) {
|
||||
FILE *f;
|
||||
|
||||
if( (f=fopen(t,"rb"))!=NULL )
|
||||
{
|
||||
if ((f = fopen(t, "rb")) != NULL) {
|
||||
fclose(f);
|
||||
strcpy(s, t);
|
||||
return;
|
||||
}
|
||||
i += 1;
|
||||
if (i < NextIncPath)
|
||||
{
|
||||
if (i < NextIncPath) {
|
||||
strcpy(t, IncludePaths[i]);
|
||||
strcat(t, s);
|
||||
}
|
||||
@@ -255,8 +245,7 @@ ULONG fstk_RunInclude (char *s)
|
||||
fstk_FindFile(tzFileName);
|
||||
//printf( "INCLUDING: %s\n", tzFileName );
|
||||
|
||||
if( (f=fopen(tzFileName,"rt"))!=NULL )
|
||||
{
|
||||
if ((f = fopen(tzFileName, "rt")) != NULL) {
|
||||
pushcontext();
|
||||
nLineNo = 1;
|
||||
nCurrentStatus = STAT_isInclude;
|
||||
@@ -271,8 +260,7 @@ ULONG fstk_RunInclude (char *s)
|
||||
nLineNo -= 1;
|
||||
|
||||
return (1);
|
||||
}
|
||||
else
|
||||
} else
|
||||
return (0);
|
||||
}
|
||||
|
||||
@@ -287,8 +275,7 @@ ULONG fstk_RunMacro (char *s)
|
||||
{
|
||||
struct sSymbol *sym;
|
||||
|
||||
if( (sym=sym_FindMacro(s))!=NULL )
|
||||
{
|
||||
if ((sym = sym_FindMacro(s)) != NULL) {
|
||||
pushcontext();
|
||||
sym_SetMacroArgID(nMacroCount++);
|
||||
nLineNo = -1;
|
||||
@@ -296,11 +283,12 @@ ULONG fstk_RunMacro (char *s)
|
||||
nCurrentStatus = STAT_isMacro;
|
||||
strcpy(tzCurrentFileName, s);
|
||||
pCurrentMacro = sym;
|
||||
CurrentFlexHandle = yy_scan_bytes (pCurrentMacro->pMacro, pCurrentMacro->ulMacroSize);
|
||||
CurrentFlexHandle =
|
||||
yy_scan_bytes(pCurrentMacro->pMacro,
|
||||
pCurrentMacro->ulMacroSize);
|
||||
yy_switch_to_buffer(CurrentFlexHandle);
|
||||
return (1);
|
||||
}
|
||||
else
|
||||
} else
|
||||
return (0);
|
||||
}
|
||||
|
||||
@@ -320,15 +308,13 @@ void fstk_RunMacroArg (SLONG s)
|
||||
else
|
||||
s -= '0';
|
||||
|
||||
if( (sym=sym_FindMacroArg(s))!=NULL )
|
||||
{
|
||||
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
|
||||
} else
|
||||
fatalerror("No such macroargument");
|
||||
}
|
||||
|
||||
@@ -343,15 +329,14 @@ void fstk_RunString (char *s)
|
||||
{
|
||||
struct sSymbol *pSym;
|
||||
|
||||
if( (pSym=sym_FindSymbol(s))!=NULL )
|
||||
{
|
||||
if ((pSym = sym_FindSymbol(s)) != NULL) {
|
||||
pushcontext();
|
||||
nCurrentStatus = STAT_isMacroArg;
|
||||
strcpy(tzCurrentFileName, s);
|
||||
CurrentFlexHandle = yy_scan_bytes (pSym->pMacro, strlen (pSym->pMacro));
|
||||
CurrentFlexHandle =
|
||||
yy_scan_bytes(pSym->pMacro, strlen(pSym->pMacro));
|
||||
yy_switch_to_buffer(CurrentFlexHandle);
|
||||
}
|
||||
else
|
||||
} else
|
||||
yyerror("No such string symbol");
|
||||
}
|
||||
|
||||
@@ -364,8 +349,7 @@ void fstk_RunString (char *s)
|
||||
|
||||
void fstk_RunRept(ULONG count)
|
||||
{
|
||||
if (count)
|
||||
{
|
||||
if (count) {
|
||||
pushcontext();
|
||||
sym_UseCurrentMacroArgs();
|
||||
sym_SetMacroArgID(nMacroCount++);
|
||||
@@ -374,7 +358,8 @@ void fstk_RunRept (ULONG count)
|
||||
nCurrentStatus = STAT_isREPTBlock;
|
||||
nCurrentREPTBlockSize = ulNewMacroSize;
|
||||
pCurrentREPTBlock = tzNewMacro;
|
||||
CurrentFlexHandle = yy_scan_bytes (pCurrentREPTBlock, nCurrentREPTBlockSize);
|
||||
CurrentFlexHandle =
|
||||
yy_scan_bytes(pCurrentREPTBlock, nCurrentREPTBlockSize);
|
||||
yy_switch_to_buffer(CurrentFlexHandle);
|
||||
}
|
||||
}
|
||||
@@ -396,8 +381,7 @@ ULONG fstk_Init (char *s)
|
||||
fstk_FindFile(tzFileName);
|
||||
|
||||
pFileStack = NULL;
|
||||
if( (pCurrentFile=fopen(tzFileName,"rt"))!=NULL )
|
||||
{
|
||||
if ((pCurrentFile = fopen(tzFileName, "rt")) != NULL) {
|
||||
nMacroCount = 0;
|
||||
nCurrentStatus = STAT_isInclude;
|
||||
strcpy(tzCurrentFileName, tzFileName);
|
||||
@@ -405,7 +389,6 @@ ULONG fstk_Init (char *s)
|
||||
yy_switch_to_buffer(CurrentFlexHandle);
|
||||
nLineNo = 1;
|
||||
return (1);
|
||||
}
|
||||
else
|
||||
} else
|
||||
return (0);
|
||||
}
|
||||
@@ -95,8 +95,7 @@
|
||||
|
||||
/* "r" defs */
|
||||
|
||||
enum
|
||||
{
|
||||
enum {
|
||||
REG_B = 0,
|
||||
REG_C,
|
||||
REG_D,
|
||||
@@ -109,8 +108,7 @@ enum
|
||||
|
||||
/* "rr" defs */
|
||||
|
||||
enum
|
||||
{
|
||||
enum {
|
||||
REG_BC_IND = 0,
|
||||
REG_DE_IND,
|
||||
REG_HL_INDINC,
|
||||
@@ -119,8 +117,7 @@ enum
|
||||
|
||||
/* "ss" defs */
|
||||
|
||||
enum
|
||||
{
|
||||
enum {
|
||||
REG_BC = 0,
|
||||
REG_DE,
|
||||
REG_HL,
|
||||
@@ -138,17 +135,9 @@ enum
|
||||
|
||||
/* "cc" defs */
|
||||
|
||||
enum
|
||||
{
|
||||
enum {
|
||||
CC_NZ = 0,
|
||||
CC_Z,
|
||||
CC_NC,
|
||||
CC_C
|
||||
};
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -3,8 +3,7 @@
|
||||
#include "rpn.h"
|
||||
#include "asmy.h"
|
||||
|
||||
struct sLexInitString localstrings[] =
|
||||
{
|
||||
struct sLexInitString localstrings[] = {
|
||||
"adc", T_Z80_ADC,
|
||||
"add", T_Z80_ADD,
|
||||
"and", T_Z80_AND,
|
||||
|
||||
@@ -18,10 +18,8 @@ SLONG gbgfx2bin (char ch)
|
||||
{
|
||||
SLONG i;
|
||||
|
||||
for( i=0; i<=3; i+=1 )
|
||||
{
|
||||
if( CurrentOptions.gbgfx[i]==ch )
|
||||
{
|
||||
for (i = 0; i <= 3; i += 1) {
|
||||
if (CurrentOptions.gbgfx[i] == ch) {
|
||||
return (i);
|
||||
}
|
||||
}
|
||||
@@ -33,10 +31,8 @@ SLONG binary2bin (char ch)
|
||||
{
|
||||
SLONG i;
|
||||
|
||||
for( i=0; i<=1; i+=1 )
|
||||
{
|
||||
if( CurrentOptions.binary[i]==ch )
|
||||
{
|
||||
for (i = 0; i <= 1; i += 1) {
|
||||
if (CurrentOptions.binary[i] == ch) {
|
||||
return (i);
|
||||
}
|
||||
|
||||
@@ -67,8 +63,7 @@ SLONG ascii2bin (char *s)
|
||||
SLONG result = 0;
|
||||
x2bin convertfunc = char2bin;
|
||||
|
||||
switch (*s)
|
||||
{
|
||||
switch (*s) {
|
||||
case '$':
|
||||
radix = 16;
|
||||
s += 1;
|
||||
@@ -91,18 +86,14 @@ SLONG ascii2bin (char *s)
|
||||
break;
|
||||
}
|
||||
|
||||
if (radix == 4)
|
||||
{
|
||||
if (radix == 4) {
|
||||
SLONG c;
|
||||
|
||||
while (*s != '\0')
|
||||
{
|
||||
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++);
|
||||
}
|
||||
@@ -113,16 +104,13 @@ SLONG ascii2bin (char *s)
|
||||
ULONG ParseFixedPoint(char *s, ULONG size)
|
||||
{
|
||||
char dest[256];
|
||||
ULONG i = 0,
|
||||
dot = 0;
|
||||
ULONG i = 0, dot = 0;
|
||||
|
||||
while (size && dot != 2)
|
||||
{
|
||||
while (size && dot != 2) {
|
||||
if (s[i] == '.')
|
||||
dot += 1;
|
||||
|
||||
if (dot < 2)
|
||||
{
|
||||
if (dot < 2) {
|
||||
dest[i] = s[i];
|
||||
size -= 1;
|
||||
i += 1;
|
||||
@@ -152,13 +140,10 @@ ULONG ParseNumber (char *s, ULONG size)
|
||||
ULONG ParseSymbol(char *src, ULONG size)
|
||||
{
|
||||
char dest[MAXSYMLEN + 1];
|
||||
int copied = 0,
|
||||
size_backup = size;
|
||||
int copied = 0, size_backup = size;
|
||||
|
||||
while (size && copied < MAXSYMLEN)
|
||||
{
|
||||
if (*src == '\\')
|
||||
{
|
||||
while (size && copied < MAXSYMLEN) {
|
||||
if (*src == '\\') {
|
||||
char *marg;
|
||||
|
||||
src += 1;
|
||||
@@ -168,8 +153,7 @@ ULONG ParseSymbol (char *src, ULONG size)
|
||||
marg = sym_FindMacroArg(-1);
|
||||
else if (*src >= '0' && *src <= '9')
|
||||
marg = sym_FindMacroArg(*src);
|
||||
else
|
||||
{
|
||||
else {
|
||||
fatalerror("Malformed ID");
|
||||
return (0);
|
||||
}
|
||||
@@ -177,14 +161,11 @@ ULONG ParseSymbol (char *src, ULONG size)
|
||||
src += 1;
|
||||
size -= 1;
|
||||
|
||||
if (marg)
|
||||
{
|
||||
if (marg) {
|
||||
while (*marg)
|
||||
dest[copied++] = *marg++;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
dest[copied++] = *src++;
|
||||
size -= 1;
|
||||
}
|
||||
@@ -195,25 +176,19 @@ ULONG ParseSymbol (char *src, ULONG size)
|
||||
|
||||
dest[copied] = 0;
|
||||
|
||||
if( oDontExpandStrings==0
|
||||
&& sym_isString(dest) )
|
||||
{
|
||||
if (oDontExpandStrings == 0 && sym_isString(dest)) {
|
||||
char *s;
|
||||
|
||||
yyskipbytes(size_backup);
|
||||
yyunputstr(s = sym_GetStringValue(dest));
|
||||
|
||||
while( *s )
|
||||
{
|
||||
if( *s++=='\n' )
|
||||
{
|
||||
while (*s) {
|
||||
if (*s++ == '\n') {
|
||||
nLineNo -= 1;
|
||||
}
|
||||
}
|
||||
return (0);
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
strcpy(yylval.tzString, dest);
|
||||
return (1);
|
||||
}
|
||||
@@ -224,12 +199,9 @@ ULONG PutMacroArg (char *src, ULONG size)
|
||||
char *s;
|
||||
|
||||
yyskipbytes(size);
|
||||
if( (s=sym_FindMacroArg (src[1] - '0'))!=NULL )
|
||||
{
|
||||
if ((s = sym_FindMacroArg(src[1] - '0')) != NULL) {
|
||||
yyunputstr(s);
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
yyerror("Macro argument not defined");
|
||||
}
|
||||
return (0);
|
||||
@@ -243,16 +215,14 @@ ULONG PutUniqueArg (char *src, ULONG size)
|
||||
return (0);
|
||||
}
|
||||
|
||||
enum
|
||||
{
|
||||
enum {
|
||||
T_LEX_MACROARG = 3000,
|
||||
T_LEX_MACROUNIQUE
|
||||
};
|
||||
|
||||
extern struct sLexInitString localstrings[];
|
||||
|
||||
struct sLexInitString staticstrings[] =
|
||||
{
|
||||
struct sLexInitString staticstrings[] = {
|
||||
"||", T_OP_LOGICOR,
|
||||
"&&", T_OP_LOGICAND,
|
||||
"==", T_OP_LOGICEQU,
|
||||
@@ -365,32 +335,27 @@ struct sLexInitString staticstrings[] =
|
||||
NULL, 0
|
||||
};
|
||||
|
||||
struct sLexFloat tNumberToken =
|
||||
{
|
||||
struct sLexFloat tNumberToken = {
|
||||
ParseNumber,
|
||||
T_NUMBER
|
||||
};
|
||||
|
||||
struct sLexFloat tFixedPointToken =
|
||||
{
|
||||
struct sLexFloat tFixedPointToken = {
|
||||
ParseFixedPoint,
|
||||
T_NUMBER
|
||||
};
|
||||
|
||||
struct sLexFloat tIDToken =
|
||||
{
|
||||
struct sLexFloat tIDToken = {
|
||||
ParseSymbol,
|
||||
T_ID
|
||||
};
|
||||
|
||||
struct sLexFloat tMacroArgToken =
|
||||
{
|
||||
struct sLexFloat tMacroArgToken = {
|
||||
PutMacroArg,
|
||||
T_LEX_MACROARG
|
||||
};
|
||||
|
||||
struct sLexFloat tMacroUniqueToken =
|
||||
{
|
||||
struct sLexFloat tMacroUniqueToken = {
|
||||
PutUniqueArg,
|
||||
T_LEX_MACROUNIQUE
|
||||
};
|
||||
@@ -423,10 +388,14 @@ void setuplex (void)
|
||||
|
||||
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]);
|
||||
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
|
||||
|
||||
@@ -439,10 +408,14 @@ void setuplex (void)
|
||||
|
||||
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_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]);
|
||||
|
||||
@@ -13,8 +13,7 @@
|
||||
#include "types.h"
|
||||
#include "lexer.h"
|
||||
|
||||
struct sContext
|
||||
{
|
||||
struct sContext {
|
||||
YY_BUFFER_STATE FlexHandle;
|
||||
struct sSymbol *pMacro;
|
||||
struct sContext *pNext;
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
typedef union
|
||||
{
|
||||
typedef union {
|
||||
char tzSym[MAXSYMLEN + 1];
|
||||
char tzString[256];
|
||||
struct Expression sVal;
|
||||
@@ -149,5 +148,4 @@ typedef union
|
||||
#define T_CC_Z 399
|
||||
#define T_CC_NC 400
|
||||
|
||||
|
||||
extern YYSTYPE yylval;
|
||||
|
||||
@@ -6,28 +6,24 @@
|
||||
|
||||
#define LEXHASHSIZE 512
|
||||
|
||||
struct sLexInitString
|
||||
{
|
||||
struct sLexInitString {
|
||||
char *tzName;
|
||||
ULONG nToken;
|
||||
};
|
||||
|
||||
struct sLexFloat
|
||||
{
|
||||
struct sLexFloat {
|
||||
ULONG(*Callback) (char *s, ULONG size);
|
||||
ULONG nToken;
|
||||
};
|
||||
|
||||
struct yy_buffer_state
|
||||
{
|
||||
struct yy_buffer_state {
|
||||
char *pBufferStart;
|
||||
char *pBuffer;
|
||||
ULONG nBufferSize;
|
||||
ULONG oAtLineStart;
|
||||
};
|
||||
|
||||
enum eLexerState
|
||||
{
|
||||
enum eLexerState {
|
||||
LEX_STATE_NORMAL,
|
||||
LEX_STATE_MACROARGS
|
||||
};
|
||||
|
||||
@@ -1,8 +1,7 @@
|
||||
#ifndef MAIN_H
|
||||
#define MAIN_H
|
||||
|
||||
struct sOptions
|
||||
{
|
||||
struct sOptions {
|
||||
ULONG endian;
|
||||
char gbgfx[4];
|
||||
char binary[2];
|
||||
|
||||
@@ -55,8 +55,7 @@
|
||||
*
|
||||
*/
|
||||
|
||||
enum
|
||||
{
|
||||
enum {
|
||||
RPN_ADD = 0,
|
||||
RPN_SUB,
|
||||
RPN_MUL,
|
||||
@@ -95,8 +94,7 @@ enum
|
||||
RPN_SYM = 0x81
|
||||
};
|
||||
|
||||
enum
|
||||
{
|
||||
enum {
|
||||
SECT_BSS = 0,
|
||||
SECT_VRAM,
|
||||
SECT_CODE,
|
||||
@@ -104,15 +102,13 @@ enum
|
||||
SECT_HRAM
|
||||
};
|
||||
|
||||
enum
|
||||
{
|
||||
enum {
|
||||
SYM_LOCAL = 0,
|
||||
SYM_IMPORT,
|
||||
SYM_EXPORT
|
||||
};
|
||||
|
||||
enum
|
||||
{
|
||||
enum {
|
||||
PATCH_BYTE = 0,
|
||||
PATCH_WORD_L,
|
||||
PATCH_LONG_L,
|
||||
|
||||
@@ -4,8 +4,7 @@
|
||||
#include "rpn.h"
|
||||
#include "types.h"
|
||||
|
||||
struct Section
|
||||
{
|
||||
struct Section {
|
||||
char *pzName;
|
||||
UBYTE nType;
|
||||
ULONG nPC;
|
||||
|
||||
@@ -1,8 +1,7 @@
|
||||
#ifndef RPN_H
|
||||
#define RPN_H 1
|
||||
|
||||
struct Expression
|
||||
{
|
||||
struct Expression {
|
||||
SLONG nVal;
|
||||
UBYTE tRPN[256];
|
||||
ULONG nRPNLength;
|
||||
@@ -11,36 +10,54 @@ struct Expression
|
||||
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_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 );
|
||||
int rpn_RangeCheck(struct Expression *expr, struct Expression *src, SLONG low,
|
||||
SLONG high);
|
||||
#ifdef GAMEBOY
|
||||
void rpn_CheckHRAM(struct Expression *expr, struct Expression *src1);
|
||||
#endif
|
||||
|
||||
@@ -6,8 +6,7 @@
|
||||
#define HASHSIZE 73
|
||||
#define MAXSYMLEN 256
|
||||
|
||||
struct sSymbol
|
||||
{
|
||||
struct sSymbol {
|
||||
char tzName[MAXSYMLEN + 1];
|
||||
SLONG nValue;
|
||||
ULONG nType;
|
||||
|
||||
414
src/asm/lexer.c
414
src/asm/lexer.c
@@ -10,8 +10,7 @@
|
||||
#include <string.h>
|
||||
#include <ctype.h>
|
||||
|
||||
struct sLexString
|
||||
{
|
||||
struct sLexString {
|
||||
char *tzName;
|
||||
ULONG nToken;
|
||||
ULONG nNameLength;
|
||||
@@ -42,8 +41,7 @@ enum eLexerState lexerstate=LEX_STATE_NORMAL;
|
||||
#ifdef __GNUC__
|
||||
void strupr(char *s)
|
||||
{
|
||||
while( *s )
|
||||
{
|
||||
while (*s) {
|
||||
*s = toupper(*s);
|
||||
s += 1;
|
||||
}
|
||||
@@ -51,8 +49,7 @@ void strupr( char *s )
|
||||
|
||||
void strlwr(char *s)
|
||||
{
|
||||
while( *s )
|
||||
{
|
||||
while (*s) {
|
||||
*s = tolower(*s);
|
||||
s += 1;
|
||||
}
|
||||
@@ -104,10 +101,11 @@ YY_BUFFER_STATE yy_scan_bytes( char *mem, ULONG size )
|
||||
{
|
||||
YY_BUFFER_STATE pBuffer;
|
||||
|
||||
if( (pBuffer=(YY_BUFFER_STATE)malloc(sizeof(struct yy_buffer_state)))!=NULL )
|
||||
{
|
||||
if( (pBuffer->pBuffer=pBuffer->pBufferStart=(char *)malloc(size+1+SAFETYMARGIN))!=NULL )
|
||||
{
|
||||
if ((pBuffer =
|
||||
(YY_BUFFER_STATE) malloc(sizeof(struct yy_buffer_state))) !=
|
||||
NULL) {
|
||||
if ((pBuffer->pBuffer = pBuffer->pBufferStart =
|
||||
(char *)malloc(size + 1 + SAFETYMARGIN)) != NULL) {
|
||||
pBuffer->pBuffer += SAFETYMARGIN;
|
||||
pBuffer->pBufferStart += SAFETYMARGIN;
|
||||
memcpy(pBuffer->pBuffer, mem, size);
|
||||
@@ -126,16 +124,17 @@ YY_BUFFER_STATE yy_create_buffer( FILE *f )
|
||||
{
|
||||
YY_BUFFER_STATE pBuffer;
|
||||
|
||||
if( (pBuffer=(YY_BUFFER_STATE)malloc(sizeof(struct yy_buffer_state)))!=NULL )
|
||||
{
|
||||
if ((pBuffer =
|
||||
(YY_BUFFER_STATE) malloc(sizeof(struct yy_buffer_state))) !=
|
||||
NULL) {
|
||||
ULONG size;
|
||||
|
||||
fseek(f, 0, SEEK_END);
|
||||
size = ftell(f);
|
||||
fseek(f, 0, SEEK_SET);
|
||||
|
||||
if( (pBuffer->pBuffer=pBuffer->pBufferStart=(char *)malloc(size+2+SAFETYMARGIN))!=NULL )
|
||||
{
|
||||
if ((pBuffer->pBuffer = pBuffer->pBufferStart =
|
||||
(char *)malloc(size + 2 + SAFETYMARGIN)) != NULL) {
|
||||
char *mem;
|
||||
ULONG instring = 0;
|
||||
|
||||
@@ -150,41 +149,34 @@ YY_BUFFER_STATE yy_create_buffer( FILE *f )
|
||||
|
||||
mem = pBuffer->pBuffer;
|
||||
|
||||
while( *mem )
|
||||
{
|
||||
while (*mem) {
|
||||
if (*mem == '\"')
|
||||
instring = 1 - instring;
|
||||
|
||||
if( instring )
|
||||
{
|
||||
if (instring) {
|
||||
mem += 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
if ((mem[0] == 10 && mem[1] == 13)
|
||||
|| (mem[0]==13 && mem[1]==10) )
|
||||
{
|
||||
|| (mem[0] == 13 && mem[1] == 10)) {
|
||||
mem[0] = ' ';
|
||||
mem[1] = '\n';
|
||||
mem += 2;
|
||||
}
|
||||
else if( mem[0]==10 || mem[0]==13 )
|
||||
{
|
||||
} else if (mem[0] == 10 || mem[0] == 13) {
|
||||
mem[0] = '\n';
|
||||
mem += 1;
|
||||
}
|
||||
else if( mem[0]=='\n' && mem[1]=='*' )
|
||||
{
|
||||
} else if (mem[0] == '\n'
|
||||
&& mem[1] == '*') {
|
||||
mem += 1;
|
||||
while( !(*mem == '\n' || *mem == '\0') )
|
||||
while (!
|
||||
(*mem == '\n'
|
||||
|| *mem == '\0'))
|
||||
*mem++ = ' ';
|
||||
}
|
||||
else if( *mem==';' )
|
||||
{
|
||||
while( !(*mem == '\n' || *mem == '\0') )
|
||||
} else if (*mem == ';') {
|
||||
while (!
|
||||
(*mem == '\n'
|
||||
|| *mem == '\0'))
|
||||
*mem++ = ' ';
|
||||
}
|
||||
else
|
||||
} else
|
||||
mem += 1;
|
||||
}
|
||||
}
|
||||
@@ -207,8 +199,7 @@ ULONG lex_FloatAlloc( struct sLexFloat *tok )
|
||||
|
||||
void lex_FloatDeleteRange(ULONG id, UWORD start, UWORD end)
|
||||
{
|
||||
while( start<=end )
|
||||
{
|
||||
while (start <= end) {
|
||||
tFloatingChars[start] &= ~id;
|
||||
start += 1;
|
||||
}
|
||||
@@ -216,8 +207,7 @@ void lex_FloatDeleteRange( ULONG id, UWORD start, UWORD end )
|
||||
|
||||
void lex_FloatAddRange(ULONG id, UWORD start, UWORD end)
|
||||
{
|
||||
while( start<=end )
|
||||
{
|
||||
while (start <= end) {
|
||||
tFloatingChars[start] |= id;
|
||||
start += 1;
|
||||
}
|
||||
@@ -225,8 +215,7 @@ void lex_FloatAddRange( ULONG id, UWORD start, UWORD end )
|
||||
|
||||
void lex_FloatDeleteFirstRange(ULONG id, UWORD start, UWORD end)
|
||||
{
|
||||
while( start<=end )
|
||||
{
|
||||
while (start <= end) {
|
||||
tFloatingFirstChar[start] &= ~id;
|
||||
start += 1;
|
||||
}
|
||||
@@ -234,8 +223,7 @@ void lex_FloatDeleteFirstRange( ULONG id, UWORD start, UWORD end )
|
||||
|
||||
void lex_FloatAddFirstRange(ULONG id, UWORD start, UWORD end)
|
||||
{
|
||||
while( start<=end )
|
||||
{
|
||||
while (start <= end) {
|
||||
tFloatingFirstChar[start] |= id;
|
||||
start += 1;
|
||||
}
|
||||
@@ -243,8 +231,7 @@ void lex_FloatAddFirstRange( ULONG id, UWORD start, UWORD end )
|
||||
|
||||
void lex_FloatDeleteSecondRange(ULONG id, UWORD start, UWORD end)
|
||||
{
|
||||
while( start<=end )
|
||||
{
|
||||
while (start <= end) {
|
||||
tFloatingSecondChar[start] &= ~id;
|
||||
start += 1;
|
||||
}
|
||||
@@ -252,8 +239,7 @@ void lex_FloatDeleteSecondRange( ULONG id, UWORD start, UWORD end )
|
||||
|
||||
void lex_FloatAddSecondRange(ULONG id, UWORD start, UWORD end)
|
||||
{
|
||||
while( start<=end )
|
||||
{
|
||||
while (start <= end) {
|
||||
tFloatingSecondChar[start] |= id;
|
||||
start += 1;
|
||||
}
|
||||
@@ -261,14 +247,12 @@ void lex_FloatAddSecondRange( ULONG id, UWORD start, UWORD end )
|
||||
|
||||
struct sLexFloat *lexgetfloat(ULONG id)
|
||||
{
|
||||
ULONG r=0,
|
||||
mask=1;
|
||||
ULONG r = 0, mask = 1;
|
||||
|
||||
if (id == 0)
|
||||
return (NULL);
|
||||
|
||||
while( (id&mask)==0 )
|
||||
{
|
||||
while ((id & mask) == 0) {
|
||||
mask <<= 1;
|
||||
r += 1;
|
||||
}
|
||||
@@ -280,8 +264,7 @@ ULONG lexcalchash( char *s )
|
||||
{
|
||||
ULONG r = 0;
|
||||
|
||||
while( *s )
|
||||
{
|
||||
while (*s) {
|
||||
r = ((r << 1) + (toupper(*s))) % LEXHASHSIZE;
|
||||
s += 1;
|
||||
}
|
||||
@@ -293,13 +276,11 @@ void lex_Init( void )
|
||||
{
|
||||
ULONG i;
|
||||
|
||||
for( i=0; i<LEXHASHSIZE; i+=1)
|
||||
{
|
||||
for (i = 0; i < LEXHASHSIZE; i += 1) {
|
||||
tLexHash[i] = NULL;
|
||||
}
|
||||
|
||||
for( i=0; i<256; i+=1 )
|
||||
{
|
||||
for (i = 0; i < 256; i += 1) {
|
||||
tFloatingFirstChar[i] = 0;
|
||||
tFloatingSecondChar[i] = 0;
|
||||
tFloatingChars[i] = 0;
|
||||
@@ -311,8 +292,7 @@ void lex_Init( void )
|
||||
|
||||
void lex_AddStrings(struct sLexInitString *lex)
|
||||
{
|
||||
while( lex->tzName )
|
||||
{
|
||||
while (lex->tzName) {
|
||||
struct sLexString **ppHash;
|
||||
ULONG hash;
|
||||
|
||||
@@ -322,10 +302,11 @@ void lex_AddStrings( struct sLexInitString *lex )
|
||||
|
||||
// printf( "%s has hashvalue %d\n", lex->tzName, hash );
|
||||
|
||||
if( ((*ppHash)=(struct sLexString *)malloc(sizeof(struct sLexString)))!=NULL )
|
||||
{
|
||||
if( ((*ppHash)->tzName=(char *)strdup(lex->tzName))!=NULL )
|
||||
{
|
||||
if (((*ppHash) =
|
||||
(struct sLexString *)malloc(sizeof(struct sLexString))) !=
|
||||
NULL) {
|
||||
if (((*ppHash)->tzName =
|
||||
(char *)strdup(lex->tzName)) != NULL) {
|
||||
(*ppHash)->nNameLength = strlen(lex->tzName);
|
||||
(*ppHash)->nToken = lex->nToken;
|
||||
(*ppHash)->pNext = NULL;
|
||||
@@ -335,11 +316,9 @@ void lex_AddStrings( struct sLexInitString *lex )
|
||||
if ((*ppHash)->nNameLength > nLexMaxLeng)
|
||||
nLexMaxLeng = (*ppHash)->nNameLength;
|
||||
|
||||
}
|
||||
else
|
||||
} else
|
||||
fatalerror("Out of memory!");
|
||||
}
|
||||
else
|
||||
} else
|
||||
fatalerror("Out of memory!");
|
||||
|
||||
lex += 1;
|
||||
@@ -348,32 +327,25 @@ void lex_AddStrings( struct sLexInitString *lex )
|
||||
|
||||
ULONG yylex(void)
|
||||
{
|
||||
ULONG hash,
|
||||
maxlen;
|
||||
ULONG hash, maxlen;
|
||||
char *s;
|
||||
struct sLexString *pLongestFixed = NULL;
|
||||
ULONG nFloatMask,
|
||||
nOldFloatMask,
|
||||
nFloatLen;
|
||||
ULONG nFloatMask, nOldFloatMask, nFloatLen;
|
||||
ULONG linestart = AtLineStart;
|
||||
|
||||
switch( lexerstate )
|
||||
{
|
||||
switch (lexerstate) {
|
||||
case LEX_STATE_NORMAL:
|
||||
AtLineStart = 0;
|
||||
|
||||
scanagain:
|
||||
|
||||
while (*pLexBuffer == ' ' || *pLexBuffer == '\t')
|
||||
{
|
||||
while (*pLexBuffer == ' ' || *pLexBuffer == '\t') {
|
||||
linestart = 0;
|
||||
pLexBuffer += 1;
|
||||
}
|
||||
|
||||
if (*pLexBuffer == 0)
|
||||
{
|
||||
if (yywrap () == 0)
|
||||
{
|
||||
if (*pLexBuffer == 0) {
|
||||
if (yywrap() == 0) {
|
||||
linestart = AtLineStart;
|
||||
AtLineStart = 0;
|
||||
goto scanagain;
|
||||
@@ -383,8 +355,7 @@ ULONG yylex (void)
|
||||
s = pLexBuffer;
|
||||
nOldFloatMask = nFloatLen = 0;
|
||||
nFloatMask = tFloatingFirstChar[*s++];
|
||||
while (nFloatMask && nFloatLen < nLexBufferLeng)
|
||||
{
|
||||
while (nFloatMask && nFloatLen < nLexBufferLeng) {
|
||||
nFloatLen += 1;
|
||||
nOldFloatMask = nFloatMask;
|
||||
if (nFloatLen == 1)
|
||||
@@ -400,22 +371,19 @@ ULONG yylex (void)
|
||||
yyleng = 0;
|
||||
hash = 0;
|
||||
s = pLexBuffer;
|
||||
while (yyleng < nLexMaxLeng)
|
||||
{
|
||||
while (yyleng < nLexMaxLeng) {
|
||||
yyleng += 1;
|
||||
hash = ((hash << 1) + (toupper(*s))) % LEXHASHSIZE;
|
||||
s += 1;
|
||||
if (tLexHash[hash])
|
||||
{
|
||||
if (tLexHash[hash]) {
|
||||
struct sLexString *lex;
|
||||
|
||||
lex = tLexHash[hash];
|
||||
while (lex)
|
||||
{
|
||||
if (lex->nNameLength == yyleng)
|
||||
{
|
||||
if (strnicmp (pLexBuffer, lex->tzName, yyleng) == 0)
|
||||
{
|
||||
while (lex) {
|
||||
if (lex->nNameLength == yyleng) {
|
||||
if (strnicmp
|
||||
(pLexBuffer, lex->tzName,
|
||||
yyleng) == 0) {
|
||||
pLongestFixed = lex;
|
||||
}
|
||||
}
|
||||
@@ -425,22 +393,17 @@ ULONG yylex (void)
|
||||
|
||||
}
|
||||
|
||||
if (nFloatLen == 0 && pLongestFixed == NULL)
|
||||
{
|
||||
if (*pLexBuffer == '"')
|
||||
{
|
||||
if (nFloatLen == 0 && pLongestFixed == NULL) {
|
||||
if (*pLexBuffer == '"') {
|
||||
ULONG index = 0;
|
||||
|
||||
pLexBuffer += 1;
|
||||
while ((*pLexBuffer != '"') && (*pLexBuffer != '\n'))
|
||||
{
|
||||
char ch,
|
||||
*marg;
|
||||
while ((*pLexBuffer != '"')
|
||||
&& (*pLexBuffer != '\n')) {
|
||||
char ch, *marg;
|
||||
|
||||
if ((ch = *pLexBuffer++) == '\\')
|
||||
{
|
||||
switch (ch = (*pLexBuffer++))
|
||||
{
|
||||
if ((ch = *pLexBuffer++) == '\\') {
|
||||
switch (ch = (*pLexBuffer++)) {
|
||||
case 'n':
|
||||
ch = '\n';
|
||||
break;
|
||||
@@ -457,33 +420,47 @@ ULONG yylex (void)
|
||||
case '7':
|
||||
case '8':
|
||||
case '9':
|
||||
if( (marg=sym_FindMacroArg(ch-'0'))!=NULL )
|
||||
{
|
||||
if ((marg =
|
||||
sym_FindMacroArg(ch
|
||||
-
|
||||
'0'))
|
||||
!= NULL) {
|
||||
while (*marg)
|
||||
yylval.tzString[index++] = *marg++;
|
||||
yylval.
|
||||
tzString
|
||||
[index++]
|
||||
=
|
||||
*marg++;
|
||||
ch = 0;
|
||||
}
|
||||
break;
|
||||
case '@':
|
||||
if( (marg=sym_FindMacroArg(-1))!=NULL )
|
||||
{
|
||||
if ((marg =
|
||||
sym_FindMacroArg
|
||||
(-1)) != NULL) {
|
||||
while (*marg)
|
||||
yylval.tzString[index++] = *marg++;
|
||||
yylval.
|
||||
tzString
|
||||
[index++]
|
||||
=
|
||||
*marg++;
|
||||
ch = 0;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
else if (ch == '{')
|
||||
{
|
||||
} else if (ch == '{') {
|
||||
char sym[MAXSYMLEN];
|
||||
int i = 0;
|
||||
|
||||
while ((*pLexBuffer != '}') && (*pLexBuffer != '"') && (*pLexBuffer != '\n'))
|
||||
{
|
||||
if ((ch = *pLexBuffer++) == '\\')
|
||||
{
|
||||
switch (ch = (*pLexBuffer++))
|
||||
while ((*pLexBuffer != '}')
|
||||
&& (*pLexBuffer != '"')
|
||||
&& (*pLexBuffer !=
|
||||
'\n')) {
|
||||
if ((ch =
|
||||
*pLexBuffer++) ==
|
||||
'\\') {
|
||||
switch (ch =
|
||||
(*pLexBuffer++))
|
||||
{
|
||||
case '0':
|
||||
case '1':
|
||||
@@ -495,29 +472,32 @@ ULONG yylex (void)
|
||||
case '7':
|
||||
case '8':
|
||||
case '9':
|
||||
if( (marg=sym_FindMacroArg(ch-'0'))!=NULL )
|
||||
{
|
||||
while (*marg)
|
||||
if ((marg = sym_FindMacroArg(ch - '0')) != NULL) {
|
||||
while
|
||||
(*marg)
|
||||
sym[i++] = *marg++;
|
||||
ch = 0;
|
||||
}
|
||||
break;
|
||||
case '@':
|
||||
if( (marg=sym_FindMacroArg(-1))!=NULL )
|
||||
{
|
||||
while (*marg)
|
||||
if ((marg = sym_FindMacroArg(-1)) != NULL) {
|
||||
while
|
||||
(*marg)
|
||||
sym[i++] = *marg++;
|
||||
ch = 0;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
else
|
||||
} else
|
||||
sym[i++] = ch;
|
||||
}
|
||||
|
||||
sym[i] = 0;
|
||||
index += symvaluetostring (&yylval.tzString[index], sym);
|
||||
index +=
|
||||
symvaluetostring(&yylval.
|
||||
tzString
|
||||
[index],
|
||||
sym);
|
||||
if (*pLexBuffer == '}')
|
||||
pLexBuffer += 1;
|
||||
else
|
||||
@@ -537,22 +517,16 @@ ULONG yylex (void)
|
||||
pLexBuffer += 1;
|
||||
|
||||
return (T_STRING);
|
||||
}
|
||||
else if (*pLexBuffer == '{')
|
||||
{
|
||||
char sym[MAXSYMLEN],
|
||||
ch,
|
||||
*marg;
|
||||
} else if (*pLexBuffer == '{') {
|
||||
char sym[MAXSYMLEN], ch, *marg;
|
||||
int i = 0;
|
||||
|
||||
pLexBuffer += 1;
|
||||
|
||||
while ((*pLexBuffer != '}') && (*pLexBuffer != '\n'))
|
||||
{
|
||||
if ((ch = *pLexBuffer++) == '\\')
|
||||
{
|
||||
switch (ch = (*pLexBuffer++))
|
||||
{
|
||||
while ((*pLexBuffer != '}')
|
||||
&& (*pLexBuffer != '\n')) {
|
||||
if ((ch = *pLexBuffer++) == '\\') {
|
||||
switch (ch = (*pLexBuffer++)) {
|
||||
case '0':
|
||||
case '1':
|
||||
case '2':
|
||||
@@ -563,24 +537,31 @@ ULONG yylex (void)
|
||||
case '7':
|
||||
case '8':
|
||||
case '9':
|
||||
if( (marg=sym_FindMacroArg(ch-'0'))!=NULL )
|
||||
{
|
||||
if ((marg =
|
||||
sym_FindMacroArg(ch
|
||||
-
|
||||
'0'))
|
||||
!= NULL) {
|
||||
while (*marg)
|
||||
sym[i++] = *marg++;
|
||||
sym[i++]
|
||||
=
|
||||
*marg++;
|
||||
ch = 0;
|
||||
}
|
||||
break;
|
||||
case '@':
|
||||
if( (marg=sym_FindMacroArg(-1))!=NULL )
|
||||
{
|
||||
if ((marg =
|
||||
sym_FindMacroArg
|
||||
(-1)) != NULL) {
|
||||
while (*marg)
|
||||
sym[i++] = *marg++;
|
||||
sym[i++]
|
||||
=
|
||||
*marg++;
|
||||
ch = 0;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
else
|
||||
} else
|
||||
sym[i++] = ch;
|
||||
}
|
||||
sym[i] = 0;
|
||||
@@ -591,9 +572,7 @@ ULONG yylex (void)
|
||||
yyerror("Missing }");
|
||||
|
||||
return (T_STRING);
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
if (*pLexBuffer == '\n')
|
||||
AtLineStart = 1;
|
||||
|
||||
@@ -602,62 +581,49 @@ ULONG yylex (void)
|
||||
}
|
||||
}
|
||||
|
||||
if (nFloatLen == 0)
|
||||
{
|
||||
if (nFloatLen == 0) {
|
||||
yyleng = pLongestFixed->nNameLength;
|
||||
pLexBuffer += yyleng;
|
||||
return (pLongestFixed->nToken);
|
||||
}
|
||||
|
||||
if (pLongestFixed == NULL)
|
||||
{
|
||||
if (pLongestFixed == NULL) {
|
||||
struct sLexFloat *tok;
|
||||
|
||||
tok = lexgetfloat(nOldFloatMask);
|
||||
yyleng = nFloatLen;
|
||||
if (tok->Callback)
|
||||
{
|
||||
if (tok->Callback) {
|
||||
if (tok->Callback(pLexBuffer, yyleng) == 0)
|
||||
goto scanagain;
|
||||
}
|
||||
|
||||
if (tok->nToken == T_ID && linestart)
|
||||
{
|
||||
if (tok->nToken == T_ID && linestart) {
|
||||
pLexBuffer += yyleng;
|
||||
return (T_LABEL);
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
pLexBuffer += yyleng;
|
||||
return (tok->nToken);
|
||||
}
|
||||
}
|
||||
|
||||
if (nFloatLen > pLongestFixed->nNameLength)
|
||||
{
|
||||
if (nFloatLen > pLongestFixed->nNameLength) {
|
||||
struct sLexFloat *tok;
|
||||
|
||||
tok = lexgetfloat(nOldFloatMask);
|
||||
yyleng = nFloatLen;
|
||||
if (tok->Callback)
|
||||
{
|
||||
if (tok->Callback) {
|
||||
if (tok->Callback(pLexBuffer, yyleng) == 0)
|
||||
goto scanagain;
|
||||
}
|
||||
|
||||
if (tok->nToken == T_ID && linestart)
|
||||
{
|
||||
if (tok->nToken == T_ID && linestart) {
|
||||
pLexBuffer += yyleng;
|
||||
return (T_LABEL);
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
pLexBuffer += yyleng;
|
||||
return (tok->nToken);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
yyleng = pLongestFixed->nNameLength;
|
||||
pLexBuffer += yyleng;
|
||||
return (pLongestFixed->nToken);
|
||||
@@ -668,22 +634,17 @@ ULONG yylex (void)
|
||||
{
|
||||
ULONG index = 0;
|
||||
|
||||
while (*pLexBuffer == ' ' || *pLexBuffer == '\t')
|
||||
{
|
||||
while (*pLexBuffer == ' ' || *pLexBuffer == '\t') {
|
||||
linestart = 0;
|
||||
pLexBuffer += 1;
|
||||
}
|
||||
|
||||
while ((*pLexBuffer != ',')
|
||||
&& (*pLexBuffer != '\n') )
|
||||
{
|
||||
char ch,
|
||||
*marg;
|
||||
&& (*pLexBuffer != '\n')) {
|
||||
char ch, *marg;
|
||||
|
||||
if ((ch = *pLexBuffer++) == '\\')
|
||||
{
|
||||
switch (ch = (*pLexBuffer++))
|
||||
{
|
||||
if ((ch = *pLexBuffer++) == '\\') {
|
||||
switch (ch = (*pLexBuffer++)) {
|
||||
case 'n':
|
||||
ch = '\n';
|
||||
break;
|
||||
@@ -700,33 +661,42 @@ ULONG yylex (void)
|
||||
case '7':
|
||||
case '8':
|
||||
case '9':
|
||||
if( (marg=sym_FindMacroArg(ch-'0'))!=NULL )
|
||||
{
|
||||
if ((marg =
|
||||
sym_FindMacroArg(ch -
|
||||
'0')) !=
|
||||
NULL) {
|
||||
while (*marg)
|
||||
yylval.tzString[index++] = *marg++;
|
||||
yylval.
|
||||
tzString
|
||||
[index++] =
|
||||
*marg++;
|
||||
ch = 0;
|
||||
}
|
||||
break;
|
||||
case '@':
|
||||
if( (marg=sym_FindMacroArg(-1))!=NULL )
|
||||
{
|
||||
if ((marg =
|
||||
sym_FindMacroArg(-1)) !=
|
||||
NULL) {
|
||||
while (*marg)
|
||||
yylval.tzString[index++] = *marg++;
|
||||
yylval.
|
||||
tzString
|
||||
[index++] =
|
||||
*marg++;
|
||||
ch = 0;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
else if (ch == '{')
|
||||
{
|
||||
} else if (ch == '{') {
|
||||
char sym[MAXSYMLEN];
|
||||
int i = 0;
|
||||
|
||||
while ((*pLexBuffer != '}') && (*pLexBuffer != '"') && (*pLexBuffer != '\n'))
|
||||
{
|
||||
if ((ch = *pLexBuffer++) == '\\')
|
||||
{
|
||||
switch (ch = (*pLexBuffer++))
|
||||
while ((*pLexBuffer != '}')
|
||||
&& (*pLexBuffer != '"')
|
||||
&& (*pLexBuffer != '\n')) {
|
||||
if ((ch =
|
||||
*pLexBuffer++) == '\\') {
|
||||
switch (ch =
|
||||
(*pLexBuffer++))
|
||||
{
|
||||
case '0':
|
||||
case '1':
|
||||
@@ -738,28 +708,37 @@ ULONG yylex (void)
|
||||
case '7':
|
||||
case '8':
|
||||
case '9':
|
||||
if( (marg=sym_FindMacroArg(ch-'0'))!=NULL )
|
||||
{
|
||||
while (*marg)
|
||||
if ((marg =
|
||||
sym_FindMacroArg
|
||||
(ch -
|
||||
'0')) !=
|
||||
NULL) {
|
||||
while
|
||||
(*marg)
|
||||
sym[i++] = *marg++;
|
||||
ch = 0;
|
||||
}
|
||||
break;
|
||||
case '@':
|
||||
if( (marg=sym_FindMacroArg(-1))!=NULL )
|
||||
{
|
||||
while (*marg)
|
||||
if ((marg =
|
||||
sym_FindMacroArg
|
||||
(-1)) !=
|
||||
NULL) {
|
||||
while
|
||||
(*marg)
|
||||
sym[i++] = *marg++;
|
||||
ch = 0;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
else
|
||||
} else
|
||||
sym[i++] = ch;
|
||||
}
|
||||
sym[i] = 0;
|
||||
index += symvaluetostring (&yylval.tzString[index], sym);
|
||||
index +=
|
||||
symvaluetostring(&yylval.
|
||||
tzString[index],
|
||||
sym);
|
||||
if (*pLexBuffer == '}')
|
||||
pLexBuffer += 1;
|
||||
else
|
||||
@@ -771,35 +750,26 @@ ULONG yylex (void)
|
||||
yylval.tzString[index++] = ch;
|
||||
}
|
||||
|
||||
if( index )
|
||||
{
|
||||
if (index) {
|
||||
yyleng = index;
|
||||
yylval.tzString[index] = 0;
|
||||
if( *pLexBuffer=='\n' )
|
||||
{
|
||||
while( yylval.tzString[--index]==' ' )
|
||||
{
|
||||
if (*pLexBuffer == '\n') {
|
||||
while (yylval.tzString[--index] == ' ') {
|
||||
yylval.tzString[index] = 0;
|
||||
yyleng -= 1;
|
||||
}
|
||||
}
|
||||
return (T_STRING);
|
||||
}
|
||||
else if( *pLexBuffer=='\n' )
|
||||
{
|
||||
} else if (*pLexBuffer == '\n') {
|
||||
pLexBuffer += 1;
|
||||
AtLineStart = 1;
|
||||
yyleng = 1;
|
||||
return ('\n');
|
||||
}
|
||||
else if( *pLexBuffer==',' )
|
||||
{
|
||||
} else if (*pLexBuffer == ',') {
|
||||
pLexBuffer += 1;
|
||||
yyleng = 1;
|
||||
return (',');
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
yyerror("INTERNAL ERROR IN YYLEX");
|
||||
return (0);
|
||||
}
|
||||
|
||||
244
src/asm/main.c
244
src/asm/main.c
@@ -30,14 +30,9 @@ __near long __stack = 65536L;
|
||||
*
|
||||
*/
|
||||
|
||||
clock_t nStartClock,
|
||||
nEndClock;
|
||||
clock_t nStartClock, nEndClock;
|
||||
SLONG nLineNo;
|
||||
ULONG nTotalLines,
|
||||
nPass,
|
||||
nPC,
|
||||
nIFDepth,
|
||||
nErrors;
|
||||
ULONG nTotalLines, nPass, nPC, nIFDepth, nErrors;
|
||||
|
||||
extern int yydebug;
|
||||
|
||||
@@ -53,8 +48,7 @@ char temptext[1024];
|
||||
struct sOptions DefaultOptions;
|
||||
struct sOptions CurrentOptions;
|
||||
|
||||
struct sOptionStackEntry
|
||||
{
|
||||
struct sOptionStackEntry {
|
||||
struct sOptions Options;
|
||||
struct sOptionStackEntry *pNext;
|
||||
};
|
||||
@@ -63,46 +57,66 @@ struct sOptionStackEntry *pOptionStack=NULL;
|
||||
|
||||
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]);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -113,72 +127,64 @@ void opt_Parse( char *s )
|
||||
|
||||
newopt = CurrentOptions;
|
||||
|
||||
switch( s[0] )
|
||||
{
|
||||
switch (s[0]) {
|
||||
case 'e':
|
||||
switch( s[1] )
|
||||
{
|
||||
switch (s[1]) {
|
||||
case 'b':
|
||||
newopt.endian = ASM_BIG_ENDIAN;
|
||||
printf( "*WARNING*\t :\n\tEndianness forced to BIG for destination CPU\n" );
|
||||
printf
|
||||
("*WARNING*\t :\n\tEndianness forced to BIG for destination CPU\n");
|
||||
break;
|
||||
case 'l':
|
||||
newopt.endian = ASM_LITTLE_ENDIAN;
|
||||
printf( "*WARNING*\t :\n\tEndianness forced to LITTLE for destination CPU\n" );
|
||||
printf
|
||||
("*WARNING*\t :\n\tEndianness forced to LITTLE for destination CPU\n");
|
||||
break;
|
||||
default:
|
||||
printf ("*ERROR*\t :\n\tArgument to option -e must be 'b' or 'l'\n" );
|
||||
printf
|
||||
("*ERROR*\t :\n\tArgument to option -e must be 'b' or 'l'\n");
|
||||
exit(5);
|
||||
}
|
||||
break;
|
||||
case 'g':
|
||||
if( strlen(&s[1])==4 )
|
||||
{
|
||||
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" );
|
||||
} else {
|
||||
printf
|
||||
("*ERROR*\t :\n\tMust specify exactly 4 characters for option 'g'\n");
|
||||
exit(5);
|
||||
}
|
||||
break;
|
||||
case 'b':
|
||||
if( strlen(&s[1])==2 )
|
||||
{
|
||||
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" );
|
||||
} 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 )
|
||||
{
|
||||
if (strlen(&s[1]) <= 2) {
|
||||
if (strcmp(&s[1], "?") == 0) {
|
||||
newopt.fillchar = -1;
|
||||
}
|
||||
else
|
||||
{
|
||||
} 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" );
|
||||
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" );
|
||||
} else {
|
||||
printf
|
||||
("*ERROR*\t :\n\tInvalid argument for option 'z'\n");
|
||||
exit(5);
|
||||
}
|
||||
break;
|
||||
@@ -194,28 +200,26 @@ void opt_Push( void )
|
||||
{
|
||||
struct sOptionStackEntry *pOpt;
|
||||
|
||||
if( (pOpt=(struct sOptionStackEntry *)malloc(sizeof(struct sOptionStackEntry)))!=NULL )
|
||||
{
|
||||
if ((pOpt =
|
||||
(struct sOptionStackEntry *)
|
||||
malloc(sizeof(struct sOptionStackEntry))) != NULL) {
|
||||
pOpt->Options = CurrentOptions;
|
||||
pOpt->pNext = pOptionStack;
|
||||
pOptionStack = pOpt;
|
||||
}
|
||||
else
|
||||
} else
|
||||
fatalerror("No memory for option stack");
|
||||
}
|
||||
|
||||
void opt_Pop(void)
|
||||
{
|
||||
if( pOptionStack )
|
||||
{
|
||||
if (pOptionStack) {
|
||||
struct sOptionStackEntry *pOpt;
|
||||
|
||||
pOpt = pOptionStack;
|
||||
opt_SetCurrentOptions(&(pOpt->Options));
|
||||
pOptionStack = pOpt->pNext;
|
||||
free(pOpt);
|
||||
}
|
||||
else
|
||||
} else
|
||||
fatalerror("No entries in the option stack");
|
||||
}
|
||||
|
||||
@@ -249,17 +253,21 @@ void fatalerror (char *s)
|
||||
|
||||
void PrintUsage(void)
|
||||
{
|
||||
printf (APPNAME " v" ASM_VERSION " (part of ASMotor " ASMOTOR_VERSION ")\n\nUsage: " EXENAME " [options] asmfile\n");
|
||||
printf(APPNAME " v" ASM_VERSION " (part of ASMotor " ASMOTOR_VERSION
|
||||
")\n\nUsage: " EXENAME " [options] asmfile\n");
|
||||
printf("Options:\n");
|
||||
printf("\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"
|
||||
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"
|
||||
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"
|
||||
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);
|
||||
}
|
||||
@@ -293,10 +301,8 @@ int main (int argc, char *argv[])
|
||||
DefaultOptions.fillchar = -1; // fill uninitialised data with random values
|
||||
opt_SetCurrentOptions(&DefaultOptions);
|
||||
|
||||
while (argv[argn][0] == '-' && argc)
|
||||
{
|
||||
switch (argv[argn][1])
|
||||
{
|
||||
while (argv[argn][0] == '-' && argc) {
|
||||
switch (argv[argn][1]) {
|
||||
case 'h':
|
||||
PrintUsage();
|
||||
break;
|
||||
@@ -313,7 +319,8 @@ int main (int argc, char *argv[])
|
||||
opt_Parse(&argv[argn][1]);
|
||||
break;
|
||||
default:
|
||||
printf ("*ERROR*\t :\n\tUnknown option '%c'\n", argv[argn][1]);
|
||||
printf("*ERROR*\t :\n\tUnknown option '%c'\n",
|
||||
argv[argn][1]);
|
||||
exit(5);
|
||||
break;
|
||||
}
|
||||
@@ -340,17 +347,14 @@ int main (int argc, char *argv[])
|
||||
nPass = 1;
|
||||
nErrors = 0;
|
||||
sym_PrepPass1();
|
||||
if (fstk_Init (tzMainfile))
|
||||
{
|
||||
if (fstk_Init(tzMainfile)) {
|
||||
printf("Pass 1...\n");
|
||||
|
||||
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;
|
||||
@@ -365,40 +369,44 @@ int main (int argc, char *argv[])
|
||||
|
||||
printf("Pass 2...\n");
|
||||
|
||||
if (yyparse () == 0 && nErrors == 0)
|
||||
{
|
||||
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);
|
||||
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");
|
||||
printf
|
||||
("(INFINITY lines/minute)\n");
|
||||
else
|
||||
printf ("(%d lines/minute)\n", (int) (60 / timespent * nTotalLines));
|
||||
printf("(%d lines/minute)\n",
|
||||
(int)(60 / timespent *
|
||||
nTotalLines));
|
||||
out_WriteObject();
|
||||
}
|
||||
else
|
||||
{
|
||||
printf ("Assembly aborted in pass 2 (%ld errors)!\n", nErrors);
|
||||
} 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);
|
||||
} else {
|
||||
printf
|
||||
("*ERROR*\t:\tUnterminated IF construct (%ld levels)!\n",
|
||||
nIFDepth);
|
||||
exit(5);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
printf ("Assembly aborted in pass 1 (%ld errors)!\n", nErrors);
|
||||
} else {
|
||||
printf("Assembly aborted in pass 1 (%ld errors)!\n",
|
||||
nErrors);
|
||||
exit(5);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
printf("File '%s' not found\n", tzMainfile);
|
||||
exit(5);
|
||||
}
|
||||
|
||||
@@ -39,9 +39,11 @@ void math_DefinePI (void)
|
||||
void math_Print(SLONG i)
|
||||
{
|
||||
if (i >= 0)
|
||||
printf ("%ld.%05ld", i >> 16, ((SLONG) (fix2double (i) * 100000 + 0.5)) % 100000);
|
||||
printf("%ld.%05ld", i >> 16,
|
||||
((SLONG) (fix2double(i) * 100000 + 0.5)) % 100000);
|
||||
else
|
||||
printf ("-%ld.%05ld", (-i) >> 16, ((SLONG) (fix2double (-i) * 100000 + 0.5)) % 100000);
|
||||
printf("-%ld.%05ld", (-i) >> 16,
|
||||
((SLONG) (fix2double(-i) * 100000 + 0.5)) % 100000);
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -125,7 +127,8 @@ SLONG math_ATan (SLONG i)
|
||||
|
||||
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));
|
||||
}
|
||||
|
||||
/*
|
||||
|
||||
281
src/asm/output.c
281
src/asm/output.c
@@ -27,8 +27,7 @@
|
||||
|
||||
void out_SetCurrentSection(struct Section *pSect);
|
||||
|
||||
struct Patch
|
||||
{
|
||||
struct Patch {
|
||||
char tzFilename[_MAX_PATH + 1];
|
||||
ULONG nLine;
|
||||
ULONG nOffset;
|
||||
@@ -38,15 +37,13 @@ struct Patch
|
||||
struct Patch *pNext;
|
||||
};
|
||||
|
||||
struct PatchSymbol
|
||||
{
|
||||
struct PatchSymbol {
|
||||
ULONG ID;
|
||||
struct sSymbol *pSymbol;
|
||||
struct PatchSymbol *pNext;
|
||||
};
|
||||
|
||||
struct SectionStackEntry
|
||||
{
|
||||
struct SectionStackEntry {
|
||||
struct Section *pSection;
|
||||
struct SectionStackEntry *pNext;
|
||||
};
|
||||
@@ -58,8 +55,7 @@ struct SectionStackEntry
|
||||
*
|
||||
*/
|
||||
|
||||
struct Section *pSectionList=NULL,
|
||||
*pCurrentSection=NULL;
|
||||
struct Section *pSectionList = NULL, *pCurrentSection = NULL;
|
||||
struct PatchSymbol *pPatchSymbols = NULL;
|
||||
char tzObjectname[_MAX_PATH];
|
||||
struct SectionStackEntry *pSectionStack = NULL;
|
||||
@@ -75,28 +71,26 @@ void out_PushSection( void )
|
||||
{
|
||||
struct SectionStackEntry *pSect;
|
||||
|
||||
if( (pSect=(struct SectionStackEntry *)malloc(sizeof(struct SectionStackEntry)))!=NULL )
|
||||
{
|
||||
if ((pSect =
|
||||
(struct SectionStackEntry *)
|
||||
malloc(sizeof(struct SectionStackEntry))) != NULL) {
|
||||
pSect->pSection = pCurrentSection;
|
||||
pSect->pNext = pSectionStack;
|
||||
pSectionStack = pSect;
|
||||
}
|
||||
else
|
||||
} else
|
||||
fatalerror("No memory for section stack");
|
||||
}
|
||||
|
||||
void out_PopSection(void)
|
||||
{
|
||||
if( pSectionStack )
|
||||
{
|
||||
if (pSectionStack) {
|
||||
struct SectionStackEntry *pSect;
|
||||
|
||||
pSect = pSectionStack;
|
||||
out_SetCurrentSection(pSect->pSection);
|
||||
pSectionStack = pSect->pNext;
|
||||
free(pSect);
|
||||
}
|
||||
else
|
||||
} else
|
||||
fatalerror("No entries in the section stack");
|
||||
}
|
||||
|
||||
@@ -114,8 +108,7 @@ ULONG countsymbols( void )
|
||||
|
||||
pSym = pPatchSymbols;
|
||||
|
||||
while( pSym )
|
||||
{
|
||||
while (pSym) {
|
||||
count += 1;
|
||||
pSym = pSym->pNext;
|
||||
}
|
||||
@@ -137,8 +130,7 @@ ULONG countsections( void )
|
||||
|
||||
pSect = pSectionList;
|
||||
|
||||
while( pSect )
|
||||
{
|
||||
while (pSect) {
|
||||
count += 1;
|
||||
pSect = pSect->pNext;
|
||||
}
|
||||
@@ -159,8 +151,7 @@ ULONG countpatches( struct Section *pSect )
|
||||
ULONG r = 0;
|
||||
|
||||
pPatch = pSect->pPatches;
|
||||
while( pPatch )
|
||||
{
|
||||
while (pPatch) {
|
||||
r += 1;
|
||||
pPatch = pPatch->pNext;
|
||||
}
|
||||
@@ -211,8 +202,7 @@ ULONG getsectid( struct Section *pSect )
|
||||
|
||||
sec = pSectionList;
|
||||
|
||||
while( sec )
|
||||
{
|
||||
while (sec) {
|
||||
if (sec == pSect)
|
||||
return (ID);
|
||||
ID += 1;
|
||||
@@ -258,16 +248,14 @@ void writesection( struct Section *pSect, FILE * f )
|
||||
fputlong(pSect->nBank, f); // RGB1 addition
|
||||
|
||||
if ((pSect->nType == SECT_HOME)
|
||||
|| (pSect->nType==SECT_CODE) )
|
||||
{
|
||||
|| (pSect->nType == SECT_CODE)) {
|
||||
struct Patch *pPatch;
|
||||
|
||||
fwrite(pSect->tData, 1, pSect->nPC, f);
|
||||
fputlong(countpatches(pSect), f);
|
||||
|
||||
pPatch = pSect->pPatches;
|
||||
while (pPatch)
|
||||
{
|
||||
while (pPatch) {
|
||||
writepatch(pPatch, f);
|
||||
pPatch = pPatch->pNext;
|
||||
}
|
||||
@@ -288,16 +276,13 @@ void writesymbol (struct sSymbol *pSym, FILE * f)
|
||||
ULONG offset;
|
||||
SLONG sectid;
|
||||
|
||||
if (pSym->nType & SYMF_IMPORT)
|
||||
{
|
||||
if (pSym->nType & SYMF_IMPORT) {
|
||||
/* Symbol should be imported */
|
||||
strcpy(symname, pSym->tzName);
|
||||
offset = 0;
|
||||
sectid = -1;
|
||||
type = SYM_IMPORT;
|
||||
}
|
||||
else if (pSym->nType & SYMF_EXPORT)
|
||||
{
|
||||
} else if (pSym->nType & SYMF_EXPORT) {
|
||||
/* Symbol should be exported */
|
||||
strcpy(symname, pSym->tzName);
|
||||
type = SYM_EXPORT;
|
||||
@@ -306,16 +291,12 @@ void writesymbol (struct sSymbol *pSym, FILE * f)
|
||||
sectid = -1;
|
||||
else
|
||||
sectid = getsectid(pSym->pSection);
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
/* Symbol is local to this file */
|
||||
if (pSym->nType & SYMF_LOCAL)
|
||||
{
|
||||
if (pSym->nType & SYMF_LOCAL) {
|
||||
strcpy(symname, pSym->pScope->tzName);
|
||||
strcat(symname, pSym->tzName);
|
||||
}
|
||||
else
|
||||
} else
|
||||
strcpy(symname, pSym->tzName);
|
||||
type = SYM_LOCAL;
|
||||
offset = pSym->nValue;
|
||||
@@ -325,8 +306,7 @@ void writesymbol (struct sSymbol *pSym, FILE * f)
|
||||
fputstring(symname, f);
|
||||
fputc(type, f);
|
||||
|
||||
if (type != SYM_IMPORT)
|
||||
{
|
||||
if (type != SYM_IMPORT) {
|
||||
fputlong(sectid, f);
|
||||
fputlong(offset, f);
|
||||
}
|
||||
@@ -341,15 +321,13 @@ void writesymbol (struct sSymbol *pSym, FILE * f)
|
||||
|
||||
ULONG addsymbol(struct sSymbol *pSym)
|
||||
{
|
||||
struct PatchSymbol *pPSym,
|
||||
**ppPSym;
|
||||
struct PatchSymbol *pPSym, **ppPSym;
|
||||
ULONG ID = 0;
|
||||
|
||||
pPSym = pPatchSymbols;
|
||||
ppPSym = &(pPatchSymbols);
|
||||
|
||||
while (pPSym)
|
||||
{
|
||||
while (pPSym) {
|
||||
if (pSym == pPSym->pSymbol)
|
||||
return (pPSym->ID);
|
||||
ppPSym = &(pPSym->pNext);
|
||||
@@ -357,14 +335,14 @@ ULONG addsymbol (struct sSymbol *pSym)
|
||||
ID += 1;
|
||||
}
|
||||
|
||||
if( (*ppPSym=pPSym=(struct PatchSymbol *)malloc(sizeof(struct PatchSymbol)))!=NULL )
|
||||
{
|
||||
if ((*ppPSym = pPSym =
|
||||
(struct PatchSymbol *)malloc(sizeof(struct PatchSymbol))) !=
|
||||
NULL) {
|
||||
pPSym->pNext = NULL;
|
||||
pPSym->pSymbol = pSym;
|
||||
pPSym->ID = ID;
|
||||
return (ID);
|
||||
}
|
||||
else
|
||||
} else
|
||||
fatalerror("No memory for patchsymbol");
|
||||
|
||||
return ((ULONG) - 1);
|
||||
@@ -381,13 +359,11 @@ void addexports (void)
|
||||
{
|
||||
int i;
|
||||
|
||||
for (i = 0; i < HASHSIZE; i += 1)
|
||||
{
|
||||
for (i = 0; i < HASHSIZE; i += 1) {
|
||||
struct sSymbol *pSym;
|
||||
|
||||
pSym = tHashedSymbols[i];
|
||||
while (pSym)
|
||||
{
|
||||
while (pSym) {
|
||||
if (pSym->nType & SYMF_EXPORT)
|
||||
addsymbol(pSym);
|
||||
pSym = pSym->pNext;
|
||||
@@ -404,25 +380,22 @@ void addexports (void)
|
||||
|
||||
struct Patch *allocpatch(void)
|
||||
{
|
||||
struct Patch *pPatch,
|
||||
**ppPatch;
|
||||
struct Patch *pPatch, **ppPatch;
|
||||
|
||||
pPatch = pCurrentSection->pPatches;
|
||||
ppPatch = &(pCurrentSection->pPatches);
|
||||
|
||||
while (pPatch)
|
||||
{
|
||||
while (pPatch) {
|
||||
ppPatch = &(pPatch->pNext);
|
||||
pPatch = pPatch->pNext;
|
||||
}
|
||||
|
||||
if( (*ppPatch=pPatch=(struct Patch *)malloc(sizeof (struct Patch)))!=NULL )
|
||||
{
|
||||
if ((*ppPatch = pPatch =
|
||||
(struct Patch *)malloc(sizeof(struct Patch))) != NULL) {
|
||||
pPatch->pNext = NULL;
|
||||
pPatch->nRPNSize = 0;
|
||||
pPatch->pRPN = NULL;
|
||||
}
|
||||
else
|
||||
} else
|
||||
fatalerror("No memory for patch");
|
||||
|
||||
return (pPatch);
|
||||
@@ -441,8 +414,7 @@ void createpatch (ULONG type, struct Expression *expr)
|
||||
UWORD rpndata;
|
||||
UBYTE rpnexpr[2048];
|
||||
char tzSym[512];
|
||||
ULONG rpnptr = 0,
|
||||
symptr;
|
||||
ULONG rpnptr = 0, symptr;
|
||||
|
||||
pPatch = allocpatch();
|
||||
pPatch->nType = type;
|
||||
@@ -450,10 +422,8 @@ void createpatch (ULONG type, struct Expression *expr)
|
||||
pPatch->nLine = nLineNo;
|
||||
pPatch->nOffset = nPC;
|
||||
|
||||
while ((rpndata = rpn_PopByte (expr)) != 0xDEAD)
|
||||
{
|
||||
switch (rpndata)
|
||||
{
|
||||
while ((rpndata = rpn_PopByte(expr)) != 0xDEAD) {
|
||||
switch (rpndata) {
|
||||
case RPN_CONST:
|
||||
rpnexpr[rpnptr++] = RPN_CONST;
|
||||
rpnexpr[rpnptr++] = rpn_PopByte(expr);
|
||||
@@ -464,8 +434,7 @@ void createpatch (ULONG type, struct Expression *expr)
|
||||
case RPN_SYM:
|
||||
symptr = 0;
|
||||
while ((tzSym[symptr++] = rpn_PopByte(expr)) != 0) ;
|
||||
if (sym_isConstant (tzSym))
|
||||
{
|
||||
if (sym_isConstant(tzSym)) {
|
||||
ULONG value;
|
||||
|
||||
value = sym_GetConstantValue(tzSym);
|
||||
@@ -474,9 +443,7 @@ void createpatch (ULONG type, struct Expression *expr)
|
||||
rpnexpr[rpnptr++] = value >> 8;
|
||||
rpnexpr[rpnptr++] = value >> 16;
|
||||
rpnexpr[rpnptr++] = value >> 24;
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
symptr = addsymbol(sym_FindSymbol(tzSym));
|
||||
rpnexpr[rpnptr++] = RPN_SYM;
|
||||
rpnexpr[rpnptr++] = symptr & 0xFF;
|
||||
@@ -500,8 +467,7 @@ void createpatch (ULONG type, struct Expression *expr)
|
||||
break;
|
||||
}
|
||||
}
|
||||
if( (pPatch->pRPN=(UBYTE *)malloc(rpnptr))!=NULL )
|
||||
{
|
||||
if ((pPatch->pRPN = (UBYTE *) malloc(rpnptr)) != NULL) {
|
||||
memcpy(pPatch->pRPN, rpnexpr, rpnptr);
|
||||
pPatch->nRPNSize = rpnptr;
|
||||
}
|
||||
@@ -533,25 +499,27 @@ void checksection (void)
|
||||
void checkcodesection(SLONG size)
|
||||
{
|
||||
checksection();
|
||||
if ((pCurrentSection->nType == SECT_HOME || pCurrentSection->nType == SECT_CODE)
|
||||
&& (pCurrentSection->nPC + size <= MAXSECTIONSIZE))
|
||||
{
|
||||
if( ((pCurrentSection->nPC%SECTIONCHUNK)>((pCurrentSection->nPC+size)%SECTIONCHUNK))
|
||||
&& (pCurrentSection->nType == SECT_HOME || pCurrentSection->nType == SECT_CODE) )
|
||||
{
|
||||
if ((pCurrentSection->nType == SECT_HOME
|
||||
|| pCurrentSection->nType == SECT_CODE)
|
||||
&& (pCurrentSection->nPC + size <= MAXSECTIONSIZE)) {
|
||||
if (((pCurrentSection->nPC % SECTIONCHUNK) >
|
||||
((pCurrentSection->nPC + size) % SECTIONCHUNK))
|
||||
&& (pCurrentSection->nType == SECT_HOME
|
||||
|| pCurrentSection->nType == SECT_CODE)) {
|
||||
if ((pCurrentSection->tData =
|
||||
(UBYTE *) realloc(pCurrentSection->tData,
|
||||
((pCurrentSection->nPC+size)/SECTIONCHUNK+1)*SECTIONCHUNK))!=NULL )
|
||||
{
|
||||
((pCurrentSection->nPC +
|
||||
size) / SECTIONCHUNK +
|
||||
1) * SECTIONCHUNK)) != NULL) {
|
||||
return;
|
||||
}
|
||||
else
|
||||
fatalerror( "Not enough memory to expand section" );
|
||||
} else
|
||||
fatalerror
|
||||
("Not enough memory to expand section");
|
||||
}
|
||||
return;
|
||||
}
|
||||
else
|
||||
fatalerror ("Section can't contain initialized data or section limit exceeded");
|
||||
} else
|
||||
fatalerror
|
||||
("Section can't contain initialized data or section limit exceeded");
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -567,8 +535,7 @@ void out_WriteObject (void)
|
||||
|
||||
addexports();
|
||||
|
||||
if( (f=fopen(tzObjectname,"wb"))!=NULL )
|
||||
{
|
||||
if ((f = fopen(tzObjectname, "wb")) != NULL) {
|
||||
struct PatchSymbol *pSym;
|
||||
struct Section *pSect;
|
||||
|
||||
@@ -577,15 +544,13 @@ void out_WriteObject (void)
|
||||
fputlong(countsections(), f);
|
||||
|
||||
pSym = pPatchSymbols;
|
||||
while (pSym)
|
||||
{
|
||||
while (pSym) {
|
||||
writesymbol(pSym->pSymbol, f);
|
||||
pSym = pSym->pNext;
|
||||
}
|
||||
|
||||
pSect = pSectionList;
|
||||
while (pSect)
|
||||
{
|
||||
while (pSect) {
|
||||
writesection(pSect, f);
|
||||
pSect = pSect->pNext;
|
||||
}
|
||||
@@ -606,8 +571,7 @@ void out_PrepPass2 (void)
|
||||
struct Section *pSect;
|
||||
|
||||
pSect = pSectionList;
|
||||
while (pSect)
|
||||
{
|
||||
while (pSect) {
|
||||
pSect->nPC = 0;
|
||||
pSect = pSect->pNext;
|
||||
}
|
||||
@@ -638,33 +602,33 @@ void out_SetFileName (char *s)
|
||||
*
|
||||
*/
|
||||
|
||||
struct Section *out_FindSection (char *pzName, ULONG secttype, SLONG org, SLONG bank)
|
||||
struct Section *out_FindSection(char *pzName, ULONG secttype, SLONG org,
|
||||
SLONG bank)
|
||||
{
|
||||
struct Section *pSect,
|
||||
**ppSect;
|
||||
struct Section *pSect, **ppSect;
|
||||
|
||||
ppSect = &pSectionList;
|
||||
pSect = pSectionList;
|
||||
|
||||
while (pSect)
|
||||
{
|
||||
if (strcmp (pzName, pSect->pzName) == 0)
|
||||
{
|
||||
if( secttype==pSect->nType && ((ULONG)org)==pSect->nOrg && ((ULONG)bank)==pSect->nBank)
|
||||
{
|
||||
while (pSect) {
|
||||
if (strcmp(pzName, pSect->pzName) == 0) {
|
||||
if (secttype == pSect->nType
|
||||
&& ((ULONG) org) == pSect->nOrg
|
||||
&& ((ULONG) bank) == pSect->nBank) {
|
||||
return (pSect);
|
||||
}
|
||||
else
|
||||
fatalerror ("Section already exists but with a different type");
|
||||
} else
|
||||
fatalerror
|
||||
("Section already exists but with a different type");
|
||||
}
|
||||
ppSect = &(pSect->pNext);
|
||||
pSect = pSect->pNext;
|
||||
}
|
||||
|
||||
if( (*ppSect=(pSect=(struct Section *)malloc(sizeof(struct Section))))!=NULL )
|
||||
{
|
||||
if( (pSect->pzName=(char *)malloc(strlen(pzName)+1))!=NULL )
|
||||
{
|
||||
if ((*ppSect =
|
||||
(pSect =
|
||||
(struct Section *)malloc(sizeof(struct Section)))) != NULL) {
|
||||
if ((pSect->pzName =
|
||||
(char *)malloc(strlen(pzName) + 1)) != NULL) {
|
||||
strcpy(pSect->pzName, pzName);
|
||||
pSect->nType = secttype;
|
||||
pSect->nPC = 0;
|
||||
@@ -674,17 +638,14 @@ struct Section *out_FindSection (char *pzName, ULONG secttype, SLONG org, SLONG
|
||||
pSect->pPatches = NULL;
|
||||
pPatchSymbols = NULL;
|
||||
|
||||
if( (pSect->tData=(UBYTE *)malloc(SECTIONCHUNK))!=NULL )
|
||||
{
|
||||
if ((pSect->tData =
|
||||
(UBYTE *) malloc(SECTIONCHUNK)) != NULL) {
|
||||
return (pSect);
|
||||
}
|
||||
else
|
||||
} else
|
||||
fatalerror("Not enough memory for section");
|
||||
}
|
||||
else
|
||||
} else
|
||||
fatalerror("Not enough memory for sectionname");
|
||||
}
|
||||
else
|
||||
} else
|
||||
fatalerror("Not enough memory for section");
|
||||
|
||||
return (NULL);
|
||||
@@ -760,14 +721,12 @@ void out_Skip (int skip)
|
||||
{
|
||||
checksection();
|
||||
if ((CurrentOptions.fillchar == -1)
|
||||
|| !((pCurrentSection->nType == SECT_HOME) || (pCurrentSection->nType == SECT_CODE)) )
|
||||
{
|
||||
|| !((pCurrentSection->nType == SECT_HOME)
|
||||
|| (pCurrentSection->nType == SECT_CODE))) {
|
||||
pCurrentSection->nPC += skip;
|
||||
nPC += skip;
|
||||
pPCSymbol->nValue += skip;
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
checkcodesection(skip);
|
||||
while (skip--)
|
||||
out_AbsByte(CurrentOptions.fillchar);
|
||||
@@ -799,18 +758,15 @@ void out_String (char *s)
|
||||
void out_RelByte(struct Expression *expr)
|
||||
{
|
||||
checkcodesection(1);
|
||||
if (rpn_isReloc (expr))
|
||||
{
|
||||
if (nPass == 2)
|
||||
{
|
||||
if (rpn_isReloc(expr)) {
|
||||
if (nPass == 2) {
|
||||
pCurrentSection->tData[nPC] = 0;
|
||||
createpatch(PATCH_BYTE, expr);
|
||||
}
|
||||
pCurrentSection->nPC += 1;
|
||||
nPC += 1;
|
||||
pPCSymbol->nValue += 1;
|
||||
}
|
||||
else
|
||||
} else
|
||||
out_AbsByte(expr->nVal);
|
||||
|
||||
rpn_Reset(expr);
|
||||
@@ -827,15 +783,11 @@ void out_AbsWord (int b)
|
||||
{
|
||||
checkcodesection(2);
|
||||
b &= 0xFFFF;
|
||||
if (nPass == 2)
|
||||
{
|
||||
if( CurrentOptions.endian==ASM_LITTLE_ENDIAN )
|
||||
{
|
||||
if (nPass == 2) {
|
||||
if (CurrentOptions.endian == ASM_LITTLE_ENDIAN) {
|
||||
pCurrentSection->tData[nPC] = b & 0xFF;
|
||||
pCurrentSection->tData[nPC + 1] = b >> 8;
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
// Assume big endian
|
||||
pCurrentSection->tData[nPC] = b >> 8;
|
||||
pCurrentSection->tData[nPC + 1] = b & 0xFF;
|
||||
@@ -860,18 +812,13 @@ void out_RelWord (struct Expression *expr)
|
||||
|
||||
checkcodesection(2);
|
||||
b = expr->nVal & 0xFFFF;
|
||||
if (rpn_isReloc (expr))
|
||||
{
|
||||
if (nPass == 2)
|
||||
{
|
||||
if( CurrentOptions.endian==ASM_LITTLE_ENDIAN )
|
||||
{
|
||||
if (rpn_isReloc(expr)) {
|
||||
if (nPass == 2) {
|
||||
if (CurrentOptions.endian == ASM_LITTLE_ENDIAN) {
|
||||
pCurrentSection->tData[nPC] = b & 0xFF;
|
||||
pCurrentSection->tData[nPC + 1] = b >> 8;
|
||||
createpatch(PATCH_WORD_L, expr);
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
// Assume big endian
|
||||
pCurrentSection->tData[nPC] = b >> 8;
|
||||
pCurrentSection->tData[nPC + 1] = b & 0xFF;
|
||||
@@ -881,8 +828,7 @@ void out_RelWord (struct Expression *expr)
|
||||
pCurrentSection->nPC += 2;
|
||||
nPC += 2;
|
||||
pPCSymbol->nValue += 2;
|
||||
}
|
||||
else
|
||||
} else
|
||||
out_AbsWord(expr->nVal);
|
||||
rpn_Reset(expr);
|
||||
}
|
||||
@@ -897,17 +843,13 @@ void out_RelWord (struct Expression *expr)
|
||||
void out_AbsLong(SLONG b)
|
||||
{
|
||||
checkcodesection(sizeof(SLONG));
|
||||
if (nPass == 2)
|
||||
{
|
||||
if( CurrentOptions.endian==ASM_LITTLE_ENDIAN )
|
||||
{
|
||||
if (nPass == 2) {
|
||||
if (CurrentOptions.endian == ASM_LITTLE_ENDIAN) {
|
||||
pCurrentSection->tData[nPC] = b & 0xFF;
|
||||
pCurrentSection->tData[nPC + 1] = b >> 8;
|
||||
pCurrentSection->tData[nPC + 2] = b >> 16;
|
||||
pCurrentSection->tData[nPC + 3] = b >> 24;
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
// Assume big endian
|
||||
pCurrentSection->tData[nPC] = b >> 24;
|
||||
pCurrentSection->tData[nPC + 1] = b >> 16;
|
||||
@@ -934,20 +876,15 @@ void out_RelLong (struct Expression *expr)
|
||||
|
||||
checkcodesection(4);
|
||||
b = expr->nVal;
|
||||
if (rpn_isReloc (expr))
|
||||
{
|
||||
if (nPass == 2)
|
||||
{
|
||||
if( CurrentOptions.endian==ASM_LITTLE_ENDIAN )
|
||||
{
|
||||
if (rpn_isReloc(expr)) {
|
||||
if (nPass == 2) {
|
||||
if (CurrentOptions.endian == ASM_LITTLE_ENDIAN) {
|
||||
pCurrentSection->tData[nPC] = b & 0xFF;
|
||||
pCurrentSection->tData[nPC + 1] = b >> 8;
|
||||
pCurrentSection->tData[nPC + 2] = b >> 16;
|
||||
pCurrentSection->tData[nPC + 3] = b >> 24;
|
||||
createpatch(PATCH_LONG_L, expr);
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
// Assume big endian
|
||||
pCurrentSection->tData[nPC] = b >> 24;
|
||||
pCurrentSection->tData[nPC + 1] = b >> 16;
|
||||
@@ -959,8 +896,7 @@ void out_RelLong (struct Expression *expr)
|
||||
pCurrentSection->nPC += 4;
|
||||
nPC += 4;
|
||||
pPCSymbol->nValue += 4;
|
||||
}
|
||||
else
|
||||
} else
|
||||
out_AbsLong(expr->nVal);
|
||||
rpn_Reset(expr);
|
||||
}
|
||||
@@ -998,8 +934,7 @@ void out_BinaryFile (char *s)
|
||||
|
||||
fstk_FindFile(s);
|
||||
|
||||
if( (f=fopen(s,"rb"))!=NULL )
|
||||
{
|
||||
if ((f = fopen(s, "rb")) != NULL) {
|
||||
SLONG fsize;
|
||||
|
||||
fseek(f, 0, SEEK_END);
|
||||
@@ -1008,8 +943,7 @@ void out_BinaryFile (char *s)
|
||||
|
||||
checkcodesection(fsize);
|
||||
|
||||
if (nPass == 2)
|
||||
{
|
||||
if (nPass == 2) {
|
||||
SLONG dest = nPC;
|
||||
SLONG todo = fsize;
|
||||
|
||||
@@ -1021,7 +955,6 @@ void out_BinaryFile (char *s)
|
||||
nPC += fsize;
|
||||
pPCSymbol->nValue += fsize;
|
||||
fclose(f);
|
||||
}
|
||||
else
|
||||
} else
|
||||
fatalerror("File not found");
|
||||
}
|
||||
@@ -15,7 +15,8 @@
|
||||
#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);
|
||||
@@ -73,11 +74,9 @@ void rpn_Reset (struct Expression *expr)
|
||||
|
||||
UWORD rpn_PopByte(struct Expression *expr)
|
||||
{
|
||||
if (expr->nRPNOut == expr->nRPNLength)
|
||||
{
|
||||
if (expr->nRPNOut == expr->nRPNLength) {
|
||||
return (0xDEAD);
|
||||
}
|
||||
else
|
||||
} else
|
||||
return (expr->tRPN[expr->nRPNOut++]);
|
||||
}
|
||||
|
||||
@@ -125,37 +124,34 @@ void rpn_Number (struct Expression *expr, ULONG i)
|
||||
|
||||
void rpn_Symbol(struct Expression *expr, char *tzSym)
|
||||
{
|
||||
if (!sym_isConstant (tzSym))
|
||||
{
|
||||
if (!sym_isConstant(tzSym)) {
|
||||
struct sSymbol *psym;
|
||||
|
||||
rpn_Reset(expr);
|
||||
|
||||
psym = sym_FindSymbol(tzSym);
|
||||
|
||||
if (psym == NULL || psym->pSection == pCurrentSection || psym->pSection == NULL)
|
||||
if (psym == NULL || psym->pSection == pCurrentSection
|
||||
|| psym->pSection == NULL)
|
||||
expr->isPCRel = 1;
|
||||
expr->isReloc = 1;
|
||||
pushbyte(expr, RPN_SYM);
|
||||
while (*tzSym)
|
||||
pushbyte(expr, *tzSym++);
|
||||
pushbyte(expr, 0);
|
||||
}
|
||||
else
|
||||
} else
|
||||
rpn_Number(expr, sym_GetConstantValue(tzSym));
|
||||
}
|
||||
|
||||
void rpn_Bank(struct Expression *expr, char *tzSym)
|
||||
{
|
||||
if (!sym_isConstant (tzSym))
|
||||
{
|
||||
if (!sym_isConstant(tzSym)) {
|
||||
struct sSymbol *psym;
|
||||
|
||||
rpn_Reset(expr);
|
||||
|
||||
psym = sym_FindSymbol(tzSym);
|
||||
if (nPass == 2 && psym == NULL)
|
||||
{
|
||||
if (nPass == 2 && psym == NULL) {
|
||||
sprintf(temptext, "'%s' not defined", tzSym);
|
||||
yyerror(temptext);
|
||||
}
|
||||
@@ -164,17 +160,16 @@ void rpn_Bank (struct Expression *expr,char *tzSym)
|
||||
while (*tzSym)
|
||||
pushbyte(expr, *tzSym++);
|
||||
pushbyte(expr, 0);
|
||||
}
|
||||
else
|
||||
} 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;
|
||||
|
||||
if( rpn_isReloc(src) )
|
||||
{
|
||||
if (rpn_isReloc(src)) {
|
||||
pushbyte(expr, RPN_RANGECHECK);
|
||||
pushbyte(expr, low);
|
||||
pushbyte(expr, low >> 8);
|
||||
@@ -185,9 +180,7 @@ int rpn_RangeCheck( struct Expression *expr, struct Expression *src, SLONG low,
|
||||
pushbyte(expr, high >> 16);
|
||||
pushbyte(expr, high >> 24);
|
||||
return (1);
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
return (expr->nVal >= low && expr->nVal <= high);
|
||||
}
|
||||
}
|
||||
@@ -214,126 +207,144 @@ void rpn_LOGNOT (struct Expression *expr, struct Expression *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);
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
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);
|
||||
@@ -353,4 +364,3 @@ void rpn_UNNOT (struct Expression *expr, struct Expression *src)
|
||||
expr->nVal = expr->nVal ^ 0xFFFFFFFF;
|
||||
pushbyte(expr, RPN_UNNOT);
|
||||
}
|
||||
|
||||
|
||||
348
src/asm/symbol.c
348
src/asm/symbol.c
@@ -57,11 +57,9 @@ SLONG Callback__LINE__ (struct sSymbol *sym)
|
||||
|
||||
SLONG getvaluefield(struct sSymbol * sym)
|
||||
{
|
||||
if (sym->Callback)
|
||||
{
|
||||
if (sym->Callback) {
|
||||
return (sym->Callback(sym));
|
||||
}
|
||||
else
|
||||
} else
|
||||
return (sym->nValue);
|
||||
}
|
||||
|
||||
@@ -100,8 +98,8 @@ struct sSymbol *createsymbol (char *s)
|
||||
while ((*ppsym) != NULL)
|
||||
ppsym = &((*ppsym)->pNext);
|
||||
|
||||
if( ((*ppsym)=(struct sSymbol *)malloc(sizeof (struct sSymbol)))!=NULL )
|
||||
{
|
||||
if (((*ppsym) =
|
||||
(struct sSymbol *)malloc(sizeof(struct sSymbol))) != NULL) {
|
||||
strcpy((*ppsym)->tzName, s);
|
||||
(*ppsym)->nValue = 0;
|
||||
(*ppsym)->nType = 0;
|
||||
@@ -111,9 +109,7 @@ struct sSymbol *createsymbol (char *s)
|
||||
(*ppsym)->pSection = NULL;
|
||||
(*ppsym)->Callback = NULL;
|
||||
return (*ppsym);
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
fatalerror("No memory for symbol");
|
||||
return (NULL);
|
||||
}
|
||||
@@ -134,14 +130,11 @@ struct sSymbol *findsymbol (char *s, struct sSymbol *scope)
|
||||
hash = calchash(s);
|
||||
ppsym = &(tHashedSymbols[hash]);
|
||||
|
||||
while ((*ppsym) != NULL)
|
||||
{
|
||||
while ((*ppsym) != NULL) {
|
||||
if ((strcmp(s, (*ppsym)->tzName) == 0)
|
||||
&& ((*ppsym)->pScope == scope) )
|
||||
{
|
||||
&& ((*ppsym)->pScope == scope)) {
|
||||
return (*ppsym);
|
||||
}
|
||||
else
|
||||
} else
|
||||
ppsym = &((*ppsym)->pNext);
|
||||
}
|
||||
return (NULL);
|
||||
@@ -162,14 +155,11 @@ struct sSymbol **findpsymbol (char *s, struct sSymbol *scope)
|
||||
hash = calchash(s);
|
||||
ppsym = &(tHashedSymbols[hash]);
|
||||
|
||||
while ((*ppsym) != NULL)
|
||||
{
|
||||
while ((*ppsym) != NULL) {
|
||||
if ((strcmp(s, (*ppsym)->tzName) == 0)
|
||||
&& ((*ppsym)->pScope == scope) )
|
||||
{
|
||||
&& ((*ppsym)->pScope == scope)) {
|
||||
return (ppsym);
|
||||
}
|
||||
else
|
||||
} else
|
||||
ppsym = &((*ppsym)->pNext);
|
||||
}
|
||||
return (NULL);
|
||||
@@ -213,8 +203,7 @@ void sym_Purge( char *tzName )
|
||||
|
||||
ppSym = findpsymbol(tzName, pscope);
|
||||
|
||||
if( ppSym )
|
||||
{
|
||||
if (ppSym) {
|
||||
struct sSymbol *pSym;
|
||||
|
||||
pSym = *ppSym;
|
||||
@@ -224,9 +213,7 @@ void sym_Purge( char *tzName )
|
||||
free(pSym->pMacro);
|
||||
|
||||
free(pSym);
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
sprintf(temptext, "'%s' not defined", tzName);
|
||||
yyerror(temptext);
|
||||
}
|
||||
@@ -241,8 +228,7 @@ void sym_Purge( char *tzName )
|
||||
|
||||
ULONG sym_isConstDefined(char *tzName)
|
||||
{
|
||||
struct sSymbol *psym,
|
||||
*pscope;
|
||||
struct sSymbol *psym, *pscope;
|
||||
|
||||
if (*tzName == '.')
|
||||
pscope = pScope;
|
||||
@@ -251,16 +237,14 @@ ULONG sym_isConstDefined (char *tzName)
|
||||
|
||||
psym = findsymbol(tzName, pscope);
|
||||
|
||||
if( psym
|
||||
&& (psym->nType & SYMF_DEFINED) )
|
||||
{
|
||||
if( psym->nType & (SYMF_EQU|SYMF_SET|SYMF_MACRO|SYMF_STRING) )
|
||||
{
|
||||
if (psym && (psym->nType & SYMF_DEFINED)) {
|
||||
if (psym->
|
||||
nType & (SYMF_EQU | SYMF_SET | SYMF_MACRO | SYMF_STRING)) {
|
||||
return (1);
|
||||
}
|
||||
else
|
||||
{
|
||||
sprintf( temptext, "'%s' is not allowed as argument to the DEF function", tzName );
|
||||
} else {
|
||||
sprintf(temptext,
|
||||
"'%s' is not allowed as argument to the DEF function",
|
||||
tzName);
|
||||
fatalerror(temptext);
|
||||
}
|
||||
}
|
||||
@@ -269,8 +253,7 @@ ULONG sym_isConstDefined (char *tzName)
|
||||
|
||||
ULONG sym_isDefined(char *tzName)
|
||||
{
|
||||
struct sSymbol *psym,
|
||||
*pscope;
|
||||
struct sSymbol *psym, *pscope;
|
||||
|
||||
if (*tzName == '.')
|
||||
pscope = pScope;
|
||||
@@ -294,16 +277,14 @@ ULONG sym_isDefined (char *tzName)
|
||||
|
||||
ULONG sym_isConstant(char *s)
|
||||
{
|
||||
struct sSymbol *psym,
|
||||
*pscope;
|
||||
struct sSymbol *psym, *pscope;
|
||||
|
||||
if (*s == '.')
|
||||
pscope = pScope;
|
||||
else
|
||||
pscope = NULL;
|
||||
|
||||
if( (psym=findsymbol(s,pscope))!=NULL )
|
||||
{
|
||||
if ((psym = findsymbol(s, pscope)) != NULL) {
|
||||
if (psym->nType & SYMF_CONST)
|
||||
return (1);
|
||||
}
|
||||
@@ -324,8 +305,7 @@ char *sym_GetStringValue (char *tzSym)
|
||||
|
||||
if ((pSym = sym_FindSymbol(tzSym)) != NULL)
|
||||
return (pSym->pMacro);
|
||||
else
|
||||
{
|
||||
else {
|
||||
sprintf(temptext, "Stringsymbol '%s' not defined", tzSym);
|
||||
yyerror(temptext);
|
||||
}
|
||||
@@ -342,25 +322,20 @@ char *sym_GetStringValue (char *tzSym)
|
||||
|
||||
ULONG sym_GetConstantValue(char *s)
|
||||
{
|
||||
struct sSymbol *psym,
|
||||
*pscope;
|
||||
struct sSymbol *psym, *pscope;
|
||||
|
||||
if (*s == '.')
|
||||
pscope = pScope;
|
||||
else
|
||||
pscope = NULL;
|
||||
|
||||
if( (psym=findsymbol(s,pscope))!=NULL )
|
||||
{
|
||||
if ((psym = findsymbol(s, pscope)) != NULL) {
|
||||
if (psym->nType & SYMF_CONST)
|
||||
return (getvaluefield(psym));
|
||||
else
|
||||
{
|
||||
else {
|
||||
fatalerror("Expression must have a constant value");
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
sprintf(temptext, "'%s' not defined", s);
|
||||
yyerror(temptext);
|
||||
}
|
||||
@@ -377,48 +352,35 @@ ULONG sym_GetConstantValue (char *s)
|
||||
|
||||
ULONG sym_GetValue(char *s)
|
||||
{
|
||||
struct sSymbol *psym,
|
||||
*pscope;
|
||||
struct sSymbol *psym, *pscope;
|
||||
|
||||
if (*s == '.')
|
||||
pscope = pScope;
|
||||
else
|
||||
pscope = NULL;
|
||||
|
||||
if( (psym=findsymbol(s,pscope))!=NULL )
|
||||
{
|
||||
if( psym->nType & SYMF_DEFINED )
|
||||
{
|
||||
if( psym->nType & (SYMF_MACRO|SYMF_STRING) )
|
||||
{
|
||||
sprintf (temptext, "'%s' is a macro or string symbol", s);
|
||||
if ((psym = findsymbol(s, pscope)) != NULL) {
|
||||
if (psym->nType & SYMF_DEFINED) {
|
||||
if (psym->nType & (SYMF_MACRO | SYMF_STRING)) {
|
||||
sprintf(temptext,
|
||||
"'%s' is a macro or string symbol", s);
|
||||
yyerror(temptext);
|
||||
}
|
||||
return (getvaluefield(psym));
|
||||
}
|
||||
else
|
||||
{
|
||||
if ((nPass == 1) || (psym->nType & SYMF_IMPORT))
|
||||
{
|
||||
} else {
|
||||
if ((nPass == 1) || (psym->nType & SYMF_IMPORT)) {
|
||||
/* 0x80 seems like a good default value... */
|
||||
return (0x80);
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
sprintf(temptext, "'%s' not defined", s);
|
||||
yyerror(temptext);
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (nPass == 1)
|
||||
{
|
||||
} else {
|
||||
if (nPass == 1) {
|
||||
createsymbol(s);
|
||||
return (0x80);
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
sprintf(temptext, "'%s' not defined", s);
|
||||
yyerror(temptext);
|
||||
}
|
||||
@@ -436,34 +398,27 @@ ULONG sym_GetValue (char *s)
|
||||
|
||||
ULONG sym_GetDefinedValue(char *s)
|
||||
{
|
||||
struct sSymbol *psym,
|
||||
*pscope;
|
||||
struct sSymbol *psym, *pscope;
|
||||
|
||||
if (*s == '.')
|
||||
pscope = pScope;
|
||||
else
|
||||
pscope = NULL;
|
||||
|
||||
if( (psym=findsymbol(s,pscope))!=NULL )
|
||||
{
|
||||
if( (psym->nType & SYMF_DEFINED) )
|
||||
{
|
||||
if( psym->nType & (SYMF_MACRO|SYMF_STRING) )
|
||||
{
|
||||
sprintf (temptext, "'%s' is a macro or string symbol", s);
|
||||
if ((psym = findsymbol(s, pscope)) != NULL) {
|
||||
if ((psym->nType & SYMF_DEFINED)) {
|
||||
if (psym->nType & (SYMF_MACRO | SYMF_STRING)) {
|
||||
sprintf(temptext,
|
||||
"'%s' is a macro or string symbol", s);
|
||||
yyerror(temptext);
|
||||
}
|
||||
|
||||
return (getvaluefield(psym));
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
sprintf(temptext, "'%s' not defined", s);
|
||||
yyerror(temptext);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
sprintf(temptext, "'%s' not defined", s);
|
||||
yyerror(temptext);
|
||||
}
|
||||
@@ -483,8 +438,7 @@ void sym_ShiftCurrentMacroArgs (void)
|
||||
SLONG i;
|
||||
|
||||
free(currentmacroargs[0]);
|
||||
for (i = 0; i < MAXMACROARGS - 1; i += 1)
|
||||
{
|
||||
for (i = 0; i < MAXMACROARGS - 1; i += 1) {
|
||||
currentmacroargs[i] = currentmacroargs[i + 1];
|
||||
}
|
||||
currentmacroargs[MAXMACROARGS - 1] = NULL;
|
||||
@@ -502,8 +456,7 @@ void sym_UseNewMacroArgs (void)
|
||||
{
|
||||
SLONG i;
|
||||
|
||||
for (i = 0; i <= MAXMACROARGS; i += 1)
|
||||
{
|
||||
for (i = 0; i <= MAXMACROARGS; i += 1) {
|
||||
currentmacroargs[i] = newmacroargs[i];
|
||||
newmacroargs[i] = NULL;
|
||||
}
|
||||
@@ -529,8 +482,7 @@ void sym_FreeCurrentMacroArgs (void)
|
||||
{
|
||||
SLONG i;
|
||||
|
||||
for (i = 0; i <= MAXMACROARGS; i += 1)
|
||||
{
|
||||
for (i = 0; i <= MAXMACROARGS; i += 1) {
|
||||
free(currentmacroargs[i]);
|
||||
currentmacroargs[i] = NULL;
|
||||
}
|
||||
@@ -543,14 +495,12 @@ void sym_AddNewMacroArg (char *s)
|
||||
while (i < MAXMACROARGS && newmacroargs[i] != NULL)
|
||||
i += 1;
|
||||
|
||||
if (i < MAXMACROARGS)
|
||||
{
|
||||
if (i < MAXMACROARGS) {
|
||||
if (s)
|
||||
newmacroargs[i] = strdup(s);
|
||||
else
|
||||
newmacroargs[i] = NULL;
|
||||
}
|
||||
else
|
||||
} else
|
||||
yyerror("A maximum of 9 arguments allowed");
|
||||
}
|
||||
|
||||
@@ -592,24 +542,20 @@ struct sSymbol *sym_FindMacro (char *s)
|
||||
void sym_AddEqu(char *tzSym, SLONG value)
|
||||
{
|
||||
if ((nPass == 1)
|
||||
|| ((nPass==2)&&(sym_isDefined(tzSym)==0)) )
|
||||
{
|
||||
|| ((nPass == 2) && (sym_isDefined(tzSym) == 0))) {
|
||||
/* only add equated symbols in pass 1 */
|
||||
struct sSymbol *nsym;
|
||||
|
||||
if( (nsym=findsymbol(tzSym,NULL))!=NULL )
|
||||
{
|
||||
if (nsym->nType & SYMF_DEFINED)
|
||||
{
|
||||
sprintf (temptext, "'%s' already defined", tzSym);
|
||||
if ((nsym = findsymbol(tzSym, NULL)) != NULL) {
|
||||
if (nsym->nType & SYMF_DEFINED) {
|
||||
sprintf(temptext, "'%s' already defined",
|
||||
tzSym);
|
||||
yyerror(temptext);
|
||||
}
|
||||
}
|
||||
else
|
||||
} else
|
||||
nsym = createsymbol(tzSym);
|
||||
|
||||
if (nsym)
|
||||
{
|
||||
if (nsym) {
|
||||
nsym->nValue = value;
|
||||
nsym->nType |= SYMF_EQU | SYMF_DEFINED | SYMF_CONST;
|
||||
nsym->pScope = NULL;
|
||||
@@ -628,20 +574,17 @@ void sym_AddString (char *tzSym, char *tzValue)
|
||||
{
|
||||
struct sSymbol *nsym;
|
||||
|
||||
if( (nsym=findsymbol(tzSym,NULL))!=NULL )
|
||||
{
|
||||
if (nsym->nType & SYMF_DEFINED)
|
||||
{
|
||||
if ((nsym = findsymbol(tzSym, NULL)) != NULL) {
|
||||
if (nsym->nType & SYMF_DEFINED) {
|
||||
sprintf(temptext, "'%s' already defined", tzSym);
|
||||
yyerror(temptext);
|
||||
}
|
||||
}
|
||||
else
|
||||
} else
|
||||
nsym = createsymbol(tzSym);
|
||||
|
||||
if (nsym)
|
||||
{
|
||||
if( (nsym->pMacro=(char *)malloc(strlen(tzValue)+1))!=NULL )
|
||||
if (nsym) {
|
||||
if ((nsym->pMacro =
|
||||
(char *)malloc(strlen(tzValue) + 1)) != NULL)
|
||||
strcpy(nsym->pMacro, tzValue);
|
||||
else
|
||||
fatalerror("No memory for stringequate");
|
||||
@@ -662,8 +605,7 @@ ULONG sym_isString (char *tzSym)
|
||||
{
|
||||
struct sSymbol *pSym;
|
||||
|
||||
if( (pSym=findsymbol(tzSym,NULL))!=NULL )
|
||||
{
|
||||
if ((pSym = findsymbol(tzSym, NULL)) != NULL) {
|
||||
if (pSym->nType & SYMF_STRING)
|
||||
return (1);
|
||||
}
|
||||
@@ -681,14 +623,11 @@ void sym_AddSet (char *tzSym, SLONG value)
|
||||
{
|
||||
struct sSymbol *nsym;
|
||||
|
||||
if( (nsym=findsymbol(tzSym,NULL))!=NULL )
|
||||
{
|
||||
}
|
||||
else
|
||||
if ((nsym = findsymbol(tzSym, NULL)) != NULL) {
|
||||
} else
|
||||
nsym = createsymbol(tzSym);
|
||||
|
||||
if (nsym)
|
||||
{
|
||||
if (nsym) {
|
||||
nsym->nValue = value;
|
||||
nsym->nType |= SYMF_SET | SYMF_DEFINED | SYMF_CONST;
|
||||
nsym->pScope = NULL;
|
||||
@@ -705,33 +644,28 @@ void sym_AddSet (char *tzSym, SLONG value)
|
||||
void sym_AddLocalReloc(char *tzSym)
|
||||
{
|
||||
if ((nPass == 1)
|
||||
|| ((nPass==2)&&(sym_isDefined(tzSym)==0)) )
|
||||
{
|
||||
|| ((nPass == 2) && (sym_isDefined(tzSym) == 0))) {
|
||||
/* only add local reloc symbols in pass 1 */
|
||||
struct sSymbol *nsym;
|
||||
|
||||
if (pScope)
|
||||
{
|
||||
if( (nsym=findsymbol(tzSym,pScope))!=NULL )
|
||||
{
|
||||
if (nsym->nType & SYMF_DEFINED)
|
||||
{
|
||||
sprintf (temptext, "'%s' already defined", tzSym);
|
||||
if (pScope) {
|
||||
if ((nsym = findsymbol(tzSym, pScope)) != NULL) {
|
||||
if (nsym->nType & SYMF_DEFINED) {
|
||||
sprintf(temptext,
|
||||
"'%s' already defined", tzSym);
|
||||
yyerror(temptext);
|
||||
}
|
||||
}
|
||||
else
|
||||
} else
|
||||
nsym = createsymbol(tzSym);
|
||||
|
||||
if (nsym)
|
||||
{
|
||||
if (nsym) {
|
||||
nsym->nValue = nPC;
|
||||
nsym->nType |= SYMF_RELOC | SYMF_LOCAL | SYMF_DEFINED;
|
||||
nsym->nType |=
|
||||
SYMF_RELOC | SYMF_LOCAL | SYMF_DEFINED;
|
||||
nsym->pScope = pScope;
|
||||
nsym->pSection = pCurrentSection;
|
||||
}
|
||||
}
|
||||
else
|
||||
} else
|
||||
fatalerror("Local label in main scope");
|
||||
}
|
||||
}
|
||||
@@ -746,24 +680,20 @@ void sym_AddLocalReloc (char *tzSym)
|
||||
void sym_AddReloc(char *tzSym)
|
||||
{
|
||||
if ((nPass == 1)
|
||||
|| ((nPass==2)&&(sym_isDefined(tzSym)==0)) )
|
||||
{
|
||||
|| ((nPass == 2) && (sym_isDefined(tzSym) == 0))) {
|
||||
/* only add reloc symbols in pass 1 */
|
||||
struct sSymbol *nsym;
|
||||
|
||||
if( (nsym=findsymbol(tzSym,NULL))!=NULL )
|
||||
{
|
||||
if (nsym->nType & SYMF_DEFINED)
|
||||
{
|
||||
sprintf (temptext, "'%s' already defined", tzSym);
|
||||
if ((nsym = findsymbol(tzSym, NULL)) != NULL) {
|
||||
if (nsym->nType & SYMF_DEFINED) {
|
||||
sprintf(temptext, "'%s' already defined",
|
||||
tzSym);
|
||||
yyerror(temptext);
|
||||
}
|
||||
}
|
||||
else
|
||||
} else
|
||||
nsym = createsymbol(tzSym);
|
||||
|
||||
if (nsym)
|
||||
{
|
||||
if (nsym) {
|
||||
nsym->nValue = nPC;
|
||||
nsym->nType |= SYMF_RELOC | SYMF_DEFINED;
|
||||
nsym->pScope = NULL;
|
||||
@@ -783,8 +713,7 @@ void sym_AddReloc (char *tzSym)
|
||||
|
||||
void sym_Export(char *tzSym)
|
||||
{
|
||||
if (nPass == 1)
|
||||
{
|
||||
if (nPass == 1) {
|
||||
/* only export symbols in pass 1 */
|
||||
struct sSymbol *nsym;
|
||||
|
||||
@@ -793,13 +722,10 @@ void sym_Export (char *tzSym)
|
||||
|
||||
if (nsym)
|
||||
nsym->nType |= SYMF_EXPORT;
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
struct sSymbol *nsym;
|
||||
|
||||
if( (nsym=findsymbol(tzSym,0))!=NULL )
|
||||
{
|
||||
if ((nsym = findsymbol(tzSym, 0)) != NULL) {
|
||||
if (nsym->nType & SYMF_DEFINED)
|
||||
return;
|
||||
}
|
||||
@@ -818,13 +744,11 @@ void sym_Export (char *tzSym)
|
||||
|
||||
void sym_Import(char *tzSym)
|
||||
{
|
||||
if (nPass == 1)
|
||||
{
|
||||
if (nPass == 1) {
|
||||
/* only import symbols in pass 1 */
|
||||
struct sSymbol *nsym;
|
||||
|
||||
if (findsymbol (tzSym, NULL))
|
||||
{
|
||||
if (findsymbol(tzSym, NULL)) {
|
||||
sprintf(temptext, "'%s' already defined", tzSym);
|
||||
yyerror(temptext);
|
||||
}
|
||||
@@ -843,23 +767,19 @@ void sym_Import (char *tzSym)
|
||||
|
||||
void sym_Global(char *tzSym)
|
||||
{
|
||||
if (nPass == 2)
|
||||
{
|
||||
if (nPass == 2) {
|
||||
/* only globalize symbols in pass 2 */
|
||||
struct sSymbol *nsym;
|
||||
|
||||
nsym = findsymbol(tzSym, 0);
|
||||
|
||||
if ((nsym == NULL) || ((nsym->nType & SYMF_DEFINED) == 0))
|
||||
{
|
||||
if ((nsym == NULL) || ((nsym->nType & SYMF_DEFINED) == 0)) {
|
||||
if (nsym == NULL)
|
||||
nsym = createsymbol(tzSym);
|
||||
|
||||
if (nsym)
|
||||
nsym->nType |= SYMF_IMPORT;
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
if (nsym)
|
||||
nsym->nType |= SYMF_EXPORT;
|
||||
}
|
||||
@@ -876,24 +796,20 @@ void sym_Global (char *tzSym)
|
||||
void sym_AddMacro(char *tzSym)
|
||||
{
|
||||
if ((nPass == 1)
|
||||
|| ((nPass==2)&&(sym_isDefined(tzSym)==0)) )
|
||||
{
|
||||
|| ((nPass == 2) && (sym_isDefined(tzSym) == 0))) {
|
||||
/* only add macros in pass 1 */
|
||||
struct sSymbol *nsym;
|
||||
|
||||
if( (nsym=findsymbol(tzSym,NULL))!=NULL )
|
||||
{
|
||||
if (nsym->nType & SYMF_DEFINED)
|
||||
{
|
||||
sprintf (temptext, "'%s' already defined", tzSym);
|
||||
if ((nsym = findsymbol(tzSym, NULL)) != NULL) {
|
||||
if (nsym->nType & SYMF_DEFINED) {
|
||||
sprintf(temptext, "'%s' already defined",
|
||||
tzSym);
|
||||
yyerror(temptext);
|
||||
}
|
||||
}
|
||||
else
|
||||
} else
|
||||
nsym = createsymbol(tzSym);
|
||||
|
||||
if (nsym)
|
||||
{
|
||||
if (nsym) {
|
||||
nsym->nValue = nPC;
|
||||
nsym->nType |= SYMF_MACRO | SYMF_DEFINED;
|
||||
nsym->pScope = NULL;
|
||||
@@ -926,21 +842,18 @@ void sym_PrepPass2 (void)
|
||||
{
|
||||
SLONG i;
|
||||
|
||||
for (i = 0; i < HASHSIZE; i += 1)
|
||||
{
|
||||
for (i = 0; i < HASHSIZE; i += 1) {
|
||||
struct sSymbol **ppSym = &(tHashedSymbols[i]);
|
||||
|
||||
while (*ppSym)
|
||||
{
|
||||
if ((*ppSym)->nType & (SYMF_SET | SYMF_STRING | SYMF_EQU))
|
||||
{
|
||||
while (*ppSym) {
|
||||
if ((*ppSym)->
|
||||
nType & (SYMF_SET | SYMF_STRING | SYMF_EQU)) {
|
||||
struct sSymbol *pTemp;
|
||||
|
||||
pTemp = (*ppSym)->pNext;
|
||||
free(*ppSym);
|
||||
*ppSym = pTemp;
|
||||
}
|
||||
else
|
||||
} else
|
||||
ppSym = &((*ppSym)->pNext);
|
||||
}
|
||||
}
|
||||
@@ -964,8 +877,7 @@ void sym_Init (void)
|
||||
SLONG i;
|
||||
time_t tod;
|
||||
|
||||
for (i = 0; i < MAXMACROARGS; i += 1)
|
||||
{
|
||||
for (i = 0; i < MAXMACROARGS; i += 1) {
|
||||
currentmacroargs[i] = NULL;
|
||||
newmacroargs[i] = NULL;
|
||||
}
|
||||
@@ -985,8 +897,7 @@ void sym_Init (void)
|
||||
sym_AddEqu("__ASM__", (SLONG) (atof(ASM_VERSION) * 65536));
|
||||
sym_AddSet("_RS", 0);
|
||||
|
||||
if( time(&tod)!=-1 )
|
||||
{
|
||||
if (time(&tod) != -1) {
|
||||
struct tm *tptr;
|
||||
|
||||
tptr = localtime(&tod);
|
||||
@@ -1013,44 +924,43 @@ void sym_PrintSymbolTable (void)
|
||||
{
|
||||
ULONG i;
|
||||
|
||||
for (i = 0; i < HASHSIZE; i += 1)
|
||||
{
|
||||
for (i = 0; i < HASHSIZE; i += 1) {
|
||||
struct sSymbol *sym = tHashedSymbols[i];
|
||||
|
||||
if (sym != NULL)
|
||||
printf("\nHashTable #%ld:\n", i);
|
||||
|
||||
while (sym != NULL)
|
||||
{
|
||||
while (sym != NULL) {
|
||||
if (sym->nType & SYMF_LOCAL)
|
||||
printf ("LOCAL : '%s%s' - %08lX\n", sym->pScope->tzName, sym->tzName, getvaluefield (sym));
|
||||
else if (sym->nType & (SYMF_MACRO | SYMF_STRING))
|
||||
{
|
||||
printf("LOCAL : '%s%s' - %08lX\n",
|
||||
sym->pScope->tzName, sym->tzName,
|
||||
getvaluefield(sym));
|
||||
else if (sym->nType & (SYMF_MACRO | SYMF_STRING)) {
|
||||
ULONG i = 0;
|
||||
|
||||
printf("MACRO : '%s'\n\"", sym->tzName);
|
||||
while (i < sym->ulMacroSize)
|
||||
{
|
||||
if (sym->pMacro[i] == '\n')
|
||||
{
|
||||
while (i < sym->ulMacroSize) {
|
||||
if (sym->pMacro[i] == '\n') {
|
||||
printf("\n");
|
||||
i += 1;
|
||||
}
|
||||
else
|
||||
} else
|
||||
printf("%c", sym->pMacro[i++]);
|
||||
}
|
||||
printf("\"\n");
|
||||
}
|
||||
else if (sym->nType & SYMF_EXPORT)
|
||||
printf ("EXPORT: '%s' - %08lX\n", sym->tzName, getvaluefield (sym));
|
||||
} else if (sym->nType & SYMF_EXPORT)
|
||||
printf("EXPORT: '%s' - %08lX\n", sym->tzName,
|
||||
getvaluefield(sym));
|
||||
else if (sym->nType & SYMF_IMPORT)
|
||||
printf("IMPORT: '%s'\n", sym->tzName);
|
||||
else if (sym->nType & SYMF_EQU)
|
||||
printf ("EQU : '%s' - %08lX\n", sym->tzName, getvaluefield (sym));
|
||||
printf("EQU : '%s' - %08lX\n", sym->tzName,
|
||||
getvaluefield(sym));
|
||||
else if (sym->nType & SYMF_SET)
|
||||
printf ("SET : '%s' - %08lX\n", sym->tzName, getvaluefield (sym));
|
||||
printf("SET : '%s' - %08lX\n", sym->tzName,
|
||||
getvaluefield(sym));
|
||||
else
|
||||
printf ("SYMBOL: '%s' - %08lX\n", sym->tzName, getvaluefield (sym));
|
||||
printf("SYMBOL: '%s' - %08lX\n", sym->tzName,
|
||||
getvaluefield(sym));
|
||||
|
||||
sym = sym->pNext;
|
||||
}
|
||||
|
||||
@@ -5,8 +5,7 @@
|
||||
|
||||
#define MAXNAMELENGTH 256
|
||||
|
||||
struct LibraryWrapper
|
||||
{
|
||||
struct LibraryWrapper {
|
||||
char tName[MAXNAMELENGTH];
|
||||
UWORD uwTime;
|
||||
UWORD uwDate;
|
||||
|
||||
@@ -8,8 +8,7 @@ extern void fatalerror( char *s );
|
||||
|
||||
SLONG file_Length(FILE * f)
|
||||
{
|
||||
ULONG r,
|
||||
p;
|
||||
ULONG r, p;
|
||||
|
||||
p = ftell(f);
|
||||
fseek(f, 0, SEEK_END);
|
||||
@@ -75,37 +74,37 @@ void file_WriteLong( UWORD w, FILE *f )
|
||||
|
||||
sLibrary *lib_ReadLib0(FILE * f, SLONG size)
|
||||
{
|
||||
if( size )
|
||||
{
|
||||
sLibrary *l=NULL,
|
||||
*first=NULL;
|
||||
if (size) {
|
||||
sLibrary *l = NULL, *first = NULL;
|
||||
|
||||
while( size>0 )
|
||||
{
|
||||
if( l==NULL )
|
||||
{
|
||||
if( (l=(sLibrary *)malloc(sizeof(sLibrary)))==NULL )
|
||||
while (size > 0) {
|
||||
if (l == NULL) {
|
||||
if ((l =
|
||||
(sLibrary *) malloc(sizeof(sLibrary))) ==
|
||||
NULL)
|
||||
fatalerror("Out of memory");
|
||||
|
||||
first = l;
|
||||
}
|
||||
else
|
||||
{
|
||||
if( (l->pNext=(sLibrary *)malloc(sizeof(sLibrary)))==NULL )
|
||||
} else {
|
||||
if ((l->pNext =
|
||||
(sLibrary *) malloc(sizeof(sLibrary))) ==
|
||||
NULL)
|
||||
fatalerror("Out of memory");
|
||||
l = l->pNext;
|
||||
}
|
||||
|
||||
size -= file_ReadASCIIz(l->tName, f);
|
||||
l->uwTime=file_ReadWord( f ); size-=2;
|
||||
l->uwDate=file_ReadWord( f ); size-=2;
|
||||
l->nByteLength=file_ReadLong( f ); size-=4;
|
||||
if( l->pData=(UBYTE *)malloc(l->nByteLength) )
|
||||
{
|
||||
fread( l->pData, sizeof(UBYTE), l->nByteLength, f );
|
||||
l->uwTime = file_ReadWord(f);
|
||||
size -= 2;
|
||||
l->uwDate = file_ReadWord(f);
|
||||
size -= 2;
|
||||
l->nByteLength = file_ReadLong(f);
|
||||
size -= 4;
|
||||
if (l->pData = (UBYTE *) malloc(l->nByteLength)) {
|
||||
fread(l->pData, sizeof(UBYTE), l->nByteLength,
|
||||
f);
|
||||
size -= l->nByteLength;
|
||||
}
|
||||
else
|
||||
} else
|
||||
fatalerror("Out of memory");
|
||||
|
||||
l->pNext = NULL;
|
||||
@@ -120,14 +119,12 @@ sLibrary *lib_Read( char *filename )
|
||||
{
|
||||
FILE *f;
|
||||
|
||||
if( f=fopen(filename,"rb") )
|
||||
{
|
||||
if (f = fopen(filename, "rb")) {
|
||||
SLONG size;
|
||||
char ID[5];
|
||||
|
||||
size = file_Length(f);
|
||||
if( size==0 )
|
||||
{
|
||||
if (size == 0) {
|
||||
fclose(f);
|
||||
return (NULL);
|
||||
}
|
||||
@@ -136,25 +133,22 @@ sLibrary *lib_Read( char *filename )
|
||||
ID[4] = 0;
|
||||
size -= 4;
|
||||
|
||||
if( strcmp(ID,"XLB0")==0 )
|
||||
{
|
||||
if (strcmp(ID, "XLB0") == 0) {
|
||||
sLibrary *r;
|
||||
|
||||
r = lib_ReadLib0(f, size);
|
||||
fclose(f);
|
||||
printf("Library '%s' opened\n", filename);
|
||||
return (r);
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
fclose(f);
|
||||
fatalerror("Not a valid xLib library");
|
||||
return (NULL);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
printf( "Library '%s' not found, it will be created if necessary\n", filename );
|
||||
} else {
|
||||
printf
|
||||
("Library '%s' not found, it will be created if necessary\n",
|
||||
filename);
|
||||
return (NULL);
|
||||
}
|
||||
}
|
||||
@@ -163,11 +157,9 @@ BBOOL lib_Write( sLibrary *lib, char *filename )
|
||||
{
|
||||
FILE *f;
|
||||
|
||||
if( f=fopen(filename,"wb") )
|
||||
{
|
||||
if (f = fopen(filename, "wb")) {
|
||||
fwrite("XLB0", sizeof(char), 4, f);
|
||||
while( lib )
|
||||
{
|
||||
while (lib) {
|
||||
file_WriteASCIIz(lib->tName, f);
|
||||
file_WriteWord(lib->uwTime, f);
|
||||
file_WriteWord(lib->uwDate, f);
|
||||
@@ -201,8 +193,7 @@ sLibrary *lib_Find( sLibrary *lib, char *filename )
|
||||
|
||||
TruncateFileName(truncname, filename);
|
||||
|
||||
while( lib )
|
||||
{
|
||||
while (lib) {
|
||||
if (strcmp(lib->tName, truncname) == 0)
|
||||
break;
|
||||
|
||||
@@ -216,34 +207,28 @@ sLibrary *lib_AddReplace( sLibrary *lib, char *filename )
|
||||
{
|
||||
FILE *f;
|
||||
|
||||
if( f=fopen(filename,"rb") )
|
||||
{
|
||||
if (f = fopen(filename, "rb")) {
|
||||
sLibrary *module;
|
||||
char truncname[MAXNAMELENGTH];
|
||||
|
||||
TruncateFileName(truncname, filename);
|
||||
|
||||
if( (module=lib_Find(lib,filename))==NULL )
|
||||
{
|
||||
if( module=(sLibrary *)malloc(sizeof(sLibrary)) )
|
||||
{
|
||||
if ((module = lib_Find(lib, filename)) == NULL) {
|
||||
if (module = (sLibrary *) malloc(sizeof(sLibrary))) {
|
||||
module->pNext = lib;
|
||||
lib = module;
|
||||
}
|
||||
else
|
||||
} else
|
||||
fatalerror("Out of memory");
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
/* Module already exists */
|
||||
free(module->pData);
|
||||
}
|
||||
|
||||
module->nByteLength = file_Length(f);
|
||||
strcpy(module->tName, truncname);
|
||||
if( module->pData=(UBYTE *)malloc(module->nByteLength) )
|
||||
{
|
||||
fread( module->pData, sizeof(UBYTE), module->nByteLength, f );
|
||||
if (module->pData = (UBYTE *) malloc(module->nByteLength)) {
|
||||
fread(module->pData, sizeof(UBYTE), module->nByteLength,
|
||||
f);
|
||||
}
|
||||
|
||||
printf("Added module '%s'\n", truncname);
|
||||
@@ -257,18 +242,15 @@ sLibrary *lib_AddReplace( sLibrary *lib, char *filename )
|
||||
sLibrary *lib_DeleteModule(sLibrary * lib, char *filename)
|
||||
{
|
||||
char truncname[MAXNAMELENGTH];
|
||||
sLibrary **pp,
|
||||
**first;
|
||||
sLibrary **pp, **first;
|
||||
BBOOL found = 0;
|
||||
|
||||
pp = &lib;
|
||||
first = pp;
|
||||
|
||||
TruncateFileName(truncname, filename);
|
||||
while( (*pp) && (!found) )
|
||||
{
|
||||
if( strcmp((*pp)->tName,truncname)==0 )
|
||||
{
|
||||
while ((*pp) && (!found)) {
|
||||
if (strcmp((*pp)->tName, truncname) == 0) {
|
||||
sLibrary *t;
|
||||
|
||||
t = *pp;
|
||||
@@ -294,8 +276,7 @@ sLibrary *lib_DeleteModule( sLibrary *lib, char *filename )
|
||||
|
||||
void lib_Free(sLibrary * lib)
|
||||
{
|
||||
while( lib )
|
||||
{
|
||||
while (lib) {
|
||||
sLibrary *l;
|
||||
|
||||
if (lib->pData)
|
||||
|
||||
@@ -52,24 +52,20 @@ int main( int argc, char *argv[] )
|
||||
argc -= 1;
|
||||
argn += 1;
|
||||
|
||||
if( argc>=2 )
|
||||
{
|
||||
if (argc >= 2) {
|
||||
UBYTE command;
|
||||
sLibrary *lib;
|
||||
|
||||
lib = lib_Read(libname = argv[argn++]);
|
||||
argc -= 1;
|
||||
|
||||
if( strlen(argv[argn])==1 )
|
||||
{
|
||||
if (strlen(argv[argn]) == 1) {
|
||||
command = argv[argn++][0];
|
||||
argc -= 1;
|
||||
|
||||
switch( tolower(command) )
|
||||
{
|
||||
switch (tolower(command)) {
|
||||
case 'a':
|
||||
while( argc )
|
||||
{
|
||||
while (argc) {
|
||||
lib = lib_AddReplace(lib, argv[argn++]);
|
||||
argc -= 1;
|
||||
}
|
||||
@@ -77,9 +73,9 @@ int main( int argc, char *argv[] )
|
||||
lib_Free(lib);
|
||||
break;
|
||||
case 'd':
|
||||
while( argc )
|
||||
{
|
||||
lib=lib_DeleteModule( lib, argv[argn++] );
|
||||
while (argc) {
|
||||
lib =
|
||||
lib_DeleteModule(lib, argv[argn++]);
|
||||
argc -= 1;
|
||||
}
|
||||
lib_Write(lib, libname);
|
||||
@@ -91,33 +87,35 @@ int main( int argc, char *argv[] )
|
||||
|
||||
l = lib;
|
||||
|
||||
while( l )
|
||||
{
|
||||
printf( "%10d %s\n", l->nByteLength, l->tName );
|
||||
while (l) {
|
||||
printf("%10d %s\n",
|
||||
l->nByteLength,
|
||||
l->tName);
|
||||
l = l->pNext;
|
||||
}
|
||||
}
|
||||
break;
|
||||
case 'x':
|
||||
while( argc )
|
||||
{
|
||||
while (argc) {
|
||||
sLibrary *l;
|
||||
|
||||
l = lib_Find(lib, argv[argn]);
|
||||
if( l )
|
||||
{
|
||||
if (l) {
|
||||
FILE *f;
|
||||
|
||||
if( f=fopen(argv[argn],"wb") )
|
||||
{
|
||||
fwrite( l->pData, sizeof(UBYTE), l->nByteLength, f );
|
||||
if (f = fopen(argv[argn], "wb")) {
|
||||
fwrite(l->pData,
|
||||
sizeof(UBYTE),
|
||||
l->nByteLength,
|
||||
f);
|
||||
fclose(f);
|
||||
printf( "Extracted module '%s'\n", argv[argn] );
|
||||
}
|
||||
else
|
||||
fatalerror( "Unable to write module" );
|
||||
}
|
||||
else
|
||||
printf
|
||||
("Extracted module '%s'\n",
|
||||
argv[argn]);
|
||||
} else
|
||||
fatalerror
|
||||
("Unable to write module");
|
||||
} else
|
||||
fatalerror("Module not found");
|
||||
|
||||
argn += 1;
|
||||
@@ -130,13 +128,10 @@ int main( int argc, char *argv[] )
|
||||
break;
|
||||
}
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
fatalerror("Invalid command");
|
||||
}
|
||||
}
|
||||
else
|
||||
} else
|
||||
PrintUsage();
|
||||
|
||||
return (0);
|
||||
|
||||
@@ -5,8 +5,7 @@
|
||||
#include "symbol.h"
|
||||
#include "assign.h"
|
||||
|
||||
struct sFreeArea
|
||||
{
|
||||
struct sFreeArea {
|
||||
SLONG nOrg;
|
||||
SLONG nSize;
|
||||
struct sFreeArea *pPrev, *pNext;
|
||||
@@ -26,8 +25,7 @@ SLONG area_Avail( SLONG bank )
|
||||
r = 0;
|
||||
pArea = BankFree[bank];
|
||||
|
||||
while( pArea )
|
||||
{
|
||||
while (pArea) {
|
||||
r += pArea->nSize;
|
||||
pArea = pArea->pNext;
|
||||
}
|
||||
@@ -40,39 +38,36 @@ SLONG area_AllocAbs( struct sFreeArea **ppArea, SLONG org, SLONG size )
|
||||
struct sFreeArea *pArea;
|
||||
|
||||
pArea = *ppArea;
|
||||
while( pArea )
|
||||
{
|
||||
if( org>=pArea->nOrg && (org+size-1)<=(pArea->nOrg+pArea->nSize-1) )
|
||||
{
|
||||
if( org==pArea->nOrg )
|
||||
{
|
||||
while (pArea) {
|
||||
if (org >= pArea->nOrg
|
||||
&& (org + size - 1) <= (pArea->nOrg + pArea->nSize - 1)) {
|
||||
if (org == pArea->nOrg) {
|
||||
pArea->nOrg += size;
|
||||
pArea->nSize -= size;
|
||||
return (org);
|
||||
}
|
||||
else
|
||||
{
|
||||
if( (org+size-1)==(pArea->nOrg+pArea->nSize-1) )
|
||||
{
|
||||
} else {
|
||||
if ((org + size - 1) ==
|
||||
(pArea->nOrg + pArea->nSize - 1)) {
|
||||
pArea->nSize -= size;
|
||||
return (org);
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
struct sFreeArea *pNewArea;
|
||||
|
||||
if( (pNewArea=(struct sFreeArea *)malloc(sizeof(struct sFreeArea)))!=NULL )
|
||||
{
|
||||
if ((pNewArea =
|
||||
(struct sFreeArea *)
|
||||
malloc(sizeof(struct sFreeArea)))
|
||||
!= NULL) {
|
||||
*pNewArea = *pArea;
|
||||
pNewArea->pPrev = pArea;
|
||||
pArea->pNext = pNewArea;
|
||||
pArea->nSize=org-pArea->nOrg;
|
||||
pArea->nSize =
|
||||
org - pArea->nOrg;
|
||||
pNewArea->nOrg = org + size;
|
||||
pNewArea->nSize-=size+pArea->nSize;
|
||||
pNewArea->nSize -=
|
||||
size + pArea->nSize;
|
||||
|
||||
return (org);
|
||||
}
|
||||
else
|
||||
} else
|
||||
fatalerror("Out of memory!");
|
||||
}
|
||||
}
|
||||
@@ -88,8 +83,7 @@ SLONG area_AllocAbsCODEAnyBank( SLONG org, SLONG size )
|
||||
{
|
||||
SLONG i;
|
||||
|
||||
for( i=1; i<=255; i+=1 )
|
||||
{
|
||||
for (i = 1; i <= 255; i += 1) {
|
||||
if (area_AllocAbs(&BankFree[i], org, size) == org)
|
||||
return (i);
|
||||
}
|
||||
@@ -102,10 +96,8 @@ SLONG area_Alloc( struct sFreeArea **ppArea, SLONG size )
|
||||
struct sFreeArea *pArea;
|
||||
|
||||
pArea = *ppArea;
|
||||
while( pArea )
|
||||
{
|
||||
if( size<=pArea->nSize )
|
||||
{
|
||||
while (pArea) {
|
||||
if (size <= pArea->nSize) {
|
||||
SLONG r;
|
||||
|
||||
r = pArea->nOrg;
|
||||
@@ -125,8 +117,7 @@ SLONG area_AllocCODEAnyBank( SLONG size )
|
||||
{
|
||||
SLONG i, org;
|
||||
|
||||
for( i=1; i<=255; i+=1 )
|
||||
{
|
||||
for (i = 1; i <= 255; i += 1) {
|
||||
if ((org = area_Alloc(&BankFree[i], size)) != -1)
|
||||
return ((i << 16) | org);
|
||||
}
|
||||
@@ -140,12 +131,9 @@ struct sSection *FindLargestCode( void )
|
||||
SLONG nLargest = 0;
|
||||
|
||||
pSection = pSections;
|
||||
while( pSection )
|
||||
{
|
||||
if( pSection->oAssigned==0 && pSection->Type==SECT_CODE )
|
||||
{
|
||||
if( pSection->nByteSize > nLargest )
|
||||
{
|
||||
while (pSection) {
|
||||
if (pSection->oAssigned == 0 && pSection->Type == SECT_CODE) {
|
||||
if (pSection->nByteSize > nLargest) {
|
||||
nLargest = pSection->nByteSize;
|
||||
r = pSection;
|
||||
}
|
||||
@@ -155,23 +143,19 @@ struct sSection *FindLargestCode( void )
|
||||
return (r);
|
||||
}
|
||||
|
||||
|
||||
void AssignCodeSections(void)
|
||||
{
|
||||
struct sSection *pSection;
|
||||
|
||||
while( pSection=FindLargestCode() )
|
||||
{
|
||||
while (pSection = FindLargestCode()) {
|
||||
SLONG org;
|
||||
|
||||
if( (org=area_AllocCODEAnyBank( pSection->nByteSize ))!=-1 )
|
||||
{
|
||||
if ((org = area_AllocCODEAnyBank(pSection->nByteSize)) != -1) {
|
||||
pSection->nOrg = org & 0xFFFF;
|
||||
pSection->nBank = org >> 16;
|
||||
pSection->oAssigned = 1;
|
||||
DOMAXBANK(pSection->nBank);
|
||||
}
|
||||
else
|
||||
} else
|
||||
fatalerror("Unable to place CODE section anywhere");
|
||||
}
|
||||
}
|
||||
@@ -188,65 +172,48 @@ void GBROM_AssignSections( void )
|
||||
*
|
||||
*/
|
||||
|
||||
for( i=0; i<MAXBANKS; i+=1 )
|
||||
{
|
||||
if( BankFree[i]=(struct sFreeArea *)malloc(sizeof(struct sFreeArea)) )
|
||||
{
|
||||
if( i==0 )
|
||||
{
|
||||
for (i = 0; i < MAXBANKS; i += 1) {
|
||||
if (BankFree[i] =
|
||||
(struct sFreeArea *)malloc(sizeof(struct sFreeArea))) {
|
||||
if (i == 0) {
|
||||
BankFree[i]->nOrg = 0x0000;
|
||||
if( options&OPT_SMALL )
|
||||
{
|
||||
if (options & OPT_SMALL) {
|
||||
BankFree[i]->nSize = 0x8000;
|
||||
MaxAvail[i] = 0x8000;
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
BankFree[i]->nSize = 0x4000;
|
||||
MaxAvail[i] = 0x4000;
|
||||
}
|
||||
}
|
||||
else if( i>=1 && i<=255 )
|
||||
{
|
||||
} else if (i >= 1 && i <= 255) {
|
||||
BankFree[i]->nOrg = 0x4000;
|
||||
/*
|
||||
* Now, this shouldn't really be necessary... but for good
|
||||
* measure we'll do it anyway
|
||||
*
|
||||
*/
|
||||
if( options&OPT_SMALL )
|
||||
{
|
||||
if (options & OPT_SMALL) {
|
||||
BankFree[i]->nSize = 0;
|
||||
MaxAvail[i] = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
BankFree[i]->nSize = 0x4000;
|
||||
MaxAvail[i] = 0x4000;
|
||||
}
|
||||
}
|
||||
else if( i==BANK_BSS )
|
||||
{
|
||||
} else if (i == BANK_BSS) {
|
||||
BankFree[i]->nOrg = 0xC000;
|
||||
BankFree[i]->nSize = 0x2000;
|
||||
MaxAvail[i] = 0x2000;
|
||||
}
|
||||
else if( i==BANK_VRAM )
|
||||
{
|
||||
} else if (i == BANK_VRAM) {
|
||||
BankFree[i]->nOrg = 0x8000;
|
||||
BankFree[i]->nSize = 0x2000;
|
||||
MaxAvail[i] = 0x2000;
|
||||
}
|
||||
else if( i==BANK_HRAM )
|
||||
{
|
||||
} else if (i == BANK_HRAM) {
|
||||
BankFree[i]->nOrg = 0xFF80;
|
||||
BankFree[i]->nSize = 0x007F;
|
||||
MaxAvail[i] = 0x007F;
|
||||
}
|
||||
BankFree[i]->pPrev = NULL;
|
||||
BankFree[i]->pNext = NULL;
|
||||
}
|
||||
else
|
||||
} else
|
||||
fatalerror("Out of memory!");
|
||||
}
|
||||
|
||||
@@ -257,53 +224,62 @@ void GBROM_AssignSections( void )
|
||||
*/
|
||||
|
||||
pSection = pSections;
|
||||
while( pSection )
|
||||
{
|
||||
if( (pSection->nOrg!=-1 || pSection->nBank!=-1) && pSection->oAssigned==0 )
|
||||
{
|
||||
while (pSection) {
|
||||
if ((pSection->nOrg != -1 || pSection->nBank != -1)
|
||||
&& pSection->oAssigned == 0) {
|
||||
/* User wants to have a say... */
|
||||
|
||||
switch( pSection->Type )
|
||||
{
|
||||
switch (pSection->Type) {
|
||||
case SECT_BSS:
|
||||
if( area_AllocAbs(&BankFree[BANK_BSS],pSection->nOrg,pSection->nByteSize)!=pSection->nOrg )
|
||||
{
|
||||
sprintf( temptext, "Unable to load fixed BSS section at $%X", pSection->nOrg );
|
||||
if (area_AllocAbs
|
||||
(&BankFree[BANK_BSS], pSection->nOrg,
|
||||
pSection->nByteSize) != pSection->nOrg) {
|
||||
sprintf(temptext,
|
||||
"Unable to load fixed BSS section at $%X",
|
||||
pSection->nOrg);
|
||||
fatalerror(temptext);
|
||||
}
|
||||
pSection->oAssigned = 1;
|
||||
pSection->nBank = BANK_BSS;
|
||||
break;
|
||||
case SECT_HRAM:
|
||||
if( area_AllocAbs(&BankFree[BANK_HRAM],pSection->nOrg,pSection->nByteSize)!=pSection->nOrg )
|
||||
{
|
||||
sprintf( temptext, "Unable to load fixed HRAM section at $%X", pSection->nOrg );
|
||||
if (area_AllocAbs
|
||||
(&BankFree[BANK_HRAM], pSection->nOrg,
|
||||
pSection->nByteSize) != pSection->nOrg) {
|
||||
sprintf(temptext,
|
||||
"Unable to load fixed HRAM section at $%X",
|
||||
pSection->nOrg);
|
||||
fatalerror(temptext);
|
||||
}
|
||||
pSection->oAssigned = 1;
|
||||
pSection->nBank = BANK_HRAM;
|
||||
break;
|
||||
case SECT_VRAM:
|
||||
if( area_AllocAbs(&BankFree[BANK_VRAM],pSection->nOrg,pSection->nByteSize)!=pSection->nOrg )
|
||||
{
|
||||
sprintf( temptext, "Unable to load fixed VRAM section at $%X", pSection->nOrg );
|
||||
if (area_AllocAbs
|
||||
(&BankFree[BANK_VRAM], pSection->nOrg,
|
||||
pSection->nByteSize) != pSection->nOrg) {
|
||||
sprintf(temptext,
|
||||
"Unable to load fixed VRAM section at $%X",
|
||||
pSection->nOrg);
|
||||
fatalerror(temptext);
|
||||
}
|
||||
pSection->oAssigned = 1;
|
||||
pSection->nBank = BANK_VRAM;
|
||||
break;
|
||||
case SECT_HOME:
|
||||
if( area_AllocAbs(&BankFree[BANK_HOME],pSection->nOrg,pSection->nByteSize)!=pSection->nOrg )
|
||||
{
|
||||
sprintf( temptext, "Unable to load fixed HOME section at $%X", pSection->nOrg );
|
||||
if (area_AllocAbs
|
||||
(&BankFree[BANK_HOME], pSection->nOrg,
|
||||
pSection->nByteSize) != pSection->nOrg) {
|
||||
sprintf(temptext,
|
||||
"Unable to load fixed HOME section at $%X",
|
||||
pSection->nOrg);
|
||||
fatalerror(temptext);
|
||||
}
|
||||
pSection->oAssigned = 1;
|
||||
pSection->nBank = BANK_HOME;
|
||||
break;
|
||||
case SECT_CODE:
|
||||
if( pSection->nBank==-1 )
|
||||
{
|
||||
if (pSection->nBank == -1) {
|
||||
/*
|
||||
* User doesn't care which bank, so he must want to
|
||||
* decide which position within that bank.
|
||||
@@ -311,25 +287,20 @@ void GBROM_AssignSections( void )
|
||||
* hardcoded things are allocated
|
||||
*
|
||||
*/
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
/*
|
||||
* User wants to decide which bank we use
|
||||
* Does he care about the position as well?
|
||||
*
|
||||
*/
|
||||
|
||||
if( pSection->nOrg==-1 )
|
||||
{
|
||||
if (pSection->nOrg == -1) {
|
||||
/*
|
||||
* Nope, any position will do
|
||||
* Again, we'll do that later
|
||||
*
|
||||
*/
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
/*
|
||||
* How hardcore can you possibly get? Why does
|
||||
* he even USE this package? Yeah let's just
|
||||
@@ -338,19 +309,34 @@ void GBROM_AssignSections( void )
|
||||
*
|
||||
*/
|
||||
|
||||
if( pSection->nBank>=1 && pSection->nBank<=255 )
|
||||
{
|
||||
if( area_AllocAbs(&BankFree[pSection->nBank],pSection->nOrg,pSection->nByteSize)!=pSection->nOrg )
|
||||
{
|
||||
sprintf( temptext, "Unable to load fixed CODE/DATA section at $%X in bank $%02X", pSection->nOrg, pSection->nBank );
|
||||
fatalerror( temptext );
|
||||
if (pSection->nBank >= 1
|
||||
&& pSection->nBank <= 255) {
|
||||
if (area_AllocAbs
|
||||
(&BankFree
|
||||
[pSection->nBank],
|
||||
pSection->nOrg,
|
||||
pSection->
|
||||
nByteSize) !=
|
||||
pSection->nOrg) {
|
||||
sprintf
|
||||
(temptext,
|
||||
"Unable to load fixed CODE/DATA section at $%X in bank $%02X",
|
||||
pSection->
|
||||
nOrg,
|
||||
pSection->
|
||||
nBank);
|
||||
fatalerror
|
||||
(temptext);
|
||||
}
|
||||
DOMAXBANK(pSection->nBank);
|
||||
DOMAXBANK(pSection->
|
||||
nBank);
|
||||
pSection->oAssigned = 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
sprintf( temptext, "Unable to load fixed CODE/DATA section at $%X in bank $%02X", pSection->nOrg, pSection->nBank );
|
||||
} else {
|
||||
sprintf(temptext,
|
||||
"Unable to load fixed CODE/DATA section at $%X in bank $%02X",
|
||||
pSection->nOrg,
|
||||
pSection->
|
||||
nBank);
|
||||
fatalerror(temptext);
|
||||
}
|
||||
}
|
||||
@@ -368,27 +354,26 @@ void GBROM_AssignSections( void )
|
||||
*/
|
||||
|
||||
pSection = pSections;
|
||||
while( pSection )
|
||||
{
|
||||
while (pSection) {
|
||||
if (pSection->oAssigned == 0
|
||||
&& pSection->Type == SECT_CODE
|
||||
&& pSection->nOrg==-1
|
||||
&& pSection->nBank!=-1 )
|
||||
{
|
||||
&& pSection->nOrg == -1 && pSection->nBank != -1) {
|
||||
/* User wants to have a say... and he's pissed */
|
||||
if( pSection->nBank>=1 && pSection->nBank<=255 )
|
||||
{
|
||||
if( (pSection->nOrg=area_Alloc(&BankFree[pSection->nBank],pSection->nByteSize))==-1 )
|
||||
{
|
||||
sprintf( temptext, "Unable to load fixed CODE/DATA section into bank $%02X", pSection->nBank );
|
||||
if (pSection->nBank >= 1 && pSection->nBank <= 255) {
|
||||
if ((pSection->nOrg =
|
||||
area_Alloc(&BankFree[pSection->nBank],
|
||||
pSection->nByteSize)) == -1) {
|
||||
sprintf(temptext,
|
||||
"Unable to load fixed CODE/DATA section into bank $%02X",
|
||||
pSection->nBank);
|
||||
fatalerror(temptext);
|
||||
}
|
||||
pSection->oAssigned = 1;
|
||||
DOMAXBANK(pSection->nBank);
|
||||
}
|
||||
else
|
||||
{
|
||||
sprintf( temptext, "Unable to load fixed CODE/DATA section into bank $%02X", pSection->nBank );
|
||||
} else {
|
||||
sprintf(temptext,
|
||||
"Unable to load fixed CODE/DATA section into bank $%02X",
|
||||
pSection->nBank);
|
||||
fatalerror(temptext);
|
||||
}
|
||||
}
|
||||
@@ -401,17 +386,18 @@ void GBROM_AssignSections( void )
|
||||
*/
|
||||
|
||||
pSection = pSections;
|
||||
while( pSection )
|
||||
{
|
||||
while (pSection) {
|
||||
if (pSection->oAssigned == 0
|
||||
&& pSection->Type == SECT_CODE
|
||||
&& pSection->nOrg!=-1
|
||||
&& pSection->nBank==-1 )
|
||||
{
|
||||
&& pSection->nOrg != -1 && pSection->nBank == -1) {
|
||||
/* User wants to have a say... and he's back with a vengeance */
|
||||
if( (pSection->nBank=area_AllocAbsCODEAnyBank(pSection->nOrg,pSection->nByteSize))==-1 )
|
||||
{
|
||||
sprintf( temptext, "Unable to load fixed CODE/DATA section at $%X into any bank", pSection->nOrg );
|
||||
if ((pSection->nBank =
|
||||
area_AllocAbsCODEAnyBank(pSection->nOrg,
|
||||
pSection->nByteSize)) ==
|
||||
-1) {
|
||||
sprintf(temptext,
|
||||
"Unable to load fixed CODE/DATA section at $%X into any bank",
|
||||
pSection->nOrg);
|
||||
fatalerror(temptext);
|
||||
}
|
||||
pSection->oAssigned = 1;
|
||||
@@ -427,39 +413,40 @@ void GBROM_AssignSections( void )
|
||||
*/
|
||||
|
||||
pSection = pSections;
|
||||
while( pSection )
|
||||
{
|
||||
if( pSection->oAssigned==0 )
|
||||
{
|
||||
switch( pSection->Type )
|
||||
{
|
||||
while (pSection) {
|
||||
if (pSection->oAssigned == 0) {
|
||||
switch (pSection->Type) {
|
||||
case SECT_BSS:
|
||||
if( (pSection->nOrg=area_Alloc(&BankFree[BANK_BSS],pSection->nByteSize))==-1 )
|
||||
{
|
||||
if ((pSection->nOrg =
|
||||
area_Alloc(&BankFree[BANK_BSS],
|
||||
pSection->nByteSize)) == -1) {
|
||||
fatalerror("BSS section too large\n");
|
||||
}
|
||||
pSection->nBank = BANK_BSS;
|
||||
pSection->oAssigned = 1;
|
||||
break;
|
||||
case SECT_HRAM:
|
||||
if( (pSection->nOrg=area_Alloc(&BankFree[BANK_HRAM],pSection->nByteSize))==-1 )
|
||||
{
|
||||
if ((pSection->nOrg =
|
||||
area_Alloc(&BankFree[BANK_HRAM],
|
||||
pSection->nByteSize)) == -1) {
|
||||
fatalerror("HRAM section too large");
|
||||
}
|
||||
pSection->nBank = BANK_HRAM;
|
||||
pSection->oAssigned = 1;
|
||||
break;
|
||||
case SECT_VRAM:
|
||||
if( (pSection->nOrg=area_Alloc(&BankFree[BANK_VRAM],pSection->nByteSize))==-1 )
|
||||
{
|
||||
if ((pSection->nOrg =
|
||||
area_Alloc(&BankFree[BANK_VRAM],
|
||||
pSection->nByteSize)) == -1) {
|
||||
fatalerror("VRAM section too large");
|
||||
}
|
||||
pSection->nBank = BANK_VRAM;
|
||||
pSection->oAssigned = 1;
|
||||
break;
|
||||
case SECT_HOME:
|
||||
if( (pSection->nOrg=area_Alloc(&BankFree[BANK_HOME],pSection->nByteSize))==-1 )
|
||||
{
|
||||
if ((pSection->nOrg =
|
||||
area_Alloc(&BankFree[BANK_HOME],
|
||||
pSection->nByteSize)) == -1) {
|
||||
fatalerror("HOME section too large");
|
||||
}
|
||||
pSection->nBank = BANK_HOME;
|
||||
@@ -482,8 +469,7 @@ void PSION2_AssignSections( void )
|
||||
{
|
||||
struct sSection *pSection;
|
||||
|
||||
if( BankFree[0]=(struct sFreeArea *)malloc(sizeof(struct sFreeArea)) )
|
||||
{
|
||||
if (BankFree[0] = (struct sFreeArea *)malloc(sizeof(struct sFreeArea))) {
|
||||
BankFree[0]->nOrg = 0x0000;
|
||||
BankFree[0]->nSize = 0x10000;
|
||||
MaxAvail[0] = 0x10000;
|
||||
@@ -491,10 +477,9 @@ void PSION2_AssignSections( void )
|
||||
BankFree[0]->pNext = NULL;
|
||||
|
||||
pSection = pSections;
|
||||
while( pSection )
|
||||
{
|
||||
if( pSection->oAssigned==0 && pSection->Type==SECT_CODE )
|
||||
{
|
||||
while (pSection) {
|
||||
if (pSection->oAssigned == 0
|
||||
&& pSection->Type == SECT_CODE) {
|
||||
pSection->oAssigned = 1;
|
||||
pSection->nBank = 0;
|
||||
pSection->nOrg = BankFree[0]->nOrg;
|
||||
@@ -505,10 +490,9 @@ void PSION2_AssignSections( void )
|
||||
}
|
||||
|
||||
pSection = pSections;
|
||||
while( pSection )
|
||||
{
|
||||
if( pSection->oAssigned==0 && pSection->Type==SECT_BSS )
|
||||
{
|
||||
while (pSection) {
|
||||
if (pSection->oAssigned == 0
|
||||
&& pSection->Type == SECT_BSS) {
|
||||
pSection->oAssigned = 1;
|
||||
pSection->nBank = 0;
|
||||
pSection->nOrg = BankFree[0]->nOrg;
|
||||
@@ -517,15 +501,13 @@ void PSION2_AssignSections( void )
|
||||
}
|
||||
pSection = pSection->pNext;
|
||||
}
|
||||
}
|
||||
else
|
||||
} else
|
||||
fatalerror("Out of memory!");
|
||||
}
|
||||
|
||||
void AssignSections(void)
|
||||
{
|
||||
switch( outputtype )
|
||||
{
|
||||
switch (outputtype) {
|
||||
case OUTPUT_GBROM:
|
||||
GBROM_AssignSections();
|
||||
break;
|
||||
@@ -543,26 +525,26 @@ void CreateSymbolTable( void )
|
||||
|
||||
pSect = pSections;
|
||||
|
||||
while( pSect )
|
||||
{
|
||||
while (pSect) {
|
||||
SLONG i;
|
||||
|
||||
i = pSect->nNumberOfSymbols;
|
||||
|
||||
while( i-- )
|
||||
{
|
||||
while (i--) {
|
||||
if ((pSect->tSymbols[i]->Type == SYM_EXPORT) &&
|
||||
((pSect->tSymbols[i]->pSection == pSect) ||
|
||||
(pSect->tSymbols[i]->pSection==NULL)) )
|
||||
{
|
||||
(pSect->tSymbols[i]->pSection == NULL))) {
|
||||
if (pSect->tSymbols[i]->pSection == NULL)
|
||||
sym_CreateSymbol( pSect->tSymbols[i]->pzName,
|
||||
pSect->tSymbols[i]->nOffset,
|
||||
-1 );
|
||||
sym_CreateSymbol(pSect->tSymbols[i]->
|
||||
pzName,
|
||||
pSect->tSymbols[i]->
|
||||
nOffset, -1);
|
||||
else
|
||||
sym_CreateSymbol( pSect->tSymbols[i]->pzName,
|
||||
pSect->nOrg+pSect->tSymbols[i]->nOffset,
|
||||
pSect->nBank );
|
||||
sym_CreateSymbol(pSect->tSymbols[i]->
|
||||
pzName,
|
||||
pSect->nOrg +
|
||||
pSect->tSymbols[i]->
|
||||
nOffset, pSect->nBank);
|
||||
}
|
||||
}
|
||||
pSect = pSect->pNext;
|
||||
|
||||
@@ -3,8 +3,7 @@
|
||||
|
||||
#include "types.h"
|
||||
|
||||
enum eBankDefine
|
||||
{
|
||||
enum eBankDefine {
|
||||
BANK_HOME = 0,
|
||||
BANK_BSS = 256,
|
||||
BANK_VRAM,
|
||||
|
||||
@@ -9,13 +9,11 @@ extern char temptext[1024];
|
||||
extern SLONG fillchar;
|
||||
extern char smartlinkstartsymbol[256];
|
||||
|
||||
enum eOutputType
|
||||
{
|
||||
enum eOutputType {
|
||||
OUTPUT_GBROM,
|
||||
OUTPUT_PSION2
|
||||
};
|
||||
|
||||
extern enum eOutputType outputtype;
|
||||
|
||||
|
||||
#endif
|
||||
@@ -11,8 +11,7 @@ extern SLONG options;
|
||||
#define OPT_SMALL 0x01
|
||||
#define OPT_SMART_C_LINK 0x02
|
||||
|
||||
enum eRpnData
|
||||
{
|
||||
enum eRpnData {
|
||||
RPN_ADD = 0,
|
||||
RPN_SUB,
|
||||
RPN_MUL,
|
||||
@@ -51,8 +50,7 @@ enum eRpnData
|
||||
RPN_SYM = 0x81
|
||||
};
|
||||
|
||||
enum eSectionType
|
||||
{
|
||||
enum eSectionType {
|
||||
SECT_BSS,
|
||||
SECT_VRAM,
|
||||
SECT_CODE,
|
||||
@@ -60,8 +58,7 @@ enum eSectionType
|
||||
SECT_HRAM
|
||||
};
|
||||
|
||||
struct sSection
|
||||
{
|
||||
struct sSection {
|
||||
SLONG nBank;
|
||||
SLONG nOrg;
|
||||
BBOOL oAssigned;
|
||||
@@ -75,15 +72,13 @@ struct sSection
|
||||
struct sSection *pNext;
|
||||
};
|
||||
|
||||
enum eSymbolType
|
||||
{
|
||||
enum eSymbolType {
|
||||
SYM_LOCAL,
|
||||
SYM_IMPORT,
|
||||
SYM_EXPORT
|
||||
};
|
||||
|
||||
struct sSymbol
|
||||
{
|
||||
struct sSymbol {
|
||||
char *pzName;
|
||||
enum eSymbolType Type;
|
||||
/* the following 3 items only valid when Type!=SYM_IMPORT */
|
||||
@@ -92,8 +87,7 @@ struct sSymbol
|
||||
SLONG nOffset;
|
||||
};
|
||||
|
||||
enum ePatchType
|
||||
{
|
||||
enum ePatchType {
|
||||
PATCH_BYTE = 0,
|
||||
PATCH_WORD_L,
|
||||
PATCH_LONG_L,
|
||||
@@ -101,8 +95,7 @@ enum ePatchType
|
||||
PATCH_LONG_B
|
||||
};
|
||||
|
||||
struct sPatch
|
||||
{
|
||||
struct sPatch {
|
||||
char *pzFilename;
|
||||
SLONG nLineNo;
|
||||
SLONG nOffset;
|
||||
|
||||
@@ -11,17 +11,15 @@ static BBOOL symboldefined( char *name )
|
||||
|
||||
pSect = pSections;
|
||||
|
||||
while( pSect )
|
||||
{
|
||||
while (pSect) {
|
||||
ULONG i;
|
||||
|
||||
for( i=0; i<pSect->nNumberOfSymbols; i+=1 )
|
||||
{
|
||||
for (i = 0; i < pSect->nNumberOfSymbols; i += 1) {
|
||||
if ((pSect->tSymbols[i]->Type == SYM_EXPORT)
|
||||
|| ((pSect->tSymbols[i]->Type == SYM_LOCAL)
|
||||
&& (pSect==pSect->tSymbols[i]->pSection) ) )
|
||||
{
|
||||
if( strcmp(pSect->tSymbols[i]->pzName,name)==0 )
|
||||
&& (pSect == pSect->tSymbols[i]->pSection))) {
|
||||
if (strcmp(pSect->tSymbols[i]->pzName, name) ==
|
||||
0)
|
||||
return (1);
|
||||
}
|
||||
|
||||
@@ -37,18 +35,17 @@ static BBOOL addmodulecontaining( char *name )
|
||||
|
||||
ppLSect = &pLibSections;
|
||||
|
||||
while( *ppLSect )
|
||||
{
|
||||
while (*ppLSect) {
|
||||
ULONG i;
|
||||
|
||||
for( i=0; i<(*ppLSect)->nNumberOfSymbols; i+=1 )
|
||||
{
|
||||
for (i = 0; i < (*ppLSect)->nNumberOfSymbols; i += 1) {
|
||||
if (((*ppLSect)->tSymbols[i]->Type == SYM_EXPORT)
|
||||
|| (((*ppLSect)->tSymbols[i]->Type == SYM_LOCAL)
|
||||
&& ((*ppLSect)==(*ppLSect)->tSymbols[i]->pSection) ) )
|
||||
{
|
||||
if( strcmp((*ppLSect)->tSymbols[i]->pzName,name)==0 )
|
||||
{
|
||||
&& ((*ppLSect) ==
|
||||
(*ppLSect)->tSymbols[i]->pSection))) {
|
||||
if (strcmp
|
||||
((*ppLSect)->tSymbols[i]->pzName,
|
||||
name) == 0) {
|
||||
struct sSection **ppSect;
|
||||
ppSect = &pSections;
|
||||
while (*ppSect)
|
||||
@@ -71,14 +68,12 @@ void AddNeededModules( void )
|
||||
{
|
||||
struct sSection *pSect;
|
||||
|
||||
if( (options&OPT_SMART_C_LINK)==0 )
|
||||
{
|
||||
if ((options & OPT_SMART_C_LINK) == 0) {
|
||||
struct sSection **ppLSect;
|
||||
|
||||
ppLSect = &pLibSections;
|
||||
|
||||
while( *ppLSect )
|
||||
{
|
||||
while (*ppLSect) {
|
||||
struct sSection **ppSect;
|
||||
ppSect = &pSections;
|
||||
while (*ppSect)
|
||||
@@ -93,31 +88,27 @@ void AddNeededModules( void )
|
||||
return;
|
||||
}
|
||||
|
||||
if( options&OPT_SMART_C_LINK )
|
||||
{
|
||||
if( !addmodulecontaining( smartlinkstartsymbol ) )
|
||||
{
|
||||
sprintf( temptext, "Can't find start symbol '%s'", smartlinkstartsymbol );
|
||||
if (options & OPT_SMART_C_LINK) {
|
||||
if (!addmodulecontaining(smartlinkstartsymbol)) {
|
||||
sprintf(temptext, "Can't find start symbol '%s'",
|
||||
smartlinkstartsymbol);
|
||||
fatalerror(temptext);
|
||||
}
|
||||
else
|
||||
printf( "Smart linking with symbol '%s'\n", smartlinkstartsymbol );
|
||||
} else
|
||||
printf("Smart linking with symbol '%s'\n",
|
||||
smartlinkstartsymbol);
|
||||
}
|
||||
|
||||
pSect = pSections;
|
||||
|
||||
while( pSect )
|
||||
{
|
||||
while (pSect) {
|
||||
ULONG i;
|
||||
|
||||
for( i=0; i<pSect->nNumberOfSymbols; i+=1 )
|
||||
{
|
||||
for (i = 0; i < pSect->nNumberOfSymbols; i += 1) {
|
||||
if ((pSect->tSymbols[i]->Type == SYM_IMPORT)
|
||||
|| (pSect->tSymbols[i]->Type==SYM_LOCAL) )
|
||||
{
|
||||
if( !symboldefined(pSect->tSymbols[i]->pzName) )
|
||||
{
|
||||
addmodulecontaining( pSect->tSymbols[i]->pzName );
|
||||
|| (pSect->tSymbols[i]->Type == SYM_LOCAL)) {
|
||||
if (!symboldefined(pSect->tSymbols[i]->pzName)) {
|
||||
addmodulecontaining(pSect->tSymbols[i]->
|
||||
pzName);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -17,8 +17,7 @@
|
||||
#define strcmpi strcasecmp
|
||||
#endif
|
||||
|
||||
enum eBlockType
|
||||
{
|
||||
enum eBlockType {
|
||||
BLOCK_COMMENT,
|
||||
BLOCK_OBJECTS,
|
||||
BLOCK_LIBRARIES,
|
||||
@@ -49,16 +48,15 @@ void fatalerror( char *s )
|
||||
|
||||
void PrintUsage(void)
|
||||
{
|
||||
printf( "xLink v" LINK_VERSION " (part of ASMotor " ASMOTOR_VERSION ")\n\n"
|
||||
"Usage: xlink [options] linkfile\n"
|
||||
printf("xLink v" LINK_VERSION " (part of ASMotor " ASMOTOR_VERSION
|
||||
")\n\n" "Usage: xlink [options] linkfile\n"
|
||||
"Options:\n\t-h\t\tThis text\n"
|
||||
"\t-m<mapfile>\tWrite a mapfile\n"
|
||||
"\t-n<symfile>\tWrite a NO$GMB compatible symfile\n"
|
||||
"\t-z<hx>\t\tSet the byte value (hex format) used for uninitialised\n"
|
||||
"\t\t\tdata (default is ? for random)\n"
|
||||
"\t-s<symbol>\tPerform smart linking starting with <symbol>\n"
|
||||
"\t-t\t\tOutput target\n"
|
||||
"\t\t-tg\tGameboy ROM image(default)\n"
|
||||
"\t-t\t\tOutput target\n" "\t\t-tg\tGameboy ROM image(default)\n"
|
||||
"\t\t-ts\tGameboy small mode (32kB)\n"
|
||||
"\t\t-tp\tPsion2 reloc module\n");
|
||||
exit(0);
|
||||
@@ -74,36 +72,34 @@ void ProcessLinkfile( char *tzLinkfile )
|
||||
FILE *pLinkfile;
|
||||
enum eBlockType CurrentBlock = BLOCK_COMMENT;
|
||||
|
||||
if( pLinkfile=fopen(tzLinkfile,"rt") )
|
||||
{
|
||||
while( !feof(pLinkfile) )
|
||||
{
|
||||
if (pLinkfile = fopen(tzLinkfile, "rt")) {
|
||||
while (!feof(pLinkfile)) {
|
||||
char tzLine[256];
|
||||
|
||||
fscanf(pLinkfile, "%s\n", tzLine);
|
||||
if( tzLine[0]!='#' )
|
||||
{
|
||||
if( tzLine[0]=='[' && tzLine[strlen(tzLine)-1]==']' )
|
||||
{
|
||||
if (tzLine[0] != '#') {
|
||||
if (tzLine[0] == '['
|
||||
&& tzLine[strlen(tzLine) - 1] == ']') {
|
||||
if (strcmpi("[objects]", tzLine) == 0)
|
||||
CurrentBlock = BLOCK_OBJECTS;
|
||||
else if( strcmpi("[output]",tzLine)==0 )
|
||||
else if (strcmpi("[output]", tzLine) ==
|
||||
0)
|
||||
CurrentBlock = BLOCK_OUTPUT;
|
||||
else if( strcmpi("[libraries]",tzLine)==0 )
|
||||
else if (strcmpi("[libraries]", tzLine)
|
||||
== 0)
|
||||
CurrentBlock = BLOCK_LIBRARIES;
|
||||
else if( strcmpi("[comment]",tzLine)==0 )
|
||||
else if (strcmpi("[comment]", tzLine) ==
|
||||
0)
|
||||
CurrentBlock = BLOCK_COMMENT;
|
||||
else
|
||||
{
|
||||
else {
|
||||
fclose(pLinkfile);
|
||||
sprintf( temptext, "Unknown block '%s'\n", tzLine );
|
||||
sprintf(temptext,
|
||||
"Unknown block '%s'\n",
|
||||
tzLine);
|
||||
fatalerror(temptext);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
switch( CurrentBlock )
|
||||
{
|
||||
} else {
|
||||
switch (CurrentBlock) {
|
||||
case BLOCK_COMMENT:
|
||||
break;
|
||||
case BLOCK_OBJECTS:
|
||||
@@ -120,9 +116,7 @@ void ProcessLinkfile( char *tzLinkfile )
|
||||
}
|
||||
}
|
||||
fclose(pLinkfile);
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
sprintf(temptext, "Unable to find linkfile '%s'\n", tzLinkfile);
|
||||
fatalerror(temptext);
|
||||
}
|
||||
@@ -144,12 +138,10 @@ int main( int argc, char *argv[] )
|
||||
if (argc == 0)
|
||||
PrintUsage();
|
||||
|
||||
while( *argv[argn]=='-' )
|
||||
{
|
||||
while (*argv[argn] == '-') {
|
||||
char opt;
|
||||
argc -= 1;
|
||||
switch( opt=argv[argn++][1] )
|
||||
{
|
||||
switch (opt = argv[argn++][1]) {
|
||||
case '?':
|
||||
case 'h':
|
||||
PrintUsage();
|
||||
@@ -161,8 +153,7 @@ int main( int argc, char *argv[] )
|
||||
SetSymfileName(argv[argn - 1] + 2);
|
||||
break;
|
||||
case 't':
|
||||
switch( opt=argv[argn-1][2] )
|
||||
{
|
||||
switch (opt = argv[argn - 1][2]) {
|
||||
case 'g':
|
||||
outputtype = OUTPUT_GBROM;
|
||||
break;
|
||||
@@ -174,31 +165,28 @@ int main( int argc, char *argv[] )
|
||||
outputtype = OUTPUT_PSION2;
|
||||
break;
|
||||
default:
|
||||
sprintf( temptext, "Unknown option 't%c'\n", opt );
|
||||
sprintf(temptext, "Unknown option 't%c'\n",
|
||||
opt);
|
||||
fatalerror(temptext);
|
||||
break;
|
||||
}
|
||||
break;
|
||||
case 'z':
|
||||
if( strlen(argv[argn-1]+2)<=2 )
|
||||
{
|
||||
if( strcmp(argv[argn-1]+2,"?")==0 )
|
||||
{
|
||||
if (strlen(argv[argn - 1] + 2) <= 2) {
|
||||
if (strcmp(argv[argn - 1] + 2, "?") == 0) {
|
||||
fillchar = -1;
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
int result;
|
||||
|
||||
result=sscanf( argv[argn-1]+2, "%x", &fillchar );
|
||||
if( !((result==EOF) || (result==1)) )
|
||||
{
|
||||
fatalerror("Invalid argument for option 'z'\n" );
|
||||
result =
|
||||
sscanf(argv[argn - 1] + 2, "%x",
|
||||
&fillchar);
|
||||
if (!((result == EOF) || (result == 1))) {
|
||||
fatalerror
|
||||
("Invalid argument for option 'z'\n");
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
fatalerror("Invalid argument for option 'z'\n");
|
||||
}
|
||||
break;
|
||||
@@ -213,8 +201,7 @@ int main( int argc, char *argv[] )
|
||||
}
|
||||
}
|
||||
|
||||
if( argc==1 )
|
||||
{
|
||||
if (argc == 1) {
|
||||
ProcessLinkfile(argv[argn++]);
|
||||
AddNeededModules();
|
||||
AssignSections();
|
||||
@@ -222,8 +209,7 @@ int main( int argc, char *argv[] )
|
||||
Patch();
|
||||
Output();
|
||||
CloseMapfile();
|
||||
}
|
||||
else
|
||||
} else
|
||||
PrintUsage();
|
||||
|
||||
return (0);
|
||||
|
||||
@@ -22,24 +22,20 @@ void SetMapfileName( char *name )
|
||||
|
||||
void SetSymfileName(char *name)
|
||||
{
|
||||
if( sf=fopen(name,"wt") )
|
||||
{
|
||||
if (sf = fopen(name, "wt")) {
|
||||
fprintf(sf, ";File generated by xLink v" LINK_VERSION "\n\n");
|
||||
return;
|
||||
}
|
||||
else
|
||||
} else
|
||||
fatalerror("Unable to open symfile for writing");
|
||||
}
|
||||
|
||||
void CloseMapfile(void)
|
||||
{
|
||||
if( mf )
|
||||
{
|
||||
if (mf) {
|
||||
fclose(mf);
|
||||
mf = NULL;
|
||||
}
|
||||
if( sf )
|
||||
{
|
||||
if (sf) {
|
||||
fclose(sf);
|
||||
sf = NULL;
|
||||
}
|
||||
@@ -47,8 +43,7 @@ void CloseMapfile( void )
|
||||
|
||||
void MapfileInitBank(SLONG bank)
|
||||
{
|
||||
if( mf )
|
||||
{
|
||||
if (mf) {
|
||||
currentbank = bank;
|
||||
if (bank == 0)
|
||||
fprintf(mf, "Bank #0 (HOME):\n");
|
||||
@@ -62,33 +57,34 @@ void MapfileInitBank( SLONG bank )
|
||||
fprintf(mf, "VRAM:\n");
|
||||
}
|
||||
|
||||
if( sf )
|
||||
{
|
||||
if (sf) {
|
||||
sfbank = (bank >= 1 && bank <= 255) ? bank : 0;
|
||||
}
|
||||
}
|
||||
|
||||
void MapfileWriteSection(struct sSection *pSect)
|
||||
{
|
||||
if( mf || sf )
|
||||
{
|
||||
if (mf || sf) {
|
||||
SLONG i;
|
||||
|
||||
fprintf( mf, " SECTION: $%04X-$%04X ($%04X bytes)\n", pSect->nOrg, pSect->nOrg+pSect->nByteSize-1, pSect->nByteSize );
|
||||
fprintf(mf, " SECTION: $%04X-$%04X ($%04X bytes)\n",
|
||||
pSect->nOrg, pSect->nOrg + pSect->nByteSize - 1,
|
||||
pSect->nByteSize);
|
||||
|
||||
for( i=0; i<pSect->nNumberOfSymbols; i+=1 )
|
||||
{
|
||||
for (i = 0; i < pSect->nNumberOfSymbols; i += 1) {
|
||||
struct sSymbol *pSym;
|
||||
pSym = pSect->tSymbols[i];
|
||||
if( (pSym->pSection==pSect) && (pSym->Type!=SYM_IMPORT) )
|
||||
{
|
||||
if( mf )
|
||||
{
|
||||
fprintf( mf, " $%04X = %s\n", pSym->nOffset+pSect->nOrg, pSym->pzName );
|
||||
if ((pSym->pSection == pSect)
|
||||
&& (pSym->Type != SYM_IMPORT)) {
|
||||
if (mf) {
|
||||
fprintf(mf, " $%04X = %s\n",
|
||||
pSym->nOffset + pSect->nOrg,
|
||||
pSym->pzName);
|
||||
}
|
||||
if( sf )
|
||||
{
|
||||
fprintf( sf, "%02X:%04X %s\n", sfbank, pSym->nOffset+pSect->nOrg, pSym->pzName );
|
||||
if (sf) {
|
||||
fprintf(sf, "%02X:%04X %s\n", sfbank,
|
||||
pSym->nOffset + pSect->nOrg,
|
||||
pSym->pzName);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -98,8 +94,7 @@ void MapfileWriteSection( struct sSection *pSect )
|
||||
|
||||
void MapfileCloseBank(SLONG slack)
|
||||
{
|
||||
if( mf )
|
||||
{
|
||||
if (mf) {
|
||||
if (slack == MaxAvail[currentbank])
|
||||
fprintf(mf, " EMPTY\n\n");
|
||||
else
|
||||
|
||||
@@ -16,7 +16,6 @@ struct sSection *pLibSections=NULL;
|
||||
UBYTE dummymem;
|
||||
BBOOL oReadLib = 0;
|
||||
|
||||
|
||||
/*
|
||||
* The usual byte order stuff
|
||||
*
|
||||
@@ -59,7 +58,6 @@ SLONG readasciiz( char *s, FILE *f )
|
||||
return (r + 1);
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Allocate a new section and link it into the list
|
||||
*
|
||||
@@ -77,16 +75,13 @@ struct sSection *AllocSection( void )
|
||||
while (*ppSections)
|
||||
ppSections = &((*ppSections)->pNext);
|
||||
|
||||
if( (*ppSections)=(struct sSection *)malloc(sizeof(struct sSection)) )
|
||||
{
|
||||
if ((*ppSections) = (struct sSection *)malloc(sizeof(struct sSection))) {
|
||||
(*ppSections)->tSymbols = tSymbols;
|
||||
(*ppSections)->pNext = NULL;
|
||||
(*ppSections)->pPatches = NULL;
|
||||
(*ppSections)->oAssigned = 0;
|
||||
return (*ppSections);
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
fatalerror("Out of memory!");
|
||||
return (NULL);
|
||||
}
|
||||
@@ -102,23 +97,19 @@ struct sSymbol *obj_ReadSymbol( FILE *f )
|
||||
char s[256];
|
||||
struct sSymbol *pSym;
|
||||
|
||||
if( pSym=(struct sSymbol *)malloc(sizeof(struct sSymbol)) )
|
||||
{
|
||||
if (pSym = (struct sSymbol *)malloc(sizeof(struct sSymbol))) {
|
||||
readasciiz(s, f);
|
||||
if( pSym->pzName=(char *)malloc(strlen(s)+1) )
|
||||
{
|
||||
if (pSym->pzName = (char *)malloc(strlen(s) + 1)) {
|
||||
strcpy(pSym->pzName, s);
|
||||
if( (pSym->Type=(enum eSymbolType)fgetc(f))!=SYM_IMPORT )
|
||||
{
|
||||
if ((pSym->Type =
|
||||
(enum eSymbolType)fgetc(f)) != SYM_IMPORT) {
|
||||
pSym->nSectionID = readlong(f);
|
||||
pSym->nOffset = readlong(f);
|
||||
}
|
||||
return (pSym);
|
||||
}
|
||||
else
|
||||
} else
|
||||
fatalerror("Out of memory!");
|
||||
}
|
||||
else
|
||||
} else
|
||||
fatalerror("Out of memory!");
|
||||
|
||||
return (NULL);
|
||||
@@ -142,26 +133,24 @@ struct sSection *obj_ReadRGB0Section( FILE *f )
|
||||
|
||||
/* does the user want the -s mode? */
|
||||
|
||||
if( (options&OPT_SMALL) && (pSection->Type==SECT_CODE) )
|
||||
{
|
||||
if ((options & OPT_SMALL) && (pSection->Type == SECT_CODE)) {
|
||||
pSection->Type = SECT_HOME;
|
||||
}
|
||||
|
||||
if( (pSection->Type==SECT_CODE) || (pSection->Type==SECT_HOME) )
|
||||
{
|
||||
if ((pSection->Type == SECT_CODE) || (pSection->Type == SECT_HOME)) {
|
||||
/*
|
||||
* These sectiontypes contain data...
|
||||
*
|
||||
*/
|
||||
if( pSection->nByteSize )
|
||||
{
|
||||
if( pSection->pData=(UBYTE *)malloc(pSection->nByteSize) )
|
||||
{
|
||||
if (pSection->nByteSize) {
|
||||
if (pSection->pData =
|
||||
(UBYTE *) malloc(pSection->nByteSize)) {
|
||||
SLONG nNumberOfPatches;
|
||||
struct sPatch **ppPatch, *pPatch;
|
||||
char s[256];
|
||||
|
||||
fread( pSection->pData, sizeof(UBYTE), pSection->nByteSize, f );
|
||||
fread(pSection->pData, sizeof(UBYTE),
|
||||
pSection->nByteSize, f);
|
||||
nNumberOfPatches = readlong(f);
|
||||
ppPatch = &pSection->pPatches;
|
||||
|
||||
@@ -169,42 +158,58 @@ struct sSection *obj_ReadRGB0Section( FILE *f )
|
||||
* And patches...
|
||||
*
|
||||
*/
|
||||
while( nNumberOfPatches-- )
|
||||
{
|
||||
if( pPatch=(struct sPatch *)malloc(sizeof(struct sPatch)) )
|
||||
{
|
||||
while (nNumberOfPatches--) {
|
||||
if (pPatch =
|
||||
(struct sPatch *)
|
||||
malloc(sizeof(struct sPatch))) {
|
||||
*ppPatch = pPatch;
|
||||
readasciiz(s, f);
|
||||
if( pPatch->pzFilename=(char *)malloc(strlen(s)+1) )
|
||||
{
|
||||
strcpy( pPatch->pzFilename, s );
|
||||
pPatch->nLineNo=readlong( f );
|
||||
pPatch->nOffset=readlong( f );
|
||||
pPatch->Type=(enum ePatchType)fgetc( f );
|
||||
if( (pPatch->nRPNSize=readlong(f))>0 )
|
||||
{
|
||||
if( pPatch->pRPN=(UBYTE *)malloc(pPatch->nRPNSize) )
|
||||
fread( pPatch->pRPN, sizeof(UBYTE), pPatch->nRPNSize, f );
|
||||
if (pPatch->pzFilename =
|
||||
(char *)malloc(strlen(s) +
|
||||
1)) {
|
||||
strcpy(pPatch->
|
||||
pzFilename, s);
|
||||
pPatch->nLineNo =
|
||||
readlong(f);
|
||||
pPatch->nOffset =
|
||||
readlong(f);
|
||||
pPatch->Type =
|
||||
(enum ePatchType)
|
||||
fgetc(f);
|
||||
if ((pPatch->nRPNSize =
|
||||
readlong(f)) > 0) {
|
||||
if (pPatch->
|
||||
pRPN =
|
||||
(UBYTE *)
|
||||
malloc
|
||||
(pPatch->
|
||||
nRPNSize))
|
||||
fread
|
||||
(pPatch->
|
||||
pRPN,
|
||||
sizeof
|
||||
(UBYTE),
|
||||
pPatch->
|
||||
nRPNSize,
|
||||
f);
|
||||
else
|
||||
fatalerror( "Out of memory!" );
|
||||
}
|
||||
else
|
||||
pPatch->pRPN=NULL;
|
||||
fatalerror
|
||||
("Out of memory!");
|
||||
} else
|
||||
pPatch->pRPN =
|
||||
NULL;
|
||||
pPatch->pNext = NULL;
|
||||
ppPatch=&(pPatch->pNext);
|
||||
}
|
||||
else
|
||||
ppPatch =
|
||||
&(pPatch->pNext);
|
||||
} else
|
||||
fatalerror
|
||||
("Out of memory!");
|
||||
} else
|
||||
fatalerror("Out of memory!");
|
||||
}
|
||||
else
|
||||
} else
|
||||
fatalerror("Out of memory!");
|
||||
}
|
||||
}
|
||||
else
|
||||
fatalerror( "Out of memory!" );
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
readlong(f); // Skip number of patches
|
||||
pSection->pData = &dummymem;
|
||||
}
|
||||
@@ -223,24 +228,21 @@ void obj_ReadRGB0( FILE *pObjfile )
|
||||
|
||||
/* First comes the symbols */
|
||||
|
||||
if( nNumberOfSymbols )
|
||||
{
|
||||
if( tSymbols=(struct sSymbol **)malloc(nNumberOfSymbols*sizeof(struct sSymbol *)) )
|
||||
{
|
||||
if (nNumberOfSymbols) {
|
||||
if (tSymbols =
|
||||
(struct sSymbol **)malloc(nNumberOfSymbols *
|
||||
sizeof(struct sSymbol *))) {
|
||||
for (i = 0; i < nNumberOfSymbols; i += 1)
|
||||
tSymbols[i] = obj_ReadSymbol(pObjfile);
|
||||
}
|
||||
else
|
||||
} else
|
||||
fatalerror("Out of memory!");
|
||||
}
|
||||
else
|
||||
} else
|
||||
tSymbols = (struct sSymbol **)&dummymem;
|
||||
|
||||
/* Next we have the sections */
|
||||
|
||||
pFirstSection = NULL;
|
||||
while( nNumberOfSections-- )
|
||||
{
|
||||
while (nNumberOfSections--) {
|
||||
struct sSection *pNewSection;
|
||||
|
||||
pNewSection = obj_ReadRGB0Section(pObjfile);
|
||||
@@ -255,21 +257,18 @@ void obj_ReadRGB0( FILE *pObjfile )
|
||||
*
|
||||
*/
|
||||
|
||||
for( i=0; i<nNumberOfSymbols; i+=1 )
|
||||
{
|
||||
for (i = 0; i < nNumberOfSymbols; i += 1) {
|
||||
struct sSection *pConvSect = pFirstSection;
|
||||
|
||||
if( tSymbols[i]->Type!=SYM_IMPORT && tSymbols[i]->nSectionID!=-1 )
|
||||
{
|
||||
if (tSymbols[i]->Type != SYM_IMPORT
|
||||
&& tSymbols[i]->nSectionID != -1) {
|
||||
SLONG j = 0;
|
||||
while( j != tSymbols[i]->nSectionID )
|
||||
{
|
||||
while (j != tSymbols[i]->nSectionID) {
|
||||
j += 1;
|
||||
pConvSect = pConvSect->pNext;
|
||||
}
|
||||
tSymbols[i]->pSection = pConvSect;
|
||||
}
|
||||
else
|
||||
} else
|
||||
tSymbols[i]->pSection = NULL;
|
||||
}
|
||||
}
|
||||
@@ -297,26 +296,24 @@ struct sSection *obj_ReadRGB1Section( FILE *f )
|
||||
|
||||
/* does the user want the -s mode? */
|
||||
|
||||
if( (options&OPT_SMALL) && (pSection->Type==SECT_CODE) )
|
||||
{
|
||||
if ((options & OPT_SMALL) && (pSection->Type == SECT_CODE)) {
|
||||
pSection->Type = SECT_HOME;
|
||||
}
|
||||
|
||||
if( (pSection->Type==SECT_CODE) || (pSection->Type==SECT_HOME) )
|
||||
{
|
||||
if ((pSection->Type == SECT_CODE) || (pSection->Type == SECT_HOME)) {
|
||||
/*
|
||||
* These sectiontypes contain data...
|
||||
*
|
||||
*/
|
||||
if( pSection->nByteSize )
|
||||
{
|
||||
if( pSection->pData=(UBYTE *)malloc(pSection->nByteSize) )
|
||||
{
|
||||
if (pSection->nByteSize) {
|
||||
if (pSection->pData =
|
||||
(UBYTE *) malloc(pSection->nByteSize)) {
|
||||
SLONG nNumberOfPatches;
|
||||
struct sPatch **ppPatch, *pPatch;
|
||||
char s[256];
|
||||
|
||||
fread( pSection->pData, sizeof(UBYTE), pSection->nByteSize, f );
|
||||
fread(pSection->pData, sizeof(UBYTE),
|
||||
pSection->nByteSize, f);
|
||||
nNumberOfPatches = readlong(f);
|
||||
ppPatch = &pSection->pPatches;
|
||||
|
||||
@@ -324,42 +321,58 @@ struct sSection *obj_ReadRGB1Section( FILE *f )
|
||||
* And patches...
|
||||
*
|
||||
*/
|
||||
while( nNumberOfPatches-- )
|
||||
{
|
||||
if( pPatch=(struct sPatch *)malloc(sizeof(struct sPatch)) )
|
||||
{
|
||||
while (nNumberOfPatches--) {
|
||||
if (pPatch =
|
||||
(struct sPatch *)
|
||||
malloc(sizeof(struct sPatch))) {
|
||||
*ppPatch = pPatch;
|
||||
readasciiz(s, f);
|
||||
if( pPatch->pzFilename=(char *)malloc(strlen(s)+1) )
|
||||
{
|
||||
strcpy( pPatch->pzFilename, s );
|
||||
pPatch->nLineNo=readlong( f );
|
||||
pPatch->nOffset=readlong( f );
|
||||
pPatch->Type=(enum ePatchType)fgetc( f );
|
||||
if( (pPatch->nRPNSize=readlong(f))>0 )
|
||||
{
|
||||
if( pPatch->pRPN=(UBYTE *)malloc(pPatch->nRPNSize) )
|
||||
fread( pPatch->pRPN, sizeof(UBYTE), pPatch->nRPNSize, f );
|
||||
if (pPatch->pzFilename =
|
||||
(char *)malloc(strlen(s) +
|
||||
1)) {
|
||||
strcpy(pPatch->
|
||||
pzFilename, s);
|
||||
pPatch->nLineNo =
|
||||
readlong(f);
|
||||
pPatch->nOffset =
|
||||
readlong(f);
|
||||
pPatch->Type =
|
||||
(enum ePatchType)
|
||||
fgetc(f);
|
||||
if ((pPatch->nRPNSize =
|
||||
readlong(f)) > 0) {
|
||||
if (pPatch->
|
||||
pRPN =
|
||||
(UBYTE *)
|
||||
malloc
|
||||
(pPatch->
|
||||
nRPNSize))
|
||||
fread
|
||||
(pPatch->
|
||||
pRPN,
|
||||
sizeof
|
||||
(UBYTE),
|
||||
pPatch->
|
||||
nRPNSize,
|
||||
f);
|
||||
else
|
||||
fatalerror( "Out of memory!" );
|
||||
}
|
||||
else
|
||||
pPatch->pRPN=NULL;
|
||||
fatalerror
|
||||
("Out of memory!");
|
||||
} else
|
||||
pPatch->pRPN =
|
||||
NULL;
|
||||
pPatch->pNext = NULL;
|
||||
ppPatch=&(pPatch->pNext);
|
||||
}
|
||||
else
|
||||
ppPatch =
|
||||
&(pPatch->pNext);
|
||||
} else
|
||||
fatalerror
|
||||
("Out of memory!");
|
||||
} else
|
||||
fatalerror("Out of memory!");
|
||||
}
|
||||
else
|
||||
} else
|
||||
fatalerror("Out of memory!");
|
||||
}
|
||||
}
|
||||
else
|
||||
fatalerror( "Out of memory!" );
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
readlong(f); // Skip number of patches
|
||||
pSection->pData = &dummymem;
|
||||
}
|
||||
@@ -378,24 +391,21 @@ void obj_ReadRGB1( FILE *pObjfile )
|
||||
|
||||
/* First comes the symbols */
|
||||
|
||||
if( nNumberOfSymbols )
|
||||
{
|
||||
if( tSymbols=(struct sSymbol **)malloc(nNumberOfSymbols*sizeof(struct sSymbol *)) )
|
||||
{
|
||||
if (nNumberOfSymbols) {
|
||||
if (tSymbols =
|
||||
(struct sSymbol **)malloc(nNumberOfSymbols *
|
||||
sizeof(struct sSymbol *))) {
|
||||
for (i = 0; i < nNumberOfSymbols; i += 1)
|
||||
tSymbols[i] = obj_ReadSymbol(pObjfile);
|
||||
}
|
||||
else
|
||||
} else
|
||||
fatalerror("Out of memory!");
|
||||
}
|
||||
else
|
||||
} else
|
||||
tSymbols = (struct sSymbol **)&dummymem;
|
||||
|
||||
/* Next we have the sections */
|
||||
|
||||
pFirstSection = NULL;
|
||||
while( nNumberOfSections-- )
|
||||
{
|
||||
while (nNumberOfSections--) {
|
||||
struct sSection *pNewSection;
|
||||
|
||||
pNewSection = obj_ReadRGB1Section(pObjfile);
|
||||
@@ -410,21 +420,18 @@ void obj_ReadRGB1( FILE *pObjfile )
|
||||
*
|
||||
*/
|
||||
|
||||
for( i=0; i<nNumberOfSymbols; i+=1 )
|
||||
{
|
||||
for (i = 0; i < nNumberOfSymbols; i += 1) {
|
||||
struct sSection *pConvSect = pFirstSection;
|
||||
|
||||
if( tSymbols[i]->Type!=SYM_IMPORT && tSymbols[i]->nSectionID!=-1 )
|
||||
{
|
||||
if (tSymbols[i]->Type != SYM_IMPORT
|
||||
&& tSymbols[i]->nSectionID != -1) {
|
||||
SLONG j = 0;
|
||||
while( j != tSymbols[i]->nSectionID )
|
||||
{
|
||||
while (j != tSymbols[i]->nSectionID) {
|
||||
j += 1;
|
||||
pConvSect = pConvSect->pNext;
|
||||
}
|
||||
tSymbols[i]->pSection = pConvSect;
|
||||
}
|
||||
else
|
||||
} else
|
||||
tSymbols[i]->pSection = NULL;
|
||||
}
|
||||
}
|
||||
@@ -440,10 +447,8 @@ void obj_ReadOpenFile( FILE *pObjfile, char *tzObjectfile )
|
||||
|
||||
fread(tzHeader, sizeof(char), 4, pObjfile);
|
||||
tzHeader[4] = 0;
|
||||
if( strncmp(tzHeader,"RGB", 3)==0 )
|
||||
{
|
||||
switch( tzHeader[3] )
|
||||
{
|
||||
if (strncmp(tzHeader, "RGB", 3) == 0) {
|
||||
switch (tzHeader[3]) {
|
||||
case '0':
|
||||
obj_ReadRGB0(pObjfile);
|
||||
break;
|
||||
@@ -452,13 +457,12 @@ void obj_ReadOpenFile( FILE *pObjfile, char *tzObjectfile )
|
||||
obj_ReadRGB1(pObjfile);
|
||||
break;
|
||||
default:
|
||||
sprintf( temptext, "'%s' is an unsupported version\n", tzObjectfile );
|
||||
sprintf(temptext, "'%s' is an unsupported version\n",
|
||||
tzObjectfile);
|
||||
fatalerror(temptext);
|
||||
break;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
sprintf(temptext, "'%s' is not a valid object\n", tzObjectfile);
|
||||
fatalerror(temptext);
|
||||
}
|
||||
@@ -473,13 +477,10 @@ void obj_Readfile( char *tzObjectfile )
|
||||
else
|
||||
oReadLib = 0;
|
||||
|
||||
if( pObjfile=fopen(tzObjectfile,"rb") )
|
||||
{
|
||||
if (pObjfile = fopen(tzObjectfile, "rb")) {
|
||||
obj_ReadOpenFile(pObjfile, tzObjectfile);
|
||||
fclose(pObjfile);
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
sprintf(temptext, "Unable to open '%s'\n", tzObjectfile);
|
||||
fatalerror(temptext);
|
||||
}
|
||||
@@ -489,8 +490,7 @@ void obj_Readfile( char *tzObjectfile )
|
||||
|
||||
SLONG file_Length(FILE * f)
|
||||
{
|
||||
ULONG r,
|
||||
p;
|
||||
ULONG r, p;
|
||||
|
||||
p = ftell(f);
|
||||
fseek(f, 0, SEEK_END);
|
||||
@@ -505,14 +505,16 @@ void lib_ReadXLB0( FILE *f )
|
||||
SLONG size;
|
||||
|
||||
size = file_Length(f) - 4;
|
||||
while( size )
|
||||
{
|
||||
while (size) {
|
||||
char name[256];
|
||||
|
||||
size -= readasciiz(name, f);
|
||||
readword( f ); size-=2;
|
||||
readword( f ); size-=2;
|
||||
size-=readlong( f ); size-=4;
|
||||
readword(f);
|
||||
size -= 2;
|
||||
readword(f);
|
||||
size -= 2;
|
||||
size -= readlong(f);
|
||||
size -= 4;
|
||||
obj_ReadOpenFile(f, name);
|
||||
}
|
||||
}
|
||||
@@ -523,23 +525,20 @@ void lib_Readfile( char *tzLibfile )
|
||||
|
||||
oReadLib = 1;
|
||||
|
||||
if( pObjfile=fopen(tzLibfile,"rb") )
|
||||
{
|
||||
if (pObjfile = fopen(tzLibfile, "rb")) {
|
||||
char tzHeader[5];
|
||||
|
||||
fread(tzHeader, sizeof(char), 4, pObjfile);
|
||||
tzHeader[4] = 0;
|
||||
if (strcmp(tzHeader, "XLB0") == 0)
|
||||
lib_ReadXLB0(pObjfile);
|
||||
else
|
||||
{
|
||||
sprintf( temptext, "'%s' is an invalid library\n", tzLibfile );
|
||||
else {
|
||||
sprintf(temptext, "'%s' is an invalid library\n",
|
||||
tzLibfile);
|
||||
fatalerror(temptext);
|
||||
}
|
||||
fclose(pObjfile);
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
sprintf(temptext, "Unable to open '%s'\n", tzLibfile);
|
||||
fatalerror(temptext);
|
||||
}
|
||||
|
||||
@@ -15,20 +15,17 @@ void writehome( FILE *f )
|
||||
struct sSection *pSect;
|
||||
UBYTE *mem;
|
||||
|
||||
if( mem=(UBYTE *)malloc(MaxAvail[BANK_HOME]) )
|
||||
{
|
||||
if( fillchar!=-1 )
|
||||
{
|
||||
if (mem = (UBYTE *) malloc(MaxAvail[BANK_HOME])) {
|
||||
if (fillchar != -1) {
|
||||
memset(mem, fillchar, MaxAvail[BANK_HOME]);
|
||||
}
|
||||
MapfileInitBank(0);
|
||||
|
||||
pSect = pSections;
|
||||
while( pSect )
|
||||
{
|
||||
if( pSect->Type==SECT_HOME )
|
||||
{
|
||||
memcpy( mem+pSect->nOrg, pSect->pData, pSect->nByteSize );
|
||||
while (pSect) {
|
||||
if (pSect->Type == SECT_HOME) {
|
||||
memcpy(mem + pSect->nOrg, pSect->pData,
|
||||
pSect->nByteSize);
|
||||
MapfileWriteSection(pSect);
|
||||
}
|
||||
pSect = pSect->pNext;
|
||||
@@ -46,21 +43,18 @@ void writebank( FILE *f, SLONG bank )
|
||||
struct sSection *pSect;
|
||||
UBYTE *mem;
|
||||
|
||||
if( mem=(UBYTE *)malloc(MaxAvail[bank]) )
|
||||
{
|
||||
if( fillchar!=-1 )
|
||||
{
|
||||
if (mem = (UBYTE *) malloc(MaxAvail[bank])) {
|
||||
if (fillchar != -1) {
|
||||
memset(mem, fillchar, MaxAvail[bank]);
|
||||
}
|
||||
|
||||
MapfileInitBank(bank);
|
||||
|
||||
pSect = pSections;
|
||||
while( pSect )
|
||||
{
|
||||
if( pSect->Type==SECT_CODE && pSect->nBank==bank )
|
||||
{
|
||||
memcpy( mem+pSect->nOrg-0x4000, pSect->pData, pSect->nByteSize );
|
||||
while (pSect) {
|
||||
if (pSect->Type == SECT_CODE && pSect->nBank == bank) {
|
||||
memcpy(mem + pSect->nOrg - 0x4000, pSect->pData,
|
||||
pSect->nByteSize);
|
||||
MapfileWriteSection(pSect);
|
||||
}
|
||||
pSect = pSect->pNext;
|
||||
@@ -84,8 +78,7 @@ void GBROM_Output( void )
|
||||
SLONG i;
|
||||
FILE *f;
|
||||
|
||||
if( f=fopen(tzOutname,"wb") )
|
||||
{
|
||||
if (f = fopen(tzOutname, "wb")) {
|
||||
writehome(f);
|
||||
for (i = 1; i <= MaxBankUsed; i += 1)
|
||||
writebank(f, i);
|
||||
@@ -93,15 +86,12 @@ void GBROM_Output( void )
|
||||
fclose(f);
|
||||
}
|
||||
|
||||
for( i=256; i<MAXBANKS; i+=1 )
|
||||
{
|
||||
for (i = 256; i < MAXBANKS; i += 1) {
|
||||
struct sSection *pSect;
|
||||
MapfileInitBank(i);
|
||||
pSect = pSections;
|
||||
while( pSect )
|
||||
{
|
||||
if( pSect->nBank==i )
|
||||
{
|
||||
while (pSect) {
|
||||
if (pSect->nBank == i) {
|
||||
MapfileWriteSection(pSect);
|
||||
}
|
||||
pSect = pSect->pNext;
|
||||
@@ -114,8 +104,7 @@ void PSION2_Output( void )
|
||||
{
|
||||
FILE *f;
|
||||
|
||||
if( f=fopen(tzOutname,"wb") )
|
||||
{
|
||||
if (f = fopen(tzOutname, "wb")) {
|
||||
struct sSection *pSect;
|
||||
UBYTE *mem;
|
||||
ULONG size = MaxAvail[0] - area_Avail(0);
|
||||
@@ -126,21 +115,18 @@ void PSION2_Output( void )
|
||||
fputc(size >> 8, f);
|
||||
fputc(size, f);
|
||||
|
||||
if( mem=(UBYTE *)malloc(MaxAvail[0]-area_Avail(0)) )
|
||||
{
|
||||
if (mem = (UBYTE *) malloc(MaxAvail[0] - area_Avail(0))) {
|
||||
MapfileInitBank(0);
|
||||
|
||||
pSect = pSections;
|
||||
while( pSect )
|
||||
{
|
||||
if( pSect->Type==SECT_CODE )
|
||||
{
|
||||
memcpy( mem+pSect->nOrg, pSect->pData, pSect->nByteSize );
|
||||
while (pSect) {
|
||||
if (pSect->Type == SECT_CODE) {
|
||||
memcpy(mem + pSect->nOrg, pSect->pData,
|
||||
pSect->nByteSize);
|
||||
MapfileWriteSection(pSect);
|
||||
}
|
||||
else
|
||||
{
|
||||
memset( mem+pSect->nOrg, 0, pSect->nByteSize );
|
||||
} else {
|
||||
memset(mem + pSect->nOrg, 0,
|
||||
pSect->nByteSize);
|
||||
}
|
||||
pSect = pSect->pNext;
|
||||
}
|
||||
@@ -153,16 +139,13 @@ void PSION2_Output( void )
|
||||
|
||||
relocpatches = 0;
|
||||
pSect = pSections;
|
||||
while( pSect )
|
||||
{
|
||||
while (pSect) {
|
||||
struct sPatch *pPatch;
|
||||
|
||||
pPatch = pSect->pPatches;
|
||||
|
||||
while( pPatch )
|
||||
{
|
||||
if( pPatch->oRelocPatch )
|
||||
{
|
||||
while (pPatch) {
|
||||
if (pPatch->oRelocPatch) {
|
||||
relocpatches += 1;
|
||||
}
|
||||
pPatch = pPatch->pNext;
|
||||
@@ -176,16 +159,13 @@ void PSION2_Output( void )
|
||||
fputc(relocpatches, f);
|
||||
|
||||
pSect = pSections;
|
||||
while( pSect )
|
||||
{
|
||||
while (pSect) {
|
||||
struct sPatch *pPatch;
|
||||
|
||||
pPatch = pSect->pPatches;
|
||||
|
||||
while( pPatch )
|
||||
{
|
||||
if( pPatch->oRelocPatch )
|
||||
{
|
||||
while (pPatch) {
|
||||
if (pPatch->oRelocPatch) {
|
||||
ULONG address;
|
||||
|
||||
address = pPatch->nOffset + pSect->nOrg;
|
||||
@@ -199,18 +179,14 @@ void PSION2_Output( void )
|
||||
pSect = pSect->pNext;
|
||||
}
|
||||
|
||||
|
||||
|
||||
fclose(f);
|
||||
}
|
||||
}
|
||||
|
||||
void Output(void)
|
||||
{
|
||||
if( oOutput )
|
||||
{
|
||||
switch( outputtype )
|
||||
{
|
||||
if (oOutput) {
|
||||
switch (outputtype) {
|
||||
case OUTPUT_GBROM:
|
||||
GBROM_Output();
|
||||
break;
|
||||
|
||||
124
src/link/patch.c
124
src/link/patch.c
@@ -22,20 +22,22 @@ SLONG rpnpop( void )
|
||||
|
||||
SLONG getsymvalue(SLONG symid)
|
||||
{
|
||||
switch( pCurrentSection->tSymbols[symid]->Type )
|
||||
{
|
||||
switch (pCurrentSection->tSymbols[symid]->Type) {
|
||||
case SYM_IMPORT:
|
||||
return (sym_GetValue(pCurrentSection->tSymbols[symid]->pzName));
|
||||
break;
|
||||
case SYM_EXPORT:
|
||||
case SYM_LOCAL:
|
||||
{
|
||||
if( strcmp(pCurrentSection->tSymbols[symid]->pzName,"@")==0 )
|
||||
{
|
||||
if (strcmp
|
||||
(pCurrentSection->tSymbols[symid]->pzName,
|
||||
"@") == 0) {
|
||||
return (nPC);
|
||||
}
|
||||
else
|
||||
return( pCurrentSection->tSymbols[symid]->nOffset+pCurrentSection->tSymbols[symid]->pSection->nOrg );
|
||||
} else
|
||||
return (pCurrentSection->tSymbols[symid]->
|
||||
nOffset +
|
||||
pCurrentSection->tSymbols[symid]->
|
||||
pSection->nOrg);
|
||||
}
|
||||
default:
|
||||
break;
|
||||
@@ -46,8 +48,7 @@ SLONG getsymvalue( SLONG symid )
|
||||
|
||||
SLONG getsymbank(SLONG symid)
|
||||
{
|
||||
switch( pCurrentSection->tSymbols[symid]->Type )
|
||||
{
|
||||
switch (pCurrentSection->tSymbols[symid]->Type) {
|
||||
case SYM_IMPORT:
|
||||
return (sym_GetBank(pCurrentSection->tSymbols[symid]->pzName));
|
||||
break;
|
||||
@@ -73,11 +74,9 @@ SLONG calcrpn( struct sPatch *pPatch )
|
||||
rpn = pPatch->pRPN;
|
||||
pPatch->oRelocPatch = 0;
|
||||
|
||||
while( size>0 )
|
||||
{
|
||||
while (size > 0) {
|
||||
size -= 1;
|
||||
switch( *rpn++ )
|
||||
{
|
||||
switch (*rpn++) {
|
||||
case RPN_ADD:
|
||||
rpnpush(rpnpop() + rpnpop());
|
||||
break;
|
||||
@@ -153,18 +152,20 @@ SLONG calcrpn( struct sPatch *pPatch )
|
||||
case RPN_HRAM:
|
||||
t = rpnpop();
|
||||
rpnpush(t & 0xFF);
|
||||
if( t<0 || (t>0xFF && t<0xFF00) || t>0xFFFF )
|
||||
{
|
||||
sprintf( temptext, "%s(%d) : Value must be in the HRAM area", pPatch->pzFilename, pPatch->nLineNo );
|
||||
if (t < 0 || (t > 0xFF && t < 0xFF00) || t > 0xFFFF) {
|
||||
sprintf(temptext,
|
||||
"%s(%d) : Value must be in the HRAM area",
|
||||
pPatch->pzFilename, pPatch->nLineNo);
|
||||
fatalerror(temptext);
|
||||
}
|
||||
break;
|
||||
case RPN_PCEZP:
|
||||
t = rpnpop();
|
||||
rpnpush(t & 0xFF);
|
||||
if( t<0x2000 || t>0x20FF )
|
||||
{
|
||||
sprintf( temptext, "%s(%d) : Value must be in the ZP area", pPatch->pzFilename, pPatch->nLineNo );
|
||||
if (t < 0x2000 || t > 0x20FF) {
|
||||
sprintf(temptext,
|
||||
"%s(%d) : Value must be in the ZP area",
|
||||
pPatch->pzFilename, pPatch->nLineNo);
|
||||
fatalerror(temptext);
|
||||
}
|
||||
break;
|
||||
@@ -198,8 +199,7 @@ SLONG calcrpn( struct sPatch *pPatch )
|
||||
break;
|
||||
case RPN_RANGECHECK:
|
||||
{
|
||||
SLONG low,
|
||||
high;
|
||||
SLONG low, high;
|
||||
|
||||
low = (*rpn++);
|
||||
low |= (*rpn++) << 8;
|
||||
@@ -210,9 +210,11 @@ SLONG calcrpn( struct sPatch *pPatch )
|
||||
high |= (*rpn++) << 16;
|
||||
high |= (*rpn++) << 24;
|
||||
t = rpnpop();
|
||||
if( t<low || t>high )
|
||||
{
|
||||
sprintf( temptext, "%s(%d) : Value must be in the range [%d;%d]", pPatch->pzFilename, pPatch->nLineNo, low, high );
|
||||
if (t < low || t > high) {
|
||||
sprintf(temptext,
|
||||
"%s(%d) : Value must be in the range [%d;%d]",
|
||||
pPatch->pzFilename,
|
||||
pPatch->nLineNo, low, high);
|
||||
fatalerror(temptext);
|
||||
}
|
||||
rpnpush(t);
|
||||
@@ -229,65 +231,71 @@ void Patch( void )
|
||||
struct sSection *pSect;
|
||||
|
||||
pSect = pSections;
|
||||
while( pSect )
|
||||
{
|
||||
while (pSect) {
|
||||
struct sPatch *pPatch;
|
||||
|
||||
pCurrentSection = pSect;
|
||||
pPatch = pSect->pPatches;
|
||||
while( pPatch )
|
||||
{
|
||||
while (pPatch) {
|
||||
SLONG t;
|
||||
|
||||
nPC = pSect->nOrg + pPatch->nOffset;
|
||||
t = calcrpn(pPatch);
|
||||
switch( pPatch->Type )
|
||||
{
|
||||
switch (pPatch->Type) {
|
||||
case PATCH_BYTE:
|
||||
if( t>=-128 && t<=255 )
|
||||
{
|
||||
if (t >= -128 && t <= 255) {
|
||||
t &= 0xFF;
|
||||
pSect->pData[pPatch->nOffset]=(UBYTE)t;
|
||||
}
|
||||
else
|
||||
{
|
||||
sprintf( temptext, "%s(%d) : Value must be 8-bit\n", pPatch->pzFilename, pPatch->nLineNo );
|
||||
pSect->pData[pPatch->nOffset] =
|
||||
(UBYTE) t;
|
||||
} else {
|
||||
sprintf(temptext,
|
||||
"%s(%d) : Value must be 8-bit\n",
|
||||
pPatch->pzFilename,
|
||||
pPatch->nLineNo);
|
||||
fatalerror(temptext);
|
||||
}
|
||||
break;
|
||||
case PATCH_WORD_L:
|
||||
case PATCH_WORD_B:
|
||||
if( t>=-32768 && t<=65535 )
|
||||
{
|
||||
if (t >= -32768 && t <= 65535) {
|
||||
t &= 0xFFFF;
|
||||
if( pPatch->Type==PATCH_WORD_L )
|
||||
{
|
||||
pSect->pData[pPatch->nOffset]=t&0xFF;
|
||||
pSect->pData[pPatch->nOffset+1]=(t>>8)&0xFF;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (pPatch->Type == PATCH_WORD_L) {
|
||||
pSect->pData[pPatch->nOffset] =
|
||||
t & 0xFF;
|
||||
pSect->pData[pPatch->nOffset +
|
||||
1] =
|
||||
(t >> 8) & 0xFF;
|
||||
} else {
|
||||
// Assume big endian
|
||||
pSect->pData[pPatch->nOffset]=(t>>8)&0xFF;
|
||||
pSect->pData[pPatch->nOffset+1]=t&0xFF;
|
||||
pSect->pData[pPatch->nOffset] =
|
||||
(t >> 8) & 0xFF;
|
||||
pSect->pData[pPatch->nOffset +
|
||||
1] = t & 0xFF;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
sprintf( temptext, "%s(%d) : Value must be 16-bit\n", pPatch->pzFilename, pPatch->nLineNo );
|
||||
} else {
|
||||
sprintf(temptext,
|
||||
"%s(%d) : Value must be 16-bit\n",
|
||||
pPatch->pzFilename,
|
||||
pPatch->nLineNo);
|
||||
fatalerror(temptext);
|
||||
}
|
||||
break;
|
||||
case PATCH_LONG_L:
|
||||
pSect->pData[pPatch->nOffset + 0] = t & 0xFF;
|
||||
pSect->pData[pPatch->nOffset+1]=(t>>8)&0xFF;
|
||||
pSect->pData[pPatch->nOffset+2]=(t>>16)&0xFF;
|
||||
pSect->pData[pPatch->nOffset+3]=(t>>24)&0xFF;
|
||||
pSect->pData[pPatch->nOffset + 1] =
|
||||
(t >> 8) & 0xFF;
|
||||
pSect->pData[pPatch->nOffset + 2] =
|
||||
(t >> 16) & 0xFF;
|
||||
pSect->pData[pPatch->nOffset + 3] =
|
||||
(t >> 24) & 0xFF;
|
||||
break;
|
||||
case PATCH_LONG_B:
|
||||
pSect->pData[pPatch->nOffset+0]=(t>>24)&0xFF;
|
||||
pSect->pData[pPatch->nOffset+1]=(t>>16)&0xFF;
|
||||
pSect->pData[pPatch->nOffset+2]=(t>>8)&0xFF;
|
||||
pSect->pData[pPatch->nOffset + 0] =
|
||||
(t >> 24) & 0xFF;
|
||||
pSect->pData[pPatch->nOffset + 1] =
|
||||
(t >> 16) & 0xFF;
|
||||
pSect->pData[pPatch->nOffset + 2] =
|
||||
(t >> 8) & 0xFF;
|
||||
pSect->pData[pPatch->nOffset + 3] = t & 0xFF;
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -7,8 +7,7 @@
|
||||
|
||||
#define HASHSIZE 73
|
||||
|
||||
struct ISymbol
|
||||
{
|
||||
struct ISymbol {
|
||||
char *pzName;
|
||||
SLONG nValue;
|
||||
SLONG nBank; // -1=const
|
||||
@@ -35,23 +34,16 @@ void sym_Init( void )
|
||||
|
||||
SLONG sym_GetValue(char *tzName)
|
||||
{
|
||||
if( strcmp(tzName,"@")==0 )
|
||||
{
|
||||
if (strcmp(tzName, "@") == 0) {
|
||||
return (nPC);
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
struct ISymbol **ppSym;
|
||||
|
||||
ppSym = &(tHash[calchash(tzName)]);
|
||||
while( *ppSym )
|
||||
{
|
||||
if( strcmp(tzName,(*ppSym)->pzName) )
|
||||
{
|
||||
while (*ppSym) {
|
||||
if (strcmp(tzName, (*ppSym)->pzName)) {
|
||||
ppSym = &((*ppSym)->pNext);
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
return ((*ppSym)->nValue);
|
||||
}
|
||||
}
|
||||
@@ -67,14 +59,10 @@ SLONG sym_GetBank( char *tzName )
|
||||
struct ISymbol **ppSym;
|
||||
|
||||
ppSym = &(tHash[calchash(tzName)]);
|
||||
while( *ppSym )
|
||||
{
|
||||
if( strcmp(tzName,(*ppSym)->pzName) )
|
||||
{
|
||||
while (*ppSym) {
|
||||
if (strcmp(tzName, (*ppSym)->pzName)) {
|
||||
ppSym = &((*ppSym)->pNext);
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
return ((*ppSym)->nBank);
|
||||
}
|
||||
}
|
||||
@@ -86,35 +74,29 @@ SLONG sym_GetBank( char *tzName )
|
||||
|
||||
void sym_CreateSymbol(char *tzName, SLONG nValue, SBYTE nBank)
|
||||
{
|
||||
if( strcmp(tzName,"@")==0 )
|
||||
{
|
||||
}
|
||||
else
|
||||
{
|
||||
if (strcmp(tzName, "@") == 0) {
|
||||
} else {
|
||||
struct ISymbol **ppSym;
|
||||
|
||||
ppSym = &(tHash[calchash(tzName)]);
|
||||
|
||||
while( *ppSym )
|
||||
{
|
||||
if( strcmp(tzName,(*ppSym)->pzName) )
|
||||
{
|
||||
while (*ppSym) {
|
||||
if (strcmp(tzName, (*ppSym)->pzName)) {
|
||||
ppSym = &((*ppSym)->pNext);
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
if (nBank == -1)
|
||||
return;
|
||||
|
||||
sprintf( temptext, "Symbol '%s' defined more than once\n", tzName );
|
||||
sprintf(temptext,
|
||||
"Symbol '%s' defined more than once\n",
|
||||
tzName);
|
||||
fatalerror(temptext);
|
||||
}
|
||||
}
|
||||
|
||||
if( *ppSym=(struct ISymbol *)malloc(sizeof(struct ISymbol)) )
|
||||
{
|
||||
if( (*ppSym)->pzName=(char *)malloc(strlen(tzName)+1) )
|
||||
{
|
||||
if (*ppSym = (struct ISymbol *)malloc(sizeof(struct ISymbol))) {
|
||||
if ((*ppSym)->pzName =
|
||||
(char *)malloc(strlen(tzName) + 1)) {
|
||||
strcpy((*ppSym)->pzName, tzName);
|
||||
(*ppSym)->nValue = nValue;
|
||||
(*ppSym)->nBank = nBank;
|
||||
|
||||
@@ -8,8 +8,6 @@
|
||||
#include <string.h>
|
||||
#include "asmotor.h"
|
||||
|
||||
|
||||
|
||||
/*
|
||||
* Option defines
|
||||
*
|
||||
@@ -23,24 +21,20 @@
|
||||
|
||||
unsigned long ulOptions;
|
||||
|
||||
|
||||
|
||||
|
||||
/*
|
||||
* Misc. variables
|
||||
*
|
||||
*/
|
||||
|
||||
unsigned char NintendoChar[48]=
|
||||
{
|
||||
0xCE,0xED,0x66,0x66,0xCC,0x0D,0x00,0x0B,0x03,0x73,0x00,0x83,0x00,0x0C,0x00,0x0D,
|
||||
0x00,0x08,0x11,0x1F,0x88,0x89,0x00,0x0E,0xDC,0xCC,0x6E,0xE6,0xDD,0xDD,0xD9,0x99,
|
||||
0xBB,0xBB,0x67,0x63,0x6E,0x0E,0xEC,0xCC,0xDD,0xDC,0x99,0x9F,0xBB,0xB9,0x33,0x3E
|
||||
unsigned char NintendoChar[48] = {
|
||||
0xCE, 0xED, 0x66, 0x66, 0xCC, 0x0D, 0x00, 0x0B, 0x03, 0x73, 0x00, 0x83,
|
||||
0x00, 0x0C, 0x00, 0x0D,
|
||||
0x00, 0x08, 0x11, 0x1F, 0x88, 0x89, 0x00, 0x0E, 0xDC, 0xCC, 0x6E, 0xE6,
|
||||
0xDD, 0xDD, 0xD9, 0x99,
|
||||
0xBB, 0xBB, 0x67, 0x63, 0x6E, 0x0E, 0xEC, 0xCC, 0xDD, 0xDC, 0x99, 0x9F,
|
||||
0xBB, 0xB9, 0x33, 0x3E
|
||||
};
|
||||
|
||||
|
||||
|
||||
|
||||
/*
|
||||
* Misc. routines
|
||||
*
|
||||
@@ -48,15 +42,19 @@ unsigned char NintendoChar[48]=
|
||||
|
||||
void PrintUsage(void)
|
||||
{
|
||||
printf( "RGBFix v" RGBFIX_VERSION " (part of ASMotor " ASMOTOR_VERSION ")\n\n" );
|
||||
printf("RGBFix v" RGBFIX_VERSION " (part of ASMotor " ASMOTOR_VERSION
|
||||
")\n\n");
|
||||
printf("Usage: rgbfix [options] image[.gb]\n");
|
||||
printf("Options:\n");
|
||||
printf("\t-h\t\tThis text\n");
|
||||
printf("\t-d\t\tDebug: Don't change image\n");
|
||||
printf( "\t-p\t\tPad image to valid size\n\t\t\tPads to 32/64/128/256/512kB as appropriate\n" );
|
||||
printf( "\t-r\t\ttRuncate image to valid size\n\t\t\tTruncates to 32/64/128/256/512kB as appropriate\n" );
|
||||
printf
|
||||
("\t-p\t\tPad image to valid size\n\t\t\tPads to 32/64/128/256/512kB as appropriate\n");
|
||||
printf
|
||||
("\t-r\t\ttRuncate image to valid size\n\t\t\tTruncates to 32/64/128/256/512kB as appropriate\n");
|
||||
printf("\t-t<name>\tChange cartridge title field (16 characters)\n");
|
||||
printf( "\t-v\t\tValidate header\n\t\t\tCorrects - Nintendo Character Area (0x0104)\n\t\t\t\t - ROM type (0x0147)\n\t\t\t\t - ROM size (0x0148)\n\t\t\t\t - Checksums (0x014D-0x014F)\n" );
|
||||
printf
|
||||
("\t-v\t\tValidate header\n\t\t\tCorrects - Nintendo Character Area (0x0104)\n\t\t\t\t - ROM type (0x0147)\n\t\t\t\t - ROM size (0x0148)\n\t\t\t\t - Checksums (0x014D-0x014F)\n");
|
||||
exit(0);
|
||||
}
|
||||
|
||||
@@ -83,12 +81,10 @@ int FileExists( char *s )
|
||||
{
|
||||
FILE *f;
|
||||
|
||||
if( (f=fopen(s,"rb"))!=NULL )
|
||||
{
|
||||
if ((f = fopen(s, "rb")) != NULL) {
|
||||
fclose(f);
|
||||
return (1);
|
||||
}
|
||||
else
|
||||
} else
|
||||
return (0);
|
||||
}
|
||||
|
||||
@@ -109,11 +105,9 @@ int main( int argc, char *argv[] )
|
||||
if ((--argc) == 0)
|
||||
PrintUsage();
|
||||
|
||||
while( *argv[argn]=='-' )
|
||||
{
|
||||
while (*argv[argn] == '-') {
|
||||
argc -= 1;
|
||||
switch( argv[argn++][1] )
|
||||
{
|
||||
switch (argv[argn++][1]) {
|
||||
case '?':
|
||||
case 'h':
|
||||
PrintUsage();
|
||||
@@ -142,15 +136,13 @@ int main( int argc, char *argv[] )
|
||||
if (!FileExists(filename))
|
||||
strcat(filename, ".gb");
|
||||
|
||||
if( (f=fopen(filename,"rb+"))!=NULL )
|
||||
{
|
||||
if ((f = fopen(filename, "rb+")) != NULL) {
|
||||
/*
|
||||
* -d (Debug) option code
|
||||
*
|
||||
*/
|
||||
|
||||
if( ulOptions&OPTF_DEBUG )
|
||||
{
|
||||
if (ulOptions & OPTF_DEBUG) {
|
||||
printf("-d (Debug) option enabled...\n");
|
||||
}
|
||||
|
||||
@@ -159,8 +151,7 @@ int main( int argc, char *argv[] )
|
||||
*
|
||||
*/
|
||||
|
||||
if( ulOptions&OPTF_PAD )
|
||||
{
|
||||
if (ulOptions & OPTF_PAD) {
|
||||
long size, padto;
|
||||
long bytesadded = 0;
|
||||
|
||||
@@ -175,13 +166,11 @@ int main( int argc, char *argv[] )
|
||||
if( padto<=0x80000L )
|
||||
{
|
||||
*/
|
||||
if( size!=padto )
|
||||
{
|
||||
if (size != padto) {
|
||||
fflush(stdout);
|
||||
|
||||
fseek(f, 0, SEEK_END);
|
||||
while( size<padto )
|
||||
{
|
||||
while (size < padto) {
|
||||
size += 1;
|
||||
if ((ulOptions & OPTF_DEBUG) == 0)
|
||||
fputc(0, f);
|
||||
@@ -190,8 +179,7 @@ int main( int argc, char *argv[] )
|
||||
fflush(f);
|
||||
|
||||
printf("\tAdded %ld bytes\n", bytesadded);
|
||||
}
|
||||
else
|
||||
} else
|
||||
printf("\tNo padding needed\n");
|
||||
/*
|
||||
}
|
||||
@@ -205,8 +193,7 @@ int main( int argc, char *argv[] )
|
||||
*
|
||||
*/
|
||||
|
||||
if( ulOptions&OPTF_TRUNCATE )
|
||||
{
|
||||
if (ulOptions & OPTF_TRUNCATE) {
|
||||
long size, padto;
|
||||
char tempfile[512];
|
||||
FILE *tf;
|
||||
@@ -220,13 +207,10 @@ int main( int argc, char *argv[] )
|
||||
|
||||
tmpnam(tempfile);
|
||||
|
||||
if( (ulOptions&OPTF_DEBUG)==0 )
|
||||
{
|
||||
if( (tf=fopen(tempfile,"wb"))!=NULL )
|
||||
{
|
||||
if ((ulOptions & OPTF_DEBUG) == 0) {
|
||||
if ((tf = fopen(tempfile, "wb")) != NULL) {
|
||||
fseek(f, 0, SEEK_SET);
|
||||
while( padto-- )
|
||||
{
|
||||
while (padto--) {
|
||||
fputc(fgetc(f), tf);
|
||||
}
|
||||
fclose(f);
|
||||
@@ -243,11 +227,9 @@ int main( int argc, char *argv[] )
|
||||
*
|
||||
*/
|
||||
|
||||
if( ulOptions&OPTF_TITLE )
|
||||
{
|
||||
if (ulOptions & OPTF_TITLE) {
|
||||
printf("Setting cartridge title:\n");
|
||||
if( (ulOptions&OPTF_DEBUG)==0 )
|
||||
{
|
||||
if ((ulOptions & OPTF_DEBUG) == 0) {
|
||||
fflush(f);
|
||||
fseek(f, 0x0134L, SEEK_SET);
|
||||
fwrite(cartname, 16, 1, f);
|
||||
@@ -261,13 +243,13 @@ int main( int argc, char *argv[] )
|
||||
*
|
||||
*/
|
||||
|
||||
if( ulOptions&OPTF_VALIDATE )
|
||||
{
|
||||
if (ulOptions & OPTF_VALIDATE) {
|
||||
long i, byteschanged = 0;
|
||||
long cartromsize, calcromsize = 0, filesize;
|
||||
long carttype;
|
||||
unsigned short cartchecksum = 0, calcchecksum = 0;
|
||||
unsigned char cartcompchecksum=0, calccompchecksum=0;
|
||||
unsigned char cartcompchecksum = 0, calccompchecksum =
|
||||
0;
|
||||
int ch;
|
||||
|
||||
printf("Validating header:\n");
|
||||
@@ -278,19 +260,16 @@ int main( int argc, char *argv[] )
|
||||
fflush(f);
|
||||
fseek(f, 0x0104L, SEEK_SET);
|
||||
|
||||
for( i=0; i<48; i+=1 )
|
||||
{
|
||||
for (i = 0; i < 48; i += 1) {
|
||||
int ch;
|
||||
|
||||
ch = fgetc(f);
|
||||
if (ch == EOF)
|
||||
ch = 0x00;
|
||||
if( ch!=NintendoChar[i] )
|
||||
{
|
||||
if (ch != NintendoChar[i]) {
|
||||
byteschanged += 1;
|
||||
|
||||
if( (ulOptions&OPTF_DEBUG)==0 )
|
||||
{
|
||||
if ((ulOptions & OPTF_DEBUG) == 0) {
|
||||
fseek(f, -1, SEEK_CUR);
|
||||
fputc(NintendoChar[i], f);
|
||||
fflush(f);
|
||||
@@ -301,7 +280,9 @@ int main( int argc, char *argv[] )
|
||||
fflush(f);
|
||||
|
||||
if (byteschanged)
|
||||
printf( "\tChanged %ld bytes in the Nintendo Character Area\n", byteschanged );
|
||||
printf
|
||||
("\tChanged %ld bytes in the Nintendo Character Area\n",
|
||||
byteschanged);
|
||||
else
|
||||
printf("\tNintendo Character Area is OK\n");
|
||||
|
||||
@@ -316,19 +297,19 @@ int main( int argc, char *argv[] )
|
||||
while (filesize > (0x8000L << calcromsize))
|
||||
calcromsize += 1;
|
||||
|
||||
if( calcromsize!=cartromsize )
|
||||
{
|
||||
if( (ulOptions&OPTF_DEBUG)==0 )
|
||||
{
|
||||
if (calcromsize != cartromsize) {
|
||||
if ((ulOptions & OPTF_DEBUG) == 0) {
|
||||
fseek(f, -1, SEEK_CUR);
|
||||
fputc(calcromsize, f);
|
||||
fflush(f);
|
||||
}
|
||||
printf( "\tChanged ROM size byte from 0x%02lX (%ldkB) to 0x%02lX (%ldkB)\n",
|
||||
cartromsize, (0x8000L<<cartromsize)/1024,
|
||||
calcromsize, (0x8000L<<calcromsize)/1024 );
|
||||
}
|
||||
else
|
||||
printf
|
||||
("\tChanged ROM size byte from 0x%02lX (%ldkB) to 0x%02lX (%ldkB)\n",
|
||||
cartromsize,
|
||||
(0x8000L << cartromsize) / 1024,
|
||||
calcromsize,
|
||||
(0x8000L << calcromsize) / 1024);
|
||||
} else
|
||||
printf("\tROM size byte is OK\n");
|
||||
|
||||
/* Cartridge type */
|
||||
@@ -339,24 +320,19 @@ int main( int argc, char *argv[] )
|
||||
if (carttype == EOF)
|
||||
carttype = 0x00;
|
||||
|
||||
if( FileSize(f)>0x8000L )
|
||||
{
|
||||
if (FileSize(f) > 0x8000L) {
|
||||
/* carttype byte must != 0x00 */
|
||||
if( carttype==0x00 )
|
||||
{
|
||||
if( (ulOptions&OPTF_DEBUG)==0 )
|
||||
{
|
||||
if (carttype == 0x00) {
|
||||
if ((ulOptions & OPTF_DEBUG) == 0) {
|
||||
fseek(f, -1, SEEK_CUR);
|
||||
fputc(0x01, f);
|
||||
fflush(f);
|
||||
}
|
||||
printf( "\tCartridge type byte changed to 0x01\n" );
|
||||
}
|
||||
else
|
||||
printf
|
||||
("\tCartridge type byte changed to 0x01\n");
|
||||
} else
|
||||
printf("\tCartridge type byte is OK\n");
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
/* carttype byte can be anything? */
|
||||
printf("\tCartridge type byte is OK\n");
|
||||
}
|
||||
@@ -366,20 +342,17 @@ int main( int argc, char *argv[] )
|
||||
fflush(f);
|
||||
fseek(f, 0, SEEK_SET);
|
||||
|
||||
for( i=0; i<(0x8000L<<calcromsize); i+=1 )
|
||||
{
|
||||
for (i = 0; i < (0x8000L << calcromsize); i += 1) {
|
||||
ch = fgetc(f);
|
||||
if (ch == EOF)
|
||||
ch = 0;
|
||||
|
||||
if (i < 0x0134L)
|
||||
calcchecksum += ch;
|
||||
else if( i<0x014DL )
|
||||
{
|
||||
else if (i < 0x014DL) {
|
||||
calccompchecksum += ch;
|
||||
calcchecksum += ch;
|
||||
}
|
||||
else if( i==0x014DL )
|
||||
} else if (i == 0x014DL)
|
||||
cartcompchecksum = ch;
|
||||
else if (i == 0x014EL)
|
||||
cartchecksum = ch << 8;
|
||||
@@ -392,39 +365,36 @@ int main( int argc, char *argv[] )
|
||||
calccompchecksum = 0xE7 - calccompchecksum;
|
||||
calcchecksum += calccompchecksum;
|
||||
|
||||
if( cartchecksum!=calcchecksum )
|
||||
{
|
||||
if (cartchecksum != calcchecksum) {
|
||||
fflush(f);
|
||||
fseek(f, 0x014EL, SEEK_SET);
|
||||
if( (ulOptions&OPTF_DEBUG)==0 )
|
||||
{
|
||||
if ((ulOptions & OPTF_DEBUG) == 0) {
|
||||
fputc(calcchecksum >> 8, f);
|
||||
fputc(calcchecksum & 0xFF, f);
|
||||
}
|
||||
fflush(f);
|
||||
printf( "\tChecksum changed from 0x%04lX to 0x%04lX\n", (long)cartchecksum, (long)calcchecksum );
|
||||
}
|
||||
else
|
||||
printf
|
||||
("\tChecksum changed from 0x%04lX to 0x%04lX\n",
|
||||
(long)cartchecksum, (long)calcchecksum);
|
||||
} else
|
||||
printf("\tChecksum is OK\n");
|
||||
|
||||
|
||||
if( cartcompchecksum!=calccompchecksum )
|
||||
{
|
||||
if (cartcompchecksum != calccompchecksum) {
|
||||
fflush(f);
|
||||
fseek(f, 0x014DL, SEEK_SET);
|
||||
if ((ulOptions & OPTF_DEBUG) == 0)
|
||||
fputc(calccompchecksum, f);
|
||||
fflush(f);
|
||||
printf( "\tCompChecksum changed from 0x%02lX to 0x%02lX\n", (long)cartcompchecksum, (long)calccompchecksum );
|
||||
}
|
||||
else
|
||||
printf
|
||||
("\tCompChecksum changed from 0x%02lX to 0x%02lX\n",
|
||||
(long)cartcompchecksum,
|
||||
(long)calccompchecksum);
|
||||
} else
|
||||
printf("\tCompChecksum is OK\n");
|
||||
|
||||
}
|
||||
fclose(f);
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
FatalError("Unable to open file");
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user