Compare commits

..

31 Commits

Author SHA1 Message Date
Antonio Niño Díaz
748943f6fc Increase version number to 0.3.7
Signed-off-by: Antonio Niño Díaz <antonio_nd@outlook.com>
2018-05-02 20:04:00 +01:00
Antonio Niño Díaz
d945c5811c rgbasm: Check the values of operands in bit shifts
The tests are not exhaustive, there are some conditions that aren't
checked. The tests are based in the C standard rules about undefined
behaviour.

This is a compatibility break but, hopefully, all projects are using
sane values. If not, there is no guarantee that the projects will build
in any platform where RGBDS can be compiled, so it would be better to
fix them.

Even though, technically, the left shift of a negative value is always
undefined, some projects rely on its current behaviour. This is the
reason why this doesn't cause a fatal error.

Signed-off-by: Antonio Niño Díaz <antonio_nd@outlook.com>
2018-04-28 01:59:37 +01:00
Antonio Niño Díaz
6fe2741f2d Enable GCC options to detect undefined behaviour
GCC has an Undefined Behavior Sanitizer (ubsan), which enables run-time
checks of undefined behaviour. It has been enabled for the `develop`
build target.

A small bug detected with it has been fixed.

Signed-off-by: Antonio Niño Díaz <antonio_nd@outlook.com>
2018-04-28 00:57:25 +01:00
Antonio Niño Díaz
24d7cfe0f9 checkpatch: Ignore warnings about SPDX
The Linux kernel expects the SPDX license tag to be in the first line of
all source code files. The reason is that they have many different
license headers, and this simplifies the work for any tool that has to
determine the license of each file.

In this project, the license headers follow the same pattern, so it
isn't useful.

Signed-off-by: Antonio Niño Díaz <antonio_nd@outlook.com>
2018-04-27 23:00:29 +01:00
Antonio Niño Díaz
630933b148 rgbfix: Fix checkpatch issues
Signed-off-by: Antonio Niño Díaz <antonio_nd@outlook.com>
2018-04-22 21:02:08 +01:00
Antonio Niño Díaz
e8a16c6f53 Don't generate output file if overlay isn't found
Previously, the output file was opened before trying to open the
overlay. Because of this, rgblink generated an empty output file if the
overlay couldn't be opened.

Now the overlay is opened (and checked) before the output file, so the
output file is only generated if the overlay is found.

Signed-off-by: Antonio Niño Díaz <antonio_nd@outlook.com>
2018-04-22 20:54:48 +01:00
Antonio Niño Díaz
2cb50730a1 Document Section ID == -1 in object files
Signed-off-by: Antonio Niño Díaz <antonio_nd@outlook.com>
2018-04-22 20:21:45 +01:00
Antonio Niño Díaz
efae6c7fd2 Merge pull request #264 from inmemrgbfix
Rewrite rgbfix to perform most actions in memory.

Limit file operations to a small number that can be reasonably checked,
and do the majority of the actual work on a buffered header in memory
where operations won't fail.

Signed-off-by: Antonio Niño Díaz <antonio_nd@outlook.com>
2018-04-22 20:03:32 +01:00
Anthony J. Bentley
8a559beeb8 Rewrite rgbfix to perform most actions in memory.
Limit file operations to a small number that can be reasonably checked,
and do the majority of the actual work on a buffered header in memory
where operations won't fail.
2018-04-05 00:41:09 -06:00
Antonio Niño Díaz
7149fc1e39 tests: Update references
Signed-off-by: Antonio Niño Díaz <antonio_nd@outlook.com>
2018-04-03 23:04:29 +01:00
Antonio Niño Díaz
2e695334c1 rgbfix: Add check to malloc()
Signed-off-by: Antonio Niño Díaz <antonio_nd@outlook.com>
2018-04-03 22:41:51 +01:00
Antonio Niño Díaz
e2b4554a5c Replace tabs by spaces in fprintf()
Signed-off-by: Antonio Niño Díaz <antonio_nd@outlook.com>
2018-04-03 22:41:44 +01:00
Antonio Niño Díaz
ef87dd5a6e rgbasm: Fix declaration of fatalerror()
Signed-off-by: Antonio Niño Díaz <antonio_nd@outlook.com>
2018-04-03 22:41:37 +01:00
Antonio Niño Díaz
4f126b37d0 Merge pull request #261 from warnings
Enable a lot of GCC warnings and cleanup Makefile and compiler macros

Most of the warnings in the GCC documentation have been enabled. As the
build system was using `-Werror`, this made the new builds very
susceptible to any minor change in the compiler. To fix that, this
option has been removed from the default Makefile target and it is only
used when the code is compiled through `make develop`.

The file `stdnoreturn.h` has been modified to remove support for
compilers that aren't actually tested. It now has defines for
`__attribute__((unused))` and it has been renamed to `helpers.h`.

Signed-off-by: Antonio Niño Díaz <antonio_nd@outlook.com>
2018-04-03 19:57:04 +01:00
Antonio Niño Díaz
1b4187e51f Cleanup GCC compiler attributes
Added define 'unused_' for '__attribute__((unused))'. The oldest version
of GCC with online docs (GCC 2.95.3, released in March 16, 2001 [1])
already has support for this attribute, so it doesn't make sense to
check the version.

Renamed 'noreturn' to 'noreturn_' for consistency.

[1] https://gcc.gnu.org/onlinedocs/

Signed-off-by: Antonio Niño Díaz <antonio_nd@outlook.com>
2018-04-03 19:52:50 +01:00
Antonio Niño Díaz
0daec91683 Check code style as part of the CI tests
If checkpatch.pl detects any ERROR in the new patches, the Travis CI
build will fail.

Signed-off-by: Antonio Niño Díaz <antonio_nd@outlook.com>
2018-04-03 00:02:17 +01:00
Antonio Niño Díaz
cbaaec98ca Simplify helpers.h
`__attribute__((noreturn))` has been supported since GCC 2.5, that was
released October 22, 1993. It doesn't make sense to check if the version
is at least that one, we are compiling for C99, that is more modern. [1]

Also, remove the MSVC check. This code is never compiled with it so
there may be problems that need to be solved to make it compile. All
releases cross-compiled from linux. If there is an actual need to
support MSVC, the compiler definitions can be added again.

Also, if the compiler is not supported, the compiler helpers default to
nothing, so the code can still compile.

[1] https://gcc.gnu.org/onlinedocs/

Signed-off-by: Antonio Niño Díaz <antonio_nd@outlook.com>
2018-04-02 22:53:48 +01:00
Antonio Niño Díaz
895d1d5813 Remove check for C11 in helpers.h
The mandatory CFLAGS in the Makefile make the compiler use C99.

Signed-off-by: Antonio Niño Díaz <antonio_nd@outlook.com>
2018-04-02 22:53:48 +01:00
Antonio Niño Díaz
e99a651165 Create makefile target to check all warnings
Remove '-Werror' from the default make target to make it easy for
regular users of RGBDS to compile the source code. Only a few basic
warnings are left in that target.

All the warnings have been moved to a new target called 'develop'. This
target is now the one used in Travis CI to check for problems during
compilation.

Signed-off-by: Antonio Niño Díaz <antonio_nd@outlook.com>
2018-04-02 22:53:48 +01:00
Antonio Niño Díaz
0ae69b3114 Rename stdnoreturn.h to helpers.h
This file will contain more compiler-specific helpers.

Signed-off-by: Antonio Niño Díaz <antonio_nd@outlook.com>
2018-04-02 22:53:48 +01:00
Antonio Niño Díaz
95ccc48d0c Enable -Wundef
Signed-off-by: Antonio Niño Díaz <antonio_nd@outlook.com>
2018-04-02 22:53:48 +01:00
Antonio Niño Díaz
29253046d5 Remove C++ check in stdnoreturn.h
This isn't a C++ project, only keep checks for C compilers.

Signed-off-by: Antonio Niño Díaz <antonio_nd@outlook.com>
2018-04-02 22:53:48 +01:00
Antonio Niño Díaz
340362d984 Enable a few warning flags
Signed-off-by: Antonio Niño Díaz <antonio_nd@outlook.com>
2018-04-02 22:53:48 +01:00
Antonio Niño Díaz
85ece88268 Add default clauses to switch statements
Signed-off-by: Antonio Niño Díaz <antonio_nd@outlook.com>
2018-04-02 22:53:43 +01:00
Antonio Niño Díaz
516e4578ea Enable more optional warnings
-Wformat-truncation is set to 1 instead of 2 because in some cases the
return value of snprintf is used to warn about truncations but GCC still
creates a warning for it, preventing the compilation from continuing.

Signed-off-by: Antonio Niño Díaz <antonio_nd@outlook.com>
2018-04-01 01:42:55 +01:00
Antonio Niño Díaz
9829be1045 Enable -Wextra
-Wsign-compare has been disabled because flex generates a comparison
that triggers a warning and cannot be fixed in the code.

Signed-off-by: Antonio Niño Díaz <antonio_nd@outlook.com>
2018-04-01 01:42:55 +01:00
Antonio Niño Díaz
b28a16c0da Enable -Wpedantic
Fix a few warnings related needed to build the source with this option.

Add new exception to .checkpatch.conf.

Signed-off-by: Antonio Niño Díaz <antonio_nd@outlook.com>
2018-04-01 00:56:00 +01:00
Antonio Niño Díaz
4d13d57491 Fix behaviour of '@'
When '@' is used as argument of any instruction (LD, JR, JP, etc), the
address it refers to is the address of the first byte of the
instruction. When '@' is used with DB/DW/DL, it refers to the same
address it is being placed at. This means that instructions need an
offset of 1 byte and others need an offset of 0 bytes.

The assembler doesn't evaluate anything related to '@' because it would
only work in sections with a fixed base address. It is left to the
linker. This means that the offset needs to be added to the RPN
expression of the patch that is saved in the linker. It isn't enough by
adding an offset to the final expresion. The following value wouldn't be
calculated correctly (even if it doesn't make sense):

    JP @ * @

The correct patch is `(@ - 1) * (@ - 1)`, not `(@ * @) - 1`.

This patch introduces an offset on 1 byte by default in every line, and
sets it to 0 only if a DB/DW/DL is detected.

Signed-off-by: Antonio Niño Díaz <antonio_nd@outlook.com>
2018-03-31 00:43:25 +01:00
Antonio Niño Díaz
be6bc7460b Don't save '@' in map and sym files
Signed-off-by: Antonio Niño Díaz <antonio_nd@outlook.com>
2018-03-31 00:43:25 +01:00
Antonio Niño Díaz
efdd42c6a8 Simplify parsing of variable-length lists
This change removes 2 reduce/reduce conflicts in the parser while
preserving the behaviour of the rules.

Note that now each list with empty elements will only print a warning
per line.

Signed-off-by: Antonio Niño Díaz <antonio_nd@outlook.com>
2018-03-31 00:43:02 +01:00
Antonio Niño Díaz
c1a97f6541 Allow to JR to numeric constants
Previously, JR was only allowed to labels (in the same section, or
different sections). When trying to JR to an address specified as a
numeric value, rgbasm would fail to calculate the JR offset (as it
doesn't know the final address of the JR so it can't calculate the
difference).

This patch makes rgblink calculate the offset whenever there is a JR.

Signed-off-by: Antonio Niño Díaz <antonio_nd@outlook.com>
2018-03-29 23:38:54 +01:00
40 changed files with 458 additions and 283 deletions

View File

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

View File

@@ -10,5 +10,6 @@ compiler:
- clang
- gcc
script:
- ./.travis-checkpatch.sh
- cd test
- ./run-tests.sh

View File

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

View File

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

View File

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

View File

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

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

View File

@@ -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
View 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 */

View File

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

View File

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

View File

@@ -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,7 +582,10 @@ asmfile : lines;
/* Note: The lexer adds '\n' at the end of the input */
lines : /* empty */
| lines line '\n' {
| lines {
nListCountEmpty = 0;
nPCOffset = 1;
} line '\n' {
nLineNo += 1;
nTotalLines += 1;
}
@@ -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,9 +1111,40 @@ const_16bit : relocconst
relocconst : T_ID
{
/*
* 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
{
rpn_Number(&$$, $1);
@@ -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; }

View File

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

View File

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

View File

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

View File

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

View File

@@ -882,7 +882,8 @@ void out_PCRelByte(struct Expression *expr)
{
checkcodesection();
checksectionoverflow(1);
if (rpn_isReloc(expr)) {
/* Always let the linker calculate the offset. */
if (nPass == 2) {
pCurrentSection->tData[nPC] = 0;
createpatch(PATCH_BYTE_JR, expr);
@@ -890,16 +891,7 @@ void out_PCRelByte(struct Expression *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);
}
rpn_Reset(expr);
}

View File

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

View File

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

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

View File

@@ -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 0x1040x133: 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 0x1440x145.
*/
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 0x14E0x14F: 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)
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;
}

View File

@@ -53,6 +53,7 @@ int main(int argc, char *argv[])
break;
case 'F':
opts.hardfix = true;
/* fallthrough */
case 'f':
opts.fix = true;
break;

View File

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

View File

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

View File

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

View File

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

View File

@@ -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;
}
/*

View File

@@ -110,12 +110,9 @@ void Output(void)
FILE *f_overlay = NULL;
/*
* Apply overlay
* Load overlay
*/
f = fopen(tzOutname, "wb");
if (f != NULL) {
if (tzOverlayname) {
f_overlay = fopen(tzOverlayname, "rb");
@@ -138,18 +135,28 @@ void Output(void)
MaxBankUsed = MaxOverlayBank;
}
/*
* Write ROM.
*/
f = fopen(tzOutname, "wb");
if (f != NULL) {
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++) {

View File

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

View File

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

View File

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

View File

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

View File

@@ -1,2 +1,2 @@
ERROR: divzero-instr.asm(2):
division by zero
Division by zero

View File

@@ -1,2 +1,2 @@
ERROR: divzero-section-bank.asm(1):
division by zero
Division by zero