mirror of
https://github.com/gbdev/rgbds.git
synced 2025-11-21 10:42:07 +00:00
Compare commits
41 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 | ||
|
|
d81d128a04 | ||
|
|
d067f31678 | ||
|
|
d02294505c | ||
|
|
eb4bbb3e0b | ||
|
|
2ab10a95e4 | ||
|
|
bc60b85785 | ||
|
|
9d0203a4ee | ||
|
|
a18b65de21 | ||
|
|
1c47ffcce8 | ||
|
|
bbf60c7197 | ||
|
|
60c3a7e2f3 | ||
|
|
5702995978 | ||
|
|
483d94f88b | ||
|
|
9b4d16b0d8 | ||
|
|
a3e95f99d2 | ||
|
|
e3a31d7e59 | ||
|
|
d9f5ce339a |
3
LICENSE
3
LICENSE
@@ -21,5 +21,8 @@ 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,
|
extern/err.c is derived from the Musl C library, http://www.musl-libc.org,
|
||||||
and is released under the MIT license.
|
and is released under the MIT license.
|
||||||
|
|
||||||
|
extern/reallocarray.c is derived from the OpenBSD Project,
|
||||||
|
http://www.openbsd.org, and is released under the ISC license.
|
||||||
|
|
||||||
extern/strl.c is derived from the OpenBSD Project, http://www.openbsd.org,
|
extern/strl.c is derived from the OpenBSD Project, http://www.openbsd.org,
|
||||||
and is released under the BSD license.
|
and is released under the BSD license.
|
||||||
|
|||||||
4
Makefile
4
Makefile
@@ -23,6 +23,7 @@ rgbasm_obj = \
|
|||||||
src/asm/symbol.o \
|
src/asm/symbol.o \
|
||||||
src/asm/locallex.o \
|
src/asm/locallex.o \
|
||||||
src/extern/err.o \
|
src/extern/err.o \
|
||||||
|
src/extern/reallocarray.o \
|
||||||
src/extern/strlcpy.o \
|
src/extern/strlcpy.o \
|
||||||
src/extern/strlcat.o
|
src/extern/strlcat.o
|
||||||
|
|
||||||
@@ -85,8 +86,7 @@ src/asm/asmy.h: src/asm/asmy.c
|
|||||||
# install instructions instead.
|
# install instructions instead.
|
||||||
mingw:
|
mingw:
|
||||||
$Qenv PATH=/usr/local/mingw32/bin:/bin:/usr/bin:/usr/local/bin \
|
$Qenv PATH=/usr/local/mingw32/bin:/bin:/usr/bin:/usr/local/bin \
|
||||||
make CC=gcc CFLAGS="-I/usr/local/mingw32/include \
|
make WARNFLAGS= CC=gcc CFLAGS="-I/usr/local/mingw32/include \
|
||||||
-D__progname=\\\"\\\" \
|
|
||||||
${CFLAGS}"
|
${CFLAGS}"
|
||||||
$Qmv rgbasm rgbasm.exe
|
$Qmv rgbasm rgbasm.exe
|
||||||
$Qmv rgblink rgblink.exe
|
$Qmv rgblink rgblink.exe
|
||||||
|
|||||||
2
README
2
README
@@ -53,6 +53,6 @@ this variable. Defaults to @.
|
|||||||
Installing RGBDS (Windows)
|
Installing RGBDS (Windows)
|
||||||
============================
|
============================
|
||||||
|
|
||||||
Windows builds are available here: http://anthony.bentley.name/rgbds/
|
Windows builds are available here: https://github.com/bentley/rgbds/releases
|
||||||
|
|
||||||
Copy the .exe files to C:\Windows\ or similar.
|
Copy the .exe files to C:\Windows\ or similar.
|
||||||
|
|||||||
@@ -6,17 +6,17 @@
|
|||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#ifndef ASMOTOR_ASM_ASM_H
|
#ifndef RGBDS_ASM_ASM_H
|
||||||
#define ASMOTOR_ASM_ASM_H
|
#define RGBDS_ASM_ASM_H
|
||||||
|
|
||||||
#include <stdbool.h>
|
#include <stdbool.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
|
||||||
#include "asm/types.h"
|
#include "types.h"
|
||||||
#include "asm/symbol.h"
|
#include "asm/symbol.h"
|
||||||
|
|
||||||
#include "localasm.h"
|
#include "asm/localasm.h"
|
||||||
|
|
||||||
extern SLONG nLineNo;
|
extern SLONG nLineNo;
|
||||||
extern ULONG nTotalLines;
|
extern ULONG nTotalLines;
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
#ifndef ASMOTOR_ASM_CHARMAP_H
|
#ifndef RGBDS_ASM_CHARMAP_H
|
||||||
#define ASMOTOR_ASM_CHARMAP_H
|
#define RGBDS_ASM_CHARMAP_H
|
||||||
|
|
||||||
#define MAXCHARMAPS 512
|
#define MAXCHARMAPS 512
|
||||||
#define CHARMAPLENGTH 8
|
#define CHARMAPLENGTH 8
|
||||||
|
|||||||
@@ -6,13 +6,13 @@
|
|||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#ifndef ASMOTOR_ASM_FSTACK_H
|
#ifndef RGBDS_ASM_FSTACK_H
|
||||||
#define ASMOTOR_ASM_FSTACK_H
|
#define RGBDS_ASM_FSTACK_H
|
||||||
|
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
|
||||||
#include "asm/asm.h"
|
#include "asm/asm.h"
|
||||||
#include "asm/types.h"
|
#include "types.h"
|
||||||
#include "asm/lexer.h"
|
#include "asm/lexer.h"
|
||||||
|
|
||||||
struct sContext {
|
struct sContext {
|
||||||
|
|||||||
@@ -1,9 +1,9 @@
|
|||||||
#ifndef ASMOTOR_ASM_LEXER_H
|
#ifndef RGBDS_ASM_LEXER_H
|
||||||
#define ASMOTOR_ASM_LEXER_H
|
#define RGBDS_ASM_LEXER_H
|
||||||
|
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
|
||||||
#include "asm/types.h"
|
#include "types.h"
|
||||||
|
|
||||||
#define LEXHASHSIZE (1 << 11)
|
#define LEXHASHSIZE (1 << 11)
|
||||||
#define MAXSTRLEN 255
|
#define MAXSTRLEN 255
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
#ifndef ASMOTOR_MAIN_H
|
#ifndef RGBDS_MAIN_H
|
||||||
#define ASMOTOR_MAIN_H
|
#define RGBDS_MAIN_H
|
||||||
|
|
||||||
#include <stdbool.h>
|
#include <stdbool.h>
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
#ifndef ASMOTOR_ASM_LINK_H
|
#ifndef RGBDS_ASM_LINK_H
|
||||||
#define ASMOTOR_ASM_LINK_H
|
#define RGBDS_ASM_LINK_H
|
||||||
|
|
||||||
/* RGB0 .obj format:
|
/* RGB0 .obj format:
|
||||||
*
|
*
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
#ifndef ASMOTOR_ASM_MATH_H
|
#ifndef RGBDS_ASM_MATH_H
|
||||||
#define ASMOTOR_ASM_MATH_H
|
#define RGBDS_ASM_MATH_H
|
||||||
|
|
||||||
#include "asm/types.h"
|
#include "types.h"
|
||||||
|
|
||||||
void math_DefinePI(void);
|
void math_DefinePI(void);
|
||||||
void math_Print(SLONG i);
|
void math_Print(SLONG i);
|
||||||
|
|||||||
@@ -1,8 +1,8 @@
|
|||||||
#ifndef ASMOTOR_ASM_OUTPUT_H
|
#ifndef RGBDS_ASM_OUTPUT_H
|
||||||
#define ASMOTOR_ASM_OUTPUT_H
|
#define RGBDS_ASM_OUTPUT_H
|
||||||
|
|
||||||
#include "asm/rpn.h"
|
#include "asm/rpn.h"
|
||||||
#include "asm/types.h"
|
#include "types.h"
|
||||||
|
|
||||||
struct Section {
|
struct Section {
|
||||||
char *pzName;
|
char *pzName;
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
#ifndef ASMOTOR_ASM_RPN_H
|
#ifndef RGBDS_ASM_RPN_H
|
||||||
#define ASMOTOR_ASM_RPN_H
|
#define RGBDS_ASM_RPN_H
|
||||||
|
|
||||||
struct Expression {
|
struct Expression {
|
||||||
SLONG nVal;
|
SLONG nVal;
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
#ifndef ASMOTOR_SYMBOL_H
|
#ifndef RGBDS_SYMBOL_H
|
||||||
#define ASMOTOR_SYMBOL_H
|
#define RGBDS_SYMBOL_H
|
||||||
|
|
||||||
#include "asm/types.h"
|
#include "types.h"
|
||||||
|
|
||||||
#define HASHSIZE (1 << 16)
|
#define HASHSIZE (1 << 16)
|
||||||
#define MAXSYMLEN 256
|
#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
|
#ifndef EXTERN_ERR_H
|
||||||
#define EXTERN_ERR_H
|
#define EXTERN_ERR_H
|
||||||
|
|
||||||
@@ -29,7 +6,7 @@
|
|||||||
#else
|
#else
|
||||||
|
|
||||||
#include <stdarg.h>
|
#include <stdarg.h>
|
||||||
#include "stdnoreturn.h"
|
#include "extern/stdnoreturn.h"
|
||||||
|
|
||||||
#define warn rgbds_warn
|
#define warn rgbds_warn
|
||||||
#define vwarn rgbds_vwarn
|
#define vwarn rgbds_vwarn
|
||||||
@@ -41,10 +18,6 @@
|
|||||||
#define errx rgbds_errx
|
#define errx rgbds_errx
|
||||||
#define verrx rgbds_verrx
|
#define verrx rgbds_verrx
|
||||||
|
|
||||||
#ifdef __cplusplus
|
|
||||||
extern "C" {
|
|
||||||
#endif
|
|
||||||
|
|
||||||
void warn(const char *, ...);
|
void warn(const char *, ...);
|
||||||
void vwarn(const char *, va_list);
|
void vwarn(const char *, va_list);
|
||||||
void warnx(const char *, ...);
|
void warnx(const char *, ...);
|
||||||
@@ -55,10 +28,6 @@ noreturn void verr(int, const char *, va_list);
|
|||||||
noreturn void errx(int, const char *, ...);
|
noreturn void errx(int, const char *, ...);
|
||||||
noreturn void verrx(int, const char *, va_list);
|
noreturn void verrx(int, const char *, va_list);
|
||||||
|
|
||||||
#ifdef __cplusplus
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
14
include/extern/reallocarray.h
vendored
Normal file
14
include/extern/reallocarray.h
vendored
Normal file
@@ -0,0 +1,14 @@
|
|||||||
|
#ifndef EXTERN_REALLOCARRAY_H
|
||||||
|
#define EXTERN_REALLOCARRAY_H
|
||||||
|
|
||||||
|
#ifdef REALLOCARRAY_IN_LIBC
|
||||||
|
#include <stdlib.h>
|
||||||
|
#else
|
||||||
|
|
||||||
|
#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
|
#if __STDC_VERSION__ >= 201112L
|
||||||
// C11 or newer
|
/* C11 or newer */
|
||||||
#define noreturn _Noreturn
|
#define noreturn _Noreturn
|
||||||
#elif __cplusplus >= 201103L
|
#elif __cplusplus >= 201103L
|
||||||
// C++11 or newer
|
/* C++11 or newer */
|
||||||
#define noreturn [[noreturn]]
|
#define noreturn [[noreturn]]
|
||||||
#elif __GNUC__ > 2 || (__GNUC__ == 2 && (__GNUC_MINOR__ >= 5))
|
#elif __GNUC__ > 2 || (__GNUC__ == 2 && (__GNUC_MINOR__ >= 5))
|
||||||
// GCC 2.5 or newer
|
/* GCC 2.5 or newer */
|
||||||
#define noreturn __attribute__ ((noreturn))
|
#define noreturn __attribute__ ((noreturn))
|
||||||
#elif _MSC_VER >= 1310
|
#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)
|
#define noreturn _declspec( noreturn)
|
||||||
#else
|
#else
|
||||||
// unsupported, but no need to throw a fit
|
/* unsupported, but no need to throw a fit */
|
||||||
#define noreturn
|
#define noreturn
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
#ifndef ASMOTOR_LINK_ASSIGN_H
|
#ifndef RGBDS_LINK_ASSIGN_H
|
||||||
#define ASMOTOR_LINK_ASSIGN_H
|
#define RGBDS_LINK_ASSIGN_H
|
||||||
|
|
||||||
#include "link/types.h"
|
#include "types.h"
|
||||||
|
|
||||||
enum eBankDefine {
|
enum eBankDefine {
|
||||||
BANK_ROM0 = 0,
|
BANK_ROM0 = 0,
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
#ifndef ASMOTOR_LINK_LIBRARY_H
|
#ifndef RGBDS_LINK_LIBRARY_H
|
||||||
#define ASMOTOR_LINK_LIBRARY_H
|
#define RGBDS_LINK_LIBRARY_H
|
||||||
|
|
||||||
extern void AddNeededModules(void);
|
extern void AddNeededModules(void);
|
||||||
|
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
#ifndef ASMOTOR_LINK_MAIN_H
|
#ifndef RGBDS_LINK_MAIN_H
|
||||||
#define ASMOTOR_LINK_MAIN_H
|
#define RGBDS_LINK_MAIN_H
|
||||||
|
|
||||||
#include "link/types.h"
|
#include "types.h"
|
||||||
|
|
||||||
extern SLONG fillchar;
|
extern SLONG fillchar;
|
||||||
extern char smartlinkstartsymbol[256];
|
extern char smartlinkstartsymbol[256];
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
#ifndef ASMOTOR_LINK_MAPFILE_H
|
#ifndef RGBDS_LINK_MAPFILE_H
|
||||||
#define ASMOTOR_LINK_MAPFILE_H
|
#define RGBDS_LINK_MAPFILE_H
|
||||||
|
|
||||||
extern void SetMapfileName(char *name);
|
extern void SetMapfileName(char *name);
|
||||||
extern void SetSymfileName(char *name);
|
extern void SetSymfileName(char *name);
|
||||||
|
|||||||
@@ -1,11 +1,11 @@
|
|||||||
#ifndef ASMOTOR_LINK_LINK_H
|
#ifndef RGBDS_LINK_LINK_H
|
||||||
#define ASMOTOR_LINK_LINK_H
|
#define RGBDS_LINK_LINK_H
|
||||||
|
|
||||||
#ifndef _MAX_PATH
|
#ifndef _MAX_PATH
|
||||||
#define _MAX_PATH 512
|
#define _MAX_PATH 512
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#include "link/types.h"
|
#include "types.h"
|
||||||
|
|
||||||
extern SLONG options;
|
extern SLONG options;
|
||||||
#define OPT_SMALL 0x01
|
#define OPT_SMALL 0x01
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
#ifndef ASMOTOR_LINK_OBJECT_H
|
#ifndef RGBDS_LINK_OBJECT_H
|
||||||
#define ASMOTOR_LINK_OBJECT_H
|
#define RGBDS_LINK_OBJECT_H
|
||||||
|
|
||||||
extern void obj_Readfile(char *tzObjectfile);
|
extern void obj_Readfile(char *tzObjectfile);
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
#ifndef ASMOTOR_LINK_OUTPUT_H
|
#ifndef RGBDS_LINK_OUTPUT_H
|
||||||
#define ASMOTOR_LINK_OUTPUT_H
|
#define RGBDS_LINK_OUTPUT_H
|
||||||
|
|
||||||
void out_Setname(char *tzOutputfile);
|
void out_Setname(char *tzOutputfile);
|
||||||
void Output(void);
|
void Output(void);
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
#ifndef ASMOTOR_LINK_PATCH_H
|
#ifndef RGBDS_LINK_PATCH_H
|
||||||
#define ASMOTOR_LINK_PATCH_H
|
#define RGBDS_LINK_PATCH_H
|
||||||
|
|
||||||
#include "link/types.h"
|
#include "types.h"
|
||||||
|
|
||||||
void Patch(void);
|
void Patch(void);
|
||||||
extern SLONG nPC;
|
extern SLONG nPC;
|
||||||
|
|||||||
@@ -1,10 +1,10 @@
|
|||||||
#ifndef ASMOTOR_LINK_SYMBOL_H
|
#ifndef RGBDS_LINK_SYMBOL_H
|
||||||
#define ASMOTOR_LINK_SYMBOL_H
|
#define RGBDS_LINK_SYMBOL_H
|
||||||
|
|
||||||
#include "link/types.h"
|
#include "types.h"
|
||||||
|
|
||||||
void sym_Init(void);
|
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_GetValue(char *tzName);
|
||||||
SLONG sym_GetBank(char *tzName);
|
SLONG sym_GetBank(char *tzName);
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
#ifndef ASMOTOR_LINK_TYPES_H
|
#ifndef RGBDS_TYPES_H
|
||||||
#define ASMOTOR_LINK_TYPES_H
|
#define RGBDS_TYPES_H
|
||||||
|
|
||||||
#ifndef _MAX_PATH
|
#ifndef _MAX_PATH
|
||||||
#define _MAX_PATH 512
|
#define _MAX_PATH 512
|
||||||
@@ -497,22 +497,16 @@ void if_skip_to_endc( void )
|
|||||||
|
|
||||||
%%
|
%%
|
||||||
|
|
||||||
asmfile : lines lastline;
|
asmfile : lines;
|
||||||
|
|
||||||
lastline : /* empty */
|
|
||||||
| line {
|
|
||||||
nLineNo += 1;
|
|
||||||
nTotalLines += 1;
|
|
||||||
};
|
|
||||||
|
|
||||||
|
/* Note: The lexer add '\n' at the end of the input */
|
||||||
lines : /* empty */
|
lines : /* empty */
|
||||||
| lines line '\n' {
|
| lines line '\n' {
|
||||||
nLineNo += 1;
|
nLineNo += 1;
|
||||||
nTotalLines += 1;
|
nTotalLines += 1;
|
||||||
};
|
};
|
||||||
|
|
||||||
line : /* empty */
|
line : label
|
||||||
| label
|
|
||||||
| label cpu_command
|
| label cpu_command
|
||||||
| label macro
|
| label macro
|
||||||
| label simple_pseudoop
|
| label simple_pseudoop
|
||||||
@@ -992,8 +986,16 @@ const : T_ID { $$ = sym_GetConstantValue($1); }
|
|||||||
| const T_OP_SHL const { $$ = $1 << $3; }
|
| const T_OP_SHL const { $$ = $1 << $3; }
|
||||||
| const T_OP_SHR const { $$ = $1 >> $3; }
|
| const T_OP_SHR const { $$ = $1 >> $3; }
|
||||||
| const T_OP_MUL const { $$ = $1 * $3; }
|
| const T_OP_MUL const { $$ = $1 * $3; }
|
||||||
| const T_OP_DIV const { $$ = $1 / $3; }
|
| const T_OP_DIV const {
|
||||||
| const T_OP_MOD const { $$ = $1 % $3; }
|
if ($3 == 0)
|
||||||
|
fatalerror("division by zero");
|
||||||
|
$$ = $1 / $3;
|
||||||
|
}
|
||||||
|
| const T_OP_MOD const {
|
||||||
|
if ($3 == 0)
|
||||||
|
fatalerror("division by zero");
|
||||||
|
$$ = $1 % $3;
|
||||||
|
}
|
||||||
| T_OP_ADD const %prec NEG { $$ = +$2; }
|
| T_OP_ADD const %prec NEG { $$ = +$2; }
|
||||||
| T_OP_SUB const %prec NEG { $$ = -$2; }
|
| T_OP_SUB const %prec NEG { $$ = -$2; }
|
||||||
| T_OP_NOT const %prec NEG { $$ = 0xFFFFFFFF^$2; }
|
| T_OP_NOT const %prec NEG { $$ = 0xFFFFFFFF^$2; }
|
||||||
@@ -1065,7 +1067,7 @@ section:
|
|||||||
}
|
}
|
||||||
} else if ($4 == SECT_WRAMX) {
|
} else if ($4 == SECT_WRAMX) {
|
||||||
if ($8 >= 1 && $8 <= 7) {
|
if ($8 >= 1 && $8 <= 7) {
|
||||||
out_NewAbsSection($2, $4, -1, $8);
|
out_NewAbsSection($2, $4, -1, $8 - 1);
|
||||||
} else {
|
} else {
|
||||||
yyerror("WRAMX bank value $%x out of range (1 to 7)", $8);
|
yyerror("WRAMX bank value $%x out of range (1 to 7)", $8);
|
||||||
}
|
}
|
||||||
@@ -1102,7 +1104,7 @@ section:
|
|||||||
} else if ($4 == SECT_WRAMX) {
|
} else if ($4 == SECT_WRAMX) {
|
||||||
if ($6 >= 0 && $6 < 0x10000) {
|
if ($6 >= 0 && $6 < 0x10000) {
|
||||||
if ($11 >= 1 && $11 <= 7) {
|
if ($11 >= 1 && $11 <= 7) {
|
||||||
out_NewAbsSection($2, $4, $6, $11);
|
out_NewAbsSection($2, $4, $6, $11 - 1);
|
||||||
} else {
|
} else {
|
||||||
yyerror("WRAMX bank value $%x out of range (1 to 7)", $11);
|
yyerror("WRAMX bank value $%x out of range (1 to 7)", $11);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -10,7 +10,7 @@
|
|||||||
|
|
||||||
#include "asm/symbol.h"
|
#include "asm/symbol.h"
|
||||||
#include "asm/fstack.h"
|
#include "asm/fstack.h"
|
||||||
#include "asm/types.h"
|
#include "types.h"
|
||||||
#include "asm/main.h"
|
#include "asm/main.h"
|
||||||
#include "asm/lexer.h"
|
#include "asm/lexer.h"
|
||||||
#include "extern/err.h"
|
#include "extern/err.h"
|
||||||
|
|||||||
@@ -161,7 +161,7 @@ ParseSymbol(char *src, ULONG size)
|
|||||||
if (*src == '@')
|
if (*src == '@')
|
||||||
marg = sym_FindMacroArg(-1);
|
marg = sym_FindMacroArg(-1);
|
||||||
else if (*src >= '0' && *src <= '9')
|
else if (*src >= '0' && *src <= '9')
|
||||||
marg = sym_FindMacroArg(*src);
|
marg = sym_FindMacroArg(*src - '0');
|
||||||
else {
|
else {
|
||||||
fatalerror("Malformed ID");
|
fatalerror("Malformed ID");
|
||||||
return (0);
|
return (0);
|
||||||
|
|||||||
@@ -6,7 +6,7 @@
|
|||||||
|
|
||||||
#include "asm/asm.h"
|
#include "asm/asm.h"
|
||||||
#include "asm/lexer.h"
|
#include "asm/lexer.h"
|
||||||
#include "asm/types.h"
|
#include "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"
|
||||||
|
|||||||
@@ -11,10 +11,17 @@
|
|||||||
#include "asm/output.h"
|
#include "asm/output.h"
|
||||||
#include "asm/main.h"
|
#include "asm/main.h"
|
||||||
#include "extern/err.h"
|
#include "extern/err.h"
|
||||||
|
#include "extern/reallocarray.h"
|
||||||
|
|
||||||
int yyparse(void);
|
int yyparse(void);
|
||||||
void setuplex(void);
|
void setuplex(void);
|
||||||
|
|
||||||
|
int cldefines_index;
|
||||||
|
int cldefines_size;
|
||||||
|
char **cldefines;
|
||||||
|
|
||||||
|
char *progname;
|
||||||
|
|
||||||
clock_t nStartClock, nEndClock;
|
clock_t nStartClock, nEndClock;
|
||||||
SLONG nLineNo;
|
SLONG nLineNo;
|
||||||
ULONG nTotalLines, nPass, nPC, nIFDepth, nErrors;
|
ULONG nTotalLines, nPass, nPC, nIFDepth, nErrors;
|
||||||
@@ -174,6 +181,45 @@ opt_Pop(void)
|
|||||||
fatalerror("No entries in the option stack");
|
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
|
* Error handling
|
||||||
*/
|
*/
|
||||||
@@ -211,8 +257,8 @@ static void
|
|||||||
usage(void)
|
usage(void)
|
||||||
{
|
{
|
||||||
printf(
|
printf(
|
||||||
"Usage: rgbasm [-v] [-h] [-b chars] [-g chars] [-i path] [-o outfile]\n"
|
"Usage: rgbasm [-hv] [-b chars] [-Dname[=value]] [-g chars] [-i path]\n"
|
||||||
" [-p pad_value] file.asm\n");
|
" [-o outfile] [-p pad_value] file.asm\n");
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -226,11 +272,19 @@ main(int argc, char *argv[])
|
|||||||
|
|
||||||
char *tzMainfile;
|
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)
|
if (argc == 1)
|
||||||
usage();
|
usage();
|
||||||
|
|
||||||
|
progname = argv[0];
|
||||||
|
|
||||||
/* yydebug=1; */
|
/* yydebug=1; */
|
||||||
|
|
||||||
DefaultOptions.gbgfx[0] = '0';
|
DefaultOptions.gbgfx[0] = '0';
|
||||||
@@ -247,7 +301,7 @@ main(int argc, char *argv[])
|
|||||||
|
|
||||||
newopt = CurrentOptions;
|
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) {
|
switch (ch) {
|
||||||
case 'b':
|
case 'b':
|
||||||
if (strlen(optarg) == 2) {
|
if (strlen(optarg) == 2) {
|
||||||
@@ -258,6 +312,9 @@ main(int argc, char *argv[])
|
|||||||
"option 'b'");
|
"option 'b'");
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
case 'D':
|
||||||
|
opt_AddDefine(optarg);
|
||||||
|
break;
|
||||||
case 'g':
|
case 'g':
|
||||||
if (strlen(optarg) == 4) {
|
if (strlen(optarg) == 4) {
|
||||||
newopt.gbgfx[0] = optarg[1];
|
newopt.gbgfx[0] = optarg[1];
|
||||||
@@ -323,6 +380,7 @@ main(int argc, char *argv[])
|
|||||||
nErrors = 0;
|
nErrors = 0;
|
||||||
sym_PrepPass1();
|
sym_PrepPass1();
|
||||||
fstk_Init(tzMainfile);
|
fstk_Init(tzMainfile);
|
||||||
|
opt_ParseDefines();
|
||||||
|
|
||||||
if (CurrentOptions.verbose) {
|
if (CurrentOptions.verbose) {
|
||||||
printf("Pass 1...\n");
|
printf("Pass 1...\n");
|
||||||
@@ -350,6 +408,7 @@ main(int argc, char *argv[])
|
|||||||
fstk_Init(tzMainfile);
|
fstk_Init(tzMainfile);
|
||||||
yy_set_state(LEX_STATE_NORMAL);
|
yy_set_state(LEX_STATE_NORMAL);
|
||||||
opt_SetCurrentOptions(&DefaultOptions);
|
opt_SetCurrentOptions(&DefaultOptions);
|
||||||
|
opt_ParseDefines();
|
||||||
|
|
||||||
if (CurrentOptions.verbose) {
|
if (CurrentOptions.verbose) {
|
||||||
printf("Pass 2...\n");
|
printf("Pass 2...\n");
|
||||||
|
|||||||
@@ -5,7 +5,7 @@
|
|||||||
#include <math.h>
|
#include <math.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
|
||||||
#include "asm/types.h"
|
#include "types.h"
|
||||||
#include "asm/mymath.h"
|
#include "asm/mymath.h"
|
||||||
#include "asm/symbol.h"
|
#include "asm/symbol.h"
|
||||||
|
|
||||||
|
|||||||
@@ -386,7 +386,10 @@ createpatch(ULONG type, struct Expression * expr)
|
|||||||
rpnexpr[rpnptr++] = value >> 16;
|
rpnexpr[rpnptr++] = value >> 16;
|
||||||
rpnexpr[rpnptr++] = value >> 24;
|
rpnexpr[rpnptr++] = value >> 24;
|
||||||
} else {
|
} 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++] = RPN_SYM;
|
||||||
rpnexpr[rpnptr++] = symptr & 0xFF;
|
rpnexpr[rpnptr++] = symptr & 0xFF;
|
||||||
rpnexpr[rpnptr++] = symptr >> 8;
|
rpnexpr[rpnptr++] = symptr >> 8;
|
||||||
@@ -394,15 +397,19 @@ createpatch(ULONG type, struct Expression * expr)
|
|||||||
rpnexpr[rpnptr++] = symptr >> 24;
|
rpnexpr[rpnptr++] = symptr >> 24;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case RPN_BANK:
|
case RPN_BANK: {
|
||||||
|
struct sSymbol *sym;
|
||||||
symptr = 0;
|
symptr = 0;
|
||||||
while ((tzSym[symptr++] = rpn_PopByte(expr)) != 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++] = RPN_BANK;
|
||||||
rpnexpr[rpnptr++] = symptr & 0xFF;
|
rpnexpr[rpnptr++] = symptr & 0xFF;
|
||||||
rpnexpr[rpnptr++] = symptr >> 8;
|
rpnexpr[rpnptr++] = symptr >> 8;
|
||||||
rpnexpr[rpnptr++] = symptr >> 16;
|
rpnexpr[rpnptr++] = symptr >> 16;
|
||||||
rpnexpr[rpnptr++] = symptr >> 24;
|
rpnexpr[rpnptr++] = symptr >> 24;
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
rpnexpr[rpnptr++] = rpndata;
|
rpnexpr[rpnptr++] = rpndata;
|
||||||
@@ -440,24 +447,30 @@ checkcodesection(SLONG size)
|
|||||||
errx(1, "Section '%s' cannot contain code or data (not a "
|
errx(1, "Section '%s' cannot contain code or data (not a "
|
||||||
"ROM0 or ROMX)", pCurrentSection->pzName);
|
"ROM0 or ROMX)", pCurrentSection->pzName);
|
||||||
}
|
}
|
||||||
if (pCurrentSection->nPC + size <= MAXSECTIONSIZE) {
|
if (pCurrentSection->nPC + size > MAXSECTIONSIZE) {
|
||||||
|
/*
|
||||||
|
* N.B.: This check is not sufficient to ensure the section
|
||||||
|
* will fit, because there can be multiple sections of this
|
||||||
|
* type. The definitive check must be done at the linking
|
||||||
|
* stage.
|
||||||
|
*/
|
||||||
|
errx(1, "Section '%s' is too big (old size %d + %d > %d)",
|
||||||
|
pCurrentSection->pzName, 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 ||
|
||||||
|| pCurrentSection->nType == SECT_ROMX)) {
|
pCurrentSection->nType == SECT_ROMX)) {
|
||||||
if ((pCurrentSection->tData =
|
pCurrentSection->tData = realloc(pCurrentSection->tData,
|
||||||
(UBYTE *) realloc(pCurrentSection->tData,
|
((pCurrentSection->nPC + size) / SECTIONCHUNK + 1) *
|
||||||
((pCurrentSection->nPC +
|
SECTIONCHUNK);
|
||||||
size) / SECTIONCHUNK +
|
|
||||||
1) * SECTIONCHUNK)) != NULL) {
|
if (pCurrentSection->tData == NULL) {
|
||||||
return;
|
err(1, "Could not expand section");
|
||||||
} else
|
}
|
||||||
fatalerror
|
|
||||||
("Not enough memory to expand section");
|
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
} else
|
|
||||||
errx(1, "Section '%s' is too big", pCurrentSection->pzName);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
.Dd $Mdocdate$
|
.Dd February 26, 2015
|
||||||
.Dt RGBASM 1
|
.Dt RGBASM 1
|
||||||
.Os RGBDS Manual
|
.Os RGBDS Manual
|
||||||
.Sh NAME
|
.Sh NAME
|
||||||
@@ -6,9 +6,9 @@
|
|||||||
.Nd Game Boy assembler
|
.Nd Game Boy assembler
|
||||||
.Sh SYNOPSIS
|
.Sh SYNOPSIS
|
||||||
.Nm rgbasm
|
.Nm rgbasm
|
||||||
.Op Fl v
|
.Op Fl hv
|
||||||
.Op Fl h
|
|
||||||
.Op Fl b Ar chars
|
.Op Fl b Ar chars
|
||||||
|
.Op Fl D Ar name Ns Op = Ns Ar value
|
||||||
.Op Fl g Ar chars
|
.Op Fl g Ar chars
|
||||||
.Op Fl i Ar path
|
.Op Fl i Ar path
|
||||||
.Op Fl o Ar outfile
|
.Op Fl o Ar outfile
|
||||||
@@ -23,6 +23,12 @@ Its arguments are as follows:
|
|||||||
.It Fl b Ar chars
|
.It Fl b Ar chars
|
||||||
Change the two characters used for binary constants.
|
Change the two characters used for binary constants.
|
||||||
The defaults are 01.
|
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
|
.It Fl g Ar chars
|
||||||
Change the four characters used for binary constants.
|
Change the four characters used for binary constants.
|
||||||
The defaults are 0123.
|
The defaults are 0123.
|
||||||
@@ -50,7 +56,7 @@ Be verbose.
|
|||||||
.Sh EXAMPLES
|
.Sh EXAMPLES
|
||||||
Assembling a basic source file is simple:
|
Assembling a basic source file is simple:
|
||||||
.Pp
|
.Pp
|
||||||
.D1 $ rgbasm \-o bar.o foo.asm
|
.D1 $ rgbasm -o bar.o foo.asm
|
||||||
.Pp
|
.Pp
|
||||||
The resulting object file is not yet a usable ROM image \(em it must first be
|
The resulting object file is not yet a usable ROM image \(em it must first be
|
||||||
run through
|
run through
|
||||||
@@ -58,10 +64,9 @@ run through
|
|||||||
and
|
and
|
||||||
.Xr rgbfix 1 .
|
.Xr rgbfix 1 .
|
||||||
.Sh SEE ALSO
|
.Sh SEE ALSO
|
||||||
.Xr rgbds 7 ,
|
|
||||||
.Xr rgbfix 1 ,
|
.Xr rgbfix 1 ,
|
||||||
.Xr rgblink 1 ,
|
.Xr rgblink 1 ,
|
||||||
.Xr gbz80 7
|
.Xr rgbds 7
|
||||||
.Sh HISTORY
|
.Sh HISTORY
|
||||||
.Nm
|
.Nm
|
||||||
was originally written by Carsten S\(/orensen as part of the ASMotor package,
|
was originally written by Carsten S\(/orensen as part of the ASMotor package,
|
||||||
|
|||||||
@@ -6,7 +6,7 @@
|
|||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
#include "asm/mylink.h"
|
#include "asm/mylink.h"
|
||||||
#include "asm/types.h"
|
#include "types.h"
|
||||||
#include "asm/symbol.h"
|
#include "asm/symbol.h"
|
||||||
#include "asm/asm.h"
|
#include "asm/asm.h"
|
||||||
#include "asm/main.h"
|
#include "asm/main.h"
|
||||||
|
|||||||
@@ -751,6 +751,8 @@ sym_PrepPass2(void)
|
|||||||
sym_AddEqu("_NARG", 0);
|
sym_AddEqu("_NARG", 0);
|
||||||
p_NARGSymbol = findsymbol("_NARG", NULL);
|
p_NARGSymbol = findsymbol("_NARG", NULL);
|
||||||
p_NARGSymbol->Callback = Callback_NARG;
|
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 <stdlib.h>
|
||||||
#include "extern/err.h"
|
#include "extern/err.h"
|
||||||
|
|
||||||
#ifndef __MINGW32__
|
extern char *progname;
|
||||||
char *__progname;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
void rgbds_vwarn(const char *fmt, va_list ap)
|
void rgbds_vwarn(const char *fmt, va_list ap)
|
||||||
{
|
{
|
||||||
fprintf (stderr, "%s: ", __progname);
|
fprintf (stderr, "%s: ", progname);
|
||||||
if (fmt) {
|
if (fmt) {
|
||||||
vfprintf(stderr, fmt, ap);
|
vfprintf(stderr, fmt, ap);
|
||||||
fputs (": ", stderr);
|
fputs (": ", stderr);
|
||||||
@@ -42,7 +40,7 @@ void rgbds_vwarn(const char *fmt, va_list ap)
|
|||||||
|
|
||||||
void rgbds_vwarnx(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);
|
if (fmt) vfprintf(stderr, fmt, ap);
|
||||||
putc('\n', stderr);
|
putc('\n', stderr);
|
||||||
}
|
}
|
||||||
|
|||||||
38
src/extern/reallocarray.c
vendored
Normal file
38
src/extern/reallocarray.c
vendored
Normal file
@@ -0,0 +1,38 @@
|
|||||||
|
/* $OpenBSD: reallocarray.c,v 1.2 2014/12/08 03:45:00 bcook Exp $ */
|
||||||
|
/*
|
||||||
|
* Copyright (c) 2008 Otto Moerbeek <otto@drijf.net>
|
||||||
|
*
|
||||||
|
* 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 <errno.h>
|
||||||
|
#include <stdint.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
|
||||||
|
/*
|
||||||
|
* This is sqrt(SIZE_MAX+1), as s1*s2 <= SIZE_MAX
|
||||||
|
* if both s1 < MUL_NO_OVERFLOW and s2 < MUL_NO_OVERFLOW
|
||||||
|
*/
|
||||||
|
#define MUL_NO_OVERFLOW ((size_t)1 << (sizeof(size_t) * 4))
|
||||||
|
|
||||||
|
void *
|
||||||
|
rgbds_reallocarray(void *optr, size_t nmemb, size_t size)
|
||||||
|
{
|
||||||
|
if ((nmemb >= MUL_NO_OVERFLOW || size >= MUL_NO_OVERFLOW) &&
|
||||||
|
nmemb > 0 && SIZE_MAX / nmemb < size) {
|
||||||
|
errno = ENOMEM;
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
return realloc(optr, size * nmemb);
|
||||||
|
}
|
||||||
48
src/extern/strlcat.c
vendored
48
src/extern/strlcat.c
vendored
@@ -1,7 +1,7 @@
|
|||||||
/* $OpenBSD: strlcat.c,v 1.13 2005/08/08 08:05:37 espie Exp $ */
|
/* $OpenBSD: strlcat.c,v 1.14 2015/01/15 03:54:12 millert Exp $ */
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Copyright (c) 1998 Todd C. Miller <Todd.Miller@courtesan.com>
|
* Copyright (c) 1998, 2015 Todd C. Miller <Todd.Miller@courtesan.com>
|
||||||
*
|
*
|
||||||
* Permission to use, copy, modify, and distribute this software for any
|
* Permission to use, copy, modify, and distribute this software for any
|
||||||
* purpose with or without fee is hereby granted, provided that the above
|
* purpose with or without fee is hereby granted, provided that the above
|
||||||
@@ -20,36 +20,36 @@
|
|||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Appends src to string dst of size siz (unlike strncat, siz is the
|
* Appends src to string dst of size dsize (unlike strncat, dsize is the
|
||||||
* full size of dst, not space left). At most siz-1 characters
|
* full size of dst, not space left). At most dsize-1 characters
|
||||||
* will be copied. Always NUL terminates (unless siz <= strlen(dst)).
|
* will be copied. Always NUL terminates (unless dsize <= strlen(dst)).
|
||||||
* Returns strlen(src) + MIN(siz, strlen(initial dst)).
|
* Returns strlen(src) + MIN(dsize, strlen(initial dst)).
|
||||||
* If retval >= siz, truncation occurred.
|
* If retval >= dsize, truncation occurred.
|
||||||
*/
|
*/
|
||||||
size_t
|
size_t
|
||||||
rgbds_strlcat(char *dst, const char *src, size_t siz)
|
rgbds_strlcat(char *dst, const char *src, size_t dsize)
|
||||||
{
|
{
|
||||||
char *d = dst;
|
const char *odst = dst;
|
||||||
const char *s = src;
|
const char *osrc = src;
|
||||||
size_t n = siz;
|
size_t n = dsize;
|
||||||
size_t dlen;
|
size_t dlen;
|
||||||
|
|
||||||
/* Find the end of dst and adjust bytes left but don't go past end */
|
/* Find the end of dst and adjust bytes left but don't go past end. */
|
||||||
while (n-- != 0 && *d != '\0')
|
while (n-- != 0 && *dst != '\0')
|
||||||
d++;
|
dst++;
|
||||||
dlen = d - dst;
|
dlen = dst - odst;
|
||||||
n = siz - dlen;
|
n = dsize - dlen;
|
||||||
|
|
||||||
if (n == 0)
|
if (n-- == 0)
|
||||||
return(dlen + strlen(s));
|
return(dlen + strlen(src));
|
||||||
while (*s != '\0') {
|
while (*src != '\0') {
|
||||||
if (n != 1) {
|
if (n != 0) {
|
||||||
*d++ = *s;
|
*dst++ = *src;
|
||||||
n--;
|
n--;
|
||||||
}
|
}
|
||||||
s++;
|
src++;
|
||||||
}
|
}
|
||||||
*d = '\0';
|
*dst = '\0';
|
||||||
|
|
||||||
return(dlen + (s - src)); /* count does not include NUL */
|
return(dlen + (src - osrc)); /* count does not include NUL */
|
||||||
}
|
}
|
||||||
|
|||||||
37
src/extern/strlcpy.c
vendored
37
src/extern/strlcpy.c
vendored
@@ -1,7 +1,7 @@
|
|||||||
/* $OpenBSD: strlcpy.c,v 1.11 2006/05/05 15:27:38 millert Exp $ */
|
/* $OpenBSD: strlcpy.c,v 1.12 2015/01/15 03:54:12 millert Exp $ */
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Copyright (c) 1998 Todd C. Miller <Todd.Miller@courtesan.com>
|
* Copyright (c) 1998, 2015 Todd C. Miller <Todd.Miller@courtesan.com>
|
||||||
*
|
*
|
||||||
* Permission to use, copy, modify, and distribute this software for any
|
* Permission to use, copy, modify, and distribute this software for any
|
||||||
* purpose with or without fee is hereby granted, provided that the above
|
* purpose with or without fee is hereby granted, provided that the above
|
||||||
@@ -20,32 +20,31 @@
|
|||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Copy src to string dst of size siz. At most siz-1 characters
|
* Copy string src to buffer dst of size dsize. At most dsize-1
|
||||||
* will be copied. Always NUL terminates (unless siz == 0).
|
* chars will be copied. Always NUL terminates (unless dsize == 0).
|
||||||
* Returns strlen(src); if retval >= siz, truncation occurred.
|
* Returns strlen(src); if retval >= dsize, truncation occurred.
|
||||||
*/
|
*/
|
||||||
size_t
|
size_t
|
||||||
rgbds_strlcpy(char *dst, const char *src, size_t siz)
|
rgbds_strlcpy(char *dst, const char *src, size_t dsize)
|
||||||
{
|
{
|
||||||
char *d = dst;
|
const char *osrc = src;
|
||||||
const char *s = src;
|
size_t nleft = dsize;
|
||||||
size_t n = siz;
|
|
||||||
|
|
||||||
/* Copy as many bytes as will fit */
|
/* Copy as many bytes as will fit. */
|
||||||
if (n != 0) {
|
if (nleft != 0) {
|
||||||
while (--n != 0) {
|
while (--nleft != 0) {
|
||||||
if ((*d++ = *s++) == '\0')
|
if ((*dst++ = *src++) == '\0')
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Not enough room in dst, add NUL and traverse rest of src */
|
/* Not enough room in dst, add NUL and traverse rest of src. */
|
||||||
if (n == 0) {
|
if (nleft == 0) {
|
||||||
if (siz != 0)
|
if (dsize != 0)
|
||||||
*d = '\0'; /* NUL-terminate dst */
|
*dst = '\0'; /* NUL-terminate dst */
|
||||||
while (*s++)
|
while (*src++)
|
||||||
;
|
;
|
||||||
}
|
}
|
||||||
|
|
||||||
return(s - src - 1); /* count does not include NUL */
|
return(src - osrc - 1); /* count does not include NUL */
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -23,6 +23,8 @@
|
|||||||
|
|
||||||
#include "extern/err.h"
|
#include "extern/err.h"
|
||||||
|
|
||||||
|
char *progname;
|
||||||
|
|
||||||
static void
|
static void
|
||||||
usage(void)
|
usage(void)
|
||||||
{
|
{
|
||||||
@@ -69,6 +71,8 @@ main(int argc, char *argv[])
|
|||||||
int version; /* mask ROM version number */
|
int version; /* mask ROM version number */
|
||||||
int padvalue; /* to pad the rom with if it changes size */
|
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) {
|
while ((ch = getopt(argc, argv, "Cci:jk:l:m:n:p:sr:t:v")) != -1) {
|
||||||
switch (ch) {
|
switch (ch) {
|
||||||
case 'C':
|
case 'C':
|
||||||
@@ -353,7 +357,8 @@ main(int argc, char *argv[])
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
/* We will pad the ROM to match the size given in the header. */
|
/* 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;
|
uint8_t *buf;
|
||||||
fseek(rom, 0, SEEK_END);
|
fseek(rom, 0, SEEK_END);
|
||||||
romsize = ftell(rom);
|
romsize = ftell(rom);
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
.Dd $Mdocdate$
|
.Dd February 26, 2015
|
||||||
.Dt RGBFIX 1
|
.Dt RGBFIX 1
|
||||||
.Os RGBDS Manual
|
.Os RGBDS Manual
|
||||||
.Sh NAME
|
.Sh NAME
|
||||||
@@ -41,7 +41,7 @@ flag are set,
|
|||||||
takes precedence.
|
takes precedence.
|
||||||
.It Fl i Ar game_id
|
.It Fl i Ar game_id
|
||||||
Set the game ID string
|
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.
|
to a given string of exactly 4 characters.
|
||||||
If both this and the title are set, the game ID will overwrite the
|
If both this and the title are set, the game ID will overwrite the
|
||||||
overlapping portion of the title.
|
overlapping portion of the title.
|
||||||
@@ -51,7 +51,7 @@ Set the non-Japanese region flag:
|
|||||||
= 1.
|
= 1.
|
||||||
.It Fl k Ar licensee_str
|
.It Fl k Ar licensee_str
|
||||||
Set the new licensee string
|
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.
|
to a given string, truncated to at most two characters.
|
||||||
.It Fl l Ar licensee_id
|
.It Fl l Ar licensee_id
|
||||||
Set the old licensee code,
|
Set the old licensee code,
|
||||||
@@ -84,7 +84,7 @@ Set the SGB flag:
|
|||||||
= 3.
|
= 3.
|
||||||
.It Fl t Ar title
|
.It Fl t Ar title
|
||||||
Set the title string
|
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.
|
to a given string, truncated to at most 16 characters.
|
||||||
It is recommended to use 15 characters instead, to avoid clashing with the CGB
|
It is recommended to use 15 characters instead, to avoid clashing with the CGB
|
||||||
flag
|
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.
|
overlapping portion of the title.
|
||||||
.It Fl v
|
.It Fl v
|
||||||
Validate the header and fix checksums: the Nintendo character area
|
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
|
the header checksum
|
||||||
.Pq Ad 0x14D ,
|
.Pq Ad 0x14D ,
|
||||||
and the global checksum
|
and the global checksum
|
||||||
.Pq Ad 0x14E No Ns \(en Ns Ad 0x14F .
|
.Pq Ad 0x14E Ns \(en Ns Ad 0x14F .
|
||||||
.El
|
.El
|
||||||
.Sh EXAMPLES
|
.Sh EXAMPLES
|
||||||
Most values in the ROM header are only cosmetic.
|
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
|
The following will make a plain, no-color Game Boy game without checking for
|
||||||
a valid size:
|
a valid size:
|
||||||
.Pp
|
.Pp
|
||||||
.D1 $ rgbfix \-v foo.gb
|
.D1 $ rgbfix -v foo.gb
|
||||||
.Pp
|
.Pp
|
||||||
The following will make a SGB-enabled, color-enabled game with a title of
|
The following will make a SGB-enabled, color-enabled game with a title of
|
||||||
.Dq foobar ,
|
.Dq foobar ,
|
||||||
@@ -119,19 +119,19 @@ The Game Boy itself does not use the title, but some emulators or ROM managers
|
|||||||
might.
|
might.
|
||||||
.Pc
|
.Pc
|
||||||
.Pp
|
.Pp
|
||||||
.D1 $ rgbfix \-vcs \-l 0x33 \-p 0 \-t foobar baz.gb
|
.D1 $ rgbfix -vcs -l 0x33 -p 0 -t foobar baz.gb
|
||||||
.Pp
|
.Pp
|
||||||
The following will duplicate the header
|
The following will duplicate the header
|
||||||
.Pq sans global checksum
|
.Pq sans global checksum
|
||||||
of the game
|
of the game
|
||||||
.Dq Survival Kids :
|
.Dq Survival Kids :
|
||||||
.Pp
|
.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
|
.Sh SEE ALSO
|
||||||
.Xr rgbds 7 ,
|
|
||||||
.Xr rgbasm 1 ,
|
.Xr rgbasm 1 ,
|
||||||
.Xr rgblink 1 ,
|
.Xr rgblink 1 ,
|
||||||
.Xr gbz80 7
|
.Xr rgbds 7
|
||||||
.Sh HISTORY
|
.Sh HISTORY
|
||||||
.Nm
|
.Nm
|
||||||
was originally released by Carsten S\(/orensen as a standalone program called
|
was originally released by Carsten S\(/orensen as a standalone program called
|
||||||
|
|||||||
@@ -324,6 +324,7 @@ AssignSRAMSections(void)
|
|||||||
if ((org = area_AllocSRAMAnyBank(pSection->nByteSize)) != -1) {
|
if ((org = area_AllocSRAMAnyBank(pSection->nByteSize)) != -1) {
|
||||||
pSection->nOrg = org & 0xFFFF;
|
pSection->nOrg = org & 0xFFFF;
|
||||||
pSection->nBank = org >> 16;
|
pSection->nBank = org >> 16;
|
||||||
|
pSection->nBank += BANK_SRAM;
|
||||||
pSection->oAssigned = 1;
|
pSection->oAssigned = 1;
|
||||||
DOMAXSBANK(pSection->nBank);
|
DOMAXSBANK(pSection->nBank);
|
||||||
} else {
|
} else {
|
||||||
@@ -343,6 +344,7 @@ AssignWRAMSections(void)
|
|||||||
if ((org = area_AllocWRAMAnyBank(pSection->nByteSize)) != -1) {
|
if ((org = area_AllocWRAMAnyBank(pSection->nByteSize)) != -1) {
|
||||||
pSection->nOrg = org & 0xFFFF;
|
pSection->nOrg = org & 0xFFFF;
|
||||||
pSection->nBank = org >> 16;
|
pSection->nBank = org >> 16;
|
||||||
|
pSection->nBank += BANK_WRAMX - 1;
|
||||||
pSection->oAssigned = 1;
|
pSection->oAssigned = 1;
|
||||||
DOMAXWBANK(pSection->nBank);
|
DOMAXWBANK(pSection->nBank);
|
||||||
} else {
|
} else {
|
||||||
@@ -557,8 +559,8 @@ AssignSections(void)
|
|||||||
* bank are hardcoded.
|
* bank are hardcoded.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
if (pSection->nBank >= 1
|
if (pSection->nBank >= 0
|
||||||
&& pSection->nBank <= 7) {
|
&& pSection->nBank <= 6) {
|
||||||
pSection->nBank +=
|
pSection->nBank +=
|
||||||
BANK_WRAMX;
|
BANK_WRAMX;
|
||||||
if (area_AllocAbs
|
if (area_AllocAbs
|
||||||
|
|||||||
@@ -3,7 +3,7 @@
|
|||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
#include "extern/err.h"
|
#include "extern/err.h"
|
||||||
#include "link/types.h"
|
#include "types.h"
|
||||||
#include "link/mylink.h"
|
#include "link/mylink.h"
|
||||||
#include "link/main.h"
|
#include "link/main.h"
|
||||||
|
|
||||||
|
|||||||
@@ -24,6 +24,8 @@ SLONG options = 0;
|
|||||||
SLONG fillchar = 0;
|
SLONG fillchar = 0;
|
||||||
char smartlinkstartsymbol[256];
|
char smartlinkstartsymbol[256];
|
||||||
|
|
||||||
|
char *progname;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Print the usagescreen
|
* Print the usagescreen
|
||||||
*
|
*
|
||||||
@@ -33,8 +35,8 @@ static void
|
|||||||
usage(void)
|
usage(void)
|
||||||
{
|
{
|
||||||
printf(
|
printf(
|
||||||
"usage: rgblink [-t] [-m mapfile] [-n symfile] [-o outfile] [-s symbol]\n"
|
"usage: rgblink [-t] [-m mapfile] [-n symfile] [-o outfile] [-p pad_value]\n"
|
||||||
" [-z pad_value] file [...]\n");
|
" [-s symbol] file [...]\n");
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -52,7 +54,9 @@ main(int argc, char *argv[])
|
|||||||
if (argc == 1)
|
if (argc == 1)
|
||||||
usage();
|
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) {
|
switch (ch) {
|
||||||
case 'm':
|
case 'm':
|
||||||
SetMapfileName(optarg);
|
SetMapfileName(optarg);
|
||||||
|
|||||||
@@ -53,19 +53,36 @@ MapfileInitBank(SLONG bank)
|
|||||||
{
|
{
|
||||||
if (mf) {
|
if (mf) {
|
||||||
currentbank = bank;
|
currentbank = bank;
|
||||||
if (bank == 0)
|
if (bank == BANK_ROM0)
|
||||||
fprintf(mf, "Bank #0 (HOME):\n");
|
fprintf(mf, "ROM Bank #0 (HOME):\n");
|
||||||
else if (bank < BANK_WRAM0)
|
else if (bank < BANK_WRAM0)
|
||||||
fprintf(mf, "Bank #%ld:\n", bank);
|
fprintf(mf, "ROM Bank #%ld:\n", bank);
|
||||||
else if (bank == BANK_WRAM0)
|
else if (bank == BANK_WRAM0)
|
||||||
fprintf(mf, "WRAM0:\n");
|
fprintf(mf, "WRAM Bank #0:\n");
|
||||||
|
else if (bank < BANK_VRAM)
|
||||||
|
fprintf(mf, "WRAM Bank #%ld:\n", bank - BANK_WRAMX + 1);
|
||||||
else if (bank == BANK_HRAM)
|
else if (bank == BANK_HRAM)
|
||||||
fprintf(mf, "HRAM:\n");
|
fprintf(mf, "HRAM:\n");
|
||||||
else if (bank == BANK_VRAM || bank == BANK_VRAM + 1)
|
else if (bank == BANK_VRAM || bank == BANK_VRAM + 1)
|
||||||
fprintf(mf, "VRAM Bank #%ld:\n", bank - BANK_VRAM);
|
fprintf(mf, "VRAM Bank #%ld:\n", bank - BANK_VRAM);
|
||||||
|
else if (bank < MAXBANKS)
|
||||||
|
fprintf(mf, "SRAM Bank #%ld:\n", bank - BANK_SRAM);
|
||||||
}
|
}
|
||||||
if (sf) {
|
if (sf) {
|
||||||
sfbank = (bank >= 1 && bank <= 511) ? bank : 0;
|
if (bank < BANK_WRAM0)
|
||||||
|
sfbank = bank;
|
||||||
|
else if (bank == BANK_WRAM0)
|
||||||
|
sfbank = 0;
|
||||||
|
else if (bank < BANK_VRAM)
|
||||||
|
sfbank = bank - BANK_WRAMX + 1;
|
||||||
|
else if (bank == BANK_HRAM)
|
||||||
|
sfbank = 0;
|
||||||
|
else if (bank == BANK_VRAM || bank == BANK_VRAM + 1)
|
||||||
|
sfbank = bank - BANK_VRAM;
|
||||||
|
else if (bank < MAXBANKS)
|
||||||
|
sfbank = bank - BANK_SRAM;
|
||||||
|
else
|
||||||
|
sfbank = 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -86,7 +86,7 @@ Output(void)
|
|||||||
|
|
||||||
fclose(f);
|
fclose(f);
|
||||||
}
|
}
|
||||||
for (i = 256; i < MAXBANKS; i += 1) {
|
for (i = BANK_WRAM0; i < MAXBANKS; i++) {
|
||||||
struct sSection *pSect;
|
struct sSection *pSect;
|
||||||
MapfileInitBank(i);
|
MapfileInitBank(i);
|
||||||
pSect = pSections;
|
pSect = pSections;
|
||||||
|
|||||||
@@ -3,6 +3,7 @@
|
|||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
#include "extern/err.h"
|
#include "extern/err.h"
|
||||||
|
#include "link/assign.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"
|
||||||
@@ -53,20 +54,30 @@ getsymvalue(SLONG symid)
|
|||||||
SLONG
|
SLONG
|
||||||
getsymbank(SLONG symid)
|
getsymbank(SLONG symid)
|
||||||
{
|
{
|
||||||
|
SLONG nBank;
|
||||||
|
|
||||||
switch (pCurrentSection->tSymbols[symid]->Type) {
|
switch (pCurrentSection->tSymbols[symid]->Type) {
|
||||||
case SYM_IMPORT:
|
case SYM_IMPORT:
|
||||||
return (sym_GetBank(pCurrentSection->tSymbols[symid]->pzName));
|
nBank = sym_GetBank(pCurrentSection->tSymbols[symid]->pzName);
|
||||||
break;
|
break;
|
||||||
case SYM_EXPORT:
|
case SYM_EXPORT:
|
||||||
case SYM_LOCAL:
|
case SYM_LOCAL:
|
||||||
return (pCurrentSection->tSymbols[symid]->pSection->nBank);
|
nBank = pCurrentSection->tSymbols[symid]->pSection->nBank;
|
||||||
//return (pCurrentSection->nBank);
|
|
||||||
default:
|
|
||||||
break;
|
break;
|
||||||
}
|
default:
|
||||||
errx(1, "*INTERNAL* UNKNOWN SYMBOL TYPE");
|
errx(1, "*INTERNAL* UNKNOWN SYMBOL TYPE");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (nBank >= BANK_WRAMX && nBank <= (BANK_WRAMX+6))
|
||||||
|
return nBank - BANK_WRAMX + 1;
|
||||||
|
if (nBank >= BANK_VRAM && nBank <= (BANK_VRAM+1))
|
||||||
|
return nBank - BANK_VRAM;
|
||||||
|
if (nBank >= BANK_SRAM && nBank <= (BANK_SRAM+3))
|
||||||
|
return nBank - BANK_SRAM;
|
||||||
|
|
||||||
|
return nBank;
|
||||||
|
}
|
||||||
|
|
||||||
SLONG
|
SLONG
|
||||||
calcrpn(struct sPatch * pPatch)
|
calcrpn(struct sPatch * pPatch)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
.Dd $Mdocdate$
|
.Dd February 26, 2015
|
||||||
.Dt RGBLINK 1
|
.Dt RGBLINK 1
|
||||||
.Os RGBDS Manual
|
.Os RGBDS Manual
|
||||||
.Sh NAME
|
.Sh NAME
|
||||||
@@ -7,7 +7,6 @@
|
|||||||
.Sh SYNOPSIS
|
.Sh SYNOPSIS
|
||||||
.Nm rgblink
|
.Nm rgblink
|
||||||
.Op Fl t
|
.Op Fl t
|
||||||
.Op Fl l Ar library
|
|
||||||
.Op Fl m Ar mapfile
|
.Op Fl m Ar mapfile
|
||||||
.Op Fl n Ar symfile
|
.Op Fl n Ar symfile
|
||||||
.Op Fl o Ar outfile
|
.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
|
All you need for a basic ROM is an object file, which can be made into a ROM
|
||||||
image like so:
|
image like so:
|
||||||
.Pp
|
.Pp
|
||||||
.D1 $ rgblink \-o bar.gb foo.o
|
.D1 $ rgblink -o bar.gb foo.o
|
||||||
.Pp
|
.Pp
|
||||||
The resulting bar.gb will not have correct checksums
|
The resulting bar.gb will not have correct checksums
|
||||||
.Pq unless you put them in the assembly source .
|
.Pq unless you put them in the assembly source .
|
||||||
@@ -59,12 +58,11 @@ You should use
|
|||||||
.Xr rgbfix 1
|
.Xr rgbfix 1
|
||||||
to fix these so that the program will actually run in a Game Boy:
|
to fix these so that the program will actually run in a Game Boy:
|
||||||
.Pp
|
.Pp
|
||||||
.D1 $ rgbfix \-v bar.gb
|
.D1 $ rgbfix -v bar.gb
|
||||||
.Sh SEE ALSO
|
.Sh SEE ALSO
|
||||||
.Xr rgbds 7 ,
|
|
||||||
.Xr rgbasm 1 ,
|
.Xr rgbasm 1 ,
|
||||||
.Xr rgbfix 1 ,
|
.Xr rgbfix 1 ,
|
||||||
.Xr gbz80 7
|
.Xr rgbds 7
|
||||||
.Sh HISTORY
|
.Sh HISTORY
|
||||||
.Nm
|
.Nm
|
||||||
was originally written by Carsten S\(/orensen as part of the ASMotor package,
|
was originally written by Carsten S\(/orensen as part of the ASMotor package,
|
||||||
|
|||||||
@@ -5,7 +5,7 @@
|
|||||||
#include "extern/err.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 "types.h"
|
||||||
|
|
||||||
#define HASHSIZE 73
|
#define HASHSIZE 73
|
||||||
|
|
||||||
@@ -76,7 +76,7 @@ sym_GetBank(char *tzName)
|
|||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
sym_CreateSymbol(char *tzName, SLONG nValue, SBYTE nBank)
|
sym_CreateSymbol(char *tzName, SLONG nValue, SLONG nBank)
|
||||||
{
|
{
|
||||||
if (strcmp(tzName, "@") == 0)
|
if (strcmp(tzName, "@") == 0)
|
||||||
return;
|
return;
|
||||||
|
|||||||
2
test/asm/bank-noexist.asm
Normal file
2
test/asm/bank-noexist.asm
Normal file
@@ -0,0 +1,2 @@
|
|||||||
|
SECTION "sec", ROM0
|
||||||
|
db BANK(noexist)
|
||||||
2
test/asm/bank-noexist.out
Normal file
2
test/asm/bank-noexist.out
Normal file
@@ -0,0 +1,2 @@
|
|||||||
|
ERROR: bank-noexist.asm(2) :
|
||||||
|
'noexist' not defined
|
||||||
2
test/asm/divzero-instr.asm
Normal file
2
test/asm/divzero-instr.asm
Normal file
@@ -0,0 +1,2 @@
|
|||||||
|
SECTION "sec", ROM0
|
||||||
|
ld a, 1/0
|
||||||
2
test/asm/divzero-instr.out
Normal file
2
test/asm/divzero-instr.out
Normal file
@@ -0,0 +1,2 @@
|
|||||||
|
ERROR: divzero-instr.asm(2) :
|
||||||
|
division by zero
|
||||||
1
test/asm/divzero-section-bank.asm
Normal file
1
test/asm/divzero-section-bank.asm
Normal file
@@ -0,0 +1 @@
|
|||||||
|
SECTION "sec", ROMX[$/0]
|
||||||
2
test/asm/divzero-section-bank.out
Normal file
2
test/asm/divzero-section-bank.out
Normal file
@@ -0,0 +1,2 @@
|
|||||||
|
ERROR: divzero-section-bank.asm(1) :
|
||||||
|
division by zero
|
||||||
1
test/asm/macro-@.asm
Normal file
1
test/asm/macro-@.asm
Normal file
@@ -0,0 +1 @@
|
|||||||
|
foo @bar
|
||||||
2
test/asm/macro-@.out
Normal file
2
test/asm/macro-@.out
Normal file
@@ -0,0 +1,2 @@
|
|||||||
|
ERROR: macro-@.asm(1) -> @(-1) :
|
||||||
|
Macro '@' not defined
|
||||||
BIN
test/asm/null-in-macro.asm
Normal file
BIN
test/asm/null-in-macro.asm
Normal file
Binary file not shown.
0
test/asm/null-in-macro.out
Normal file
0
test/asm/null-in-macro.out
Normal file
6
test/asm/test.sh
Normal file
6
test/asm/test.sh
Normal file
@@ -0,0 +1,6 @@
|
|||||||
|
fname=$(mktemp)
|
||||||
|
|
||||||
|
for i in *.asm; do
|
||||||
|
../../rgbasm $i >$fname 2>&1
|
||||||
|
diff -u $fname ${i%.asm}.out
|
||||||
|
done
|
||||||
3
test/asm/undefined-dot.asm
Normal file
3
test/asm/undefined-dot.asm
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
SECTION "sec", ROM0
|
||||||
|
foo:
|
||||||
|
add sp, .
|
||||||
2
test/asm/undefined-dot.out
Normal file
2
test/asm/undefined-dot.out
Normal file
@@ -0,0 +1,2 @@
|
|||||||
|
ERROR: undefined-dot.asm(3) :
|
||||||
|
'.' not defined
|
||||||
36
test/link/ram-bank-numbers.asm
Normal file
36
test/link/ram-bank-numbers.asm
Normal file
@@ -0,0 +1,36 @@
|
|||||||
|
; this should generate a rom consisting of the following bytes:
|
||||||
|
; 01 02 03 04 05 06 07 00 01 02 03 00 01
|
||||||
|
|
||||||
|
section "x",rom0
|
||||||
|
db bank(w1),bank(w2),bank(w3),bank(w4),bank(w5),bank(w6),bank(w7)
|
||||||
|
db bank(s0),bank(s1),bank(s2),bank(s3)
|
||||||
|
db bank(v0),bank(v1)
|
||||||
|
|
||||||
|
section "wa",wramx,bank[1]
|
||||||
|
w1:
|
||||||
|
section "wb",wramx,bank[2]
|
||||||
|
w2:
|
||||||
|
section "wc",wramx,bank[3]
|
||||||
|
w3:
|
||||||
|
section "wd",wramx,bank[4]
|
||||||
|
w4:
|
||||||
|
section "we",wramx,bank[5]
|
||||||
|
w5:
|
||||||
|
section "wf",wramx,bank[6]
|
||||||
|
w6:
|
||||||
|
section "wg",wramx,bank[7]
|
||||||
|
w7:
|
||||||
|
|
||||||
|
section "sa",sram,bank[0]
|
||||||
|
s0:
|
||||||
|
section "sb",sram,bank[1]
|
||||||
|
s1:
|
||||||
|
section "sc",sram,bank[2]
|
||||||
|
s2:
|
||||||
|
section "sd",sram,bank[3]
|
||||||
|
s3:
|
||||||
|
|
||||||
|
section "v00",vram,bank[0]
|
||||||
|
v0:
|
||||||
|
section "v01",vram,bank[1]
|
||||||
|
v1:
|
||||||
Reference in New Issue
Block a user