mirror of
https://github.com/gbdev/rgbds.git
synced 2025-11-20 18:22:07 +00:00
Now that we replace missing libc functions, switch back to err().
This commit is contained in:
10
Makefile
10
Makefile
@@ -23,12 +23,14 @@ rgbasm_obj := \
|
|||||||
src/asm/rpn.o \
|
src/asm/rpn.o \
|
||||||
src/asm/symbol.o \
|
src/asm/symbol.o \
|
||||||
src/asm/gameboy/locallex.o \
|
src/asm/gameboy/locallex.o \
|
||||||
|
src/extern/err.o \
|
||||||
src/extern/strlcpy.o \
|
src/extern/strlcpy.o \
|
||||||
src/extern/strlcat.o
|
src/extern/strlcat.o
|
||||||
|
|
||||||
rgblib_obj := \
|
rgblib_obj := \
|
||||||
src/lib/library.o \
|
src/lib/library.o \
|
||||||
src/lib/main.o
|
src/lib/main.o \
|
||||||
|
src/extern/err.o
|
||||||
|
|
||||||
rgblink_obj := \
|
rgblink_obj := \
|
||||||
src/link/assign.o \
|
src/link/assign.o \
|
||||||
@@ -38,10 +40,12 @@ rgblink_obj := \
|
|||||||
src/link/object.o \
|
src/link/object.o \
|
||||||
src/link/output.o \
|
src/link/output.o \
|
||||||
src/link/patch.o \
|
src/link/patch.o \
|
||||||
src/link/symbol.o
|
src/link/symbol.o \
|
||||||
|
src/extern/err.o
|
||||||
|
|
||||||
rgbfix_obj := \
|
rgbfix_obj := \
|
||||||
src/fix/main.o
|
src/fix/main.o \
|
||||||
|
src/extern/err.o
|
||||||
|
|
||||||
all: rgbasm rgblib rgblink rgbfix
|
all: rgbasm rgblib rgblink rgbfix
|
||||||
|
|
||||||
|
|||||||
63
include/extern/err.h
vendored
Normal file
63
include/extern/err.h
vendored
Normal file
@@ -0,0 +1,63 @@
|
|||||||
|
/*
|
||||||
|
* Copyright © 2005-2013 Rich Felker, et al.
|
||||||
|
*
|
||||||
|
* Permission is hereby granted, free of charge, to any person obtaining
|
||||||
|
* a copy of this software and associated documentation files (the
|
||||||
|
* "Software"), to deal in the Software without restriction, including
|
||||||
|
* without limitation the rights to use, copy, modify, merge, publish,
|
||||||
|
* distribute, sublicense, and/or sell copies of the Software, and to
|
||||||
|
* permit persons to whom the Software is furnished to do so, subject to
|
||||||
|
* the following conditions:
|
||||||
|
*
|
||||||
|
* The above copyright notice and this permission notice shall be
|
||||||
|
* included in all copies or substantial portions of the Software.
|
||||||
|
*
|
||||||
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||||
|
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||||
|
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
||||||
|
* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
||||||
|
* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
||||||
|
* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
||||||
|
* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef EXTERN_ERR_H
|
||||||
|
#define EXTERN_ERR_H
|
||||||
|
|
||||||
|
#ifdef ERR_IN_LIBC
|
||||||
|
#include <err.h>
|
||||||
|
#else
|
||||||
|
|
||||||
|
#include <stdarg.h>
|
||||||
|
|
||||||
|
#define warn rgbds_warn
|
||||||
|
#define vwarn rgbds_vwarn
|
||||||
|
#define warnx rgbds_warnx
|
||||||
|
#define vwarnx rgbds_vwarnx
|
||||||
|
|
||||||
|
#define err rgbds_err
|
||||||
|
#define verr rgbds_verr
|
||||||
|
#define errx rgbds_errx
|
||||||
|
#define verrx rgbds_verrx
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
extern "C" {
|
||||||
|
#endif
|
||||||
|
|
||||||
|
void warn(const char *, ...);
|
||||||
|
void vwarn(const char *, va_list);
|
||||||
|
void warnx(const char *, ...);
|
||||||
|
void vwarnx(const char *, va_list);
|
||||||
|
|
||||||
|
void err(int, const char *, ...);
|
||||||
|
void verr(int, const char *, va_list);
|
||||||
|
void errx(int, const char *, ...);
|
||||||
|
void verrx(int, const char *, va_list);
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#endif
|
||||||
13
include/extern/strl.h
vendored
Normal file
13
include/extern/strl.h
vendored
Normal file
@@ -0,0 +1,13 @@
|
|||||||
|
#ifndef STRL_H
|
||||||
|
#define STRL_H
|
||||||
|
|
||||||
|
#ifdef STRL_IN_LIBC
|
||||||
|
#include <string.h>
|
||||||
|
#else
|
||||||
|
#define strlcpy rgbds_strlcpy
|
||||||
|
#define strlcat rgbds_strlcat
|
||||||
|
size_t strlcpy(char *, const char *, size_t);
|
||||||
|
size_t strlcat(char *, const char *, size_t);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#endif
|
||||||
@@ -11,18 +11,13 @@
|
|||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
#ifndef STRL_IN_LIBC
|
|
||||||
#define strlcpy rgbds_strlcpy
|
|
||||||
#define strlcat rgbds_strlcat
|
|
||||||
size_t strlcpy(char *, const char *, size_t);
|
|
||||||
size_t strlcat(char *, const char *, size_t);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#include "asm/symbol.h"
|
#include "asm/symbol.h"
|
||||||
#include "asm/fstack.h"
|
#include "asm/fstack.h"
|
||||||
#include "asm/types.h"
|
#include "asm/types.h"
|
||||||
#include "asm/main.h"
|
#include "asm/main.h"
|
||||||
#include "asm/lexer.h"
|
#include "asm/lexer.h"
|
||||||
|
#include "extern/err.h"
|
||||||
|
#include "extern/strl.h"
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* RGBAsm - FSTACK.C (FileStack routines)
|
* RGBAsm - FSTACK.C (FileStack routines)
|
||||||
@@ -245,10 +240,8 @@ fstk_RunInclude(char *tzFileName)
|
|||||||
f = fstk_FindFile(tzFileName);
|
f = fstk_FindFile(tzFileName);
|
||||||
|
|
||||||
if (f == NULL) {
|
if (f == NULL) {
|
||||||
fprintf(stderr, "Unable to open included file '%s': ",
|
err(1, "Unable to open included file '%s'",
|
||||||
tzFileName);
|
tzFileName);
|
||||||
perror(NULL);
|
|
||||||
exit(1);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pushcontext();
|
pushcontext();
|
||||||
@@ -357,10 +350,7 @@ fstk_Init(char *s)
|
|||||||
pFileStack = NULL;
|
pFileStack = NULL;
|
||||||
pCurrentFile = fopen(tzFileName, "rb");
|
pCurrentFile = fopen(tzFileName, "rb");
|
||||||
if (pCurrentFile == NULL) {
|
if (pCurrentFile == NULL) {
|
||||||
fprintf(stderr, "Unable to open file '%s': ",
|
err(1, "Unable to open file '%s'", tzFileName);
|
||||||
tzFileName);
|
|
||||||
perror(NULL);
|
|
||||||
exit(1);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
nMacroCount = 0;
|
nMacroCount = 0;
|
||||||
|
|||||||
@@ -4,6 +4,7 @@
|
|||||||
#include "asm/main.h"
|
#include "asm/main.h"
|
||||||
#include "asm/rpn.h"
|
#include "asm/rpn.h"
|
||||||
#include "asm/fstack.h"
|
#include "asm/fstack.h"
|
||||||
|
#include "extern/err.h"
|
||||||
|
|
||||||
#include "asmy.h"
|
#include "asmy.h"
|
||||||
|
|
||||||
@@ -213,9 +214,8 @@ void
|
|||||||
lex_CheckCharacterRange(UWORD start, UWORD end)
|
lex_CheckCharacterRange(UWORD start, UWORD end)
|
||||||
{
|
{
|
||||||
if (start > end || start < 1 || end > 127) {
|
if (start > end || start < 1 || end > 127) {
|
||||||
fprintf(stderr, "Invalid character range (start: %u, end: %u)\n",
|
errx(1, "Invalid character range (start: %u, end: %u)",
|
||||||
start, end);
|
start, end);
|
||||||
exit(1);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -344,8 +344,6 @@ lex_AddStrings(struct sLexInitString * lex)
|
|||||||
while (*ppHash)
|
while (*ppHash)
|
||||||
ppHash = &((*ppHash)->pNext);
|
ppHash = &((*ppHash)->pNext);
|
||||||
|
|
||||||
//printf("%s has hashvalue %d\n", lex->tzName, hash);
|
|
||||||
|
|
||||||
if (((*ppHash) =
|
if (((*ppHash) =
|
||||||
(struct sLexString *) malloc(sizeof(struct sLexString))) !=
|
(struct sLexString *) malloc(sizeof(struct sLexString))) !=
|
||||||
NULL) {
|
NULL) {
|
||||||
|
|||||||
@@ -19,6 +19,7 @@
|
|||||||
#include "asm/fstack.h"
|
#include "asm/fstack.h"
|
||||||
#include "asm/output.h"
|
#include "asm/output.h"
|
||||||
#include "asm/main.h"
|
#include "asm/main.h"
|
||||||
|
#include "extern/err.h"
|
||||||
|
|
||||||
int yyparse(void);
|
int yyparse(void);
|
||||||
void setuplex(void);
|
void setuplex(void);
|
||||||
@@ -133,9 +134,8 @@ opt_Parse(char *s)
|
|||||||
newopt.gbgfx[2] = s[3];
|
newopt.gbgfx[2] = s[3];
|
||||||
newopt.gbgfx[3] = s[4];
|
newopt.gbgfx[3] = s[4];
|
||||||
} else {
|
} else {
|
||||||
fprintf(stderr, "Must specify exactly 4 characters "
|
errx(1, "Must specify exactly 4 characters for "
|
||||||
"for option 'g'\n");
|
"option 'g'");
|
||||||
exit(1);
|
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case 'b':
|
case 'b':
|
||||||
@@ -143,9 +143,8 @@ opt_Parse(char *s)
|
|||||||
newopt.binary[0] = s[1];
|
newopt.binary[0] = s[1];
|
||||||
newopt.binary[1] = s[2];
|
newopt.binary[1] = s[2];
|
||||||
} else {
|
} else {
|
||||||
fprintf(stderr, "Must specify exactly 2 characters "
|
errx(1, "Must specify exactly 2 characters for option "
|
||||||
"for option 'b'\n");
|
"'b'");
|
||||||
exit(1);
|
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case 'z':
|
case 'z':
|
||||||
@@ -154,12 +153,10 @@ opt_Parse(char *s)
|
|||||||
|
|
||||||
result = sscanf(&s[1], "%lx", &newopt.fillchar);
|
result = sscanf(&s[1], "%lx", &newopt.fillchar);
|
||||||
if (!((result == EOF) || (result == 1))) {
|
if (!((result == EOF) || (result == 1))) {
|
||||||
fprintf(stderr,
|
errx(1, "Invalid argument for option 'z'");
|
||||||
"Invalid argument for option 'z'\n");
|
|
||||||
exit(1);
|
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
fprintf(stderr, "Invalid argument for option 'z'\n");
|
errx(1, "Invalid argument for option 'z'");
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
@@ -295,9 +292,8 @@ main(int argc, char *argv[])
|
|||||||
newopt.binary[0] = optarg[1];
|
newopt.binary[0] = optarg[1];
|
||||||
newopt.binary[1] = optarg[2];
|
newopt.binary[1] = optarg[2];
|
||||||
} else {
|
} else {
|
||||||
fprintf(stderr, "Must specify exactly "
|
errx(1, "Must specify exactly 2 characters for "
|
||||||
"2 characters for option 'b'\n");
|
"option 'b'");
|
||||||
exit(1);
|
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case 'g':
|
case 'g':
|
||||||
@@ -307,9 +303,8 @@ main(int argc, char *argv[])
|
|||||||
newopt.gbgfx[2] = optarg[3];
|
newopt.gbgfx[2] = optarg[3];
|
||||||
newopt.gbgfx[3] = optarg[4];
|
newopt.gbgfx[3] = optarg[4];
|
||||||
} else {
|
} else {
|
||||||
fprintf(stderr, "Must specify exactly "
|
errx(1, "Must specify exactly 4 characters for "
|
||||||
"4 characters for option 'g'\n");
|
"option 'g'");
|
||||||
exit(1);
|
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case 'h':
|
case 'h':
|
||||||
@@ -324,14 +319,11 @@ main(int argc, char *argv[])
|
|||||||
case 'p':
|
case 'p':
|
||||||
newopt.fillchar = strtoul(optarg, &ep, 0);
|
newopt.fillchar = strtoul(optarg, &ep, 0);
|
||||||
if (optarg[0] == '\0' || *ep != '\0') {
|
if (optarg[0] == '\0' || *ep != '\0') {
|
||||||
fprintf(stderr,
|
errx(1, "Invalid argument for option 'p'");
|
||||||
"Invalid argument for option 'p'\n");
|
|
||||||
exit(1);
|
|
||||||
}
|
}
|
||||||
if (newopt.fillchar < 0 || newopt.fillchar > 0xFF) {
|
if (newopt.fillchar < 0 || newopt.fillchar > 0xFF) {
|
||||||
fprintf(stderr, "Argument for option 'p' "
|
errx(1, "Argument for option 'p' must be "
|
||||||
"must be between 0 and 0xFF\n");
|
"between 0 and 0xFF");
|
||||||
exit(1);
|
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case 'v':
|
case 'v':
|
||||||
@@ -420,16 +412,12 @@ main(int argc, char *argv[])
|
|||||||
exit(5);
|
exit(5);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
fprintf(stderr,
|
errx(1, "Unterminated IF construct (%ld levels)!",
|
||||||
"Unterminated IF construct (%ld levels)!\n",
|
|
||||||
nIFDepth);
|
nIFDepth);
|
||||||
exit(1);
|
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
fprintf(stderr,
|
errx(1, "Assembly aborted in pass 1 (%ld errors)!",
|
||||||
"Assembly aborted in pass 1 (%ld errors)!\n",
|
|
||||||
nErrors);
|
nErrors);
|
||||||
exit(1);
|
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -17,6 +17,7 @@
|
|||||||
#include "asm/main.h"
|
#include "asm/main.h"
|
||||||
#include "asm/rpn.h"
|
#include "asm/rpn.h"
|
||||||
#include "asm/fstack.h"
|
#include "asm/fstack.h"
|
||||||
|
#include "extern/err.h"
|
||||||
|
|
||||||
#define SECTIONCHUNK 0x4000
|
#define SECTIONCHUNK 0x4000
|
||||||
|
|
||||||
@@ -909,10 +910,7 @@ out_BinaryFile(char *s)
|
|||||||
|
|
||||||
f = fstk_FindFile(s);
|
f = fstk_FindFile(s);
|
||||||
if (f == NULL) {
|
if (f == NULL) {
|
||||||
fprintf(stderr, "Unable to open incbin file '%s': ",
|
err(1, "Unable to open incbin file '%s'", s);
|
||||||
s);
|
|
||||||
perror(NULL);
|
|
||||||
exit(1);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
SLONG fsize;
|
SLONG fsize;
|
||||||
@@ -949,10 +947,7 @@ out_BinaryFileSlice(char *s, SLONG start_pos, SLONG length)
|
|||||||
|
|
||||||
f = fstk_FindFile(s);
|
f = fstk_FindFile(s);
|
||||||
if (f == NULL) {
|
if (f == NULL) {
|
||||||
fprintf(stderr, "Unable to open included file '%s': ",
|
err(1, "Unable to open included file '%s'", s);
|
||||||
s);
|
|
||||||
perror(NULL);
|
|
||||||
exit(1);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
SLONG fsize;
|
SLONG fsize;
|
||||||
|
|||||||
90
src/extern/err.c
vendored
Normal file
90
src/extern/err.c
vendored
Normal file
@@ -0,0 +1,90 @@
|
|||||||
|
/*
|
||||||
|
* Copyright © 2005-2013 Rich Felker, et al.
|
||||||
|
*
|
||||||
|
* Permission is hereby granted, free of charge, to any person obtaining
|
||||||
|
* a copy of this software and associated documentation files (the
|
||||||
|
* "Software"), to deal in the Software without restriction, including
|
||||||
|
* without limitation the rights to use, copy, modify, merge, publish,
|
||||||
|
* distribute, sublicense, and/or sell copies of the Software, and to
|
||||||
|
* permit persons to whom the Software is furnished to do so, subject to
|
||||||
|
* the following conditions:
|
||||||
|
*
|
||||||
|
* The above copyright notice and this permission notice shall be
|
||||||
|
* included in all copies or substantial portions of the Software.
|
||||||
|
*
|
||||||
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||||
|
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||||
|
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
||||||
|
* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
||||||
|
* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
||||||
|
* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
||||||
|
* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <err.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <stdarg.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
|
||||||
|
extern char *__progname;
|
||||||
|
|
||||||
|
void rgbds_vwarn(const char *fmt, va_list ap)
|
||||||
|
{
|
||||||
|
fprintf (stderr, "%s: ", __progname);
|
||||||
|
if (fmt) {
|
||||||
|
vfprintf(stderr, fmt, ap);
|
||||||
|
fputs (": ", stderr);
|
||||||
|
}
|
||||||
|
perror(0);
|
||||||
|
}
|
||||||
|
|
||||||
|
void rgbds_vwarnx(const char *fmt, va_list ap)
|
||||||
|
{
|
||||||
|
fprintf (stderr, "%s: ", __progname);
|
||||||
|
if (fmt) vfprintf(stderr, fmt, ap);
|
||||||
|
putc('\n', stderr);
|
||||||
|
}
|
||||||
|
|
||||||
|
void rgbds_verr(int status, const char *fmt, va_list ap)
|
||||||
|
{
|
||||||
|
vwarn(fmt, ap);
|
||||||
|
exit(status);
|
||||||
|
}
|
||||||
|
|
||||||
|
void rgbds_verrx(int status, const char *fmt, va_list ap)
|
||||||
|
{
|
||||||
|
vwarnx(fmt, ap);
|
||||||
|
exit(status);
|
||||||
|
}
|
||||||
|
|
||||||
|
void rgbds_warn(const char *fmt, ...)
|
||||||
|
{
|
||||||
|
va_list ap;
|
||||||
|
va_start(ap, fmt);
|
||||||
|
vwarn(fmt, ap);
|
||||||
|
va_end(ap);
|
||||||
|
}
|
||||||
|
|
||||||
|
void rgbds_warnx(const char *fmt, ...)
|
||||||
|
{
|
||||||
|
va_list ap;
|
||||||
|
va_start(ap, fmt);
|
||||||
|
vwarnx(fmt, ap);
|
||||||
|
va_end(ap);
|
||||||
|
}
|
||||||
|
|
||||||
|
void rgbds_err(int status, const char *fmt, ...)
|
||||||
|
{
|
||||||
|
va_list ap;
|
||||||
|
va_start(ap, fmt);
|
||||||
|
verr(status, fmt, ap);
|
||||||
|
va_end(ap);
|
||||||
|
}
|
||||||
|
|
||||||
|
void rgbds_errx(int status, const char *fmt, ...)
|
||||||
|
{
|
||||||
|
va_list ap;
|
||||||
|
va_start(ap, fmt);
|
||||||
|
verrx(status, fmt, ap);
|
||||||
|
va_end(ap);
|
||||||
|
}
|
||||||
@@ -22,6 +22,8 @@
|
|||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
|
|
||||||
|
#include "extern/err.h"
|
||||||
|
|
||||||
static void
|
static void
|
||||||
usage(void)
|
usage(void)
|
||||||
{
|
{
|
||||||
@@ -47,9 +49,7 @@ main(int argc, char *argv[])
|
|||||||
usage();
|
usage();
|
||||||
|
|
||||||
if ((rom = fopen(argv[argc - 1], "rb+")) == NULL) {
|
if ((rom = fopen(argv[argc - 1], "rb+")) == NULL) {
|
||||||
fprintf(stderr, "Error opening file %s: \n", argv[argc - 1]);
|
err(1, "Error opening file %s", argv[argc - 1]);
|
||||||
perror(NULL);
|
|
||||||
exit(1);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@@ -93,9 +93,8 @@ main(int argc, char *argv[])
|
|||||||
setid = true;
|
setid = true;
|
||||||
|
|
||||||
if (strlen(optarg) != 4) {
|
if (strlen(optarg) != 4) {
|
||||||
fprintf(stderr, "Game ID %s must be exactly 4 "
|
errx(1, "Game ID %s must be exactly 4 "
|
||||||
"characters\n", optarg);
|
"characters", optarg);
|
||||||
exit(1);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
id = optarg;
|
id = optarg;
|
||||||
@@ -107,10 +106,8 @@ main(int argc, char *argv[])
|
|||||||
setnewlicensee = true;
|
setnewlicensee = true;
|
||||||
|
|
||||||
if (strlen(optarg) != 2) {
|
if (strlen(optarg) != 2) {
|
||||||
fprintf(stderr,
|
errx(1, "New licensee code %s is not the "
|
||||||
"New licensee code %s is not the correct "
|
"correct length of 2 characters", optarg);
|
||||||
"length of 2 characters\n", optarg);
|
|
||||||
exit(1);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
newlicensee = optarg;
|
newlicensee = optarg;
|
||||||
@@ -120,15 +117,11 @@ main(int argc, char *argv[])
|
|||||||
|
|
||||||
licensee = strtoul(optarg, &ep, 0);
|
licensee = strtoul(optarg, &ep, 0);
|
||||||
if (optarg[0] == '\0' || *ep != '\0') {
|
if (optarg[0] == '\0' || *ep != '\0') {
|
||||||
fprintf(stderr,
|
errx(1, "Invalid argument for option 'l'");
|
||||||
"Invalid argument for option 'l'\n");
|
|
||||||
exit(1);
|
|
||||||
}
|
}
|
||||||
if (licensee < 0 || licensee > 0xFF) {
|
if (licensee < 0 || licensee > 0xFF) {
|
||||||
fprintf(stderr,
|
errx(1, "Argument for option 'l' must be "
|
||||||
"Argument for option 'l' must be "
|
"between 0 and 255");
|
||||||
"between 0 and 255\n");
|
|
||||||
exit(1);
|
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case 'm':
|
case 'm':
|
||||||
@@ -136,15 +129,11 @@ main(int argc, char *argv[])
|
|||||||
|
|
||||||
cartridge = strtoul(optarg, &ep, 0);
|
cartridge = strtoul(optarg, &ep, 0);
|
||||||
if (optarg[0] == '\0' || *ep != '\0') {
|
if (optarg[0] == '\0' || *ep != '\0') {
|
||||||
fprintf(stderr,
|
errx(1, "Invalid argument for option 'm'");
|
||||||
"Invalid argument for option 'm'\n");
|
|
||||||
exit(1);
|
|
||||||
}
|
}
|
||||||
if (cartridge < 0 || cartridge > 0xFF) {
|
if (cartridge < 0 || cartridge > 0xFF) {
|
||||||
fprintf(stderr,
|
errx(1, "Argument for option 'm' must be "
|
||||||
"Argument for option 'm' must be "
|
"between 0 and 255");
|
||||||
"between 0 and 255\n");
|
|
||||||
exit(1);
|
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case 'n':
|
case 'n':
|
||||||
@@ -152,15 +141,11 @@ main(int argc, char *argv[])
|
|||||||
|
|
||||||
version = strtoul(optarg, &ep, 0);
|
version = strtoul(optarg, &ep, 0);
|
||||||
if (optarg[0] == '\0' || *ep != '\0') {
|
if (optarg[0] == '\0' || *ep != '\0') {
|
||||||
fprintf(stderr,
|
errx(1, "Invalid argument for option 'n'");
|
||||||
"Invalid argument for option 'n'\n");
|
|
||||||
exit(1);
|
|
||||||
}
|
}
|
||||||
if (version < 0 || version > 0xFF) {
|
if (version < 0 || version > 0xFF) {
|
||||||
fprintf(stderr,
|
errx(1, "Argument for option 'n' must be "
|
||||||
"Argument for option 'n' must be "
|
"between 0 and 255");
|
||||||
"between 0 and 255\n");
|
|
||||||
exit(1);
|
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case 'p':
|
case 'p':
|
||||||
@@ -168,15 +153,11 @@ main(int argc, char *argv[])
|
|||||||
|
|
||||||
padvalue = strtoul(optarg, &ep, 0);
|
padvalue = strtoul(optarg, &ep, 0);
|
||||||
if (optarg[0] == '\0' || *ep != '\0') {
|
if (optarg[0] == '\0' || *ep != '\0') {
|
||||||
fprintf(stderr,
|
errx(1, "Invalid argument for option 'p'");
|
||||||
"Invalid argument for option 'p'\n");
|
|
||||||
exit(1);
|
|
||||||
}
|
}
|
||||||
if (padvalue < 0 || padvalue > 0xFF) {
|
if (padvalue < 0 || padvalue > 0xFF) {
|
||||||
fprintf(stderr,
|
errx(1, "Argument for option 'p' must be "
|
||||||
"Argument for option 'p' must be "
|
"between 0 and 255");
|
||||||
"between 0 and 255\n");
|
|
||||||
exit(1);
|
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case 'r':
|
case 'r':
|
||||||
@@ -184,14 +165,11 @@ main(int argc, char *argv[])
|
|||||||
|
|
||||||
ramsize = strtoul(optarg, &ep, 0);
|
ramsize = strtoul(optarg, &ep, 0);
|
||||||
if (optarg[0] == '\0' || *ep != '\0') {
|
if (optarg[0] == '\0' || *ep != '\0') {
|
||||||
fprintf(stderr,
|
errx(1, "Invalid argument for option 'r'");
|
||||||
"Invalid argument for option 'r'\n");
|
|
||||||
}
|
}
|
||||||
if (ramsize < 0 || ramsize > 0xFF) {
|
if (ramsize < 0 || ramsize > 0xFF) {
|
||||||
fprintf(stderr,
|
errx(1, "Argument for option 'r' must be "
|
||||||
"Argument for option 'r' must be "
|
"between 0 and 255");
|
||||||
"between 0 and 255\n");
|
|
||||||
exit(1);
|
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case 's':
|
case 's':
|
||||||
@@ -201,15 +179,13 @@ main(int argc, char *argv[])
|
|||||||
settitle = true;
|
settitle = true;
|
||||||
|
|
||||||
if (strlen(optarg) > 16) {
|
if (strlen(optarg) > 16) {
|
||||||
fprintf(stderr, "Title %s is greater than the "
|
errx(1, "Title %s is greater than the "
|
||||||
"maximum of 16 characters\n", optarg);
|
"maximum of 16 characters", optarg);
|
||||||
exit(1);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (strlen(optarg) == 16)
|
if (strlen(optarg) == 16)
|
||||||
fprintf(stderr,
|
warnx("Title %s is 16 chars, it is best to "
|
||||||
"Title %s is 16 chars, it is best "
|
"keep it to 15 or fewer", optarg);
|
||||||
"to keep it to 15 or fewer\n", optarg);
|
|
||||||
|
|
||||||
title = optarg;
|
title = optarg;
|
||||||
break;
|
break;
|
||||||
@@ -313,8 +289,7 @@ main(int argc, char *argv[])
|
|||||||
byte |= 1 << 6;
|
byte |= 1 << 6;
|
||||||
|
|
||||||
if (byte & 0x3F)
|
if (byte & 0x3F)
|
||||||
fprintf(stderr,
|
warnx("Color flag conflicts with game title");
|
||||||
"Color flag conflicts with game title\n");
|
|
||||||
|
|
||||||
fseek(rom, 0x143, SEEK_SET);
|
fseek(rom, 0x143, SEEK_SET);
|
||||||
fputc(byte, rom);
|
fputc(byte, rom);
|
||||||
@@ -351,9 +326,8 @@ main(int argc, char *argv[])
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
if (!setlicensee)
|
if (!setlicensee)
|
||||||
fprintf(stderr,
|
warnx("You should probably set both '-s' and "
|
||||||
"You should probably set both '-s' and "
|
"'-l 0x33'");
|
||||||
"'-l 0x33'\n");
|
|
||||||
|
|
||||||
fseek(rom, 0x146, SEEK_SET);
|
fseek(rom, 0x146, SEEK_SET);
|
||||||
fputc(3, rom);
|
fputc(3, rom);
|
||||||
@@ -390,7 +364,7 @@ main(int argc, char *argv[])
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (newsize > 0x800000) /* ROM is bigger than 8MiB */
|
if (newsize > 0x800000) /* ROM is bigger than 8MiB */
|
||||||
fprintf(stderr, "ROM size is bigger than 8MiB\n");
|
warnx("ROM size is bigger than 8MiB");
|
||||||
|
|
||||||
buf = malloc(newsize - romsize);
|
buf = malloc(newsize - romsize);
|
||||||
memset(buf, padvalue, newsize - romsize);
|
memset(buf, padvalue, newsize - romsize);
|
||||||
|
|||||||
@@ -88,16 +88,14 @@ lib_ReadLib0(FILE * f, SLONG size)
|
|||||||
if (l == NULL) {
|
if (l == NULL) {
|
||||||
l = malloc(sizeof *l);
|
l = malloc(sizeof *l);
|
||||||
if (!l) {
|
if (!l) {
|
||||||
fprintf(stderr, "Out of memory\n");
|
err(1, NULL);
|
||||||
exit(1);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
first = l;
|
first = l;
|
||||||
} else {
|
} else {
|
||||||
l->pNext = malloc(sizeof *l->pNext);
|
l->pNext = malloc(sizeof *l->pNext);
|
||||||
if (!l->pNext) {
|
if (!l->pNext) {
|
||||||
fprintf(stderr, "Out of memory\n");
|
err(1, NULL);
|
||||||
exit(1);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
l = l->pNext;
|
l = l->pNext;
|
||||||
@@ -115,8 +113,7 @@ lib_ReadLib0(FILE * f, SLONG size)
|
|||||||
f);
|
f);
|
||||||
size -= l->nByteLength;
|
size -= l->nByteLength;
|
||||||
} else {
|
} else {
|
||||||
fprintf(stderr, "Out of memory\n");
|
err(1, NULL);
|
||||||
exit(1);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
l->pNext = NULL;
|
l->pNext = NULL;
|
||||||
@@ -153,8 +150,7 @@ lib_Read(char *filename)
|
|||||||
return (r);
|
return (r);
|
||||||
} else {
|
} else {
|
||||||
fclose(f);
|
fclose(f);
|
||||||
fprintf(stderr, "Not a valid xLib library\n");
|
errx(1, "Not a valid xLib library");
|
||||||
exit(1);
|
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
printf
|
printf
|
||||||
@@ -191,8 +187,7 @@ sLibrary *
|
|||||||
lib_Find(sLibrary * lib, char *filename)
|
lib_Find(sLibrary * lib, char *filename)
|
||||||
{
|
{
|
||||||
if (strlen(filename) >= MAXNAMELENGTH) {
|
if (strlen(filename) >= MAXNAMELENGTH) {
|
||||||
fprintf(stderr, "Module name too long: %s\n", filename);
|
errx(1, "Module name too long: %s", filename);
|
||||||
exit(1);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
while (lib) {
|
while (lib) {
|
||||||
@@ -214,16 +209,13 @@ lib_AddReplace(sLibrary * lib, char *filename)
|
|||||||
sLibrary *module;
|
sLibrary *module;
|
||||||
|
|
||||||
if (strlen(filename) >= MAXNAMELENGTH) {
|
if (strlen(filename) >= MAXNAMELENGTH) {
|
||||||
fprintf(stderr, "Module name too long: %s\n",
|
errx(1, "Module name too long: %s\n", filename);
|
||||||
filename);
|
|
||||||
exit(1);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((module = lib_Find(lib, filename)) == NULL) {
|
if ((module = lib_Find(lib, filename)) == NULL) {
|
||||||
module = malloc(sizeof *module);
|
module = malloc(sizeof *module);
|
||||||
if (!module) {
|
if (!module) {
|
||||||
fprintf(stderr, "Out of memory\n");
|
err(1, NULL);
|
||||||
exit(1);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
module->pNext = lib;
|
module->pNext = lib;
|
||||||
@@ -237,8 +229,7 @@ lib_AddReplace(sLibrary * lib, char *filename)
|
|||||||
strcpy(module->tName, filename);
|
strcpy(module->tName, filename);
|
||||||
module->pData = malloc(module->nByteLength);
|
module->pData = malloc(module->nByteLength);
|
||||||
if (!module->pData) {
|
if (!module->pData) {
|
||||||
fprintf(stderr, "Out of memory\n");
|
err(1, NULL);
|
||||||
exit(1);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fread(module->pData, sizeof(UBYTE), module->nByteLength, f);
|
fread(module->pData, sizeof(UBYTE), module->nByteLength, f);
|
||||||
@@ -260,8 +251,7 @@ lib_DeleteModule(sLibrary * lib, char *filename)
|
|||||||
first = pp;
|
first = pp;
|
||||||
|
|
||||||
if (strlen(filename) >= MAXNAMELENGTH) {
|
if (strlen(filename) >= MAXNAMELENGTH) {
|
||||||
fprintf(stderr, "Module name too long: %s\n", filename);
|
errx(1, "Module name too long: %s\n", filename);
|
||||||
exit(1);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
while ((*pp) && (!found)) {
|
while ((*pp) && (!found)) {
|
||||||
@@ -282,8 +272,7 @@ lib_DeleteModule(sLibrary * lib, char *filename)
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (!found) {
|
if (!found) {
|
||||||
fprintf(stderr, "Module not found\n");
|
errx(1, "Module not found\n");
|
||||||
exit(1);
|
|
||||||
} else
|
} else
|
||||||
printf("Module '%s' deleted from library\n", filename);
|
printf("Module '%s' deleted from library\n", filename);
|
||||||
|
|
||||||
|
|||||||
@@ -6,6 +6,7 @@
|
|||||||
|
|
||||||
#include "asmotor.h"
|
#include "asmotor.h"
|
||||||
|
|
||||||
|
#include "extern/err.h"
|
||||||
#include "lib/types.h"
|
#include "lib/types.h"
|
||||||
#include "lib/library.h"
|
#include "lib/library.h"
|
||||||
|
|
||||||
@@ -83,10 +84,8 @@ main(int argc, char *argv[])
|
|||||||
("Extracted module '%s'\n",
|
("Extracted module '%s'\n",
|
||||||
argv[argn]);
|
argv[argn]);
|
||||||
} else {
|
} else {
|
||||||
fprintf(stderr,
|
err(1,
|
||||||
"Unable to write module '%s': ", argv[argn]);
|
"Unable to write module '%s'", argv[argn]);
|
||||||
perror(NULL);
|
|
||||||
exit(1);
|
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
fprintf(stderr, "Module not found\n");
|
fprintf(stderr, "Module not found\n");
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
|
||||||
|
#include "extern/err.h"
|
||||||
#include "link/mylink.h"
|
#include "link/mylink.h"
|
||||||
#include "link/main.h"
|
#include "link/main.h"
|
||||||
#include "link/symbol.h"
|
#include "link/symbol.h"
|
||||||
@@ -77,9 +78,7 @@ area_AllocAbs(struct sFreeArea ** ppArea, SLONG org, SLONG size)
|
|||||||
|
|
||||||
return (org);
|
return (org);
|
||||||
} else {
|
} else {
|
||||||
fprintf(stderr,
|
err(1, NULL);
|
||||||
"Out of memory!\n");
|
|
||||||
exit(1);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -310,9 +309,7 @@ AssignVRAMSections(void)
|
|||||||
pSection->oAssigned = 1;
|
pSection->oAssigned = 1;
|
||||||
DOMAXVBANK(pSection->nBank);
|
DOMAXVBANK(pSection->nBank);
|
||||||
} else {
|
} else {
|
||||||
fprintf(stderr,
|
errx(1, "Unable to place VRAM section anywhere");
|
||||||
"Unable to place VRAM section anywhere\n");
|
|
||||||
exit(1);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -331,9 +328,7 @@ AssignSRAMSections(void)
|
|||||||
pSection->oAssigned = 1;
|
pSection->oAssigned = 1;
|
||||||
DOMAXSBANK(pSection->nBank);
|
DOMAXSBANK(pSection->nBank);
|
||||||
} else {
|
} else {
|
||||||
fprintf(stderr,
|
errx(1, "Unable to place SRAM section anywhere");
|
||||||
"Unable to place SRAM section anywhere\n");
|
|
||||||
exit(1);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -352,9 +347,7 @@ AssignWRAMSections(void)
|
|||||||
pSection->oAssigned = 1;
|
pSection->oAssigned = 1;
|
||||||
DOMAXWBANK(pSection->nBank);
|
DOMAXWBANK(pSection->nBank);
|
||||||
} else {
|
} else {
|
||||||
fprintf(stderr,
|
errx(1, "Unable to place WRAMX section anywhere");
|
||||||
"Unable to place WRAMX section anywhere\n");
|
|
||||||
exit(1);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -373,9 +366,7 @@ AssignCodeSections(void)
|
|||||||
pSection->oAssigned = 1;
|
pSection->oAssigned = 1;
|
||||||
DOMAXBANK(pSection->nBank);
|
DOMAXBANK(pSection->nBank);
|
||||||
} else {
|
} else {
|
||||||
fprintf(stderr,
|
errx(1, "Unable to place ROMX section anywhere");
|
||||||
"Unable to place ROMX section anywhere\n");
|
|
||||||
exit(1);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -397,8 +388,7 @@ AssignSections(void)
|
|||||||
BankFree[i] = malloc(sizeof *BankFree[i]);
|
BankFree[i] = malloc(sizeof *BankFree[i]);
|
||||||
|
|
||||||
if (!BankFree[i]) {
|
if (!BankFree[i]) {
|
||||||
fprintf(stderr, "Out of memory!\n");
|
err(1, NULL);
|
||||||
exit(1);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (i == 0) {
|
if (i == 0) {
|
||||||
@@ -472,10 +462,9 @@ AssignSections(void)
|
|||||||
if (area_AllocAbs
|
if (area_AllocAbs
|
||||||
(&BankFree[BANK_WRAM0], pSection->nOrg,
|
(&BankFree[BANK_WRAM0], pSection->nOrg,
|
||||||
pSection->nByteSize) != pSection->nOrg) {
|
pSection->nByteSize) != pSection->nOrg) {
|
||||||
fprintf(stderr,
|
errx(1,
|
||||||
"Unable to load fixed WRAM0 section "
|
"Unable to load fixed WRAM0 "
|
||||||
"at $%lX\n", pSection->nOrg);
|
"section at $%lX", pSection->nOrg);
|
||||||
exit(1);
|
|
||||||
}
|
}
|
||||||
pSection->oAssigned = 1;
|
pSection->oAssigned = 1;
|
||||||
pSection->nBank = BANK_WRAM0;
|
pSection->nBank = BANK_WRAM0;
|
||||||
@@ -484,10 +473,8 @@ AssignSections(void)
|
|||||||
if (area_AllocAbs
|
if (area_AllocAbs
|
||||||
(&BankFree[BANK_HRAM], pSection->nOrg,
|
(&BankFree[BANK_HRAM], pSection->nOrg,
|
||||||
pSection->nByteSize) != pSection->nOrg) {
|
pSection->nByteSize) != pSection->nOrg) {
|
||||||
fprintf(stderr, "Unable to load fixed "
|
errx(1, "Unable to load fixed HRAM "
|
||||||
"HRAM section at $%lX\n",
|
"section at $%lX", pSection->nOrg);
|
||||||
pSection->nOrg);
|
|
||||||
exit(1);
|
|
||||||
}
|
}
|
||||||
pSection->oAssigned = 1;
|
pSection->oAssigned = 1;
|
||||||
pSection->nBank = BANK_HRAM;
|
pSection->nBank = BANK_HRAM;
|
||||||
@@ -530,17 +517,15 @@ AssignSections(void)
|
|||||||
pSection->nOrg,
|
pSection->nOrg,
|
||||||
pSection->nByteSize)
|
pSection->nByteSize)
|
||||||
!= pSection->nOrg) {
|
!= pSection->nOrg) {
|
||||||
fprintf(stderr,
|
errx(1,
|
||||||
"Unable to load fixed SRAM section at $%lX in bank $%02lX\n", pSection->nOrg, pSection->nBank);
|
"Unable to load fixed SRAM section at $%lX in bank $%02lX", pSection->nOrg, pSection->nBank);
|
||||||
exit(1);
|
|
||||||
}
|
}
|
||||||
DOMAXVBANK(pSection->
|
DOMAXVBANK(pSection->
|
||||||
nBank);
|
nBank);
|
||||||
pSection->oAssigned = 1;
|
pSection->oAssigned = 1;
|
||||||
} else {
|
} else {
|
||||||
fprintf(stderr,
|
errx(1,
|
||||||
"Unable to load fixed SRAM section at $%lX in bank $%02lX\n", pSection->nOrg, pSection->nBank);
|
"Unable to load fixed SRAM section at $%lX in bank $%02lX", pSection->nOrg, pSection->nBank);
|
||||||
exit(1);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -583,17 +568,15 @@ AssignSections(void)
|
|||||||
pSection->nOrg,
|
pSection->nOrg,
|
||||||
pSection->nByteSize)
|
pSection->nByteSize)
|
||||||
!= pSection->nOrg) {
|
!= pSection->nOrg) {
|
||||||
fprintf(stderr,
|
errx(1,
|
||||||
"Unable to load fixed WRAMX section at $%lX in bank $%02lX\n", pSection->nOrg, pSection->nBank);
|
"Unable to load fixed WRAMX section at $%lX in bank $%02lX", pSection->nOrg, pSection->nBank);
|
||||||
exit(1);
|
|
||||||
}
|
}
|
||||||
DOMAXWBANK(pSection->
|
DOMAXWBANK(pSection->
|
||||||
nBank);
|
nBank);
|
||||||
pSection->oAssigned = 1;
|
pSection->oAssigned = 1;
|
||||||
} else {
|
} else {
|
||||||
fprintf(stderr,
|
errx(1,
|
||||||
"Unable to load fixed WRAMX section at $%lX in bank $%02lX\n", pSection->nOrg, pSection->nBank);
|
"Unable to load fixed WRAMX section at $%lX in bank $%02lX", pSection->nOrg, pSection->nBank);
|
||||||
exit(1);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -636,17 +619,15 @@ AssignSections(void)
|
|||||||
pSection->nOrg,
|
pSection->nOrg,
|
||||||
pSection->nByteSize)
|
pSection->nByteSize)
|
||||||
!= pSection->nOrg) {
|
!= pSection->nOrg) {
|
||||||
fprintf(stderr,
|
errx(1,
|
||||||
"Unable to load fixed VRAM section at $%lX in bank $%02lX\n", pSection->nOrg, pSection->nBank);
|
"Unable to load fixed VRAM section at $%lX in bank $%02lX", pSection->nOrg, pSection->nBank);
|
||||||
exit(1);
|
|
||||||
}
|
}
|
||||||
DOMAXVBANK(pSection->
|
DOMAXVBANK(pSection->
|
||||||
nBank);
|
nBank);
|
||||||
pSection->oAssigned = 1;
|
pSection->oAssigned = 1;
|
||||||
} else {
|
} else {
|
||||||
fprintf(stderr,
|
errx(1,
|
||||||
"Unable to load fixed VRAM section at $%lX in bank $%02lX\n", pSection->nOrg, pSection->nBank);
|
"Unable to load fixed VRAM section at $%lX in bank $%02lX", pSection->nOrg, pSection->nBank);
|
||||||
exit(1);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -655,10 +636,8 @@ AssignSections(void)
|
|||||||
if (area_AllocAbs
|
if (area_AllocAbs
|
||||||
(&BankFree[BANK_ROM0], pSection->nOrg,
|
(&BankFree[BANK_ROM0], pSection->nOrg,
|
||||||
pSection->nByteSize) != pSection->nOrg) {
|
pSection->nByteSize) != pSection->nOrg) {
|
||||||
fprintf(stderr, "Unable to load fixed "
|
errx(1, "Unable to load fixed ROM0 "
|
||||||
"ROM0 section at $%lX\n",
|
"section at $%lX", pSection->nOrg);
|
||||||
pSection->nOrg);
|
|
||||||
exit(1);
|
|
||||||
}
|
}
|
||||||
pSection->oAssigned = 1;
|
pSection->oAssigned = 1;
|
||||||
pSection->nBank = BANK_ROM0;
|
pSection->nBank = BANK_ROM0;
|
||||||
@@ -703,15 +682,15 @@ AssignSections(void)
|
|||||||
pSection->
|
pSection->
|
||||||
nByteSize) !=
|
nByteSize) !=
|
||||||
pSection->nOrg) {
|
pSection->nOrg) {
|
||||||
fprintf(stderr, "Unable to load fixed ROMX section at $%lX in bank $%02lX\n", pSection->nOrg, pSection->nBank);
|
errx(1,
|
||||||
exit(1);
|
"Unable to load fixed ROMX section at $%lX in bank $%02lX", pSection->nOrg, pSection->nBank);
|
||||||
}
|
}
|
||||||
DOMAXBANK(pSection->
|
DOMAXBANK(pSection->
|
||||||
nBank);
|
nBank);
|
||||||
pSection->oAssigned = 1;
|
pSection->oAssigned = 1;
|
||||||
} else {
|
} else {
|
||||||
fprintf(stderr, "Unable to load fixed ROMX section at $%lX in bank $%02lX\n", pSection->nOrg, pSection->nBank);
|
errx(1,
|
||||||
exit(1);
|
"Unable to load fixed ROMX section at $%lX in bank $%02lX", pSection->nOrg, pSection->nBank);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -737,14 +716,13 @@ AssignSections(void)
|
|||||||
if ((pSection->nOrg =
|
if ((pSection->nOrg =
|
||||||
area_Alloc(&BankFree[pSection->nBank],
|
area_Alloc(&BankFree[pSection->nBank],
|
||||||
pSection->nByteSize)) == -1) {
|
pSection->nByteSize)) == -1) {
|
||||||
fprintf(stderr, "Unable to load fixed ROMX section into bank $%02lX\n", pSection->nBank);
|
errx(1,
|
||||||
exit(1);
|
"Unable to load fixed ROMX section into bank $%02lX", pSection->nBank);
|
||||||
}
|
}
|
||||||
pSection->oAssigned = 1;
|
pSection->oAssigned = 1;
|
||||||
DOMAXBANK(pSection->nBank);
|
DOMAXBANK(pSection->nBank);
|
||||||
} else {
|
} else {
|
||||||
fprintf(stderr, "Unable to load fixed ROMX section into bank $%02lX\n", pSection->nBank);
|
errx(1, "Unable to load fixed ROMX section into bank $%02lX", pSection->nBank);
|
||||||
exit(1);
|
|
||||||
}
|
}
|
||||||
} else if (pSection->oAssigned == 0
|
} else if (pSection->oAssigned == 0
|
||||||
&& pSection->Type == SECT_SRAM
|
&& pSection->Type == SECT_SRAM
|
||||||
@@ -755,14 +733,12 @@ AssignSections(void)
|
|||||||
if ((pSection->nOrg =
|
if ((pSection->nOrg =
|
||||||
area_Alloc(&BankFree[pSection->nBank],
|
area_Alloc(&BankFree[pSection->nBank],
|
||||||
pSection->nByteSize)) == -1) {
|
pSection->nByteSize)) == -1) {
|
||||||
fprintf(stderr, "Unable to load fixed SRAM section into bank $%02lX\n", pSection->nBank);
|
errx(1, "Unable to load fixed SRAM section into bank $%02lX", pSection->nBank);
|
||||||
exit(1);
|
|
||||||
}
|
}
|
||||||
pSection->oAssigned = 1;
|
pSection->oAssigned = 1;
|
||||||
DOMAXSBANK(pSection->nBank);
|
DOMAXSBANK(pSection->nBank);
|
||||||
} else {
|
} else {
|
||||||
fprintf(stderr, "Unable to load fixed VRAM section into bank $%02lX\n", pSection->nBank);
|
errx(1, "Unable to load fixed VRAM section into bank $%02lX", pSection->nBank);
|
||||||
exit(1);
|
|
||||||
}
|
}
|
||||||
} else if (pSection->oAssigned == 0
|
} else if (pSection->oAssigned == 0
|
||||||
&& pSection->Type == SECT_VRAM
|
&& pSection->Type == SECT_VRAM
|
||||||
@@ -773,14 +749,12 @@ AssignSections(void)
|
|||||||
if ((pSection->nOrg =
|
if ((pSection->nOrg =
|
||||||
area_Alloc(&BankFree[pSection->nBank],
|
area_Alloc(&BankFree[pSection->nBank],
|
||||||
pSection->nByteSize)) == -1) {
|
pSection->nByteSize)) == -1) {
|
||||||
fprintf(stderr, "Unable to load fixed VRAM section into bank $%02lX\n", pSection->nBank);
|
errx(1, "Unable to load fixed VRAM section into bank $%02lX", pSection->nBank);
|
||||||
exit(1);
|
|
||||||
}
|
}
|
||||||
pSection->oAssigned = 1;
|
pSection->oAssigned = 1;
|
||||||
DOMAXVBANK(pSection->nBank);
|
DOMAXVBANK(pSection->nBank);
|
||||||
} else {
|
} else {
|
||||||
fprintf(stderr, "Unable to load fixed VRAM section into bank $%02lX\n", pSection->nBank);
|
errx(1, "Unable to load fixed VRAM section into bank $%02lX", pSection->nBank);
|
||||||
exit(1);
|
|
||||||
}
|
}
|
||||||
} else if (pSection->oAssigned == 0
|
} else if (pSection->oAssigned == 0
|
||||||
&& pSection->Type == SECT_WRAMX
|
&& pSection->Type == SECT_WRAMX
|
||||||
@@ -791,14 +765,12 @@ AssignSections(void)
|
|||||||
if ((pSection->nOrg =
|
if ((pSection->nOrg =
|
||||||
area_Alloc(&BankFree[pSection->nBank],
|
area_Alloc(&BankFree[pSection->nBank],
|
||||||
pSection->nByteSize)) == -1) {
|
pSection->nByteSize)) == -1) {
|
||||||
fprintf(stderr, "Unable to load fixed WRAMX section into bank $%02lX\n", pSection->nBank - BANK_WRAMX);
|
errx(1, "Unable to load fixed WRAMX section into bank $%02lX", pSection->nBank - BANK_WRAMX);
|
||||||
exit(1);
|
|
||||||
}
|
}
|
||||||
pSection->oAssigned = 1;
|
pSection->oAssigned = 1;
|
||||||
DOMAXWBANK(pSection->nBank);
|
DOMAXWBANK(pSection->nBank);
|
||||||
} else {
|
} else {
|
||||||
fprintf(stderr, "Unable to load fixed WRAMX section into bank $%02lX\n", pSection->nBank - BANK_WRAMX);
|
errx(1, "Unable to load fixed WRAMX section into bank $%02lX", pSection->nBank - BANK_WRAMX);
|
||||||
exit(1);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
pSection = pSection->pNext;
|
pSection = pSection->pNext;
|
||||||
@@ -820,8 +792,7 @@ AssignSections(void)
|
|||||||
area_AllocAbsROMXAnyBank(pSection->nOrg,
|
area_AllocAbsROMXAnyBank(pSection->nOrg,
|
||||||
pSection->nByteSize)) ==
|
pSection->nByteSize)) ==
|
||||||
-1) {
|
-1) {
|
||||||
fprintf(stderr, "Unable to load fixed ROMX section at $%lX into any bank\n", pSection->nOrg);
|
errx(1, "Unable to load fixed ROMX section at $%lX into any bank", pSection->nOrg);
|
||||||
exit(1);
|
|
||||||
}
|
}
|
||||||
pSection->oAssigned = 1;
|
pSection->oAssigned = 1;
|
||||||
DOMAXBANK(pSection->nBank);
|
DOMAXBANK(pSection->nBank);
|
||||||
@@ -834,8 +805,7 @@ AssignSections(void)
|
|||||||
area_AllocAbsVRAMAnyBank(pSection->nOrg,
|
area_AllocAbsVRAMAnyBank(pSection->nOrg,
|
||||||
pSection->nByteSize)) ==
|
pSection->nByteSize)) ==
|
||||||
-1) {
|
-1) {
|
||||||
fprintf(stderr, "Unable to load fixed VRAM section at $%lX into any bank\n", pSection->nOrg);
|
errx(1, "Unable to load fixed VRAM section at $%lX into any bank", pSection->nOrg);
|
||||||
exit(1);
|
|
||||||
}
|
}
|
||||||
pSection->oAssigned = 1;
|
pSection->oAssigned = 1;
|
||||||
DOMAXVBANK(pSection->nBank);
|
DOMAXVBANK(pSection->nBank);
|
||||||
@@ -848,8 +818,7 @@ AssignSections(void)
|
|||||||
area_AllocAbsSRAMAnyBank(pSection->nOrg,
|
area_AllocAbsSRAMAnyBank(pSection->nOrg,
|
||||||
pSection->nByteSize)) ==
|
pSection->nByteSize)) ==
|
||||||
-1) {
|
-1) {
|
||||||
fprintf(stderr, "Unable to load fixed SRAM section at $%lX into any bank\n", pSection->nOrg);
|
errx(1, "Unable to load fixed SRAM section at $%lX into any bank", pSection->nOrg);
|
||||||
exit(1);
|
|
||||||
}
|
}
|
||||||
pSection->oAssigned = 1;
|
pSection->oAssigned = 1;
|
||||||
DOMAXSBANK(pSection->nBank);
|
DOMAXSBANK(pSection->nBank);
|
||||||
@@ -862,8 +831,7 @@ AssignSections(void)
|
|||||||
area_AllocAbsWRAMAnyBank(pSection->nOrg,
|
area_AllocAbsWRAMAnyBank(pSection->nOrg,
|
||||||
pSection->nByteSize)) ==
|
pSection->nByteSize)) ==
|
||||||
-1) {
|
-1) {
|
||||||
fprintf(stderr, "Unable to load fixed WRAMX section at $%lX into any bank\n", pSection->nOrg);
|
errx(1, "Unable to load fixed WRAMX section at $%lX into any bank", pSection->nOrg);
|
||||||
exit(1);
|
|
||||||
}
|
}
|
||||||
pSection->oAssigned = 1;
|
pSection->oAssigned = 1;
|
||||||
DOMAXWBANK(pSection->nBank);
|
DOMAXWBANK(pSection->nBank);
|
||||||
@@ -885,8 +853,7 @@ AssignSections(void)
|
|||||||
if ((pSection->nOrg =
|
if ((pSection->nOrg =
|
||||||
area_Alloc(&BankFree[BANK_WRAM0],
|
area_Alloc(&BankFree[BANK_WRAM0],
|
||||||
pSection->nByteSize)) == -1) {
|
pSection->nByteSize)) == -1) {
|
||||||
fprintf(stderr, "WRAM0 section too large\n");
|
errx(1, "WRAM0 section too large");
|
||||||
exit(1);
|
|
||||||
}
|
}
|
||||||
pSection->nBank = BANK_WRAM0;
|
pSection->nBank = BANK_WRAM0;
|
||||||
pSection->oAssigned = 1;
|
pSection->oAssigned = 1;
|
||||||
@@ -895,8 +862,7 @@ AssignSections(void)
|
|||||||
if ((pSection->nOrg =
|
if ((pSection->nOrg =
|
||||||
area_Alloc(&BankFree[BANK_HRAM],
|
area_Alloc(&BankFree[BANK_HRAM],
|
||||||
pSection->nByteSize)) == -1) {
|
pSection->nByteSize)) == -1) {
|
||||||
fprintf(stderr, "HRAM section too large\n");
|
errx(1, "HRAM section too large");
|
||||||
exit(1);
|
|
||||||
}
|
}
|
||||||
pSection->nBank = BANK_HRAM;
|
pSection->nBank = BANK_HRAM;
|
||||||
pSection->oAssigned = 1;
|
pSection->oAssigned = 1;
|
||||||
@@ -911,8 +877,7 @@ AssignSections(void)
|
|||||||
if ((pSection->nOrg =
|
if ((pSection->nOrg =
|
||||||
area_Alloc(&BankFree[BANK_ROM0],
|
area_Alloc(&BankFree[BANK_ROM0],
|
||||||
pSection->nByteSize)) == -1) {
|
pSection->nByteSize)) == -1) {
|
||||||
fprintf(stderr, "ROM0 section too large\n");
|
errx(1, "ROM0 section too large");
|
||||||
exit(1);
|
|
||||||
}
|
}
|
||||||
pSection->nBank = BANK_ROM0;
|
pSection->nBank = BANK_ROM0;
|
||||||
pSection->oAssigned = 1;
|
pSection->oAssigned = 1;
|
||||||
@@ -920,8 +885,7 @@ AssignSections(void)
|
|||||||
case SECT_ROMX:
|
case SECT_ROMX:
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
fprintf(stderr, "(INTERNAL) Unknown section type!\n");
|
errx(1, "(INTERNAL) Unknown section type!");
|
||||||
exit(1);
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,6 +2,7 @@
|
|||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
|
#include "extern/err.h"
|
||||||
#include "link/types.h"
|
#include "link/types.h"
|
||||||
#include "link/mylink.h"
|
#include "link/mylink.h"
|
||||||
#include "link/main.h"
|
#include "link/main.h"
|
||||||
@@ -91,9 +92,8 @@ AddNeededModules(void)
|
|||||||
}
|
}
|
||||||
if (options & OPT_SMART_C_LINK) {
|
if (options & OPT_SMART_C_LINK) {
|
||||||
if (!addmodulecontaining(smartlinkstartsymbol)) {
|
if (!addmodulecontaining(smartlinkstartsymbol)) {
|
||||||
fprintf(stderr, "Can't find start symbol '%s'\n",
|
errx(1, "Can't find start symbol '%s'",
|
||||||
smartlinkstartsymbol);
|
smartlinkstartsymbol);
|
||||||
exit(1);
|
|
||||||
} else
|
} else
|
||||||
printf("Smart linking with symbol '%s'\n",
|
printf("Smart linking with symbol '%s'\n",
|
||||||
smartlinkstartsymbol);
|
smartlinkstartsymbol);
|
||||||
|
|||||||
@@ -6,6 +6,7 @@
|
|||||||
|
|
||||||
#include "asmotor.h"
|
#include "asmotor.h"
|
||||||
|
|
||||||
|
#include "extern/err.h"
|
||||||
#include "link/object.h"
|
#include "link/object.h"
|
||||||
#include "link/output.h"
|
#include "link/output.h"
|
||||||
#include "link/assign.h"
|
#include "link/assign.h"
|
||||||
@@ -73,8 +74,7 @@ main(int argc, char *argv[])
|
|||||||
case 'p':
|
case 'p':
|
||||||
fillchar = strtoul(optarg, &ep, 0);
|
fillchar = strtoul(optarg, &ep, 0);
|
||||||
if (optarg[0] == '\0' || *ep != '\0') {
|
if (optarg[0] == '\0' || *ep != '\0') {
|
||||||
fprintf(stderr, "Invalid argument for option 'p'\n");
|
errx(1, "Invalid argument for option 'p'");
|
||||||
exit(1);
|
|
||||||
}
|
}
|
||||||
if (fillchar < 0 || fillchar > 0xFF) {
|
if (fillchar < 0 || fillchar > 0xFF) {
|
||||||
fprintf(stderr, "Argument for option 'p' must be between 0 and 0xFF");
|
fprintf(stderr, "Argument for option 'p' must be between 0 and 0xFF");
|
||||||
|
|||||||
@@ -5,6 +5,7 @@
|
|||||||
|
|
||||||
#include "asmotor.h"
|
#include "asmotor.h"
|
||||||
|
|
||||||
|
#include "extern/err.h"
|
||||||
#include "link/main.h"
|
#include "link/main.h"
|
||||||
#include "link/mylink.h"
|
#include "link/mylink.h"
|
||||||
#include "link/assign.h"
|
#include "link/assign.h"
|
||||||
@@ -20,9 +21,7 @@ SetMapfileName(char *name)
|
|||||||
mf = fopen(name, "w");
|
mf = fopen(name, "w");
|
||||||
|
|
||||||
if (mf == NULL) {
|
if (mf == NULL) {
|
||||||
fprintf(stderr, "Cannot open mapfile '%s': ", name);
|
err(1, "Cannot open mapfile '%s'", name);
|
||||||
perror(NULL);
|
|
||||||
exit(1);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -32,8 +31,7 @@ SetSymfileName(char *name)
|
|||||||
sf = fopen(name, "w");
|
sf = fopen(name, "w");
|
||||||
|
|
||||||
if (sf == NULL) {
|
if (sf == NULL) {
|
||||||
fprintf(stderr, "Cannot open symfile '%s'\n", name);
|
err(1, "Cannot open symfile '%s'", name);
|
||||||
exit(1);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fprintf(sf, ";File generated by xLink v" LINK_VERSION "\n\n");
|
fprintf(sf, ";File generated by xLink v" LINK_VERSION "\n\n");
|
||||||
|
|||||||
@@ -8,6 +8,7 @@
|
|||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
|
#include "extern/err.h"
|
||||||
#include "link/mylink.h"
|
#include "link/mylink.h"
|
||||||
#include "link/main.h"
|
#include "link/main.h"
|
||||||
|
|
||||||
@@ -80,8 +81,7 @@ AllocSection(void)
|
|||||||
|
|
||||||
*ppSections = malloc(sizeof **ppSections);
|
*ppSections = malloc(sizeof **ppSections);
|
||||||
if (!*ppSections) {
|
if (!*ppSections) {
|
||||||
fprintf(stderr, "Out of memory!\n");
|
err(1, NULL);
|
||||||
exit(1);
|
|
||||||
}
|
}
|
||||||
(*ppSections)->tSymbols = tSymbols;
|
(*ppSections)->tSymbols = tSymbols;
|
||||||
(*ppSections)->pNext = NULL;
|
(*ppSections)->pNext = NULL;
|
||||||
@@ -102,15 +102,13 @@ obj_ReadSymbol(FILE * f)
|
|||||||
|
|
||||||
pSym = malloc(sizeof *pSym);
|
pSym = malloc(sizeof *pSym);
|
||||||
if (!pSym) {
|
if (!pSym) {
|
||||||
fprintf(stderr, "Out of memory!\n");
|
err(1, NULL);
|
||||||
exit(1);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
readasciiz(s, f);
|
readasciiz(s, f);
|
||||||
pSym->pzName = malloc(strlen(s) + 1);
|
pSym->pzName = malloc(strlen(s) + 1);
|
||||||
if (!pSym->pzName) {
|
if (!pSym->pzName) {
|
||||||
fprintf(stderr, "Out of memory!\n");
|
err(1, NULL);
|
||||||
exit(1);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
strcpy(pSym->pzName, s);
|
strcpy(pSym->pzName, s);
|
||||||
@@ -150,7 +148,7 @@ obj_ReadRGB0Section(FILE * f)
|
|||||||
if (pSection->nByteSize) {
|
if (pSection->nByteSize) {
|
||||||
pSection->pData = malloc(pSection->nByteSize);
|
pSection->pData = malloc(pSection->nByteSize);
|
||||||
if (!pSection->pData) {
|
if (!pSection->pData) {
|
||||||
fprintf(stderr, "Out of memory!\n");
|
err(1, NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
SLONG nNumberOfPatches;
|
SLONG nNumberOfPatches;
|
||||||
@@ -169,7 +167,7 @@ obj_ReadRGB0Section(FILE * f)
|
|||||||
while (nNumberOfPatches--) {
|
while (nNumberOfPatches--) {
|
||||||
pPatch = malloc(sizeof *pPatch);
|
pPatch = malloc(sizeof *pPatch);
|
||||||
if (!pPatch) {
|
if (!pPatch) {
|
||||||
fprintf(stderr, "Out of memory!\n");
|
err(1, NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
*ppPatch = pPatch;
|
*ppPatch = pPatch;
|
||||||
@@ -177,7 +175,7 @@ obj_ReadRGB0Section(FILE * f)
|
|||||||
|
|
||||||
pPatch->pzFilename = malloc(strlen(s) + 1);
|
pPatch->pzFilename = malloc(strlen(s) + 1);
|
||||||
if (!pPatch->pzFilename) {
|
if (!pPatch->pzFilename) {
|
||||||
fprintf(stderr, "Out of memory!\n");
|
err(1, NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
strcpy(pPatch->pzFilename, s);
|
strcpy(pPatch->pzFilename, s);
|
||||||
@@ -193,8 +191,7 @@ obj_ReadRGB0Section(FILE * f)
|
|||||||
if ((pPatch->nRPNSize = readlong(f)) > 0) {
|
if ((pPatch->nRPNSize = readlong(f)) > 0) {
|
||||||
pPatch->pRPN = malloc(pPatch->nRPNSize);
|
pPatch->pRPN = malloc(pPatch->nRPNSize);
|
||||||
if (!pPatch->pRPN) {
|
if (!pPatch->pRPN) {
|
||||||
fprintf(stderr, "Out of memory!\n");
|
err(1, NULL);
|
||||||
exit(1);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fread(pPatch->pRPN, sizeof(UBYTE),
|
fread(pPatch->pRPN, sizeof(UBYTE),
|
||||||
@@ -228,8 +225,7 @@ obj_ReadRGB0(FILE * pObjfile)
|
|||||||
if (nNumberOfSymbols) {
|
if (nNumberOfSymbols) {
|
||||||
tSymbols = malloc(nNumberOfSymbols * sizeof(struct sSymbol *));
|
tSymbols = malloc(nNumberOfSymbols * sizeof(struct sSymbol *));
|
||||||
if (!tSymbols) {
|
if (!tSymbols) {
|
||||||
fprintf(stderr, "Out of memory!\n");
|
err(1, NULL);
|
||||||
exit(1);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
for (i = 0; i < nNumberOfSymbols; i += 1)
|
for (i = 0; i < nNumberOfSymbols; i += 1)
|
||||||
@@ -305,8 +301,7 @@ obj_ReadRGB1Section(FILE * f)
|
|||||||
if (pSection->nByteSize) {
|
if (pSection->nByteSize) {
|
||||||
pSection->pData = malloc(pSection->nByteSize);
|
pSection->pData = malloc(pSection->nByteSize);
|
||||||
if (!pSection->pData) {
|
if (!pSection->pData) {
|
||||||
fprintf(stderr, "Out of memory!\n");
|
err(1, NULL);
|
||||||
exit(1);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
SLONG nNumberOfPatches;
|
SLONG nNumberOfPatches;
|
||||||
@@ -325,14 +320,14 @@ obj_ReadRGB1Section(FILE * f)
|
|||||||
while (nNumberOfPatches--) {
|
while (nNumberOfPatches--) {
|
||||||
pPatch = malloc(sizeof *pPatch);
|
pPatch = malloc(sizeof *pPatch);
|
||||||
if (!pPatch) {
|
if (!pPatch) {
|
||||||
fprintf(stderr, "Out of memory!\n");
|
err(1, NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
*ppPatch = pPatch;
|
*ppPatch = pPatch;
|
||||||
readasciiz(s, f);
|
readasciiz(s, f);
|
||||||
pPatch->pzFilename = malloc(strlen(s) + 1);
|
pPatch->pzFilename = malloc(strlen(s) + 1);
|
||||||
if (!pPatch->pzFilename) {
|
if (!pPatch->pzFilename) {
|
||||||
fprintf(stderr, "Out of memory!\n");
|
err(1, NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
strcpy(pPatch->pzFilename, s);
|
strcpy(pPatch->pzFilename, s);
|
||||||
@@ -342,7 +337,7 @@ obj_ReadRGB1Section(FILE * f)
|
|||||||
if ((pPatch->nRPNSize = readlong(f)) > 0) {
|
if ((pPatch->nRPNSize = readlong(f)) > 0) {
|
||||||
pPatch->pRPN = malloc(pPatch->nRPNSize);
|
pPatch->pRPN = malloc(pPatch->nRPNSize);
|
||||||
if (!pPatch->pRPN) {
|
if (!pPatch->pRPN) {
|
||||||
fprintf(stderr, "Out of memory!\n");
|
err(1, NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
fread(pPatch->pRPN, sizeof(UBYTE),
|
fread(pPatch->pRPN, sizeof(UBYTE),
|
||||||
@@ -376,7 +371,7 @@ obj_ReadRGB1(FILE * pObjfile)
|
|||||||
if (nNumberOfSymbols) {
|
if (nNumberOfSymbols) {
|
||||||
tSymbols = malloc(nNumberOfSymbols * sizeof *tSymbols);
|
tSymbols = malloc(nNumberOfSymbols * sizeof *tSymbols);
|
||||||
if (!tSymbols) {
|
if (!tSymbols) {
|
||||||
fprintf(stderr, "Out of memory!\n");
|
err(1, NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
for (i = 0; i < nNumberOfSymbols; i += 1)
|
for (i = 0; i < nNumberOfSymbols; i += 1)
|
||||||
@@ -440,14 +435,10 @@ obj_ReadOpenFile(FILE * pObjfile, char *tzObjectfile)
|
|||||||
obj_ReadRGB1(pObjfile);
|
obj_ReadRGB1(pObjfile);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
fprintf(stderr, "'%s' is an unsupported version",
|
errx(1, "'%s' is an unsupported version", tzObjectfile);
|
||||||
tzObjectfile);
|
|
||||||
exit(1);
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
fprintf(stderr, "'%s' is not a valid object\n", tzObjectfile);
|
errx(1, "'%s' is not a valid object", tzObjectfile);
|
||||||
exit(1);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -463,10 +454,7 @@ obj_Readfile(char *tzObjectfile)
|
|||||||
|
|
||||||
pObjfile = fopen(tzObjectfile, "rb");
|
pObjfile = fopen(tzObjectfile, "rb");
|
||||||
if (pObjfile == NULL) {
|
if (pObjfile == NULL) {
|
||||||
fprintf(stderr, "Unable to open object '%s': ",
|
err(1, "Unable to open object '%s'", tzObjectfile);
|
||||||
tzObjectfile);
|
|
||||||
perror(NULL);
|
|
||||||
exit(1);
|
|
||||||
}
|
}
|
||||||
obj_ReadOpenFile(pObjfile, tzObjectfile);
|
obj_ReadOpenFile(pObjfile, tzObjectfile);
|
||||||
fclose(pObjfile);
|
fclose(pObjfile);
|
||||||
@@ -516,13 +504,7 @@ lib_Readfile(char *tzLibfile)
|
|||||||
|
|
||||||
pObjfile = fopen(tzLibfile, "rb");
|
pObjfile = fopen(tzLibfile, "rb");
|
||||||
if (pObjfile == NULL) {
|
if (pObjfile == NULL) {
|
||||||
fprintf(stderr, "Unable to open object '%s': ", tzLibfile);
|
err(1, "Unable to open object '%s'", tzLibfile);
|
||||||
perror(NULL);
|
|
||||||
exit(1);
|
|
||||||
}
|
|
||||||
if (!pObjfile) {
|
|
||||||
fprintf(stderr, "Unable to open '%s'\n", tzLibfile);
|
|
||||||
exit(1);
|
|
||||||
}
|
}
|
||||||
char tzHeader[5];
|
char tzHeader[5];
|
||||||
|
|
||||||
@@ -531,9 +513,7 @@ lib_Readfile(char *tzLibfile)
|
|||||||
if (strcmp(tzHeader, "XLB0") == 0)
|
if (strcmp(tzHeader, "XLB0") == 0)
|
||||||
lib_ReadXLB0(pObjfile);
|
lib_ReadXLB0(pObjfile);
|
||||||
else {
|
else {
|
||||||
fprintf(stderr, "'%s' is an invalid library\n",
|
errx(1, "'%s' is an invalid library", tzLibfile);
|
||||||
tzLibfile);
|
|
||||||
exit(1);
|
|
||||||
}
|
}
|
||||||
fclose(pObjfile);
|
fclose(pObjfile);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,6 +2,7 @@
|
|||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
|
#include "extern/err.h"
|
||||||
#include "link/mylink.h"
|
#include "link/mylink.h"
|
||||||
#include "link/symbol.h"
|
#include "link/symbol.h"
|
||||||
#include "link/main.h"
|
#include "link/main.h"
|
||||||
@@ -46,8 +47,7 @@ getsymvalue(SLONG symid)
|
|||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
fprintf(stderr, "*INTERNAL* UNKNOWN SYMBOL TYPE\n");
|
errx(1, "*INTERNAL* UNKNOWN SYMBOL TYPE");
|
||||||
exit(1);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
SLONG
|
SLONG
|
||||||
@@ -64,8 +64,7 @@ getsymbank(SLONG symid)
|
|||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
fprintf(stderr, "*INTERNAL* UNKNOWN SYMBOL TYPE\n");
|
errx(1, "*INTERNAL* UNKNOWN SYMBOL TYPE");
|
||||||
exit(1);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
SLONG
|
SLONG
|
||||||
@@ -159,20 +158,18 @@ calcrpn(struct sPatch * pPatch)
|
|||||||
t = rpnpop();
|
t = rpnpop();
|
||||||
rpnpush(t & 0xFF);
|
rpnpush(t & 0xFF);
|
||||||
if (t < 0 || (t > 0xFF && t < 0xFF00) || t > 0xFFFF) {
|
if (t < 0 || (t > 0xFF && t < 0xFF00) || t > 0xFFFF) {
|
||||||
fprintf(stderr,
|
errx(1,
|
||||||
"%s(%ld) : Value must be in the HRAM area\n",
|
"%s(%ld) : Value must be in the HRAM area",
|
||||||
pPatch->pzFilename, pPatch->nLineNo);
|
pPatch->pzFilename, pPatch->nLineNo);
|
||||||
exit(1);
|
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case RPN_PCEZP:
|
case RPN_PCEZP:
|
||||||
t = rpnpop();
|
t = rpnpop();
|
||||||
rpnpush(t & 0xFF);
|
rpnpush(t & 0xFF);
|
||||||
if (t < 0x2000 || t > 0x20FF) {
|
if (t < 0x2000 || t > 0x20FF) {
|
||||||
fprintf(stderr,
|
errx(1,
|
||||||
"%s(%ld) : Value must be in the ZP area\n",
|
"%s(%ld) : Value must be in the ZP area",
|
||||||
pPatch->pzFilename, pPatch->nLineNo);
|
pPatch->pzFilename, pPatch->nLineNo);
|
||||||
exit(1);
|
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case RPN_CONST:
|
case RPN_CONST:
|
||||||
@@ -217,11 +214,10 @@ calcrpn(struct sPatch * pPatch)
|
|||||||
high |= (*rpn++) << 24;
|
high |= (*rpn++) << 24;
|
||||||
t = rpnpop();
|
t = rpnpop();
|
||||||
if (t < low || t > high) {
|
if (t < low || t > high) {
|
||||||
fprintf(stderr,
|
errx(1,
|
||||||
"%s(%ld) : Value must be in the range [%ld;%ld]\n",
|
"%s(%ld) : Value must be in the range [%ld;%ld]",
|
||||||
pPatch->pzFilename,
|
pPatch->pzFilename,
|
||||||
pPatch->nLineNo, low, high);
|
pPatch->nLineNo, low, high);
|
||||||
exit(1);
|
|
||||||
}
|
}
|
||||||
rpnpush(t);
|
rpnpush(t);
|
||||||
size -= 8;
|
size -= 8;
|
||||||
@@ -255,11 +251,10 @@ Patch(void)
|
|||||||
pSect->pData[pPatch->nOffset] =
|
pSect->pData[pPatch->nOffset] =
|
||||||
(UBYTE) t;
|
(UBYTE) t;
|
||||||
} else {
|
} else {
|
||||||
fprintf(stderr,
|
errx(1,
|
||||||
"%s(%ld) : Value must be 8-bit\n",
|
"%s(%ld) : Value must be 8-bit",
|
||||||
pPatch->pzFilename,
|
pPatch->pzFilename,
|
||||||
pPatch->nLineNo);
|
pPatch->nLineNo);
|
||||||
exit(1);
|
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case PATCH_WORD_L:
|
case PATCH_WORD_L:
|
||||||
@@ -280,11 +275,10 @@ Patch(void)
|
|||||||
1] = t & 0xFF;
|
1] = t & 0xFF;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
fprintf(stderr,
|
errx(1,
|
||||||
"%s(%ld) : Value must be 16-bit\n",
|
"%s(%ld) : Value must be 16-bit",
|
||||||
pPatch->pzFilename,
|
pPatch->pzFilename,
|
||||||
pPatch->nLineNo);
|
pPatch->nLineNo);
|
||||||
exit(1);
|
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case PATCH_LONG_L:
|
case PATCH_LONG_L:
|
||||||
|
|||||||
@@ -2,6 +2,7 @@
|
|||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
|
#include "extern/err.h"
|
||||||
#include "link/main.h"
|
#include "link/main.h"
|
||||||
#include "link/patch.h"
|
#include "link/patch.h"
|
||||||
#include "link/types.h"
|
#include "link/types.h"
|
||||||
@@ -53,8 +54,7 @@ sym_GetValue(char *tzName)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fprintf(stderr, "Unknown symbol '%s'\n", tzName);
|
errx(1, "Unknown symbol '%s'", tzName);
|
||||||
exit(1);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -72,8 +72,7 @@ sym_GetBank(char *tzName)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fprintf(stderr, "Unknown symbol '%s'\n", tzName);
|
errx(1, "Unknown symbol '%s'", tzName);
|
||||||
exit(1);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
@@ -93,10 +92,7 @@ sym_CreateSymbol(char *tzName, SLONG nValue, SBYTE nBank)
|
|||||||
if (nBank == -1)
|
if (nBank == -1)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
fprintf(stderr,
|
errx(1, "Symbol '%s' defined more than once", tzName);
|
||||||
"Symbol '%s' defined more than once\n",
|
|
||||||
tzName);
|
|
||||||
exit(1);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user