mirror of
https://github.com/gbdev/rgbds.git
synced 2025-11-21 02:32:06 +00:00
Compare commits
25 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
6c10ca62ad | ||
|
|
49809f6caf | ||
|
|
81675bc4c7 | ||
|
|
37b615f070 | ||
|
|
6438ae2591 | ||
|
|
33ae6d8ca3 | ||
|
|
ebc9a4b786 | ||
|
|
e195076793 | ||
|
|
b14beeff10 | ||
|
|
db54c2ebd6 | ||
|
|
eadaa47770 | ||
|
|
b5e7855afd | ||
|
|
ce7d1d5d49 | ||
|
|
64a3929f4e | ||
|
|
1c1a4e6ac9 | ||
|
|
cc3aa969b8 | ||
|
|
7055301616 | ||
|
|
bbf24916e6 | ||
|
|
261503c7c8 | ||
|
|
b924f58bb0 | ||
|
|
ac78c37f9d | ||
|
|
c8d9ae21e6 | ||
|
|
5281704f62 | ||
|
|
fd4327327c | ||
|
|
bbf60c7197 |
2
Makefile
2
Makefile
@@ -23,6 +23,7 @@ rgbasm_obj = \
|
||||
src/asm/symbol.o \
|
||||
src/asm/locallex.o \
|
||||
src/extern/err.o \
|
||||
src/extern/reallocarray.o \
|
||||
src/extern/strlcpy.o \
|
||||
src/extern/strlcat.o
|
||||
|
||||
@@ -86,7 +87,6 @@ src/asm/asmy.h: src/asm/asmy.c
|
||||
mingw:
|
||||
$Qenv PATH=/usr/local/mingw32/bin:/bin:/usr/bin:/usr/local/bin \
|
||||
make WARNFLAGS= CC=gcc CFLAGS="-I/usr/local/mingw32/include \
|
||||
-D__progname=\\\"\\\" \
|
||||
${CFLAGS}"
|
||||
$Qmv rgbasm rgbasm.exe
|
||||
$Qmv rgblink rgblink.exe
|
||||
|
||||
@@ -6,17 +6,17 @@
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef ASMOTOR_ASM_ASM_H
|
||||
#define ASMOTOR_ASM_ASM_H
|
||||
#ifndef RGBDS_ASM_ASM_H
|
||||
#define RGBDS_ASM_ASM_H
|
||||
|
||||
#include <stdbool.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#include "asm/types.h"
|
||||
#include "types.h"
|
||||
#include "asm/symbol.h"
|
||||
|
||||
#include "localasm.h"
|
||||
#include "asm/localasm.h"
|
||||
|
||||
extern SLONG nLineNo;
|
||||
extern ULONG nTotalLines;
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
#ifndef ASMOTOR_ASM_CHARMAP_H
|
||||
#define ASMOTOR_ASM_CHARMAP_H
|
||||
#ifndef RGBDS_ASM_CHARMAP_H
|
||||
#define RGBDS_ASM_CHARMAP_H
|
||||
|
||||
#define MAXCHARMAPS 512
|
||||
#define CHARMAPLENGTH 8
|
||||
|
||||
@@ -6,13 +6,13 @@
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef ASMOTOR_ASM_FSTACK_H
|
||||
#define ASMOTOR_ASM_FSTACK_H
|
||||
#ifndef RGBDS_ASM_FSTACK_H
|
||||
#define RGBDS_ASM_FSTACK_H
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
#include "asm/asm.h"
|
||||
#include "asm/types.h"
|
||||
#include "types.h"
|
||||
#include "asm/lexer.h"
|
||||
|
||||
struct sContext {
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
#ifndef ASMOTOR_ASM_LEXER_H
|
||||
#define ASMOTOR_ASM_LEXER_H
|
||||
#ifndef RGBDS_ASM_LEXER_H
|
||||
#define RGBDS_ASM_LEXER_H
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
#include "asm/types.h"
|
||||
#include "types.h"
|
||||
|
||||
#define LEXHASHSIZE (1 << 11)
|
||||
#define MAXSTRLEN 255
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
#ifndef ASMOTOR_MAIN_H
|
||||
#define ASMOTOR_MAIN_H
|
||||
#ifndef RGBDS_MAIN_H
|
||||
#define RGBDS_MAIN_H
|
||||
|
||||
#include <stdbool.h>
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
#ifndef ASMOTOR_ASM_LINK_H
|
||||
#define ASMOTOR_ASM_LINK_H
|
||||
#ifndef RGBDS_ASM_LINK_H
|
||||
#define RGBDS_ASM_LINK_H
|
||||
|
||||
/* RGB0 .obj format:
|
||||
*
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
#ifndef ASMOTOR_ASM_MATH_H
|
||||
#define ASMOTOR_ASM_MATH_H
|
||||
#ifndef RGBDS_ASM_MATH_H
|
||||
#define RGBDS_ASM_MATH_H
|
||||
|
||||
#include "asm/types.h"
|
||||
#include "types.h"
|
||||
|
||||
void math_DefinePI(void);
|
||||
void math_Print(SLONG i);
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
#ifndef ASMOTOR_ASM_OUTPUT_H
|
||||
#define ASMOTOR_ASM_OUTPUT_H
|
||||
#ifndef RGBDS_ASM_OUTPUT_H
|
||||
#define RGBDS_ASM_OUTPUT_H
|
||||
|
||||
#include "asm/rpn.h"
|
||||
#include "asm/types.h"
|
||||
#include "types.h"
|
||||
|
||||
struct Section {
|
||||
char *pzName;
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
#ifndef ASMOTOR_ASM_RPN_H
|
||||
#define ASMOTOR_ASM_RPN_H
|
||||
#ifndef RGBDS_ASM_RPN_H
|
||||
#define RGBDS_ASM_RPN_H
|
||||
|
||||
struct Expression {
|
||||
SLONG nVal;
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
#ifndef ASMOTOR_SYMBOL_H
|
||||
#define ASMOTOR_SYMBOL_H
|
||||
#ifndef RGBDS_SYMBOL_H
|
||||
#define RGBDS_SYMBOL_H
|
||||
|
||||
#include "asm/types.h"
|
||||
#include "types.h"
|
||||
|
||||
#define HASHSIZE (1 << 16)
|
||||
#define MAXSYMLEN 256
|
||||
|
||||
@@ -1,15 +0,0 @@
|
||||
#ifndef ASMOTOR_ASM_TYPES_H
|
||||
#define ASMOTOR_ASM_TYPES_H
|
||||
|
||||
#ifndef _MAX_PATH
|
||||
#define _MAX_PATH 512
|
||||
#endif
|
||||
|
||||
typedef unsigned char UBYTE;
|
||||
typedef signed char SBYTE;
|
||||
typedef unsigned short UWORD;
|
||||
typedef signed short SWORD;
|
||||
typedef unsigned long ULONG;
|
||||
typedef signed long SLONG;
|
||||
|
||||
#endif
|
||||
33
include/extern/err.h
vendored
33
include/extern/err.h
vendored
@@ -1,26 +1,3 @@
|
||||
/*
|
||||
* 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
|
||||
|
||||
@@ -29,7 +6,7 @@
|
||||
#else
|
||||
|
||||
#include <stdarg.h>
|
||||
#include "stdnoreturn.h"
|
||||
#include "extern/stdnoreturn.h"
|
||||
|
||||
#define warn rgbds_warn
|
||||
#define vwarn rgbds_vwarn
|
||||
@@ -41,10 +18,6 @@
|
||||
#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 *, ...);
|
||||
@@ -55,10 +28,6 @@ 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
|
||||
|
||||
6
include/extern/reallocarray.h
vendored
6
include/extern/reallocarray.h
vendored
@@ -1,10 +1,14 @@
|
||||
#ifndef EXTERN_REALLOCARRAY_H
|
||||
#define EXTERN_REALLOCARRAY_H
|
||||
|
||||
#ifdef REALLOCARRAY_IN_LIBC
|
||||
#include <stdlib.h>
|
||||
#else
|
||||
|
||||
#ifndef REALLOCARRAY_IN_LIBC
|
||||
#define reallocarray rgbds_reallocarray
|
||||
|
||||
void *reallocarray(void *, size_t, size_t);
|
||||
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
10
include/extern/stdnoreturn.h
vendored
10
include/extern/stdnoreturn.h
vendored
@@ -1,16 +1,16 @@
|
||||
#if __STDC_VERSION__ >= 201112L
|
||||
// C11 or newer
|
||||
/* C11 or newer */
|
||||
#define noreturn _Noreturn
|
||||
#elif __cplusplus >= 201103L
|
||||
// C++11 or newer
|
||||
/* C++11 or newer */
|
||||
#define noreturn [[noreturn]]
|
||||
#elif __GNUC__ > 2 || (__GNUC__ == 2 && (__GNUC_MINOR__ >= 5))
|
||||
// GCC 2.5 or newer
|
||||
/* GCC 2.5 or newer */
|
||||
#define noreturn __attribute__ ((noreturn))
|
||||
#elif _MSC_VER >= 1310
|
||||
// MS Visual Studio 2003/.NET Framework 1.1 or newer
|
||||
/* MS Visual Studio 2003/.NET Framework 1.1 or newer */
|
||||
#define noreturn _declspec( noreturn)
|
||||
#else
|
||||
// unsupported, but no need to throw a fit
|
||||
/* unsupported, but no need to throw a fit */
|
||||
#define noreturn
|
||||
#endif
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
#ifndef ASMOTOR_LINK_ASSIGN_H
|
||||
#define ASMOTOR_LINK_ASSIGN_H
|
||||
#ifndef RGBDS_LINK_ASSIGN_H
|
||||
#define RGBDS_LINK_ASSIGN_H
|
||||
|
||||
#include "link/types.h"
|
||||
#include "types.h"
|
||||
|
||||
enum eBankDefine {
|
||||
BANK_ROM0 = 0,
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
#ifndef ASMOTOR_LINK_LIBRARY_H
|
||||
#define ASMOTOR_LINK_LIBRARY_H
|
||||
#ifndef RGBDS_LINK_LIBRARY_H
|
||||
#define RGBDS_LINK_LIBRARY_H
|
||||
|
||||
extern void AddNeededModules(void);
|
||||
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
#ifndef ASMOTOR_LINK_MAIN_H
|
||||
#define ASMOTOR_LINK_MAIN_H
|
||||
#ifndef RGBDS_LINK_MAIN_H
|
||||
#define RGBDS_LINK_MAIN_H
|
||||
|
||||
#include "link/types.h"
|
||||
#include "types.h"
|
||||
|
||||
extern SLONG fillchar;
|
||||
extern char smartlinkstartsymbol[256];
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
#ifndef ASMOTOR_LINK_MAPFILE_H
|
||||
#define ASMOTOR_LINK_MAPFILE_H
|
||||
#ifndef RGBDS_LINK_MAPFILE_H
|
||||
#define RGBDS_LINK_MAPFILE_H
|
||||
|
||||
extern void SetMapfileName(char *name);
|
||||
extern void SetSymfileName(char *name);
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
#ifndef ASMOTOR_LINK_LINK_H
|
||||
#define ASMOTOR_LINK_LINK_H
|
||||
#ifndef RGBDS_LINK_LINK_H
|
||||
#define RGBDS_LINK_LINK_H
|
||||
|
||||
#ifndef _MAX_PATH
|
||||
#define _MAX_PATH 512
|
||||
#endif
|
||||
|
||||
#include "link/types.h"
|
||||
#include "types.h"
|
||||
|
||||
extern SLONG options;
|
||||
#define OPT_SMALL 0x01
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
#ifndef ASMOTOR_LINK_OBJECT_H
|
||||
#define ASMOTOR_LINK_OBJECT_H
|
||||
#ifndef RGBDS_LINK_OBJECT_H
|
||||
#define RGBDS_LINK_OBJECT_H
|
||||
|
||||
extern void obj_Readfile(char *tzObjectfile);
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
#ifndef ASMOTOR_LINK_OUTPUT_H
|
||||
#define ASMOTOR_LINK_OUTPUT_H
|
||||
#ifndef RGBDS_LINK_OUTPUT_H
|
||||
#define RGBDS_LINK_OUTPUT_H
|
||||
|
||||
void out_Setname(char *tzOutputfile);
|
||||
void Output(void);
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
#ifndef ASMOTOR_LINK_PATCH_H
|
||||
#define ASMOTOR_LINK_PATCH_H
|
||||
#ifndef RGBDS_LINK_PATCH_H
|
||||
#define RGBDS_LINK_PATCH_H
|
||||
|
||||
#include "link/types.h"
|
||||
#include "types.h"
|
||||
|
||||
void Patch(void);
|
||||
extern SLONG nPC;
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
#ifndef ASMOTOR_LINK_SYMBOL_H
|
||||
#define ASMOTOR_LINK_SYMBOL_H
|
||||
#ifndef RGBDS_LINK_SYMBOL_H
|
||||
#define RGBDS_LINK_SYMBOL_H
|
||||
|
||||
#include "link/types.h"
|
||||
#include "types.h"
|
||||
|
||||
void sym_Init(void);
|
||||
void sym_CreateSymbol(char *tzName, SLONG nValue, SBYTE nBank);
|
||||
void sym_CreateSymbol(char *tzName, SLONG nValue, SLONG nBank);
|
||||
SLONG sym_GetValue(char *tzName);
|
||||
SLONG sym_GetBank(char *tzName);
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
#ifndef ASMOTOR_LINK_TYPES_H
|
||||
#define ASMOTOR_LINK_TYPES_H
|
||||
#ifndef RGBDS_TYPES_H
|
||||
#define RGBDS_TYPES_H
|
||||
|
||||
#ifndef _MAX_PATH
|
||||
#define _MAX_PATH 512
|
||||
@@ -497,22 +497,16 @@ void if_skip_to_endc( void )
|
||||
|
||||
%%
|
||||
|
||||
asmfile : lines lastline;
|
||||
|
||||
lastline : /* empty */
|
||||
| line {
|
||||
nLineNo += 1;
|
||||
nTotalLines += 1;
|
||||
};
|
||||
asmfile : lines;
|
||||
|
||||
/* Note: The lexer add '\n' at the end of the input */
|
||||
lines : /* empty */
|
||||
| lines line '\n' {
|
||||
nLineNo += 1;
|
||||
nTotalLines += 1;
|
||||
};
|
||||
|
||||
line : /* empty */
|
||||
| label
|
||||
line : label
|
||||
| label cpu_command
|
||||
| label macro
|
||||
| label simple_pseudoop
|
||||
|
||||
@@ -10,7 +10,7 @@
|
||||
|
||||
#include "asm/symbol.h"
|
||||
#include "asm/fstack.h"
|
||||
#include "asm/types.h"
|
||||
#include "types.h"
|
||||
#include "asm/main.h"
|
||||
#include "asm/lexer.h"
|
||||
#include "extern/err.h"
|
||||
|
||||
@@ -161,7 +161,7 @@ ParseSymbol(char *src, ULONG size)
|
||||
if (*src == '@')
|
||||
marg = sym_FindMacroArg(-1);
|
||||
else if (*src >= '0' && *src <= '9')
|
||||
marg = sym_FindMacroArg(*src);
|
||||
marg = sym_FindMacroArg(*src - '0');
|
||||
else {
|
||||
fatalerror("Malformed ID");
|
||||
return (0);
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
|
||||
#include "asm/asm.h"
|
||||
#include "asm/lexer.h"
|
||||
#include "asm/types.h"
|
||||
#include "types.h"
|
||||
#include "asm/main.h"
|
||||
#include "asm/rpn.h"
|
||||
#include "asm/fstack.h"
|
||||
|
||||
@@ -11,10 +11,17 @@
|
||||
#include "asm/output.h"
|
||||
#include "asm/main.h"
|
||||
#include "extern/err.h"
|
||||
#include "extern/reallocarray.h"
|
||||
|
||||
int yyparse(void);
|
||||
void setuplex(void);
|
||||
|
||||
int cldefines_index;
|
||||
int cldefines_size;
|
||||
char **cldefines;
|
||||
|
||||
char *progname;
|
||||
|
||||
clock_t nStartClock, nEndClock;
|
||||
SLONG nLineNo;
|
||||
ULONG nTotalLines, nPass, nPC, nIFDepth, nErrors;
|
||||
@@ -174,6 +181,45 @@ opt_Pop(void)
|
||||
fatalerror("No entries in the option stack");
|
||||
}
|
||||
|
||||
void
|
||||
opt_AddDefine(char *s)
|
||||
{
|
||||
char *value, *equals;
|
||||
if(cldefines_index >= cldefines_size)
|
||||
{
|
||||
cldefines_size *= 2;
|
||||
cldefines = reallocarray(cldefines, cldefines_size,
|
||||
2 * sizeof(void *));
|
||||
if(!cldefines)
|
||||
{
|
||||
fatalerror("No memory for command line defines");
|
||||
}
|
||||
}
|
||||
equals = strchr(s, '=');
|
||||
if(equals)
|
||||
{
|
||||
*equals = '\0';
|
||||
value = equals + 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
value = "1";
|
||||
}
|
||||
cldefines[cldefines_index++] = s;
|
||||
cldefines[cldefines_index++] = value;
|
||||
}
|
||||
|
||||
void
|
||||
opt_ParseDefines()
|
||||
{
|
||||
int i;
|
||||
|
||||
for(i = 0; i < cldefines_index; i += 2)
|
||||
{
|
||||
sym_AddString(cldefines[i], cldefines[i + 1]);
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Error handling
|
||||
*/
|
||||
@@ -211,8 +257,8 @@ static void
|
||||
usage(void)
|
||||
{
|
||||
printf(
|
||||
"Usage: rgbasm [-v] [-h] [-b chars] [-g chars] [-i path] [-o outfile]\n"
|
||||
" [-p pad_value] file.asm\n");
|
||||
"Usage: rgbasm [-hv] [-b chars] [-Dname[=value]] [-g chars] [-i path]\n"
|
||||
" [-o outfile] [-p pad_value] file.asm\n");
|
||||
exit(1);
|
||||
}
|
||||
|
||||
@@ -226,11 +272,19 @@ main(int argc, char *argv[])
|
||||
|
||||
char *tzMainfile;
|
||||
|
||||
|
||||
cldefines_size = 32;
|
||||
cldefines = reallocarray(cldefines, cldefines_size,
|
||||
2 * sizeof(void *));
|
||||
if(!cldefines)
|
||||
{
|
||||
fatalerror("No memory for command line defines");
|
||||
}
|
||||
|
||||
if (argc == 1)
|
||||
usage();
|
||||
|
||||
progname = argv[0];
|
||||
|
||||
/* yydebug=1; */
|
||||
|
||||
DefaultOptions.gbgfx[0] = '0';
|
||||
@@ -247,7 +301,7 @@ main(int argc, char *argv[])
|
||||
|
||||
newopt = CurrentOptions;
|
||||
|
||||
while ((ch = getopt(argc, argv, "b:g:hi:o:p:v")) != -1) {
|
||||
while ((ch = getopt(argc, argv, "b:D:g:hi:o:p:v")) != -1) {
|
||||
switch (ch) {
|
||||
case 'b':
|
||||
if (strlen(optarg) == 2) {
|
||||
@@ -258,6 +312,9 @@ main(int argc, char *argv[])
|
||||
"option 'b'");
|
||||
}
|
||||
break;
|
||||
case 'D':
|
||||
opt_AddDefine(optarg);
|
||||
break;
|
||||
case 'g':
|
||||
if (strlen(optarg) == 4) {
|
||||
newopt.gbgfx[0] = optarg[1];
|
||||
@@ -323,6 +380,7 @@ main(int argc, char *argv[])
|
||||
nErrors = 0;
|
||||
sym_PrepPass1();
|
||||
fstk_Init(tzMainfile);
|
||||
opt_ParseDefines();
|
||||
|
||||
if (CurrentOptions.verbose) {
|
||||
printf("Pass 1...\n");
|
||||
@@ -350,6 +408,7 @@ main(int argc, char *argv[])
|
||||
fstk_Init(tzMainfile);
|
||||
yy_set_state(LEX_STATE_NORMAL);
|
||||
opt_SetCurrentOptions(&DefaultOptions);
|
||||
opt_ParseDefines();
|
||||
|
||||
if (CurrentOptions.verbose) {
|
||||
printf("Pass 2...\n");
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
#include <math.h>
|
||||
#include <stdio.h>
|
||||
|
||||
#include "asm/types.h"
|
||||
#include "types.h"
|
||||
#include "asm/mymath.h"
|
||||
#include "asm/symbol.h"
|
||||
|
||||
|
||||
@@ -386,7 +386,10 @@ createpatch(ULONG type, struct Expression * expr)
|
||||
rpnexpr[rpnptr++] = value >> 16;
|
||||
rpnexpr[rpnptr++] = value >> 24;
|
||||
} else {
|
||||
symptr = addsymbol(sym_FindSymbol(tzSym));
|
||||
struct sSymbol *sym;
|
||||
if ((sym = sym_FindSymbol(tzSym)) == NULL)
|
||||
break;
|
||||
symptr = addsymbol(sym);
|
||||
rpnexpr[rpnptr++] = RPN_SYM;
|
||||
rpnexpr[rpnptr++] = symptr & 0xFF;
|
||||
rpnexpr[rpnptr++] = symptr >> 8;
|
||||
@@ -394,15 +397,19 @@ createpatch(ULONG type, struct Expression * expr)
|
||||
rpnexpr[rpnptr++] = symptr >> 24;
|
||||
}
|
||||
break;
|
||||
case RPN_BANK:
|
||||
case RPN_BANK: {
|
||||
struct sSymbol *sym;
|
||||
symptr = 0;
|
||||
while ((tzSym[symptr++] = rpn_PopByte(expr)) != 0);
|
||||
symptr = addsymbol(sym_FindSymbol(tzSym));
|
||||
if ((sym = sym_FindSymbol(tzSym)) == NULL)
|
||||
break;
|
||||
symptr = addsymbol(sym);
|
||||
rpnexpr[rpnptr++] = RPN_BANK;
|
||||
rpnexpr[rpnptr++] = symptr & 0xFF;
|
||||
rpnexpr[rpnptr++] = symptr >> 8;
|
||||
rpnexpr[rpnptr++] = symptr >> 16;
|
||||
rpnexpr[rpnptr++] = symptr >> 24;
|
||||
}
|
||||
break;
|
||||
default:
|
||||
rpnexpr[rpnptr++] = rpndata;
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
.Dd $Mdocdate$
|
||||
.Dd February 26, 2015
|
||||
.Dt RGBASM 1
|
||||
.Os RGBDS Manual
|
||||
.Sh NAME
|
||||
@@ -6,9 +6,9 @@
|
||||
.Nd Game Boy assembler
|
||||
.Sh SYNOPSIS
|
||||
.Nm rgbasm
|
||||
.Op Fl v
|
||||
.Op Fl h
|
||||
.Op Fl hv
|
||||
.Op Fl b Ar chars
|
||||
.Op Fl D Ar name Ns Op = Ns Ar value
|
||||
.Op Fl g Ar chars
|
||||
.Op Fl i Ar path
|
||||
.Op Fl o Ar outfile
|
||||
@@ -23,6 +23,12 @@ Its arguments are as follows:
|
||||
.It Fl b Ar chars
|
||||
Change the two characters used for binary constants.
|
||||
The defaults are 01.
|
||||
.It Fl D Ar name Ns Op = Ns Ar value
|
||||
Add string symbol to the compiled source code. This is equivalent to
|
||||
.Ar name
|
||||
.Cm EQUS
|
||||
.Qq Ar "value"
|
||||
in code. If a value is not specified, a value of 1 is given.
|
||||
.It Fl g Ar chars
|
||||
Change the four characters used for binary constants.
|
||||
The defaults are 0123.
|
||||
@@ -50,7 +56,7 @@ Be verbose.
|
||||
.Sh EXAMPLES
|
||||
Assembling a basic source file is simple:
|
||||
.Pp
|
||||
.D1 $ rgbasm \-o bar.o foo.asm
|
||||
.D1 $ rgbasm -o bar.o foo.asm
|
||||
.Pp
|
||||
The resulting object file is not yet a usable ROM image \(em it must first be
|
||||
run through
|
||||
@@ -58,10 +64,9 @@ run through
|
||||
and
|
||||
.Xr rgbfix 1 .
|
||||
.Sh SEE ALSO
|
||||
.Xr rgbds 7 ,
|
||||
.Xr rgbfix 1 ,
|
||||
.Xr rgblink 1 ,
|
||||
.Xr gbz80 7
|
||||
.Xr rgbds 7
|
||||
.Sh HISTORY
|
||||
.Nm
|
||||
was originally written by Carsten S\(/orensen as part of the ASMotor package,
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
#include <string.h>
|
||||
|
||||
#include "asm/mylink.h"
|
||||
#include "asm/types.h"
|
||||
#include "types.h"
|
||||
#include "asm/symbol.h"
|
||||
#include "asm/asm.h"
|
||||
#include "asm/main.h"
|
||||
|
||||
@@ -751,6 +751,8 @@ sym_PrepPass2(void)
|
||||
sym_AddEqu("_NARG", 0);
|
||||
p_NARGSymbol = findsymbol("_NARG", NULL);
|
||||
p_NARGSymbol->Callback = Callback_NARG;
|
||||
|
||||
math_DefinePI();
|
||||
}
|
||||
|
||||
/*
|
||||
|
||||
8
src/extern/err.c
vendored
8
src/extern/err.c
vendored
@@ -26,13 +26,11 @@
|
||||
#include <stdlib.h>
|
||||
#include "extern/err.h"
|
||||
|
||||
#ifndef __MINGW32__
|
||||
char *__progname;
|
||||
#endif
|
||||
extern char *progname;
|
||||
|
||||
void rgbds_vwarn(const char *fmt, va_list ap)
|
||||
{
|
||||
fprintf (stderr, "%s: ", __progname);
|
||||
fprintf (stderr, "%s: ", progname);
|
||||
if (fmt) {
|
||||
vfprintf(stderr, fmt, ap);
|
||||
fputs (": ", stderr);
|
||||
@@ -42,7 +40,7 @@ void rgbds_vwarn(const char *fmt, va_list ap)
|
||||
|
||||
void rgbds_vwarnx(const char *fmt, va_list ap)
|
||||
{
|
||||
fprintf (stderr, "%s: ", __progname);
|
||||
fprintf (stderr, "%s: ", progname);
|
||||
if (fmt) vfprintf(stderr, fmt, ap);
|
||||
putc('\n', stderr);
|
||||
}
|
||||
|
||||
2
src/extern/strlcat.c
vendored
2
src/extern/strlcat.c
vendored
@@ -24,7 +24,7 @@
|
||||
* full size of dst, not space left). At most dsize-1 characters
|
||||
* will be copied. Always NUL terminates (unless dsize <= strlen(dst)).
|
||||
* Returns strlen(src) + MIN(dsize, strlen(initial dst)).
|
||||
* If retval >= siz, truncation occurred.
|
||||
* If retval >= dsize, truncation occurred.
|
||||
*/
|
||||
size_t
|
||||
rgbds_strlcat(char *dst, const char *src, size_t dsize)
|
||||
|
||||
@@ -23,6 +23,8 @@
|
||||
|
||||
#include "extern/err.h"
|
||||
|
||||
char *progname;
|
||||
|
||||
static void
|
||||
usage(void)
|
||||
{
|
||||
@@ -69,6 +71,8 @@ main(int argc, char *argv[])
|
||||
int version; /* mask ROM version number */
|
||||
int padvalue; /* to pad the rom with if it changes size */
|
||||
|
||||
progname = argv[0];
|
||||
|
||||
while ((ch = getopt(argc, argv, "Cci:jk:l:m:n:p:sr:t:v")) != -1) {
|
||||
switch (ch) {
|
||||
case 'C':
|
||||
@@ -353,7 +357,8 @@ main(int argc, char *argv[])
|
||||
*/
|
||||
|
||||
/* We will pad the ROM to match the size given in the header. */
|
||||
int romsize, newsize, headbyte;
|
||||
long romsize, newsize;
|
||||
int headbyte;
|
||||
uint8_t *buf;
|
||||
fseek(rom, 0, SEEK_END);
|
||||
romsize = ftell(rom);
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
.Dd $Mdocdate$
|
||||
.Dd February 26, 2015
|
||||
.Dt RGBFIX 1
|
||||
.Os RGBDS Manual
|
||||
.Sh NAME
|
||||
@@ -41,7 +41,7 @@ flag are set,
|
||||
takes precedence.
|
||||
.It Fl i Ar game_id
|
||||
Set the game ID string
|
||||
.Pq Ad 0x13F No Ns \(en Ns Ad 0x142
|
||||
.Pq Ad 0x13F Ns \(en Ns Ad 0x142
|
||||
to a given string of exactly 4 characters.
|
||||
If both this and the title are set, the game ID will overwrite the
|
||||
overlapping portion of the title.
|
||||
@@ -51,7 +51,7 @@ Set the non-Japanese region flag:
|
||||
= 1.
|
||||
.It Fl k Ar licensee_str
|
||||
Set the new licensee string
|
||||
.Pq Ad 0x144 No Ns \(en Ns Ad 0x145
|
||||
.Pq Ad 0x144 Ns \(en Ns Ad 0x145
|
||||
to a given string, truncated to at most two characters.
|
||||
.It Fl l Ar licensee_id
|
||||
Set the old licensee code,
|
||||
@@ -84,7 +84,7 @@ Set the SGB flag:
|
||||
= 3.
|
||||
.It Fl t Ar title
|
||||
Set the title string
|
||||
.Pq Ad 0x134 No Ns \(en Ns Ad 0x143
|
||||
.Pq Ad 0x134 Ns \(en Ns Ad 0x143
|
||||
to a given string, truncated to at most 16 characters.
|
||||
It is recommended to use 15 characters instead, to avoid clashing with the CGB
|
||||
flag
|
||||
@@ -93,11 +93,11 @@ If both this and the game ID are set, the game ID will overwrite the
|
||||
overlapping portion of the title.
|
||||
.It Fl v
|
||||
Validate the header and fix checksums: the Nintendo character area
|
||||
.Pq Ad 0x104 No Ns \(en Ns Ad 0x133 ,
|
||||
.Pq Ad 0x104 Ns \(en Ns Ad 0x133 ,
|
||||
the header checksum
|
||||
.Pq Ad 0x14D ,
|
||||
and the global checksum
|
||||
.Pq Ad 0x14E No Ns \(en Ns Ad 0x14F .
|
||||
.Pq Ad 0x14E Ns \(en Ns Ad 0x14F .
|
||||
.El
|
||||
.Sh EXAMPLES
|
||||
Most values in the ROM header are only cosmetic.
|
||||
@@ -109,7 +109,7 @@ It is a good idea to pad the image to a valid size as well
|
||||
The following will make a plain, no-color Game Boy game without checking for
|
||||
a valid size:
|
||||
.Pp
|
||||
.D1 $ rgbfix \-v foo.gb
|
||||
.D1 $ rgbfix -v foo.gb
|
||||
.Pp
|
||||
The following will make a SGB-enabled, color-enabled game with a title of
|
||||
.Dq foobar ,
|
||||
@@ -119,19 +119,19 @@ The Game Boy itself does not use the title, but some emulators or ROM managers
|
||||
might.
|
||||
.Pc
|
||||
.Pp
|
||||
.D1 $ rgbfix \-vcs \-l 0x33 \-p 0 \-t foobar baz.gb
|
||||
.D1 $ rgbfix -vcs -l 0x33 -p 0 -t foobar baz.gb
|
||||
.Pp
|
||||
The following will duplicate the header
|
||||
.Pq sans global checksum
|
||||
of the game
|
||||
.Dq Survival Kids :
|
||||
.Pp
|
||||
.D1 $ rgbfix \-cjsv \-k A4 \-l 0x33 \-m 0x1B \-p 0xFF \-r 3 \-t SURVIVALKIDAVKE SurvivalKids.gbc
|
||||
.D1 $ rgbfix -cjsv -k A4 -l 0x33 -m 0x1B -p 0xFF -r 3 -t SURVIVALKIDAVKE \
|
||||
SurvivalKids.gbc
|
||||
.Sh SEE ALSO
|
||||
.Xr rgbds 7 ,
|
||||
.Xr rgbasm 1 ,
|
||||
.Xr rgblink 1 ,
|
||||
.Xr gbz80 7
|
||||
.Xr rgbds 7
|
||||
.Sh HISTORY
|
||||
.Nm
|
||||
was originally released by Carsten S\(/orensen as a standalone program called
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
#include <string.h>
|
||||
|
||||
#include "extern/err.h"
|
||||
#include "link/types.h"
|
||||
#include "types.h"
|
||||
#include "link/mylink.h"
|
||||
#include "link/main.h"
|
||||
|
||||
|
||||
@@ -24,6 +24,8 @@ SLONG options = 0;
|
||||
SLONG fillchar = 0;
|
||||
char smartlinkstartsymbol[256];
|
||||
|
||||
char *progname;
|
||||
|
||||
/*
|
||||
* Print the usagescreen
|
||||
*
|
||||
@@ -33,8 +35,8 @@ static void
|
||||
usage(void)
|
||||
{
|
||||
printf(
|
||||
"usage: rgblink [-t] [-m mapfile] [-n symfile] [-o outfile] [-s symbol]\n"
|
||||
" [-z pad_value] file [...]\n");
|
||||
"usage: rgblink [-t] [-m mapfile] [-n symfile] [-o outfile] [-p pad_value]\n"
|
||||
" [-s symbol] file [...]\n");
|
||||
exit(1);
|
||||
}
|
||||
|
||||
@@ -52,7 +54,9 @@ main(int argc, char *argv[])
|
||||
if (argc == 1)
|
||||
usage();
|
||||
|
||||
while ((ch = getopt(argc, argv, "l:m:n:o:p:s:t")) != -1) {
|
||||
progname = argv[0];
|
||||
|
||||
while ((ch = getopt(argc, argv, "m:n:o:p:s:t")) != -1) {
|
||||
switch (ch) {
|
||||
case 'm':
|
||||
SetMapfileName(optarg);
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
.Dd $Mdocdate$
|
||||
.Dd February 26, 2015
|
||||
.Dt RGBLINK 1
|
||||
.Os RGBDS Manual
|
||||
.Sh NAME
|
||||
@@ -7,7 +7,6 @@
|
||||
.Sh SYNOPSIS
|
||||
.Nm rgblink
|
||||
.Op Fl t
|
||||
.Op Fl l Ar library
|
||||
.Op Fl m Ar mapfile
|
||||
.Op Fl n Ar symfile
|
||||
.Op Fl o Ar outfile
|
||||
@@ -51,7 +50,7 @@ section size from 16KiB to 32KiB.
|
||||
All you need for a basic ROM is an object file, which can be made into a ROM
|
||||
image like so:
|
||||
.Pp
|
||||
.D1 $ rgblink \-o bar.gb foo.o
|
||||
.D1 $ rgblink -o bar.gb foo.o
|
||||
.Pp
|
||||
The resulting bar.gb will not have correct checksums
|
||||
.Pq unless you put them in the assembly source .
|
||||
@@ -59,12 +58,11 @@ You should use
|
||||
.Xr rgbfix 1
|
||||
to fix these so that the program will actually run in a Game Boy:
|
||||
.Pp
|
||||
.D1 $ rgbfix \-v bar.gb
|
||||
.D1 $ rgbfix -v bar.gb
|
||||
.Sh SEE ALSO
|
||||
.Xr rgbds 7 ,
|
||||
.Xr rgbasm 1 ,
|
||||
.Xr rgbfix 1 ,
|
||||
.Xr gbz80 7
|
||||
.Xr rgbds 7
|
||||
.Sh HISTORY
|
||||
.Nm
|
||||
was originally written by Carsten S\(/orensen as part of the ASMotor package,
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
#include "extern/err.h"
|
||||
#include "link/main.h"
|
||||
#include "link/patch.h"
|
||||
#include "link/types.h"
|
||||
#include "types.h"
|
||||
|
||||
#define HASHSIZE 73
|
||||
|
||||
@@ -76,7 +76,7 @@ sym_GetBank(char *tzName)
|
||||
}
|
||||
|
||||
void
|
||||
sym_CreateSymbol(char *tzName, SLONG nValue, SBYTE nBank)
|
||||
sym_CreateSymbol(char *tzName, SLONG nValue, SLONG nBank)
|
||||
{
|
||||
if (strcmp(tzName, "@") == 0)
|
||||
return;
|
||||
|
||||
Reference in New Issue
Block a user