mirror of
https://github.com/gbdev/rgbds.git
synced 2025-11-21 02:32:06 +00:00
Compare commits
74 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
361f1ac50b | ||
|
|
4f8cf84ed4 | ||
|
|
c75b9d4d55 | ||
|
|
cd2af0204e | ||
|
|
91241b44da | ||
|
|
1d174f37da | ||
|
|
2777044f70 | ||
|
|
e5e64b8cec | ||
|
|
8534f3a148 | ||
|
|
bdc6401eba | ||
|
|
21d0b402d3 | ||
|
|
a305649557 | ||
|
|
3b0e207036 | ||
|
|
83eddb4c4e | ||
|
|
57997756b6 | ||
|
|
ab66b28fdf | ||
|
|
116569f54d | ||
|
|
2b839fec37 | ||
|
|
513d451710 | ||
|
|
9399ba36f9 | ||
|
|
ef3a486845 | ||
|
|
f0e5c5ccc8 | ||
|
|
9b4959cb75 | ||
|
|
dca82e6d95 | ||
|
|
871c5ed360 | ||
|
|
635014b74d | ||
|
|
7ad634febd | ||
|
|
1e1339467e | ||
|
|
9e24c26468 | ||
|
|
c1213f536b | ||
|
|
82de716454 | ||
|
|
a64d725a8d | ||
|
|
80e2129f22 | ||
|
|
af70f03933 | ||
|
|
004bc2e50e | ||
|
|
25efb00769 | ||
|
|
c6c7b99fad | ||
|
|
e28d8384fb | ||
|
|
27a350eaab | ||
|
|
cd8d895c1b | ||
|
|
4577a01c68 | ||
|
|
6758387668 | ||
|
|
424702b272 | ||
|
|
191f98a008 | ||
|
|
00de7674af | ||
|
|
32fa032a62 | ||
|
|
73e44cb803 | ||
|
|
3e4350afa4 | ||
|
|
0d07caba60 | ||
|
|
3992ce2502 | ||
|
|
215d6f0c5b | ||
|
|
f3394f46b4 | ||
|
|
e3df758897 | ||
|
|
d7319ecd00 | ||
|
|
d661b3a532 | ||
|
|
c0be5ddbb2 | ||
|
|
97d431d1f4 | ||
|
|
a849e1107e | ||
|
|
a41bdff88f | ||
|
|
cb383e6b1a | ||
|
|
45b6872e2a | ||
|
|
056109652d | ||
|
|
284600ef1f | ||
|
|
af506985e5 | ||
|
|
240d2a7f14 | ||
|
|
34656f9e5d | ||
|
|
c61c112218 | ||
|
|
55974bc743 | ||
|
|
94005513a4 | ||
|
|
36edec6231 | ||
|
|
7d176245d8 | ||
|
|
c65d58c589 | ||
|
|
1f9fd0f060 | ||
|
|
1218da79a9 |
10
LICENSE
10
LICENSE
@@ -1,5 +1,5 @@
|
|||||||
rgbasm, rgblink, and rgblib are derived from Justin Lloyd's RGBDS, which
|
rgbasm and rgblink are derived from Justin Lloyd's RGBDS, which is
|
||||||
is released under the following license:
|
released under the following license:
|
||||||
|
|
||||||
DO WHATEVER PUBLIC LICENSE*
|
DO WHATEVER PUBLIC LICENSE*
|
||||||
TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
|
TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
|
||||||
@@ -17,3 +17,9 @@ is released under the following license:
|
|||||||
|
|
||||||
rgbfix was rewritten from scratch by Anthony J. Bentley, and is released
|
rgbfix was rewritten from scratch by Anthony J. Bentley, and is released
|
||||||
under the ISC license; see the source file for the text of the license.
|
under the ISC license; see the source file for the text of the license.
|
||||||
|
|
||||||
|
extern/err.c is derived from the Musl C library, http://www.musl-libc.org,
|
||||||
|
and is released under the MIT license.
|
||||||
|
|
||||||
|
extern/strl.c is derived from the OpenBSD Project, http://www.openbsd.org,
|
||||||
|
and is released under the BSD license.
|
||||||
|
|||||||
123
Makefile
123
Makefile
@@ -1,4 +1,8 @@
|
|||||||
CFLAGS += -Wall -Iinclude -Iinclude/asm/gameboy -g -std=c99
|
.POSIX:
|
||||||
|
|
||||||
|
WARNFLAGS = -Wall -Werror=implicit
|
||||||
|
REALCFLAGS = ${CFLAGS} ${WARNFLAGS} -Iinclude -g \
|
||||||
|
-std=c99 -D_POSIX_C_SOURCE=200809L
|
||||||
|
|
||||||
# User-defined variables
|
# User-defined variables
|
||||||
PREFIX = /usr/local
|
PREFIX = /usr/local
|
||||||
@@ -6,14 +10,9 @@ BINPREFIX = ${PREFIX}/bin
|
|||||||
MANPREFIX = ${PREFIX}/man
|
MANPREFIX = ${PREFIX}/man
|
||||||
Q = @
|
Q = @
|
||||||
|
|
||||||
yacc_pre := \
|
rgbasm_obj = \
|
||||||
src/asm/yaccprt1.y\
|
|
||||||
src/asm/gameboy/yaccprt2.y\
|
|
||||||
src/asm/yaccprt3.y\
|
|
||||||
src/asm/gameboy/yaccprt4.y
|
|
||||||
|
|
||||||
rgbasm_obj := \
|
|
||||||
src/asm/asmy.o \
|
src/asm/asmy.o \
|
||||||
|
src/asm/charmap.o \
|
||||||
src/asm/fstack.o \
|
src/asm/fstack.o \
|
||||||
src/asm/globlex.o \
|
src/asm/globlex.o \
|
||||||
src/asm/lexer.o \
|
src/asm/lexer.o \
|
||||||
@@ -22,13 +21,12 @@ rgbasm_obj := \
|
|||||||
src/asm/output.o \
|
src/asm/output.o \
|
||||||
src/asm/rpn.o \
|
src/asm/rpn.o \
|
||||||
src/asm/symbol.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
|
||||||
|
|
||||||
rgblib_obj := \
|
rgblink_obj = \
|
||||||
src/lib/library.o \
|
|
||||||
src/lib/main.o
|
|
||||||
|
|
||||||
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 \
|
||||||
@@ -36,81 +34,74 @@ rgblink_obj := \
|
|||||||
src/link/object.o \
|
src/link/object.o \
|
||||||
src/link/output.o \
|
src/link/output.o \
|
||||||
src/link/patch.o \
|
src/link/patch.o \
|
||||||
src/link/symbol.o
|
src/link/symbol.o \
|
||||||
|
src/extern/err.o
|
||||||
|
|
||||||
rgbfix_obj := \
|
rgbfix_obj = \
|
||||||
src/fix/main.o
|
src/fix/main.o \
|
||||||
|
src/extern/err.o
|
||||||
|
|
||||||
all: rgbasm rgblib rgblink rgbfix
|
all: rgbasm rgblink rgbfix
|
||||||
|
|
||||||
clean:
|
clean:
|
||||||
${Q}rm -rf rgbds.html
|
$Qrm -rf rgbds.html
|
||||||
${Q}rm -rf rgbasm rgbasm.exe ${rgbasm_obj} rgbasm.html
|
$Qrm -rf rgbasm rgbasm.exe ${rgbasm_obj} rgbasm.html
|
||||||
${Q}rm -rf rgblib rgblib.exe ${rgblib_obj} rgblib.html
|
$Qrm -rf rgblink rgblink.exe ${rgblink_obj} rgblink.html
|
||||||
${Q}rm -rf rgblink rgblink.exe ${rgblink_obj} rgblink.html
|
$Qrm -rf rgbfix rgbfix.exe ${rgbfix_obj} rgbfix.html
|
||||||
${Q}rm -rf rgbfix rgbfix.exe ${rgbfix_obj} rgbfix.html
|
$Qrm -rf src/asm/asmy.c src/asm/asmy.h
|
||||||
${Q}rm -rf src/asm/asmy.c src/asm/asmy.h src/asm/asmy.y
|
|
||||||
|
|
||||||
install: all
|
install: all
|
||||||
${Q}install -s -m 555 rgbasm ${BINPREFIX}/rgbasm
|
$Qmkdir -p ${BINPREFIX}
|
||||||
${Q}install -s -m 555 rgbfix ${BINPREFIX}/rgbfix
|
$Qinstall -s -m 555 rgbasm ${BINPREFIX}/rgbasm
|
||||||
${Q}install -s -m 555 rgblink ${BINPREFIX}/rgblink
|
$Qinstall -s -m 555 rgbfix ${BINPREFIX}/rgbfix
|
||||||
${Q}install -s -m 555 rgblib ${BINPREFIX}/rgblib
|
$Qinstall -s -m 555 rgblink ${BINPREFIX}/rgblink
|
||||||
${Q}install -m 444 src/rgbds.7 ${MANPREFIX}/man7/rgbds.7 || \
|
$Qmkdir -p ${MANPREFIX}/man1 ${MANPREFIX}/man7
|
||||||
(echo Installing manpages to ${MANPREFIX} failed. >&2 && \
|
$Qinstall -m 444 src/rgbds.7 ${MANPREFIX}/man7/rgbds.7
|
||||||
echo Check where your manpages are installed and set the \
|
$Qinstall -m 444 src/asm/rgbasm.1 ${MANPREFIX}/man1/rgbasm.1
|
||||||
proper directory >&2 && \
|
$Qinstall -m 444 src/fix/rgbfix.1 ${MANPREFIX}/man1/rgbfix.1
|
||||||
echo with, e.g., make install MANPREFIX=/usr/share/man \
|
$Qinstall -m 444 src/link/rgblink.1 ${MANPREFIX}/man1/rgblink.1
|
||||||
>&2 ; false)
|
|
||||||
${Q}install -m 444 src/asm/rgbasm.1 \
|
|
||||||
${MANPREFIX}/man1/rgbasm.1
|
|
||||||
${Q}install -m 444 src/fix/rgbfix.1 \
|
|
||||||
${MANPREFIX}/man1/rgbfix.1
|
|
||||||
${Q}install -m 444 src/link/rgblink.1 \
|
|
||||||
${MANPREFIX}/man1/rgblink.1
|
|
||||||
${Q}install -m 444 src/lib/rgblib.1 \
|
|
||||||
${MANPREFIX}/man1/rgblib.1
|
|
||||||
|
|
||||||
rgbasm: ${rgbasm_obj}
|
rgbasm: ${rgbasm_obj}
|
||||||
${Q}${CC} ${CFLAGS} -o $@ ${rgbasm_obj} -lm
|
$Q${CC} ${REALCFLAGS} -o $@ ${rgbasm_obj} -lm
|
||||||
|
|
||||||
rgblib: ${rgblib_obj}
|
|
||||||
${Q}${CC} ${CFLAGS} -o $@ ${rgblib_obj}
|
|
||||||
|
|
||||||
rgblink: ${rgblink_obj}
|
rgblink: ${rgblink_obj}
|
||||||
${Q}${CC} ${CFLAGS} -o $@ ${rgblink_obj}
|
$Q${CC} ${REALCFLAGS} -o $@ ${rgblink_obj}
|
||||||
|
|
||||||
rgbfix: ${rgbfix_obj}
|
rgbfix: ${rgbfix_obj}
|
||||||
${Q}${CC} ${CFLAGS} -o $@ ${rgbfix_obj}
|
$Q${CC} ${REALCFLAGS} -o $@ ${rgbfix_obj}
|
||||||
|
|
||||||
|
.y.c:
|
||||||
|
$Q${YACC} -d ${YFLAGS} -o $@ $<
|
||||||
|
|
||||||
.c.o:
|
.c.o:
|
||||||
${Q}${CC} ${CFLAGS} -c -o $@ $<
|
$Q${CC} ${REALCFLAGS} -c -o $@ $<
|
||||||
|
|
||||||
src/asm/asmy.c: src/asm/asmy.y
|
|
||||||
${Q}${YACC} -d -o $@ $<
|
|
||||||
|
|
||||||
src/asm/asmy.y: ${yacc_pre}
|
|
||||||
${Q}cat ${yacc_pre} > $@
|
|
||||||
|
|
||||||
|
src/asm/locallex.o src/asm/globlex.o src/asm/lexer.o: src/asm/asmy.h
|
||||||
|
src/asm/asmy.h: src/asm/asmy.c
|
||||||
|
|
||||||
# Below is a target for the project maintainer to easily create win32 exes.
|
# Below is a target for the project maintainer to easily create win32 exes.
|
||||||
# This is not for Windows users!
|
# This is not for Windows users!
|
||||||
# If you're building on Windows with Cygwin or Mingw, just follow the Unix
|
# If you're building on Windows with Cygwin or Mingw, just follow the Unix
|
||||||
# install instructions instead.
|
# install instructions instead.
|
||||||
mingw:
|
mingw:
|
||||||
${Q}env PATH=/usr/local/mingw32/bin:/bin:/usr/bin:/usr/local/bin make CC=gcc CFLAGS="-I/usr/local/mingw32/include ${CFLAGS}"
|
$Qenv PATH=/usr/local/mingw32/bin:/bin:/usr/bin:/usr/local/bin \
|
||||||
${Q}mv rgbasm rgbasm.exe
|
make CC=gcc CFLAGS="-I/usr/local/mingw32/include \
|
||||||
${Q}mv rgblib rgblib.exe
|
-D__progname=\\\"\\\" \
|
||||||
${Q}mv rgblink rgblink.exe
|
${CFLAGS}"
|
||||||
${Q}mv rgbfix rgbfix.exe
|
$Qmv rgbasm rgbasm.exe
|
||||||
|
$Qmv rgblink rgblink.exe
|
||||||
|
$Qmv rgbfix rgbfix.exe
|
||||||
|
|
||||||
# Below is a target for the project maintainer to easily create web manuals.
|
# Below is a target for the project maintainer to easily create web manuals.
|
||||||
# It relies on mandoc: http://mdocml.bsd.lv
|
# It relies on mandoc: http://mdocml.bsd.lv
|
||||||
MANDOC = -Thtml -Oman=/rgbds/manual/%N/ -Ostyle=/rgbds/manual/manual.css -Ios=General
|
MANDOC = -Thtml -Ios=General -Oman=/rgbds/manual/%N/ \
|
||||||
|
-Ostyle=/rgbds/manual/manual.css
|
||||||
|
|
||||||
wwwman:
|
wwwman:
|
||||||
${Q}mandoc ${MANDOC} src/rgbds.7 | sed s/OpenBSD/General/ > rgbds.html
|
$Qmandoc ${MANDOC} src/rgbds.7 | sed s/OpenBSD/General/ > rgbds.html
|
||||||
${Q}mandoc ${MANDOC} src/asm/rgbasm.1 | sed s/OpenBSD/General/ > rgbasm.html
|
$Qmandoc ${MANDOC} src/asm/rgbasm.1 | sed s/OpenBSD/General/ > \
|
||||||
${Q}mandoc ${MANDOC} src/fix/rgbfix.1 | sed s/OpenBSD/General/ > rgbfix.html
|
rgbasm.html
|
||||||
${Q}mandoc ${MANDOC} src/lib/rgblib.1 | sed s/OpenBSD/General/ > rgblib.html
|
$Qmandoc ${MANDOC} src/fix/rgbfix.1 | sed s/OpenBSD/General/ > \
|
||||||
${Q}mandoc ${MANDOC} src/link/rgblink.1 | sed s/OpenBSD/General/ > rgblink.html
|
rgbfix.html
|
||||||
|
$Qmandoc ${MANDOC} src/link/rgblink.1 | sed s/OpenBSD/General/ > \
|
||||||
|
rgblink.html
|
||||||
|
|||||||
1
README
1
README
@@ -7,7 +7,6 @@ for the Game Boy and Game Boy Color. It consists of:
|
|||||||
|
|
||||||
- rgbasm (assembler)
|
- rgbasm (assembler)
|
||||||
- rgblink (linker)
|
- rgblink (linker)
|
||||||
- rgblib (library manager)
|
|
||||||
- rgbfix (checksum/header fixer)
|
- rgbfix (checksum/header fixer)
|
||||||
|
|
||||||
rgbds-linux is a fork of the original RGBDS which aims to make the programs
|
rgbds-linux is a fork of the original RGBDS which aims to make the programs
|
||||||
|
|||||||
@@ -12,7 +12,6 @@
|
|||||||
<li><a href="geninfo.htm">ASMotor General Information</a>
|
<li><a href="geninfo.htm">ASMotor General Information</a>
|
||||||
<li><a href="asm.htm">xASM Documentation</a>
|
<li><a href="asm.htm">xASM Documentation</a>
|
||||||
<li><a href="link.htm">xLink Documentation</a>
|
<li><a href="link.htm">xLink Documentation</a>
|
||||||
<li><a href="lib.htm">xLib Documentation</a>
|
|
||||||
<li><a href="fix.htm">RGBFix Documentation</a>
|
<li><a href="fix.htm">RGBFix Documentation</a>
|
||||||
<li><a href="rgb0.htm">The RGB0-2 ObjectFileFormat</a>
|
<li><a href="rgb0.htm">The RGB0-2 ObjectFileFormat</a>
|
||||||
</ul>
|
</ul>
|
||||||
|
|||||||
47
doc/lib.htm
47
doc/lib.htm
@@ -1,47 +0,0 @@
|
|||||||
<!DOCTYPE HTML PUBliC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
|
|
||||||
<html>
|
|
||||||
<head>
|
|
||||||
<meta http-equiv="Content-Type" content="text/html;charset=UTF-8">
|
|
||||||
<title>xLib</title>
|
|
||||||
<link rel="stylesheet" type="text/css" href="./style.css">
|
|
||||||
</head>
|
|
||||||
<body>
|
|
||||||
<h1>xLib Documentation</h1>
|
|
||||||
<h2>Table of Contents</h2>
|
|
||||||
<ul>
|
|
||||||
<li><a href="#history"> History</A>
|
|
||||||
<li><a href="#usage"> Usage</A>
|
|
||||||
<li><a href="#commands"> The commands</A>
|
|
||||||
</ul>
|
|
||||||
<hr>
|
|
||||||
<h2 id="history">History</h2>
|
|
||||||
<table>
|
|
||||||
<caption>The history of xLib</caption>
|
|
||||||
<thead>
|
|
||||||
<tr>
|
|
||||||
<th scope="col">Version</th>
|
|
||||||
<th scope="col">Dated</th>
|
|
||||||
<th scope="col">Release notes</th>
|
|
||||||
</tr>
|
|
||||||
</thead>
|
|
||||||
<tr>
|
|
||||||
<td>1.0</td>
|
|
||||||
<td>21 Sep. 1997</td>
|
|
||||||
<td>First release</td>
|
|
||||||
</tr>
|
|
||||||
</table>
|
|
||||||
<h2 id="usage">Usage</h2>
|
|
||||||
<pre> xlib library command [module1 module2 ... modulen]</pre>
|
|
||||||
<h2 id="commands">The Commands</h2>
|
|
||||||
<p>The <b>command</b> specified after <b>library</b> on the <a href="#Usage">commandline</a> tells xLib what to do.
|
|
||||||
<p>The following commands are available:
|
|
||||||
<ul>
|
|
||||||
<li>a — Adds (or replaces if already present) the modules to the library
|
|
||||||
<li>d — Deletes the modules specified from the library
|
|
||||||
<li>l — Lists the library contents
|
|
||||||
<li>x — Extracts the modules from the library
|
|
||||||
</ul>
|
|
||||||
<hr>
|
|
||||||
<p>Last updated 21 September 1997 by <a href="mailto:surfsmurf@matilde.demon.co.uk">Carsten Sorensen</a></p>
|
|
||||||
</body>
|
|
||||||
</html>
|
|
||||||
@@ -9,16 +9,15 @@
|
|||||||
#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"
|
||||||
|
|
||||||
#include "localasm.h"
|
#include "localasm.h"
|
||||||
|
|
||||||
#include "asmotor.h"
|
|
||||||
|
|
||||||
extern SLONG nLineNo;
|
extern SLONG nLineNo;
|
||||||
extern ULONG nTotalLines;
|
extern ULONG nTotalLines;
|
||||||
extern ULONG nPC;
|
extern ULONG nPC;
|
||||||
@@ -28,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 */
|
||||||
|
|||||||
18
include/asm/charmap.h
Normal file
18
include/asm/charmap.h
Normal file
@@ -0,0 +1,18 @@
|
|||||||
|
#ifndef ASMOTOR_ASM_CHARMAP_H
|
||||||
|
#define ASMOTOR_ASM_CHARMAP_H
|
||||||
|
|
||||||
|
#define MAXCHARMAPS 512
|
||||||
|
#define CHARMAPLENGTH 8
|
||||||
|
|
||||||
|
struct Charmap {
|
||||||
|
int count;
|
||||||
|
char input[MAXCHARMAPS][CHARMAPLENGTH + 1];
|
||||||
|
char output[MAXCHARMAPS];
|
||||||
|
};
|
||||||
|
|
||||||
|
int readUTF8Char(char *destination, char *source);
|
||||||
|
void charmap_Sort();
|
||||||
|
int charmap_Add(char *input, UBYTE output);
|
||||||
|
int charmap_Convert(char **input);
|
||||||
|
|
||||||
|
#endif
|
||||||
@@ -9,6 +9,8 @@
|
|||||||
#ifndef ASMOTOR_ASM_FSTACK_H
|
#ifndef ASMOTOR_ASM_FSTACK_H
|
||||||
#define ASMOTOR_ASM_FSTACK_H
|
#define ASMOTOR_ASM_FSTACK_H
|
||||||
|
|
||||||
|
#include <stdio.h>
|
||||||
|
|
||||||
#include "asm/asm.h"
|
#include "asm/asm.h"
|
||||||
#include "asm/types.h"
|
#include "asm/types.h"
|
||||||
#include "asm/lexer.h"
|
#include "asm/lexer.h"
|
||||||
@@ -27,14 +29,17 @@ struct sContext {
|
|||||||
ULONG nREPTBlockSize;
|
ULONG nREPTBlockSize;
|
||||||
};
|
};
|
||||||
|
|
||||||
extern ULONG fstk_RunInclude(char *s);
|
void
|
||||||
|
fstk_RunInclude(char *);
|
||||||
extern void fstk_RunMacroArg(SLONG s);
|
extern void fstk_RunMacroArg(SLONG s);
|
||||||
extern ULONG fstk_Init(char *s);
|
void
|
||||||
|
fstk_Init(char *);
|
||||||
extern void fstk_Dump(void);
|
extern void fstk_Dump(void);
|
||||||
extern void fstk_AddIncludePath(char *s);
|
extern void fstk_AddIncludePath(char *s);
|
||||||
extern ULONG fstk_RunMacro(char *s);
|
extern ULONG fstk_RunMacro(char *s);
|
||||||
extern void fstk_RunRept(ULONG count);
|
extern void fstk_RunRept(ULONG count);
|
||||||
extern void fstk_FindFile(char *s);
|
FILE *
|
||||||
|
fstk_FindFile(char *);
|
||||||
|
|
||||||
extern int yywrap(void);
|
extern int yywrap(void);
|
||||||
|
|
||||||
|
|||||||
@@ -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
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -14,5 +14,8 @@ SLONG math_ATan(SLONG i);
|
|||||||
SLONG math_ATan2(SLONG i, SLONG j);
|
SLONG math_ATan2(SLONG i, SLONG j);
|
||||||
SLONG math_Mul(SLONG i, SLONG j);
|
SLONG math_Mul(SLONG i, SLONG j);
|
||||||
SLONG math_Div(SLONG i, SLONG j);
|
SLONG math_Div(SLONG i, SLONG j);
|
||||||
|
SLONG math_Round(SLONG i);
|
||||||
|
SLONG math_Ceil(SLONG i);
|
||||||
|
SLONG math_Floor(SLONG i);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -12,6 +12,7 @@ struct Section {
|
|||||||
ULONG nBank;
|
ULONG nBank;
|
||||||
struct Section *pNext;
|
struct Section *pNext;
|
||||||
struct Patch *pPatches;
|
struct Patch *pPatches;
|
||||||
|
struct Charmap *charmap;
|
||||||
UBYTE *tData;
|
UBYTE *tData;
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -20,12 +21,14 @@ void out_SetFileName(char *s);
|
|||||||
void out_NewSection(char *pzName, ULONG secttype);
|
void out_NewSection(char *pzName, ULONG secttype);
|
||||||
void out_NewAbsSection(char *pzName, ULONG secttype, SLONG org, SLONG bank);
|
void out_NewAbsSection(char *pzName, ULONG secttype, SLONG org, SLONG bank);
|
||||||
void out_AbsByte(int b);
|
void out_AbsByte(int b);
|
||||||
|
void out_AbsByteGroup(char *s, int length);
|
||||||
void out_RelByte(struct Expression * expr);
|
void out_RelByte(struct Expression * expr);
|
||||||
void out_RelWord(struct Expression * expr);
|
void out_RelWord(struct Expression * expr);
|
||||||
void out_PCRelByte(struct Expression * expr);
|
void out_PCRelByte(struct Expression * expr);
|
||||||
void out_WriteObject(void);
|
void out_WriteObject(void);
|
||||||
void out_Skip(int skip);
|
void out_Skip(int skip);
|
||||||
void out_BinaryFile(char *s);
|
void out_BinaryFile(char *s);
|
||||||
|
void out_BinaryFileSlice(char *s, SLONG start_pos, SLONG length);
|
||||||
void out_String(char *s);
|
void out_String(char *s);
|
||||||
void out_AbsLong(SLONG b);
|
void out_AbsLong(SLONG b);
|
||||||
void out_RelLong(struct Expression * expr);
|
void out_RelLong(struct Expression * expr);
|
||||||
|
|||||||
@@ -1,7 +1,9 @@
|
|||||||
#ifndef ASMOTOR_ASM_TYPES_H
|
#ifndef ASMOTOR_ASM_TYPES_H
|
||||||
#define ASMOTOR_ASM_TYPES_H
|
#define ASMOTOR_ASM_TYPES_H
|
||||||
|
|
||||||
|
#ifndef _MAX_PATH
|
||||||
#define _MAX_PATH 512
|
#define _MAX_PATH 512
|
||||||
|
#endif
|
||||||
|
|
||||||
typedef unsigned char UBYTE;
|
typedef unsigned char UBYTE;
|
||||||
typedef signed char SBYTE;
|
typedef signed char SBYTE;
|
||||||
|
|||||||
@@ -1,21 +0,0 @@
|
|||||||
/* asmotor.h
|
|
||||||
*
|
|
||||||
* Contains defines for every program in the ASMotor package
|
|
||||||
*
|
|
||||||
* Copyright 1997 Carsten Sorensen
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
|
|
||||||
#ifndef ASMOTOR_ASMOTOR_H
|
|
||||||
#define ASMOTOR_ASMOTOR_H
|
|
||||||
|
|
||||||
#define ASMOTOR
|
|
||||||
|
|
||||||
#define ASMOTOR_VERSION "1.10-linux"
|
|
||||||
|
|
||||||
#define ASM_VERSION "1.08c"
|
|
||||||
#define LINK_VERSION "1.06c"
|
|
||||||
#define RGBFIX_VERSION "1.02"
|
|
||||||
#define LIB_VERSION "1.00"
|
|
||||||
|
|
||||||
#endif
|
|
||||||
64
include/extern/err.h
vendored
Normal file
64
include/extern/err.h
vendored
Normal file
@@ -0,0 +1,64 @@
|
|||||||
|
/*
|
||||||
|
* Copyright © 2005-2013 Rich Felker, et al.
|
||||||
|
*
|
||||||
|
* Permission is hereby granted, free of charge, to any person obtaining
|
||||||
|
* a copy of this software and associated documentation files (the
|
||||||
|
* "Software"), to deal in the Software without restriction, including
|
||||||
|
* without limitation the rights to use, copy, modify, merge, publish,
|
||||||
|
* distribute, sublicense, and/or sell copies of the Software, and to
|
||||||
|
* permit persons to whom the Software is furnished to do so, subject to
|
||||||
|
* the following conditions:
|
||||||
|
*
|
||||||
|
* The above copyright notice and this permission notice shall be
|
||||||
|
* included in all copies or substantial portions of the Software.
|
||||||
|
*
|
||||||
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||||
|
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||||
|
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
||||||
|
* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
||||||
|
* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
||||||
|
* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
||||||
|
* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef EXTERN_ERR_H
|
||||||
|
#define EXTERN_ERR_H
|
||||||
|
|
||||||
|
#ifdef ERR_IN_LIBC
|
||||||
|
#include <err.h>
|
||||||
|
#else
|
||||||
|
|
||||||
|
#include <stdarg.h>
|
||||||
|
#include "stdnoreturn.h"
|
||||||
|
|
||||||
|
#define warn rgbds_warn
|
||||||
|
#define vwarn rgbds_vwarn
|
||||||
|
#define warnx rgbds_warnx
|
||||||
|
#define vwarnx rgbds_vwarnx
|
||||||
|
|
||||||
|
#define err rgbds_err
|
||||||
|
#define verr rgbds_verr
|
||||||
|
#define errx rgbds_errx
|
||||||
|
#define verrx rgbds_verrx
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
extern "C" {
|
||||||
|
#endif
|
||||||
|
|
||||||
|
void warn(const char *, ...);
|
||||||
|
void vwarn(const char *, va_list);
|
||||||
|
void warnx(const char *, ...);
|
||||||
|
void vwarnx(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
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#endif
|
||||||
16
include/extern/stdnoreturn.h
vendored
Normal file
16
include/extern/stdnoreturn.h
vendored
Normal 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
|
||||||
13
include/extern/strl.h
vendored
Normal file
13
include/extern/strl.h
vendored
Normal file
@@ -0,0 +1,13 @@
|
|||||||
|
#ifndef STRL_H
|
||||||
|
#define STRL_H
|
||||||
|
|
||||||
|
#ifdef STRL_IN_LIBC
|
||||||
|
#include <string.h>
|
||||||
|
#else
|
||||||
|
#define strlcpy rgbds_strlcpy
|
||||||
|
#define strlcat rgbds_strlcat
|
||||||
|
size_t strlcpy(char *, const char *, size_t);
|
||||||
|
size_t strlcat(char *, const char *, size_t);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#endif
|
||||||
@@ -1,13 +0,0 @@
|
|||||||
#ifndef ASMOTOR_LIB_LIBRARY_H
|
|
||||||
#define ASMOTOR_LIB_LIBRARY_H
|
|
||||||
|
|
||||||
#include "lib/libwrap.h"
|
|
||||||
|
|
||||||
extern sLibrary *lib_Read(char *filename);
|
|
||||||
extern BBOOL lib_Write(sLibrary * lib, char *filename);
|
|
||||||
extern sLibrary *lib_AddReplace(sLibrary * lib, char *filename);
|
|
||||||
extern void lib_Free(sLibrary * lib);
|
|
||||||
extern sLibrary *lib_DeleteModule(sLibrary * lib, char *filename);
|
|
||||||
extern sLibrary *lib_Find(sLibrary * lib, char *filename);
|
|
||||||
|
|
||||||
#endif
|
|
||||||
@@ -1,19 +0,0 @@
|
|||||||
#ifndef ASMOTOR_LIB_LIBWRAP_H
|
|
||||||
#define ASMOTOR_LIB_LIBWRAP_H
|
|
||||||
|
|
||||||
#include "lib/types.h"
|
|
||||||
|
|
||||||
#define MAXNAMELENGTH 256
|
|
||||||
|
|
||||||
struct LibraryWrapper {
|
|
||||||
char tName[MAXNAMELENGTH];
|
|
||||||
UWORD uwTime;
|
|
||||||
UWORD uwDate;
|
|
||||||
SLONG nByteLength;
|
|
||||||
UBYTE *pData;
|
|
||||||
struct LibraryWrapper *pNext;
|
|
||||||
};
|
|
||||||
|
|
||||||
typedef struct LibraryWrapper sLibrary;
|
|
||||||
|
|
||||||
#endif
|
|
||||||
@@ -1,14 +0,0 @@
|
|||||||
#ifndef ASMOTOR_LIB_TYPES_H
|
|
||||||
#define ASMOTOR_LIB_TYPES_H
|
|
||||||
|
|
||||||
#define _MAX_PATH 512
|
|
||||||
|
|
||||||
typedef unsigned char UBYTE;
|
|
||||||
typedef signed char SBYTE;
|
|
||||||
typedef unsigned short UWORD;
|
|
||||||
typedef signed short SWORD;
|
|
||||||
typedef unsigned long ULONG;
|
|
||||||
typedef signed long SLONG;
|
|
||||||
typedef signed char BBOOL;
|
|
||||||
|
|
||||||
#endif
|
|
||||||
@@ -1,7 +1,9 @@
|
|||||||
#ifndef ASMOTOR_LINK_LINK_H
|
#ifndef ASMOTOR_LINK_LINK_H
|
||||||
#define ASMOTOR_LINK_LINK_H
|
#define ASMOTOR_LINK_LINK_H
|
||||||
|
|
||||||
|
#ifndef _MAX_PATH
|
||||||
#define _MAX_PATH 512
|
#define _MAX_PATH 512
|
||||||
|
#endif
|
||||||
|
|
||||||
#include "link/types.h"
|
#include "link/types.h"
|
||||||
|
|
||||||
|
|||||||
@@ -2,6 +2,5 @@
|
|||||||
#define ASMOTOR_LINK_OBJECT_H
|
#define ASMOTOR_LINK_OBJECT_H
|
||||||
|
|
||||||
extern void obj_Readfile(char *tzObjectfile);
|
extern void obj_Readfile(char *tzObjectfile);
|
||||||
extern void lib_Readfile(char *tzLibfile);
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -1,7 +1,9 @@
|
|||||||
#ifndef ASMOTOR_LINK_TYPES_H
|
#ifndef ASMOTOR_LINK_TYPES_H
|
||||||
#define ASMOTOR_LINK_TYPES_H
|
#define ASMOTOR_LINK_TYPES_H
|
||||||
|
|
||||||
|
#ifndef _MAX_PATH
|
||||||
#define _MAX_PATH 512
|
#define _MAX_PATH 512
|
||||||
|
#endif
|
||||||
|
|
||||||
typedef unsigned char UBYTE;
|
typedef unsigned char UBYTE;
|
||||||
typedef signed char SBYTE;
|
typedef signed char SBYTE;
|
||||||
|
|||||||
1
src/asm/.gitignore
vendored
1
src/asm/.gitignore
vendored
@@ -1,3 +1,2 @@
|
|||||||
asmy.c
|
asmy.c
|
||||||
asmy.h
|
asmy.h
|
||||||
asmy.y
|
|
||||||
|
|||||||
1597
src/asm/asmy.y
Normal file
1597
src/asm/asmy.y
Normal file
File diff suppressed because it is too large
Load Diff
204
src/asm/charmap.c
Normal file
204
src/asm/charmap.c
Normal file
@@ -0,0 +1,204 @@
|
|||||||
|
/*
|
||||||
|
* Copyright © 2013 stag019 <stag019@gmail.com>
|
||||||
|
*
|
||||||
|
* Permission to use, copy, modify, and distribute this software for any
|
||||||
|
* purpose with or without fee is hereby granted, provided that the above
|
||||||
|
* copyright notice and this permission notice appear in all copies.
|
||||||
|
*
|
||||||
|
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
||||||
|
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
||||||
|
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
||||||
|
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
||||||
|
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
||||||
|
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
||||||
|
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <string.h>
|
||||||
|
|
||||||
|
#include "asm/asm.h"
|
||||||
|
#include "asm/charmap.h"
|
||||||
|
#include "asm/main.h"
|
||||||
|
#include "asm/output.h"
|
||||||
|
|
||||||
|
struct Charmap globalCharmap = {0};
|
||||||
|
|
||||||
|
extern struct Section *pCurrentSection;
|
||||||
|
|
||||||
|
int
|
||||||
|
readUTF8Char(char *destination, char *source)
|
||||||
|
{
|
||||||
|
int size;
|
||||||
|
UBYTE first;
|
||||||
|
first = source[0];
|
||||||
|
|
||||||
|
if(first >= 0xFC)
|
||||||
|
{
|
||||||
|
size = 6;
|
||||||
|
}
|
||||||
|
else if(first >= 0xF8)
|
||||||
|
{
|
||||||
|
size = 5;
|
||||||
|
}
|
||||||
|
else if(first >= 0xF0)
|
||||||
|
{
|
||||||
|
size = 4;
|
||||||
|
}
|
||||||
|
else if(first >= 0xE0)
|
||||||
|
{
|
||||||
|
size = 3;
|
||||||
|
}
|
||||||
|
else if(first >= 0xC0)
|
||||||
|
{
|
||||||
|
size = 2;
|
||||||
|
}
|
||||||
|
else if(first != '\0')
|
||||||
|
{
|
||||||
|
size = 1;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
size = 0;
|
||||||
|
}
|
||||||
|
strncpy(destination, source, size);
|
||||||
|
destination[size] = 0;
|
||||||
|
return size;
|
||||||
|
}
|
||||||
|
|
||||||
|
int
|
||||||
|
charmap_Add(char *input, UBYTE output)
|
||||||
|
{
|
||||||
|
int i, input_length;
|
||||||
|
char temp1i[CHARMAPLENGTH + 1], temp2i[CHARMAPLENGTH + 1], temp1o = 0, temp2o = 0;
|
||||||
|
|
||||||
|
struct Charmap *charmap;
|
||||||
|
|
||||||
|
if(pCurrentSection)
|
||||||
|
{
|
||||||
|
if(pCurrentSection -> charmap)
|
||||||
|
{
|
||||||
|
charmap = pCurrentSection -> charmap;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if((charmap = (struct Charmap *) calloc(1, sizeof(struct Charmap))) == NULL)
|
||||||
|
{
|
||||||
|
fatalerror("Not enough memory for charmap");
|
||||||
|
}
|
||||||
|
pCurrentSection -> charmap = charmap;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
charmap = &globalCharmap;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(nPass == 2)
|
||||||
|
{
|
||||||
|
return charmap -> count;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(charmap -> count > MAXCHARMAPS || strlen(input) > CHARMAPLENGTH)
|
||||||
|
{
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
input_length = strlen(input);
|
||||||
|
if(input_length > 1)
|
||||||
|
{
|
||||||
|
i = 0;
|
||||||
|
while(i < charmap -> count + 1)
|
||||||
|
{
|
||||||
|
if(input_length > strlen(charmap -> input[i]))
|
||||||
|
{
|
||||||
|
memcpy(temp1i, charmap -> input[i], CHARMAPLENGTH + 1);
|
||||||
|
memcpy(charmap -> input[i], input, input_length);
|
||||||
|
temp1o = charmap -> output[i];
|
||||||
|
charmap -> output[i] = output;
|
||||||
|
i++;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
i++;
|
||||||
|
}
|
||||||
|
while(i < charmap -> count + 1)
|
||||||
|
{
|
||||||
|
memcpy(temp2i, charmap -> input[i], CHARMAPLENGTH + 1);
|
||||||
|
memcpy(charmap -> input[i], temp1i, CHARMAPLENGTH + 1);
|
||||||
|
memcpy(temp1i, temp2i, CHARMAPLENGTH + 1);
|
||||||
|
temp2o = charmap -> output[i];
|
||||||
|
charmap -> output[i] = temp1o;
|
||||||
|
temp1o = temp2o;
|
||||||
|
i++;
|
||||||
|
}
|
||||||
|
memcpy(charmap -> input[charmap -> count + 1], temp1i, CHARMAPLENGTH + 1);
|
||||||
|
charmap -> output[charmap -> count + 1] = temp1o;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
memcpy(charmap -> input[charmap -> count], input, input_length);
|
||||||
|
charmap -> output[charmap -> count] = output;
|
||||||
|
}
|
||||||
|
return ++charmap -> count;
|
||||||
|
}
|
||||||
|
|
||||||
|
int
|
||||||
|
charmap_Convert(char **input)
|
||||||
|
{
|
||||||
|
struct Charmap *charmap;
|
||||||
|
|
||||||
|
char outchar[CHARMAPLENGTH + 1];
|
||||||
|
char *buffer;
|
||||||
|
int i, j, length;
|
||||||
|
|
||||||
|
if(pCurrentSection && pCurrentSection -> charmap)
|
||||||
|
{
|
||||||
|
charmap = pCurrentSection -> charmap;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
charmap = &globalCharmap;
|
||||||
|
}
|
||||||
|
|
||||||
|
if((buffer = (char *) malloc(strlen(*input))) == NULL)
|
||||||
|
{
|
||||||
|
fatalerror("Not enough memory for buffer");
|
||||||
|
}
|
||||||
|
|
||||||
|
length = 0;
|
||||||
|
while(**input)
|
||||||
|
{
|
||||||
|
j = 0;
|
||||||
|
for(i = 0; i < charmap -> count; i++)
|
||||||
|
{
|
||||||
|
j = strlen(charmap -> input[i]);
|
||||||
|
if(memcmp(*input, charmap -> input[i], j) == 0)
|
||||||
|
{
|
||||||
|
outchar[0] = charmap -> output[i];
|
||||||
|
outchar[1] = 0;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
j = 0;
|
||||||
|
}
|
||||||
|
if(!j)
|
||||||
|
{
|
||||||
|
j = readUTF8Char(outchar, *input);
|
||||||
|
}
|
||||||
|
if(!outchar[0])
|
||||||
|
{
|
||||||
|
buffer[length++] = 0;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
for(i = 0; outchar[i]; i++)
|
||||||
|
{
|
||||||
|
buffer[length++] = outchar[i];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
*input += j;
|
||||||
|
}
|
||||||
|
*input = buffer;
|
||||||
|
return length;
|
||||||
|
}
|
||||||
|
|
||||||
172
src/asm/fstack.c
172
src/asm/fstack.c
@@ -1,10 +1,9 @@
|
|||||||
/*
|
/*
|
||||||
* RGBAsm - FSTACK.C (FileStack routines)
|
* FileStack routines
|
||||||
*
|
|
||||||
* INCLUDES
|
|
||||||
*
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#include <errno.h>
|
||||||
|
#include <limits.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
@@ -14,13 +13,12 @@
|
|||||||
#include "asm/types.h"
|
#include "asm/types.h"
|
||||||
#include "asm/main.h"
|
#include "asm/main.h"
|
||||||
#include "asm/lexer.h"
|
#include "asm/lexer.h"
|
||||||
|
#include "extern/err.h"
|
||||||
|
#include "extern/strl.h"
|
||||||
|
|
||||||
/*
|
#ifndef PATH_MAX
|
||||||
* RGBAsm - FSTACK.C (FileStack routines)
|
#define PATH_MAX 256
|
||||||
*
|
#endif
|
||||||
* VARIABLES
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
|
|
||||||
struct sContext *pFileStack;
|
struct sContext *pFileStack;
|
||||||
struct sSymbol *pCurrentMacro;
|
struct sSymbol *pCurrentMacro;
|
||||||
@@ -47,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)
|
||||||
{
|
{
|
||||||
@@ -62,8 +56,7 @@ pushcontext(void)
|
|||||||
while (*ppFileStack)
|
while (*ppFileStack)
|
||||||
ppFileStack = &((*ppFileStack)->pNext);
|
ppFileStack = &((*ppFileStack)->pNext);
|
||||||
|
|
||||||
if ((*ppFileStack =
|
if ((*ppFileStack = malloc(sizeof(struct sContext))) != NULL) {
|
||||||
(struct sContext *) malloc(sizeof(struct sContext))) != NULL) {
|
|
||||||
(*ppFileStack)->FlexHandle = CurrentFlexHandle;
|
(*ppFileStack)->FlexHandle = CurrentFlexHandle;
|
||||||
(*ppFileStack)->pNext = NULL;
|
(*ppFileStack)->pNext = NULL;
|
||||||
strcpy((char *) (*ppFileStack)->tzFileName,
|
strcpy((char *) (*ppFileStack)->tzFileName,
|
||||||
@@ -160,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)
|
||||||
{
|
{
|
||||||
@@ -182,60 +172,60 @@ 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)
|
||||||
{
|
{
|
||||||
strcpy(IncludePaths[NextIncPath++], s);
|
strcpy(IncludePaths[NextIncPath++], s);
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
FILE *
|
||||||
fstk_FindFile(char *s)
|
fstk_FindFile(char *fname)
|
||||||
{
|
{
|
||||||
char t[_MAX_PATH + 1];
|
char path[PATH_MAX];
|
||||||
SLONG i = -1;
|
int i;
|
||||||
|
|
||||||
strcpy(t, s);
|
|
||||||
|
|
||||||
while (i < NextIncPath) {
|
|
||||||
FILE *f;
|
FILE *f;
|
||||||
|
|
||||||
if ((f = fopen(t, "rb")) != NULL) {
|
if ((f = fopen(fname, "rb")) != NULL || errno != ENOENT) {
|
||||||
fclose(f);
|
return f;
|
||||||
strcpy(s, t);
|
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
i += 1;
|
|
||||||
if (i < NextIncPath) {
|
|
||||||
strcpy(t, IncludePaths[i]);
|
|
||||||
strcat(t, s);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
/*
|
|
||||||
* RGBAsm - FSTACK.C (FileStack routines)
|
|
||||||
*
|
|
||||||
* Set up an include file for parsing
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
|
|
||||||
ULONG
|
for (i = 0; i < NextIncPath; ++i) {
|
||||||
|
if (strlcpy(path, IncludePaths[i], sizeof path) >=
|
||||||
|
sizeof path) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
if (strlcat(path, fname, sizeof path) >= sizeof path) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ((f = fopen(path, "rb")) != NULL || errno != ENOENT) {
|
||||||
|
return f;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
errno = ENOENT;
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Set up an include file for parsing
|
||||||
|
*/
|
||||||
|
void
|
||||||
fstk_RunInclude(char *tzFileName)
|
fstk_RunInclude(char *tzFileName)
|
||||||
{
|
{
|
||||||
FILE *f;
|
FILE *f;
|
||||||
|
|
||||||
//printf("INCLUDE: %s\n", s);
|
f = fstk_FindFile(tzFileName);
|
||||||
|
|
||||||
fstk_FindFile(tzFileName);
|
if (f == NULL) {
|
||||||
//printf("INCLUDING: %s\n", tzFileName);
|
err(1, "Unable to open included file '%s'",
|
||||||
|
tzFileName);
|
||||||
|
}
|
||||||
|
|
||||||
if ((f = fopen(tzFileName, "r")) != NULL) {
|
|
||||||
pushcontext();
|
pushcontext();
|
||||||
nLineNo = 1;
|
nLineNo = 1;
|
||||||
nCurrentStatus = STAT_isInclude;
|
nCurrentStatus = STAT_isInclude;
|
||||||
@@ -248,18 +238,11 @@ fstk_RunInclude(char *tzFileName)
|
|||||||
|
|
||||||
yyunput('\n');
|
yyunput('\n');
|
||||||
nLineNo -= 1;
|
nLineNo -= 1;
|
||||||
|
|
||||||
return (1);
|
|
||||||
} else
|
|
||||||
return (0);
|
|
||||||
}
|
}
|
||||||
/*
|
|
||||||
* 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)
|
||||||
{
|
{
|
||||||
@@ -272,22 +255,21 @@ 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,
|
||||||
pCurrentMacro->ulMacroSize);
|
strlen(pCurrentMacro->pMacro));
|
||||||
yy_switch_to_buffer(CurrentFlexHandle);
|
yy_switch_to_buffer(CurrentFlexHandle);
|
||||||
return (1);
|
return (1);
|
||||||
} else
|
} else
|
||||||
return (0);
|
return (0);
|
||||||
}
|
}
|
||||||
/*
|
|
||||||
* RGBAsm - FSTACK.C (FileStack routines)
|
|
||||||
*
|
|
||||||
* Set up a macroargument for parsing
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Set up a macroargument for parsing
|
||||||
|
*/
|
||||||
void
|
void
|
||||||
fstk_RunMacroArg(SLONG s)
|
fstk_RunMacroArg(SLONG s)
|
||||||
{
|
{
|
||||||
@@ -307,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)
|
||||||
{
|
{
|
||||||
@@ -329,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)
|
||||||
{
|
{
|
||||||
@@ -353,14 +329,11 @@ fstk_RunRept(ULONG count)
|
|||||||
yy_switch_to_buffer(CurrentFlexHandle);
|
yy_switch_to_buffer(CurrentFlexHandle);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
/*
|
|
||||||
* RGBAsm - FSTACK.C (FileStack routines)
|
|
||||||
*
|
|
||||||
* Initialize the filestack routines
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
|
|
||||||
ULONG
|
/*
|
||||||
|
* Initialize the filestack routines
|
||||||
|
*/
|
||||||
|
void
|
||||||
fstk_Init(char *s)
|
fstk_Init(char *s)
|
||||||
{
|
{
|
||||||
char tzFileName[_MAX_PATH + 1];
|
char tzFileName[_MAX_PATH + 1];
|
||||||
@@ -368,17 +341,16 @@ fstk_Init(char *s)
|
|||||||
sym_AddString("__FILE__", s);
|
sym_AddString("__FILE__", s);
|
||||||
|
|
||||||
strcpy(tzFileName, s);
|
strcpy(tzFileName, s);
|
||||||
fstk_FindFile(tzFileName);
|
|
||||||
|
|
||||||
pFileStack = NULL;
|
pFileStack = NULL;
|
||||||
if ((pCurrentFile = fopen(tzFileName, "r")) != NULL) {
|
pCurrentFile = fopen(tzFileName, "rb");
|
||||||
|
if (pCurrentFile == NULL) {
|
||||||
|
err(1, "Unable to open file '%s'", tzFileName);
|
||||||
|
}
|
||||||
|
|
||||||
nMacroCount = 0;
|
nMacroCount = 0;
|
||||||
nCurrentStatus = STAT_isInclude;
|
nCurrentStatus = STAT_isInclude;
|
||||||
strcpy(tzCurrentFileName, tzFileName);
|
strcpy(tzCurrentFileName, tzFileName);
|
||||||
CurrentFlexHandle = yy_create_buffer(pCurrentFile);
|
CurrentFlexHandle = yy_create_buffer(pCurrentFile);
|
||||||
yy_switch_to_buffer(CurrentFlexHandle);
|
yy_switch_to_buffer(CurrentFlexHandle);
|
||||||
nLineNo = 1;
|
nLineNo = 1;
|
||||||
return (1);
|
|
||||||
} else
|
|
||||||
return (0);
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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
|
|
||||||
@@ -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; }
|
|
||||||
;
|
|
||||||
|
|
||||||
%%
|
|
||||||
@@ -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;
|
||||||
|
|
||||||
@@ -109,7 +110,7 @@ ascii2bin(char *s)
|
|||||||
ULONG
|
ULONG
|
||||||
ParseFixedPoint(char *s, ULONG size)
|
ParseFixedPoint(char *s, ULONG size)
|
||||||
{
|
{
|
||||||
char dest[256];
|
//char dest[256];
|
||||||
ULONG i = 0, dot = 0;
|
ULONG i = 0, dot = 0;
|
||||||
|
|
||||||
while (size && dot != 2) {
|
while (size && dot != 2) {
|
||||||
@@ -117,13 +118,13 @@ ParseFixedPoint(char *s, ULONG size)
|
|||||||
dot += 1;
|
dot += 1;
|
||||||
|
|
||||||
if (dot < 2) {
|
if (dot < 2) {
|
||||||
dest[i] = s[i];
|
//dest[i] = s[i];
|
||||||
size -= 1;
|
size -= 1;
|
||||||
i += 1;
|
i += 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
dest[i] = 0;
|
//dest[i] = 0;
|
||||||
|
|
||||||
yyunputbytes(size);
|
yyunputbytes(size);
|
||||||
|
|
||||||
@@ -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);
|
||||||
@@ -208,20 +209,29 @@ PutMacroArg(char *src, ULONG size)
|
|||||||
char *s;
|
char *s;
|
||||||
|
|
||||||
yyskipbytes(size);
|
yyskipbytes(size);
|
||||||
|
if ((size == 2 && src[1] >= '1' && src[1] <= '9')) {
|
||||||
if ((s = sym_FindMacroArg(src[1] - '0')) != NULL) {
|
if ((s = sym_FindMacroArg(src[1] - '0')) != NULL) {
|
||||||
yyunputstr(s);
|
yyunputstr(s);
|
||||||
} else {
|
} else {
|
||||||
yyerror("Macro argument not defined");
|
yyerror("Macro argument not defined");
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
yyerror("Invalid macro argument");
|
||||||
|
}
|
||||||
return (0);
|
return (0);
|
||||||
}
|
}
|
||||||
|
|
||||||
ULONG
|
ULONG
|
||||||
PutUniqueArg(char *src, ULONG size)
|
PutUniqueArg(char *src, ULONG size)
|
||||||
{
|
{
|
||||||
src = src;
|
char *s;
|
||||||
|
|
||||||
yyskipbytes(size);
|
yyskipbytes(size);
|
||||||
yyunputstr(sym_FindMacroArg(-1));
|
if ((s = sym_FindMacroArg(-1)) != NULL) {
|
||||||
|
yyunputstr(s);
|
||||||
|
} else {
|
||||||
|
yyerror("Macro unique label string not defined");
|
||||||
|
}
|
||||||
return (0);
|
return (0);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -258,6 +268,9 @@ struct sLexInitString staticstrings[] = {
|
|||||||
|
|
||||||
{"bank", T_OP_BANK},
|
{"bank", T_OP_BANK},
|
||||||
|
|
||||||
|
{"round", T_OP_ROUND},
|
||||||
|
{"ceil", T_OP_CEIL},
|
||||||
|
{"floor", T_OP_FLOOR},
|
||||||
{"div", T_OP_FDIV},
|
{"div", T_OP_FDIV},
|
||||||
{"mul", T_OP_FMUL},
|
{"mul", T_OP_FMUL},
|
||||||
{"sin", T_OP_SIN},
|
{"sin", T_OP_SIN},
|
||||||
@@ -298,6 +311,7 @@ struct sLexInitString staticstrings[] = {
|
|||||||
{"rsset", T_POP_RSSET},
|
{"rsset", T_POP_RSSET},
|
||||||
|
|
||||||
{"incbin", T_POP_INCBIN},
|
{"incbin", T_POP_INCBIN},
|
||||||
|
{"charmap", T_POP_CHARMAP},
|
||||||
|
|
||||||
{"fail", T_POP_FAIL},
|
{"fail", T_POP_FAIL},
|
||||||
{"warn", T_POP_WARN},
|
{"warn", T_POP_WARN},
|
||||||
@@ -387,7 +401,7 @@ setuplex(void)
|
|||||||
|
|
||||||
id = lex_FloatAlloc(&tMacroArgToken);
|
id = lex_FloatAlloc(&tMacroArgToken);
|
||||||
lex_FloatAddFirstRange(id, '\\', '\\');
|
lex_FloatAddFirstRange(id, '\\', '\\');
|
||||||
lex_FloatAddSecondRange(id, '0', '9');
|
lex_FloatAddSecondRange(id, '1', '9');
|
||||||
id = lex_FloatAlloc(&tMacroUniqueToken);
|
id = lex_FloatAlloc(&tMacroUniqueToken);
|
||||||
lex_FloatAddFirstRange(id, '\\', '\\');
|
lex_FloatAddFirstRange(id, '\\', '\\');
|
||||||
lex_FloatAddSecondRange(id, '@', '@');
|
lex_FloatAddSecondRange(id, '@', '@');
|
||||||
|
|||||||
@@ -1,17 +1,19 @@
|
|||||||
|
#include <stdio.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <string.h>
|
||||||
|
#include <strings.h>
|
||||||
|
#include <ctype.h>
|
||||||
|
|
||||||
#include "asm/asm.h"
|
#include "asm/asm.h"
|
||||||
#include "asm/lexer.h"
|
#include "asm/lexer.h"
|
||||||
#include "asm/types.h"
|
#include "asm/types.h"
|
||||||
#include "asm/main.h"
|
#include "asm/main.h"
|
||||||
#include "asm/rpn.h"
|
#include "asm/rpn.h"
|
||||||
#include "asm/fstack.h"
|
#include "asm/fstack.h"
|
||||||
|
#include "extern/err.h"
|
||||||
|
|
||||||
#include "asmy.h"
|
#include "asmy.h"
|
||||||
|
|
||||||
#include <stdio.h>
|
|
||||||
#include <stdlib.h>
|
|
||||||
#include <string.h>
|
|
||||||
#include <ctype.h>
|
|
||||||
|
|
||||||
struct sLexString {
|
struct sLexString {
|
||||||
char *tzName;
|
char *tzName;
|
||||||
ULONG nToken;
|
ULONG nToken;
|
||||||
@@ -115,11 +117,9 @@ yy_scan_bytes(char *mem, ULONG size)
|
|||||||
{
|
{
|
||||||
YY_BUFFER_STATE pBuffer;
|
YY_BUFFER_STATE pBuffer;
|
||||||
|
|
||||||
if ((pBuffer =
|
if ((pBuffer = malloc(sizeof(struct yy_buffer_state))) != NULL) {
|
||||||
(YY_BUFFER_STATE) malloc(sizeof(struct yy_buffer_state))) !=
|
|
||||||
NULL) {
|
|
||||||
if ((pBuffer->pBufferRealStart =
|
if ((pBuffer->pBufferRealStart =
|
||||||
(char *) malloc(size + 1 + SAFETYMARGIN)) != NULL) {
|
malloc(size + 1 + SAFETYMARGIN)) != NULL) {
|
||||||
pBuffer->pBufferStart = pBuffer->pBufferRealStart + SAFETYMARGIN;
|
pBuffer->pBufferStart = pBuffer->pBufferRealStart + SAFETYMARGIN;
|
||||||
pBuffer->pBuffer = pBuffer->pBufferRealStart + SAFETYMARGIN;
|
pBuffer->pBuffer = pBuffer->pBufferRealStart + SAFETYMARGIN;
|
||||||
memcpy(pBuffer->pBuffer, mem, size);
|
memcpy(pBuffer->pBuffer, mem, size);
|
||||||
@@ -138,8 +138,7 @@ yy_create_buffer(FILE * f)
|
|||||||
{
|
{
|
||||||
YY_BUFFER_STATE pBuffer;
|
YY_BUFFER_STATE pBuffer;
|
||||||
|
|
||||||
if ((pBuffer =
|
if ((pBuffer = malloc(sizeof(struct yy_buffer_state))) != NULL) {
|
||||||
(YY_BUFFER_STATE) malloc(sizeof(struct yy_buffer_state))) != NULL) {
|
|
||||||
ULONG size;
|
ULONG size;
|
||||||
|
|
||||||
fseek(f, 0, SEEK_END);
|
fseek(f, 0, SEEK_END);
|
||||||
@@ -147,7 +146,7 @@ yy_create_buffer(FILE * f)
|
|||||||
fseek(f, 0, SEEK_SET);
|
fseek(f, 0, SEEK_SET);
|
||||||
|
|
||||||
if ((pBuffer->pBufferRealStart =
|
if ((pBuffer->pBufferRealStart =
|
||||||
(char *) malloc(size + 2 + SAFETYMARGIN)) != NULL) {
|
malloc(size + 2 + SAFETYMARGIN)) != NULL) {
|
||||||
char *mem;
|
char *mem;
|
||||||
ULONG instring = 0;
|
ULONG instring = 0;
|
||||||
|
|
||||||
@@ -166,7 +165,10 @@ yy_create_buffer(FILE * f)
|
|||||||
if (*mem == '\"')
|
if (*mem == '\"')
|
||||||
instring = 1 - instring;
|
instring = 1 - instring;
|
||||||
|
|
||||||
if (instring) {
|
if (mem[0] == '\\' &&
|
||||||
|
(mem[1] == '\"' || mem[1] == '\\')) {
|
||||||
|
mem += 2;
|
||||||
|
} else if (instring) {
|
||||||
mem += 1;
|
mem += 1;
|
||||||
} else {
|
} else {
|
||||||
if ((mem[0] == 10 && mem[1] == 13)
|
if ((mem[0] == 10 && mem[1] == 13)
|
||||||
@@ -213,9 +215,8 @@ void
|
|||||||
lex_CheckCharacterRange(UWORD start, UWORD end)
|
lex_CheckCharacterRange(UWORD start, UWORD end)
|
||||||
{
|
{
|
||||||
if (start > end || start < 1 || end > 127) {
|
if (start > end || start < 1 || end > 127) {
|
||||||
fprintf(stderr, "Invalid character range (start: %u, end: %u)\n",
|
errx(1, "Invalid character range (start: %u, end: %u)",
|
||||||
start, end);
|
start, end);
|
||||||
exit(1);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -344,11 +345,7 @@ lex_AddStrings(struct sLexInitString * lex)
|
|||||||
while (*ppHash)
|
while (*ppHash)
|
||||||
ppHash = &((*ppHash)->pNext);
|
ppHash = &((*ppHash)->pNext);
|
||||||
|
|
||||||
//printf("%s has hashvalue %d\n", lex->tzName, hash);
|
if (((*ppHash) = malloc(sizeof(struct sLexString))) != NULL) {
|
||||||
|
|
||||||
if (((*ppHash) =
|
|
||||||
(struct sLexString *) malloc(sizeof(struct sLexString))) !=
|
|
||||||
NULL) {
|
|
||||||
if (((*ppHash)->tzName =
|
if (((*ppHash)->tzName =
|
||||||
(char *) strdup(lex->tzName)) != NULL) {
|
(char *) strdup(lex->tzName)) != NULL) {
|
||||||
(*ppHash)->nNameLength = strlen(lex->tzName);
|
(*ppHash)->nNameLength = strlen(lex->tzName);
|
||||||
@@ -444,7 +441,6 @@ CopyMacroArg(char *dest, size_t maxLength, char c)
|
|||||||
int argNum;
|
int argNum;
|
||||||
|
|
||||||
switch (c) {
|
switch (c) {
|
||||||
case '0':
|
|
||||||
case '1':
|
case '1':
|
||||||
case '2':
|
case '2':
|
||||||
case '3':
|
case '3':
|
||||||
|
|||||||
@@ -2,7 +2,7 @@
|
|||||||
#include "asm/lexer.h"
|
#include "asm/lexer.h"
|
||||||
#include "asm/rpn.h"
|
#include "asm/rpn.h"
|
||||||
|
|
||||||
#include "../asmy.h"
|
#include "asmy.h"
|
||||||
|
|
||||||
struct sLexInitString localstrings[] = {
|
struct sLexInitString localstrings[] = {
|
||||||
{"adc", T_Z80_ADC},
|
{"adc", T_Z80_ADC},
|
||||||
164
src/asm/main.c
164
src/asm/main.c
@@ -1,14 +1,5 @@
|
|||||||
/*
|
|
||||||
* RGBAsm - MAIN.C
|
|
||||||
*
|
|
||||||
* INCLUDES
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
|
|
||||||
#include <math.h>
|
#include <math.h>
|
||||||
#include <getopt.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>
|
||||||
@@ -19,19 +10,11 @@
|
|||||||
#include "asm/fstack.h"
|
#include "asm/fstack.h"
|
||||||
#include "asm/output.h"
|
#include "asm/output.h"
|
||||||
#include "asm/main.h"
|
#include "asm/main.h"
|
||||||
|
#include "extern/err.h"
|
||||||
|
|
||||||
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;
|
||||||
@@ -133,9 +113,8 @@ opt_Parse(char *s)
|
|||||||
newopt.gbgfx[2] = s[3];
|
newopt.gbgfx[2] = s[3];
|
||||||
newopt.gbgfx[3] = s[4];
|
newopt.gbgfx[3] = s[4];
|
||||||
} else {
|
} else {
|
||||||
fprintf(stderr, "Must specify exactly 4 characters "
|
errx(1, "Must specify exactly 4 characters for "
|
||||||
"for option 'g'\n");
|
"option 'g'");
|
||||||
exit(1);
|
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case 'b':
|
case 'b':
|
||||||
@@ -143,9 +122,8 @@ opt_Parse(char *s)
|
|||||||
newopt.binary[0] = s[1];
|
newopt.binary[0] = s[1];
|
||||||
newopt.binary[1] = s[2];
|
newopt.binary[1] = s[2];
|
||||||
} else {
|
} else {
|
||||||
fprintf(stderr, "Must specify exactly 2 characters "
|
errx(1, "Must specify exactly 2 characters for option "
|
||||||
"for option 'b'\n");
|
"'b'");
|
||||||
exit(1);
|
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case 'z':
|
case 'z':
|
||||||
@@ -154,12 +132,10 @@ opt_Parse(char *s)
|
|||||||
|
|
||||||
result = sscanf(&s[1], "%lx", &newopt.fillchar);
|
result = sscanf(&s[1], "%lx", &newopt.fillchar);
|
||||||
if (!((result == EOF) || (result == 1))) {
|
if (!((result == EOF) || (result == 1))) {
|
||||||
fprintf(stderr,
|
errx(1, "Invalid argument for option 'z'");
|
||||||
"Invalid argument for option 'z'\n");
|
|
||||||
exit(1);
|
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
fprintf(stderr, "Invalid argument for option 'z'\n");
|
errx(1, "Invalid argument for option 'z'");
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
@@ -176,9 +152,7 @@ opt_Push(void)
|
|||||||
{
|
{
|
||||||
struct sOptionStackEntry *pOpt;
|
struct sOptionStackEntry *pOpt;
|
||||||
|
|
||||||
if ((pOpt =
|
if ((pOpt = malloc(sizeof(struct sOptionStackEntry))) != NULL) {
|
||||||
(struct sOptionStackEntry *)
|
|
||||||
malloc(sizeof(struct sOptionStackEntry))) != NULL) {
|
|
||||||
pOpt->Options = CurrentOptions;
|
pOpt->Options = CurrentOptions;
|
||||||
pOpt->pNext = pOptionStack;
|
pOpt->pNext = pOptionStack;
|
||||||
pOptionStack = pOpt;
|
pOptionStack = pOpt;
|
||||||
@@ -199,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)
|
||||||
{
|
{
|
||||||
@@ -235,28 +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("RGBAsm v" ASM_VERSION " (part of ASMotor " ASMOTOR_VERSION
|
printf(
|
||||||
")\n\n");
|
"Usage: rgbasm [-v] [-h] [-b chars] [-g chars] [-i path] [-o outfile]\n"
|
||||||
printf("Usage: rgbasm [-v] [-h] [-b chars] [-g chars] [-i path] [-o outfile] [-p pad_value]\n"
|
" [-p pad_value] file.asm\n");
|
||||||
" file\n");
|
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
/*
|
|
||||||
* RGBAsm - MAIN.C
|
|
||||||
*
|
|
||||||
* main
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
|
|
||||||
int
|
int
|
||||||
main(int argc, char *argv[])
|
main(int argc, char *argv[])
|
||||||
@@ -268,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; */
|
||||||
|
|
||||||
@@ -283,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);
|
||||||
|
|
||||||
@@ -295,9 +254,8 @@ main(int argc, char *argv[])
|
|||||||
newopt.binary[0] = optarg[1];
|
newopt.binary[0] = optarg[1];
|
||||||
newopt.binary[1] = optarg[2];
|
newopt.binary[1] = optarg[2];
|
||||||
} else {
|
} else {
|
||||||
fprintf(stderr, "Must specify exactly "
|
errx(1, "Must specify exactly 2 characters for "
|
||||||
"2 characters for option 'b'\n");
|
"option 'b'");
|
||||||
exit(1);
|
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case 'g':
|
case 'g':
|
||||||
@@ -307,13 +265,12 @@ main(int argc, char *argv[])
|
|||||||
newopt.gbgfx[2] = optarg[3];
|
newopt.gbgfx[2] = optarg[3];
|
||||||
newopt.gbgfx[3] = optarg[4];
|
newopt.gbgfx[3] = optarg[4];
|
||||||
} else {
|
} else {
|
||||||
fprintf(stderr, "Must specify exactly "
|
errx(1, "Must specify exactly 4 characters for "
|
||||||
"4 characters for option 'g'\n");
|
"option 'g'");
|
||||||
exit(1);
|
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case 'h':
|
case 'h':
|
||||||
haltnop = false;
|
newopt.haltnop = false;
|
||||||
break;
|
break;
|
||||||
case 'i':
|
case 'i':
|
||||||
fstk_AddIncludePath(optarg);
|
fstk_AddIncludePath(optarg);
|
||||||
@@ -324,21 +281,18 @@ main(int argc, char *argv[])
|
|||||||
case 'p':
|
case 'p':
|
||||||
newopt.fillchar = strtoul(optarg, &ep, 0);
|
newopt.fillchar = strtoul(optarg, &ep, 0);
|
||||||
if (optarg[0] == '\0' || *ep != '\0') {
|
if (optarg[0] == '\0' || *ep != '\0') {
|
||||||
fprintf(stderr,
|
errx(1, "Invalid argument for option 'p'");
|
||||||
"Invalid argument for option 'p'\n");
|
|
||||||
exit(1);
|
|
||||||
}
|
}
|
||||||
if (newopt.fillchar < 0 || newopt.fillchar > 0xFF) {
|
if (newopt.fillchar < 0 || newopt.fillchar > 0xFF) {
|
||||||
fprintf(stderr, "Argument for option 'p' "
|
errx(1, "Argument for option 'p' must be "
|
||||||
"must be between 0 and 0xFF\n");
|
"between 0 and 0xFF");
|
||||||
exit(1);
|
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case 'v':
|
case 'v':
|
||||||
newopt.verbose = true;
|
newopt.verbose = true;
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
PrintUsage();
|
usage();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
argc -= optind;
|
argc -= optind;
|
||||||
@@ -348,7 +302,9 @@ main(int argc, char *argv[])
|
|||||||
|
|
||||||
DefaultOptions = CurrentOptions;
|
DefaultOptions = CurrentOptions;
|
||||||
|
|
||||||
/* tzMainfile=argv[argn++]; argc-=1; */
|
if (argc == 0)
|
||||||
|
usage();
|
||||||
|
|
||||||
tzMainfile = argv[argc - 1];
|
tzMainfile = argv[argc - 1];
|
||||||
|
|
||||||
setuplex();
|
setuplex();
|
||||||
@@ -366,7 +322,8 @@ main(int argc, char *argv[])
|
|||||||
nPass = 1;
|
nPass = 1;
|
||||||
nErrors = 0;
|
nErrors = 0;
|
||||||
sym_PrepPass1();
|
sym_PrepPass1();
|
||||||
if (fstk_Init(tzMainfile)) {
|
fstk_Init(tzMainfile);
|
||||||
|
|
||||||
if (CurrentOptions.verbose) {
|
if (CurrentOptions.verbose) {
|
||||||
printf("Pass 1...\n");
|
printf("Pass 1...\n");
|
||||||
}
|
}
|
||||||
@@ -374,8 +331,14 @@ 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);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (nIFDepth != 0) {
|
||||||
|
errx(1, "Unterminated IF construct (%ld levels)!", nIFDepth);
|
||||||
|
}
|
||||||
|
|
||||||
nTotalLines = 0;
|
nTotalLines = 0;
|
||||||
nLineNo = 1;
|
nLineNo = 1;
|
||||||
nIFDepth = 0;
|
nIFDepth = 0;
|
||||||
@@ -392,49 +355,24 @@ main(int argc, char *argv[])
|
|||||||
printf("Pass 2...\n");
|
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;
|
double timespent;
|
||||||
|
|
||||||
nEndClock = clock();
|
nEndClock = clock();
|
||||||
timespent =
|
timespent = ((double)(nEndClock - nStartClock))
|
||||||
((double) (nEndClock - nStartClock))
|
|
||||||
/ (double)CLOCKS_PER_SEC;
|
/ (double)CLOCKS_PER_SEC;
|
||||||
if (CurrentOptions.verbose) {
|
if (CurrentOptions.verbose) {
|
||||||
printf
|
printf("Success! %ld lines in %d.%02d seconds ", nTotalLines,
|
||||||
("Success! %ld lines in %d.%02d seconds ",
|
(int) timespent, ((int) (timespent * 100.0)) % 100);
|
||||||
nTotalLines, (int) timespent,
|
|
||||||
((int) (timespent * 100.0)) % 100);
|
|
||||||
if (timespent == 0)
|
if (timespent == 0)
|
||||||
printf
|
printf("(INFINITY lines/minute)\n");
|
||||||
("(INFINITY lines/minute)\n");
|
|
||||||
else
|
else
|
||||||
printf("(%d lines/minute)\n",
|
printf("(%d lines/minute)\n",
|
||||||
(int) (60 / timespent *
|
(int) (60 / timespent * nTotalLines));
|
||||||
nTotalLines));
|
|
||||||
}
|
}
|
||||||
out_WriteObject();
|
out_WriteObject();
|
||||||
} else {
|
return 0;
|
||||||
printf
|
|
||||||
("Assembly aborted in pass 2 (%ld errors)!\n",
|
|
||||||
nErrors);
|
|
||||||
//sym_PrintSymbolTable();
|
|
||||||
exit(5);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
fprintf(stderr,
|
|
||||||
"Unterminated IF construct (%ld levels)!\n",
|
|
||||||
nIFDepth);
|
|
||||||
exit(1);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
fprintf(stderr,
|
|
||||||
"Assembly aborted in pass 1 (%ld errors)!\n",
|
|
||||||
nErrors);
|
|
||||||
exit(1);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
printf("File '%s' not found\n", tzMainfile);
|
|
||||||
exit(5);
|
|
||||||
}
|
|
||||||
return (0);
|
|
||||||
}
|
}
|
||||||
|
|||||||
126
src/asm/math.c
126
src/asm/math.c
@@ -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,112 +37,112 @@ 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)));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* 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)));
|
||||||
|
}
|
||||||
|
|||||||
368
src/asm/output.c
368
src/asm/output.c
@@ -1,8 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* RGBAsm - OUTPUT.C - Outputs an objectfile
|
* Outputs an objectfile
|
||||||
*
|
|
||||||
* INCLUDES
|
|
||||||
*
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
@@ -11,22 +8,17 @@
|
|||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
#include "asm/asm.h"
|
#include "asm/asm.h"
|
||||||
|
#include "asm/charmap.h"
|
||||||
#include "asm/output.h"
|
#include "asm/output.h"
|
||||||
#include "asm/symbol.h"
|
#include "asm/symbol.h"
|
||||||
#include "asm/mylink.h"
|
#include "asm/mylink.h"
|
||||||
#include "asm/main.h"
|
#include "asm/main.h"
|
||||||
#include "asm/rpn.h"
|
#include "asm/rpn.h"
|
||||||
#include "asm/fstack.h"
|
#include "asm/fstack.h"
|
||||||
|
#include "extern/err.h"
|
||||||
|
|
||||||
#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 {
|
||||||
@@ -50,35 +42,23 @@ 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;
|
||||||
struct PatchSymbol *pPatchSymbols = NULL;
|
struct PatchSymbol *pPatchSymbols = NULL;
|
||||||
struct PatchSymbol **ppPatchSymbolsTail = &pPatchSymbols;
|
struct PatchSymbol **ppPatchSymbolsTail = &pPatchSymbols;
|
||||||
char tzObjectname[_MAX_PATH];
|
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)
|
||||||
{
|
{
|
||||||
struct SectionStackEntry *pSect;
|
struct SectionStackEntry *pSect;
|
||||||
|
|
||||||
if ((pSect =
|
if ((pSect = malloc(sizeof(struct SectionStackEntry))) != NULL) {
|
||||||
(struct SectionStackEntry *)
|
|
||||||
malloc(sizeof(struct SectionStackEntry))) != NULL) {
|
|
||||||
pSect->pSection = pCurrentSection;
|
pSect->pSection = pCurrentSection;
|
||||||
pSect->pNext = pSectionStack;
|
pSect->pNext = pSectionStack;
|
||||||
pSectionStack = pSect;
|
pSectionStack = pSect;
|
||||||
@@ -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)
|
||||||
{
|
{
|
||||||
@@ -342,9 +292,7 @@ addsymbol(struct sSymbol * pSym)
|
|||||||
ppPSym = &((*ppPSym)->pBucketNext);
|
ppPSym = &((*ppPSym)->pBucketNext);
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((*ppPSym = pPSym =
|
if ((*ppPSym = pPSym = malloc(sizeof(struct PatchSymbol))) != NULL) {
|
||||||
(struct PatchSymbol *) malloc(sizeof(struct PatchSymbol))) !=
|
|
||||||
NULL) {
|
|
||||||
pPSym->pNext = NULL;
|
pPSym->pNext = NULL;
|
||||||
pPSym->pBucketNext = NULL;
|
pPSym->pBucketNext = NULL;
|
||||||
pPSym->pSymbol = pSym;
|
pPSym->pSymbol = pSym;
|
||||||
@@ -357,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)
|
||||||
{
|
{
|
||||||
@@ -380,20 +325,16 @@ 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)
|
||||||
{
|
{
|
||||||
struct Patch *pPatch;
|
struct Patch *pPatch;
|
||||||
|
|
||||||
if ((pPatch =
|
if ((pPatch = malloc(sizeof(struct Patch))) != NULL) {
|
||||||
(struct Patch *) malloc(sizeof(struct Patch))) != NULL) {
|
|
||||||
pPatch->pNext = pCurrentSection->pPatches;
|
pPatch->pNext = pCurrentSection->pPatches;
|
||||||
pPatch->nRPNSize = 0;
|
pPatch->nRPNSize = 0;
|
||||||
pPatch->pRPN = NULL;
|
pPatch->pRPN = NULL;
|
||||||
@@ -404,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)
|
||||||
{
|
{
|
||||||
@@ -471,18 +409,15 @@ createpatch(ULONG type, struct Expression * expr)
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if ((pPatch->pRPN = (UBYTE *) malloc(rpnptr)) != NULL) {
|
if ((pPatch->pRPN = malloc(rpnptr)) != NULL) {
|
||||||
memcpy(pPatch->pRPN, rpnexpr, rpnptr);
|
memcpy(pPatch->pRPN, rpnexpr, rpnptr);
|
||||||
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)
|
||||||
{
|
{
|
||||||
@@ -491,21 +426,21 @@ 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)
|
||||||
{
|
{
|
||||||
checksection();
|
checksection();
|
||||||
if ((pCurrentSection->nType == SECT_ROM0
|
if (pCurrentSection->nType != SECT_ROM0 &&
|
||||||
|| pCurrentSection->nType == SECT_ROMX)
|
pCurrentSection->nType != SECT_ROMX) {
|
||||||
&& (pCurrentSection->nPC + size <= MAXSECTIONSIZE)) {
|
errx(1, "Section '%s' cannot contain code or data (not a "
|
||||||
|
"ROM0 or ROMX)", pCurrentSection->pzName);
|
||||||
|
}
|
||||||
|
if (pCurrentSection->nPC + size <= MAXSECTIONSIZE) {
|
||||||
if (((pCurrentSection->nPC % SECTIONCHUNK) >
|
if (((pCurrentSection->nPC % SECTIONCHUNK) >
|
||||||
((pCurrentSection->nPC + size) % SECTIONCHUNK))
|
((pCurrentSection->nPC + size) % SECTIONCHUNK))
|
||||||
&& (pCurrentSection->nType == SECT_ROM0
|
&& (pCurrentSection->nType == SECT_ROM0
|
||||||
@@ -522,16 +457,12 @@ checkcodesection(SLONG size)
|
|||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
} else
|
} else
|
||||||
fatalerror
|
errx(1, "Section '%s' is too big", pCurrentSection->pzName);
|
||||||
("Section can't contain initialized data or section limit exceeded");
|
|
||||||
}
|
}
|
||||||
/*
|
|
||||||
* RGBAsm - OUTPUT.C - Outputs an objectfile
|
|
||||||
*
|
|
||||||
* Write an objectfile
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Write an objectfile
|
||||||
|
*/
|
||||||
void
|
void
|
||||||
out_WriteObject(void)
|
out_WriteObject(void)
|
||||||
{
|
{
|
||||||
@@ -562,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)
|
||||||
{
|
{
|
||||||
@@ -582,17 +510,14 @@ 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)
|
||||||
{
|
{
|
||||||
strcpy(tzObjectname, s);
|
tzObjectname = s;
|
||||||
if (CurrentOptions.verbose) {
|
if (CurrentOptions.verbose) {
|
||||||
printf("Output filename %s\n", s);
|
printf("Output filename %s\n", s);
|
||||||
}
|
}
|
||||||
@@ -600,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;
|
||||||
|
|
||||||
@@ -630,11 +551,8 @@ out_FindSection(char *pzName, ULONG secttype, SLONG org,
|
|||||||
pSect = pSect->pNext;
|
pSect = pSect->pNext;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((*ppSect =
|
if ((*ppSect = (pSect = malloc(sizeof(struct Section)))) != NULL) {
|
||||||
(pSect =
|
if ((pSect->pzName = malloc(strlen(pzName) + 1)) != NULL) {
|
||||||
(struct Section *) malloc(sizeof(struct Section)))) != NULL) {
|
|
||||||
if ((pSect->pzName =
|
|
||||||
(char *) malloc(strlen(pzName) + 1)) != NULL) {
|
|
||||||
strcpy(pSect->pzName, pzName);
|
strcpy(pSect->pzName, pzName);
|
||||||
pSect->nType = secttype;
|
pSect->nType = secttype;
|
||||||
pSect->nPC = 0;
|
pSect->nPC = 0;
|
||||||
@@ -642,10 +560,10 @@ out_FindSection(char *pzName, ULONG secttype, SLONG org,
|
|||||||
pSect->nBank = bank;
|
pSect->nBank = bank;
|
||||||
pSect->pNext = NULL;
|
pSect->pNext = NULL;
|
||||||
pSect->pPatches = NULL;
|
pSect->pPatches = NULL;
|
||||||
|
pSect->charmap = NULL;
|
||||||
pPatchSymbols = NULL;
|
pPatchSymbols = NULL;
|
||||||
|
|
||||||
if ((pSect->tData =
|
if ((pSect->tData = malloc(SECTIONCHUNK)) != NULL) {
|
||||||
(UBYTE *) malloc(SECTIONCHUNK)) != NULL) {
|
|
||||||
return (pSect);
|
return (pSect);
|
||||||
} else
|
} else
|
||||||
fatalerror("Not enough memory for section");
|
fatalerror("Not enough memory for section");
|
||||||
@@ -656,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)
|
||||||
{
|
{
|
||||||
@@ -672,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)
|
||||||
{
|
{
|
||||||
@@ -715,13 +621,18 @@ out_AbsByte(int b)
|
|||||||
nPC += 1;
|
nPC += 1;
|
||||||
pPCSymbol->nValue += 1;
|
pPCSymbol->nValue += 1;
|
||||||
}
|
}
|
||||||
/*
|
|
||||||
* RGBAsm - OUTPUT.C - Outputs an objectfile
|
|
||||||
*
|
|
||||||
* Skip this many bytes
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
|
|
||||||
|
void
|
||||||
|
out_AbsByteGroup(char *s, int length)
|
||||||
|
{
|
||||||
|
checkcodesection(length);
|
||||||
|
while (length--)
|
||||||
|
out_AbsByte(*s++);
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Skip this many bytes
|
||||||
|
*/
|
||||||
void
|
void
|
||||||
out_Skip(int skip)
|
out_Skip(int skip)
|
||||||
{
|
{
|
||||||
@@ -737,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)
|
||||||
{
|
{
|
||||||
@@ -751,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
|
||||||
@@ -776,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)
|
||||||
{
|
{
|
||||||
@@ -796,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)
|
||||||
{
|
{
|
||||||
@@ -824,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)
|
||||||
{
|
{
|
||||||
@@ -845,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)
|
||||||
{
|
{
|
||||||
@@ -875,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)
|
||||||
{
|
{
|
||||||
@@ -895,21 +786,20 @@ 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)
|
||||||
{
|
{
|
||||||
FILE *f;
|
FILE *f;
|
||||||
|
|
||||||
fstk_FindFile(s);
|
f = fstk_FindFile(s);
|
||||||
|
if (f == NULL) {
|
||||||
|
err(1, "Unable to open incbin file '%s'", s);
|
||||||
|
}
|
||||||
|
|
||||||
if ((f = fopen(s, "rb")) != NULL) {
|
|
||||||
SLONG fsize;
|
SLONG fsize;
|
||||||
|
|
||||||
fseek(f, 0, SEEK_END);
|
fseek(f, 0, SEEK_END);
|
||||||
@@ -929,8 +819,6 @@ out_BinaryFile(char *s)
|
|||||||
nPC += fsize;
|
nPC += fsize;
|
||||||
pPCSymbol->nValue += fsize;
|
pPCSymbol->nValue += fsize;
|
||||||
fclose(f);
|
fclose(f);
|
||||||
} else
|
|
||||||
fatalerror("Could not open file '%s': %s", s, strerror(errno));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
@@ -944,9 +832,11 @@ out_BinaryFileSlice(char *s, SLONG start_pos, SLONG length)
|
|||||||
if (length < 0)
|
if (length < 0)
|
||||||
fatalerror("Number of bytes to read must be greater than zero");
|
fatalerror("Number of bytes to read must be greater than zero");
|
||||||
|
|
||||||
fstk_FindFile(s);
|
f = fstk_FindFile(s);
|
||||||
|
if (f == NULL) {
|
||||||
|
err(1, "Unable to open included file '%s'", s);
|
||||||
|
}
|
||||||
|
|
||||||
if ((f = fopen(s, "rb")) != NULL) {
|
|
||||||
SLONG fsize;
|
SLONG fsize;
|
||||||
|
|
||||||
fseek(f, 0, SEEK_END);
|
fseek(f, 0, SEEK_END);
|
||||||
@@ -974,6 +864,4 @@ out_BinaryFileSlice(char *s, SLONG start_pos, SLONG length)
|
|||||||
pPCSymbol->nValue += length;
|
pPCSymbol->nValue += length;
|
||||||
|
|
||||||
fclose(f);
|
fclose(f);
|
||||||
} else
|
|
||||||
fatalerror("Could not open file '%s': %s", s, strerror(errno));
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -60,7 +60,6 @@ and
|
|||||||
.Sh SEE ALSO
|
.Sh SEE ALSO
|
||||||
.Xr rgbds 7 ,
|
.Xr rgbds 7 ,
|
||||||
.Xr rgbfix 1 ,
|
.Xr rgbfix 1 ,
|
||||||
.Xr rgblib 1 ,
|
|
||||||
.Xr rgblink 1 ,
|
.Xr rgblink 1 ,
|
||||||
.Xr gbz80 7
|
.Xr gbz80 7
|
||||||
.Sh HISTORY
|
.Sh HISTORY
|
||||||
|
|||||||
@@ -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)
|
||||||
{
|
{
|
||||||
|
|||||||
337
src/asm/symbol.c
337
src/asm/symbol.c
@@ -1,10 +1,8 @@
|
|||||||
/*
|
/*
|
||||||
* RGBAsm - SYMBOL.C - Symboltable and macroargs stuff
|
* Symboltable and macroargs stuff
|
||||||
*
|
|
||||||
* INCLUDES
|
|
||||||
*
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#include <assert.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <time.h>
|
#include <time.h>
|
||||||
@@ -15,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;
|
||||||
@@ -36,7 +27,6 @@ Callback_NARG(struct sSymbol * sym)
|
|||||||
{
|
{
|
||||||
ULONG i = 0;
|
ULONG i = 0;
|
||||||
|
|
||||||
sym = sym;
|
|
||||||
while (currentmacroargs[i] && i < MAXMACROARGS)
|
while (currentmacroargs[i] && i < MAXMACROARGS)
|
||||||
i += 1;
|
i += 1;
|
||||||
|
|
||||||
@@ -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)
|
||||||
{
|
{
|
||||||
@@ -94,8 +74,7 @@ createsymbol(char *s)
|
|||||||
while ((*ppsym) != NULL)
|
while ((*ppsym) != NULL)
|
||||||
ppsym = &((*ppsym)->pNext);
|
ppsym = &((*ppsym)->pNext);
|
||||||
|
|
||||||
if (((*ppsym) =
|
if (((*ppsym) = malloc(sizeof(struct sSymbol))) != NULL) {
|
||||||
(struct sSymbol *) malloc(sizeof(struct sSymbol))) != NULL) {
|
|
||||||
strcpy((*ppsym)->tzName, s);
|
strcpy((*ppsym)->tzName, s);
|
||||||
(*ppsym)->nValue = 0;
|
(*ppsym)->nValue = 0;
|
||||||
(*ppsym)->nType = 0;
|
(*ppsym)->nType = 0;
|
||||||
@@ -111,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)
|
||||||
{
|
{
|
||||||
@@ -135,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)
|
||||||
{
|
{
|
||||||
@@ -160,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)
|
||||||
{
|
{
|
||||||
@@ -179,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)
|
||||||
{
|
{
|
||||||
@@ -213,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)
|
||||||
{
|
{
|
||||||
@@ -261,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)
|
||||||
{
|
{
|
||||||
@@ -284,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)
|
||||||
{
|
{
|
||||||
@@ -304,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)
|
||||||
{
|
{
|
||||||
@@ -333,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)
|
||||||
{
|
{
|
||||||
@@ -375,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)
|
||||||
{
|
{
|
||||||
@@ -407,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)
|
||||||
{
|
{
|
||||||
@@ -432,6 +377,8 @@ sym_FindMacroArg(SLONG i)
|
|||||||
if (i == -1)
|
if (i == -1)
|
||||||
i = MAXMACROARGS + 1;
|
i = MAXMACROARGS + 1;
|
||||||
|
|
||||||
|
assert(i-1 >= 0 &&
|
||||||
|
i-1 < sizeof currentmacroargs / sizeof *currentmacroargs);
|
||||||
return (currentmacroargs[i - 1]);
|
return (currentmacroargs[i - 1]);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -489,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
|
||||||
@@ -509,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)
|
||||||
{
|
{
|
||||||
@@ -550,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)
|
||||||
{
|
{
|
||||||
@@ -570,8 +508,7 @@ sym_AddString(char *tzSym, char *tzValue)
|
|||||||
nsym = createsymbol(tzSym);
|
nsym = createsymbol(tzSym);
|
||||||
|
|
||||||
if (nsym) {
|
if (nsym) {
|
||||||
if ((nsym->pMacro =
|
if ((nsym->pMacro = malloc(strlen(tzValue) + 1)) != NULL)
|
||||||
(char *) malloc(strlen(tzValue) + 1)) != NULL)
|
|
||||||
strcpy(nsym->pMacro, tzValue);
|
strcpy(nsym->pMacro, tzValue);
|
||||||
else
|
else
|
||||||
fatalerror("No memory for stringequate");
|
fatalerror("No memory for stringequate");
|
||||||
@@ -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)
|
||||||
{
|
{
|
||||||
@@ -873,7 +776,6 @@ sym_Init(void)
|
|||||||
p_NARGSymbol = findsymbol("_NARG", NULL);
|
p_NARGSymbol = findsymbol("_NARG", NULL);
|
||||||
p_NARGSymbol->Callback = Callback_NARG;
|
p_NARGSymbol->Callback = Callback_NARG;
|
||||||
|
|
||||||
sym_AddEqu("__ASM__", (SLONG) (atof(ASM_VERSION) * 65536));
|
|
||||||
sym_AddSet("_RS", 0);
|
sym_AddSet("_RS", 0);
|
||||||
|
|
||||||
if (time(&tod) != -1) {
|
if (time(&tod) != -1) {
|
||||||
@@ -890,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]);
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -1,437 +0,0 @@
|
|||||||
%{
|
|
||||||
#include <ctype.h>
|
|
||||||
#include <errno.h>
|
|
||||||
#include <stdbool.h>
|
|
||||||
#include <stdio.h>
|
|
||||||
#include <stdlib.h>
|
|
||||||
#include <string.h>
|
|
||||||
|
|
||||||
#include "asm/symbol.h"
|
|
||||||
#include "asm/asm.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 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=(char *)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_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
|
|
||||||
@@ -1,536 +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
|
|
||||||
| 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
|
|
||||||
{
|
|
||||||
if( !fstk_RunInclude($2) )
|
|
||||||
{
|
|
||||||
yyerror("Could not open file '%s' : %s\n", $2, strerror(errno));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
;
|
|
||||||
|
|
||||||
incbin : T_POP_INCBIN string
|
|
||||||
{ out_BinaryFile( $2 ); }
|
|
||||||
| T_POP_INCBIN string ',' const ',' const
|
|
||||||
{
|
|
||||||
out_BinaryFileSlice( $2, $4, $6 );
|
|
||||||
}
|
|
||||||
;
|
|
||||||
|
|
||||||
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 { out_String( $1 ); }
|
|
||||||
;
|
|
||||||
|
|
||||||
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
|
|
||||||
{ ULONG r; r=str2int($1); 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($$); }
|
|
||||||
;
|
|
||||||
92
src/extern/err.c
vendored
Normal file
92
src/extern/err.c
vendored
Normal file
@@ -0,0 +1,92 @@
|
|||||||
|
/*
|
||||||
|
* Copyright © 2005-2013 Rich Felker, et al.
|
||||||
|
*
|
||||||
|
* Permission is hereby granted, free of charge, to any person obtaining
|
||||||
|
* a copy of this software and associated documentation files (the
|
||||||
|
* "Software"), to deal in the Software without restriction, including
|
||||||
|
* without limitation the rights to use, copy, modify, merge, publish,
|
||||||
|
* distribute, sublicense, and/or sell copies of the Software, and to
|
||||||
|
* permit persons to whom the Software is furnished to do so, subject to
|
||||||
|
* the following conditions:
|
||||||
|
*
|
||||||
|
* The above copyright notice and this permission notice shall be
|
||||||
|
* included in all copies or substantial portions of the Software.
|
||||||
|
*
|
||||||
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||||
|
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||||
|
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
||||||
|
* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
||||||
|
* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
||||||
|
* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
||||||
|
* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <stdarg.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include "extern/err.h"
|
||||||
|
|
||||||
|
#ifndef __MINGW32__
|
||||||
|
char *__progname;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
void rgbds_vwarn(const char *fmt, va_list ap)
|
||||||
|
{
|
||||||
|
fprintf (stderr, "%s: ", __progname);
|
||||||
|
if (fmt) {
|
||||||
|
vfprintf(stderr, fmt, ap);
|
||||||
|
fputs (": ", stderr);
|
||||||
|
}
|
||||||
|
perror(0);
|
||||||
|
}
|
||||||
|
|
||||||
|
void rgbds_vwarnx(const char *fmt, va_list ap)
|
||||||
|
{
|
||||||
|
fprintf (stderr, "%s: ", __progname);
|
||||||
|
if (fmt) vfprintf(stderr, fmt, ap);
|
||||||
|
putc('\n', stderr);
|
||||||
|
}
|
||||||
|
|
||||||
|
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)
|
||||||
|
{
|
||||||
|
vwarnx(fmt, ap);
|
||||||
|
exit(status);
|
||||||
|
}
|
||||||
|
|
||||||
|
void rgbds_warn(const char *fmt, ...)
|
||||||
|
{
|
||||||
|
va_list ap;
|
||||||
|
va_start(ap, fmt);
|
||||||
|
vwarn(fmt, ap);
|
||||||
|
va_end(ap);
|
||||||
|
}
|
||||||
|
|
||||||
|
void rgbds_warnx(const char *fmt, ...)
|
||||||
|
{
|
||||||
|
va_list ap;
|
||||||
|
va_start(ap, fmt);
|
||||||
|
vwarnx(fmt, ap);
|
||||||
|
va_end(ap);
|
||||||
|
}
|
||||||
|
|
||||||
|
noreturn void rgbds_err(int status, const char *fmt, ...)
|
||||||
|
{
|
||||||
|
va_list ap;
|
||||||
|
va_start(ap, fmt);
|
||||||
|
verr(status, fmt, ap);
|
||||||
|
va_end(ap);
|
||||||
|
}
|
||||||
|
|
||||||
|
noreturn void rgbds_errx(int status, const char *fmt, ...)
|
||||||
|
{
|
||||||
|
va_list ap;
|
||||||
|
va_start(ap, fmt);
|
||||||
|
verrx(status, fmt, ap);
|
||||||
|
va_end(ap);
|
||||||
|
}
|
||||||
55
src/extern/strlcat.c
vendored
Normal file
55
src/extern/strlcat.c
vendored
Normal file
@@ -0,0 +1,55 @@
|
|||||||
|
/* $OpenBSD: strlcat.c,v 1.13 2005/08/08 08:05:37 espie Exp $ */
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Copyright (c) 1998 Todd C. Miller <Todd.Miller@courtesan.com>
|
||||||
|
*
|
||||||
|
* Permission to use, copy, modify, and distribute this software for any
|
||||||
|
* purpose with or without fee is hereby granted, provided that the above
|
||||||
|
* copyright notice and this permission notice appear in all copies.
|
||||||
|
*
|
||||||
|
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
||||||
|
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
||||||
|
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
||||||
|
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
||||||
|
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
||||||
|
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
||||||
|
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <sys/types.h>
|
||||||
|
#include <string.h>
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Appends src to string dst of size siz (unlike strncat, siz is the
|
||||||
|
* full size of dst, not space left). At most siz-1 characters
|
||||||
|
* will be copied. Always NUL terminates (unless siz <= strlen(dst)).
|
||||||
|
* Returns strlen(src) + MIN(siz, strlen(initial dst)).
|
||||||
|
* If retval >= siz, truncation occurred.
|
||||||
|
*/
|
||||||
|
size_t
|
||||||
|
rgbds_strlcat(char *dst, const char *src, size_t siz)
|
||||||
|
{
|
||||||
|
char *d = dst;
|
||||||
|
const char *s = src;
|
||||||
|
size_t n = siz;
|
||||||
|
size_t dlen;
|
||||||
|
|
||||||
|
/* Find the end of dst and adjust bytes left but don't go past end */
|
||||||
|
while (n-- != 0 && *d != '\0')
|
||||||
|
d++;
|
||||||
|
dlen = d - dst;
|
||||||
|
n = siz - dlen;
|
||||||
|
|
||||||
|
if (n == 0)
|
||||||
|
return(dlen + strlen(s));
|
||||||
|
while (*s != '\0') {
|
||||||
|
if (n != 1) {
|
||||||
|
*d++ = *s;
|
||||||
|
n--;
|
||||||
|
}
|
||||||
|
s++;
|
||||||
|
}
|
||||||
|
*d = '\0';
|
||||||
|
|
||||||
|
return(dlen + (s - src)); /* count does not include NUL */
|
||||||
|
}
|
||||||
51
src/extern/strlcpy.c
vendored
Normal file
51
src/extern/strlcpy.c
vendored
Normal file
@@ -0,0 +1,51 @@
|
|||||||
|
/* $OpenBSD: strlcpy.c,v 1.11 2006/05/05 15:27:38 millert Exp $ */
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Copyright (c) 1998 Todd C. Miller <Todd.Miller@courtesan.com>
|
||||||
|
*
|
||||||
|
* Permission to use, copy, modify, and distribute this software for any
|
||||||
|
* purpose with or without fee is hereby granted, provided that the above
|
||||||
|
* copyright notice and this permission notice appear in all copies.
|
||||||
|
*
|
||||||
|
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
||||||
|
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
||||||
|
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
||||||
|
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
||||||
|
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
||||||
|
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
||||||
|
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <sys/types.h>
|
||||||
|
#include <string.h>
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Copy src to string dst of size siz. At most siz-1 characters
|
||||||
|
* will be copied. Always NUL terminates (unless siz == 0).
|
||||||
|
* Returns strlen(src); if retval >= siz, truncation occurred.
|
||||||
|
*/
|
||||||
|
size_t
|
||||||
|
rgbds_strlcpy(char *dst, const char *src, size_t siz)
|
||||||
|
{
|
||||||
|
char *d = dst;
|
||||||
|
const char *s = src;
|
||||||
|
size_t n = siz;
|
||||||
|
|
||||||
|
/* Copy as many bytes as will fit */
|
||||||
|
if (n != 0) {
|
||||||
|
while (--n != 0) {
|
||||||
|
if ((*d++ = *s++) == '\0')
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Not enough room in dst, add NUL and traverse rest of src */
|
||||||
|
if (n == 0) {
|
||||||
|
if (siz != 0)
|
||||||
|
*d = '\0'; /* NUL-terminate dst */
|
||||||
|
while (*s++)
|
||||||
|
;
|
||||||
|
}
|
||||||
|
|
||||||
|
return(s - src - 1); /* count does not include NUL */
|
||||||
|
}
|
||||||
132
src/fix/main.c
132
src/fix/main.c
@@ -14,7 +14,6 @@
|
|||||||
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <getopt.h>
|
|
||||||
#include <stdbool.h>
|
#include <stdbool.h>
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
@@ -22,13 +21,15 @@
|
|||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
|
|
||||||
|
#include "extern/err.h"
|
||||||
|
|
||||||
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);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -39,19 +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) {
|
|
||||||
fprintf(stderr, "Error opening file %s: \n", argv[argc - 1]);
|
|
||||||
perror(NULL);
|
|
||||||
exit(1);
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Parse command-line options
|
* Parse command-line options
|
||||||
*/
|
*/
|
||||||
@@ -71,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) {
|
||||||
@@ -93,9 +81,8 @@ main(int argc, char *argv[])
|
|||||||
setid = true;
|
setid = true;
|
||||||
|
|
||||||
if (strlen(optarg) != 4) {
|
if (strlen(optarg) != 4) {
|
||||||
fprintf(stderr, "Game ID %s must be exactly 4 "
|
errx(1, "Game ID %s must be exactly 4 "
|
||||||
"characters\n", optarg);
|
"characters", optarg);
|
||||||
exit(1);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
id = optarg;
|
id = optarg;
|
||||||
@@ -107,10 +94,8 @@ main(int argc, char *argv[])
|
|||||||
setnewlicensee = true;
|
setnewlicensee = true;
|
||||||
|
|
||||||
if (strlen(optarg) != 2) {
|
if (strlen(optarg) != 2) {
|
||||||
fprintf(stderr,
|
errx(1, "New licensee code %s is not the "
|
||||||
"New licensee code %s is not the correct "
|
"correct length of 2 characters", optarg);
|
||||||
"length of 2 characters\n", optarg);
|
|
||||||
exit(1);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
newlicensee = optarg;
|
newlicensee = optarg;
|
||||||
@@ -120,15 +105,11 @@ main(int argc, char *argv[])
|
|||||||
|
|
||||||
licensee = strtoul(optarg, &ep, 0);
|
licensee = strtoul(optarg, &ep, 0);
|
||||||
if (optarg[0] == '\0' || *ep != '\0') {
|
if (optarg[0] == '\0' || *ep != '\0') {
|
||||||
fprintf(stderr,
|
errx(1, "Invalid argument for option 'l'");
|
||||||
"Invalid argument for option 'l'\n");
|
|
||||||
exit(1);
|
|
||||||
}
|
}
|
||||||
if (licensee < 0 || licensee > 0xFF) {
|
if (licensee < 0 || licensee > 0xFF) {
|
||||||
fprintf(stderr,
|
errx(1, "Argument for option 'l' must be "
|
||||||
"Argument for option 'l' must be "
|
"between 0 and 255");
|
||||||
"between 0 and 255\n");
|
|
||||||
exit(1);
|
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case 'm':
|
case 'm':
|
||||||
@@ -136,15 +117,11 @@ main(int argc, char *argv[])
|
|||||||
|
|
||||||
cartridge = strtoul(optarg, &ep, 0);
|
cartridge = strtoul(optarg, &ep, 0);
|
||||||
if (optarg[0] == '\0' || *ep != '\0') {
|
if (optarg[0] == '\0' || *ep != '\0') {
|
||||||
fprintf(stderr,
|
errx(1, "Invalid argument for option 'm'");
|
||||||
"Invalid argument for option 'm'\n");
|
|
||||||
exit(1);
|
|
||||||
}
|
}
|
||||||
if (cartridge < 0 || cartridge > 0xFF) {
|
if (cartridge < 0 || cartridge > 0xFF) {
|
||||||
fprintf(stderr,
|
errx(1, "Argument for option 'm' must be "
|
||||||
"Argument for option 'm' must be "
|
"between 0 and 255");
|
||||||
"between 0 and 255\n");
|
|
||||||
exit(1);
|
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case 'n':
|
case 'n':
|
||||||
@@ -152,15 +129,11 @@ main(int argc, char *argv[])
|
|||||||
|
|
||||||
version = strtoul(optarg, &ep, 0);
|
version = strtoul(optarg, &ep, 0);
|
||||||
if (optarg[0] == '\0' || *ep != '\0') {
|
if (optarg[0] == '\0' || *ep != '\0') {
|
||||||
fprintf(stderr,
|
errx(1, "Invalid argument for option 'n'");
|
||||||
"Invalid argument for option 'n'\n");
|
|
||||||
exit(1);
|
|
||||||
}
|
}
|
||||||
if (version < 0 || version > 0xFF) {
|
if (version < 0 || version > 0xFF) {
|
||||||
fprintf(stderr,
|
errx(1, "Argument for option 'n' must be "
|
||||||
"Argument for option 'n' must be "
|
"between 0 and 255");
|
||||||
"between 0 and 255\n");
|
|
||||||
exit(1);
|
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case 'p':
|
case 'p':
|
||||||
@@ -168,15 +141,11 @@ main(int argc, char *argv[])
|
|||||||
|
|
||||||
padvalue = strtoul(optarg, &ep, 0);
|
padvalue = strtoul(optarg, &ep, 0);
|
||||||
if (optarg[0] == '\0' || *ep != '\0') {
|
if (optarg[0] == '\0' || *ep != '\0') {
|
||||||
fprintf(stderr,
|
errx(1, "Invalid argument for option 'p'");
|
||||||
"Invalid argument for option 'p'\n");
|
|
||||||
exit(1);
|
|
||||||
}
|
}
|
||||||
if (padvalue < 0 || padvalue > 0xFF) {
|
if (padvalue < 0 || padvalue > 0xFF) {
|
||||||
fprintf(stderr,
|
errx(1, "Argument for option 'p' must be "
|
||||||
"Argument for option 'p' must be "
|
"between 0 and 255");
|
||||||
"between 0 and 255\n");
|
|
||||||
exit(1);
|
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case 'r':
|
case 'r':
|
||||||
@@ -184,14 +153,11 @@ main(int argc, char *argv[])
|
|||||||
|
|
||||||
ramsize = strtoul(optarg, &ep, 0);
|
ramsize = strtoul(optarg, &ep, 0);
|
||||||
if (optarg[0] == '\0' || *ep != '\0') {
|
if (optarg[0] == '\0' || *ep != '\0') {
|
||||||
fprintf(stderr,
|
errx(1, "Invalid argument for option 'r'");
|
||||||
"Invalid argument for option 'r'\n");
|
|
||||||
}
|
}
|
||||||
if (ramsize < 0 || ramsize > 0xFF) {
|
if (ramsize < 0 || ramsize > 0xFF) {
|
||||||
fprintf(stderr,
|
errx(1, "Argument for option 'r' must be "
|
||||||
"Argument for option 'r' must be "
|
"between 0 and 255");
|
||||||
"between 0 and 255\n");
|
|
||||||
exit(1);
|
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case 's':
|
case 's':
|
||||||
@@ -201,15 +167,13 @@ main(int argc, char *argv[])
|
|||||||
settitle = true;
|
settitle = true;
|
||||||
|
|
||||||
if (strlen(optarg) > 16) {
|
if (strlen(optarg) > 16) {
|
||||||
fprintf(stderr, "Title %s is greater than the "
|
errx(1, "Title %s is greater than the "
|
||||||
"maximum of 16 characters\n", optarg);
|
"maximum of 16 characters", optarg);
|
||||||
exit(1);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (strlen(optarg) == 16)
|
if (strlen(optarg) == 16)
|
||||||
fprintf(stderr,
|
warnx("Title %s is 16 chars, it is best to "
|
||||||
"Title %s is 16 chars, it is best "
|
"keep it to 15 or fewer", optarg);
|
||||||
"to keep it to 15 or fewer\n", optarg);
|
|
||||||
|
|
||||||
title = optarg;
|
title = optarg;
|
||||||
break;
|
break;
|
||||||
@@ -221,9 +185,21 @@ main(int argc, char *argv[])
|
|||||||
/* NOTREACHED */
|
/* NOTREACHED */
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
argc -= optind;
|
argc -= optind;
|
||||||
argv += 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
|
||||||
*/
|
*/
|
||||||
@@ -315,8 +291,7 @@ main(int argc, char *argv[])
|
|||||||
byte |= 1 << 6;
|
byte |= 1 << 6;
|
||||||
|
|
||||||
if (byte & 0x3F)
|
if (byte & 0x3F)
|
||||||
fprintf(stderr,
|
warnx("Color flag conflicts with game title");
|
||||||
"Color flag conflicts with game title\n");
|
|
||||||
|
|
||||||
fseek(rom, 0x143, SEEK_SET);
|
fseek(rom, 0x143, SEEK_SET);
|
||||||
fputc(byte, rom);
|
fputc(byte, rom);
|
||||||
@@ -353,9 +328,8 @@ main(int argc, char *argv[])
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
if (!setlicensee)
|
if (!setlicensee)
|
||||||
fprintf(stderr,
|
warnx("You should probably set both '-s' and "
|
||||||
"You should probably set both '-s' and "
|
"'-l 0x33'");
|
||||||
"'-l 0x33'\n");
|
|
||||||
|
|
||||||
fseek(rom, 0x146, SEEK_SET);
|
fseek(rom, 0x146, SEEK_SET);
|
||||||
fputc(3, rom);
|
fputc(3, rom);
|
||||||
@@ -392,7 +366,7 @@ main(int argc, char *argv[])
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (newsize > 0x800000) /* ROM is bigger than 8MiB */
|
if (newsize > 0x800000) /* ROM is bigger than 8MiB */
|
||||||
fprintf(stderr, "ROM size is bigger than 8MiB\n");
|
warnx("ROM size is bigger than 8MiB");
|
||||||
|
|
||||||
buf = malloc(newsize - romsize);
|
buf = malloc(newsize - romsize);
|
||||||
memset(buf, padvalue, newsize - romsize);
|
memset(buf, padvalue, newsize - romsize);
|
||||||
|
|||||||
@@ -130,7 +130,6 @@ of the game
|
|||||||
.Sh SEE ALSO
|
.Sh SEE ALSO
|
||||||
.Xr rgbds 7 ,
|
.Xr rgbds 7 ,
|
||||||
.Xr rgbasm 1 ,
|
.Xr rgbasm 1 ,
|
||||||
.Xr rgblib 1 ,
|
|
||||||
.Xr rgblink 1 ,
|
.Xr rgblink 1 ,
|
||||||
.Xr gbz80 7
|
.Xr gbz80 7
|
||||||
.Sh HISTORY
|
.Sh HISTORY
|
||||||
|
|||||||
@@ -1,306 +0,0 @@
|
|||||||
#include <stdio.h>
|
|
||||||
#include <stdlib.h>
|
|
||||||
#include <string.h>
|
|
||||||
|
|
||||||
#include "lib/types.h"
|
|
||||||
#include "lib/libwrap.h"
|
|
||||||
|
|
||||||
SLONG
|
|
||||||
file_Length(FILE * f)
|
|
||||||
{
|
|
||||||
ULONG r, p;
|
|
||||||
|
|
||||||
p = ftell(f);
|
|
||||||
fseek(f, 0, SEEK_END);
|
|
||||||
r = ftell(f);
|
|
||||||
fseek(f, p, SEEK_SET);
|
|
||||||
|
|
||||||
return (r);
|
|
||||||
}
|
|
||||||
|
|
||||||
SLONG
|
|
||||||
file_ReadASCIIz(char *b, FILE * f)
|
|
||||||
{
|
|
||||||
SLONG r = 0;
|
|
||||||
|
|
||||||
while ((*b++ = fgetc(f)) != 0)
|
|
||||||
r += 1;
|
|
||||||
|
|
||||||
return (r + 1);
|
|
||||||
}
|
|
||||||
|
|
||||||
void
|
|
||||||
file_WriteASCIIz(char *b, FILE * f)
|
|
||||||
{
|
|
||||||
while (*b)
|
|
||||||
fputc(*b++, f);
|
|
||||||
|
|
||||||
fputc(0, f);
|
|
||||||
}
|
|
||||||
|
|
||||||
UWORD
|
|
||||||
file_ReadWord(FILE * f)
|
|
||||||
{
|
|
||||||
UWORD r;
|
|
||||||
|
|
||||||
r = fgetc(f);
|
|
||||||
r |= fgetc(f) << 8;
|
|
||||||
|
|
||||||
return (r);
|
|
||||||
}
|
|
||||||
|
|
||||||
void
|
|
||||||
file_WriteWord(UWORD w, FILE * f)
|
|
||||||
{
|
|
||||||
fputc(w, f);
|
|
||||||
fputc(w >> 8, f);
|
|
||||||
}
|
|
||||||
|
|
||||||
ULONG
|
|
||||||
file_ReadLong(FILE * f)
|
|
||||||
{
|
|
||||||
ULONG r;
|
|
||||||
|
|
||||||
r = fgetc(f);
|
|
||||||
r |= fgetc(f) << 8;
|
|
||||||
r |= fgetc(f) << 16;
|
|
||||||
r |= fgetc(f) << 24;
|
|
||||||
|
|
||||||
return (r);
|
|
||||||
}
|
|
||||||
|
|
||||||
void
|
|
||||||
file_WriteLong(UWORD w, FILE * f)
|
|
||||||
{
|
|
||||||
fputc(w, f);
|
|
||||||
fputc(w >> 8, f);
|
|
||||||
fputc(w >> 16, f);
|
|
||||||
fputc(w >> 24, f);
|
|
||||||
}
|
|
||||||
|
|
||||||
sLibrary *
|
|
||||||
lib_ReadLib0(FILE * f, SLONG size)
|
|
||||||
{
|
|
||||||
if (size) {
|
|
||||||
sLibrary *l = NULL, *first = NULL;
|
|
||||||
|
|
||||||
while (size > 0) {
|
|
||||||
if (l == NULL) {
|
|
||||||
l = malloc(sizeof *l);
|
|
||||||
if (!l) {
|
|
||||||
fprintf(stderr, "Out of memory\n");
|
|
||||||
exit(1);
|
|
||||||
}
|
|
||||||
|
|
||||||
first = l;
|
|
||||||
} else {
|
|
||||||
l->pNext = malloc(sizeof *l->pNext);
|
|
||||||
if (!l->pNext) {
|
|
||||||
fprintf(stderr, "Out of memory\n");
|
|
||||||
exit(1);
|
|
||||||
}
|
|
||||||
|
|
||||||
l = l->pNext;
|
|
||||||
}
|
|
||||||
|
|
||||||
size -= file_ReadASCIIz(l->tName, f);
|
|
||||||
l->uwTime = file_ReadWord(f);
|
|
||||||
size -= 2;
|
|
||||||
l->uwDate = file_ReadWord(f);
|
|
||||||
size -= 2;
|
|
||||||
l->nByteLength = file_ReadLong(f);
|
|
||||||
size -= 4;
|
|
||||||
if ((l->pData = malloc(l->nByteLength))) {
|
|
||||||
fread(l->pData, sizeof(UBYTE), l->nByteLength,
|
|
||||||
f);
|
|
||||||
size -= l->nByteLength;
|
|
||||||
} else {
|
|
||||||
fprintf(stderr, "Out of memory\n");
|
|
||||||
exit(1);
|
|
||||||
}
|
|
||||||
|
|
||||||
l->pNext = NULL;
|
|
||||||
}
|
|
||||||
return (first);
|
|
||||||
}
|
|
||||||
return (NULL);
|
|
||||||
}
|
|
||||||
|
|
||||||
sLibrary *
|
|
||||||
lib_Read(char *filename)
|
|
||||||
{
|
|
||||||
FILE *f;
|
|
||||||
|
|
||||||
if ((f = fopen(filename, "rb"))) {
|
|
||||||
SLONG size;
|
|
||||||
char ID[5];
|
|
||||||
|
|
||||||
size = file_Length(f);
|
|
||||||
if (size == 0) {
|
|
||||||
fclose(f);
|
|
||||||
return (NULL);
|
|
||||||
}
|
|
||||||
fread(ID, sizeof(char), 4, f);
|
|
||||||
ID[4] = 0;
|
|
||||||
size -= 4;
|
|
||||||
|
|
||||||
if (strcmp(ID, "XLB0") == 0) {
|
|
||||||
sLibrary *r;
|
|
||||||
|
|
||||||
r = lib_ReadLib0(f, size);
|
|
||||||
fclose(f);
|
|
||||||
printf("Library '%s' opened\n", filename);
|
|
||||||
return (r);
|
|
||||||
} else {
|
|
||||||
fclose(f);
|
|
||||||
fprintf(stderr, "Not a valid xLib library\n");
|
|
||||||
exit(1);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
printf
|
|
||||||
("Library '%s' not found, it will be created if necessary\n",
|
|
||||||
filename);
|
|
||||||
return (NULL);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
BBOOL
|
|
||||||
lib_Write(sLibrary * lib, char *filename)
|
|
||||||
{
|
|
||||||
FILE *f;
|
|
||||||
|
|
||||||
if ((f = fopen(filename, "wb"))) {
|
|
||||||
fwrite("XLB0", sizeof(char), 4, f);
|
|
||||||
while (lib) {
|
|
||||||
file_WriteASCIIz(lib->tName, f);
|
|
||||||
file_WriteWord(lib->uwTime, f);
|
|
||||||
file_WriteWord(lib->uwDate, f);
|
|
||||||
file_WriteLong(lib->nByteLength, f);
|
|
||||||
fwrite(lib->pData, sizeof(UBYTE), lib->nByteLength, f);
|
|
||||||
lib = lib->pNext;
|
|
||||||
}
|
|
||||||
|
|
||||||
fclose(f);
|
|
||||||
printf("Library '%s' closed\n", filename);
|
|
||||||
return (1);
|
|
||||||
}
|
|
||||||
return (0);
|
|
||||||
}
|
|
||||||
|
|
||||||
sLibrary *
|
|
||||||
lib_Find(sLibrary * lib, char *filename)
|
|
||||||
{
|
|
||||||
if (strlen(filename) >= MAXNAMELENGTH) {
|
|
||||||
fprintf(stderr, "Module name too long: %s\n", filename);
|
|
||||||
exit(1);
|
|
||||||
}
|
|
||||||
|
|
||||||
while (lib) {
|
|
||||||
if (strcmp(lib->tName, filename) == 0)
|
|
||||||
break;
|
|
||||||
|
|
||||||
lib = lib->pNext;
|
|
||||||
}
|
|
||||||
|
|
||||||
return (lib);
|
|
||||||
}
|
|
||||||
|
|
||||||
sLibrary *
|
|
||||||
lib_AddReplace(sLibrary * lib, char *filename)
|
|
||||||
{
|
|
||||||
FILE *f;
|
|
||||||
|
|
||||||
if ((f = fopen(filename, "rb"))) {
|
|
||||||
sLibrary *module;
|
|
||||||
|
|
||||||
if (strlen(filename) >= MAXNAMELENGTH) {
|
|
||||||
fprintf(stderr, "Module name too long: %s\n",
|
|
||||||
filename);
|
|
||||||
exit(1);
|
|
||||||
}
|
|
||||||
|
|
||||||
if ((module = lib_Find(lib, filename)) == NULL) {
|
|
||||||
module = malloc(sizeof *module);
|
|
||||||
if (!module) {
|
|
||||||
fprintf(stderr, "Out of memory\n");
|
|
||||||
exit(1);
|
|
||||||
}
|
|
||||||
|
|
||||||
module->pNext = lib;
|
|
||||||
lib = module;
|
|
||||||
} else {
|
|
||||||
/* Module already exists */
|
|
||||||
free(module->pData);
|
|
||||||
}
|
|
||||||
|
|
||||||
module->nByteLength = file_Length(f);
|
|
||||||
strcpy(module->tName, filename);
|
|
||||||
module->pData = malloc(module->nByteLength);
|
|
||||||
if (!module->pData) {
|
|
||||||
fprintf(stderr, "Out of memory\n");
|
|
||||||
exit(1);
|
|
||||||
}
|
|
||||||
|
|
||||||
fread(module->pData, sizeof(UBYTE), module->nByteLength, f);
|
|
||||||
|
|
||||||
printf("Added module '%s'\n", filename);
|
|
||||||
|
|
||||||
fclose(f);
|
|
||||||
}
|
|
||||||
return (lib);
|
|
||||||
}
|
|
||||||
|
|
||||||
sLibrary *
|
|
||||||
lib_DeleteModule(sLibrary * lib, char *filename)
|
|
||||||
{
|
|
||||||
sLibrary **pp, **first;
|
|
||||||
BBOOL found = 0;
|
|
||||||
|
|
||||||
pp = &lib;
|
|
||||||
first = pp;
|
|
||||||
|
|
||||||
if (strlen(filename) >= MAXNAMELENGTH) {
|
|
||||||
fprintf(stderr, "Module name too long: %s\n", filename);
|
|
||||||
exit(1);
|
|
||||||
}
|
|
||||||
|
|
||||||
while ((*pp) && (!found)) {
|
|
||||||
if (strcmp((*pp)->tName, filename) == 0) {
|
|
||||||
sLibrary *t;
|
|
||||||
|
|
||||||
t = *pp;
|
|
||||||
|
|
||||||
if (t->pData)
|
|
||||||
free(t->pData);
|
|
||||||
|
|
||||||
*pp = t->pNext;
|
|
||||||
|
|
||||||
free(t);
|
|
||||||
found = 1;
|
|
||||||
}
|
|
||||||
pp = &((*pp)->pNext);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!found) {
|
|
||||||
fprintf(stderr, "Module not found\n");
|
|
||||||
exit(1);
|
|
||||||
} else
|
|
||||||
printf("Module '%s' deleted from library\n", filename);
|
|
||||||
|
|
||||||
return (*first);
|
|
||||||
}
|
|
||||||
|
|
||||||
void
|
|
||||||
lib_Free(sLibrary * lib)
|
|
||||||
{
|
|
||||||
while (lib) {
|
|
||||||
sLibrary *l;
|
|
||||||
|
|
||||||
if (lib->pData)
|
|
||||||
free(lib->pData);
|
|
||||||
|
|
||||||
l = lib;
|
|
||||||
lib = lib->pNext;
|
|
||||||
free(l);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
120
src/lib/main.c
120
src/lib/main.c
@@ -1,120 +0,0 @@
|
|||||||
#include <ctype.h>
|
|
||||||
#include <errno.h>
|
|
||||||
#include <stdio.h>
|
|
||||||
#include <stdlib.h>
|
|
||||||
#include <string.h>
|
|
||||||
|
|
||||||
#include "asmotor.h"
|
|
||||||
|
|
||||||
#include "lib/types.h"
|
|
||||||
#include "lib/library.h"
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Print the usagescreen
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
|
|
||||||
static void
|
|
||||||
usage(void)
|
|
||||||
{
|
|
||||||
printf("RGBLib v" LIB_VERSION " (part of ASMotor " ASMOTOR_VERSION ")\n\n");
|
|
||||||
printf("usage: rgblib file [add | delete | extract | list] [module ...]\n");
|
|
||||||
exit(1);
|
|
||||||
}
|
|
||||||
/*
|
|
||||||
* The main routine
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
|
|
||||||
int
|
|
||||||
main(int argc, char *argv[])
|
|
||||||
{
|
|
||||||
SLONG argn = 0;
|
|
||||||
char *libname;
|
|
||||||
|
|
||||||
argc -= 1;
|
|
||||||
argn += 1;
|
|
||||||
|
|
||||||
if (argc >= 2) {
|
|
||||||
sLibrary *lib;
|
|
||||||
|
|
||||||
lib = lib_Read(libname = argv[argn++]);
|
|
||||||
argc -= 1;
|
|
||||||
|
|
||||||
if (strcmp(argv[argn], "add") == 0) {
|
|
||||||
argn += 1;
|
|
||||||
argc -= 1;
|
|
||||||
|
|
||||||
while (argc) {
|
|
||||||
lib = lib_AddReplace(lib, argv[argn++]);
|
|
||||||
argc -= 1;
|
|
||||||
}
|
|
||||||
lib_Write(lib, libname);
|
|
||||||
lib_Free(lib);
|
|
||||||
} else if (strcmp(argv[argn], "delete") == 0) {
|
|
||||||
argn += 1;
|
|
||||||
argc -= 1;
|
|
||||||
|
|
||||||
while (argc) {
|
|
||||||
lib =
|
|
||||||
lib_DeleteModule(lib, argv[argn++]);
|
|
||||||
argc -= 1;
|
|
||||||
}
|
|
||||||
lib_Write(lib, libname);
|
|
||||||
lib_Free(lib);
|
|
||||||
} else if (strcmp(argv[argn], "extract") == 0) {
|
|
||||||
argn += 1;
|
|
||||||
argc -= 1;
|
|
||||||
|
|
||||||
while (argc) {
|
|
||||||
sLibrary *l;
|
|
||||||
|
|
||||||
l = lib_Find(lib, argv[argn]);
|
|
||||||
if (l) {
|
|
||||||
FILE *f;
|
|
||||||
|
|
||||||
if ((f = fopen(argv[argn], "wb"))) {
|
|
||||||
fwrite(l->pData,
|
|
||||||
sizeof(UBYTE),
|
|
||||||
l->nByteLength,
|
|
||||||
f);
|
|
||||||
fclose(f);
|
|
||||||
printf
|
|
||||||
("Extracted module '%s'\n",
|
|
||||||
argv[argn]);
|
|
||||||
} else {
|
|
||||||
fprintf(stderr,
|
|
||||||
"Unable to write module '%s': ", argv[argn]);
|
|
||||||
perror(NULL);
|
|
||||||
exit(1);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
fprintf(stderr, "Module not found\n");
|
|
||||||
exit(1);
|
|
||||||
}
|
|
||||||
|
|
||||||
argn += 1;
|
|
||||||
argc -= 1;
|
|
||||||
}
|
|
||||||
lib_Free(lib);
|
|
||||||
} else if (strcmp(argv[argn], "list") == 0) {
|
|
||||||
argn += 1;
|
|
||||||
argc -= 1;
|
|
||||||
|
|
||||||
sLibrary *l;
|
|
||||||
|
|
||||||
l = lib;
|
|
||||||
|
|
||||||
while (l) {
|
|
||||||
printf("%10ld %s\n",
|
|
||||||
l->nByteLength,
|
|
||||||
l->tName);
|
|
||||||
l = l->pNext;
|
|
||||||
}
|
|
||||||
} else
|
|
||||||
usage();
|
|
||||||
} else
|
|
||||||
usage();
|
|
||||||
|
|
||||||
return (0);
|
|
||||||
}
|
|
||||||
@@ -1,36 +0,0 @@
|
|||||||
.Dd $Mdocdate$
|
|
||||||
.Dt RGBLIB 1
|
|
||||||
.Os RGBDS Manual
|
|
||||||
.Sh NAME
|
|
||||||
.Nm rgblib
|
|
||||||
.Nd Game Boy library manager
|
|
||||||
.Sh SYNOPSIS
|
|
||||||
.Nm rgblib
|
|
||||||
.Ar library
|
|
||||||
.Op add | delete | extract | list
|
|
||||||
.Ar module ...
|
|
||||||
.Sh DESCRIPTION
|
|
||||||
The
|
|
||||||
.Nm
|
|
||||||
program manages libraries for use with
|
|
||||||
.Xr rgblink 1 .
|
|
||||||
.Bl -tag -width Ds
|
|
||||||
.It add
|
|
||||||
Add the given modules to the library.
|
|
||||||
.It delete
|
|
||||||
Delete the given modules from the library.
|
|
||||||
.It extract
|
|
||||||
Extract the given modules from the library.
|
|
||||||
.It list
|
|
||||||
List all the modules in the library.
|
|
||||||
.El
|
|
||||||
.Sh SEE ALSO
|
|
||||||
.Xr rgbds 7 ,
|
|
||||||
.Xr rgbasm 1 ,
|
|
||||||
.Xr rgbfix 1 ,
|
|
||||||
.Xr rgblink 1 ,
|
|
||||||
.Xr gbz80 7
|
|
||||||
.Sh HISTORY
|
|
||||||
.Nm
|
|
||||||
was originally released by Carsten S\(/orensen as part of the ASMotor package,
|
|
||||||
and was later packaged in RGBDS by Justin Lloyd.
|
|
||||||
@@ -1,6 +1,7 @@
|
|||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
|
||||||
|
#include "extern/err.h"
|
||||||
#include "link/mylink.h"
|
#include "link/mylink.h"
|
||||||
#include "link/main.h"
|
#include "link/main.h"
|
||||||
#include "link/symbol.h"
|
#include "link/symbol.h"
|
||||||
@@ -63,7 +64,6 @@ area_AllocAbs(struct sFreeArea ** ppArea, SLONG org, SLONG size)
|
|||||||
struct sFreeArea *pNewArea;
|
struct sFreeArea *pNewArea;
|
||||||
|
|
||||||
if ((pNewArea =
|
if ((pNewArea =
|
||||||
(struct sFreeArea *)
|
|
||||||
malloc(sizeof(struct sFreeArea)))
|
malloc(sizeof(struct sFreeArea)))
|
||||||
!= NULL) {
|
!= NULL) {
|
||||||
*pNewArea = *pArea;
|
*pNewArea = *pArea;
|
||||||
@@ -77,9 +77,7 @@ area_AllocAbs(struct sFreeArea ** ppArea, SLONG org, SLONG size)
|
|||||||
|
|
||||||
return (org);
|
return (org);
|
||||||
} else {
|
} else {
|
||||||
fprintf(stderr,
|
err(1, NULL);
|
||||||
"Out of memory!\n");
|
|
||||||
exit(1);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -310,9 +308,7 @@ AssignVRAMSections(void)
|
|||||||
pSection->oAssigned = 1;
|
pSection->oAssigned = 1;
|
||||||
DOMAXVBANK(pSection->nBank);
|
DOMAXVBANK(pSection->nBank);
|
||||||
} else {
|
} else {
|
||||||
fprintf(stderr,
|
errx(1, "Unable to place VRAM section anywhere");
|
||||||
"Unable to place VRAM section anywhere\n");
|
|
||||||
exit(1);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -331,9 +327,7 @@ AssignSRAMSections(void)
|
|||||||
pSection->oAssigned = 1;
|
pSection->oAssigned = 1;
|
||||||
DOMAXSBANK(pSection->nBank);
|
DOMAXSBANK(pSection->nBank);
|
||||||
} else {
|
} else {
|
||||||
fprintf(stderr,
|
errx(1, "Unable to place SRAM section anywhere");
|
||||||
"Unable to place SRAM section anywhere\n");
|
|
||||||
exit(1);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -352,9 +346,7 @@ AssignWRAMSections(void)
|
|||||||
pSection->oAssigned = 1;
|
pSection->oAssigned = 1;
|
||||||
DOMAXWBANK(pSection->nBank);
|
DOMAXWBANK(pSection->nBank);
|
||||||
} else {
|
} else {
|
||||||
fprintf(stderr,
|
errx(1, "Unable to place WRAMX section anywhere");
|
||||||
"Unable to place WRAMX section anywhere\n");
|
|
||||||
exit(1);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -373,9 +365,7 @@ AssignCodeSections(void)
|
|||||||
pSection->oAssigned = 1;
|
pSection->oAssigned = 1;
|
||||||
DOMAXBANK(pSection->nBank);
|
DOMAXBANK(pSection->nBank);
|
||||||
} else {
|
} else {
|
||||||
fprintf(stderr,
|
errx(1, "Unable to place ROMX section anywhere");
|
||||||
"Unable to place ROMX section anywhere\n");
|
|
||||||
exit(1);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -397,8 +387,7 @@ AssignSections(void)
|
|||||||
BankFree[i] = malloc(sizeof *BankFree[i]);
|
BankFree[i] = malloc(sizeof *BankFree[i]);
|
||||||
|
|
||||||
if (!BankFree[i]) {
|
if (!BankFree[i]) {
|
||||||
fprintf(stderr, "Out of memory!\n");
|
err(1, NULL);
|
||||||
exit(1);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (i == 0) {
|
if (i == 0) {
|
||||||
@@ -472,10 +461,9 @@ AssignSections(void)
|
|||||||
if (area_AllocAbs
|
if (area_AllocAbs
|
||||||
(&BankFree[BANK_WRAM0], pSection->nOrg,
|
(&BankFree[BANK_WRAM0], pSection->nOrg,
|
||||||
pSection->nByteSize) != pSection->nOrg) {
|
pSection->nByteSize) != pSection->nOrg) {
|
||||||
fprintf(stderr,
|
errx(1,
|
||||||
"Unable to load fixed WRAM0 section "
|
"Unable to load fixed WRAM0 "
|
||||||
"at $%lX\n", pSection->nOrg);
|
"section at $%lX", pSection->nOrg);
|
||||||
exit(1);
|
|
||||||
}
|
}
|
||||||
pSection->oAssigned = 1;
|
pSection->oAssigned = 1;
|
||||||
pSection->nBank = BANK_WRAM0;
|
pSection->nBank = BANK_WRAM0;
|
||||||
@@ -484,10 +472,8 @@ AssignSections(void)
|
|||||||
if (area_AllocAbs
|
if (area_AllocAbs
|
||||||
(&BankFree[BANK_HRAM], pSection->nOrg,
|
(&BankFree[BANK_HRAM], pSection->nOrg,
|
||||||
pSection->nByteSize) != pSection->nOrg) {
|
pSection->nByteSize) != pSection->nOrg) {
|
||||||
fprintf(stderr, "Unable to load fixed "
|
errx(1, "Unable to load fixed HRAM "
|
||||||
"HRAM section at $%lX\n",
|
"section at $%lX", pSection->nOrg);
|
||||||
pSection->nOrg);
|
|
||||||
exit(1);
|
|
||||||
}
|
}
|
||||||
pSection->oAssigned = 1;
|
pSection->oAssigned = 1;
|
||||||
pSection->nBank = BANK_HRAM;
|
pSection->nBank = BANK_HRAM;
|
||||||
@@ -530,17 +516,15 @@ AssignSections(void)
|
|||||||
pSection->nOrg,
|
pSection->nOrg,
|
||||||
pSection->nByteSize)
|
pSection->nByteSize)
|
||||||
!= pSection->nOrg) {
|
!= pSection->nOrg) {
|
||||||
fprintf(stderr,
|
errx(1,
|
||||||
"Unable to load fixed SRAM section at $%lX in bank $%02lX\n", pSection->nOrg, pSection->nBank);
|
"Unable to load fixed SRAM section at $%lX in bank $%02lX", pSection->nOrg, pSection->nBank);
|
||||||
exit(1);
|
|
||||||
}
|
}
|
||||||
DOMAXVBANK(pSection->
|
DOMAXVBANK(pSection->
|
||||||
nBank);
|
nBank);
|
||||||
pSection->oAssigned = 1;
|
pSection->oAssigned = 1;
|
||||||
} else {
|
} else {
|
||||||
fprintf(stderr,
|
errx(1,
|
||||||
"Unable to load fixed SRAM section at $%lX in bank $%02lX\n", pSection->nOrg, pSection->nBank);
|
"Unable to load fixed SRAM section at $%lX in bank $%02lX", pSection->nOrg, pSection->nBank);
|
||||||
exit(1);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -583,17 +567,15 @@ AssignSections(void)
|
|||||||
pSection->nOrg,
|
pSection->nOrg,
|
||||||
pSection->nByteSize)
|
pSection->nByteSize)
|
||||||
!= pSection->nOrg) {
|
!= pSection->nOrg) {
|
||||||
fprintf(stderr,
|
errx(1,
|
||||||
"Unable to load fixed WRAMX section at $%lX in bank $%02lX\n", pSection->nOrg, pSection->nBank);
|
"Unable to load fixed WRAMX section at $%lX in bank $%02lX", pSection->nOrg, pSection->nBank);
|
||||||
exit(1);
|
|
||||||
}
|
}
|
||||||
DOMAXWBANK(pSection->
|
DOMAXWBANK(pSection->
|
||||||
nBank);
|
nBank);
|
||||||
pSection->oAssigned = 1;
|
pSection->oAssigned = 1;
|
||||||
} else {
|
} else {
|
||||||
fprintf(stderr,
|
errx(1,
|
||||||
"Unable to load fixed WRAMX section at $%lX in bank $%02lX\n", pSection->nOrg, pSection->nBank);
|
"Unable to load fixed WRAMX section at $%lX in bank $%02lX", pSection->nOrg, pSection->nBank);
|
||||||
exit(1);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -636,17 +618,15 @@ AssignSections(void)
|
|||||||
pSection->nOrg,
|
pSection->nOrg,
|
||||||
pSection->nByteSize)
|
pSection->nByteSize)
|
||||||
!= pSection->nOrg) {
|
!= pSection->nOrg) {
|
||||||
fprintf(stderr,
|
errx(1,
|
||||||
"Unable to load fixed VRAM section at $%lX in bank $%02lX\n", pSection->nOrg, pSection->nBank);
|
"Unable to load fixed VRAM section at $%lX in bank $%02lX", pSection->nOrg, pSection->nBank);
|
||||||
exit(1);
|
|
||||||
}
|
}
|
||||||
DOMAXVBANK(pSection->
|
DOMAXVBANK(pSection->
|
||||||
nBank);
|
nBank);
|
||||||
pSection->oAssigned = 1;
|
pSection->oAssigned = 1;
|
||||||
} else {
|
} else {
|
||||||
fprintf(stderr,
|
errx(1,
|
||||||
"Unable to load fixed VRAM section at $%lX in bank $%02lX\n", pSection->nOrg, pSection->nBank);
|
"Unable to load fixed VRAM section at $%lX in bank $%02lX", pSection->nOrg, pSection->nBank);
|
||||||
exit(1);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -655,10 +635,8 @@ AssignSections(void)
|
|||||||
if (area_AllocAbs
|
if (area_AllocAbs
|
||||||
(&BankFree[BANK_ROM0], pSection->nOrg,
|
(&BankFree[BANK_ROM0], pSection->nOrg,
|
||||||
pSection->nByteSize) != pSection->nOrg) {
|
pSection->nByteSize) != pSection->nOrg) {
|
||||||
fprintf(stderr, "Unable to load fixed "
|
errx(1, "Unable to load fixed ROM0 "
|
||||||
"ROM0 section at $%lX\n",
|
"section at $%lX", pSection->nOrg);
|
||||||
pSection->nOrg);
|
|
||||||
exit(1);
|
|
||||||
}
|
}
|
||||||
pSection->oAssigned = 1;
|
pSection->oAssigned = 1;
|
||||||
pSection->nBank = BANK_ROM0;
|
pSection->nBank = BANK_ROM0;
|
||||||
@@ -703,15 +681,15 @@ AssignSections(void)
|
|||||||
pSection->
|
pSection->
|
||||||
nByteSize) !=
|
nByteSize) !=
|
||||||
pSection->nOrg) {
|
pSection->nOrg) {
|
||||||
fprintf(stderr, "Unable to load fixed ROMX section at $%lX in bank $%02lX\n", pSection->nOrg, pSection->nBank);
|
errx(1,
|
||||||
exit(1);
|
"Unable to load fixed ROMX section at $%lX in bank $%02lX", pSection->nOrg, pSection->nBank);
|
||||||
}
|
}
|
||||||
DOMAXBANK(pSection->
|
DOMAXBANK(pSection->
|
||||||
nBank);
|
nBank);
|
||||||
pSection->oAssigned = 1;
|
pSection->oAssigned = 1;
|
||||||
} else {
|
} else {
|
||||||
fprintf(stderr, "Unable to load fixed ROMX section at $%lX in bank $%02lX\n", pSection->nOrg, pSection->nBank);
|
errx(1,
|
||||||
exit(1);
|
"Unable to load fixed ROMX section at $%lX in bank $%02lX", pSection->nOrg, pSection->nBank);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -737,14 +715,13 @@ AssignSections(void)
|
|||||||
if ((pSection->nOrg =
|
if ((pSection->nOrg =
|
||||||
area_Alloc(&BankFree[pSection->nBank],
|
area_Alloc(&BankFree[pSection->nBank],
|
||||||
pSection->nByteSize)) == -1) {
|
pSection->nByteSize)) == -1) {
|
||||||
fprintf(stderr, "Unable to load fixed ROMX section into bank $%02lX\n", pSection->nBank);
|
errx(1,
|
||||||
exit(1);
|
"Unable to load fixed ROMX section into bank $%02lX", pSection->nBank);
|
||||||
}
|
}
|
||||||
pSection->oAssigned = 1;
|
pSection->oAssigned = 1;
|
||||||
DOMAXBANK(pSection->nBank);
|
DOMAXBANK(pSection->nBank);
|
||||||
} else {
|
} else {
|
||||||
fprintf(stderr, "Unable to load fixed ROMX section into bank $%02lX\n", pSection->nBank);
|
errx(1, "Unable to load fixed ROMX section into bank $%02lX", pSection->nBank);
|
||||||
exit(1);
|
|
||||||
}
|
}
|
||||||
} else if (pSection->oAssigned == 0
|
} else if (pSection->oAssigned == 0
|
||||||
&& pSection->Type == SECT_SRAM
|
&& pSection->Type == SECT_SRAM
|
||||||
@@ -755,14 +732,12 @@ AssignSections(void)
|
|||||||
if ((pSection->nOrg =
|
if ((pSection->nOrg =
|
||||||
area_Alloc(&BankFree[pSection->nBank],
|
area_Alloc(&BankFree[pSection->nBank],
|
||||||
pSection->nByteSize)) == -1) {
|
pSection->nByteSize)) == -1) {
|
||||||
fprintf(stderr, "Unable to load fixed SRAM section into bank $%02lX\n", pSection->nBank);
|
errx(1, "Unable to load fixed SRAM section into bank $%02lX", pSection->nBank);
|
||||||
exit(1);
|
|
||||||
}
|
}
|
||||||
pSection->oAssigned = 1;
|
pSection->oAssigned = 1;
|
||||||
DOMAXSBANK(pSection->nBank);
|
DOMAXSBANK(pSection->nBank);
|
||||||
} else {
|
} else {
|
||||||
fprintf(stderr, "Unable to load fixed VRAM section into bank $%02lX\n", pSection->nBank);
|
errx(1, "Unable to load fixed VRAM section into bank $%02lX", pSection->nBank);
|
||||||
exit(1);
|
|
||||||
}
|
}
|
||||||
} else if (pSection->oAssigned == 0
|
} else if (pSection->oAssigned == 0
|
||||||
&& pSection->Type == SECT_VRAM
|
&& pSection->Type == SECT_VRAM
|
||||||
@@ -773,14 +748,12 @@ AssignSections(void)
|
|||||||
if ((pSection->nOrg =
|
if ((pSection->nOrg =
|
||||||
area_Alloc(&BankFree[pSection->nBank],
|
area_Alloc(&BankFree[pSection->nBank],
|
||||||
pSection->nByteSize)) == -1) {
|
pSection->nByteSize)) == -1) {
|
||||||
fprintf(stderr, "Unable to load fixed VRAM section into bank $%02lX\n", pSection->nBank);
|
errx(1, "Unable to load fixed VRAM section into bank $%02lX", pSection->nBank);
|
||||||
exit(1);
|
|
||||||
}
|
}
|
||||||
pSection->oAssigned = 1;
|
pSection->oAssigned = 1;
|
||||||
DOMAXVBANK(pSection->nBank);
|
DOMAXVBANK(pSection->nBank);
|
||||||
} else {
|
} else {
|
||||||
fprintf(stderr, "Unable to load fixed VRAM section into bank $%02lX\n", pSection->nBank);
|
errx(1, "Unable to load fixed VRAM section into bank $%02lX", pSection->nBank);
|
||||||
exit(1);
|
|
||||||
}
|
}
|
||||||
} else if (pSection->oAssigned == 0
|
} else if (pSection->oAssigned == 0
|
||||||
&& pSection->Type == SECT_WRAMX
|
&& pSection->Type == SECT_WRAMX
|
||||||
@@ -791,14 +764,12 @@ AssignSections(void)
|
|||||||
if ((pSection->nOrg =
|
if ((pSection->nOrg =
|
||||||
area_Alloc(&BankFree[pSection->nBank],
|
area_Alloc(&BankFree[pSection->nBank],
|
||||||
pSection->nByteSize)) == -1) {
|
pSection->nByteSize)) == -1) {
|
||||||
fprintf(stderr, "Unable to load fixed WRAMX section into bank $%02lX\n", pSection->nBank - BANK_WRAMX);
|
errx(1, "Unable to load fixed WRAMX section into bank $%02lX", pSection->nBank - BANK_WRAMX);
|
||||||
exit(1);
|
|
||||||
}
|
}
|
||||||
pSection->oAssigned = 1;
|
pSection->oAssigned = 1;
|
||||||
DOMAXWBANK(pSection->nBank);
|
DOMAXWBANK(pSection->nBank);
|
||||||
} else {
|
} else {
|
||||||
fprintf(stderr, "Unable to load fixed WRAMX section into bank $%02lX\n", pSection->nBank - BANK_WRAMX);
|
errx(1, "Unable to load fixed WRAMX section into bank $%02lX", pSection->nBank - BANK_WRAMX);
|
||||||
exit(1);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
pSection = pSection->pNext;
|
pSection = pSection->pNext;
|
||||||
@@ -820,8 +791,7 @@ AssignSections(void)
|
|||||||
area_AllocAbsROMXAnyBank(pSection->nOrg,
|
area_AllocAbsROMXAnyBank(pSection->nOrg,
|
||||||
pSection->nByteSize)) ==
|
pSection->nByteSize)) ==
|
||||||
-1) {
|
-1) {
|
||||||
fprintf(stderr, "Unable to load fixed ROMX section at $%lX into any bank\n", pSection->nOrg);
|
errx(1, "Unable to load fixed ROMX section at $%lX into any bank", pSection->nOrg);
|
||||||
exit(1);
|
|
||||||
}
|
}
|
||||||
pSection->oAssigned = 1;
|
pSection->oAssigned = 1;
|
||||||
DOMAXBANK(pSection->nBank);
|
DOMAXBANK(pSection->nBank);
|
||||||
@@ -834,8 +804,7 @@ AssignSections(void)
|
|||||||
area_AllocAbsVRAMAnyBank(pSection->nOrg,
|
area_AllocAbsVRAMAnyBank(pSection->nOrg,
|
||||||
pSection->nByteSize)) ==
|
pSection->nByteSize)) ==
|
||||||
-1) {
|
-1) {
|
||||||
fprintf(stderr, "Unable to load fixed VRAM section at $%lX into any bank\n", pSection->nOrg);
|
errx(1, "Unable to load fixed VRAM section at $%lX into any bank", pSection->nOrg);
|
||||||
exit(1);
|
|
||||||
}
|
}
|
||||||
pSection->oAssigned = 1;
|
pSection->oAssigned = 1;
|
||||||
DOMAXVBANK(pSection->nBank);
|
DOMAXVBANK(pSection->nBank);
|
||||||
@@ -848,8 +817,7 @@ AssignSections(void)
|
|||||||
area_AllocAbsSRAMAnyBank(pSection->nOrg,
|
area_AllocAbsSRAMAnyBank(pSection->nOrg,
|
||||||
pSection->nByteSize)) ==
|
pSection->nByteSize)) ==
|
||||||
-1) {
|
-1) {
|
||||||
fprintf(stderr, "Unable to load fixed SRAM section at $%lX into any bank\n", pSection->nOrg);
|
errx(1, "Unable to load fixed SRAM section at $%lX into any bank", pSection->nOrg);
|
||||||
exit(1);
|
|
||||||
}
|
}
|
||||||
pSection->oAssigned = 1;
|
pSection->oAssigned = 1;
|
||||||
DOMAXSBANK(pSection->nBank);
|
DOMAXSBANK(pSection->nBank);
|
||||||
@@ -862,8 +830,7 @@ AssignSections(void)
|
|||||||
area_AllocAbsWRAMAnyBank(pSection->nOrg,
|
area_AllocAbsWRAMAnyBank(pSection->nOrg,
|
||||||
pSection->nByteSize)) ==
|
pSection->nByteSize)) ==
|
||||||
-1) {
|
-1) {
|
||||||
fprintf(stderr, "Unable to load fixed WRAMX section at $%lX into any bank\n", pSection->nOrg);
|
errx(1, "Unable to load fixed WRAMX section at $%lX into any bank", pSection->nOrg);
|
||||||
exit(1);
|
|
||||||
}
|
}
|
||||||
pSection->oAssigned = 1;
|
pSection->oAssigned = 1;
|
||||||
DOMAXWBANK(pSection->nBank);
|
DOMAXWBANK(pSection->nBank);
|
||||||
@@ -885,8 +852,7 @@ AssignSections(void)
|
|||||||
if ((pSection->nOrg =
|
if ((pSection->nOrg =
|
||||||
area_Alloc(&BankFree[BANK_WRAM0],
|
area_Alloc(&BankFree[BANK_WRAM0],
|
||||||
pSection->nByteSize)) == -1) {
|
pSection->nByteSize)) == -1) {
|
||||||
fprintf(stderr, "WRAM0 section too large\n");
|
errx(1, "WRAM0 section too large");
|
||||||
exit(1);
|
|
||||||
}
|
}
|
||||||
pSection->nBank = BANK_WRAM0;
|
pSection->nBank = BANK_WRAM0;
|
||||||
pSection->oAssigned = 1;
|
pSection->oAssigned = 1;
|
||||||
@@ -895,8 +861,7 @@ AssignSections(void)
|
|||||||
if ((pSection->nOrg =
|
if ((pSection->nOrg =
|
||||||
area_Alloc(&BankFree[BANK_HRAM],
|
area_Alloc(&BankFree[BANK_HRAM],
|
||||||
pSection->nByteSize)) == -1) {
|
pSection->nByteSize)) == -1) {
|
||||||
fprintf(stderr, "HRAM section too large\n");
|
errx(1, "HRAM section too large");
|
||||||
exit(1);
|
|
||||||
}
|
}
|
||||||
pSection->nBank = BANK_HRAM;
|
pSection->nBank = BANK_HRAM;
|
||||||
pSection->oAssigned = 1;
|
pSection->oAssigned = 1;
|
||||||
@@ -911,8 +876,7 @@ AssignSections(void)
|
|||||||
if ((pSection->nOrg =
|
if ((pSection->nOrg =
|
||||||
area_Alloc(&BankFree[BANK_ROM0],
|
area_Alloc(&BankFree[BANK_ROM0],
|
||||||
pSection->nByteSize)) == -1) {
|
pSection->nByteSize)) == -1) {
|
||||||
fprintf(stderr, "ROM0 section too large\n");
|
errx(1, "ROM0 section too large");
|
||||||
exit(1);
|
|
||||||
}
|
}
|
||||||
pSection->nBank = BANK_ROM0;
|
pSection->nBank = BANK_ROM0;
|
||||||
pSection->oAssigned = 1;
|
pSection->oAssigned = 1;
|
||||||
@@ -920,8 +884,7 @@ AssignSections(void)
|
|||||||
case SECT_ROMX:
|
case SECT_ROMX:
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
fprintf(stderr, "(INTERNAL) Unknown section type!\n");
|
errx(1, "(INTERNAL) Unknown section type!");
|
||||||
exit(1);
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,6 +2,7 @@
|
|||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
|
#include "extern/err.h"
|
||||||
#include "link/types.h"
|
#include "link/types.h"
|
||||||
#include "link/mylink.h"
|
#include "link/mylink.h"
|
||||||
#include "link/main.h"
|
#include "link/main.h"
|
||||||
@@ -91,9 +92,8 @@ AddNeededModules(void)
|
|||||||
}
|
}
|
||||||
if (options & OPT_SMART_C_LINK) {
|
if (options & OPT_SMART_C_LINK) {
|
||||||
if (!addmodulecontaining(smartlinkstartsymbol)) {
|
if (!addmodulecontaining(smartlinkstartsymbol)) {
|
||||||
fprintf(stderr, "Can't find start symbol '%s'\n",
|
errx(1, "Can't find start symbol '%s'",
|
||||||
smartlinkstartsymbol);
|
smartlinkstartsymbol);
|
||||||
exit(1);
|
|
||||||
} else
|
} else
|
||||||
printf("Smart linking with symbol '%s'\n",
|
printf("Smart linking with symbol '%s'\n",
|
||||||
smartlinkstartsymbol);
|
smartlinkstartsymbol);
|
||||||
|
|||||||
@@ -1,11 +1,9 @@
|
|||||||
#include <getopt.h>
|
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
|
|
||||||
#include "asmotor.h"
|
#include "extern/err.h"
|
||||||
|
|
||||||
#include "link/object.h"
|
#include "link/object.h"
|
||||||
#include "link/output.h"
|
#include "link/output.h"
|
||||||
#include "link/assign.h"
|
#include "link/assign.h"
|
||||||
@@ -34,11 +32,9 @@ char smartlinkstartsymbol[256];
|
|||||||
static void
|
static void
|
||||||
usage(void)
|
usage(void)
|
||||||
{
|
{
|
||||||
printf("RGBLink v" LINK_VERSION " (part of ASMotor " ASMOTOR_VERSION
|
printf(
|
||||||
")\n\n");
|
"usage: rgblink [-t] [-m mapfile] [-n symfile] [-o outfile] [-s symbol]\n"
|
||||||
printf("usage: rgblink [-t] [-l library] [-m mapfile] [-n symfile] [-o outfile]\n");
|
" [-z pad_value] file [...]\n");
|
||||||
printf("\t [-s symbol] [-z pad_value] objectfile [...]\n");
|
|
||||||
|
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -58,9 +54,6 @@ main(int argc, char *argv[])
|
|||||||
|
|
||||||
while ((ch = getopt(argc, argv, "l:m:n:o:p:s:t")) != -1) {
|
while ((ch = getopt(argc, argv, "l:m:n:o:p:s:t")) != -1) {
|
||||||
switch (ch) {
|
switch (ch) {
|
||||||
case 'l':
|
|
||||||
lib_Readfile(optarg);
|
|
||||||
break;
|
|
||||||
case 'm':
|
case 'm':
|
||||||
SetMapfileName(optarg);
|
SetMapfileName(optarg);
|
||||||
break;
|
break;
|
||||||
@@ -73,8 +66,7 @@ main(int argc, char *argv[])
|
|||||||
case 'p':
|
case 'p':
|
||||||
fillchar = strtoul(optarg, &ep, 0);
|
fillchar = strtoul(optarg, &ep, 0);
|
||||||
if (optarg[0] == '\0' || *ep != '\0') {
|
if (optarg[0] == '\0' || *ep != '\0') {
|
||||||
fprintf(stderr, "Invalid argument for option 'p'\n");
|
errx(1, "Invalid argument for option 'p'");
|
||||||
exit(1);
|
|
||||||
}
|
}
|
||||||
if (fillchar < 0 || fillchar > 0xFF) {
|
if (fillchar < 0 || fillchar > 0xFF) {
|
||||||
fprintf(stderr, "Argument for option 'p' must be between 0 and 0xFF");
|
fprintf(stderr, "Argument for option 'p' must be between 0 and 0xFF");
|
||||||
|
|||||||
@@ -3,8 +3,7 @@
|
|||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
#include "asmotor.h"
|
#include "extern/err.h"
|
||||||
|
|
||||||
#include "link/main.h"
|
#include "link/main.h"
|
||||||
#include "link/mylink.h"
|
#include "link/mylink.h"
|
||||||
#include "link/assign.h"
|
#include "link/assign.h"
|
||||||
@@ -20,9 +19,7 @@ SetMapfileName(char *name)
|
|||||||
mf = fopen(name, "w");
|
mf = fopen(name, "w");
|
||||||
|
|
||||||
if (mf == NULL) {
|
if (mf == NULL) {
|
||||||
fprintf(stderr, "Cannot open mapfile '%s': ", name);
|
err(1, "Cannot open mapfile '%s'", name);
|
||||||
perror(NULL);
|
|
||||||
exit(1);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -32,11 +29,10 @@ SetSymfileName(char *name)
|
|||||||
sf = fopen(name, "w");
|
sf = fopen(name, "w");
|
||||||
|
|
||||||
if (sf == NULL) {
|
if (sf == NULL) {
|
||||||
fprintf(stderr, "Cannot open symfile '%s'\n", name);
|
err(1, "Cannot open symfile '%s'", name);
|
||||||
exit(1);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fprintf(sf, ";File generated by xLink v" LINK_VERSION "\n\n");
|
fprintf(sf, ";File generated by rgblink\n\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
@@ -76,14 +72,13 @@ MapfileInitBank(SLONG bank)
|
|||||||
void
|
void
|
||||||
MapfileWriteSection(struct sSection * pSect)
|
MapfileWriteSection(struct sSection * pSect)
|
||||||
{
|
{
|
||||||
if (!mf && !sf)
|
|
||||||
return;
|
|
||||||
|
|
||||||
SLONG i;
|
SLONG i;
|
||||||
|
|
||||||
|
if (mf) {
|
||||||
fprintf(mf, " SECTION: $%04lX-$%04lX ($%04lX bytes)\n",
|
fprintf(mf, " SECTION: $%04lX-$%04lX ($%04lX bytes)\n",
|
||||||
pSect->nOrg, pSect->nOrg + pSect->nByteSize - 1,
|
pSect->nOrg, pSect->nOrg + pSect->nByteSize - 1,
|
||||||
pSect->nByteSize);
|
pSect->nByteSize);
|
||||||
|
}
|
||||||
|
|
||||||
for (i = 0; i < pSect->nNumberOfSymbols; i += 1) {
|
for (i = 0; i < pSect->nNumberOfSymbols; i += 1) {
|
||||||
struct sSymbol *pSym;
|
struct sSymbol *pSym;
|
||||||
|
|||||||
@@ -8,6 +8,7 @@
|
|||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
|
#include "extern/err.h"
|
||||||
#include "link/mylink.h"
|
#include "link/mylink.h"
|
||||||
#include "link/main.h"
|
#include "link/main.h"
|
||||||
|
|
||||||
@@ -80,8 +81,7 @@ AllocSection(void)
|
|||||||
|
|
||||||
*ppSections = malloc(sizeof **ppSections);
|
*ppSections = malloc(sizeof **ppSections);
|
||||||
if (!*ppSections) {
|
if (!*ppSections) {
|
||||||
fprintf(stderr, "Out of memory!\n");
|
err(1, NULL);
|
||||||
exit(1);
|
|
||||||
}
|
}
|
||||||
(*ppSections)->tSymbols = tSymbols;
|
(*ppSections)->tSymbols = tSymbols;
|
||||||
(*ppSections)->pNext = NULL;
|
(*ppSections)->pNext = NULL;
|
||||||
@@ -102,15 +102,13 @@ obj_ReadSymbol(FILE * f)
|
|||||||
|
|
||||||
pSym = malloc(sizeof *pSym);
|
pSym = malloc(sizeof *pSym);
|
||||||
if (!pSym) {
|
if (!pSym) {
|
||||||
fprintf(stderr, "Out of memory!\n");
|
err(1, NULL);
|
||||||
exit(1);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
readasciiz(s, f);
|
readasciiz(s, f);
|
||||||
pSym->pzName = malloc(strlen(s) + 1);
|
pSym->pzName = malloc(strlen(s) + 1);
|
||||||
if (!pSym->pzName) {
|
if (!pSym->pzName) {
|
||||||
fprintf(stderr, "Out of memory!\n");
|
err(1, NULL);
|
||||||
exit(1);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
strcpy(pSym->pzName, s);
|
strcpy(pSym->pzName, s);
|
||||||
@@ -150,7 +148,7 @@ obj_ReadRGB0Section(FILE * f)
|
|||||||
if (pSection->nByteSize) {
|
if (pSection->nByteSize) {
|
||||||
pSection->pData = malloc(pSection->nByteSize);
|
pSection->pData = malloc(pSection->nByteSize);
|
||||||
if (!pSection->pData) {
|
if (!pSection->pData) {
|
||||||
fprintf(stderr, "Out of memory!\n");
|
err(1, NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
SLONG nNumberOfPatches;
|
SLONG nNumberOfPatches;
|
||||||
@@ -169,7 +167,7 @@ obj_ReadRGB0Section(FILE * f)
|
|||||||
while (nNumberOfPatches--) {
|
while (nNumberOfPatches--) {
|
||||||
pPatch = malloc(sizeof *pPatch);
|
pPatch = malloc(sizeof *pPatch);
|
||||||
if (!pPatch) {
|
if (!pPatch) {
|
||||||
fprintf(stderr, "Out of memory!\n");
|
err(1, NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
*ppPatch = pPatch;
|
*ppPatch = pPatch;
|
||||||
@@ -177,7 +175,7 @@ obj_ReadRGB0Section(FILE * f)
|
|||||||
|
|
||||||
pPatch->pzFilename = malloc(strlen(s) + 1);
|
pPatch->pzFilename = malloc(strlen(s) + 1);
|
||||||
if (!pPatch->pzFilename) {
|
if (!pPatch->pzFilename) {
|
||||||
fprintf(stderr, "Out of memory!\n");
|
err(1, NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
strcpy(pPatch->pzFilename, s);
|
strcpy(pPatch->pzFilename, s);
|
||||||
@@ -193,8 +191,7 @@ obj_ReadRGB0Section(FILE * f)
|
|||||||
if ((pPatch->nRPNSize = readlong(f)) > 0) {
|
if ((pPatch->nRPNSize = readlong(f)) > 0) {
|
||||||
pPatch->pRPN = malloc(pPatch->nRPNSize);
|
pPatch->pRPN = malloc(pPatch->nRPNSize);
|
||||||
if (!pPatch->pRPN) {
|
if (!pPatch->pRPN) {
|
||||||
fprintf(stderr, "Out of memory!\n");
|
err(1, NULL);
|
||||||
exit(1);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fread(pPatch->pRPN, sizeof(UBYTE),
|
fread(pPatch->pRPN, sizeof(UBYTE),
|
||||||
@@ -228,8 +225,7 @@ obj_ReadRGB0(FILE * pObjfile)
|
|||||||
if (nNumberOfSymbols) {
|
if (nNumberOfSymbols) {
|
||||||
tSymbols = malloc(nNumberOfSymbols * sizeof(struct sSymbol *));
|
tSymbols = malloc(nNumberOfSymbols * sizeof(struct sSymbol *));
|
||||||
if (!tSymbols) {
|
if (!tSymbols) {
|
||||||
fprintf(stderr, "Out of memory!\n");
|
err(1, NULL);
|
||||||
exit(1);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
for (i = 0; i < nNumberOfSymbols; i += 1)
|
for (i = 0; i < nNumberOfSymbols; i += 1)
|
||||||
@@ -305,8 +301,7 @@ obj_ReadRGB1Section(FILE * f)
|
|||||||
if (pSection->nByteSize) {
|
if (pSection->nByteSize) {
|
||||||
pSection->pData = malloc(pSection->nByteSize);
|
pSection->pData = malloc(pSection->nByteSize);
|
||||||
if (!pSection->pData) {
|
if (!pSection->pData) {
|
||||||
fprintf(stderr, "Out of memory!\n");
|
err(1, NULL);
|
||||||
exit(1);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
SLONG nNumberOfPatches;
|
SLONG nNumberOfPatches;
|
||||||
@@ -325,14 +320,14 @@ obj_ReadRGB1Section(FILE * f)
|
|||||||
while (nNumberOfPatches--) {
|
while (nNumberOfPatches--) {
|
||||||
pPatch = malloc(sizeof *pPatch);
|
pPatch = malloc(sizeof *pPatch);
|
||||||
if (!pPatch) {
|
if (!pPatch) {
|
||||||
fprintf(stderr, "Out of memory!\n");
|
err(1, NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
*ppPatch = pPatch;
|
*ppPatch = pPatch;
|
||||||
readasciiz(s, f);
|
readasciiz(s, f);
|
||||||
pPatch->pzFilename = malloc(strlen(s) + 1);
|
pPatch->pzFilename = malloc(strlen(s) + 1);
|
||||||
if (!pPatch->pzFilename) {
|
if (!pPatch->pzFilename) {
|
||||||
fprintf(stderr, "Out of memory!\n");
|
err(1, NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
strcpy(pPatch->pzFilename, s);
|
strcpy(pPatch->pzFilename, s);
|
||||||
@@ -342,7 +337,7 @@ obj_ReadRGB1Section(FILE * f)
|
|||||||
if ((pPatch->nRPNSize = readlong(f)) > 0) {
|
if ((pPatch->nRPNSize = readlong(f)) > 0) {
|
||||||
pPatch->pRPN = malloc(pPatch->nRPNSize);
|
pPatch->pRPN = malloc(pPatch->nRPNSize);
|
||||||
if (!pPatch->pRPN) {
|
if (!pPatch->pRPN) {
|
||||||
fprintf(stderr, "Out of memory!\n");
|
err(1, NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
fread(pPatch->pRPN, sizeof(UBYTE),
|
fread(pPatch->pRPN, sizeof(UBYTE),
|
||||||
@@ -376,7 +371,7 @@ obj_ReadRGB1(FILE * pObjfile)
|
|||||||
if (nNumberOfSymbols) {
|
if (nNumberOfSymbols) {
|
||||||
tSymbols = malloc(nNumberOfSymbols * sizeof *tSymbols);
|
tSymbols = malloc(nNumberOfSymbols * sizeof *tSymbols);
|
||||||
if (!tSymbols) {
|
if (!tSymbols) {
|
||||||
fprintf(stderr, "Out of memory!\n");
|
err(1, NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
for (i = 0; i < nNumberOfSymbols; i += 1)
|
for (i = 0; i < nNumberOfSymbols; i += 1)
|
||||||
@@ -440,14 +435,10 @@ obj_ReadOpenFile(FILE * pObjfile, char *tzObjectfile)
|
|||||||
obj_ReadRGB1(pObjfile);
|
obj_ReadRGB1(pObjfile);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
fprintf(stderr, "'%s' is an unsupported version",
|
errx(1, "'%s' is an unsupported version", tzObjectfile);
|
||||||
tzObjectfile);
|
|
||||||
exit(1);
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
fprintf(stderr, "'%s' is not a valid object\n", tzObjectfile);
|
errx(1, "'%s' is not a valid object", tzObjectfile);
|
||||||
exit(1);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -463,10 +454,7 @@ obj_Readfile(char *tzObjectfile)
|
|||||||
|
|
||||||
pObjfile = fopen(tzObjectfile, "rb");
|
pObjfile = fopen(tzObjectfile, "rb");
|
||||||
if (pObjfile == NULL) {
|
if (pObjfile == NULL) {
|
||||||
fprintf(stderr, "Unable to open object '%s': ",
|
err(1, "Unable to open object '%s'", tzObjectfile);
|
||||||
tzObjectfile);
|
|
||||||
perror(NULL);
|
|
||||||
exit(1);
|
|
||||||
}
|
}
|
||||||
obj_ReadOpenFile(pObjfile, tzObjectfile);
|
obj_ReadOpenFile(pObjfile, tzObjectfile);
|
||||||
fclose(pObjfile);
|
fclose(pObjfile);
|
||||||
@@ -506,34 +494,3 @@ lib_ReadXLB0(FILE * f)
|
|||||||
obj_ReadOpenFile(f, name);
|
obj_ReadOpenFile(f, name);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
|
||||||
lib_Readfile(char *tzLibfile)
|
|
||||||
{
|
|
||||||
FILE *pObjfile;
|
|
||||||
|
|
||||||
oReadLib = 1;
|
|
||||||
|
|
||||||
pObjfile = fopen(tzLibfile, "rb");
|
|
||||||
if (pObjfile == NULL) {
|
|
||||||
fprintf(stderr, "Unable to open object '%s': ", tzLibfile);
|
|
||||||
perror(NULL);
|
|
||||||
exit(1);
|
|
||||||
}
|
|
||||||
if (!pObjfile) {
|
|
||||||
fprintf(stderr, "Unable to open '%s'\n", tzLibfile);
|
|
||||||
exit(1);
|
|
||||||
}
|
|
||||||
char tzHeader[5];
|
|
||||||
|
|
||||||
fread(tzHeader, sizeof(char), 4, pObjfile);
|
|
||||||
tzHeader[4] = 0;
|
|
||||||
if (strcmp(tzHeader, "XLB0") == 0)
|
|
||||||
lib_ReadXLB0(pObjfile);
|
|
||||||
else {
|
|
||||||
fprintf(stderr, "'%s' is an invalid library\n",
|
|
||||||
tzLibfile);
|
|
||||||
exit(1);
|
|
||||||
}
|
|
||||||
fclose(pObjfile);
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -7,8 +7,7 @@
|
|||||||
#include "link/main.h"
|
#include "link/main.h"
|
||||||
#include "link/assign.h"
|
#include "link/assign.h"
|
||||||
|
|
||||||
char tzOutname[_MAX_PATH];
|
char *tzOutname;
|
||||||
BBOOL oOutput = 0;
|
|
||||||
|
|
||||||
void
|
void
|
||||||
writehome(FILE * f)
|
writehome(FILE * f)
|
||||||
@@ -71,8 +70,7 @@ writebank(FILE * f, SLONG bank)
|
|||||||
void
|
void
|
||||||
out_Setname(char *tzOutputfile)
|
out_Setname(char *tzOutputfile)
|
||||||
{
|
{
|
||||||
strcpy(tzOutname, tzOutputfile);
|
tzOutname = tzOutputfile;
|
||||||
oOutput = 1;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
|
|||||||
@@ -2,6 +2,7 @@
|
|||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
|
#include "extern/err.h"
|
||||||
#include "link/mylink.h"
|
#include "link/mylink.h"
|
||||||
#include "link/symbol.h"
|
#include "link/symbol.h"
|
||||||
#include "link/main.h"
|
#include "link/main.h"
|
||||||
@@ -46,8 +47,7 @@ getsymvalue(SLONG symid)
|
|||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
fprintf(stderr, "*INTERNAL* UNKNOWN SYMBOL TYPE\n");
|
errx(1, "*INTERNAL* UNKNOWN SYMBOL TYPE");
|
||||||
exit(1);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
SLONG
|
SLONG
|
||||||
@@ -64,8 +64,7 @@ getsymbank(SLONG symid)
|
|||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
fprintf(stderr, "*INTERNAL* UNKNOWN SYMBOL TYPE\n");
|
errx(1, "*INTERNAL* UNKNOWN SYMBOL TYPE");
|
||||||
exit(1);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
SLONG
|
SLONG
|
||||||
@@ -159,20 +158,18 @@ calcrpn(struct sPatch * pPatch)
|
|||||||
t = rpnpop();
|
t = rpnpop();
|
||||||
rpnpush(t & 0xFF);
|
rpnpush(t & 0xFF);
|
||||||
if (t < 0 || (t > 0xFF && t < 0xFF00) || t > 0xFFFF) {
|
if (t < 0 || (t > 0xFF && t < 0xFF00) || t > 0xFFFF) {
|
||||||
fprintf(stderr,
|
errx(1,
|
||||||
"%s(%ld) : Value must be in the HRAM area\n",
|
"%s(%ld) : Value must be in the HRAM area",
|
||||||
pPatch->pzFilename, pPatch->nLineNo);
|
pPatch->pzFilename, pPatch->nLineNo);
|
||||||
exit(1);
|
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case RPN_PCEZP:
|
case RPN_PCEZP:
|
||||||
t = rpnpop();
|
t = rpnpop();
|
||||||
rpnpush(t & 0xFF);
|
rpnpush(t & 0xFF);
|
||||||
if (t < 0x2000 || t > 0x20FF) {
|
if (t < 0x2000 || t > 0x20FF) {
|
||||||
fprintf(stderr,
|
errx(1,
|
||||||
"%s(%ld) : Value must be in the ZP area\n",
|
"%s(%ld) : Value must be in the ZP area",
|
||||||
pPatch->pzFilename, pPatch->nLineNo);
|
pPatch->pzFilename, pPatch->nLineNo);
|
||||||
exit(1);
|
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case RPN_CONST:
|
case RPN_CONST:
|
||||||
@@ -217,11 +214,10 @@ calcrpn(struct sPatch * pPatch)
|
|||||||
high |= (*rpn++) << 24;
|
high |= (*rpn++) << 24;
|
||||||
t = rpnpop();
|
t = rpnpop();
|
||||||
if (t < low || t > high) {
|
if (t < low || t > high) {
|
||||||
fprintf(stderr,
|
errx(1,
|
||||||
"%s(%ld) : Value must be in the range [%ld;%ld]\n",
|
"%s(%ld) : Value must be in the range [%ld;%ld]",
|
||||||
pPatch->pzFilename,
|
pPatch->pzFilename,
|
||||||
pPatch->nLineNo, low, high);
|
pPatch->nLineNo, low, high);
|
||||||
exit(1);
|
|
||||||
}
|
}
|
||||||
rpnpush(t);
|
rpnpush(t);
|
||||||
size -= 8;
|
size -= 8;
|
||||||
@@ -255,11 +251,10 @@ Patch(void)
|
|||||||
pSect->pData[pPatch->nOffset] =
|
pSect->pData[pPatch->nOffset] =
|
||||||
(UBYTE) t;
|
(UBYTE) t;
|
||||||
} else {
|
} else {
|
||||||
fprintf(stderr,
|
errx(1,
|
||||||
"%s(%ld) : Value must be 8-bit\n",
|
"%s(%ld) : Value must be 8-bit",
|
||||||
pPatch->pzFilename,
|
pPatch->pzFilename,
|
||||||
pPatch->nLineNo);
|
pPatch->nLineNo);
|
||||||
exit(1);
|
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case PATCH_WORD_L:
|
case PATCH_WORD_L:
|
||||||
@@ -280,11 +275,10 @@ Patch(void)
|
|||||||
1] = t & 0xFF;
|
1] = t & 0xFF;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
fprintf(stderr,
|
errx(1,
|
||||||
"%s(%ld) : Value must be 16-bit\n",
|
"%s(%ld) : Value must be 16-bit",
|
||||||
pPatch->pzFilename,
|
pPatch->pzFilename,
|
||||||
pPatch->nLineNo);
|
pPatch->nLineNo);
|
||||||
exit(1);
|
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case PATCH_LONG_L:
|
case PATCH_LONG_L:
|
||||||
|
|||||||
@@ -29,12 +29,6 @@ option to override this.
|
|||||||
.Pp
|
.Pp
|
||||||
The arguments are as follows:
|
The arguments are as follows:
|
||||||
.Bl -tag -width Ds
|
.Bl -tag -width Ds
|
||||||
.It Fl l Ar library
|
|
||||||
Include a referenced library module created with
|
|
||||||
.Xr rgblib 1 .
|
|
||||||
Note that specified libraries will be included only if needed\(emthat is, if
|
|
||||||
a SECTION from a library is referenced by an object file.
|
|
||||||
Only the relevant SECTION will be included, rather than the entire module.
|
|
||||||
.It Fl m Ar mapfile
|
.It Fl m Ar mapfile
|
||||||
Write a mapfile to the given filename.
|
Write a mapfile to the given filename.
|
||||||
.It Fl n Ar symfile
|
.It Fl n Ar symfile
|
||||||
@@ -70,7 +64,6 @@ to fix these so that the program will actually run in a Game Boy:
|
|||||||
.Xr rgbds 7 ,
|
.Xr rgbds 7 ,
|
||||||
.Xr rgbasm 1 ,
|
.Xr rgbasm 1 ,
|
||||||
.Xr rgbfix 1 ,
|
.Xr rgbfix 1 ,
|
||||||
.Xr rgblib 1 ,
|
|
||||||
.Xr gbz80 7
|
.Xr gbz80 7
|
||||||
.Sh HISTORY
|
.Sh HISTORY
|
||||||
.Nm
|
.Nm
|
||||||
|
|||||||
@@ -2,6 +2,7 @@
|
|||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
|
#include "extern/err.h"
|
||||||
#include "link/main.h"
|
#include "link/main.h"
|
||||||
#include "link/patch.h"
|
#include "link/patch.h"
|
||||||
#include "link/types.h"
|
#include "link/types.h"
|
||||||
@@ -53,8 +54,7 @@ sym_GetValue(char *tzName)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fprintf(stderr, "Unknown symbol '%s'\n", tzName);
|
errx(1, "Unknown symbol '%s'", tzName);
|
||||||
exit(1);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -72,8 +72,7 @@ sym_GetBank(char *tzName)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fprintf(stderr, "Unknown symbol '%s'\n", tzName);
|
errx(1, "Unknown symbol '%s'", tzName);
|
||||||
exit(1);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
@@ -93,10 +92,7 @@ sym_CreateSymbol(char *tzName, SLONG nValue, SBYTE nBank)
|
|||||||
if (nBank == -1)
|
if (nBank == -1)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
fprintf(stderr,
|
errx(1, "Symbol '%s' defined more than once", tzName);
|
||||||
"Symbol '%s' defined more than once\n",
|
|
||||||
tzName);
|
|
||||||
exit(1);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -13,7 +13,6 @@ To get a working ROM image from a single assembly source file:
|
|||||||
.Sh SEE ALSO
|
.Sh SEE ALSO
|
||||||
.Xr rgbasm 1 ,
|
.Xr rgbasm 1 ,
|
||||||
.Xr rgbfix 1 ,
|
.Xr rgbfix 1 ,
|
||||||
.Xr rgblib 1 ,
|
|
||||||
.Xr rgblink 1 ,
|
.Xr rgblink 1 ,
|
||||||
.Xr gbz80 7
|
.Xr gbz80 7
|
||||||
.Sh HISTORY
|
.Sh HISTORY
|
||||||
|
|||||||
Reference in New Issue
Block a user