Compare commits

..

18 Commits

Author SHA1 Message Date
Anthony J. Bentley
361f1ac50b Work around a crash when '@' is interpreted as a macro name. 2015-01-22 21:12:57 -07:00
Anthony J. Bentley
4f8cf84ed4 rgbasm: improve (some) pathological spacing. 2015-01-22 21:09:10 -07:00
Anthony J. Bentley
c75b9d4d55 Makefile: don't expand variables in a non-POSIXish way. 2015-01-22 20:42:27 -07:00
Anthony J. Bentley
cd2af0204e rgbasm: Save some horizontal space in main.c. 2015-01-22 20:33:07 -07:00
yenatch
91241b44da rgbasm: bump MAXMACROARGS up to 256 from 9 2015-01-19 23:28:09 -08:00
Anthony J. Bentley
1d174f37da rgbasm: Convert oDontExpandStrings to bool. 2015-01-07 23:52:22 -07:00
Anthony J. Bentley
2777044f70 Delete some unused functions. 2015-01-07 23:39:00 -07:00
Anthony J. Bentley
e5e64b8cec rgbasm: trim ludicrously redundant comments. 2015-01-07 23:36:08 -07:00
Anthony J. Bentley
8534f3a148 Unify usage strings/functions across programs.
The funny spacing is to make it easier to keep to 80 characters/line.
2015-01-07 23:13:18 -07:00
Anthony J. Bentley
bdc6401eba rgbfix: deal with options and arguments in the right order. 2015-01-07 23:07:09 -07:00
Anthony J. Bentley
21d0b402d3 Don't unnecessarily initialize variables. 2015-01-07 22:59:06 -07:00
Anthony J. Bentley
a305649557 rgbasm: Print usage if no filename is given after flags. 2015-01-07 22:44:28 -07:00
Anthony J. Bentley
3b0e207036 Pass -Wimplicit (implicit + implicit-function-declaration) by default. 2015-01-07 18:43:16 -07:00
Anthony J. Bentley
83eddb4c4e Merge branch 'haltnop' of https://github.com/stag019/rgbds 2015-01-07 16:47:10 -07:00
Anthony J. Bentley
57997756b6 Merge branch 'symmapfix' of https://github.com/stag019/rgbds 2015-01-07 16:36:37 -07:00
stag019
ab66b28fdf yacc_pre is no longer needed, since all the files were merged into one. 2015-01-03 06:57:07 -05:00
stag019
116569f54d Fix for mapfiles and symfiles. Before, you couldn't define a mapfile unless you also defined a symfile. If you did, it would segfault. 2015-01-01 01:20:29 -05:00
stag019
2b839fec37 Use the options parameter provided for command line options. Specifically, for haltnop. 2014-12-31 13:29:24 -05:00
14 changed files with 453 additions and 905 deletions

View File

@@ -1,6 +1,6 @@
.POSIX: .POSIX:
WARNFLAGS = -Wall -Werror=implicit-int WARNFLAGS = -Wall -Werror=implicit
REALCFLAGS = ${CFLAGS} ${WARNFLAGS} -Iinclude -g \ REALCFLAGS = ${CFLAGS} ${WARNFLAGS} -Iinclude -g \
-std=c99 -D_POSIX_C_SOURCE=200809L -std=c99 -D_POSIX_C_SOURCE=200809L
@@ -10,13 +10,7 @@ BINPREFIX = ${PREFIX}/bin
MANPREFIX = ${PREFIX}/man MANPREFIX = ${PREFIX}/man
Q = @ Q = @
yacc_pre := \ rgbasm_obj = \
src/asm/yaccprt1.y\
src/asm/yaccprt2.y\
src/asm/yaccprt3.y\
src/asm/yaccprt4.y
rgbasm_obj := \
src/asm/asmy.o \ src/asm/asmy.o \
src/asm/charmap.o \ src/asm/charmap.o \
src/asm/fstack.o \ src/asm/fstack.o \
@@ -32,7 +26,7 @@ rgbasm_obj := \
src/extern/strlcpy.o \ src/extern/strlcpy.o \
src/extern/strlcat.o src/extern/strlcat.o
rgblink_obj := \ rgblink_obj = \
src/link/assign.o \ src/link/assign.o \
src/link/library.o \ src/link/library.o \
src/link/main.o \ src/link/main.o \
@@ -43,7 +37,7 @@ rgblink_obj := \
src/link/symbol.o \ src/link/symbol.o \
src/extern/err.o src/extern/err.o
rgbfix_obj := \ rgbfix_obj = \
src/fix/main.o \ src/fix/main.o \
src/extern/err.o src/extern/err.o

View File

@@ -9,8 +9,9 @@
#ifndef ASMOTOR_ASM_ASM_H #ifndef ASMOTOR_ASM_ASM_H
#define ASMOTOR_ASM_ASM_H #define ASMOTOR_ASM_ASM_H
#include <stdlib.h> #include <stdbool.h>
#include <stdio.h> #include <stdio.h>
#include <stdlib.h>
#include "asm/types.h" #include "asm/types.h"
#include "asm/symbol.h" #include "asm/symbol.h"
@@ -26,9 +27,9 @@ extern char tzCurrentFileName[_MAX_PATH + 1];
extern struct Section *pCurrentSection; extern struct Section *pCurrentSection;
extern struct sSymbol *tHashedSymbols[HASHSIZE]; extern struct sSymbol *tHashedSymbols[HASHSIZE];
extern struct sSymbol *pPCSymbol; extern struct sSymbol *pPCSymbol;
extern UBYTE oDontExpandStrings; extern bool oDontExpandStrings;
#define MAXMACROARGS 9 #define MAXMACROARGS 256
#define MAXINCPATHS 16 #define MAXINCPATHS 16
#endif /* // ASM_H */ #endif /* // ASM_H */

View File

@@ -8,6 +8,7 @@ struct sOptions {
char binary[2]; char binary[2];
SLONG fillchar; SLONG fillchar;
bool verbose; bool verbose;
bool haltnop;
//-1 == random //-1 == random
}; };

View File

@@ -1,7 +1,6 @@
%{ %{
#include <ctype.h> #include <ctype.h>
#include <errno.h> #include <errno.h>
#include <stdbool.h>
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
@@ -18,8 +17,6 @@
#include "asm/main.h" #include "asm/main.h"
#include "asm/lexer.h" #include "asm/lexer.h"
extern bool haltnop;
char *tzNewMacro; char *tzNewMacro;
ULONG ulNewMacroSize; ULONG ulNewMacroSize;
@@ -500,73 +497,68 @@ void if_skip_to_endc( void )
%% %%
asmfile : lines lastline asmfile : lines lastline;
;
lastline : /* empty */ lastline : /* empty */
| line | line {
{ nLineNo+=1; nTotalLines+=1; } nLineNo += 1;
; nTotalLines += 1;
};
lines : /* empty */ lines : /* empty */
| lines line '\n' | lines line '\n' {
{ nLineNo+=1; nTotalLines+=1; } nLineNo += 1;
; nTotalLines += 1;
};
line : /* empty */ line : /* empty */
| label | label
| label cpu_command | label cpu_command
| label macro | label macro
| label simple_pseudoop | label simple_pseudoop
| pseudoop | pseudoop;
;
label : /* empty */ label : /* empty */
| T_LABEL { if( $1[0]=='.' ) | T_LABEL {
sym_AddLocalReloc($1); if ($1[0] == '.')
else sym_AddLocalReloc($1);
sym_AddReloc($1); else
} sym_AddReloc($1);
| T_LABEL ':' { if( $1[0]=='.' ) } | T_LABEL ':' {
sym_AddLocalReloc($1); if ($1[0] == '.')
else sym_AddLocalReloc($1);
sym_AddReloc($1); else
} sym_AddReloc($1);
| T_LABEL ':' ':' { sym_AddReloc($1); sym_Export($1); } } | T_LABEL ':' ':' {
; sym_AddReloc($1);
sym_Export($1);
};
macro : T_ID macro : T_ID {
{ yy_set_state(LEX_STATE_MACROARGS);
yy_set_state( LEX_STATE_MACROARGS ); } macroargs {
} yy_set_state(LEX_STATE_NORMAL);
macroargs
{
yy_set_state( LEX_STATE_NORMAL );
if( !fstk_RunMacro($1) ) if (!fstk_RunMacro($1)) {
{ fatalerror("Macro '%s' not defined", $1);
yyerror("Macro '%s' not defined", $1); }
} };
}
;
macroargs : /* empty */ macroargs : /* empty */
| macroarg | macroarg
| macroarg ',' macroargs | macroarg ',' macroargs;
;
macroarg : T_STRING macroarg : T_STRING {
{ sym_AddNewMacroArg( $1 ); } sym_AddNewMacroArg($1);
; };
pseudoop : equ pseudoop : equ
| set | set
| rb | rb
| rw | rw
| rl | rl
| equs | equs
| macrodef | macrodef;
;
simple_pseudoop : include simple_pseudoop : include
| printf | printf
@@ -596,52 +588,44 @@ simple_pseudoop : include
| pushs | pushs
| popo | popo
| pusho | pusho
| opt | opt;
;
opt : T_POP_OPT opt : T_POP_OPT {
{ yy_set_state(LEX_STATE_MACROARGS);
yy_set_state( LEX_STATE_MACROARGS ); } opt_list {
} yy_set_state(LEX_STATE_NORMAL);
opt_list };
{
yy_set_state( LEX_STATE_NORMAL );
}
;
opt_list : opt_list_entry opt_list : opt_list_entry
| opt_list_entry ',' opt_list | opt_list_entry ',' opt_list;
;
opt_list_entry : T_STRING opt_list_entry : T_STRING {
{ opt_Parse($1);
opt_Parse($1); };
}
;
popo : T_POP_POPO popo : T_POP_POPO {
{ opt_Pop(); } opt_Pop();
; };
pusho : T_POP_PUSHO pusho : T_POP_PUSHO {
{ opt_Push(); } opt_Push();
; };
pops : T_POP_POPS pops : T_POP_POPS {
{ out_PopSection(); } out_PopSection();
; };
pushs : T_POP_PUSHS pushs : T_POP_PUSHS {
{ out_PushSection(); } out_PushSection();
; };
fail : T_POP_FAIL string fail : T_POP_FAIL string {
{ fatalerror("%s", $2); } fatalerror("%s", $2);
; };
warn : T_POP_WARN string warn : T_POP_WARN string {
{ yyerror("%s", $2); } yyerror("%s", $2);
; };
shift : T_POP_SHIFT shift : T_POP_SHIFT
{ sym_ShiftCurrentMacroArgs(); } { sym_ShiftCurrentMacroArgs(); }
@@ -709,11 +693,11 @@ dl : T_POP_DL constlist_32bit
purge : T_POP_PURGE purge : T_POP_PURGE
{ {
oDontExpandStrings=1; oDontExpandStrings = true;
} }
purge_list purge_list
{ {
oDontExpandStrings=0; oDontExpandStrings = false;
} }
; ;
@@ -955,8 +939,8 @@ relocconst : T_ID
{ rpn_UNNOT(&$$,&$2); } { rpn_UNNOT(&$$,&$2); }
| T_OP_BANK '(' T_ID ')' | T_OP_BANK '(' T_ID ')'
{ rpn_Bank(&$$,$3); $$.nVal = 0; } { rpn_Bank(&$$,$3); $$.nVal = 0; }
| T_OP_DEF { oDontExpandStrings=1; } '(' T_ID ')' | T_OP_DEF { oDontExpandStrings = true; } '(' T_ID ')'
{ rpn_Number(&$$,sym_isConstDefined($4)); oDontExpandStrings=0; } { rpn_Number(&$$,sym_isConstDefined($4)); oDontExpandStrings = false; }
| T_OP_ROUND '(' const ')' { rpn_Number(&$$,math_Round($3)); } | T_OP_ROUND '(' const ')' { rpn_Number(&$$,math_Round($3)); }
| T_OP_CEIL '(' const ')' { rpn_Number(&$$,math_Ceil($3)); } | T_OP_CEIL '(' const ')' { rpn_Number(&$$,math_Ceil($3)); }
| T_OP_FLOOR '(' const ')' { rpn_Number(&$$,math_Floor($3)); } | T_OP_FLOOR '(' const ')' { rpn_Number(&$$,math_Floor($3)); }
@@ -1025,7 +1009,7 @@ const : T_ID { $$ = sym_GetConstantValue($1); }
| T_OP_ACOS '(' const ')' { $$ = math_ACos($3); } | T_OP_ACOS '(' const ')' { $$ = math_ACos($3); }
| T_OP_ATAN '(' const ')' { $$ = math_ATan($3); } | T_OP_ATAN '(' const ')' { $$ = math_ATan($3); }
| T_OP_ATAN2 '(' const ',' const ')' { $$ = math_ATan2($3,$5); } | T_OP_ATAN2 '(' const ',' const ')' { $$ = math_ATan2($3,$5); }
| T_OP_DEF { oDontExpandStrings=1; } '(' T_ID ')' { $$ = sym_isConstDefined($4); oDontExpandStrings=0; } | T_OP_DEF { oDontExpandStrings = true; } '(' T_ID ')' { $$ = sym_isConstDefined($4); oDontExpandStrings = false; }
| T_OP_STRCMP '(' string ',' string ')' { $$ = strcmp( $3, $5 ); } | T_OP_STRCMP '(' string ',' string ')' { $$ = strcmp( $3, $5 ); }
| T_OP_STRIN '(' string ',' string ')' | T_OP_STRIN '(' string ',' string ')'
{ {
@@ -1264,7 +1248,7 @@ z80_ex : T_Z80_EX T_MODE_HL comma T_MODE_SP_IND
z80_halt: T_Z80_HALT z80_halt: T_Z80_HALT
{ {
out_AbsByte(0x76); out_AbsByte(0x76);
if (haltnop) { if (CurrentOptions.haltnop) {
out_AbsByte(0x00); out_AbsByte(0x00);
} }
} }

View File

@@ -1,8 +1,5 @@
/* /*
* RGBAsm - FSTACK.C (FileStack routines) * FileStack routines
*
* INCLUDES
*
*/ */
#include <errno.h> #include <errno.h>
@@ -23,13 +20,6 @@
#define PATH_MAX 256 #define PATH_MAX 256
#endif #endif
/*
* RGBAsm - FSTACK.C (FileStack routines)
*
* VARIABLES
*
*/
struct sContext *pFileStack; struct sContext *pFileStack;
struct sSymbol *pCurrentMacro; struct sSymbol *pCurrentMacro;
YY_BUFFER_STATE CurrentFlexHandle; YY_BUFFER_STATE CurrentFlexHandle;
@@ -55,12 +45,8 @@ ULONG ulMacroReturnValue;
#define STAT_isREPTBlock 3 #define STAT_isREPTBlock 3
/* /*
* RGBAsm - FSTACK.C (FileStack routines)
*
* Context push and pop * Context push and pop
*
*/ */
void void
pushcontext(void) pushcontext(void)
{ {
@@ -167,13 +153,10 @@ yywrap(void)
{ {
return (popcontext()); return (popcontext());
} }
/*
* RGBAsm - FSTACK.C (FileStack routines)
*
* Dump the context stack to stderr
*
*/
/*
* Dump the context stack to stderr
*/
void void
fstk_Dump(void) fstk_Dump(void)
{ {
@@ -189,13 +172,10 @@ fstk_Dump(void)
fprintf(stderr, "%s(%ld)", tzCurrentFileName, nLineNo); fprintf(stderr, "%s(%ld)", tzCurrentFileName, nLineNo);
} }
/*
* RGBAsm - FSTACK.C (FileStack routines)
*
* Extra includepath stuff
*
*/
/*
* Extra includepath stuff
*/
void void
fstk_AddIncludePath(char *s) fstk_AddIncludePath(char *s)
{ {
@@ -230,13 +210,10 @@ fstk_FindFile(char *fname)
errno = ENOENT; errno = ENOENT;
return NULL; return NULL;
} }
/*
* RGBAsm - FSTACK.C (FileStack routines)
*
* Set up an include file for parsing
*
*/
/*
* Set up an include file for parsing
*/
void void
fstk_RunInclude(char *tzFileName) fstk_RunInclude(char *tzFileName)
{ {
@@ -262,13 +239,10 @@ fstk_RunInclude(char *tzFileName)
yyunput('\n'); yyunput('\n');
nLineNo -= 1; nLineNo -= 1;
} }
/*
* RGBAsm - FSTACK.C (FileStack routines)
*
* Set up a macro for parsing
*
*/
/*
* Set up a macro for parsing
*/
ULONG ULONG
fstk_RunMacro(char *s) fstk_RunMacro(char *s)
{ {
@@ -281,6 +255,8 @@ fstk_RunMacro(char *s)
sym_UseNewMacroArgs(); sym_UseNewMacroArgs();
nCurrentStatus = STAT_isMacro; nCurrentStatus = STAT_isMacro;
strcpy(tzCurrentFileName, s); strcpy(tzCurrentFileName, s);
if (sym->pMacro == NULL)
return 0;
pCurrentMacro = sym; pCurrentMacro = sym;
CurrentFlexHandle = CurrentFlexHandle =
yy_scan_bytes(pCurrentMacro->pMacro, yy_scan_bytes(pCurrentMacro->pMacro,
@@ -290,13 +266,10 @@ fstk_RunMacro(char *s)
} else } else
return (0); return (0);
} }
/*
* RGBAsm - FSTACK.C (FileStack routines)
*
* Set up a macroargument for parsing
*
*/
/*
* Set up a macroargument for parsing
*/
void void
fstk_RunMacroArg(SLONG s) fstk_RunMacroArg(SLONG s)
{ {
@@ -316,13 +289,10 @@ fstk_RunMacroArg(SLONG s)
} else } else
fatalerror("No such macroargument"); fatalerror("No such macroargument");
} }
/*
* RGBAsm - FSTACK.C (FileStack routines)
*
* Set up a stringequate for parsing
*
*/
/*
* Set up a stringequate for parsing
*/
void void
fstk_RunString(char *s) fstk_RunString(char *s)
{ {
@@ -338,13 +308,10 @@ fstk_RunString(char *s)
} else } else
yyerror("No such string symbol '%s'", s); yyerror("No such string symbol '%s'", s);
} }
/*
* RGBAsm - FSTACK.C (FileStack routines)
*
* Set up a repeat block for parsing
*
*/
/*
* Set up a repeat block for parsing
*/
void void
fstk_RunRept(ULONG count) fstk_RunRept(ULONG count)
{ {
@@ -362,13 +329,10 @@ fstk_RunRept(ULONG count)
yy_switch_to_buffer(CurrentFlexHandle); yy_switch_to_buffer(CurrentFlexHandle);
} }
} }
/*
* RGBAsm - FSTACK.C (FileStack routines)
*
* Initialize the filestack routines
*
*/
/*
* Initialize the filestack routines
*/
void void
fstk_Init(char *s) fstk_Init(char *s)
{ {

View File

@@ -7,12 +7,13 @@
#include "asmy.h" #include "asmy.h"
#include <stdbool.h>
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include <math.h> #include <math.h>
#include <string.h> #include <string.h>
UBYTE oDontExpandStrings = 0; bool oDontExpandStrings = false;
SLONG nGBGfxID = -1; SLONG nGBGfxID = -1;
SLONG nBinaryID = -1; SLONG nBinaryID = -1;
@@ -184,7 +185,7 @@ ParseSymbol(char *src, ULONG size)
dest[copied] = 0; dest[copied] = 0;
if (oDontExpandStrings == 0 && sym_isString(dest)) { if (!oDontExpandStrings && sym_isString(dest)) {
char *s; char *s;
yyskipbytes(size_backup); yyskipbytes(size_backup);

View File

@@ -1,13 +1,5 @@
/*
* RGBAsm - MAIN.C
*
* INCLUDES
*
*/
#include <math.h> #include <math.h>
#include <stdarg.h> #include <stdarg.h>
#include <stdbool.h>
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
@@ -23,15 +15,6 @@
int yyparse(void); int yyparse(void);
void setuplex(void); void setuplex(void);
/*
* RGBAsm - MAIN.C
*
* VARIABLES
*
*/
bool haltnop;
clock_t nStartClock, nEndClock; clock_t nStartClock, nEndClock;
SLONG nLineNo; SLONG nLineNo;
ULONG nTotalLines, nPass, nPC, nIFDepth, nErrors; ULONG nTotalLines, nPass, nPC, nIFDepth, nErrors;
@@ -39,10 +22,7 @@ ULONG nTotalLines, nPass, nPC, nIFDepth, nErrors;
extern int yydebug; extern int yydebug;
/* /*
* RGBAsm - MAIN.C
*
* Option stack * Option stack
*
*/ */
struct sOptions DefaultOptions; struct sOptions DefaultOptions;
@@ -193,13 +173,10 @@ opt_Pop(void)
} else } else
fatalerror("No entries in the option stack"); fatalerror("No entries in the option stack");
} }
/*
* RGBAsm - MAIN.C
*
* Error handling
*
*/
/*
* Error handling
*/
void void
verror(const char *fmt, va_list args) verror(const char *fmt, va_list args)
{ {
@@ -229,26 +206,15 @@ fatalerror(const char *fmt, ...)
va_end(args); va_end(args);
exit(5); exit(5);
} }
/*
* RGBAsm - MAIN.C
*
* Help text
*
*/
void static void
PrintUsage(void) usage(void)
{ {
printf("Usage: rgbasm [-v] [-h] [-b chars] [-g chars] [-i path] [-o outfile] [-p pad_value]\n" printf(
" file\n"); "Usage: rgbasm [-v] [-h] [-b chars] [-g chars] [-i path] [-o outfile]\n"
" [-p pad_value] file.asm\n");
exit(1); exit(1);
} }
/*
* RGBAsm - MAIN.C
*
* main
*
*/
int int
main(int argc, char *argv[]) main(int argc, char *argv[])
@@ -260,10 +226,10 @@ main(int argc, char *argv[])
char *tzMainfile; char *tzMainfile;
haltnop = true;
if (argc == 1) if (argc == 1)
PrintUsage(); usage();
/* yydebug=1; */ /* yydebug=1; */
@@ -275,6 +241,7 @@ main(int argc, char *argv[])
DefaultOptions.binary[1] = '1'; DefaultOptions.binary[1] = '1';
DefaultOptions.fillchar = 0; DefaultOptions.fillchar = 0;
DefaultOptions.verbose = false; DefaultOptions.verbose = false;
DefaultOptions.haltnop = true;
opt_SetCurrentOptions(&DefaultOptions); opt_SetCurrentOptions(&DefaultOptions);
@@ -303,7 +270,7 @@ main(int argc, char *argv[])
} }
break; break;
case 'h': case 'h':
haltnop = false; newopt.haltnop = false;
break; break;
case 'i': case 'i':
fstk_AddIncludePath(optarg); fstk_AddIncludePath(optarg);
@@ -325,7 +292,7 @@ main(int argc, char *argv[])
newopt.verbose = true; newopt.verbose = true;
break; break;
default: default:
PrintUsage(); usage();
} }
} }
argc -= optind; argc -= optind;
@@ -335,6 +302,9 @@ main(int argc, char *argv[])
DefaultOptions = CurrentOptions; DefaultOptions = CurrentOptions;
if (argc == 0)
usage();
tzMainfile = argv[argc - 1]; tzMainfile = argv[argc - 1];
setuplex(); setuplex();
@@ -353,6 +323,7 @@ main(int argc, char *argv[])
nErrors = 0; nErrors = 0;
sym_PrepPass1(); sym_PrepPass1();
fstk_Init(tzMainfile); fstk_Init(tzMainfile);
if (CurrentOptions.verbose) { if (CurrentOptions.verbose) {
printf("Pass 1...\n"); printf("Pass 1...\n");
} }
@@ -360,59 +331,48 @@ main(int argc, char *argv[])
yy_set_state(LEX_STATE_NORMAL); yy_set_state(LEX_STATE_NORMAL);
opt_SetCurrentOptions(&DefaultOptions); opt_SetCurrentOptions(&DefaultOptions);
if (yyparse() == 0 && nErrors == 0) { if (yyparse() != 0 || nErrors != 0) {
if (nIFDepth == 0) { errx(1, "Assembly aborted in pass 1 (%ld errors)!", nErrors);
nTotalLines = 0;
nLineNo = 1;
nIFDepth = 0;
nPC = 0;
nPass = 2;
nErrors = 0;
sym_PrepPass2();
out_PrepPass2();
fstk_Init(tzMainfile);
yy_set_state(LEX_STATE_NORMAL);
opt_SetCurrentOptions(&DefaultOptions);
if (CurrentOptions.verbose) {
printf("Pass 2...\n");
}
if (yyparse() == 0 && nErrors == 0) {
double timespent;
nEndClock = clock();
timespent =
((double) (nEndClock - nStartClock))
/ (double) CLOCKS_PER_SEC;
if (CurrentOptions.verbose) {
printf
("Success! %ld lines in %d.%02d seconds ",
nTotalLines, (int) timespent,
((int) (timespent * 100.0)) % 100);
if (timespent == 0)
printf
("(INFINITY lines/minute)\n");
else
printf("(%d lines/minute)\n",
(int) (60 / timespent *
nTotalLines));
}
out_WriteObject();
} else {
printf
("Assembly aborted in pass 2 (%ld errors)!\n",
nErrors);
//sym_PrintSymbolTable();
exit(5);
}
} else {
errx(1, "Unterminated IF construct (%ld levels)!",
nIFDepth);
}
} else {
errx(1, "Assembly aborted in pass 1 (%ld errors)!",
nErrors);
} }
if (nIFDepth != 0) {
errx(1, "Unterminated IF construct (%ld levels)!", nIFDepth);
}
nTotalLines = 0;
nLineNo = 1;
nIFDepth = 0;
nPC = 0;
nPass = 2;
nErrors = 0;
sym_PrepPass2();
out_PrepPass2();
fstk_Init(tzMainfile);
yy_set_state(LEX_STATE_NORMAL);
opt_SetCurrentOptions(&DefaultOptions);
if (CurrentOptions.verbose) {
printf("Pass 2...\n");
}
if (yyparse() != 0 || nErrors != 0) {
errx(1, "Assembly aborted in pass 2 (%ld errors)!", nErrors);
}
double timespent;
nEndClock = clock();
timespent = ((double)(nEndClock - nStartClock))
/ (double)CLOCKS_PER_SEC;
if (CurrentOptions.verbose) {
printf("Success! %ld lines in %d.%02d seconds ", nTotalLines,
(int) timespent, ((int) (timespent * 100.0)) % 100);
if (timespent == 0)
printf("(INFINITY lines/minute)\n");
else
printf("(%d lines/minute)\n",
(int) (60 / timespent * nTotalLines));
}
out_WriteObject();
return 0; return 0;
} }

View File

@@ -1,8 +1,5 @@
/* /*
* RGBAsm - MATH.C (Fixedpoint math routines) * Fixedpoint math routines
*
* INCLUDES
*
*/ */
#include <math.h> #include <math.h>
@@ -19,24 +16,17 @@
#endif #endif
/* /*
* RGBAsm - MATH.C (Fixedpoint math routines)
*
* Define the _PI symbol * Define the _PI symbol
*
*/ */
void void
math_DefinePI(void) math_DefinePI(void)
{ {
sym_AddEqu("_PI", double2fix(PI)); sym_AddEqu("_PI", double2fix(PI));
} }
/*
* RGBAsm - MATH.C (Fixedpoint math routines)
*
* Print a fixed point value
*
*/
/*
* Print a fixed point value
*/
void void
math_Print(SLONG i) math_Print(SLONG i)
{ {
@@ -47,143 +37,110 @@ math_Print(SLONG i)
printf("-%ld.%05ld", (-i) >> 16, printf("-%ld.%05ld", (-i) >> 16,
((SLONG) (fix2double(-i) * 100000 + 0.5)) % 100000); ((SLONG) (fix2double(-i) * 100000 + 0.5)) % 100000);
} }
/*
* RGBAsm - MATH.C (Fixedpoint math routines)
*
* Calculate sine
*
*/
/*
* Calculate sine
*/
SLONG SLONG
math_Sin(SLONG i) math_Sin(SLONG i)
{ {
return (double2fix(sin(fix2double(i) * 2 * PI / 65536))); return (double2fix(sin(fix2double(i) * 2 * PI / 65536)));
} }
/*
* RGBAsm - MATH.C (Fixedpoint math routines)
*
* Calculate cosine
*
*/
/*
* Calculate cosine
*/
SLONG SLONG
math_Cos(SLONG i) math_Cos(SLONG i)
{ {
return (double2fix(cos(fix2double(i) * 2 * PI / 65536))); return (double2fix(cos(fix2double(i) * 2 * PI / 65536)));
} }
/*
* RGBAsm - MATH.C (Fixedpoint math routines)
*
* Calculate tangent
*
*/
/*
* Calculate tangent
*/
SLONG SLONG
math_Tan(SLONG i) math_Tan(SLONG i)
{ {
return (double2fix(tan(fix2double(i) * 2 * PI / 65536))); return (double2fix(tan(fix2double(i) * 2 * PI / 65536)));
} }
/*
* RGBAsm - MATH.C (Fixedpoint math routines)
*
* Calculate sine^-1
*
*/
/*
* Calculate arcsine
*/
SLONG SLONG
math_ASin(SLONG i) math_ASin(SLONG i)
{ {
return (double2fix(asin(fix2double(i)) / 2 / PI * 65536)); return (double2fix(asin(fix2double(i)) / 2 / PI * 65536));
} }
/*
* RGBAsm - MATH.C (Fixedpoint math routines)
*
* Calculate cosine^-1
*
*/
/*
* Calculate arccosine
*/
SLONG SLONG
math_ACos(SLONG i) math_ACos(SLONG i)
{ {
return (double2fix(acos(fix2double(i)) / 2 / PI * 65536)); return (double2fix(acos(fix2double(i)) / 2 / PI * 65536));
} }
/*
* RGBAsm - MATH.C (Fixedpoint math routines)
*
* Calculate tangent^-1
*
*/
/*
* Calculate arctangent
*/
SLONG SLONG
math_ATan(SLONG i) math_ATan(SLONG i)
{ {
return (double2fix(atan(fix2double(i)) / 2 / PI * 65536)); return (double2fix(atan(fix2double(i)) / 2 / PI * 65536));
} }
/*
* RGBAsm - MATH.C (Fixedpoint math routines)
*
* Calculate atan2
*
*/
/*
* Calculate atan2
*/
SLONG SLONG
math_ATan2(SLONG i, SLONG j) math_ATan2(SLONG i, SLONG j)
{ {
return (double2fix return (double2fix
(atan2(fix2double(i), fix2double(j)) / 2 / PI * 65536)); (atan2(fix2double(i), fix2double(j)) / 2 / PI * 65536));
} }
/*
* RGBAsm - MATH.C (Fixedpoint math routines)
*
* Multiplication
*
*/
/*
* Multiplication
*/
SLONG SLONG
math_Mul(SLONG i, SLONG j) math_Mul(SLONG i, SLONG j)
{ {
return (double2fix(fix2double(i) * fix2double(j))); return (double2fix(fix2double(i) * fix2double(j)));
} }
/*
* RGBAsm - MATH.C (Fixedpoint math routines)
*
* Division
*
*/
/*
* Division
*/
SLONG SLONG
math_Div(SLONG i, SLONG j) math_Div(SLONG i, SLONG j)
{ {
return (double2fix(fix2double(i) / fix2double(j))); return (double2fix(fix2double(i) / fix2double(j)));
}/* }
* RGBAsm - MATH.C (Fixedpoint math routines)
*
* Round
*
*/
/*
* Round
*/
SLONG SLONG
math_Round(SLONG i) math_Round(SLONG i)
{ {
return double2fix(round(fix2double(i))); return double2fix(round(fix2double(i)));
}/* }
* RGBAsm - MATH.C (Fixedpoint math routines)
*
* Ceil
*
*/
/*
* Ceil
*/
SLONG SLONG
math_Ceil(SLONG i) math_Ceil(SLONG i)
{ {
return double2fix(ceil(fix2double(i))); return double2fix(ceil(fix2double(i)));
}/* }
* RGBAsm - MATH.C (Fixedpoint math routines)
*
* Floor
*
*/
/*
* Floor
*/
SLONG SLONG
math_Floor(SLONG i) math_Floor(SLONG i)
{ {

View File

@@ -1,8 +1,5 @@
/* /*
* RGBAsm - OUTPUT.C - Outputs an objectfile * Outputs an objectfile
*
* INCLUDES
*
*/ */
#include <errno.h> #include <errno.h>
@@ -22,13 +19,6 @@
#define SECTIONCHUNK 0x4000 #define SECTIONCHUNK 0x4000
/*
* RGBAsm - OUTPUT.C - Outputs an objectfile
*
* Internal structures
*
*/
void out_SetCurrentSection(struct Section * pSect); void out_SetCurrentSection(struct Section * pSect);
struct Patch { struct Patch {
@@ -52,12 +42,6 @@ struct SectionStackEntry {
struct Section *pSection; struct Section *pSection;
struct SectionStackEntry *pNext; struct SectionStackEntry *pNext;
}; };
/*
* RGBAsm - OUTPUT.C - Outputs an objectfile
*
* VARIABLES
*
*/
struct PatchSymbol *tHashedPatchSymbols[HASHSIZE]; struct PatchSymbol *tHashedPatchSymbols[HASHSIZE];
struct Section *pSectionList = NULL, *pCurrentSection = NULL; struct Section *pSectionList = NULL, *pCurrentSection = NULL;
@@ -67,12 +51,8 @@ char *tzObjectname;
struct SectionStackEntry *pSectionStack = NULL; struct SectionStackEntry *pSectionStack = NULL;
/* /*
* RGBAsm - OUTPUT.C - Outputs an objectfile
*
* Section stack routines * Section stack routines
*
*/ */
void void
out_PushSection(void) out_PushSection(void)
{ {
@@ -99,13 +79,10 @@ out_PopSection(void)
} else } else
fatalerror("No entries in the section stack"); fatalerror("No entries in the section stack");
} }
/*
* RGBAsm - OUTPUT.C - Outputs an objectfile
*
* Count the number of symbols used in this object
*
*/
/*
* Count the number of symbols used in this object
*/
ULONG ULONG
countsymbols(void) countsymbols(void)
{ {
@@ -121,13 +98,10 @@ countsymbols(void)
return (count); return (count);
} }
/*
* RGBAsm - OUTPUT.C - Outputs an objectfile
*
* Count the number of sections used in this object
*
*/
/*
* Count the number of sections used in this object
*/
ULONG ULONG
countsections(void) countsections(void)
{ {
@@ -143,13 +117,10 @@ countsections(void)
return (count); return (count);
} }
/*
* RGBAsm - OUTPUT.C - Outputs an objectfile
*
* Count the number of patches used in this object
*
*/
/*
* Count the number of patches used in this object
*/
ULONG ULONG
countpatches(struct Section * pSect) countpatches(struct Section * pSect)
{ {
@@ -164,13 +135,10 @@ countpatches(struct Section * pSect)
return (r); return (r);
} }
/*
* RGBAsm - OUTPUT.C - Outputs an objectfile
*
* Write a long to a file (little-endian)
*
*/
/*
* Write a long to a file (little-endian)
*/
void void
fputlong(ULONG i, FILE * f) fputlong(ULONG i, FILE * f)
{ {
@@ -179,13 +147,10 @@ fputlong(ULONG i, FILE * f)
fputc(i >> 16, f); fputc(i >> 16, f);
fputc(i >> 24, f); fputc(i >> 24, f);
} }
/*
* RGBAsm - OUTPUT.C - Outputs an objectfile
*
* Write a NULL-terminated string to a file
*
*/
/*
* Write a NULL-terminated string to a file
*/
void void
fputstring(char *s, FILE * f) fputstring(char *s, FILE * f)
{ {
@@ -193,13 +158,10 @@ fputstring(char *s, FILE * f)
fputc(*s++, f); fputc(*s++, f);
fputc(0, f); fputc(0, f);
} }
/*
* RGBAsm - OUTPUT.C - Outputs an objectfile
*
* Return a sections ID
*
*/
/*
* Return a section's ID
*/
ULONG ULONG
getsectid(struct Section * pSect) getsectid(struct Section * pSect)
{ {
@@ -218,13 +180,10 @@ getsectid(struct Section * pSect)
fatalerror("INTERNAL: Unknown section"); fatalerror("INTERNAL: Unknown section");
return ((ULONG) - 1); return ((ULONG) - 1);
} }
/*
* RGBAsm - OUTPUT.C - Outputs an objectfile
*
* Write a patch to a file
*
*/
/*
* Write a patch to a file
*/
void void
writepatch(struct Patch * pPatch, FILE * f) writepatch(struct Patch * pPatch, FILE * f)
{ {
@@ -235,13 +194,10 @@ writepatch(struct Patch * pPatch, FILE * f)
fputlong(pPatch->nRPNSize, f); fputlong(pPatch->nRPNSize, f);
fwrite(pPatch->pRPN, 1, pPatch->nRPNSize, f); fwrite(pPatch->pRPN, 1, pPatch->nRPNSize, f);
} }
/*
* RGBAsm - OUTPUT.C - Outputs an objectfile
*
* Write a section to a file
*
*/
/*
* Write a section to a file
*/
void void
writesection(struct Section * pSect, FILE * f) writesection(struct Section * pSect, FILE * f)
{ {
@@ -269,13 +225,10 @@ writesection(struct Section * pSect, FILE * f)
} }
} }
} }
/*
* RGBAsm - OUTPUT.C - Outputs an objectfile
*
* Write a symbol to a file
*
*/
/*
* Write a symbol to a file
*/
void void
writesymbol(struct sSymbol * pSym, FILE * f) writesymbol(struct sSymbol * pSym, FILE * f)
{ {
@@ -319,13 +272,10 @@ writesymbol(struct sSymbol * pSym, FILE * f)
fputlong(offset, f); fputlong(offset, f);
} }
} }
/*
* RGBAsm - OUTPUT.C - Outputs an objectfile
*
* Add a symbol to the object
*
*/
/*
* Add a symbol to the object
*/
ULONG ULONG
addsymbol(struct sSymbol * pSym) addsymbol(struct sSymbol * pSym)
{ {
@@ -355,13 +305,10 @@ addsymbol(struct sSymbol * pSym)
return pPSym->ID; return pPSym->ID;
} }
/*
* RGBAsm - OUTPUT.C - Outputs an objectfile
*
* Add all exported symbols to the object
*
*/
/*
* Add all exported symbols to the object
*/
void void
addexports(void) addexports(void)
{ {
@@ -378,13 +325,10 @@ addexports(void)
} }
} }
} }
/*
* RGBAsm - OUTPUT.C - Outputs an objectfile
*
* Allocate a new patchstructure and link it into the list
*
*/
/*
* Allocate a new patchstructure and link it into the list
*/
struct Patch * struct Patch *
allocpatch(void) allocpatch(void)
{ {
@@ -401,13 +345,10 @@ allocpatch(void)
return (pPatch); return (pPatch);
} }
/*
* RGBAsm - OUTPUT.C - Outputs an objectfile
*
* Create a new patch (includes the rpn expr)
*
*/
/*
* Create a new patch (includes the rpn expr)
*/
void void
createpatch(ULONG type, struct Expression * expr) createpatch(ULONG type, struct Expression * expr)
{ {
@@ -473,13 +414,10 @@ createpatch(ULONG type, struct Expression * expr)
pPatch->nRPNSize = rpnptr; pPatch->nRPNSize = rpnptr;
} }
} }
/*
* RGBAsm - OUTPUT.C - Outputs an objectfile
*
* A quick check to see if we have an initialized section
*
*/
/*
* A quick check to see if we have an initialized section
*/
void void
checksection(void) checksection(void)
{ {
@@ -488,14 +426,11 @@ checksection(void)
else else
fatalerror("Code generation before SECTION directive"); fatalerror("Code generation before SECTION directive");
} }
/* /*
* RGBAsm - OUTPUT.C - Outputs an objectfile
*
* A quick check to see if we have an initialized section that can contain * A quick check to see if we have an initialized section that can contain
* this much initialized data * this much initialized data
*
*/ */
void void
checkcodesection(SLONG size) checkcodesection(SLONG size)
{ {
@@ -524,13 +459,10 @@ checkcodesection(SLONG size)
} else } else
errx(1, "Section '%s' is too big", pCurrentSection->pzName); errx(1, "Section '%s' is too big", pCurrentSection->pzName);
} }
/*
* RGBAsm - OUTPUT.C - Outputs an objectfile
*
* Write an objectfile
*
*/
/*
* Write an objectfile
*/
void void
out_WriteObject(void) out_WriteObject(void)
{ {
@@ -561,13 +493,10 @@ out_WriteObject(void)
fclose(f); fclose(f);
} }
} }
/*
* RGBAsm - OUTPUT.C - Outputs an objectfile
*
* Prepare for pass #2
*
*/
/*
* Prepare for pass #2
*/
void void
out_PrepPass2(void) out_PrepPass2(void)
{ {
@@ -581,13 +510,10 @@ out_PrepPass2(void)
pCurrentSection = NULL; pCurrentSection = NULL;
pSectionStack = NULL; pSectionStack = NULL;
} }
/*
* RGBAsm - OUTPUT.C - Outputs an objectfile
*
* Set the objectfilename
*
*/
/*
* Set the objectfilename
*/
void void
out_SetFileName(char *s) out_SetFileName(char *s)
{ {
@@ -599,16 +525,12 @@ out_SetFileName(char *s)
pCurrentSection = NULL; pCurrentSection = NULL;
pPatchSymbols = NULL; pPatchSymbols = NULL;
} }
/*
* RGBAsm - OUTPUT.C - Outputs an objectfile
*
* Find a section by name and type. If it doesn't exist, create it
*
*/
/*
* Find a section by name and type. If it doesn't exist, create it
*/
struct Section * struct Section *
out_FindSection(char *pzName, ULONG secttype, SLONG org, out_FindSection(char *pzName, ULONG secttype, SLONG org, SLONG bank)
SLONG bank)
{ {
struct Section *pSect, **ppSect; struct Section *pSect, **ppSect;
@@ -652,13 +574,10 @@ out_FindSection(char *pzName, ULONG secttype, SLONG org,
return (NULL); return (NULL);
} }
/*
* RGBAsm - OUTPUT.C - Outputs an objectfile
*
* Set the current section
*
*/
/*
* Set the current section
*/
void void
out_SetCurrentSection(struct Section * pSect) out_SetCurrentSection(struct Section * pSect)
{ {
@@ -668,37 +587,28 @@ out_SetCurrentSection(struct Section * pSect)
pPCSymbol->nValue = nPC; pPCSymbol->nValue = nPC;
pPCSymbol->pSection = pCurrentSection; pPCSymbol->pSection = pCurrentSection;
} }
/*
* RGBAsm - OUTPUT.C - Outputs an objectfile
*
* Set the current section by name and type
*
*/
/*
* Set the current section by name and type
*/
void void
out_NewSection(char *pzName, ULONG secttype) out_NewSection(char *pzName, ULONG secttype)
{ {
out_SetCurrentSection(out_FindSection(pzName, secttype, -1, -1)); out_SetCurrentSection(out_FindSection(pzName, secttype, -1, -1));
} }
/*
* RGBAsm - OUTPUT.C - Outputs an objectfile
*
* Set the current section by name and type
*
*/
/*
* Set the current section by name and type
*/
void void
out_NewAbsSection(char *pzName, ULONG secttype, SLONG org, SLONG bank) out_NewAbsSection(char *pzName, ULONG secttype, SLONG org, SLONG bank)
{ {
out_SetCurrentSection(out_FindSection(pzName, secttype, org, bank)); out_SetCurrentSection(out_FindSection(pzName, secttype, org, bank));
} }
/*
* RGBAsm - OUTPUT.C - Outputs an objectfile
*
* Output an absolute byte
*
*/
/*
* Output an absolute byte
*/
void void
out_AbsByte(int b) out_AbsByte(int b)
{ {
@@ -719,13 +629,10 @@ out_AbsByteGroup(char *s, int length)
while (length--) while (length--)
out_AbsByte(*s++); out_AbsByte(*s++);
} }
/*
* RGBAsm - OUTPUT.C - Outputs an objectfile
*
* Skip this many bytes
*
*/
/*
* Skip this many bytes
*/
void void
out_Skip(int skip) out_Skip(int skip)
{ {
@@ -741,13 +648,10 @@ out_Skip(int skip)
out_AbsByte(CurrentOptions.fillchar); out_AbsByte(CurrentOptions.fillchar);
} }
} }
/*
* RGBAsm - OUTPUT.C - Outputs an objectfile
*
* Output a NULL terminated string (excluding the NULL-character)
*
*/
/*
* Output a NULL terminated string (excluding the NULL-character)
*/
void void
out_String(char *s) out_String(char *s)
{ {
@@ -755,12 +659,10 @@ out_String(char *s)
while (*s) while (*s)
out_AbsByte(*s++); out_AbsByte(*s++);
} }
/* /*
* RGBAsm - OUTPUT.C - Outputs an objectfile
*
* Output a relocatable byte. Checking will be done to see if it * Output a relocatable byte. Checking will be done to see if it
* is an absolute value in disguise. * is an absolute value in disguise.
*
*/ */
void void
@@ -780,13 +682,10 @@ out_RelByte(struct Expression * expr)
rpn_Reset(expr); rpn_Reset(expr);
} }
/*
* RGBAsm - OUTPUT.C - Outputs an objectfile
*
* Output an absolute word
*
*/
/*
* Output an absolute word
*/
void void
out_AbsWord(int b) out_AbsWord(int b)
{ {
@@ -800,14 +699,11 @@ out_AbsWord(int b)
nPC += 2; nPC += 2;
pPCSymbol->nValue += 2; pPCSymbol->nValue += 2;
} }
/*
* RGBAsm - OUTPUT.C - Outputs an objectfile
*
* Output a relocatable word. Checking will be done to see if
* is an absolute value in disguise.
*
*/
/*
* Output a relocatable word. Checking will be done to see if
* it's an absolute value in disguise.
*/
void void
out_RelWord(struct Expression * expr) out_RelWord(struct Expression * expr)
{ {
@@ -828,13 +724,10 @@ out_RelWord(struct Expression * expr)
out_AbsWord(expr->nVal); out_AbsWord(expr->nVal);
rpn_Reset(expr); rpn_Reset(expr);
} }
/*
* RGBAsm - OUTPUT.C - Outputs an objectfile
*
* Output an absolute longword
*
*/
/*
* Output an absolute longword
*/
void void
out_AbsLong(SLONG b) out_AbsLong(SLONG b)
{ {
@@ -849,14 +742,11 @@ out_AbsLong(SLONG b)
nPC += 4; nPC += 4;
pPCSymbol->nValue += 4; pPCSymbol->nValue += 4;
} }
/* /*
* RGBAsm - OUTPUT.C - Outputs an objectfile
*
* Output a relocatable longword. Checking will be done to see if * Output a relocatable longword. Checking will be done to see if
* is an absolute value in disguise. * is an absolute value in disguise.
*
*/ */
void void
out_RelLong(struct Expression * expr) out_RelLong(struct Expression * expr)
{ {
@@ -879,13 +769,10 @@ out_RelLong(struct Expression * expr)
out_AbsLong(expr->nVal); out_AbsLong(expr->nVal);
rpn_Reset(expr); rpn_Reset(expr);
} }
/*
* RGBAsm - OUTPUT.C - Outputs an objectfile
*
* Output a PC-relative byte
*
*/
/*
* Output a PC-relative byte
*/
void void
out_PCRelByte(struct Expression * expr) out_PCRelByte(struct Expression * expr)
{ {
@@ -899,13 +786,10 @@ out_PCRelByte(struct Expression * expr)
out_AbsByte(b); out_AbsByte(b);
rpn_Reset(expr); rpn_Reset(expr);
} }
/*
* RGBAsm - OUTPUT.C - Outputs an objectfile
*
* Output a binary file
*
*/
/*
* Output a binary file
*/
void void
out_BinaryFile(char *s) out_BinaryFile(char *s)
{ {

View File

@@ -1,8 +1,5 @@
/* /*
* RGBAsm - RPN.C - Controls RPN expressions for objectfiles * Controls RPN expressions for objectfiles
*
* INCLUDES
*
*/ */
#include <stdio.h> #include <stdio.h>
@@ -29,49 +26,26 @@ mergetwoexpressions(struct Expression * expr, struct Expression * src1,
#define joinexpr() mergetwoexpressions(expr,src1,src2) #define joinexpr() mergetwoexpressions(expr,src1,src2)
/* /*
* RGBAsm - RPN.C - Controls RPN expressions for objectfiles
*
* VARIABLES
*
*/
//UBYTE rpnexpr[2048];
//ULONG rpnptr = 0;
//ULONG rpnoutptr = 0;
//ULONG reloc = 0;
//ULONG pcrel = 0;
/*
* RGBAsm - RPN.C - Controls RPN expressions for objectfiles
*
* Add a byte to the RPN expression * Add a byte to the RPN expression
*
*/ */
void void
pushbyte(struct Expression * expr, int b) pushbyte(struct Expression * expr, int b)
{ {
expr->tRPN[expr->nRPNLength++] = b & 0xFF; expr->tRPN[expr->nRPNLength++] = b & 0xFF;
} }
/*
* RGBAsm - RPN.C - Controls RPN expressions for objectfiles
*
* Reset the RPN module
*
*/
/*
* Reset the RPN module
*/
void void
rpn_Reset(struct Expression * expr) rpn_Reset(struct Expression * expr)
{ {
expr->nRPNLength = expr->nRPNOut = expr->isReloc = expr->isPCRel = 0; expr->nRPNLength = expr->nRPNOut = expr->isReloc = expr->isPCRel = 0;
} }
/*
* RGBAsm - RPN.C - Controls RPN expressions for objectfiles
*
* Returns the next rpn byte in expression
*
*/
/*
* Returns the next rpn byte in expression
*/
UWORD UWORD
rpn_PopByte(struct Expression * expr) rpn_PopByte(struct Expression * expr)
{ {
@@ -80,37 +54,28 @@ rpn_PopByte(struct Expression * expr)
} else } else
return (expr->tRPN[expr->nRPNOut++]); return (expr->tRPN[expr->nRPNOut++]);
} }
/*
* RGBAsm - RPN.C - Controls RPN expressions for objectfiles
*
* Determine if the current expression is relocatable
*
*/
/*
* Determine if the current expression is relocatable
*/
ULONG ULONG
rpn_isReloc(struct Expression * expr) rpn_isReloc(struct Expression * expr)
{ {
return (expr->isReloc); return (expr->isReloc);
} }
/*
* RGBAsm - RPN.C - Controls RPN expressions for objectfiles
*
* Determine if the current expression can be pc-relative
*
*/
/*
* Determine if the current expression can be pc-relative
*/
ULONG ULONG
rpn_isPCRelative(struct Expression * expr) rpn_isPCRelative(struct Expression * expr)
{ {
return (expr->isPCRel); return (expr->isPCRel);
} }
/*
* RGBAsm - RPN.C - Controls RPN expressions for objectfiles
*
* Add symbols, constants and operators to expression
*
*/
/*
* Add symbols, constants and operators to expression
*/
void void
rpn_Number(struct Expression * expr, ULONG i) rpn_Number(struct Expression * expr, ULONG i)
{ {
@@ -187,6 +152,7 @@ rpn_RangeCheck(struct Expression * expr, struct Expression * src, SLONG low,
return (expr->nVal >= low && expr->nVal <= high); return (expr->nVal >= low && expr->nVal <= high);
} }
} }
void void
rpn_CheckHRAM(struct Expression * expr, struct Expression * src) rpn_CheckHRAM(struct Expression * expr, struct Expression * src)
{ {

View File

@@ -1,8 +1,5 @@
/* /*
* RGBAsm - SYMBOL.C - Symboltable and macroargs stuff * Symboltable and macroargs stuff
*
* INCLUDES
*
*/ */
#include <assert.h> #include <assert.h>
@@ -16,13 +13,6 @@
#include "asm/mymath.h" #include "asm/mymath.h"
#include "asm/output.h" #include "asm/output.h"
/*
* RGBAsm - SYMBOL.C - Symboltable stuff
*
* VARIABLES
*
*/
struct sSymbol *tHashedSymbols[HASHSIZE]; struct sSymbol *tHashedSymbols[HASHSIZE];
struct sSymbol *pScope = NULL; struct sSymbol *pScope = NULL;
struct sSymbol *pPCSymbol = NULL; struct sSymbol *pPCSymbol = NULL;
@@ -44,12 +34,8 @@ Callback_NARG(struct sSymbol * sym)
} }
/* /*
* RGBAsm - SYMBOL.C - Symboltable stuff
*
* Get the nValue field of a symbol * Get the nValue field of a symbol
*
*/ */
SLONG SLONG
getvaluefield(struct sSymbol * sym) getvaluefield(struct sSymbol * sym)
{ {
@@ -58,13 +44,10 @@ getvaluefield(struct sSymbol * sym)
} else } else
return (sym->nValue); return (sym->nValue);
} }
/*
* RGBAsm - SYMBOL.C - Symboltable stuff
*
* Calculate the hash value for a string
*
*/
/*
* Calculate the hash value for a string
*/
ULONG ULONG
calchash(char *s) calchash(char *s)
{ {
@@ -75,13 +58,10 @@ calchash(char *s)
return (hash % HASHSIZE); return (hash % HASHSIZE);
} }
/*
* RGBAsm - SYMBOL.C - Symboltable stuff
*
* Create a new symbol by name
*
*/
/*
* Create a new symbol by name
*/
struct sSymbol * struct sSymbol *
createsymbol(char *s) createsymbol(char *s)
{ {
@@ -110,12 +90,8 @@ createsymbol(char *s)
} }
} }
/* /*
* RGBAsm - SYMBOL.C - Symboltable stuff
*
* Find a symbol by name and scope * Find a symbol by name and scope
*
*/ */
struct sSymbol * struct sSymbol *
findsymbol(char *s, struct sSymbol * scope) findsymbol(char *s, struct sSymbol * scope)
{ {
@@ -134,13 +110,10 @@ findsymbol(char *s, struct sSymbol * scope)
} }
return (NULL); return (NULL);
} }
/*
* RGBAsm - SYMBOL.C - Symboltable stuff
*
* Find the pointer to a symbol by name and scope
*
*/
/*
* Find the pointer to a symbol by name and scope
*/
struct sSymbol ** struct sSymbol **
findpsymbol(char *s, struct sSymbol * scope) findpsymbol(char *s, struct sSymbol * scope)
{ {
@@ -159,13 +132,10 @@ findpsymbol(char *s, struct sSymbol * scope)
} }
return (NULL); return (NULL);
} }
/*
* RGBAsm - SYMBOL.C - Symboltable stuff
*
* Find a symbol by name and scope
*
*/
/*
* Find a symbol by name and scope
*/
struct sSymbol * struct sSymbol *
sym_FindSymbol(char *tzName) sym_FindSymbol(char *tzName)
{ {
@@ -178,13 +148,10 @@ sym_FindSymbol(char *tzName)
return (findsymbol(tzName, pscope)); return (findsymbol(tzName, pscope));
} }
/*
* RGBAsm - SYMBOL.C - Symboltable stuff
*
* Purge a symbol
*
*/
/*
* Purge a symbol
*/
void void
sym_Purge(char *tzName) sym_Purge(char *tzName)
{ {
@@ -212,13 +179,10 @@ sym_Purge(char *tzName)
yyerror("'%s' not defined", tzName); yyerror("'%s' not defined", tzName);
} }
} }
/*
* RGBAsm - SYMBOL.C - Symboltable stuff
*
* Determine if a symbol has been defined
*
*/
/*
* Determine if a symbol has been defined
*/
ULONG ULONG
sym_isConstDefined(char *tzName) sym_isConstDefined(char *tzName)
{ {
@@ -260,13 +224,10 @@ sym_isDefined(char *tzName)
else else
return (0); return (0);
} }
/*
* RGBAsm - SYMBOL.C - Symboltable stuff
*
* Determine if the symbol is a constant
*
*/
/*
* Determine if the symbol is a constant
*/
ULONG ULONG
sym_isConstant(char *s) sym_isConstant(char *s)
{ {
@@ -283,13 +244,10 @@ sym_isConstant(char *s)
} }
return (0); return (0);
} }
/*
* RGBAsm - SYMBOL.C - Symboltable stuff
*
* Get a string equate's value
*
*/
/*
* Get a string equate's value
*/
char * char *
sym_GetStringValue(char *tzSym) sym_GetStringValue(char *tzSym)
{ {
@@ -303,13 +261,10 @@ sym_GetStringValue(char *tzSym)
return (NULL); return (NULL);
} }
/*
* RGBAsm - SYMBOL.C - Symboltable stuff
*
* Return a constant symbols value
*
*/
/*
* Return a constant symbols value
*/
ULONG ULONG
sym_GetConstantValue(char *s) sym_GetConstantValue(char *s)
{ {
@@ -332,13 +287,10 @@ sym_GetConstantValue(char *s)
return (0); return (0);
} }
/*
* RGBAsm - SYMBOL.C - Symboltable stuff
*
* Return a symbols value... "estimated" if not defined yet
*
*/
/*
* Return a symbols value... "estimated" if not defined yet
*/
ULONG ULONG
sym_GetValue(char *s) sym_GetValue(char *s)
{ {
@@ -374,13 +326,10 @@ sym_GetValue(char *s)
return (0); return (0);
} }
/*
* RGBAsm - SYMBOL.C - Symboltable stuff
*
* Return a defined symbols value... aborts if not defined yet
*
*/
/*
* Return a defined symbols value... aborts if not defined yet
*/
ULONG ULONG
sym_GetDefinedValue(char *s) sym_GetDefinedValue(char *s)
{ {
@@ -406,13 +355,10 @@ sym_GetDefinedValue(char *s)
return (0); return (0);
} }
/*
* RGBAsm - SYMBOL.C - Symboltable stuff
*
* Macro argument stuff
*
*/
/*
* Macro argument stuff
*/
void void
sym_ShiftCurrentMacroArgs(void) sym_ShiftCurrentMacroArgs(void)
{ {
@@ -490,7 +436,7 @@ sym_AddNewMacroArg(char *s)
else else
newmacroargs[i] = NULL; newmacroargs[i] = NULL;
} else } else
yyerror("A maximum of 9 arguments allowed"); yyerror("A maximum of %d arguments allowed", MAXMACROARGS);
} }
void void
@@ -510,25 +456,19 @@ sym_UseCurrentMacroArgs(void)
for (i = 1; i <= MAXMACROARGS; i += 1) for (i = 1; i <= MAXMACROARGS; i += 1)
sym_AddNewMacroArg(sym_FindMacroArg(i)); sym_AddNewMacroArg(sym_FindMacroArg(i));
} }
/*
* RGBAsm - SYMBOL.C - Symboltable stuff
*
* Find a macro by name
*
*/
/*
* Find a macro by name
*/
struct sSymbol * struct sSymbol *
sym_FindMacro(char *s) sym_FindMacro(char *s)
{ {
return (findsymbol(s, NULL)); return (findsymbol(s, NULL));
} }
/*
* RGBAsm - SYMBOL.C - Symboltable stuff
*
* Add an equated symbol
*
*/
/*
* Add an equated symbol
*/
void void
sym_AddEqu(char *tzSym, SLONG value) sym_AddEqu(char *tzSym, SLONG value)
{ {
@@ -551,13 +491,10 @@ sym_AddEqu(char *tzSym, SLONG value)
} }
} }
} }
/*
* RGBAsm - SYMBOL.C - Symboltable stuff
*
* Add a string equated symbol
*
*/
/*
* Add a string equated symbol
*/
void void
sym_AddString(char *tzSym, char *tzValue) sym_AddString(char *tzSym, char *tzValue)
{ {
@@ -580,13 +517,10 @@ sym_AddString(char *tzSym, char *tzValue)
nsym->pScope = NULL; nsym->pScope = NULL;
} }
} }
/*
* RGBAsm - SYMBOL.C - Symboltable stuff
*
* check if symbol is a string equated symbol
*
*/
/*
* check if symbol is a string equated symbol
*/
ULONG ULONG
sym_isString(char *tzSym) sym_isString(char *tzSym)
{ {
@@ -598,13 +532,10 @@ sym_isString(char *tzSym)
} }
return (0); return (0);
} }
/*
* RGBAsm - SYMBOL.C - Symboltable stuff
*
* Alter a SET symbols value
*
*/
/*
* Alter a SET symbols value
*/
void void
sym_AddSet(char *tzSym, SLONG value) sym_AddSet(char *tzSym, SLONG value)
{ {
@@ -620,13 +551,10 @@ sym_AddSet(char *tzSym, SLONG value)
nsym->pScope = NULL; nsym->pScope = NULL;
} }
} }
/*
* RGBAsm - SYMBOL.C - Symboltable stuff
*
* Add a local (.name) relocatable symbol
*
*/
/*
* Add a local (.name) relocatable symbol
*/
void void
sym_AddLocalReloc(char *tzSym) sym_AddLocalReloc(char *tzSym)
{ {
@@ -654,13 +582,10 @@ sym_AddLocalReloc(char *tzSym)
fatalerror("Local label in main scope"); fatalerror("Local label in main scope");
} }
} }
/*
* RGBAsm - SYMBOL.C - Symboltable stuff
*
* Add a relocatable symbol
*
*/
/*
* Add a relocatable symbol
*/
void void
sym_AddReloc(char *tzSym) sym_AddReloc(char *tzSym)
{ {
@@ -684,15 +609,11 @@ sym_AddReloc(char *tzSym)
} }
} }
pScope = findsymbol(tzSym, NULL); pScope = findsymbol(tzSym, NULL);
} }
/*
* RGBAsm - SYMBOL.C - Symboltable stuff
*
* Export a symbol
*
*/
/*
* Export a symbol
*/
void void
sym_Export(char *tzSym) sym_Export(char *tzSym)
{ {
@@ -716,13 +637,10 @@ sym_Export(char *tzSym)
} }
} }
/*
* RGBAsm - SYMBOL.C - Symboltable stuff
*
* Import a symbol
*
*/
/*
* Import a symbol
*/
void void
sym_Import(char *tzSym) sym_Import(char *tzSym)
{ {
@@ -737,13 +655,10 @@ sym_Import(char *tzSym)
nsym->nType |= SYMF_IMPORT; nsym->nType |= SYMF_IMPORT;
} }
} }
/*
* RGBAsm - SYMBOL.C - Symboltable stuff
*
* Globalize a symbol (export if defined, import if not)
*
*/
/*
* Globalize a symbol (export if defined, import if not)
*/
void void
sym_Global(char *tzSym) sym_Global(char *tzSym)
{ {
@@ -765,13 +680,10 @@ sym_Global(char *tzSym)
} }
} }
} }
/*
* RGBAsm - SYMBOL.C - Symboltable stuff
*
* Add a macro definition
*
*/
/*
* Add a macro definition
*/
void void
sym_AddMacro(char *tzSym) sym_AddMacro(char *tzSym)
{ {
@@ -796,25 +708,19 @@ sym_AddMacro(char *tzSym)
} }
} }
} }
/*
* RGBAsm - SYMBOL.C - Symboltable stuff
*
* Prepare for pass #1
*
*/
/*
* Prepare for pass #1
*/
void void
sym_PrepPass1(void) sym_PrepPass1(void)
{ {
sym_Init(); sym_Init();
} }
/*
* RGBAsm - SYMBOL.C - Symboltable stuff
*
* Prepare for pass #2
*
*/
/*
* Prepare for pass #2
*/
void void
sym_PrepPass2(void) sym_PrepPass2(void)
{ {
@@ -846,13 +752,10 @@ sym_PrepPass2(void)
p_NARGSymbol = findsymbol("_NARG", NULL); p_NARGSymbol = findsymbol("_NARG", NULL);
p_NARGSymbol->Callback = Callback_NARG; p_NARGSymbol->Callback = Callback_NARG;
} }
/*
* RGBAsm - SYMBOL.C - Symboltable stuff
*
* Initialise the symboltable
*
*/
/*
* Initialize the symboltable
*/
void void
sym_Init(void) sym_Init(void)
{ {
@@ -889,72 +792,3 @@ sym_Init(void)
math_DefinePI(); math_DefinePI();
} }
/*
* RGBAsm - SYMBOL.C - Symboltable stuff
*
* DEBUG: Print the symbol table
*
*/
void
sym_PrintSymbolTable(void)
{
ULONG i;
for (i = 0; i < HASHSIZE; i += 1) {
struct sSymbol *sym = tHashedSymbols[i];
if (sym != NULL)
printf("\nHashTable #%ld:\n", i);
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)) {
ULONG i = 0;
printf("MACRO : '%s'\n\"", sym->tzName);
while (i < sym->ulMacroSize) {
if (sym->pMacro[i] == '\n') {
printf("\n");
i += 1;
} 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_IMPORT)
printf("IMPORT: '%s'\n", sym->tzName);
else if (sym->nType & SYMF_EQU)
printf("EQU : '%s' - %08lX\n", sym->tzName,
getvaluefield(sym));
else if (sym->nType & SYMF_SET)
printf("SET : '%s' - %08lX\n", sym->tzName,
getvaluefield(sym));
else
printf("SYMBOL: '%s' - %08lX\n", sym->tzName,
getvaluefield(sym));
sym = sym->pNext;
}
}
}
/*
* RGBAsm - SYMBOL.C - Symboltable stuff
*
* DEBUG: Dump the macroargs
*
*/
void
sym_DumpMacroArgs(void)
{
ULONG i;
for (i = 0; i < MAXMACROARGS; i += 1)
printf("CurrentArg%ld: %s\n", i + 1, currentmacroargs[i]);
}

View File

@@ -26,10 +26,10 @@
static void static void
usage(void) usage(void)
{ {
printf("usage: rgbfix [-Ccjsv] [-i game_id] [-k licensee_str] " printf(
"[-l licensee_id]\n" " [-m mbc_type] [-n rom_version] " "usage: rgbfix [-Ccjsv] [-i game_id] [-k licensee_str] [-l licensee_id]\n"
"[-p pad_value] [-r ram_size]\n" " [-m mbc_type] [-n rom_version] [-p pad_value] [-r ram_size]\n"
" [-t title_str] file.gb\n"); " [-t title_str] file\n");
exit(1); exit(1);
} }
@@ -40,17 +40,6 @@ main(int argc, char *argv[])
int ch; int ch;
char *ep; char *ep;
/*
* Open the ROM file
*/
if (argc < 2)
usage();
if ((rom = fopen(argv[argc - 1], "rb+")) == NULL) {
err(1, "Error opening file %s", argv[argc - 1]);
}
/* /*
* Parse command-line options * Parse command-line options
*/ */
@@ -70,15 +59,15 @@ main(int argc, char *argv[])
bool resize = false; bool resize = false;
bool setversion = false; bool setversion = false;
char *title = NULL; /* game title in ASCII */ char *title; /* game title in ASCII */
char *id = NULL; /* game ID in ASCII */ char *id; /* game ID in ASCII */
char *newlicensee = NULL; /* new licensee ID, two ASCII characters */ char *newlicensee; /* new licensee ID, two ASCII characters */
int licensee = -1; /* old licensee ID */ int licensee; /* old licensee ID */
int cartridge = -1; /* cartridge hardware ID */ int cartridge; /* cartridge hardware ID */
int ramsize = -1; /* RAM size ID */ int ramsize; /* RAM size ID */
int version = -1; /* mask ROM version number */ int version; /* mask ROM version number */
int padvalue = -1; /* to pad the rom with if it changes size */ int padvalue; /* to pad the rom with if it changes size */
while ((ch = getopt(argc, argv, "Cci:jk:l:m:n:p:sr:t:v")) != -1) { while ((ch = getopt(argc, argv, "Cci:jk:l:m:n:p:sr:t:v")) != -1) {
switch (ch) { switch (ch) {
@@ -197,6 +186,20 @@ main(int argc, char *argv[])
} }
} }
argc -= optind;
argv += optind;
if (argc == 0)
usage();
/*
* Open the ROM file
*/
if ((rom = fopen(argv[argc - 1], "rb+")) == NULL) {
err(1, "Error opening file %s", argv[argc - 1]);
}
/* /*
* Write changes to ROM * Write changes to ROM
*/ */

View File

@@ -32,9 +32,9 @@ char smartlinkstartsymbol[256];
static void static void
usage(void) usage(void)
{ {
printf("usage: rgblink [-t] [-m mapfile] [-n symfile] [-o outfile]\n"); printf(
printf("\t [-s symbol] [-z pad_value] objectfile [...]\n"); "usage: rgblink [-t] [-m mapfile] [-n symfile] [-o outfile] [-s symbol]\n"
" [-z pad_value] file [...]\n");
exit(1); exit(1);
} }

View File

@@ -72,14 +72,13 @@ MapfileInitBank(SLONG bank)
void void
MapfileWriteSection(struct sSection * pSect) MapfileWriteSection(struct sSection * pSect)
{ {
if (!mf && !sf)
return;
SLONG i; SLONG i;
fprintf(mf, " SECTION: $%04lX-$%04lX ($%04lX bytes)\n", if (mf) {
pSect->nOrg, pSect->nOrg + pSect->nByteSize - 1, fprintf(mf, " SECTION: $%04lX-$%04lX ($%04lX bytes)\n",
pSect->nByteSize); pSect->nOrg, pSect->nOrg + pSect->nByteSize - 1,
pSect->nByteSize);
}
for (i = 0; i < pSect->nNumberOfSymbols; i += 1) { for (i = 0; i < pSect->nNumberOfSymbols; i += 1) {
struct sSymbol *pSym; struct sSymbol *pSym;