Compare commits

..

25 Commits

Author SHA1 Message Date
Anthony J. Bentley
6c10ca62ad Don't silently truncate banks greater than 255 to 8 bits. 2015-07-26 02:08:39 -06:00
Christophe Staïesse
49809f6caf Fix segfault in createpatch() when symbol is an inexistant local label or bank
Fixed as follows: if the symbol doesn't exist, don't add it to the relocation
table. The functions calling createpatch will nevertheless increment PC
correctly.

Test case:

SECTION "CODE", CODE
glob:
        jp .loc

; from test/asm/banknoexist.asm:
SECTION "sec", ROM0
        db BANK(noexist)

See also issue #68
2015-07-26 01:57:30 -06:00
Christophe Staïesse
81675bc4c7 Fix yacc conflict (asmfile/lastline/lines/line rules) 2015-07-26 01:50:56 -06:00
YamaArashi
37b615f070 Fix bug with macro args in symbol names
If a macro arg came in the middle of a symbol or at the end, e.g. "SYM\1", it would say that the symbol was not defined. This was because it wasn't looking up the macro arg's value correctly.
2015-07-25 21:20:44 -07:00
stag019
6438ae2591 Remove __progname; add progname set to argv[0] in each main(). 2015-03-09 13:57:04 -04:00
Anthony J. Bentley
33ae6d8ca3 Use long for file offsets. 2015-03-07 14:21:57 -07:00
stag019
ebc9a4b786 Merge include/link/types.h and include/asm/types.h into include/types.h 2015-03-07 16:04:07 -05:00
stag019
e195076793 Only block comments in headers 2015-03-07 15:50:09 -05:00
stag019
b14beeff10 Consistency in #includes 2015-03-07 15:49:17 -05:00
stag019
db54c2ebd6 Replace all ASMOTOR references with RGBDS. 2015-03-07 15:42:06 -05:00
Anthony J. Bentley
eadaa47770 Sync with upstream. 2015-03-03 23:15:05 -07:00
Anthony J. Bentley
b5e7855afd Remove reference to currently nonexistent gbz80(7) manual. 2015-02-26 00:37:45 -07:00
Anthony J. Bentley
ce7d1d5d49 Use real dates in the manpages. 2015-02-26 00:37:13 -07:00
Anthony J. Bentley
64a3929f4e “No Ns” is redundant. 2015-02-26 00:36:46 -07:00
Anthony J. Bentley
1c1a4e6ac9 Merge branch 'master' of https://github.com/Sanqui/rgbds 2015-02-26 00:36:14 -07:00
Anthony J. Bentley
cc3aa969b8 Merge branch 'cldefines' of https://github.com/stag019/rgbds 2015-02-26 00:25:32 -07:00
Anthony J. Bentley
7055301616 Don’t unnecessarily escape hyphens in manpages. 2015-02-25 02:17:54 -07:00
Anthony J. Bentley
bbf24916e6 Sync usage lines. 2015-02-25 02:16:41 -07:00
Anthony J. Bentley
261503c7c8 Fix the reallocarray header by providing a prototype. 2015-02-25 02:13:23 -07:00
stag019
b924f58bb0 Added -D to manpage 2015-02-24 18:31:13 -05:00
stag019
ac78c37f9d Add reallocarray to Makefile; clean up some things in main.c 2015-02-24 18:11:02 -05:00
Anthony J. Bentley
c8d9ae21e6 A header file this simple doesn’t satisfy modicum of creativity. 2015-02-24 16:02:21 -07:00
Anthony J. Bentley
5281704f62 These internal headers don’t need C++ boilerplate. 2015-02-24 16:01:53 -07:00
stag019
fd4327327c Command line definitions. 2015-02-23 21:23:51 -05:00
Sanqui
bbf60c7197 Fix _PI (define it for pass 2) 2015-02-11 00:45:42 +01:00
43 changed files with 194 additions and 164 deletions

View File

@@ -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

View File

@@ -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;

View File

@@ -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

View File

@@ -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 {

View File

@@ -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

View File

@@ -1,5 +1,5 @@
#ifndef ASMOTOR_MAIN_H
#define ASMOTOR_MAIN_H
#ifndef RGBDS_MAIN_H
#define RGBDS_MAIN_H
#include <stdbool.h>

View File

@@ -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:
*

View File

@@ -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);

View File

@@ -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;

View File

@@ -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;

View File

@@ -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

View File

@@ -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
View File

@@ -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

View File

@@ -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

View File

@@ -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

View File

@@ -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,

View File

@@ -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);

View File

@@ -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];

View File

@@ -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);

View File

@@ -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

View File

@@ -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);

View File

@@ -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);

View File

@@ -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;

View File

@@ -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);

View File

@@ -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

View File

@@ -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

View File

@@ -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"

View File

@@ -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);

View File

@@ -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"

View File

@@ -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");

View File

@@ -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"

View File

@@ -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;

View File

@@ -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,

View File

@@ -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"

View File

@@ -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
View File

@@ -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);
}

View File

@@ -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)

View File

@@ -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);

View File

@@ -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

View File

@@ -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"

View File

@@ -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);

View File

@@ -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,

View File

@@ -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;