Compare commits

...

29 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
Anthony J. Bentley
513d451710 Tweak path for stdnoreturn.h header. 2014-12-31 03:21:46 -07:00
Anthony J. Bentley
9399ba36f9 Check for standards‐compliant platforms first in stdnoreturn.h. 2014-12-31 03:20:14 -07:00
Anthony J. Bentley
ef3a486845 Request POSIX 2008 for strdup(). 2014-12-31 03:18:01 -07:00
stag019
f0e5c5ccc8 Cross-compiler noreturn support. 2014-12-31 04:11:06 -05:00
stag019
9b4959cb75 Implement round, ceil, and floor math functions. 2014-12-17 01:30:19 -05:00
stag019
dca82e6d95 Fix DEF() automatically converting string EQUS. 2014-11-07 16:42:55 -05:00
stag019
871c5ed360 We aren't kidding ourselves anymore. This is a Gameboy assembler, not any sort of generic assembler. 2014-11-07 16:36:03 -05:00
Anthony J. Bentley
635014b74d On Clang, error on implicit function declaration by default. 2014-11-06 21:54:49 -07:00
Anthony J. Bentley
7ad634febd Don’t assign to self. 2014-11-06 21:42:40 -07:00
Anthony J. Bentley
1e1339467e Use POSIX 2001 as the base standard. 2014-11-06 21:39:36 -07:00
Anthony J. Bentley
9e24c26468 Specify _Noreturn in the err family prototypes. 2014-11-06 21:36:27 -07:00
26 changed files with 2015 additions and 2412 deletions

View File

@@ -1,6 +1,8 @@
.POSIX:
REALCFLAGS = ${CFLAGS} -Wall -Iinclude -Iinclude/asm/gameboy -g -std=c99
WARNFLAGS = -Wall -Werror=implicit
REALCFLAGS = ${CFLAGS} ${WARNFLAGS} -Iinclude -g \
-std=c99 -D_POSIX_C_SOURCE=200809L
# User-defined variables
PREFIX = /usr/local
@@ -8,13 +10,7 @@ BINPREFIX = ${PREFIX}/bin
MANPREFIX = ${PREFIX}/man
Q = @
yacc_pre := \
src/asm/yaccprt1.y\
src/asm/gameboy/yaccprt2.y\
src/asm/yaccprt3.y\
src/asm/gameboy/yaccprt4.y
rgbasm_obj := \
rgbasm_obj = \
src/asm/asmy.o \
src/asm/charmap.o \
src/asm/fstack.o \
@@ -25,12 +21,12 @@ rgbasm_obj := \
src/asm/output.o \
src/asm/rpn.o \
src/asm/symbol.o \
src/asm/gameboy/locallex.o \
src/asm/locallex.o \
src/extern/err.o \
src/extern/strlcpy.o \
src/extern/strlcat.o
rgblink_obj := \
rgblink_obj = \
src/link/assign.o \
src/link/library.o \
src/link/main.o \
@@ -41,7 +37,7 @@ rgblink_obj := \
src/link/symbol.o \
src/extern/err.o
rgbfix_obj := \
rgbfix_obj = \
src/fix/main.o \
src/extern/err.o
@@ -52,7 +48,7 @@ clean:
$Qrm -rf rgbasm rgbasm.exe ${rgbasm_obj} rgbasm.html
$Qrm -rf rgblink rgblink.exe ${rgblink_obj} rgblink.html
$Qrm -rf rgbfix rgbfix.exe ${rgbfix_obj} rgbfix.html
$Qrm -rf src/asm/asmy.c src/asm/asmy.h src/asm/asmy.y
$Qrm -rf src/asm/asmy.c src/asm/asmy.h
install: all
$Qmkdir -p ${BINPREFIX}
@@ -80,13 +76,9 @@ rgbfix: ${rgbfix_obj}
.c.o:
$Q${CC} ${REALCFLAGS} -c -o $@ $<
src/asm/gameboy/locallex.o src/asm/globlex.o src/asm/lexer.o: src/asm/asmy.h
src/asm/locallex.o src/asm/globlex.o src/asm/lexer.o: src/asm/asmy.h
src/asm/asmy.h: src/asm/asmy.c
src/asm/asmy.y: ${yacc_pre}
$Qcat ${yacc_pre} > $@
# Below is a target for the project maintainer to easily create win32 exes.
# This is not for Windows users!
# If you're building on Windows with Cygwin or Mingw, just follow the Unix
@@ -95,7 +87,7 @@ mingw:
$Qenv PATH=/usr/local/mingw32/bin:/bin:/usr/bin:/usr/local/bin \
make CC=gcc CFLAGS="-I/usr/local/mingw32/include \
-D__progname=\\\"\\\" \
-D_Noreturn='__attribute__((noreturn))' ${CFLAGS}"
${CFLAGS}"
$Qmv rgbasm rgbasm.exe
$Qmv rgblink rgblink.exe
$Qmv rgbfix rgbfix.exe

View File

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

View File

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

View File

@@ -14,5 +14,8 @@ SLONG math_ATan(SLONG i);
SLONG math_ATan2(SLONG i, SLONG j);
SLONG math_Mul(SLONG i, SLONG j);
SLONG math_Div(SLONG i, SLONG j);
SLONG math_Round(SLONG i);
SLONG math_Ceil(SLONG i);
SLONG math_Floor(SLONG i);
#endif

View File

@@ -29,6 +29,7 @@
#else
#include <stdarg.h>
#include "stdnoreturn.h"
#define warn rgbds_warn
#define vwarn rgbds_vwarn
@@ -49,10 +50,10 @@ void vwarn(const char *, va_list);
void warnx(const char *, ...);
void vwarnx(const char *, va_list);
void err(int, const char *, ...);
void verr(int, const char *, va_list);
void errx(int, const char *, ...);
void verrx(int, const char *, va_list);
noreturn void err(int, const char *, ...);
noreturn void verr(int, const char *, va_list);
noreturn void errx(int, const char *, ...);
noreturn void verrx(int, const char *, va_list);
#ifdef __cplusplus
}

16
include/extern/stdnoreturn.h vendored Normal file
View File

@@ -0,0 +1,16 @@
#if __STDC_VERSION__ >= 201112L
// C11 or newer
#define noreturn _Noreturn
#elif __cplusplus >= 201103L
// C++11 or newer
#define noreturn [[noreturn]]
#elif __GNUC__ > 2 || (__GNUC__ == 2 && (__GNUC_MINOR__ >= 5))
// GCC 2.5 or newer
#define noreturn __attribute__ ((noreturn))
#elif _MSC_VER >= 1310
// MS Visual Studio 2003/.NET Framework 1.1 or newer
#define noreturn _declspec( noreturn)
#else
// unsupported, but no need to throw a fit
#define noreturn
#endif

1
src/asm/.gitignore vendored
View File

@@ -1,3 +1,2 @@
asmy.c
asmy.h
asmy.y

1597
src/asm/asmy.y Normal file

File diff suppressed because it is too large Load Diff

View File

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

View File

@@ -1,41 +0,0 @@
%token T_SECT_WRAM0 T_SECT_VRAM T_SECT_ROMX T_SECT_ROM0 T_SECT_HRAM T_SECT_WRAMX T_SECT_SRAM
%token T_Z80_ADC T_Z80_ADD T_Z80_AND
%token T_Z80_BIT
%token T_Z80_CALL T_Z80_CCF T_Z80_CP T_Z80_CPL
%token T_Z80_DAA T_Z80_DEC T_Z80_DI
%token T_Z80_EI T_Z80_EX
%token T_Z80_HALT
%token T_Z80_INC
%token T_Z80_JP T_Z80_JR
%token T_Z80_LD
%token T_Z80_LDI
%token T_Z80_LDD
%token T_Z80_LDIO
%token T_Z80_NOP
%token T_Z80_OR
%token T_Z80_POP T_Z80_PUSH
%token T_Z80_RES T_Z80_RET T_Z80_RETI T_Z80_RST
%token T_Z80_RL T_Z80_RLA T_Z80_RLC T_Z80_RLCA
%token T_Z80_RR T_Z80_RRA T_Z80_RRC T_Z80_RRCA
%token T_Z80_SBC T_Z80_SCF T_Z80_STOP
%token T_Z80_SLA T_Z80_SRA T_Z80_SRL T_Z80_SUB T_Z80_SWAP
%token T_Z80_XOR
%token T_MODE_A T_MODE_B T_MODE_C T_MODE_C_IND T_MODE_D T_MODE_E T_MODE_H T_MODE_L
%token T_MODE_AF
%token T_MODE_BC T_MODE_BC_IND
%token T_MODE_DE T_MODE_DE_IND
%token T_MODE_SP T_MODE_SP_IND
%token T_MODE_HL T_MODE_HL_IND T_MODE_HL_INDDEC T_MODE_HL_INDINC
%token T_CC_NZ T_CC_Z T_CC_NC
%type <nConstValue> reg_r
%type <nConstValue> reg_ss
%type <nConstValue> reg_rr
%type <nConstValue> reg_tt
%type <nConstValue> ccode
%type <sVal> op_a_n
%type <nConstValue> op_a_r
%type <nConstValue> op_hl_ss
%type <sVal> op_mem_ind

View File

@@ -1,557 +0,0 @@
section:
T_POP_SECTION string ',' sectiontype
{
out_NewSection($2,$4);
}
| T_POP_SECTION string ',' sectiontype '[' const ']'
{
if( $6>=0 && $6<0x10000 )
out_NewAbsSection($2,$4,$6,-1);
else
yyerror("Address $%x not 16-bit", $6);
}
| T_POP_SECTION string ',' sectiontype ',' T_OP_BANK '[' const ']'
{
if( $4==SECT_ROMX ) {
if( $8>=1 && $8<=0x1ff )
out_NewAbsSection($2,$4,-1,$8);
else
yyerror("ROM bank value $%x out of range (1 to $1ff)", $8);
} else if ($4 == SECT_SRAM) {
if ($8 >= 0 && $8 <= 3) {
out_NewAbsSection($2, $4, -1, $8);
} else {
yyerror("SRAM bank value $%x out of range (0 to 3)", $8);
}
} else if ($4 == SECT_WRAMX) {
if ($8 >= 1 && $8 <= 7) {
out_NewAbsSection($2, $4, -1, $8);
} else {
yyerror("WRAMX bank value $%x out of range (1 to 7)", $8);
}
} else if ($4 == SECT_VRAM) {
if ($8 >= 0 && $8 <= 1) {
out_NewAbsSection($2, $4, -1, $8);
} else {
yyerror("VRAM bank value $%x out of range (0 to 1)", $8);
}
} else {
yyerror("BANK only allowed for ROMX, WRAMX, SRAM, or VRAM sections");
}
}
| T_POP_SECTION string ',' sectiontype '[' const ']' ',' T_OP_BANK '[' const ']'
{
if( $4==SECT_ROMX ) {
if( $6>=0 && $6<0x10000 ) {
if( $11>=1 && $11<=0x1ff )
out_NewAbsSection($2,$4,$6,$11);
else
yyerror("ROM bank value $%x out of range (1 to $1ff)", $11);
} else
yyerror("Address $%x not 16-bit", $6);
} else if ($4 == SECT_SRAM) {
if ($6 >= 0 && $6 < 0x10000) {
if ($11 >= 0 && $11 <= 3) {
out_NewAbsSection($2, $4, $6, $11);
} else {
yyerror("SRAM bank value $%x out of range (0 to 3)", $11);
}
} else {
yyerror("Address $%x not 16-bit", $6);
}
} else if ($4 == SECT_WRAMX) {
if ($6 >= 0 && $6 < 0x10000) {
if ($11 >= 1 && $11 <= 7) {
out_NewAbsSection($2, $4, $6, $11);
} else {
yyerror("WRAMX bank value $%x out of range (1 to 7)", $11);
}
} else {
yyerror("Address $%x not 16-bit", $6);
}
} else if ($4 == SECT_VRAM) {
if ($6 >= 0 && $6 < 0x10000) {
if ($11 >= 0 && $11 <= 1) {
out_NewAbsSection($2,$4,$6,$11);
} else {
yyerror("VRAM bank value $%x out of range (0 to 1)", $11);
}
} else {
yyerror("Address $%x not 16-bit", $6);
}
} else {
yyerror("BANK only allowed for ROMX, WRAMX, SRAM, or VRAM sections");
}
}
;
sectiontype:
T_SECT_WRAM0 { $$=SECT_WRAM0; }
| T_SECT_VRAM { $$=SECT_VRAM; }
| T_SECT_ROMX { $$=SECT_ROMX; }
| T_SECT_ROM0 { $$=SECT_ROM0; }
| T_SECT_HRAM { $$=SECT_HRAM; }
| T_SECT_WRAMX { $$=SECT_WRAMX; }
| T_SECT_SRAM { $$=SECT_SRAM; }
;
cpu_command : z80_adc
| z80_add
| z80_and
| z80_bit
| z80_call
| z80_ccf
| z80_cp
| z80_cpl
| z80_daa
| z80_dec
| z80_di
| z80_ei
| z80_ex
| z80_halt
| z80_inc
| z80_jp
| z80_jr
| z80_ld
| z80_ldd
| z80_ldi
| z80_ldio
| z80_nop
| z80_or
| z80_pop
| z80_push
| z80_res
| z80_ret
| z80_reti
| z80_rl
| z80_rla
| z80_rlc
| z80_rlca
| z80_rr
| z80_rra
| z80_rrc
| z80_rrca
| z80_rst
| z80_sbc
| z80_scf
| z80_set
| z80_sla
| z80_sra
| z80_srl
| z80_stop
| z80_sub
| z80_swap
| z80_xor
;
z80_adc : T_Z80_ADC op_a_n { out_AbsByte(0xCE); out_RelByte(&$2); }
| T_Z80_ADC op_a_r { out_AbsByte(0x88|$2); }
;
z80_add : T_Z80_ADD op_a_n { out_AbsByte(0xC6); out_RelByte(&$2); }
| T_Z80_ADD op_a_r { out_AbsByte(0x80|$2); }
| T_Z80_ADD op_hl_ss { out_AbsByte(0x09|($2<<4)); }
| T_Z80_ADD T_MODE_SP comma const_8bit
{ out_AbsByte(0xE8); out_RelByte(&$4); }
;
z80_and : T_Z80_AND op_a_n { out_AbsByte(0xE6); out_RelByte(&$2); }
| T_Z80_AND op_a_r { out_AbsByte(0xA0|$2); }
;
z80_bit : T_Z80_BIT const_3bit comma reg_r
{ out_AbsByte(0xCB); out_AbsByte(0x40|($2<<3)|$4); }
;
z80_call : T_Z80_CALL const_16bit
{ out_AbsByte(0xCD); out_RelWord(&$2); }
| T_Z80_CALL ccode comma const_16bit
{ out_AbsByte(0xC4|($2<<3)); out_RelWord(&$4); }
;
z80_ccf : T_Z80_CCF
{ out_AbsByte(0x3F); }
;
z80_cp : T_Z80_CP op_a_n { out_AbsByte(0xFE); out_RelByte(&$2); }
| T_Z80_CP op_a_r { out_AbsByte(0xB8|$2); }
;
z80_cpl : T_Z80_CPL { out_AbsByte(0x2F); }
;
z80_daa : T_Z80_DAA { out_AbsByte(0x27); }
;
z80_dec : T_Z80_DEC reg_r
{ out_AbsByte(0x05|($2<<3)); }
| T_Z80_DEC reg_ss
{ out_AbsByte(0x0B|($2<<4)); }
;
z80_di : T_Z80_DI
{ out_AbsByte(0xF3); }
;
z80_ei : T_Z80_EI
{ out_AbsByte(0xFB); }
;
z80_ex : T_Z80_EX T_MODE_HL comma T_MODE_SP_IND
{ out_AbsByte(0xE3); }
| T_Z80_EX T_MODE_SP_IND comma T_MODE_HL
{ out_AbsByte(0xE3); }
;
z80_halt: T_Z80_HALT
{
out_AbsByte(0x76);
if (haltnop) {
out_AbsByte(0x00);
}
}
;
z80_inc : T_Z80_INC reg_r
{ out_AbsByte(0x04|($2<<3)); }
| T_Z80_INC reg_ss
{ out_AbsByte(0x03|($2<<4)); }
;
z80_jp : T_Z80_JP const_16bit
{ out_AbsByte(0xC3); out_RelWord(&$2); }
| T_Z80_JP ccode comma const_16bit
{ out_AbsByte(0xC2|($2<<3)); out_RelWord(&$4); }
| T_Z80_JP T_MODE_HL_IND
{ out_AbsByte(0xE9); }
| T_Z80_JP T_MODE_HL
{ out_AbsByte(0xE9); }
;
z80_jr : T_Z80_JR const_PCrel
{ out_AbsByte(0x18); out_PCRelByte(&$2); }
| T_Z80_JR ccode comma const_PCrel
{ out_AbsByte(0x20|($2<<3)); out_PCRelByte(&$4); }
;
z80_ldi : T_Z80_LDI T_MODE_HL_IND comma T_MODE_A
{ out_AbsByte(0x02|(2<<4)); }
| T_Z80_LDI T_MODE_A comma T_MODE_HL
{ out_AbsByte(0x0A|(2<<4)); }
;
z80_ldd : T_Z80_LDD T_MODE_HL_IND comma T_MODE_A
{ out_AbsByte(0x02|(3<<4)); }
| T_Z80_LDD T_MODE_A comma T_MODE_HL
{ out_AbsByte(0x0A|(3<<4)); }
;
z80_ldio : T_Z80_LDIO T_MODE_A comma op_mem_ind
{
rpn_CheckHRAM(&$4,&$4);
if( (!rpn_isReloc(&$4))
&& ($4.nVal<0 || ($4.nVal>0xFF && $4.nVal<0xFF00) || $4.nVal>0xFFFF) )
{
yyerror("Source address $%x not in HRAM ($FF00 to $FFFE)", $4.nVal);
}
out_AbsByte(0xF0);
$4.nVal&=0xFF;
out_RelByte(&$4);
}
| T_Z80_LDIO op_mem_ind comma T_MODE_A
{
rpn_CheckHRAM(&$2,&$2);
if( (!rpn_isReloc(&$2))
&& ($2.nVal<0 || ($2.nVal>0xFF && $2.nVal<0xFF00) || $2.nVal>0xFFFF) )
{
yyerror("Destination address $%x not in HRAM ($FF00 to $FFFE)", $2.nVal);
}
out_AbsByte(0xE0);
$2.nVal&=0xFF;
out_RelByte(&$2);
}
;
z80_ld : z80_ld_mem
| z80_ld_cind
| z80_ld_rr
| z80_ld_ss
| z80_ld_hl
| z80_ld_sp
| z80_ld_r
| z80_ld_a
;
z80_ld_hl : T_Z80_LD T_MODE_HL comma '[' T_MODE_SP const_8bit ']'
{ out_AbsByte(0xF8); out_RelByte(&$6); }
| T_Z80_LD T_MODE_HL comma T_MODE_SP const_8bit
{ out_AbsByte(0xF8); out_RelByte(&$5); }
| T_Z80_LD T_MODE_HL comma const_16bit
{ out_AbsByte(0x01|(REG_HL<<4)); out_RelWord(&$4); }
;
z80_ld_sp : T_Z80_LD T_MODE_SP comma T_MODE_HL
{ out_AbsByte(0xF9); }
| T_Z80_LD T_MODE_SP comma const_16bit
{ out_AbsByte(0x01|(REG_SP<<4)); out_RelWord(&$4); }
;
z80_ld_mem : T_Z80_LD op_mem_ind comma T_MODE_SP
{ out_AbsByte(0x08); out_RelWord(&$2); }
| T_Z80_LD op_mem_ind comma T_MODE_A
{
if( (!rpn_isReloc(&$2)) && $2.nVal>=0xFF00)
{
out_AbsByte(0xE0);
out_AbsByte($2.nVal&0xFF);
}
else
{
out_AbsByte(0xEA);
out_RelWord(&$2);
}
}
;
z80_ld_cind : T_Z80_LD T_MODE_C_IND comma T_MODE_A
{ out_AbsByte(0xE2); }
;
z80_ld_rr : T_Z80_LD reg_rr comma T_MODE_A
{ out_AbsByte(0x02|($2<<4)); }
;
z80_ld_r : T_Z80_LD reg_r comma const_8bit
{ out_AbsByte(0x06|($2<<3)); out_RelByte(&$4); }
| T_Z80_LD reg_r comma reg_r
{
if( ($2==REG_HL_IND) && ($4==REG_HL_IND) )
{
yyerror("LD [HL],[HL] not a valid instruction");
}
else
out_AbsByte(0x40|($2<<3)|$4);
}
;
z80_ld_a : T_Z80_LD reg_r comma T_MODE_C_IND
{
if( $2==REG_A )
out_AbsByte(0xF2);
else
{
yyerror("Destination operand must be A");
}
}
| T_Z80_LD reg_r comma reg_rr
{
if( $2==REG_A )
out_AbsByte(0x0A|($4<<4));
else
{
yyerror("Destination operand must be A");
}
}
| T_Z80_LD reg_r comma op_mem_ind
{
if( $2==REG_A )
{
if( (!rpn_isReloc(&$4)) && $4.nVal>=0xFF00 )
{
out_AbsByte(0xF0);
out_AbsByte($4.nVal&0xFF);
}
else
{
out_AbsByte(0xFA);
out_RelWord(&$4);
}
}
else
{
yyerror("Destination operand must be A");
}
}
;
z80_ld_ss : T_Z80_LD reg_ss comma const_16bit
{ out_AbsByte(0x01|($2<<4)); out_RelWord(&$4); }
;
z80_nop : T_Z80_NOP
{ out_AbsByte(0x00); }
;
z80_or : T_Z80_OR op_a_n
{ out_AbsByte(0xF6); out_RelByte(&$2); }
| T_Z80_OR op_a_r
{ out_AbsByte(0xB0|$2); }
;
z80_pop : T_Z80_POP reg_tt
{ out_AbsByte(0xC1|($2<<4)); }
;
z80_push : T_Z80_PUSH reg_tt
{ out_AbsByte(0xC5|($2<<4)); }
;
z80_res : T_Z80_RES const_3bit comma reg_r
{ out_AbsByte(0xCB); out_AbsByte(0x80|($2<<3)|$4); }
;
z80_ret : T_Z80_RET
{ out_AbsByte(0xC9); }
| T_Z80_RET ccode
{ out_AbsByte(0xC0|($2<<3)); }
;
z80_reti : T_Z80_RETI
{ out_AbsByte(0xD9); }
;
z80_rl : T_Z80_RL reg_r
{ out_AbsByte(0xCB); out_AbsByte(0x10|$2); }
;
z80_rla : T_Z80_RLA
{ out_AbsByte(0x17); }
;
z80_rlc : T_Z80_RLC reg_r
{ out_AbsByte(0xCB); out_AbsByte(0x00|$2); }
;
z80_rlca : T_Z80_RLCA
{ out_AbsByte(0x07); }
;
z80_rr : T_Z80_RR reg_r
{ out_AbsByte(0xCB); out_AbsByte(0x18|$2); }
;
z80_rra : T_Z80_RRA
{ out_AbsByte(0x1F); }
;
z80_rrc : T_Z80_RRC reg_r
{ out_AbsByte(0xCB); out_AbsByte(0x08|$2); }
;
z80_rrca : T_Z80_RRCA
{ out_AbsByte(0x0F); }
;
z80_rst : T_Z80_RST const_8bit
{
if( rpn_isReloc(&$2) )
{
yyerror("Address for RST must be absolute");
}
else if( ($2.nVal&0x38)!=$2.nVal )
{
yyerror("Invalid address $%x for RST", $2.nVal);
}
else
out_AbsByte(0xC7|$2.nVal);
}
;
z80_sbc : T_Z80_SBC op_a_n { out_AbsByte(0xDE); out_RelByte(&$2); }
| T_Z80_SBC op_a_r { out_AbsByte(0x98|$2); }
;
z80_scf : T_Z80_SCF
{ out_AbsByte(0x37); }
;
z80_set : T_POP_SET const_3bit comma reg_r
{ out_AbsByte(0xCB); out_AbsByte(0xC0|($2<<3)|$4); }
;
z80_sla : T_Z80_SLA reg_r
{ out_AbsByte(0xCB); out_AbsByte(0x20|$2); }
;
z80_sra : T_Z80_SRA reg_r
{ out_AbsByte(0xCB); out_AbsByte(0x28|$2); }
;
z80_srl : T_Z80_SRL reg_r
{ out_AbsByte(0xCB); out_AbsByte(0x38|$2); }
;
z80_stop : T_Z80_STOP
{ out_AbsByte(0x10); out_AbsByte(0x00); }
;
z80_sub : T_Z80_SUB op_a_n { out_AbsByte(0xD6); out_RelByte(&$2); }
| T_Z80_SUB op_a_r { out_AbsByte(0x90|$2); }
;
z80_swap : T_Z80_SWAP reg_r
{ out_AbsByte(0xCB); out_AbsByte(0x30|$2); }
;
z80_xor : T_Z80_XOR op_a_n { out_AbsByte(0xEE); out_RelByte(&$2); }
| T_Z80_XOR op_a_r { out_AbsByte(0xA8|$2); }
;
op_mem_ind : '[' const_16bit ']' { $$ = $2; }
;
op_hl_ss : reg_ss { $$ = $1; }
| T_MODE_HL comma reg_ss { $$ = $3; }
;
op_a_r : reg_r { $$ = $1; }
| T_MODE_A comma reg_r { $$ = $3; }
;
op_a_n : const_8bit { $$ = $1; }
| T_MODE_A comma const_8bit { $$ = $3; }
;
comma : ','
;
ccode : T_CC_NZ { $$ = CC_NZ; }
| T_CC_Z { $$ = CC_Z; }
| T_CC_NC { $$ = CC_NC; }
| T_MODE_C { $$ = CC_C; }
;
reg_r : T_MODE_B { $$ = REG_B; }
| T_MODE_C { $$ = REG_C; }
| T_MODE_D { $$ = REG_D; }
| T_MODE_E { $$ = REG_E; }
| T_MODE_H { $$ = REG_H; }
| T_MODE_L { $$ = REG_L; }
| T_MODE_HL_IND { $$ = REG_HL_IND; }
| T_MODE_A { $$ = REG_A; }
;
reg_tt : T_MODE_BC { $$ = REG_BC; }
| T_MODE_DE { $$ = REG_DE; }
| T_MODE_HL { $$ = REG_HL; }
| T_MODE_AF { $$ = REG_AF; }
;
reg_ss : T_MODE_BC { $$ = REG_BC; }
| T_MODE_DE { $$ = REG_DE; }
| T_MODE_HL { $$ = REG_HL; }
| T_MODE_SP { $$ = REG_SP; }
;
reg_rr : T_MODE_BC_IND { $$ = REG_BC_IND; }
| T_MODE_DE_IND { $$ = REG_DE_IND; }
| T_MODE_HL_INDINC { $$ = REG_HL_INDINC; }
| T_MODE_HL_INDDEC { $$ = REG_HL_INDDEC; }
;
%%

View File

@@ -7,12 +7,13 @@
#include "asmy.h"
#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <string.h>
UBYTE oDontExpandStrings = 0;
bool oDontExpandStrings = false;
SLONG nGBGfxID = -1;
SLONG nBinaryID = -1;
@@ -184,7 +185,7 @@ ParseSymbol(char *src, ULONG size)
dest[copied] = 0;
if (oDontExpandStrings == 0 && sym_isString(dest)) {
if (!oDontExpandStrings && sym_isString(dest)) {
char *s;
yyskipbytes(size_backup);
@@ -225,7 +226,6 @@ PutUniqueArg(char *src, ULONG size)
{
char *s;
src = src;
yyskipbytes(size);
if ((s = sym_FindMacroArg(-1)) != NULL) {
yyunputstr(s);
@@ -268,6 +268,9 @@ struct sLexInitString staticstrings[] = {
{"bank", T_OP_BANK},
{"round", T_OP_ROUND},
{"ceil", T_OP_CEIL},
{"floor", T_OP_FLOOR},
{"div", T_OP_FDIV},
{"mul", T_OP_FMUL},
{"sin", T_OP_SIN},

View File

@@ -1,4 +1,3 @@
#define _XOPEN_SOURCE 500
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

View File

@@ -2,7 +2,7 @@
#include "asm/lexer.h"
#include "asm/rpn.h"
#include "../asmy.h"
#include "asmy.h"
struct sLexInitString localstrings[] = {
{"adc", T_Z80_ADC},

View File

@@ -1,14 +1,5 @@
/*
* RGBAsm - MAIN.C
*
* INCLUDES
*
*/
#define _XOPEN_SOURCE 500
#include <math.h>
#include <stdarg.h>
#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
@@ -24,15 +15,6 @@
int yyparse(void);
void setuplex(void);
/*
* RGBAsm - MAIN.C
*
* VARIABLES
*
*/
bool haltnop;
clock_t nStartClock, nEndClock;
SLONG nLineNo;
ULONG nTotalLines, nPass, nPC, nIFDepth, nErrors;
@@ -40,10 +22,7 @@ ULONG nTotalLines, nPass, nPC, nIFDepth, nErrors;
extern int yydebug;
/*
* RGBAsm - MAIN.C
*
* Option stack
*
*/
struct sOptions DefaultOptions;
@@ -194,13 +173,10 @@ opt_Pop(void)
} else
fatalerror("No entries in the option stack");
}
/*
* RGBAsm - MAIN.C
*
* Error handling
*
*/
/*
* Error handling
*/
void
verror(const char *fmt, va_list args)
{
@@ -230,26 +206,15 @@ fatalerror(const char *fmt, ...)
va_end(args);
exit(5);
}
/*
* RGBAsm - MAIN.C
*
* Help text
*
*/
void
PrintUsage(void)
static void
usage(void)
{
printf("Usage: rgbasm [-v] [-h] [-b chars] [-g chars] [-i path] [-o outfile] [-p pad_value]\n"
" file\n");
printf(
"Usage: rgbasm [-v] [-h] [-b chars] [-g chars] [-i path] [-o outfile]\n"
" [-p pad_value] file.asm\n");
exit(1);
}
/*
* RGBAsm - MAIN.C
*
* main
*
*/
int
main(int argc, char *argv[])
@@ -261,10 +226,10 @@ main(int argc, char *argv[])
char *tzMainfile;
haltnop = true;
if (argc == 1)
PrintUsage();
usage();
/* yydebug=1; */
@@ -276,6 +241,7 @@ main(int argc, char *argv[])
DefaultOptions.binary[1] = '1';
DefaultOptions.fillchar = 0;
DefaultOptions.verbose = false;
DefaultOptions.haltnop = true;
opt_SetCurrentOptions(&DefaultOptions);
@@ -304,7 +270,7 @@ main(int argc, char *argv[])
}
break;
case 'h':
haltnop = false;
newopt.haltnop = false;
break;
case 'i':
fstk_AddIncludePath(optarg);
@@ -326,7 +292,7 @@ main(int argc, char *argv[])
newopt.verbose = true;
break;
default:
PrintUsage();
usage();
}
}
argc -= optind;
@@ -336,6 +302,9 @@ main(int argc, char *argv[])
DefaultOptions = CurrentOptions;
if (argc == 0)
usage();
tzMainfile = argv[argc - 1];
setuplex();
@@ -354,6 +323,7 @@ main(int argc, char *argv[])
nErrors = 0;
sym_PrepPass1();
fstk_Init(tzMainfile);
if (CurrentOptions.verbose) {
printf("Pass 1...\n");
}
@@ -361,8 +331,14 @@ main(int argc, char *argv[])
yy_set_state(LEX_STATE_NORMAL);
opt_SetCurrentOptions(&DefaultOptions);
if (yyparse() == 0 && nErrors == 0) {
if (nIFDepth == 0) {
if (yyparse() != 0 || nErrors != 0) {
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;
@@ -379,41 +355,24 @@ main(int argc, char *argv[])
printf("Pass 2...\n");
}
if (yyparse() == 0 && nErrors == 0) {
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;
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);
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));
(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);
}
return 0;
}

View File

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

View File

@@ -1,8 +1,5 @@
/*
* RGBAsm - OUTPUT.C - Outputs an objectfile
*
* INCLUDES
*
* Outputs an objectfile
*/
#include <errno.h>
@@ -22,13 +19,6 @@
#define SECTIONCHUNK 0x4000
/*
* RGBAsm - OUTPUT.C - Outputs an objectfile
*
* Internal structures
*
*/
void out_SetCurrentSection(struct Section * pSect);
struct Patch {
@@ -52,12 +42,6 @@ struct SectionStackEntry {
struct Section *pSection;
struct SectionStackEntry *pNext;
};
/*
* RGBAsm - OUTPUT.C - Outputs an objectfile
*
* VARIABLES
*
*/
struct PatchSymbol *tHashedPatchSymbols[HASHSIZE];
struct Section *pSectionList = NULL, *pCurrentSection = NULL;
@@ -67,12 +51,8 @@ char *tzObjectname;
struct SectionStackEntry *pSectionStack = NULL;
/*
* RGBAsm - OUTPUT.C - Outputs an objectfile
*
* Section stack routines
*
*/
void
out_PushSection(void)
{
@@ -99,13 +79,10 @@ out_PopSection(void)
} else
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
countsymbols(void)
{
@@ -121,13 +98,10 @@ countsymbols(void)
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
countsections(void)
{
@@ -143,13 +117,10 @@ countsections(void)
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
countpatches(struct Section * pSect)
{
@@ -164,13 +135,10 @@ countpatches(struct Section * pSect)
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
fputlong(ULONG i, FILE * f)
{
@@ -179,13 +147,10 @@ fputlong(ULONG i, FILE * f)
fputc(i >> 16, 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
fputstring(char *s, FILE * f)
{
@@ -193,13 +158,10 @@ fputstring(char *s, FILE * f)
fputc(*s++, f);
fputc(0, f);
}
/*
* RGBAsm - OUTPUT.C - Outputs an objectfile
*
* Return a sections ID
*
*/
/*
* Return a section's ID
*/
ULONG
getsectid(struct Section * pSect)
{
@@ -218,13 +180,10 @@ getsectid(struct Section * pSect)
fatalerror("INTERNAL: Unknown section");
return ((ULONG) - 1);
}
/*
* RGBAsm - OUTPUT.C - Outputs an objectfile
*
* Write a patch to a file
*
*/
/*
* Write a patch to a file
*/
void
writepatch(struct Patch * pPatch, FILE * f)
{
@@ -235,13 +194,10 @@ writepatch(struct Patch * pPatch, FILE * f)
fputlong(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
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
writesymbol(struct sSymbol * pSym, FILE * f)
{
@@ -319,13 +272,10 @@ writesymbol(struct sSymbol * pSym, FILE * f)
fputlong(offset, f);
}
}
/*
* RGBAsm - OUTPUT.C - Outputs an objectfile
*
* Add a symbol to the object
*
*/
/*
* Add a symbol to the object
*/
ULONG
addsymbol(struct sSymbol * pSym)
{
@@ -355,13 +305,10 @@ addsymbol(struct sSymbol * pSym)
return pPSym->ID;
}
/*
* RGBAsm - OUTPUT.C - Outputs an objectfile
*
* Add all exported symbols to the object
*
*/
/*
* Add all exported symbols to the object
*/
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 *
allocpatch(void)
{
@@ -401,13 +345,10 @@ allocpatch(void)
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
createpatch(ULONG type, struct Expression * expr)
{
@@ -473,13 +414,10 @@ createpatch(ULONG type, struct Expression * expr)
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
checksection(void)
{
@@ -488,14 +426,11 @@ checksection(void)
else
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
* this much initialized data
*
*/
void
checkcodesection(SLONG size)
{
@@ -524,13 +459,10 @@ checkcodesection(SLONG size)
} else
errx(1, "Section '%s' is too big", pCurrentSection->pzName);
}
/*
* RGBAsm - OUTPUT.C - Outputs an objectfile
*
* Write an objectfile
*
*/
/*
* Write an objectfile
*/
void
out_WriteObject(void)
{
@@ -561,13 +493,10 @@ out_WriteObject(void)
fclose(f);
}
}
/*
* RGBAsm - OUTPUT.C - Outputs an objectfile
*
* Prepare for pass #2
*
*/
/*
* Prepare for pass #2
*/
void
out_PrepPass2(void)
{
@@ -581,13 +510,10 @@ out_PrepPass2(void)
pCurrentSection = NULL;
pSectionStack = NULL;
}
/*
* RGBAsm - OUTPUT.C - Outputs an objectfile
*
* Set the objectfilename
*
*/
/*
* Set the objectfilename
*/
void
out_SetFileName(char *s)
{
@@ -599,16 +525,12 @@ out_SetFileName(char *s)
pCurrentSection = 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 *
out_FindSection(char *pzName, ULONG secttype, SLONG org,
SLONG bank)
out_FindSection(char *pzName, ULONG secttype, SLONG org, SLONG bank)
{
struct Section *pSect, **ppSect;
@@ -652,13 +574,10 @@ out_FindSection(char *pzName, ULONG secttype, SLONG org,
return (NULL);
}
/*
* RGBAsm - OUTPUT.C - Outputs an objectfile
*
* Set the current section
*
*/
/*
* Set the current section
*/
void
out_SetCurrentSection(struct Section * pSect)
{
@@ -668,37 +587,28 @@ out_SetCurrentSection(struct Section * pSect)
pPCSymbol->nValue = nPC;
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
out_NewSection(char *pzName, ULONG secttype)
{
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
out_NewAbsSection(char *pzName, ULONG secttype, SLONG org, SLONG bank)
{
out_SetCurrentSection(out_FindSection(pzName, secttype, org, bank));
}
/*
* RGBAsm - OUTPUT.C - Outputs an objectfile
*
* Output an absolute byte
*
*/
/*
* Output an absolute byte
*/
void
out_AbsByte(int b)
{
@@ -719,13 +629,10 @@ out_AbsByteGroup(char *s, int length)
while (length--)
out_AbsByte(*s++);
}
/*
* RGBAsm - OUTPUT.C - Outputs an objectfile
*
* Skip this many bytes
*
*/
/*
* Skip this many bytes
*/
void
out_Skip(int skip)
{
@@ -741,13 +648,10 @@ out_Skip(int skip)
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
out_String(char *s)
{
@@ -755,12 +659,10 @@ out_String(char *s)
while (*s)
out_AbsByte(*s++);
}
/*
* RGBAsm - OUTPUT.C - Outputs an objectfile
*
* Output a relocatable byte. Checking will be done to see if it
* is an absolute value in disguise.
*
*/
void
@@ -780,13 +682,10 @@ out_RelByte(struct Expression * expr)
rpn_Reset(expr);
}
/*
* RGBAsm - OUTPUT.C - Outputs an objectfile
*
* Output an absolute word
*
*/
/*
* Output an absolute word
*/
void
out_AbsWord(int b)
{
@@ -800,14 +699,11 @@ out_AbsWord(int b)
nPC += 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
out_RelWord(struct Expression * expr)
{
@@ -828,13 +724,10 @@ out_RelWord(struct Expression * expr)
out_AbsWord(expr->nVal);
rpn_Reset(expr);
}
/*
* RGBAsm - OUTPUT.C - Outputs an objectfile
*
* Output an absolute longword
*
*/
/*
* Output an absolute longword
*/
void
out_AbsLong(SLONG b)
{
@@ -849,14 +742,11 @@ out_AbsLong(SLONG b)
nPC += 4;
pPCSymbol->nValue += 4;
}
/*
* RGBAsm - OUTPUT.C - Outputs an objectfile
*
* Output a relocatable longword. Checking will be done to see if
* is an absolute value in disguise.
*
*/
void
out_RelLong(struct Expression * expr)
{
@@ -879,13 +769,10 @@ out_RelLong(struct Expression * expr)
out_AbsLong(expr->nVal);
rpn_Reset(expr);
}
/*
* RGBAsm - OUTPUT.C - Outputs an objectfile
*
* Output a PC-relative byte
*
*/
/*
* Output a PC-relative byte
*/
void
out_PCRelByte(struct Expression * expr)
{
@@ -899,13 +786,10 @@ out_PCRelByte(struct Expression * expr)
out_AbsByte(b);
rpn_Reset(expr);
}
/*
* RGBAsm - OUTPUT.C - Outputs an objectfile
*
* Output a binary file
*
*/
/*
* Output a binary file
*/
void
out_BinaryFile(char *s)
{

View File

@@ -1,8 +1,5 @@
/*
* RGBAsm - RPN.C - Controls RPN expressions for objectfiles
*
* INCLUDES
*
* Controls RPN expressions for objectfiles
*/
#include <stdio.h>
@@ -29,49 +26,26 @@ mergetwoexpressions(struct Expression * expr, struct Expression * src1,
#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
*
*/
void
pushbyte(struct Expression * expr, int b)
{
expr->tRPN[expr->nRPNLength++] = b & 0xFF;
}
/*
* RGBAsm - RPN.C - Controls RPN expressions for objectfiles
*
* Reset the RPN module
*
*/
/*
* Reset the RPN module
*/
void
rpn_Reset(struct Expression * expr)
{
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
rpn_PopByte(struct Expression * expr)
{
@@ -80,37 +54,28 @@ rpn_PopByte(struct Expression * expr)
} else
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
rpn_isReloc(struct Expression * expr)
{
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
rpn_isPCRelative(struct Expression * expr)
{
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
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);
}
}
void
rpn_CheckHRAM(struct Expression * expr, struct Expression * src)
{

View File

@@ -1,11 +1,7 @@
/*
* RGBAsm - SYMBOL.C - Symboltable and macroargs stuff
*
* INCLUDES
*
* Symboltable and macroargs stuff
*/
#define _XOPEN_SOURCE 500
#include <assert.h>
#include <stdio.h>
#include <string.h>
@@ -17,13 +13,6 @@
#include "asm/mymath.h"
#include "asm/output.h"
/*
* RGBAsm - SYMBOL.C - Symboltable stuff
*
* VARIABLES
*
*/
struct sSymbol *tHashedSymbols[HASHSIZE];
struct sSymbol *pScope = NULL;
struct sSymbol *pPCSymbol = NULL;
@@ -38,7 +27,6 @@ Callback_NARG(struct sSymbol * sym)
{
ULONG i = 0;
sym = sym;
while (currentmacroargs[i] && i < MAXMACROARGS)
i += 1;
@@ -46,12 +34,8 @@ Callback_NARG(struct sSymbol * sym)
}
/*
* RGBAsm - SYMBOL.C - Symboltable stuff
*
* Get the nValue field of a symbol
*
*/
SLONG
getvaluefield(struct sSymbol * sym)
{
@@ -60,13 +44,10 @@ getvaluefield(struct sSymbol * sym)
} else
return (sym->nValue);
}
/*
* RGBAsm - SYMBOL.C - Symboltable stuff
*
* Calculate the hash value for a string
*
*/
/*
* Calculate the hash value for a string
*/
ULONG
calchash(char *s)
{
@@ -77,13 +58,10 @@ calchash(char *s)
return (hash % HASHSIZE);
}
/*
* RGBAsm - SYMBOL.C - Symboltable stuff
*
* Create a new symbol by name
*
*/
/*
* Create a new symbol by name
*/
struct sSymbol *
createsymbol(char *s)
{
@@ -112,12 +90,8 @@ createsymbol(char *s)
}
}
/*
* RGBAsm - SYMBOL.C - Symboltable stuff
*
* Find a symbol by name and scope
*
*/
struct sSymbol *
findsymbol(char *s, struct sSymbol * scope)
{
@@ -136,13 +110,10 @@ findsymbol(char *s, struct sSymbol * scope)
}
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 **
findpsymbol(char *s, struct sSymbol * scope)
{
@@ -161,13 +132,10 @@ findpsymbol(char *s, struct sSymbol * scope)
}
return (NULL);
}
/*
* RGBAsm - SYMBOL.C - Symboltable stuff
*
* Find a symbol by name and scope
*
*/
/*
* Find a symbol by name and scope
*/
struct sSymbol *
sym_FindSymbol(char *tzName)
{
@@ -180,13 +148,10 @@ sym_FindSymbol(char *tzName)
return (findsymbol(tzName, pscope));
}
/*
* RGBAsm - SYMBOL.C - Symboltable stuff
*
* Purge a symbol
*
*/
/*
* Purge a symbol
*/
void
sym_Purge(char *tzName)
{
@@ -214,13 +179,10 @@ sym_Purge(char *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
sym_isConstDefined(char *tzName)
{
@@ -262,13 +224,10 @@ sym_isDefined(char *tzName)
else
return (0);
}
/*
* RGBAsm - SYMBOL.C - Symboltable stuff
*
* Determine if the symbol is a constant
*
*/
/*
* Determine if the symbol is a constant
*/
ULONG
sym_isConstant(char *s)
{
@@ -285,13 +244,10 @@ sym_isConstant(char *s)
}
return (0);
}
/*
* RGBAsm - SYMBOL.C - Symboltable stuff
*
* Get a string equate's value
*
*/
/*
* Get a string equate's value
*/
char *
sym_GetStringValue(char *tzSym)
{
@@ -305,13 +261,10 @@ sym_GetStringValue(char *tzSym)
return (NULL);
}
/*
* RGBAsm - SYMBOL.C - Symboltable stuff
*
* Return a constant symbols value
*
*/
/*
* Return a constant symbols value
*/
ULONG
sym_GetConstantValue(char *s)
{
@@ -334,13 +287,10 @@ sym_GetConstantValue(char *s)
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
sym_GetValue(char *s)
{
@@ -376,13 +326,10 @@ sym_GetValue(char *s)
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
sym_GetDefinedValue(char *s)
{
@@ -408,13 +355,10 @@ sym_GetDefinedValue(char *s)
return (0);
}
/*
* RGBAsm - SYMBOL.C - Symboltable stuff
*
* Macro argument stuff
*
*/
/*
* Macro argument stuff
*/
void
sym_ShiftCurrentMacroArgs(void)
{
@@ -492,7 +436,7 @@ sym_AddNewMacroArg(char *s)
else
newmacroargs[i] = NULL;
} else
yyerror("A maximum of 9 arguments allowed");
yyerror("A maximum of %d arguments allowed", MAXMACROARGS);
}
void
@@ -512,25 +456,19 @@ sym_UseCurrentMacroArgs(void)
for (i = 1; i <= MAXMACROARGS; i += 1)
sym_AddNewMacroArg(sym_FindMacroArg(i));
}
/*
* RGBAsm - SYMBOL.C - Symboltable stuff
*
* Find a macro by name
*
*/
/*
* Find a macro by name
*/
struct sSymbol *
sym_FindMacro(char *s)
{
return (findsymbol(s, NULL));
}
/*
* RGBAsm - SYMBOL.C - Symboltable stuff
*
* Add an equated symbol
*
*/
/*
* Add an equated symbol
*/
void
sym_AddEqu(char *tzSym, SLONG value)
{
@@ -553,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
sym_AddString(char *tzSym, char *tzValue)
{
@@ -582,13 +517,10 @@ sym_AddString(char *tzSym, char *tzValue)
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
sym_isString(char *tzSym)
{
@@ -600,13 +532,10 @@ sym_isString(char *tzSym)
}
return (0);
}
/*
* RGBAsm - SYMBOL.C - Symboltable stuff
*
* Alter a SET symbols value
*
*/
/*
* Alter a SET symbols value
*/
void
sym_AddSet(char *tzSym, SLONG value)
{
@@ -622,13 +551,10 @@ sym_AddSet(char *tzSym, SLONG value)
nsym->pScope = NULL;
}
}
/*
* RGBAsm - SYMBOL.C - Symboltable stuff
*
* Add a local (.name) relocatable symbol
*
*/
/*
* Add a local (.name) relocatable symbol
*/
void
sym_AddLocalReloc(char *tzSym)
{
@@ -656,13 +582,10 @@ sym_AddLocalReloc(char *tzSym)
fatalerror("Local label in main scope");
}
}
/*
* RGBAsm - SYMBOL.C - Symboltable stuff
*
* Add a relocatable symbol
*
*/
/*
* Add a relocatable symbol
*/
void
sym_AddReloc(char *tzSym)
{
@@ -686,15 +609,11 @@ sym_AddReloc(char *tzSym)
}
}
pScope = findsymbol(tzSym, NULL);
}
/*
* RGBAsm - SYMBOL.C - Symboltable stuff
*
* Export a symbol
*
*/
/*
* Export a symbol
*/
void
sym_Export(char *tzSym)
{
@@ -718,13 +637,10 @@ sym_Export(char *tzSym)
}
}
/*
* RGBAsm - SYMBOL.C - Symboltable stuff
*
* Import a symbol
*
*/
/*
* Import a symbol
*/
void
sym_Import(char *tzSym)
{
@@ -739,13 +655,10 @@ sym_Import(char *tzSym)
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
sym_Global(char *tzSym)
{
@@ -767,13 +680,10 @@ sym_Global(char *tzSym)
}
}
}
/*
* RGBAsm - SYMBOL.C - Symboltable stuff
*
* Add a macro definition
*
*/
/*
* Add a macro definition
*/
void
sym_AddMacro(char *tzSym)
{
@@ -798,25 +708,19 @@ sym_AddMacro(char *tzSym)
}
}
}
/*
* RGBAsm - SYMBOL.C - Symboltable stuff
*
* Prepare for pass #1
*
*/
/*
* Prepare for pass #1
*/
void
sym_PrepPass1(void)
{
sym_Init();
}
/*
* RGBAsm - SYMBOL.C - Symboltable stuff
*
* Prepare for pass #2
*
*/
/*
* Prepare for pass #2
*/
void
sym_PrepPass2(void)
{
@@ -848,13 +752,10 @@ sym_PrepPass2(void)
p_NARGSymbol = findsymbol("_NARG", NULL);
p_NARGSymbol->Callback = Callback_NARG;
}
/*
* RGBAsm - SYMBOL.C - Symboltable stuff
*
* Initialise the symboltable
*
*/
/*
* Initialize the symboltable
*/
void
sym_Init(void)
{
@@ -891,72 +792,3 @@ sym_Init(void)
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

@@ -1,454 +0,0 @@
%{
#define _XOPEN_SOURCE 500
#include <ctype.h>
#include <errno.h>
#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <strings.h>
#include "asm/symbol.h"
#include "asm/asm.h"
#include "asm/charmap.h"
#include "asm/output.h"
#include "asm/mylink.h"
#include "asm/fstack.h"
#include "asm/mymath.h"
#include "asm/rpn.h"
#include "asm/main.h"
#include "asm/lexer.h"
extern bool haltnop;
char *tzNewMacro;
ULONG ulNewMacroSize;
size_t symvaluetostring(char *dest, size_t maxLength, char *sym)
{
size_t length;
if (sym_isString(sym)) {
char *src = sym_GetStringValue(sym);
size_t i;
for (i = 0; src[i] != 0; i++) {
if (i >= maxLength) {
fatalerror("Symbol value too long to fit buffer");
}
dest[i] = src[i];
}
length = i;
} else {
ULONG value = sym_GetConstantValue(sym);
int fullLength = snprintf(dest, maxLength + 1, "$%lX", value);
if (fullLength < 0) {
fatalerror("snprintf encoding error");
} else {
length = (size_t)fullLength;
if (length > maxLength) {
fatalerror("Symbol value too long to fit buffer");
}
}
}
return length;
}
ULONG str2int( char *s )
{
ULONG r=0;
while( *s )
{
r<<=8;
r|=(UBYTE)(*s++);
}
return( r );
}
ULONG str2int2( char *s, int length )
{
int i;
ULONG r=0;
i = (length - 4 < 0 ? 0 : length - 4);
while(i < length)
{
r<<=8;
r|=(UBYTE)(s[i]);
i++;
}
return( r );
}
ULONG isWhiteSpace( char s )
{
return( s==' ' || s=='\t' || s=='\0' || s=='\n' );
}
ULONG isRept( char *s )
{
return( (strncasecmp(s,"REPT",4)==0) && isWhiteSpace(*(s-1)) && isWhiteSpace(s[4]) );
}
ULONG isEndr( char *s )
{
return( (strncasecmp(s,"Endr",4)==0) && isWhiteSpace(*(s-1)) && isWhiteSpace(s[4]) );
}
void copyrept( void )
{
SLONG level=1, len, instring=0;
char *src=pCurrentBuffer->pBuffer;
while( *src && level )
{
if( instring==0 )
{
if( isRept(src) )
{
level+=1;
src+=4;
}
else if( isEndr(src) )
{
level-=1;
src+=4;
}
else
{
if( *src=='\"' )
instring=1;
src+=1;
}
}
else
{
if( *src=='\\' )
{
src+=2;
}
else if( *src=='\"' )
{
src+=1;
instring=0;
}
else
{
src+=1;
}
}
}
len=src-pCurrentBuffer->pBuffer-4;
src=pCurrentBuffer->pBuffer;
ulNewMacroSize=len;
if ((tzNewMacro = malloc(ulNewMacroSize + 1)) != NULL) {
ULONG i;
tzNewMacro[ulNewMacroSize]=0;
for( i=0; i<ulNewMacroSize; i+=1 )
{
if( (tzNewMacro[i]=src[i])=='\n' )
nLineNo+=1;
}
} else
fatalerror( "No mem for REPT block" );
yyskipbytes( ulNewMacroSize+4 );
}
ULONG isMacro( char *s )
{
return( (strncasecmp(s,"MACRO",4)==0) && isWhiteSpace(*(s-1)) && isWhiteSpace(s[5]) );
}
ULONG isEndm( char *s )
{
return( (strncasecmp(s,"Endm",4)==0) && isWhiteSpace(*(s-1)) && isWhiteSpace(s[4]) );
}
void copymacro( void )
{
SLONG level=1, len, instring=0;
char *src=pCurrentBuffer->pBuffer;
while( *src && level )
{
if( instring==0 )
{
if( isMacro(src) )
{
level+=1;
src+=4;
}
else if( isEndm(src) )
{
level-=1;
src+=4;
}
else
{
if( *src=='\"' )
instring=1;
src+=1;
}
}
else
{
if( *src=='\\' )
{
src+=2;
}
else if( *src=='\"' )
{
src+=1;
instring=0;
}
else
{
src+=1;
}
}
}
len=src-pCurrentBuffer->pBuffer-4;
src=pCurrentBuffer->pBuffer;
ulNewMacroSize=len;
if( (tzNewMacro=(char *)malloc(ulNewMacroSize+2))!=NULL )
{
ULONG i;
tzNewMacro[ulNewMacroSize]='\n';
tzNewMacro[ulNewMacroSize+1]=0;
for( i=0; i<ulNewMacroSize; i+=1 )
{
if( (tzNewMacro[i]=src[i])=='\n' )
nLineNo+=1;
}
}
else
fatalerror( "No mem for MACRO definition" );
yyskipbytes( ulNewMacroSize+4 );
}
ULONG isIf( char *s )
{
return( (strncasecmp(s,"If",2)==0) && isWhiteSpace(*(s-1)) && isWhiteSpace(s[2]) );
}
ULONG isElse( char *s )
{
return( (strncasecmp(s,"Else",4)==0) && isWhiteSpace(*(s-1)) && isWhiteSpace(s[4]) );
}
ULONG isEndc( char *s )
{
return( (strncasecmp(s,"Endc",4)==0) && isWhiteSpace(*(s-1)) && isWhiteSpace(s[4]) );
}
void if_skip_to_else( void )
{
SLONG level=1, len, instring=0;
char *src=pCurrentBuffer->pBuffer;
while( *src && level )
{
if( *src=='\n' )
nLineNo+=1;
if( instring==0 )
{
if( isIf(src) )
{
level+=1;
src+=2;
}
else if( level==1 && isElse(src) )
{
level-=1;
src+=4;
}
else if( isEndc(src) )
{
level-=1;
if( level!=0 )
src+=4;
}
else
{
if( *src=='\"' )
instring=1;
src+=1;
}
}
else
{
if( *src=='\\' )
{
src+=2;
}
else if( *src=='\"' )
{
src+=1;
instring=0;
}
else
{
src+=1;
}
}
}
len=src-pCurrentBuffer->pBuffer;
yyskipbytes( len );
yyunput( '\n' );
nLineNo-=1;
}
void if_skip_to_endc( void )
{
SLONG level=1, len, instring=0;
char *src=pCurrentBuffer->pBuffer;
while( *src && level )
{
if( *src=='\n' )
nLineNo+=1;
if( instring==0 )
{
if( isIf(src) )
{
level+=1;
src+=2;
}
else if( isEndc(src) )
{
level-=1;
if( level!=0 )
src+=4;
}
else
{
if( *src=='\"' )
instring=1;
src+=1;
}
}
else
{
if( *src=='\\' )
{
src+=2;
}
else if( *src=='\"' )
{
src+=1;
instring=0;
}
else
{
src+=1;
}
}
}
len=src-pCurrentBuffer->pBuffer;
yyskipbytes( len );
yyunput( '\n' );
nLineNo-=1;
}
%}
%union
{
char tzSym[MAXSYMLEN + 1];
char tzString[MAXSTRLEN + 1];
struct Expression sVal;
SLONG nConstValue;
}
%type <sVal> relocconst
%type <nConstValue> const
%type <nConstValue> const_3bit
%type <sVal> const_8bit
%type <sVal> const_16bit
%type <sVal> const_PCrel
%type <nConstValue> sectiontype
%type <tzString> string
%token <nConstValue> T_NUMBER
%token <tzString> T_STRING
%left T_OP_LOGICNOT
%left T_OP_LOGICOR T_OP_LOGICAND T_OP_LOGICEQU
%left T_OP_LOGICGT T_OP_LOGICLT T_OP_LOGICGE T_OP_LOGICLE T_OP_LOGICNE
%left T_OP_ADD T_OP_SUB
%left T_OP_OR T_OP_XOR T_OP_AND
%left T_OP_SHL T_OP_SHR
%left T_OP_MUL T_OP_DIV T_OP_MOD
%left T_OP_NOT
%left T_OP_DEF
%left T_OP_BANK
%left T_OP_SIN
%left T_OP_COS
%left T_OP_TAN
%left T_OP_ASIN
%left T_OP_ACOS
%left T_OP_ATAN
%left T_OP_ATAN2
%left T_OP_FDIV
%left T_OP_FMUL
%left T_OP_STRCMP
%left T_OP_STRIN
%left T_OP_STRSUB
%left T_OP_STRLEN
%left T_OP_STRCAT
%left T_OP_STRUPR
%left T_OP_STRLWR
%left NEG /* negation--unary minus */
%token <tzSym> T_LABEL
%token <tzSym> T_ID
%token <tzSym> T_POP_EQU
%token <tzSym> T_POP_SET
%token <tzSym> T_POP_EQUS
%token T_POP_INCLUDE T_POP_PRINTF T_POP_PRINTT T_POP_PRINTV T_POP_IF T_POP_ELSE T_POP_ENDC
%token T_POP_IMPORT T_POP_EXPORT T_POP_GLOBAL
%token T_POP_DB T_POP_DS T_POP_DW T_POP_DL
%token T_POP_SECTION
%token T_POP_RB
%token T_POP_RW
%token T_POP_RL
%token T_POP_MACRO
%token T_POP_ENDM
%token T_POP_RSRESET T_POP_RSSET
%token T_POP_INCBIN T_POP_REPT
%token T_POP_CHARMAP
%token T_POP_SHIFT
%token T_POP_ENDR
%token T_POP_FAIL
%token T_POP_WARN
%token T_POP_PURGE
%token T_POP_POPS
%token T_POP_PUSHS
%token T_POP_POPO
%token T_POP_PUSHO
%token T_POP_OPT

View File

@@ -1,552 +0,0 @@
%start asmfile
%%
asmfile : lines lastline
;
lastline : /* empty */
| line
{ nLineNo+=1; nTotalLines+=1; }
;
lines : /* empty */
| lines line '\n'
{ nLineNo+=1; nTotalLines+=1; }
;
line : /* empty */
| label
| label cpu_command
| label macro
| label simple_pseudoop
| pseudoop
;
label : /* empty */
| T_LABEL { if( $1[0]=='.' )
sym_AddLocalReloc($1);
else
sym_AddReloc($1);
}
| T_LABEL ':' { if( $1[0]=='.' )
sym_AddLocalReloc($1);
else
sym_AddReloc($1);
}
| T_LABEL ':' ':' { sym_AddReloc($1); sym_Export($1); }
;
macro : T_ID
{
yy_set_state( LEX_STATE_MACROARGS );
}
macroargs
{
yy_set_state( LEX_STATE_NORMAL );
if( !fstk_RunMacro($1) )
{
yyerror("Macro '%s' not defined", $1);
}
}
;
macroargs : /* empty */
| macroarg
| macroarg ',' macroargs
;
macroarg : T_STRING
{ sym_AddNewMacroArg( $1 ); }
;
pseudoop : equ
| set
| rb
| rw
| rl
| equs
| macrodef
;
simple_pseudoop : include
| printf
| printt
| printv
| if
| else
| endc
| import
| export
| global
| db
| dw
| dl
| ds
| section
| rsreset
| rsset
| incbin
| charmap
| rept
| shift
| fail
| warn
| purge
| pops
| pushs
| popo
| pusho
| opt
;
opt : T_POP_OPT
{
yy_set_state( LEX_STATE_MACROARGS );
}
opt_list
{
yy_set_state( LEX_STATE_NORMAL );
}
;
opt_list : opt_list_entry
| opt_list_entry ',' opt_list
;
opt_list_entry : T_STRING
{
opt_Parse($1);
}
;
popo : T_POP_POPO
{ opt_Pop(); }
;
pusho : T_POP_PUSHO
{ opt_Push(); }
;
pops : T_POP_POPS
{ out_PopSection(); }
;
pushs : T_POP_PUSHS
{ out_PushSection(); }
;
fail : T_POP_FAIL string
{ fatalerror("%s", $2); }
;
warn : T_POP_WARN string
{ yyerror("%s", $2); }
;
shift : T_POP_SHIFT
{ sym_ShiftCurrentMacroArgs(); }
;
rept : T_POP_REPT const
{
copyrept();
fstk_RunRept( $2 );
}
;
macrodef : T_LABEL ':' T_POP_MACRO
{
copymacro();
sym_AddMacro($1);
}
;
equs : T_LABEL T_POP_EQUS string
{ sym_AddString( $1, $3 ); }
;
rsset : T_POP_RSSET const
{ sym_AddSet( "_RS", $2 ); }
;
rsreset : T_POP_RSRESET
{ sym_AddSet( "_RS", 0 ); }
;
rl : T_LABEL T_POP_RL const
{
sym_AddEqu( $1, sym_GetConstantValue("_RS") );
sym_AddSet( "_RS", sym_GetConstantValue("_RS")+4*$3 );
}
;
rw : T_LABEL T_POP_RW const
{
sym_AddEqu( $1, sym_GetConstantValue("_RS") );
sym_AddSet( "_RS", sym_GetConstantValue("_RS")+2*$3 );
}
;
rb : T_LABEL T_POP_RB const
{
sym_AddEqu( $1, sym_GetConstantValue("_RS") );
sym_AddSet( "_RS", sym_GetConstantValue("_RS")+$3 );
}
;
ds : T_POP_DS const
{ out_Skip( $2 ); }
;
db : T_POP_DB constlist_8bit
;
dw : T_POP_DW constlist_16bit
;
dl : T_POP_DL constlist_32bit
;
purge : T_POP_PURGE
{
oDontExpandStrings=1;
}
purge_list
{
oDontExpandStrings=0;
}
;
purge_list : purge_list_entry
| purge_list_entry ',' purge_list
;
purge_list_entry : T_ID { sym_Purge($1); }
;
import : T_POP_IMPORT import_list
;
import_list : import_list_entry
| import_list_entry ',' import_list
;
import_list_entry : T_ID { sym_Import($1); }
;
export : T_POP_EXPORT export_list
;
export_list : export_list_entry
| export_list_entry ',' export_list
;
export_list_entry : T_ID { sym_Export($1); }
;
global : T_POP_GLOBAL global_list
;
global_list : global_list_entry
| global_list_entry ',' global_list
;
global_list_entry : T_ID { sym_Global($1); }
;
equ : T_LABEL T_POP_EQU const
{ sym_AddEqu( $1, $3 ); }
;
set : T_LABEL T_POP_SET const
{ sym_AddSet( $1, $3 ); }
;
include : T_POP_INCLUDE string
{
fstk_RunInclude($2);
}
;
incbin : T_POP_INCBIN string
{ out_BinaryFile( $2 ); }
| T_POP_INCBIN string ',' const ',' const
{
out_BinaryFileSlice( $2, $4, $6 );
}
;
charmap : T_POP_CHARMAP string ',' string
{
if(charmap_Add($2, $4[0] & 0xFF) == -1)
{
fprintf(stderr, "Error parsing charmap. Either you've added too many (%i), or the input character length is too long (%i)' : %s\n", MAXCHARMAPS, CHARMAPLENGTH, strerror(errno));
yyerror("Error parsing charmap.");
}
}
| T_POP_CHARMAP string ',' const
{
if(charmap_Add($2, $4 & 0xFF) == -1)
{
fprintf(stderr, "Error parsing charmap. Either you've added too many (%i), or the input character length is too long (%i)' : %s\n", MAXCHARMAPS, CHARMAPLENGTH, strerror(errno));
yyerror("Error parsing charmap.");
}
}
;
printt : T_POP_PRINTT string
{
if( nPass==1 )
printf( "%s", $2 );
}
;
printv : T_POP_PRINTV const
{
if( nPass==1 )
printf( "$%lX", $2 );
}
;
printf : T_POP_PRINTF const
{
if( nPass==1 )
math_Print( $2 );
}
;
if : T_POP_IF const
{
nIFDepth+=1;
if( !$2 )
{
if_skip_to_else(); /* will continue parsing just after ELSE or just at ENDC keyword */
}
}
else : T_POP_ELSE
{
if_skip_to_endc(); /* will continue parsing just at ENDC keyword */
}
;
endc : T_POP_ENDC
{
nIFDepth-=1;
}
;
const_3bit : const
{
if( ($1<0) || ($1>7) )
{
yyerror("Immediate value must be 3-bit");
}
else
$$=$1&0x7;
}
;
constlist_8bit : constlist_8bit_entry
| constlist_8bit_entry ',' constlist_8bit
;
constlist_8bit_entry : { out_Skip( 1 ); }
| const_8bit { out_RelByte( &$1 ); }
| string { char *s; int length; s = $1; length = charmap_Convert(&s); out_AbsByteGroup(s, length); free(s); }
;
constlist_16bit : constlist_16bit_entry
| constlist_16bit_entry ',' constlist_16bit
;
constlist_16bit_entry : { out_Skip( 2 ); }
| const_16bit { out_RelWord( &$1 ); }
;
constlist_32bit : constlist_32bit_entry
| constlist_32bit_entry ',' constlist_32bit
;
constlist_32bit_entry : { out_Skip( 4 ); }
| relocconst { out_RelLong( &$1 ); }
;
const_PCrel : relocconst
{
$$ = $1;
if( !rpn_isPCRelative(&$1) )
yyerror("Expression must be PC-relative");
}
;
const_8bit : relocconst
{
if( (!rpn_isReloc(&$1)) && (($1.nVal<-128) || ($1.nVal>255)) )
{
yyerror("Expression must be 8-bit");
}
$$=$1;
}
;
const_16bit : relocconst
{
if( (!rpn_isReloc(&$1)) && (($1.nVal<-32768) || ($1.nVal>65535)) )
{
yyerror("Expression must be 16-bit");
}
$$=$1;
}
;
relocconst : T_ID
{ rpn_Symbol(&$$,$1); $$.nVal = sym_GetValue($1); }
| T_NUMBER
{ rpn_Number(&$$,$1); $$.nVal = $1; }
| string
{ char *s; int length; ULONG r; s = $1; length = charmap_Convert(&s); r = str2int2(s, length); free(s); rpn_Number(&$$,r); $$.nVal=r; }
| T_OP_LOGICNOT relocconst %prec NEG
{ rpn_LOGNOT(&$$,&$2); }
| relocconst T_OP_LOGICOR relocconst
{ rpn_LOGOR(&$$,&$1,&$3); }
| relocconst T_OP_LOGICAND relocconst
{ rpn_LOGAND(&$$,&$1,&$3); }
| relocconst T_OP_LOGICEQU relocconst
{ rpn_LOGEQU(&$$,&$1,&$3); }
| relocconst T_OP_LOGICGT relocconst
{ rpn_LOGGT(&$$,&$1,&$3); }
| relocconst T_OP_LOGICLT relocconst
{ rpn_LOGLT(&$$,&$1,&$3); }
| relocconst T_OP_LOGICGE relocconst
{ rpn_LOGGE(&$$,&$1,&$3); }
| relocconst T_OP_LOGICLE relocconst
{ rpn_LOGLE(&$$,&$1,&$3); }
| relocconst T_OP_LOGICNE relocconst
{ rpn_LOGNE(&$$,&$1,&$3); }
| relocconst T_OP_ADD relocconst
{ rpn_ADD(&$$,&$1,&$3); }
| relocconst T_OP_SUB relocconst
{ rpn_SUB(&$$,&$1,&$3); }
| relocconst T_OP_XOR relocconst
{ rpn_XOR(&$$,&$1,&$3); }
| relocconst T_OP_OR relocconst
{ rpn_OR(&$$,&$1,&$3); }
| relocconst T_OP_AND relocconst
{ rpn_AND(&$$,&$1,&$3); }
| relocconst T_OP_SHL relocconst
{ rpn_SHL(&$$,&$1,&$3); }
| relocconst T_OP_SHR relocconst
{ rpn_SHR(&$$,&$1,&$3); }
| relocconst T_OP_MUL relocconst
{ rpn_MUL(&$$,&$1,&$3); }
| relocconst T_OP_DIV relocconst
{ rpn_DIV(&$$,&$1,&$3); }
| relocconst T_OP_MOD relocconst
{ rpn_MOD(&$$,&$1,&$3); }
| T_OP_ADD relocconst %prec NEG
{ $$ = $2; }
| T_OP_SUB relocconst %prec NEG
{ rpn_UNNEG(&$$,&$2); }
| T_OP_NOT relocconst %prec NEG
{ rpn_UNNOT(&$$,&$2); }
| T_OP_BANK '(' T_ID ')'
{ rpn_Bank(&$$,$3); $$.nVal = 0; }
| T_OP_DEF '(' T_ID ')'
{ rpn_Number(&$$,sym_isConstDefined($3)); }
| T_OP_FDIV '(' const ',' const ')' { rpn_Number(&$$,math_Div($3,$5)); }
| T_OP_FMUL '(' const ',' const ')' { rpn_Number(&$$,math_Mul($3,$5)); }
| T_OP_SIN '(' const ')' { rpn_Number(&$$,math_Sin($3)); }
| T_OP_COS '(' const ')' { rpn_Number(&$$,math_Cos($3)); }
| T_OP_TAN '(' const ')' { rpn_Number(&$$,math_Tan($3)); }
| T_OP_ASIN '(' const ')' { rpn_Number(&$$,math_ASin($3)); }
| T_OP_ACOS '(' const ')' { rpn_Number(&$$,math_ACos($3)); }
| T_OP_ATAN '(' const ')' { rpn_Number(&$$,math_ATan($3)); }
| T_OP_ATAN2 '(' const ',' const ')' { rpn_Number(&$$,math_ATan2($3,$5)); }
| T_OP_STRCMP '(' string ',' string ')' { rpn_Number(&$$,strcmp($3,$5)); }
| T_OP_STRIN '(' string ',' string ')'
{
char *p;
if( (p=strstr($3,$5))!=NULL )
{
rpn_Number(&$$,p-$3+1);
}
else
{
rpn_Number(&$$,0);
}
}
| T_OP_STRLEN '(' string ')' { rpn_Number(&$$,strlen($3)); }
| '(' relocconst ')'
{ $$ = $2; }
;
const : T_ID { $$ = sym_GetConstantValue($1); }
| T_NUMBER { $$ = $1; }
| string { $$ = str2int($1); }
| T_OP_LOGICNOT const %prec NEG { $$ = !$2; }
| const T_OP_LOGICOR const { $$ = $1 || $3; }
| const T_OP_LOGICAND const { $$ = $1 && $3; }
| const T_OP_LOGICEQU const { $$ = $1 == $3; }
| const T_OP_LOGICGT const { $$ = $1 > $3; }
| const T_OP_LOGICLT const { $$ = $1 < $3; }
| const T_OP_LOGICGE const { $$ = $1 >= $3; }
| const T_OP_LOGICLE const { $$ = $1 <= $3; }
| const T_OP_LOGICNE const { $$ = $1 != $3; }
| const T_OP_ADD const { $$ = $1 + $3; }
| const T_OP_SUB const { $$ = $1 - $3; }
| T_ID T_OP_SUB T_ID { $$ = sym_GetDefinedValue($1) - sym_GetDefinedValue($3); }
| const T_OP_XOR const { $$ = $1 ^ $3; }
| const T_OP_OR const { $$ = $1 | $3; }
| const T_OP_AND const { $$ = $1 & $3; }
| const T_OP_SHL const { $$ = $1 << $3; }
| const T_OP_SHR const { $$ = $1 >> $3; }
| const T_OP_MUL const { $$ = $1 * $3; }
| const T_OP_DIV const { $$ = $1 / $3; }
| const T_OP_MOD const { $$ = $1 % $3; }
| T_OP_ADD const %prec NEG { $$ = +$2; }
| T_OP_SUB const %prec NEG { $$ = -$2; }
| T_OP_NOT const %prec NEG { $$ = 0xFFFFFFFF^$2; }
| T_OP_FDIV '(' const ',' const ')' { $$ = math_Div($3,$5); }
| T_OP_FMUL '(' const ',' const ')' { $$ = math_Mul($3,$5); }
| T_OP_SIN '(' const ')' { $$ = math_Sin($3); }
| T_OP_COS '(' const ')' { $$ = math_Cos($3); }
| T_OP_TAN '(' const ')' { $$ = math_Tan($3); }
| T_OP_ASIN '(' const ')' { $$ = math_ASin($3); }
| T_OP_ACOS '(' const ')' { $$ = math_ACos($3); }
| T_OP_ATAN '(' const ')' { $$ = math_ATan($3); }
| T_OP_ATAN2 '(' const ',' const ')' { $$ = math_ATan2($3,$5); }
| T_OP_DEF '(' T_ID ')' { $$ = sym_isConstDefined($3); }
| T_OP_STRCMP '(' string ',' string ')' { $$ = strcmp( $3, $5 ); }
| T_OP_STRIN '(' string ',' string ')'
{
char *p;
if( (p=strstr($3,$5))!=NULL )
{
$$ = p-$3+1;
}
else
{
$$ = 0;
}
}
| T_OP_STRLEN '(' string ')' { $$ = strlen($3); }
| '(' const ')' { $$ = $2; }
;
string : T_STRING
{ strcpy($$,$1); }
| T_OP_STRSUB '(' string ',' const ',' const ')'
{ strncpy($$,$3+$5-1,$7); $$[$7]=0; }
| T_OP_STRCAT '(' string ',' string ')'
{ strcpy($$,$3); strcat($$,$5); }
| T_OP_STRUPR '(' string ')'
{ strcpy($$,$3); strupr($$); }
| T_OP_STRLWR '(' string ')'
{ strcpy($$,$3); strlwr($$); }
;

8
src/extern/err.c vendored
View File

@@ -47,13 +47,13 @@ void rgbds_vwarnx(const char *fmt, va_list ap)
putc('\n', stderr);
}
_Noreturn void rgbds_verr(int status, const char *fmt, va_list ap)
noreturn void rgbds_verr(int status, const char *fmt, va_list ap)
{
vwarn(fmt, ap);
exit(status);
}
_Noreturn void rgbds_verrx(int status, const char *fmt, va_list ap)
noreturn void rgbds_verrx(int status, const char *fmt, va_list ap)
{
vwarnx(fmt, ap);
exit(status);
@@ -75,7 +75,7 @@ void rgbds_warnx(const char *fmt, ...)
va_end(ap);
}
_Noreturn void rgbds_err(int status, const char *fmt, ...)
noreturn void rgbds_err(int status, const char *fmt, ...)
{
va_list ap;
va_start(ap, fmt);
@@ -83,7 +83,7 @@ _Noreturn void rgbds_err(int status, const char *fmt, ...)
va_end(ap);
}
_Noreturn void rgbds_errx(int status, const char *fmt, ...)
noreturn void rgbds_errx(int status, const char *fmt, ...)
{
va_list ap;
va_start(ap, fmt);

View File

@@ -14,7 +14,6 @@
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
#define _XOPEN_SOURCE 500
#include <stdbool.h>
#include <stdint.h>
#include <stdio.h>
@@ -27,10 +26,10 @@
static void
usage(void)
{
printf("usage: rgbfix [-Ccjsv] [-i game_id] [-k licensee_str] "
"[-l licensee_id]\n" " [-m mbc_type] [-n rom_version] "
"[-p pad_value] [-r ram_size]\n"
" [-t title_str] file.gb\n");
printf(
"usage: rgbfix [-Ccjsv] [-i game_id] [-k licensee_str] [-l licensee_id]\n"
" [-m mbc_type] [-n rom_version] [-p pad_value] [-r ram_size]\n"
" [-t title_str] file\n");
exit(1);
}
@@ -41,17 +40,6 @@ main(int argc, char *argv[])
int ch;
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
*/
@@ -71,15 +59,15 @@ main(int argc, char *argv[])
bool resize = false;
bool setversion = false;
char *title = NULL; /* game title in ASCII */
char *id = NULL; /* game ID in ASCII */
char *newlicensee = NULL; /* new licensee ID, two ASCII characters */
char *title; /* game title in ASCII */
char *id; /* game ID in ASCII */
char *newlicensee; /* new licensee ID, two ASCII characters */
int licensee = -1; /* old licensee ID */
int cartridge = -1; /* cartridge hardware ID */
int ramsize = -1; /* RAM size ID */
int version = -1; /* mask ROM version number */
int padvalue = -1; /* to pad the rom with if it changes size */
int licensee; /* old licensee ID */
int cartridge; /* cartridge hardware ID */
int ramsize; /* RAM size ID */
int version; /* mask ROM version number */
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) {
switch (ch) {
@@ -198,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
*/

View File

@@ -1,4 +1,3 @@
#define _XOPEN_SOURCE 500
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
@@ -33,9 +32,9 @@ char smartlinkstartsymbol[256];
static void
usage(void)
{
printf("usage: rgblink [-t] [-m mapfile] [-n symfile] [-o outfile]\n");
printf("\t [-s symbol] [-z pad_value] objectfile [...]\n");
printf(
"usage: rgblink [-t] [-m mapfile] [-n symfile] [-o outfile] [-s symbol]\n"
" [-z pad_value] file [...]\n");
exit(1);
}

View File

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