mirror of
https://github.com/gbdev/rgbds.git
synced 2025-11-21 10:42:07 +00:00
Compare commits
81 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 | ||
|
|
ea4276c7ac | ||
|
|
7bce97f817 | ||
|
|
483a63156b | ||
|
|
5a4bbe4985 | ||
|
|
f86dbafad0 | ||
|
|
8744d360a3 | ||
|
|
b6bd57a764 | ||
|
|
f2b55527d5 | ||
|
|
84a6899c6c | ||
|
|
8cffe22295 | ||
|
|
0c85240b97 | ||
|
|
58ab88da82 | ||
|
|
3e219dee36 | ||
|
|
6ad5bd2325 | ||
|
|
2a97535e75 | ||
|
|
0e0e12a769 | ||
|
|
3bebedf1f8 | ||
|
|
2ed937db2c | ||
|
|
d243bd04ef | ||
|
|
3623638be7 | ||
|
|
8ea3669a64 | ||
|
|
8fe5293077 | ||
|
|
825fa915ee | ||
|
|
885e8ea24a | ||
|
|
898f75ce57 | ||
|
|
b8af100c63 | ||
|
|
3075945367 | ||
|
|
d602ebfde5 | ||
|
|
305512a2b7 | ||
|
|
a6b244b12e | ||
|
|
ceabbeaa2f | ||
|
|
3995852cc5 | ||
|
|
9793bcba6f | ||
|
|
0727eb4374 | ||
|
|
f8f67fcbce | ||
|
|
abeca2d305 | ||
|
|
a7dc86001c | ||
|
|
c071586ae5 | ||
|
|
c6187be210 | ||
|
|
f9f3bb7761 | ||
|
|
1a5c423984 | ||
|
|
b382dffdec | ||
|
|
33e9eb098c | ||
|
|
e77ebfe38a | ||
|
|
698ed9d5fc | ||
|
|
b07a8501d6 | ||
|
|
f779e724e2 | ||
|
|
494b98e46a | ||
|
|
d1ff057889 | ||
|
|
292302c6d1 |
@@ -16,6 +16,9 @@
|
|||||||
# Show file line, not input line
|
# Show file line, not input line
|
||||||
--showfile
|
--showfile
|
||||||
|
|
||||||
|
# Don't expect SPDX tag in the first line of a file
|
||||||
|
--ignore SPDX_LICENSE_TAG
|
||||||
|
|
||||||
# List of ignored rules
|
# List of ignored rules
|
||||||
# ---------------------
|
# ---------------------
|
||||||
|
|
||||||
@@ -53,6 +56,9 @@
|
|||||||
# Prefer stdint.h types over kernel types
|
# Prefer stdint.h types over kernel types
|
||||||
--ignore PREFER_KERNEL_TYPES
|
--ignore PREFER_KERNEL_TYPES
|
||||||
|
|
||||||
|
# Don't ask to replace sscanf by kstrto
|
||||||
|
--ignore SSCANF_TO_KSTRTO
|
||||||
|
|
||||||
# Parentheses can make the code clearer
|
# Parentheses can make the code clearer
|
||||||
--ignore UNNECESSARY_PARENTHESES
|
--ignore UNNECESSARY_PARENTHESES
|
||||||
|
|
||||||
|
|||||||
1
.gitignore
vendored
1
.gitignore
vendored
@@ -4,5 +4,4 @@ rgbfix
|
|||||||
rgbgfx
|
rgbgfx
|
||||||
*.o
|
*.o
|
||||||
*.exe
|
*.exe
|
||||||
*.html
|
|
||||||
.checkpatch-camelcase.*
|
.checkpatch-camelcase.*
|
||||||
|
|||||||
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
|
||||||
11
.travis.yml
11
.travis.yml
@@ -2,15 +2,14 @@ language: c
|
|||||||
sudo: required
|
sudo: required
|
||||||
install:
|
install:
|
||||||
- ./.travis-deps.sh
|
- ./.travis-deps.sh
|
||||||
|
- make
|
||||||
|
- sudo make install
|
||||||
os:
|
os:
|
||||||
- linux
|
- linux
|
||||||
- osx
|
|
||||||
compiler:
|
compiler:
|
||||||
- clang
|
- clang
|
||||||
- gcc
|
- gcc
|
||||||
script:
|
script:
|
||||||
- make
|
- ./.travis-checkpatch.sh
|
||||||
- sudo make install
|
- cd test
|
||||||
after_success:
|
- ./run-tests.sh
|
||||||
- pushd test/asm/ && ./test.sh && popd
|
|
||||||
- pushd test/link/ && ./test.sh && popd
|
|
||||||
|
|||||||
@@ -58,6 +58,11 @@ If you are going to work on a specific issue that involves a lot of work, it is
|
|||||||
always a good idea to leave a message, just in case someone else is interested
|
always a good idea to leave a message, just in case someone else is interested
|
||||||
but doesn't know that there's someone working on it.
|
but doesn't know that there's someone working on it.
|
||||||
|
|
||||||
|
Note that you must contribute all your changes under the MIT License. If you are
|
||||||
|
just modifying a file, you don't need to do anything (maybe update the copyright
|
||||||
|
years). If you are adding new files, you need to use the correct header with the
|
||||||
|
copyright and the reference to the MIT License.
|
||||||
|
|
||||||
1. Fork this repository.
|
1. Fork this repository.
|
||||||
|
|
||||||
2. Checkout the ``develop`` branch.
|
2. Checkout the ``develop`` branch.
|
||||||
@@ -65,24 +70,29 @@ but doesn't know that there's someone working on it.
|
|||||||
3. Create a new branch to work on. You could still work on ``develop``, but it's
|
3. Create a new branch to work on. You could still work on ``develop``, but it's
|
||||||
easier that way.
|
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.
|
``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
|
Note that the coding style isn't writen on stone, if there is a good reason
|
||||||
to deviate from it, it should be fine.
|
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.
|
``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
|
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
|
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
|
located in ``../linux/scripts/``, but you can place them anywhere you like as
|
||||||
long as you specify it when executing the command:
|
long as you specify it when executing the command:
|
||||||
``CHECKPATCH=../path/to/folder make checkpatch``.
|
``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.
|
``git rebase -i origin/develop`` to modify chains of commits.
|
||||||
|
|||||||
41
CONTRIBUTORS.rst
Normal file
41
CONTRIBUTORS.rst
Normal file
@@ -0,0 +1,41 @@
|
|||||||
|
Contributors to RGBDS
|
||||||
|
=====================
|
||||||
|
|
||||||
|
Original author
|
||||||
|
---------------
|
||||||
|
|
||||||
|
- Carsten Elton Sørensen <csoren@gmail.com>
|
||||||
|
|
||||||
|
Main contributors
|
||||||
|
-----------------
|
||||||
|
|
||||||
|
- Justin Lloyd <jlloyd@imf.la>
|
||||||
|
|
||||||
|
- Vegard Nossum <vegard.nossum@gmail.com>
|
||||||
|
|
||||||
|
- Anthony J. Bentley <anthony@anjbe.name>
|
||||||
|
|
||||||
|
- stag019 <stag019@gmail.com>
|
||||||
|
|
||||||
|
- Antonio Niño Díaz <antonio_nd@outlook.com>
|
||||||
|
|
||||||
|
Other contributors
|
||||||
|
------------------
|
||||||
|
|
||||||
|
- Ben10do
|
||||||
|
|
||||||
|
- Björn Höhrmann <bjoern@hoehrmann.de>
|
||||||
|
|
||||||
|
- Christophe Staïesse <chastai@skynet.be>
|
||||||
|
|
||||||
|
- The Musl C library <http://www.musl-libc.org>
|
||||||
|
|
||||||
|
- obskyr <powpowd@gmail.com>
|
||||||
|
|
||||||
|
- The OpenBSD Project <http://www.openbsd.org>
|
||||||
|
|
||||||
|
- Sanqui <gsanky@gmail.com>
|
||||||
|
|
||||||
|
- YamaArashi <shadow962@live.com>
|
||||||
|
|
||||||
|
- yenatch <yenatch@gmail.com>
|
||||||
21
LICENSE
Normal file
21
LICENSE
Normal file
@@ -0,0 +1,21 @@
|
|||||||
|
The MIT License
|
||||||
|
|
||||||
|
Copyright (c) 1997-2018, Carsten Sorensen and RGBDS contributors.
|
||||||
|
|
||||||
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
of this software and associated documentation files (the "Software"), to
|
||||||
|
deal in the Software without restriction, including without limitation the
|
||||||
|
rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
|
||||||
|
sell copies of the Software, and to permit persons to whom the Software is
|
||||||
|
furnished to do so, subject to the following conditions:
|
||||||
|
|
||||||
|
The above copyright notice and this permission notice shall be included in
|
||||||
|
all copies or substantial portions of the Software.
|
||||||
|
|
||||||
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||||
|
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
|
||||||
|
IN THE SOFTWARE.
|
||||||
81
LICENSE.rst
81
LICENSE.rst
@@ -1,81 +0,0 @@
|
|||||||
LICENSE
|
|
||||||
=======
|
|
||||||
|
|
||||||
Original code
|
|
||||||
-------------
|
|
||||||
|
|
||||||
Copyright (C) 1997 Carsten Sorensen <surfsmurf@matilde.demon.co.uk>
|
|
||||||
|
|
||||||
The ASMotor package (xAsm, xLink, RGBFix, examples and documentation) is
|
|
||||||
freeware and distributed as is. The author retains his copyright and right to
|
|
||||||
modify the specifications and operation of the software without notice.
|
|
||||||
|
|
||||||
In other words this means I encourage you to...
|
|
||||||
|
|
||||||
- use it for whatever purpose even professional work without me charging you a
|
|
||||||
penny
|
|
||||||
- copy it to another person (wholly or in part, though I'm sure he'd appreciate
|
|
||||||
the whole package) in whatever form you find suitable
|
|
||||||
- mass-distribute the ASMotor package if it is complete (xAsm, xLink, RGBFix and
|
|
||||||
documentation).
|
|
||||||
- contact me if you have any problems
|
|
||||||
|
|
||||||
This also means you can't...
|
|
||||||
|
|
||||||
- blame me for loss of profit, data, sleep, food or other nasty things through
|
|
||||||
the use or distribution of ASMotor. If you choose to use ASMotor you do so at
|
|
||||||
your own risk.
|
|
||||||
- expect me to be able to help you should you have a problem related or not to
|
|
||||||
ASMotor.
|
|
||||||
|
|
||||||
Otaku no Zoku's modifications
|
|
||||||
-----------------------------
|
|
||||||
|
|
||||||
Copyright (C) 1999 Justin Lloyd <jlloyd@imf.la> (?)
|
|
||||||
|
|
||||||
::
|
|
||||||
|
|
||||||
DO WHATEVER PUBLIC LICENSE*
|
|
||||||
TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
|
|
||||||
|
|
||||||
0. You can do whatever you want to with the work.
|
|
||||||
1. You cannot stop anybody from doing whatever they want to with the work.
|
|
||||||
2. You cannot revoke anybody elses DO WHATEVER PUBLIC LICENSE in the work.
|
|
||||||
|
|
||||||
This program is free software. It comes without any warranty, to
|
|
||||||
the extent permitted by applicable law. You can redistribute it
|
|
||||||
and/or modify it under the terms of the DO WHATEVER PUBLIC LICENSE
|
|
||||||
|
|
||||||
Software originally created by Justin Lloyd @ http://otakunozoku.com/
|
|
||||||
|
|
||||||
rgbds-linux
|
|
||||||
-----------
|
|
||||||
|
|
||||||
Copyright (C) 2009 Vegard Nossum <vegard.nossum@gmail.com>
|
|
||||||
|
|
||||||
Current
|
|
||||||
-------
|
|
||||||
|
|
||||||
rgbasm and rgblink are derived from Justin Lloyd's RGBDS.
|
|
||||||
|
|
||||||
rgbfix was rewritten from scratch by Anthony J. Bentley, and is released under
|
|
||||||
the ISC license; see the source file for the text of the license.
|
|
||||||
|
|
||||||
rgbgfx was written by stag019, and is released under the ISC license.
|
|
||||||
|
|
||||||
Some files of rgblink were written by Antonio Niño Díaz, and they are relased
|
|
||||||
under the ISC license. The affected files have the appropriate license in the
|
|
||||||
header of the file.
|
|
||||||
|
|
||||||
The UTF-8 decoder in src/asm/charmap.c was written by Björn Höhrmann and is
|
|
||||||
released under the MIT license. The remainder of charmap.c was written by
|
|
||||||
stag019, and is released under the ISC license.
|
|
||||||
|
|
||||||
extern/err.c is derived from the Musl C library, http://www.musl-libc.org, and
|
|
||||||
is released under the MIT license.
|
|
||||||
|
|
||||||
extern/reallocarray.c is derived from the OpenBSD Project,
|
|
||||||
http://www.openbsd.org, and is released under the ISC license.
|
|
||||||
|
|
||||||
extern/strl.c is derived from the OpenBSD Project, http://www.openbsd.org, and
|
|
||||||
is released under the BSD license.
|
|
||||||
91
Makefile
91
Makefile
@@ -1,3 +1,11 @@
|
|||||||
|
#
|
||||||
|
# This file is part of RGBDS.
|
||||||
|
#
|
||||||
|
# Copyright (c) 1997-2018, Carsten Sorensen and RGBDS contributors.
|
||||||
|
#
|
||||||
|
# SPDX-License-Identifier: MIT
|
||||||
|
#
|
||||||
|
|
||||||
# User-defined variables
|
# User-defined variables
|
||||||
|
|
||||||
Q := @
|
Q := @
|
||||||
@@ -18,7 +26,7 @@ PNGLDLIBS := `${PKG_CONFIG} --static --libs-only-l libpng`
|
|||||||
|
|
||||||
VERSION_STRING := `git describe --tags --dirty --always 2>/dev/null`
|
VERSION_STRING := `git describe --tags --dirty --always 2>/dev/null`
|
||||||
|
|
||||||
WARNFLAGS := -Wall -Werror
|
WARNFLAGS := -Wall
|
||||||
|
|
||||||
# Overridable CFLAGS
|
# Overridable CFLAGS
|
||||||
CFLAGS := -g
|
CFLAGS := -g
|
||||||
@@ -49,11 +57,8 @@ rgbasm_obj := \
|
|||||||
src/asm/rpn.o \
|
src/asm/rpn.o \
|
||||||
src/asm/symbol.o \
|
src/asm/symbol.o \
|
||||||
src/extern/err.o \
|
src/extern/err.o \
|
||||||
src/extern/reallocarray.o \
|
src/extern/utf8decoder.o \
|
||||||
src/extern/strlcpy.o \
|
src/version.o
|
||||||
src/extern/strlcat.o \
|
|
||||||
src/extern/version.o
|
|
||||||
|
|
||||||
|
|
||||||
src/asm/asmy.h: src/asm/asmy.c
|
src/asm/asmy.h: src/asm/asmy.c
|
||||||
src/asm/locallex.o src/asm/globlex.o src/asm/lexer.o: src/asm/asmy.h
|
src/asm/locallex.o src/asm/globlex.o src/asm/lexer.o: src/asm/asmy.h
|
||||||
@@ -71,7 +76,7 @@ rgblink_obj := \
|
|||||||
src/link/script.o \
|
src/link/script.o \
|
||||||
src/link/symbol.o \
|
src/link/symbol.o \
|
||||||
src/extern/err.o \
|
src/extern/err.o \
|
||||||
src/extern/version.o
|
src/version.o
|
||||||
|
|
||||||
src/link/parser.h: src/link/parser.c
|
src/link/parser.h: src/link/parser.c
|
||||||
src/link/lexer.o: src/link/parser.h
|
src/link/lexer.o: src/link/parser.h
|
||||||
@@ -79,14 +84,14 @@ src/link/lexer.o: src/link/parser.h
|
|||||||
rgbfix_obj := \
|
rgbfix_obj := \
|
||||||
src/fix/main.o \
|
src/fix/main.o \
|
||||||
src/extern/err.o \
|
src/extern/err.o \
|
||||||
src/extern/version.o
|
src/version.o
|
||||||
|
|
||||||
rgbgfx_obj := \
|
rgbgfx_obj := \
|
||||||
src/gfx/gb.o \
|
src/gfx/gb.o \
|
||||||
src/gfx/main.o \
|
src/gfx/main.o \
|
||||||
src/gfx/makepng.o \
|
src/gfx/makepng.o \
|
||||||
src/extern/err.o \
|
src/extern/err.o \
|
||||||
src/extern/version.o
|
src/version.o
|
||||||
|
|
||||||
rgbasm: ${rgbasm_obj}
|
rgbasm: ${rgbasm_obj}
|
||||||
$Q${CC} ${REALCFLAGS} -o $@ ${rgbasm_obj} -lm
|
$Q${CC} ${REALCFLAGS} -o $@ ${rgbasm_obj} -lm
|
||||||
@@ -114,17 +119,26 @@ rgbgfx: ${rgbgfx_obj}
|
|||||||
.c.o:
|
.c.o:
|
||||||
$Q${CC} ${REALCFLAGS} ${PNGCFLAGS} -c -o $@ $<
|
$Q${CC} ${REALCFLAGS} ${PNGCFLAGS} -c -o $@ $<
|
||||||
|
|
||||||
# Target used to remove all files generated by other Makefile targets.
|
# Target used to remove all files generated by other Makefile targets, except
|
||||||
|
# for the html documentation.
|
||||||
|
|
||||||
clean:
|
clean:
|
||||||
$Q${RM} rgbds.7.html gbz80.7.html rgbds.5.html
|
$Q${RM} rgbasm rgbasm.exe ${rgbasm_obj}
|
||||||
$Q${RM} rgbasm rgbasm.exe ${rgbasm_obj} rgbasm.1.html rgbasm.5.html
|
$Q${RM} rgblink rgblink.exe ${rgblink_obj}
|
||||||
$Q${RM} rgblink rgblink.exe ${rgblink_obj} rgblink.1.html rgblink.5.html
|
$Q${RM} rgbfix rgbfix.exe ${rgbfix_obj}
|
||||||
$Q${RM} rgbfix rgbfix.exe ${rgbfix_obj} rgbfix.1.html
|
$Q${RM} rgbgfx rgbgfx.exe ${rgbgfx_obj}
|
||||||
$Q${RM} rgbgfx rgbgfx.exe ${rgbgfx_obj} rgbgfx.1.html
|
|
||||||
$Q${RM} src/asm/asmy.c src/asm/asmy.h
|
$Q${RM} src/asm/asmy.c src/asm/asmy.h
|
||||||
$Q${RM} src/link/lexer.c src/link/parser.c src/link/parser.h
|
$Q${RM} src/link/lexer.c src/link/parser.c src/link/parser.h
|
||||||
|
|
||||||
|
# Target used to remove all html files generated by the wwwman target
|
||||||
|
|
||||||
|
cleanwwwman:
|
||||||
|
$Q${RM} docs/rgbds.7.html docs/gbz80.7.html docs/rgbds.5.html
|
||||||
|
$Q${RM} docs/rgbasm.1.html docs/rgbasm.5.html
|
||||||
|
$Q${RM} docs/rgblink.1.html docs/rgblink.5.html
|
||||||
|
$Q${RM} docs/rgbfix.1.html
|
||||||
|
$Q${RM} docs/rgbgfx.1.html
|
||||||
|
|
||||||
# Target used to install the binaries and man pages.
|
# Target used to install the binaries and man pages.
|
||||||
|
|
||||||
install: all
|
install: all
|
||||||
@@ -146,8 +160,9 @@ install: all
|
|||||||
|
|
||||||
# Target used to check the coding style of the whole codebase. '.y' and '.l'
|
# Target used to check the coding style of the whole codebase. '.y' and '.l'
|
||||||
# files aren't checked, unfortunately...
|
# files aren't checked, unfortunately...
|
||||||
|
|
||||||
checkcodebase:
|
checkcodebase:
|
||||||
$Qfor file in `git ls-files | grep -E '\.c|\.h'`; do \
|
$Qfor file in `git ls-files | grep -E '\.c|\.h' | grep -v '\.html'`; do \
|
||||||
${CHECKPATCH} -f "$$file"; \
|
${CHECKPATCH} -f "$$file"; \
|
||||||
done
|
done
|
||||||
|
|
||||||
@@ -155,6 +170,7 @@ checkcodebase:
|
|||||||
# to the HEAD. Runs checkpatch once for each commit between the current HEAD and
|
# 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'
|
# the first common commit between the HEAD and origin/develop. '.y' and '.l'
|
||||||
# files aren't checked, unfortunately...
|
# files aren't checked, unfortunately...
|
||||||
|
|
||||||
checkpatch:
|
checkpatch:
|
||||||
$Qeval COMMON_COMMIT=$$(git merge-base HEAD origin/develop); \
|
$Qeval COMMON_COMMIT=$$(git merge-base HEAD origin/develop); \
|
||||||
for commit in `git rev-list $$COMMON_COMMIT..HEAD`; do \
|
for commit in `git rev-list $$COMMON_COMMIT..HEAD`; do \
|
||||||
@@ -166,18 +182,37 @@ checkpatch:
|
|||||||
# Target for the project maintainer to easily create web manuals.
|
# Target for the project maintainer to easily create web manuals.
|
||||||
# It relies on mandoc: http://mdocml.bsd.lv
|
# It relies on mandoc: http://mdocml.bsd.lv
|
||||||
|
|
||||||
MANDOC := -Thtml -Ios=General -Oman=%N.%S.html -Ostyle=manual.css
|
MANDOC := -Thtml -Ios=General -Oman=%N.%S.html -Ostyle=mandoc.css
|
||||||
|
|
||||||
wwwman:
|
wwwman:
|
||||||
$Qmandoc ${MANDOC} src/rgbds.7 > rgbds.7.html
|
$Qmandoc ${MANDOC} src/rgbds.7 > docs/rgbds.7.html
|
||||||
$Qmandoc ${MANDOC} src/gbz80.7 > gbz80.7.html
|
$Qmandoc ${MANDOC} src/gbz80.7 > docs/gbz80.7.html
|
||||||
$Qmandoc ${MANDOC} src/rgbds.5 > rgbds.5.html
|
$Qmandoc ${MANDOC} src/rgbds.5 > docs/rgbds.5.html
|
||||||
$Qmandoc ${MANDOC} src/asm/rgbasm.1 > rgbasm.1.html
|
$Qmandoc ${MANDOC} src/asm/rgbasm.1 > docs/rgbasm.1.html
|
||||||
$Qmandoc ${MANDOC} src/asm/rgbasm.5 > rgbasm.5.html
|
$Qmandoc ${MANDOC} src/asm/rgbasm.5 > docs/rgbasm.5.html
|
||||||
$Qmandoc ${MANDOC} src/fix/rgbfix.1 > rgbfix.1.html
|
$Qmandoc ${MANDOC} src/fix/rgbfix.1 > docs/rgbfix.1.html
|
||||||
$Qmandoc ${MANDOC} src/link/rgblink.1 > rgblink.1.html
|
$Qmandoc ${MANDOC} src/link/rgblink.1 > docs/rgblink.1.html
|
||||||
$Qmandoc ${MANDOC} src/link/rgblink.5 > rgblink.5.html
|
$Qmandoc ${MANDOC} src/link/rgblink.5 > docs/rgblink.5.html
|
||||||
$Qmandoc ${MANDOC} src/gfx/rgbgfx.1 > rgbgfx.1.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.
|
# Targets for the project maintainer to easily create Windows exes.
|
||||||
# This is not for Windows users!
|
# This is not for Windows users!
|
||||||
@@ -186,7 +221,7 @@ wwwman:
|
|||||||
|
|
||||||
mingw32:
|
mingw32:
|
||||||
$Qenv PKG_CONFIG_PATH=/usr/i686-w64-mingw32/sys-root/mingw/lib/pkgconfig/ \
|
$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 rgbasm rgbasm.exe
|
||||||
$Qmv rgblink rgblink.exe
|
$Qmv rgblink rgblink.exe
|
||||||
$Qmv rgbfix rgbfix.exe
|
$Qmv rgbfix rgbfix.exe
|
||||||
@@ -194,7 +229,7 @@ mingw32:
|
|||||||
|
|
||||||
mingw64:
|
mingw64:
|
||||||
$Qenv PKG_CONFIG_PATH=/usr/x86_64-w64-mingw32/sys-root/mingw/lib/pkgconfig/ \
|
$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 rgbasm rgbasm.exe
|
||||||
$Qmv rgblink rgblink.exe
|
$Qmv rgblink rgblink.exe
|
||||||
$Qmv rgbfix rgbfix.exe
|
$Qmv rgbfix rgbfix.exe
|
||||||
|
|||||||
@@ -12,12 +12,11 @@ for the Game Boy and Game Boy Color. It consists of:
|
|||||||
This is a fork of the original RGBDS which aims to make the programs more like
|
This is a fork of the original RGBDS which aims to make the programs more like
|
||||||
other UNIX tools.
|
other UNIX tools.
|
||||||
|
|
||||||
This toolchain is maintained on `GitHub <https://github.com/rednex/rgbds>`__, as
|
This toolchain is maintained on `GitHub <https://github.com/rednex/rgbds>`__.
|
||||||
well as its `documentation <https://github.com/rednex/rednex.github.io>`__.
|
|
||||||
|
|
||||||
The documentation of this toolchain can be viewed online
|
The documentation of this toolchain can be viewed online
|
||||||
`here <https://rednex.github.io/>`__, it is generated from the man pages found
|
`here <https://rednex.github.io/rgbds/>`__, it is generated from the man pages
|
||||||
in this repository.
|
found in this repository.
|
||||||
|
|
||||||
1. Installing RGBDS
|
1. Installing RGBDS
|
||||||
-------------------
|
-------------------
|
||||||
@@ -171,3 +170,5 @@ This is the complete list of user-defined variables:
|
|||||||
implementation of rgbds.
|
implementation of rgbds.
|
||||||
|
|
||||||
- 2017, Bentley's repository is moved to a neutral name.
|
- 2017, Bentley's repository is moved to a neutral name.
|
||||||
|
|
||||||
|
- 2018, codebase relicensed under the MIT license.
|
||||||
|
|||||||
1701
docs/gbz80.7.html
Normal file
1701
docs/gbz80.7.html
Normal file
File diff suppressed because it is too large
Load Diff
36
docs/index.html
Normal file
36
docs/index.html
Normal file
@@ -0,0 +1,36 @@
|
|||||||
|
<!DOCTYPE html>
|
||||||
|
<html>
|
||||||
|
<head>
|
||||||
|
<meta charset="utf-8"/>
|
||||||
|
<meta http-equiv="Content-Type" content="text/html;charset=UTF-8">
|
||||||
|
<title>General Information</title>
|
||||||
|
<link rel="stylesheet" type="text/css" href="mandoc.css">
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<h1>RGBDS — Rednex Game Boy Development System</h1>
|
||||||
|
<h2>Table of Contents</h2>
|
||||||
|
<ol>
|
||||||
|
<li>General information
|
||||||
|
<ul>
|
||||||
|
<li><a href="rgbds.7.html">RGBDS general information</a></li>
|
||||||
|
<li><a href="rgbds.5.html">RGBDS object file format</a></li>
|
||||||
|
</ul>
|
||||||
|
<li>Language description
|
||||||
|
<ul>
|
||||||
|
<li><a href="rgbasm.5.html">RGBASM language description</a></li>
|
||||||
|
<li><a href="rgblink.5.html">RGBLINK linkerscript language description</a></li>
|
||||||
|
<li><a href="gbz80.7.html">GBZ80 CPU instruction set description</a></li>
|
||||||
|
</ul>
|
||||||
|
<li>Command line usage
|
||||||
|
<ul>
|
||||||
|
<li><a href="rgbasm.1.html">RGBASM command-line usage</a></li>
|
||||||
|
<li><a href="rgblink.1.html">RGBLINK command-line usage</a></li>
|
||||||
|
<li><a href="rgbfix.1.html">RGBFIX command-line usage</a></li>
|
||||||
|
<li><a href="rgbgfx.1.html">RGBGFX command-line usage</a></li>
|
||||||
|
</ul>
|
||||||
|
</ol>
|
||||||
|
<h2 id="GitHub Repository">GitHub Repository:</h2>
|
||||||
|
<ul>
|
||||||
|
<li><a href="https://github.com/rednex/rgbds">https://github.com/rednex/rgbds</a></li>
|
||||||
|
</ul>
|
||||||
|
</body>
|
||||||
203
docs/mandoc.css
Executable file
203
docs/mandoc.css
Executable file
@@ -0,0 +1,203 @@
|
|||||||
|
/* $Id: mandoc.css,v 1.22 2017/07/16 18:45:00 schwarze Exp $ */
|
||||||
|
/*
|
||||||
|
* Standard style sheet for mandoc(1) -Thtml and man.cgi(8).
|
||||||
|
*/
|
||||||
|
|
||||||
|
/* Global defaults. */
|
||||||
|
|
||||||
|
html { max-width: 100ex; }
|
||||||
|
body { font-family: Helvetica,Arial,sans-serif; }
|
||||||
|
table { margin-top: 0em;
|
||||||
|
margin-bottom: 0em; }
|
||||||
|
td { vertical-align: top; }
|
||||||
|
ul, ol, dl { margin-top: 0em;
|
||||||
|
margin-bottom: 0em; }
|
||||||
|
li, dt { margin-top: 1em; }
|
||||||
|
|
||||||
|
a.selflink { border-bottom: thin dotted;
|
||||||
|
color: inherit;
|
||||||
|
font: inherit;
|
||||||
|
text-decoration: inherit; }
|
||||||
|
* { clear: both }
|
||||||
|
|
||||||
|
/* Search form and search results. */
|
||||||
|
|
||||||
|
fieldset { border: thin solid silver;
|
||||||
|
border-radius: 1em;
|
||||||
|
text-align: center; }
|
||||||
|
input[name=expr] {
|
||||||
|
width: 25%; }
|
||||||
|
|
||||||
|
table.results { margin-top: 1em;
|
||||||
|
margin-left: 2em;
|
||||||
|
font-size: smaller; }
|
||||||
|
|
||||||
|
/* Header and footer lines. */
|
||||||
|
|
||||||
|
table.head { width: 100%;
|
||||||
|
border-bottom: 1px dotted #808080;
|
||||||
|
margin-bottom: 1em;
|
||||||
|
font-size: smaller; }
|
||||||
|
td.head-vol { text-align: center; }
|
||||||
|
td.head-rtitle {
|
||||||
|
text-align: right; }
|
||||||
|
span.Nd { }
|
||||||
|
|
||||||
|
table.foot { width: 100%;
|
||||||
|
border-top: 1px dotted #808080;
|
||||||
|
margin-top: 1em;
|
||||||
|
font-size: smaller; }
|
||||||
|
td.foot-os { text-align: right; }
|
||||||
|
|
||||||
|
/* Sections and paragraphs. */
|
||||||
|
|
||||||
|
div.manual-text {
|
||||||
|
margin-left: 5ex; }
|
||||||
|
h1.Sh { margin-top: 2ex;
|
||||||
|
margin-bottom: 1ex;
|
||||||
|
margin-left: -4ex;
|
||||||
|
font-size: 110%; }
|
||||||
|
h2.Ss { margin-top: 2ex;
|
||||||
|
margin-bottom: 1ex;
|
||||||
|
margin-left: -2ex;
|
||||||
|
font-size: 105%; }
|
||||||
|
div.Pp { margin: 1ex 0ex; }
|
||||||
|
a.Sx { }
|
||||||
|
a.Xr { }
|
||||||
|
|
||||||
|
/* Displays and lists. */
|
||||||
|
|
||||||
|
div.Bd { }
|
||||||
|
div.D1 { margin-left: 5ex; }
|
||||||
|
|
||||||
|
ul.Bl-bullet { list-style-type: disc;
|
||||||
|
padding-left: 1em; }
|
||||||
|
li.It-bullet { }
|
||||||
|
ul.Bl-dash { list-style-type: none;
|
||||||
|
padding-left: 0em; }
|
||||||
|
li.It-dash:before {
|
||||||
|
content: "\2014 "; }
|
||||||
|
ul.Bl-item { list-style-type: none;
|
||||||
|
padding-left: 0em; }
|
||||||
|
li.It-item { }
|
||||||
|
ul.Bl-compact > li {
|
||||||
|
margin-top: 0ex; }
|
||||||
|
|
||||||
|
ol.Bl-enum { padding-left: 2em; }
|
||||||
|
li.It-enum { }
|
||||||
|
ol.Bl-compact > li {
|
||||||
|
margin-top: 0ex; }
|
||||||
|
|
||||||
|
dl.Bl-diag { }
|
||||||
|
dt.It-diag { }
|
||||||
|
dd.It-diag { margin-left: 0ex; }
|
||||||
|
b.It-diag { font-style: normal; }
|
||||||
|
dl.Bl-hang { }
|
||||||
|
dt.It-hang { }
|
||||||
|
dd.It-hang { margin-left: 10.2ex; }
|
||||||
|
dl.Bl-inset { }
|
||||||
|
dt.It-inset { }
|
||||||
|
dd.It-inset { margin-left: 0ex; }
|
||||||
|
dl.Bl-ohang { }
|
||||||
|
dt.It-ohang { }
|
||||||
|
dd.It-ohang { margin-left: 0ex; }
|
||||||
|
dl.Bl-tag { margin-left: 10.2ex; }
|
||||||
|
dt.It-tag { float: left;
|
||||||
|
margin-top: 0ex;
|
||||||
|
margin-left: -10.2ex;
|
||||||
|
padding-right: 2ex;
|
||||||
|
vertical-align: top; }
|
||||||
|
dd.It-tag { clear: right;
|
||||||
|
width: 100%;
|
||||||
|
margin-top: 0ex;
|
||||||
|
margin-left: 0ex;
|
||||||
|
vertical-align: top;
|
||||||
|
overflow: auto; }
|
||||||
|
dl.Bl-compact > dt {
|
||||||
|
margin-top: 0ex; }
|
||||||
|
|
||||||
|
table.Bl-column { }
|
||||||
|
tr.It-column { }
|
||||||
|
td.It-column { margin-top: 1em; }
|
||||||
|
table.Bl-compact > tbody > tr > td {
|
||||||
|
margin-top: 0ex; }
|
||||||
|
|
||||||
|
cite.Rs { font-style: normal;
|
||||||
|
font-weight: normal; }
|
||||||
|
span.RsA { }
|
||||||
|
i.RsB { font-weight: normal; }
|
||||||
|
span.RsC { }
|
||||||
|
span.RsD { }
|
||||||
|
i.RsI { font-weight: normal; }
|
||||||
|
i.RsJ { font-weight: normal; }
|
||||||
|
span.RsN { }
|
||||||
|
span.RsO { }
|
||||||
|
span.RsP { }
|
||||||
|
span.RsQ { }
|
||||||
|
span.RsR { }
|
||||||
|
span.RsT { text-decoration: underline; }
|
||||||
|
a.RsU { }
|
||||||
|
span.RsV { }
|
||||||
|
|
||||||
|
span.eqn { }
|
||||||
|
table.tbl { }
|
||||||
|
|
||||||
|
/* Semantic markup for command line utilities. */
|
||||||
|
|
||||||
|
table.Nm { }
|
||||||
|
b.Nm { font-style: normal; }
|
||||||
|
b.Fl { font-style: normal; }
|
||||||
|
b.Cm { font-style: normal; }
|
||||||
|
var.Ar { font-style: italic;
|
||||||
|
font-weight: normal; }
|
||||||
|
span.Op { }
|
||||||
|
b.Ic { font-style: normal; }
|
||||||
|
code.Ev { font-style: normal;
|
||||||
|
font-weight: normal;
|
||||||
|
font-family: monospace; }
|
||||||
|
i.Pa { font-weight: normal; }
|
||||||
|
|
||||||
|
/* Semantic markup for function libraries. */
|
||||||
|
|
||||||
|
span.Lb { }
|
||||||
|
b.In { font-style: normal; }
|
||||||
|
a.In { }
|
||||||
|
b.Fd { font-style: normal; }
|
||||||
|
var.Ft { font-style: italic;
|
||||||
|
font-weight: normal; }
|
||||||
|
b.Fn { font-style: normal; }
|
||||||
|
var.Fa { font-style: italic;
|
||||||
|
font-weight: normal; }
|
||||||
|
var.Vt { font-style: italic;
|
||||||
|
font-weight: normal; }
|
||||||
|
var.Va { font-style: italic;
|
||||||
|
font-weight: normal; }
|
||||||
|
code.Dv { font-style: normal;
|
||||||
|
font-weight: normal;
|
||||||
|
font-family: monospace; }
|
||||||
|
code.Er { font-style: normal;
|
||||||
|
font-weight: normal;
|
||||||
|
font-family: monospace; }
|
||||||
|
|
||||||
|
/* Various semantic markup. */
|
||||||
|
|
||||||
|
span.An { }
|
||||||
|
a.Lk { }
|
||||||
|
a.Mt { }
|
||||||
|
b.Cd { font-style: normal; }
|
||||||
|
i.Ad { font-weight: normal; }
|
||||||
|
b.Ms { font-style: normal; }
|
||||||
|
span.St { }
|
||||||
|
a.Ux { }
|
||||||
|
|
||||||
|
/* Physical markup. */
|
||||||
|
|
||||||
|
.No { font-style: normal;
|
||||||
|
font-weight: normal; }
|
||||||
|
.Em { font-style: italic;
|
||||||
|
font-weight: normal; }
|
||||||
|
.Sy { font-style: normal;
|
||||||
|
font-weight: bold; }
|
||||||
|
.Li { font-style: normal;
|
||||||
|
font-weight: normal;
|
||||||
|
font-family: monospace; }
|
||||||
157
docs/rgbasm.1.html
Normal file
157
docs/rgbasm.1.html
Normal file
@@ -0,0 +1,157 @@
|
|||||||
|
<!DOCTYPE html>
|
||||||
|
<html>
|
||||||
|
<head>
|
||||||
|
<meta charset="utf-8"/>
|
||||||
|
<style>
|
||||||
|
table.head, table.foot { width: 100%; }
|
||||||
|
td.head-rtitle, td.foot-os { text-align: right; }
|
||||||
|
td.head-vol { text-align: center; }
|
||||||
|
div.Pp { margin: 1ex 0ex; }
|
||||||
|
</style>
|
||||||
|
<link rel="stylesheet" href="mandoc.css" type="text/css" media="all"/>
|
||||||
|
<title>RGBASM(1)</title>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<table class="head">
|
||||||
|
<tr>
|
||||||
|
<td class="head-ltitle">RGBASM(1)</td>
|
||||||
|
<td class="head-vol">General Commands Manual</td>
|
||||||
|
<td class="head-rtitle">RGBASM(1)</td>
|
||||||
|
</tr>
|
||||||
|
</table>
|
||||||
|
<div class="manual-text">
|
||||||
|
<h1 class="Sh" title="Sh" id="NAME"><a class="selflink" href="#NAME">NAME</a></h1>
|
||||||
|
<b class="Nm" title="Nm">rgbasm</b> — <span class="Nd" title="Nd">Game
|
||||||
|
Boy assembler</span>
|
||||||
|
<h1 class="Sh" title="Sh" id="SYNOPSIS"><a class="selflink" href="#SYNOPSIS">SYNOPSIS</a></h1>
|
||||||
|
<table class="Nm">
|
||||||
|
<tr>
|
||||||
|
<td><b class="Nm" title="Nm">rgbasm</b></td>
|
||||||
|
<td>[<span class="Op"><b class="Fl" title="Fl">-EhLVvw</b></span>]
|
||||||
|
[<span class="Op"><b class="Fl" title="Fl">-b</b>
|
||||||
|
<var class="Ar" title="Ar">chars</var></span>]
|
||||||
|
[<span class="Op"><b class="Fl" title="Fl">-D</b>
|
||||||
|
<var class="Ar" title="Ar">name</var>[<span class="Op">=<var class="Ar" title="Ar">value</var></span>]</span>]
|
||||||
|
[<span class="Op"><b class="Fl" title="Fl">-g</b>
|
||||||
|
<var class="Ar" title="Ar">chars</var></span>]
|
||||||
|
[<span class="Op"><b class="Fl" title="Fl">-i</b>
|
||||||
|
<var class="Ar" title="Ar">path</var></span>]
|
||||||
|
[<span class="Op"><b class="Fl" title="Fl">-M</b>
|
||||||
|
<var class="Ar" title="Ar">dependfile</var></span>]
|
||||||
|
[<span class="Op"><b class="Fl" title="Fl">-o</b>
|
||||||
|
<var class="Ar" title="Ar">outfile</var></span>]
|
||||||
|
[<span class="Op"><b class="Fl" title="Fl">-p</b>
|
||||||
|
<var class="Ar" title="Ar">pad_value</var></span>]
|
||||||
|
<var class="Ar" title="Ar">file</var></td>
|
||||||
|
</tr>
|
||||||
|
</table>
|
||||||
|
<h1 class="Sh" title="Sh" id="DESCRIPTION"><a class="selflink" href="#DESCRIPTION">DESCRIPTION</a></h1>
|
||||||
|
The <b class="Nm" title="Nm">rgbasm</b> program creates an object file from an
|
||||||
|
assembly source file. Its arguments are as follows:
|
||||||
|
<dl class="Bl-tag">
|
||||||
|
<dt class="It-tag"> </dt>
|
||||||
|
<dd class="It-tag"> </dd>
|
||||||
|
<dt class="It-tag"><a class="selflink" href="#b"><b class="Fl" title="Fl" id="b">-b</b></a>
|
||||||
|
<var class="Ar" title="Ar">chars</var></dt>
|
||||||
|
<dd class="It-tag">Change the two characters used for binary constants. The
|
||||||
|
defaults are 01.</dd>
|
||||||
|
<dt class="It-tag"> </dt>
|
||||||
|
<dd class="It-tag"> </dd>
|
||||||
|
<dt class="It-tag"><a class="selflink" href="#D"><b class="Fl" title="Fl" id="D">-D</b></a>
|
||||||
|
<var class="Ar" title="Ar">name</var>[<span class="Op">=<var class="Ar" title="Ar">value</var></span>]</dt>
|
||||||
|
<dd class="It-tag">Add string symbol to the compiled source code. This is
|
||||||
|
equivalent to <var class="Ar" title="Ar">name</var>
|
||||||
|
<b class="Cm" title="Cm">EQUS</b>
|
||||||
|
“<var class="Ar" title="Ar">value</var>” in code. If a value
|
||||||
|
is not specified, a value of 1 is given.</dd>
|
||||||
|
<dt class="It-tag"> </dt>
|
||||||
|
<dd class="It-tag"> </dd>
|
||||||
|
<dt class="It-tag"><a class="selflink" href="#E"><b class="Fl" title="Fl" id="E">-E</b></a></dt>
|
||||||
|
<dd class="It-tag">Export all labels, including unreferenced and local
|
||||||
|
labels.</dd>
|
||||||
|
<dt class="It-tag"> </dt>
|
||||||
|
<dd class="It-tag"> </dd>
|
||||||
|
<dt class="It-tag"><a class="selflink" href="#g"><b class="Fl" title="Fl" id="g">-g</b></a>
|
||||||
|
<var class="Ar" title="Ar">chars</var></dt>
|
||||||
|
<dd class="It-tag">Change the four characters used for binary constants. The
|
||||||
|
defaults are 0123.</dd>
|
||||||
|
<dt class="It-tag"> </dt>
|
||||||
|
<dd class="It-tag"> </dd>
|
||||||
|
<dt class="It-tag"><a class="selflink" href="#h"><b class="Fl" title="Fl" id="h">-h</b></a></dt>
|
||||||
|
<dd class="It-tag">By default, <b class="Nm" title="Nm">rgbasm</b> inserts a
|
||||||
|
‘nop’ instruction immediately after any ‘halt’
|
||||||
|
instruction. The <b class="Fl" title="Fl">-h</b> option disables this
|
||||||
|
behavior.</dd>
|
||||||
|
<dt class="It-tag"> </dt>
|
||||||
|
<dd class="It-tag"> </dd>
|
||||||
|
<dt class="It-tag"><a class="selflink" href="#i"><b class="Fl" title="Fl" id="i">-i</b></a>
|
||||||
|
<var class="Ar" title="Ar">path</var></dt>
|
||||||
|
<dd class="It-tag">Add an include path.</dd>
|
||||||
|
<dt class="It-tag"> </dt>
|
||||||
|
<dd class="It-tag"> </dd>
|
||||||
|
<dt class="It-tag"><a class="selflink" href="#L"><b class="Fl" title="Fl" id="L">-L</b></a></dt>
|
||||||
|
<dd class="It-tag">Disable the optimization that turns loads of the form
|
||||||
|
<b class="Sy" title="Sy">LD [$FF00+n8],A</b> into the opcode
|
||||||
|
<b class="Sy" title="Sy">LDH [$FF00+n8],A</b> in order to have full
|
||||||
|
control of the result in the final ROM.</dd>
|
||||||
|
<dt class="It-tag"> </dt>
|
||||||
|
<dd class="It-tag"> </dd>
|
||||||
|
<dt class="It-tag"><a class="selflink" href="#M"><b class="Fl" title="Fl" id="M">-M</b></a>
|
||||||
|
<var class="Ar" title="Ar">dependfile</var></dt>
|
||||||
|
<dd class="It-tag">Print <a class="Xr" title="Xr">make(1)</a> dependencies to
|
||||||
|
<var class="Ar" title="Ar">dependfile</var>.</dd>
|
||||||
|
<dt class="It-tag"> </dt>
|
||||||
|
<dd class="It-tag"> </dd>
|
||||||
|
<dt class="It-tag"><a class="selflink" href="#o"><b class="Fl" title="Fl" id="o">-o</b></a>
|
||||||
|
<var class="Ar" title="Ar">outfile</var></dt>
|
||||||
|
<dd class="It-tag">Write an object file to the given filename.</dd>
|
||||||
|
<dt class="It-tag"> </dt>
|
||||||
|
<dd class="It-tag"> </dd>
|
||||||
|
<dt class="It-tag"><a class="selflink" href="#p"><b class="Fl" title="Fl" id="p">-p</b></a>
|
||||||
|
<var class="Ar" title="Ar">pad_value</var></dt>
|
||||||
|
<dd class="It-tag">When padding an image, pad with this value. The default is
|
||||||
|
0x00.</dd>
|
||||||
|
<dt class="It-tag"> </dt>
|
||||||
|
<dd class="It-tag"> </dd>
|
||||||
|
<dt class="It-tag"><a class="selflink" href="#V"><b class="Fl" title="Fl" id="V">-V</b></a></dt>
|
||||||
|
<dd class="It-tag">Print the version of the program and exit.</dd>
|
||||||
|
<dt class="It-tag"> </dt>
|
||||||
|
<dd class="It-tag"> </dd>
|
||||||
|
<dt class="It-tag"><a class="selflink" href="#v"><b class="Fl" title="Fl" id="v">-v</b></a></dt>
|
||||||
|
<dd class="It-tag">Be verbose.</dd>
|
||||||
|
<dt class="It-tag"> </dt>
|
||||||
|
<dd class="It-tag"> </dd>
|
||||||
|
<dt class="It-tag"><a class="selflink" href="#w"><b class="Fl" title="Fl" id="w">-w</b></a></dt>
|
||||||
|
<dd class="It-tag">Disable warning output.</dd>
|
||||||
|
</dl>
|
||||||
|
<h1 class="Sh" title="Sh" id="EXAMPLES"><a class="selflink" href="#EXAMPLES">EXAMPLES</a></h1>
|
||||||
|
Assembling a basic source file is simple:
|
||||||
|
<div class="Pp"></div>
|
||||||
|
<div class="Bd" style="margin-left: 5.00ex;">
|
||||||
|
<pre class="Li">
|
||||||
|
$ rgbasm -o bar.o foo.asm
|
||||||
|
</pre>
|
||||||
|
</div>
|
||||||
|
<div class="Pp"></div>
|
||||||
|
The resulting object file is not yet a usable ROM image — it must first
|
||||||
|
be run through <a class="Xr" title="Xr">rgblink(1)</a> and
|
||||||
|
<a class="Xr" title="Xr">rgbfix(1)</a>.
|
||||||
|
<h1 class="Sh" title="Sh" id="SEE_ALSO"><a class="selflink" href="#SEE_ALSO">SEE
|
||||||
|
ALSO</a></h1>
|
||||||
|
<a class="Xr" title="Xr">rgbasm(5)</a>, <a class="Xr" title="Xr">rgbfix(1)</a>,
|
||||||
|
<a class="Xr" title="Xr">rgblink(1)</a>,
|
||||||
|
<a class="Xr" title="Xr">rgbds(5)</a>, <a class="Xr" title="Xr">rgbds(7)</a>,
|
||||||
|
<a class="Xr" title="Xr">gbz80(7)</a>
|
||||||
|
<h1 class="Sh" title="Sh" id="HISTORY"><a class="selflink" href="#HISTORY">HISTORY</a></h1>
|
||||||
|
<b class="Nm" title="Nm">rgbasm</b> was originally written by Carsten
|
||||||
|
Sørensen as part of the ASMotor package, and was later packaged in
|
||||||
|
RGBDS by Justin Lloyd. It is now maintained by a number of contributors at
|
||||||
|
<a class="Lk" title="Lk" href="https://github.com/rednex/rgbds">https://github.com/rednex/rgbds</a>.</div>
|
||||||
|
<table class="foot">
|
||||||
|
<tr>
|
||||||
|
<td class="foot-date">February 24, 2018</td>
|
||||||
|
<td class="foot-os">RGBDS Manual</td>
|
||||||
|
</tr>
|
||||||
|
</table>
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
1599
docs/rgbasm.5.html
Normal file
1599
docs/rgbasm.5.html
Normal file
File diff suppressed because it is too large
Load Diff
309
docs/rgbds.5.html
Normal file
309
docs/rgbds.5.html
Normal file
@@ -0,0 +1,309 @@
|
|||||||
|
<!DOCTYPE html>
|
||||||
|
<html>
|
||||||
|
<head>
|
||||||
|
<meta charset="utf-8"/>
|
||||||
|
<style>
|
||||||
|
table.head, table.foot { width: 100%; }
|
||||||
|
td.head-rtitle, td.foot-os { text-align: right; }
|
||||||
|
td.head-vol { text-align: center; }
|
||||||
|
div.Pp { margin: 1ex 0ex; }
|
||||||
|
</style>
|
||||||
|
<link rel="stylesheet" href="mandoc.css" type="text/css" media="all"/>
|
||||||
|
<title>RGBDS(5)</title>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<table class="head">
|
||||||
|
<tr>
|
||||||
|
<td class="head-ltitle">RGBDS(5)</td>
|
||||||
|
<td class="head-vol">File Formats Manual</td>
|
||||||
|
<td class="head-rtitle">RGBDS(5)</td>
|
||||||
|
</tr>
|
||||||
|
</table>
|
||||||
|
<div class="manual-text">
|
||||||
|
<h1 class="Sh" title="Sh" id="NAME"><a class="selflink" href="#NAME">NAME</a></h1>
|
||||||
|
<b class="Nm" title="Nm">rgbds</b> — <span class="Nd" title="Nd">object
|
||||||
|
file format documentation</span>
|
||||||
|
<h1 class="Sh" title="Sh" id="DESCRIPTION"><a class="selflink" href="#DESCRIPTION">DESCRIPTION</a></h1>
|
||||||
|
This is the description of the object files used by
|
||||||
|
<a class="Xr" title="Xr">rgbasm(1)</a> and
|
||||||
|
<a class="Xr" title="Xr">rgblink(1)</a>. Please, note that the specifications
|
||||||
|
may change. This toolchain is in development and new features may require
|
||||||
|
adding more information to the current format, or modifying some fields, which
|
||||||
|
would break compatibility with older versions.
|
||||||
|
<h1 class="Sh" title="Sh" id="FILE_STRUCTURE"><a class="selflink" href="#FILE_STRUCTURE">FILE
|
||||||
|
STRUCTURE</a></h1>
|
||||||
|
The following types are used:
|
||||||
|
<div class="Pp"></div>
|
||||||
|
<var class="Ar" title="Ar">LONG</var> is a 32‐bit integer stored in
|
||||||
|
little‐endian format (Intel). <var class="Ar" title="Ar">BYTE</var> is
|
||||||
|
an 8‐bit integer. <var class="Ar" title="Ar">STRING</var> is a
|
||||||
|
0‐terminated string of <var class="Ar" title="Ar">BYTE</var>.
|
||||||
|
<div class="Pp"></div>
|
||||||
|
<div class="Bd" style="margin-left: 0.00ex;">
|
||||||
|
<pre class="Li">
|
||||||
|
; Header
|
||||||
|
|
||||||
|
BYTE ID[4] ; "RGB6"
|
||||||
|
LONG NumberOfSymbols ; The number of symbols used in this file
|
||||||
|
LONG NumberOfSections ; The number of sections used in this file
|
||||||
|
|
||||||
|
; Symbols
|
||||||
|
|
||||||
|
REPT NumberOfSymbols ; Number of symbols defined in this object file.
|
||||||
|
|
||||||
|
STRING Name ; The name of this symbol. Local symbols are stored
|
||||||
|
; as "Scope.Symbol".
|
||||||
|
|
||||||
|
BYTE Type ; 0 = LOCAL symbol only used in this file.
|
||||||
|
; 1 = IMPORT this symbol from elsewhere (unused).
|
||||||
|
; 2 = EXPORT this symbol to other objects.
|
||||||
|
|
||||||
|
IF Type != 1 ; If symbol is defined in this object file.
|
||||||
|
|
||||||
|
STRING FileName ; File where the symbol is defined.
|
||||||
|
|
||||||
|
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. 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.
|
||||||
|
|
||||||
|
ENDC
|
||||||
|
|
||||||
|
ENDR
|
||||||
|
|
||||||
|
; Sections
|
||||||
|
|
||||||
|
REPT NumberOfSections
|
||||||
|
STRING Name ; Name of the section
|
||||||
|
|
||||||
|
LONG Size ; Size in bytes of this section
|
||||||
|
|
||||||
|
BYTE Type ; 0 = WRAM0
|
||||||
|
; 1 = VRAM
|
||||||
|
; 2 = ROMX
|
||||||
|
; 3 = ROM0
|
||||||
|
; 4 = HRAM
|
||||||
|
; 5 = WRAMX
|
||||||
|
; 6 = SRAM
|
||||||
|
; 7 = OAM
|
||||||
|
|
||||||
|
LONG Org ; Address to fix this section at. -1 if the linker should
|
||||||
|
; decide (floating address).
|
||||||
|
|
||||||
|
LONG Bank ; Bank to load this section into. -1 if the linker should
|
||||||
|
; decide (floating bank). This field is only valid for ROMX,
|
||||||
|
; VRAM, WRAMX and SRAM sections.
|
||||||
|
|
||||||
|
LONG Align ; Alignment of this section (expressed as number of low bits
|
||||||
|
; to leave as 0). -1 if not defined.
|
||||||
|
|
||||||
|
IF (Type == ROMX) || (Type == ROM0) ; Sections that can contain data.
|
||||||
|
|
||||||
|
BYTE Data[Size] ; Raw data of the section.
|
||||||
|
|
||||||
|
LONG NumberOfPatches ; Number of patches to apply.
|
||||||
|
|
||||||
|
; These types of sections may have patches
|
||||||
|
|
||||||
|
REPT NumberOfPatches
|
||||||
|
|
||||||
|
STRING SourceFile ; Name of the source file (for printing error
|
||||||
|
; messages).
|
||||||
|
|
||||||
|
LONG Line ; The line of the source file.
|
||||||
|
|
||||||
|
LONG Offset ; Offset into the section where patch should
|
||||||
|
; be applied (in bytes).
|
||||||
|
|
||||||
|
BYTE Type ; 0 = BYTE patch.
|
||||||
|
; 1 = little endian WORD patch.
|
||||||
|
; 2 = little endian LONG patch.
|
||||||
|
; 3 = JR offset value BYTE patch.
|
||||||
|
|
||||||
|
LONG RPNSize ; Size of the buffer with the RPN.
|
||||||
|
; expression.
|
||||||
|
|
||||||
|
BYTE RPN[RPNSize] ; RPN expression. Definition below.
|
||||||
|
|
||||||
|
ENDR
|
||||||
|
|
||||||
|
ENDC
|
||||||
|
|
||||||
|
ENDR
|
||||||
|
</pre>
|
||||||
|
</div>
|
||||||
|
<h2 class="Ss" title="Ss" id="RPN_DATA"><a class="selflink" href="#RPN_DATA">RPN
|
||||||
|
DATA</a></h2>
|
||||||
|
Expressions in the object file are stored as RPN. This is an expression of the
|
||||||
|
form “2 5 +”. This will first push the value “2”
|
||||||
|
to the stack. Then “5”. The “+” operator pops two
|
||||||
|
arguments from the stack, adds them, and then pushes the result on the stack,
|
||||||
|
effectively replacing the two top arguments with their sum. In the RGB format,
|
||||||
|
RPN expressions are stored as BYTEs with some bytes being special prefixes for
|
||||||
|
integers and symbols.
|
||||||
|
<table class="Bl-column" style="margin-left: 6.00ex;">
|
||||||
|
<colgroup>
|
||||||
|
<col style="width: 15.00ex;"/>
|
||||||
|
<col style="min-width: 10.00ex;"/>
|
||||||
|
</colgroup>
|
||||||
|
<tr class="It-column">
|
||||||
|
<td class="It-column"><b class="Sy" title="Sy">Value</b></td>
|
||||||
|
<td class="It-column"><b class="Sy" title="Sy">Meaning</b></td>
|
||||||
|
</tr>
|
||||||
|
<tr class="It-column">
|
||||||
|
<td class="It-column"><a class="selflink" href="#$00"><code class="Li" id="$00">$00</code></a></td>
|
||||||
|
<td class="It-column"><a class="selflink" href="#+_operator"><code class="Li" id="+_operator">+
|
||||||
|
operator</code></a></td>
|
||||||
|
</tr>
|
||||||
|
<tr class="It-column">
|
||||||
|
<td class="It-column"><a class="selflink" href="#$01"><code class="Li" id="$01">$01</code></a></td>
|
||||||
|
<td class="It-column"><a class="selflink" href="#-_operator"><code class="Li" id="-_operator">-
|
||||||
|
operator</code></a></td>
|
||||||
|
</tr>
|
||||||
|
<tr class="It-column">
|
||||||
|
<td class="It-column"><a class="selflink" href="#$02"><code class="Li" id="$02">$02</code></a></td>
|
||||||
|
<td class="It-column"><a class="selflink" href="#*_operator"><code class="Li" id="*_operator">*
|
||||||
|
operator</code></a></td>
|
||||||
|
</tr>
|
||||||
|
<tr class="It-column">
|
||||||
|
<td class="It-column"><a class="selflink" href="#$03"><code class="Li" id="$03">$03</code></a></td>
|
||||||
|
<td class="It-column"><a class="selflink" href="#/_operator"><code class="Li" id="/_operator">/
|
||||||
|
operator</code></a></td>
|
||||||
|
</tr>
|
||||||
|
<tr class="It-column">
|
||||||
|
<td class="It-column"><a class="selflink" href="#$04"><code class="Li" id="$04">$04</code></a></td>
|
||||||
|
<td class="It-column"><a class="selflink" href="#%_operator"><code class="Li" id="%_operator">%
|
||||||
|
operator</code></a></td>
|
||||||
|
</tr>
|
||||||
|
<tr class="It-column">
|
||||||
|
<td class="It-column"><a class="selflink" href="#$05"><code class="Li" id="$05">$05</code></a></td>
|
||||||
|
<td class="It-column"><a class="selflink" href="#unary_-"><code class="Li" id="unary_-">unary
|
||||||
|
-</code></a></td>
|
||||||
|
</tr>
|
||||||
|
<tr class="It-column">
|
||||||
|
<td class="It-column"><a class="selflink" href="#$10"><code class="Li" id="$10">$10</code></a></td>
|
||||||
|
<td class="It-column">|
|
||||||
|
<a class="selflink" href="#operator"><code class="Li" id="operator">operator</code></a></td>
|
||||||
|
</tr>
|
||||||
|
<tr class="It-column">
|
||||||
|
<td class="It-column"><a class="selflink" href="#$11"><code class="Li" id="$11">$11</code></a></td>
|
||||||
|
<td class="It-column"><a class="selflink" href="#&_operator"><code class="Li" id="&_operator">&
|
||||||
|
operator</code></a></td>
|
||||||
|
</tr>
|
||||||
|
<tr class="It-column">
|
||||||
|
<td class="It-column"><a class="selflink" href="#$12"><code class="Li" id="$12">$12</code></a></td>
|
||||||
|
<td class="It-column"><a class="selflink" href="#^_operator"><code class="Li" id="^_operator">^
|
||||||
|
operator</code></a></td>
|
||||||
|
</tr>
|
||||||
|
<tr class="It-column">
|
||||||
|
<td class="It-column"><a class="selflink" href="#$13"><code class="Li" id="$13">$13</code></a></td>
|
||||||
|
<td class="It-column"><a class="selflink" href="#unary_~"><code class="Li" id="unary_~">unary
|
||||||
|
~</code></a></td>
|
||||||
|
</tr>
|
||||||
|
<tr class="It-column">
|
||||||
|
<td class="It-column"><a class="selflink" href="#$21"><code class="Li" id="$21">$21</code></a></td>
|
||||||
|
<td class="It-column"><a class="selflink" href="#&&_comparison"><code class="Li" id="&&_comparison">&&
|
||||||
|
comparison</code></a></td>
|
||||||
|
</tr>
|
||||||
|
<tr class="It-column">
|
||||||
|
<td class="It-column"><a class="selflink" href="#$22"><code class="Li" id="$22">$22</code></a></td>
|
||||||
|
<td class="It-column"><a class="selflink" href="#||_comparison"><code class="Li" id="||_comparison">||
|
||||||
|
comparison</code></a></td>
|
||||||
|
</tr>
|
||||||
|
<tr class="It-column">
|
||||||
|
<td class="It-column"><a class="selflink" href="#$23"><code class="Li" id="$23">$23</code></a></td>
|
||||||
|
<td class="It-column"><a class="selflink" href="#unary"><code class="Li" id="unary">unary</code></a>!</td>
|
||||||
|
</tr>
|
||||||
|
<tr class="It-column">
|
||||||
|
<td class="It-column"><a class="selflink" href="#$30"><code class="Li" id="$30">$30</code></a></td>
|
||||||
|
<td class="It-column"><a class="selflink" href="#==_comparison"><code class="Li" id="==_comparison">==
|
||||||
|
comparison</code></a></td>
|
||||||
|
</tr>
|
||||||
|
<tr class="It-column">
|
||||||
|
<td class="It-column"><a class="selflink" href="#$31"><code class="Li" id="$31">$31</code></a></td>
|
||||||
|
<td class="It-column"><a class="selflink" href="#!=_comparison"><code class="Li" id="!=_comparison">!=
|
||||||
|
comparison</code></a></td>
|
||||||
|
</tr>
|
||||||
|
<tr class="It-column">
|
||||||
|
<td class="It-column"><a class="selflink" href="#$32"><code class="Li" id="$32">$32</code></a></td>
|
||||||
|
<td class="It-column"><a class="selflink" href="#>_comparison"><code class="Li" id=">_comparison">>
|
||||||
|
comparison</code></a></td>
|
||||||
|
</tr>
|
||||||
|
<tr class="It-column">
|
||||||
|
<td class="It-column"><a class="selflink" href="#$33"><code class="Li" id="$33">$33</code></a></td>
|
||||||
|
<td class="It-column"><a class="selflink" href="#<_comparison"><code class="Li" id="<_comparison"><
|
||||||
|
comparison</code></a></td>
|
||||||
|
</tr>
|
||||||
|
<tr class="It-column">
|
||||||
|
<td class="It-column"><a class="selflink" href="#$34"><code class="Li" id="$34">$34</code></a></td>
|
||||||
|
<td class="It-column"><a class="selflink" href="#>=_comparison"><code class="Li" id=">=_comparison">>=
|
||||||
|
comparison</code></a></td>
|
||||||
|
</tr>
|
||||||
|
<tr class="It-column">
|
||||||
|
<td class="It-column"><a class="selflink" href="#$35"><code class="Li" id="$35">$35</code></a></td>
|
||||||
|
<td class="It-column"><a class="selflink" href="#<=_comparison"><code class="Li" id="<=_comparison"><=
|
||||||
|
comparison</code></a></td>
|
||||||
|
</tr>
|
||||||
|
<tr class="It-column">
|
||||||
|
<td class="It-column"><a class="selflink" href="#$40"><code class="Li" id="$40">$40</code></a></td>
|
||||||
|
<td class="It-column"><a class="selflink" href="#<<_comparison"><code class="Li" id="<<_comparison"><<
|
||||||
|
comparison</code></a></td>
|
||||||
|
</tr>
|
||||||
|
<tr class="It-column">
|
||||||
|
<td class="It-column"><a class="selflink" href="#$41"><code class="Li" id="$41">$41</code></a></td>
|
||||||
|
<td class="It-column"><a class="selflink" href="#>>_comparison"><code class="Li" id=">>_comparison">>>
|
||||||
|
comparison</code></a></td>
|
||||||
|
</tr>
|
||||||
|
<tr class="It-column">
|
||||||
|
<td class="It-column"><a class="selflink" href="#$50"><code class="Li" id="$50">$50</code></a></td>
|
||||||
|
<td class="It-column"><a class="selflink" href="#BANK(symbol),"><code class="Li" id="BANK(symbol),">BANK(symbol),</code></a>
|
||||||
|
a <var class="Ar" title="Ar">LONG</var> Symbol ID follows.</td>
|
||||||
|
</tr>
|
||||||
|
<tr class="It-column">
|
||||||
|
<td class="It-column"><a class="selflink" href="#$51"><code class="Li" id="$51">$51</code></a></td>
|
||||||
|
<td class="It-column"><a class="selflink" href="#BANK(section_name),"><code class="Li" id="BANK(section_name),">BANK(section_name),</code></a>
|
||||||
|
a null-terminated string follows.</td>
|
||||||
|
</tr>
|
||||||
|
<tr class="It-column">
|
||||||
|
<td class="It-column"><a class="selflink" href="#$52"><code class="Li" id="$52">$52</code></a></td>
|
||||||
|
<td class="It-column"><a class="selflink" href="#Current_BANK()"><code class="Li" id="Current_BANK()">Current
|
||||||
|
BANK()</code></a>.</td>
|
||||||
|
</tr>
|
||||||
|
<tr class="It-column">
|
||||||
|
<td class="It-column"><a class="selflink" href="#$60"><code class="Li" id="$60">$60</code></a></td>
|
||||||
|
<td class="It-column"><a class="selflink" href="#HRAMCheck."><code class="Li" id="HRAMCheck.">HRAMCheck.</code></a>
|
||||||
|
Check if the value is in HRAM, AND it with 0xFF.</td>
|
||||||
|
</tr>
|
||||||
|
<tr class="It-column">
|
||||||
|
<td class="It-column"><a class="selflink" href="#$80"><code class="Li" id="$80">$80</code></a></td>
|
||||||
|
<td class="It-column"><var class="Ar" title="Ar">LONG</var> integer
|
||||||
|
follows.</td>
|
||||||
|
</tr>
|
||||||
|
<tr class="It-column">
|
||||||
|
<td class="It-column"><a class="selflink" href="#$81"><code class="Li" id="$81">$81</code></a></td>
|
||||||
|
<td class="It-column"><var class="Ar" title="Ar">LONG</var> Symbol ID
|
||||||
|
follows.</td>
|
||||||
|
</tr>
|
||||||
|
</table>
|
||||||
|
<h1 class="Sh" title="Sh" id="SEE_ALSO"><a class="selflink" href="#SEE_ALSO">SEE
|
||||||
|
ALSO</a></h1>
|
||||||
|
<a class="Xr" title="Xr">rgbasm(1)</a>, <a class="Xr" title="Xr">rgblink(1)</a>,
|
||||||
|
<a class="Xr" title="Xr">rgbds(7)</a>, <a class="Xr" title="Xr">gbz80(7)</a>
|
||||||
|
<h1 class="Sh" title="Sh" id="HISTORY"><a class="selflink" href="#HISTORY">HISTORY</a></h1>
|
||||||
|
<b class="Nm" title="Nm">rgbds</b> was originally written by Carsten
|
||||||
|
Sørensen as part of the ASMotor package, and was later packaged in
|
||||||
|
RGBDS by Justin Lloyd. It is now maintained by a number of contributors at
|
||||||
|
<a class="Lk" title="Lk" href="https://github.com/rednex/rgbds">https://github.com/rednex/rgbds</a>.</div>
|
||||||
|
<table class="foot">
|
||||||
|
<tr>
|
||||||
|
<td class="foot-date">January 26, 2018</td>
|
||||||
|
<td class="foot-os">RGBDS Manual</td>
|
||||||
|
</tr>
|
||||||
|
</table>
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
71
docs/rgbds.7.html
Normal file
71
docs/rgbds.7.html
Normal file
@@ -0,0 +1,71 @@
|
|||||||
|
<!DOCTYPE html>
|
||||||
|
<html>
|
||||||
|
<head>
|
||||||
|
<meta charset="utf-8"/>
|
||||||
|
<style>
|
||||||
|
table.head, table.foot { width: 100%; }
|
||||||
|
td.head-rtitle, td.foot-os { text-align: right; }
|
||||||
|
td.head-vol { text-align: center; }
|
||||||
|
div.Pp { margin: 1ex 0ex; }
|
||||||
|
</style>
|
||||||
|
<link rel="stylesheet" href="mandoc.css" type="text/css" media="all"/>
|
||||||
|
<title>RGBDS(7)</title>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<table class="head">
|
||||||
|
<tr>
|
||||||
|
<td class="head-ltitle">RGBDS(7)</td>
|
||||||
|
<td class="head-vol">Miscellaneous Information Manual</td>
|
||||||
|
<td class="head-rtitle">RGBDS(7)</td>
|
||||||
|
</tr>
|
||||||
|
</table>
|
||||||
|
<div class="manual-text">
|
||||||
|
<h1 class="Sh" title="Sh" id="NAME"><a class="selflink" href="#NAME">NAME</a></h1>
|
||||||
|
<b class="Nm" title="Nm">rgbds</b> — <span class="Nd" title="Nd">Rednex
|
||||||
|
Game Boy Development System</span>
|
||||||
|
<h1 class="Sh" title="Sh" id="EXAMPLES"><a class="selflink" href="#EXAMPLES">EXAMPLES</a></h1>
|
||||||
|
To get a working ROM image from a single assembly source file:
|
||||||
|
<div class="Pp"></div>
|
||||||
|
<div class="Bd" style="margin-left: 5.00ex;">
|
||||||
|
<pre class="Li">
|
||||||
|
$ rgbasm -o bar.o foo.asm
|
||||||
|
$ rgblink -o baz.gb bar.o
|
||||||
|
$ rgbfix -v -p 0 baz.gb
|
||||||
|
</pre>
|
||||||
|
</div>
|
||||||
|
<h1 class="Sh" title="Sh" id="SEE_ALSO"><a class="selflink" href="#SEE_ALSO">SEE
|
||||||
|
ALSO</a></h1>
|
||||||
|
<a class="Xr" title="Xr">rgbasm(1)</a>, <a class="Xr" title="Xr">rgbfix(1)</a>,
|
||||||
|
<a class="Xr" title="Xr">rgblink(1)</a>,
|
||||||
|
<a class="Xr" title="Xr">rgbds(5)</a>, <a class="Xr" title="Xr">gbz80(7)</a>
|
||||||
|
<h1 class="Sh" title="Sh" id="HISTORY"><a class="selflink" href="#HISTORY">HISTORY</a></h1>
|
||||||
|
<dl class="Bl-ohang">
|
||||||
|
<dt class="It-ohang"></dt>
|
||||||
|
<dd class="It-ohang">1997, Carsten Sørensen (AKA SurfSmurf) writes
|
||||||
|
ASMotor as a general-purpose assembler/linker system for DOS/Win32.</dd>
|
||||||
|
<dt class="It-ohang"></dt>
|
||||||
|
<dd class="It-ohang">1999, Justin Lloyd (AKA Otaku no Zoku) adapts ASMotor to
|
||||||
|
read and produce GBZ80 assembly/machine code, and releases this version as
|
||||||
|
RGBDS.</dd>
|
||||||
|
<dt class="It-ohang"></dt>
|
||||||
|
<dd class="It-ohang">2009, Vegard Nossum adapts the code to be more UNIX-like
|
||||||
|
and releases this version as rgbds-linux on GitHub.</dd>
|
||||||
|
<dt class="It-ohang"></dt>
|
||||||
|
<dd class="It-ohang">2010, Anthony J. Bentley forks that repository. The fork
|
||||||
|
becomes the reference implementation of rgbds.</dd>
|
||||||
|
<dt class="It-ohang"></dt>
|
||||||
|
<dd class="It-ohang">2017, Bentley's repository is moved to a neutral name. It
|
||||||
|
is now maintained by a number of contributors at
|
||||||
|
<a class="Lk" title="Lk" href="https://github.com/rednex/rgbds">https://github.com/rednex/rgbds</a>.</dd>
|
||||||
|
<dt class="It-ohang"></dt>
|
||||||
|
<dd class="It-ohang">2018, codebase relicensed under the MIT license.</dd>
|
||||||
|
</dl>
|
||||||
|
</div>
|
||||||
|
<table class="foot">
|
||||||
|
<tr>
|
||||||
|
<td class="foot-date">March 7, 2018</td>
|
||||||
|
<td class="foot-os">RGBDS Manual</td>
|
||||||
|
</tr>
|
||||||
|
</table>
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
213
docs/rgbfix.1.html
Normal file
213
docs/rgbfix.1.html
Normal file
@@ -0,0 +1,213 @@
|
|||||||
|
<!DOCTYPE html>
|
||||||
|
<html>
|
||||||
|
<head>
|
||||||
|
<meta charset="utf-8"/>
|
||||||
|
<style>
|
||||||
|
table.head, table.foot { width: 100%; }
|
||||||
|
td.head-rtitle, td.foot-os { text-align: right; }
|
||||||
|
td.head-vol { text-align: center; }
|
||||||
|
div.Pp { margin: 1ex 0ex; }
|
||||||
|
</style>
|
||||||
|
<link rel="stylesheet" href="mandoc.css" type="text/css" media="all"/>
|
||||||
|
<title>RGBFIX(1)</title>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<table class="head">
|
||||||
|
<tr>
|
||||||
|
<td class="head-ltitle">RGBFIX(1)</td>
|
||||||
|
<td class="head-vol">General Commands Manual</td>
|
||||||
|
<td class="head-rtitle">RGBFIX(1)</td>
|
||||||
|
</tr>
|
||||||
|
</table>
|
||||||
|
<div class="manual-text">
|
||||||
|
<h1 class="Sh" title="Sh" id="NAME"><a class="selflink" href="#NAME">NAME</a></h1>
|
||||||
|
<b class="Nm" title="Nm">rgbfix</b> — <span class="Nd" title="Nd">Game
|
||||||
|
Boy checksum fixer</span>
|
||||||
|
<h1 class="Sh" title="Sh" id="SYNOPSIS"><a class="selflink" href="#SYNOPSIS">SYNOPSIS</a></h1>
|
||||||
|
<table class="Nm">
|
||||||
|
<tr>
|
||||||
|
<td><b class="Nm" title="Nm">rgbfix</b></td>
|
||||||
|
<td>[<span class="Op"><b class="Fl" title="Fl">-CcjsVv</b></span>]
|
||||||
|
[<span class="Op"><b class="Fl" title="Fl">-f</b>
|
||||||
|
<var class="Ar" title="Ar">fix_spec</var></span>]
|
||||||
|
[<span class="Op"><b class="Fl" title="Fl">-i</b>
|
||||||
|
<var class="Ar" title="Ar">game_id</var></span>]
|
||||||
|
[<span class="Op"><b class="Fl" title="Fl">-k</b>
|
||||||
|
<var class="Ar" title="Ar">licensee_str</var></span>]
|
||||||
|
[<span class="Op"><b class="Fl" title="Fl">-l</b>
|
||||||
|
<var class="Ar" title="Ar">licensee_id</var></span>]
|
||||||
|
[<span class="Op"><b class="Fl" title="Fl">-m</b>
|
||||||
|
<var class="Ar" title="Ar">mbc_type</var></span>]
|
||||||
|
[<span class="Op"><b class="Fl" title="Fl">-n</b>
|
||||||
|
<var class="Ar" title="Ar">rom_version</var></span>]
|
||||||
|
[<span class="Op"><b class="Fl" title="Fl">-p</b>
|
||||||
|
<var class="Ar" title="Ar">pad_value</var></span>]
|
||||||
|
[<span class="Op"><b class="Fl" title="Fl">-r</b>
|
||||||
|
<var class="Ar" title="Ar">ram_size</var></span>]
|
||||||
|
[<span class="Op"><b class="Fl" title="Fl">-t</b>
|
||||||
|
<var class="Ar" title="Ar">title_str</var></span>]
|
||||||
|
<var class="Ar" title="Ar">file</var></td>
|
||||||
|
</tr>
|
||||||
|
</table>
|
||||||
|
<h1 class="Sh" title="Sh" id="DESCRIPTION"><a class="selflink" href="#DESCRIPTION">DESCRIPTION</a></h1>
|
||||||
|
The <b class="Nm" title="Nm">rgbfix</b> program changes headers of Game Boy ROM
|
||||||
|
images. It also performs other filetype operations, such as truncation. The
|
||||||
|
arguments are as follows:
|
||||||
|
<dl class="Bl-tag">
|
||||||
|
<dt class="It-tag"> </dt>
|
||||||
|
<dd class="It-tag"> </dd>
|
||||||
|
<dt class="It-tag"><a class="selflink" href="#C"><b class="Fl" title="Fl" id="C">-C</b></a></dt>
|
||||||
|
<dd class="It-tag">Set the Game Boy Color–only flag:
|
||||||
|
<i class="Ad">0x143</i> = 0xC0. If both this and the
|
||||||
|
<b class="Fl" title="Fl">-c</b> flag are set, this takes precedence.</dd>
|
||||||
|
<dt class="It-tag"> </dt>
|
||||||
|
<dd class="It-tag"> </dd>
|
||||||
|
<dt class="It-tag"><a class="selflink" href="#c"><b class="Fl" title="Fl" id="c">-c</b></a></dt>
|
||||||
|
<dd class="It-tag">Set the Game Boy Color–compatible flag:
|
||||||
|
<i class="Ad">0x143</i> = 0x80. If both this and the
|
||||||
|
<b class="Fl" title="Fl">-C</b> flag are set,
|
||||||
|
<b class="Fl" title="Fl">-C</b> takes precedence.</dd>
|
||||||
|
<dt class="It-tag"> </dt>
|
||||||
|
<dd class="It-tag"> </dd>
|
||||||
|
<dt class="It-tag"><a class="selflink" href="#f"><b class="Fl" title="Fl" id="f">-f</b></a>
|
||||||
|
<var class="Ar" title="Ar">fix_spec</var></dt>
|
||||||
|
<dd class="It-tag">Fix certain header values that the Game Boy checks for
|
||||||
|
correctness. Alternatively, intentionally trash these values by writing
|
||||||
|
their binary inverse instead. <var class="Ar" title="Ar">fix_spec</var> is
|
||||||
|
a string containing any combination of the following characters:
|
||||||
|
<div class="Pp"></div>
|
||||||
|
<dl class="Bl-tag Bl-compact" style="margin-left: 5.40ex;">
|
||||||
|
<dt class="It-tag" style="margin-left: -5.40ex;"><a class="selflink" href="#l"><b class="Cm" title="Cm" id="l">l</b></a></dt>
|
||||||
|
<dd class="It-tag">Fix the Nintendo logo
|
||||||
|
(<i class="Ad">0x104</i>–<i class="Ad">0x133</i>).</dd>
|
||||||
|
<dt class="It-tag" style="margin-left: -5.40ex;"><a class="selflink" href="#L"><b class="Cm" title="Cm" id="L">L</b></a></dt>
|
||||||
|
<dd class="It-tag">Trash the Nintendo logo.</dd>
|
||||||
|
<dt class="It-tag" style="margin-left: -5.40ex;"><a class="selflink" href="#h"><b class="Cm" title="Cm" id="h">h</b></a></dt>
|
||||||
|
<dd class="It-tag">Fix the header checksum (<i class="Ad">0x14D</i>).</dd>
|
||||||
|
<dt class="It-tag" style="margin-left: -5.40ex;"><a class="selflink" href="#H"><b class="Cm" title="Cm" id="H">H</b></a></dt>
|
||||||
|
<dd class="It-tag">Trash the header checksum.</dd>
|
||||||
|
<dt class="It-tag" style="margin-left: -5.40ex;"><a class="selflink" href="#g"><b class="Cm" title="Cm" id="g">g</b></a></dt>
|
||||||
|
<dd class="It-tag">Fix the global checksum
|
||||||
|
(<i class="Ad">0x14E</i>–<i class="Ad">0x14F</i>).</dd>
|
||||||
|
<dt class="It-tag" style="margin-left: -5.40ex;"><a class="selflink" href="#G"><b class="Cm" title="Cm" id="G">G</b></a></dt>
|
||||||
|
<dd class="It-tag">Trash the global checksum.</dd>
|
||||||
|
</dl>
|
||||||
|
</dd>
|
||||||
|
<dt class="It-tag"> </dt>
|
||||||
|
<dd class="It-tag"> </dd>
|
||||||
|
<dt class="It-tag"><a class="selflink" href="#i"><b class="Fl" title="Fl" id="i">-i</b></a>
|
||||||
|
<var class="Ar" title="Ar">game_id</var></dt>
|
||||||
|
<dd class="It-tag">Set the game ID string
|
||||||
|
(<i class="Ad">0x13F</i>–<i class="Ad">0x142</i>) to a given string
|
||||||
|
of exactly 4 characters. If both this and the title are set, the game ID
|
||||||
|
will overwrite the overlapping portion of the title.</dd>
|
||||||
|
<dt class="It-tag"> </dt>
|
||||||
|
<dd class="It-tag"> </dd>
|
||||||
|
<dt class="It-tag"><a class="selflink" href="#j"><b class="Fl" title="Fl" id="j">-j</b></a></dt>
|
||||||
|
<dd class="It-tag">Set the non-Japanese region flag: <i class="Ad">0x14A</i> =
|
||||||
|
1.</dd>
|
||||||
|
<dt class="It-tag"> </dt>
|
||||||
|
<dd class="It-tag"> </dd>
|
||||||
|
<dt class="It-tag"><a class="selflink" href="#k"><b class="Fl" title="Fl" id="k">-k</b></a>
|
||||||
|
<var class="Ar" title="Ar">licensee_str</var></dt>
|
||||||
|
<dd class="It-tag">Set the new licensee string
|
||||||
|
(<i class="Ad">0x144</i>–<i class="Ad">0x145</i>) to a given
|
||||||
|
string, truncated to at most two characters.</dd>
|
||||||
|
<dt class="It-tag"> </dt>
|
||||||
|
<dd class="It-tag"> </dd>
|
||||||
|
<dt class="It-tag"><a class="selflink" href="#l"><b class="Fl" title="Fl" id="l">-l</b></a>
|
||||||
|
<var class="Ar" title="Ar">licensee_id</var></dt>
|
||||||
|
<dd class="It-tag">Set the old licensee code, <i class="Ad">0x14B</i>, to a
|
||||||
|
given value from 0 to 0xFF. This value is deprecated and should be set to
|
||||||
|
0x33 in all new software.</dd>
|
||||||
|
<dt class="It-tag"> </dt>
|
||||||
|
<dd class="It-tag"> </dd>
|
||||||
|
<dt class="It-tag"><a class="selflink" href="#m"><b class="Fl" title="Fl" id="m">-m</b></a>
|
||||||
|
<var class="Ar" title="Ar">mbc_type</var></dt>
|
||||||
|
<dd class="It-tag">Set the MBC type, <i class="Ad">0x147</i>, to a given value
|
||||||
|
from 0 to 0xFF.</dd>
|
||||||
|
<dt class="It-tag"> </dt>
|
||||||
|
<dd class="It-tag"> </dd>
|
||||||
|
<dt class="It-tag"><a class="selflink" href="#n"><b class="Fl" title="Fl" id="n">-n</b></a>
|
||||||
|
<var class="Ar" title="Ar">rom_version</var></dt>
|
||||||
|
<dd class="It-tag">Set the ROM version, <i class="Ad">0x14C</i>, to a given
|
||||||
|
value from 0 to 0xFF.</dd>
|
||||||
|
<dt class="It-tag"> </dt>
|
||||||
|
<dd class="It-tag"> </dd>
|
||||||
|
<dt class="It-tag"><a class="selflink" href="#p"><b class="Fl" title="Fl" id="p">-p</b></a>
|
||||||
|
<var class="Ar" title="Ar">pad_value</var></dt>
|
||||||
|
<dd class="It-tag">Pad the image to a valid size with a given pad value from 0
|
||||||
|
to 0xFF. <b class="Nm" title="Nm">rgbfix</b> will automatically pick a
|
||||||
|
size from 32KiB, 64KiB, 128KiB, ..., 8192KiB and give a warning
|
||||||
|
thereafter. The cartridge size byte (<i class="Ad">0x148</i>) will be
|
||||||
|
changed to reflect this new size.</dd>
|
||||||
|
<dt class="It-tag"> </dt>
|
||||||
|
<dd class="It-tag"> </dd>
|
||||||
|
<dt class="It-tag"><a class="selflink" href="#r"><b class="Fl" title="Fl" id="r">-r</b></a>
|
||||||
|
<var class="Ar" title="Ar">ram_size</var></dt>
|
||||||
|
<dd class="It-tag">Set the RAM size, <i class="Ad">0x149</i>, to a given value
|
||||||
|
from 0 to 0xFF.</dd>
|
||||||
|
<dt class="It-tag"> </dt>
|
||||||
|
<dd class="It-tag"> </dd>
|
||||||
|
<dt class="It-tag"><a class="selflink" href="#s"><b class="Fl" title="Fl" id="s">-s</b></a></dt>
|
||||||
|
<dd class="It-tag">Set the SGB flag: <i class="Ad">0x146</i> = 3.</dd>
|
||||||
|
<dt class="It-tag"> </dt>
|
||||||
|
<dd class="It-tag"> </dd>
|
||||||
|
<dt class="It-tag"><a class="selflink" href="#t"><b class="Fl" title="Fl" id="t">-t</b></a>
|
||||||
|
<var class="Ar" title="Ar">title</var></dt>
|
||||||
|
<dd class="It-tag">Set the title string
|
||||||
|
(<i class="Ad">0x134</i>–<i class="Ad">0x143</i>) to a given
|
||||||
|
string, truncated to at most 16 characters. It is recommended to use 15
|
||||||
|
characters instead, to avoid clashing with the CGB flag
|
||||||
|
(<b class="Fl" title="Fl">-c</b> or <b class="Fl" title="Fl">-C</b>). If
|
||||||
|
both this and the game ID are set, the game ID will overwrite the
|
||||||
|
overlapping portion of the title.</dd>
|
||||||
|
<dt class="It-tag"> </dt>
|
||||||
|
<dd class="It-tag"> </dd>
|
||||||
|
<dt class="It-tag"><a class="selflink" href="#V"><b class="Fl" title="Fl" id="V">-V</b></a></dt>
|
||||||
|
<dd class="It-tag">Print the version of the program and exit.</dd>
|
||||||
|
<dt class="It-tag"> </dt>
|
||||||
|
<dd class="It-tag"> </dd>
|
||||||
|
<dt class="It-tag"><a class="selflink" href="#v"><b class="Fl" title="Fl" id="v">-v</b></a></dt>
|
||||||
|
<dd class="It-tag">Equivalent to <b class="Fl" title="Fl">-f</b>
|
||||||
|
<b class="Cm" title="Cm">lhg</b>.</dd>
|
||||||
|
</dl>
|
||||||
|
<h1 class="Sh" title="Sh" id="EXAMPLES"><a class="selflink" href="#EXAMPLES">EXAMPLES</a></h1>
|
||||||
|
Most values in the ROM header are only cosmetic. The bare minimum requirements
|
||||||
|
for a workable image are checksums, the Nintendo logo, and (if needed) the
|
||||||
|
CGB/SGB flags. It is a good idea to pad the image to a valid size as well
|
||||||
|
(“valid” meaning a multiple of 32KiB).
|
||||||
|
<div class="Pp"></div>
|
||||||
|
The following will make a plain, no-color Game Boy game without checking for a
|
||||||
|
valid size:
|
||||||
|
<div class="Pp"></div>
|
||||||
|
<div class="D1">$ rgbfix -v foo.gb</div>
|
||||||
|
<div class="Pp"></div>
|
||||||
|
The following will make a SGB-enabled, color-enabled game with a title of
|
||||||
|
“foobar”, and pad it to a multiple of 32KiB. (The Game Boy
|
||||||
|
itself does not use the title, but some emulators or ROM managers might.)
|
||||||
|
<div class="Pp"></div>
|
||||||
|
<div class="D1">$ rgbfix -vcs -l 0x33 -p 0 -t foobar baz.gb</div>
|
||||||
|
<div class="Pp"></div>
|
||||||
|
The following will duplicate the header (sans global checksum) of the game
|
||||||
|
“Survival Kids”:
|
||||||
|
<div class="Pp"></div>
|
||||||
|
<div class="D1">$ rgbfix -cjsv -k A4 -l 0x33 -m 0x1B -p 0xFF -r 3 -t
|
||||||
|
SURVIVALKIDAVKE SurvivalKids.gbc</div>
|
||||||
|
<h1 class="Sh" title="Sh" id="SEE_ALSO"><a class="selflink" href="#SEE_ALSO">SEE
|
||||||
|
ALSO</a></h1>
|
||||||
|
<a class="Xr" title="Xr">rgbasm(1)</a>, <a class="Xr" title="Xr">rgblink(1)</a>,
|
||||||
|
<a class="Xr" title="Xr">rgbds(7)</a>
|
||||||
|
<h1 class="Sh" title="Sh" id="HISTORY"><a class="selflink" href="#HISTORY">HISTORY</a></h1>
|
||||||
|
<b class="Nm" title="Nm">rgbfix</b> was originally released by Carsten
|
||||||
|
Sørensen as a standalone program called gbfix, and was later packaged
|
||||||
|
in RGBDS by Justin Lloyd. It is now maintained by a number of contributors at
|
||||||
|
<a class="Lk" title="Lk" href="https://github.com/rednex/rgbds">https://github.com/rednex/rgbds</a>.</div>
|
||||||
|
<table class="foot">
|
||||||
|
<tr>
|
||||||
|
<td class="foot-date">March 11, 2018</td>
|
||||||
|
<td class="foot-os">RGBDS Manual</td>
|
||||||
|
</tr>
|
||||||
|
</table>
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
175
docs/rgbgfx.1.html
Normal file
175
docs/rgbgfx.1.html
Normal file
@@ -0,0 +1,175 @@
|
|||||||
|
<!DOCTYPE html>
|
||||||
|
<html>
|
||||||
|
<head>
|
||||||
|
<meta charset="utf-8"/>
|
||||||
|
<style>
|
||||||
|
table.head, table.foot { width: 100%; }
|
||||||
|
td.head-rtitle, td.foot-os { text-align: right; }
|
||||||
|
td.head-vol { text-align: center; }
|
||||||
|
div.Pp { margin: 1ex 0ex; }
|
||||||
|
</style>
|
||||||
|
<link rel="stylesheet" href="mandoc.css" type="text/css" media="all"/>
|
||||||
|
<title>RGBGFX(1)</title>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<table class="head">
|
||||||
|
<tr>
|
||||||
|
<td class="head-ltitle">RGBGFX(1)</td>
|
||||||
|
<td class="head-vol">General Commands Manual</td>
|
||||||
|
<td class="head-rtitle">RGBGFX(1)</td>
|
||||||
|
</tr>
|
||||||
|
</table>
|
||||||
|
<div class="manual-text">
|
||||||
|
<h1 class="Sh" title="Sh" id="NAME"><a class="selflink" href="#NAME">NAME</a></h1>
|
||||||
|
<b class="Nm" title="Nm">rgbgfx</b> — <span class="Nd" title="Nd">Game
|
||||||
|
Boy graphics converter</span>
|
||||||
|
<h1 class="Sh" title="Sh" id="SYNOPSIS"><a class="selflink" href="#SYNOPSIS">SYNOPSIS</a></h1>
|
||||||
|
<table class="Nm">
|
||||||
|
<tr>
|
||||||
|
<td><b class="Nm" title="Nm">rgbgfx</b></td>
|
||||||
|
<td>[<span class="Op"><b class="Fl" title="Fl">-DfFhPTVv</b></span>]
|
||||||
|
[<span class="Op"><b class="Fl" title="Fl">-o</b>
|
||||||
|
<var class="Ar" title="Ar">outfile</var></span>]
|
||||||
|
[<span class="Op"><b class="Fl" title="Fl">-d</b>
|
||||||
|
<var class="Ar" title="Ar">depth</var></span>]
|
||||||
|
[<span class="Op"><b class="Fl" title="Fl">-p</b>
|
||||||
|
<var class="Ar" title="Ar">palfile</var></span>]
|
||||||
|
[<span class="Op"><b class="Fl" title="Fl">-t</b>
|
||||||
|
<var class="Ar" title="Ar">mapfile</var></span>]
|
||||||
|
[<span class="Op"><b class="Fl" title="Fl">-x</b>
|
||||||
|
<var class="Ar" title="Ar">tiles</var></span>]
|
||||||
|
<var class="Ar" title="Ar">file</var></td>
|
||||||
|
</tr>
|
||||||
|
</table>
|
||||||
|
<h1 class="Sh" title="Sh" id="DESCRIPTION"><a class="selflink" href="#DESCRIPTION">DESCRIPTION</a></h1>
|
||||||
|
The <b class="Nm" title="Nm">rgbgfx</b> program converts PNG images into the
|
||||||
|
Nintendo Game Boy's planar tile format.
|
||||||
|
<div style="height: 1.00em;"> </div>
|
||||||
|
The resulting colors and their palette indices are determined differently
|
||||||
|
depending on the input PNG file:
|
||||||
|
<ul class="Bl-dash">
|
||||||
|
<li class="It-dash">If the file has an embedded palette, that palette's color
|
||||||
|
and order are used.</li>
|
||||||
|
<li class="It-dash">If not, and the image only contains shades of gray, rgbgfx
|
||||||
|
maps them to the indices appropriate for each shade. Any undetermined
|
||||||
|
indices are set to respective default shades of gray. For example: if the
|
||||||
|
bit depth is 2 and the image contains light gray and black, they become
|
||||||
|
the second and fourth colors - and the first and third colors get set to
|
||||||
|
default white and dark gray. If the image has multiple shades that map to
|
||||||
|
the same index, the palette is instead determined as if the image had
|
||||||
|
color.</li>
|
||||||
|
<li class="It-dash">If the image has color (or the grayscale method failed),
|
||||||
|
the colors are sorted from lightest to darkest.</li>
|
||||||
|
</ul>
|
||||||
|
<div style="height: 1.00em;"> </div>
|
||||||
|
The input image may not contain more colors than the selected bit depth allows.
|
||||||
|
Transparent pixels are set to palette index 0.
|
||||||
|
<h1 class="Sh" title="Sh" id="ARGUMENTS"><a class="selflink" href="#ARGUMENTS">ARGUMENTS</a></h1>
|
||||||
|
<dl class="Bl-tag">
|
||||||
|
<dt class="It-tag"> </dt>
|
||||||
|
<dd class="It-tag"> </dd>
|
||||||
|
<dt class="It-tag"><a class="selflink" href="#D"><b class="Fl" title="Fl" id="D">-D</b></a></dt>
|
||||||
|
<dd class="It-tag">Debug features are enabled.</dd>
|
||||||
|
<dt class="It-tag"> </dt>
|
||||||
|
<dd class="It-tag"> </dd>
|
||||||
|
<dt class="It-tag"><a class="selflink" href="#f"><b class="Fl" title="Fl" id="f">-f</b></a></dt>
|
||||||
|
<dd class="It-tag">Fix the input PNG file to be a correctly indexed
|
||||||
|
image.</dd>
|
||||||
|
<dt class="It-tag"> </dt>
|
||||||
|
<dd class="It-tag"> </dd>
|
||||||
|
<dt class="It-tag"><a class="selflink" href="#F"><b class="Fl" title="Fl" id="F">-F</b></a></dt>
|
||||||
|
<dd class="It-tag">Same as <b class="Fl" title="Fl">-f</b>, but additionally,
|
||||||
|
the supplied command line parameters are saved within the PNG and will be
|
||||||
|
loaded and automatically used next time.</dd>
|
||||||
|
<dt class="It-tag"> </dt>
|
||||||
|
<dd class="It-tag"> </dd>
|
||||||
|
<dt class="It-tag"><a class="selflink" href="#d"><b class="Fl" title="Fl" id="d">-d</b></a>
|
||||||
|
<var class="Ar" title="Ar">depth</var></dt>
|
||||||
|
<dd class="It-tag">The bit depth of the output image (either 1 or 2). By
|
||||||
|
default, the bit depth is 2 (two bits per pixel).</dd>
|
||||||
|
<dt class="It-tag"> </dt>
|
||||||
|
<dd class="It-tag"> </dd>
|
||||||
|
<dt class="It-tag"><a class="selflink" href="#h"><b class="Fl" title="Fl" id="h">-h</b></a></dt>
|
||||||
|
<dd class="It-tag">Lay out tiles horizontally rather than vertically.</dd>
|
||||||
|
<dt class="It-tag"> </dt>
|
||||||
|
<dd class="It-tag"> </dd>
|
||||||
|
<dt class="It-tag"><a class="selflink" href="#o"><b class="Fl" title="Fl" id="o">-o</b></a>
|
||||||
|
<var class="Ar" title="Ar">outfile</var></dt>
|
||||||
|
<dd class="It-tag">The name of the output file.</dd>
|
||||||
|
<dt class="It-tag"> </dt>
|
||||||
|
<dd class="It-tag"> </dd>
|
||||||
|
<dt class="It-tag"><a class="selflink" href="#p"><b class="Fl" title="Fl" id="p">-p</b></a>
|
||||||
|
<var class="Ar" title="Ar">palfile</var></dt>
|
||||||
|
<dd class="It-tag">Output the image's palette in standard GBC palette format -
|
||||||
|
bytes (8 bytes for two bits per pixel, 4 bytes for one bit per pixel)
|
||||||
|
containing the RGB15 values in little-endian byte order. If the palette
|
||||||
|
contains too few colors, the remaining entries are set to black.</dd>
|
||||||
|
<dt class="It-tag"> </dt>
|
||||||
|
<dd class="It-tag"> </dd>
|
||||||
|
<dt class="It-tag"><a class="selflink" href="#P"><b class="Fl" title="Fl" id="P">-P</b></a></dt>
|
||||||
|
<dd class="It-tag">Same as <b class="Fl" title="Fl">-p</b>, but the palette
|
||||||
|
file output name is made by taking the input PNG file's filename, removing
|
||||||
|
the file extension, and appending <i class="Pa" title="Pa">.pal</i>.</dd>
|
||||||
|
<dt class="It-tag"> </dt>
|
||||||
|
<dd class="It-tag"> </dd>
|
||||||
|
<dt class="It-tag"><a class="selflink" href="#t"><b class="Fl" title="Fl" id="t">-t</b></a>
|
||||||
|
<var class="Ar" title="Ar">mapfile</var></dt>
|
||||||
|
<dd class="It-tag">If any tiles are the same, don't place the repeat tiles in
|
||||||
|
the output file, and make a tilemap file.</dd>
|
||||||
|
<dt class="It-tag"> </dt>
|
||||||
|
<dd class="It-tag"> </dd>
|
||||||
|
<dt class="It-tag"><a class="selflink" href="#T"><b class="Fl" title="Fl" id="T">-T</b></a></dt>
|
||||||
|
<dd class="It-tag">Same as <b class="Fl" title="Fl">-t</b>, but the tilemap
|
||||||
|
file output name is made by taking the input filename, removing the file
|
||||||
|
extension, and appending <i class="Pa" title="Pa">.tilemap</i>.</dd>
|
||||||
|
<dt class="It-tag"> </dt>
|
||||||
|
<dd class="It-tag"> </dd>
|
||||||
|
<dt class="It-tag"><a class="selflink" href="#u"><b class="Fl" title="Fl" id="u">-u</b></a></dt>
|
||||||
|
<dd class="It-tag">Truncate repeated tiles. Useful with tilemaps.</dd>
|
||||||
|
<dt class="It-tag"> </dt>
|
||||||
|
<dd class="It-tag"> </dd>
|
||||||
|
<dt class="It-tag"><a class="selflink" href="#V"><b class="Fl" title="Fl" id="V">-V</b></a></dt>
|
||||||
|
<dd class="It-tag">Print the version of the program and exit.</dd>
|
||||||
|
<dt class="It-tag"> </dt>
|
||||||
|
<dd class="It-tag"> </dd>
|
||||||
|
<dt class="It-tag"><a class="selflink" href="#v"><b class="Fl" title="Fl" id="v">-v</b></a></dt>
|
||||||
|
<dd class="It-tag">Verbose. Print errors when the command line parameters and
|
||||||
|
the parameters in the PNG file don't match.</dd>
|
||||||
|
<dt class="It-tag"> </dt>
|
||||||
|
<dd class="It-tag"> </dd>
|
||||||
|
<dt class="It-tag"><a class="selflink" href="#x"><b class="Fl" title="Fl" id="x">-x</b></a>
|
||||||
|
<var class="Ar" title="Ar">tiles</var></dt>
|
||||||
|
<dd class="It-tag">Trim the end of the output file by this many tiles.</dd>
|
||||||
|
</dl>
|
||||||
|
<h1 class="Sh" title="Sh" id="EXAMPLES"><a class="selflink" href="#EXAMPLES">EXAMPLES</a></h1>
|
||||||
|
The following will take a PNG file with a bit depth of 1, 2, or 8, and output
|
||||||
|
planar 2bpp data:
|
||||||
|
<div class="Pp"></div>
|
||||||
|
<div class="D1">$ rgbgfx -o out.2bpp in.png</div>
|
||||||
|
<div class="Pp"></div>
|
||||||
|
The following creates a planar 2bpp file with only unique tiles, and its tilemap
|
||||||
|
<i class="Pa" title="Pa">out.tilemap</i>:
|
||||||
|
<div class="Pp"></div>
|
||||||
|
<div class="D1">$ rgbgfx -T -u -o out.2bpp in.png</div>
|
||||||
|
<div class="Pp"></div>
|
||||||
|
The following will do nothing:
|
||||||
|
<div class="Pp"></div>
|
||||||
|
<div class="D1">$ rgbgfx in.png</div>
|
||||||
|
<h1 class="Sh" title="Sh" id="SEE_ALSO"><a class="selflink" href="#SEE_ALSO">SEE
|
||||||
|
ALSO</a></h1>
|
||||||
|
<a class="Xr" title="Xr">rgbds(7)</a>, <a class="Xr" title="Xr">rgbasm(1)</a>,
|
||||||
|
<a class="Xr" title="Xr">rgblink(1)</a>,
|
||||||
|
<a class="Xr" title="Xr">rgbfix(1)</a>, <a class="Xr" title="Xr">gbz80(7)</a>
|
||||||
|
<h1 class="Sh" title="Sh" id="HISTORY"><a class="selflink" href="#HISTORY">HISTORY</a></h1>
|
||||||
|
<b class="Nm" title="Nm">rgbgfx</b> was created by
|
||||||
|
<span class="An" title="An">stag019</span> to be included in RGBDS. It is now
|
||||||
|
maintained by a number of contributors at
|
||||||
|
<a class="Lk" title="Lk" href="https://github.com/rednex/rgbds">https://github.com/rednex/rgbds</a>.</div>
|
||||||
|
<table class="foot">
|
||||||
|
<tr>
|
||||||
|
<td class="foot-date">January 26, 2018</td>
|
||||||
|
<td class="foot-os">RGBDS Manual</td>
|
||||||
|
</tr>
|
||||||
|
</table>
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
161
docs/rgblink.1.html
Normal file
161
docs/rgblink.1.html
Normal file
@@ -0,0 +1,161 @@
|
|||||||
|
<!DOCTYPE html>
|
||||||
|
<html>
|
||||||
|
<head>
|
||||||
|
<meta charset="utf-8"/>
|
||||||
|
<style>
|
||||||
|
table.head, table.foot { width: 100%; }
|
||||||
|
td.head-rtitle, td.foot-os { text-align: right; }
|
||||||
|
td.head-vol { text-align: center; }
|
||||||
|
div.Pp { margin: 1ex 0ex; }
|
||||||
|
</style>
|
||||||
|
<link rel="stylesheet" href="mandoc.css" type="text/css" media="all"/>
|
||||||
|
<title>RGBLINK(1)</title>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<table class="head">
|
||||||
|
<tr>
|
||||||
|
<td class="head-ltitle">RGBLINK(1)</td>
|
||||||
|
<td class="head-vol">General Commands Manual</td>
|
||||||
|
<td class="head-rtitle">RGBLINK(1)</td>
|
||||||
|
</tr>
|
||||||
|
</table>
|
||||||
|
<div class="manual-text">
|
||||||
|
<h1 class="Sh" title="Sh" id="NAME"><a class="selflink" href="#NAME">NAME</a></h1>
|
||||||
|
<b class="Nm" title="Nm">rgblink</b> — <span class="Nd" title="Nd">Game
|
||||||
|
Boy linker</span>
|
||||||
|
<h1 class="Sh" title="Sh" id="SYNOPSIS"><a class="selflink" href="#SYNOPSIS">SYNOPSIS</a></h1>
|
||||||
|
<table class="Nm">
|
||||||
|
<tr>
|
||||||
|
<td><b class="Nm" title="Nm">rgblink</b></td>
|
||||||
|
<td>[<span class="Op"><b class="Fl" title="Fl">-dtVw</b></span>]
|
||||||
|
[<span class="Op"><b class="Fl" title="Fl">-m</b>
|
||||||
|
<var class="Ar" title="Ar">mapfile</var></span>]
|
||||||
|
[<span class="Op"><b class="Fl" title="Fl">-n</b>
|
||||||
|
<var class="Ar" title="Ar">symfile</var></span>]
|
||||||
|
[<span class="Op"><b class="Fl" title="Fl">-O</b>
|
||||||
|
<var class="Ar" title="Ar">overlayfile</var></span>]
|
||||||
|
[<span class="Op"><b class="Fl" title="Fl">-o</b>
|
||||||
|
<var class="Ar" title="Ar">outfile</var></span>]
|
||||||
|
[<span class="Op"><b class="Fl" title="Fl">-p</b>
|
||||||
|
<var class="Ar" title="Ar">pad_value</var></span>]
|
||||||
|
[<span class="Op"><b class="Fl" title="Fl">-s</b>
|
||||||
|
<var class="Ar" title="Ar">symbol</var></span>]
|
||||||
|
[<span class="Op"><b class="Fl" title="Fl">-l</b>
|
||||||
|
<var class="Ar" title="Ar">linkerscript</var></span>]
|
||||||
|
<var class="Ar" title="Ar">file ...</var></td>
|
||||||
|
</tr>
|
||||||
|
</table>
|
||||||
|
<h1 class="Sh" title="Sh" id="DESCRIPTION"><a class="selflink" href="#DESCRIPTION">DESCRIPTION</a></h1>
|
||||||
|
The <b class="Nm" title="Nm">rgblink</b> program links objects created by
|
||||||
|
<a class="Xr" title="Xr">rgbasm(1)</a> into a single Game Boy ROM file.
|
||||||
|
<div class="Pp"></div>
|
||||||
|
By default, ROM0 sections created by the assembler are placed in the 16KiB bank
|
||||||
|
0, and ROMX sections are placed in any bank except bank 0. If your ROM will
|
||||||
|
only be 32KiB, you can use the <b class="Fl" title="Fl">-t</b> option to
|
||||||
|
override this.
|
||||||
|
<div class="Pp"></div>
|
||||||
|
Similarly, WRAM0 sections are placed in the first 4KiB of WRAM bank 0 and WRAMX
|
||||||
|
sections are placed in any bank except bank 0. If your ROM doesn't use banked
|
||||||
|
WRAM you can use option <b class="Fl" title="Fl">-w</b> option to override
|
||||||
|
this.
|
||||||
|
<div class="Pp"></div>
|
||||||
|
Also, if your ROM is designed for DMG, you can make sure that you don't use any
|
||||||
|
prohibited section by using the option <b class="Fl" title="Fl">-d</b>, which
|
||||||
|
implies <b class="Fl" title="Fl">-w</b> but also prohibits the use of VRAM
|
||||||
|
bank 1.
|
||||||
|
<div class="Pp"></div>
|
||||||
|
The arguments are as follows:
|
||||||
|
<dl class="Bl-tag">
|
||||||
|
<dt class="It-tag"> </dt>
|
||||||
|
<dd class="It-tag"> </dd>
|
||||||
|
<dt class="It-tag"><a class="selflink" href="#m"><b class="Fl" title="Fl" id="m">-m</b></a>
|
||||||
|
<var class="Ar" title="Ar">mapfile</var></dt>
|
||||||
|
<dd class="It-tag">Write a mapfile to the given filename.</dd>
|
||||||
|
<dt class="It-tag"> </dt>
|
||||||
|
<dd class="It-tag"> </dd>
|
||||||
|
<dt class="It-tag"><a class="selflink" href="#n"><b class="Fl" title="Fl" id="n">-n</b></a>
|
||||||
|
<var class="Ar" title="Ar">symfile</var></dt>
|
||||||
|
<dd class="It-tag">Write a symbol file to the given filename.</dd>
|
||||||
|
<dt class="It-tag"> </dt>
|
||||||
|
<dd class="It-tag"> </dd>
|
||||||
|
<dt class="It-tag"><a class="selflink" href="#O"><b class="Fl" title="Fl" id="O">-O</b></a>
|
||||||
|
<var class="Ar" title="Ar">overlayfile</var></dt>
|
||||||
|
<dd class="It-tag">The ROM image to overlay sections over. When an overlay ROM
|
||||||
|
is provided, all sections must be fixed. This may be used to patch an
|
||||||
|
existing binary.</dd>
|
||||||
|
<dt class="It-tag"> </dt>
|
||||||
|
<dd class="It-tag"> </dd>
|
||||||
|
<dt class="It-tag"><a class="selflink" href="#o"><b class="Fl" title="Fl" id="o">-o</b></a>
|
||||||
|
<var class="Ar" title="Ar">outfile</var></dt>
|
||||||
|
<dd class="It-tag">Write ROM image to the given filename.</dd>
|
||||||
|
<dt class="It-tag"> </dt>
|
||||||
|
<dd class="It-tag"> </dd>
|
||||||
|
<dt class="It-tag"><a class="selflink" href="#p"><b class="Fl" title="Fl" id="p">-p</b></a>
|
||||||
|
<var class="Ar" title="Ar">pad_value</var></dt>
|
||||||
|
<dd class="It-tag">When padding an image, pad with this value. The default is
|
||||||
|
0x00.</dd>
|
||||||
|
<dt class="It-tag"> </dt>
|
||||||
|
<dd class="It-tag"> </dd>
|
||||||
|
<dt class="It-tag"><a class="selflink" href="#s"><b class="Fl" title="Fl" id="s">-s</b></a>
|
||||||
|
<var class="Ar" title="Ar">symbol</var></dt>
|
||||||
|
<dd class="It-tag">???</dd>
|
||||||
|
<dt class="It-tag"> </dt>
|
||||||
|
<dd class="It-tag"> </dd>
|
||||||
|
<dt class="It-tag"><a class="selflink" href="#w"><b class="Fl" title="Fl" id="w">-w</b></a></dt>
|
||||||
|
<dd class="It-tag">Expand the WRAM0 section size from 4KiB to the full 8KiB
|
||||||
|
assigned to WRAM and prohibit the use of WRAMX sections.</dd>
|
||||||
|
<dt class="It-tag"> </dt>
|
||||||
|
<dd class="It-tag"> </dd>
|
||||||
|
<dt class="It-tag"><a class="selflink" href="#d"><b class="Fl" title="Fl" id="d">-d</b></a></dt>
|
||||||
|
<dd class="It-tag">Enable DMG mode. Prohibit the use of sections that doesn't
|
||||||
|
exist on a DMG, such as WRAMX and VRAM bank 1. This option automatically
|
||||||
|
enables <b class="Fl" title="Fl">-w</b>.</dd>
|
||||||
|
<dt class="It-tag"> </dt>
|
||||||
|
<dd class="It-tag"> </dd>
|
||||||
|
<dt class="It-tag"><a class="selflink" href="#t"><b class="Fl" title="Fl" id="t">-t</b></a></dt>
|
||||||
|
<dd class="It-tag">Expand the ROM0 section size from 16KiB to the full 32KiB
|
||||||
|
assigned to ROM and prohibit the use of ROMX sections. Useful for ROMs
|
||||||
|
that fit in 32 KiB.</dd>
|
||||||
|
<dt class="It-tag"> </dt>
|
||||||
|
<dd class="It-tag"> </dd>
|
||||||
|
<dt class="It-tag"><a class="selflink" href="#l"><b class="Fl" title="Fl" id="l">-l</b></a>
|
||||||
|
<var class="Ar" title="Ar">linkerscript</var></dt>
|
||||||
|
<dd class="It-tag">Specify a linkerscript file that tells the linker how
|
||||||
|
sections must be placed in the ROM. This file has priority over the
|
||||||
|
attributes assigned in the source code, but they have to be consistent.
|
||||||
|
See <a class="Xr" title="Xr">rgblink(5)</a> for more information about its
|
||||||
|
format.</dd>
|
||||||
|
<dt class="It-tag"> </dt>
|
||||||
|
<dd class="It-tag"> </dd>
|
||||||
|
<dt class="It-tag"><a class="selflink" href="#V"><b class="Fl" title="Fl" id="V">-V</b></a></dt>
|
||||||
|
<dd class="It-tag">Print the version of the program and exit.</dd>
|
||||||
|
</dl>
|
||||||
|
<h1 class="Sh" title="Sh" id="EXAMPLES"><a class="selflink" href="#EXAMPLES">EXAMPLES</a></h1>
|
||||||
|
All you need for a basic ROM is an object file, which can be made into a ROM
|
||||||
|
image like so:
|
||||||
|
<div class="Pp"></div>
|
||||||
|
<div class="D1">$ rgblink -o bar.gb foo.o</div>
|
||||||
|
<div class="Pp"></div>
|
||||||
|
The resulting bar.gb will not have correct checksums (unless you put them in the
|
||||||
|
assembly source). You should use <a class="Xr" title="Xr">rgbfix(1)</a> to fix
|
||||||
|
these so that the program will actually run in a Game Boy:
|
||||||
|
<div class="Pp"></div>
|
||||||
|
<div class="D1">$ rgbfix -v bar.gb</div>
|
||||||
|
<h1 class="Sh" title="Sh" id="SEE_ALSO"><a class="selflink" href="#SEE_ALSO">SEE
|
||||||
|
ALSO</a></h1>
|
||||||
|
<a class="Xr" title="Xr">rgbasm(1)</a>, <a class="Xr" title="Xr">rgblink(5)</a>,
|
||||||
|
<a class="Xr" title="Xr">rgbfix(1)</a>, <a class="Xr" title="Xr">rgbds(5)</a>,
|
||||||
|
<a class="Xr" title="Xr">rgbds(7)</a>
|
||||||
|
<h1 class="Sh" title="Sh" id="HISTORY"><a class="selflink" href="#HISTORY">HISTORY</a></h1>
|
||||||
|
<b class="Nm" title="Nm">rgblink</b> was originally written by Carsten
|
||||||
|
Sørensen as part of the ASMotor package, and was later packaged in
|
||||||
|
RGBDS by Justin Lloyd. It is now maintained by a number of contributors at
|
||||||
|
<a class="Lk" title="Lk" href="https://github.com/rednex/rgbds">https://github.com/rednex/rgbds</a>.</div>
|
||||||
|
<table class="foot">
|
||||||
|
<tr>
|
||||||
|
<td class="foot-date">January 26, 2018</td>
|
||||||
|
<td class="foot-os">RGBDS Manual</td>
|
||||||
|
</tr>
|
||||||
|
</table>
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
105
docs/rgblink.5.html
Normal file
105
docs/rgblink.5.html
Normal file
@@ -0,0 +1,105 @@
|
|||||||
|
<!DOCTYPE html>
|
||||||
|
<html>
|
||||||
|
<head>
|
||||||
|
<meta charset="utf-8"/>
|
||||||
|
<style>
|
||||||
|
table.head, table.foot { width: 100%; }
|
||||||
|
td.head-rtitle, td.foot-os { text-align: right; }
|
||||||
|
td.head-vol { text-align: center; }
|
||||||
|
div.Pp { margin: 1ex 0ex; }
|
||||||
|
</style>
|
||||||
|
<link rel="stylesheet" href="mandoc.css" type="text/css" media="all"/>
|
||||||
|
<title>RGBLINK(5)</title>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<table class="head">
|
||||||
|
<tr>
|
||||||
|
<td class="head-ltitle">RGBLINK(5)</td>
|
||||||
|
<td class="head-vol">File Formats Manual</td>
|
||||||
|
<td class="head-rtitle">RGBLINK(5)</td>
|
||||||
|
</tr>
|
||||||
|
</table>
|
||||||
|
<div class="manual-text">
|
||||||
|
<h1 class="Sh" title="Sh" id="NAME"><a class="selflink" href="#NAME">NAME</a></h1>
|
||||||
|
<b class="Nm" title="Nm">rgblink</b> —
|
||||||
|
<span class="Nd" title="Nd">linkerscript file format</span>
|
||||||
|
<h1 class="Sh" title="Sh" id="DESCRIPTION"><a class="selflink" href="#DESCRIPTION">DESCRIPTION</a></h1>
|
||||||
|
The linkerscript is an external file that allows the user to specify the order
|
||||||
|
of sections without the need for doing so before assembling each object file.
|
||||||
|
<div class="Pp"></div>
|
||||||
|
The placement of sections specified in the linkerscript is done before the
|
||||||
|
sections whose placement is defined in the source code.
|
||||||
|
<div class="Pp"></div>
|
||||||
|
A linkerscript consists on a series of banks followed by a list of sections and,
|
||||||
|
optionally, commands. They can be lowercase or uppercase, it is ignored. Any
|
||||||
|
line can contain a comment starting with
|
||||||
|
‘<code class="Li">;</code>’ that ends at the end of the line:
|
||||||
|
<div class="Pp"></div>
|
||||||
|
<div class="Bd" style="margin-left: 5.00ex;">
|
||||||
|
<pre class="Li">
|
||||||
|
ROMX $F ; This is a comment
|
||||||
|
"Functions to read array"
|
||||||
|
ALIGN 8
|
||||||
|
"Array aligned to 256 bytes"
|
||||||
|
|
||||||
|
WRAMX 2
|
||||||
|
"Some variables"
|
||||||
|
</pre>
|
||||||
|
</div>
|
||||||
|
<div class="Pp"></div>
|
||||||
|
Numbers can be in decimal or hexadecimal format (the prefix is
|
||||||
|
‘<code class="Li">$</code>’). It is an error if any section name
|
||||||
|
or command are found before setting a bank.
|
||||||
|
<div class="Pp"></div>
|
||||||
|
Files can be included by using the <var class="Ar" title="Ar">INCLUDE</var>
|
||||||
|
keyword followed by a string with the path of the file that has to be
|
||||||
|
included.
|
||||||
|
<div class="Pp"></div>
|
||||||
|
The possible bank types are: <b class="Sy" title="Sy">ROM0</b>,
|
||||||
|
<b class="Sy" title="Sy">ROMX</b>, <b class="Sy" title="Sy">VRAM</b>,
|
||||||
|
<b class="Sy" title="Sy">WRAM0</b>, <b class="Sy" title="Sy">WRAMX</b>,
|
||||||
|
<b class="Sy" title="Sy">OAM</b> and <b class="Sy" title="Sy">HRAM</b>. Types
|
||||||
|
<b class="Sy" title="Sy">ROMX</b>, <b class="Sy" title="Sy">VRAM</b>,
|
||||||
|
<b class="Sy" title="Sy">WRAMX</b> and <b class="Sy" title="Sy">SRAM</b> are
|
||||||
|
banked, which means that it is needed to specify a bank after the type.
|
||||||
|
<div class="Pp"></div>
|
||||||
|
When a new bank statement is found, sections found after it will be placed right
|
||||||
|
from the beginning of that bank. If the linkerscript switches to a different
|
||||||
|
bank and then it comes back to the previous one it will continue from the last
|
||||||
|
address that was used.
|
||||||
|
<div class="Pp"></div>
|
||||||
|
The only two commands are <var class="Ar" title="Ar">ORG</var> and
|
||||||
|
<var class="Ar" title="Ar">ALIGN</var>:
|
||||||
|
<ul class="Bl-bullet">
|
||||||
|
<li class="It-bullet"><var class="Ar" title="Ar">ORG</var> sets the address in
|
||||||
|
which new sections will be placed. It can not be lower than the current
|
||||||
|
address.</li>
|
||||||
|
<li class="It-bullet"><var class="Ar" title="Ar">ALIGN</var> will increase the
|
||||||
|
address until it is aligned to the specified boundary (it tries to set to
|
||||||
|
0 the number of bits specified after the command:
|
||||||
|
<b class="Sy" title="Sy">ALIGN 8</b> will align to $100).</li>
|
||||||
|
</ul>
|
||||||
|
<div class="Pp"></div>
|
||||||
|
Note: The bank, alignment, address and type of sections can be specified both in
|
||||||
|
the source code and in the linkerscript. For a section to be able to be placed
|
||||||
|
with the linkerscript the bank must be left unassigned in the source code or
|
||||||
|
be the same as the one specified in the linkerscript. The address and
|
||||||
|
alignment musn't be set.
|
||||||
|
<h1 class="Sh" title="Sh" id="SEE_ALSO"><a class="selflink" href="#SEE_ALSO">SEE
|
||||||
|
ALSO</a></h1>
|
||||||
|
<a class="Xr" title="Xr">rgbasm(1)</a>, <a class="Xr" title="Xr">rgblink(1)</a>,
|
||||||
|
<a class="Xr" title="Xr">rgbfix(1)</a>, <a class="Xr" title="Xr">rgbds(5)</a>,
|
||||||
|
<a class="Xr" title="Xr">rgbds(7)</a>
|
||||||
|
<h1 class="Sh" title="Sh" id="HISTORY"><a class="selflink" href="#HISTORY">HISTORY</a></h1>
|
||||||
|
<b class="Nm" title="Nm">rgblink</b> was originally written by Carsten
|
||||||
|
Sørensen as part of the ASMotor package, and was later packaged in
|
||||||
|
RGBDS by Justin Lloyd. It is now maintained by a number of contributors at
|
||||||
|
<a class="Lk" title="Lk" href="https://github.com/rednex/rgbds">https://github.com/rednex/rgbds</a>.</div>
|
||||||
|
<table class="foot">
|
||||||
|
<tr>
|
||||||
|
<td class="foot-date">January 27, 2018</td>
|
||||||
|
<td class="foot-os">RGBDS Manual</td>
|
||||||
|
</tr>
|
||||||
|
</table>
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
@@ -1,9 +1,13 @@
|
|||||||
/*
|
/*
|
||||||
* asm.h
|
* This file is part of RGBDS.
|
||||||
*
|
*
|
||||||
|
* Copyright (c) 1997-2018, Carsten Sorensen and RGBDS contributors.
|
||||||
|
*
|
||||||
|
* SPDX-License-Identifier: MIT
|
||||||
|
*/
|
||||||
|
|
||||||
|
/*
|
||||||
* Contains some assembler-wide defines and externs
|
* Contains some assembler-wide defines and externs
|
||||||
*
|
|
||||||
* Copyright 1997 Carsten Sorensen
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#ifndef RGBDS_ASM_ASM_H
|
#ifndef RGBDS_ASM_ASM_H
|
||||||
|
|||||||
@@ -1,3 +1,11 @@
|
|||||||
|
/*
|
||||||
|
* This file is part of RGBDS.
|
||||||
|
*
|
||||||
|
* Copyright (c) 1997-2018, Carsten Sorensen and RGBDS contributors.
|
||||||
|
*
|
||||||
|
* SPDX-License-Identifier: MIT
|
||||||
|
*/
|
||||||
|
|
||||||
#ifndef RGBDS_ASM_CHARMAP_H
|
#ifndef RGBDS_ASM_CHARMAP_H
|
||||||
#define RGBDS_ASM_CHARMAP_H
|
#define RGBDS_ASM_CHARMAP_H
|
||||||
|
|
||||||
|
|||||||
@@ -1,9 +1,13 @@
|
|||||||
/* fstack.h
|
/*
|
||||||
|
* This file is part of RGBDS.
|
||||||
*
|
*
|
||||||
|
* Copyright (c) 1997-2018, Carsten Sorensen and RGBDS contributors.
|
||||||
|
*
|
||||||
|
* SPDX-License-Identifier: MIT
|
||||||
|
*/
|
||||||
|
|
||||||
|
/*
|
||||||
* Contains some assembler-wide defines and externs
|
* Contains some assembler-wide defines and externs
|
||||||
*
|
|
||||||
* Copyright 1997 Carsten Sorensen
|
|
||||||
*
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#ifndef RGBDS_ASM_FSTACK_H
|
#ifndef RGBDS_ASM_FSTACK_H
|
||||||
|
|||||||
@@ -1,3 +1,11 @@
|
|||||||
|
/*
|
||||||
|
* This file is part of RGBDS.
|
||||||
|
*
|
||||||
|
* Copyright (c) 1997-2018, Carsten Sorensen and RGBDS contributors.
|
||||||
|
*
|
||||||
|
* SPDX-License-Identifier: MIT
|
||||||
|
*/
|
||||||
|
|
||||||
#ifndef RGBDS_ASM_LEXER_H
|
#ifndef RGBDS_ASM_LEXER_H
|
||||||
#define RGBDS_ASM_LEXER_H
|
#define RGBDS_ASM_LEXER_H
|
||||||
|
|
||||||
|
|||||||
@@ -1,3 +1,11 @@
|
|||||||
|
/*
|
||||||
|
* This file is part of RGBDS.
|
||||||
|
*
|
||||||
|
* Copyright (c) 1997-2018, Carsten Sorensen and RGBDS contributors.
|
||||||
|
*
|
||||||
|
* SPDX-License-Identifier: MIT
|
||||||
|
*/
|
||||||
|
|
||||||
#ifndef RGBDS_ASM_LOCALASM_H
|
#ifndef RGBDS_ASM_LOCALASM_H
|
||||||
#define RGBDS_ASM_LOCALASM_H
|
#define RGBDS_ASM_LOCALASM_H
|
||||||
|
|
||||||
|
|||||||
@@ -1,18 +1,27 @@
|
|||||||
|
/*
|
||||||
|
* This file is part of RGBDS.
|
||||||
|
*
|
||||||
|
* Copyright (c) 1997-2018, Carsten Sorensen and RGBDS contributors.
|
||||||
|
*
|
||||||
|
* SPDX-License-Identifier: MIT
|
||||||
|
*/
|
||||||
|
|
||||||
#ifndef RGBDS_MAIN_H
|
#ifndef RGBDS_MAIN_H
|
||||||
#define RGBDS_MAIN_H
|
#define RGBDS_MAIN_H
|
||||||
|
|
||||||
#include <stdbool.h>
|
#include <stdbool.h>
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
|
|
||||||
#include "extern/stdnoreturn.h"
|
#include "helpers.h"
|
||||||
|
|
||||||
struct sOptions {
|
struct sOptions {
|
||||||
char gbgfx[4];
|
|
||||||
char binary[2];
|
char binary[2];
|
||||||
int32_t fillchar;
|
char gbgfx[4];
|
||||||
bool verbose;
|
|
||||||
bool haltnop;
|
|
||||||
bool exportall;
|
bool exportall;
|
||||||
|
int32_t fillchar;
|
||||||
|
bool haltnop;
|
||||||
|
bool optimizeloads;
|
||||||
|
bool verbose;
|
||||||
bool warnings; /* True to enable warnings, false to disable them. */
|
bool warnings; /* True to enable warnings, false to disable them. */
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -37,7 +46,7 @@ void opt_Parse(char *s);
|
|||||||
* It is also used when the assembler goes into an invalid state (for example,
|
* It is also used when the assembler goes into an invalid state (for example,
|
||||||
* when it fails to allocate memory).
|
* 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
|
* Used for errors that make it impossible to assemble correctly, but don't
|
||||||
|
|||||||
@@ -1,3 +1,11 @@
|
|||||||
|
/*
|
||||||
|
* This file is part of RGBDS.
|
||||||
|
*
|
||||||
|
* Copyright (c) 1997-2018, Carsten Sorensen and RGBDS contributors.
|
||||||
|
*
|
||||||
|
* SPDX-License-Identifier: MIT
|
||||||
|
*/
|
||||||
|
|
||||||
#ifndef RGBDS_ASM_MATH_H
|
#ifndef RGBDS_ASM_MATH_H
|
||||||
#define RGBDS_ASM_MATH_H
|
#define RGBDS_ASM_MATH_H
|
||||||
|
|
||||||
|
|||||||
@@ -1,3 +1,11 @@
|
|||||||
|
/*
|
||||||
|
* This file is part of RGBDS.
|
||||||
|
*
|
||||||
|
* Copyright (c) 1997-2018, Carsten Sorensen and RGBDS contributors.
|
||||||
|
*
|
||||||
|
* SPDX-License-Identifier: MIT
|
||||||
|
*/
|
||||||
|
|
||||||
#ifndef RGBDS_ASM_OUTPUT_H
|
#ifndef RGBDS_ASM_OUTPUT_H
|
||||||
#define RGBDS_ASM_OUTPUT_H
|
#define RGBDS_ASM_OUTPUT_H
|
||||||
|
|
||||||
|
|||||||
@@ -1,3 +1,11 @@
|
|||||||
|
/*
|
||||||
|
* This file is part of RGBDS.
|
||||||
|
*
|
||||||
|
* Copyright (c) 1997-2018, Carsten Sorensen and RGBDS contributors.
|
||||||
|
*
|
||||||
|
* SPDX-License-Identifier: MIT
|
||||||
|
*/
|
||||||
|
|
||||||
#ifndef RGBDS_ASM_RPN_H
|
#ifndef RGBDS_ASM_RPN_H
|
||||||
#define RGBDS_ASM_RPN_H
|
#define RGBDS_ASM_RPN_H
|
||||||
|
|
||||||
|
|||||||
@@ -1,3 +1,11 @@
|
|||||||
|
/*
|
||||||
|
* This file is part of RGBDS.
|
||||||
|
*
|
||||||
|
* Copyright (c) 1997-2018, Carsten Sorensen and RGBDS contributors.
|
||||||
|
*
|
||||||
|
* SPDX-License-Identifier: MIT
|
||||||
|
*/
|
||||||
|
|
||||||
#ifndef RGBDS_SYMBOL_H
|
#ifndef RGBDS_SYMBOL_H
|
||||||
#define RGBDS_SYMBOL_H
|
#define RGBDS_SYMBOL_H
|
||||||
|
|
||||||
|
|||||||
@@ -1,3 +1,11 @@
|
|||||||
|
/*
|
||||||
|
* This file is part of RGBDS.
|
||||||
|
*
|
||||||
|
* Copyright (c) 1997-2018, Carsten Sorensen and RGBDS contributors.
|
||||||
|
*
|
||||||
|
* SPDX-License-Identifier: MIT
|
||||||
|
*/
|
||||||
|
|
||||||
#ifndef RGBDS_COMMON_H
|
#ifndef RGBDS_COMMON_H
|
||||||
#define RGBDS_COMMON_H
|
#define RGBDS_COMMON_H
|
||||||
|
|
||||||
|
|||||||
18
include/extern/err.h
vendored
18
include/extern/err.h
vendored
@@ -1,3 +1,11 @@
|
|||||||
|
/*
|
||||||
|
* This file is part of RGBDS.
|
||||||
|
*
|
||||||
|
* Copyright (c) 1997-2018, RGBDS contributors.
|
||||||
|
*
|
||||||
|
* SPDX-License-Identifier: MIT
|
||||||
|
*/
|
||||||
|
|
||||||
#ifndef EXTERN_ERR_H
|
#ifndef EXTERN_ERR_H
|
||||||
#define EXTERN_ERR_H
|
#define EXTERN_ERR_H
|
||||||
|
|
||||||
@@ -9,7 +17,7 @@
|
|||||||
|
|
||||||
#include <stdarg.h>
|
#include <stdarg.h>
|
||||||
|
|
||||||
#include "extern/stdnoreturn.h"
|
#include "helpers.h"
|
||||||
|
|
||||||
#define warn rgbds_warn
|
#define warn rgbds_warn
|
||||||
#define vwarn rgbds_vwarn
|
#define vwarn rgbds_vwarn
|
||||||
@@ -26,10 +34,10 @@ void vwarn(const char *fmt, va_list ap);
|
|||||||
void warnx(const char *fmt, ...);
|
void warnx(const char *fmt, ...);
|
||||||
void vwarnx(const char *fmt, va_list ap);
|
void vwarnx(const char *fmt, va_list ap);
|
||||||
|
|
||||||
noreturn void err(int status, const char *fmt, ...);
|
noreturn_ void err(int status, const char *fmt, ...);
|
||||||
noreturn void verr(int status, const char *fmt, va_list ap);
|
noreturn_ void verr(int status, const char *fmt, va_list ap);
|
||||||
noreturn void errx(int status, const char *fmt, ...);
|
noreturn_ void errx(int status, const char *fmt, ...);
|
||||||
noreturn void verrx(int status, const char *fmt, va_list ap);
|
noreturn_ void verrx(int status, const char *fmt, va_list ap);
|
||||||
|
|
||||||
#endif /* ERR_IN_LIBC */
|
#endif /* ERR_IN_LIBC */
|
||||||
|
|
||||||
|
|||||||
15
include/extern/reallocarray.h
vendored
15
include/extern/reallocarray.h
vendored
@@ -1,15 +0,0 @@
|
|||||||
#ifndef EXTERN_REALLOCARRAY_H
|
|
||||||
#define EXTERN_REALLOCARRAY_H
|
|
||||||
|
|
||||||
#ifdef REALLOCARRAY_IN_LIBC
|
|
||||||
|
|
||||||
#include <stdlib.h>
|
|
||||||
|
|
||||||
#else /* REALLOCARRAY_IN_LIBC */
|
|
||||||
|
|
||||||
#define reallocarray rgbds_reallocarray
|
|
||||||
void *reallocarray(void *, size_t, size_t);
|
|
||||||
|
|
||||||
#endif /* REALLOCARRAY_IN_LIBC */
|
|
||||||
|
|
||||||
#endif /* EXTERN_REALLOCARRAY_H */
|
|
||||||
21
include/extern/stdnoreturn.h
vendored
21
include/extern/stdnoreturn.h
vendored
@@ -1,21 +0,0 @@
|
|||||||
#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 */
|
|
||||||
17
include/extern/strl.h
vendored
17
include/extern/strl.h
vendored
@@ -1,17 +0,0 @@
|
|||||||
#ifndef EXTERN_STRL_H
|
|
||||||
#define EXTERN_STRL_H
|
|
||||||
|
|
||||||
#ifdef STRL_IN_LIBC
|
|
||||||
|
|
||||||
#include <string.h>
|
|
||||||
|
|
||||||
#else /* STRL_IN_LIBC */
|
|
||||||
|
|
||||||
#define strlcpy rgbds_strlcpy
|
|
||||||
#define strlcat rgbds_strlcat
|
|
||||||
size_t strlcpy(char *dst, const char *src, size_t dsize);
|
|
||||||
size_t strlcat(char *dst, const char *src, size_t dsize);
|
|
||||||
|
|
||||||
#endif /* STRL_IN_LIBC */
|
|
||||||
|
|
||||||
#endif /* EXTERN_STRL_H */
|
|
||||||
14
include/extern/utf8decoder.h
vendored
Normal file
14
include/extern/utf8decoder.h
vendored
Normal file
@@ -0,0 +1,14 @@
|
|||||||
|
/*
|
||||||
|
* This file is part of RGBDS.
|
||||||
|
*
|
||||||
|
* Copyright (c) 2018, Antonio Nino Diaz and RGBDS contributors.
|
||||||
|
*
|
||||||
|
* SPDX-License-Identifier: MIT
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef EXTERN_UTF8DECODER_H
|
||||||
|
#define EXTERN_UTF8DECODER_H
|
||||||
|
|
||||||
|
uint32_t decode(uint32_t *state, uint32_t *codep, uint32_t byte);
|
||||||
|
|
||||||
|
#endif /* EXTERN_UTF8DECODER_H */
|
||||||
26
include/extern/version.h
vendored
26
include/extern/version.h
vendored
@@ -1,26 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright (C) 2017 Antonio Nino Diaz <antonio_nd@outlook.com>
|
|
||||||
*
|
|
||||||
* Permission to use, copy, modify, and distribute this software for any
|
|
||||||
* purpose with or without fee is hereby granted, provided that the above
|
|
||||||
* copyright notice and this permission notice appear in all copies.
|
|
||||||
*
|
|
||||||
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
|
||||||
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
|
||||||
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
|
||||||
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
|
||||||
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
|
||||||
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
|
||||||
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#ifndef EXTERN_VERSION_H
|
|
||||||
#define EXTERN_VERSION_H
|
|
||||||
|
|
||||||
#define PACKAGE_VERSION_MAJOR (0)
|
|
||||||
#define PACKAGE_VERSION_MINOR (3)
|
|
||||||
#define PACKAGE_VERSION_PATCH (4)
|
|
||||||
|
|
||||||
const char *get_package_version_string(void);
|
|
||||||
|
|
||||||
#endif /* EXTERN_VERSION_H */
|
|
||||||
@@ -1,17 +1,9 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright © 2013 stag019 <stag019@gmail.com>
|
* This file is part of RGBDS.
|
||||||
*
|
*
|
||||||
* Permission to use, copy, modify, and distribute this software for any
|
* Copyright (c) 2013-2018, stag019 and RGBDS contributors.
|
||||||
* purpose with or without fee is hereby granted, provided that the above
|
|
||||||
* copyright notice and this permission notice appear in all copies.
|
|
||||||
*
|
*
|
||||||
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
* SPDX-License-Identifier: MIT
|
||||||
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
|
||||||
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
|
||||||
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
|
||||||
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
|
||||||
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
|
||||||
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#ifndef RGBDS_GFX_GB_H
|
#ifndef RGBDS_GFX_GB_H
|
||||||
@@ -20,14 +12,15 @@
|
|||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
#include "gfx/main.h"
|
#include "gfx/main.h"
|
||||||
|
|
||||||
void png_to_gb(const struct PNGImage png, struct GBImage *gb);
|
void raw_to_gb(const struct RawIndexedImage *raw_image, struct GBImage *gb);
|
||||||
void output_file(const struct Options opts, const struct GBImage gb);
|
void output_file(const struct Options *opts, const struct GBImage *gb);
|
||||||
int get_tile_index(uint8_t *tile, uint8_t **tiles, int num_tiles,
|
int get_tile_index(uint8_t *tile, uint8_t **tiles, int num_tiles,
|
||||||
int tile_size);
|
int tile_size);
|
||||||
void create_tilemap(const struct Options opts, struct GBImage *gb,
|
void create_tilemap(const struct Options *opts, struct GBImage *gb,
|
||||||
struct Tilemap *tilemap);
|
struct Tilemap *tilemap);
|
||||||
void output_tilemap_file(const struct Options opts,
|
void output_tilemap_file(const struct Options *opts,
|
||||||
const struct Tilemap tilemap);
|
const struct Tilemap *tilemap);
|
||||||
void output_palette_file(const struct Options opts, const struct PNGImage png);
|
void output_palette_file(const struct Options *opts,
|
||||||
|
const struct RawIndexedImage *raw_image);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -1,17 +1,9 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright © 2013 stag019 <stag019@gmail.com>
|
* This file is part of RGBDS.
|
||||||
*
|
*
|
||||||
* Permission to use, copy, modify, and distribute this software for any
|
* Copyright (c) 2013-2018, stag019 and RGBDS contributors.
|
||||||
* purpose with or without fee is hereby granted, provided that the above
|
|
||||||
* copyright notice and this permission notice appear in all copies.
|
|
||||||
*
|
*
|
||||||
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
* SPDX-License-Identifier: MIT
|
||||||
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
|
||||||
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
|
||||||
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
|
||||||
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
|
||||||
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
|
||||||
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#ifndef RGBDS_GFX_MAIN_H
|
#ifndef RGBDS_GFX_MAIN_H
|
||||||
@@ -39,6 +31,21 @@ struct Options {
|
|||||||
char *infile;
|
char *infile;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
struct RGBColor {
|
||||||
|
uint8_t red;
|
||||||
|
uint8_t green;
|
||||||
|
uint8_t blue;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct ImageOptions {
|
||||||
|
bool horizontal;
|
||||||
|
int trim;
|
||||||
|
char *mapfile;
|
||||||
|
bool mapout;
|
||||||
|
char *palfile;
|
||||||
|
bool palout;
|
||||||
|
};
|
||||||
|
|
||||||
struct PNGImage {
|
struct PNGImage {
|
||||||
png_struct *png;
|
png_struct *png;
|
||||||
png_info *info;
|
png_info *info;
|
||||||
@@ -47,12 +54,14 @@ struct PNGImage {
|
|||||||
int height;
|
int height;
|
||||||
png_byte depth;
|
png_byte depth;
|
||||||
png_byte type;
|
png_byte type;
|
||||||
bool horizontal;
|
};
|
||||||
int trim;
|
|
||||||
char *mapfile;
|
struct RawIndexedImage {
|
||||||
bool mapout;
|
uint8_t **data;
|
||||||
char *palfile;
|
struct RGBColor *palette;
|
||||||
bool palout;
|
int num_colors;
|
||||||
|
int width;
|
||||||
|
int height;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct GBImage {
|
struct GBImage {
|
||||||
|
|||||||
@@ -1,17 +1,9 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright © 2013 stag019 <stag019@gmail.com>
|
* This file is part of RGBDS.
|
||||||
*
|
*
|
||||||
* Permission to use, copy, modify, and distribute this software for any
|
* Copyright (c) 2013-2018, stag019 and RGBDS contributors.
|
||||||
* purpose with or without fee is hereby granted, provided that the above
|
|
||||||
* copyright notice and this permission notice appear in all copies.
|
|
||||||
*
|
*
|
||||||
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
* SPDX-License-Identifier: MIT
|
||||||
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
|
||||||
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
|
||||||
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
|
||||||
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
|
||||||
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
|
||||||
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#ifndef RGBDS_GFX_PNG_H
|
#ifndef RGBDS_GFX_PNG_H
|
||||||
@@ -19,10 +11,11 @@
|
|||||||
|
|
||||||
#include "gfx/main.h"
|
#include "gfx/main.h"
|
||||||
|
|
||||||
void input_png_file(const struct Options opts, struct PNGImage *img);
|
struct RawIndexedImage *input_png_file(const struct Options *opts,
|
||||||
void get_text(struct PNGImage *png);
|
struct ImageOptions *png_options);
|
||||||
void set_text(const struct PNGImage *png);
|
void output_png_file(const struct Options *opts,
|
||||||
void output_png_file(const struct Options opts, const struct PNGImage *png);
|
const struct ImageOptions *png_options,
|
||||||
void free_png_data(const struct PNGImage *png);
|
const struct RawIndexedImage *raw_image);
|
||||||
|
void destroy_raw_image(struct RawIndexedImage **raw_image_ptr_ptr);
|
||||||
|
|
||||||
#endif /* RGBDS_GFX_PNG_H */
|
#endif /* RGBDS_GFX_PNG_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 */
|
||||||
@@ -1,3 +1,11 @@
|
|||||||
|
/*
|
||||||
|
* This file is part of RGBDS.
|
||||||
|
*
|
||||||
|
* Copyright (c) 1997-2018, Carsten Sorensen and RGBDS contributors.
|
||||||
|
*
|
||||||
|
* SPDX-License-Identifier: MIT
|
||||||
|
*/
|
||||||
|
|
||||||
#ifndef RGBDS_LINK_ASSIGN_H
|
#ifndef RGBDS_LINK_ASSIGN_H
|
||||||
#define RGBDS_LINK_ASSIGN_H
|
#define RGBDS_LINK_ASSIGN_H
|
||||||
|
|
||||||
|
|||||||
@@ -1,3 +1,11 @@
|
|||||||
|
/*
|
||||||
|
* This file is part of RGBDS.
|
||||||
|
*
|
||||||
|
* Copyright (c) 1997-2018, Carsten Sorensen and RGBDS contributors.
|
||||||
|
*
|
||||||
|
* SPDX-License-Identifier: MIT
|
||||||
|
*/
|
||||||
|
|
||||||
#ifndef RGBDS_LINK_LIBRARY_H
|
#ifndef RGBDS_LINK_LIBRARY_H
|
||||||
#define RGBDS_LINK_LIBRARY_H
|
#define RGBDS_LINK_LIBRARY_H
|
||||||
|
|
||||||
|
|||||||
@@ -1,3 +1,11 @@
|
|||||||
|
/*
|
||||||
|
* This file is part of RGBDS.
|
||||||
|
*
|
||||||
|
* Copyright (c) 1997-2018, Carsten Sorensen and RGBDS contributors.
|
||||||
|
*
|
||||||
|
* SPDX-License-Identifier: MIT
|
||||||
|
*/
|
||||||
|
|
||||||
#ifndef RGBDS_LINK_MAIN_H
|
#ifndef RGBDS_LINK_MAIN_H
|
||||||
#define RGBDS_LINK_MAIN_H
|
#define RGBDS_LINK_MAIN_H
|
||||||
|
|
||||||
|
|||||||
@@ -1,3 +1,11 @@
|
|||||||
|
/*
|
||||||
|
* This file is part of RGBDS.
|
||||||
|
*
|
||||||
|
* Copyright (c) 1997-2018, Carsten Sorensen and RGBDS contributors.
|
||||||
|
*
|
||||||
|
* SPDX-License-Identifier: MIT
|
||||||
|
*/
|
||||||
|
|
||||||
#ifndef RGBDS_LINK_MAPFILE_H
|
#ifndef RGBDS_LINK_MAPFILE_H
|
||||||
#define RGBDS_LINK_MAPFILE_H
|
#define RGBDS_LINK_MAPFILE_H
|
||||||
|
|
||||||
|
|||||||
@@ -1,3 +1,11 @@
|
|||||||
|
/*
|
||||||
|
* This file is part of RGBDS.
|
||||||
|
*
|
||||||
|
* Copyright (c) 1997-2018, Carsten Sorensen and RGBDS contributors.
|
||||||
|
*
|
||||||
|
* SPDX-License-Identifier: MIT
|
||||||
|
*/
|
||||||
|
|
||||||
#ifndef RGBDS_LINK_LINK_H
|
#ifndef RGBDS_LINK_LINK_H
|
||||||
#define RGBDS_LINK_LINK_H
|
#define RGBDS_LINK_LINK_H
|
||||||
|
|
||||||
|
|||||||
@@ -1,3 +1,11 @@
|
|||||||
|
/*
|
||||||
|
* This file is part of RGBDS.
|
||||||
|
*
|
||||||
|
* Copyright (c) 1997-2018, Carsten Sorensen and RGBDS contributors.
|
||||||
|
*
|
||||||
|
* SPDX-License-Identifier: MIT
|
||||||
|
*/
|
||||||
|
|
||||||
#ifndef RGBDS_LINK_OBJECT_H
|
#ifndef RGBDS_LINK_OBJECT_H
|
||||||
#define RGBDS_LINK_OBJECT_H
|
#define RGBDS_LINK_OBJECT_H
|
||||||
|
|
||||||
|
|||||||
@@ -1,3 +1,11 @@
|
|||||||
|
/*
|
||||||
|
* This file is part of RGBDS.
|
||||||
|
*
|
||||||
|
* Copyright (c) 1997-2018, Carsten Sorensen and RGBDS contributors.
|
||||||
|
*
|
||||||
|
* SPDX-License-Identifier: MIT
|
||||||
|
*/
|
||||||
|
|
||||||
#ifndef RGBDS_LINK_OUTPUT_H
|
#ifndef RGBDS_LINK_OUTPUT_H
|
||||||
#define RGBDS_LINK_OUTPUT_H
|
#define RGBDS_LINK_OUTPUT_H
|
||||||
|
|
||||||
|
|||||||
@@ -1,3 +1,11 @@
|
|||||||
|
/*
|
||||||
|
* This file is part of RGBDS.
|
||||||
|
*
|
||||||
|
* Copyright (c) 1997-2018, Carsten Sorensen and RGBDS contributors.
|
||||||
|
*
|
||||||
|
* SPDX-License-Identifier: MIT
|
||||||
|
*/
|
||||||
|
|
||||||
#ifndef RGBDS_LINK_PATCH_H
|
#ifndef RGBDS_LINK_PATCH_H
|
||||||
#define RGBDS_LINK_PATCH_H
|
#define RGBDS_LINK_PATCH_H
|
||||||
|
|
||||||
|
|||||||
@@ -1,17 +1,9 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (C) 2017 Antonio Nino Diaz <antonio_nd@outlook.com>
|
* This file is part of RGBDS.
|
||||||
*
|
*
|
||||||
* Permission to use, copy, modify, and distribute this software for any
|
* Copyright (c) 2017-2018, Antonio Nino Diaz and RGBDS contributors.
|
||||||
* purpose with or without fee is hereby granted, provided that the above
|
|
||||||
* copyright notice and this permission notice appear in all copies.
|
|
||||||
*
|
*
|
||||||
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
* SPDX-License-Identifier: MIT
|
||||||
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
|
||||||
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
|
||||||
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
|
||||||
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
|
||||||
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
|
||||||
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#ifndef RGBDS_LINK_SCRIPT_H
|
#ifndef RGBDS_LINK_SCRIPT_H
|
||||||
@@ -19,9 +11,9 @@
|
|||||||
|
|
||||||
#include <stdint.h>
|
#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);
|
void script_Parse(const char *path);
|
||||||
|
|
||||||
|
|||||||
@@ -1,3 +1,11 @@
|
|||||||
|
/*
|
||||||
|
* This file is part of RGBDS.
|
||||||
|
*
|
||||||
|
* Copyright (c) 1997-2018, Carsten Sorensen and RGBDS contributors.
|
||||||
|
*
|
||||||
|
* SPDX-License-Identifier: MIT
|
||||||
|
*/
|
||||||
|
|
||||||
#ifndef RGBDS_LINK_SYMBOL_H
|
#ifndef RGBDS_LINK_SYMBOL_H
|
||||||
#define RGBDS_LINK_SYMBOL_H
|
#define RGBDS_LINK_SYMBOL_H
|
||||||
|
|
||||||
|
|||||||
@@ -1,3 +1,11 @@
|
|||||||
|
/*
|
||||||
|
* This file is part of RGBDS.
|
||||||
|
*
|
||||||
|
* Copyright (c) 1997-2018, Carsten Sorensen and RGBDS contributors.
|
||||||
|
*
|
||||||
|
* SPDX-License-Identifier: MIT
|
||||||
|
*/
|
||||||
|
|
||||||
#ifndef RGBDS_LINKDEFS_H
|
#ifndef RGBDS_LINKDEFS_H
|
||||||
#define RGBDS_LINKDEFS_H
|
#define RGBDS_LINKDEFS_H
|
||||||
|
|
||||||
@@ -58,7 +66,8 @@ enum eSymbolType {
|
|||||||
enum ePatchType {
|
enum ePatchType {
|
||||||
PATCH_BYTE = 0x00,
|
PATCH_BYTE = 0x00,
|
||||||
PATCH_WORD_L = 0x01,
|
PATCH_WORD_L = 0x01,
|
||||||
PATCH_LONG_L = 0x02
|
PATCH_LONG_L = 0x02,
|
||||||
|
PATCH_BYTE_JR = 0x03
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif /* RGBDS_LINKDEFS_H */
|
#endif /* RGBDS_LINKDEFS_H */
|
||||||
|
|||||||
@@ -1,3 +1,11 @@
|
|||||||
|
/*
|
||||||
|
* This file is part of RGBDS.
|
||||||
|
*
|
||||||
|
* Copyright (c) 1997-2018, Carsten Sorensen and RGBDS contributors.
|
||||||
|
*
|
||||||
|
* SPDX-License-Identifier: MIT
|
||||||
|
*/
|
||||||
|
|
||||||
#ifndef RGBDS_TYPES_H
|
#ifndef RGBDS_TYPES_H
|
||||||
#define RGBDS_TYPES_H
|
#define RGBDS_TYPES_H
|
||||||
|
|
||||||
|
|||||||
18
include/version.h
Normal file
18
include/version.h
Normal file
@@ -0,0 +1,18 @@
|
|||||||
|
/*
|
||||||
|
* This file is part of RGBDS.
|
||||||
|
*
|
||||||
|
* Copyright (c) 2017-2018, Antonio Nino Diaz and RGBDS contributors.
|
||||||
|
*
|
||||||
|
* SPDX-License-Identifier: MIT
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef EXTERN_VERSION_H
|
||||||
|
#define EXTERN_VERSION_H
|
||||||
|
|
||||||
|
#define PACKAGE_VERSION_MAJOR (0)
|
||||||
|
#define PACKAGE_VERSION_MINOR (3)
|
||||||
|
#define PACKAGE_VERSION_PATCH (7)
|
||||||
|
|
||||||
|
const char *get_package_version_string(void);
|
||||||
|
|
||||||
|
#endif /* EXTERN_VERSION_H */
|
||||||
209
src/asm/asmy.y
209
src/asm/asmy.y
@@ -1,3 +1,11 @@
|
|||||||
|
/*
|
||||||
|
* This file is part of RGBDS.
|
||||||
|
*
|
||||||
|
* Copyright (c) 1997-2018, Carsten Sorensen and RGBDS contributors.
|
||||||
|
*
|
||||||
|
* SPDX-License-Identifier: MIT
|
||||||
|
*/
|
||||||
|
|
||||||
%{
|
%{
|
||||||
#include <ctype.h>
|
#include <ctype.h>
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
@@ -20,8 +28,10 @@
|
|||||||
#include "common.h"
|
#include "common.h"
|
||||||
#include "linkdefs.h"
|
#include "linkdefs.h"
|
||||||
|
|
||||||
|
uint32_t nListCountEmpty;
|
||||||
char *tzNewMacro;
|
char *tzNewMacro;
|
||||||
uint32_t ulNewMacroSize;
|
uint32_t ulNewMacroSize;
|
||||||
|
int32_t nPCOffset;
|
||||||
|
|
||||||
static void bankrangecheck(char *name, uint32_t secttype, int32_t org,
|
static void bankrangecheck(char *name, uint32_t secttype, int32_t org,
|
||||||
int32_t bank)
|
int32_t bank)
|
||||||
@@ -331,8 +341,9 @@ static void if_skip_to_else(void)
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
case '\"':
|
case '\"':
|
||||||
src++;
|
src += 2;
|
||||||
inString = false;
|
inString = false;
|
||||||
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
src++;
|
src++;
|
||||||
@@ -447,7 +458,6 @@ static void updateUnion(void)
|
|||||||
%type <nConstValue> const_3bit
|
%type <nConstValue> const_3bit
|
||||||
%type <sVal> const_8bit
|
%type <sVal> const_8bit
|
||||||
%type <sVal> const_16bit
|
%type <sVal> const_16bit
|
||||||
%type <sVal> const_PCrel
|
|
||||||
%type <nConstValue> sectiontype
|
%type <nConstValue> sectiontype
|
||||||
|
|
||||||
%type <tzString> string
|
%type <tzString> string
|
||||||
@@ -496,7 +506,7 @@ static void updateUnion(void)
|
|||||||
%token <tzSym> T_POP_SET
|
%token <tzSym> T_POP_SET
|
||||||
%token <tzSym> T_POP_EQUS
|
%token <tzSym> T_POP_EQUS
|
||||||
|
|
||||||
%token T_POP_INCLUDE T_POP_PRINTF T_POP_PRINTT T_POP_PRINTV
|
%token T_POP_INCLUDE T_POP_PRINTF T_POP_PRINTT T_POP_PRINTV T_POP_PRINTI
|
||||||
%token T_POP_IF T_POP_ELIF T_POP_ELSE T_POP_ENDC
|
%token T_POP_IF T_POP_ELIF T_POP_ELSE T_POP_ENDC
|
||||||
%token T_POP_IMPORT T_POP_EXPORT T_POP_GLOBAL
|
%token T_POP_IMPORT T_POP_EXPORT T_POP_GLOBAL
|
||||||
%token T_POP_DB T_POP_DS T_POP_DW T_POP_DL
|
%token T_POP_DB T_POP_DS T_POP_DW T_POP_DL
|
||||||
@@ -572,7 +582,10 @@ asmfile : lines;
|
|||||||
|
|
||||||
/* Note: The lexer adds '\n' at the end of the input */
|
/* Note: The lexer adds '\n' at the end of the input */
|
||||||
lines : /* empty */
|
lines : /* empty */
|
||||||
| lines line '\n' {
|
| lines {
|
||||||
|
nListCountEmpty = 0;
|
||||||
|
nPCOffset = 1;
|
||||||
|
} line '\n' {
|
||||||
nLineNo += 1;
|
nLineNo += 1;
|
||||||
nTotalLines += 1;
|
nTotalLines += 1;
|
||||||
}
|
}
|
||||||
@@ -640,6 +653,7 @@ simple_pseudoop : include
|
|||||||
| printf
|
| printf
|
||||||
| printt
|
| printt
|
||||||
| printv
|
| printv
|
||||||
|
| printi
|
||||||
| if
|
| if
|
||||||
| elif
|
| elif
|
||||||
| else
|
| else
|
||||||
@@ -647,9 +661,9 @@ simple_pseudoop : include
|
|||||||
| import
|
| import
|
||||||
| export
|
| export
|
||||||
| global
|
| global
|
||||||
| db
|
| { nPCOffset = 0; } db
|
||||||
| dw
|
| { nPCOffset = 0; } dw
|
||||||
| dl
|
| { nPCOffset = 0; } dl
|
||||||
| ds
|
| ds
|
||||||
| section
|
| section
|
||||||
| rsreset
|
| rsreset
|
||||||
@@ -794,16 +808,28 @@ ds : T_POP_DS uconst
|
|||||||
}
|
}
|
||||||
;
|
;
|
||||||
|
|
||||||
db : T_POP_DB constlist_8bit_entry comma constlist_8bit
|
db : T_POP_DB constlist_8bit_entry comma constlist_8bit {
|
||||||
| T_POP_DB constlist_8bit_entry_single
|
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
|
dw : T_POP_DW constlist_16bit_entry comma constlist_16bit {
|
||||||
| T_POP_DW constlist_16bit_entry_single
|
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
|
dl : T_POP_DL constlist_32bit_entry comma constlist_32bit {
|
||||||
| T_POP_DL constlist_32bit_entry_single
|
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 {
|
purge : T_POP_PURGE {
|
||||||
@@ -925,6 +951,13 @@ printv : T_POP_PRINTV const
|
|||||||
}
|
}
|
||||||
;
|
;
|
||||||
|
|
||||||
|
printi : T_POP_PRINTI const
|
||||||
|
{
|
||||||
|
if (nPass == 1)
|
||||||
|
printf("%d", $2);
|
||||||
|
}
|
||||||
|
;
|
||||||
|
|
||||||
printf : T_POP_PRINTF const
|
printf : T_POP_PRINTF const
|
||||||
{
|
{
|
||||||
if (nPass == 1)
|
if (nPass == 1)
|
||||||
@@ -1013,26 +1046,7 @@ constlist_8bit : constlist_8bit_entry
|
|||||||
constlist_8bit_entry : /* empty */
|
constlist_8bit_entry : /* empty */
|
||||||
{
|
{
|
||||||
out_Skip(1);
|
out_Skip(1);
|
||||||
if (nPass == 1)
|
nListCountEmpty++;
|
||||||
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);
|
|
||||||
}
|
}
|
||||||
| const_8bit
|
| const_8bit
|
||||||
{
|
{
|
||||||
@@ -1055,18 +1069,7 @@ constlist_16bit : constlist_16bit_entry
|
|||||||
constlist_16bit_entry : /* empty */
|
constlist_16bit_entry : /* empty */
|
||||||
{
|
{
|
||||||
out_Skip(2);
|
out_Skip(2);
|
||||||
if (nPass == 1)
|
nListCountEmpty++;
|
||||||
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);
|
|
||||||
}
|
}
|
||||||
| const_16bit
|
| const_16bit
|
||||||
{
|
{
|
||||||
@@ -1081,8 +1084,7 @@ constlist_32bit : constlist_32bit_entry
|
|||||||
constlist_32bit_entry : /* empty */
|
constlist_32bit_entry : /* empty */
|
||||||
{
|
{
|
||||||
out_Skip(4);
|
out_Skip(4);
|
||||||
if (nPass == 1)
|
nListCountEmpty++;
|
||||||
warning("Empty entry in list of 32-bit elements (treated as 0).");
|
|
||||||
}
|
}
|
||||||
| relocconst
|
| relocconst
|
||||||
{
|
{
|
||||||
@@ -1090,24 +1092,6 @@ constlist_32bit_entry : /* empty */
|
|||||||
}
|
}
|
||||||
;
|
;
|
||||||
|
|
||||||
constlist_32bit_entry_single : /* empty */
|
|
||||||
{
|
|
||||||
out_Skip(4);
|
|
||||||
}
|
|
||||||
| relocconst
|
|
||||||
{
|
|
||||||
out_RelLong(&$1);
|
|
||||||
}
|
|
||||||
;
|
|
||||||
|
|
||||||
const_PCrel : relocconst
|
|
||||||
{
|
|
||||||
if (!rpn_isPCRelative(&$1))
|
|
||||||
yyerror("Expression must be PC-relative");
|
|
||||||
$$ = $1;
|
|
||||||
}
|
|
||||||
;
|
|
||||||
|
|
||||||
const_8bit : relocconst
|
const_8bit : relocconst
|
||||||
{
|
{
|
||||||
if( (!rpn_isReloc(&$1)) && (($1.nVal < -128) || ($1.nVal > 255)) )
|
if( (!rpn_isReloc(&$1)) && (($1.nVal < -128) || ($1.nVal > 255)) )
|
||||||
@@ -1127,9 +1111,40 @@ const_16bit : relocconst
|
|||||||
|
|
||||||
relocconst : T_ID
|
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);
|
rpn_Symbol(&$$, $1);
|
||||||
$$.nVal = sym_GetValue($1);
|
$$.nVal = sym_GetValue($1);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
| T_NUMBER
|
| T_NUMBER
|
||||||
{
|
{
|
||||||
rpn_Number(&$$, $1);
|
rpn_Number(&$$, $1);
|
||||||
@@ -1226,6 +1241,8 @@ uconst : const
|
|||||||
|
|
||||||
const : T_ID { $$ = sym_GetConstantValue($1); }
|
const : T_ID { $$ = sym_GetConstantValue($1); }
|
||||||
| T_NUMBER { $$ = $1; }
|
| T_NUMBER { $$ = $1; }
|
||||||
|
| T_OP_HIGH '(' const ')' { $$ = ($3 >> 8) & 0xFF; }
|
||||||
|
| T_OP_LOW '(' const ')' { $$ = $3 & 0xFF; }
|
||||||
| string { $$ = str2int($1); }
|
| string { $$ = str2int($1); }
|
||||||
| T_OP_LOGICNOT const %prec NEG { $$ = !$2; }
|
| T_OP_LOGICNOT const %prec NEG { $$ = !$2; }
|
||||||
| const T_OP_LOGICOR const { $$ = $1 || $3; }
|
| const T_OP_LOGICOR const { $$ = $1 || $3; }
|
||||||
@@ -1247,19 +1264,38 @@ const : T_ID { $$ = sym_GetConstantValue($1); }
|
|||||||
| const T_OP_XOR const { $$ = $1 ^ $3; }
|
| const T_OP_XOR const { $$ = $1 ^ $3; }
|
||||||
| const T_OP_OR const { $$ = $1 | $3; }
|
| const T_OP_OR const { $$ = $1 | $3; }
|
||||||
| const T_OP_AND const { $$ = $1 & $3; }
|
| const T_OP_AND const { $$ = $1 & $3; }
|
||||||
| const T_OP_SHL const { $$ = $1 << $3; }
|
| const T_OP_SHL const
|
||||||
| const T_OP_SHR const { $$ = $1 >> $3; }
|
{
|
||||||
|
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_MUL const { $$ = $1 * $3; }
|
||||||
| const T_OP_DIV const
|
| const T_OP_DIV const
|
||||||
{
|
{
|
||||||
if ($3 == 0)
|
if ($3 == 0)
|
||||||
fatalerror("division by zero");
|
fatalerror("Division by zero");
|
||||||
$$ = $1 / $3;
|
$$ = $1 / $3;
|
||||||
}
|
}
|
||||||
| const T_OP_MOD const
|
| const T_OP_MOD const
|
||||||
{
|
{
|
||||||
if ($3 == 0)
|
if ($3 == 0)
|
||||||
fatalerror("division by zero");
|
fatalerror("Division by zero");
|
||||||
$$ = $1 % $3;
|
$$ = $1 % $3;
|
||||||
}
|
}
|
||||||
| T_OP_ADD const %prec NEG { $$ = +$2; }
|
| T_OP_ADD const %prec NEG { $$ = +$2; }
|
||||||
@@ -1303,26 +1339,37 @@ const : T_ID { $$ = sym_GetConstantValue($1); }
|
|||||||
|
|
||||||
string : T_STRING
|
string : T_STRING
|
||||||
{
|
{
|
||||||
strcpy($$, $1);
|
if (snprintf($$, MAXSTRLEN + 1, "%s", $1) > MAXSTRLEN)
|
||||||
|
warning("String is too long '%s'", $1);
|
||||||
}
|
}
|
||||||
| T_OP_STRSUB '(' string comma uconst comma uconst ')'
|
| T_OP_STRSUB '(' string comma uconst comma uconst ')'
|
||||||
{
|
{
|
||||||
strncpy($$, $3 + $5 - 1, $7);
|
uint32_t len = $7;
|
||||||
$$[$7] = 0;
|
if (len > MAXSTRLEN) {
|
||||||
|
warning("STRSUB: Length too big: %u", len);
|
||||||
|
len = MAXSTRLEN;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (snprintf($$, len + 1, "%s", $3 + $5 - 1) > MAXSTRLEN)
|
||||||
|
warning("STRSUB: String too long '%s'", $$);
|
||||||
}
|
}
|
||||||
| T_OP_STRCAT '(' string comma string ')'
|
| T_OP_STRCAT '(' string comma string ')'
|
||||||
{
|
{
|
||||||
strcpy($$, $3);
|
if (snprintf($$, MAXSTRLEN + 1, "%s%s", $3, $5) > MAXSTRLEN)
|
||||||
strcat($$, $5);
|
warning("STRCAT: String too long '%s%s'", $3, $5);
|
||||||
}
|
}
|
||||||
| T_OP_STRUPR '(' string ')'
|
| T_OP_STRUPR '(' string ')'
|
||||||
{
|
{
|
||||||
strcpy($$, $3);
|
if (snprintf($$, MAXSTRLEN + 1, "%s", $3) > MAXSTRLEN)
|
||||||
|
warning("STRUPR: String too long '%s'", $3);
|
||||||
|
|
||||||
upperstring($$);
|
upperstring($$);
|
||||||
}
|
}
|
||||||
| T_OP_STRLWR '(' string ')'
|
| T_OP_STRLWR '(' string ')'
|
||||||
{
|
{
|
||||||
strcpy($$, $3);
|
if (snprintf($$, MAXSTRLEN + 1, "%s", $3) > MAXSTRLEN)
|
||||||
|
warning("STRUPR: String too long '%s'", $3);
|
||||||
|
|
||||||
lowerstring($$);
|
lowerstring($$);
|
||||||
}
|
}
|
||||||
;
|
;
|
||||||
@@ -1594,12 +1641,12 @@ z80_jp : T_Z80_JP const_16bit
|
|||||||
}
|
}
|
||||||
;
|
;
|
||||||
|
|
||||||
z80_jr : T_Z80_JR const_PCrel
|
z80_jr : T_Z80_JR const_16bit
|
||||||
{
|
{
|
||||||
out_AbsByte(0x18);
|
out_AbsByte(0x18);
|
||||||
out_PCRelByte(&$2);
|
out_PCRelByte(&$2);
|
||||||
}
|
}
|
||||||
| T_Z80_JR ccode comma const_PCrel
|
| T_Z80_JR ccode comma const_16bit
|
||||||
{
|
{
|
||||||
out_AbsByte(0x20 | ($2 << 3));
|
out_AbsByte(0x20 | ($2 << 3));
|
||||||
out_PCRelByte(&$4);
|
out_PCRelByte(&$4);
|
||||||
@@ -1708,7 +1755,8 @@ z80_ld_mem : T_Z80_LD op_mem_ind comma T_MODE_SP
|
|||||||
}
|
}
|
||||||
| T_Z80_LD op_mem_ind comma T_MODE_A
|
| T_Z80_LD op_mem_ind comma T_MODE_A
|
||||||
{
|
{
|
||||||
if ((!rpn_isReloc(&$2)) && ($2.nVal >= 0xFF00)) {
|
if (CurrentOptions.optimizeloads &&
|
||||||
|
(!rpn_isReloc(&$2)) && ($2.nVal >= 0xFF00)) {
|
||||||
out_AbsByte(0xE0);
|
out_AbsByte(0xE0);
|
||||||
out_AbsByte($2.nVal & 0xFF);
|
out_AbsByte($2.nVal & 0xFF);
|
||||||
} else {
|
} else {
|
||||||
@@ -1761,7 +1809,8 @@ z80_ld_a : T_Z80_LD reg_r comma T_MODE_C_IND
|
|||||||
| T_Z80_LD reg_r comma op_mem_ind
|
| T_Z80_LD reg_r comma op_mem_ind
|
||||||
{
|
{
|
||||||
if ($2 == REG_A) {
|
if ($2 == REG_A) {
|
||||||
if ((!rpn_isReloc(&$4)) && ($4.nVal >= 0xFF00)) {
|
if (CurrentOptions.optimizeloads &&
|
||||||
|
(!rpn_isReloc(&$4)) && ($4.nVal >= 0xFF00)) {
|
||||||
out_AbsByte(0xF0);
|
out_AbsByte(0xF0);
|
||||||
out_AbsByte($4.nVal & 0xFF);
|
out_AbsByte($4.nVal & 0xFF);
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
@@ -1,87 +1,12 @@
|
|||||||
/*
|
/*
|
||||||
* UTF-8 decoder copyright © 2008–2009 Björn Höhrmann <bjoern@hoehrmann.de>
|
* This file is part of RGBDS.
|
||||||
* http://bjoern.hoehrmann.de/utf-8/decoder/dfa/
|
|
||||||
*
|
*
|
||||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
* Copyright (c) 2013-2018, stag019 and RGBDS contributors.
|
||||||
* of this software and associated documentation files (the "Software"), to
|
|
||||||
* deal in the Software without restriction, including without limitation the
|
|
||||||
* rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
|
|
||||||
* sell copies of the Software, and to permit persons to whom the Software is
|
|
||||||
* furnished to do so, subject to the following conditions:
|
|
||||||
*
|
*
|
||||||
* The above copyright notice and this permission notice shall be included in
|
* SPDX-License-Identifier: MIT
|
||||||
* all copies or substantial portions of the Software.
|
|
||||||
*
|
|
||||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
||||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
||||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
||||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
||||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
|
||||||
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
|
|
||||||
* IN THE SOFTWARE.
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
|
|
||||||
static const uint8_t utf8d[] = {
|
|
||||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 00..0f */
|
|
||||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 10..1f */
|
|
||||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 20..2f */
|
|
||||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 30..3f */
|
|
||||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 40..4f */
|
|
||||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 50..5f */
|
|
||||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 60..6f */
|
|
||||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 70..7f */
|
|
||||||
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, /* 80..8f */
|
|
||||||
9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, /* 90..9f */
|
|
||||||
7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, /* a0..af */
|
|
||||||
7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, /* b0..bf */
|
|
||||||
8, 8, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, /* c0..cf */
|
|
||||||
2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, /* d0..df */
|
|
||||||
0xa, 0x3, 0x3, 0x3, 0x3, 0x3, 0x3, 0x3, /* e0..e7 */
|
|
||||||
0x3, 0x3, 0x3, 0x3, 0x3, 0x4, 0x3, 0x3, /* e8..ef */
|
|
||||||
0xb, 0x6, 0x6, 0x6, 0x5, 0x8, 0x8, 0x8, /* f0..f7 */
|
|
||||||
0x8, 0x8, 0x8, 0x8, 0x8, 0x8, 0x8, 0x8, /* f8..ff */
|
|
||||||
0x0, 0x1, 0x2, 0x3, 0x5, 0x8, 0x7, 0x1, /* s0.. */
|
|
||||||
0x1, 0x1, 0x4, 0x6, 0x1, 0x1, 0x1, 0x1, /* ..s0 */
|
|
||||||
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, /* s1 */
|
|
||||||
1, 0, 1, 1, 1, 1, 1, 0, 1, 0, 1, 1, 1, 1, 1, 1, /* s1 */
|
|
||||||
1, 2, 1, 1, 1, 1, 1, 2, 1, 2, 1, 1, 1, 1, 1, 1, /* s3 */
|
|
||||||
1, 1, 1, 1, 1, 1, 1, 2, 1, 1, 1, 1, 1, 1, 1, 1, /* s4 */
|
|
||||||
1, 2, 1, 1, 1, 1, 1, 1, 1, 2, 1, 1, 1, 1, 1, 1, /* s5 */
|
|
||||||
1, 1, 1, 1, 1, 1, 1, 3, 1, 3, 1, 1, 1, 1, 1, 1, /* s6 */
|
|
||||||
1, 3, 1, 1, 1, 1, 1, 3, 1, 3, 1, 1, 1, 1, 1, 1, /* s7 */
|
|
||||||
1, 3, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, /* s8 */
|
|
||||||
};
|
|
||||||
|
|
||||||
uint32_t decode(uint32_t *state, uint32_t *codep, uint32_t byte)
|
|
||||||
{
|
|
||||||
uint32_t type = utf8d[byte];
|
|
||||||
|
|
||||||
*codep = (*state != 0) ?
|
|
||||||
(byte & 0x3fu) | (*codep << 6) :
|
|
||||||
(0xff >> type) & (byte);
|
|
||||||
|
|
||||||
*state = utf8d[256 + *state * 16 + type];
|
|
||||||
return *state;
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Copyright © 2013 stag019 <stag019@gmail.com>
|
|
||||||
*
|
|
||||||
* Permission to use, copy, modify, and distribute this software for any
|
|
||||||
* purpose with or without fee is hereby granted, provided that the above
|
|
||||||
* copyright notice and this permission notice appear in all copies.
|
|
||||||
*
|
|
||||||
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
|
||||||
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
|
||||||
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
|
||||||
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
|
||||||
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
|
||||||
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
|
||||||
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
@@ -91,6 +16,8 @@ uint32_t decode(uint32_t *state, uint32_t *codep, uint32_t byte)
|
|||||||
#include "asm/main.h"
|
#include "asm/main.h"
|
||||||
#include "asm/output.h"
|
#include "asm/output.h"
|
||||||
|
|
||||||
|
#include "extern/utf8decoder.h"
|
||||||
|
|
||||||
struct Charmap globalCharmap = {0};
|
struct Charmap globalCharmap = {0};
|
||||||
|
|
||||||
int32_t readUTF8Char(char *dest, char *src)
|
int32_t readUTF8Char(char *dest, char *src)
|
||||||
|
|||||||
@@ -1,3 +1,11 @@
|
|||||||
|
/*
|
||||||
|
* This file is part of RGBDS.
|
||||||
|
*
|
||||||
|
* Copyright (c) 1997-2018, Carsten Sorensen and RGBDS contributors.
|
||||||
|
*
|
||||||
|
* SPDX-License-Identifier: MIT
|
||||||
|
*/
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* FileStack routines
|
* FileStack routines
|
||||||
*/
|
*/
|
||||||
@@ -16,7 +24,6 @@
|
|||||||
#include "asm/symbol.h"
|
#include "asm/symbol.h"
|
||||||
|
|
||||||
#include "extern/err.h"
|
#include "extern/err.h"
|
||||||
#include "extern/strl.h"
|
|
||||||
|
|
||||||
#include "types.h"
|
#include "types.h"
|
||||||
|
|
||||||
@@ -80,6 +87,8 @@ static void pushcontext(void)
|
|||||||
(*ppFileStack)->nREPTBlockSize = nCurrentREPTBlockSize;
|
(*ppFileStack)->nREPTBlockSize = nCurrentREPTBlockSize;
|
||||||
(*ppFileStack)->nREPTBlockCount = nCurrentREPTBlockCount;
|
(*ppFileStack)->nREPTBlockCount = nCurrentREPTBlockCount;
|
||||||
break;
|
break;
|
||||||
|
default:
|
||||||
|
fatalerror("%s: Internal error.", __func__);
|
||||||
}
|
}
|
||||||
|
|
||||||
nLineNo = 0;
|
nLineNo = 0;
|
||||||
@@ -145,6 +154,8 @@ static int32_t popcontext(void)
|
|||||||
nCurrentREPTBlockSize = pLastFile->nREPTBlockSize;
|
nCurrentREPTBlockSize = pLastFile->nREPTBlockSize;
|
||||||
nCurrentREPTBlockCount = pLastFile->nREPTBlockCount;
|
nCurrentREPTBlockCount = pLastFile->nREPTBlockCount;
|
||||||
break;
|
break;
|
||||||
|
default:
|
||||||
|
fatalerror("%s: Internal error.", __func__);
|
||||||
}
|
}
|
||||||
|
|
||||||
free(*ppLastFile);
|
free(*ppLastFile);
|
||||||
@@ -167,6 +178,8 @@ int32_t fstk_GetLine(void)
|
|||||||
return nLineNo; /* ??? */
|
return nLineNo; /* ??? */
|
||||||
case STAT_isREPTBlock:
|
case STAT_isREPTBlock:
|
||||||
break; /* Peek top file of the stack */
|
break; /* Peek top file of the stack */
|
||||||
|
default:
|
||||||
|
fatalerror("%s: Internal error.", __func__);
|
||||||
}
|
}
|
||||||
|
|
||||||
pLastFile = pFileStack;
|
pLastFile = pFileStack;
|
||||||
@@ -218,7 +231,7 @@ void fstk_AddIncludePath(char *s)
|
|||||||
if (NextIncPath == MAXINCPATHS)
|
if (NextIncPath == MAXINCPATHS)
|
||||||
fatalerror("Too many include directories passed from command line");
|
fatalerror("Too many include directories passed from command line");
|
||||||
|
|
||||||
if (strlcpy(IncludePaths[NextIncPath++], s, _MAX_PATH) >= _MAX_PATH)
|
if (snprintf(IncludePaths[NextIncPath++], _MAX_PATH, "%s", s) >= _MAX_PATH)
|
||||||
fatalerror("Include path too long '%s'", s);
|
fatalerror("Include path too long '%s'", s);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -228,6 +241,9 @@ FILE *fstk_FindFile(char *fname)
|
|||||||
int32_t i;
|
int32_t i;
|
||||||
FILE *f;
|
FILE *f;
|
||||||
|
|
||||||
|
if (fname == NULL)
|
||||||
|
return NULL;
|
||||||
|
|
||||||
f = fopen(fname, "rb");
|
f = fopen(fname, "rb");
|
||||||
|
|
||||||
if (f != NULL || errno != ENOENT) {
|
if (f != NULL || errno != ENOENT) {
|
||||||
@@ -238,11 +254,19 @@ FILE *fstk_FindFile(char *fname)
|
|||||||
}
|
}
|
||||||
|
|
||||||
for (i = 0; i < NextIncPath; ++i) {
|
for (i = 0; i < NextIncPath; ++i) {
|
||||||
if (strlcpy(path, IncludePaths[i], sizeof(path))
|
/*
|
||||||
>= sizeof(path))
|
* The function snprintf() does not write more than `size` bytes
|
||||||
continue;
|
* (including the terminating null byte ('\0')). If the output
|
||||||
|
* was truncated due to this limit, the return value is the
|
||||||
|
* number of characters (excluding the terminating null byte)
|
||||||
|
* which would have been written to the final string if enough
|
||||||
|
* space had been available. Thus, a return value of `size` or
|
||||||
|
* more means that the output was truncated.
|
||||||
|
*/
|
||||||
|
int fullpathlen = snprintf(path, sizeof(path), "%s%s",
|
||||||
|
IncludePaths[i], fname);
|
||||||
|
|
||||||
if (strlcat(path, fname, sizeof(path)) >= sizeof(path))
|
if (fullpathlen >= (int)sizeof(path))
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
f = fopen(path, "rb");
|
f = fopen(path, "rb");
|
||||||
@@ -331,7 +355,7 @@ void fstk_RunMacroArg(int32_t s)
|
|||||||
|
|
||||||
pushcontext();
|
pushcontext();
|
||||||
nCurrentStatus = STAT_isMacroArg;
|
nCurrentStatus = STAT_isMacroArg;
|
||||||
sprintf(tzCurrentFileName, "%c", (uint8_t)s);
|
snprintf(tzCurrentFileName, _MAX_PATH + 1, "%c", (uint8_t)s);
|
||||||
CurrentFlexHandle = yy_scan_bytes(sym, strlen(sym));
|
CurrentFlexHandle = yy_scan_bytes(sym, strlen(sym));
|
||||||
yy_switch_to_buffer(CurrentFlexHandle);
|
yy_switch_to_buffer(CurrentFlexHandle);
|
||||||
}
|
}
|
||||||
@@ -394,7 +418,7 @@ void fstk_Init(char *s)
|
|||||||
|
|
||||||
nMacroCount = 0;
|
nMacroCount = 0;
|
||||||
nCurrentStatus = STAT_isInclude;
|
nCurrentStatus = STAT_isInclude;
|
||||||
strcpy(tzCurrentFileName, tzFileName);
|
snprintf(tzCurrentFileName, _MAX_PATH + 1, "%s", tzFileName);
|
||||||
CurrentFlexHandle = yy_create_buffer(pCurrentFile);
|
CurrentFlexHandle = yy_create_buffer(pCurrentFile);
|
||||||
yy_switch_to_buffer(CurrentFlexHandle);
|
yy_switch_to_buffer(CurrentFlexHandle);
|
||||||
nLineNo = 1;
|
nLineNo = 1;
|
||||||
|
|||||||
@@ -1,3 +1,11 @@
|
|||||||
|
/*
|
||||||
|
* This file is part of RGBDS.
|
||||||
|
*
|
||||||
|
* Copyright (c) 1997-2018, Carsten Sorensen and RGBDS contributors.
|
||||||
|
*
|
||||||
|
* SPDX-License-Identifier: MIT
|
||||||
|
*/
|
||||||
|
|
||||||
#include <math.h>
|
#include <math.h>
|
||||||
#include <stdbool.h>
|
#include <stdbool.h>
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
@@ -12,6 +20,8 @@
|
|||||||
#include "asm/symbol.h"
|
#include "asm/symbol.h"
|
||||||
#include "asm/symbol.h"
|
#include "asm/symbol.h"
|
||||||
|
|
||||||
|
#include "helpers.h"
|
||||||
|
|
||||||
#include "asmy.h"
|
#include "asmy.h"
|
||||||
|
|
||||||
bool oDontExpandStrings;
|
bool oDontExpandStrings;
|
||||||
@@ -85,6 +95,9 @@ static int32_t ascii2bin(char *s)
|
|||||||
s += 1;
|
s += 1;
|
||||||
convertfunc = binary2bin;
|
convertfunc = binary2bin;
|
||||||
break;
|
break;
|
||||||
|
default:
|
||||||
|
/* Handle below */
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (radix == 4) {
|
if (radix == 4) {
|
||||||
@@ -208,7 +221,7 @@ uint32_t PutMacroArg(char *src, uint32_t size)
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
uint32_t PutUniqueArg(char *src, uint32_t size)
|
uint32_t PutUniqueArg(unused_ char *src, uint32_t size)
|
||||||
{
|
{
|
||||||
char *s;
|
char *s;
|
||||||
|
|
||||||
@@ -360,6 +373,7 @@ const struct sLexInitString lexer_strings[] = {
|
|||||||
|
|
||||||
{"include", T_POP_INCLUDE},
|
{"include", T_POP_INCLUDE},
|
||||||
{"printt", T_POP_PRINTT},
|
{"printt", T_POP_PRINTT},
|
||||||
|
{"printi", T_POP_PRINTI},
|
||||||
{"printv", T_POP_PRINTV},
|
{"printv", T_POP_PRINTV},
|
||||||
{"printf", T_POP_PRINTF},
|
{"printf", T_POP_PRINTF},
|
||||||
{"export", T_POP_EXPORT},
|
{"export", T_POP_EXPORT},
|
||||||
@@ -570,7 +584,7 @@ void setup_lexer(void)
|
|||||||
lex_FloatAddRange(id, '@', '@');
|
lex_FloatAddRange(id, '@', '@');
|
||||||
lex_FloatAddRange(id, '#', '#');
|
lex_FloatAddRange(id, '#', '#');
|
||||||
|
|
||||||
//@ID
|
// "@"
|
||||||
|
|
||||||
id = lex_FloatAlloc(&tIDToken);
|
id = lex_FloatAlloc(&tIDToken);
|
||||||
lex_FloatAddFirstRange(id, '@', '@');
|
lex_FloatAddFirstRange(id, '@', '@');
|
||||||
|
|||||||
120
src/asm/lexer.c
120
src/asm/lexer.c
@@ -1,3 +1,11 @@
|
|||||||
|
/*
|
||||||
|
* This file is part of RGBDS.
|
||||||
|
*
|
||||||
|
* Copyright (c) 1997-2018, Carsten Sorensen and RGBDS contributors.
|
||||||
|
*
|
||||||
|
* SPDX-License-Identifier: MIT
|
||||||
|
*/
|
||||||
|
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
@@ -151,6 +159,8 @@ YY_BUFFER_STATE yy_create_buffer(FILE *f)
|
|||||||
pBuffer->pBuffer[size + 1] = 0;
|
pBuffer->pBuffer[size + 1] = 0;
|
||||||
pBuffer->nBufferSize = size + 1;
|
pBuffer->nBufferSize = size + 1;
|
||||||
|
|
||||||
|
/* Convert all line endings to LF and spaces */
|
||||||
|
|
||||||
char *mem = pBuffer->pBuffer;
|
char *mem = pBuffer->pBuffer;
|
||||||
uint32_t instring = 0;
|
uint32_t instring = 0;
|
||||||
|
|
||||||
@@ -163,20 +173,44 @@ YY_BUFFER_STATE yy_create_buffer(FILE *f)
|
|||||||
} else if (instring) {
|
} else if (instring) {
|
||||||
mem += 1;
|
mem += 1;
|
||||||
} else {
|
} else {
|
||||||
if ((mem[0] == 10 && mem[1] == 13)
|
/* LF CR and CR LF */
|
||||||
|| (mem[0] == 13 && mem[1] == 10)) {
|
if (((mem[0] == 10) && (mem[1] == 13))
|
||||||
|
|| ((mem[0] == 13) && (mem[1] == 10))) {
|
||||||
mem[0] = ' ';
|
mem[0] = ' ';
|
||||||
mem[1] = '\n';
|
mem[1] = '\n';
|
||||||
mem += 2;
|
mem += 2;
|
||||||
} else if (mem[0] == 10 || mem[0] == 13) {
|
/* LF and CR */
|
||||||
|
} else if ((mem[0] == 10) || (mem[0] == 13)) {
|
||||||
mem[0] = '\n';
|
mem[0] = '\n';
|
||||||
mem += 1;
|
mem += 1;
|
||||||
} else if (mem[0] == '\n' && mem[1] == '*') {
|
} else {
|
||||||
mem += 1;
|
mem += 1;
|
||||||
while (!(*mem == '\n' || *mem == '\0'))
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Remove comments */
|
||||||
|
|
||||||
|
mem = pBuffer->pBuffer;
|
||||||
|
instring = 0;
|
||||||
|
|
||||||
|
while (*mem) {
|
||||||
|
if (*mem == '\"')
|
||||||
|
instring = 1 - instring;
|
||||||
|
|
||||||
|
if ((mem[0] == '\\') && (mem[1] == '\"' || mem[1] == '\\')) {
|
||||||
|
mem += 2;
|
||||||
|
} else if (instring) {
|
||||||
|
mem += 1;
|
||||||
|
} else {
|
||||||
|
/* Comments that start with ; anywhere in a line */
|
||||||
|
if (*mem == ';') {
|
||||||
|
while (!((*mem == '\n') || (*mem == '\0')))
|
||||||
*mem++ = ' ';
|
*mem++ = ' ';
|
||||||
} else if (*mem == ';') {
|
/* Comments that start with * at the start of a line */
|
||||||
while (!(*mem == '\n' || *mem == '\0'))
|
} else if ((mem[0] == '\n') && (mem[1] == '*')) {
|
||||||
|
mem += 1;
|
||||||
|
while (!((*mem == '\n') || (*mem == '\0')))
|
||||||
*mem++ = ' ';
|
*mem++ = ' ';
|
||||||
} else {
|
} else {
|
||||||
mem += 1;
|
mem += 1;
|
||||||
@@ -380,7 +414,7 @@ void yylex_GetFloatMaskAndFloatLen(uint32_t *pnFloatMask, uint32_t *pnFloatLen)
|
|||||||
/*
|
/*
|
||||||
* Gets the longest keyword/operator from the current position in the buffer.
|
* 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;
|
struct sLexString *pLongestFixed = NULL;
|
||||||
char *s = pLexBuffer;
|
char *s = pLexBuffer;
|
||||||
@@ -604,6 +638,43 @@ 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
|
||||||
|
* endings: "\r\n" is replaced by " \n" before the lexer has the
|
||||||
|
* opportunity to see it.
|
||||||
|
*/
|
||||||
|
if (pLexBuffer[1] == ' ') {
|
||||||
|
pLexBuffer += 2;
|
||||||
|
while (1) {
|
||||||
|
if (*pLexBuffer == ' ') {
|
||||||
|
pLexBuffer++;
|
||||||
|
} else if (*pLexBuffer == '\n') {
|
||||||
|
pLexBuffer++;
|
||||||
|
nLineNo += 1;
|
||||||
|
goto scanagain;
|
||||||
|
} else {
|
||||||
|
errx(1, "Expected a new line after the continuation character.");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Line continuation character */
|
||||||
|
if (pLexBuffer[1] == '\n') {
|
||||||
|
pLexBuffer += 2;
|
||||||
|
nLineNo += 1;
|
||||||
|
goto scanagain;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* If there isn't a newline character or a space, ignore the
|
||||||
|
* character '\'. It will eventually be handled by other
|
||||||
|
* functions like PutMacroArg().
|
||||||
|
*/
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Try to match an identifier, macro argument (e.g. \1),
|
* Try to match an identifier, macro argument (e.g. \1),
|
||||||
* or numeric literal.
|
* or numeric literal.
|
||||||
@@ -691,6 +762,9 @@ static uint32_t yylex_MACROARGS(void)
|
|||||||
case '\\':
|
case '\\':
|
||||||
ch = '\\';
|
ch = '\\';
|
||||||
break;
|
break;
|
||||||
|
case '"':
|
||||||
|
ch = '\"';
|
||||||
|
break;
|
||||||
case ',':
|
case ',':
|
||||||
ch = ',';
|
ch = ',';
|
||||||
break;
|
break;
|
||||||
@@ -700,6 +774,32 @@ static uint32_t yylex_MACROARGS(void)
|
|||||||
case '}':
|
case '}':
|
||||||
ch = '}';
|
ch = '}';
|
||||||
break;
|
break;
|
||||||
|
case ' ':
|
||||||
|
/*
|
||||||
|
* Look for line continuation character after a
|
||||||
|
* series of spaces. This is also useful for
|
||||||
|
* files that use Windows line endings: "\r\n"
|
||||||
|
* is replaced by " \n" before the lexer has the
|
||||||
|
* opportunity to see it.
|
||||||
|
*/
|
||||||
|
while (1) {
|
||||||
|
if (*pLexBuffer == ' ') {
|
||||||
|
pLexBuffer++;
|
||||||
|
} else if (*pLexBuffer == '\n') {
|
||||||
|
pLexBuffer++;
|
||||||
|
nLineNo += 1;
|
||||||
|
ch = 0;
|
||||||
|
break;
|
||||||
|
} else {
|
||||||
|
errx(1, "Expected a new line after the continuation character.");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case '\n':
|
||||||
|
/* Line continuation character */
|
||||||
|
nLineNo += 1;
|
||||||
|
ch = 0;
|
||||||
|
break;
|
||||||
default:
|
default:
|
||||||
maxLength = MAXSTRLEN - index;
|
maxLength = MAXSTRLEN - index;
|
||||||
length = CopyMacroArg(&yylval.tzString[index],
|
length = CopyMacroArg(&yylval.tzString[index],
|
||||||
@@ -750,7 +850,7 @@ uint32_t yylex(void)
|
|||||||
return yylex_NORMAL();
|
return yylex_NORMAL();
|
||||||
case LEX_STATE_MACROARGS:
|
case LEX_STATE_MACROARGS:
|
||||||
return yylex_MACROARGS();
|
return yylex_MACROARGS();
|
||||||
|
default:
|
||||||
|
fatalerror("%s: Internal error.", __func__);
|
||||||
}
|
}
|
||||||
|
|
||||||
fatalerror("Internal error in %s", __func__);
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,3 +1,12 @@
|
|||||||
|
/*
|
||||||
|
* This file is part of RGBDS.
|
||||||
|
*
|
||||||
|
* Copyright (c) 1997-2018, Carsten Sorensen and RGBDS contributors.
|
||||||
|
*
|
||||||
|
* SPDX-License-Identifier: MIT
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <float.h>
|
||||||
#include <math.h>
|
#include <math.h>
|
||||||
#include <stdarg.h>
|
#include <stdarg.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
@@ -14,13 +23,16 @@
|
|||||||
#include "asm/main.h"
|
#include "asm/main.h"
|
||||||
|
|
||||||
#include "extern/err.h"
|
#include "extern/err.h"
|
||||||
#include "extern/reallocarray.h"
|
|
||||||
#include "extern/version.h"
|
#include "helpers.h"
|
||||||
|
#include "version.h"
|
||||||
|
|
||||||
extern int yyparse(void);
|
extern int yyparse(void);
|
||||||
|
|
||||||
int32_t cldefines_index;
|
size_t cldefines_index;
|
||||||
int32_t cldefines_size;
|
size_t cldefines_numindices;
|
||||||
|
size_t cldefines_bufsize;
|
||||||
|
const size_t cldefine_entrysize = 2 * sizeof(void *);
|
||||||
char **cldefines;
|
char **cldefines;
|
||||||
|
|
||||||
clock_t nStartClock, nEndClock;
|
clock_t nStartClock, nEndClock;
|
||||||
@@ -137,10 +149,13 @@ void opt_Parse(char *s)
|
|||||||
case 'z':
|
case 'z':
|
||||||
if (strlen(&s[1]) <= 2) {
|
if (strlen(&s[1]) <= 2) {
|
||||||
int32_t result;
|
int32_t result;
|
||||||
|
unsigned int fillchar;
|
||||||
|
|
||||||
result = sscanf(&s[1], "%x", &newopt.fillchar);
|
result = sscanf(&s[1], "%x", &fillchar);
|
||||||
if (!((result == EOF) || (result == 1)))
|
if (!((result == EOF) || (result == 1)))
|
||||||
errx(1, "Invalid argument for option 'z'");
|
errx(1, "Invalid argument for option 'z'");
|
||||||
|
|
||||||
|
newopt.fillchar = fillchar;
|
||||||
} else {
|
} else {
|
||||||
errx(1, "Invalid argument for option 'z'");
|
errx(1, "Invalid argument for option 'z'");
|
||||||
}
|
}
|
||||||
@@ -184,10 +199,18 @@ void opt_AddDefine(char *s)
|
|||||||
{
|
{
|
||||||
char *value, *equals;
|
char *value, *equals;
|
||||||
|
|
||||||
if (cldefines_index >= cldefines_size) {
|
if (cldefines_index >= cldefines_numindices) {
|
||||||
cldefines_size *= 2;
|
/* Check for overflows */
|
||||||
cldefines = reallocarray(cldefines, cldefines_size,
|
if ((cldefines_numindices * 2) < cldefines_numindices)
|
||||||
2 * sizeof(void *));
|
fatalerror("No memory for command line defines");
|
||||||
|
|
||||||
|
if ((cldefines_bufsize * 2) < cldefines_bufsize)
|
||||||
|
fatalerror("No memory for command line defines");
|
||||||
|
|
||||||
|
cldefines_numindices *= 2;
|
||||||
|
cldefines_bufsize *= 2;
|
||||||
|
|
||||||
|
cldefines = realloc(cldefines, cldefines_bufsize);
|
||||||
if (!cldefines)
|
if (!cldefines)
|
||||||
fatalerror("No memory for command line defines");
|
fatalerror("No memory for command line defines");
|
||||||
}
|
}
|
||||||
@@ -204,7 +227,7 @@ void opt_AddDefine(char *s)
|
|||||||
|
|
||||||
static void opt_ParseDefines(void)
|
static void opt_ParseDefines(void)
|
||||||
{
|
{
|
||||||
int32_t i;
|
uint32_t i;
|
||||||
|
|
||||||
for (i = 0; i < cldefines_index; i += 2)
|
for (i = 0; i < cldefines_index; i += 2)
|
||||||
sym_AddString(cldefines[i], cldefines[i + 1]);
|
sym_AddString(cldefines[i], cldefines[i + 1]);
|
||||||
@@ -217,7 +240,7 @@ void verror(const char *fmt, va_list args)
|
|||||||
{
|
{
|
||||||
fprintf(stderr, "ERROR: ");
|
fprintf(stderr, "ERROR: ");
|
||||||
fstk_Dump();
|
fstk_Dump();
|
||||||
fprintf(stderr, ":\n\t");
|
fprintf(stderr, ":\n ");
|
||||||
vfprintf(stderr, fmt, args);
|
vfprintf(stderr, fmt, args);
|
||||||
fprintf(stderr, "\n");
|
fprintf(stderr, "\n");
|
||||||
nErrors += 1;
|
nErrors += 1;
|
||||||
@@ -232,7 +255,7 @@ void yyerror(const char *fmt, ...)
|
|||||||
va_end(args);
|
va_end(args);
|
||||||
}
|
}
|
||||||
|
|
||||||
void fatalerror(const char *fmt, ...)
|
noreturn_ void fatalerror(const char *fmt, ...)
|
||||||
{
|
{
|
||||||
va_list args;
|
va_list args;
|
||||||
|
|
||||||
@@ -254,7 +277,7 @@ void warning(const char *fmt, ...)
|
|||||||
|
|
||||||
fprintf(stderr, "warning: ");
|
fprintf(stderr, "warning: ");
|
||||||
fstk_Dump();
|
fstk_Dump();
|
||||||
fprintf(stderr, ":\n\t");
|
fprintf(stderr, ":\n ");
|
||||||
vfprintf(stderr, fmt, args);
|
vfprintf(stderr, fmt, args);
|
||||||
fprintf(stderr, "\n");
|
fprintf(stderr, "\n");
|
||||||
|
|
||||||
@@ -264,7 +287,7 @@ void warning(const char *fmt, ...)
|
|||||||
static void print_usage(void)
|
static void print_usage(void)
|
||||||
{
|
{
|
||||||
printf(
|
printf(
|
||||||
"usage: rgbasm [-EhVvw] [-b chars] [-Dname[=value]] [-g chars] [-i path]\n"
|
"usage: rgbasm [-EhLVvw] [-b chars] [-Dname[=value]] [-g chars] [-i path]\n"
|
||||||
" [-M dependfile] [-o outfile] [-p pad_value] file.asm\n");
|
" [-M dependfile] [-o outfile] [-p pad_value] file.asm\n");
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
@@ -280,8 +303,10 @@ int main(int argc, char *argv[])
|
|||||||
|
|
||||||
dependfile = NULL;
|
dependfile = NULL;
|
||||||
|
|
||||||
cldefines_size = 32;
|
/* Initial number of allocated elements in array */
|
||||||
cldefines = reallocarray(cldefines, cldefines_size, 2 * sizeof(void *));
|
cldefines_numindices = 32;
|
||||||
|
cldefines_bufsize = cldefines_numindices * cldefine_entrysize;
|
||||||
|
cldefines = malloc(cldefines_bufsize);
|
||||||
if (!cldefines)
|
if (!cldefines)
|
||||||
fatalerror("No memory for command line defines");
|
fatalerror("No memory for command line defines");
|
||||||
|
|
||||||
@@ -296,17 +321,18 @@ int main(int argc, char *argv[])
|
|||||||
DefaultOptions.gbgfx[3] = '3';
|
DefaultOptions.gbgfx[3] = '3';
|
||||||
DefaultOptions.binary[0] = '0';
|
DefaultOptions.binary[0] = '0';
|
||||||
DefaultOptions.binary[1] = '1';
|
DefaultOptions.binary[1] = '1';
|
||||||
DefaultOptions.fillchar = 0;
|
|
||||||
DefaultOptions.verbose = false;
|
|
||||||
DefaultOptions.haltnop = true;
|
|
||||||
DefaultOptions.exportall = false;
|
DefaultOptions.exportall = false;
|
||||||
|
DefaultOptions.fillchar = 0;
|
||||||
|
DefaultOptions.optimizeloads = true;
|
||||||
|
DefaultOptions.haltnop = true;
|
||||||
|
DefaultOptions.verbose = false;
|
||||||
DefaultOptions.warnings = true;
|
DefaultOptions.warnings = true;
|
||||||
|
|
||||||
opt_SetCurrentOptions(&DefaultOptions);
|
opt_SetCurrentOptions(&DefaultOptions);
|
||||||
|
|
||||||
newopt = CurrentOptions;
|
newopt = CurrentOptions;
|
||||||
|
|
||||||
while ((ch = getopt(argc, argv, "b:D:g:hi:M:o:p:EVvw")) != -1) {
|
while ((ch = getopt(argc, argv, "b:D:Eg:hi:LM:o:p:Vvw")) != -1) {
|
||||||
switch (ch) {
|
switch (ch) {
|
||||||
case 'b':
|
case 'b':
|
||||||
if (strlen(optarg) == 2) {
|
if (strlen(optarg) == 2) {
|
||||||
@@ -338,6 +364,9 @@ int main(int argc, char *argv[])
|
|||||||
case 'i':
|
case 'i':
|
||||||
fstk_AddIncludePath(optarg);
|
fstk_AddIncludePath(optarg);
|
||||||
break;
|
break;
|
||||||
|
case 'L':
|
||||||
|
newopt.optimizeloads = false;
|
||||||
|
break;
|
||||||
case 'M':
|
case 'M':
|
||||||
dependfile = fopen(optarg, "w");
|
dependfile = fopen(optarg, "w");
|
||||||
if (dependfile == NULL)
|
if (dependfile == NULL)
|
||||||
@@ -456,7 +485,7 @@ int main(int argc, char *argv[])
|
|||||||
if (CurrentOptions.verbose) {
|
if (CurrentOptions.verbose) {
|
||||||
printf("Success! %u lines in %d.%02d seconds ", nTotalLines,
|
printf("Success! %u lines in %d.%02d seconds ", nTotalLines,
|
||||||
(int)timespent, ((int)(timespent * 100.0)) % 100);
|
(int)timespent, ((int)(timespent * 100.0)) % 100);
|
||||||
if (timespent == 0)
|
if (timespent < FLT_MIN_EXP)
|
||||||
printf("(INFINITY lines/minute)\n");
|
printf("(INFINITY lines/minute)\n");
|
||||||
else
|
else
|
||||||
printf("(%d lines/minute)\n",
|
printf("(%d lines/minute)\n",
|
||||||
|
|||||||
@@ -1,3 +1,11 @@
|
|||||||
|
/*
|
||||||
|
* This file is part of RGBDS.
|
||||||
|
*
|
||||||
|
* Copyright (c) 1997-2018, Carsten Sorensen and RGBDS contributors.
|
||||||
|
*
|
||||||
|
* SPDX-License-Identifier: MIT
|
||||||
|
*/
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Fixedpoint math routines
|
* Fixedpoint math routines
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -1,3 +1,11 @@
|
|||||||
|
/*
|
||||||
|
* This file is part of RGBDS.
|
||||||
|
*
|
||||||
|
* Copyright (c) 1997-2018, Carsten Sorensen and RGBDS contributors.
|
||||||
|
*
|
||||||
|
* SPDX-License-Identifier: MIT
|
||||||
|
*/
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Outputs an objectfile
|
* Outputs an objectfile
|
||||||
*/
|
*/
|
||||||
@@ -867,19 +875,23 @@ void out_RelLong(struct Expression *expr)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Output a PC-relative byte
|
* Output a PC-relative relocatable byte. Checking will be done to see if it
|
||||||
|
* is an absolute value in disguise.
|
||||||
*/
|
*/
|
||||||
void out_PCRelByte(struct Expression *expr)
|
void out_PCRelByte(struct Expression *expr)
|
||||||
{
|
{
|
||||||
int32_t b = expr->nVal;
|
|
||||||
|
|
||||||
checkcodesection();
|
checkcodesection();
|
||||||
checksectionoverflow(1);
|
checksectionoverflow(1);
|
||||||
b = (b & 0xFFFF) - (nPC + 1);
|
|
||||||
if (nPass == 2 && (b < -128 || b > 127))
|
|
||||||
yyerror("PC-relative value must be 8-bit");
|
|
||||||
|
|
||||||
out_AbsByte(b);
|
/* 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);
|
rpn_Reset(expr);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,18 +1,11 @@
|
|||||||
.\" Copyright © 2010 Anthony J. Bentley <anthony@anjbe.name>
|
|
||||||
.\"
|
.\"
|
||||||
.\" Permission to use, copy, modify, and distribute this software for any
|
.\" This file is part of RGBDS.
|
||||||
.\" purpose with or without fee is hereby granted, provided that the above
|
|
||||||
.\" copyright notice and this permission notice appear in all copies.
|
|
||||||
.\"
|
.\"
|
||||||
.\" THE SOFTWARE IS PROVIDED “AS IS” AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
.\" Copyright (c) 2010-2018, Anthony J. Bentley and RGBDS contributors.
|
||||||
.\" WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
|
||||||
.\" MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
|
||||||
.\" ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
|
||||||
.\" WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
|
||||||
.\" ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
|
||||||
.\" OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
|
||||||
.\"
|
.\"
|
||||||
.Dd April 17, 2017
|
.\" SPDX-License-Identifier: MIT
|
||||||
|
.\"
|
||||||
|
.Dd February 24, 2018
|
||||||
.Dt RGBASM 1
|
.Dt RGBASM 1
|
||||||
.Os RGBDS Manual
|
.Os RGBDS Manual
|
||||||
.Sh NAME
|
.Sh NAME
|
||||||
@@ -20,7 +13,7 @@
|
|||||||
.Nd Game Boy assembler
|
.Nd Game Boy assembler
|
||||||
.Sh SYNOPSIS
|
.Sh SYNOPSIS
|
||||||
.Nm rgbasm
|
.Nm rgbasm
|
||||||
.Op Fl EhVvw
|
.Op Fl EhLVvw
|
||||||
.Op Fl b Ar chars
|
.Op Fl b Ar chars
|
||||||
.Op Fl D Ar name Ns Op = Ns Ar value
|
.Op Fl D Ar name Ns Op = Ns Ar value
|
||||||
.Op Fl g Ar chars
|
.Op Fl g Ar chars
|
||||||
@@ -62,6 +55,12 @@ The
|
|||||||
option disables this behavior.
|
option disables this behavior.
|
||||||
.It Fl i Ar path
|
.It Fl i Ar path
|
||||||
Add an include path.
|
Add an include path.
|
||||||
|
.It Fl L
|
||||||
|
Disable the optimization that turns loads of the form
|
||||||
|
.Sy LD [$FF00+n8],A
|
||||||
|
into the opcode
|
||||||
|
.Sy LDH [$FF00+n8],A
|
||||||
|
in order to have full control of the result in the final ROM.
|
||||||
.It Fl M Ar dependfile
|
.It Fl M Ar dependfile
|
||||||
Print
|
Print
|
||||||
.Xr make 1
|
.Xr make 1
|
||||||
@@ -82,7 +81,9 @@ Disable warning output.
|
|||||||
.Sh EXAMPLES
|
.Sh EXAMPLES
|
||||||
Assembling a basic source file is simple:
|
Assembling a basic source file is simple:
|
||||||
.Pp
|
.Pp
|
||||||
.D1 $ rgbasm -o bar.o foo.asm
|
.Bd -literal -offset indent
|
||||||
|
$ rgbasm -o bar.o foo.asm
|
||||||
|
.Ed
|
||||||
.Pp
|
.Pp
|
||||||
The resulting object file is not yet a usable ROM image \(em it must first be
|
The resulting object file is not yet a usable ROM image \(em it must first be
|
||||||
run through
|
run through
|
||||||
|
|||||||
195
src/asm/rgbasm.5
195
src/asm/rgbasm.5
@@ -1,18 +1,11 @@
|
|||||||
.\" Copyright (c) 2017-2018 Antonio Nino Diaz <antonio_nd@outlook.com>
|
|
||||||
.\"
|
.\"
|
||||||
.\" Permission to use, copy, modify, and distribute this software for any
|
.\" This file is part of RGBDS.
|
||||||
.\" purpose with or without fee is hereby granted, provided that the above
|
|
||||||
.\" copyright notice and this permission notice appear in all copies.
|
|
||||||
.\"
|
.\"
|
||||||
.\" THE SOFTWARE IS PROVIDED “AS IS” AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
.\" Copyright (c) 2017-2018, Antonio Nino Diaz and RGBDS contributors.
|
||||||
.\" WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
|
||||||
.\" MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
|
||||||
.\" ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
|
||||||
.\" WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
|
||||||
.\" ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
|
||||||
.\" OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
|
||||||
.\"
|
.\"
|
||||||
.Dd January 7, 2018
|
.\" SPDX-License-Identifier: MIT
|
||||||
|
.\"
|
||||||
|
.Dd March 13, 2018
|
||||||
.Dt RGBASM 5
|
.Dt RGBASM 5
|
||||||
.Os RGBDS Manual
|
.Os RGBDS Manual
|
||||||
.Sh NAME
|
.Sh NAME
|
||||||
@@ -33,16 +26,46 @@ one instruction or pseudo‐op per line:
|
|||||||
.Pp
|
.Pp
|
||||||
Example:
|
Example:
|
||||||
.Pp
|
.Pp
|
||||||
.Dl John: ld a,87 ;Weee
|
.Bd -literal -offset indent
|
||||||
|
John: ld a,87 ;Weee
|
||||||
|
.Ed
|
||||||
.Pp
|
.Pp
|
||||||
All pseudo‐ops, mnemonics and registers (reserved keywords) are case‐insensitive
|
All pseudo‐ops, mnemonics and registers (reserved keywords) are case‐insensitive
|
||||||
and all labels are case‐sensitive.
|
and all labels are case‐sensitive.
|
||||||
|
.Pp
|
||||||
|
There are two syntaxes for comments. In both cases, a comment ends at the end of
|
||||||
|
the line. The most common one is: anything that follows a semicolon
|
||||||
|
\[dq]\&;\[dq] (that isn't inside a string) is a comment. There is another
|
||||||
|
format: anything that follows a \[dq]*\[dq] that is placed right at the start of
|
||||||
|
a line is a comment. The assembler removes all comments from the code before
|
||||||
|
doing anything else.
|
||||||
|
.Pp
|
||||||
|
Sometimes lines can be too long and it may be necessary to split them. The
|
||||||
|
syntax to do so is the following one:
|
||||||
|
.Pp
|
||||||
|
.Bd -literal -offset indent
|
||||||
|
DB 1, 2, 3, 4 \[rs]
|
||||||
|
5, 6, 7, 8
|
||||||
|
.Ed
|
||||||
|
.Pp
|
||||||
|
This works anywhere in the code except inside of strings. To split strings it is
|
||||||
|
needed to use
|
||||||
|
.Sy STRCAT
|
||||||
|
like this:
|
||||||
|
.Pp
|
||||||
|
.Bd -literal -offset indent
|
||||||
|
DB STRCAT("Hello ", \[rs]
|
||||||
|
"world!")
|
||||||
|
.Ed
|
||||||
|
.Pp
|
||||||
.Ss Sections
|
.Ss Sections
|
||||||
Before you can start writing code, you must define a section.
|
Before you can start writing code, you must define a section.
|
||||||
This tells the assembler what kind of information follows and, if it is code,
|
This tells the assembler what kind of information follows and, if it is code,
|
||||||
where to put it.
|
where to put it.
|
||||||
.Pp
|
.Pp
|
||||||
.Dl SECTION \[dq]CoolStuff\[dq],ROMX
|
.Bd -literal -offset indent
|
||||||
|
SECTION \[dq]CoolStuff\[dq],ROMX
|
||||||
|
.Ed
|
||||||
.Pp
|
.Pp
|
||||||
This switches to the section called "CoolStuff" (or creates it if it doesn't
|
This switches to the section called "CoolStuff" (or creates it if it doesn't
|
||||||
already exist) and it defines it as a code section.
|
already exist) and it defines it as a code section.
|
||||||
@@ -111,7 +134,13 @@ and
|
|||||||
.Sy LDH A,[$FF00+n8]
|
.Sy LDH A,[$FF00+n8]
|
||||||
syntax instead.
|
syntax instead.
|
||||||
This forces the assembler to emit the correct instruction and the linker to
|
This forces the assembler to emit the correct instruction and the linker to
|
||||||
check if the value is in the correct range.
|
check if the value is in the correct range. This optimization can be disabled
|
||||||
|
by passing the
|
||||||
|
.Fl L
|
||||||
|
flag to
|
||||||
|
.Sy rgbasm
|
||||||
|
as explained in
|
||||||
|
.Xr rgbasm 1 .
|
||||||
.El
|
.El
|
||||||
.Pp
|
.Pp
|
||||||
A section is usually defined as a floating one, but the code can restrict where
|
A section is usually defined as a floating one, but the code can restrict where
|
||||||
@@ -123,22 +152,30 @@ obligation to follow any specific rules.
|
|||||||
The following example defines a section that can be placed anywhere in any ROMX
|
The following example defines a section that can be placed anywhere in any ROMX
|
||||||
bank:
|
bank:
|
||||||
.Pp
|
.Pp
|
||||||
.Dl SECTION \[dq]CoolStuff\[dq],ROMX
|
.Bd -literal -offset indent
|
||||||
|
SECTION \[dq]CoolStuff\[dq],ROMX
|
||||||
|
.Ed
|
||||||
.Pp
|
.Pp
|
||||||
If it is needed, the following syntax can be used to fix the base address of the
|
If it is needed, the following syntax can be used to fix the base address of the
|
||||||
section:
|
section:
|
||||||
.Pp
|
.Pp
|
||||||
.Dl SECTION \[dq]CoolStuff\[dq],ROMX[$4567]
|
.Bd -literal -offset indent
|
||||||
|
SECTION \[dq]CoolStuff\[dq],ROMX[$4567]
|
||||||
|
.Ed
|
||||||
.Pp
|
.Pp
|
||||||
It won't, however, fix the bank number, which is left to the linker.
|
It won't, however, fix the bank number, which is left to the linker.
|
||||||
If you also want to specify the bank you can do:
|
If you also want to specify the bank you can do:
|
||||||
.Pp
|
.Pp
|
||||||
.Dl SECTION \[dq]CoolStuff\[dq],ROMX[$4567],BANK[3]
|
.Bd -literal -offset indent
|
||||||
|
SECTION \[dq]CoolStuff\[dq],ROMX[$4567],BANK[3]
|
||||||
|
.Ed
|
||||||
.Pp
|
.Pp
|
||||||
And if you only want to force the section into a certain bank, and not it's
|
And if you only want to force the section into a certain bank, and not it's
|
||||||
position within the bank, that's also possible:
|
position within the bank, that's also possible:
|
||||||
.Pp
|
.Pp
|
||||||
.Dl SECTION \[dq]CoolStuff\[dq],ROMX,BANK[7]
|
.Bd -literal -offset indent
|
||||||
|
SECTION \[dq]CoolStuff\[dq],ROMX,BANK[7]
|
||||||
|
.Ed
|
||||||
.Pp
|
.Pp
|
||||||
In addition, you can specify byte alignment for a section.
|
In addition, you can specify byte alignment for a section.
|
||||||
This ensures that the section starts at a memory address where the given number
|
This ensures that the section starts at a memory address where the given number
|
||||||
@@ -150,9 +187,11 @@ However, if an alignment is specified, the base address must be left unassigned.
|
|||||||
This can be useful when using DMA to copy data or when it is needed to align the
|
This can be useful when using DMA to copy data or when it is needed to align the
|
||||||
start of an array to 256 bytes to optimize the code that accesses it.
|
start of an array to 256 bytes to optimize the code that accesses it.
|
||||||
.Pp
|
.Pp
|
||||||
.Dl SECTION \[dq]OAM Data\[dq],WRAM0,ALIGN[8] ; align to 256 bytes
|
.Bd -literal -offset indent
|
||||||
.Pp
|
SECTION \[dq]OAM Data\[dq],WRAM0,ALIGN[8] ; align to 256 bytes
|
||||||
.Dl SECTION \[dq]VRAM Data\[dq],ROMX,BANK[2],ALIGN[4] ; align to 16 bytes
|
|
||||||
|
SECTION \[dq]VRAM Data\[dq],ROMX,BANK[2],ALIGN[4] ; align to 16 bytes
|
||||||
|
.Ed
|
||||||
.Pp
|
.Pp
|
||||||
HINT: If you think this is a lot of typing for doing a simple
|
HINT: If you think this is a lot of typing for doing a simple
|
||||||
.Ic ORG
|
.Ic ORG
|
||||||
@@ -250,8 +289,10 @@ EQUates are constant symbols.
|
|||||||
They can, for example, be used for things such as bit-definitions of hardware
|
They can, for example, be used for things such as bit-definitions of hardware
|
||||||
registers.
|
registers.
|
||||||
.Pp
|
.Pp
|
||||||
.Dl EXIT_OK EQU $00
|
.Bd -literal -offset indent
|
||||||
.Dl EXIT_FAILURE EQU $01
|
EXIT_OK EQU $00
|
||||||
|
EXIT_FAILURE EQU $01
|
||||||
|
.Ed
|
||||||
.Pp
|
.Pp
|
||||||
Note that a colon (:) following the label-name is not allowed.
|
Note that a colon (:) following the label-name is not allowed.
|
||||||
EQUates cannot be exported and imported.
|
EQUates cannot be exported and imported.
|
||||||
@@ -273,7 +314,9 @@ Note that a colon (:) following the label-name is not allowed.
|
|||||||
SETs cannot be exported and imported.
|
SETs cannot be exported and imported.
|
||||||
Alternatively you can use = as a synonym for SET.
|
Alternatively you can use = as a synonym for SET.
|
||||||
.Pp
|
.Pp
|
||||||
.Dl COUNT = 2
|
.Bd -literal -offset indent
|
||||||
|
COUNT = 2
|
||||||
|
.Ed
|
||||||
.Pp
|
.Pp
|
||||||
.It Sy RSSET , RSRESET , RB , RW
|
.It Sy RSSET , RSRESET , RB , RW
|
||||||
.Pp
|
.Pp
|
||||||
@@ -300,7 +343,7 @@ There are four commands in the RS group of commands:
|
|||||||
.Pp
|
.Pp
|
||||||
.Bl -column ".Sy String" ".Sy String"
|
.Bl -column ".Sy String" ".Sy String"
|
||||||
.It Sy Command Ta Ta Ta Sy Meaning
|
.It Sy Command Ta Ta Ta Sy Meaning
|
||||||
.It Ic RSRESET No Ta Ta Resets the _RS counter to zero.
|
.It Ic RSRESET Ta Ta Resets the _RS counter to zero.
|
||||||
.It Ic RSSET Ar constexpr Ta Sets the
|
.It Ic RSSET Ar constexpr Ta Sets the
|
||||||
.Ic _RS No counter to Ar constexpr .
|
.Ic _RS No counter to Ar constexpr .
|
||||||
.It Ic RB Ar constexpr Ta Sets the preceding symbol to
|
.It Ic RB Ar constexpr Ta Sets the preceding symbol to
|
||||||
@@ -325,10 +368,10 @@ If you are familiar with C you can think of it as the same as #define.
|
|||||||
.Pp
|
.Pp
|
||||||
.Bd -literal -offset indent
|
.Bd -literal -offset indent
|
||||||
COUNTREG EQUS "[hl+]"
|
COUNTREG EQUS "[hl+]"
|
||||||
ld a,COUNTREG
|
ld a,COUNTREG
|
||||||
|
|
||||||
PLAYER_NAME EQUS \[dq]\[rs]\[dq]John\[rs]\[dq]\[dq]
|
PLAYER_NAME EQUS \[dq]\[rs]\[dq]John\[rs]\[dq]\[dq]
|
||||||
db PLAYER_NAME
|
db PLAYER_NAME
|
||||||
.Ed
|
.Ed
|
||||||
.Pp
|
.Pp
|
||||||
Note that : following the label-name is not allowed, and that strings must be
|
Note that : following the label-name is not allowed, and that strings must be
|
||||||
@@ -336,12 +379,16 @@ quoted to be useful.
|
|||||||
.Pp
|
.Pp
|
||||||
This will be interpreted as:
|
This will be interpreted as:
|
||||||
.Pp
|
.Pp
|
||||||
.Dl ld a,[hl+]
|
.Bd -literal -offset indent
|
||||||
.Dl db \[dq]John\[dq]
|
ld a,[hl+]
|
||||||
|
db \[dq]John\[dq]
|
||||||
|
.Ed
|
||||||
.Pp
|
.Pp
|
||||||
String-symbols can also be used to define small one-line macros:
|
String-symbols can also be used to define small one-line macros:
|
||||||
.Pp
|
.Pp
|
||||||
.Dl PUSHA EQUS \[dq]push af\[rs]npush bc\[rs]npush de\[rs]npush hl\[rs]n\[dq]
|
.Bd -literal -offset indent
|
||||||
|
PUSHA EQUS \[dq]push af\[rs]npush bc\[rs]npush de\[rs]npush hl\[rs]n\[dq]
|
||||||
|
.Ed
|
||||||
.Pp
|
.Pp
|
||||||
Note that a colon (:) following the label-name is not allowed.
|
Note that a colon (:) following the label-name is not allowed.
|
||||||
String equates can't be exported or imported.
|
String equates can't be exported or imported.
|
||||||
@@ -454,7 +501,9 @@ Now I can call the macro specifying two arguments.
|
|||||||
The first being the address and the second being a bytecount.
|
The first being the address and the second being a bytecount.
|
||||||
The macro will then reset all bytes in this range.
|
The macro will then reset all bytes in this range.
|
||||||
.Pp
|
.Pp
|
||||||
.Dl LoopyMacro MyVars,54
|
.Bd -literal -offset indent
|
||||||
|
LoopyMacro MyVars,54
|
||||||
|
.Ed
|
||||||
.Pp
|
.Pp
|
||||||
Arguments are passed as string equates.
|
Arguments are passed as string equates.
|
||||||
There's no need to enclose them in quotes.
|
There's no need to enclose them in quotes.
|
||||||
@@ -474,6 +523,19 @@ In reality, up to 256 arguments can be passed to a macro, but you can only use
|
|||||||
the first 9 like this. If you want to use the rest, you need to use the keyword
|
the first 9 like this. If you want to use the rest, you need to use the keyword
|
||||||
.Ic SHIFT .
|
.Ic SHIFT .
|
||||||
.Pp
|
.Pp
|
||||||
|
Line continuations work as usual inside macros or lists of arguments of macros.
|
||||||
|
Strings, however, are a bit trickier. The following example shows how to use
|
||||||
|
strings as arguments for a macro:
|
||||||
|
.Pp
|
||||||
|
.Bd -literal -offset indent
|
||||||
|
PrintMacro : MACRO
|
||||||
|
PRINTT \[rs]1
|
||||||
|
ENDM
|
||||||
|
|
||||||
|
PrintMacro STRCAT(\[rs]\[dq]Hello\[rs]\[dq]\[rs], \[rs]
|
||||||
|
\[rs]\[dq] world\[rs]\[rs]n\[rs]\[dq])
|
||||||
|
.Ed
|
||||||
|
.Pp
|
||||||
.Ic SHIFT
|
.Ic SHIFT
|
||||||
is a special command only available in macros.
|
is a special command only available in macros.
|
||||||
Very useful in REPT-blocks.
|
Very useful in REPT-blocks.
|
||||||
@@ -560,7 +622,9 @@ The following symbols are defined by the assembler:
|
|||||||
defines a list of bytes that will be stored in the final image.
|
defines a list of bytes that will be stored in the final image.
|
||||||
Ideal for tables and text (which is not zero-terminated).
|
Ideal for tables and text (which is not zero-terminated).
|
||||||
.Pp
|
.Pp
|
||||||
.Dl DB 1,2,3,4,\[dq]This is a string\[dq]
|
.Bd -literal -offset indent
|
||||||
|
DB 1,2,3,4,\[dq]This is a string\[dq]
|
||||||
|
.Ed
|
||||||
.Pp
|
.Pp
|
||||||
Alternatively, you can use
|
Alternatively, you can use
|
||||||
.Ic DW
|
.Ic DW
|
||||||
@@ -604,7 +668,9 @@ and
|
|||||||
.Ic DL
|
.Ic DL
|
||||||
without any arguments instead.
|
without any arguments instead.
|
||||||
.Pp
|
.Pp
|
||||||
.Dl DS str_SIZEOF ;allocate str_SIZEOF bytes
|
.Bd -literal -offset indent
|
||||||
|
DS str_SIZEOF ;allocate str_SIZEOF bytes
|
||||||
|
.Ed
|
||||||
.Pp
|
.Pp
|
||||||
.Ss Including binary files
|
.Ss Including binary files
|
||||||
You probably have some graphics you'd like to include.
|
You probably have some graphics you'd like to include.
|
||||||
@@ -614,15 +680,19 @@ to include a raw binary file as it is.
|
|||||||
If the file isn't found in the current directory, the include-path list passed
|
If the file isn't found in the current directory, the include-path list passed
|
||||||
to the linker on the command line will be searched.
|
to the linker on the command line will be searched.
|
||||||
.Pp
|
.Pp
|
||||||
.Dl INCBIN \[dq]titlepic.bin\[dq]
|
.Bd -literal -offset indent
|
||||||
.Dl INCBIN \[dq]sprites/hero.bin\[dq]\ ; UNIX
|
INCBIN \[dq]titlepic.bin\[dq]
|
||||||
.Dl INCBIN \[dq]sprites\[rs]\[rs]hero.bin\[dq]\ ; Windows
|
INCBIN \[dq]sprites/hero.bin\[dq]\ ; UNIX
|
||||||
|
INCBIN \[dq]sprites\[rs]\[rs]hero.bin\[dq]\ ; Windows
|
||||||
|
.Ed
|
||||||
.Pp
|
.Pp
|
||||||
You can also include only part of a file with
|
You can also include only part of a file with
|
||||||
.Ic INCBIN .
|
.Ic INCBIN .
|
||||||
The example below includes 256 bytes from data.bin starting from byte 78.
|
The example below includes 256 bytes from data.bin starting from byte 78.
|
||||||
.Pp
|
.Pp
|
||||||
.Dl INCBIN \[dq]data.bin\[dq],78,256
|
.Bd -literal -offset indent
|
||||||
|
INCBIN \[dq]data.bin\[dq],78,256
|
||||||
|
.Ed
|
||||||
.Ss Unions
|
.Ss Unions
|
||||||
Unions allow multiple memory allocations to share the same space in memory,
|
Unions allow multiple memory allocations to share the same space in memory,
|
||||||
like unions in C.
|
like unions in C.
|
||||||
@@ -667,16 +737,19 @@ some important information.
|
|||||||
.Pp
|
.Pp
|
||||||
.Bd -literal -offset indent
|
.Bd -literal -offset indent
|
||||||
PRINTT \[dq]I'm the greatest programmer in the whole wide world\[rs]n\[dq]
|
PRINTT \[dq]I'm the greatest programmer in the whole wide world\[rs]n\[dq]
|
||||||
PRINTV (2+3)/5
|
PRINTI (2 + 3) / 5
|
||||||
PRINTF MUL(3.14,3987.0)
|
PRINTV $FF00 + $F0
|
||||||
|
PRINTF MUL(3.14, 3987.0)
|
||||||
.Ed
|
.Ed
|
||||||
.Pp
|
.Pp
|
||||||
.Bl -inset
|
.Bl -inset
|
||||||
.It Ic PRINTT
|
.It Ic PRINTT
|
||||||
prints out a string.
|
prints out a string.
|
||||||
.It Ic PRINTV
|
.It Ic PRINTV
|
||||||
prints out an integer value or, as in the example, the result of a calculation.
|
prints out an integer value in hexadecimal or, as in the example, the result of
|
||||||
Unsurprisingly, you can also print out a constant symbols value.
|
a calculation. Unsurprisingly, you can also print out a constant symbols value.
|
||||||
|
.It Ic PRINTI
|
||||||
|
prints out a signed integer value.
|
||||||
.It Ic PRINTF
|
.It Ic PRINTF
|
||||||
prints out a fixed point value.
|
prints out a fixed point value.
|
||||||
.El
|
.El
|
||||||
@@ -747,7 +820,9 @@ You may nest
|
|||||||
.Ic INCLUDE
|
.Ic INCLUDE
|
||||||
calls infinitely (or until you run out of memory, whichever comes first).
|
calls infinitely (or until you run out of memory, whichever comes first).
|
||||||
.Pp
|
.Pp
|
||||||
.Dl INCLUDE \[dq]irq.inc\[dq]
|
.Bd -literal -offset indent
|
||||||
|
INCLUDE \[dq]irq.inc\[dq]
|
||||||
|
.Ed
|
||||||
.Pp
|
.Pp
|
||||||
.Ss Conditional assembling
|
.Ss Conditional assembling
|
||||||
The four commands
|
The four commands
|
||||||
@@ -823,7 +898,9 @@ The last one, Gameboy graphics, is quite interesting and useful.
|
|||||||
The values are actually pixel values and it converts the
|
The values are actually pixel values and it converts the
|
||||||
.Do chunky Dc data to Do planar Dc data as used in the Gameboy.
|
.Do chunky Dc data to Do planar Dc data as used in the Gameboy.
|
||||||
.Pp
|
.Pp
|
||||||
.Dl DW \`01012323
|
.Bd -literal -offset indent
|
||||||
|
DW \`01012323
|
||||||
|
.Ed
|
||||||
.Pp
|
.Pp
|
||||||
Admittedly, an expression with just a single number is quite boring.
|
Admittedly, an expression with just a single number is quite boring.
|
||||||
To spice things up a bit there are a few operators you can use to perform
|
To spice things up a bit there are a few operators you can use to perform
|
||||||
@@ -964,6 +1041,34 @@ new string.
|
|||||||
the new string.
|
the new string.
|
||||||
.El
|
.El
|
||||||
.Pp
|
.Pp
|
||||||
|
.Ss Character maps
|
||||||
|
.Pp
|
||||||
|
When writing text that is meant to be displayed in the Game Boy, the ASCII
|
||||||
|
characters used in the source code may not be the same ones used in the tileset
|
||||||
|
used in the ROM.
|
||||||
|
For example, the tiles used for uppercase letters may be placed starting at tile
|
||||||
|
index 128, which makes it difficult to add text strings to the ROM.
|
||||||
|
.Pp
|
||||||
|
Character maps allow the code to map strings up to 16 characters long to an
|
||||||
|
abitrary 8-bit value:
|
||||||
|
.Pp
|
||||||
|
.Bd -literal -offset indent
|
||||||
|
CHARMAP "<LF>", 10
|
||||||
|
CHARMAP "í", 20
|
||||||
|
CHARMAP "A", 128
|
||||||
|
.Ed
|
||||||
|
.Pp
|
||||||
|
.Sy Note:
|
||||||
|
Character maps affect all strings in the file from the point in which they are
|
||||||
|
defined.
|
||||||
|
This means that any string that the code may want to print as debug information
|
||||||
|
will also be affected by it.
|
||||||
|
.Pp
|
||||||
|
.Sy Note:
|
||||||
|
The output value of a mapping can be 0.
|
||||||
|
If this happens, the assembler will treat this as the end of the string and the
|
||||||
|
rest of it will be trimmed.
|
||||||
|
.Pp
|
||||||
.Ss Other functions
|
.Ss Other functions
|
||||||
There are a few other functions that do various useful things:
|
There are a few other functions that do various useful things:
|
||||||
.Pp
|
.Pp
|
||||||
@@ -1046,6 +1151,7 @@ machine.
|
|||||||
.It Sx ATAN
|
.It Sx ATAN
|
||||||
.It Sx ATAN2
|
.It Sx ATAN2
|
||||||
.It Sx BANK
|
.It Sx BANK
|
||||||
|
.It Sx CHARMAP
|
||||||
.It Sx COS
|
.It Sx COS
|
||||||
.It Sx DB
|
.It Sx DB
|
||||||
.It Sx DEF
|
.It Sx DEF
|
||||||
@@ -1075,6 +1181,7 @@ machine.
|
|||||||
.It Sx POPO
|
.It Sx POPO
|
||||||
.It Sx POPS
|
.It Sx POPS
|
||||||
.It Sx PRINTF
|
.It Sx PRINTF
|
||||||
|
.It Sx PRINTI
|
||||||
.It Sx PRINTT
|
.It Sx PRINTT
|
||||||
.It Sx PRINTV
|
.It Sx PRINTV
|
||||||
.It Sx PURGE
|
.It Sx PURGE
|
||||||
|
|||||||
@@ -1,3 +1,11 @@
|
|||||||
|
/*
|
||||||
|
* This file is part of RGBDS.
|
||||||
|
*
|
||||||
|
* Copyright (c) 1997-2018, Carsten Sorensen and RGBDS contributors.
|
||||||
|
*
|
||||||
|
* SPDX-License-Identifier: MIT
|
||||||
|
*/
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Controls RPN expressions for objectfiles
|
* Controls RPN expressions for objectfiles
|
||||||
*/
|
*/
|
||||||
@@ -322,6 +330,15 @@ void rpn_SHL(struct Expression *expr, const struct Expression *src1,
|
|||||||
const struct Expression *src2)
|
const struct Expression *src2)
|
||||||
{
|
{
|
||||||
joinexpr();
|
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);
|
expr->nVal = (expr->nVal << src2->nVal);
|
||||||
pushbyte(expr, RPN_SHL);
|
pushbyte(expr, RPN_SHL);
|
||||||
}
|
}
|
||||||
@@ -330,6 +347,11 @@ void rpn_SHR(struct Expression *expr, const struct Expression *src1,
|
|||||||
const struct Expression *src2)
|
const struct Expression *src2)
|
||||||
{
|
{
|
||||||
joinexpr();
|
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);
|
expr->nVal = (expr->nVal >> src2->nVal);
|
||||||
pushbyte(expr, RPN_SHR);
|
pushbyte(expr, RPN_SHR);
|
||||||
}
|
}
|
||||||
@@ -347,7 +369,7 @@ void rpn_DIV(struct Expression *expr, const struct Expression *src1,
|
|||||||
{
|
{
|
||||||
joinexpr();
|
joinexpr();
|
||||||
if (src2->nVal == 0)
|
if (src2->nVal == 0)
|
||||||
fatalerror("division by zero");
|
fatalerror("Division by zero");
|
||||||
|
|
||||||
expr->nVal = (expr->nVal / src2->nVal);
|
expr->nVal = (expr->nVal / src2->nVal);
|
||||||
pushbyte(expr, RPN_DIV);
|
pushbyte(expr, RPN_DIV);
|
||||||
@@ -358,7 +380,7 @@ void rpn_MOD(struct Expression *expr, const struct Expression *src1,
|
|||||||
{
|
{
|
||||||
joinexpr();
|
joinexpr();
|
||||||
if (src2->nVal == 0)
|
if (src2->nVal == 0)
|
||||||
fatalerror("division by zero");
|
fatalerror("Division by zero");
|
||||||
|
|
||||||
expr->nVal = (expr->nVal % src2->nVal);
|
expr->nVal = (expr->nVal % src2->nVal);
|
||||||
pushbyte(expr, RPN_MOD);
|
pushbyte(expr, RPN_MOD);
|
||||||
|
|||||||
@@ -1,3 +1,11 @@
|
|||||||
|
/*
|
||||||
|
* This file is part of RGBDS.
|
||||||
|
*
|
||||||
|
* Copyright (c) 1997-2018, Carsten Sorensen and RGBDS contributors.
|
||||||
|
*
|
||||||
|
* SPDX-License-Identifier: MIT
|
||||||
|
*/
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Symboltable and macroargs stuff
|
* Symboltable and macroargs stuff
|
||||||
*/
|
*/
|
||||||
@@ -16,7 +24,9 @@
|
|||||||
#include "asm/output.h"
|
#include "asm/output.h"
|
||||||
|
|
||||||
#include "extern/err.h"
|
#include "extern/err.h"
|
||||||
#include "extern/version.h"
|
|
||||||
|
#include "helpers.h"
|
||||||
|
#include "version.h"
|
||||||
|
|
||||||
struct sSymbol *tHashedSymbols[HASHSIZE];
|
struct sSymbol *tHashedSymbols[HASHSIZE];
|
||||||
static struct sSymbol *pScope; /* Current section symbol scope */
|
static struct sSymbol *pScope; /* Current section symbol scope */
|
||||||
@@ -31,7 +41,7 @@ static char SavedTIMESTAMP_ISO8601_LOCAL[256];
|
|||||||
static char SavedTIMESTAMP_ISO8601_UTC[256];
|
static char SavedTIMESTAMP_ISO8601_UTC[256];
|
||||||
static char SavedDAY[3];
|
static char SavedDAY[3];
|
||||||
static char SavedMONTH[3];
|
static char SavedMONTH[3];
|
||||||
static char SavedYEAR[5];
|
static char SavedYEAR[20];
|
||||||
static char SavedHOUR[3];
|
static char SavedHOUR[3];
|
||||||
static char SavedMINUTE[3];
|
static char SavedMINUTE[3];
|
||||||
static char SavedSECOND[3];
|
static char SavedSECOND[3];
|
||||||
@@ -53,7 +63,7 @@ void helper_RemoveLeadingZeros(char *string)
|
|||||||
memmove(string, new_beginning, strlen(new_beginning) + 1);
|
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;
|
uint32_t i = 0;
|
||||||
|
|
||||||
@@ -63,7 +73,7 @@ int32_t Callback_NARG(struct sSymbol *sym)
|
|||||||
return i;
|
return i;
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t Callback__LINE__(struct sSymbol __attribute__((unused)) *sym)
|
int32_t Callback__LINE__(unused_ struct sSymbol *sym)
|
||||||
{
|
{
|
||||||
return nLineNo;
|
return nLineNo;
|
||||||
}
|
}
|
||||||
@@ -113,7 +123,9 @@ struct sSymbol *createsymbol(char *s)
|
|||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
strcpy((*ppsym)->tzName, s);
|
if (snprintf((*ppsym)->tzName, MAXSYMLEN + 1, "%s", s) > MAXSYMLEN)
|
||||||
|
warning("Symbol name is too long: '%s'", s);
|
||||||
|
|
||||||
(*ppsym)->nValue = 0;
|
(*ppsym)->nValue = 0;
|
||||||
(*ppsym)->nType = 0;
|
(*ppsym)->nType = 0;
|
||||||
(*ppsym)->pScope = NULL;
|
(*ppsym)->pScope = NULL;
|
||||||
@@ -121,7 +133,13 @@ struct sSymbol *createsymbol(char *s)
|
|||||||
(*ppsym)->pMacro = NULL;
|
(*ppsym)->pMacro = NULL;
|
||||||
(*ppsym)->pSection = NULL;
|
(*ppsym)->pSection = NULL;
|
||||||
(*ppsym)->Callback = NULL;
|
(*ppsym)->Callback = NULL;
|
||||||
strcpy((*ppsym)->tzFileName, tzCurrentFileName);
|
|
||||||
|
if (snprintf((*ppsym)->tzFileName, _MAX_PATH + 1, "%s",
|
||||||
|
tzCurrentFileName) > _MAX_PATH) {
|
||||||
|
fatalerror("%s: File name is too long: '%s'", __func__,
|
||||||
|
tzCurrentFileName);
|
||||||
|
}
|
||||||
|
|
||||||
(*ppsym)->nFileLine = fstk_GetLine();
|
(*ppsym)->nFileLine = fstk_GetLine();
|
||||||
return *ppsym;
|
return *ppsym;
|
||||||
}
|
}
|
||||||
@@ -500,7 +518,7 @@ void sym_SetMacroArgID(uint32_t nMacroCount)
|
|||||||
{
|
{
|
||||||
char s[256];
|
char s[256];
|
||||||
|
|
||||||
sprintf(s, "_%u", nMacroCount);
|
snprintf(s, sizeof(s), "_%u", nMacroCount);
|
||||||
newmacroargs[MAXMACROARGS] = strdup(s);
|
newmacroargs[MAXMACROARGS] = strdup(s);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -551,7 +569,7 @@ void sym_AddEqu(char *tzSym, int32_t value)
|
|||||||
*
|
*
|
||||||
* If the desired symbol is a string it needs to be passed to this function with
|
* If the desired symbol is a string it needs to be passed to this function with
|
||||||
* quotes inside the string, like sym_AddString("name", "\"test\"), or the
|
* quotes inside the string, like sym_AddString("name", "\"test\"), or the
|
||||||
* assembler won't be able to use it with DB and similar. This is equivalent as
|
* assembler won't be able to use it with DB and similar. This is equivalent to
|
||||||
* ``` name EQUS "\"test\"" ```
|
* ``` name EQUS "\"test\"" ```
|
||||||
*
|
*
|
||||||
* If the desired symbol is a register or a number, just the terminator quotes
|
* If the desired symbol is a register or a number, just the terminator quotes
|
||||||
@@ -656,7 +674,7 @@ void sym_AddReloc(char *tzSym)
|
|||||||
|
|
||||||
struct sSymbol *parent = pScope->pScope ?
|
struct sSymbol *parent = pScope->pScope ?
|
||||||
pScope->pScope : pScope;
|
pScope->pScope : pScope;
|
||||||
int32_t parentLen = localPtr - tzSym;
|
uint32_t parentLen = localPtr - tzSym;
|
||||||
|
|
||||||
if (strchr(localPtr + 1, '.') != NULL) {
|
if (strchr(localPtr + 1, '.') != NULL) {
|
||||||
fatalerror("'%s' is a nonsensical reference to a nested local symbol",
|
fatalerror("'%s' is a nonsensical reference to a nested local symbol",
|
||||||
@@ -956,16 +974,22 @@ void sym_Init(void)
|
|||||||
* The '?' have to be escaped or they will be treated as
|
* The '?' have to be escaped or they will be treated as
|
||||||
* trigraphs...
|
* trigraphs...
|
||||||
*/
|
*/
|
||||||
strcpy(SavedTIME, "\"\?\?:\?\?:\?\?\"");
|
snprintf(SavedTIME, sizeof(SavedTIME),
|
||||||
strcpy(SavedDATE, "\"\?\? \?\?\? \?\?\?\?\"");
|
"\"\?\?:\?\?:\?\?\"");
|
||||||
strcpy(SavedTIMESTAMP_ISO8601_LOCAL, "\"\?\?\?\?-\?\?-\?\?T\?\?:\?\?:\?\?+\?\?\?\?\"");
|
snprintf(SavedDATE, sizeof(SavedDATE),
|
||||||
strcpy(SavedTIMESTAMP_ISO8601_UTC, "\"\?\?\?\?-\?\?-\?\?T\?\?:\?\?:\?\?Z\"");
|
"\"\?\? \?\?\? \?\?\?\?\"");
|
||||||
strcpy(SavedDAY, "1");
|
snprintf(SavedTIMESTAMP_ISO8601_LOCAL,
|
||||||
strcpy(SavedMONTH, "1");
|
sizeof(SavedTIMESTAMP_ISO8601_LOCAL),
|
||||||
strcpy(SavedYEAR, "1900");
|
"\"\?\?\?\?-\?\?-\?\?T\?\?:\?\?:\?\?+\?\?\?\?\"");
|
||||||
strcpy(SavedHOUR, "0");
|
snprintf(SavedTIMESTAMP_ISO8601_UTC,
|
||||||
strcpy(SavedMINUTE, "0");
|
sizeof(SavedTIMESTAMP_ISO8601_UTC),
|
||||||
strcpy(SavedSECOND, "0");
|
"\"\?\?\?\?-\?\?-\?\?T\?\?:\?\?:\?\?Z\"");
|
||||||
|
snprintf(SavedDAY, sizeof(SavedDAY), "1");
|
||||||
|
snprintf(SavedMONTH, sizeof(SavedMONTH), "1");
|
||||||
|
snprintf(SavedYEAR, sizeof(SavedYEAR), "1900");
|
||||||
|
snprintf(SavedHOUR, sizeof(SavedHOUR), "0");
|
||||||
|
snprintf(SavedMINUTE, sizeof(SavedMINUTE), "0");
|
||||||
|
snprintf(SavedSECOND, sizeof(SavedSECOND), "0");
|
||||||
}
|
}
|
||||||
|
|
||||||
sym_AddString("__TIME__", SavedTIME);
|
sym_AddString("__TIME__", SavedTIME);
|
||||||
|
|||||||
29
src/extern/err.c
vendored
29
src/extern/err.c
vendored
@@ -1,24 +1,9 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright © 2005-2013 Rich Felker, et al.
|
* This file is part of RGBDS.
|
||||||
*
|
*
|
||||||
* Permission is hereby granted, free of charge, to any person obtaining
|
* Copyright (c) 2005-2018, Rich Felker and RGBDS contributors.
|
||||||
* a copy of this software and associated documentation files (the
|
|
||||||
* "Software"), to deal in the Software without restriction, including
|
|
||||||
* without limitation the rights to use, copy, modify, merge, publish,
|
|
||||||
* distribute, sublicense, and/or sell copies of the Software, and to
|
|
||||||
* permit persons to whom the Software is furnished to do so, subject to
|
|
||||||
* the following conditions:
|
|
||||||
*
|
*
|
||||||
* The above copyright notice and this permission notice shall be
|
* SPDX-License-Identifier: MIT
|
||||||
* included in all copies or substantial portions of the Software.
|
|
||||||
*
|
|
||||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
|
||||||
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
|
||||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
|
||||||
* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
|
||||||
* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
|
||||||
* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
|
||||||
* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <stdarg.h>
|
#include <stdarg.h>
|
||||||
@@ -48,7 +33,7 @@ void rgbds_vwarnx(const char *fmt, va_list ap)
|
|||||||
putc('\n', stderr);
|
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");
|
fprintf(stderr, "error");
|
||||||
if (fmt) {
|
if (fmt) {
|
||||||
@@ -59,7 +44,7 @@ noreturn void rgbds_verr(int status, const char *fmt, va_list ap)
|
|||||||
exit(status);
|
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");
|
fprintf(stderr, "error");
|
||||||
if (fmt) {
|
if (fmt) {
|
||||||
@@ -88,7 +73,7 @@ void rgbds_warnx(const char *fmt, ...)
|
|||||||
va_end(ap);
|
va_end(ap);
|
||||||
}
|
}
|
||||||
|
|
||||||
noreturn void rgbds_err(int status, const char *fmt, ...)
|
noreturn_ void rgbds_err(int status, const char *fmt, ...)
|
||||||
{
|
{
|
||||||
va_list ap;
|
va_list ap;
|
||||||
|
|
||||||
@@ -97,7 +82,7 @@ noreturn void rgbds_err(int status, const char *fmt, ...)
|
|||||||
va_end(ap);
|
va_end(ap);
|
||||||
}
|
}
|
||||||
|
|
||||||
noreturn void rgbds_errx(int status, const char *fmt, ...)
|
noreturn_ void rgbds_errx(int status, const char *fmt, ...)
|
||||||
{
|
{
|
||||||
va_list ap;
|
va_list ap;
|
||||||
|
|
||||||
|
|||||||
37
src/extern/reallocarray.c
vendored
37
src/extern/reallocarray.c
vendored
@@ -1,37 +0,0 @@
|
|||||||
/* $OpenBSD: reallocarray.c,v 1.2 2014/12/08 03:45:00 bcook Exp $ */
|
|
||||||
/*
|
|
||||||
* Copyright (c) 2008 Otto Moerbeek <otto@drijf.net>
|
|
||||||
*
|
|
||||||
* Permission to use, copy, modify, and distribute this software for any
|
|
||||||
* purpose with or without fee is hereby granted, provided that the above
|
|
||||||
* copyright notice and this permission notice appear in all copies.
|
|
||||||
*
|
|
||||||
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
|
||||||
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
|
||||||
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
|
||||||
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
|
||||||
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
|
||||||
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
|
||||||
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#include <errno.h>
|
|
||||||
#include <stdint.h>
|
|
||||||
#include <stdlib.h>
|
|
||||||
#include <sys/types.h>
|
|
||||||
|
|
||||||
/*
|
|
||||||
* This is sqrt(SIZE_MAX+1), as s1*s2 <= SIZE_MAX
|
|
||||||
* if both s1 < MUL_NO_OVERFLOW and s2 < MUL_NO_OVERFLOW
|
|
||||||
*/
|
|
||||||
#define MUL_NO_OVERFLOW ((size_t)1 << (sizeof(size_t) * 4))
|
|
||||||
|
|
||||||
void *rgbds_reallocarray(void *optr, size_t nmemb, size_t size)
|
|
||||||
{
|
|
||||||
if (((nmemb >= MUL_NO_OVERFLOW) || (size >= MUL_NO_OVERFLOW)) &&
|
|
||||||
(nmemb > 0) && (SIZE_MAX / nmemb < size)) {
|
|
||||||
errno = ENOMEM;
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
return realloc(optr, size * nmemb);
|
|
||||||
}
|
|
||||||
54
src/extern/strlcat.c
vendored
54
src/extern/strlcat.c
vendored
@@ -1,54 +0,0 @@
|
|||||||
/* $OpenBSD: strlcat.c,v 1.14 2015/01/15 03:54:12 millert Exp $ */
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Copyright (c) 1998, 2015 Todd C. Miller <Todd.Miller@courtesan.com>
|
|
||||||
*
|
|
||||||
* Permission to use, copy, modify, and distribute this software for any
|
|
||||||
* purpose with or without fee is hereby granted, provided that the above
|
|
||||||
* copyright notice and this permission notice appear in all copies.
|
|
||||||
*
|
|
||||||
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
|
||||||
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
|
||||||
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
|
||||||
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
|
||||||
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
|
||||||
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
|
||||||
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#include <string.h>
|
|
||||||
#include <sys/types.h>
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Appends src to string dst of size dsize (unlike strncat, dsize is the
|
|
||||||
* full size of dst, not space left). At most dsize-1 characters
|
|
||||||
* will be copied. Always NUL terminates (unless dsize <= strlen(dst)).
|
|
||||||
* Returns strlen(src) + MIN(dsize, strlen(initial dst)).
|
|
||||||
* If retval >= dsize, truncation occurred.
|
|
||||||
*/
|
|
||||||
size_t rgbds_strlcat(char *dst, const char *src, size_t dsize)
|
|
||||||
{
|
|
||||||
const char *odst = dst;
|
|
||||||
const char *osrc = src;
|
|
||||||
size_t n = dsize;
|
|
||||||
size_t dlen;
|
|
||||||
|
|
||||||
/* Find the end of dst and adjust bytes left but don't go past end. */
|
|
||||||
while (n-- != 0 && *dst != '\0')
|
|
||||||
dst++;
|
|
||||||
dlen = dst - odst;
|
|
||||||
n = dsize - dlen;
|
|
||||||
|
|
||||||
if (n-- == 0)
|
|
||||||
return(dlen + strlen(src));
|
|
||||||
while (*src != '\0') {
|
|
||||||
if (n != 0) {
|
|
||||||
*dst++ = *src;
|
|
||||||
n--;
|
|
||||||
}
|
|
||||||
src++;
|
|
||||||
}
|
|
||||||
*dst = '\0';
|
|
||||||
|
|
||||||
return dlen + (src - osrc); /* count does not include NUL */
|
|
||||||
}
|
|
||||||
52
src/extern/strlcpy.c
vendored
52
src/extern/strlcpy.c
vendored
@@ -1,52 +0,0 @@
|
|||||||
/* $OpenBSD: strlcpy.c,v 1.12 2015/01/15 03:54:12 millert Exp $ */
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Copyright (c) 1998, 2015 Todd C. Miller <Todd.Miller@courtesan.com>
|
|
||||||
*
|
|
||||||
* Permission to use, copy, modify, and distribute this software for any
|
|
||||||
* purpose with or without fee is hereby granted, provided that the above
|
|
||||||
* copyright notice and this permission notice appear in all copies.
|
|
||||||
*
|
|
||||||
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
|
||||||
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
|
||||||
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
|
||||||
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
|
||||||
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
|
||||||
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
|
||||||
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#include <string.h>
|
|
||||||
#include <sys/types.h>
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Copy string src to buffer dst of size dsize. At most dsize-1
|
|
||||||
* chars will be copied. Always NUL terminates (unless dsize == 0).
|
|
||||||
* Returns strlen(src); if retval >= dsize, truncation occurred.
|
|
||||||
*/
|
|
||||||
size_t rgbds_strlcpy(char *dst, const char *src, size_t dsize)
|
|
||||||
{
|
|
||||||
const char *osrc = src;
|
|
||||||
size_t nleft = dsize;
|
|
||||||
|
|
||||||
/* Copy as many bytes as will fit. */
|
|
||||||
if (nleft != 0) {
|
|
||||||
while (--nleft != 0) {
|
|
||||||
char n = *src++;
|
|
||||||
*dst++ = n;
|
|
||||||
|
|
||||||
if (n == '\0')
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Not enough room in dst, add NUL and traverse rest of src. */
|
|
||||||
if (nleft == 0) {
|
|
||||||
if (dsize != 0)
|
|
||||||
*dst = '\0'; /* NUL-terminate dst */
|
|
||||||
while (*src++)
|
|
||||||
;
|
|
||||||
}
|
|
||||||
|
|
||||||
return (src - osrc - 1); /* count does not include NUL */
|
|
||||||
}
|
|
||||||
54
src/extern/utf8decoder.c
vendored
Normal file
54
src/extern/utf8decoder.c
vendored
Normal file
@@ -0,0 +1,54 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2008-2009, Björn Höhrmann <bjoern@hoehrmann.de>
|
||||||
|
*
|
||||||
|
* SPDX-License-Identifier: MIT
|
||||||
|
*/
|
||||||
|
|
||||||
|
/*
|
||||||
|
* UTF-8 decoder: http://bjoern.hoehrmann.de/utf-8/decoder/dfa/
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <stdint.h>
|
||||||
|
|
||||||
|
static const uint8_t utf8d[] = {
|
||||||
|
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 00..0f */
|
||||||
|
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 10..1f */
|
||||||
|
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 20..2f */
|
||||||
|
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 30..3f */
|
||||||
|
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 40..4f */
|
||||||
|
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 50..5f */
|
||||||
|
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 60..6f */
|
||||||
|
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 70..7f */
|
||||||
|
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, /* 80..8f */
|
||||||
|
9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, /* 90..9f */
|
||||||
|
7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, /* a0..af */
|
||||||
|
7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, /* b0..bf */
|
||||||
|
8, 8, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, /* c0..cf */
|
||||||
|
2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, /* d0..df */
|
||||||
|
0xa, 0x3, 0x3, 0x3, 0x3, 0x3, 0x3, 0x3, /* e0..e7 */
|
||||||
|
0x3, 0x3, 0x3, 0x3, 0x3, 0x4, 0x3, 0x3, /* e8..ef */
|
||||||
|
0xb, 0x6, 0x6, 0x6, 0x5, 0x8, 0x8, 0x8, /* f0..f7 */
|
||||||
|
0x8, 0x8, 0x8, 0x8, 0x8, 0x8, 0x8, 0x8, /* f8..ff */
|
||||||
|
0x0, 0x1, 0x2, 0x3, 0x5, 0x8, 0x7, 0x1, /* s0.. */
|
||||||
|
0x1, 0x1, 0x4, 0x6, 0x1, 0x1, 0x1, 0x1, /* ..s0 */
|
||||||
|
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, /* s1 */
|
||||||
|
1, 0, 1, 1, 1, 1, 1, 0, 1, 0, 1, 1, 1, 1, 1, 1, /* s1 */
|
||||||
|
1, 2, 1, 1, 1, 1, 1, 2, 1, 2, 1, 1, 1, 1, 1, 1, /* s3 */
|
||||||
|
1, 1, 1, 1, 1, 1, 1, 2, 1, 1, 1, 1, 1, 1, 1, 1, /* s4 */
|
||||||
|
1, 2, 1, 1, 1, 1, 1, 1, 1, 2, 1, 1, 1, 1, 1, 1, /* s5 */
|
||||||
|
1, 1, 1, 1, 1, 1, 1, 3, 1, 3, 1, 1, 1, 1, 1, 1, /* s6 */
|
||||||
|
1, 3, 1, 1, 1, 1, 1, 3, 1, 3, 1, 1, 1, 1, 1, 1, /* s7 */
|
||||||
|
1, 3, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, /* s8 */
|
||||||
|
};
|
||||||
|
|
||||||
|
uint32_t decode(uint32_t *state, uint32_t *codep, uint32_t byte)
|
||||||
|
{
|
||||||
|
uint32_t type = utf8d[byte];
|
||||||
|
|
||||||
|
*codep = (*state != 0) ?
|
||||||
|
(byte & 0x3fu) | (*codep << 6) :
|
||||||
|
(0xff >> type) & (byte);
|
||||||
|
|
||||||
|
*state = utf8d[256 + *state * 16 + type];
|
||||||
|
return *state;
|
||||||
|
}
|
||||||
34
src/extern/version.c
vendored
34
src/extern/version.c
vendored
@@ -1,34 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright (C) 2017 Antonio Nino Diaz <antonio_nd@outlook.com>
|
|
||||||
*
|
|
||||||
* Permission to use, copy, modify, and distribute this software for any
|
|
||||||
* purpose with or without fee is hereby granted, provided that the above
|
|
||||||
* copyright notice and this permission notice appear in all copies.
|
|
||||||
*
|
|
||||||
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
|
||||||
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
|
||||||
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
|
||||||
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
|
||||||
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
|
||||||
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
|
||||||
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#include <stdio.h>
|
|
||||||
#include <string.h>
|
|
||||||
|
|
||||||
#include "extern/version.h"
|
|
||||||
|
|
||||||
const char *get_package_version_string(void)
|
|
||||||
{
|
|
||||||
static char s[50];
|
|
||||||
|
|
||||||
/* The following conditional should be simplified by the compiler. */
|
|
||||||
if (strlen(BUILD_VERSION_STRING) == 0) {
|
|
||||||
snprintf(s, sizeof(s), "v%d.%d.%d", PACKAGE_VERSION_MAJOR,
|
|
||||||
PACKAGE_VERSION_MINOR, PACKAGE_VERSION_PATCH);
|
|
||||||
return s;
|
|
||||||
} else {
|
|
||||||
return BUILD_VERSION_STRING;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
182
src/fix/main.c
182
src/fix/main.c
@@ -1,17 +1,9 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright © 2010 Anthony J. Bentley <anthonyjbentley@gmail.com>
|
* This file is part of RGBDS.
|
||||||
*
|
*
|
||||||
* Permission to use, copy, modify, and distribute this software for any
|
* Copyright (c) 2010-2018, Anthony J. Bentley and RGBDS contributors.
|
||||||
* purpose with or without fee is hereby granted, provided that the above
|
|
||||||
* copyright notice and this permission notice appear in all copies.
|
|
||||||
*
|
*
|
||||||
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
* SPDX-License-Identifier: MIT
|
||||||
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
|
||||||
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
|
||||||
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
|
||||||
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
|
||||||
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
|
||||||
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <stdbool.h>
|
#include <stdbool.h>
|
||||||
@@ -22,14 +14,15 @@
|
|||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
|
|
||||||
#include "extern/err.h"
|
#include "extern/err.h"
|
||||||
#include "extern/version.h"
|
|
||||||
|
#include "version.h"
|
||||||
|
|
||||||
static void print_usage(void)
|
static void print_usage(void)
|
||||||
{
|
{
|
||||||
printf(
|
printf(
|
||||||
"usage: rgbfix [-CcjsVv] [-i game_id] [-k licensee_str] [-l licensee_id]\n"
|
"usage: rgbfix [-CcjsVv] [-f fix_spec] [-i game_id] [-k licensee_str]\n"
|
||||||
" [-m mbc_type] [-n rom_version] [-p pad_value] [-r ram_size]\n"
|
" [-l licensee_id] [-m mbc_type] [-n rom_version] [-p pad_value]\n"
|
||||||
" [-t title_str] file\n");
|
" [-r ram_size] [-t title_str] file\n");
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -44,7 +37,12 @@ int main(int argc, char *argv[])
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
/* all flags default to false unless options specify otherwise */
|
/* all flags default to false unless options specify otherwise */
|
||||||
bool validate = false;
|
bool fixlogo = false;
|
||||||
|
bool fixheadsum = false;
|
||||||
|
bool fixglobalsum = false;
|
||||||
|
bool trashlogo = false;
|
||||||
|
bool trashheadsum = false;
|
||||||
|
bool trashglobalsum = false;
|
||||||
bool settitle = false;
|
bool settitle = false;
|
||||||
bool setid = false;
|
bool setid = false;
|
||||||
bool colorcompatible = false;
|
bool colorcompatible = false;
|
||||||
@@ -68,7 +66,7 @@ int main(int argc, char *argv[])
|
|||||||
int version = 0; /* mask ROM version number */
|
int version = 0; /* mask ROM version number */
|
||||||
int padvalue = 0; /* to pad the rom with if it changes size */
|
int padvalue = 0; /* to pad the rom with if it changes size */
|
||||||
|
|
||||||
while ((ch = getopt(argc, argv, "Cci:jk:l:m:n:p:sr:t:Vv")) != -1) {
|
while ((ch = getopt(argc, argv, "Ccf:i:jk:l:m:n:p:sr:t:Vv")) != -1) {
|
||||||
switch (ch) {
|
switch (ch) {
|
||||||
case 'C':
|
case 'C':
|
||||||
coloronly = true;
|
coloronly = true;
|
||||||
@@ -76,6 +74,14 @@ int main(int argc, char *argv[])
|
|||||||
case 'c':
|
case 'c':
|
||||||
colorcompatible = true;
|
colorcompatible = true;
|
||||||
break;
|
break;
|
||||||
|
case 'f':
|
||||||
|
fixlogo = strchr(optarg, 'l');
|
||||||
|
fixheadsum = strchr(optarg, 'h');
|
||||||
|
fixglobalsum = strchr(optarg, 'g');
|
||||||
|
trashlogo = strchr(optarg, 'L');
|
||||||
|
trashheadsum = strchr(optarg, 'H');
|
||||||
|
trashglobalsum = strchr(optarg, 'G');
|
||||||
|
break;
|
||||||
case 'i':
|
case 'i':
|
||||||
setid = true;
|
setid = true;
|
||||||
|
|
||||||
@@ -175,7 +181,9 @@ int main(int argc, char *argv[])
|
|||||||
printf("rgbfix %s\n", get_package_version_string());
|
printf("rgbfix %s\n", get_package_version_string());
|
||||||
exit(0);
|
exit(0);
|
||||||
case 'v':
|
case 'v':
|
||||||
validate = true;
|
fixlogo = true;
|
||||||
|
fixheadsum = true;
|
||||||
|
fixglobalsum = true;
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
print_usage();
|
print_usage();
|
||||||
@@ -199,10 +207,20 @@ int main(int argc, char *argv[])
|
|||||||
err(1, "Error opening file %s", argv[argc - 1]);
|
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.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
if (validate) {
|
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
|
* Offset 0x104–0x133: Nintendo Logo
|
||||||
* This is a bitmap image that displays when the Game Boy is
|
* This is a bitmap image that displays when the Game Boy is
|
||||||
@@ -212,7 +230,7 @@ int main(int argc, char *argv[])
|
|||||||
/*
|
/*
|
||||||
* See also: global checksums at 0x14D–0x14F, They must
|
* See also: global checksums at 0x14D–0x14F, They must
|
||||||
* also be correct for the game to boot, so we fix them
|
* also be correct for the game to boot, so we fix them
|
||||||
* as well when the -v flag is set.
|
* as well when requested with the -f flag.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
uint8_t ninlogo[48] = {
|
uint8_t ninlogo[48] = {
|
||||||
@@ -224,8 +242,12 @@ int main(int argc, char *argv[])
|
|||||||
0xDD, 0xDC, 0x99, 0x9F, 0xBB, 0xB9, 0x33, 0x3E
|
0xDD, 0xDC, 0x99, 0x9F, 0xBB, 0xB9, 0x33, 0x3E
|
||||||
};
|
};
|
||||||
|
|
||||||
fseek(rom, 0x104, SEEK_SET);
|
if (trashlogo) {
|
||||||
fwrite(ninlogo, 1, 48, rom);
|
for (int i = 0; i < sizeof(ninlogo); i++)
|
||||||
|
ninlogo[i] = ~ninlogo[i];
|
||||||
|
}
|
||||||
|
|
||||||
|
memcpy(header + 0x04, ninlogo, sizeof(ninlogo));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (settitle) {
|
if (settitle) {
|
||||||
@@ -246,11 +268,10 @@ int main(int argc, char *argv[])
|
|||||||
* characters may conflict with the title.
|
* characters may conflict with the title.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
fseek(rom, 0x134, SEEK_SET);
|
int n = snprintf((char *)header + 0x34, 16, "%s", title);
|
||||||
fwrite(title, 1, strlen(title) + 1, rom);
|
|
||||||
|
|
||||||
while (ftell(rom) < 0x143)
|
for (int i = 16; i > n; i--)
|
||||||
fputc(0, rom);
|
header[0x34 + i] = '\0';
|
||||||
}
|
}
|
||||||
|
|
||||||
if (setid) {
|
if (setid) {
|
||||||
@@ -260,8 +281,7 @@ int main(int argc, char *argv[])
|
|||||||
* characters).
|
* characters).
|
||||||
*/
|
*/
|
||||||
|
|
||||||
fseek(rom, 0x13F, SEEK_SET);
|
memcpy(header + 0x3F, id, 4);
|
||||||
fwrite(id, 1, 4, rom);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (colorcompatible) {
|
if (colorcompatible) {
|
||||||
@@ -279,20 +299,12 @@ int main(int argc, char *argv[])
|
|||||||
* may conflict.
|
* may conflict.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
uint8_t byte;
|
header[0x43] |= 1 << 7;
|
||||||
|
|
||||||
fseek(rom, 0x143, SEEK_SET);
|
|
||||||
byte = fgetc(rom);
|
|
||||||
|
|
||||||
byte |= 1 << 7;
|
|
||||||
if (coloronly)
|
if (coloronly)
|
||||||
byte |= 1 << 6;
|
header[0x43] |= 1 << 6;
|
||||||
|
|
||||||
if (byte & 0x3F)
|
if (header[0x43] & 0x3F)
|
||||||
warnx("Color flag conflicts with game title");
|
warnx("Color flag conflicts with game title");
|
||||||
|
|
||||||
fseek(rom, 0x143, SEEK_SET);
|
|
||||||
fputc(byte, rom);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (setnewlicensee) {
|
if (setnewlicensee) {
|
||||||
@@ -308,8 +320,8 @@ int main(int argc, char *argv[])
|
|||||||
* as a Super Game Boy flag.
|
* as a Super Game Boy flag.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
fseek(rom, 0x144, SEEK_SET);
|
header[0x44] = newlicensee[0];
|
||||||
fwrite(newlicensee, 1, 2, rom);
|
header[0x45] = newlicensee[1];
|
||||||
}
|
}
|
||||||
|
|
||||||
if (super) {
|
if (super) {
|
||||||
@@ -328,8 +340,7 @@ int main(int argc, char *argv[])
|
|||||||
if (!setlicensee)
|
if (!setlicensee)
|
||||||
warnx("You should probably set both '-s' and '-l 0x33'");
|
warnx("You should probably set both '-s' and '-l 0x33'");
|
||||||
|
|
||||||
fseek(rom, 0x146, SEEK_SET);
|
header[0x46] = 3;
|
||||||
fputc(3, rom);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (setcartridge) {
|
if (setcartridge) {
|
||||||
@@ -339,8 +350,7 @@ int main(int argc, char *argv[])
|
|||||||
* external RAM, timer, rumble, or battery.
|
* external RAM, timer, rumble, or battery.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
fseek(rom, 0x147, SEEK_SET);
|
header[0x47] = cartridge;
|
||||||
fputc(cartridge, rom);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (resize) {
|
if (resize) {
|
||||||
@@ -354,8 +364,13 @@ int main(int argc, char *argv[])
|
|||||||
int headbyte;
|
int headbyte;
|
||||||
uint8_t *buf;
|
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);
|
romsize = ftell(rom);
|
||||||
|
if (romsize == -1)
|
||||||
|
err(1, "Could not pad ROM file");
|
||||||
|
|
||||||
newsize = 0x8000;
|
newsize = 0x8000;
|
||||||
|
|
||||||
headbyte = 0;
|
headbyte = 0;
|
||||||
@@ -368,11 +383,14 @@ int main(int argc, char *argv[])
|
|||||||
warnx("ROM size is bigger than 8MiB");
|
warnx("ROM size is bigger than 8MiB");
|
||||||
|
|
||||||
buf = malloc(newsize - romsize);
|
buf = malloc(newsize - romsize);
|
||||||
memset(buf, padvalue, newsize - romsize);
|
if (buf == NULL)
|
||||||
fwrite(buf, 1, newsize - romsize, rom);
|
errx(1, "Couldn't allocate memory for padded ROM.");
|
||||||
|
|
||||||
fseek(rom, 0x148, SEEK_SET);
|
memset(buf, padvalue, newsize - romsize);
|
||||||
fputc(headbyte, rom);
|
if (fwrite(buf, 1, newsize - romsize, rom) != newsize - romsize)
|
||||||
|
err(1, "Could not pad ROM file");
|
||||||
|
|
||||||
|
header[0x48] = headbyte;
|
||||||
|
|
||||||
free(buf);
|
free(buf);
|
||||||
}
|
}
|
||||||
@@ -382,8 +400,7 @@ int main(int argc, char *argv[])
|
|||||||
* Offset 0x149: RAM Size
|
* Offset 0x149: RAM Size
|
||||||
*/
|
*/
|
||||||
|
|
||||||
fseek(rom, 0x149, SEEK_SET);
|
header[0x49] = ramsize;
|
||||||
fputc(ramsize, rom);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (nonjapan) {
|
if (nonjapan) {
|
||||||
@@ -391,8 +408,7 @@ int main(int argc, char *argv[])
|
|||||||
* Offset 0x14A: Non-Japanese Region Flag
|
* Offset 0x14A: Non-Japanese Region Flag
|
||||||
*/
|
*/
|
||||||
|
|
||||||
fseek(rom, 0x14A, SEEK_SET);
|
header[0x4A] = 1;
|
||||||
fputc(1, rom);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (setlicensee) {
|
if (setlicensee) {
|
||||||
@@ -408,8 +424,7 @@ int main(int argc, char *argv[])
|
|||||||
* See also: the New Licensee ID at 0x144–0x145.
|
* See also: the New Licensee ID at 0x144–0x145.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
fseek(rom, 0x14B, SEEK_SET);
|
header[0x4B] = licensee;
|
||||||
fputc(licensee, rom);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (setversion) {
|
if (setversion) {
|
||||||
@@ -418,46 +433,71 @@ int main(int argc, char *argv[])
|
|||||||
* Which version of the ROM this is.
|
* Which version of the ROM this is.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
fseek(rom, 0x14C, SEEK_SET);
|
header[0x4C] = version;
|
||||||
fputc(version, rom);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (validate) {
|
if (fixheadsum || trashheadsum) {
|
||||||
/*
|
/*
|
||||||
* Offset 0x14D: Header Checksum
|
* Offset 0x14D: Header Checksum
|
||||||
*/
|
*/
|
||||||
|
|
||||||
uint8_t headcksum = 0;
|
uint8_t headcksum = 0;
|
||||||
|
|
||||||
fseek(rom, 0x134, SEEK_SET);
|
for (int i = 0x34; i < 0x4D; ++i)
|
||||||
for (int i = 0; i < (0x14D - 0x134); ++i)
|
headcksum = headcksum - header[i] - 1;
|
||||||
headcksum = headcksum - fgetc(rom) - 1;
|
|
||||||
|
|
||||||
fseek(rom, 0x14D, SEEK_SET);
|
if (trashheadsum)
|
||||||
fputc(headcksum, rom);
|
headcksum = ~headcksum;
|
||||||
|
|
||||||
|
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
|
* Offset 0x14E–0x14F: Global Checksum
|
||||||
*/
|
*/
|
||||||
|
|
||||||
uint16_t globalcksum = 0;
|
uint16_t globalcksum = 0;
|
||||||
|
|
||||||
rewind(rom);
|
if (fseek(rom, 0, SEEK_SET) != 0)
|
||||||
for (int i = 0; i < 0x14E; ++i)
|
err(1, "Could not start calculating global checksum");
|
||||||
globalcksum += fgetc(rom);
|
|
||||||
|
|
||||||
|
int i = 0;
|
||||||
int byte;
|
int byte;
|
||||||
|
|
||||||
fseek(rom, 0x150, SEEK_SET);
|
while ((byte = fgetc(rom)) != EOF) {
|
||||||
while ((byte = fgetc(rom)) != EOF)
|
i++;
|
||||||
|
if (i != 0x150)
|
||||||
globalcksum += byte;
|
globalcksum += byte;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (ferror(rom))
|
||||||
|
err(1, "Could not calculate global checksum");
|
||||||
|
|
||||||
|
if (trashglobalsum)
|
||||||
|
globalcksum = ~globalcksum;
|
||||||
|
|
||||||
fseek(rom, 0x14E, SEEK_SET);
|
fseek(rom, 0x14E, SEEK_SET);
|
||||||
fputc(globalcksum >> 8, rom);
|
fputc(globalcksum >> 8, rom);
|
||||||
fputc(globalcksum & 0xFF, 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;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,18 +1,11 @@
|
|||||||
.\" Copyright © 2010 Anthony J. Bentley <anthony@anjbe.name>
|
|
||||||
.\"
|
.\"
|
||||||
.\" Permission to use, copy, modify, and distribute this software for any
|
.\" This file is part of RGBDS.
|
||||||
.\" purpose with or without fee is hereby granted, provided that the above
|
|
||||||
.\" copyright notice and this permission notice appear in all copies.
|
|
||||||
.\"
|
.\"
|
||||||
.\" THE SOFTWARE IS PROVIDED “AS IS” AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
.\" Copyright (c) 2010-2017, Anthony J. Bentley and RGBDS contributors.
|
||||||
.\" WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
|
||||||
.\" MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
|
||||||
.\" ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
|
||||||
.\" WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
|
||||||
.\" ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
|
||||||
.\" OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
|
||||||
.\"
|
.\"
|
||||||
.Dd April 17, 2017
|
.\" SPDX-License-Identifier: MIT
|
||||||
|
.\"
|
||||||
|
.Dd March 11, 2018
|
||||||
.Dt RGBFIX 1
|
.Dt RGBFIX 1
|
||||||
.Os RGBDS Manual
|
.Os RGBDS Manual
|
||||||
.Sh NAME
|
.Sh NAME
|
||||||
@@ -21,6 +14,7 @@
|
|||||||
.Sh SYNOPSIS
|
.Sh SYNOPSIS
|
||||||
.Nm rgbfix
|
.Nm rgbfix
|
||||||
.Op Fl CcjsVv
|
.Op Fl CcjsVv
|
||||||
|
.Op Fl f Ar fix_spec
|
||||||
.Op Fl i Ar game_id
|
.Op Fl i Ar game_id
|
||||||
.Op Fl k Ar licensee_str
|
.Op Fl k Ar licensee_str
|
||||||
.Op Fl l Ar licensee_id
|
.Op Fl l Ar licensee_id
|
||||||
@@ -53,6 +47,30 @@ If both this and the
|
|||||||
flag are set,
|
flag are set,
|
||||||
.Fl C
|
.Fl C
|
||||||
takes precedence.
|
takes precedence.
|
||||||
|
.It Fl f Ar fix_spec
|
||||||
|
Fix certain header values that the Game Boy checks for correctness.
|
||||||
|
Alternatively, intentionally trash these values by writing their binary inverse
|
||||||
|
instead.
|
||||||
|
.Ar fix_spec
|
||||||
|
is a string containing any combination of the following characters:
|
||||||
|
.Pp
|
||||||
|
.Bl -tag -compact -width xx
|
||||||
|
.It Cm l
|
||||||
|
Fix the Nintendo logo
|
||||||
|
.Pq Ad 0x104 Ns \(en Ns Ad 0x133 .
|
||||||
|
.It Cm L
|
||||||
|
Trash the Nintendo logo.
|
||||||
|
.It Cm h
|
||||||
|
Fix the header checksum
|
||||||
|
.Pq Ad 0x14D .
|
||||||
|
.It Cm H
|
||||||
|
Trash the header checksum.
|
||||||
|
.It Cm g
|
||||||
|
Fix the global checksum
|
||||||
|
.Pq Ad 0x14E Ns \(en Ns Ad 0x14F .
|
||||||
|
.It Cm G
|
||||||
|
Trash the global checksum.
|
||||||
|
.El
|
||||||
.It Fl i Ar game_id
|
.It Fl i Ar game_id
|
||||||
Set the game ID string
|
Set the game ID string
|
||||||
.Pq Ad 0x13F Ns \(en Ns Ad 0x142
|
.Pq Ad 0x13F Ns \(en Ns Ad 0x142
|
||||||
@@ -111,12 +129,8 @@ overlapping portion of the title.
|
|||||||
.It Fl V
|
.It Fl V
|
||||||
Print the version of the program and exit.
|
Print the version of the program and exit.
|
||||||
.It Fl v
|
.It Fl v
|
||||||
Validate the header and fix checksums: the Nintendo character area
|
Equivalent to
|
||||||
.Pq Ad 0x104 Ns \(en Ns Ad 0x133 ,
|
.Fl f Cm lhg .
|
||||||
the header checksum
|
|
||||||
.Pq Ad 0x14D ,
|
|
||||||
and the global checksum
|
|
||||||
.Pq Ad 0x14E Ns \(en Ns Ad 0x14F .
|
|
||||||
.El
|
.El
|
||||||
.Sh EXAMPLES
|
.Sh EXAMPLES
|
||||||
Most values in the ROM header are only cosmetic.
|
Most values in the ROM header are only cosmetic.
|
||||||
|
|||||||
25
src/gbz80.7
25
src/gbz80.7
@@ -1,18 +1,11 @@
|
|||||||
.\" Copyright (c) 2017 Antonio Nino Diaz <antonio_nd@outlook.com>
|
|
||||||
.\"
|
.\"
|
||||||
.\" Permission to use, copy, modify, and distribute this software for any
|
.\" This file is part of RGBDS.
|
||||||
.\" purpose with or without fee is hereby granted, provided that the above
|
|
||||||
.\" copyright notice and this permission notice appear in all copies.
|
|
||||||
.\"
|
.\"
|
||||||
.\" THE SOFTWARE IS PROVIDED “AS IS” AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
.\" Copyright (c) 2017-2018, Antonio Nino Diaz and RGBDS contributors.
|
||||||
.\" WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
|
||||||
.\" MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
|
||||||
.\" ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
|
||||||
.\" WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
|
||||||
.\" ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
|
||||||
.\" OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
|
||||||
.\"
|
.\"
|
||||||
.Dd April 17, 2017
|
.\" SPDX-License-Identifier: MIT
|
||||||
|
.\"
|
||||||
|
.Dd February 23, 2018
|
||||||
.Dt GBZ80 7
|
.Dt GBZ80 7
|
||||||
.Os RGBDS Manual
|
.Os RGBDS Manual
|
||||||
.Sh NAME
|
.Sh NAME
|
||||||
@@ -31,8 +24,10 @@ as destination can omit the destination as it is assumed it's register
|
|||||||
.Sy A .
|
.Sy A .
|
||||||
The following two lines have the same effect:
|
The following two lines have the same effect:
|
||||||
.Pp
|
.Pp
|
||||||
.Dl OR A,B
|
.Bd -literal -offset indent
|
||||||
.Dl OR B
|
OR A,B
|
||||||
|
OR B
|
||||||
|
.Ed
|
||||||
.Pp
|
.Pp
|
||||||
.Sh LEGEND
|
.Sh LEGEND
|
||||||
List of abbreviations used in this document.
|
List of abbreviations used in this document.
|
||||||
@@ -1669,7 +1664,7 @@ Flags: See
|
|||||||
.Sx SRA r8
|
.Sx SRA r8
|
||||||
.Ss STOP
|
.Ss STOP
|
||||||
Enter CPU very low power mode.
|
Enter CPU very low power mode.
|
||||||
Also used to switch between doube speed and normal CPU modes in GBC.
|
Also used to switch between double and normal speed CPU modes in GBC.
|
||||||
.Pp
|
.Pp
|
||||||
Cycles: -
|
Cycles: -
|
||||||
.Pp
|
.Pp
|
||||||
|
|||||||
106
src/gfx/gb.c
106
src/gfx/gb.c
@@ -1,19 +1,12 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright © 2013 stag019 <stag019@gmail.com>
|
* This file is part of RGBDS.
|
||||||
*
|
*
|
||||||
* Permission to use, copy, modify, and distribute this software for any
|
* Copyright (c) 2013-2018, stag019 and RGBDS contributors.
|
||||||
* purpose with or without fee is hereby granted, provided that the above
|
|
||||||
* copyright notice and this permission notice appear in all copies.
|
|
||||||
*
|
*
|
||||||
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
* SPDX-License-Identifier: MIT
|
||||||
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
|
||||||
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
|
||||||
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
|
||||||
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
|
||||||
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
|
||||||
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#include <stdint.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
|
||||||
@@ -39,23 +32,18 @@ void transpose_tiles(struct GBImage *gb, int width)
|
|||||||
gb->data = newdata;
|
gb->data = newdata;
|
||||||
}
|
}
|
||||||
|
|
||||||
void png_to_gb(const struct PNGImage png, struct GBImage *gb)
|
void raw_to_gb(const struct RawIndexedImage *raw_image, struct GBImage *gb)
|
||||||
{
|
{
|
||||||
int x, y, byte;
|
int x, y, byte;
|
||||||
png_byte index;
|
uint8_t index;
|
||||||
|
|
||||||
for (y = 0; y < png.height; y++) {
|
for (y = 0; y < raw_image->height; y++) {
|
||||||
for (x = 0; x < png.width; x++) {
|
for (x = 0; x < raw_image->width; x++) {
|
||||||
index = png.data[y][x];
|
index = raw_image->data[y][x];
|
||||||
index &= (1 << depth) - 1;
|
index &= (1 << depth) - 1;
|
||||||
|
|
||||||
if (!gb->horizontal) {
|
|
||||||
byte = y * depth
|
byte = y * depth
|
||||||
+ x / 8 * png.height / 8 * 8 * depth;
|
+ x / 8 * raw_image->height / 8 * 8 * depth;
|
||||||
} else {
|
|
||||||
byte = y * depth
|
|
||||||
+ x / 8 * png.height / 8 * 8 * depth;
|
|
||||||
}
|
|
||||||
gb->data[byte] |= (index & 1) << (7 - x % 8);
|
gb->data[byte] |= (index & 1) << (7 - x % 8);
|
||||||
if (depth == 2) {
|
if (depth == 2) {
|
||||||
gb->data[byte + 1] |=
|
gb->data[byte + 1] |=
|
||||||
@@ -65,18 +53,18 @@ void png_to_gb(const struct PNGImage png, struct GBImage *gb)
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (!gb->horizontal)
|
if (!gb->horizontal)
|
||||||
transpose_tiles(gb, png.width / 8);
|
transpose_tiles(gb, raw_image->width / 8);
|
||||||
}
|
}
|
||||||
|
|
||||||
void output_file(const struct Options opts, const struct GBImage gb)
|
void output_file(const struct Options *opts, const struct GBImage *gb)
|
||||||
{
|
{
|
||||||
FILE *f;
|
FILE *f;
|
||||||
|
|
||||||
f = fopen(opts.outfile, "wb");
|
f = fopen(opts->outfile, "wb");
|
||||||
if (!f)
|
if (!f)
|
||||||
err(1, "Opening output file '%s' failed", opts.outfile);
|
err(1, "Opening output file '%s' failed", opts->outfile);
|
||||||
|
|
||||||
fwrite(gb.data, 1, gb.size - gb.trim * 8 * depth, f);
|
fwrite(gb->data, 1, gb->size - gb->trim * 8 * depth, f);
|
||||||
|
|
||||||
fclose(f);
|
fclose(f);
|
||||||
}
|
}
|
||||||
@@ -97,7 +85,7 @@ int get_tile_index(uint8_t *tile, uint8_t **tiles, int num_tiles, int tile_size)
|
|||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
void create_tilemap(const struct Options opts, struct GBImage *gb,
|
void create_tilemap(const struct Options *opts, struct GBImage *gb,
|
||||||
struct Tilemap *tilemap)
|
struct Tilemap *tilemap)
|
||||||
{
|
{
|
||||||
int i, j;
|
int i, j;
|
||||||
@@ -113,10 +101,15 @@ void create_tilemap(const struct Options opts, struct GBImage *gb,
|
|||||||
tile_size = sizeof(uint8_t) * depth * 8;
|
tile_size = sizeof(uint8_t) * depth * 8;
|
||||||
gb_size = gb->size - (gb->trim * tile_size);
|
gb_size = gb->size - (gb->trim * tile_size);
|
||||||
max_tiles = gb_size / tile_size;
|
max_tiles = gb_size / tile_size;
|
||||||
tiles = malloc(sizeof(uint8_t *) * max_tiles);
|
|
||||||
|
/* If the input image doesn't fill the last tile, increase the count. */
|
||||||
|
if (gb_size > max_tiles * tile_size)
|
||||||
|
max_tiles++;
|
||||||
|
|
||||||
|
tiles = calloc(max_tiles, sizeof(uint8_t *));
|
||||||
num_tiles = 0;
|
num_tiles = 0;
|
||||||
|
|
||||||
tilemap->data = malloc(sizeof(uint8_t) * max_tiles);
|
tilemap->data = calloc(max_tiles, sizeof(uint8_t));
|
||||||
tilemap->size = 0;
|
tilemap->size = 0;
|
||||||
|
|
||||||
gb_i = 0;
|
gb_i = 0;
|
||||||
@@ -126,7 +119,7 @@ void create_tilemap(const struct Options opts, struct GBImage *gb,
|
|||||||
tile[i] = gb->data[gb_i];
|
tile[i] = gb->data[gb_i];
|
||||||
gb_i++;
|
gb_i++;
|
||||||
}
|
}
|
||||||
if (opts.unique) {
|
if (opts->unique) {
|
||||||
index = get_tile_index(tile, tiles, num_tiles,
|
index = get_tile_index(tile, tiles, num_tiles,
|
||||||
tile_size);
|
tile_size);
|
||||||
if (index < 0) {
|
if (index < 0) {
|
||||||
@@ -143,7 +136,7 @@ void create_tilemap(const struct Options opts, struct GBImage *gb,
|
|||||||
tilemap->size++;
|
tilemap->size++;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (opts.unique) {
|
if (opts->unique) {
|
||||||
free(gb->data);
|
free(gb->data);
|
||||||
gb->data = malloc(tile_size * num_tiles);
|
gb->data = malloc(tile_size * num_tiles);
|
||||||
for (i = 0; i < num_tiles; i++) {
|
for (i = 0; i < num_tiles; i++) {
|
||||||
@@ -160,43 +153,44 @@ void create_tilemap(const struct Options opts, struct GBImage *gb,
|
|||||||
free(tiles);
|
free(tiles);
|
||||||
}
|
}
|
||||||
|
|
||||||
void output_tilemap_file(const struct Options opts,
|
void output_tilemap_file(const struct Options *opts,
|
||||||
const struct Tilemap tilemap)
|
const struct Tilemap *tilemap)
|
||||||
{
|
{
|
||||||
FILE *f;
|
FILE *f;
|
||||||
|
|
||||||
f = fopen(opts.mapfile, "wb");
|
f = fopen(opts->mapfile, "wb");
|
||||||
if (!f)
|
if (!f)
|
||||||
err(1, "Opening tilemap file '%s' failed", opts.mapfile);
|
err(1, "Opening tilemap file '%s' failed", opts->mapfile);
|
||||||
|
|
||||||
fwrite(tilemap.data, 1, tilemap.size, f);
|
fwrite(tilemap->data, 1, tilemap->size, f);
|
||||||
fclose(f);
|
fclose(f);
|
||||||
|
|
||||||
if (opts.mapout)
|
if (opts->mapout)
|
||||||
free(opts.mapfile);
|
free(opts->mapfile);
|
||||||
}
|
}
|
||||||
|
|
||||||
void output_palette_file(const struct Options opts, const struct PNGImage png)
|
void output_palette_file(const struct Options *opts,
|
||||||
|
const struct RawIndexedImage *raw_image)
|
||||||
{
|
{
|
||||||
FILE *f;
|
FILE *f;
|
||||||
int i, colors, color;
|
int i, color;
|
||||||
png_color *palette;
|
uint8_t cur_bytes[2];
|
||||||
|
|
||||||
if (png_get_PLTE(png.png, png.info, &palette, &colors)) {
|
f = fopen(opts->palfile, "wb");
|
||||||
f = fopen(opts.palfile, "wb");
|
if (!f)
|
||||||
if (!f) {
|
err(1, "Opening palette file '%s' failed", opts->palfile);
|
||||||
err(1, "Opening palette file '%s' failed",
|
|
||||||
opts.palfile);
|
for (i = 0; i < raw_image->num_colors; i++) {
|
||||||
}
|
color =
|
||||||
for (i = 0; i < colors; i++) {
|
raw_image->palette[i].blue >> 3 << 10 |
|
||||||
color = palette[i].blue >> 3 << 10
|
raw_image->palette[i].green >> 3 << 5 |
|
||||||
| palette[i].green >> 3 << 5
|
raw_image->palette[i].red >> 3;
|
||||||
| palette[i].red >> 3;
|
cur_bytes[0] = color & 0xFF;
|
||||||
fwrite(&color, 2, 1, f);
|
cur_bytes[1] = color >> 8;
|
||||||
|
fwrite(cur_bytes, 2, 1, f);
|
||||||
}
|
}
|
||||||
fclose(f);
|
fclose(f);
|
||||||
}
|
|
||||||
|
|
||||||
if (opts.palout)
|
if (opts->palout)
|
||||||
free(opts.palfile);
|
free(opts->palfile);
|
||||||
}
|
}
|
||||||
|
|||||||
112
src/gfx/main.c
112
src/gfx/main.c
@@ -1,27 +1,20 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright © 2013 stag019 <stag019@gmail.com>
|
* This file is part of RGBDS.
|
||||||
*
|
*
|
||||||
* Permission to use, copy, modify, and distribute this software for any
|
* Copyright (c) 2013-2018, stag019 and RGBDS contributors.
|
||||||
* purpose with or without fee is hereby granted, provided that the above
|
|
||||||
* copyright notice and this permission notice appear in all copies.
|
|
||||||
*
|
*
|
||||||
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
* SPDX-License-Identifier: MIT
|
||||||
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
|
||||||
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
|
||||||
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
|
||||||
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
|
||||||
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
|
||||||
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#include <png.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
|
|
||||||
#include "extern/version.h"
|
|
||||||
|
|
||||||
#include "gfx/main.h"
|
#include "gfx/main.h"
|
||||||
|
|
||||||
|
#include "version.h"
|
||||||
|
|
||||||
static void print_usage(void)
|
static void print_usage(void)
|
||||||
{
|
{
|
||||||
printf(
|
printf(
|
||||||
@@ -34,7 +27,8 @@ int main(int argc, char *argv[])
|
|||||||
{
|
{
|
||||||
int ch, size;
|
int ch, size;
|
||||||
struct Options opts = {0};
|
struct Options opts = {0};
|
||||||
struct PNGImage png = {0};
|
struct ImageOptions png_options = {0};
|
||||||
|
struct RawIndexedImage *raw_image;
|
||||||
struct GBImage gb = {0};
|
struct GBImage gb = {0};
|
||||||
struct Tilemap tilemap = {0};
|
struct Tilemap tilemap = {0};
|
||||||
char *ext;
|
char *ext;
|
||||||
@@ -59,6 +53,7 @@ int main(int argc, char *argv[])
|
|||||||
break;
|
break;
|
||||||
case 'F':
|
case 'F':
|
||||||
opts.hardfix = true;
|
opts.hardfix = true;
|
||||||
|
/* fallthrough */
|
||||||
case 'f':
|
case 'f':
|
||||||
opts.fix = true;
|
opts.fix = true;
|
||||||
break;
|
break;
|
||||||
@@ -110,80 +105,89 @@ int main(int argc, char *argv[])
|
|||||||
|
|
||||||
colors = 1 << depth;
|
colors = 1 << depth;
|
||||||
|
|
||||||
input_png_file(opts, &png);
|
raw_image = input_png_file(&opts, &png_options);
|
||||||
|
|
||||||
png.mapfile = "";
|
png_options.mapfile = "";
|
||||||
png.palfile = "";
|
png_options.palfile = "";
|
||||||
|
|
||||||
get_text(&png);
|
if (png_options.horizontal != opts.horizontal) {
|
||||||
|
|
||||||
if (png.horizontal != opts.horizontal) {
|
|
||||||
if (opts.verbose)
|
if (opts.verbose)
|
||||||
warnx(errmsg, "horizontal");
|
warnx(errmsg, "horizontal");
|
||||||
|
|
||||||
if (opts.hardfix)
|
if (opts.hardfix)
|
||||||
png.horizontal = opts.horizontal;
|
png_options.horizontal = opts.horizontal;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (png.horizontal)
|
if (png_options.horizontal)
|
||||||
opts.horizontal = png.horizontal;
|
opts.horizontal = png_options.horizontal;
|
||||||
|
|
||||||
if (png.trim != opts.trim) {
|
if (png_options.trim != opts.trim) {
|
||||||
if (opts.verbose)
|
if (opts.verbose)
|
||||||
warnx(errmsg, "trim");
|
warnx(errmsg, "trim");
|
||||||
|
|
||||||
if (opts.hardfix)
|
if (opts.hardfix)
|
||||||
png.trim = opts.trim;
|
png_options.trim = opts.trim;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (png.trim)
|
if (png_options.trim)
|
||||||
opts.trim = png.trim;
|
opts.trim = png_options.trim;
|
||||||
|
|
||||||
if (opts.trim > png.width / 8 - 1) {
|
if (raw_image->width % 8) {
|
||||||
errx(1, "Trim (%i) for input png file '%s' too large (max: %i)",
|
errx(1, "Input PNG file %s not sized correctly. The image's width must be a multiple of 8.",
|
||||||
opts.trim, opts.infile, png.width / 8 - 1);
|
opts.infile);
|
||||||
|
}
|
||||||
|
if (raw_image->width / 8 > 1 && raw_image->height % 8) {
|
||||||
|
errx(1, "Input PNG file %s not sized correctly. If the image is more than 1 tile wide, its height must be a multiple of 8.",
|
||||||
|
opts.infile);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (strcmp(png.mapfile, opts.mapfile) != 0) {
|
if (opts.trim &&
|
||||||
|
opts.trim > (raw_image->width / 8) * (raw_image->height / 8) - 1) {
|
||||||
|
errx(1, "Trim (%i) for input raw_image file '%s' too large (max: %i)",
|
||||||
|
opts.trim, opts.infile,
|
||||||
|
(raw_image->width / 8) * (raw_image->height / 8) - 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (strcmp(png_options.mapfile, opts.mapfile) != 0) {
|
||||||
if (opts.verbose)
|
if (opts.verbose)
|
||||||
warnx(errmsg, "tilemap file");
|
warnx(errmsg, "tilemap file");
|
||||||
|
|
||||||
if (opts.hardfix)
|
if (opts.hardfix)
|
||||||
png.mapfile = opts.mapfile;
|
png_options.mapfile = opts.mapfile;
|
||||||
}
|
}
|
||||||
if (!*opts.mapfile)
|
if (!*opts.mapfile)
|
||||||
opts.mapfile = png.mapfile;
|
opts.mapfile = png_options.mapfile;
|
||||||
|
|
||||||
if (png.mapout != opts.mapout) {
|
if (png_options.mapout != opts.mapout) {
|
||||||
if (opts.verbose)
|
if (opts.verbose)
|
||||||
warnx(errmsg, "tilemap file");
|
warnx(errmsg, "tilemap file");
|
||||||
|
|
||||||
if (opts.hardfix)
|
if (opts.hardfix)
|
||||||
png.mapout = opts.mapout;
|
png_options.mapout = opts.mapout;
|
||||||
}
|
}
|
||||||
if (png.mapout)
|
if (png_options.mapout)
|
||||||
opts.mapout = png.mapout;
|
opts.mapout = png_options.mapout;
|
||||||
|
|
||||||
if (strcmp(png.palfile, opts.palfile) != 0) {
|
if (strcmp(png_options.palfile, opts.palfile) != 0) {
|
||||||
if (opts.verbose)
|
if (opts.verbose)
|
||||||
warnx(errmsg, "palette file");
|
warnx(errmsg, "palette file");
|
||||||
|
|
||||||
if (opts.hardfix)
|
if (opts.hardfix)
|
||||||
png.palfile = opts.palfile;
|
png_options.palfile = opts.palfile;
|
||||||
}
|
}
|
||||||
if (!*opts.palfile)
|
if (!*opts.palfile)
|
||||||
opts.palfile = png.palfile;
|
opts.palfile = png_options.palfile;
|
||||||
|
|
||||||
if (png.palout != opts.palout) {
|
if (png_options.palout != opts.palout) {
|
||||||
if (opts.verbose)
|
if (opts.verbose)
|
||||||
warnx(errmsg, "palette file");
|
warnx(errmsg, "palette file");
|
||||||
|
|
||||||
if (opts.hardfix)
|
if (opts.hardfix)
|
||||||
png.palout = opts.palout;
|
png_options.palout = opts.palout;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (png.palout)
|
if (png_options.palout)
|
||||||
opts.palout = png.palout;
|
opts.palout = png_options.palout;
|
||||||
|
|
||||||
if (!*opts.mapfile && opts.mapout) {
|
if (!*opts.mapfile && opts.mapout) {
|
||||||
ext = strrchr(opts.infile, '.');
|
ext = strrchr(opts.infile, '.');
|
||||||
@@ -217,31 +221,29 @@ int main(int argc, char *argv[])
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
gb.size = png.width * png.height * depth / 8;
|
gb.size = raw_image->width * raw_image->height * depth / 8;
|
||||||
gb.data = calloc(gb.size, 1);
|
gb.data = calloc(gb.size, 1);
|
||||||
gb.trim = opts.trim;
|
gb.trim = opts.trim;
|
||||||
gb.horizontal = opts.horizontal;
|
gb.horizontal = opts.horizontal;
|
||||||
|
|
||||||
if (*opts.outfile || *opts.mapfile) {
|
if (*opts.outfile || *opts.mapfile) {
|
||||||
png_to_gb(png, &gb);
|
raw_to_gb(raw_image, &gb);
|
||||||
create_tilemap(opts, &gb, &tilemap);
|
create_tilemap(&opts, &gb, &tilemap);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (*opts.outfile)
|
if (*opts.outfile)
|
||||||
output_file(opts, gb);
|
output_file(&opts, &gb);
|
||||||
|
|
||||||
if (*opts.mapfile)
|
if (*opts.mapfile)
|
||||||
output_tilemap_file(opts, tilemap);
|
output_tilemap_file(&opts, &tilemap);
|
||||||
|
|
||||||
if (*opts.palfile)
|
if (*opts.palfile)
|
||||||
output_palette_file(opts, png);
|
output_palette_file(&opts, raw_image);
|
||||||
|
|
||||||
if (opts.fix || opts.debug) {
|
if (opts.fix || opts.debug)
|
||||||
set_text(&png);
|
output_png_file(&opts, &png_options, raw_image);
|
||||||
output_png_file(opts, &png);
|
|
||||||
}
|
|
||||||
|
|
||||||
free_png_data(&png);
|
destroy_raw_image(&raw_image);
|
||||||
free(gb.data);
|
free(gb.data);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
|||||||
@@ -1,38 +1,155 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright © 2013 stag019 <stag019@gmail.com>
|
* This file is part of RGBDS.
|
||||||
*
|
*
|
||||||
* Permission to use, copy, modify, and distribute this software for any
|
* Copyright (c) 2013-2018, stag019 and RGBDS contributors.
|
||||||
* purpose with or without fee is hereby granted, provided that the above
|
|
||||||
* copyright notice and this permission notice appear in all copies.
|
|
||||||
*
|
*
|
||||||
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
* SPDX-License-Identifier: MIT
|
||||||
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
|
||||||
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
|
||||||
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
|
||||||
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
|
||||||
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
|
||||||
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#include <png.h>
|
||||||
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
#include "gfx/main.h"
|
#include "gfx/main.h"
|
||||||
|
|
||||||
void input_png_file(const struct Options opts, struct PNGImage *img)
|
static void initialize_png(struct PNGImage *img, FILE *f);
|
||||||
|
static struct RawIndexedImage *indexed_png_to_raw(struct PNGImage *img);
|
||||||
|
static struct RawIndexedImage *grayscale_png_to_raw(struct PNGImage *img);
|
||||||
|
static struct RawIndexedImage *truecolor_png_to_raw(struct PNGImage *img);
|
||||||
|
static void get_text(const struct PNGImage *img,
|
||||||
|
struct ImageOptions *png_options);
|
||||||
|
static void set_text(const struct PNGImage *img,
|
||||||
|
const struct ImageOptions *png_options);
|
||||||
|
static void free_png_data(const struct PNGImage *png);
|
||||||
|
|
||||||
|
struct RawIndexedImage *input_png_file(const struct Options *opts,
|
||||||
|
struct ImageOptions *png_options)
|
||||||
|
{
|
||||||
|
struct PNGImage img;
|
||||||
|
struct RawIndexedImage *raw_image;
|
||||||
|
FILE *f;
|
||||||
|
|
||||||
|
f = fopen(opts->infile, "rb");
|
||||||
|
if (!f)
|
||||||
|
err(1, "Opening input png file '%s' failed", opts->infile);
|
||||||
|
|
||||||
|
initialize_png(&img, f);
|
||||||
|
|
||||||
|
if (img.depth != depth) {
|
||||||
|
if (opts->verbose) {
|
||||||
|
warnx("Image bit depth is not %i (is %i).",
|
||||||
|
depth, img.depth);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
switch (img.type) {
|
||||||
|
case PNG_COLOR_TYPE_PALETTE:
|
||||||
|
raw_image = indexed_png_to_raw(&img); break;
|
||||||
|
case PNG_COLOR_TYPE_GRAY:
|
||||||
|
case PNG_COLOR_TYPE_GRAY_ALPHA:
|
||||||
|
raw_image = grayscale_png_to_raw(&img); break;
|
||||||
|
case PNG_COLOR_TYPE_RGB:
|
||||||
|
case PNG_COLOR_TYPE_RGB_ALPHA:
|
||||||
|
raw_image = truecolor_png_to_raw(&img); break;
|
||||||
|
default:
|
||||||
|
/* Shouldn't happen, but might as well handle just in case. */
|
||||||
|
errx(1, "Input PNG file is of invalid color type.");
|
||||||
|
}
|
||||||
|
|
||||||
|
get_text(&img, png_options);
|
||||||
|
|
||||||
|
png_destroy_read_struct(&img.png, &img.info, NULL);
|
||||||
|
fclose(f);
|
||||||
|
free_png_data(&img);
|
||||||
|
|
||||||
|
return raw_image;
|
||||||
|
}
|
||||||
|
|
||||||
|
void output_png_file(const struct Options *opts,
|
||||||
|
const struct ImageOptions *png_options,
|
||||||
|
const struct RawIndexedImage *raw_image)
|
||||||
{
|
{
|
||||||
FILE *f;
|
FILE *f;
|
||||||
int i, y, num_trans;
|
char *outfile;
|
||||||
bool has_palette = false;
|
struct PNGImage img;
|
||||||
png_byte *trans_alpha;
|
png_color *png_palette;
|
||||||
png_color_16 *trans_values;
|
int i;
|
||||||
bool *full_alpha;
|
|
||||||
png_color *palette;
|
|
||||||
|
|
||||||
f = fopen(opts.infile, "rb");
|
/*
|
||||||
|
* TODO: Variable outfile is for debugging purposes. Eventually,
|
||||||
|
* opts.infile will be used directly.
|
||||||
|
*/
|
||||||
|
if (opts->debug) {
|
||||||
|
outfile = malloc(strlen(opts->infile) + 5);
|
||||||
|
strcpy(outfile, opts->infile);
|
||||||
|
strcat(outfile, ".out");
|
||||||
|
} else {
|
||||||
|
outfile = opts->infile;
|
||||||
|
}
|
||||||
|
|
||||||
|
f = fopen(outfile, "wb");
|
||||||
if (!f)
|
if (!f)
|
||||||
err(1, "Opening input png file '%s' failed", opts.infile);
|
err(1, "Opening output png file '%s' failed", outfile);
|
||||||
|
|
||||||
|
img.png = png_create_write_struct(PNG_LIBPNG_VER_STRING,
|
||||||
|
NULL, NULL, NULL);
|
||||||
|
if (!img.png)
|
||||||
|
errx(1, "Creating png structure failed");
|
||||||
|
|
||||||
|
img.info = png_create_info_struct(img.png);
|
||||||
|
if (!img.info)
|
||||||
|
errx(1, "Creating png info structure failed");
|
||||||
|
|
||||||
|
if (setjmp(png_jmpbuf(img.png)))
|
||||||
|
exit(1);
|
||||||
|
|
||||||
|
png_init_io(img.png, f);
|
||||||
|
|
||||||
|
png_set_IHDR(img.png, img.info, raw_image->width, raw_image->height,
|
||||||
|
8, PNG_COLOR_TYPE_PALETTE, PNG_INTERLACE_NONE,
|
||||||
|
PNG_COMPRESSION_TYPE_DEFAULT, PNG_FILTER_TYPE_DEFAULT);
|
||||||
|
|
||||||
|
png_palette = malloc(sizeof(png_color *) * raw_image->num_colors);
|
||||||
|
for (i = 0; i < raw_image->num_colors; i++) {
|
||||||
|
png_palette[i].red = raw_image->palette[i].red;
|
||||||
|
png_palette[i].green = raw_image->palette[i].green;
|
||||||
|
png_palette[i].blue = raw_image->palette[i].blue;
|
||||||
|
}
|
||||||
|
png_set_PLTE(img.png, img.info, png_palette, raw_image->num_colors);
|
||||||
|
free(png_palette);
|
||||||
|
|
||||||
|
if (opts->fix)
|
||||||
|
set_text(&img, png_options);
|
||||||
|
|
||||||
|
png_write_info(img.png, img.info);
|
||||||
|
|
||||||
|
png_write_image(img.png, (png_byte **) raw_image->data);
|
||||||
|
png_write_end(img.png, NULL);
|
||||||
|
|
||||||
|
png_destroy_write_struct(&img.png, &img.info);
|
||||||
|
fclose(f);
|
||||||
|
|
||||||
|
if (opts->debug)
|
||||||
|
free(outfile);
|
||||||
|
}
|
||||||
|
|
||||||
|
void destroy_raw_image(struct RawIndexedImage **raw_image_ptr_ptr)
|
||||||
|
{
|
||||||
|
int y;
|
||||||
|
struct RawIndexedImage *raw_image = *raw_image_ptr_ptr;
|
||||||
|
|
||||||
|
for (y = 0; y < raw_image->height; y++)
|
||||||
|
free(raw_image->data[y]);
|
||||||
|
|
||||||
|
free(raw_image->data);
|
||||||
|
free(raw_image->palette);
|
||||||
|
free(raw_image);
|
||||||
|
*raw_image_ptr_ptr = NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
static void initialize_png(struct PNGImage *img, FILE *f)
|
||||||
|
{
|
||||||
img->png = png_create_read_struct(PNG_LIBPNG_VER_STRING,
|
img->png = png_create_read_struct(PNG_LIBPNG_VER_STRING,
|
||||||
NULL, NULL, NULL);
|
NULL, NULL, NULL);
|
||||||
if (!img->png)
|
if (!img->png)
|
||||||
@@ -42,7 +159,6 @@ void input_png_file(const struct Options opts, struct PNGImage *img)
|
|||||||
if (!img->info)
|
if (!img->info)
|
||||||
errx(1, "Creating png info structure failed");
|
errx(1, "Creating png info structure failed");
|
||||||
|
|
||||||
/* TODO: Better error handling here? */
|
|
||||||
if (setjmp(png_jmpbuf(img->png)))
|
if (setjmp(png_jmpbuf(img->png)))
|
||||||
exit(1);
|
exit(1);
|
||||||
|
|
||||||
@@ -54,125 +170,415 @@ void input_png_file(const struct Options opts, struct PNGImage *img)
|
|||||||
img->height = png_get_image_height(img->png, img->info);
|
img->height = png_get_image_height(img->png, img->info);
|
||||||
img->depth = png_get_bit_depth(img->png, img->info);
|
img->depth = png_get_bit_depth(img->png, img->info);
|
||||||
img->type = png_get_color_type(img->png, img->info);
|
img->type = png_get_color_type(img->png, img->info);
|
||||||
|
}
|
||||||
|
|
||||||
if (img->type & PNG_COLOR_MASK_ALPHA)
|
static void read_png(struct PNGImage *img);
|
||||||
png_set_strip_alpha(img->png);
|
static struct RawIndexedImage *create_raw_image(int width, int height,
|
||||||
|
int num_colors);
|
||||||
|
static void set_raw_image_palette(struct RawIndexedImage *raw_image,
|
||||||
|
const png_color *palette, int num_colors);
|
||||||
|
|
||||||
if (img->depth != depth) {
|
static struct RawIndexedImage *indexed_png_to_raw(struct PNGImage *img)
|
||||||
if (opts.verbose) {
|
{
|
||||||
warnx("Image bit depth is not %i (is %i).", depth,
|
struct RawIndexedImage *raw_image;
|
||||||
img->depth);
|
png_color *palette;
|
||||||
|
int colors_in_PLTE;
|
||||||
|
int colors_in_new_palette;
|
||||||
|
png_byte *trans_alpha;
|
||||||
|
int num_trans;
|
||||||
|
png_color_16 *trans_color;
|
||||||
|
png_color *original_palette;
|
||||||
|
uint8_t *old_to_new_palette;
|
||||||
|
int i, x, y;
|
||||||
|
|
||||||
|
if (img->depth < 8)
|
||||||
|
png_set_packing(img->png);
|
||||||
|
|
||||||
|
png_get_PLTE(img->png, img->info, &palette, &colors_in_PLTE);
|
||||||
|
|
||||||
|
raw_image = create_raw_image(img->width, img->height, colors);
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Transparent palette entries are removed, and the palette is collapsed.
|
||||||
|
* Transparent pixels are then replaced with palette index 0.
|
||||||
|
* This way, an indexed PNG can contain transparent pixels in *addition*
|
||||||
|
* to 4 normal colors.
|
||||||
|
*/
|
||||||
|
if (png_get_tRNS(img->png, img->info, &trans_alpha, &num_trans,
|
||||||
|
&trans_color)) {
|
||||||
|
original_palette = palette;
|
||||||
|
palette = malloc(sizeof(png_color) * colors_in_PLTE);
|
||||||
|
colors_in_new_palette = 0;
|
||||||
|
old_to_new_palette = malloc(sizeof(uint8_t) * colors_in_PLTE);
|
||||||
|
|
||||||
|
for (i = 0; i < num_trans; i++) {
|
||||||
|
if (trans_alpha[i] == 0) {
|
||||||
|
old_to_new_palette[i] = 0;
|
||||||
|
} else {
|
||||||
|
old_to_new_palette[i] = colors_in_new_palette;
|
||||||
|
palette[colors_in_new_palette++] =
|
||||||
|
original_palette[i];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
for (i = num_trans; i < colors_in_PLTE; i++) {
|
||||||
|
old_to_new_palette[i] = colors_in_new_palette;
|
||||||
|
palette[colors_in_new_palette++] = original_palette[i];
|
||||||
|
}
|
||||||
|
|
||||||
|
if (colors_in_new_palette != colors_in_PLTE) {
|
||||||
|
palette = realloc(palette,
|
||||||
|
sizeof(png_color) *
|
||||||
|
colors_in_new_palette);
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Setting and validating palette before reading
|
||||||
|
* allows us to error out *before* doing the data
|
||||||
|
* transformation if the palette is too long.
|
||||||
|
*/
|
||||||
|
set_raw_image_palette(raw_image, palette,
|
||||||
|
colors_in_new_palette);
|
||||||
|
read_png(img);
|
||||||
|
|
||||||
|
for (y = 0; y < img->height; y++) {
|
||||||
|
for (x = 0; x < img->width; x++) {
|
||||||
|
raw_image->data[y][x] =
|
||||||
|
old_to_new_palette[img->data[y][x]];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (img->type == PNG_COLOR_TYPE_GRAY) {
|
free(old_to_new_palette);
|
||||||
|
} else {
|
||||||
|
set_raw_image_palette(raw_image, palette, colors_in_PLTE);
|
||||||
|
read_png(img);
|
||||||
|
|
||||||
|
for (y = 0; y < img->height; y++) {
|
||||||
|
for (x = 0; x < img->width; x++)
|
||||||
|
raw_image->data[y][x] = img->data[y][x];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return raw_image;
|
||||||
|
}
|
||||||
|
|
||||||
|
static struct RawIndexedImage *grayscale_png_to_raw(struct PNGImage *img)
|
||||||
|
{
|
||||||
if (img->depth < 8)
|
if (img->depth < 8)
|
||||||
png_set_expand_gray_1_2_4_to_8(img->png);
|
png_set_expand_gray_1_2_4_to_8(img->png);
|
||||||
|
|
||||||
png_set_gray_to_rgb(img->png);
|
png_set_gray_to_rgb(img->png);
|
||||||
} else {
|
return truecolor_png_to_raw(img);
|
||||||
if (img->depth < 8)
|
}
|
||||||
png_set_expand_gray_1_2_4_to_8(img->png);
|
|
||||||
|
|
||||||
has_palette = png_get_PLTE(img->png, img->info, &palette,
|
static void rgba_png_palette(struct PNGImage *img,
|
||||||
&colors);
|
png_color **palette_ptr_ptr, int *num_colors);
|
||||||
}
|
static struct RawIndexedImage
|
||||||
|
*processed_rgba_png_to_raw(const struct PNGImage *img,
|
||||||
|
const png_color *palette,
|
||||||
|
int colors_in_palette);
|
||||||
|
|
||||||
if (png_get_tRNS(img->png, img->info, &trans_alpha, &num_trans,
|
static struct RawIndexedImage *truecolor_png_to_raw(struct PNGImage *img)
|
||||||
&trans_values)) {
|
{
|
||||||
if (img->type == PNG_COLOR_TYPE_PALETTE) {
|
struct RawIndexedImage *raw_image;
|
||||||
full_alpha = malloc(sizeof(bool) * num_trans);
|
png_color *palette;
|
||||||
|
int colors_in_palette;
|
||||||
|
|
||||||
for (i = 0; i < num_trans; i++) {
|
if (img->depth == 16) {
|
||||||
if (trans_alpha[i] > 0)
|
#if PNG_LIBPNG_VER >= 10504
|
||||||
full_alpha[i] = false;
|
png_set_scale_16(img->png);
|
||||||
else
|
|
||||||
full_alpha[i] = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
for (i = 0; i < num_trans; i++) {
|
|
||||||
if (full_alpha[i]) {
|
|
||||||
palette[i].red = 0xFF;
|
|
||||||
palette[i].green = 0x00;
|
|
||||||
palette[i].blue = 0xFF;
|
|
||||||
/*
|
|
||||||
* Set to the lightest color in the
|
|
||||||
* palette.
|
|
||||||
*/
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
free(full_alpha);
|
|
||||||
} else {
|
|
||||||
/* Set to the lightest color in the image. */
|
|
||||||
}
|
|
||||||
|
|
||||||
png_free_data(img->png, img->info, PNG_FREE_TRNS, -1);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (has_palette) {
|
|
||||||
/* Make sure palette only has the amount of colors you want. */
|
|
||||||
} else {
|
|
||||||
/*
|
|
||||||
* Eventually when this copies colors from the image itself,
|
|
||||||
* make sure order is lightest to darkest.
|
|
||||||
*/
|
|
||||||
palette = malloc(sizeof(png_color) * colors);
|
|
||||||
|
|
||||||
if (strcmp(opts.infile, "rgb.png") == 0) {
|
|
||||||
palette[0].red = 0xFF;
|
|
||||||
palette[0].green = 0xEF;
|
|
||||||
palette[0].blue = 0xFF;
|
|
||||||
|
|
||||||
palette[1].red = 0xF7;
|
|
||||||
palette[1].green = 0xF7;
|
|
||||||
palette[1].blue = 0x8C;
|
|
||||||
|
|
||||||
palette[2].red = 0x94;
|
|
||||||
palette[2].green = 0x94;
|
|
||||||
palette[2].blue = 0xC6;
|
|
||||||
|
|
||||||
palette[3].red = 0x39;
|
|
||||||
palette[3].green = 0x39;
|
|
||||||
palette[3].blue = 0x84;
|
|
||||||
} else {
|
|
||||||
palette[0].red = 0xFF;
|
|
||||||
palette[0].green = 0xFF;
|
|
||||||
palette[0].blue = 0xFF;
|
|
||||||
|
|
||||||
palette[1].red = 0xA9;
|
|
||||||
palette[1].green = 0xA9;
|
|
||||||
palette[1].blue = 0xA9;
|
|
||||||
|
|
||||||
palette[2].red = 0x55;
|
|
||||||
palette[2].green = 0x55;
|
|
||||||
palette[2].blue = 0x55;
|
|
||||||
|
|
||||||
palette[3].red = 0x00;
|
|
||||||
palette[3].green = 0x00;
|
|
||||||
palette[3].blue = 0x00;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Also unfortunately, this sets it at 8 bit, and I can't find any
|
|
||||||
* option to reduce to 2 or 1 bit.
|
|
||||||
*/
|
|
||||||
#if PNG_LIBPNG_VER < 10402
|
|
||||||
png_set_dither(img->png, palette, colors, colors, NULL, 1);
|
|
||||||
#else
|
#else
|
||||||
png_set_quantize(img->png, palette, colors, colors, NULL, 1);
|
png_set_strip_16(img->png);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
if (!has_palette) {
|
|
||||||
png_set_PLTE(img->png, img->info, palette, colors);
|
|
||||||
free(palette);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!(img->type & PNG_COLOR_MASK_ALPHA)) {
|
||||||
|
if (png_get_valid(img->png, img->info, PNG_INFO_tRNS))
|
||||||
|
png_set_tRNS_to_alpha(img->png);
|
||||||
|
else
|
||||||
|
png_set_add_alpha(img->png, 0xFF, PNG_FILLER_AFTER);
|
||||||
|
}
|
||||||
|
|
||||||
|
read_png(img);
|
||||||
|
|
||||||
|
rgba_png_palette(img, &palette, &colors_in_palette);
|
||||||
|
raw_image = processed_rgba_png_to_raw(img, palette, colors_in_palette);
|
||||||
|
|
||||||
|
free(palette);
|
||||||
|
|
||||||
|
return raw_image;
|
||||||
|
}
|
||||||
|
|
||||||
|
static void rgba_PLTE_palette(struct PNGImage *img,
|
||||||
|
png_color **palette_ptr_ptr, int *num_colors);
|
||||||
|
static void rgba_build_palette(struct PNGImage *img,
|
||||||
|
png_color **palette_ptr_ptr, int *num_colors);
|
||||||
|
|
||||||
|
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))
|
||||||
|
rgba_PLTE_palette(img, palette_ptr_ptr, num_colors);
|
||||||
|
else
|
||||||
|
rgba_build_palette(img, palette_ptr_ptr, num_colors);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void rgba_PLTE_palette(struct PNGImage *img,
|
||||||
|
png_color **palette_ptr_ptr, int *num_colors)
|
||||||
|
{
|
||||||
|
png_get_PLTE(img->png, img->info, palette_ptr_ptr, num_colors);
|
||||||
/*
|
/*
|
||||||
* If other useless chunks exist (sRGB, bKGD, pHYs, gAMA, cHRM, iCCP,
|
* Lets us free the palette manually instead of leaving it to libpng,
|
||||||
* etc.) offer to remove?
|
* which lets us handle a PLTE and a built palette the same way.
|
||||||
*/
|
*/
|
||||||
|
png_data_freer(img->png, img->info,
|
||||||
|
PNG_USER_WILL_FREE_DATA, PNG_FREE_PLTE);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void update_built_palette(png_color *palette,
|
||||||
|
const png_color *pixel_color, png_byte alpha,
|
||||||
|
int *num_colors, bool *only_grayscale);
|
||||||
|
static int fit_grayscale_palette(png_color *palette, int *num_colors);
|
||||||
|
static void order_color_palette(png_color *palette, int num_colors);
|
||||||
|
|
||||||
|
static void rgba_build_palette(struct PNGImage *img,
|
||||||
|
png_color **palette_ptr_ptr, int *num_colors)
|
||||||
|
{
|
||||||
|
png_color *palette;
|
||||||
|
int y, value_index;
|
||||||
|
png_color cur_pixel_color;
|
||||||
|
png_byte cur_alpha;
|
||||||
|
bool only_grayscale = true;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* By filling the palette up with black by default, if the image
|
||||||
|
* doesn't have enough colors, the palette gets padded with black.
|
||||||
|
*/
|
||||||
|
*palette_ptr_ptr = calloc(colors, sizeof(png_color));
|
||||||
|
palette = *palette_ptr_ptr;
|
||||||
|
*num_colors = 0;
|
||||||
|
|
||||||
|
for (y = 0; y < img->height; y++) {
|
||||||
|
value_index = 0;
|
||||||
|
while (value_index < img->width * 4) {
|
||||||
|
cur_pixel_color.red = img->data[y][value_index++];
|
||||||
|
cur_pixel_color.green = img->data[y][value_index++];
|
||||||
|
cur_pixel_color.blue = img->data[y][value_index++];
|
||||||
|
cur_alpha = img->data[y][value_index++];
|
||||||
|
|
||||||
|
update_built_palette(palette, &cur_pixel_color,
|
||||||
|
cur_alpha,
|
||||||
|
num_colors, &only_grayscale);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/* In order not to count 100% transparent images as grayscale. */
|
||||||
|
only_grayscale = *num_colors ? only_grayscale : false;
|
||||||
|
|
||||||
|
if (!only_grayscale || !fit_grayscale_palette(palette, num_colors))
|
||||||
|
order_color_palette(palette, *num_colors);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void update_built_palette(png_color *palette,
|
||||||
|
const png_color *pixel_color, png_byte alpha,
|
||||||
|
int *num_colors, bool *only_grayscale)
|
||||||
|
{
|
||||||
|
bool color_exists;
|
||||||
|
png_color cur_palette_color;
|
||||||
|
int i;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Transparent pixels don't count toward the palette,
|
||||||
|
* as they'll be replaced with color #0 later.
|
||||||
|
*/
|
||||||
|
if (alpha == 0)
|
||||||
|
return;
|
||||||
|
|
||||||
|
if (*only_grayscale && !(pixel_color->red == pixel_color->green &&
|
||||||
|
pixel_color->red == pixel_color->blue)) {
|
||||||
|
*only_grayscale = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
color_exists = false;
|
||||||
|
for (i = 0; i < *num_colors; i++) {
|
||||||
|
cur_palette_color = palette[i];
|
||||||
|
if (pixel_color->red == cur_palette_color.red &&
|
||||||
|
pixel_color->green == cur_palette_color.green &&
|
||||||
|
pixel_color->blue == cur_palette_color.blue) {
|
||||||
|
color_exists = true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (!color_exists) {
|
||||||
|
if (*num_colors == colors) {
|
||||||
|
err(1, "Too many colors in input PNG file to fit into a %d-bit palette (max %d).",
|
||||||
|
depth, colors);
|
||||||
|
}
|
||||||
|
palette[*num_colors] = *pixel_color;
|
||||||
|
(*num_colors)++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static int fit_grayscale_palette(png_color *palette, int *num_colors)
|
||||||
|
{
|
||||||
|
int interval = 256 / colors;
|
||||||
|
png_color *fitted_palette = malloc(sizeof(png_color) * colors);
|
||||||
|
bool *set_indices = calloc(colors, sizeof(bool));
|
||||||
|
int i, shade_index;
|
||||||
|
|
||||||
|
fitted_palette[0].red = 0xFF;
|
||||||
|
fitted_palette[0].green = 0xFF;
|
||||||
|
fitted_palette[0].blue = 0xFF;
|
||||||
|
fitted_palette[colors - 1].red = 0;
|
||||||
|
fitted_palette[colors - 1].green = 0;
|
||||||
|
fitted_palette[colors - 1].blue = 0;
|
||||||
|
if (colors == 4) {
|
||||||
|
fitted_palette[1].red = 0xA9;
|
||||||
|
fitted_palette[1].green = 0xA9;
|
||||||
|
fitted_palette[1].blue = 0xA9;
|
||||||
|
fitted_palette[2].red = 0x55;
|
||||||
|
fitted_palette[2].green = 0x55;
|
||||||
|
fitted_palette[2].blue = 0x55;
|
||||||
|
}
|
||||||
|
|
||||||
|
for (i = 0; i < *num_colors; i++) {
|
||||||
|
shade_index = colors - 1 - palette[i].red / interval;
|
||||||
|
if (set_indices[shade_index]) {
|
||||||
|
free(fitted_palette);
|
||||||
|
free(set_indices);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
fitted_palette[shade_index] = palette[i];
|
||||||
|
set_indices[shade_index] = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
for (i = 0; i < colors; i++)
|
||||||
|
palette[i] = fitted_palette[i];
|
||||||
|
|
||||||
|
*num_colors = colors;
|
||||||
|
|
||||||
|
free(fitted_palette);
|
||||||
|
free(set_indices);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* A combined struct is needed to sort csolors in order of luminance. */
|
||||||
|
struct ColorWithLuminance {
|
||||||
|
png_color color;
|
||||||
|
int luminance;
|
||||||
|
};
|
||||||
|
|
||||||
|
static int compare_luminance(const void *a, const void *b)
|
||||||
|
{
|
||||||
|
const struct ColorWithLuminance *x, *y;
|
||||||
|
|
||||||
|
x = (const struct ColorWithLuminance *)a;
|
||||||
|
y = (const struct ColorWithLuminance *)b;
|
||||||
|
|
||||||
|
return y->luminance - x->luminance;
|
||||||
|
}
|
||||||
|
|
||||||
|
static void order_color_palette(png_color *palette, int num_colors)
|
||||||
|
{
|
||||||
|
int i;
|
||||||
|
struct ColorWithLuminance *palette_with_luminance =
|
||||||
|
malloc(sizeof(struct ColorWithLuminance) * num_colors);
|
||||||
|
|
||||||
|
for (i = 0; i < num_colors; i++) {
|
||||||
|
/*
|
||||||
|
* Normally this would be done with floats, but since it's only
|
||||||
|
* used for comparison, we might as well use integer math.
|
||||||
|
*/
|
||||||
|
palette_with_luminance[i].color = palette[i];
|
||||||
|
palette_with_luminance[i].luminance = 2126 * palette[i].red +
|
||||||
|
7152 * palette[i].green +
|
||||||
|
722 * palette[i].blue;
|
||||||
|
}
|
||||||
|
qsort(palette_with_luminance, num_colors,
|
||||||
|
sizeof(struct ColorWithLuminance), compare_luminance);
|
||||||
|
for (i = 0; i < num_colors; i++)
|
||||||
|
palette[i] = palette_with_luminance[i].color;
|
||||||
|
|
||||||
|
free(palette_with_luminance);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void put_raw_image_pixel(struct RawIndexedImage *raw_image,
|
||||||
|
const struct PNGImage *img,
|
||||||
|
int *value_index, int x, int y,
|
||||||
|
const png_color *palette,
|
||||||
|
int colors_in_palette);
|
||||||
|
|
||||||
|
static struct RawIndexedImage
|
||||||
|
*processed_rgba_png_to_raw(const struct PNGImage *img,
|
||||||
|
const png_color *palette,
|
||||||
|
int colors_in_palette)
|
||||||
|
{
|
||||||
|
struct RawIndexedImage *raw_image;
|
||||||
|
int x, y, value_index;
|
||||||
|
|
||||||
|
raw_image = create_raw_image(img->width, img->height, colors);
|
||||||
|
|
||||||
|
set_raw_image_palette(raw_image, palette, colors_in_palette);
|
||||||
|
|
||||||
|
for (y = 0; y < img->height; y++) {
|
||||||
|
x = raw_image->width - 1;
|
||||||
|
value_index = img->width * 4 - 1;
|
||||||
|
|
||||||
|
while (x >= 0) {
|
||||||
|
put_raw_image_pixel(raw_image, img,
|
||||||
|
&value_index, x, y,
|
||||||
|
palette, colors_in_palette);
|
||||||
|
x--;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return raw_image;
|
||||||
|
}
|
||||||
|
|
||||||
|
static uint8_t palette_index_of(const png_color *palette,
|
||||||
|
int num_colors, const png_color *color);
|
||||||
|
|
||||||
|
static void put_raw_image_pixel(struct RawIndexedImage *raw_image,
|
||||||
|
const struct PNGImage *img,
|
||||||
|
int *value_index, int x, int y,
|
||||||
|
const png_color *palette,
|
||||||
|
int colors_in_palette)
|
||||||
|
{
|
||||||
|
png_color pixel_color;
|
||||||
|
png_byte alpha;
|
||||||
|
|
||||||
|
alpha = img->data[y][*value_index];
|
||||||
|
if (alpha == 0) {
|
||||||
|
raw_image->data[y][x] = 0;
|
||||||
|
*value_index -= 4;
|
||||||
|
} else {
|
||||||
|
(*value_index)--;
|
||||||
|
pixel_color.blue = img->data[y][(*value_index)--];
|
||||||
|
pixel_color.green = img->data[y][(*value_index)--];
|
||||||
|
pixel_color.red = img->data[y][(*value_index)--];
|
||||||
|
raw_image->data[y][x] = palette_index_of(palette,
|
||||||
|
colors_in_palette,
|
||||||
|
&pixel_color);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static uint8_t palette_index_of(const png_color *palette,
|
||||||
|
int num_colors, const png_color *color)
|
||||||
|
{
|
||||||
|
uint8_t i;
|
||||||
|
|
||||||
|
for (i = 0; i < num_colors; i++) {
|
||||||
|
if (palette[i].red == color->red &&
|
||||||
|
palette[i].green == color->green &&
|
||||||
|
palette[i].blue == color->blue) {
|
||||||
|
return i;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
errx(1, "The input PNG file contains colors that don't appear in its embedded palette.");
|
||||||
|
}
|
||||||
|
|
||||||
|
static void read_png(struct PNGImage *img)
|
||||||
|
{
|
||||||
|
int y;
|
||||||
|
|
||||||
png_read_update_info(img->png, img->info);
|
png_read_update_info(img->png, img->info);
|
||||||
|
|
||||||
@@ -182,35 +588,78 @@ void input_png_file(const struct Options opts, struct PNGImage *img)
|
|||||||
|
|
||||||
png_read_image(img->png, img->data);
|
png_read_image(img->png, img->data);
|
||||||
png_read_end(img->png, img->info);
|
png_read_end(img->png, img->info);
|
||||||
|
|
||||||
fclose(f);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void get_text(struct PNGImage *png)
|
static struct RawIndexedImage *create_raw_image(int width, int height,
|
||||||
|
int num_colors)
|
||||||
|
{
|
||||||
|
struct RawIndexedImage *raw_image;
|
||||||
|
int y;
|
||||||
|
|
||||||
|
raw_image = malloc(sizeof(struct RawIndexedImage));
|
||||||
|
|
||||||
|
raw_image->width = width;
|
||||||
|
raw_image->height = height;
|
||||||
|
raw_image->num_colors = num_colors;
|
||||||
|
|
||||||
|
raw_image->palette = malloc(sizeof(struct RGBColor) * num_colors);
|
||||||
|
|
||||||
|
raw_image->data = malloc(sizeof(uint8_t *) * height);
|
||||||
|
for (y = 0; y < height; y++)
|
||||||
|
raw_image->data[y] = malloc(sizeof(uint8_t) * width);
|
||||||
|
|
||||||
|
return raw_image;
|
||||||
|
}
|
||||||
|
|
||||||
|
static void set_raw_image_palette(struct RawIndexedImage *raw_image,
|
||||||
|
const png_color *palette, int num_colors)
|
||||||
|
{
|
||||||
|
int i;
|
||||||
|
|
||||||
|
if (num_colors > raw_image->num_colors) {
|
||||||
|
errx(1, "Too many colors in input PNG file's palette to fit into a %d-bit palette (%d in input palette, max %d).",
|
||||||
|
raw_image->num_colors >> 1,
|
||||||
|
num_colors, raw_image->num_colors);
|
||||||
|
}
|
||||||
|
|
||||||
|
for (i = 0; i < num_colors; i++) {
|
||||||
|
raw_image->palette[i].red = palette[i].red;
|
||||||
|
raw_image->palette[i].green = palette[i].green;
|
||||||
|
raw_image->palette[i].blue = palette[i].blue;
|
||||||
|
}
|
||||||
|
for (i = num_colors; i < raw_image->num_colors; i++) {
|
||||||
|
raw_image->palette[i].red = 0;
|
||||||
|
raw_image->palette[i].green = 0;
|
||||||
|
raw_image->palette[i].blue = 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static void get_text(const struct PNGImage *img,
|
||||||
|
struct ImageOptions *png_options)
|
||||||
{
|
{
|
||||||
png_text *text;
|
png_text *text;
|
||||||
int i, numtxts, numremoved;
|
int i, numtxts, numremoved;
|
||||||
|
|
||||||
png_get_text(png->png, png->info, &text, &numtxts);
|
png_get_text(img->png, img->info, &text, &numtxts);
|
||||||
for (i = 0; i < numtxts; i++) {
|
for (i = 0; i < numtxts; i++) {
|
||||||
if (strcmp(text[i].key, "h") == 0 && !*text[i].text) {
|
if (strcmp(text[i].key, "h") == 0 && !*text[i].text) {
|
||||||
png->horizontal = true;
|
png_options->horizontal = true;
|
||||||
png_free_data(png->png, png->info, PNG_FREE_TEXT, i);
|
png_free_data(img->png, img->info, PNG_FREE_TEXT, i);
|
||||||
} else if (strcmp(text[i].key, "x") == 0) {
|
} else if (strcmp(text[i].key, "x") == 0) {
|
||||||
png->trim = strtoul(text[i].text, NULL, 0);
|
png_options->trim = strtoul(text[i].text, NULL, 0);
|
||||||
png_free_data(png->png, png->info, PNG_FREE_TEXT, i);
|
png_free_data(img->png, img->info, PNG_FREE_TEXT, i);
|
||||||
} else if (strcmp(text[i].key, "t") == 0) {
|
} else if (strcmp(text[i].key, "t") == 0) {
|
||||||
png->mapfile = text[i].text;
|
png_options->mapfile = text[i].text;
|
||||||
png_free_data(png->png, png->info, PNG_FREE_TEXT, i);
|
png_free_data(img->png, img->info, PNG_FREE_TEXT, i);
|
||||||
} else if (strcmp(text[i].key, "T") == 0 && !*text[i].text) {
|
} else if (strcmp(text[i].key, "T") == 0 && !*text[i].text) {
|
||||||
png->mapout = true;
|
png_options->mapout = true;
|
||||||
png_free_data(png->png, png->info, PNG_FREE_TEXT, i);
|
png_free_data(img->png, img->info, PNG_FREE_TEXT, i);
|
||||||
} else if (strcmp(text[i].key, "p") == 0) {
|
} else if (strcmp(text[i].key, "p") == 0) {
|
||||||
png->palfile = text[i].text;
|
png_options->palfile = text[i].text;
|
||||||
png_free_data(png->png, png->info, PNG_FREE_TEXT, i);
|
png_free_data(img->png, img->info, PNG_FREE_TEXT, i);
|
||||||
} else if (strcmp(text[i].key, "P") == 0 && !*text[i].text) {
|
} else if (strcmp(text[i].key, "P") == 0 && !*text[i].text) {
|
||||||
png->palout = true;
|
png_options->palout = true;
|
||||||
png_free_data(png->png, png->info, PNG_FREE_TEXT, i);
|
png_free_data(img->png, img->info, PNG_FREE_TEXT, i);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -226,106 +675,64 @@ void get_text(struct PNGImage *png)
|
|||||||
text[i].text = text[i + numremoved].text;
|
text[i].text = text[i + numremoved].text;
|
||||||
text[i].compression = text[i + numremoved].compression;
|
text[i].compression = text[i + numremoved].compression;
|
||||||
}
|
}
|
||||||
png_set_text(png->png, png->info, text, numtxts - numremoved);
|
png_set_text(img->png, img->info, text, numtxts - numremoved);
|
||||||
}
|
}
|
||||||
|
|
||||||
void set_text(const struct PNGImage *png)
|
static void set_text(const struct PNGImage *img,
|
||||||
|
const struct ImageOptions *png_options)
|
||||||
{
|
{
|
||||||
png_text *text;
|
png_text *text;
|
||||||
char buffer[3];
|
char buffer[3];
|
||||||
|
|
||||||
text = malloc(sizeof(png_text));
|
text = malloc(sizeof(png_text));
|
||||||
|
|
||||||
if (png->horizontal) {
|
if (png_options->horizontal) {
|
||||||
text[0].key = "h";
|
text[0].key = "h";
|
||||||
text[0].text = "";
|
text[0].text = "";
|
||||||
text[0].compression = PNG_TEXT_COMPRESSION_NONE;
|
text[0].compression = PNG_TEXT_COMPRESSION_NONE;
|
||||||
png_set_text(png->png, png->info, text, 1);
|
png_set_text(img->png, img->info, text, 1);
|
||||||
}
|
}
|
||||||
if (png->trim) {
|
if (png_options->trim) {
|
||||||
text[0].key = "x";
|
text[0].key = "x";
|
||||||
snprintf(buffer, 3, "%d", png->trim);
|
snprintf(buffer, 3, "%d", png_options->trim);
|
||||||
text[0].text = buffer;
|
text[0].text = buffer;
|
||||||
text[0].compression = PNG_TEXT_COMPRESSION_NONE;
|
text[0].compression = PNG_TEXT_COMPRESSION_NONE;
|
||||||
png_set_text(png->png, png->info, text, 1);
|
png_set_text(img->png, img->info, text, 1);
|
||||||
}
|
}
|
||||||
if (*png->mapfile) {
|
if (*png_options->mapfile) {
|
||||||
text[0].key = "t";
|
text[0].key = "t";
|
||||||
text[0].text = "";
|
text[0].text = "";
|
||||||
text[0].compression = PNG_TEXT_COMPRESSION_NONE;
|
text[0].compression = PNG_TEXT_COMPRESSION_NONE;
|
||||||
png_set_text(png->png, png->info, text, 1);
|
png_set_text(img->png, img->info, text, 1);
|
||||||
}
|
}
|
||||||
if (png->mapout) {
|
if (png_options->mapout) {
|
||||||
text[0].key = "T";
|
text[0].key = "T";
|
||||||
text[0].text = "";
|
text[0].text = "";
|
||||||
text[0].compression = PNG_TEXT_COMPRESSION_NONE;
|
text[0].compression = PNG_TEXT_COMPRESSION_NONE;
|
||||||
png_set_text(png->png, png->info, text, 1);
|
png_set_text(img->png, img->info, text, 1);
|
||||||
}
|
}
|
||||||
if (*png->palfile) {
|
if (*png_options->palfile) {
|
||||||
text[0].key = "p";
|
text[0].key = "p";
|
||||||
text[0].text = "";
|
text[0].text = "";
|
||||||
text[0].compression = PNG_TEXT_COMPRESSION_NONE;
|
text[0].compression = PNG_TEXT_COMPRESSION_NONE;
|
||||||
png_set_text(png->png, png->info, text, 1);
|
png_set_text(img->png, img->info, text, 1);
|
||||||
}
|
}
|
||||||
if (png->palout) {
|
if (png_options->palout) {
|
||||||
text[0].key = "P";
|
text[0].key = "P";
|
||||||
text[0].text = "";
|
text[0].text = "";
|
||||||
text[0].compression = PNG_TEXT_COMPRESSION_NONE;
|
text[0].compression = PNG_TEXT_COMPRESSION_NONE;
|
||||||
png_set_text(png->png, png->info, text, 1);
|
png_set_text(img->png, img->info, text, 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
free(text);
|
free(text);
|
||||||
}
|
}
|
||||||
|
|
||||||
void output_png_file(const struct Options opts, const struct PNGImage *png)
|
static void free_png_data(const struct PNGImage *img)
|
||||||
{
|
|
||||||
FILE *f;
|
|
||||||
char *outfile;
|
|
||||||
png_struct *img;
|
|
||||||
|
|
||||||
/*
|
|
||||||
* TODO: Variable outfile is for debugging purposes. Eventually,
|
|
||||||
* opts.infile will be used directly.
|
|
||||||
*/
|
|
||||||
if (opts.debug) {
|
|
||||||
outfile = malloc(strlen(opts.infile) + 5);
|
|
||||||
strcpy(outfile, opts.infile);
|
|
||||||
strcat(outfile, ".out");
|
|
||||||
} else {
|
|
||||||
outfile = opts.infile;
|
|
||||||
}
|
|
||||||
|
|
||||||
f = fopen(outfile, "wb");
|
|
||||||
if (!f)
|
|
||||||
err(1, "Opening output png file '%s' failed", outfile);
|
|
||||||
|
|
||||||
img = png_create_write_struct(PNG_LIBPNG_VER_STRING, NULL, NULL, NULL);
|
|
||||||
if (!img)
|
|
||||||
errx(1, "Creating png structure failed");
|
|
||||||
|
|
||||||
/* TODO: Better error handling here? */
|
|
||||||
if (setjmp(png_jmpbuf(img)))
|
|
||||||
exit(1);
|
|
||||||
|
|
||||||
png_init_io(img, f);
|
|
||||||
|
|
||||||
png_write_info(img, png->info);
|
|
||||||
|
|
||||||
png_write_image(img, png->data);
|
|
||||||
png_write_end(img, NULL);
|
|
||||||
|
|
||||||
fclose(f);
|
|
||||||
|
|
||||||
if (opts.debug)
|
|
||||||
free(outfile);
|
|
||||||
}
|
|
||||||
|
|
||||||
void free_png_data(const struct PNGImage *png)
|
|
||||||
{
|
{
|
||||||
int y;
|
int y;
|
||||||
|
|
||||||
for (y = 0; y < png->height; y++)
|
for (y = 0; y < img->height; y++)
|
||||||
free(png->data[y]);
|
free(img->data[y]);
|
||||||
|
|
||||||
free(png->data);
|
free(img->data);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,18 +1,11 @@
|
|||||||
.\" Copyright © 2013 stag019 <stag019@gmail.com>
|
|
||||||
.\"
|
.\"
|
||||||
.\" Permission to use, copy, modify, and distribute this software for any
|
.\" This file is part of RGBDS.
|
||||||
.\" purpose with or without fee is hereby granted, provided that the above
|
|
||||||
.\" copyright notice and this permission notice appear in all copies.
|
|
||||||
.\"
|
.\"
|
||||||
.\" THE SOFTWARE IS PROVIDED “AS IS” AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
.\" Copyright (c) 2013-2018, stag019 and RGBDS contributors.
|
||||||
.\" WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
|
||||||
.\" MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
|
||||||
.\" ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
|
||||||
.\" WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
|
||||||
.\" ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
|
||||||
.\" OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
|
||||||
.\"
|
.\"
|
||||||
.Dd April 17, 2017
|
.\" SPDX-License-Identifier: MIT
|
||||||
|
.\"
|
||||||
|
.Dd January 26, 2018
|
||||||
.Dt RGBGFX 1
|
.Dt RGBGFX 1
|
||||||
.Os RGBDS Manual
|
.Os RGBDS Manual
|
||||||
.Sh NAME
|
.Sh NAME
|
||||||
@@ -31,7 +24,28 @@
|
|||||||
The
|
The
|
||||||
.Nm
|
.Nm
|
||||||
program converts PNG images into the Nintendo Game Boy's planar tile format.
|
program converts PNG images into the Nintendo Game Boy's planar tile format.
|
||||||
The arguments are as follows:
|
|
||||||
|
The resulting colors and their palette indices are determined differently
|
||||||
|
depending on the input PNG file:
|
||||||
|
.Bl -dash -width Ds
|
||||||
|
.It
|
||||||
|
If the file has an embedded palette, that palette's color and order are used.
|
||||||
|
.It
|
||||||
|
If not, and the image only contains shades of gray, rgbgfx maps them to the
|
||||||
|
indices appropriate for each shade. Any undetermined indices are set to
|
||||||
|
respective default shades of gray. For example: if the bit depth is 2 and the
|
||||||
|
image contains light gray and black, they become the second and fourth colors -
|
||||||
|
and the first and third colors get set to default white and dark gray. If the
|
||||||
|
image has multiple shades that map to the same index, the palette is instead
|
||||||
|
determined as if the image had color.
|
||||||
|
.It
|
||||||
|
If the image has color (or the grayscale method failed), the colors are sorted
|
||||||
|
from lightest to darkest.
|
||||||
|
.El
|
||||||
|
|
||||||
|
The input image may not contain more colors than the selected bit depth
|
||||||
|
allows. Transparent pixels are set to palette index 0.
|
||||||
|
.Sh ARGUMENTS
|
||||||
.Bl -tag -width Ds
|
.Bl -tag -width Ds
|
||||||
.It Fl D
|
.It Fl D
|
||||||
Debug features are enabled.
|
Debug features are enabled.
|
||||||
@@ -40,24 +54,25 @@ Fix the input PNG file to be a correctly indexed image.
|
|||||||
.It Fl F
|
.It Fl F
|
||||||
Same as
|
Same as
|
||||||
.Fl f ,
|
.Fl f ,
|
||||||
but additionally, the input PNG file is fixed to have its parameters match the
|
but additionally, the supplied command line parameters are saved within the PNG
|
||||||
command line's parameters.
|
and will be loaded and automatically used next time.
|
||||||
.It Fl d Ar depth
|
.It Fl d Ar depth
|
||||||
The bitdepth of the output image (either 1 or 2).
|
The bit depth of the output image (either 1 or 2).
|
||||||
By default, the bitdepth is 2 (two bits per pixel).
|
By default, the bit depth is 2 (two bits per pixel).
|
||||||
.It Fl h
|
.It Fl h
|
||||||
Lay out tiles horizontally rather than vertically.
|
Lay out tiles horizontally rather than vertically.
|
||||||
.It Fl o Ar outfile
|
.It Fl o Ar outfile
|
||||||
The name of the output file.
|
The name of the output file.
|
||||||
.It Fl p Ar palfile
|
.It Fl p Ar palfile
|
||||||
Raw bytes (8 bytes for two bits per pixel, 4 bytes for one bit per pixel)
|
Output the image's palette in standard GBC palette format - bytes (8 bytes for
|
||||||
containing the RGB15 values in the little-endian byte order and then ordered
|
two bits per pixel, 4 bytes for one bit per pixel) containing the RGB15 values
|
||||||
from lightest to darkest.
|
in little-endian byte order. If the palette contains too few colors, the
|
||||||
|
remaining entries are set to black.
|
||||||
.It Fl P
|
.It Fl P
|
||||||
Same as
|
Same as
|
||||||
.Fl p ,
|
.Fl p ,
|
||||||
but the pallete file output name is made by taking the input filename,
|
but the palette file output name is made by taking the input PNG file's
|
||||||
removing the file extension, and appending
|
filename, removing the file extension, and appending
|
||||||
.Pa .pal .
|
.Pa .pal .
|
||||||
.It Fl t Ar mapfile
|
.It Fl t Ar mapfile
|
||||||
If any tiles are the same, don't place the repeat tiles in the output file, and
|
If any tiles are the same, don't place the repeat tiles in the output file, and
|
||||||
@@ -80,7 +95,7 @@ the PNG file don't match.
|
|||||||
Trim the end of the output file by this many tiles.
|
Trim the end of the output file by this many tiles.
|
||||||
.El
|
.El
|
||||||
.Sh EXAMPLES
|
.Sh EXAMPLES
|
||||||
The following will take a PNG file with a bitdepth of 1, 2, or 8, and output
|
The following will take a PNG file with a bit depth of 1, 2, or 8, and output
|
||||||
planar 2bpp data:
|
planar 2bpp data:
|
||||||
.Pp
|
.Pp
|
||||||
.D1 $ rgbgfx -o out.2bpp in.png
|
.D1 $ rgbgfx -o out.2bpp in.png
|
||||||
|
|||||||
@@ -1,3 +1,11 @@
|
|||||||
|
/*
|
||||||
|
* This file is part of RGBDS.
|
||||||
|
*
|
||||||
|
* Copyright (c) 1997-2018, Carsten Sorensen and RGBDS contributors.
|
||||||
|
*
|
||||||
|
* SPDX-License-Identifier: MIT
|
||||||
|
*/
|
||||||
|
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
@@ -66,6 +74,10 @@ static void do_max_bank(enum eSectionType Type, int32_t nBank)
|
|||||||
if (nBank > MaxVBankUsed)
|
if (nBank > MaxVBankUsed)
|
||||||
MaxVBankUsed = nBank;
|
MaxVBankUsed = nBank;
|
||||||
break;
|
break;
|
||||||
|
case SECT_ROM0:
|
||||||
|
case SECT_WRAM0:
|
||||||
|
case SECT_OAM:
|
||||||
|
case SECT_HRAM:
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@@ -486,7 +498,6 @@ void SetLinkerscriptName(char *tzLinkerscriptFile)
|
|||||||
|
|
||||||
void AssignSections(void)
|
void AssignSections(void)
|
||||||
{
|
{
|
||||||
int32_t i;
|
|
||||||
struct sSection *pSection;
|
struct sSection *pSection;
|
||||||
|
|
||||||
MaxBankUsed = 0;
|
MaxBankUsed = 0;
|
||||||
@@ -495,7 +506,7 @@ void AssignSections(void)
|
|||||||
* Initialize the memory areas
|
* 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]));
|
BankFree[i] = malloc(sizeof(*BankFree[i]));
|
||||||
|
|
||||||
if (!BankFree[i]) {
|
if (!BankFree[i]) {
|
||||||
@@ -609,6 +620,9 @@ void AssignSections(void)
|
|||||||
pSection->nOrg, pSection->nBank);
|
pSection->nOrg, pSection->nBank);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
default:
|
||||||
|
errx(1, "%s: Internal error: Type %d", __func__,
|
||||||
|
pSection->Type);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -652,6 +666,10 @@ void AssignSections(void)
|
|||||||
do_max_bank(pSection->Type, pSection->nBank);
|
do_max_bank(pSection->Type, pSection->nBank);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
case SECT_ROM0:
|
||||||
|
case SECT_WRAM0:
|
||||||
|
case SECT_OAM:
|
||||||
|
case SECT_HRAM:
|
||||||
default: /* Handle other sections later */
|
default: /* Handle other sections later */
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,17 +1,9 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (C) 2017 Antonio Nino Diaz <antonio_nd@outlook.com>
|
* This file is part of RGBDS.
|
||||||
*
|
*
|
||||||
* Permission to use, copy, modify, and distribute this software for any
|
* Copyright (c) 2017-2018, Antonio Nino Diaz and RGBDS contributors.
|
||||||
* purpose with or without fee is hereby granted, provided that the above
|
|
||||||
* copyright notice and this permission notice appear in all copies.
|
|
||||||
*
|
*
|
||||||
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
* SPDX-License-Identifier: MIT
|
||||||
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
|
||||||
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
|
||||||
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
|
||||||
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
|
||||||
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
|
||||||
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
%option noinput
|
%option noinput
|
||||||
@@ -31,7 +23,7 @@
|
|||||||
|
|
||||||
#include "types.h"
|
#include "types.h"
|
||||||
|
|
||||||
extern int yyparse();
|
extern int yyparse(void);
|
||||||
|
|
||||||
/* File include stack. */
|
/* File include stack. */
|
||||||
|
|
||||||
@@ -187,13 +179,13 @@ void script_PrintFileStack(void)
|
|||||||
fprintf(stderr, "%s(%d)", linkerscript_path, include_line[i]);
|
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_list args;
|
||||||
va_start(args, fmt);
|
va_start(args, fmt);
|
||||||
fprintf(stderr, "error: ");
|
fprintf(stderr, "error: ");
|
||||||
script_PrintFileStack();
|
script_PrintFileStack();
|
||||||
fprintf(stderr, ":\n\t");
|
fprintf(stderr, ":\n ");
|
||||||
vfprintf(stderr, fmt, args);
|
vfprintf(stderr, fmt, args);
|
||||||
fprintf(stderr, "\n");
|
fprintf(stderr, "\n");
|
||||||
va_end(args);
|
va_end(args);
|
||||||
|
|||||||
@@ -1,3 +1,11 @@
|
|||||||
|
/*
|
||||||
|
* This file is part of RGBDS.
|
||||||
|
*
|
||||||
|
* Copyright (c) 1997-2018, Carsten Sorensen and RGBDS contributors.
|
||||||
|
*
|
||||||
|
* SPDX-License-Identifier: MIT
|
||||||
|
*/
|
||||||
|
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
|||||||
@@ -1,3 +1,11 @@
|
|||||||
|
/*
|
||||||
|
* This file is part of RGBDS.
|
||||||
|
*
|
||||||
|
* Copyright (c) 1997-2018, Carsten Sorensen and RGBDS contributors.
|
||||||
|
*
|
||||||
|
* SPDX-License-Identifier: MIT
|
||||||
|
*/
|
||||||
|
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
@@ -5,7 +13,6 @@
|
|||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
|
|
||||||
#include "extern/err.h"
|
#include "extern/err.h"
|
||||||
#include "extern/version.h"
|
|
||||||
|
|
||||||
#include "link/object.h"
|
#include "link/object.h"
|
||||||
#include "link/output.h"
|
#include "link/output.h"
|
||||||
@@ -16,6 +23,8 @@
|
|||||||
#include "link/main.h"
|
#include "link/main.h"
|
||||||
#include "link/library.h"
|
#include "link/library.h"
|
||||||
|
|
||||||
|
#include "version.h"
|
||||||
|
|
||||||
enum eBlockType {
|
enum eBlockType {
|
||||||
BLOCK_COMMENT,
|
BLOCK_COMMENT,
|
||||||
BLOCK_OBJECTS,
|
BLOCK_OBJECTS,
|
||||||
|
|||||||
@@ -1,3 +1,11 @@
|
|||||||
|
/*
|
||||||
|
* This file is part of RGBDS.
|
||||||
|
*
|
||||||
|
* Copyright (c) 1997-2018, Carsten Sorensen and RGBDS contributors.
|
||||||
|
*
|
||||||
|
* SPDX-License-Identifier: MIT
|
||||||
|
*/
|
||||||
|
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
@@ -112,6 +120,10 @@ void MapfileWriteSection(const struct sSection *pSect)
|
|||||||
for (i = 0; i < pSect->nNumberOfSymbols; i += 1) {
|
for (i = 0; i < pSect->nNumberOfSymbols; i += 1) {
|
||||||
const struct sSymbol *pSym = pSect->tSymbols[i];
|
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 ((pSym->pSection == pSect) && (pSym->Type != SYM_IMPORT)) {
|
||||||
if (mf) {
|
if (mf) {
|
||||||
fprintf(mf, " $%04X = %s\n",
|
fprintf(mf, " $%04X = %s\n",
|
||||||
|
|||||||
@@ -1,3 +1,11 @@
|
|||||||
|
/*
|
||||||
|
* This file is part of RGBDS.
|
||||||
|
*
|
||||||
|
* Copyright (c) 1997-2018, Carsten Sorensen and RGBDS contributors.
|
||||||
|
*
|
||||||
|
* SPDX-License-Identifier: MIT
|
||||||
|
*/
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Here we have the routines that read an objectfile
|
* Here we have the routines that read an objectfile
|
||||||
*/
|
*/
|
||||||
@@ -28,14 +36,14 @@ uint8_t oReadLib;
|
|||||||
*/
|
*/
|
||||||
static int32_t readlong(FILE *f)
|
static int32_t readlong(FILE *f)
|
||||||
{
|
{
|
||||||
int32_t r;
|
uint32_t r;
|
||||||
|
|
||||||
r = fgetc(f);
|
r = ((uint32_t)(uint8_t)fgetc(f));
|
||||||
r |= fgetc(f) << 8;
|
r |= ((uint32_t)(uint8_t)fgetc(f)) << 8;
|
||||||
r |= fgetc(f) << 16;
|
r |= ((uint32_t)(uint8_t)fgetc(f)) << 16;
|
||||||
r |= fgetc(f) << 24;
|
r |= ((uint32_t)(uint8_t)fgetc(f)) << 24;
|
||||||
|
|
||||||
return r;
|
return (int32_t)r;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|||||||
@@ -1,3 +1,11 @@
|
|||||||
|
/*
|
||||||
|
* This file is part of RGBDS.
|
||||||
|
*
|
||||||
|
* Copyright (c) 1997-2018, Carsten Sorensen and RGBDS contributors.
|
||||||
|
*
|
||||||
|
* SPDX-License-Identifier: MIT
|
||||||
|
*/
|
||||||
|
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
@@ -102,12 +110,9 @@ void Output(void)
|
|||||||
FILE *f_overlay = NULL;
|
FILE *f_overlay = NULL;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Apply overlay
|
* Load overlay
|
||||||
*/
|
*/
|
||||||
|
|
||||||
f = fopen(tzOutname, "wb");
|
|
||||||
|
|
||||||
if (f != NULL) {
|
|
||||||
if (tzOverlayname) {
|
if (tzOverlayname) {
|
||||||
f_overlay = fopen(tzOverlayname, "rb");
|
f_overlay = fopen(tzOverlayname, "rb");
|
||||||
|
|
||||||
@@ -130,18 +135,28 @@ void Output(void)
|
|||||||
MaxBankUsed = MaxOverlayBank;
|
MaxBankUsed = MaxOverlayBank;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Write ROM.
|
||||||
|
*/
|
||||||
|
|
||||||
|
f = fopen(tzOutname, "wb");
|
||||||
|
if (f != NULL) {
|
||||||
writehome(f, f_overlay);
|
writehome(f, f_overlay);
|
||||||
for (i = 1; i <= MaxBankUsed; i += 1)
|
for (i = 1; i <= MaxBankUsed; i += 1)
|
||||||
writebank(f, f_overlay, i);
|
writebank(f, f_overlay, i);
|
||||||
|
|
||||||
fclose(f);
|
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++) {
|
for (i = BANK_INDEX_WRAM0; i < BANK_INDEX_MAX; i++) {
|
||||||
|
|||||||
@@ -1,17 +1,9 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (C) 2017 Antonio Nino Diaz <antonio_nd@outlook.com>
|
* This file is part of RGBDS.
|
||||||
*
|
*
|
||||||
* Permission to use, copy, modify, and distribute this software for any
|
* Copyright (c) 2017-2018, Antonio Nino Diaz and RGBDS contributors.
|
||||||
* purpose with or without fee is hereby granted, provided that the above
|
|
||||||
* copyright notice and this permission notice appear in all copies.
|
|
||||||
*
|
*
|
||||||
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
* SPDX-License-Identifier: MIT
|
||||||
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
|
||||||
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
|
||||||
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
|
||||||
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
|
||||||
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
|
||||||
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
%{
|
%{
|
||||||
@@ -22,7 +14,7 @@
|
|||||||
|
|
||||||
#include "link/script.h"
|
#include "link/script.h"
|
||||||
|
|
||||||
int yylex();
|
int yylex(void);
|
||||||
void yyerror(char *);
|
void yyerror(char *);
|
||||||
|
|
||||||
extern int yylineno;
|
extern int yylineno;
|
||||||
@@ -115,8 +107,8 @@ statement:
|
|||||||
|
|
||||||
%%
|
%%
|
||||||
|
|
||||||
extern int yylex();
|
extern int yylex(void);
|
||||||
extern int yyparse();
|
extern int yyparse(void);
|
||||||
|
|
||||||
int yywrap(void)
|
int yywrap(void)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -1,3 +1,11 @@
|
|||||||
|
/*
|
||||||
|
* This file is part of RGBDS.
|
||||||
|
*
|
||||||
|
* Copyright (c) 1997-2018, Carsten Sorensen and RGBDS contributors.
|
||||||
|
*
|
||||||
|
* SPDX-License-Identifier: MIT
|
||||||
|
*/
|
||||||
|
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
@@ -49,7 +57,6 @@ static int32_t getsymvalue(int32_t symid)
|
|||||||
errx(1, "%s: Unknown symbol type", __func__);
|
errx(1, "%s: Unknown symbol type", __func__);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static int32_t getrealbankfrominternalbank(int32_t n)
|
static int32_t getrealbankfrominternalbank(int32_t n)
|
||||||
{
|
{
|
||||||
if (BankIndexIsWRAM0(n) || BankIndexIsROM0(n) ||
|
if (BankIndexIsWRAM0(n) || BankIndexIsROM0(n) ||
|
||||||
@@ -65,8 +72,6 @@ static int32_t getrealbankfrominternalbank(int32_t n)
|
|||||||
return n - BANK_INDEX_SRAM;
|
return n - BANK_INDEX_SRAM;
|
||||||
}
|
}
|
||||||
|
|
||||||
errx(1, "%s: Unknown bank %d", __func__, n);
|
|
||||||
|
|
||||||
return n;
|
return n;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -262,6 +267,7 @@ void Patch(void)
|
|||||||
pPatch = pSect->pPatches;
|
pPatch = pSect->pPatches;
|
||||||
while (pPatch) {
|
while (pPatch) {
|
||||||
int32_t t;
|
int32_t t;
|
||||||
|
int32_t nPatchOrg;
|
||||||
|
|
||||||
nPC = pSect->nOrg + pPatch->nOffset;
|
nPC = pSect->nOrg + pPatch->nOffset;
|
||||||
t = calcrpn(pPatch);
|
t = calcrpn(pPatch);
|
||||||
@@ -301,6 +307,26 @@ void Patch(void)
|
|||||||
pSect->pData[pPatch->nOffset + 3] =
|
pSect->pData[pPatch->nOffset + 3] =
|
||||||
(t >> 24) & 0xFF;
|
(t >> 24) & 0xFF;
|
||||||
break;
|
break;
|
||||||
|
case PATCH_BYTE_JR:
|
||||||
|
/* Calculate absolute address of the patch */
|
||||||
|
nPatchOrg = pSect->nOrg + pPatch->nOffset;
|
||||||
|
|
||||||
|
/* t contains the destination of the jump */
|
||||||
|
t = (int16_t)((t & 0xFFFF) - (nPatchOrg + 1));
|
||||||
|
|
||||||
|
if (t >= -128 && t <= 127) {
|
||||||
|
t &= 0xFF;
|
||||||
|
pSect->pData[pPatch->nOffset] =
|
||||||
|
(uint8_t)t;
|
||||||
|
} else {
|
||||||
|
errx(1,
|
||||||
|
"%s(%ld) : Value must be 8-bit",
|
||||||
|
pPatch->pzFilename,
|
||||||
|
pPatch->nLineNo);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
errx(1, "%s: Internal error.", __func__);
|
||||||
}
|
}
|
||||||
|
|
||||||
pPatch = pPatch->pNext;
|
pPatch = pPatch->pNext;
|
||||||
|
|||||||
@@ -1,18 +1,11 @@
|
|||||||
.\" Copyright © 2010 Anthony J. Bentley <anthony@anjbe.name>
|
|
||||||
.\"
|
.\"
|
||||||
.\" Permission to use, copy, modify, and distribute this software for any
|
.\" This file is part of RGBDS.
|
||||||
.\" purpose with or without fee is hereby granted, provided that the above
|
|
||||||
.\" copyright notice and this permission notice appear in all copies.
|
|
||||||
.\"
|
.\"
|
||||||
.\" THE SOFTWARE IS PROVIDED “AS IS” AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
.\" Copyright (c) 2010-2018, Anthony J. Bentley and RGBDS contributors.
|
||||||
.\" WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
|
||||||
.\" MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
|
||||||
.\" ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
|
||||||
.\" WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
|
||||||
.\" ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
|
||||||
.\" OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
|
||||||
.\"
|
.\"
|
||||||
.Dd April 17, 2017
|
.\" SPDX-License-Identifier: MIT
|
||||||
|
.\"
|
||||||
|
.Dd January 26, 2018
|
||||||
.Dt RGBLINK 1
|
.Dt RGBLINK 1
|
||||||
.Os RGBDS Manual
|
.Os RGBDS Manual
|
||||||
.Sh NAME
|
.Sh NAME
|
||||||
@@ -64,7 +57,7 @@ Write a symbol file to the given filename.
|
|||||||
.It Fl O Ar overlayfile
|
.It Fl O Ar overlayfile
|
||||||
The ROM image to overlay sections over.
|
The ROM image to overlay sections over.
|
||||||
When an overlay ROM is provided, all sections must be fixed.
|
When an overlay ROM is provided, all sections must be fixed.
|
||||||
This may be used to patch an existing binray.
|
This may be used to patch an existing binary.
|
||||||
.It Fl o Ar outfile
|
.It Fl o Ar outfile
|
||||||
Write ROM image to the given filename.
|
Write ROM image to the given filename.
|
||||||
.It Fl p Ar pad_value
|
.It Fl p Ar pad_value
|
||||||
|
|||||||
@@ -1,18 +1,11 @@
|
|||||||
.\" Copyright (C) 2017 Antonio Nino Diaz <antonio_nd@outlook.com>
|
|
||||||
.\"
|
.\"
|
||||||
.\" Permission to use, copy, modify, and distribute this software for any
|
.\" This file is part of RGBDS.
|
||||||
.\" purpose with or without fee is hereby granted, provided that the above
|
|
||||||
.\" copyright notice and this permission notice appear in all copies.
|
|
||||||
.\"
|
.\"
|
||||||
.\" THE SOFTWARE IS PROVIDED “AS IS” AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
.\" Copyright (c) 2017-2018, Antonio Nino Diaz and RGBDS contributors.
|
||||||
.\" WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
|
||||||
.\" MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
|
||||||
.\" ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
|
||||||
.\" WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
|
||||||
.\" ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
|
||||||
.\" OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
|
||||||
.\"
|
.\"
|
||||||
.Dd April 17, 2017
|
.\" SPDX-License-Identifier: MIT
|
||||||
|
.\"
|
||||||
|
.Dd January 27, 2018
|
||||||
.Dt RGBLINK 5
|
.Dt RGBLINK 5
|
||||||
.Os RGBDS Manual
|
.Os RGBDS Manual
|
||||||
.Sh NAME
|
.Sh NAME
|
||||||
@@ -45,7 +38,7 @@ WRAMX 2
|
|||||||
.Pp
|
.Pp
|
||||||
Numbers can be in decimal or hexadecimal format (the prefix is
|
Numbers can be in decimal or hexadecimal format (the prefix is
|
||||||
.Ql $ ) .
|
.Ql $ ) .
|
||||||
It is an error if any bank or command is found before setting a bank.
|
It is an error if any section name or command are found before setting a bank.
|
||||||
.Pp
|
.Pp
|
||||||
Files can be included by using the
|
Files can be included by using the
|
||||||
.Ar INCLUDE
|
.Ar INCLUDE
|
||||||
|
|||||||
@@ -1,17 +1,9 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (C) 2017 Antonio Nino Diaz <antonio_nd@outlook.com>
|
* This file is part of RGBDS.
|
||||||
*
|
*
|
||||||
* Permission to use, copy, modify, and distribute this software for any
|
* Copyright (c) 2017-2018, Antonio Nino Diaz and RGBDS contributors.
|
||||||
* purpose with or without fee is hereby granted, provided that the above
|
|
||||||
* copyright notice and this permission notice appear in all copies.
|
|
||||||
*
|
*
|
||||||
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
* SPDX-License-Identifier: MIT
|
||||||
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
|
||||||
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
|
||||||
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
|
||||||
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
|
||||||
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
|
||||||
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
@@ -93,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 (strcmp(type, "ROM0") == 0) {
|
||||||
if (bank != 0)
|
if (bank_num != 0)
|
||||||
errx(1, "Trying to assign a bank number to ROM0.\n");
|
errx(1, "Trying to assign a bank number to ROM0.\n");
|
||||||
current_bank = BANK_INDEX_ROM0;
|
current_bank = BANK_INDEX_ROM0;
|
||||||
current_real_bank = 0;
|
current_real_bank = 0;
|
||||||
return;
|
return;
|
||||||
} else if (strcmp(type, "ROMX") == 0) {
|
} else if (strcmp(type, "ROMX") == 0) {
|
||||||
if (bank == 0)
|
if (bank_num == 0)
|
||||||
errx(1, "ROMX index can't be 0.\n");
|
errx(1, "ROMX index can't be 0.\n");
|
||||||
if (bank > BANK_COUNT_ROMX) {
|
if (bank_num > BANK_COUNT_ROMX) {
|
||||||
errx(1, "ROMX index too big (%d > %d).\n", bank,
|
errx(1, "ROMX index too big (%d > %d).\n", bank_num,
|
||||||
BANK_COUNT_ROMX);
|
BANK_COUNT_ROMX);
|
||||||
}
|
}
|
||||||
current_bank = BANK_INDEX_ROMX + bank - 1;
|
current_bank = BANK_INDEX_ROMX + bank_num - 1;
|
||||||
current_real_bank = bank;
|
current_real_bank = bank_num;
|
||||||
return;
|
return;
|
||||||
} else if (strcmp(type, "VRAM") == 0) {
|
} else if (strcmp(type, "VRAM") == 0) {
|
||||||
if (bank >= BANK_COUNT_VRAM) {
|
if (bank_num >= BANK_COUNT_VRAM) {
|
||||||
errx(1, "VRAM index too big (%d >= %d).\n", bank,
|
errx(1, "VRAM index too big (%d >= %d).\n", bank_num,
|
||||||
BANK_COUNT_VRAM);
|
BANK_COUNT_VRAM);
|
||||||
}
|
}
|
||||||
current_bank = BANK_INDEX_VRAM + bank;
|
current_bank = BANK_INDEX_VRAM + bank_num;
|
||||||
current_real_bank = bank;
|
current_real_bank = bank_num;
|
||||||
return;
|
return;
|
||||||
} else if (strcmp(type, "WRAM0") == 0) {
|
} else if (strcmp(type, "WRAM0") == 0) {
|
||||||
if (bank != 0) {
|
if (bank_num != 0)
|
||||||
errx(1, "Trying to assign a bank number to WRAM0.\n");
|
errx(1, "Trying to assign a bank number to WRAM0.\n");
|
||||||
}
|
|
||||||
current_bank = BANK_INDEX_WRAM0;
|
current_bank = BANK_INDEX_WRAM0;
|
||||||
current_real_bank = 0;
|
current_real_bank = 0;
|
||||||
return;
|
return;
|
||||||
} else if (strcmp(type, "WRAMX") == 0) {
|
} else if (strcmp(type, "WRAMX") == 0) {
|
||||||
if (bank == 0)
|
if (bank_num == 0)
|
||||||
errx(1, "WRAMX index can't be 0.\n");
|
errx(1, "WRAMX index can't be 0.\n");
|
||||||
if (bank > BANK_COUNT_WRAMX) {
|
if (bank_num > BANK_COUNT_WRAMX) {
|
||||||
errx(1, "WRAMX index too big (%d > %d).\n", bank,
|
errx(1, "WRAMX index too big (%d > %d).\n", bank_num,
|
||||||
BANK_COUNT_WRAMX);
|
BANK_COUNT_WRAMX);
|
||||||
}
|
}
|
||||||
current_bank = BANK_INDEX_WRAMX + bank - 1;
|
current_bank = BANK_INDEX_WRAMX + bank_num - 1;
|
||||||
current_real_bank = bank - 1;
|
current_real_bank = bank_num;
|
||||||
return;
|
return;
|
||||||
} else if (strcmp(type, "SRAM") == 0) {
|
} else if (strcmp(type, "SRAM") == 0) {
|
||||||
if (bank >= BANK_COUNT_SRAM) {
|
if (bank_num >= BANK_COUNT_SRAM) {
|
||||||
errx(1, "SRAM index too big (%d >= %d).\n", bank,
|
errx(1, "SRAM index too big (%d >= %d).\n", bank_num,
|
||||||
BANK_COUNT_SRAM);
|
BANK_COUNT_SRAM);
|
||||||
}
|
}
|
||||||
current_bank = BANK_INDEX_SRAM + bank;
|
current_bank = BANK_INDEX_SRAM + bank_num;
|
||||||
current_real_bank = bank;
|
current_real_bank = bank_num;
|
||||||
return;
|
return;
|
||||||
} else if (strcmp(type, "OAM") == 0) {
|
} 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",
|
errx(1, "%s: Trying to assign a bank number to OAM.\n",
|
||||||
__func__);
|
__func__);
|
||||||
}
|
}
|
||||||
@@ -153,7 +145,7 @@ void script_SetCurrentSectionType(const char *type, uint32_t bank)
|
|||||||
current_real_bank = 0;
|
current_real_bank = 0;
|
||||||
return;
|
return;
|
||||||
} else if (strcmp(type, "HRAM") == 0) {
|
} 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",
|
errx(1, "%s: Trying to assign a bank number to HRAM.\n",
|
||||||
__func__);
|
__func__);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,3 +1,11 @@
|
|||||||
|
/*
|
||||||
|
* This file is part of RGBDS.
|
||||||
|
*
|
||||||
|
* Copyright (c) 1997-2018, Carsten Sorensen and RGBDS contributors.
|
||||||
|
*
|
||||||
|
* SPDX-License-Identifier: MIT
|
||||||
|
*/
|
||||||
|
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
|||||||
22
src/rgbds.5
22
src/rgbds.5
@@ -1,18 +1,11 @@
|
|||||||
.\" Copyright (c) 2017-2018 Antonio Nino Diaz <antonio_nd@outlook.com>
|
|
||||||
.\"
|
.\"
|
||||||
.\" Permission to use, copy, modify, and distribute this software for any
|
.\" This file is part of RGBDS.
|
||||||
.\" purpose with or without fee is hereby granted, provided that the above
|
|
||||||
.\" copyright notice and this permission notice appear in all copies.
|
|
||||||
.\"
|
.\"
|
||||||
.\" THE SOFTWARE IS PROVIDED “AS IS” AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
.\" Copyright (c) 2017-2018, Antonio Nino Diaz and RGBDS contributors.
|
||||||
.\" WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
|
||||||
.\" MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
|
||||||
.\" ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
|
||||||
.\" WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
|
||||||
.\" ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
|
||||||
.\" OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
|
||||||
.\"
|
.\"
|
||||||
.Dd January 7, 2018
|
.\" SPDX-License-Identifier: MIT
|
||||||
|
.\"
|
||||||
|
.Dd January 26, 2018
|
||||||
.Dt RGBDS 5
|
.Dt RGBDS 5
|
||||||
.Os RGBDS Manual
|
.Os RGBDS Manual
|
||||||
.Sh NAME
|
.Sh NAME
|
||||||
@@ -64,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 LineNum ; Line number in the file where the symbol is defined.
|
||||||
|
|
||||||
LONG SectionID ; The section number (of this object file) in which
|
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
|
LONG Value ; The symbols value. It's the offset into that
|
||||||
; symbol's section.
|
; symbol's section.
|
||||||
@@ -120,6 +115,7 @@ REPT NumberOfSections
|
|||||||
BYTE Type ; 0 = BYTE patch.
|
BYTE Type ; 0 = BYTE patch.
|
||||||
; 1 = little endian WORD patch.
|
; 1 = little endian WORD patch.
|
||||||
; 2 = little endian LONG patch.
|
; 2 = little endian LONG patch.
|
||||||
|
; 3 = JR offset value BYTE patch.
|
||||||
|
|
||||||
LONG RPNSize ; Size of the buffer with the RPN.
|
LONG RPNSize ; Size of the buffer with the RPN.
|
||||||
; expression.
|
; expression.
|
||||||
|
|||||||
27
src/rgbds.7
27
src/rgbds.7
@@ -1,18 +1,11 @@
|
|||||||
.\" Copyright © 2010 Anthony J. Bentley <anthony@anjbe.name>
|
|
||||||
.\"
|
.\"
|
||||||
.\" Permission to use, copy, modify, and distribute this software for any
|
.\" This file is part of RGBDS.
|
||||||
.\" purpose with or without fee is hereby granted, provided that the above
|
|
||||||
.\" copyright notice and this permission notice appear in all copies.
|
|
||||||
.\"
|
.\"
|
||||||
.\" THE SOFTWARE IS PROVIDED “AS IS” AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
.\" Copyright (c) 2010-2018, Anthony J. Bentley and RGBDS contributors.
|
||||||
.\" WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
|
||||||
.\" MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
|
||||||
.\" ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
|
||||||
.\" WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
|
||||||
.\" ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
|
||||||
.\" OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
|
||||||
.\"
|
.\"
|
||||||
.Dd April 17, 2017
|
.\" SPDX-License-Identifier: MIT
|
||||||
|
.\"
|
||||||
|
.Dd March 7, 2018
|
||||||
.Dt RGBDS 7
|
.Dt RGBDS 7
|
||||||
.Os RGBDS Manual
|
.Os RGBDS Manual
|
||||||
.Sh NAME
|
.Sh NAME
|
||||||
@@ -21,9 +14,11 @@
|
|||||||
.Sh EXAMPLES
|
.Sh EXAMPLES
|
||||||
To get a working ROM image from a single assembly source file:
|
To get a working ROM image from a single assembly source file:
|
||||||
.Pp
|
.Pp
|
||||||
.D1 $ rgbasm \-o bar.o foo.asm
|
.Bd -literal -offset indent
|
||||||
.D1 $ rgblink \-o baz.gb bar.o
|
$ rgbasm \-o bar.o foo.asm
|
||||||
.D1 $ rgbfix \-v \-p 0 baz.gb
|
$ rgblink \-o baz.gb bar.o
|
||||||
|
$ rgbfix \-v \-p 0 baz.gb
|
||||||
|
.Ed
|
||||||
.Sh SEE ALSO
|
.Sh SEE ALSO
|
||||||
.Xr rgbasm 1 ,
|
.Xr rgbasm 1 ,
|
||||||
.Xr rgbfix 1 ,
|
.Xr rgbfix 1 ,
|
||||||
@@ -48,4 +43,6 @@ implementation of rgbds.
|
|||||||
2017, Bentley's repository is moved to a neutral name.
|
2017, Bentley's repository is moved to a neutral name.
|
||||||
It is now maintained by a number of contributors at
|
It is now maintained by a number of contributors at
|
||||||
.Lk https://github.com/rednex/rgbds .
|
.Lk https://github.com/rednex/rgbds .
|
||||||
|
.It
|
||||||
|
2018, codebase relicensed under the MIT license.
|
||||||
.El
|
.El
|
||||||
|
|||||||
26
src/version.c
Normal file
26
src/version.c
Normal file
@@ -0,0 +1,26 @@
|
|||||||
|
/*
|
||||||
|
* This file is part of RGBDS.
|
||||||
|
*
|
||||||
|
* Copyright (c) 2017-2018, Antonio Nino Diaz and RGBDS contributors.
|
||||||
|
*
|
||||||
|
* SPDX-License-Identifier: MIT
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <string.h>
|
||||||
|
|
||||||
|
#include "version.h"
|
||||||
|
|
||||||
|
const char *get_package_version_string(void)
|
||||||
|
{
|
||||||
|
static char s[50];
|
||||||
|
|
||||||
|
/* The following conditional should be simplified by the compiler. */
|
||||||
|
if (strlen(BUILD_VERSION_STRING) == 0) {
|
||||||
|
snprintf(s, sizeof(s), "v%d.%d.%d", PACKAGE_VERSION_MAJOR,
|
||||||
|
PACKAGE_VERSION_MINOR, PACKAGE_VERSION_PATCH);
|
||||||
|
return s;
|
||||||
|
} else {
|
||||||
|
return BUILD_VERSION_STRING;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,2 +1,2 @@
|
|||||||
ERROR: divzero-instr.asm(2):
|
ERROR: divzero-instr.asm(2):
|
||||||
division by zero
|
Division by zero
|
||||||
|
|||||||
@@ -1,2 +1,2 @@
|
|||||||
ERROR: divzero-section-bank.asm(1):
|
ERROR: divzero-section-bank.asm(1):
|
||||||
division by zero
|
Division by zero
|
||||||
|
|||||||
237
test/link/all-instructions.asm
Normal file
237
test/link/all-instructions.asm
Normal file
@@ -0,0 +1,237 @@
|
|||||||
|
SECTION "All instructions", ROM0
|
||||||
|
|
||||||
|
; 8-bit Arithmetic and Logic Instructions
|
||||||
|
|
||||||
|
alu_instruction_list : MACRO
|
||||||
|
\1 a,a
|
||||||
|
\1 a,b
|
||||||
|
\1 a,c
|
||||||
|
\1 a,d
|
||||||
|
\1 a,$DB
|
||||||
|
\1 a,e
|
||||||
|
\1 a,h
|
||||||
|
\1 a,[hl]
|
||||||
|
\1 a,l
|
||||||
|
ENDM
|
||||||
|
|
||||||
|
alu_instruction_list adc
|
||||||
|
alu_instruction_list add
|
||||||
|
alu_instruction_list and
|
||||||
|
alu_instruction_list cp
|
||||||
|
alu_instruction_list or
|
||||||
|
alu_instruction_list sbc
|
||||||
|
alu_instruction_list sub
|
||||||
|
alu_instruction_list xor
|
||||||
|
|
||||||
|
incdec_8bit_instruction_list : MACRO
|
||||||
|
\1 a
|
||||||
|
\1 b
|
||||||
|
\1 c
|
||||||
|
\1 d
|
||||||
|
\1 e
|
||||||
|
\1 h
|
||||||
|
\1 [hl]
|
||||||
|
\1 l
|
||||||
|
ENDM
|
||||||
|
|
||||||
|
incdec_8bit_instruction_list inc
|
||||||
|
incdec_8bit_instruction_list dec
|
||||||
|
|
||||||
|
; 16-bit Arithmetic Instructions
|
||||||
|
|
||||||
|
add hl,bc
|
||||||
|
add hl,de
|
||||||
|
add hl,hl
|
||||||
|
add hl,sp
|
||||||
|
|
||||||
|
inc bc
|
||||||
|
inc de
|
||||||
|
inc hl
|
||||||
|
inc sp
|
||||||
|
|
||||||
|
dec bc
|
||||||
|
dec de
|
||||||
|
dec hl
|
||||||
|
dec sp
|
||||||
|
|
||||||
|
; Bit Operations Instructions
|
||||||
|
|
||||||
|
bitop_u3_instruction_list : MACRO
|
||||||
|
NBIT SET 0
|
||||||
|
REPT 8
|
||||||
|
\1 NBIT,a
|
||||||
|
\1 NBIT,b
|
||||||
|
\1 NBIT,c
|
||||||
|
\1 NBIT,d
|
||||||
|
\1 NBIT,e
|
||||||
|
\1 NBIT,h
|
||||||
|
\1 NBIT,[hl]
|
||||||
|
\1 NBIT,l
|
||||||
|
NBIT SET NBIT + 1
|
||||||
|
ENDR
|
||||||
|
ENDM
|
||||||
|
|
||||||
|
bitop_u3_instruction_list bit
|
||||||
|
bitop_u3_instruction_list res
|
||||||
|
bitop_u3_instruction_list set
|
||||||
|
|
||||||
|
bitop_noarg_instruction_list : MACRO
|
||||||
|
\1 a
|
||||||
|
\1 b
|
||||||
|
\1 c
|
||||||
|
\1 d
|
||||||
|
\1 e
|
||||||
|
\1 h
|
||||||
|
\1 [hl]
|
||||||
|
\1 l
|
||||||
|
ENDM
|
||||||
|
|
||||||
|
bitop_noarg_instruction_list swap
|
||||||
|
|
||||||
|
; Bit Shift Instructions
|
||||||
|
|
||||||
|
rla
|
||||||
|
rlca
|
||||||
|
rra
|
||||||
|
rrca
|
||||||
|
|
||||||
|
bitop_noarg_instruction_list rl
|
||||||
|
bitop_noarg_instruction_list rlc
|
||||||
|
bitop_noarg_instruction_list rr
|
||||||
|
bitop_noarg_instruction_list rrc
|
||||||
|
bitop_noarg_instruction_list sla
|
||||||
|
bitop_noarg_instruction_list sra
|
||||||
|
bitop_noarg_instruction_list srl
|
||||||
|
|
||||||
|
; Load Instructions
|
||||||
|
|
||||||
|
ld_r8_x_instruction_list : MACRO
|
||||||
|
ld \1,a
|
||||||
|
ld \1,b
|
||||||
|
ld \1,c
|
||||||
|
ld \1,d
|
||||||
|
ld \1,$DB
|
||||||
|
ld \1,e
|
||||||
|
ld \1,h
|
||||||
|
ld \1,l
|
||||||
|
ENDM
|
||||||
|
|
||||||
|
ld_r8_x_instruction_list a
|
||||||
|
ld_r8_x_instruction_list b
|
||||||
|
ld_r8_x_instruction_list c
|
||||||
|
ld_r8_x_instruction_list d
|
||||||
|
ld_r8_x_instruction_list e
|
||||||
|
ld_r8_x_instruction_list h
|
||||||
|
ld_r8_x_instruction_list [hl]
|
||||||
|
ld_r8_x_instruction_list l
|
||||||
|
|
||||||
|
ld_x_r8_instruction_list : MACRO
|
||||||
|
ld a,\1
|
||||||
|
ld b,\1
|
||||||
|
ld c,\1
|
||||||
|
ld d,\1
|
||||||
|
ld e,\1
|
||||||
|
ld h,\1
|
||||||
|
ld l,\1
|
||||||
|
ENDM
|
||||||
|
|
||||||
|
ld_x_r8_instruction_list a
|
||||||
|
ld_x_r8_instruction_list b
|
||||||
|
ld_x_r8_instruction_list c
|
||||||
|
ld_x_r8_instruction_list d
|
||||||
|
ld_x_r8_instruction_list e
|
||||||
|
ld_x_r8_instruction_list h
|
||||||
|
ld_x_r8_instruction_list [hl]
|
||||||
|
ld_x_r8_instruction_list l
|
||||||
|
|
||||||
|
ld bc,$ABCD
|
||||||
|
ld de,$ABCD
|
||||||
|
ld hl,$ABCD
|
||||||
|
ld sp,$ABCD
|
||||||
|
|
||||||
|
ld [bc],a
|
||||||
|
ld [de],a
|
||||||
|
ld [hl],a
|
||||||
|
ld [$ABCD],a
|
||||||
|
ldh [$ff00+$DB],a
|
||||||
|
ld [$ff00+c],a
|
||||||
|
|
||||||
|
ld a,[bc]
|
||||||
|
ld a,[de]
|
||||||
|
ld a,[hl]
|
||||||
|
ld a,[$ABCD]
|
||||||
|
ldh a,[$ff00+$DB]
|
||||||
|
ld a,[$ff00+c]
|
||||||
|
|
||||||
|
ld [hl+],a
|
||||||
|
ld [hl-],a
|
||||||
|
ld a,[hl+]
|
||||||
|
ld a,[hl-]
|
||||||
|
|
||||||
|
; Jumps and Subroutines
|
||||||
|
|
||||||
|
call $ABCD
|
||||||
|
call z,$ABCD
|
||||||
|
call nz,$ABCD
|
||||||
|
call c,$ABCD
|
||||||
|
call nc,$ABCD
|
||||||
|
|
||||||
|
jp hl
|
||||||
|
|
||||||
|
jp $ABCD
|
||||||
|
jp z,$ABCD
|
||||||
|
jp nz,$ABCD
|
||||||
|
jp c,$ABCD
|
||||||
|
jp nc,$ABCD
|
||||||
|
|
||||||
|
jrlabel:
|
||||||
|
jr jrlabel
|
||||||
|
jr z,jrlabel
|
||||||
|
jr nz,jrlabel
|
||||||
|
jr c,jrlabel
|
||||||
|
jr nc,jrlabel
|
||||||
|
|
||||||
|
ret
|
||||||
|
ret z
|
||||||
|
ret nz
|
||||||
|
ret c
|
||||||
|
ret nc
|
||||||
|
reti
|
||||||
|
|
||||||
|
rst $00
|
||||||
|
rst $08
|
||||||
|
rst $10
|
||||||
|
rst $18
|
||||||
|
rst $20
|
||||||
|
rst $28
|
||||||
|
rst $30
|
||||||
|
rst $38
|
||||||
|
|
||||||
|
; Stack Operations Instructions
|
||||||
|
|
||||||
|
add sp,$DB
|
||||||
|
ld [$ABCD],sp
|
||||||
|
ld hl,sp+$DB
|
||||||
|
ld sp,hl
|
||||||
|
|
||||||
|
pop af
|
||||||
|
pop bc
|
||||||
|
pop de
|
||||||
|
pop hl
|
||||||
|
|
||||||
|
push af
|
||||||
|
push bc
|
||||||
|
push de
|
||||||
|
push hl
|
||||||
|
|
||||||
|
; Miscellaneous Instructions
|
||||||
|
|
||||||
|
ccf
|
||||||
|
cpl
|
||||||
|
daa
|
||||||
|
di
|
||||||
|
ei
|
||||||
|
halt
|
||||||
|
nop
|
||||||
|
scf
|
||||||
|
stop
|
||||||
BIN
test/link/all-instructions.out.bin
Normal file
BIN
test/link/all-instructions.out.bin
Normal file
Binary file not shown.
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user