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>
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.
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>
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>
`__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>
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>
-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>
-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>
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>
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>
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>
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>
Images are allowed to have any arbitrary height if the width is 8. If
the height is not a multiple of 8, the number of tiles calculated won't
be an exact number and it will be rounded down. This patch increases the
number of tiles allocated in this case to prevent rgbgfx from accessing
memory that hasn't been allocated.
The buffers are now initialized to 0 with calloc instead of being
created with malloc.
Signed-off-by: Antonio Niño Díaz <antonio_nd@outlook.com>
For example:
PrintMacro : MACRO
PRINTT \1
ENDM
PrintMacro STRCAT(\"Hello\"\, \
\" world\\n\")
It is possible to have spaces after the '\' and before the newline
character. This is needed because Windows line endings "\r\n" are
converted to " \n" before the lexer has a chance to handle them.
Signed-off-by: Antonio Niño Díaz <antonio_nd@outlook.com>
Lines can be continuated after a newline character ('\n'):
DB 1, 2, 3, 4 \
5, 6, 7, 8
This doesn't work for now in lists of arguments of macros.
It is possible to have spaces after the '\' and before the newline
character. This is needed because Windows line endings "\r\n" are
converted to " \n" before the lexer has a chance to handle them.
Signed-off-by: Antonio Niño Díaz <antonio_nd@outlook.com>
rgbasm tries to optimize any loads from/to $FF00-$FFFF and generate
LDH 2-byte opcodes instead of regular LD 3-byte opcodes. This is a bit
inconsistent as it only works for constant values. If a load is trying
to access a label in a HRAM floating section, or a section found in a
different object file, this optimization doesn't work.
This means that a simple refactor or code could allow rgbasm to perform
the optimzation or prevent it from doing so. For certain projects, like
disassemblies, this is a problem.
This patch adds flag -L to rgbasm to disable the optimization, and
doesn't change the behaviour of any other existing code.
Signed-off-by: Antonio Niño Díaz <antonio_nd@outlook.com>
Use snprintf instead of other unsafe functions. That way it is possible
to limit the size of the buffer and to ensure that it never overflows.
Signed-off-by: Antonio Niño Díaz <antonio_nd@outlook.com>
Newlines have to be handled before comments or comments won't be able to
handle line endings that don't include at least one LF character.
Also, document an obscure comment syntax: Anything that follows a '*'
placed at the start of a line is also a comment until the end of the
line.
Signed-off-by: Antonio Niño Díaz <antonio_nd@outlook.com>
Previously, JR was only allowed if the destination label was in the same
section as the JR. This patch removes this restriction. The check to see
if the relative value overflows is now done when linking the ROM.
Signed-off-by: Antonio Niño Díaz <antonio_nd@outlook.com>
PRINTV prints integers in hexadecimal, PRINTI prints them in signed
decimal. For example:
PRINTT "Error at line "
PRINTI __LINE__
PRINTT "\n"
Signed-off-by: Antonio Niño Díaz <antonio_nd@outlook.com>