mirror of
https://github.com/gbdev/rgbds.git
synced 2025-11-21 10:42:07 +00:00
Compare commits
31 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
748943f6fc | ||
|
|
d945c5811c | ||
|
|
6fe2741f2d | ||
|
|
24d7cfe0f9 | ||
|
|
630933b148 | ||
|
|
e8a16c6f53 | ||
|
|
2cb50730a1 | ||
|
|
efae6c7fd2 | ||
|
|
8a559beeb8 | ||
|
|
7149fc1e39 | ||
|
|
2e695334c1 | ||
|
|
e2b4554a5c | ||
|
|
ef87dd5a6e | ||
|
|
4f126b37d0 | ||
|
|
1b4187e51f | ||
|
|
0daec91683 | ||
|
|
cbaaec98ca | ||
|
|
895d1d5813 | ||
|
|
e99a651165 | ||
|
|
0ae69b3114 | ||
|
|
95ccc48d0c | ||
|
|
29253046d5 | ||
|
|
340362d984 | ||
|
|
85ece88268 | ||
|
|
516e4578ea | ||
|
|
9829be1045 | ||
|
|
b28a16c0da | ||
|
|
4d13d57491 | ||
|
|
be6bc7460b | ||
|
|
efdd42c6a8 | ||
|
|
c1a97f6541 |
@@ -16,6 +16,9 @@
|
||||
# Show file line, not input line
|
||||
--showfile
|
||||
|
||||
# Don't expect SPDX tag in the first line of a file
|
||||
--ignore SPDX_LICENSE_TAG
|
||||
|
||||
# List of ignored rules
|
||||
# ---------------------
|
||||
|
||||
@@ -53,6 +56,9 @@
|
||||
# Prefer stdint.h types over kernel types
|
||||
--ignore PREFER_KERNEL_TYPES
|
||||
|
||||
# Don't ask to replace sscanf by kstrto
|
||||
--ignore SSCANF_TO_KSTRTO
|
||||
|
||||
# Parentheses can make the code clearer
|
||||
--ignore UNNECESSARY_PARENTHESES
|
||||
|
||||
|
||||
48
.travis-checkpatch.sh
Executable file
48
.travis-checkpatch.sh
Executable file
@@ -0,0 +1,48 @@
|
||||
#!/bin/bash
|
||||
|
||||
echo "Checking code style..."
|
||||
|
||||
# Return failure as soon as a command fails to execute
|
||||
|
||||
set -e
|
||||
|
||||
# Download checkpatch.pl and related files
|
||||
|
||||
echo "Getting checkpatch.pl..."
|
||||
|
||||
mkdir checkpatchdir
|
||||
|
||||
wget https://raw.githubusercontent.com/torvalds/linux/master/scripts/checkpatch.pl
|
||||
mv checkpatch.pl checkpatchdir/checkpatch.pl
|
||||
chmod +x checkpatchdir/checkpatch.pl
|
||||
|
||||
touch checkpatchdir/const_structs.checkpatch
|
||||
touch checkpatchdir/spelling.txt
|
||||
|
||||
# Run checkpatch.pl on the new commits
|
||||
|
||||
echo "Running checkpatch.pl..."
|
||||
|
||||
fname=$(mktemp)
|
||||
rc=0
|
||||
|
||||
git remote set-branches --add origin develop
|
||||
git fetch
|
||||
|
||||
make CHECKPATCH=checkpatchdir/checkpatch.pl checkpatch > $fname
|
||||
|
||||
cat $fname
|
||||
|
||||
if grep "ERROR" $fname; then
|
||||
# At least one error found
|
||||
echo "Code style errors have been found!"
|
||||
rc=1
|
||||
else
|
||||
echo "No code style errors found, your patches are ready!"
|
||||
fi
|
||||
|
||||
# Cleanup
|
||||
|
||||
rm -rf checkpatchdir
|
||||
|
||||
exit $rc
|
||||
@@ -10,5 +10,6 @@ compiler:
|
||||
- clang
|
||||
- gcc
|
||||
script:
|
||||
- ./.travis-checkpatch.sh
|
||||
- cd test
|
||||
- ./run-tests.sh
|
||||
|
||||
@@ -70,24 +70,29 @@ copyright and the reference to the MIT License.
|
||||
3. Create a new branch to work on. You could still work on ``develop``, but it's
|
||||
easier that way.
|
||||
|
||||
4. Sign off your commits: ``git commit -s``
|
||||
4. Compile your changes with ``make develop`` instead of just ``make``. This
|
||||
target checks for additional warnings. Your patches shouldn't introduce any
|
||||
new warning (but it may be possible to remove some warning checks if it makes
|
||||
the code much easier).
|
||||
|
||||
5. Follow the Linux kernel coding style, which can be found in the file
|
||||
5. Sign off your commits: ``git commit -s``
|
||||
|
||||
6. Follow the Linux kernel coding style, which can be found in the file
|
||||
``Documentation/process/coding-style.rst`` in the Linux kernel repository.
|
||||
Note that the coding style isn't writen on stone, if there is a good reason
|
||||
to deviate from it, it should be fine.
|
||||
|
||||
6. Download the files ``checkpatch.pl``, ``const_structs.checkpatch`` and
|
||||
7. Download the files ``checkpatch.pl``, ``const_structs.checkpatch`` and
|
||||
``spelling.txt`` from the folder ``scripts`` in the Linux kernel repository.
|
||||
|
||||
7. To use ``checkpatch.pl`` you can use ``make checkpatch``, which will check
|
||||
8. To use ``checkpatch.pl`` you can use ``make checkpatch``, which will check
|
||||
the coding style of all patches between the current one and the upstream
|
||||
code. By default, the Makefile expects the script (and associate files) to be
|
||||
located in ``../linux/scripts/``, but you can place them anywhere you like as
|
||||
long as you specify it when executing the command:
|
||||
``CHECKPATCH=../path/to/folder make checkpatch``.
|
||||
|
||||
8. Create a pull request against the branch ``develop``.
|
||||
9. Create a pull request against the branch ``develop``.
|
||||
|
||||
9. Be prepared to get some comments about your code and to modify it. Tip: Use
|
||||
``git rebase -i origin/develop`` to modify chains of commits.
|
||||
10. Be prepared to get some comments about your code and to modify it. Tip: Use
|
||||
``git rebase -i origin/develop`` to modify chains of commits.
|
||||
|
||||
27
Makefile
27
Makefile
@@ -26,7 +26,7 @@ PNGLDLIBS := `${PKG_CONFIG} --static --libs-only-l libpng`
|
||||
|
||||
VERSION_STRING := `git describe --tags --dirty --always 2>/dev/null`
|
||||
|
||||
WARNFLAGS := -Wall -Werror
|
||||
WARNFLAGS := -Wall
|
||||
|
||||
# Overridable CFLAGS
|
||||
CFLAGS := -g
|
||||
@@ -160,6 +160,7 @@ install: all
|
||||
|
||||
# Target used to check the coding style of the whole codebase. '.y' and '.l'
|
||||
# files aren't checked, unfortunately...
|
||||
|
||||
checkcodebase:
|
||||
$Qfor file in `git ls-files | grep -E '\.c|\.h' | grep -v '\.html'`; do \
|
||||
${CHECKPATCH} -f "$$file"; \
|
||||
@@ -169,6 +170,7 @@ checkcodebase:
|
||||
# to the HEAD. Runs checkpatch once for each commit between the current HEAD and
|
||||
# the first common commit between the HEAD and origin/develop. '.y' and '.l'
|
||||
# files aren't checked, unfortunately...
|
||||
|
||||
checkpatch:
|
||||
$Qeval COMMON_COMMIT=$$(git merge-base HEAD origin/develop); \
|
||||
for commit in `git rev-list $$COMMON_COMMIT..HEAD`; do \
|
||||
@@ -193,6 +195,25 @@ wwwman:
|
||||
$Qmandoc ${MANDOC} src/link/rgblink.5 > docs/rgblink.5.html
|
||||
$Qmandoc ${MANDOC} src/gfx/rgbgfx.1 > docs/rgbgfx.1.html
|
||||
|
||||
# This target is used during development in order to prevent adding new issues
|
||||
# to the source code. All warnings are treated as errors in order to block the
|
||||
# compilation and make the continous integration infrastructure return failure.
|
||||
|
||||
develop:
|
||||
$Qenv make -j WARNFLAGS="-Werror -Wall -Wextra -Wpedantic \
|
||||
-Wno-sign-compare -Wchkp -Wformat=2 -Wformat-overflow=2 \
|
||||
-Wformat-truncation=1 -Wformat-y2k -Wswitch-enum -Wunused \
|
||||
-Wuninitialized -Wunknown-pragmas -Wstrict-overflow=5 \
|
||||
-Wstringop-overflow=4 -Walloc-zero -Wduplicated-cond \
|
||||
-Wfloat-equal -Wshadow -Wcast-qual -Wcast-align -Wlogical-op \
|
||||
-Wnested-externs -Wno-aggressive-loop-optimizations -Winline \
|
||||
-Wundef -Wstrict-prototypes -Wold-style-definition \
|
||||
-fsanitize=shift -fsanitize=integer-divide-by-zero \
|
||||
-fsanitize=unreachable -fsanitize=vla-bound \
|
||||
-fsanitize=signed-integer-overflow -fsanitize=bounds \
|
||||
-fsanitize=object-size -fsanitize=bool -fsanitize=enum \
|
||||
-fsanitize=alignment -fsanitize=null"
|
||||
|
||||
# Targets for the project maintainer to easily create Windows exes.
|
||||
# This is not for Windows users!
|
||||
# If you're building on Windows with Cygwin or Mingw, just follow the Unix
|
||||
@@ -200,7 +221,7 @@ wwwman:
|
||||
|
||||
mingw32:
|
||||
$Qenv PKG_CONFIG_PATH=/usr/i686-w64-mingw32/sys-root/mingw/lib/pkgconfig/ \
|
||||
make CC=i686-w64-mingw32-gcc YACC=bison WARNFLAGS= -j
|
||||
make CC=i686-w64-mingw32-gcc YACC=bison -j
|
||||
$Qmv rgbasm rgbasm.exe
|
||||
$Qmv rgblink rgblink.exe
|
||||
$Qmv rgbfix rgbfix.exe
|
||||
@@ -208,7 +229,7 @@ mingw32:
|
||||
|
||||
mingw64:
|
||||
$Qenv PKG_CONFIG_PATH=/usr/x86_64-w64-mingw32/sys-root/mingw/lib/pkgconfig/ \
|
||||
make CC=x86_64-w64-mingw32-gcc YACC=bison WARNFLAGS= -j
|
||||
make CC=x86_64-w64-mingw32-gcc YACC=bison -j
|
||||
$Qmv rgbasm rgbasm.exe
|
||||
$Qmv rgblink rgblink.exe
|
||||
$Qmv rgbfix rgbfix.exe
|
||||
|
||||
@@ -65,7 +65,9 @@ REPT NumberOfSymbols ; Number of symbols defined in this object file.
|
||||
LONG LineNum ; Line number in the file where the symbol is defined.
|
||||
|
||||
LONG SectionID ; The section number (of this object file) in which
|
||||
; this symbol is defined.
|
||||
; this symbol is defined. If it doesn't belong to any
|
||||
; specific section (like a constant), this field has
|
||||
; the value -1.
|
||||
|
||||
LONG Value ; The symbols value. It's the offset into that
|
||||
; symbol's section.
|
||||
|
||||
@@ -12,7 +12,7 @@
|
||||
#include <stdbool.h>
|
||||
#include <stdint.h>
|
||||
|
||||
#include "extern/stdnoreturn.h"
|
||||
#include "helpers.h"
|
||||
|
||||
struct sOptions {
|
||||
char binary[2];
|
||||
@@ -46,7 +46,7 @@ void opt_Parse(char *s);
|
||||
* It is also used when the assembler goes into an invalid state (for example,
|
||||
* when it fails to allocate memory).
|
||||
*/
|
||||
noreturn void fatalerror(const char *fmt, ...);
|
||||
noreturn_ void fatalerror(const char *fmt, ...);
|
||||
|
||||
/*
|
||||
* Used for errors that make it impossible to assemble correctly, but don't
|
||||
|
||||
10
include/extern/err.h
vendored
10
include/extern/err.h
vendored
@@ -17,7 +17,7 @@
|
||||
|
||||
#include <stdarg.h>
|
||||
|
||||
#include "extern/stdnoreturn.h"
|
||||
#include "helpers.h"
|
||||
|
||||
#define warn rgbds_warn
|
||||
#define vwarn rgbds_vwarn
|
||||
@@ -34,10 +34,10 @@ void vwarn(const char *fmt, va_list ap);
|
||||
void warnx(const char *fmt, ...);
|
||||
void vwarnx(const char *fmt, va_list ap);
|
||||
|
||||
noreturn void err(int status, const char *fmt, ...);
|
||||
noreturn void verr(int status, const char *fmt, va_list ap);
|
||||
noreturn void errx(int status, const char *fmt, ...);
|
||||
noreturn void verrx(int status, const char *fmt, va_list ap);
|
||||
noreturn_ void err(int status, const char *fmt, ...);
|
||||
noreturn_ void verr(int status, const char *fmt, va_list ap);
|
||||
noreturn_ void errx(int status, const char *fmt, ...);
|
||||
noreturn_ void verrx(int status, const char *fmt, va_list ap);
|
||||
|
||||
#endif /* ERR_IN_LIBC */
|
||||
|
||||
|
||||
29
include/extern/stdnoreturn.h
vendored
29
include/extern/stdnoreturn.h
vendored
@@ -1,29 +0,0 @@
|
||||
/*
|
||||
* This file is part of RGBDS.
|
||||
*
|
||||
* Copyright (c) 2014-2018, RGBDS contributors.
|
||||
*
|
||||
* SPDX-License-Identifier: MIT
|
||||
*/
|
||||
|
||||
#ifndef EXTERN_STDNORETURN_H
|
||||
#define EXTERN_STDNORETURN_H
|
||||
|
||||
#if __STDC_VERSION__ >= 201112L
|
||||
/* C11 or newer */
|
||||
#define noreturn _Noreturn
|
||||
#elif __cplusplus >= 201103L
|
||||
/* C++11 or newer */
|
||||
#define noreturn [[noreturn]]
|
||||
#elif __GNUC__ > 2 || (__GNUC__ == 2 && (__GNUC_MINOR__ >= 5))
|
||||
/* GCC 2.5 or newer */
|
||||
#define noreturn __attribute__ ((noreturn))
|
||||
#elif _MSC_VER >= 1310
|
||||
/* MS Visual Studio 2003/.NET Framework 1.1 or newer */
|
||||
#define noreturn _declspec(noreturn)
|
||||
#else
|
||||
/* Unsupported, but no need to throw a fit */
|
||||
#define noreturn
|
||||
#endif
|
||||
|
||||
#endif /* EXTERN_STDNORETURN_H */
|
||||
22
include/helpers.h
Normal file
22
include/helpers.h
Normal file
@@ -0,0 +1,22 @@
|
||||
/*
|
||||
* This file is part of RGBDS.
|
||||
*
|
||||
* Copyright (c) 2014-2018, RGBDS contributors.
|
||||
*
|
||||
* SPDX-License-Identifier: MIT
|
||||
*/
|
||||
|
||||
#ifndef HELPERS_H
|
||||
#define HELPERS_H
|
||||
|
||||
#ifdef __GNUC__
|
||||
/* GCC or compatible */
|
||||
#define noreturn_ __attribute__ ((noreturn))
|
||||
#define unused_ __attribute__ ((unused))
|
||||
#else
|
||||
/* Unsupported, but no need to throw a fit */
|
||||
#define noreturn_
|
||||
#define unused_
|
||||
#endif
|
||||
|
||||
#endif /* HELPERS_H */
|
||||
@@ -11,9 +11,9 @@
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
#include "extern/stdnoreturn.h"
|
||||
#include "helpers.h"
|
||||
|
||||
noreturn void script_fatalerror(const char *fmt, ...);
|
||||
noreturn_ void script_fatalerror(const char *fmt, ...);
|
||||
|
||||
void script_Parse(const char *path);
|
||||
|
||||
|
||||
@@ -11,7 +11,7 @@
|
||||
|
||||
#define PACKAGE_VERSION_MAJOR (0)
|
||||
#define PACKAGE_VERSION_MINOR (3)
|
||||
#define PACKAGE_VERSION_PATCH (6)
|
||||
#define PACKAGE_VERSION_PATCH (7)
|
||||
|
||||
const char *get_package_version_string(void);
|
||||
|
||||
|
||||
155
src/asm/asmy.y
155
src/asm/asmy.y
@@ -28,8 +28,10 @@
|
||||
#include "common.h"
|
||||
#include "linkdefs.h"
|
||||
|
||||
uint32_t nListCountEmpty;
|
||||
char *tzNewMacro;
|
||||
uint32_t ulNewMacroSize;
|
||||
int32_t nPCOffset;
|
||||
|
||||
static void bankrangecheck(char *name, uint32_t secttype, int32_t org,
|
||||
int32_t bank)
|
||||
@@ -339,8 +341,9 @@ static void if_skip_to_else(void)
|
||||
break;
|
||||
|
||||
case '\"':
|
||||
src++;
|
||||
src += 2;
|
||||
inString = false;
|
||||
break;
|
||||
|
||||
default:
|
||||
src++;
|
||||
@@ -579,10 +582,13 @@ asmfile : lines;
|
||||
|
||||
/* Note: The lexer adds '\n' at the end of the input */
|
||||
lines : /* empty */
|
||||
| lines line '\n' {
|
||||
nLineNo += 1;
|
||||
nTotalLines += 1;
|
||||
}
|
||||
| lines {
|
||||
nListCountEmpty = 0;
|
||||
nPCOffset = 1;
|
||||
} line '\n' {
|
||||
nLineNo += 1;
|
||||
nTotalLines += 1;
|
||||
}
|
||||
;
|
||||
|
||||
line : label
|
||||
@@ -655,9 +661,9 @@ simple_pseudoop : include
|
||||
| import
|
||||
| export
|
||||
| global
|
||||
| db
|
||||
| dw
|
||||
| dl
|
||||
| { nPCOffset = 0; } db
|
||||
| { nPCOffset = 0; } dw
|
||||
| { nPCOffset = 0; } dl
|
||||
| ds
|
||||
| section
|
||||
| rsreset
|
||||
@@ -802,16 +808,28 @@ ds : T_POP_DS uconst
|
||||
}
|
||||
;
|
||||
|
||||
db : T_POP_DB constlist_8bit_entry comma constlist_8bit
|
||||
| T_POP_DB constlist_8bit_entry_single
|
||||
db : T_POP_DB constlist_8bit_entry comma constlist_8bit {
|
||||
if ((nPass == 1) && (nListCountEmpty > 0)) {
|
||||
warning("Empty entry in list of 8-bit elements (treated as 0).");
|
||||
}
|
||||
}
|
||||
| T_POP_DB constlist_8bit_entry
|
||||
;
|
||||
|
||||
dw : T_POP_DW constlist_16bit_entry comma constlist_16bit
|
||||
| T_POP_DW constlist_16bit_entry_single
|
||||
dw : T_POP_DW constlist_16bit_entry comma constlist_16bit {
|
||||
if ((nPass == 1) && (nListCountEmpty > 0)) {
|
||||
warning("Empty entry in list of 16-bit elements (treated as 0).");
|
||||
}
|
||||
}
|
||||
| T_POP_DW constlist_16bit_entry
|
||||
;
|
||||
|
||||
dl : T_POP_DL constlist_32bit_entry comma constlist_32bit
|
||||
| T_POP_DL constlist_32bit_entry_single
|
||||
dl : T_POP_DL constlist_32bit_entry comma constlist_32bit {
|
||||
if ((nPass == 1) && (nListCountEmpty > 0)) {
|
||||
warning("Empty entry in list of 32-bit elements (treated as 0).");
|
||||
}
|
||||
}
|
||||
| T_POP_DL constlist_32bit_entry
|
||||
;
|
||||
|
||||
purge : T_POP_PURGE {
|
||||
@@ -1028,26 +1046,7 @@ constlist_8bit : constlist_8bit_entry
|
||||
constlist_8bit_entry : /* empty */
|
||||
{
|
||||
out_Skip(1);
|
||||
if (nPass == 1)
|
||||
warning("Empty entry in list of 8-bit elements (treated as 0).");
|
||||
}
|
||||
| const_8bit
|
||||
{
|
||||
out_RelByte(&$1);
|
||||
}
|
||||
| string
|
||||
{
|
||||
char *s = $1;
|
||||
int32_t length = charmap_Convert(&s);
|
||||
|
||||
out_AbsByteGroup(s, length);
|
||||
free(s);
|
||||
}
|
||||
;
|
||||
|
||||
constlist_8bit_entry_single : /* empty */
|
||||
{
|
||||
out_Skip(1);
|
||||
nListCountEmpty++;
|
||||
}
|
||||
| const_8bit
|
||||
{
|
||||
@@ -1070,18 +1069,7 @@ constlist_16bit : constlist_16bit_entry
|
||||
constlist_16bit_entry : /* empty */
|
||||
{
|
||||
out_Skip(2);
|
||||
if (nPass == 1)
|
||||
warning("Empty entry in list of 16-bit elements (treated as 0).");
|
||||
}
|
||||
| const_16bit
|
||||
{
|
||||
out_RelWord(&$1);
|
||||
}
|
||||
;
|
||||
|
||||
constlist_16bit_entry_single : /* empty */
|
||||
{
|
||||
out_Skip(2);
|
||||
nListCountEmpty++;
|
||||
}
|
||||
| const_16bit
|
||||
{
|
||||
@@ -1096,18 +1084,7 @@ constlist_32bit : constlist_32bit_entry
|
||||
constlist_32bit_entry : /* empty */
|
||||
{
|
||||
out_Skip(4);
|
||||
if (nPass == 1)
|
||||
warning("Empty entry in list of 32-bit elements (treated as 0).");
|
||||
}
|
||||
| relocconst
|
||||
{
|
||||
out_RelLong(&$1);
|
||||
}
|
||||
;
|
||||
|
||||
constlist_32bit_entry_single : /* empty */
|
||||
{
|
||||
out_Skip(4);
|
||||
nListCountEmpty++;
|
||||
}
|
||||
| relocconst
|
||||
{
|
||||
@@ -1134,8 +1111,39 @@ const_16bit : relocconst
|
||||
|
||||
relocconst : T_ID
|
||||
{
|
||||
rpn_Symbol(&$$, $1);
|
||||
$$.nVal = sym_GetValue($1);
|
||||
/*
|
||||
* The value of @ needs to be evaluated by the linker,
|
||||
* it can only be calculated by the assembler in very
|
||||
* few cases (when the base address of a section is
|
||||
* known).
|
||||
*
|
||||
* '@' is a bit special in that it means different
|
||||
* things depending on when it is used:
|
||||
*
|
||||
* - JR/LD/ADD/etc: It refers to the first byte of the
|
||||
* instruction (1 byte offset relative to the value
|
||||
* stored in the ROM).
|
||||
* - DB/DW/DL: It refers to the address of the value
|
||||
* that is being saved (0 byte offset relative to the
|
||||
* value stored in the ROM.
|
||||
*
|
||||
* This offset must be added whenever '@' is added to a
|
||||
* RPN expression so that the linker can calculate the
|
||||
* correct result of any expression that uses '@'.
|
||||
*/
|
||||
if ((strcmp($1, "@") == 0) && (nPCOffset != 0)) {
|
||||
struct Expression sTemp, sOffset;
|
||||
|
||||
rpn_Symbol(&sTemp, $1);
|
||||
sTemp.nVal = sym_GetValue($1);
|
||||
|
||||
rpn_Number(&sOffset, nPCOffset);
|
||||
|
||||
rpn_SUB(&$$, &sTemp, &sOffset);
|
||||
} else {
|
||||
rpn_Symbol(&$$, $1);
|
||||
$$.nVal = sym_GetValue($1);
|
||||
}
|
||||
}
|
||||
| T_NUMBER
|
||||
{
|
||||
@@ -1256,19 +1264,38 @@ const : T_ID { $$ = sym_GetConstantValue($1); }
|
||||
| const T_OP_XOR const { $$ = $1 ^ $3; }
|
||||
| const T_OP_OR const { $$ = $1 | $3; }
|
||||
| const T_OP_AND const { $$ = $1 & $3; }
|
||||
| const T_OP_SHL const { $$ = $1 << $3; }
|
||||
| const T_OP_SHR const { $$ = $1 >> $3; }
|
||||
| const T_OP_SHL const
|
||||
{
|
||||
if ($1 < 0)
|
||||
warning("Left shift of negative value: %d", $1);
|
||||
|
||||
if ($3 < 0)
|
||||
fatalerror("Shift by negative value: %d", $3);
|
||||
else if ($3 >= 32)
|
||||
fatalerror("Shift by too big value: %d", $3);
|
||||
|
||||
$$ = $1 << $3;
|
||||
}
|
||||
| const T_OP_SHR const
|
||||
{
|
||||
if ($3 < 0)
|
||||
fatalerror("Shift by negative value: %d", $3);
|
||||
else if ($3 >= 32)
|
||||
fatalerror("Shift by too big value: %d", $3);
|
||||
|
||||
$$ = $1 >> $3;
|
||||
}
|
||||
| const T_OP_MUL const { $$ = $1 * $3; }
|
||||
| const T_OP_DIV const
|
||||
{
|
||||
if ($3 == 0)
|
||||
fatalerror("division by zero");
|
||||
fatalerror("Division by zero");
|
||||
$$ = $1 / $3;
|
||||
}
|
||||
| const T_OP_MOD const
|
||||
{
|
||||
if ($3 == 0)
|
||||
fatalerror("division by zero");
|
||||
fatalerror("Division by zero");
|
||||
$$ = $1 % $3;
|
||||
}
|
||||
| T_OP_ADD const %prec NEG { $$ = +$2; }
|
||||
|
||||
@@ -87,6 +87,8 @@ static void pushcontext(void)
|
||||
(*ppFileStack)->nREPTBlockSize = nCurrentREPTBlockSize;
|
||||
(*ppFileStack)->nREPTBlockCount = nCurrentREPTBlockCount;
|
||||
break;
|
||||
default:
|
||||
fatalerror("%s: Internal error.", __func__);
|
||||
}
|
||||
|
||||
nLineNo = 0;
|
||||
@@ -152,6 +154,8 @@ static int32_t popcontext(void)
|
||||
nCurrentREPTBlockSize = pLastFile->nREPTBlockSize;
|
||||
nCurrentREPTBlockCount = pLastFile->nREPTBlockCount;
|
||||
break;
|
||||
default:
|
||||
fatalerror("%s: Internal error.", __func__);
|
||||
}
|
||||
|
||||
free(*ppLastFile);
|
||||
@@ -174,6 +178,8 @@ int32_t fstk_GetLine(void)
|
||||
return nLineNo; /* ??? */
|
||||
case STAT_isREPTBlock:
|
||||
break; /* Peek top file of the stack */
|
||||
default:
|
||||
fatalerror("%s: Internal error.", __func__);
|
||||
}
|
||||
|
||||
pLastFile = pFileStack;
|
||||
@@ -257,8 +263,10 @@ FILE *fstk_FindFile(char *fname)
|
||||
* space had been available. Thus, a return value of `size` or
|
||||
* more means that the output was truncated.
|
||||
*/
|
||||
if (snprintf(path, sizeof(path), "%s%s", IncludePaths[i], fname)
|
||||
>= sizeof(path))
|
||||
int fullpathlen = snprintf(path, sizeof(path), "%s%s",
|
||||
IncludePaths[i], fname);
|
||||
|
||||
if (fullpathlen >= (int)sizeof(path))
|
||||
continue;
|
||||
|
||||
f = fopen(path, "rb");
|
||||
|
||||
@@ -20,6 +20,8 @@
|
||||
#include "asm/symbol.h"
|
||||
#include "asm/symbol.h"
|
||||
|
||||
#include "helpers.h"
|
||||
|
||||
#include "asmy.h"
|
||||
|
||||
bool oDontExpandStrings;
|
||||
@@ -93,6 +95,9 @@ static int32_t ascii2bin(char *s)
|
||||
s += 1;
|
||||
convertfunc = binary2bin;
|
||||
break;
|
||||
default:
|
||||
/* Handle below */
|
||||
break;
|
||||
}
|
||||
|
||||
if (radix == 4) {
|
||||
@@ -216,7 +221,7 @@ uint32_t PutMacroArg(char *src, uint32_t size)
|
||||
return 0;
|
||||
}
|
||||
|
||||
uint32_t PutUniqueArg(char *src, uint32_t size)
|
||||
uint32_t PutUniqueArg(unused_ char *src, uint32_t size)
|
||||
{
|
||||
char *s;
|
||||
|
||||
@@ -579,7 +584,7 @@ void setup_lexer(void)
|
||||
lex_FloatAddRange(id, '@', '@');
|
||||
lex_FloatAddRange(id, '#', '#');
|
||||
|
||||
//@ID
|
||||
// "@"
|
||||
|
||||
id = lex_FloatAlloc(&tIDToken);
|
||||
lex_FloatAddFirstRange(id, '@', '@');
|
||||
|
||||
@@ -414,7 +414,7 @@ void yylex_GetFloatMaskAndFloatLen(uint32_t *pnFloatMask, uint32_t *pnFloatLen)
|
||||
/*
|
||||
* Gets the longest keyword/operator from the current position in the buffer.
|
||||
*/
|
||||
struct sLexString *yylex_GetLongestFixed()
|
||||
struct sLexString *yylex_GetLongestFixed(void)
|
||||
{
|
||||
struct sLexString *pLongestFixed = NULL;
|
||||
char *s = pLexBuffer;
|
||||
@@ -640,7 +640,6 @@ scanagain:
|
||||
|
||||
/* Check for line continuation character */
|
||||
if (*pLexBuffer == '\\') {
|
||||
|
||||
/*
|
||||
* Look for line continuation character after a series of
|
||||
* spaces. This is also useful for files that use Windows line
|
||||
@@ -851,7 +850,7 @@ uint32_t yylex(void)
|
||||
return yylex_NORMAL();
|
||||
case LEX_STATE_MACROARGS:
|
||||
return yylex_MACROARGS();
|
||||
default:
|
||||
fatalerror("%s: Internal error.", __func__);
|
||||
}
|
||||
|
||||
fatalerror("Internal error in %s", __func__);
|
||||
}
|
||||
|
||||
@@ -6,6 +6,7 @@
|
||||
* SPDX-License-Identifier: MIT
|
||||
*/
|
||||
|
||||
#include <float.h>
|
||||
#include <math.h>
|
||||
#include <stdarg.h>
|
||||
#include <stdio.h>
|
||||
@@ -23,6 +24,7 @@
|
||||
|
||||
#include "extern/err.h"
|
||||
|
||||
#include "helpers.h"
|
||||
#include "version.h"
|
||||
|
||||
extern int yyparse(void);
|
||||
@@ -147,10 +149,13 @@ void opt_Parse(char *s)
|
||||
case 'z':
|
||||
if (strlen(&s[1]) <= 2) {
|
||||
int32_t result;
|
||||
unsigned int fillchar;
|
||||
|
||||
result = sscanf(&s[1], "%x", &newopt.fillchar);
|
||||
result = sscanf(&s[1], "%x", &fillchar);
|
||||
if (!((result == EOF) || (result == 1)))
|
||||
errx(1, "Invalid argument for option 'z'");
|
||||
|
||||
newopt.fillchar = fillchar;
|
||||
} else {
|
||||
errx(1, "Invalid argument for option 'z'");
|
||||
}
|
||||
@@ -222,7 +227,7 @@ void opt_AddDefine(char *s)
|
||||
|
||||
static void opt_ParseDefines(void)
|
||||
{
|
||||
int32_t i;
|
||||
uint32_t i;
|
||||
|
||||
for (i = 0; i < cldefines_index; i += 2)
|
||||
sym_AddString(cldefines[i], cldefines[i + 1]);
|
||||
@@ -235,7 +240,7 @@ void verror(const char *fmt, va_list args)
|
||||
{
|
||||
fprintf(stderr, "ERROR: ");
|
||||
fstk_Dump();
|
||||
fprintf(stderr, ":\n\t");
|
||||
fprintf(stderr, ":\n ");
|
||||
vfprintf(stderr, fmt, args);
|
||||
fprintf(stderr, "\n");
|
||||
nErrors += 1;
|
||||
@@ -250,7 +255,7 @@ void yyerror(const char *fmt, ...)
|
||||
va_end(args);
|
||||
}
|
||||
|
||||
void fatalerror(const char *fmt, ...)
|
||||
noreturn_ void fatalerror(const char *fmt, ...)
|
||||
{
|
||||
va_list args;
|
||||
|
||||
@@ -272,7 +277,7 @@ void warning(const char *fmt, ...)
|
||||
|
||||
fprintf(stderr, "warning: ");
|
||||
fstk_Dump();
|
||||
fprintf(stderr, ":\n\t");
|
||||
fprintf(stderr, ":\n ");
|
||||
vfprintf(stderr, fmt, args);
|
||||
fprintf(stderr, "\n");
|
||||
|
||||
@@ -480,7 +485,7 @@ int main(int argc, char *argv[])
|
||||
if (CurrentOptions.verbose) {
|
||||
printf("Success! %u lines in %d.%02d seconds ", nTotalLines,
|
||||
(int)timespent, ((int)(timespent * 100.0)) % 100);
|
||||
if (timespent == 0)
|
||||
if (timespent < FLT_MIN_EXP)
|
||||
printf("(INFINITY lines/minute)\n");
|
||||
else
|
||||
printf("(%d lines/minute)\n",
|
||||
|
||||
@@ -882,24 +882,16 @@ void out_PCRelByte(struct Expression *expr)
|
||||
{
|
||||
checkcodesection();
|
||||
checksectionoverflow(1);
|
||||
if (rpn_isReloc(expr)) {
|
||||
if (nPass == 2) {
|
||||
pCurrentSection->tData[nPC] = 0;
|
||||
createpatch(PATCH_BYTE_JR, expr);
|
||||
}
|
||||
pCurrentSection->nPC += 1;
|
||||
nPC += 1;
|
||||
pPCSymbol->nValue += 1;
|
||||
} else {
|
||||
int32_t b = expr->nVal;
|
||||
|
||||
b = (int16_t)((b & 0xFFFF) - (nPC + 1));
|
||||
|
||||
if (nPass == 2 && ((b < -128) || (b > 127)))
|
||||
yyerror("PC-relative value must be 8-bit");
|
||||
|
||||
out_AbsByte(b & 0xFF);
|
||||
/* Always let the linker calculate the offset. */
|
||||
if (nPass == 2) {
|
||||
pCurrentSection->tData[nPC] = 0;
|
||||
createpatch(PATCH_BYTE_JR, expr);
|
||||
}
|
||||
pCurrentSection->nPC += 1;
|
||||
nPC += 1;
|
||||
pPCSymbol->nValue += 1;
|
||||
|
||||
rpn_Reset(expr);
|
||||
}
|
||||
|
||||
|
||||
@@ -330,6 +330,15 @@ void rpn_SHL(struct Expression *expr, const struct Expression *src1,
|
||||
const struct Expression *src2)
|
||||
{
|
||||
joinexpr();
|
||||
|
||||
if (src1->nVal < 0)
|
||||
warning("Left shift of negative value: %d", src1->nVal);
|
||||
|
||||
if (src2->nVal < 0)
|
||||
fatalerror("Shift by negative value: %d", src2->nVal);
|
||||
else if (src2->nVal >= 32)
|
||||
fatalerror("Shift by too big value: %d", src2->nVal);
|
||||
|
||||
expr->nVal = (expr->nVal << src2->nVal);
|
||||
pushbyte(expr, RPN_SHL);
|
||||
}
|
||||
@@ -338,6 +347,11 @@ void rpn_SHR(struct Expression *expr, const struct Expression *src1,
|
||||
const struct Expression *src2)
|
||||
{
|
||||
joinexpr();
|
||||
if (src2->nVal < 0)
|
||||
fatalerror("Shift by negative value: %d", src2->nVal);
|
||||
else if (src2->nVal >= 32)
|
||||
fatalerror("Shift by too big value: %d", src2->nVal);
|
||||
|
||||
expr->nVal = (expr->nVal >> src2->nVal);
|
||||
pushbyte(expr, RPN_SHR);
|
||||
}
|
||||
@@ -355,7 +369,7 @@ void rpn_DIV(struct Expression *expr, const struct Expression *src1,
|
||||
{
|
||||
joinexpr();
|
||||
if (src2->nVal == 0)
|
||||
fatalerror("division by zero");
|
||||
fatalerror("Division by zero");
|
||||
|
||||
expr->nVal = (expr->nVal / src2->nVal);
|
||||
pushbyte(expr, RPN_DIV);
|
||||
@@ -366,7 +380,7 @@ void rpn_MOD(struct Expression *expr, const struct Expression *src1,
|
||||
{
|
||||
joinexpr();
|
||||
if (src2->nVal == 0)
|
||||
fatalerror("division by zero");
|
||||
fatalerror("Division by zero");
|
||||
|
||||
expr->nVal = (expr->nVal % src2->nVal);
|
||||
pushbyte(expr, RPN_MOD);
|
||||
|
||||
@@ -25,6 +25,7 @@
|
||||
|
||||
#include "extern/err.h"
|
||||
|
||||
#include "helpers.h"
|
||||
#include "version.h"
|
||||
|
||||
struct sSymbol *tHashedSymbols[HASHSIZE];
|
||||
@@ -62,7 +63,7 @@ void helper_RemoveLeadingZeros(char *string)
|
||||
memmove(string, new_beginning, strlen(new_beginning) + 1);
|
||||
}
|
||||
|
||||
int32_t Callback_NARG(struct sSymbol *sym)
|
||||
int32_t Callback_NARG(unused_ struct sSymbol *sym)
|
||||
{
|
||||
uint32_t i = 0;
|
||||
|
||||
@@ -72,7 +73,7 @@ int32_t Callback_NARG(struct sSymbol *sym)
|
||||
return i;
|
||||
}
|
||||
|
||||
int32_t Callback__LINE__(struct sSymbol __attribute__((unused)) *sym)
|
||||
int32_t Callback__LINE__(unused_ struct sSymbol *sym)
|
||||
{
|
||||
return nLineNo;
|
||||
}
|
||||
@@ -673,7 +674,7 @@ void sym_AddReloc(char *tzSym)
|
||||
|
||||
struct sSymbol *parent = pScope->pScope ?
|
||||
pScope->pScope : pScope;
|
||||
int32_t parentLen = localPtr - tzSym;
|
||||
uint32_t parentLen = localPtr - tzSym;
|
||||
|
||||
if (strchr(localPtr + 1, '.') != NULL) {
|
||||
fatalerror("'%s' is a nonsensical reference to a nested local symbol",
|
||||
|
||||
8
src/extern/err.c
vendored
8
src/extern/err.c
vendored
@@ -33,7 +33,7 @@ void rgbds_vwarnx(const char *fmt, va_list ap)
|
||||
putc('\n', stderr);
|
||||
}
|
||||
|
||||
noreturn void rgbds_verr(int status, const char *fmt, va_list ap)
|
||||
noreturn_ void rgbds_verr(int status, const char *fmt, va_list ap)
|
||||
{
|
||||
fprintf(stderr, "error");
|
||||
if (fmt) {
|
||||
@@ -44,7 +44,7 @@ noreturn void rgbds_verr(int status, const char *fmt, va_list ap)
|
||||
exit(status);
|
||||
}
|
||||
|
||||
noreturn void rgbds_verrx(int status, const char *fmt, va_list ap)
|
||||
noreturn_ void rgbds_verrx(int status, const char *fmt, va_list ap)
|
||||
{
|
||||
fprintf(stderr, "error");
|
||||
if (fmt) {
|
||||
@@ -73,7 +73,7 @@ void rgbds_warnx(const char *fmt, ...)
|
||||
va_end(ap);
|
||||
}
|
||||
|
||||
noreturn void rgbds_err(int status, const char *fmt, ...)
|
||||
noreturn_ void rgbds_err(int status, const char *fmt, ...)
|
||||
{
|
||||
va_list ap;
|
||||
|
||||
@@ -82,7 +82,7 @@ noreturn void rgbds_err(int status, const char *fmt, ...)
|
||||
va_end(ap);
|
||||
}
|
||||
|
||||
noreturn void rgbds_errx(int status, const char *fmt, ...)
|
||||
noreturn_ void rgbds_errx(int status, const char *fmt, ...)
|
||||
{
|
||||
va_list ap;
|
||||
|
||||
|
||||
124
src/fix/main.c
124
src/fix/main.c
@@ -207,9 +207,19 @@ int main(int argc, char *argv[])
|
||||
err(1, "Error opening file %s", argv[argc - 1]);
|
||||
|
||||
/*
|
||||
* Write changes to ROM
|
||||
* Read ROM header
|
||||
*
|
||||
* Offsets in the buffer are 0x100 less than the equivalent in ROM.
|
||||
*/
|
||||
|
||||
uint8_t header[0x50];
|
||||
|
||||
if (fseek(rom, 0x100, SEEK_SET) != 0)
|
||||
err(1, "Could not locate ROM header");
|
||||
if (fread(header, sizeof(uint8_t), sizeof(header), rom)
|
||||
!= sizeof(header))
|
||||
err(1, "Could not read ROM header");
|
||||
|
||||
if (fixlogo || trashlogo) {
|
||||
/*
|
||||
* Offset 0x104–0x133: Nintendo Logo
|
||||
@@ -232,12 +242,12 @@ int main(int argc, char *argv[])
|
||||
0xDD, 0xDC, 0x99, 0x9F, 0xBB, 0xB9, 0x33, 0x3E
|
||||
};
|
||||
|
||||
if (trashlogo)
|
||||
if (trashlogo) {
|
||||
for (int i = 0; i < sizeof(ninlogo); i++)
|
||||
ninlogo[i] = ~ninlogo[i];
|
||||
}
|
||||
|
||||
fseek(rom, 0x104, SEEK_SET);
|
||||
fwrite(ninlogo, 1, 48, rom);
|
||||
memcpy(header + 0x04, ninlogo, sizeof(ninlogo));
|
||||
}
|
||||
|
||||
if (settitle) {
|
||||
@@ -258,11 +268,10 @@ int main(int argc, char *argv[])
|
||||
* characters may conflict with the title.
|
||||
*/
|
||||
|
||||
fseek(rom, 0x134, SEEK_SET);
|
||||
fwrite(title, 1, strlen(title) + 1, rom);
|
||||
int n = snprintf((char *)header + 0x34, 16, "%s", title);
|
||||
|
||||
while (ftell(rom) < 0x143)
|
||||
fputc(0, rom);
|
||||
for (int i = 16; i > n; i--)
|
||||
header[0x34 + i] = '\0';
|
||||
}
|
||||
|
||||
if (setid) {
|
||||
@@ -272,8 +281,7 @@ int main(int argc, char *argv[])
|
||||
* characters).
|
||||
*/
|
||||
|
||||
fseek(rom, 0x13F, SEEK_SET);
|
||||
fwrite(id, 1, 4, rom);
|
||||
memcpy(header + 0x3F, id, 4);
|
||||
}
|
||||
|
||||
if (colorcompatible) {
|
||||
@@ -291,20 +299,12 @@ int main(int argc, char *argv[])
|
||||
* may conflict.
|
||||
*/
|
||||
|
||||
uint8_t byte;
|
||||
|
||||
fseek(rom, 0x143, SEEK_SET);
|
||||
byte = fgetc(rom);
|
||||
|
||||
byte |= 1 << 7;
|
||||
header[0x43] |= 1 << 7;
|
||||
if (coloronly)
|
||||
byte |= 1 << 6;
|
||||
header[0x43] |= 1 << 6;
|
||||
|
||||
if (byte & 0x3F)
|
||||
if (header[0x43] & 0x3F)
|
||||
warnx("Color flag conflicts with game title");
|
||||
|
||||
fseek(rom, 0x143, SEEK_SET);
|
||||
fputc(byte, rom);
|
||||
}
|
||||
|
||||
if (setnewlicensee) {
|
||||
@@ -320,8 +320,8 @@ int main(int argc, char *argv[])
|
||||
* as a Super Game Boy flag.
|
||||
*/
|
||||
|
||||
fseek(rom, 0x144, SEEK_SET);
|
||||
fwrite(newlicensee, 1, 2, rom);
|
||||
header[0x44] = newlicensee[0];
|
||||
header[0x45] = newlicensee[1];
|
||||
}
|
||||
|
||||
if (super) {
|
||||
@@ -340,8 +340,7 @@ int main(int argc, char *argv[])
|
||||
if (!setlicensee)
|
||||
warnx("You should probably set both '-s' and '-l 0x33'");
|
||||
|
||||
fseek(rom, 0x146, SEEK_SET);
|
||||
fputc(3, rom);
|
||||
header[0x46] = 3;
|
||||
}
|
||||
|
||||
if (setcartridge) {
|
||||
@@ -351,8 +350,7 @@ int main(int argc, char *argv[])
|
||||
* external RAM, timer, rumble, or battery.
|
||||
*/
|
||||
|
||||
fseek(rom, 0x147, SEEK_SET);
|
||||
fputc(cartridge, rom);
|
||||
header[0x47] = cartridge;
|
||||
}
|
||||
|
||||
if (resize) {
|
||||
@@ -366,8 +364,13 @@ int main(int argc, char *argv[])
|
||||
int headbyte;
|
||||
uint8_t *buf;
|
||||
|
||||
fseek(rom, 0, SEEK_END);
|
||||
if (fseek(rom, 0, SEEK_END) != 0)
|
||||
err(1, "Could not pad ROM file");
|
||||
|
||||
romsize = ftell(rom);
|
||||
if (romsize == -1)
|
||||
err(1, "Could not pad ROM file");
|
||||
|
||||
newsize = 0x8000;
|
||||
|
||||
headbyte = 0;
|
||||
@@ -380,11 +383,14 @@ int main(int argc, char *argv[])
|
||||
warnx("ROM size is bigger than 8MiB");
|
||||
|
||||
buf = malloc(newsize - romsize);
|
||||
memset(buf, padvalue, newsize - romsize);
|
||||
fwrite(buf, 1, newsize - romsize, rom);
|
||||
if (buf == NULL)
|
||||
errx(1, "Couldn't allocate memory for padded ROM.");
|
||||
|
||||
fseek(rom, 0x148, SEEK_SET);
|
||||
fputc(headbyte, rom);
|
||||
memset(buf, padvalue, newsize - romsize);
|
||||
if (fwrite(buf, 1, newsize - romsize, rom) != newsize - romsize)
|
||||
err(1, "Could not pad ROM file");
|
||||
|
||||
header[0x48] = headbyte;
|
||||
|
||||
free(buf);
|
||||
}
|
||||
@@ -394,8 +400,7 @@ int main(int argc, char *argv[])
|
||||
* Offset 0x149: RAM Size
|
||||
*/
|
||||
|
||||
fseek(rom, 0x149, SEEK_SET);
|
||||
fputc(ramsize, rom);
|
||||
header[0x49] = ramsize;
|
||||
}
|
||||
|
||||
if (nonjapan) {
|
||||
@@ -403,8 +408,7 @@ int main(int argc, char *argv[])
|
||||
* Offset 0x14A: Non-Japanese Region Flag
|
||||
*/
|
||||
|
||||
fseek(rom, 0x14A, SEEK_SET);
|
||||
fputc(1, rom);
|
||||
header[0x4A] = 1;
|
||||
}
|
||||
|
||||
if (setlicensee) {
|
||||
@@ -420,8 +424,7 @@ int main(int argc, char *argv[])
|
||||
* See also: the New Licensee ID at 0x144–0x145.
|
||||
*/
|
||||
|
||||
fseek(rom, 0x14B, SEEK_SET);
|
||||
fputc(licensee, rom);
|
||||
header[0x4B] = licensee;
|
||||
}
|
||||
|
||||
if (setversion) {
|
||||
@@ -430,8 +433,7 @@ int main(int argc, char *argv[])
|
||||
* Which version of the ROM this is.
|
||||
*/
|
||||
|
||||
fseek(rom, 0x14C, SEEK_SET);
|
||||
fputc(version, rom);
|
||||
header[0x4C] = version;
|
||||
}
|
||||
|
||||
if (fixheadsum || trashheadsum) {
|
||||
@@ -441,17 +443,27 @@ int main(int argc, char *argv[])
|
||||
|
||||
uint8_t headcksum = 0;
|
||||
|
||||
fseek(rom, 0x134, SEEK_SET);
|
||||
for (int i = 0; i < (0x14D - 0x134); ++i)
|
||||
headcksum = headcksum - fgetc(rom) - 1;
|
||||
for (int i = 0x34; i < 0x4D; ++i)
|
||||
headcksum = headcksum - header[i] - 1;
|
||||
|
||||
if (trashheadsum)
|
||||
headcksum = ~headcksum;
|
||||
|
||||
fseek(rom, 0x14D, SEEK_SET);
|
||||
fputc(headcksum, rom);
|
||||
header[0x4D] = headcksum;
|
||||
}
|
||||
|
||||
/*
|
||||
* Before calculating the global checksum, we must write the modified
|
||||
* header to the ROM.
|
||||
*/
|
||||
|
||||
if (fseek(rom, 0x100, SEEK_SET) != 0)
|
||||
err(1, "Could not locate header for writing");
|
||||
|
||||
if (fwrite(header, sizeof(uint8_t), sizeof(header), rom)
|
||||
!= sizeof(header))
|
||||
err(1, "Could not write modified ROM header");
|
||||
|
||||
if (fixglobalsum || trashglobalsum) {
|
||||
/*
|
||||
* Offset 0x14E–0x14F: Global Checksum
|
||||
@@ -459,15 +471,20 @@ int main(int argc, char *argv[])
|
||||
|
||||
uint16_t globalcksum = 0;
|
||||
|
||||
rewind(rom);
|
||||
for (int i = 0; i < 0x14E; ++i)
|
||||
globalcksum += fgetc(rom);
|
||||
if (fseek(rom, 0, SEEK_SET) != 0)
|
||||
err(1, "Could not start calculating global checksum");
|
||||
|
||||
int i = 0;
|
||||
int byte;
|
||||
|
||||
fseek(rom, 0x150, SEEK_SET);
|
||||
while ((byte = fgetc(rom)) != EOF)
|
||||
globalcksum += byte;
|
||||
while ((byte = fgetc(rom)) != EOF) {
|
||||
i++;
|
||||
if (i != 0x150)
|
||||
globalcksum += byte;
|
||||
}
|
||||
|
||||
if (ferror(rom))
|
||||
err(1, "Could not calculate global checksum");
|
||||
|
||||
if (trashglobalsum)
|
||||
globalcksum = ~globalcksum;
|
||||
@@ -475,9 +492,12 @@ int main(int argc, char *argv[])
|
||||
fseek(rom, 0x14E, SEEK_SET);
|
||||
fputc(globalcksum >> 8, rom);
|
||||
fputc(globalcksum & 0xFF, rom);
|
||||
if (ferror(rom))
|
||||
err(1, "Could not write global checksum");
|
||||
}
|
||||
|
||||
fclose(rom);
|
||||
if (fclose(rom) != 0)
|
||||
err(1, "Could not complete ROM write");
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -53,6 +53,7 @@ int main(int argc, char *argv[])
|
||||
break;
|
||||
case 'F':
|
||||
opts.hardfix = true;
|
||||
/* fallthrough */
|
||||
case 'f':
|
||||
opts.fix = true;
|
||||
break;
|
||||
|
||||
@@ -317,9 +317,9 @@ static void rgba_png_palette(struct PNGImage *img,
|
||||
png_color **palette_ptr_ptr, int *num_colors)
|
||||
{
|
||||
if (png_get_valid(img->png, img->info, PNG_INFO_PLTE))
|
||||
return rgba_PLTE_palette(img, palette_ptr_ptr, num_colors);
|
||||
rgba_PLTE_palette(img, palette_ptr_ptr, num_colors);
|
||||
else
|
||||
return rgba_build_palette(img, palette_ptr_ptr, num_colors);
|
||||
rgba_build_palette(img, palette_ptr_ptr, num_colors);
|
||||
}
|
||||
|
||||
static void rgba_PLTE_palette(struct PNGImage *img,
|
||||
@@ -469,8 +469,10 @@ struct ColorWithLuminance {
|
||||
|
||||
static int compare_luminance(const void *a, const void *b)
|
||||
{
|
||||
struct ColorWithLuminance *x = (struct ColorWithLuminance *)a;
|
||||
struct ColorWithLuminance *y = (struct ColorWithLuminance *)b;
|
||||
const struct ColorWithLuminance *x, *y;
|
||||
|
||||
x = (const struct ColorWithLuminance *)a;
|
||||
y = (const struct ColorWithLuminance *)b;
|
||||
|
||||
return y->luminance - x->luminance;
|
||||
}
|
||||
|
||||
@@ -74,6 +74,10 @@ static void do_max_bank(enum eSectionType Type, int32_t nBank)
|
||||
if (nBank > MaxVBankUsed)
|
||||
MaxVBankUsed = nBank;
|
||||
break;
|
||||
case SECT_ROM0:
|
||||
case SECT_WRAM0:
|
||||
case SECT_OAM:
|
||||
case SECT_HRAM:
|
||||
default:
|
||||
break;
|
||||
}
|
||||
@@ -494,7 +498,6 @@ void SetLinkerscriptName(char *tzLinkerscriptFile)
|
||||
|
||||
void AssignSections(void)
|
||||
{
|
||||
int32_t i;
|
||||
struct sSection *pSection;
|
||||
|
||||
MaxBankUsed = 0;
|
||||
@@ -503,7 +506,7 @@ void AssignSections(void)
|
||||
* Initialize the memory areas
|
||||
*/
|
||||
|
||||
for (i = 0; i < BANK_INDEX_MAX; i += 1) {
|
||||
for (int32_t i = 0; i < BANK_INDEX_MAX; i += 1) {
|
||||
BankFree[i] = malloc(sizeof(*BankFree[i]));
|
||||
|
||||
if (!BankFree[i]) {
|
||||
@@ -617,6 +620,9 @@ void AssignSections(void)
|
||||
pSection->nOrg, pSection->nBank);
|
||||
}
|
||||
break;
|
||||
default:
|
||||
errx(1, "%s: Internal error: Type %d", __func__,
|
||||
pSection->Type);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -660,6 +666,10 @@ void AssignSections(void)
|
||||
do_max_bank(pSection->Type, pSection->nBank);
|
||||
break;
|
||||
|
||||
case SECT_ROM0:
|
||||
case SECT_WRAM0:
|
||||
case SECT_OAM:
|
||||
case SECT_HRAM:
|
||||
default: /* Handle other sections later */
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -23,7 +23,7 @@
|
||||
|
||||
#include "types.h"
|
||||
|
||||
extern int yyparse();
|
||||
extern int yyparse(void);
|
||||
|
||||
/* File include stack. */
|
||||
|
||||
@@ -179,13 +179,13 @@ void script_PrintFileStack(void)
|
||||
fprintf(stderr, "%s(%d)", linkerscript_path, include_line[i]);
|
||||
}
|
||||
|
||||
noreturn void script_fatalerror(const char *fmt, ...)
|
||||
noreturn_ void script_fatalerror(const char *fmt, ...)
|
||||
{
|
||||
va_list args;
|
||||
va_start(args, fmt);
|
||||
fprintf(stderr, "error: ");
|
||||
script_PrintFileStack();
|
||||
fprintf(stderr, ":\n\t");
|
||||
fprintf(stderr, ":\n ");
|
||||
vfprintf(stderr, fmt, args);
|
||||
fprintf(stderr, "\n");
|
||||
va_end(args);
|
||||
|
||||
@@ -120,6 +120,10 @@ void MapfileWriteSection(const struct sSection *pSect)
|
||||
for (i = 0; i < pSect->nNumberOfSymbols; i += 1) {
|
||||
const struct sSymbol *pSym = pSect->tSymbols[i];
|
||||
|
||||
/* Don't print '@' */
|
||||
if (strcmp(pSym->pzName, "@") == 0)
|
||||
continue;
|
||||
|
||||
if ((pSym->pSection == pSect) && (pSym->Type != SYM_IMPORT)) {
|
||||
if (mf) {
|
||||
fprintf(mf, " $%04X = %s\n",
|
||||
|
||||
@@ -36,14 +36,14 @@ uint8_t oReadLib;
|
||||
*/
|
||||
static int32_t readlong(FILE *f)
|
||||
{
|
||||
int32_t r;
|
||||
uint32_t r;
|
||||
|
||||
r = fgetc(f);
|
||||
r |= fgetc(f) << 8;
|
||||
r |= fgetc(f) << 16;
|
||||
r |= fgetc(f) << 24;
|
||||
r = ((uint32_t)(uint8_t)fgetc(f));
|
||||
r |= ((uint32_t)(uint8_t)fgetc(f)) << 8;
|
||||
r |= ((uint32_t)(uint8_t)fgetc(f)) << 16;
|
||||
r |= ((uint32_t)(uint8_t)fgetc(f)) << 24;
|
||||
|
||||
return r;
|
||||
return (int32_t)r;
|
||||
}
|
||||
|
||||
/*
|
||||
|
||||
@@ -110,46 +110,53 @@ void Output(void)
|
||||
FILE *f_overlay = NULL;
|
||||
|
||||
/*
|
||||
* Apply overlay
|
||||
* Load overlay
|
||||
*/
|
||||
|
||||
if (tzOverlayname) {
|
||||
f_overlay = fopen(tzOverlayname, "rb");
|
||||
|
||||
if (!f_overlay) {
|
||||
errx(1, "Failed to open overlay file %s\n",
|
||||
tzOverlayname);
|
||||
}
|
||||
|
||||
fseek(f_overlay, 0, SEEK_END);
|
||||
|
||||
if (ftell(f_overlay) % 0x4000 != 0)
|
||||
errx(1, "Overlay file must be aligned to 0x4000 bytes.");
|
||||
|
||||
MaxOverlayBank = (ftell(f_overlay) / 0x4000) - 1;
|
||||
|
||||
if (MaxOverlayBank < 1)
|
||||
errx(1, "Overlay file must be at least 0x8000 bytes.");
|
||||
|
||||
if (MaxOverlayBank > MaxBankUsed)
|
||||
MaxBankUsed = MaxOverlayBank;
|
||||
}
|
||||
|
||||
/*
|
||||
* Write ROM.
|
||||
*/
|
||||
|
||||
f = fopen(tzOutname, "wb");
|
||||
|
||||
if (f != NULL) {
|
||||
if (tzOverlayname) {
|
||||
f_overlay = fopen(tzOverlayname, "rb");
|
||||
|
||||
if (!f_overlay) {
|
||||
errx(1, "Failed to open overlay file %s\n",
|
||||
tzOverlayname);
|
||||
}
|
||||
|
||||
fseek(f_overlay, 0, SEEK_END);
|
||||
|
||||
if (ftell(f_overlay) % 0x4000 != 0)
|
||||
errx(1, "Overlay file must be aligned to 0x4000 bytes.");
|
||||
|
||||
MaxOverlayBank = (ftell(f_overlay) / 0x4000) - 1;
|
||||
|
||||
if (MaxOverlayBank < 1)
|
||||
errx(1, "Overlay file must be at least 0x8000 bytes.");
|
||||
|
||||
if (MaxOverlayBank > MaxBankUsed)
|
||||
MaxBankUsed = MaxOverlayBank;
|
||||
}
|
||||
|
||||
writehome(f, f_overlay);
|
||||
for (i = 1; i <= MaxBankUsed; i += 1)
|
||||
writebank(f, f_overlay, i);
|
||||
|
||||
fclose(f);
|
||||
|
||||
if (tzOverlayname)
|
||||
fclose(f_overlay);
|
||||
}
|
||||
|
||||
/*
|
||||
* Add regular sections
|
||||
* Close overlay
|
||||
*/
|
||||
|
||||
if (tzOverlayname)
|
||||
fclose(f_overlay);
|
||||
|
||||
/*
|
||||
* Add regular sections to map and sym files.
|
||||
*/
|
||||
|
||||
for (i = BANK_INDEX_WRAM0; i < BANK_INDEX_MAX; i++) {
|
||||
|
||||
@@ -14,7 +14,7 @@
|
||||
|
||||
#include "link/script.h"
|
||||
|
||||
int yylex();
|
||||
int yylex(void);
|
||||
void yyerror(char *);
|
||||
|
||||
extern int yylineno;
|
||||
@@ -107,8 +107,8 @@ statement:
|
||||
|
||||
%%
|
||||
|
||||
extern int yylex();
|
||||
extern int yyparse();
|
||||
extern int yylex(void);
|
||||
extern int yyparse(void);
|
||||
|
||||
int yywrap(void)
|
||||
{
|
||||
|
||||
@@ -314,7 +314,7 @@ void Patch(void)
|
||||
/* t contains the destination of the jump */
|
||||
t = (int16_t)((t & 0xFFFF) - (nPatchOrg + 1));
|
||||
|
||||
if (t >= -128 && t <= 255) {
|
||||
if (t >= -128 && t <= 127) {
|
||||
t &= 0xFF;
|
||||
pSect->pData[pPatch->nOffset] =
|
||||
(uint8_t)t;
|
||||
@@ -325,6 +325,8 @@ void Patch(void)
|
||||
pPatch->nLineNo);
|
||||
}
|
||||
break;
|
||||
default:
|
||||
errx(1, "%s: Internal error.", __func__);
|
||||
}
|
||||
|
||||
pPatch = pPatch->pNext;
|
||||
|
||||
@@ -85,59 +85,59 @@ void script_InitSections(void)
|
||||
}
|
||||
}
|
||||
|
||||
void script_SetCurrentSectionType(const char *type, uint32_t bank)
|
||||
void script_SetCurrentSectionType(const char *type, uint32_t bank_num)
|
||||
{
|
||||
if (strcmp(type, "ROM0") == 0) {
|
||||
if (bank != 0)
|
||||
if (bank_num != 0)
|
||||
errx(1, "Trying to assign a bank number to ROM0.\n");
|
||||
current_bank = BANK_INDEX_ROM0;
|
||||
current_real_bank = 0;
|
||||
return;
|
||||
} else if (strcmp(type, "ROMX") == 0) {
|
||||
if (bank == 0)
|
||||
if (bank_num == 0)
|
||||
errx(1, "ROMX index can't be 0.\n");
|
||||
if (bank > BANK_COUNT_ROMX) {
|
||||
errx(1, "ROMX index too big (%d > %d).\n", bank,
|
||||
if (bank_num > BANK_COUNT_ROMX) {
|
||||
errx(1, "ROMX index too big (%d > %d).\n", bank_num,
|
||||
BANK_COUNT_ROMX);
|
||||
}
|
||||
current_bank = BANK_INDEX_ROMX + bank - 1;
|
||||
current_real_bank = bank;
|
||||
current_bank = BANK_INDEX_ROMX + bank_num - 1;
|
||||
current_real_bank = bank_num;
|
||||
return;
|
||||
} else if (strcmp(type, "VRAM") == 0) {
|
||||
if (bank >= BANK_COUNT_VRAM) {
|
||||
errx(1, "VRAM index too big (%d >= %d).\n", bank,
|
||||
if (bank_num >= BANK_COUNT_VRAM) {
|
||||
errx(1, "VRAM index too big (%d >= %d).\n", bank_num,
|
||||
BANK_COUNT_VRAM);
|
||||
}
|
||||
current_bank = BANK_INDEX_VRAM + bank;
|
||||
current_real_bank = bank;
|
||||
current_bank = BANK_INDEX_VRAM + bank_num;
|
||||
current_real_bank = bank_num;
|
||||
return;
|
||||
} else if (strcmp(type, "WRAM0") == 0) {
|
||||
if (bank != 0)
|
||||
if (bank_num != 0)
|
||||
errx(1, "Trying to assign a bank number to WRAM0.\n");
|
||||
|
||||
current_bank = BANK_INDEX_WRAM0;
|
||||
current_real_bank = 0;
|
||||
return;
|
||||
} else if (strcmp(type, "WRAMX") == 0) {
|
||||
if (bank == 0)
|
||||
if (bank_num == 0)
|
||||
errx(1, "WRAMX index can't be 0.\n");
|
||||
if (bank > BANK_COUNT_WRAMX) {
|
||||
errx(1, "WRAMX index too big (%d > %d).\n", bank,
|
||||
if (bank_num > BANK_COUNT_WRAMX) {
|
||||
errx(1, "WRAMX index too big (%d > %d).\n", bank_num,
|
||||
BANK_COUNT_WRAMX);
|
||||
}
|
||||
current_bank = BANK_INDEX_WRAMX + bank - 1;
|
||||
current_real_bank = bank;
|
||||
current_bank = BANK_INDEX_WRAMX + bank_num - 1;
|
||||
current_real_bank = bank_num;
|
||||
return;
|
||||
} else if (strcmp(type, "SRAM") == 0) {
|
||||
if (bank >= BANK_COUNT_SRAM) {
|
||||
errx(1, "SRAM index too big (%d >= %d).\n", bank,
|
||||
if (bank_num >= BANK_COUNT_SRAM) {
|
||||
errx(1, "SRAM index too big (%d >= %d).\n", bank_num,
|
||||
BANK_COUNT_SRAM);
|
||||
}
|
||||
current_bank = BANK_INDEX_SRAM + bank;
|
||||
current_real_bank = bank;
|
||||
current_bank = BANK_INDEX_SRAM + bank_num;
|
||||
current_real_bank = bank_num;
|
||||
return;
|
||||
} else if (strcmp(type, "OAM") == 0) {
|
||||
if (bank != 0) {
|
||||
if (bank_num != 0) {
|
||||
errx(1, "%s: Trying to assign a bank number to OAM.\n",
|
||||
__func__);
|
||||
}
|
||||
@@ -145,7 +145,7 @@ void script_SetCurrentSectionType(const char *type, uint32_t bank)
|
||||
current_real_bank = 0;
|
||||
return;
|
||||
} else if (strcmp(type, "HRAM") == 0) {
|
||||
if (bank != 0) {
|
||||
if (bank_num != 0) {
|
||||
errx(1, "%s: Trying to assign a bank number to HRAM.\n",
|
||||
__func__);
|
||||
}
|
||||
|
||||
@@ -57,7 +57,9 @@ REPT NumberOfSymbols ; Number of symbols defined in this object file.
|
||||
LONG LineNum ; Line number in the file where the symbol is defined.
|
||||
|
||||
LONG SectionID ; The section number (of this object file) in which
|
||||
; this symbol is defined.
|
||||
; this symbol is defined. If it doesn't belong to any
|
||||
; specific section (like a constant), this field has
|
||||
; the value -1.
|
||||
|
||||
LONG Value ; The symbols value. It's the offset into that
|
||||
; symbol's section.
|
||||
|
||||
@@ -1,2 +1,2 @@
|
||||
ERROR: divzero-instr.asm(2):
|
||||
division by zero
|
||||
Division by zero
|
||||
|
||||
@@ -1,2 +1,2 @@
|
||||
ERROR: divzero-section-bank.asm(1):
|
||||
division by zero
|
||||
Division by zero
|
||||
|
||||
@@ -1,3 +1,3 @@
|
||||
ERROR: local-wrong-parent.asm(5):
|
||||
Not currently in the scope of 'WrongParent'
|
||||
Not currently in the scope of 'WrongParent'
|
||||
error: Assembly aborted in pass 1 (1 errors)!
|
||||
|
||||
@@ -1,2 +1,2 @@
|
||||
ERROR: macro-@.asm(1) -> @(-1):
|
||||
Macro '@' not defined
|
||||
Macro '@' not defined
|
||||
|
||||
@@ -1,2 +1,2 @@
|
||||
ERROR: null-in-macro.asm(1):
|
||||
Unterminated MACRO definition.
|
||||
Unterminated MACRO definition.
|
||||
|
||||
@@ -1,2 +1,2 @@
|
||||
ERROR: remote-local-noexist.asm(7):
|
||||
'Parent.child.fail' is a nonsensical reference to a nested local symbol
|
||||
'Parent.child.fail' is a nonsensical reference to a nested local symbol
|
||||
|
||||
@@ -1,3 +1,3 @@
|
||||
ERROR: undefined-dot.asm(3):
|
||||
'.' not defined
|
||||
'.' not defined
|
||||
error: Assembly aborted in pass 2 (1 errors)!
|
||||
|
||||
Reference in New Issue
Block a user