mirror of
https://github.com/gbdev/rgbds.git
synced 2025-11-20 10:12:06 +00:00
Compare commits
180 Commits
v0.5.0
...
v0.6.0-wel
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
bffe7eb4de | ||
|
|
cd454d2e9a | ||
|
|
c814a616d6 | ||
|
|
e6ae1992fe | ||
|
|
d9b46cdec9 | ||
|
|
570cd62b81 | ||
|
|
a4ead0c25f | ||
|
|
da66eeb40e | ||
|
|
0c4f1f8334 | ||
|
|
af70d555fc | ||
|
|
e07bd92314 | ||
|
|
9169028e57 | ||
|
|
7dd8ba37f1 | ||
|
|
6842c831fd | ||
|
|
6b903059fe | ||
|
|
eb5af70d79 | ||
|
|
cf19879281 | ||
|
|
ac59ecf3c0 | ||
|
|
72b677a8d7 | ||
|
|
bbae9966e9 | ||
|
|
b3304ae1ac | ||
|
|
a48801a675 | ||
|
|
7dc81a64d3 | ||
|
|
3afa6b5a5a | ||
|
|
9b49f788e4 | ||
|
|
acc31feaa1 | ||
|
|
4ed5ba7508 | ||
|
|
20a26599a3 | ||
|
|
7bdfc9da23 | ||
|
|
d073cffa74 | ||
|
|
8435a29c4e | ||
|
|
b7fe78cad8 | ||
|
|
9d993d84e8 | ||
|
|
fef168b2a5 | ||
|
|
4a4b22c78c | ||
|
|
db79689e81 | ||
|
|
c2ca46c27d | ||
|
|
aac839f389 | ||
|
|
9d9febe1d3 | ||
|
|
b9fd85470e | ||
|
|
ec6d63bce3 | ||
|
|
bdcef6f252 | ||
|
|
54293a9184 | ||
|
|
b04e71ed34 | ||
|
|
f82603f196 | ||
|
|
cedfd2582a | ||
|
|
c7322258fc | ||
|
|
036b6c1b89 | ||
|
|
8e2a164a32 | ||
|
|
b76819792d | ||
|
|
3e945679ad | ||
|
|
efccf6c931 | ||
|
|
e5552e27f2 | ||
|
|
438963fb24 | ||
|
|
0bb815edc0 | ||
|
|
55a02981b5 | ||
|
|
b06e3b239d | ||
|
|
47442941b6 | ||
|
|
b16d2d0695 | ||
|
|
8b1cc72f09 | ||
|
|
11a6a81169 | ||
|
|
0ce66009c1 | ||
|
|
33f2f555a6 | ||
|
|
0487f9f841 | ||
|
|
0d6bfb84ce | ||
|
|
1e4ace8974 | ||
|
|
a378d1e8cb | ||
|
|
81ea39effe | ||
|
|
1a07391a97 | ||
|
|
b002d95459 | ||
|
|
646fc62b89 | ||
|
|
699c00dc20 | ||
|
|
9b9f3ffb96 | ||
|
|
00a67c3fb2 | ||
|
|
50d6403c72 | ||
|
|
9111157b82 | ||
|
|
794dd6cd7e | ||
|
|
ae4352c198 | ||
|
|
4a73eb56ea | ||
|
|
0f321bc797 | ||
|
|
94d07c78d8 | ||
|
|
b51e1c7c2c | ||
|
|
26ddf1ff4d | ||
|
|
20fd6eabbb | ||
|
|
fbe29006d4 | ||
|
|
03bb510588 | ||
|
|
695dfe9dbd | ||
|
|
9782f7d942 | ||
|
|
1b5648bb06 | ||
|
|
a67f5d6e01 | ||
|
|
06b57aa1ce | ||
|
|
6d2db2ef64 | ||
|
|
9868a01163 | ||
|
|
0c8cdd92d6 | ||
|
|
80a376f045 | ||
|
|
0068c1375c | ||
|
|
872af9c7ed | ||
|
|
06ea7b20bf | ||
|
|
a3c4652bfd | ||
|
|
5ad48851ed | ||
|
|
e3b7339dd6 | ||
|
|
69d7f84502 | ||
|
|
e970b6d6eb | ||
|
|
d9cce3fa1f | ||
|
|
23721694ea | ||
|
|
aa02958e18 | ||
|
|
011d4ec392 | ||
|
|
afbaf10185 | ||
|
|
6a5e2f439e | ||
|
|
fba77c4dce | ||
|
|
830df360ae | ||
|
|
c75551b1b3 | ||
|
|
5a38f6e148 | ||
|
|
869021f47d | ||
|
|
c06985a7ad | ||
|
|
c502804192 | ||
|
|
75f1bcde31 | ||
|
|
60b85298a9 | ||
|
|
8bbafb7200 | ||
|
|
75ce230dce | ||
|
|
1d01268249 | ||
|
|
02cb5a0526 | ||
|
|
8397b3d8ec | ||
|
|
296e5489c9 | ||
|
|
9ab9d0f39c | ||
|
|
6e1a5dcc9d | ||
|
|
d360d03403 | ||
|
|
e9bfe849ad | ||
|
|
665eb916a2 | ||
|
|
04788e15af | ||
|
|
dcb8c69661 | ||
|
|
cc6b70f1d5 | ||
|
|
38a9a613da | ||
|
|
ad9a766a56 | ||
|
|
21b59c4651 | ||
|
|
3ffdd50909 | ||
|
|
ca36422ac9 | ||
|
|
8e4ba8d2e4 | ||
|
|
ee67f1039c | ||
|
|
d37aa93a7d | ||
|
|
bba532193b | ||
|
|
b4814b06b9 | ||
|
|
4ee2eb845b | ||
|
|
3fdf01c0f5 | ||
|
|
1949a61c6f | ||
|
|
43cf20b155 | ||
|
|
e27a6d53a0 | ||
|
|
d17e9c663e | ||
|
|
dd8f396227 | ||
|
|
b60853ea21 | ||
|
|
b936ca27ab | ||
|
|
e050803ed1 | ||
|
|
27f38770d4 | ||
|
|
db1f77f90b | ||
|
|
4d21588eb2 | ||
|
|
e596dbfc80 | ||
|
|
1aeaca2af6 | ||
|
|
267e4bc25c | ||
|
|
c3e27217dd | ||
|
|
fe3521c7a4 | ||
|
|
b0f8d75d1d | ||
|
|
7a314e7aff | ||
|
|
637bbbdf43 | ||
|
|
8230e8165c | ||
|
|
a727a0f81f | ||
|
|
7a587eb7d6 | ||
|
|
7ac8bd6e24 | ||
|
|
be2572edca | ||
|
|
cf2bbe6435 | ||
|
|
dc5b7802c8 | ||
|
|
b1e6c73197 | ||
|
|
459773b3f0 | ||
|
|
6d0a3c75e9 | ||
|
|
e35585960c | ||
|
|
3bea7930a9 | ||
|
|
52797b6f68 | ||
|
|
5108c5643c | ||
|
|
2005ed1df9 | ||
|
|
d43408f4f3 | ||
|
|
2c30ab8731 |
99
.clang-format
Normal file
99
.clang-format
Normal file
@@ -0,0 +1,99 @@
|
|||||||
|
AccessModifierOffset: -4
|
||||||
|
AlignAfterOpenBracket: Align
|
||||||
|
AlignArrayOfStructures: Left
|
||||||
|
AlignConsecutiveAssignments: None
|
||||||
|
AlignConsecutiveBitFields: Consecutive
|
||||||
|
AlignConsecutiveDeclarations: None
|
||||||
|
AlignConsecutiveMacros: Consecutive
|
||||||
|
AlignEscapedNewlines: Left
|
||||||
|
AlignOperands: Align
|
||||||
|
AlignTrailingComments: false
|
||||||
|
AllowShortBlocksOnASingleLine: Empty
|
||||||
|
AllowShortCaseLabelsOnASingleLine: false
|
||||||
|
AllowShortEnumsOnASingleLine: true
|
||||||
|
AllowShortFunctionsOnASingleLine: InlineOnly
|
||||||
|
AllowShortIfStatementsOnASingleLine: Never
|
||||||
|
AllowShortLambdasOnASingleLine: All
|
||||||
|
AllowShortLoopsOnASingleLine: false
|
||||||
|
AlwaysBreakAfterReturnType: None
|
||||||
|
AlwaysBreakBeforeMultilineStrings: false
|
||||||
|
AlwaysBreakTemplateDeclarations: Yes
|
||||||
|
AttributeMacros:
|
||||||
|
- format_
|
||||||
|
- attr_
|
||||||
|
BinPackArguments: true
|
||||||
|
BinPackParameters: true
|
||||||
|
BitFieldColonSpacing: Both
|
||||||
|
BreakBeforeBinaryOperators: NonAssignment
|
||||||
|
BreakBeforeBraces: Attach
|
||||||
|
BreakBeforeConceptDeclarations: true
|
||||||
|
BreakBeforeTernaryOperators: true
|
||||||
|
BreakConstructorInitializers: BeforeColon
|
||||||
|
BreakInheritanceList: AfterComma
|
||||||
|
BreakStringLiterals: true
|
||||||
|
ColumnLimit: 100
|
||||||
|
CompactNamespaces: false
|
||||||
|
ContinuationIndentWidth: 4
|
||||||
|
Cpp11BracedListStyle: true
|
||||||
|
DeriveLineEnding: true
|
||||||
|
DerivePointerAlignment: false
|
||||||
|
EmptyLineBeforeAccessModifier: Leave
|
||||||
|
FixNamespaceComments: false
|
||||||
|
IncludeBlocks: Regroup
|
||||||
|
IncludeCategories:
|
||||||
|
- Regex: '^<sys/'
|
||||||
|
Priority: 0
|
||||||
|
- Regex: '^<'
|
||||||
|
Priority: 1
|
||||||
|
- Regex: '^"extern/'
|
||||||
|
Priority: 2
|
||||||
|
- Regex: '^"(asm|link|fix|gfx)/'
|
||||||
|
Priority: 3
|
||||||
|
- Regex: '^"'
|
||||||
|
Priority: 2
|
||||||
|
IndentAccessModifiers: false
|
||||||
|
IndentCaseBlocks: false
|
||||||
|
IndentCaseLabels: false
|
||||||
|
IndentExternBlock: NoIndent
|
||||||
|
IndentGotoLabels: false
|
||||||
|
IndentPPDirectives: BeforeHash
|
||||||
|
IndentRequires: true
|
||||||
|
IndentWidth: 4
|
||||||
|
IndentWrappedFunctionNames: true
|
||||||
|
# Only support for Javascript as of clang-format 13...
|
||||||
|
# InsertTrailingCommas: true
|
||||||
|
KeepEmptyLinesAtTheStartOfBlocks: false
|
||||||
|
LambdaBodyIndentation: Signature
|
||||||
|
Language: Cpp
|
||||||
|
MaxEmptyLinesToKeep: 1
|
||||||
|
NamespaceIndentation: None
|
||||||
|
PPIndentWidth: -1
|
||||||
|
PointerAlignment: Right
|
||||||
|
ReflowComments: true
|
||||||
|
SortIncludes: CaseSensitive
|
||||||
|
SortUsingDeclarations: true
|
||||||
|
SpaceAfterCStyleCast: false
|
||||||
|
SpaceAfterLogicalNot: false
|
||||||
|
SpaceAfterTemplateKeyword: false
|
||||||
|
SpaceAroundPointerQualifiers: Both
|
||||||
|
SpaceBeforeAssignmentOperators: true
|
||||||
|
SpaceBeforeCaseColon: false
|
||||||
|
SpaceBeforeCpp11BracedList: false
|
||||||
|
SpaceBeforeCtorInitializerColon: true
|
||||||
|
SpaceBeforeInheritanceColon: true
|
||||||
|
SpaceBeforeParens: ControlStatements
|
||||||
|
SpaceBeforeRangeBasedForLoopColon: true
|
||||||
|
SpaceBeforeSquareBrackets: false
|
||||||
|
SpaceInEmptyBlock: false
|
||||||
|
SpaceInEmptyParentheses: false
|
||||||
|
SpacesBeforeTrailingComments: 1
|
||||||
|
SpacesInAngles: false
|
||||||
|
SpacesInCStyleCastParentheses: false
|
||||||
|
SpacesInConditionalStatement: false
|
||||||
|
SpacesInContainerLiterals: false
|
||||||
|
SpacesInParentheses: false
|
||||||
|
SpacesInSquareBrackets: false
|
||||||
|
Standard: c++20
|
||||||
|
TabWidth: 4
|
||||||
|
UseCRLF: false
|
||||||
|
UseTab: AlignWithSpaces
|
||||||
2
.gitattributes
vendored
Normal file
2
.gitattributes
vendored
Normal file
@@ -0,0 +1,2 @@
|
|||||||
|
# Shell scripts need Unix line endings (see https://github.com/gbdev/rgbds/issues/841)
|
||||||
|
*.sh text eol=lf
|
||||||
5
.github/actions/install_deps.sh
vendored
5
.github/actions/install_deps.sh
vendored
@@ -1,4 +1,7 @@
|
|||||||
case `echo $1 | cut -d '-' -f 1` in
|
#!/bin/bash
|
||||||
|
set -e
|
||||||
|
|
||||||
|
case "${1%-*}" in
|
||||||
ubuntu)
|
ubuntu)
|
||||||
sudo apt-get -qq update
|
sudo apt-get -qq update
|
||||||
sudo apt-get install -yq bison libpng-dev pkg-config
|
sudo apt-get install -yq bison libpng-dev pkg-config
|
||||||
|
|||||||
17
.github/workflows/checkdiff.yml
vendored
Normal file
17
.github/workflows/checkdiff.yml
vendored
Normal file
@@ -0,0 +1,17 @@
|
|||||||
|
name: "Code coverage checking"
|
||||||
|
on: pull_request
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
checkdiff:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
steps:
|
||||||
|
- name: Set up repo
|
||||||
|
run: |
|
||||||
|
git clone -b "${{ github.event.pull_request.head.ref }}" "${{ github.event.pull_request.head.repo.clone_url }}" rgbds
|
||||||
|
cd rgbds
|
||||||
|
git remote add upstream "${{ github.event.pull_request.base.repo.clone_url }}"
|
||||||
|
git fetch upstream
|
||||||
|
- name: Checkdiff
|
||||||
|
working-directory: rgbds
|
||||||
|
run: |
|
||||||
|
make checkdiff "BASE_REF=${{ github.event.pull_request.base.sha }}" Q= | tee log
|
||||||
10
.github/workflows/create-release-artifacts.yaml
vendored
10
.github/workflows/create-release-artifacts.yaml
vendored
@@ -17,9 +17,9 @@ jobs:
|
|||||||
- name: Get zlib, libpng and bison
|
- name: Get zlib, libpng and bison
|
||||||
run: | # TODO: use an array
|
run: | # TODO: use an array
|
||||||
$wc = New-Object System.Net.WebClient
|
$wc = New-Object System.Net.WebClient
|
||||||
$wc.DownloadFile('https://www.zlib.net/zlib1211.zip', 'zlib.zip')
|
$wc.DownloadFile('https://www.zlib.net/zlib1212.zip', 'zlib.zip')
|
||||||
$hash = (Get-FileHash "zlib.zip" -Algorithm SHA256).Hash
|
$hash = (Get-FileHash "zlib.zip" -Algorithm SHA256).Hash
|
||||||
if ($hash -ne 'd7510a8ee1918b7d0cad197a089c0a2cd4d6df05fee22389f67f115e738b178d') {
|
if ($hash -ne '173e89893dcb8b4a150d7731cd72f0602f1d6b45e60e2a54efdf7f3fc3325fd7') {
|
||||||
Write-Host "zlib SHA256 mismatch! ($hash)"
|
Write-Host "zlib SHA256 mismatch! ($hash)"
|
||||||
exit 1
|
exit 1
|
||||||
}
|
}
|
||||||
@@ -29,15 +29,15 @@ jobs:
|
|||||||
Write-Host "libpng SHA256 mismatch! ($hash)"
|
Write-Host "libpng SHA256 mismatch! ($hash)"
|
||||||
exit 1
|
exit 1
|
||||||
}
|
}
|
||||||
$wc.DownloadFile('https://github.com/lexxmark/winflexbison/releases/download/v2.5.23/win_flex_bison-2.5.23.zip', 'winflexbison.zip')
|
$wc.DownloadFile('https://github.com/lexxmark/winflexbison/releases/download/v2.5.24/win_flex_bison-2.5.24.zip', 'winflexbison.zip')
|
||||||
$hash = (Get-FileHash "winflexbison.zip" -Algorithm SHA256).Hash
|
$hash = (Get-FileHash "winflexbison.zip" -Algorithm SHA256).Hash
|
||||||
if ($hash -ne '6AA5C8EA662DA1550020A5804C28BE63FFAA53486DA9F6842E24C379EC422DFC') {
|
if ($hash -ne '39c6086ce211d5415500acc5ed2d8939861ca1696aee48909c7f6daf5122b505') {
|
||||||
Write-Host "bison SHA256 mismatch! ($hash)"
|
Write-Host "bison SHA256 mismatch! ($hash)"
|
||||||
}
|
}
|
||||||
Expand-Archive -DestinationPath . "zlib.zip"
|
Expand-Archive -DestinationPath . "zlib.zip"
|
||||||
Expand-Archive -DestinationPath . "libpng.zip"
|
Expand-Archive -DestinationPath . "libpng.zip"
|
||||||
Expand-Archive -DestinationPath install_dir "winflexbison.zip"
|
Expand-Archive -DestinationPath install_dir "winflexbison.zip"
|
||||||
Move-Item zlib-1.2.11 zlib
|
Move-Item zlib-1.2.12 zlib
|
||||||
Move-Item lpng1637 libpng
|
Move-Item lpng1637 libpng
|
||||||
- name: Build 32-bit zlib
|
- name: Build 32-bit zlib
|
||||||
run: | # BUILD_SHARED_LIBS causes the output DLL to be correctly called `zlib1.dll`
|
run: | # BUILD_SHARED_LIBS causes the output DLL to be correctly called `zlib1.dll`
|
||||||
|
|||||||
1
.github/workflows/create-release-docs.yml
vendored
1
.github/workflows/create-release-docs.yml
vendored
@@ -6,6 +6,7 @@ on:
|
|||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
build:
|
build:
|
||||||
|
if: github.repository_owner == 'gbdev'
|
||||||
runs-on: ubuntu-18.04
|
runs-on: ubuntu-18.04
|
||||||
steps:
|
steps:
|
||||||
- name: Checkout rgbds@release
|
- name: Checkout rgbds@release
|
||||||
|
|||||||
35
.github/workflows/testing.yml
vendored
35
.github/workflows/testing.yml
vendored
@@ -7,18 +7,15 @@ jobs:
|
|||||||
unix-testing:
|
unix-testing:
|
||||||
strategy:
|
strategy:
|
||||||
matrix:
|
matrix:
|
||||||
os: [ubuntu-20.04, ubuntu-18.04, ubuntu-16.04, macos-10.15]
|
os: [ubuntu-20.04, ubuntu-18.04, macos-11.0, macos-10.15]
|
||||||
cc: [gcc, clang]
|
cc: [gcc, clang]
|
||||||
buildsys: [make, cmake]
|
buildsys: [make, cmake]
|
||||||
include:
|
exclude:
|
||||||
- os: ubuntu-18.04
|
# `gcc` is just an alias to `clang` on macOS, don't bother
|
||||||
|
- os: macos-10.15
|
||||||
cc: gcc
|
cc: gcc
|
||||||
target: develop
|
- os: macos-11.0
|
||||||
cmakevars: -DSANITIZERS=ON -DMORE_WARNINGS=ON -DCMAKE_BUILD_TYPE=Debug
|
|
||||||
- os: ubuntu-20.04
|
|
||||||
cc: gcc
|
cc: gcc
|
||||||
target: develop
|
|
||||||
cmakevars: -DSANITIZERS=ON -DMORE_WARNINGS=ON -DCMAKE_BUILD_TYPE=Debug
|
|
||||||
fail-fast: false
|
fail-fast: false
|
||||||
runs-on: ${{ matrix.os }}
|
runs-on: ${{ matrix.os }}
|
||||||
steps:
|
steps:
|
||||||
@@ -33,14 +30,14 @@ jobs:
|
|||||||
- name: Build & install using Make
|
- name: Build & install using Make
|
||||||
run: |
|
run: |
|
||||||
export PATH="/usr/local/opt/bison/bin:$PATH"
|
export PATH="/usr/local/opt/bison/bin:$PATH"
|
||||||
make ${{ matrix.target }} -j Q= CC=${{ matrix.cc }}
|
make develop -j Q= CC=${{ matrix.cc }}
|
||||||
sudo make install -j Q=
|
sudo make install -j Q=
|
||||||
if: matrix.buildsys == 'make'
|
if: matrix.buildsys == 'make'
|
||||||
- name: Build & install using CMake
|
- name: Build & install using CMake
|
||||||
run: |
|
run: |
|
||||||
export PATH="/usr/local/opt/bison/bin:$PATH"
|
export PATH="/usr/local/opt/bison/bin:$PATH"
|
||||||
cmake -S . -B build -DCMAKE_VERBOSE_MAKEFILE=ON -DCMAKE_BUILD_TYPE=Release -DCMAKE_C_COMPILER=${{ matrix.cc }} ${{ matrix.cmakevars }}
|
cmake -S . -B build -DCMAKE_VERBOSE_MAKEFILE=ON -DCMAKE_BUILD_TYPE=Debug -DCMAKE_C_COMPILER=${{ matrix.cc }} -DSANITIZERS=ON -DMORE_WARNINGS=ON
|
||||||
cmake --build build
|
cmake --build build -j
|
||||||
cp build/src/rgb{asm,link,fix,gfx} .
|
cp build/src/rgb{asm,link,fix,gfx} .
|
||||||
sudo cmake --install build
|
sudo cmake --install build
|
||||||
if: matrix.buildsys == 'cmake'
|
if: matrix.buildsys == 'cmake'
|
||||||
@@ -76,9 +73,9 @@ jobs:
|
|||||||
- name: Get zlib, libpng and bison
|
- name: Get zlib, libpng and bison
|
||||||
run: | # TODO: use an array
|
run: | # TODO: use an array
|
||||||
$wc = New-Object System.Net.WebClient
|
$wc = New-Object System.Net.WebClient
|
||||||
$wc.DownloadFile('https://www.zlib.net/zlib1211.zip', 'zlib.zip')
|
$wc.DownloadFile('https://www.zlib.net/zlib1212.zip', 'zlib.zip')
|
||||||
$hash = (Get-FileHash "zlib.zip" -Algorithm SHA256).Hash
|
$hash = (Get-FileHash "zlib.zip" -Algorithm SHA256).Hash
|
||||||
if ($hash -ne 'd7510a8ee1918b7d0cad197a089c0a2cd4d6df05fee22389f67f115e738b178d') {
|
if ($hash -ne '173e89893dcb8b4a150d7731cd72f0602f1d6b45e60e2a54efdf7f3fc3325fd7') {
|
||||||
Write-Host "zlib SHA256 mismatch! ($hash)"
|
Write-Host "zlib SHA256 mismatch! ($hash)"
|
||||||
exit 1
|
exit 1
|
||||||
}
|
}
|
||||||
@@ -88,30 +85,30 @@ jobs:
|
|||||||
Write-Host "libpng SHA256 mismatch! ($hash)"
|
Write-Host "libpng SHA256 mismatch! ($hash)"
|
||||||
exit 1
|
exit 1
|
||||||
}
|
}
|
||||||
$wc.DownloadFile('https://github.com/lexxmark/winflexbison/releases/download/v2.5.23/win_flex_bison-2.5.23.zip', 'winflexbison.zip')
|
$wc.DownloadFile('https://github.com/lexxmark/winflexbison/releases/download/v2.5.24/win_flex_bison-2.5.24.zip', 'winflexbison.zip')
|
||||||
$hash = (Get-FileHash "winflexbison.zip" -Algorithm SHA256).Hash
|
$hash = (Get-FileHash "winflexbison.zip" -Algorithm SHA256).Hash
|
||||||
if ($hash -ne '6AA5C8EA662DA1550020A5804C28BE63FFAA53486DA9F6842E24C379EC422DFC') {
|
if ($hash -ne '39c6086ce211d5415500acc5ed2d8939861ca1696aee48909c7f6daf5122b505') {
|
||||||
Write-Host "bison SHA256 mismatch! ($hash)"
|
Write-Host "bison SHA256 mismatch! ($hash)"
|
||||||
}
|
}
|
||||||
Expand-Archive -DestinationPath . "zlib.zip"
|
Expand-Archive -DestinationPath . "zlib.zip"
|
||||||
Expand-Archive -DestinationPath . "libpng.zip"
|
Expand-Archive -DestinationPath . "libpng.zip"
|
||||||
Expand-Archive -DestinationPath install_dir "winflexbison.zip"
|
Expand-Archive -DestinationPath install_dir "winflexbison.zip"
|
||||||
Move-Item zlib-1.2.11 zlib
|
Move-Item zlib-1.2.12 zlib
|
||||||
Move-Item lpng1637 libpng
|
Move-Item lpng1637 libpng
|
||||||
- name: Build zlib
|
- name: Build zlib
|
||||||
run: | # BUILD_SHARED_LIBS causes the output DLL to be correctly called `zlib1.dll`
|
run: | # BUILD_SHARED_LIBS causes the output DLL to be correctly called `zlib1.dll`
|
||||||
cmake -S zlib -B zbuild -A ${{ matrix.platform }} -DCMAKE_INSTALL_PREFIX=install_dir -DBUILD_SHARED_LIBS=ON
|
cmake -S zlib -B zbuild -A ${{ matrix.platform }} -DCMAKE_INSTALL_PREFIX=install_dir -DBUILD_SHARED_LIBS=ON
|
||||||
cmake --build zbuild --config Release
|
cmake --build zbuild --config Release -j
|
||||||
cmake --install zbuild
|
cmake --install zbuild
|
||||||
- name: Build libpng
|
- name: Build libpng
|
||||||
run: |
|
run: |
|
||||||
cmake -S libpng -B pngbuild -A ${{ matrix.platform }} -DCMAKE_INSTALL_PREFIX=install_dir -DPNG_SHARED=ON -DPNG_STATIC=ON -DPNG_TESTS=OFF
|
cmake -S libpng -B pngbuild -A ${{ matrix.platform }} -DCMAKE_INSTALL_PREFIX=install_dir -DPNG_SHARED=ON -DPNG_STATIC=ON -DPNG_TESTS=OFF
|
||||||
cmake --build pngbuild --config Release
|
cmake --build pngbuild --config Release -j
|
||||||
cmake --install pngbuild
|
cmake --install pngbuild
|
||||||
- name: Build Windows binaries
|
- name: Build Windows binaries
|
||||||
run: |
|
run: |
|
||||||
cmake -S . -B build -A ${{ matrix.platform }} -DCMAKE_INSTALL_PREFIX=install_dir -DCMAKE_BUILD_TYPE=Release
|
cmake -S . -B build -A ${{ matrix.platform }} -DCMAKE_INSTALL_PREFIX=install_dir -DCMAKE_BUILD_TYPE=Release
|
||||||
cmake --build build --config Release
|
cmake --build build --config Release -j
|
||||||
cmake --install build
|
cmake --install build
|
||||||
- name: Package binaries
|
- name: Package binaries
|
||||||
shell: bash
|
shell: bash
|
||||||
|
|||||||
1
.github/workflows/update-master-docs.yml
vendored
1
.github/workflows/update-master-docs.yml
vendored
@@ -17,6 +17,7 @@ on:
|
|||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
build:
|
build:
|
||||||
|
if: github.repository_owner == 'gbdev'
|
||||||
runs-on: ubuntu-18.04
|
runs-on: ubuntu-18.04
|
||||||
steps:
|
steps:
|
||||||
- name: Checkout rgbds@master
|
- name: Checkout rgbds@master
|
||||||
|
|||||||
16
.gitignore
vendored
16
.gitignore
vendored
@@ -1,16 +1,12 @@
|
|||||||
rgbasm
|
/rgbasm
|
||||||
rgblink
|
/rgblink
|
||||||
rgbfix
|
/rgbfix
|
||||||
rgbgfx
|
/rgbgfx
|
||||||
rgbshim.sh
|
/rgbshim.sh
|
||||||
*.o
|
*.o
|
||||||
*.exe
|
*.exe
|
||||||
*.dll
|
*.dll
|
||||||
.checkpatch-camelcase.*
|
.checkpatch-camelcase.*
|
||||||
CMakeCache.txt
|
CMakeCache.txt
|
||||||
CMakeFiles
|
CMakeFiles/
|
||||||
cmake_install.cmake
|
cmake_install.cmake
|
||||||
|
|
||||||
test/pokecrystal
|
|
||||||
test/pokered
|
|
||||||
test/ucity
|
|
||||||
|
|||||||
@@ -25,8 +25,6 @@ endif()
|
|||||||
|
|
||||||
option(SANITIZERS "Build with sanitizers enabled" OFF) # Ignored on MSVC
|
option(SANITIZERS "Build with sanitizers enabled" OFF) # Ignored on MSVC
|
||||||
option(MORE_WARNINGS "Turn on more warnings" OFF) # Ignored on MSVC
|
option(MORE_WARNINGS "Turn on more warnings" OFF) # Ignored on MSVC
|
||||||
option(TRACE_PARSER "Trace parser execution" OFF)
|
|
||||||
option(TRACE_LEXER "Trace lexer execution" OFF)
|
|
||||||
|
|
||||||
if(MSVC)
|
if(MSVC)
|
||||||
# MSVC's standard library triggers warning C5105,
|
# MSVC's standard library triggers warning C5105,
|
||||||
@@ -35,40 +33,52 @@ if(MSVC)
|
|||||||
add_definitions(/D_CRT_SECURE_NO_WARNINGS)
|
add_definitions(/D_CRT_SECURE_NO_WARNINGS)
|
||||||
else()
|
else()
|
||||||
add_compile_options(-Wall -pedantic)
|
add_compile_options(-Wall -pedantic)
|
||||||
|
add_definitions(-D_POSIX_C_SOURCE=200809L -D_ISOC11_SOURCE)
|
||||||
if(SANITIZERS)
|
if(SANITIZERS)
|
||||||
set(SAN_FLAGS -fsanitize=shift -fsanitize=integer-divide-by-zero
|
set(SAN_FLAGS -fsanitize=shift -fsanitize=integer-divide-by-zero
|
||||||
-fsanitize=unreachable -fsanitize=vla-bound
|
-fsanitize=unreachable -fsanitize=vla-bound
|
||||||
-fsanitize=signed-integer-overflow -fsanitize=bounds
|
-fsanitize=signed-integer-overflow -fsanitize=bounds
|
||||||
-fsanitize=object-size -fsanitize=bool -fsanitize=enum
|
-fsanitize=object-size -fsanitize=bool -fsanitize=enum
|
||||||
-fsanitize=alignment -fsanitize=null)
|
-fsanitize=alignment -fsanitize=null -fsanitize=address)
|
||||||
add_compile_options(${SAN_FLAGS})
|
add_compile_options(${SAN_FLAGS})
|
||||||
link_libraries(${SAN_FLAGS})
|
link_libraries(${SAN_FLAGS})
|
||||||
|
# A non-zero optimization level is desired in debug mode, but allow overriding it nonetheless
|
||||||
|
# TODO: this overrides anything previously set... that's a bit sloppy!
|
||||||
|
set(CMAKE_C_FLAGS_DEBUG "-g -Og -fno-omit-frame-pointer -fno-optimize-sibling-calls" CACHE STRING "" FORCE)
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
if(MORE_WARNINGS)
|
if(MORE_WARNINGS)
|
||||||
add_compile_options(-Werror -Wextra -Wno-type-limits
|
add_compile_options(-Werror -Wextra
|
||||||
-Wno-sign-compare -Wvla -Wformat -Wformat-security -Wformat-overflow=2
|
-Walloc-zero -Wcast-align -Wcast-qual -Wduplicated-branches -Wduplicated-cond
|
||||||
-Wformat-truncation=1 -Wformat-y2k -Wswitch-enum -Wunused
|
-Wfloat-equal -Winline -Wlogical-op -Wnested-externs -Wnull-dereference
|
||||||
-Wuninitialized -Wunknown-pragmas -Wstrict-overflow=5
|
-Wold-style-definition -Wshift-overflow=2 -Wstrict-overflow=5
|
||||||
-Wstringop-overflow=4 -Walloc-zero -Wduplicated-cond
|
-Wstrict-prototypes -Wstringop-overflow=4 -Wundef -Wuninitialized -Wunused
|
||||||
-Wfloat-equal -Wshadow -Wcast-qual -Wcast-align -Wlogical-op
|
-Wshadow # TODO: -Wshadow=compatible-local ?
|
||||||
-Wnested-externs -Wno-aggressive-loop-optimizations -Winline
|
-Wformat=2 -Wformat-overflow=2 -Wformat-truncation=1
|
||||||
-Wundef -Wstrict-prototypes -Wold-style-definition)
|
-Wno-format-nonliteral # We have a couple of "dynamic" prints
|
||||||
|
# We do some range checks that are always false on some platforms (GCC, Clang)
|
||||||
|
-Wno-type-limits -Wno-tautological-constant-out-of-range-compare
|
||||||
|
-Wvla # MSVC does not support VLAs
|
||||||
|
-Wno-unknown-warning-option) # Clang shouldn't diagnose unknown warnings
|
||||||
endif()
|
endif()
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
# Use versioning consistent with Makefile
|
# Use versioning consistent with Makefile
|
||||||
# the git revision is used but uses the fallback in an archive
|
# the git revision is used but uses the fallback in an archive
|
||||||
|
|
||||||
execute_process(COMMAND git describe --tags --dirty --always
|
find_program(GIT git)
|
||||||
OUTPUT_VARIABLE GIT_REV
|
if(GIT)
|
||||||
|
execute_process(COMMAND ${GIT} describe --tags --dirty --always
|
||||||
|
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
|
||||||
|
OUTPUT_VARIABLE GIT_REV OUTPUT_STRIP_TRAILING_WHITESPACE
|
||||||
ERROR_QUIET)
|
ERROR_QUIET)
|
||||||
string(STRIP "${GIT_REV}" GIT_REV)
|
message(STATUS "RGBDS version: ${GIT_REV}")
|
||||||
|
else(GIT)
|
||||||
|
message(STATUS "Cannot determine RGBDS version (Git not installed), falling back")
|
||||||
|
endif(GIT)
|
||||||
|
|
||||||
include_directories("${PROJECT_SOURCE_DIR}/include")
|
include_directories("${PROJECT_SOURCE_DIR}/include")
|
||||||
|
|
||||||
add_definitions(-DBUILD_VERSION_STRING="${GIT_REV}")
|
|
||||||
|
|
||||||
set(CMAKE_C_STANDARD 11)
|
set(CMAKE_C_STANDARD 11)
|
||||||
set(CMAKE_C_STANDARD_REQUIRED True)
|
set(CMAKE_C_STANDARD_REQUIRED True)
|
||||||
|
|
||||||
@@ -87,11 +97,3 @@ if(CMAKE_BUILD_TYPE STREQUAL "Release")
|
|||||||
message(CHECK_FAIL "no")
|
message(CHECK_FAIL "no")
|
||||||
endif()
|
endif()
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
if(TRACE_PARSER)
|
|
||||||
target_compile_definitions(rgbasm PRIVATE -DYYDEBUG)
|
|
||||||
endif()
|
|
||||||
|
|
||||||
if(TRACE_LEXER)
|
|
||||||
target_compile_definitions(rgbasm PRIVATE -DLEXER_DEBUG)
|
|
||||||
endif()
|
|
||||||
|
|||||||
@@ -19,6 +19,10 @@ Main contributors
|
|||||||
|
|
||||||
- Antonio Niño Díaz <antonio_nd@outlook.com>
|
- Antonio Niño Díaz <antonio_nd@outlook.com>
|
||||||
|
|
||||||
|
- Eldred "ISSOtm" Habert <eldredhabert0@gmail.com>
|
||||||
|
|
||||||
|
- Rangi <http://github.com/Rangi42>
|
||||||
|
|
||||||
Other contributors
|
Other contributors
|
||||||
------------------
|
------------------
|
||||||
|
|
||||||
@@ -30,7 +34,9 @@ Other contributors
|
|||||||
|
|
||||||
- David Brotz <dbrotz007@gmail.com>
|
- David Brotz <dbrotz007@gmail.com>
|
||||||
|
|
||||||
- Eldred Habert <eldredhabert0@gmail.com>
|
- Jakub Kądziołka <kuba@kadziolka.net>
|
||||||
|
|
||||||
|
- James "JL2210" Larrowe <https://github.com/JL2210>
|
||||||
|
|
||||||
- The Musl C library <http://www.musl-libc.org>
|
- The Musl C library <http://www.musl-libc.org>
|
||||||
|
|
||||||
@@ -40,8 +46,6 @@ Other contributors
|
|||||||
|
|
||||||
- Quint Guvernator <quint@guvernator.net>
|
- Quint Guvernator <quint@guvernator.net>
|
||||||
|
|
||||||
- Rangi <http://github.com/Rangi42>
|
|
||||||
|
|
||||||
- Sanqui <gsanky@gmail.com>
|
- Sanqui <gsanky@gmail.com>
|
||||||
|
|
||||||
- YamaArashi <shadow962@live.com>
|
- YamaArashi <shadow962@live.com>
|
||||||
|
|||||||
60
Makefile
60
Makefile
@@ -30,13 +30,14 @@ PNGLDLIBS := `${PKG_CONFIG} --libs-only-l libpng`
|
|||||||
# Note: if this comes up empty, `version.c` will automatically fall back to last release number
|
# Note: if this comes up empty, `version.c` will automatically fall back to last release number
|
||||||
VERSION_STRING := `git describe --tags --dirty --always 2>/dev/null`
|
VERSION_STRING := `git describe --tags --dirty --always 2>/dev/null`
|
||||||
|
|
||||||
WARNFLAGS := -Wall
|
WARNFLAGS := -Wall -pedantic
|
||||||
|
|
||||||
# Overridable CFLAGS
|
# Overridable CFLAGS
|
||||||
CFLAGS ?= -O3 -flto -DNDEBUG
|
CFLAGS ?= -O3 -flto -DNDEBUG
|
||||||
# Non-overridable CFLAGS
|
# Non-overridable CFLAGS
|
||||||
REALCFLAGS := ${CFLAGS} ${WARNFLAGS} -std=gnu11 -D_POSIX_C_SOURCE=200809L \
|
# _ISOC11_SOURCE is required on certain platforms to get C11 on top of the C99-based POSIX 2008
|
||||||
-Iinclude
|
REALCFLAGS := ${CFLAGS} ${WARNFLAGS} -std=gnu11 -I include \
|
||||||
|
-D_POSIX_C_SOURCE=200809L -D_ISOC11_SOURCE
|
||||||
# Overridable LDFLAGS
|
# Overridable LDFLAGS
|
||||||
LDFLAGS ?=
|
LDFLAGS ?=
|
||||||
# Non-overridable LDFLAGS
|
# Non-overridable LDFLAGS
|
||||||
@@ -48,6 +49,9 @@ YFLAGS ?= -Wall
|
|||||||
BISON := bison
|
BISON := bison
|
||||||
RM := rm -rf
|
RM := rm -rf
|
||||||
|
|
||||||
|
# Used for checking pull requests
|
||||||
|
BASE_REF := origin/master
|
||||||
|
|
||||||
# Rules to build the RGBDS binaries
|
# Rules to build the RGBDS binaries
|
||||||
|
|
||||||
all: rgbasm rgblink rgbfix rgbgfx
|
all: rgbasm rgblink rgbfix rgbgfx
|
||||||
@@ -60,17 +64,17 @@ rgbasm_obj := \
|
|||||||
src/asm/lexer.o \
|
src/asm/lexer.o \
|
||||||
src/asm/macro.o \
|
src/asm/macro.o \
|
||||||
src/asm/main.o \
|
src/asm/main.o \
|
||||||
src/asm/parser.o \
|
|
||||||
src/asm/opt.o \
|
src/asm/opt.o \
|
||||||
src/asm/output.o \
|
src/asm/output.o \
|
||||||
|
src/asm/parser.o \
|
||||||
src/asm/rpn.o \
|
src/asm/rpn.o \
|
||||||
src/asm/section.o \
|
src/asm/section.o \
|
||||||
src/asm/symbol.o \
|
src/asm/symbol.o \
|
||||||
src/asm/util.o \
|
src/asm/util.o \
|
||||||
src/asm/warning.o \
|
src/asm/warning.o \
|
||||||
src/extern/err.o \
|
|
||||||
src/extern/getopt.o \
|
src/extern/getopt.o \
|
||||||
src/extern/utf8decoder.o \
|
src/extern/utf8decoder.o \
|
||||||
|
src/error.o \
|
||||||
src/hashmap.o \
|
src/hashmap.o \
|
||||||
src/linkdefs.o \
|
src/linkdefs.o \
|
||||||
src/opmath.o
|
src/opmath.o
|
||||||
@@ -86,23 +90,23 @@ rgblink_obj := \
|
|||||||
src/link/script.o \
|
src/link/script.o \
|
||||||
src/link/section.o \
|
src/link/section.o \
|
||||||
src/link/symbol.o \
|
src/link/symbol.o \
|
||||||
src/extern/err.o \
|
|
||||||
src/extern/getopt.o \
|
src/extern/getopt.o \
|
||||||
|
src/error.o \
|
||||||
src/hashmap.o \
|
src/hashmap.o \
|
||||||
src/linkdefs.o \
|
src/linkdefs.o \
|
||||||
src/opmath.o
|
src/opmath.o
|
||||||
|
|
||||||
rgbfix_obj := \
|
rgbfix_obj := \
|
||||||
src/fix/main.o \
|
src/fix/main.o \
|
||||||
src/extern/err.o \
|
src/extern/getopt.o \
|
||||||
src/extern/getopt.o
|
src/error.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/getopt.o \
|
||||||
src/extern/getopt.o
|
src/error.o
|
||||||
|
|
||||||
rgbasm: ${rgbasm_obj}
|
rgbasm: ${rgbasm_obj}
|
||||||
$Q${CC} ${REALLDFLAGS} -o $@ ${rgbasm_obj} ${REALCFLAGS} src/version.c -lm
|
$Q${CC} ${REALLDFLAGS} -o $@ ${rgbasm_obj} ${REALCFLAGS} src/version.c -lm
|
||||||
@@ -188,9 +192,8 @@ checkcodebase:
|
|||||||
# the first common commit between the HEAD and origin/master.
|
# the first common commit between the HEAD and origin/master.
|
||||||
# `.y` files aren't checked, unfortunately...
|
# `.y` files aren't checked, unfortunately...
|
||||||
|
|
||||||
BASE_REF:= origin/master
|
|
||||||
checkpatch:
|
checkpatch:
|
||||||
$Qeval COMMON_COMMIT=$$(git merge-base HEAD ${BASE_REF}); \
|
$QCOMMON_COMMIT=`git merge-base HEAD ${BASE_REF}`; \
|
||||||
for commit in `git rev-list $$COMMON_COMMIT..HEAD`; do \
|
for commit in `git rev-list $$COMMON_COMMIT..HEAD`; do \
|
||||||
echo "[*] Analyzing commit '$$commit'"; \
|
echo "[*] Analyzing commit '$$commit'"; \
|
||||||
git format-patch --stdout "$$commit~..$$commit" \
|
git format-patch --stdout "$$commit~..$$commit" \
|
||||||
@@ -198,24 +201,35 @@ checkpatch:
|
|||||||
| ${CHECKPATCH} - || true; \
|
| ${CHECKPATCH} - || true; \
|
||||||
done
|
done
|
||||||
|
|
||||||
|
# Target used to check for suspiciously missing changed files.
|
||||||
|
|
||||||
|
checkdiff:
|
||||||
|
$Qcontrib/checkdiff.bash `git merge-base HEAD ${BASE_REF}`
|
||||||
|
|
||||||
# This target is used during development in order to prevent adding new issues
|
# 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
|
# to the source code. All warnings are treated as errors in order to block the
|
||||||
# compilation and make the continous integration infrastructure return failure.
|
# compilation and make the continous integration infrastructure return failure.
|
||||||
|
# The rationale for some of the flags is documented in the CMakeLists.
|
||||||
|
|
||||||
develop:
|
develop:
|
||||||
$Qenv $(MAKE) -j WARNFLAGS="-Werror -Wall -Wextra -Wpedantic -Wno-type-limits \
|
$Qenv ${MAKE} WARNFLAGS="-Werror -Wextra \
|
||||||
-Wno-sign-compare -Wvla -Wformat -Wformat-security -Wformat-overflow=2 \
|
-Walloc-zero -Wcast-align -Wcast-qual -Wduplicated-branches -Wduplicated-cond \
|
||||||
-Wformat-truncation=1 -Wformat-y2k -Wswitch-enum -Wunused \
|
-Wfloat-equal -Winline -Wlogical-op -Wnested-externs -Wold-style-definition \
|
||||||
-Wuninitialized -Wunknown-pragmas -Wstrict-overflow=4 \
|
-Wshift-overflow=2 \
|
||||||
-Wstringop-overflow=4 -Walloc-zero -Wduplicated-cond \
|
-Wstrict-overflow=5 -Wstrict-prototypes -Wundef -Wuninitialized -Wunused \
|
||||||
-Wfloat-equal -Wshadow -Wcast-qual -Wcast-align -Wlogical-op \
|
-Wshadow \
|
||||||
-Wnested-externs -Wno-aggressive-loop-optimizations -Winline \
|
-Wnull-dereference -Wstringop-overflow=4 \
|
||||||
-Wundef -Wstrict-prototypes -Wold-style-definition \
|
-Wformat=2 -Wformat-overflow=2 -Wformat-truncation=1 \
|
||||||
|
-Wno-format-nonliteral \
|
||||||
|
-Wno-type-limits -Wno-tautological-constant-out-of-range-compare \
|
||||||
|
-Wvla \
|
||||||
|
-Wno-unknown-warning-option \
|
||||||
-fsanitize=shift -fsanitize=integer-divide-by-zero \
|
-fsanitize=shift -fsanitize=integer-divide-by-zero \
|
||||||
-fsanitize=unreachable -fsanitize=vla-bound \
|
-fsanitize=unreachable -fsanitize=vla-bound \
|
||||||
-fsanitize=signed-integer-overflow -fsanitize=bounds \
|
-fsanitize=signed-integer-overflow -fsanitize=bounds \
|
||||||
-fsanitize=object-size -fsanitize=bool -fsanitize=enum \
|
-fsanitize=object-size -fsanitize=bool -fsanitize=enum \
|
||||||
-fsanitize=alignment -fsanitize=null" CFLAGS="-ggdb3 -O0"
|
-fsanitize=alignment -fsanitize=null -fsanitize=address" \
|
||||||
|
CFLAGS="-ggdb3 -Og -fno-omit-frame-pointer -fno-optimize-sibling-calls"
|
||||||
|
|
||||||
# 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!
|
||||||
@@ -223,11 +237,11 @@ develop:
|
|||||||
# install instructions instead.
|
# install instructions instead.
|
||||||
|
|
||||||
mingw32:
|
mingw32:
|
||||||
$Qmake CC=i686-w64-mingw32-gcc BISON=bison \
|
$Q${MAKE} CC=i686-w64-mingw32-gcc BISON=bison \
|
||||||
PKG_CONFIG=i686-w64-mingw32-pkg-config -j
|
PKG_CONFIG=i686-w64-mingw32-pkg-config -j
|
||||||
|
|
||||||
mingw64:
|
mingw64:
|
||||||
$Qmake CC=x86_64-w64-mingw32-gcc BISON=bison \
|
$Q${MAKE} CC=x86_64-w64-mingw32-gcc BISON=bison \
|
||||||
PKG_CONFIG=x86_64-w64-mingw32-pkg-config -j
|
PKG_CONFIG=x86_64-w64-mingw32-pkg-config -j
|
||||||
|
|
||||||
wine-shim:
|
wine-shim:
|
||||||
|
|||||||
53
README.rst
53
README.rst
@@ -47,44 +47,53 @@ The RGBDS source code file structure somewhat resembles the following:
|
|||||||
|
|
||||||
.
|
.
|
||||||
├── .github/
|
├── .github/
|
||||||
│ ├── actions/
|
│ ├── actions/
|
||||||
│ │ └── ...
|
│ │ └── ...
|
||||||
│ └── workflows/
|
│ └── workflows/
|
||||||
│ └── ...
|
│ └── ...
|
||||||
├── contrib/
|
├── contrib/
|
||||||
│ ├── zsh_compl/
|
│ ├── zsh_compl/
|
||||||
│ │ └── ...
|
│ │ └── ...
|
||||||
│ └── ...
|
│ └── ...
|
||||||
├── include/
|
├── include/
|
||||||
│ └── ...
|
│ └── ...
|
||||||
├── src/
|
├── src/
|
||||||
│ ├── asm/
|
│ ├── asm/
|
||||||
│ │ └── ...
|
│ │ └── ...
|
||||||
│ ├── extern/
|
│ ├── extern/
|
||||||
│ │ └── ...
|
│ │ └── ...
|
||||||
│ ├── fix/
|
│ ├── fix/
|
||||||
│ │ └── ...
|
│ │ └── ...
|
||||||
│ ├── gfx/
|
│ ├── gfx/
|
||||||
│ │ └── ...
|
│ │ └── ...
|
||||||
│ ├── link/
|
│ ├── link/
|
||||||
│ │ └── ...
|
│ │ └── ...
|
||||||
│ ├── CMakeLists.txt
|
│ ├── CMakeLists.txt
|
||||||
│ └── ...
|
│ └── ...
|
||||||
├── test/
|
├── test/
|
||||||
│ ├── ...
|
│ ├── ...
|
||||||
│ └── run-tests.sh
|
│ └── run-tests.sh
|
||||||
|
├── .clang-format
|
||||||
├── CMakeLists.txt
|
├── CMakeLists.txt
|
||||||
├── Makefile
|
├── Makefile
|
||||||
└── README.rst
|
└── README.rst
|
||||||
|
|
||||||
|
.. |clang-format| replace:: ``clang-format``
|
||||||
|
.. _clang-format: https://clang.llvm.org/docs/ClangFormat.html
|
||||||
|
|
||||||
- ``.github/`` - files and scripts related to the integration of the RGBDS codebase with
|
- ``.github/`` - files and scripts related to the integration of the RGBDS codebase with
|
||||||
GitHub.
|
GitHub.
|
||||||
|
|
||||||
|
* ``actions/`` - scripts used by workflow files.
|
||||||
|
* ``workflows/`` - CI workflow description files.
|
||||||
|
|
||||||
- ``contrib/`` - scripts and other resources which may be useful to users and developers of
|
- ``contrib/`` - scripts and other resources which may be useful to users and developers of
|
||||||
RGBDS.
|
RGBDS.
|
||||||
|
|
||||||
* ``zsh_compl`` contains tab completion scripts for use with zsh. Put them somewhere in your ``fpath``, and they should auto-load.
|
* ``zsh_compl`` contains tab completion scripts for use with zsh. Put them somewhere in your ``fpath``, and they should auto-load.
|
||||||
|
|
||||||
|
* ``bash_compl`` contains tab completion scripts for use with bash. Run them with ``source`` somewhere in your ``.bashrc``, and they should load every time you open a shell.
|
||||||
|
|
||||||
- ``include/`` - header files for each respective C files in `src`.
|
- ``include/`` - header files for each respective C files in `src`.
|
||||||
|
|
||||||
- ``src/`` - source code and manual pages for RGBDS.
|
- ``src/`` - source code and manual pages for RGBDS.
|
||||||
@@ -94,6 +103,8 @@ The RGBDS source code file structure somewhat resembles the following:
|
|||||||
|
|
||||||
- ``test/`` - testing framework used to verify that changes to the code don't break or modify the behavior of RGBDS.
|
- ``test/`` - testing framework used to verify that changes to the code don't break or modify the behavior of RGBDS.
|
||||||
|
|
||||||
|
- ``.clang-format`` - code style for automated formatting with |clang-format|_. The C code does not currently follow this style, but all C++ code should.
|
||||||
|
|
||||||
3. History
|
3. History
|
||||||
----------
|
----------
|
||||||
|
|
||||||
|
|||||||
@@ -63,3 +63,5 @@ GitHub.
|
|||||||
5. Write a changelog in the GitHub draft release.
|
5. Write a changelog in the GitHub draft release.
|
||||||
|
|
||||||
6. Click the "Publish release" button to publish it!
|
6. Click the "Publish release" button to publish it!
|
||||||
|
|
||||||
|
7. Update the `release` branch. You can use ``git push origin release``.
|
||||||
|
|||||||
215
contrib/bash_compl/_rgbasm.bash
Executable file
215
contrib/bash_compl/_rgbasm.bash
Executable file
@@ -0,0 +1,215 @@
|
|||||||
|
#/usr/bin/env bash
|
||||||
|
|
||||||
|
# Known bugs:
|
||||||
|
# - Newlines in file/directory names break this script
|
||||||
|
# This is because we rely on `compgen -A`, which is broken like this.
|
||||||
|
# A fix would require implementing it ourselves, and no thanks!
|
||||||
|
# - `rgbasm --binary-digits=a` is treated the same as `rgbasm --binary-digits=` (for example)
|
||||||
|
# This is not our fault, Bash passes both of these identically.
|
||||||
|
# Maybe it could be worked around, but such a fix would likely be involved.
|
||||||
|
# The user can work around it by typing `--binary-digits ''` instead, for example.
|
||||||
|
# - Directories are not completed as such in "coalesced" short-opt arguments. For example,
|
||||||
|
# `rgbasm -M d<tab>` can autocomplete to `rgbasm -M dir/` (no space), but
|
||||||
|
# `rgbasm -Md<tab>` would autocomplete to `rgbasm -Mdir ` (trailing space) instead.
|
||||||
|
# This is because dircetory handling is performed by Readline, whom we can't tell about the short
|
||||||
|
# opt kerfuffle. The user can work around by separating the argument, as shown above.
|
||||||
|
# (Also, there might be more possible bugs if `-Mdir` is actually a directory. Ugh.)
|
||||||
|
|
||||||
|
# Something to note:
|
||||||
|
# `rgbasm --binary-digits=a` gets passed to us as ('rgbasm' '--binary-digits' '=' 'a')
|
||||||
|
# Thus, we don't need to do much to handle that form of argument passing: skip '=' after long opts.
|
||||||
|
|
||||||
|
_rgbasm_completions() {
|
||||||
|
COMPREPLY=()
|
||||||
|
|
||||||
|
# Format: "long_opt:state_after"
|
||||||
|
# Empty long opt = it doesn't exit
|
||||||
|
# See the `state` variable below for info about `state_after`
|
||||||
|
declare -A opts=(
|
||||||
|
[V]="version:normal"
|
||||||
|
[E]="export-all:normal"
|
||||||
|
[h]="halt-without-nop:normal"
|
||||||
|
[L]="preserve-ld:normal"
|
||||||
|
[v]="verbose:normal"
|
||||||
|
[w]=":normal"
|
||||||
|
[b]="binary-digits:unk"
|
||||||
|
[D]="define:unk"
|
||||||
|
[g]="gfx-chars:unk"
|
||||||
|
[i]="include:dir"
|
||||||
|
[M]="dependfile:glob-*.mk *.d"
|
||||||
|
[o]="output:glob-*.o"
|
||||||
|
[p]="pad-value:unk"
|
||||||
|
[r]="recursion-depth:unk"
|
||||||
|
[W]="warning:warning"
|
||||||
|
)
|
||||||
|
# Parse command-line up to current word
|
||||||
|
local opt_ena=true
|
||||||
|
# Possible states:
|
||||||
|
# - normal = Well, normal. Options are parsed normally.
|
||||||
|
# - unk = An argument that can't be completed, and should just be skipped.
|
||||||
|
# - warning = A warning flag.
|
||||||
|
# - dir = A directory path
|
||||||
|
# - glob-* = A glob, after the dash is a whitespace-separated list of file globs to use
|
||||||
|
local state=normal
|
||||||
|
# The length of the option, used as a return value by the function below
|
||||||
|
local optlen=0
|
||||||
|
# $1: a short option word
|
||||||
|
# `state` will be set to the parsing state after the last option character in the word. If
|
||||||
|
# "normal" is not returned, `optlen` will be set to the length (dash included) of the "option"
|
||||||
|
# part of the argument.
|
||||||
|
parse_short_opt() {
|
||||||
|
for (( i = 1; i < "${#1}"; i++ )); do
|
||||||
|
# If the option is not known, assume it doesn't take an argument
|
||||||
|
local opt="${opts["${1:$i:1}"]:-":normal"}"
|
||||||
|
state="${opt#*:}"
|
||||||
|
# If the option takes an argument, record the length and exit
|
||||||
|
if [[ "$state" != 'normal' ]]; then
|
||||||
|
let optlen="$i + 1"
|
||||||
|
return
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
optlen=0
|
||||||
|
}
|
||||||
|
|
||||||
|
for (( i = 1; i < $COMP_CWORD; i++ )); do
|
||||||
|
local word="${COMP_WORDS[$i]}"
|
||||||
|
|
||||||
|
# If currently processing an argument, skip this word
|
||||||
|
if [[ "$state" != 'normal' ]]; then
|
||||||
|
state=normal
|
||||||
|
continue
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [[ "$word" = '--' ]]; then
|
||||||
|
# Options stop being parsed after this
|
||||||
|
opt_ena=false
|
||||||
|
break
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Check if it's a long option
|
||||||
|
if [[ "${word:0:2}" = '--' ]]; then
|
||||||
|
# If the option is unknown, assume it takes no arguments: keep the state at "normal"
|
||||||
|
for long_opt in "${opts[@]}"; do
|
||||||
|
if [[ "$word" = "--${long_opt%%:*}" ]]; then
|
||||||
|
state="${long_opt#*:}"
|
||||||
|
# Check if the next word is just '='; if so, skip it, the argument must follow
|
||||||
|
# (See "known bugs" at the top of this script)
|
||||||
|
let i++
|
||||||
|
if [[ "${COMP_WORDS[$i]}" != '=' ]]; then
|
||||||
|
let i--
|
||||||
|
fi
|
||||||
|
optlen=0
|
||||||
|
break
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
# Check if it's a short option
|
||||||
|
elif [[ "${word:0:1}" = '-' ]]; then
|
||||||
|
# The `-M?` ones are a mix of short and long, augh
|
||||||
|
# They must match the *full* word, but only take a single dash
|
||||||
|
# So, handle them here
|
||||||
|
if [[ "$1" = "-M"[GP] ]]; then
|
||||||
|
state=normal
|
||||||
|
elif [[ "$1" = "-M"[TQ] ]]; then
|
||||||
|
state='glob-*.d *.mk *.o'
|
||||||
|
else
|
||||||
|
parse_short_opt "$word"
|
||||||
|
# The last option takes an argument...
|
||||||
|
if [[ "$state" != 'normal' ]]; then
|
||||||
|
if [[ "$optlen" -ne "${#word}" ]]; then
|
||||||
|
# If it's contained within the word, we won't complete it, revert to "normal"
|
||||||
|
state=normal
|
||||||
|
else
|
||||||
|
# Otherwise, complete it, but start at the beginning of *that* word
|
||||||
|
optlen=0
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
|
||||||
|
# Parse current word
|
||||||
|
# Careful that it might look like an option, so use `--` aggressively!
|
||||||
|
local cur_word="${COMP_WORDS[$COMP_CWORD]}"
|
||||||
|
|
||||||
|
# Process options, as short ones may change the state
|
||||||
|
if $opt_ena && [[ "$state" = 'normal' && "${cur_word:0:1}" = '-' ]]; then
|
||||||
|
# We might want to complete to an option or an arg to that option
|
||||||
|
# Parse the option word to check
|
||||||
|
# There's no whitespace in the option names, so we can ride a little dirty...
|
||||||
|
|
||||||
|
# Is this a long option?
|
||||||
|
if [[ "${cur_word:1:1}" = '-' ]]; then
|
||||||
|
# It is, try to complete one
|
||||||
|
COMPREPLY+=( $(compgen -W "${opts[*]%%:*}" -P '--' -- "${cur_word#--}") )
|
||||||
|
return 0
|
||||||
|
else
|
||||||
|
# Short options may be grouped, parse them to determine what to complete
|
||||||
|
# The `-M?` ones may not be followed by anything
|
||||||
|
if [[ "$1" != "-M"[GPTQ] ]]; then
|
||||||
|
parse_short_opt "$cur_word"
|
||||||
|
# We got some short options that behave like long ones
|
||||||
|
COMPREPLY+=( $(compgen -W '-MG -MP -MT -MQ' -- "$cur_word") )
|
||||||
|
|
||||||
|
if [[ "$state" = 'normal' ]]; then
|
||||||
|
COMPREPLY+=( $(compgen -W "${!opts[*]}" -P "$cur_word" '') )
|
||||||
|
return 0
|
||||||
|
elif [[ "$optlen" = "${#cur_word}" && "$state" != "warning" ]]; then
|
||||||
|
# This short option group only awaits its argument!
|
||||||
|
# Post the option group as-is as a reply so that Readline inserts a space,
|
||||||
|
# so that the next completion request switches to the argument
|
||||||
|
# An exception is made for warnings, since it's idiomatic to stick them to the
|
||||||
|
# `-W`, and it doesn't break anything.
|
||||||
|
COMPREPLY+=( "$cur_word" )
|
||||||
|
return 0
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
|
||||||
|
case "$state" in
|
||||||
|
unk) # Return with no replies: no idea what to complete!
|
||||||
|
;;
|
||||||
|
warning)
|
||||||
|
COMPREPLY+=( $(compgen -W "
|
||||||
|
assert
|
||||||
|
backwards-for
|
||||||
|
builtin-args
|
||||||
|
charmap-redef
|
||||||
|
div
|
||||||
|
empty-data-directive
|
||||||
|
empty-macro-arg
|
||||||
|
empty-strrpl
|
||||||
|
large-constant
|
||||||
|
long-string
|
||||||
|
macro-shift
|
||||||
|
nested-comment
|
||||||
|
numeric-string
|
||||||
|
obsolete
|
||||||
|
shift
|
||||||
|
shift-amount
|
||||||
|
truncation
|
||||||
|
user
|
||||||
|
all
|
||||||
|
extra
|
||||||
|
everything
|
||||||
|
error" -P "${cur_word:0:$optlen}" -- "${cur_word:$optlen}") )
|
||||||
|
;;
|
||||||
|
normal) # Acts like a glob...
|
||||||
|
state="glob-*.asm *.inc *.sm83"
|
||||||
|
;&
|
||||||
|
glob-*)
|
||||||
|
while read -r word; do
|
||||||
|
COMPREPLY+=("${cur_word:0:$optlen}$word")
|
||||||
|
done < <(for glob in ${state#glob-}; do compgen -A file -X \!"$glob" -- "${cur_word:$optlen}"; done)
|
||||||
|
# Also complete directories
|
||||||
|
;&
|
||||||
|
dir)
|
||||||
|
while read -r word; do
|
||||||
|
COMPREPLY+=("${cur_word:0:$optlen}$word")
|
||||||
|
done < <(compgen -A directory -- "${cur_word:$optlen}")
|
||||||
|
compopt -o filenames
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
}
|
||||||
|
|
||||||
|
complete -F _rgbasm_completions rgbasm
|
||||||
181
contrib/bash_compl/_rgbfix.bash
Executable file
181
contrib/bash_compl/_rgbfix.bash
Executable file
@@ -0,0 +1,181 @@
|
|||||||
|
#/usr/bin/env bash
|
||||||
|
|
||||||
|
# Same notes as RGBASM
|
||||||
|
|
||||||
|
_rgbfix_completions() {
|
||||||
|
COMPREPLY=()
|
||||||
|
|
||||||
|
# Format: "long_opt:state_after"
|
||||||
|
# Empty long opt = it doesn't exit
|
||||||
|
# See the `state` variable below for info about `state_after`
|
||||||
|
declare -A opts=(
|
||||||
|
[V]="version:normal"
|
||||||
|
[j]="non-japanese:normal"
|
||||||
|
[s]="sgb-compatible:normal"
|
||||||
|
[v]="validate:normal"
|
||||||
|
[C]="color-only:normal"
|
||||||
|
[c]="color-compatible:normal"
|
||||||
|
[f]="fix-spec:fix-spec"
|
||||||
|
[i]="game-id:unk"
|
||||||
|
[k]="new-licensee:unk"
|
||||||
|
[l]="old-licensee:unk"
|
||||||
|
[m]="mbc-type:mbc"
|
||||||
|
[n]="rom-version:unk"
|
||||||
|
[p]="pad-value:unk"
|
||||||
|
[r]="ram-size:unk"
|
||||||
|
[t]="title:unk"
|
||||||
|
)
|
||||||
|
# Parse command-line up to current word
|
||||||
|
local opt_ena=true
|
||||||
|
# Possible states:
|
||||||
|
# - normal = Well, normal. Options are parsed normally.
|
||||||
|
# - unk = An argument that can't be completed, and should just be skipped.
|
||||||
|
# - warning = A warning flag.
|
||||||
|
# - dir = A directory path
|
||||||
|
# - glob-* = A glob, after the dash is a whitespace-separated list of file globs to use
|
||||||
|
local state=normal
|
||||||
|
# The length of the option, used as a return value by the function below
|
||||||
|
local optlen=0
|
||||||
|
# $1: a short option word
|
||||||
|
# `state` will be set to the parsing state after the last option character in the word. If
|
||||||
|
# "normal" is not returned, `optlen` will be set to the length (dash included) of the "option"
|
||||||
|
# part of the argument.
|
||||||
|
parse_short_opt() {
|
||||||
|
for (( i = 1; i < "${#1}"; i++ )); do
|
||||||
|
# If the option is not known, assume it doesn't take an argument
|
||||||
|
local opt="${opts["${1:$i:1}"]:-":normal"}"
|
||||||
|
state="${opt#*:}"
|
||||||
|
# If the option takes an argument, record the length and exit
|
||||||
|
if [[ "$state" != 'normal' ]]; then
|
||||||
|
let optlen="$i + 1"
|
||||||
|
return
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
optlen=0
|
||||||
|
}
|
||||||
|
|
||||||
|
for (( i = 1; i < $COMP_CWORD; i++ )); do
|
||||||
|
local word="${COMP_WORDS[$i]}"
|
||||||
|
|
||||||
|
# If currently processing an argument, skip this word
|
||||||
|
if [[ "$state" != 'normal' ]]; then
|
||||||
|
state=normal
|
||||||
|
continue
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [[ "$word" = '--' ]]; then
|
||||||
|
# Options stop being parsed after this
|
||||||
|
opt_ena=false
|
||||||
|
break
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Check if it's a long option
|
||||||
|
if [[ "${word:0:2}" = '--' ]]; then
|
||||||
|
# If the option is unknown, assume it takes no arguments: keep the state at "normal"
|
||||||
|
for long_opt in "${opts[@]}"; do
|
||||||
|
if [[ "$word" = "--${long_opt%%:*}" ]]; then
|
||||||
|
state="${long_opt#*:}"
|
||||||
|
# Check if the next word is just '='; if so, skip it, the argument must follow
|
||||||
|
# (See "known bugs" at the top of this script)
|
||||||
|
let i++
|
||||||
|
if [[ "${COMP_WORDS[$i]}" != '=' ]]; then
|
||||||
|
let i--
|
||||||
|
fi
|
||||||
|
optlen=0
|
||||||
|
break
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
# Check if it's a short option
|
||||||
|
elif [[ "${word:0:1}" = '-' ]]; then
|
||||||
|
parse_short_opt "$word"
|
||||||
|
# The last option takes an argument...
|
||||||
|
if [[ "$state" != 'normal' ]]; then
|
||||||
|
if [[ "$optlen" -ne "${#word}" ]]; then
|
||||||
|
# If it's contained within the word, we won't complete it, revert to "normal"
|
||||||
|
state=normal
|
||||||
|
else
|
||||||
|
# Otherwise, complete it, but start at the beginning of *that* word
|
||||||
|
optlen=0
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
|
||||||
|
# Parse current word
|
||||||
|
# Careful that it might look like an option, so use `--` aggressively!
|
||||||
|
local cur_word="${COMP_WORDS[$COMP_CWORD]}"
|
||||||
|
|
||||||
|
# Process options, as short ones may change the state
|
||||||
|
if $opt_ena && [[ "$state" = 'normal' && "${cur_word:0:1}" = '-' ]]; then
|
||||||
|
# We might want to complete to an option or an arg to that option
|
||||||
|
# Parse the option word to check
|
||||||
|
# There's no whitespace in the option names, so we can ride a little dirty...
|
||||||
|
|
||||||
|
# Is this a long option?
|
||||||
|
if [[ "${cur_word:1:1}" = '-' ]]; then
|
||||||
|
# It is, try to complete one
|
||||||
|
COMPREPLY+=( $(compgen -W "${opts[*]%%:*}" -P '--' -- "${cur_word#--}") )
|
||||||
|
return 0
|
||||||
|
else
|
||||||
|
# Short options may be grouped, parse them to determine what to complete
|
||||||
|
parse_short_opt "$cur_word"
|
||||||
|
|
||||||
|
if [[ "$state" = 'normal' ]]; then
|
||||||
|
COMPREPLY+=( $(compgen -W "${!opts[*]}" -P "$cur_word" '') )
|
||||||
|
return 0
|
||||||
|
elif [[ "$optlen" = "${#cur_word}" && "$state" != "warning" ]]; then
|
||||||
|
# This short option group only awaits its argument!
|
||||||
|
# Post the option group as-is as a reply so that Readline inserts a space,
|
||||||
|
# so that the next completion request switches to the argument
|
||||||
|
# An exception is made for warnings, since it's idiomatic to stick them to the
|
||||||
|
# `-W`, and it doesn't break anything.
|
||||||
|
COMPREPLY+=( "$cur_word" )
|
||||||
|
return 0
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
|
||||||
|
case "$state" in
|
||||||
|
unk) # Return with no replies: no idea what to complete!
|
||||||
|
;;
|
||||||
|
fix-spec)
|
||||||
|
COMPREPLY+=( "${cur_word}"{l,h,g,L,H,G} )
|
||||||
|
;;
|
||||||
|
mbc)
|
||||||
|
local cur_arg="${cur_word:$optlen}"
|
||||||
|
cur_arg="${cur_arg@U}"
|
||||||
|
COMPREPLY=( $(compgen -W "
|
||||||
|
ROM_ONLY
|
||||||
|
MBC1{,+RAM,+RAM+BATTERY}
|
||||||
|
MBC2{,+BATTERY}
|
||||||
|
MMM01{,+RAM}
|
||||||
|
MBC3{+TIMER+BATTERY,+TIMER+RAM+BATTERY,,+RAM,+RAM+BATTERY}
|
||||||
|
MBC5{,+RAM,+RAM+BATTERY,+RUMBLE,+RUMBLE+RAM,+RUMBLE+RAM+BATTERY}
|
||||||
|
MBC6
|
||||||
|
MBC7+SENSOR+RUMBLE+RAM+BATTERY
|
||||||
|
POCKET_CAMERA
|
||||||
|
BANDAI_TAMA5
|
||||||
|
HUC3
|
||||||
|
HUC1+RAM+BATTERY
|
||||||
|
TPP1_1.0{,+BATTERY}{,+RTC}{,+RUMBLE,+MULTIRUMBLE}" -P "${cur_word:0:$optlen}" -- "`tr 'a-z ' 'A-Z_' <<<"${cur_word/ /_}"`") )
|
||||||
|
COMPREPLY+=( $(compgen -W "help" -P "${cur_word:0:$optlen}" -- "${cur_word:$optlen}") )
|
||||||
|
;;
|
||||||
|
normal) # Acts like a glob...
|
||||||
|
state="glob-*.gb *.gbc *.sgb"
|
||||||
|
;&
|
||||||
|
glob-*)
|
||||||
|
while read -r word; do
|
||||||
|
COMPREPLY+=("${cur_word:0:$optlen}$word")
|
||||||
|
done < <(for glob in ${state#glob-}; do compgen -A file -X \!"$glob" -- "${cur_word:$optlen}"; done)
|
||||||
|
# Also complete directories
|
||||||
|
;&
|
||||||
|
dir)
|
||||||
|
while read -r word; do
|
||||||
|
COMPREPLY+=("${cur_word:0:$optlen}$word")
|
||||||
|
done < <(compgen -A directory -- "${cur_word:$optlen}")
|
||||||
|
compopt -o filenames
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
}
|
||||||
|
|
||||||
|
complete -F _rgbfix_completions rgbfix
|
||||||
162
contrib/bash_compl/_rgbgfx.bash
Executable file
162
contrib/bash_compl/_rgbgfx.bash
Executable file
@@ -0,0 +1,162 @@
|
|||||||
|
#/usr/bin/env bash
|
||||||
|
|
||||||
|
# Same notes as RGBASM
|
||||||
|
|
||||||
|
_rgbgfx_completions() {
|
||||||
|
COMPREPLY=()
|
||||||
|
|
||||||
|
# Format: "long_opt:state_after"
|
||||||
|
# Empty long opt = it doesn't exit
|
||||||
|
# See the `state` variable below for info about `state_after`
|
||||||
|
declare -A opts=(
|
||||||
|
[V]="version:normal"
|
||||||
|
[C]="color-curve:normal"
|
||||||
|
[D]="debug:normal"
|
||||||
|
[h]="horizontal:normal"
|
||||||
|
[m]="mirror-tiles:normal"
|
||||||
|
[u]="unique-tiles:normal"
|
||||||
|
[v]="verbose:normal"
|
||||||
|
[f]="fix:normal"
|
||||||
|
[F]="fix-and-save:normal"
|
||||||
|
[a]="attr-map:*.attrmap"
|
||||||
|
[A]="output-attr-map:normal"
|
||||||
|
[d]="depth:unk"
|
||||||
|
[o]="output:glob *.2bpp"
|
||||||
|
[p]="palette:glob *.pal"
|
||||||
|
[P]="output-palette:normal"
|
||||||
|
[t]="tilemap:glob *.tilemap"
|
||||||
|
[T]="output-tilemap:normal"
|
||||||
|
[x]="trim-end:unk"
|
||||||
|
)
|
||||||
|
# Parse command-line up to current word
|
||||||
|
local opt_ena=true
|
||||||
|
# Possible states:
|
||||||
|
# - normal = Well, normal. Options are parsed normally.
|
||||||
|
# - unk = An argument that can't be completed, and should just be skipped.
|
||||||
|
# - warning = A warning flag.
|
||||||
|
# - dir = A directory path
|
||||||
|
# - glob-* = A glob, after the dash is a whitespace-separated list of file globs to use
|
||||||
|
local state=normal
|
||||||
|
# The length of the option, used as a return value by the function below
|
||||||
|
local optlen=0
|
||||||
|
# $1: a short option word
|
||||||
|
# `state` will be set to the parsing state after the last option character in the word. If
|
||||||
|
# "normal" is not returned, `optlen` will be set to the length (dash included) of the "option"
|
||||||
|
# part of the argument.
|
||||||
|
parse_short_opt() {
|
||||||
|
for (( i = 1; i < "${#1}"; i++ )); do
|
||||||
|
# If the option is not known, assume it doesn't take an argument
|
||||||
|
local opt="${opts["${1:$i:1}"]:-":normal"}"
|
||||||
|
state="${opt#*:}"
|
||||||
|
# If the option takes an argument, record the length and exit
|
||||||
|
if [[ "$state" != 'normal' ]]; then
|
||||||
|
let optlen="$i + 1"
|
||||||
|
return
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
optlen=0
|
||||||
|
}
|
||||||
|
|
||||||
|
for (( i = 1; i < $COMP_CWORD; i++ )); do
|
||||||
|
local word="${COMP_WORDS[$i]}"
|
||||||
|
|
||||||
|
# If currently processing an argument, skip this word
|
||||||
|
if [[ "$state" != 'normal' ]]; then
|
||||||
|
state=normal
|
||||||
|
continue
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [[ "$word" = '--' ]]; then
|
||||||
|
# Options stop being parsed after this
|
||||||
|
opt_ena=false
|
||||||
|
break
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Check if it's a long option
|
||||||
|
if [[ "${word:0:2}" = '--' ]]; then
|
||||||
|
# If the option is unknown, assume it takes no arguments: keep the state at "normal"
|
||||||
|
for long_opt in "${opts[@]}"; do
|
||||||
|
if [[ "$word" = "--${long_opt%%:*}" ]]; then
|
||||||
|
state="${long_opt#*:}"
|
||||||
|
# Check if the next word is just '='; if so, skip it, the argument must follow
|
||||||
|
# (See "known bugs" at the top of this script)
|
||||||
|
let i++
|
||||||
|
if [[ "${COMP_WORDS[$i]}" != '=' ]]; then
|
||||||
|
let i--
|
||||||
|
fi
|
||||||
|
optlen=0
|
||||||
|
break
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
# Check if it's a short option
|
||||||
|
elif [[ "${word:0:1}" = '-' ]]; then
|
||||||
|
parse_short_opt "$word"
|
||||||
|
# The last option takes an argument...
|
||||||
|
if [[ "$state" != 'normal' ]]; then
|
||||||
|
if [[ "$optlen" -ne "${#word}" ]]; then
|
||||||
|
# If it's contained within the word, we won't complete it, revert to "normal"
|
||||||
|
state=normal
|
||||||
|
else
|
||||||
|
# Otherwise, complete it, but start at the beginning of *that* word
|
||||||
|
optlen=0
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
|
||||||
|
# Parse current word
|
||||||
|
# Careful that it might look like an option, so use `--` aggressively!
|
||||||
|
local cur_word="${COMP_WORDS[$COMP_CWORD]}"
|
||||||
|
|
||||||
|
# Process options, as short ones may change the state
|
||||||
|
if $opt_ena && [[ "$state" = 'normal' && "${cur_word:0:1}" = '-' ]]; then
|
||||||
|
# We might want to complete to an option or an arg to that option
|
||||||
|
# Parse the option word to check
|
||||||
|
# There's no whitespace in the option names, so we can ride a little dirty...
|
||||||
|
|
||||||
|
# Is this a long option?
|
||||||
|
if [[ "${cur_word:1:1}" = '-' ]]; then
|
||||||
|
# It is, try to complete one
|
||||||
|
COMPREPLY+=( $(compgen -W "${opts[*]%%:*}" -P '--' -- "${cur_word#--}") )
|
||||||
|
return 0
|
||||||
|
else
|
||||||
|
# Short options may be grouped, parse them to determine what to complete
|
||||||
|
parse_short_opt "$cur_word"
|
||||||
|
|
||||||
|
if [[ "$state" = 'normal' ]]; then
|
||||||
|
COMPREPLY+=( $(compgen -W "${!opts[*]}" -P "$cur_word" '') )
|
||||||
|
return 0
|
||||||
|
elif [[ "$optlen" = "${#cur_word}" && "$state" != "warning" ]]; then
|
||||||
|
# This short option group only awaits its argument!
|
||||||
|
# Post the option group as-is as a reply so that Readline inserts a space,
|
||||||
|
# so that the next completion request switches to the argument
|
||||||
|
# An exception is made for warnings, since it's idiomatic to stick them to the
|
||||||
|
# `-W`, and it doesn't break anything.
|
||||||
|
COMPREPLY+=( "$cur_word" )
|
||||||
|
return 0
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
|
||||||
|
case "$state" in
|
||||||
|
unk) # Return with no replies: no idea what to complete!
|
||||||
|
;;
|
||||||
|
normal) # Acts like a glob...
|
||||||
|
state="glob-*.png"
|
||||||
|
;&
|
||||||
|
glob-*)
|
||||||
|
while read -r word; do
|
||||||
|
COMPREPLY+=("${cur_word:0:$optlen}$word")
|
||||||
|
done < <(for glob in ${state#glob-}; do compgen -A file -X \!"$glob" -- "${cur_word:$optlen}"; done)
|
||||||
|
# Also complete directories
|
||||||
|
;&
|
||||||
|
dir)
|
||||||
|
while read -r word; do
|
||||||
|
COMPREPLY+=("${cur_word:0:$optlen}$word")
|
||||||
|
done < <(compgen -A directory -- "${cur_word:$optlen}")
|
||||||
|
compopt -o filenames
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
}
|
||||||
|
|
||||||
|
complete -F _rgbgfx_completions rgbgfx
|
||||||
157
contrib/bash_compl/_rgblink.bash
Executable file
157
contrib/bash_compl/_rgblink.bash
Executable file
@@ -0,0 +1,157 @@
|
|||||||
|
#/usr/bin/env bash
|
||||||
|
|
||||||
|
# Same notes as RGBASM
|
||||||
|
|
||||||
|
_rgblink_completions() {
|
||||||
|
COMPREPLY=()
|
||||||
|
|
||||||
|
# Format: "long_opt:state_after"
|
||||||
|
# Empty long opt = it doesn't exit
|
||||||
|
# See the `state` variable below for info about `state_after`
|
||||||
|
declare -A opts=(
|
||||||
|
[V]="version:normal"
|
||||||
|
[d]="dmg:normal"
|
||||||
|
[t]="tiny:normal"
|
||||||
|
[v]="verbose:normal"
|
||||||
|
[w]="wramx:normal"
|
||||||
|
[x]="nopad:normal"
|
||||||
|
[l]="linkerscript:glob-*"
|
||||||
|
[m]="map:glob-*.map"
|
||||||
|
[n]="sym:glob-*.sym"
|
||||||
|
[O]="overlay:glob-*.gb *.gbc *.sgb"
|
||||||
|
[o]="output:glob-*.gb *.gbc *.sgb"
|
||||||
|
[p]="pad:unk"
|
||||||
|
[s]="smart:unk"
|
||||||
|
)
|
||||||
|
# Parse command-line up to current word
|
||||||
|
local opt_ena=true
|
||||||
|
# Possible states:
|
||||||
|
# - normal = Well, normal. Options are parsed normally.
|
||||||
|
# - unk = An argument that can't be completed, and should just be skipped.
|
||||||
|
# - warning = A warning flag.
|
||||||
|
# - dir = A directory path
|
||||||
|
# - glob-* = A glob, after the dash is a whitespace-separated list of file globs to use
|
||||||
|
local state=normal
|
||||||
|
# The length of the option, used as a return value by the function below
|
||||||
|
local optlen=0
|
||||||
|
# $1: a short option word
|
||||||
|
# `state` will be set to the parsing state after the last option character in the word. If
|
||||||
|
# "normal" is not returned, `optlen` will be set to the length (dash included) of the "option"
|
||||||
|
# part of the argument.
|
||||||
|
parse_short_opt() {
|
||||||
|
for (( i = 1; i < "${#1}"; i++ )); do
|
||||||
|
# If the option is not known, assume it doesn't take an argument
|
||||||
|
local opt="${opts["${1:$i:1}"]:-":normal"}"
|
||||||
|
state="${opt#*:}"
|
||||||
|
# If the option takes an argument, record the length and exit
|
||||||
|
if [[ "$state" != 'normal' ]]; then
|
||||||
|
let optlen="$i + 1"
|
||||||
|
return
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
optlen=0
|
||||||
|
}
|
||||||
|
|
||||||
|
for (( i = 1; i < $COMP_CWORD; i++ )); do
|
||||||
|
local word="${COMP_WORDS[$i]}"
|
||||||
|
|
||||||
|
# If currently processing an argument, skip this word
|
||||||
|
if [[ "$state" != 'normal' ]]; then
|
||||||
|
state=normal
|
||||||
|
continue
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [[ "$word" = '--' ]]; then
|
||||||
|
# Options stop being parsed after this
|
||||||
|
opt_ena=false
|
||||||
|
break
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Check if it's a long option
|
||||||
|
if [[ "${word:0:2}" = '--' ]]; then
|
||||||
|
# If the option is unknown, assume it takes no arguments: keep the state at "normal"
|
||||||
|
for long_opt in "${opts[@]}"; do
|
||||||
|
if [[ "$word" = "--${long_opt%%:*}" ]]; then
|
||||||
|
state="${long_opt#*:}"
|
||||||
|
# Check if the next word is just '='; if so, skip it, the argument must follow
|
||||||
|
# (See "known bugs" at the top of this script)
|
||||||
|
let i++
|
||||||
|
if [[ "${COMP_WORDS[$i]}" != '=' ]]; then
|
||||||
|
let i--
|
||||||
|
fi
|
||||||
|
optlen=0
|
||||||
|
break
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
# Check if it's a short option
|
||||||
|
elif [[ "${word:0:1}" = '-' ]]; then
|
||||||
|
parse_short_opt "$word"
|
||||||
|
# The last option takes an argument...
|
||||||
|
if [[ "$state" != 'normal' ]]; then
|
||||||
|
if [[ "$optlen" -ne "${#word}" ]]; then
|
||||||
|
# If it's contained within the word, we won't complete it, revert to "normal"
|
||||||
|
state=normal
|
||||||
|
else
|
||||||
|
# Otherwise, complete it, but start at the beginning of *that* word
|
||||||
|
optlen=0
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
|
||||||
|
# Parse current word
|
||||||
|
# Careful that it might look like an option, so use `--` aggressively!
|
||||||
|
local cur_word="${COMP_WORDS[$COMP_CWORD]}"
|
||||||
|
|
||||||
|
# Process options, as short ones may change the state
|
||||||
|
if $opt_ena && [[ "$state" = 'normal' && "${cur_word:0:1}" = '-' ]]; then
|
||||||
|
# We might want to complete to an option or an arg to that option
|
||||||
|
# Parse the option word to check
|
||||||
|
# There's no whitespace in the option names, so we can ride a little dirty...
|
||||||
|
|
||||||
|
# Is this a long option?
|
||||||
|
if [[ "${cur_word:1:1}" = '-' ]]; then
|
||||||
|
# It is, try to complete one
|
||||||
|
COMPREPLY+=( $(compgen -W "${opts[*]%%:*}" -P '--' -- "${cur_word#--}") )
|
||||||
|
return 0
|
||||||
|
else
|
||||||
|
# Short options may be grouped, parse them to determine what to complete
|
||||||
|
parse_short_opt "$cur_word"
|
||||||
|
|
||||||
|
if [[ "$state" = 'normal' ]]; then
|
||||||
|
COMPREPLY+=( $(compgen -W "${!opts[*]}" -P "$cur_word" '') )
|
||||||
|
return 0
|
||||||
|
elif [[ "$optlen" = "${#cur_word}" && "$state" != "warning" ]]; then
|
||||||
|
# This short option group only awaits its argument!
|
||||||
|
# Post the option group as-is as a reply so that Readline inserts a space,
|
||||||
|
# so that the next completion request switches to the argument
|
||||||
|
# An exception is made for warnings, since it's idiomatic to stick them to the
|
||||||
|
# `-W`, and it doesn't break anything.
|
||||||
|
COMPREPLY+=( "$cur_word" )
|
||||||
|
return 0
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
|
||||||
|
case "$state" in
|
||||||
|
unk) # Return with no replies: no idea what to complete!
|
||||||
|
;;
|
||||||
|
normal) # Acts like a glob...
|
||||||
|
state="glob-*.o *.obj"
|
||||||
|
;&
|
||||||
|
glob-*)
|
||||||
|
while read -r word; do
|
||||||
|
COMPREPLY+=("${cur_word:0:$optlen}$word")
|
||||||
|
done < <(for glob in ${state#glob-}; do compgen -A file -X \!"$glob" -- "${cur_word:$optlen}"; done)
|
||||||
|
# Also complete directories
|
||||||
|
;&
|
||||||
|
dir)
|
||||||
|
while read -r word; do
|
||||||
|
COMPREPLY+=("${cur_word:0:$optlen}$word")
|
||||||
|
done < <(compgen -A directory -- "${cur_word:$optlen}")
|
||||||
|
compopt -o filenames
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
}
|
||||||
|
|
||||||
|
complete -F _rgblink_completions rgblink
|
||||||
85
contrib/checkdiff.bash
Executable file
85
contrib/checkdiff.bash
Executable file
@@ -0,0 +1,85 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
# SPDX-License-Identifier: MIT
|
||||||
|
#
|
||||||
|
# Copyright (c) 2021 Rangi
|
||||||
|
#
|
||||||
|
# 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.
|
||||||
|
|
||||||
|
declare -A FILES
|
||||||
|
while read -r -d '' file; do
|
||||||
|
FILES["$file"]="true"
|
||||||
|
done < <(git diff --name-only -z $1 HEAD)
|
||||||
|
|
||||||
|
edited () {
|
||||||
|
${FILES["$1"]:-"false"}
|
||||||
|
}
|
||||||
|
|
||||||
|
dependency () {
|
||||||
|
if edited "$1" && ! edited "$2"; then
|
||||||
|
echo "'$1' was modified, but not '$2'! $3" | xargs
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
# Pull requests that edit the first file without the second may be correct,
|
||||||
|
# but are suspicious enough to require review.
|
||||||
|
|
||||||
|
dependency include/linkdefs.h src/rgbds.5 \
|
||||||
|
"Was the object file format changed?"
|
||||||
|
|
||||||
|
dependency src/asm/parser.y src/asm/rgbasm.5 \
|
||||||
|
"Was the rgbasm grammar changed?"
|
||||||
|
|
||||||
|
dependency include/asm/warning.h src/asm/rgbasm.1 \
|
||||||
|
"Were the rgbasm warnings changed?"
|
||||||
|
|
||||||
|
dependency src/asm/object.c include/linkdefs.h \
|
||||||
|
"Should the object file revision be bumped?"
|
||||||
|
dependency src/link/object.c include/linkdefs.h \
|
||||||
|
"Should the object file revision be bumped?"
|
||||||
|
|
||||||
|
dependency Makefile CMakeLists.txt \
|
||||||
|
"Did the build process change?"
|
||||||
|
dependency Makefile src/CMakeLists.txt \
|
||||||
|
"Did the build process change?"
|
||||||
|
|
||||||
|
dependency src/asm/main.c src/asm/rgbasm.1 \
|
||||||
|
"Did the rgbasm CLI change?"
|
||||||
|
dependency src/asm/main.c contrib/zsh_compl/_rgbasm \
|
||||||
|
"Did the rgbasm CLI change?"
|
||||||
|
dependency src/asm/main.c contrib/bash_compl/_rgbasm.bash \
|
||||||
|
"Did the rgbasm CLI change?"
|
||||||
|
dependency src/link/main.c src/link/rgblink.1 \
|
||||||
|
"Did the rgblink CLI change?"
|
||||||
|
dependency src/link/main.c contrib/zsh_compl/_rgblink \
|
||||||
|
"Did the rgblink CLI change?"
|
||||||
|
dependency src/link/main.c contrib/bash_compl/_rgblink.bash \
|
||||||
|
"Did the rgblink CLI change?"
|
||||||
|
dependency src/fix/main.c src/fix/rgbfix.1 \
|
||||||
|
"Did the rgbfix CLI change?"
|
||||||
|
dependency src/fix/main.c contrib/zsh_compl/_rgbfix \
|
||||||
|
"Did the rgbfix CLI change?"
|
||||||
|
dependency src/fix/main.c contrib/bash_compl/_rgbfix.bash \
|
||||||
|
"Did the rgbfix CLI change?"
|
||||||
|
dependency src/gfx/main.c src/gfx/rgbgfx.1 \
|
||||||
|
"Did the rgbgfx CLI change?"
|
||||||
|
dependency src/gfx/main.c contrib/zsh_compl/_rgbgfx \
|
||||||
|
"Did the rgbgfx CLI change?"
|
||||||
|
dependency src/gfx/main.c contrib/bash_compl/_rgbgfx.bash \
|
||||||
|
"Did the rgbgfx CLI change?"
|
||||||
@@ -9,18 +9,26 @@ _rgbasm_warnings() {
|
|||||||
'everything:Enable literally everything'
|
'everything:Enable literally everything'
|
||||||
|
|
||||||
'assert:Warn when WARN-type asserts fail'
|
'assert:Warn when WARN-type asserts fail'
|
||||||
|
'backwards-for:Warn when start and stop are backwards relative to step'
|
||||||
'builtin-args:Report incorrect args to built-in funcs'
|
'builtin-args:Report incorrect args to built-in funcs'
|
||||||
|
'charmap-redef:Warn when redefining a charmap mapping'
|
||||||
'div:Warn when dividing the smallest int by -1'
|
'div:Warn when dividing the smallest int by -1'
|
||||||
'empty-entry:Warn on empty entries in db, dw, dl args'
|
'empty-data-directive:Warn on arg-less d[bwl] in ROM'
|
||||||
|
'empty-macro-arg:Warn on empty macro arg'
|
||||||
|
'empty-strrpl:Warn on calling STRRPL with empty pattern'
|
||||||
'large-constant:Warn on constants too large for a signed 32-bit int'
|
'large-constant:Warn on constants too large for a signed 32-bit int'
|
||||||
'long-string:Warn on strings too long'
|
'long-string:Warn on strings too long'
|
||||||
|
'macro-shift:Warn when shifting macro args part their limits'
|
||||||
|
'nested-comment:Warn on "/*" inside block comments'
|
||||||
|
'numeric-string:Warn when a multi-character string is treated as a number'
|
||||||
'obsolete:Warn when using deprecated features'
|
'obsolete:Warn when using deprecated features'
|
||||||
'shift:Warn when shifting negative values'
|
'shift:Warn when shifting negative values'
|
||||||
'shift-amount:Warn when a shift'\''s operand it negative or \> 32'
|
'shift-amount:Warn when a shift'\''s operand it negative or \> 32'
|
||||||
'truncation:Warn when implicit truncations lose bits'
|
'truncation:Warn when implicit truncation loses bits'
|
||||||
'user:Warn when executing the WARN built-in'
|
'user:Warn when executing the WARN built-in'
|
||||||
)
|
)
|
||||||
# TODO: handle `no-` and `error=` somehow?
|
# TODO: handle `no-` and `error=` somehow?
|
||||||
|
# TODO: handle `=0|1|2` levels for `numeric-string` and `truncation`?
|
||||||
_describe warning warnings
|
_describe warning warnings
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -35,15 +43,19 @@ local args=(
|
|||||||
-w'[Disable all warnings]'
|
-w'[Disable all warnings]'
|
||||||
|
|
||||||
'(-b --binary-digits)'{-b,--binary-digits}'+[Change chars for binary constants]:digit spec:'
|
'(-b --binary-digits)'{-b,--binary-digits}'+[Change chars for binary constants]:digit spec:'
|
||||||
'(-D --define)'{-D,--define}'+[Define a string symbol]:name + value (default 1):'
|
'*'{-D,--define}'+[Define a string symbol]:name + value (default 1):'
|
||||||
'(-g --gfx-chars)'{-g,--gfx-chars}'+[Change chars for gfx constants]:chars spec:'
|
'(-g --gfx-chars)'{-g,--gfx-chars}'+[Change chars for gfx constants]:chars spec:'
|
||||||
'(-i --include)'{-i,--include}'+[Add an include directory]:include path:_files -/'
|
'(-i --include)'{-i,--include}'+[Add an include directory]:include path:_files -/'
|
||||||
'(-M --dependfile)'{-M,--dependfile}"+[List deps in make format]:output file:_files -g '*.{d,mk}"
|
'(-M --dependfile)'{-M,--dependfile}"+[List deps in make format]:output file:_files -g '*.{d,mk}'"
|
||||||
|
-MG'[Assume missing files should be generated]'
|
||||||
|
-MP'[Add phony targets to all deps]'
|
||||||
|
'*'-MT"+[Add a target to the rules]:target:_files -g '*.{d,mk,o}'"
|
||||||
|
'*'-MQ"+[Add a target to the rules]:target:_files -g '*.{d,mk,o}'"
|
||||||
'(-o --output)'{-o,--output}'+[Output file]:output file:_files'
|
'(-o --output)'{-o,--output}'+[Output file]:output file:_files'
|
||||||
'(-p --pad-value)'{-p,--pad-value}'+[Set padding byte]:padding byte:'
|
'(-p --pad-value)'{-p,--pad-value}'+[Set padding byte]:padding byte:'
|
||||||
'(-r --recursion-depth)'{-r,--recursion-depth}'+[Set maximum recursion depth]:depth:'
|
'(-r --recursion-depth)'{-r,--recursion-depth}'+[Set maximum recursion depth]:depth:'
|
||||||
'(-W --warning)'{-W,--warning}'+[Toggle warning flags]:warning flag:_rgbasm_warnings'
|
'(-W --warning)'{-W,--warning}'+[Toggle warning flags]:warning flag:_rgbasm_warnings'
|
||||||
|
|
||||||
'*'":assembly sources:_files -g '*.asm'"
|
":assembly sources:_files -g '*.asm'"
|
||||||
)
|
)
|
||||||
_arguments -s -S : $args
|
_arguments -s -S : $args
|
||||||
|
|||||||
@@ -1,12 +1,47 @@
|
|||||||
#compdef rgbfix
|
#compdef rgbfix
|
||||||
|
|
||||||
|
_mbc_names() {
|
||||||
|
local mbc_names=(
|
||||||
|
'ROM:$00'
|
||||||
|
'MBC1:$01'
|
||||||
|
'MBC1+RAM:$02'
|
||||||
|
'MBC1+RAM+BATTERY:$03'
|
||||||
|
'MBC2:$05'
|
||||||
|
'MBC2+BATTERY:$06'
|
||||||
|
'ROM+RAM:$08'
|
||||||
|
'ROM+RAM+BATTERY:$09'
|
||||||
|
'MMM01:$0B'
|
||||||
|
'MMM01+RAM:$0C'
|
||||||
|
'MMM01+RAM+BATTERY:$0D'
|
||||||
|
'MBC3+TIMER+BATTERY:$0F'
|
||||||
|
'MBC3+TIMER+RAM+BATTERY:$10'
|
||||||
|
'MBC3:$11'
|
||||||
|
'MBC3+RAM:$12'
|
||||||
|
'MBC3+RAM+BATTERY:$13'
|
||||||
|
'MBC5:$19'
|
||||||
|
'MBC5+RAM:$1A'
|
||||||
|
'MBC5+RAM+BATTERY:$1B'
|
||||||
|
'MBC5+RUMBLE:$1C'
|
||||||
|
'MBC5+RUMBLE+RAM:$1D'
|
||||||
|
'MBC5+RUMBLE+RAM+BATTERY:$1E'
|
||||||
|
'MBC6:$20'
|
||||||
|
'MBC7+SENSOR+RUMBLE+RAM+BATTERY:$22'
|
||||||
|
'POCKET_CAMERA:$FC'
|
||||||
|
'BANDAI_TAMA5:$FD'
|
||||||
|
'HUC3:$FE'
|
||||||
|
'HUC1+RAM+BATTERY:$FF'
|
||||||
|
)
|
||||||
|
_describe "MBC name" mbc_names
|
||||||
|
}
|
||||||
|
|
||||||
local args=(
|
local args=(
|
||||||
# Arguments are listed here in the same order as in the manual, except for the version
|
# Arguments are listed here in the same order as in the manual, except for the version
|
||||||
'(- : * options)'{-V,--version}'[Print version number]'
|
'(- : * options)'{-V,--version}'[Print version number]'
|
||||||
|
|
||||||
'(-C --color-only)'{-C,--color-only}'[Mark ROM as GBC-only]'
|
'(-C --color-only -c --color-compatible)'{-C,--color-only}'[Mark ROM as GBC-only]'
|
||||||
'(-c --color-compatible)'{-c,--color-compatible}'[Mark ROM as GBC-compatible]'
|
'(-C --color-only -c --color-compatible)'{-c,--color-compatible}'[Mark ROM as GBC-compatible]'
|
||||||
'(-j --non-japanese)'{-j,--non-japanese}'[Set the non-Japanese region flag]'
|
'(-j --non-japanese)'{-j,--non-japanese}'[Set the non-Japanese region flag]'
|
||||||
|
'(-O --overwrite)'{-O,--overwrite}'[Allow overwriting non-zero bytes]'
|
||||||
'(-s --sgb-compatible)'{-s,--sgb-compatible}'[Set the SGB flag]'
|
'(-s --sgb-compatible)'{-s,--sgb-compatible}'[Set the SGB flag]'
|
||||||
'(-f --fix-spec -v --validate)'{-v,--validate}'[Shorthand for -f lhg]'
|
'(-f --fix-spec -v --validate)'{-v,--validate}'[Shorthand for -f lhg]'
|
||||||
|
|
||||||
@@ -14,7 +49,7 @@ local args=(
|
|||||||
'(-i --game-id)'{-i,--game-id}'+[Set game ID string]:4-char game ID:'
|
'(-i --game-id)'{-i,--game-id}'+[Set game ID string]:4-char game ID:'
|
||||||
'(-k --new-licensee)'{-k,--new-licensee}'+[Set new licensee string]:2-char licensee ID:'
|
'(-k --new-licensee)'{-k,--new-licensee}'+[Set new licensee string]:2-char licensee ID:'
|
||||||
'(-l --old-licensee)'{-l,--old-licensee}'+[Set old licensee ID]:licensee number:'
|
'(-l --old-licensee)'{-l,--old-licensee}'+[Set old licensee ID]:licensee number:'
|
||||||
'(-m --mbc-type)'{-m,--mbc-type}'+[Set MBC flags]:mbc flags byte:'
|
'(-m --mbc-type)'{-m,--mbc-type}"+[Set MBC flags]:mbc name:_mbc_names"
|
||||||
'(-n --rom-version)'{-n,--rom-version}'+[Set ROM version]:rom version byte:'
|
'(-n --rom-version)'{-n,--rom-version}'+[Set ROM version]:rom version byte:'
|
||||||
'(-p --pad-value)'{-p,--pad-value}'+[Pad to next valid size using this byte as padding]:padding byte:'
|
'(-p --pad-value)'{-p,--pad-value}'+[Pad to next valid size using this byte as padding]:padding byte:'
|
||||||
'(-r --ram-size)'{-r,--ram-size}'+[Set RAM size]:ram size byte:'
|
'(-r --ram-size)'{-r,--ram-size}'+[Set RAM size]:ram size byte:'
|
||||||
|
|||||||
@@ -32,6 +32,6 @@ local args=(
|
|||||||
'(-t --tilemap -T --output-tilemap)'{-t,--tilemap}'+[Generate a map of tile indices]:tilemap file:_files'
|
'(-t --tilemap -T --output-tilemap)'{-t,--tilemap}'+[Generate a map of tile indices]:tilemap file:_files'
|
||||||
'(-x --trim-end)'{-x,--trim-end}'+[Trim end of output by this many tiles]:tile count:'
|
'(-x --trim-end)'{-x,--trim-end}'+[Trim end of output by this many tiles]:tile count:'
|
||||||
|
|
||||||
'*'":input png files:_files -g '*.png'"
|
":input png file:_files -g '*.png'"
|
||||||
)
|
)
|
||||||
_arguments -s -S : $args
|
_arguments -s -S : $args
|
||||||
|
|||||||
@@ -8,6 +8,7 @@ local args=(
|
|||||||
'(-t --tiny)'{-t,--tiny}'[Enable tiny mode, disabling ROM banking]'
|
'(-t --tiny)'{-t,--tiny}'[Enable tiny mode, disabling ROM banking]'
|
||||||
'(-v --verbose)'{-v,--verbose}'[Enable verbose output]'
|
'(-v --verbose)'{-v,--verbose}'[Enable verbose output]'
|
||||||
'(-w --wramx)'{-w,--wramx}'[Disable WRAM banking]'
|
'(-w --wramx)'{-w,--wramx}'[Disable WRAM banking]'
|
||||||
|
'(-x --nopad)'{-x,--nopad}'[Disable padding the end of the final file]'
|
||||||
|
|
||||||
'(-l --linkerscript)'{-l,--linkerscript}"+[Use a linker script]:linker script:_files -g '*.link'"
|
'(-l --linkerscript)'{-l,--linkerscript}"+[Use a linker script]:linker script:_files -g '*.link'"
|
||||||
'(-m --map)'{-m,--map}"+[Produce a map file]:map file:_files -g '*.map'"
|
'(-m --map)'{-m,--map}"+[Produce a map file]:map file:_files -g '*.map'"
|
||||||
@@ -15,6 +16,7 @@ local args=(
|
|||||||
'(-O --overlay)'{-O,--overlay}'+[Overlay sections over on top of bin file]:base overlay:_files'
|
'(-O --overlay)'{-O,--overlay}'+[Overlay sections over on top of bin file]:base overlay:_files'
|
||||||
'(-o --output)'{-o,--output}"+[Write ROM image to this file]:rom file:_files -g '*.{gb,sgb,gbc}'"
|
'(-o --output)'{-o,--output}"+[Write ROM image to this file]:rom file:_files -g '*.{gb,sgb,gbc}'"
|
||||||
'(-p --pad-value)'{-p,--pad-value}'+[Set padding byte]:padding byte:'
|
'(-p --pad-value)'{-p,--pad-value}'+[Set padding byte]:padding byte:'
|
||||||
|
'(-S --scramble)'{-s,--scramble}'+[Activate scrambling]:scramble spec'
|
||||||
'(-s --smart)'{-s,--smart}'+[!BROKEN! Perform smart linking from this symbol]:symbol name:'
|
'(-s --smart)'{-s,--smart}'+[!BROKEN! Perform smart linking from this symbol]:symbol name:'
|
||||||
|
|
||||||
'*'":object files:_files -g '*.o'"
|
'*'":object files:_files -g '*.o'"
|
||||||
|
|||||||
@@ -11,12 +11,13 @@
|
|||||||
|
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
|
|
||||||
struct Charmap *charmap_New(const char *name, const char *baseName);
|
struct Charmap *charmap_New(char const *name, char const *baseName);
|
||||||
void charmap_Delete(struct Charmap *charmap);
|
void charmap_Delete(struct Charmap *charmap);
|
||||||
void charmap_Set(const char *name);
|
void charmap_Set(char const *name);
|
||||||
void charmap_Push(void);
|
void charmap_Push(void);
|
||||||
void charmap_Pop(void);
|
void charmap_Pop(void);
|
||||||
void charmap_Add(char *mapping, uint8_t value);
|
void charmap_Add(char *mapping, uint8_t value);
|
||||||
size_t charmap_Convert(char const *input, uint8_t *output);
|
size_t charmap_Convert(char const *input, uint8_t *output);
|
||||||
|
size_t charmap_ConvertNext(char const **input, uint8_t **output);
|
||||||
|
|
||||||
#endif /* RGBDS_ASM_CHARMAP_H */
|
#endif /* RGBDS_ASM_CHARMAP_H */
|
||||||
|
|||||||
@@ -9,8 +9,8 @@
|
|||||||
#ifndef RGBDS_FORMAT_SPEC_H
|
#ifndef RGBDS_FORMAT_SPEC_H
|
||||||
#define RGBDS_FORMAT_SPEC_H
|
#define RGBDS_FORMAT_SPEC_H
|
||||||
|
|
||||||
#include <stdint.h>
|
|
||||||
#include <stdbool.h>
|
#include <stdbool.h>
|
||||||
|
#include <stdint.h>
|
||||||
|
|
||||||
enum FormatState {
|
enum FormatState {
|
||||||
FORMAT_SIGN, // expects '+' or ' ' (optional)
|
FORMAT_SIGN, // expects '+' or ' ' (optional)
|
||||||
|
|||||||
@@ -19,7 +19,6 @@
|
|||||||
|
|
||||||
#include "asm/lexer.h"
|
#include "asm/lexer.h"
|
||||||
|
|
||||||
#include "types.h"
|
|
||||||
|
|
||||||
struct FileStackNode {
|
struct FileStackNode {
|
||||||
struct FileStackNode *parent; /* Pointer to parent node, for error reporting */
|
struct FileStackNode *parent; /* Pointer to parent node, for error reporting */
|
||||||
@@ -49,7 +48,7 @@ struct FileStackNamedNode { /* NODE_FILE, NODE_MACRO */
|
|||||||
char name[]; /* File name for files, file::macro name for macros */
|
char name[]; /* File name for files, file::macro name for macros */
|
||||||
};
|
};
|
||||||
|
|
||||||
extern size_t nMaxRecursionDepth;
|
extern size_t maxRecursionDepth;
|
||||||
|
|
||||||
struct MacroArgs;
|
struct MacroArgs;
|
||||||
|
|
||||||
@@ -72,12 +71,13 @@ bool fstk_FindFile(char const *path, char **fullPath, size_t *size);
|
|||||||
bool yywrap(void);
|
bool yywrap(void);
|
||||||
void fstk_RunInclude(char const *path);
|
void fstk_RunInclude(char const *path);
|
||||||
void fstk_RunMacro(char const *macroName, struct MacroArgs *args);
|
void fstk_RunMacro(char const *macroName, struct MacroArgs *args);
|
||||||
void fstk_RunRept(uint32_t count, int32_t nReptLineNo, char *body, size_t size);
|
void fstk_RunRept(uint32_t count, int32_t reptLineNo, char *body, size_t size);
|
||||||
void fstk_RunFor(char const *symName, int32_t start, int32_t stop, int32_t step,
|
void fstk_RunFor(char const *symName, int32_t start, int32_t stop, int32_t step,
|
||||||
int32_t reptLineNo, char *body, size_t size);
|
int32_t reptLineNo, char *body, size_t size);
|
||||||
void fstk_StopRept(void);
|
void fstk_StopRept(void);
|
||||||
bool fstk_Break(void);
|
bool fstk_Break(void);
|
||||||
|
|
||||||
void fstk_Init(char const *mainPath, size_t maxRecursionDepth);
|
void fstk_NewRecursionDepth(size_t newDepth);
|
||||||
|
void fstk_Init(char const *mainPath, size_t maxDepth);
|
||||||
|
|
||||||
#endif /* RGBDS_ASM_FSTACK_H */
|
#endif /* RGBDS_ASM_FSTACK_H */
|
||||||
|
|||||||
@@ -53,7 +53,7 @@ static inline void lexer_SetGfxDigits(char const digits[4])
|
|||||||
* `path` is referenced, but not held onto..!
|
* `path` is referenced, but not held onto..!
|
||||||
*/
|
*/
|
||||||
struct LexerState *lexer_OpenFile(char const *path);
|
struct LexerState *lexer_OpenFile(char const *path);
|
||||||
struct LexerState *lexer_OpenFileView(char *buf, size_t size, uint32_t lineNo);
|
struct LexerState *lexer_OpenFileView(char const *path, char *buf, size_t size, uint32_t lineNo);
|
||||||
void lexer_RestartRept(uint32_t lineNo);
|
void lexer_RestartRept(uint32_t lineNo);
|
||||||
void lexer_DeleteState(struct LexerState *state);
|
void lexer_DeleteState(struct LexerState *state);
|
||||||
void lexer_Init(void);
|
void lexer_Init(void);
|
||||||
@@ -83,13 +83,14 @@ struct CaptureBody {
|
|||||||
size_t size;
|
size_t size;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
void lexer_CheckRecursionDepth(void);
|
||||||
char const *lexer_GetFileName(void);
|
char const *lexer_GetFileName(void);
|
||||||
uint32_t lexer_GetLineNo(void);
|
uint32_t lexer_GetLineNo(void);
|
||||||
uint32_t lexer_GetColNo(void);
|
uint32_t lexer_GetColNo(void);
|
||||||
void lexer_DumpStringExpansions(void);
|
void lexer_DumpStringExpansions(void);
|
||||||
int yylex(void);
|
int yylex(void);
|
||||||
void lexer_CaptureRept(struct CaptureBody *capture);
|
bool lexer_CaptureRept(struct CaptureBody *capture);
|
||||||
void lexer_CaptureMacroBody(struct CaptureBody *capture);
|
bool lexer_CaptureMacroBody(struct CaptureBody *capture);
|
||||||
|
|
||||||
#define INITIAL_DS_ARG_SIZE 2
|
#define INITIAL_DS_ARG_SIZE 2
|
||||||
struct DsArgList {
|
struct DsArgList {
|
||||||
|
|||||||
@@ -25,7 +25,7 @@ void macro_AppendArg(struct MacroArgs **args, char *s);
|
|||||||
void macro_UseNewArgs(struct MacroArgs *args);
|
void macro_UseNewArgs(struct MacroArgs *args);
|
||||||
void macro_FreeArgs(struct MacroArgs *args);
|
void macro_FreeArgs(struct MacroArgs *args);
|
||||||
char const *macro_GetArg(uint32_t i);
|
char const *macro_GetArg(uint32_t i);
|
||||||
char *macro_GetAllArgs(void);
|
char const *macro_GetAllArgs(void);
|
||||||
|
|
||||||
uint32_t macro_GetUniqueID(void);
|
uint32_t macro_GetUniqueID(void);
|
||||||
char const *macro_GetUniqueIDStr(void);
|
char const *macro_GetUniqueIDStr(void);
|
||||||
|
|||||||
@@ -16,22 +16,14 @@
|
|||||||
#include "helpers.h"
|
#include "helpers.h"
|
||||||
|
|
||||||
extern bool haltnop;
|
extern bool haltnop;
|
||||||
extern bool optimizeloads;
|
extern bool optimizeLoads;
|
||||||
extern bool verbose;
|
extern bool verbose;
|
||||||
extern bool warnings; /* True to enable warnings, false to disable them. */
|
extern bool warnings; /* True to enable warnings, false to disable them. */
|
||||||
|
|
||||||
extern FILE *dependfile;
|
extern FILE *dependfile;
|
||||||
extern char *tzTargetFileName;
|
extern char *targetFileName;
|
||||||
extern bool oGeneratedMissingIncludes;
|
extern bool generatedMissingIncludes;
|
||||||
extern bool oFailedOnMissingInclude;
|
extern bool failedOnMissingInclude;
|
||||||
extern bool oGeneratePhonyDeps;
|
extern bool generatePhonyDeps;
|
||||||
|
|
||||||
/* TODO: are these really needed? */
|
|
||||||
#define YY_FATAL_ERROR fatalerror
|
|
||||||
|
|
||||||
#ifdef YYLMAX
|
|
||||||
#undef YYLMAX
|
|
||||||
#endif
|
|
||||||
#define YYLMAX 65536
|
|
||||||
|
|
||||||
#endif /* RGBDS_MAIN_H */
|
#endif /* RGBDS_MAIN_H */
|
||||||
|
|||||||
@@ -9,14 +9,17 @@
|
|||||||
#ifndef RGBDS_OPT_H
|
#ifndef RGBDS_OPT_H
|
||||||
#define RGBDS_OPT_H
|
#define RGBDS_OPT_H
|
||||||
|
|
||||||
|
#include <stdbool.h>
|
||||||
|
#include <stdint.h>
|
||||||
|
|
||||||
void opt_B(char chars[2]);
|
void opt_B(char const chars[2]);
|
||||||
void opt_G(char chars[4]);
|
void opt_G(char const chars[4]);
|
||||||
void opt_P(uint8_t fill);
|
void opt_P(uint8_t fill);
|
||||||
|
void opt_L(bool optimize);
|
||||||
|
void opt_W(char const *flag);
|
||||||
void opt_Parse(char const *option);
|
void opt_Parse(char const *option);
|
||||||
|
|
||||||
void opt_Push(void);
|
void opt_Push(void);
|
||||||
void opt_Pop(void);
|
void opt_Pop(void);
|
||||||
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -16,8 +16,8 @@
|
|||||||
struct Expression;
|
struct Expression;
|
||||||
struct FileStackNode;
|
struct FileStackNode;
|
||||||
|
|
||||||
extern char *tzObjectname;
|
extern char *objectName;
|
||||||
extern struct Section *pSectionList, *pCurrentSection;
|
extern struct Section *sectionList;
|
||||||
|
|
||||||
void out_RegisterNode(struct FileStackNode *node);
|
void out_RegisterNode(struct FileStackNode *node);
|
||||||
void out_ReplaceNode(struct FileStackNode *node);
|
void out_ReplaceNode(struct FileStackNode *node);
|
||||||
|
|||||||
@@ -17,20 +17,20 @@
|
|||||||
#define MAXRPNLEN 1048576
|
#define MAXRPNLEN 1048576
|
||||||
|
|
||||||
struct Expression {
|
struct Expression {
|
||||||
int32_t nVal; // If the expression's value is known, it's here
|
int32_t val; // If the expression's value is known, it's here
|
||||||
char *reason; // Why the expression is not known, if it isn't
|
char *reason; // Why the expression is not known, if it isn't
|
||||||
bool isKnown; // Whether the expression's value is known
|
bool isKnown; // Whether the expression's value is known
|
||||||
bool isSymbol; // Whether the expression represents a symbol
|
bool isSymbol; // Whether the expression represents a symbol
|
||||||
uint8_t *tRPN; // Array of bytes serializing the RPN expression
|
uint8_t *rpn; // Array of bytes serializing the RPN expression
|
||||||
uint32_t nRPNCapacity; // Size of the `tRPN` buffer
|
uint32_t rpnCapacity; // Size of the `rpn` buffer
|
||||||
uint32_t nRPNLength; // Used size of the `tRPN` buffer
|
uint32_t rpnLength; // Used size of the `rpn` buffer
|
||||||
uint32_t nRPNPatchSize; // Size the expression will take in the obj file
|
uint32_t rpnPatchSize; // Size the expression will take in the object file
|
||||||
};
|
};
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Determines if an expression is known at assembly time
|
* Determines if an expression is known at assembly time
|
||||||
*/
|
*/
|
||||||
static inline bool rpn_isKnown(const struct Expression *expr)
|
static inline bool rpn_isKnown(struct Expression const *expr)
|
||||||
{
|
{
|
||||||
return expr->isKnown;
|
return expr->isKnown;
|
||||||
}
|
}
|
||||||
@@ -43,11 +43,11 @@ static inline bool rpn_isSymbol(const struct Expression *expr)
|
|||||||
return expr->isSymbol;
|
return expr->isSymbol;
|
||||||
}
|
}
|
||||||
|
|
||||||
void rpn_Symbol(struct Expression *expr, char const *tzSym);
|
void rpn_Symbol(struct Expression *expr, char const *symName);
|
||||||
void rpn_Number(struct Expression *expr, uint32_t i);
|
void rpn_Number(struct Expression *expr, uint32_t i);
|
||||||
void rpn_LOGNOT(struct Expression *expr, const struct Expression *src);
|
void rpn_LOGNOT(struct Expression *expr, const struct Expression *src);
|
||||||
struct Symbol const *rpn_SymbolOf(struct Expression const *expr);
|
struct Symbol const *rpn_SymbolOf(struct Expression const *expr);
|
||||||
bool rpn_IsDiffConstant(struct Expression const *src, struct Symbol const *sym);
|
bool rpn_IsDiffConstant(struct Expression const *src, struct Symbol const *symName);
|
||||||
void rpn_BinaryOp(enum RPNCommand op, struct Expression *expr,
|
void rpn_BinaryOp(enum RPNCommand op, struct Expression *expr,
|
||||||
const struct Expression *src1,
|
const struct Expression *src1,
|
||||||
const struct Expression *src2);
|
const struct Expression *src2);
|
||||||
@@ -56,11 +56,15 @@ void rpn_LOW(struct Expression *expr, const struct Expression *src);
|
|||||||
void rpn_ISCONST(struct Expression *expr, const struct Expression *src);
|
void rpn_ISCONST(struct Expression *expr, const struct Expression *src);
|
||||||
void rpn_UNNEG(struct Expression *expr, const struct Expression *src);
|
void rpn_UNNEG(struct Expression *expr, const struct Expression *src);
|
||||||
void rpn_UNNOT(struct Expression *expr, const struct Expression *src);
|
void rpn_UNNOT(struct Expression *expr, const struct Expression *src);
|
||||||
void rpn_BankSymbol(struct Expression *expr, char const *tzSym);
|
void rpn_BankSymbol(struct Expression *expr, char const *symName);
|
||||||
void rpn_BankSection(struct Expression *expr, char const *tzSectionName);
|
void rpn_BankSection(struct Expression *expr, char const *sectionName);
|
||||||
void rpn_BankSelf(struct Expression *expr);
|
void rpn_BankSelf(struct Expression *expr);
|
||||||
|
void rpn_SizeOfSection(struct Expression *expr, char const *sectionName);
|
||||||
|
void rpn_StartOfSection(struct Expression *expr, char const *sectionName);
|
||||||
void rpn_Free(struct Expression *expr);
|
void rpn_Free(struct Expression *expr);
|
||||||
void rpn_CheckHRAM(struct Expression *expr, const struct Expression *src);
|
void rpn_CheckHRAM(struct Expression *expr, const struct Expression *src);
|
||||||
void rpn_CheckRST(struct Expression *expr, const struct Expression *src);
|
void rpn_CheckRST(struct Expression *expr, const struct Expression *src);
|
||||||
|
void rpn_CheckNBit(struct Expression const *expr, uint8_t n);
|
||||||
|
int32_t rpn_GetConstVal(struct Expression const *expr);
|
||||||
|
|
||||||
#endif /* RGBDS_ASM_RPN_H */
|
#endif /* RGBDS_ASM_RPN_H */
|
||||||
|
|||||||
@@ -13,6 +13,7 @@
|
|||||||
#include <stdbool.h>
|
#include <stdbool.h>
|
||||||
|
|
||||||
#include "linkdefs.h"
|
#include "linkdefs.h"
|
||||||
|
#include "platform.h" // NONNULL
|
||||||
|
|
||||||
extern uint8_t fillByte;
|
extern uint8_t fillByte;
|
||||||
|
|
||||||
@@ -27,7 +28,7 @@ struct Section {
|
|||||||
uint32_t size;
|
uint32_t size;
|
||||||
uint32_t org;
|
uint32_t org;
|
||||||
uint32_t bank;
|
uint32_t bank;
|
||||||
uint8_t align;
|
uint8_t align; // Exactly as specified in `ALIGN[]`
|
||||||
uint16_t alignOfs;
|
uint16_t alignOfs;
|
||||||
struct Section *next;
|
struct Section *next;
|
||||||
struct Patch *patches;
|
struct Patch *patches;
|
||||||
@@ -40,14 +41,14 @@ struct SectionSpec {
|
|||||||
uint16_t alignOfs;
|
uint16_t alignOfs;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct Section *out_FindSectionByName(const char *name);
|
extern struct Section *currentSection;
|
||||||
void out_NewSection(char const *name, uint32_t secttype, uint32_t org,
|
|
||||||
struct SectionSpec const *attributes,
|
struct Section *sect_FindSectionByName(char const *name);
|
||||||
enum SectionModifier mod);
|
void sect_NewSection(char const *name, uint32_t secttype, uint32_t org,
|
||||||
void out_SetLoadSection(char const *name, uint32_t secttype, uint32_t org,
|
struct SectionSpec const *attributes, enum SectionModifier mod);
|
||||||
struct SectionSpec const *attributes,
|
void sect_SetLoadSection(char const *name, uint32_t secttype, uint32_t org,
|
||||||
enum SectionModifier mod);
|
struct SectionSpec const *attributes, enum SectionModifier mod);
|
||||||
void out_EndLoadSection(void);
|
void sect_EndLoadSection(void);
|
||||||
|
|
||||||
struct Section *sect_GetSymbolSection(void);
|
struct Section *sect_GetSymbolSection(void);
|
||||||
uint32_t sect_GetSymbolOffset(void);
|
uint32_t sect_GetSymbolOffset(void);
|
||||||
@@ -59,21 +60,23 @@ void sect_NextUnionMember(void);
|
|||||||
void sect_EndUnion(void);
|
void sect_EndUnion(void);
|
||||||
void sect_CheckUnionClosed(void);
|
void sect_CheckUnionClosed(void);
|
||||||
|
|
||||||
void out_AbsByte(uint8_t b);
|
void sect_AbsByte(uint8_t b);
|
||||||
void out_AbsByteGroup(uint8_t const *s, int32_t length);
|
void sect_AbsByteGroup(uint8_t const *s, size_t length);
|
||||||
void out_AbsWordGroup(uint8_t const *s, int32_t length);
|
void sect_AbsWordGroup(uint8_t const *s, size_t length);
|
||||||
void out_AbsLongGroup(uint8_t const *s, int32_t length);
|
void sect_AbsLongGroup(uint8_t const *s, size_t length);
|
||||||
void out_Skip(int32_t skip, bool ds);
|
void sect_Skip(uint32_t skip, bool ds);
|
||||||
void out_String(char const *s);
|
void sect_String(char const *s);
|
||||||
void out_RelByte(struct Expression *expr, uint32_t pcShift);
|
void sect_RelByte(struct Expression *expr, uint32_t pcShift);
|
||||||
void out_RelBytes(uint32_t n, struct Expression *exprs, size_t size);
|
void sect_RelBytes(uint32_t n, struct Expression *exprs, size_t size);
|
||||||
void out_RelWord(struct Expression *expr, uint32_t pcShift);
|
void sect_RelWord(struct Expression *expr, uint32_t pcShift);
|
||||||
void out_RelLong(struct Expression *expr, uint32_t pcShift);
|
void sect_RelLong(struct Expression *expr, uint32_t pcShift);
|
||||||
void out_PCRelByte(struct Expression *expr, uint32_t pcShift);
|
void sect_PCRelByte(struct Expression *expr, uint32_t pcShift);
|
||||||
void out_BinaryFile(char const *s, int32_t startPos);
|
void sect_BinaryFile(char const *s, int32_t startPos);
|
||||||
void out_BinaryFileSlice(char const *s, int32_t start_pos, int32_t length);
|
void sect_BinaryFileSlice(char const *s, int32_t start_pos, int32_t length);
|
||||||
|
|
||||||
void out_PushSection(void);
|
void sect_PushSection(void);
|
||||||
void out_PopSection(void);
|
void sect_PopSection(void);
|
||||||
|
|
||||||
|
bool sect_IsSizeKnown(struct Section const NONNULL(name));
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -17,15 +17,13 @@
|
|||||||
#include "asm/section.h"
|
#include "asm/section.h"
|
||||||
|
|
||||||
#include "platform.h" // MIN_NB_ELMS
|
#include "platform.h" // MIN_NB_ELMS
|
||||||
#include "types.h"
|
|
||||||
|
|
||||||
#define HASHSIZE (1 << 16)
|
#define MAXSYMLEN 255
|
||||||
#define MAXSYMLEN 256
|
|
||||||
|
|
||||||
enum SymbolType {
|
enum SymbolType {
|
||||||
SYM_LABEL,
|
SYM_LABEL,
|
||||||
SYM_EQU,
|
SYM_EQU,
|
||||||
SYM_SET,
|
SYM_VAR,
|
||||||
SYM_MACRO,
|
SYM_MACRO,
|
||||||
SYM_EQUS,
|
SYM_EQUS,
|
||||||
SYM_REF // Forward reference to a label
|
SYM_REF // Forward reference to a label
|
||||||
@@ -45,13 +43,13 @@ struct Symbol {
|
|||||||
/* If sym_IsNumeric */
|
/* If sym_IsNumeric */
|
||||||
int32_t value;
|
int32_t value;
|
||||||
int32_t (*numCallback)(void);
|
int32_t (*numCallback)(void);
|
||||||
/* For SYM_MACRO */
|
/* For SYM_MACRO and SYM_EQUS; TODO: have separate fields */
|
||||||
struct {
|
struct {
|
||||||
size_t macroSize;
|
size_t macroSize;
|
||||||
char *macro;
|
char *macro;
|
||||||
};
|
};
|
||||||
/* For SYM_EQUS, TODO: separate "base" fields from SYM_MACRO */
|
/* For SYM_EQUS */
|
||||||
char const *(*strCallback)(void); /* For SYM_EQUS */
|
char const *(*strCallback)(void);
|
||||||
};
|
};
|
||||||
|
|
||||||
uint32_t ID; /* ID of the symbol in the object file (-1 if none) */
|
uint32_t ID; /* ID of the symbol in the object file (-1 if none) */
|
||||||
@@ -77,13 +75,12 @@ static inline bool sym_IsConstant(struct Symbol const *sym)
|
|||||||
|
|
||||||
return sect && sect->org != (uint32_t)-1;
|
return sect && sect->org != (uint32_t)-1;
|
||||||
}
|
}
|
||||||
return sym->type == SYM_EQU || sym->type == SYM_SET;
|
return sym->type == SYM_EQU || sym->type == SYM_VAR;
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline bool sym_IsNumeric(struct Symbol const *sym)
|
static inline bool sym_IsNumeric(struct Symbol const *sym)
|
||||||
{
|
{
|
||||||
return sym->type == SYM_LABEL || sym->type == SYM_EQU
|
return sym->type == SYM_LABEL || sym->type == SYM_EQU || sym->type == SYM_VAR;
|
||||||
|| sym->type == SYM_SET;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline bool sym_IsLabel(struct Symbol const *sym)
|
static inline bool sym_IsLabel(struct Symbol const *sym)
|
||||||
@@ -121,22 +118,23 @@ struct Symbol *sym_AddAnonLabel(void);
|
|||||||
void sym_WriteAnonLabelName(char buf[MIN_NB_ELMS(MAXSYMLEN + 1)], uint32_t ofs, bool neg);
|
void sym_WriteAnonLabelName(char buf[MIN_NB_ELMS(MAXSYMLEN + 1)], uint32_t ofs, bool neg);
|
||||||
void sym_Export(char const *symName);
|
void sym_Export(char const *symName);
|
||||||
struct Symbol *sym_AddEqu(char const *symName, int32_t value);
|
struct Symbol *sym_AddEqu(char const *symName, int32_t value);
|
||||||
struct Symbol *sym_AddSet(char const *symName, int32_t value);
|
struct Symbol *sym_RedefEqu(char const *symName, int32_t value);
|
||||||
|
struct Symbol *sym_AddVar(char const *symName, int32_t value);
|
||||||
uint32_t sym_GetPCValue(void);
|
uint32_t sym_GetPCValue(void);
|
||||||
uint32_t sym_GetConstantSymValue(struct Symbol const *sym);
|
uint32_t sym_GetConstantSymValue(struct Symbol const *sym);
|
||||||
uint32_t sym_GetConstantValue(char const *s);
|
uint32_t sym_GetConstantValue(char const *symName);
|
||||||
/*
|
/*
|
||||||
* Find a symbol by exact name, bypassing expansion checks
|
* Find a symbol by exact name, bypassing expansion checks
|
||||||
*/
|
*/
|
||||||
struct Symbol *sym_FindExactSymbol(char const *name);
|
struct Symbol *sym_FindExactSymbol(char const *symName);
|
||||||
/*
|
/*
|
||||||
* Find a symbol by exact name; may not be scoped, produces an error if it is
|
* Find a symbol by exact name; may not be scoped, produces an error if it is
|
||||||
*/
|
*/
|
||||||
struct Symbol *sym_FindUnscopedSymbol(char const *name);
|
struct Symbol *sym_FindUnscopedSymbol(char const *symName);
|
||||||
/*
|
/*
|
||||||
* Find a symbol, possibly scoped, by name
|
* Find a symbol, possibly scoped, by name
|
||||||
*/
|
*/
|
||||||
struct Symbol *sym_FindScopedSymbol(char const *name);
|
struct Symbol *sym_FindScopedSymbol(char const *symName);
|
||||||
struct Symbol const *sym_GetPC(void);
|
struct Symbol const *sym_GetPC(void);
|
||||||
struct Symbol *sym_AddMacro(char const *symName, int32_t defLineNo, char *body, size_t size);
|
struct Symbol *sym_AddMacro(char const *symName, int32_t defLineNo, char *body, size_t size);
|
||||||
struct Symbol *sym_Ref(char const *symName);
|
struct Symbol *sym_Ref(char const *symName);
|
||||||
|
|||||||
@@ -13,43 +13,65 @@
|
|||||||
|
|
||||||
extern unsigned int nbErrors;
|
extern unsigned int nbErrors;
|
||||||
|
|
||||||
|
enum WarningState {
|
||||||
|
WARNING_DEFAULT,
|
||||||
|
WARNING_DISABLED,
|
||||||
|
WARNING_ENABLED,
|
||||||
|
WARNING_ERROR
|
||||||
|
};
|
||||||
|
|
||||||
enum WarningID {
|
enum WarningID {
|
||||||
WARNING_ASSERT, /* Assertions */
|
WARNING_ASSERT, // Assertions
|
||||||
WARNING_BACKWARDS_FOR, /* `for` loop with backwards range */
|
WARNING_BACKWARDS_FOR, // `for` loop with backwards range
|
||||||
WARNING_BUILTIN_ARG, /* Invalid args to builtins */
|
WARNING_BUILTIN_ARG, // Invalid args to builtins
|
||||||
WARNING_CHARMAP_REDEF, /* Charmap entry re-definition */
|
WARNING_CHARMAP_REDEF, // Charmap entry re-definition
|
||||||
WARNING_DIV, /* Division undefined behavior */
|
WARNING_DIV, // Division undefined behavior
|
||||||
WARNING_EMPTY_DATA_DIRECTIVE, /* `db`, `dw` or `dl` directive without data in ROM */
|
WARNING_EMPTY_DATA_DIRECTIVE, // `db`, `dw` or `dl` directive without data in ROM
|
||||||
WARNING_EMPTY_MACRO_ARG, /* Empty macro argument */
|
WARNING_EMPTY_MACRO_ARG, // Empty macro argument
|
||||||
WARNING_EMPTY_STRRPL, /* Empty second argument in `STRRPL` */
|
WARNING_EMPTY_STRRPL, // Empty second argument in `STRRPL`
|
||||||
WARNING_LARGE_CONSTANT, /* Constants too large */
|
WARNING_LARGE_CONSTANT, // Constants too large
|
||||||
WARNING_LONG_STR, /* String too long for internal buffers */
|
WARNING_LONG_STR, // String too long for internal buffers
|
||||||
WARNING_MACRO_SHIFT, /* Shift past available arguments in macro */
|
WARNING_MACRO_SHIFT, // Shift past available arguments in macro
|
||||||
WARNING_NESTED_COMMENT, /* Comment-start delimiter in a block comment */
|
WARNING_NESTED_COMMENT, // Comment-start delimiter in a block comment
|
||||||
WARNING_OBSOLETE, /* Obsolete things */
|
WARNING_OBSOLETE, // Obsolete things
|
||||||
WARNING_SHIFT, /* Shifting undefined behavior */
|
WARNING_SHIFT, // Shifting undefined behavior
|
||||||
WARNING_SHIFT_AMOUNT, /* Strange shift amount */
|
WARNING_SHIFT_AMOUNT, // Strange shift amount
|
||||||
WARNING_TRUNCATION, /* Implicit truncation loses some bits */
|
WARNING_USER, // User warnings
|
||||||
WARNING_USER, /* User warnings */
|
|
||||||
|
|
||||||
NB_WARNINGS,
|
NB_PLAIN_WARNINGS,
|
||||||
|
|
||||||
/* Warnings past this point are "meta" warnings */
|
// Warnings past this point are "parametric" warnings, only mapping to a single flag
|
||||||
WARNING_ALL = NB_WARNINGS,
|
#define PARAM_WARNINGS_START NB_PLAIN_WARNINGS
|
||||||
|
// Treating string as number may lose some bits
|
||||||
|
WARNING_NUMERIC_STRING_1 = PARAM_WARNINGS_START,
|
||||||
|
WARNING_NUMERIC_STRING_2,
|
||||||
|
// Implicit truncation loses some bits
|
||||||
|
WARNING_TRUNCATION_1,
|
||||||
|
WARNING_TRUNCATION_2,
|
||||||
|
|
||||||
|
NB_PLAIN_AND_PARAM_WARNINGS,
|
||||||
|
#define NB_PARAM_WARNINGS (NB_PLAIN_AND_PARAM_WARNINGS - PARAM_WARNINGS_START)
|
||||||
|
|
||||||
|
// Warnings past this point are "meta" warnings
|
||||||
|
#define META_WARNINGS_START NB_PLAIN_AND_PARAM_WARNINGS
|
||||||
|
WARNING_ALL = META_WARNINGS_START,
|
||||||
WARNING_EXTRA,
|
WARNING_EXTRA,
|
||||||
WARNING_EVERYTHING,
|
WARNING_EVERYTHING,
|
||||||
|
|
||||||
NB_WARNINGS_ALL
|
NB_WARNINGS,
|
||||||
#define NB_META_WARNINGS (NB_WARNINGS_ALL - NB_WARNINGS)
|
#define NB_META_WARNINGS (NB_WARNINGS - META_WARNINGS_START)
|
||||||
};
|
};
|
||||||
|
|
||||||
void processWarningFlag(char const *flag);
|
extern enum WarningState warningStates[NB_PLAIN_AND_PARAM_WARNINGS];
|
||||||
|
extern bool warningsAreErrors;
|
||||||
|
|
||||||
|
void processWarningFlag(char *flag);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Used to warn the user about problems that don't prevent the generation of
|
* Used to warn the user about problems that don't prevent the generation of
|
||||||
* valid code.
|
* valid code.
|
||||||
*/
|
*/
|
||||||
void warning(enum WarningID id, const char *fmt, ...) format_(printf, 2, 3);
|
void warning(enum WarningID id, char const *fmt, ...) format_(printf, 2, 3);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Used for errors that compromise the whole assembly process by affecting the
|
* Used for errors that compromise the whole assembly process by affecting the
|
||||||
@@ -58,7 +80,7 @@ void warning(enum WarningID id, const char *fmt, ...) format_(printf, 2, 3);
|
|||||||
* 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, ...) format_(printf, 1, 2);
|
_Noreturn void fatalerror(char const *fmt, ...) format_(printf, 1, 2);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* 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
|
||||||
@@ -66,6 +88,6 @@ _Noreturn void fatalerror(const char *fmt, ...) format_(printf, 1, 2);
|
|||||||
* get a list of all errors at the end, making it easier to fix all of them at
|
* get a list of all errors at the end, making it easier to fix all of them at
|
||||||
* once.
|
* once.
|
||||||
*/
|
*/
|
||||||
void error(const char *fmt, ...) format_(printf, 1, 2);
|
void error(char const *fmt, ...) format_(printf, 1, 2);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
21
include/error.h
Normal file
21
include/error.h
Normal file
@@ -0,0 +1,21 @@
|
|||||||
|
/*
|
||||||
|
* This file is part of RGBDS.
|
||||||
|
*
|
||||||
|
* Copyright (c) 1997-2021, RGBDS contributors.
|
||||||
|
*
|
||||||
|
* SPDX-License-Identifier: MIT
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef RGBDS_ERROR_H
|
||||||
|
#define RGBDS_ERROR_H
|
||||||
|
|
||||||
|
#include "helpers.h"
|
||||||
|
#include "platform.h"
|
||||||
|
|
||||||
|
void warn(char const NONNULL(fmt), ...) format_(printf, 1, 2);
|
||||||
|
void warnx(char const NONNULL(fmt), ...) format_(printf, 1, 2);
|
||||||
|
|
||||||
|
_Noreturn void err(char const NONNULL(fmt), ...) format_(printf, 1, 2);
|
||||||
|
_Noreturn void errx(char const NONNULL(fmt), ...) format_(printf, 1, 2);
|
||||||
|
|
||||||
|
#endif /* RGBDS_ERROR_H */
|
||||||
44
include/extern/err.h
vendored
44
include/extern/err.h
vendored
@@ -1,44 +0,0 @@
|
|||||||
/*
|
|
||||||
* This file is part of RGBDS.
|
|
||||||
*
|
|
||||||
* Copyright (c) 1997-2018, RGBDS contributors.
|
|
||||||
*
|
|
||||||
* SPDX-License-Identifier: MIT
|
|
||||||
*/
|
|
||||||
|
|
||||||
#ifndef EXTERN_ERR_H
|
|
||||||
#define EXTERN_ERR_H
|
|
||||||
|
|
||||||
#ifdef ERR_IN_LIBC
|
|
||||||
|
|
||||||
#include <err.h>
|
|
||||||
|
|
||||||
#else /* ERR_IN_LIBC */
|
|
||||||
|
|
||||||
#include <stdarg.h>
|
|
||||||
|
|
||||||
#include "helpers.h"
|
|
||||||
|
|
||||||
#define warn rgbds_warn
|
|
||||||
#define vwarn rgbds_vwarn
|
|
||||||
#define warnx rgbds_warnx
|
|
||||||
#define vwarnx rgbds_vwarnx
|
|
||||||
|
|
||||||
#define err rgbds_err
|
|
||||||
#define verr rgbds_verr
|
|
||||||
#define errx rgbds_errx
|
|
||||||
#define verrx rgbds_verrx
|
|
||||||
|
|
||||||
void warn(const char *fmt, ...) format_(printf, 1, 2);
|
|
||||||
void vwarn(const char *fmt, va_list ap) format_(printf, 1, 0);
|
|
||||||
void warnx(const char *fmt, ...) format_(printf, 1, 2);
|
|
||||||
void vwarnx(const char *fmt, va_list ap) format_(printf, 1, 0);
|
|
||||||
|
|
||||||
_Noreturn void err(int status, const char *fmt, ...) format_(printf, 2, 3);
|
|
||||||
_Noreturn void verr(int status, const char *fmt, va_list ap) format_(printf, 2, 0);
|
|
||||||
_Noreturn void errx(int status, const char *fmt, ...) format_(printf, 2, 3);
|
|
||||||
_Noreturn void verrx(int status, const char *fmt, va_list ap) format_(printf, 2, 0);
|
|
||||||
|
|
||||||
#endif /* ERR_IN_LIBC */
|
|
||||||
|
|
||||||
#endif /* EXTERN_ERR_H */
|
|
||||||
5
include/extern/getopt.h
vendored
5
include/extern/getopt.h
vendored
@@ -30,13 +30,14 @@ extern char *musl_optarg;
|
|||||||
extern int musl_optind, musl_opterr, musl_optopt, musl_optreset;
|
extern int musl_optind, musl_opterr, musl_optopt, musl_optreset;
|
||||||
|
|
||||||
struct option {
|
struct option {
|
||||||
const char *name;
|
char const *name;
|
||||||
int has_arg;
|
int has_arg;
|
||||||
int *flag;
|
int *flag;
|
||||||
int val;
|
int val;
|
||||||
};
|
};
|
||||||
|
|
||||||
int musl_getopt_long_only(int, char **, const char *, const struct option *, int *);
|
int musl_getopt_long_only(int argc, char **argv, char const *optstring,
|
||||||
|
const struct option *longopts, int *idx);
|
||||||
|
|
||||||
#define no_argument 0
|
#define no_argument 0
|
||||||
#define required_argument 1
|
#define required_argument 1
|
||||||
|
|||||||
@@ -13,7 +13,7 @@
|
|||||||
#include <stdbool.h>
|
#include <stdbool.h>
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
|
|
||||||
#include "extern/err.h"
|
#include "error.h"
|
||||||
|
|
||||||
struct Options {
|
struct Options {
|
||||||
bool debug;
|
bool debug;
|
||||||
@@ -24,7 +24,7 @@ struct Options {
|
|||||||
bool mirror;
|
bool mirror;
|
||||||
bool unique;
|
bool unique;
|
||||||
bool colorcurve;
|
bool colorcurve;
|
||||||
int trim;
|
unsigned int trim;
|
||||||
char *tilemapfile;
|
char *tilemapfile;
|
||||||
bool tilemapout;
|
bool tilemapout;
|
||||||
char *attrmapfile;
|
char *attrmapfile;
|
||||||
@@ -43,7 +43,7 @@ struct RGBColor {
|
|||||||
|
|
||||||
struct ImageOptions {
|
struct ImageOptions {
|
||||||
bool horizontal;
|
bool horizontal;
|
||||||
int trim;
|
unsigned int trim;
|
||||||
char *tilemapfile;
|
char *tilemapfile;
|
||||||
bool tilemapout;
|
bool tilemapout;
|
||||||
char *attrmapfile;
|
char *attrmapfile;
|
||||||
|
|||||||
@@ -18,6 +18,7 @@
|
|||||||
#ifdef __GNUC__ // GCC or compatible
|
#ifdef __GNUC__ // GCC or compatible
|
||||||
#define format_(archetype, str_index, first_arg) \
|
#define format_(archetype, str_index, first_arg) \
|
||||||
__attribute__ ((format (archetype, str_index, first_arg)))
|
__attribute__ ((format (archetype, str_index, first_arg)))
|
||||||
|
#define attr_(...) __attribute__ ((__VA_ARGS__))
|
||||||
// In release builds, define "unreachable" as such, but trap in debug builds
|
// In release builds, define "unreachable" as such, but trap in debug builds
|
||||||
#ifdef NDEBUG
|
#ifdef NDEBUG
|
||||||
#define unreachable_ __builtin_unreachable
|
#define unreachable_ __builtin_unreachable
|
||||||
@@ -27,6 +28,7 @@
|
|||||||
#else
|
#else
|
||||||
// Unsupported, but no need to throw a fit
|
// Unsupported, but no need to throw a fit
|
||||||
#define format_(archetype, str_index, first_arg)
|
#define format_(archetype, str_index, first_arg)
|
||||||
|
#define attr_(...)
|
||||||
// This seems to generate similar code to __builtin_unreachable, despite different semantics
|
// This seems to generate similar code to __builtin_unreachable, despite different semantics
|
||||||
// Note that executing this is undefined behavior (declared _Noreturn, but does return)
|
// Note that executing this is undefined behavior (declared _Noreturn, but does return)
|
||||||
static inline _Noreturn unreachable_(void) {}
|
static inline _Noreturn unreachable_(void) {}
|
||||||
@@ -59,7 +61,6 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
#else
|
#else
|
||||||
// FIXME: these are rarely used, and need testing...
|
|
||||||
#include <limits.h>
|
#include <limits.h>
|
||||||
static inline int ctz(unsigned int x)
|
static inline int ctz(unsigned int x)
|
||||||
{
|
{
|
||||||
@@ -88,4 +89,8 @@
|
|||||||
#define STR(x) #x
|
#define STR(x) #x
|
||||||
#define EXPAND_AND_STR(x) STR(x)
|
#define EXPAND_AND_STR(x) STR(x)
|
||||||
|
|
||||||
|
// Obtaining the size of an array; `arr` must be an expression, not a type!
|
||||||
|
// (Having two instances of `arr` is OK because the contents of `sizeof` are not evaluated.)
|
||||||
|
#define ARRAY_SIZE(arr) (sizeof(arr) / sizeof *(arr))
|
||||||
|
|
||||||
#endif /* HELPERS_H */
|
#endif /* HELPERS_H */
|
||||||
|
|||||||
@@ -24,6 +24,9 @@ extern char const *symFileName;
|
|||||||
extern char const *overlayFileName;
|
extern char const *overlayFileName;
|
||||||
extern char const *outputFileName;
|
extern char const *outputFileName;
|
||||||
extern uint8_t padValue;
|
extern uint8_t padValue;
|
||||||
|
extern uint16_t scrambleROMX;
|
||||||
|
extern uint8_t scrambleWRAMX;
|
||||||
|
extern uint8_t scrambleSRAM;
|
||||||
extern bool is32kMode;
|
extern bool is32kMode;
|
||||||
extern bool beVerbose;
|
extern bool beVerbose;
|
||||||
extern bool isWRA0Mode;
|
extern bool isWRA0Mode;
|
||||||
|
|||||||
@@ -21,10 +21,7 @@ struct Assertion {
|
|||||||
struct Patch patch;
|
struct Patch patch;
|
||||||
// enum AssertionType type; The `patch`'s field is instead re-used
|
// enum AssertionType type; The `patch`'s field is instead re-used
|
||||||
char *message;
|
char *message;
|
||||||
/*
|
// This would be redundant with `.section->fileSymbols`... but `section` is sometimes NULL!
|
||||||
* This would be redundant with `.section->fileSymbols`... but
|
|
||||||
* `section` is sometimes NULL!
|
|
||||||
*/
|
|
||||||
struct Symbol **fileSymbols;
|
struct Symbol **fileSymbols;
|
||||||
|
|
||||||
struct Assertion *next;
|
struct Assertion *next;
|
||||||
|
|||||||
@@ -14,7 +14,7 @@
|
|||||||
|
|
||||||
#define RGBDS_OBJECT_VERSION_STRING "RGB%1u"
|
#define RGBDS_OBJECT_VERSION_STRING "RGB%1u"
|
||||||
#define RGBDS_OBJECT_VERSION_NUMBER 9U
|
#define RGBDS_OBJECT_VERSION_NUMBER 9U
|
||||||
#define RGBDS_OBJECT_REV 7U
|
#define RGBDS_OBJECT_REV 9U
|
||||||
|
|
||||||
enum AssertionType {
|
enum AssertionType {
|
||||||
ASSERT_WARN,
|
ASSERT_WARN,
|
||||||
@@ -28,17 +28,17 @@ enum RPNCommand {
|
|||||||
RPN_MUL = 0x02,
|
RPN_MUL = 0x02,
|
||||||
RPN_DIV = 0x03,
|
RPN_DIV = 0x03,
|
||||||
RPN_MOD = 0x04,
|
RPN_MOD = 0x04,
|
||||||
RPN_UNSUB = 0x05,
|
RPN_UNSUB = 0x05, // FIXME: should be renamed to "NEG" for consistency
|
||||||
RPN_EXP = 0x06,
|
RPN_EXP = 0x06,
|
||||||
|
|
||||||
RPN_OR = 0x10,
|
RPN_OR = 0x10,
|
||||||
RPN_AND = 0x11,
|
RPN_AND = 0x11,
|
||||||
RPN_XOR = 0x12,
|
RPN_XOR = 0x12,
|
||||||
RPN_UNNOT = 0x13,
|
RPN_UNNOT = 0x13, // FIXME: should be renamed to "NOT" for consistency
|
||||||
|
|
||||||
RPN_LOGAND = 0x21,
|
RPN_LOGAND = 0x21,
|
||||||
RPN_LOGOR = 0x22,
|
RPN_LOGOR = 0x22,
|
||||||
RPN_LOGUNNOT = 0x23,
|
RPN_LOGUNNOT = 0x23, // FIXME: should be renamed to "LOGNOT" for consistency
|
||||||
|
|
||||||
RPN_LOGEQ = 0x30,
|
RPN_LOGEQ = 0x30,
|
||||||
RPN_LOGNE = 0x31,
|
RPN_LOGNE = 0x31,
|
||||||
@@ -49,10 +49,13 @@ enum RPNCommand {
|
|||||||
|
|
||||||
RPN_SHL = 0x40,
|
RPN_SHL = 0x40,
|
||||||
RPN_SHR = 0x41,
|
RPN_SHR = 0x41,
|
||||||
|
RPN_USHR = 0x42,
|
||||||
|
|
||||||
RPN_BANK_SYM = 0x50,
|
RPN_BANK_SYM = 0x50,
|
||||||
RPN_BANK_SECT = 0x51,
|
RPN_BANK_SECT = 0x51,
|
||||||
RPN_BANK_SELF = 0x52,
|
RPN_BANK_SELF = 0x52,
|
||||||
|
RPN_SIZEOF_SECT = 0x53,
|
||||||
|
RPN_STARTOF_SECT = 0x54,
|
||||||
|
|
||||||
RPN_HRAM = 0x60,
|
RPN_HRAM = 0x60,
|
||||||
RPN_RST = 0x61,
|
RPN_RST = 0x61,
|
||||||
|
|||||||
@@ -16,5 +16,6 @@ int32_t op_modulo(int32_t dividend, int32_t divisor);
|
|||||||
int32_t op_exponent(int32_t base, uint32_t power);
|
int32_t op_exponent(int32_t base, uint32_t power);
|
||||||
int32_t op_shift_left(int32_t value, int32_t amount);
|
int32_t op_shift_left(int32_t value, int32_t amount);
|
||||||
int32_t op_shift_right(int32_t value, int32_t amount);
|
int32_t op_shift_right(int32_t value, int32_t amount);
|
||||||
|
int32_t op_shift_right_unsigned(int32_t value, int32_t amount);
|
||||||
|
|
||||||
#endif /* RGBDS_OP_MATH_H */
|
#endif /* RGBDS_OP_MATH_H */
|
||||||
|
|||||||
@@ -11,9 +11,10 @@
|
|||||||
#ifndef RGBDS_PLATFORM_H
|
#ifndef RGBDS_PLATFORM_H
|
||||||
#define RGBDS_PLATFORM_H
|
#define RGBDS_PLATFORM_H
|
||||||
|
|
||||||
/* MSVC doesn't have strncasecmp, use a suitable replacement */
|
// MSVC doesn't have str(n)casecmp, use a suitable replacement
|
||||||
#ifdef _MSC_VER
|
#ifdef _MSC_VER
|
||||||
# include <string.h>
|
# include <string.h>
|
||||||
|
# define strcasecmp _stricmp
|
||||||
# define strncasecmp _strnicmp
|
# define strncasecmp _strnicmp
|
||||||
#else
|
#else
|
||||||
# include <strings.h>
|
# include <strings.h>
|
||||||
@@ -48,8 +49,10 @@
|
|||||||
/* MSVC doesn't support `[static N]` for array arguments from C99 */
|
/* MSVC doesn't support `[static N]` for array arguments from C99 */
|
||||||
#ifdef _MSC_VER
|
#ifdef _MSC_VER
|
||||||
# define MIN_NB_ELMS(N)
|
# define MIN_NB_ELMS(N)
|
||||||
|
# define NONNULL(ptr) *ptr
|
||||||
#else
|
#else
|
||||||
# define MIN_NB_ELMS(N) static (N)
|
# define MIN_NB_ELMS(N) static (N)
|
||||||
|
# define NONNULL(ptr) ptr[static 1]
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// MSVC uses a different name for O_RDWR, and needs an additional _O_BINARY flag
|
// MSVC uses a different name for O_RDWR, and needs an additional _O_BINARY flag
|
||||||
|
|||||||
@@ -1,16 +0,0 @@
|
|||||||
/*
|
|
||||||
* This file is part of RGBDS.
|
|
||||||
*
|
|
||||||
* Copyright (c) 1997-2018, Carsten Sorensen and RGBDS contributors.
|
|
||||||
*
|
|
||||||
* SPDX-License-Identifier: MIT
|
|
||||||
*/
|
|
||||||
|
|
||||||
#ifndef RGBDS_TYPES_H
|
|
||||||
#define RGBDS_TYPES_H
|
|
||||||
|
|
||||||
#ifndef _MAX_PATH
|
|
||||||
#define _MAX_PATH 512
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#endif /* RGBDS_TYPES_H */
|
|
||||||
@@ -11,8 +11,8 @@
|
|||||||
|
|
||||||
#define PACKAGE_VERSION_MAJOR 0
|
#define PACKAGE_VERSION_MAJOR 0
|
||||||
#define PACKAGE_VERSION_MINOR 5
|
#define PACKAGE_VERSION_MINOR 5
|
||||||
#define PACKAGE_VERSION_PATCH 0
|
#define PACKAGE_VERSION_PATCH 2
|
||||||
|
|
||||||
const char *get_package_version_string(void);
|
char const *get_package_version_string(void);
|
||||||
|
|
||||||
#endif /* EXTERN_VERSION_H */
|
#endif /* EXTERN_VERSION_H */
|
||||||
|
|||||||
2
src/.gitignore
vendored
Normal file
2
src/.gitignore
vendored
Normal file
@@ -0,0 +1,2 @@
|
|||||||
|
# Generated by CMake
|
||||||
|
/.version.c
|
||||||
@@ -6,10 +6,12 @@
|
|||||||
# SPDX-License-Identifier: MIT
|
# SPDX-License-Identifier: MIT
|
||||||
#
|
#
|
||||||
|
|
||||||
|
configure_file(version.c _version.c ESCAPE_QUOTES)
|
||||||
|
|
||||||
set(common_src
|
set(common_src
|
||||||
"extern/err.c"
|
"error.c"
|
||||||
"extern/getopt.c"
|
"extern/getopt.c"
|
||||||
"version.c"
|
"_version.c"
|
||||||
)
|
)
|
||||||
|
|
||||||
find_package(PkgConfig)
|
find_package(PkgConfig)
|
||||||
|
|||||||
@@ -57,7 +57,7 @@ struct CharmapStackEntry {
|
|||||||
|
|
||||||
struct CharmapStackEntry *charmapStack;
|
struct CharmapStackEntry *charmapStack;
|
||||||
|
|
||||||
static struct Charmap *charmap_Get(const char *name)
|
static struct Charmap *charmap_Get(char const *name)
|
||||||
{
|
{
|
||||||
return hash_GetElement(charmaps, name);
|
return hash_GetElement(charmaps, name);
|
||||||
}
|
}
|
||||||
@@ -78,7 +78,7 @@ static void initNode(struct Charnode *node)
|
|||||||
memset(node->next, 0, sizeof(node->next));
|
memset(node->next, 0, sizeof(node->next));
|
||||||
}
|
}
|
||||||
|
|
||||||
struct Charmap *charmap_New(const char *name, const char *baseName)
|
struct Charmap *charmap_New(char const *name, char const *baseName)
|
||||||
{
|
{
|
||||||
struct Charmap *base = NULL;
|
struct Charmap *base = NULL;
|
||||||
|
|
||||||
@@ -120,7 +120,7 @@ void charmap_Delete(struct Charmap *charmap)
|
|||||||
free(charmap);
|
free(charmap);
|
||||||
}
|
}
|
||||||
|
|
||||||
void charmap_Set(const char *name)
|
void charmap_Set(char const *name)
|
||||||
{
|
{
|
||||||
struct Charmap **charmap = (struct Charmap **)hash_GetNode(charmaps, name);
|
struct Charmap **charmap = (struct Charmap **)hash_GetNode(charmaps, name);
|
||||||
|
|
||||||
@@ -192,6 +192,16 @@ void charmap_Add(char *mapping, uint8_t value)
|
|||||||
}
|
}
|
||||||
|
|
||||||
size_t charmap_Convert(char const *input, uint8_t *output)
|
size_t charmap_Convert(char const *input, uint8_t *output)
|
||||||
|
{
|
||||||
|
uint8_t *start = output;
|
||||||
|
|
||||||
|
while (charmap_ConvertNext(&input, &output))
|
||||||
|
;
|
||||||
|
|
||||||
|
return output - start;
|
||||||
|
}
|
||||||
|
|
||||||
|
size_t charmap_ConvertNext(char const **input, uint8_t **output)
|
||||||
{
|
{
|
||||||
/*
|
/*
|
||||||
* The goal is to match the longest mapping possible.
|
* The goal is to match the longest mapping possible.
|
||||||
@@ -199,52 +209,56 @@ size_t charmap_Convert(char const *input, uint8_t *output)
|
|||||||
* If that would lead to a dead end, rewind characters until the last match, and output.
|
* If that would lead to a dead end, rewind characters until the last match, and output.
|
||||||
* If no match, read a UTF-8 codepoint and output that.
|
* If no match, read a UTF-8 codepoint and output that.
|
||||||
*/
|
*/
|
||||||
size_t outputLen = 0;
|
|
||||||
struct Charmap const *charmap = *currentCharmap;
|
struct Charmap const *charmap = *currentCharmap;
|
||||||
struct Charnode const *node = &charmap->nodes[0];
|
struct Charnode const *node = &charmap->nodes[0];
|
||||||
struct Charnode const *match = NULL;
|
struct Charnode const *match = NULL;
|
||||||
size_t rewindDistance = 0;
|
size_t rewindDistance = 0;
|
||||||
|
|
||||||
for (;;) {
|
for (;;) {
|
||||||
/* We still want NULs to reach the `else` path, to give a chance to rewind */
|
uint8_t c = **input - 1;
|
||||||
uint8_t c = *input - 1;
|
|
||||||
|
|
||||||
if (*input && node->next[c]) {
|
if (**input && node->next[c]) {
|
||||||
input++; /* Consume that char */
|
// Consume that char
|
||||||
|
(*input)++;
|
||||||
rewindDistance++;
|
rewindDistance++;
|
||||||
|
|
||||||
|
// Advance to next node (index starts at 1)
|
||||||
node = &charmap->nodes[node->next[c]];
|
node = &charmap->nodes[node->next[c]];
|
||||||
if (node->isTerminal) {
|
if (node->isTerminal) {
|
||||||
|
// This node matches, register it
|
||||||
match = node;
|
match = node;
|
||||||
rewindDistance = 0; /* Rewind from after the match */
|
rewindDistance = 0; // If no longer match is found, rewind here
|
||||||
}
|
}
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
input -= rewindDistance; /* Rewind */
|
// We are at a dead end (either because we reached the end of input, or of
|
||||||
rewindDistance = 0;
|
// the trie), so rewind up to the last match, and output.
|
||||||
node = &charmap->nodes[0];
|
*input -= rewindDistance; // This will rewind all the way if no match found
|
||||||
|
|
||||||
if (match) { /* Arrived at a dead end with a match found */
|
if (match) { // A match was found, use it
|
||||||
*output++ = match->value;
|
if (output)
|
||||||
outputLen++;
|
*(*output)++ = match->value;
|
||||||
match = NULL; /* Reset match for next round */
|
|
||||||
|
|
||||||
} else if (*input) { /* No match found */
|
return 1;
|
||||||
size_t codepointLen = readUTF8Char(output, input);
|
|
||||||
|
|
||||||
if (codepointLen == 0) {
|
} else if (**input) { // No match found, but there is some input left
|
||||||
|
// This will write the codepoint's value to `output`, little-endian
|
||||||
|
size_t codepointLen = readUTF8Char(output ? *output : NULL,
|
||||||
|
*input);
|
||||||
|
|
||||||
|
if (codepointLen == 0)
|
||||||
error("Input string is not valid UTF-8!\n");
|
error("Input string is not valid UTF-8!\n");
|
||||||
break;
|
|
||||||
}
|
|
||||||
input += codepointLen; /* OK because UTF-8 has no NUL in multi-byte chars */
|
|
||||||
output += codepointLen;
|
|
||||||
outputLen += codepointLen;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!*input)
|
// OK because UTF-8 has no NUL in multi-byte chars
|
||||||
break;
|
*input += codepointLen;
|
||||||
}
|
if (output)
|
||||||
}
|
*output += codepointLen;
|
||||||
|
|
||||||
return outputLen;
|
return codepointLen;
|
||||||
|
|
||||||
|
} else { // End of input
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -46,7 +46,7 @@ int32_t fix_Callback_PI(void)
|
|||||||
void fix_Print(int32_t i)
|
void fix_Print(int32_t i)
|
||||||
{
|
{
|
||||||
uint32_t u = i;
|
uint32_t u = i;
|
||||||
const char *sign = "";
|
char const *sign = "";
|
||||||
|
|
||||||
if (i < 0) {
|
if (i < 0) {
|
||||||
u = -u;
|
u = -u;
|
||||||
|
|||||||
@@ -228,21 +228,13 @@ void fmt_PrintNumber(char *buf, size_t bufLen, struct FormatSpec const *fmt, uin
|
|||||||
/* Default fractional width (C's is 6 for "%f"; here 5 is enough) */
|
/* Default fractional width (C's is 6 for "%f"; here 5 is enough) */
|
||||||
size_t fracWidth = fmt->hasFrac ? fmt->fracWidth : 5;
|
size_t fracWidth = fmt->hasFrac ? fmt->fracWidth : 5;
|
||||||
|
|
||||||
if (fracWidth) {
|
|
||||||
if (fracWidth > 255) {
|
if (fracWidth > 255) {
|
||||||
error("Fractional width %zu too long, limiting to 255\n",
|
error("Fractional width %zu too long, limiting to 255\n",
|
||||||
fracWidth);
|
fracWidth);
|
||||||
fracWidth = 255;
|
fracWidth = 255;
|
||||||
}
|
}
|
||||||
|
|
||||||
char spec[16]; /* Max "%" + 5-char PRIu32 + ".%0255.f" + terminator */
|
snprintf(valueBuf, sizeof(valueBuf), "%.*f", (int)fracWidth, value / 65536.0);
|
||||||
|
|
||||||
snprintf(spec, sizeof(spec), "%%" PRIu32 ".%%0%zu.f", fracWidth);
|
|
||||||
snprintf(valueBuf, sizeof(valueBuf), spec, value >> 16,
|
|
||||||
(value % 65536) / 65536.0 * pow(10, fracWidth) + 0.5);
|
|
||||||
} else {
|
|
||||||
snprintf(valueBuf, sizeof(valueBuf), "%" PRIu32, value >> 16);
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
char const *spec = fmt->type == 'd' ? "%" PRId32
|
char const *spec = fmt->type == 'd' ? "%" PRId32
|
||||||
: fmt->type == 'u' ? "%" PRIu32
|
: fmt->type == 'u' ? "%" PRIu32
|
||||||
|
|||||||
@@ -23,12 +23,6 @@
|
|||||||
|
|
||||||
#define MAXINCPATHS 128
|
#define MAXINCPATHS 128
|
||||||
|
|
||||||
#ifdef LEXER_DEBUG
|
|
||||||
#define dbgPrint(...) fprintf(stderr, "[fstack] " __VA_ARGS__)
|
|
||||||
#else
|
|
||||||
#define dbgPrint(...)
|
|
||||||
#endif
|
|
||||||
|
|
||||||
struct Context {
|
struct Context {
|
||||||
struct Context *parent;
|
struct Context *parent;
|
||||||
struct FileStackNode *fileInfo;
|
struct FileStackNode *fileInfo;
|
||||||
@@ -44,7 +38,7 @@ struct Context {
|
|||||||
static struct Context *contextStack;
|
static struct Context *contextStack;
|
||||||
static size_t contextDepth = 0;
|
static size_t contextDepth = 0;
|
||||||
#define DEFAULT_MAX_DEPTH 64
|
#define DEFAULT_MAX_DEPTH 64
|
||||||
size_t nMaxRecursionDepth;
|
size_t maxRecursionDepth;
|
||||||
|
|
||||||
static unsigned int nbIncPaths = 0;
|
static unsigned int nbIncPaths = 0;
|
||||||
static char const *includePaths[MAXINCPATHS];
|
static char const *includePaths[MAXINCPATHS];
|
||||||
@@ -143,8 +137,8 @@ void fstk_AddIncludePath(char const *path)
|
|||||||
static void printDep(char const *path)
|
static void printDep(char const *path)
|
||||||
{
|
{
|
||||||
if (dependfile) {
|
if (dependfile) {
|
||||||
fprintf(dependfile, "%s: %s\n", tzTargetFileName, path);
|
fprintf(dependfile, "%s: %s\n", targetFileName, path);
|
||||||
if (oGeneratePhonyDeps)
|
if (generatePhonyDeps)
|
||||||
fprintf(dependfile, "%s:\n", path);
|
fprintf(dependfile, "%s:\n", path);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -206,18 +200,18 @@ bool fstk_FindFile(char const *path, char **fullPath, size_t *size)
|
|||||||
}
|
}
|
||||||
|
|
||||||
errno = ENOENT;
|
errno = ENOENT;
|
||||||
if (oGeneratedMissingIncludes)
|
if (generatedMissingIncludes)
|
||||||
printDep(path);
|
printDep(path);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool yywrap(void)
|
bool yywrap(void)
|
||||||
{
|
{
|
||||||
uint32_t nIFDepth = lexer_GetIFDepth();
|
uint32_t ifDepth = lexer_GetIFDepth();
|
||||||
|
|
||||||
if (nIFDepth != 0)
|
if (ifDepth != 0)
|
||||||
fatalerror("Ended block with %" PRIu32 " unterminated IF construct%s\n",
|
fatalerror("Ended block with %" PRIu32 " unterminated IF construct%s\n",
|
||||||
nIFDepth, nIFDepth == 1 ? "" : "s");
|
ifDepth, ifDepth == 1 ? "" : "s");
|
||||||
|
|
||||||
if (contextStack->fileInfo->type == NODE_REPT) { /* The context is a REPT block, which may loop */
|
if (contextStack->fileInfo->type == NODE_REPT) { /* The context is a REPT block, which may loop */
|
||||||
struct FileStackReptNode *fileInfo = (struct FileStackReptNode *)contextStack->fileInfo;
|
struct FileStackReptNode *fileInfo = (struct FileStackReptNode *)contextStack->fileInfo;
|
||||||
@@ -241,11 +235,11 @@ bool yywrap(void)
|
|||||||
/* If this is a FOR, update the symbol value */
|
/* If this is a FOR, update the symbol value */
|
||||||
if (contextStack->forName && fileInfo->iters[0] <= contextStack->nbReptIters) {
|
if (contextStack->forName && fileInfo->iters[0] <= contextStack->nbReptIters) {
|
||||||
contextStack->forValue += contextStack->forStep;
|
contextStack->forValue += contextStack->forStep;
|
||||||
struct Symbol *sym = sym_AddSet(contextStack->forName,
|
struct Symbol *sym = sym_AddVar(contextStack->forName,
|
||||||
contextStack->forValue);
|
contextStack->forValue);
|
||||||
|
|
||||||
/* This error message will refer to the current iteration */
|
/* This error message will refer to the current iteration */
|
||||||
if (sym->type != SYM_SET)
|
if (sym->type != SYM_VAR)
|
||||||
fatalerror("Failed to update FOR symbol value\n");
|
fatalerror("Failed to update FOR symbol value\n");
|
||||||
}
|
}
|
||||||
/* Advance to the next iteration */
|
/* Advance to the next iteration */
|
||||||
@@ -259,7 +253,6 @@ bool yywrap(void)
|
|||||||
} else if (!contextStack->parent) {
|
} else if (!contextStack->parent) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
dbgPrint("Popping context\n");
|
|
||||||
|
|
||||||
struct Context *context = contextStack;
|
struct Context *context = contextStack;
|
||||||
|
|
||||||
@@ -269,10 +262,8 @@ bool yywrap(void)
|
|||||||
|
|
||||||
lexer_DeleteState(context->lexerState);
|
lexer_DeleteState(context->lexerState);
|
||||||
/* Restore args if a macro (not REPT) saved them */
|
/* Restore args if a macro (not REPT) saved them */
|
||||||
if (context->fileInfo->type == NODE_MACRO) {
|
if (context->fileInfo->type == NODE_MACRO)
|
||||||
dbgPrint("Restoring macro args %p\n", (void *)contextStack->macroArgs);
|
|
||||||
macro_UseNewArgs(contextStack->macroArgs);
|
macro_UseNewArgs(contextStack->macroArgs);
|
||||||
}
|
|
||||||
/* Free the file stack node */
|
/* Free the file stack node */
|
||||||
if (!context->fileInfo->referenced)
|
if (!context->fileInfo->referenced)
|
||||||
free(context->fileInfo);
|
free(context->fileInfo);
|
||||||
@@ -293,8 +284,9 @@ bool yywrap(void)
|
|||||||
*/
|
*/
|
||||||
static void newContext(struct FileStackNode *fileInfo)
|
static void newContext(struct FileStackNode *fileInfo)
|
||||||
{
|
{
|
||||||
if (++contextDepth >= nMaxRecursionDepth)
|
++contextDepth;
|
||||||
fatalerror("Recursion limit (%zu) exceeded\n", nMaxRecursionDepth);
|
fstk_NewRecursionDepth(maxRecursionDepth); // Only checks if the max depth was exceeded
|
||||||
|
|
||||||
struct Context *context = malloc(sizeof(*context));
|
struct Context *context = malloc(sizeof(*context));
|
||||||
|
|
||||||
if (!context)
|
if (!context)
|
||||||
@@ -315,24 +307,21 @@ static void newContext(struct FileStackNode *fileInfo)
|
|||||||
|
|
||||||
void fstk_RunInclude(char const *path)
|
void fstk_RunInclude(char const *path)
|
||||||
{
|
{
|
||||||
dbgPrint("Including path \"%s\"\n", path);
|
|
||||||
|
|
||||||
char *fullPath = NULL;
|
char *fullPath = NULL;
|
||||||
size_t size = 0;
|
size_t size = 0;
|
||||||
|
|
||||||
if (!fstk_FindFile(path, &fullPath, &size)) {
|
if (!fstk_FindFile(path, &fullPath, &size)) {
|
||||||
free(fullPath);
|
free(fullPath);
|
||||||
if (oGeneratedMissingIncludes) {
|
if (generatedMissingIncludes) {
|
||||||
if (verbose)
|
if (verbose)
|
||||||
printf("Aborting (-MG) on INCLUDE file '%s' (%s)\n",
|
printf("Aborting (-MG) on INCLUDE file '%s' (%s)\n",
|
||||||
path, strerror(errno));
|
path, strerror(errno));
|
||||||
oFailedOnMissingInclude = true;
|
failedOnMissingInclude = true;
|
||||||
} else {
|
} else {
|
||||||
error("Unable to open included file '%s': %s\n", path, strerror(errno));
|
error("Unable to open included file '%s': %s\n", path, strerror(errno));
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
dbgPrint("Full path: \"%s\"\n", fullPath);
|
|
||||||
|
|
||||||
struct FileStackNamedNode *fileInfo = malloc(sizeof(*fileInfo) + size);
|
struct FileStackNamedNode *fileInfo = malloc(sizeof(*fileInfo) + size);
|
||||||
|
|
||||||
@@ -356,8 +345,6 @@ void fstk_RunInclude(char const *path)
|
|||||||
|
|
||||||
void fstk_RunMacro(char const *macroName, struct MacroArgs *args)
|
void fstk_RunMacro(char const *macroName, struct MacroArgs *args)
|
||||||
{
|
{
|
||||||
dbgPrint("Running macro \"%s\"\n", macroName);
|
|
||||||
|
|
||||||
struct Symbol *macro = sym_FindExactSymbol(macroName);
|
struct Symbol *macro = sym_FindExactSymbol(macroName);
|
||||||
|
|
||||||
if (!macro) {
|
if (!macro) {
|
||||||
@@ -417,7 +404,7 @@ void fstk_RunMacro(char const *macroName, struct MacroArgs *args)
|
|||||||
memcpy(dest, macro->name, macroNameLen + 1);
|
memcpy(dest, macro->name, macroNameLen + 1);
|
||||||
|
|
||||||
newContext((struct FileStackNode *)fileInfo);
|
newContext((struct FileStackNode *)fileInfo);
|
||||||
contextStack->lexerState = lexer_OpenFileView(macro->macro, macro->macroSize,
|
contextStack->lexerState = lexer_OpenFileView("MACRO", macro->macro, macro->macroSize,
|
||||||
macro->fileLine);
|
macro->fileLine);
|
||||||
if (!contextStack->lexerState)
|
if (!contextStack->lexerState)
|
||||||
fatalerror("Failed to set up lexer for macro invocation\n");
|
fatalerror("Failed to set up lexer for macro invocation\n");
|
||||||
@@ -451,7 +438,7 @@ static bool newReptContext(int32_t reptLineNo, char *body, size_t size)
|
|||||||
/* Correct our line number, which currently points to the `ENDR` line */
|
/* Correct our line number, which currently points to the `ENDR` line */
|
||||||
contextStack->fileInfo->lineNo = reptLineNo;
|
contextStack->fileInfo->lineNo = reptLineNo;
|
||||||
|
|
||||||
contextStack->lexerState = lexer_OpenFileView(body, size, reptLineNo);
|
contextStack->lexerState = lexer_OpenFileView("REPT", body, size, reptLineNo);
|
||||||
if (!contextStack->lexerState)
|
if (!contextStack->lexerState)
|
||||||
fatalerror("Failed to set up lexer for REPT block\n");
|
fatalerror("Failed to set up lexer for REPT block\n");
|
||||||
lexer_SetStateAtEOL(contextStack->lexerState);
|
lexer_SetStateAtEOL(contextStack->lexerState);
|
||||||
@@ -461,8 +448,6 @@ static bool newReptContext(int32_t reptLineNo, char *body, size_t size)
|
|||||||
|
|
||||||
void fstk_RunRept(uint32_t count, int32_t reptLineNo, char *body, size_t size)
|
void fstk_RunRept(uint32_t count, int32_t reptLineNo, char *body, size_t size)
|
||||||
{
|
{
|
||||||
dbgPrint("Running REPT(%" PRIu32 ")\n", count);
|
|
||||||
|
|
||||||
if (count == 0)
|
if (count == 0)
|
||||||
return;
|
return;
|
||||||
if (!newReptContext(reptLineNo, body, size))
|
if (!newReptContext(reptLineNo, body, size))
|
||||||
@@ -475,12 +460,9 @@ void fstk_RunRept(uint32_t count, int32_t reptLineNo, char *body, size_t size)
|
|||||||
void fstk_RunFor(char const *symName, int32_t start, int32_t stop, int32_t step,
|
void fstk_RunFor(char const *symName, int32_t start, int32_t stop, int32_t step,
|
||||||
int32_t reptLineNo, char *body, size_t size)
|
int32_t reptLineNo, char *body, size_t size)
|
||||||
{
|
{
|
||||||
dbgPrint("Running FOR(\"%s\", %" PRId32 ", %" PRId32 ", %" PRId32 ")\n",
|
struct Symbol *sym = sym_AddVar(symName, start);
|
||||||
symName, start, stop, step);
|
|
||||||
|
|
||||||
struct Symbol *sym = sym_AddSet(symName, start);
|
if (sym->type != SYM_VAR)
|
||||||
|
|
||||||
if (sym->type != SYM_SET)
|
|
||||||
return;
|
return;
|
||||||
|
|
||||||
uint32_t count = 0;
|
uint32_t count = 0;
|
||||||
@@ -517,8 +499,6 @@ void fstk_StopRept(void)
|
|||||||
|
|
||||||
bool fstk_Break(void)
|
bool fstk_Break(void)
|
||||||
{
|
{
|
||||||
dbgPrint("Breaking out of REPT/FOR\n");
|
|
||||||
|
|
||||||
if (contextStack->fileInfo->type != NODE_REPT) {
|
if (contextStack->fileInfo->type != NODE_REPT) {
|
||||||
error("BREAK can only be used inside a REPT/FOR block\n");
|
error("BREAK can only be used inside a REPT/FOR block\n");
|
||||||
return false;
|
return false;
|
||||||
@@ -528,7 +508,14 @@ bool fstk_Break(void)
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void fstk_Init(char const *mainPath, size_t maxRecursionDepth)
|
void fstk_NewRecursionDepth(size_t newDepth)
|
||||||
|
{
|
||||||
|
if (contextDepth >= newDepth)
|
||||||
|
fatalerror("Recursion limit (%zu) exceeded\n", newDepth);
|
||||||
|
maxRecursionDepth = newDepth;
|
||||||
|
}
|
||||||
|
|
||||||
|
void fstk_Init(char const *mainPath, size_t maxDepth)
|
||||||
{
|
{
|
||||||
struct LexerState *state = lexer_OpenFile(mainPath);
|
struct LexerState *state = lexer_OpenFile(mainPath);
|
||||||
|
|
||||||
@@ -570,12 +557,12 @@ void fstk_Init(char const *mainPath, size_t maxRecursionDepth)
|
|||||||
* This assumes that the rept node is larger
|
* This assumes that the rept node is larger
|
||||||
*/
|
*/
|
||||||
#define DEPTH_LIMIT ((SIZE_MAX - sizeof(struct FileStackReptNode)) / sizeof(uint32_t))
|
#define DEPTH_LIMIT ((SIZE_MAX - sizeof(struct FileStackReptNode)) / sizeof(uint32_t))
|
||||||
if (maxRecursionDepth > DEPTH_LIMIT) {
|
if (maxDepth > DEPTH_LIMIT) {
|
||||||
error("Recursion depth may not be higher than %zu, defaulting to "
|
error("Recursion depth may not be higher than %zu, defaulting to "
|
||||||
EXPAND_AND_STR(DEFAULT_MAX_DEPTH) "\n", DEPTH_LIMIT);
|
EXPAND_AND_STR(DEFAULT_MAX_DEPTH) "\n", DEPTH_LIMIT);
|
||||||
nMaxRecursionDepth = DEFAULT_MAX_DEPTH;
|
maxRecursionDepth = DEFAULT_MAX_DEPTH;
|
||||||
} else {
|
} else {
|
||||||
nMaxRecursionDepth = maxRecursionDepth;
|
maxRecursionDepth = maxDepth;
|
||||||
}
|
}
|
||||||
/* Make sure that the default of 64 is OK, though */
|
/* Make sure that the default of 64 is OK, though */
|
||||||
assert(DEPTH_LIMIT >= DEFAULT_MAX_DEPTH);
|
assert(DEPTH_LIMIT >= DEFAULT_MAX_DEPTH);
|
||||||
|
|||||||
841
src/asm/lexer.c
841
src/asm/lexer.c
File diff suppressed because it is too large
Load Diff
@@ -101,7 +101,7 @@ char const *macro_GetArg(uint32_t i)
|
|||||||
: macroArgs->args[realIndex];
|
: macroArgs->args[realIndex];
|
||||||
}
|
}
|
||||||
|
|
||||||
char *macro_GetAllArgs(void)
|
char const *macro_GetAllArgs(void)
|
||||||
{
|
{
|
||||||
if (!macroArgs)
|
if (!macroArgs)
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|||||||
129
src/asm/main.c
129
src/asm/main.c
@@ -30,39 +30,47 @@
|
|||||||
#include "asm/warning.h"
|
#include "asm/warning.h"
|
||||||
#include "parser.h"
|
#include "parser.h"
|
||||||
|
|
||||||
#include "extern/err.h"
|
|
||||||
#include "extern/getopt.h"
|
#include "extern/getopt.h"
|
||||||
|
|
||||||
#include "helpers.h"
|
#include "helpers.h"
|
||||||
|
#include "error.h"
|
||||||
#include "version.h"
|
#include "version.h"
|
||||||
|
|
||||||
|
#ifdef __clang__
|
||||||
|
#if __has_feature(address_sanitizer) && !defined(__SANITIZE_ADDRESS__)
|
||||||
|
#define __SANITIZE_ADDRESS__
|
||||||
|
#endif /* __has_feature(address_sanitizer) && !defined(__SANITIZE_ADDRESS__) */
|
||||||
|
#endif /* __clang__ */
|
||||||
|
|
||||||
|
#ifdef __SANITIZE_ADDRESS__
|
||||||
|
// There are known, non-trivial to fix leaks. We would still like to have `make develop'
|
||||||
|
// detect memory corruption, though.
|
||||||
|
char const *__asan_default_options(void) { return "detect_leaks=0"; }
|
||||||
|
#endif
|
||||||
|
|
||||||
// Old Bison versions (confirmed for 2.3) do not forward-declare `yyparse` in the generated header
|
// Old Bison versions (confirmed for 2.3) do not forward-declare `yyparse` in the generated header
|
||||||
// Unfortunately, macOS still ships 2.3, which is from 2008...
|
// Unfortunately, macOS still ships 2.3, which is from 2008...
|
||||||
int yyparse(void);
|
int yyparse(void);
|
||||||
|
|
||||||
#if defined(YYDEBUG) && YYDEBUG
|
|
||||||
extern int yydebug;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
FILE * dependfile;
|
FILE * dependfile;
|
||||||
bool oGeneratedMissingIncludes;
|
bool generatedMissingIncludes;
|
||||||
bool oFailedOnMissingInclude;
|
bool failedOnMissingInclude;
|
||||||
bool oGeneratePhonyDeps;
|
bool generatePhonyDeps;
|
||||||
char *tzTargetFileName;
|
char *targetFileName;
|
||||||
|
|
||||||
bool haltnop;
|
bool haltnop;
|
||||||
bool optimizeloads;
|
bool optimizeLoads;
|
||||||
bool verbose;
|
bool verbose;
|
||||||
bool warnings; /* True to enable warnings, false to disable them. */
|
bool warnings; /* True to enable warnings, false to disable them. */
|
||||||
|
|
||||||
/* Escapes Make-special chars from a string */
|
/* Escapes Make-special chars from a string */
|
||||||
static char *make_escape(const char *str)
|
static char *make_escape(char const *str)
|
||||||
{
|
{
|
||||||
char * const escaped_str = malloc(strlen(str) * 2 + 1);
|
char * const escaped_str = malloc(strlen(str) * 2 + 1);
|
||||||
char *dest = escaped_str;
|
char *dest = escaped_str;
|
||||||
|
|
||||||
if (escaped_str == NULL)
|
if (escaped_str == NULL)
|
||||||
err(1, "%s: Failed to allocate memory", __func__);
|
err("%s: Failed to allocate memory", __func__);
|
||||||
|
|
||||||
while (*str) {
|
while (*str) {
|
||||||
/* All dollars needs to be doubled */
|
/* All dollars needs to be doubled */
|
||||||
@@ -134,6 +142,9 @@ static void print_usage(void)
|
|||||||
|
|
||||||
int main(int argc, char *argv[])
|
int main(int argc, char *argv[])
|
||||||
{
|
{
|
||||||
|
#if YYDEBUG
|
||||||
|
yydebug = 1;
|
||||||
|
#endif
|
||||||
int ch;
|
int ch;
|
||||||
char *ep;
|
char *ep;
|
||||||
|
|
||||||
@@ -149,30 +160,26 @@ int main(int argc, char *argv[])
|
|||||||
|
|
||||||
dependfile = NULL;
|
dependfile = NULL;
|
||||||
|
|
||||||
#if defined(YYDEBUG) && YYDEBUG
|
|
||||||
yydebug = 1;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
// Perform some init for below
|
// Perform some init for below
|
||||||
sym_Init(now);
|
sym_Init(now);
|
||||||
|
|
||||||
// Set defaults
|
// Set defaults
|
||||||
|
|
||||||
oGeneratePhonyDeps = false;
|
generatePhonyDeps = false;
|
||||||
oGeneratedMissingIncludes = false;
|
generatedMissingIncludes = false;
|
||||||
oFailedOnMissingInclude = false;
|
failedOnMissingInclude = false;
|
||||||
tzTargetFileName = NULL;
|
targetFileName = NULL;
|
||||||
|
|
||||||
opt_B("01");
|
opt_B("01");
|
||||||
opt_G("0123");
|
opt_G("0123");
|
||||||
opt_P(0);
|
opt_P(0);
|
||||||
optimizeloads = true;
|
optimizeLoads = true;
|
||||||
haltnop = true;
|
haltnop = true;
|
||||||
verbose = false;
|
verbose = false;
|
||||||
warnings = true;
|
warnings = true;
|
||||||
sym_SetExportAll(false);
|
sym_SetExportAll(false);
|
||||||
uint32_t maxRecursionDepth = 64;
|
uint32_t maxDepth = 64;
|
||||||
size_t nTargetFileNameLen = 0;
|
size_t targetFileNameLen = 0;
|
||||||
|
|
||||||
while ((ch = musl_getopt_long_only(argc, argv, optstring, longopts, NULL)) != -1) {
|
while ((ch = musl_getopt_long_only(argc, argv, optstring, longopts, NULL)) != -1) {
|
||||||
switch (ch) {
|
switch (ch) {
|
||||||
@@ -180,7 +187,7 @@ int main(int argc, char *argv[])
|
|||||||
if (strlen(musl_optarg) == 2)
|
if (strlen(musl_optarg) == 2)
|
||||||
opt_B(&musl_optarg[1]);
|
opt_B(&musl_optarg[1]);
|
||||||
else
|
else
|
||||||
errx(1, "Must specify exactly 2 characters for option 'b'");
|
errx("Must specify exactly 2 characters for option 'b'");
|
||||||
break;
|
break;
|
||||||
|
|
||||||
char *equals;
|
char *equals;
|
||||||
@@ -202,7 +209,7 @@ int main(int argc, char *argv[])
|
|||||||
if (strlen(musl_optarg) == 4)
|
if (strlen(musl_optarg) == 4)
|
||||||
opt_G(&musl_optarg[1]);
|
opt_G(&musl_optarg[1]);
|
||||||
else
|
else
|
||||||
errx(1, "Must specify exactly 4 characters for option 'g'");
|
errx("Must specify exactly 4 characters for option 'g'");
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 'h':
|
case 'h':
|
||||||
@@ -214,7 +221,7 @@ int main(int argc, char *argv[])
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
case 'L':
|
case 'L':
|
||||||
optimizeloads = false;
|
optimizeLoads = false;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 'M':
|
case 'M':
|
||||||
@@ -223,7 +230,7 @@ int main(int argc, char *argv[])
|
|||||||
else
|
else
|
||||||
dependfile = fopen(musl_optarg, "w");
|
dependfile = fopen(musl_optarg, "w");
|
||||||
if (dependfile == NULL)
|
if (dependfile == NULL)
|
||||||
err(1, "Could not open dependfile %s", musl_optarg);
|
err("Could not open dependfile %s", musl_optarg);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 'o':
|
case 'o':
|
||||||
@@ -235,19 +242,19 @@ int main(int argc, char *argv[])
|
|||||||
fill = strtoul(musl_optarg, &ep, 0);
|
fill = strtoul(musl_optarg, &ep, 0);
|
||||||
|
|
||||||
if (musl_optarg[0] == '\0' || *ep != '\0')
|
if (musl_optarg[0] == '\0' || *ep != '\0')
|
||||||
errx(1, "Invalid argument for option 'p'");
|
errx("Invalid argument for option 'p'");
|
||||||
|
|
||||||
if (fill < 0 || fill > 0xFF)
|
if (fill > 0xFF)
|
||||||
errx(1, "Argument for option 'p' must be between 0 and 0xFF");
|
errx("Argument for option 'p' must be between 0 and 0xFF");
|
||||||
|
|
||||||
opt_P(fill);
|
opt_P(fill);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 'r':
|
case 'r':
|
||||||
maxRecursionDepth = strtoul(musl_optarg, &ep, 0);
|
maxDepth = strtoul(musl_optarg, &ep, 0);
|
||||||
|
|
||||||
if (musl_optarg[0] == '\0' || *ep != '\0')
|
if (musl_optarg[0] == '\0' || *ep != '\0')
|
||||||
errx(1, "Invalid argument for option 'r'");
|
errx("Invalid argument for option 'r'");
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 'V':
|
case 'V':
|
||||||
@@ -269,40 +276,30 @@ int main(int argc, char *argv[])
|
|||||||
case 0:
|
case 0:
|
||||||
switch (depType) {
|
switch (depType) {
|
||||||
case 'G':
|
case 'G':
|
||||||
oGeneratedMissingIncludes = true;
|
generatedMissingIncludes = true;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 'P':
|
case 'P':
|
||||||
oGeneratePhonyDeps = true;
|
generatePhonyDeps = true;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
char *newTarget;
|
||||||
case 'Q':
|
case 'Q':
|
||||||
case 'T':
|
case 'T':
|
||||||
if (musl_optind == argc)
|
newTarget = musl_optarg;
|
||||||
errx(1, "-M%c takes a target file name argument", depType);
|
|
||||||
ep = musl_optarg;
|
|
||||||
if (depType == 'Q')
|
if (depType == 'Q')
|
||||||
ep = make_escape(ep);
|
newTarget = make_escape(newTarget);
|
||||||
|
size_t newTargetLen = strlen(newTarget) + 1; // Plus the space
|
||||||
|
|
||||||
nTargetFileNameLen += strlen(ep) + 1;
|
targetFileName = realloc(targetFileName,
|
||||||
if (!tzTargetFileName) {
|
targetFileNameLen + newTargetLen + 1);
|
||||||
/* On first alloc, make an empty str */
|
if (targetFileName == NULL)
|
||||||
tzTargetFileName = malloc(nTargetFileNameLen + 1);
|
err("Cannot append new file to target file list");
|
||||||
if (tzTargetFileName)
|
memcpy(&targetFileName[targetFileNameLen], newTarget, newTargetLen);
|
||||||
*tzTargetFileName = '\0';
|
|
||||||
} else {
|
|
||||||
tzTargetFileName = realloc(tzTargetFileName,
|
|
||||||
nTargetFileNameLen + 1);
|
|
||||||
}
|
|
||||||
if (tzTargetFileName == NULL)
|
|
||||||
err(1, "Cannot append new file to target file list");
|
|
||||||
strcat(tzTargetFileName, ep);
|
|
||||||
if (depType == 'Q')
|
if (depType == 'Q')
|
||||||
free(ep);
|
free(newTarget);
|
||||||
char *ptr = tzTargetFileName + strlen(tzTargetFileName);
|
targetFileNameLen += newTargetLen;
|
||||||
|
targetFileName[targetFileNameLen - 1] = ' ';
|
||||||
*ptr++ = ' ';
|
|
||||||
*ptr = '\0';
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
@@ -314,8 +311,10 @@ int main(int argc, char *argv[])
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (tzTargetFileName == NULL)
|
if (targetFileName == NULL)
|
||||||
tzTargetFileName = tzObjectname;
|
targetFileName = objectName;
|
||||||
|
else
|
||||||
|
targetFileName[targetFileNameLen - 1] = '\0'; // Overwrite the last space
|
||||||
|
|
||||||
if (argc == musl_optind) {
|
if (argc == musl_optind) {
|
||||||
fputs("FATAL: No input files\n", stderr);
|
fputs("FATAL: No input files\n", stderr);
|
||||||
@@ -331,17 +330,17 @@ int main(int argc, char *argv[])
|
|||||||
printf("Assembling %s\n", mainFileName);
|
printf("Assembling %s\n", mainFileName);
|
||||||
|
|
||||||
if (dependfile) {
|
if (dependfile) {
|
||||||
if (!tzTargetFileName)
|
if (!targetFileName)
|
||||||
errx(1, "Dependency files can only be created if a target file is specified with either -o, -MQ or -MT\n");
|
errx("Dependency files can only be created if a target file is specified with either -o, -MQ or -MT");
|
||||||
|
|
||||||
fprintf(dependfile, "%s: %s\n", tzTargetFileName, mainFileName);
|
fprintf(dependfile, "%s: %s\n", targetFileName, mainFileName);
|
||||||
}
|
}
|
||||||
|
|
||||||
charmap_New("main", NULL);
|
charmap_New("main", NULL);
|
||||||
|
|
||||||
// Init lexer and file stack, prodiving file info
|
// Init lexer and file stack, prodiving file info
|
||||||
lexer_Init();
|
lexer_Init();
|
||||||
fstk_Init(mainFileName, maxRecursionDepth);
|
fstk_Init(mainFileName, maxDepth);
|
||||||
|
|
||||||
// Perform parse (yyparse is auto-generated from `parser.y`)
|
// Perform parse (yyparse is auto-generated from `parser.y`)
|
||||||
if (yyparse() != 0 && nbErrors == 0)
|
if (yyparse() != 0 && nbErrors == 0)
|
||||||
@@ -353,15 +352,15 @@ int main(int argc, char *argv[])
|
|||||||
sect_CheckUnionClosed();
|
sect_CheckUnionClosed();
|
||||||
|
|
||||||
if (nbErrors != 0)
|
if (nbErrors != 0)
|
||||||
errx(1, "Assembly aborted (%u error%s)!", nbErrors,
|
errx("Assembly aborted (%u error%s)!", nbErrors,
|
||||||
nbErrors == 1 ? "" : "s");
|
nbErrors == 1 ? "" : "s");
|
||||||
|
|
||||||
// If parse aborted due to missing an include, and `-MG` was given, exit normally
|
// If parse aborted due to missing an include, and `-MG` was given, exit normally
|
||||||
if (oFailedOnMissingInclude)
|
if (failedOnMissingInclude)
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
/* If no path specified, don't write file */
|
/* If no path specified, don't write file */
|
||||||
if (tzObjectname != NULL)
|
if (objectName != NULL)
|
||||||
out_WriteObject();
|
out_WriteObject();
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|||||||
116
src/asm/opt.c
116
src/asm/opt.c
@@ -1,4 +1,4 @@
|
|||||||
|
#include <ctype.h>
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
#include <stdbool.h>
|
#include <stdbool.h>
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
@@ -6,7 +6,9 @@
|
|||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
|
#include "asm/fstack.h"
|
||||||
#include "asm/lexer.h"
|
#include "asm/lexer.h"
|
||||||
|
#include "asm/main.h"
|
||||||
#include "asm/section.h"
|
#include "asm/section.h"
|
||||||
#include "asm/warning.h"
|
#include "asm/warning.h"
|
||||||
|
|
||||||
@@ -14,17 +16,23 @@ struct OptStackEntry {
|
|||||||
char binary[2];
|
char binary[2];
|
||||||
char gbgfx[4];
|
char gbgfx[4];
|
||||||
int32_t fillByte;
|
int32_t fillByte;
|
||||||
|
bool haltnop;
|
||||||
|
bool optimizeLoads;
|
||||||
|
bool warningsAreErrors;
|
||||||
|
size_t maxRecursionDepth;
|
||||||
|
// Don't be confused: we use the size of the **global variable** `warningStates`!
|
||||||
|
enum WarningState warningStates[sizeof(warningStates)];
|
||||||
struct OptStackEntry *next;
|
struct OptStackEntry *next;
|
||||||
};
|
};
|
||||||
|
|
||||||
static struct OptStackEntry *stack = NULL;
|
static struct OptStackEntry *stack = NULL;
|
||||||
|
|
||||||
void opt_B(char chars[2])
|
void opt_B(char const chars[2])
|
||||||
{
|
{
|
||||||
lexer_SetBinDigits(chars);
|
lexer_SetBinDigits(chars);
|
||||||
}
|
}
|
||||||
|
|
||||||
void opt_G(char chars[4])
|
void opt_G(char const chars[4])
|
||||||
{
|
{
|
||||||
lexer_SetGfxDigits(chars);
|
lexer_SetGfxDigits(chars);
|
||||||
}
|
}
|
||||||
@@ -34,6 +42,27 @@ void opt_P(uint8_t fill)
|
|||||||
fillByte = fill;
|
fillByte = fill;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void opt_R(size_t newDepth)
|
||||||
|
{
|
||||||
|
fstk_NewRecursionDepth(newDepth);
|
||||||
|
lexer_CheckRecursionDepth();
|
||||||
|
}
|
||||||
|
|
||||||
|
void opt_h(bool halt)
|
||||||
|
{
|
||||||
|
haltnop = halt;
|
||||||
|
}
|
||||||
|
|
||||||
|
void opt_L(bool optimize)
|
||||||
|
{
|
||||||
|
optimizeLoads = optimize;
|
||||||
|
}
|
||||||
|
|
||||||
|
void opt_W(char *flag)
|
||||||
|
{
|
||||||
|
processWarningFlag(flag);
|
||||||
|
}
|
||||||
|
|
||||||
void opt_Parse(char *s)
|
void opt_Parse(char *s)
|
||||||
{
|
{
|
||||||
switch (s[0]) {
|
switch (s[0]) {
|
||||||
@@ -66,6 +95,72 @@ void opt_Parse(char *s)
|
|||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
case 'r': {
|
||||||
|
++s; // Skip 'r'
|
||||||
|
while (isblank(*s))
|
||||||
|
++s; // Skip leading whitespace
|
||||||
|
|
||||||
|
if (s[0] == '\0') {
|
||||||
|
error("Missing argument to option 'r'\n");
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
char *endptr;
|
||||||
|
unsigned long newDepth = strtoul(s, &endptr, 10);
|
||||||
|
|
||||||
|
if (*endptr != '\0') {
|
||||||
|
error("Invalid argument to option 'r' (\"%s\")\n", s);
|
||||||
|
} else if (errno == ERANGE) {
|
||||||
|
error("Argument to 'r' is out of range (\"%s\")\n", s);
|
||||||
|
} else {
|
||||||
|
opt_R(newDepth);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
case 'h':
|
||||||
|
if (s[1] == '\0')
|
||||||
|
opt_h(false);
|
||||||
|
else
|
||||||
|
error("Option 'h' does not take an argument\n");
|
||||||
|
break;
|
||||||
|
|
||||||
|
case 'L':
|
||||||
|
if (s[1] == '\0')
|
||||||
|
opt_L(false);
|
||||||
|
else
|
||||||
|
error("Option 'L' does not take an argument\n");
|
||||||
|
break;
|
||||||
|
|
||||||
|
case 'W':
|
||||||
|
if (strlen(&s[1]) > 0)
|
||||||
|
opt_W(&s[1]);
|
||||||
|
else
|
||||||
|
error("Must specify an argument for option 'W'\n");
|
||||||
|
break;
|
||||||
|
|
||||||
|
case '!': // negates flag options that do not take an argument
|
||||||
|
switch (s[1]) {
|
||||||
|
case 'h':
|
||||||
|
if (s[2] == '\0')
|
||||||
|
opt_h(true);
|
||||||
|
else
|
||||||
|
error("Option '!h' does not take an argument\n");
|
||||||
|
break;
|
||||||
|
|
||||||
|
case 'L':
|
||||||
|
if (s[2] == '\0')
|
||||||
|
opt_L(true);
|
||||||
|
else
|
||||||
|
error("Option '!L' does not take an argument\n");
|
||||||
|
break;
|
||||||
|
|
||||||
|
default:
|
||||||
|
error("Unknown option '!%c'\n", s[1]);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
error("Unknown option '%c'\n", s[0]);
|
error("Unknown option '%c'\n", s[0]);
|
||||||
break;
|
break;
|
||||||
@@ -90,6 +185,14 @@ void opt_Push(void)
|
|||||||
|
|
||||||
entry->fillByte = fillByte; // Pulled from section.h
|
entry->fillByte = fillByte; // Pulled from section.h
|
||||||
|
|
||||||
|
entry->haltnop = haltnop; // Pulled from main.h
|
||||||
|
|
||||||
|
entry->optimizeLoads = optimizeLoads; // Pulled from main.h
|
||||||
|
|
||||||
|
// Both of these pulled from warning.h
|
||||||
|
entry->warningsAreErrors = warningsAreErrors;
|
||||||
|
memcpy(entry->warningStates, warningStates, sizeof(warningStates));
|
||||||
|
|
||||||
entry->next = stack;
|
entry->next = stack;
|
||||||
stack = entry;
|
stack = entry;
|
||||||
}
|
}
|
||||||
@@ -106,6 +209,13 @@ void opt_Pop(void)
|
|||||||
opt_B(entry->binary);
|
opt_B(entry->binary);
|
||||||
opt_G(entry->gbgfx);
|
opt_G(entry->gbgfx);
|
||||||
opt_P(entry->fillByte);
|
opt_P(entry->fillByte);
|
||||||
|
opt_h(entry->haltnop);
|
||||||
|
opt_L(entry->optimizeLoads);
|
||||||
|
|
||||||
|
// opt_W does not apply a whole warning state; it processes one flag string
|
||||||
|
warningsAreErrors = entry->warningsAreErrors;
|
||||||
|
memcpy(warningStates, entry->warningStates, sizeof(warningStates));
|
||||||
|
|
||||||
stack = entry->next;
|
stack = entry->next;
|
||||||
free(entry);
|
free(entry);
|
||||||
}
|
}
|
||||||
|
|||||||
142
src/asm/output.c
142
src/asm/output.c
@@ -27,20 +27,19 @@
|
|||||||
#include "asm/symbol.h"
|
#include "asm/symbol.h"
|
||||||
#include "asm/warning.h"
|
#include "asm/warning.h"
|
||||||
|
|
||||||
#include "extern/err.h"
|
#include "error.h"
|
||||||
|
|
||||||
#include "linkdefs.h"
|
#include "linkdefs.h"
|
||||||
#include "platform.h" // strdup
|
#include "platform.h" // strdup
|
||||||
|
|
||||||
struct Patch {
|
struct Patch {
|
||||||
struct FileStackNode const *src;
|
struct FileStackNode const *src;
|
||||||
uint32_t lineNo;
|
uint32_t lineNo;
|
||||||
uint32_t nOffset;
|
uint32_t offset;
|
||||||
struct Section *pcSection;
|
struct Section *pcSection;
|
||||||
uint32_t pcOffset;
|
uint32_t pcOffset;
|
||||||
uint8_t type;
|
uint8_t type;
|
||||||
uint32_t nRPNSize;
|
uint32_t rpnSize;
|
||||||
uint8_t *pRPN;
|
uint8_t *rpn;
|
||||||
struct Patch *next;
|
struct Patch *next;
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -51,10 +50,9 @@ struct Assertion {
|
|||||||
struct Assertion *next;
|
struct Assertion *next;
|
||||||
};
|
};
|
||||||
|
|
||||||
char *tzObjectname;
|
char *objectName;
|
||||||
|
|
||||||
/* TODO: shouldn't `pCurrentSection` be somewhere else? */
|
struct Section *sectionList;
|
||||||
struct Section *pSectionList, *pCurrentSection;
|
|
||||||
|
|
||||||
/* Linked list of symbols to put in the object file */
|
/* Linked list of symbols to put in the object file */
|
||||||
static struct Symbol *objectSymbols = NULL;
|
static struct Symbol *objectSymbols = NULL;
|
||||||
@@ -72,7 +70,7 @@ static uint32_t countSections(void)
|
|||||||
{
|
{
|
||||||
uint32_t count = 0;
|
uint32_t count = 0;
|
||||||
|
|
||||||
for (struct Section const *sect = pSectionList; sect; sect = sect->next)
|
for (struct Section const *sect = sectionList; sect; sect = sect->next)
|
||||||
count++;
|
count++;
|
||||||
|
|
||||||
return count;
|
return count;
|
||||||
@@ -179,7 +177,7 @@ This is code intended to replace a node, which is pretty useless until ref count
|
|||||||
*/
|
*/
|
||||||
static uint32_t getsectid(struct Section const *sect)
|
static uint32_t getsectid(struct Section const *sect)
|
||||||
{
|
{
|
||||||
struct Section const *sec = pSectionList;
|
struct Section const *sec = sectionList;
|
||||||
uint32_t ID = 0;
|
uint32_t ID = 0;
|
||||||
|
|
||||||
while (sec) {
|
while (sec) {
|
||||||
@@ -194,7 +192,7 @@ static uint32_t getsectid(struct Section const *sect)
|
|||||||
|
|
||||||
static uint32_t getSectIDIfAny(struct Section const *sect)
|
static uint32_t getSectIDIfAny(struct Section const *sect)
|
||||||
{
|
{
|
||||||
return sect ? getsectid(sect) : -1;
|
return sect ? getsectid(sect) : (uint32_t)-1;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@@ -202,15 +200,15 @@ static uint32_t getSectIDIfAny(struct Section const *sect)
|
|||||||
*/
|
*/
|
||||||
static void writepatch(struct Patch const *patch, FILE *f)
|
static void writepatch(struct Patch const *patch, FILE *f)
|
||||||
{
|
{
|
||||||
assert(patch->src->ID != -1);
|
assert(patch->src->ID != (uint32_t)-1);
|
||||||
putlong(patch->src->ID, f);
|
putlong(patch->src->ID, f);
|
||||||
putlong(patch->lineNo, f);
|
putlong(patch->lineNo, f);
|
||||||
putlong(patch->nOffset, f);
|
putlong(patch->offset, f);
|
||||||
putlong(getSectIDIfAny(patch->pcSection), f);
|
putlong(getSectIDIfAny(patch->pcSection), f);
|
||||||
putlong(patch->pcOffset, f);
|
putlong(patch->pcOffset, f);
|
||||||
putc(patch->type, f);
|
putc(patch->type, f);
|
||||||
putlong(patch->nRPNSize, f);
|
putlong(patch->rpnSize, f);
|
||||||
fwrite(patch->pRPN, 1, patch->nRPNSize, f);
|
fwrite(patch->rpn, 1, patch->rpnSize, f);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@@ -242,6 +240,21 @@ static void writesection(struct Section const *sect, FILE *f)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void freesection(struct Section const *sect)
|
||||||
|
{
|
||||||
|
if (sect_HasData(sect->type)) {
|
||||||
|
struct Patch *patch = sect->patches;
|
||||||
|
|
||||||
|
while (patch != NULL) {
|
||||||
|
struct Patch *next = patch->next;
|
||||||
|
|
||||||
|
free(patch->rpn);
|
||||||
|
free(patch);
|
||||||
|
patch = next;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Write a symbol to a file
|
* Write a symbol to a file
|
||||||
*/
|
*/
|
||||||
@@ -251,7 +264,7 @@ static void writesymbol(struct Symbol const *sym, FILE *f)
|
|||||||
if (!sym_IsDefined(sym)) {
|
if (!sym_IsDefined(sym)) {
|
||||||
putc(SYMTYPE_IMPORT, f);
|
putc(SYMTYPE_IMPORT, f);
|
||||||
} else {
|
} else {
|
||||||
assert(sym->src->ID != -1);
|
assert(sym->src->ID != (uint32_t)-1);
|
||||||
|
|
||||||
putc(sym->isExported ? SYMTYPE_EXPORT : SYMTYPE_LOCAL, f);
|
putc(sym->isExported ? SYMTYPE_EXPORT : SYMTYPE_LOCAL, f);
|
||||||
putlong(sym->src->ID, f);
|
putlong(sym->src->ID, f);
|
||||||
@@ -286,7 +299,7 @@ static uint32_t getSymbolID(struct Symbol *sym)
|
|||||||
static void writerpn(uint8_t *rpnexpr, uint32_t *rpnptr, uint8_t *rpn,
|
static void writerpn(uint8_t *rpnexpr, uint32_t *rpnptr, uint8_t *rpn,
|
||||||
uint32_t rpnlen)
|
uint32_t rpnlen)
|
||||||
{
|
{
|
||||||
char tzSym[512];
|
char symName[512];
|
||||||
|
|
||||||
for (size_t offset = 0; offset < rpnlen; ) {
|
for (size_t offset = 0; offset < rpnlen; ) {
|
||||||
#define popbyte() rpn[offset++]
|
#define popbyte() rpn[offset++]
|
||||||
@@ -310,14 +323,14 @@ static void writerpn(uint8_t *rpnexpr, uint32_t *rpnptr, uint8_t *rpn,
|
|||||||
case RPN_SYM:
|
case RPN_SYM:
|
||||||
i = 0;
|
i = 0;
|
||||||
do {
|
do {
|
||||||
tzSym[i] = popbyte();
|
symName[i] = popbyte();
|
||||||
} while (tzSym[i++]);
|
} while (symName[i++]);
|
||||||
|
|
||||||
// The symbol name is always written expanded
|
// The symbol name is always written expanded
|
||||||
sym = sym_FindExactSymbol(tzSym);
|
sym = sym_FindExactSymbol(symName);
|
||||||
if (sym_IsConstant(sym)) {
|
if (sym_IsConstant(sym)) {
|
||||||
writebyte(RPN_CONST);
|
writebyte(RPN_CONST);
|
||||||
value = sym_GetConstantValue(tzSym);
|
value = sym_GetConstantValue(symName);
|
||||||
} else {
|
} else {
|
||||||
writebyte(RPN_SYM);
|
writebyte(RPN_SYM);
|
||||||
value = getSymbolID(sym);
|
value = getSymbolID(sym);
|
||||||
@@ -332,11 +345,11 @@ static void writerpn(uint8_t *rpnexpr, uint32_t *rpnptr, uint8_t *rpn,
|
|||||||
case RPN_BANK_SYM:
|
case RPN_BANK_SYM:
|
||||||
i = 0;
|
i = 0;
|
||||||
do {
|
do {
|
||||||
tzSym[i] = popbyte();
|
symName[i] = popbyte();
|
||||||
} while (tzSym[i++]);
|
} while (symName[i++]);
|
||||||
|
|
||||||
// The symbol name is always written expanded
|
// The symbol name is always written expanded
|
||||||
sym = sym_FindExactSymbol(tzSym);
|
sym = sym_FindExactSymbol(symName);
|
||||||
value = getSymbolID(sym);
|
value = getSymbolID(sym);
|
||||||
|
|
||||||
writebyte(RPN_BANK_SYM);
|
writebyte(RPN_BANK_SYM);
|
||||||
@@ -354,6 +367,22 @@ static void writerpn(uint8_t *rpnexpr, uint32_t *rpnptr, uint8_t *rpn,
|
|||||||
} while (b != 0);
|
} while (b != 0);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
case RPN_SIZEOF_SECT:
|
||||||
|
writebyte(RPN_SIZEOF_SECT);
|
||||||
|
do {
|
||||||
|
b = popbyte();
|
||||||
|
writebyte(b);
|
||||||
|
} while (b != 0);
|
||||||
|
break;
|
||||||
|
|
||||||
|
case RPN_STARTOF_SECT:
|
||||||
|
writebyte(RPN_STARTOF_SECT);
|
||||||
|
do {
|
||||||
|
b = popbyte();
|
||||||
|
writebyte(b);
|
||||||
|
} while (b != 0);
|
||||||
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
writebyte(rpndata);
|
writebyte(rpndata);
|
||||||
break;
|
break;
|
||||||
@@ -370,38 +399,38 @@ static void writerpn(uint8_t *rpnexpr, uint32_t *rpnptr, uint8_t *rpn,
|
|||||||
static struct Patch *allocpatch(uint32_t type, struct Expression const *expr, uint32_t ofs)
|
static struct Patch *allocpatch(uint32_t type, struct Expression const *expr, uint32_t ofs)
|
||||||
{
|
{
|
||||||
struct Patch *patch = malloc(sizeof(struct Patch));
|
struct Patch *patch = malloc(sizeof(struct Patch));
|
||||||
uint32_t rpnSize = expr->isKnown ? 5 : expr->nRPNPatchSize;
|
uint32_t rpnSize = expr->isKnown ? 5 : expr->rpnPatchSize;
|
||||||
struct FileStackNode *node = fstk_GetFileStack();
|
struct FileStackNode *node = fstk_GetFileStack();
|
||||||
|
|
||||||
if (!patch)
|
if (!patch)
|
||||||
fatalerror("No memory for patch: %s\n", strerror(errno));
|
fatalerror("No memory for patch: %s\n", strerror(errno));
|
||||||
|
|
||||||
patch->pRPN = malloc(sizeof(*patch->pRPN) * rpnSize);
|
patch->rpn = malloc(sizeof(*patch->rpn) * rpnSize);
|
||||||
if (!patch->pRPN)
|
if (!patch->rpn)
|
||||||
fatalerror("No memory for patch's RPN expression: %s\n", strerror(errno));
|
fatalerror("No memory for patch's RPN rpnSize: %s\n", strerror(errno));
|
||||||
|
|
||||||
patch->type = type;
|
patch->type = type;
|
||||||
patch->src = node;
|
patch->src = node;
|
||||||
out_RegisterNode(node);
|
out_RegisterNode(node);
|
||||||
patch->lineNo = lexer_GetLineNo();
|
patch->lineNo = lexer_GetLineNo();
|
||||||
patch->nOffset = ofs;
|
patch->offset = ofs;
|
||||||
patch->pcSection = sect_GetSymbolSection();
|
patch->pcSection = sect_GetSymbolSection();
|
||||||
patch->pcOffset = sect_GetSymbolOffset();
|
patch->pcOffset = sect_GetSymbolOffset();
|
||||||
|
|
||||||
/* If the expression's value is known, output a constant RPN expression directly */
|
/* If the rpnSize's value is known, output a constant RPN rpnSize directly */
|
||||||
if (expr->isKnown) {
|
if (expr->isKnown) {
|
||||||
patch->nRPNSize = rpnSize;
|
patch->rpnSize = rpnSize;
|
||||||
/* Make sure to update `rpnSize` above if modifying this! */
|
/* Make sure to update `rpnSize` above if modifying this! */
|
||||||
patch->pRPN[0] = RPN_CONST;
|
patch->rpn[0] = RPN_CONST;
|
||||||
patch->pRPN[1] = (uint32_t)(expr->nVal) & 0xFF;
|
patch->rpn[1] = (uint32_t)(expr->val) & 0xFF;
|
||||||
patch->pRPN[2] = (uint32_t)(expr->nVal) >> 8;
|
patch->rpn[2] = (uint32_t)(expr->val) >> 8;
|
||||||
patch->pRPN[3] = (uint32_t)(expr->nVal) >> 16;
|
patch->rpn[3] = (uint32_t)(expr->val) >> 16;
|
||||||
patch->pRPN[4] = (uint32_t)(expr->nVal) >> 24;
|
patch->rpn[4] = (uint32_t)(expr->val) >> 24;
|
||||||
} else {
|
} else {
|
||||||
patch->nRPNSize = 0;
|
patch->rpnSize = 0;
|
||||||
writerpn(patch->pRPN, &patch->nRPNSize, expr->tRPN, expr->nRPNLength);
|
writerpn(patch->rpn, &patch->rpnSize, expr->rpn, expr->rpnLength);
|
||||||
}
|
}
|
||||||
assert(patch->nRPNSize == rpnSize);
|
assert(patch->rpnSize == rpnSize);
|
||||||
|
|
||||||
return patch;
|
return patch;
|
||||||
}
|
}
|
||||||
@@ -418,8 +447,8 @@ void out_CreatePatch(uint32_t type, struct Expression const *expr, uint32_t ofs,
|
|||||||
// before those bytes.
|
// before those bytes.
|
||||||
patch->pcOffset -= pcShift;
|
patch->pcOffset -= pcShift;
|
||||||
|
|
||||||
patch->next = pCurrentSection->patches;
|
patch->next = currentSection->patches;
|
||||||
pCurrentSection->patches = patch;
|
currentSection->patches = patch;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -452,9 +481,16 @@ static void writeassert(struct Assertion *assert, FILE *f)
|
|||||||
putstring(assert->message, f);
|
putstring(assert->message, f);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void freeassert(struct Assertion *assert)
|
||||||
|
{
|
||||||
|
free(assert->patch->rpn);
|
||||||
|
free(assert->patch);
|
||||||
|
free(assert);
|
||||||
|
}
|
||||||
|
|
||||||
static void writeFileStackNode(struct FileStackNode const *node, FILE *f)
|
static void writeFileStackNode(struct FileStackNode const *node, FILE *f)
|
||||||
{
|
{
|
||||||
putlong(node->parent ? node->parent->ID : -1, f);
|
putlong(node->parent ? node->parent->ID : (uint32_t)-1, f);
|
||||||
putlong(node->lineNo, f);
|
putlong(node->lineNo, f);
|
||||||
putc(node->type, f);
|
putc(node->type, f);
|
||||||
if (node->type != NODE_REPT) {
|
if (node->type != NODE_REPT) {
|
||||||
@@ -485,13 +521,13 @@ static void registerUnregisteredSymbol(struct Symbol *symbol, void *arg)
|
|||||||
void out_WriteObject(void)
|
void out_WriteObject(void)
|
||||||
{
|
{
|
||||||
FILE *f;
|
FILE *f;
|
||||||
if (strcmp(tzObjectname, "-") != 0)
|
if (strcmp(objectName, "-") != 0)
|
||||||
f = fopen(tzObjectname, "wb");
|
f = fopen(objectName, "wb");
|
||||||
else
|
else
|
||||||
f = fdopen(1, "wb");
|
f = fdopen(1, "wb");
|
||||||
|
|
||||||
if (!f)
|
if (!f)
|
||||||
err(1, "Couldn't write file '%s'", tzObjectname);
|
err("Couldn't write file '%s'", objectName);
|
||||||
|
|
||||||
/* Also write symbols that weren't written above */
|
/* Also write symbols that weren't written above */
|
||||||
sym_ForEach(registerUnregisteredSymbol, NULL);
|
sym_ForEach(registerUnregisteredSymbol, NULL);
|
||||||
@@ -514,13 +550,21 @@ void out_WriteObject(void)
|
|||||||
for (struct Symbol const *sym = objectSymbols; sym; sym = sym->next)
|
for (struct Symbol const *sym = objectSymbols; sym; sym = sym->next)
|
||||||
writesymbol(sym, f);
|
writesymbol(sym, f);
|
||||||
|
|
||||||
for (struct Section *sect = pSectionList; sect; sect = sect->next)
|
for (struct Section *sect = sectionList; sect; sect = sect->next) {
|
||||||
writesection(sect, f);
|
writesection(sect, f);
|
||||||
|
freesection(sect);
|
||||||
|
}
|
||||||
|
|
||||||
putlong(countAsserts(), f);
|
putlong(countAsserts(), f);
|
||||||
for (struct Assertion *assert = assertions; assert;
|
struct Assertion *assert = assertions;
|
||||||
assert = assert->next)
|
|
||||||
|
while (assert != NULL) {
|
||||||
|
struct Assertion *next = assert->next;
|
||||||
|
|
||||||
writeassert(assert, f);
|
writeassert(assert, f);
|
||||||
|
freeassert(assert);
|
||||||
|
assert = next;
|
||||||
|
}
|
||||||
|
|
||||||
fclose(f);
|
fclose(f);
|
||||||
}
|
}
|
||||||
@@ -530,7 +574,7 @@ void out_WriteObject(void)
|
|||||||
*/
|
*/
|
||||||
void out_SetFileName(char *s)
|
void out_SetFileName(char *s)
|
||||||
{
|
{
|
||||||
tzObjectname = s;
|
objectName = s;
|
||||||
if (verbose)
|
if (verbose)
|
||||||
printf("Output filename %s\n", s);
|
printf("Output filename %s\n", s);
|
||||||
}
|
}
|
||||||
|
|||||||
901
src/asm/parser.y
901
src/asm/parser.y
File diff suppressed because it is too large
Load Diff
@@ -214,7 +214,7 @@ Warn when re-defining a charmap mapping.
|
|||||||
This warning is enabled by
|
This warning is enabled by
|
||||||
.Fl Wall .
|
.Fl Wall .
|
||||||
.It Fl Wdiv
|
.It Fl Wdiv
|
||||||
Warn when dividing the smallest negative integer by -1, which yields itself due to integer overflow.
|
Warn when dividing the smallest negative integer (-2**31) by -1, which yields itself due to integer overflow.
|
||||||
.It Fl Wempty-macro-arg
|
.It Fl Wempty-macro-arg
|
||||||
Warn when a macro argument is empty.
|
Warn when a macro argument is empty.
|
||||||
This warning is enabled by
|
This warning is enabled by
|
||||||
@@ -243,15 +243,37 @@ Warn when obsolete constructs such as the
|
|||||||
constant or
|
constant or
|
||||||
.Ic PRINTT
|
.Ic PRINTT
|
||||||
directive are encountered.
|
directive are encountered.
|
||||||
|
.It Fl Wnumeric-string=
|
||||||
|
Warn when a multi-character string is treated as a number.
|
||||||
|
.Fl Wnumeric-string=0
|
||||||
|
or
|
||||||
|
.Fl Wno-numeric-string
|
||||||
|
disables this warning.
|
||||||
|
.Fl Wnumeric-string=1
|
||||||
|
or just
|
||||||
|
.Fl Wnumeric-string
|
||||||
|
warns about strings longer than four characters, since four or fewer characters fit within a 32-bit integer.
|
||||||
|
.Fl Wnumeric-string=2
|
||||||
|
warns about any multi-character string.
|
||||||
.It Fl Wshift
|
.It Fl Wshift
|
||||||
Warn when shifting right a negative value.
|
Warn when shifting right a negative value.
|
||||||
Use a division by 2**N instead.
|
Use a division by 2**N instead.
|
||||||
.It Fl Wshift-amount
|
.It Fl Wshift-amount
|
||||||
Warn when a shift's operand is negative or greater than 32.
|
Warn when a shift's operand is negative or greater than 32.
|
||||||
.It Fl Wno-truncation
|
.It Fl Wtruncation=
|
||||||
Warn when an implicit truncation (for example,
|
Warn when an implicit truncation (for example,
|
||||||
.Ic db )
|
.Ic db
|
||||||
loses some bits.
|
to an 8-bit value) loses some bits.
|
||||||
|
.Fl Wtruncation=0
|
||||||
|
or
|
||||||
|
.Fl Wno-truncation
|
||||||
|
disables this warning.
|
||||||
|
.Fl Wtruncation=1
|
||||||
|
warns when an N-bit value's absolute value is 2**N or greater.
|
||||||
|
.Fl Wtruncation=2
|
||||||
|
or just
|
||||||
|
.Fl Wtruncation
|
||||||
|
also warns when an N-bit value is less than -2**(N-1), which will not fit in two's complement encoding.
|
||||||
.It Fl Wno-user
|
.It Fl Wno-user
|
||||||
Warn when the
|
Warn when the
|
||||||
.Ic WARN
|
.Ic WARN
|
||||||
|
|||||||
910
src/asm/rgbasm.5
910
src/asm/rgbasm.5
File diff suppressed because it is too large
Load Diff
377
src/asm/rpn.c
377
src/asm/rpn.c
@@ -13,6 +13,7 @@
|
|||||||
#include <assert.h>
|
#include <assert.h>
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
#include <inttypes.h>
|
#include <inttypes.h>
|
||||||
|
#include <limits.h>
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
@@ -45,47 +46,47 @@
|
|||||||
static uint8_t *reserveSpace(struct Expression *expr, uint32_t size)
|
static uint8_t *reserveSpace(struct Expression *expr, uint32_t size)
|
||||||
{
|
{
|
||||||
/* This assumes the RPN length is always less than the capacity */
|
/* This assumes the RPN length is always less than the capacity */
|
||||||
if (expr->nRPNCapacity - expr->nRPNLength < size) {
|
if (expr->rpnCapacity - expr->rpnLength < size) {
|
||||||
/* If there isn't enough room to reserve the space, realloc */
|
/* If there isn't enough room to reserve the space, realloc */
|
||||||
if (!expr->tRPN)
|
if (!expr->rpn)
|
||||||
expr->nRPNCapacity = 256; /* Initial size */
|
expr->rpnCapacity = 256; /* Initial size */
|
||||||
while (expr->nRPNCapacity - expr->nRPNLength < size) {
|
while (expr->rpnCapacity - expr->rpnLength < size) {
|
||||||
if (expr->nRPNCapacity >= MAXRPNLEN)
|
if (expr->rpnCapacity >= MAXRPNLEN)
|
||||||
/*
|
/*
|
||||||
* To avoid generating humongous object files, cap the
|
* To avoid generating humongous object files, cap the
|
||||||
* size of RPN expressions
|
* size of RPN expressions
|
||||||
*/
|
*/
|
||||||
fatalerror("RPN expression cannot grow larger than "
|
fatalerror("RPN expression cannot grow larger than "
|
||||||
EXPAND_AND_STR(MAXRPNLEN) " bytes\n");
|
EXPAND_AND_STR(MAXRPNLEN) " bytes\n");
|
||||||
else if (expr->nRPNCapacity > MAXRPNLEN / 2)
|
else if (expr->rpnCapacity > MAXRPNLEN / 2)
|
||||||
expr->nRPNCapacity = MAXRPNLEN;
|
expr->rpnCapacity = MAXRPNLEN;
|
||||||
else
|
else
|
||||||
expr->nRPNCapacity *= 2;
|
expr->rpnCapacity *= 2;
|
||||||
}
|
}
|
||||||
expr->tRPN = realloc(expr->tRPN, expr->nRPNCapacity);
|
expr->rpn = realloc(expr->rpn, expr->rpnCapacity);
|
||||||
|
|
||||||
if (!expr->tRPN)
|
if (!expr->rpn)
|
||||||
fatalerror("Failed to grow RPN expression: %s\n", strerror(errno));
|
fatalerror("Failed to grow RPN expression: %s\n", strerror(errno));
|
||||||
}
|
}
|
||||||
|
|
||||||
uint8_t *ptr = expr->tRPN + expr->nRPNLength;
|
uint8_t *ptr = expr->rpn + expr->rpnLength;
|
||||||
|
|
||||||
expr->nRPNLength += size;
|
expr->rpnLength += size;
|
||||||
return ptr;
|
return ptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Init the RPN expression
|
* Init a RPN expression
|
||||||
*/
|
*/
|
||||||
static void rpn_Init(struct Expression *expr)
|
static void rpn_Init(struct Expression *expr)
|
||||||
{
|
{
|
||||||
expr->reason = NULL;
|
expr->reason = NULL;
|
||||||
expr->isKnown = true;
|
expr->isKnown = true;
|
||||||
expr->isSymbol = false;
|
expr->isSymbol = false;
|
||||||
expr->tRPN = NULL;
|
expr->rpn = NULL;
|
||||||
expr->nRPNCapacity = 0;
|
expr->rpnCapacity = 0;
|
||||||
expr->nRPNLength = 0;
|
expr->rpnLength = 0;
|
||||||
expr->nRPNPatchSize = 0;
|
expr->rpnPatchSize = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@@ -93,7 +94,7 @@ static void rpn_Init(struct Expression *expr)
|
|||||||
*/
|
*/
|
||||||
void rpn_Free(struct Expression *expr)
|
void rpn_Free(struct Expression *expr)
|
||||||
{
|
{
|
||||||
free(expr->tRPN);
|
free(expr->rpn);
|
||||||
free(expr->reason);
|
free(expr->reason);
|
||||||
rpn_Init(expr);
|
rpn_Init(expr);
|
||||||
}
|
}
|
||||||
@@ -104,12 +105,12 @@ void rpn_Free(struct Expression *expr)
|
|||||||
void rpn_Number(struct Expression *expr, uint32_t i)
|
void rpn_Number(struct Expression *expr, uint32_t i)
|
||||||
{
|
{
|
||||||
rpn_Init(expr);
|
rpn_Init(expr);
|
||||||
expr->nVal = i;
|
expr->val = i;
|
||||||
}
|
}
|
||||||
|
|
||||||
void rpn_Symbol(struct Expression *expr, char const *tzSym)
|
void rpn_Symbol(struct Expression *expr, char const *symName)
|
||||||
{
|
{
|
||||||
struct Symbol *sym = sym_FindScopedSymbol(tzSym);
|
struct Symbol *sym = sym_FindScopedSymbol(symName);
|
||||||
|
|
||||||
if (sym_IsPC(sym) && !sect_GetSymbolSection()) {
|
if (sym_IsPC(sym) && !sect_GetSymbolSection()) {
|
||||||
error("PC has no value outside a section\n");
|
error("PC has no value outside a section\n");
|
||||||
@@ -119,16 +120,16 @@ void rpn_Symbol(struct Expression *expr, char const *tzSym)
|
|||||||
expr->isSymbol = true;
|
expr->isSymbol = true;
|
||||||
|
|
||||||
makeUnknown(expr, sym_IsPC(sym) ? "PC is not constant at assembly time"
|
makeUnknown(expr, sym_IsPC(sym) ? "PC is not constant at assembly time"
|
||||||
: "'%s' is not constant at assembly time", tzSym);
|
: "'%s' is not constant at assembly time", symName);
|
||||||
sym = sym_Ref(tzSym);
|
sym = sym_Ref(symName);
|
||||||
expr->nRPNPatchSize += 5; /* 1-byte opcode + 4-byte symbol ID */
|
expr->rpnPatchSize += 5; /* 1-byte opcode + 4-byte symbol ID */
|
||||||
|
|
||||||
size_t nameLen = strlen(sym->name) + 1; /* Don't forget NUL! */
|
size_t nameLen = strlen(sym->name) + 1; /* Don't forget NUL! */
|
||||||
uint8_t *ptr = reserveSpace(expr, nameLen + 1);
|
uint8_t *ptr = reserveSpace(expr, nameLen + 1);
|
||||||
*ptr++ = RPN_SYM;
|
*ptr++ = RPN_SYM;
|
||||||
memcpy(ptr, sym->name, nameLen);
|
memcpy(ptr, sym->name, nameLen);
|
||||||
} else {
|
} else {
|
||||||
rpn_Number(expr, sym_GetConstantValue(tzSym));
|
rpn_Number(expr, sym_GetConstantValue(symName));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -136,21 +137,21 @@ void rpn_BankSelf(struct Expression *expr)
|
|||||||
{
|
{
|
||||||
rpn_Init(expr);
|
rpn_Init(expr);
|
||||||
|
|
||||||
if (!pCurrentSection) {
|
if (!currentSection) {
|
||||||
error("PC has no bank outside a section\n");
|
error("PC has no bank outside a section\n");
|
||||||
expr->nVal = 1;
|
expr->val = 1;
|
||||||
} else if (pCurrentSection->bank == (uint32_t)-1) {
|
} else if (currentSection->bank == (uint32_t)-1) {
|
||||||
makeUnknown(expr, "Current section's bank is not known");
|
makeUnknown(expr, "Current section's bank is not known");
|
||||||
expr->nRPNPatchSize++;
|
expr->rpnPatchSize++;
|
||||||
*reserveSpace(expr, 1) = RPN_BANK_SELF;
|
*reserveSpace(expr, 1) = RPN_BANK_SELF;
|
||||||
} else {
|
} else {
|
||||||
expr->nVal = pCurrentSection->bank;
|
expr->val = currentSection->bank;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void rpn_BankSymbol(struct Expression *expr, char const *tzSym)
|
void rpn_BankSymbol(struct Expression *expr, char const *symName)
|
||||||
{
|
{
|
||||||
struct Symbol const *sym = sym_FindScopedSymbol(tzSym);
|
struct Symbol const *sym = sym_FindScopedSymbol(symName);
|
||||||
|
|
||||||
/* The @ symbol is treated differently. */
|
/* The @ symbol is treated differently. */
|
||||||
if (sym_IsPC(sym)) {
|
if (sym_IsPC(sym)) {
|
||||||
@@ -162,15 +163,15 @@ void rpn_BankSymbol(struct Expression *expr, char const *tzSym)
|
|||||||
if (sym && !sym_IsLabel(sym)) {
|
if (sym && !sym_IsLabel(sym)) {
|
||||||
error("BANK argument must be a label\n");
|
error("BANK argument must be a label\n");
|
||||||
} else {
|
} else {
|
||||||
sym = sym_Ref(tzSym);
|
sym = sym_Ref(symName);
|
||||||
assert(sym); // If the symbol didn't exist, it should have been created
|
assert(sym); // If the symbol didn't exist, it should have been created
|
||||||
|
|
||||||
if (sym_GetSection(sym) && sym_GetSection(sym)->bank != (uint32_t)-1) {
|
if (sym_GetSection(sym) && sym_GetSection(sym)->bank != (uint32_t)-1) {
|
||||||
/* Symbol's section is known and bank is fixed */
|
/* Symbol's section is known and bank is fixed */
|
||||||
expr->nVal = sym_GetSection(sym)->bank;
|
expr->val = sym_GetSection(sym)->bank;
|
||||||
} else {
|
} else {
|
||||||
makeUnknown(expr, "\"%s\"'s bank is not known", tzSym);
|
makeUnknown(expr, "\"%s\"'s bank is not known", symName);
|
||||||
expr->nRPNPatchSize += 5; /* opcode + 4-byte sect ID */
|
expr->rpnPatchSize += 5; /* opcode + 4-byte sect ID */
|
||||||
|
|
||||||
size_t nameLen = strlen(sym->name) + 1; /* Room for NUL! */
|
size_t nameLen = strlen(sym->name) + 1; /* Room for NUL! */
|
||||||
uint8_t *ptr = reserveSpace(expr, nameLen + 1);
|
uint8_t *ptr = reserveSpace(expr, nameLen + 1);
|
||||||
@@ -180,24 +181,63 @@ void rpn_BankSymbol(struct Expression *expr, char const *tzSym)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void rpn_BankSection(struct Expression *expr, char const *tzSectionName)
|
void rpn_BankSection(struct Expression *expr, char const *sectionName)
|
||||||
{
|
{
|
||||||
rpn_Init(expr);
|
rpn_Init(expr);
|
||||||
|
|
||||||
struct Section *pSection = out_FindSectionByName(tzSectionName);
|
struct Section *section = sect_FindSectionByName(sectionName);
|
||||||
|
|
||||||
if (pSection && pSection->bank != (uint32_t)-1) {
|
if (section && section->bank != (uint32_t)-1) {
|
||||||
expr->nVal = pSection->bank;
|
expr->val = section->bank;
|
||||||
} else {
|
} else {
|
||||||
makeUnknown(expr, "Section \"%s\"'s bank is not known",
|
makeUnknown(expr, "Section \"%s\"'s bank is not known", sectionName);
|
||||||
tzSectionName);
|
|
||||||
|
|
||||||
size_t nameLen = strlen(tzSectionName) + 1; /* Room for NUL! */
|
size_t nameLen = strlen(sectionName) + 1; /* Room for NUL! */
|
||||||
uint8_t *ptr = reserveSpace(expr, nameLen + 1);
|
uint8_t *ptr = reserveSpace(expr, nameLen + 1);
|
||||||
|
|
||||||
expr->nRPNPatchSize += nameLen + 1;
|
expr->rpnPatchSize += nameLen + 1;
|
||||||
*ptr++ = RPN_BANK_SECT;
|
*ptr++ = RPN_BANK_SECT;
|
||||||
memcpy(ptr, tzSectionName, nameLen);
|
memcpy(ptr, sectionName, nameLen);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void rpn_SizeOfSection(struct Expression *expr, char const *sectionName)
|
||||||
|
{
|
||||||
|
rpn_Init(expr);
|
||||||
|
|
||||||
|
struct Section *section = sect_FindSectionByName(sectionName);
|
||||||
|
|
||||||
|
if (section && sect_IsSizeKnown(section)) {
|
||||||
|
expr->val = section->size;
|
||||||
|
} else {
|
||||||
|
makeUnknown(expr, "Section \"%s\"'s size is not known", sectionName);
|
||||||
|
|
||||||
|
size_t nameLen = strlen(sectionName) + 1; /* Room for NUL! */
|
||||||
|
uint8_t *ptr = reserveSpace(expr, nameLen + 1);
|
||||||
|
|
||||||
|
expr->rpnPatchSize += nameLen + 1;
|
||||||
|
*ptr++ = RPN_SIZEOF_SECT;
|
||||||
|
memcpy(ptr, sectionName, nameLen);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void rpn_StartOfSection(struct Expression *expr, char const *sectionName)
|
||||||
|
{
|
||||||
|
rpn_Init(expr);
|
||||||
|
|
||||||
|
struct Section *section = sect_FindSectionByName(sectionName);
|
||||||
|
|
||||||
|
if (section && section->org != (uint32_t)-1) {
|
||||||
|
expr->val = section->org;
|
||||||
|
} else {
|
||||||
|
makeUnknown(expr, "Section \"%s\"'s start is not known", sectionName);
|
||||||
|
|
||||||
|
size_t nameLen = strlen(sectionName) + 1; /* Room for NUL! */
|
||||||
|
uint8_t *ptr = reserveSpace(expr, nameLen + 1);
|
||||||
|
|
||||||
|
expr->rpnPatchSize += nameLen + 1;
|
||||||
|
*ptr++ = RPN_STARTOF_SECT;
|
||||||
|
memcpy(ptr, sectionName, nameLen);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -207,13 +247,13 @@ void rpn_CheckHRAM(struct Expression *expr, const struct Expression *src)
|
|||||||
expr->isSymbol = false;
|
expr->isSymbol = false;
|
||||||
|
|
||||||
if (!rpn_isKnown(expr)) {
|
if (!rpn_isKnown(expr)) {
|
||||||
expr->nRPNPatchSize++;
|
expr->rpnPatchSize++;
|
||||||
*reserveSpace(expr, 1) = RPN_HRAM;
|
*reserveSpace(expr, 1) = RPN_HRAM;
|
||||||
} else if (expr->nVal >= 0xFF00 && expr->nVal <= 0xFFFF) {
|
} else if (expr->val >= 0xFF00 && expr->val <= 0xFFFF) {
|
||||||
/* That range is valid, but only keep the lower byte */
|
/* That range is valid, but only keep the lower byte */
|
||||||
expr->nVal &= 0xFF;
|
expr->val &= 0xFF;
|
||||||
} else if (expr->nVal < 0 || expr->nVal > 0xFF) {
|
} else if (expr->val < 0 || expr->val > 0xFF) {
|
||||||
error("Source address $%" PRIx32 " not between $FF00 to $FFFF\n", expr->nVal);
|
error("Source address $%" PRIx32 " not between $FF00 to $FFFF\n", expr->val);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -223,25 +263,52 @@ void rpn_CheckRST(struct Expression *expr, const struct Expression *src)
|
|||||||
|
|
||||||
if (rpn_isKnown(expr)) {
|
if (rpn_isKnown(expr)) {
|
||||||
/* A valid RST address must be masked with 0x38 */
|
/* A valid RST address must be masked with 0x38 */
|
||||||
if (expr->nVal & ~0x38)
|
if (expr->val & ~0x38)
|
||||||
error("Invalid address $%" PRIx32 " for RST\n", expr->nVal);
|
error("Invalid address $%" PRIx32 " for RST\n", expr->val);
|
||||||
/* The target is in the "0x38" bits, all other bits are set */
|
/* The target is in the "0x38" bits, all other bits are set */
|
||||||
expr->nVal |= 0xC7;
|
expr->val |= 0xC7;
|
||||||
} else {
|
} else {
|
||||||
expr->nRPNPatchSize++;
|
expr->rpnPatchSize++;
|
||||||
*reserveSpace(expr, 1) = RPN_RST;
|
*reserveSpace(expr, 1) = RPN_RST;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Checks that an RPN expression's value fits within N bits (signed or unsigned)
|
||||||
|
*/
|
||||||
|
void rpn_CheckNBit(struct Expression const *expr, uint8_t n)
|
||||||
|
{
|
||||||
|
assert(n != 0); // That doesn't make sense
|
||||||
|
assert(n < CHAR_BIT * sizeof(int)); // Otherwise `1 << n` is UB
|
||||||
|
|
||||||
|
if (rpn_isKnown(expr)) {
|
||||||
|
int32_t val = expr->val;
|
||||||
|
|
||||||
|
if (val <= -(1 << n) || val >= 1 << n)
|
||||||
|
warning(WARNING_TRUNCATION_1, "Expression must be %u-bit\n", n);
|
||||||
|
else if (val < -(1 << (n - 1)))
|
||||||
|
warning(WARNING_TRUNCATION_2, "Expression must be %u-bit\n", n);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
int32_t rpn_GetConstVal(struct Expression const *expr)
|
||||||
|
{
|
||||||
|
if (!rpn_isKnown(expr)) {
|
||||||
|
error("Expected constant expression: %s\n", expr->reason);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
return expr->val;
|
||||||
|
}
|
||||||
|
|
||||||
void rpn_LOGNOT(struct Expression *expr, const struct Expression *src)
|
void rpn_LOGNOT(struct Expression *expr, const struct Expression *src)
|
||||||
{
|
{
|
||||||
*expr = *src;
|
*expr = *src;
|
||||||
expr->isSymbol = false;
|
expr->isSymbol = false;
|
||||||
|
|
||||||
if (rpn_isKnown(expr)) {
|
if (rpn_isKnown(expr)) {
|
||||||
expr->nVal = !expr->nVal;
|
expr->val = !expr->val;
|
||||||
} else {
|
} else {
|
||||||
expr->nRPNPatchSize++;
|
expr->rpnPatchSize++;
|
||||||
*reserveSpace(expr, 1) = RPN_LOGUNNOT;
|
*reserveSpace(expr, 1) = RPN_LOGUNNOT;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -250,7 +317,7 @@ struct Symbol const *rpn_SymbolOf(struct Expression const *expr)
|
|||||||
{
|
{
|
||||||
if (!rpn_isSymbol(expr))
|
if (!rpn_isSymbol(expr))
|
||||||
return NULL;
|
return NULL;
|
||||||
return sym_FindScopedSymbol((char *)expr->tRPN + 1);
|
return sym_FindScopedSymbol((char const *)expr->rpn + 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool rpn_IsDiffConstant(struct Expression const *src, struct Symbol const *sym)
|
bool rpn_IsDiffConstant(struct Expression const *src, struct Symbol const *sym)
|
||||||
@@ -272,10 +339,51 @@ static bool isDiffConstant(struct Expression const *src1,
|
|||||||
return rpn_IsDiffConstant(src1, rpn_SymbolOf(src2));
|
return rpn_IsDiffConstant(src1, rpn_SymbolOf(src2));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Attempts to compute a constant binary AND from non-constant operands
|
||||||
|
* This is possible if one operand is a symbol belonging to an `ALIGN[N]` section, and the other is
|
||||||
|
* a constant that only keeps (some of) the lower N bits.
|
||||||
|
*
|
||||||
|
* @return The constant result if it can be computed, or -1 otherwise.
|
||||||
|
*/
|
||||||
|
static int32_t tryConstMask(struct Expression const *lhs, struct Expression const *rhs)
|
||||||
|
{
|
||||||
|
struct Symbol const *sym = rpn_SymbolOf(lhs);
|
||||||
|
struct Expression const *expr = rhs;
|
||||||
|
|
||||||
|
if (!sym || !sym_GetSection(sym)) {
|
||||||
|
// If the lhs isn't a symbol, try again the other way around
|
||||||
|
sym = rpn_SymbolOf(rhs);
|
||||||
|
expr = lhs;
|
||||||
|
|
||||||
|
if (!sym || !sym_GetSection(sym))
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
assert(sym_IsNumeric(sym));
|
||||||
|
|
||||||
|
if (!rpn_isKnown(expr))
|
||||||
|
return -1;
|
||||||
|
// We can now safely use `expr->val`
|
||||||
|
struct Section const *sect = sym_GetSection(sym);
|
||||||
|
int32_t unknownBits = (1 << 16) - (1 << sect->align); // The max alignment is 16
|
||||||
|
|
||||||
|
// The mask must ignore all unknown bits
|
||||||
|
if ((expr->val & unknownBits) != 0)
|
||||||
|
return -1;
|
||||||
|
|
||||||
|
// `sym_GetValue()` attempts to add the section's address,
|
||||||
|
// but that's "-1" because the section is floating (otherwise we wouldn't be here)
|
||||||
|
assert(sect->org == (uint32_t)-1);
|
||||||
|
int32_t symbolOfs = sym_GetValue(sym) + 1;
|
||||||
|
|
||||||
|
return (symbolOfs + sect->alignOfs) & ~unknownBits;
|
||||||
|
}
|
||||||
|
|
||||||
void rpn_BinaryOp(enum RPNCommand op, struct Expression *expr,
|
void rpn_BinaryOp(enum RPNCommand op, struct Expression *expr,
|
||||||
const struct Expression *src1, const struct Expression *src2)
|
const struct Expression *src1, const struct Expression *src2)
|
||||||
{
|
{
|
||||||
expr->isSymbol = false;
|
expr->isSymbol = false;
|
||||||
|
int32_t constMaskVal;
|
||||||
|
|
||||||
/* First, check if the expression is known */
|
/* First, check if the expression is known */
|
||||||
expr->isKnown = src1->isKnown && src2->isKnown;
|
expr->isKnown = src1->isKnown && src2->isKnown;
|
||||||
@@ -283,111 +391,123 @@ void rpn_BinaryOp(enum RPNCommand op, struct Expression *expr,
|
|||||||
rpn_Init(expr); /* Init the expression to something sane */
|
rpn_Init(expr); /* Init the expression to something sane */
|
||||||
|
|
||||||
/* If both expressions are known, just compute the value */
|
/* If both expressions are known, just compute the value */
|
||||||
uint32_t uleft = src1->nVal, uright = src2->nVal;
|
uint32_t uleft = src1->val, uright = src2->val;
|
||||||
|
|
||||||
switch (op) {
|
switch (op) {
|
||||||
case RPN_LOGOR:
|
case RPN_LOGOR:
|
||||||
expr->nVal = src1->nVal || src2->nVal;
|
expr->val = src1->val || src2->val;
|
||||||
break;
|
break;
|
||||||
case RPN_LOGAND:
|
case RPN_LOGAND:
|
||||||
expr->nVal = src1->nVal && src2->nVal;
|
expr->val = src1->val && src2->val;
|
||||||
break;
|
break;
|
||||||
case RPN_LOGEQ:
|
case RPN_LOGEQ:
|
||||||
expr->nVal = src1->nVal == src2->nVal;
|
expr->val = src1->val == src2->val;
|
||||||
break;
|
break;
|
||||||
case RPN_LOGGT:
|
case RPN_LOGGT:
|
||||||
expr->nVal = src1->nVal > src2->nVal;
|
expr->val = src1->val > src2->val;
|
||||||
break;
|
break;
|
||||||
case RPN_LOGLT:
|
case RPN_LOGLT:
|
||||||
expr->nVal = src1->nVal < src2->nVal;
|
expr->val = src1->val < src2->val;
|
||||||
break;
|
break;
|
||||||
case RPN_LOGGE:
|
case RPN_LOGGE:
|
||||||
expr->nVal = src1->nVal >= src2->nVal;
|
expr->val = src1->val >= src2->val;
|
||||||
break;
|
break;
|
||||||
case RPN_LOGLE:
|
case RPN_LOGLE:
|
||||||
expr->nVal = src1->nVal <= src2->nVal;
|
expr->val = src1->val <= src2->val;
|
||||||
break;
|
break;
|
||||||
case RPN_LOGNE:
|
case RPN_LOGNE:
|
||||||
expr->nVal = src1->nVal != src2->nVal;
|
expr->val = src1->val != src2->val;
|
||||||
break;
|
break;
|
||||||
case RPN_ADD:
|
case RPN_ADD:
|
||||||
expr->nVal = uleft + uright;
|
expr->val = uleft + uright;
|
||||||
break;
|
break;
|
||||||
case RPN_SUB:
|
case RPN_SUB:
|
||||||
expr->nVal = uleft - uright;
|
expr->val = uleft - uright;
|
||||||
break;
|
break;
|
||||||
case RPN_XOR:
|
case RPN_XOR:
|
||||||
expr->nVal = src1->nVal ^ src2->nVal;
|
expr->val = src1->val ^ src2->val;
|
||||||
break;
|
break;
|
||||||
case RPN_OR:
|
case RPN_OR:
|
||||||
expr->nVal = src1->nVal | src2->nVal;
|
expr->val = src1->val | src2->val;
|
||||||
break;
|
break;
|
||||||
case RPN_AND:
|
case RPN_AND:
|
||||||
expr->nVal = src1->nVal & src2->nVal;
|
expr->val = src1->val & src2->val;
|
||||||
break;
|
break;
|
||||||
case RPN_SHL:
|
case RPN_SHL:
|
||||||
if (src2->nVal < 0)
|
if (src2->val < 0)
|
||||||
warning(WARNING_SHIFT_AMOUNT,
|
warning(WARNING_SHIFT_AMOUNT,
|
||||||
"Shifting left by negative amount %" PRId32 "\n",
|
"Shifting left by negative amount %" PRId32 "\n",
|
||||||
src2->nVal);
|
src2->val);
|
||||||
|
|
||||||
if (src2->nVal >= 32)
|
if (src2->val >= 32)
|
||||||
warning(WARNING_SHIFT_AMOUNT,
|
warning(WARNING_SHIFT_AMOUNT,
|
||||||
"Shifting left by large amount %" PRId32 "\n",
|
"Shifting left by large amount %" PRId32 "\n", src2->val);
|
||||||
src2->nVal);
|
|
||||||
|
|
||||||
expr->nVal = op_shift_left(src1->nVal, src2->nVal);
|
expr->val = op_shift_left(src1->val, src2->val);
|
||||||
break;
|
break;
|
||||||
case RPN_SHR:
|
case RPN_SHR:
|
||||||
if (src1->nVal < 0)
|
if (src1->val < 0)
|
||||||
warning(WARNING_SHIFT, "Shifting right negative value %"
|
warning(WARNING_SHIFT,
|
||||||
PRId32 "\n",
|
"Shifting right negative value %" PRId32 "\n", src1->val);
|
||||||
src1->nVal);
|
|
||||||
|
|
||||||
if (src2->nVal < 0)
|
if (src2->val < 0)
|
||||||
warning(WARNING_SHIFT_AMOUNT,
|
warning(WARNING_SHIFT_AMOUNT,
|
||||||
"Shifting right by negative amount %" PRId32 "\n",
|
"Shifting right by negative amount %" PRId32 "\n",
|
||||||
src2->nVal);
|
src2->val);
|
||||||
|
|
||||||
if (src2->nVal >= 32)
|
if (src2->val >= 32)
|
||||||
warning(WARNING_SHIFT_AMOUNT,
|
warning(WARNING_SHIFT_AMOUNT,
|
||||||
"Shifting right by large amount %" PRId32 "\n",
|
"Shifting right by large amount %" PRId32 "\n",
|
||||||
src2->nVal);
|
src2->val);
|
||||||
|
|
||||||
expr->nVal = op_shift_right(src1->nVal, src2->nVal);
|
expr->val = op_shift_right(src1->val, src2->val);
|
||||||
|
break;
|
||||||
|
case RPN_USHR:
|
||||||
|
if (src2->val < 0)
|
||||||
|
warning(WARNING_SHIFT_AMOUNT,
|
||||||
|
"Shifting right by negative amount %" PRId32 "\n",
|
||||||
|
src2->val);
|
||||||
|
|
||||||
|
if (src2->val >= 32)
|
||||||
|
warning(WARNING_SHIFT_AMOUNT,
|
||||||
|
"Shifting right by large amount %" PRId32 "\n",
|
||||||
|
src2->val);
|
||||||
|
|
||||||
|
expr->val = op_shift_right_unsigned(src1->val, src2->val);
|
||||||
break;
|
break;
|
||||||
case RPN_MUL:
|
case RPN_MUL:
|
||||||
expr->nVal = uleft * uright;
|
expr->val = uleft * uright;
|
||||||
break;
|
break;
|
||||||
case RPN_DIV:
|
case RPN_DIV:
|
||||||
if (src2->nVal == 0)
|
if (src2->val == 0)
|
||||||
fatalerror("Division by zero\n");
|
fatalerror("Division by zero\n");
|
||||||
|
|
||||||
if (src1->nVal == INT32_MIN && src2->nVal == -1) {
|
if (src1->val == INT32_MIN && src2->val == -1) {
|
||||||
warning(WARNING_DIV, "Division of %" PRId32 " by -1 yields %"
|
warning(WARNING_DIV,
|
||||||
PRId32 "\n", INT32_MIN, INT32_MIN);
|
"Division of %" PRId32 " by -1 yields %" PRId32 "\n",
|
||||||
expr->nVal = INT32_MIN;
|
INT32_MIN, INT32_MIN);
|
||||||
|
expr->val = INT32_MIN;
|
||||||
} else {
|
} else {
|
||||||
expr->nVal = op_divide(src1->nVal, src2->nVal);
|
expr->val = op_divide(src1->val, src2->val);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case RPN_MOD:
|
case RPN_MOD:
|
||||||
if (src2->nVal == 0)
|
if (src2->val == 0)
|
||||||
fatalerror("Modulo by zero\n");
|
fatalerror("Modulo by zero\n");
|
||||||
|
|
||||||
if (src1->nVal == INT32_MIN && src2->nVal == -1)
|
if (src1->val == INT32_MIN && src2->val == -1)
|
||||||
expr->nVal = 0;
|
expr->val = 0;
|
||||||
else
|
else
|
||||||
expr->nVal = op_modulo(src1->nVal, src2->nVal);
|
expr->val = op_modulo(src1->val, src2->val);
|
||||||
break;
|
break;
|
||||||
case RPN_EXP:
|
case RPN_EXP:
|
||||||
if (src2->nVal < 0)
|
if (src2->val < 0)
|
||||||
fatalerror("Exponentiation by negative power\n");
|
fatalerror("Exponentiation by negative power\n");
|
||||||
|
|
||||||
if (src1->nVal == INT32_MIN && src2->nVal == -1)
|
if (src1->val == INT32_MIN && src2->val == -1)
|
||||||
expr->nVal = 0;
|
expr->val = 0;
|
||||||
else
|
else
|
||||||
expr->nVal = op_exponent(src1->nVal, src2->nVal);
|
expr->val = op_exponent(src1->val, src2->val);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case RPN_UNSUB:
|
case RPN_UNSUB:
|
||||||
@@ -396,6 +516,8 @@ void rpn_BinaryOp(enum RPNCommand op, struct Expression *expr,
|
|||||||
case RPN_BANK_SYM:
|
case RPN_BANK_SYM:
|
||||||
case RPN_BANK_SECT:
|
case RPN_BANK_SECT:
|
||||||
case RPN_BANK_SELF:
|
case RPN_BANK_SELF:
|
||||||
|
case RPN_SIZEOF_SECT:
|
||||||
|
case RPN_STARTOF_SECT:
|
||||||
case RPN_HRAM:
|
case RPN_HRAM:
|
||||||
case RPN_RST:
|
case RPN_RST:
|
||||||
case RPN_CONST:
|
case RPN_CONST:
|
||||||
@@ -407,20 +529,23 @@ void rpn_BinaryOp(enum RPNCommand op, struct Expression *expr,
|
|||||||
struct Symbol const *symbol1 = rpn_SymbolOf(src1);
|
struct Symbol const *symbol1 = rpn_SymbolOf(src1);
|
||||||
struct Symbol const *symbol2 = rpn_SymbolOf(src2);
|
struct Symbol const *symbol2 = rpn_SymbolOf(src2);
|
||||||
|
|
||||||
expr->nVal = sym_GetValue(symbol1) - sym_GetValue(symbol2);
|
expr->val = sym_GetValue(symbol1) - sym_GetValue(symbol2);
|
||||||
|
expr->isKnown = true;
|
||||||
|
} else if (op == RPN_AND && (constMaskVal = tryConstMask(src1, src2)) != -1) {
|
||||||
|
expr->val = constMaskVal;
|
||||||
expr->isKnown = true;
|
expr->isKnown = true;
|
||||||
} else {
|
} else {
|
||||||
/* If it's not known, start computing the RPN expression */
|
/* If it's not known, start computing the RPN expression */
|
||||||
|
|
||||||
/* Convert the left-hand expression if it's constant */
|
/* Convert the left-hand expression if it's constant */
|
||||||
if (src1->isKnown) {
|
if (src1->isKnown) {
|
||||||
uint32_t lval = src1->nVal;
|
uint32_t lval = src1->val;
|
||||||
uint8_t bytes[] = {RPN_CONST, lval, lval >> 8,
|
uint8_t bytes[] = {RPN_CONST, lval, lval >> 8,
|
||||||
lval >> 16, lval >> 24};
|
lval >> 16, lval >> 24};
|
||||||
expr->nRPNPatchSize = sizeof(bytes);
|
expr->rpnPatchSize = sizeof(bytes);
|
||||||
expr->tRPN = NULL;
|
expr->rpn = NULL;
|
||||||
expr->nRPNCapacity = 0;
|
expr->rpnCapacity = 0;
|
||||||
expr->nRPNLength = 0;
|
expr->rpnLength = 0;
|
||||||
memcpy(reserveSpace(expr, sizeof(bytes)), bytes,
|
memcpy(reserveSpace(expr, sizeof(bytes)), bytes,
|
||||||
sizeof(bytes));
|
sizeof(bytes));
|
||||||
|
|
||||||
@@ -429,21 +554,21 @@ void rpn_BinaryOp(enum RPNCommand op, struct Expression *expr,
|
|||||||
free(src1->reason);
|
free(src1->reason);
|
||||||
} else {
|
} else {
|
||||||
/* Otherwise just reuse its RPN buffer */
|
/* Otherwise just reuse its RPN buffer */
|
||||||
expr->nRPNPatchSize = src1->nRPNPatchSize;
|
expr->rpnPatchSize = src1->rpnPatchSize;
|
||||||
expr->tRPN = src1->tRPN;
|
expr->rpn = src1->rpn;
|
||||||
expr->nRPNCapacity = src1->nRPNCapacity;
|
expr->rpnCapacity = src1->rpnCapacity;
|
||||||
expr->nRPNLength = src1->nRPNLength;
|
expr->rpnLength = src1->rpnLength;
|
||||||
expr->reason = src1->reason;
|
expr->reason = src1->reason;
|
||||||
free(src2->reason);
|
free(src2->reason);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Now, merge the right expression into the left one */
|
/* Now, merge the right expression into the left one */
|
||||||
uint8_t *ptr = src2->tRPN; /* Pointer to the right RPN */
|
uint8_t *ptr = src2->rpn; /* Pointer to the right RPN */
|
||||||
uint32_t len = src2->nRPNLength; /* Size of the right RPN */
|
uint32_t len = src2->rpnLength; /* Size of the right RPN */
|
||||||
uint32_t patchSize = src2->nRPNPatchSize;
|
uint32_t patchSize = src2->rpnPatchSize;
|
||||||
|
|
||||||
/* If the right expression is constant, merge a shim instead */
|
/* If the right expression is constant, merge a shim instead */
|
||||||
uint32_t rval = src2->nVal;
|
uint32_t rval = src2->val;
|
||||||
uint8_t bytes[] = {RPN_CONST, rval, rval >> 8, rval >> 16,
|
uint8_t bytes[] = {RPN_CONST, rval, rval >> 8, rval >> 16,
|
||||||
rval >> 24};
|
rval >> 24};
|
||||||
if (src2->isKnown) {
|
if (src2->isKnown) {
|
||||||
@@ -457,8 +582,8 @@ void rpn_BinaryOp(enum RPNCommand op, struct Expression *expr,
|
|||||||
memcpy(buf, ptr, len);
|
memcpy(buf, ptr, len);
|
||||||
buf[len] = op;
|
buf[len] = op;
|
||||||
|
|
||||||
free(src2->tRPN); /* If there was none, this is `free(NULL)` */
|
free(src2->rpn); /* If there was none, this is `free(NULL)` */
|
||||||
expr->nRPNPatchSize += patchSize + 1;
|
expr->rpnPatchSize += patchSize + 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -468,11 +593,11 @@ void rpn_HIGH(struct Expression *expr, const struct Expression *src)
|
|||||||
expr->isSymbol = false;
|
expr->isSymbol = false;
|
||||||
|
|
||||||
if (rpn_isKnown(expr)) {
|
if (rpn_isKnown(expr)) {
|
||||||
expr->nVal = (uint32_t)expr->nVal >> 8 & 0xFF;
|
expr->val = (uint32_t)expr->val >> 8 & 0xFF;
|
||||||
} else {
|
} else {
|
||||||
uint8_t bytes[] = {RPN_CONST, 8, 0, 0, 0, RPN_SHR,
|
uint8_t bytes[] = {RPN_CONST, 8, 0, 0, 0, RPN_SHR,
|
||||||
RPN_CONST, 0xFF, 0, 0, 0, RPN_AND};
|
RPN_CONST, 0xFF, 0, 0, 0, RPN_AND};
|
||||||
expr->nRPNPatchSize += sizeof(bytes);
|
expr->rpnPatchSize += sizeof(bytes);
|
||||||
memcpy(reserveSpace(expr, sizeof(bytes)), bytes, sizeof(bytes));
|
memcpy(reserveSpace(expr, sizeof(bytes)), bytes, sizeof(bytes));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -483,11 +608,11 @@ void rpn_LOW(struct Expression *expr, const struct Expression *src)
|
|||||||
expr->isSymbol = false;
|
expr->isSymbol = false;
|
||||||
|
|
||||||
if (rpn_isKnown(expr)) {
|
if (rpn_isKnown(expr)) {
|
||||||
expr->nVal = expr->nVal & 0xFF;
|
expr->val = expr->val & 0xFF;
|
||||||
} else {
|
} else {
|
||||||
uint8_t bytes[] = {RPN_CONST, 0xFF, 0, 0, 0, RPN_AND};
|
uint8_t bytes[] = {RPN_CONST, 0xFF, 0, 0, 0, RPN_AND};
|
||||||
|
|
||||||
expr->nRPNPatchSize += sizeof(bytes);
|
expr->rpnPatchSize += sizeof(bytes);
|
||||||
memcpy(reserveSpace(expr, sizeof(bytes)), bytes, sizeof(bytes));
|
memcpy(reserveSpace(expr, sizeof(bytes)), bytes, sizeof(bytes));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -495,7 +620,7 @@ void rpn_LOW(struct Expression *expr, const struct Expression *src)
|
|||||||
void rpn_ISCONST(struct Expression *expr, const struct Expression *src)
|
void rpn_ISCONST(struct Expression *expr, const struct Expression *src)
|
||||||
{
|
{
|
||||||
rpn_Init(expr);
|
rpn_Init(expr);
|
||||||
expr->nVal = rpn_isKnown(src);
|
expr->val = rpn_isKnown(src);
|
||||||
expr->isKnown = true;
|
expr->isKnown = true;
|
||||||
expr->isSymbol = false;
|
expr->isSymbol = false;
|
||||||
}
|
}
|
||||||
@@ -506,9 +631,9 @@ void rpn_UNNEG(struct Expression *expr, const struct Expression *src)
|
|||||||
expr->isSymbol = false;
|
expr->isSymbol = false;
|
||||||
|
|
||||||
if (rpn_isKnown(expr)) {
|
if (rpn_isKnown(expr)) {
|
||||||
expr->nVal = -(uint32_t)expr->nVal;
|
expr->val = -(uint32_t)expr->val;
|
||||||
} else {
|
} else {
|
||||||
expr->nRPNPatchSize++;
|
expr->rpnPatchSize++;
|
||||||
*reserveSpace(expr, 1) = RPN_UNSUB;
|
*reserveSpace(expr, 1) = RPN_UNSUB;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -519,9 +644,9 @@ void rpn_UNNOT(struct Expression *expr, const struct Expression *src)
|
|||||||
expr->isSymbol = false;
|
expr->isSymbol = false;
|
||||||
|
|
||||||
if (rpn_isKnown(expr)) {
|
if (rpn_isKnown(expr)) {
|
||||||
expr->nVal = ~expr->nVal;
|
expr->val = ~expr->val;
|
||||||
} else {
|
} else {
|
||||||
expr->nRPNPatchSize++;
|
expr->rpnPatchSize++;
|
||||||
*reserveSpace(expr, 1) = RPN_UNNOT;
|
*reserveSpace(expr, 1) = RPN_UNNOT;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -15,79 +15,104 @@
|
|||||||
#include "asm/symbol.h"
|
#include "asm/symbol.h"
|
||||||
#include "asm/warning.h"
|
#include "asm/warning.h"
|
||||||
|
|
||||||
#include "extern/err.h"
|
#include "error.h"
|
||||||
#include "platform.h" // strdup
|
#include "platform.h" // strdup
|
||||||
|
|
||||||
uint8_t fillByte;
|
uint8_t fillByte;
|
||||||
|
|
||||||
struct SectionStackEntry {
|
|
||||||
struct Section *section;
|
|
||||||
char const *scope; /* Section's symbol scope */
|
|
||||||
uint32_t offset;
|
|
||||||
struct SectionStackEntry *next;
|
|
||||||
};
|
|
||||||
|
|
||||||
struct SectionStackEntry *sectionStack;
|
|
||||||
uint32_t curOffset; /* Offset into the current section (see sect_GetSymbolOffset) */
|
|
||||||
static struct Section *currentLoadSection = NULL;
|
|
||||||
int32_t loadOffset; /* Offset into the LOAD section's parent (see sect_GetOutputOffset) */
|
|
||||||
|
|
||||||
struct UnionStackEntry {
|
struct UnionStackEntry {
|
||||||
uint32_t start;
|
uint32_t start;
|
||||||
uint32_t size;
|
uint32_t size;
|
||||||
struct UnionStackEntry *next;
|
struct UnionStackEntry *next;
|
||||||
} *unionStack = NULL;
|
} *unionStack = NULL;
|
||||||
|
|
||||||
|
struct SectionStackEntry {
|
||||||
|
struct Section *section;
|
||||||
|
struct Section *loadSection;
|
||||||
|
char const *scope; /* Section's symbol scope */
|
||||||
|
uint32_t offset;
|
||||||
|
int32_t loadOffset;
|
||||||
|
struct UnionStackEntry *unionStack;
|
||||||
|
struct SectionStackEntry *next;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct SectionStackEntry *sectionStack;
|
||||||
|
uint32_t curOffset; /* Offset into the current section (see sect_GetSymbolOffset) */
|
||||||
|
struct Section *currentSection = NULL;
|
||||||
|
static struct Section *currentLoadSection = NULL;
|
||||||
|
int32_t loadOffset; /* Offset into the LOAD section's parent (see sect_GetOutputOffset) */
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* A quick check to see if we have an initialized section
|
* A quick check to see if we have an initialized section
|
||||||
*/
|
*/
|
||||||
static void checksection(void)
|
attr_(warn_unused_result) static bool checksection(void)
|
||||||
{
|
{
|
||||||
if (pCurrentSection == NULL)
|
if (currentSection)
|
||||||
fatalerror("Code generation before SECTION directive\n");
|
return true;
|
||||||
|
|
||||||
|
error("Cannot output data outside of a SECTION\n");
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* A quick check to see if we have an initialized section that can contain
|
* A quick check to see if we have an initialized section that can contain
|
||||||
* this much initialized data
|
* this much initialized data
|
||||||
*/
|
*/
|
||||||
static void checkcodesection(void)
|
attr_(warn_unused_result) static bool checkcodesection(void)
|
||||||
{
|
{
|
||||||
checksection();
|
if (!checksection())
|
||||||
|
return false;
|
||||||
|
|
||||||
if (!sect_HasData(pCurrentSection->type))
|
if (sect_HasData(currentSection->type))
|
||||||
fatalerror("Section '%s' cannot contain code or data (not ROM0 or ROMX)\n",
|
return true;
|
||||||
pCurrentSection->name);
|
|
||||||
|
error("Section '%s' cannot contain code or data (not ROM0 or ROMX)\n",
|
||||||
|
currentSection->name);
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void checkSectionSize(struct Section const *sect, uint32_t size)
|
attr_(warn_unused_result) static bool checkSectionSize(struct Section const *sect, uint32_t size)
|
||||||
{
|
{
|
||||||
uint32_t maxSize = maxsize[sect->type];
|
uint32_t maxSize = maxsize[sect->type];
|
||||||
|
|
||||||
if (size > maxSize)
|
// If the new size is reasonable, keep going
|
||||||
fatalerror("Section '%s' grew too big (max size = 0x%" PRIX32
|
if (size <= maxSize)
|
||||||
|
return true;
|
||||||
|
|
||||||
|
error("Section '%s' grew too big (max size = 0x%" PRIX32
|
||||||
" bytes, reached 0x%" PRIX32 ").\n", sect->name, maxSize, size);
|
" bytes, reached 0x%" PRIX32 ").\n", sect->name, maxSize, size);
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Check if the section has grown too much.
|
* Check if the section has grown too much.
|
||||||
*/
|
*/
|
||||||
static void reserveSpace(uint32_t delta_size)
|
attr_(warn_unused_result) static bool reserveSpace(uint32_t delta_size)
|
||||||
{
|
{
|
||||||
/*
|
/*
|
||||||
* This check is here to trap broken code that generates sections that
|
* This check is here to trap broken code that generates sections that are too big and to
|
||||||
* are too big and to prevent the assembler from generating huge object
|
* prevent the assembler from generating huge object files or trying to allocate too much
|
||||||
* files or trying to allocate too much memory.
|
* memory.
|
||||||
* A check at the linking stage is still necessary.
|
* A check at the linking stage is still necessary.
|
||||||
*/
|
*/
|
||||||
checkSectionSize(pCurrentSection, curOffset + loadOffset + delta_size);
|
|
||||||
if (currentLoadSection)
|
// If the section has already overflowed, skip the check to avoid erroring out ad nauseam
|
||||||
checkSectionSize(currentLoadSection, curOffset + delta_size);
|
if (currentSection->size != UINT32_MAX
|
||||||
|
&& !checkSectionSize(currentSection, curOffset + loadOffset + delta_size))
|
||||||
|
// Mark the section as overflowed, to avoid repeating the error
|
||||||
|
currentSection->size = UINT32_MAX;
|
||||||
|
|
||||||
|
if (currentLoadSection && currentLoadSection->size != UINT32_MAX
|
||||||
|
&& !checkSectionSize(currentLoadSection, curOffset + delta_size))
|
||||||
|
currentLoadSection->size = UINT32_MAX;
|
||||||
|
|
||||||
|
return currentSection->size != UINT32_MAX
|
||||||
|
&& (!currentLoadSection || currentLoadSection->size != UINT32_MAX);
|
||||||
}
|
}
|
||||||
|
|
||||||
struct Section *out_FindSectionByName(const char *name)
|
struct Section *sect_FindSectionByName(char const *name)
|
||||||
{
|
{
|
||||||
for (struct Section *sect = pSectionList; sect; sect = sect->next) {
|
for (struct Section *sect = sectionList; sect; sect = sect->next) {
|
||||||
if (strcmp(name, sect->name) == 0)
|
if (strcmp(name, sect->name) == 0)
|
||||||
return sect;
|
return sect;
|
||||||
}
|
}
|
||||||
@@ -135,9 +160,9 @@ static unsigned int mergeSectUnion(struct Section *sect, enum SectionType type,
|
|||||||
/* Check if alignment offsets are compatible */
|
/* Check if alignment offsets are compatible */
|
||||||
} else if ((alignOffset & mask(sect->align))
|
} else if ((alignOffset & mask(sect->align))
|
||||||
!= (sect->alignOfs & mask(alignment))) {
|
!= (sect->alignOfs & mask(alignment))) {
|
||||||
fail("Section already declared with incompatible %" PRIu8
|
fail("Section already declared with incompatible %u"
|
||||||
"-byte alignment (offset %" PRIu16 ")\n",
|
"-byte alignment (offset %" PRIu16 ")\n",
|
||||||
sect->align, sect->alignOfs);
|
1u << sect->align, sect->alignOfs);
|
||||||
} else if (alignment > sect->align) {
|
} else if (alignment > sect->align) {
|
||||||
// If the section is not fixed, its alignment is the largest of both
|
// If the section is not fixed, its alignment is the largest of both
|
||||||
sect->align = alignment;
|
sect->align = alignment;
|
||||||
@@ -188,9 +213,9 @@ static unsigned int mergeFragments(struct Section *sect, enum SectionType type,
|
|||||||
PRIx32 "\n", sect->org);
|
PRIx32 "\n", sect->org);
|
||||||
/* Check if alignment offsets are compatible */
|
/* Check if alignment offsets are compatible */
|
||||||
} else if ((curOfs & mask(sect->align)) != (sect->alignOfs & mask(alignment))) {
|
} else if ((curOfs & mask(sect->align)) != (sect->alignOfs & mask(alignment))) {
|
||||||
fail("Section already declared with incompatible %" PRIu8
|
fail("Section already declared with incompatible %u"
|
||||||
"-byte alignment (offset %" PRIu16 ")\n",
|
"-byte alignment (offset %" PRIu16 ")\n",
|
||||||
sect->align, sect->alignOfs);
|
1u << sect->align, sect->alignOfs);
|
||||||
} else if (alignment > sect->align) {
|
} else if (alignment > sect->align) {
|
||||||
// If the section is not fixed, its alignment is the largest of both
|
// If the section is not fixed, its alignment is the largest of both
|
||||||
sect->align = alignment;
|
sect->align = alignment;
|
||||||
@@ -351,15 +376,15 @@ static struct Section *getSection(char const *name, enum SectionType type, uint3
|
|||||||
|
|
||||||
// Check if another section exists with the same name; merge if yes, otherwise create one
|
// Check if another section exists with the same name; merge if yes, otherwise create one
|
||||||
|
|
||||||
struct Section *sect = out_FindSectionByName(name);
|
struct Section *sect = sect_FindSectionByName(name);
|
||||||
|
|
||||||
if (sect) {
|
if (sect) {
|
||||||
mergeSections(sect, type, org, bank, alignment, alignOffset, mod);
|
mergeSections(sect, type, org, bank, alignment, alignOffset, mod);
|
||||||
} else {
|
} else {
|
||||||
sect = createSection(name, type, org, bank, alignment, alignOffset, mod);
|
sect = createSection(name, type, org, bank, alignment, alignOffset, mod);
|
||||||
// Add the new section to the list (order doesn't matter)
|
// Add the new section to the list (order doesn't matter)
|
||||||
sect->next = pSectionList;
|
sect->next = sectionList;
|
||||||
pSectionList = sect;
|
sectionList = sect;
|
||||||
}
|
}
|
||||||
|
|
||||||
return sect;
|
return sect;
|
||||||
@@ -379,7 +404,7 @@ static void changeSection(void)
|
|||||||
/*
|
/*
|
||||||
* Set the current section by name and type
|
* Set the current section by name and type
|
||||||
*/
|
*/
|
||||||
void out_NewSection(char const *name, uint32_t type, uint32_t org,
|
void sect_NewSection(char const *name, uint32_t type, uint32_t org,
|
||||||
struct SectionSpec const *attribs, enum SectionModifier mod)
|
struct SectionSpec const *attribs, enum SectionModifier mod)
|
||||||
{
|
{
|
||||||
if (currentLoadSection)
|
if (currentLoadSection)
|
||||||
@@ -394,23 +419,38 @@ void out_NewSection(char const *name, uint32_t type, uint32_t org,
|
|||||||
|
|
||||||
changeSection();
|
changeSection();
|
||||||
curOffset = mod == SECTION_UNION ? 0 : sect->size;
|
curOffset = mod == SECTION_UNION ? 0 : sect->size;
|
||||||
pCurrentSection = sect;
|
loadOffset = 0; // This is still used when checking for section size overflow!
|
||||||
|
currentSection = sect;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Set the current section by name and type
|
* Set the current section by name and type
|
||||||
*/
|
*/
|
||||||
void out_SetLoadSection(char const *name, uint32_t type, uint32_t org,
|
void sect_SetLoadSection(char const *name, uint32_t type, uint32_t org,
|
||||||
struct SectionSpec const *attribs,
|
struct SectionSpec const *attribs, enum SectionModifier mod)
|
||||||
enum SectionModifier mod)
|
|
||||||
{
|
{
|
||||||
checkcodesection();
|
// Important info: currently, UNION and LOAD cannot interact, since UNION is prohibited in
|
||||||
|
// "code" sections, whereas LOAD is restricted to them.
|
||||||
|
// Therefore, any interactions are NOT TESTED, so lift either of those restrictions at
|
||||||
|
// your own peril! ^^
|
||||||
|
|
||||||
if (currentLoadSection)
|
if (!checkcodesection())
|
||||||
fatalerror("`LOAD` blocks cannot be nested\n");
|
return;
|
||||||
|
|
||||||
if (sect_HasData(type))
|
if (currentLoadSection) {
|
||||||
|
error("`LOAD` blocks cannot be nested\n");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (sect_HasData(type)) {
|
||||||
error("`LOAD` blocks cannot create a ROM section\n");
|
error("`LOAD` blocks cannot create a ROM section\n");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (mod == SECTION_FRAGMENT) {
|
||||||
|
error("`LOAD FRAGMENT` is not allowed\n");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
struct Section *sect = getSection(name, type, org, attribs, mod);
|
struct Section *sect = getSection(name, type, org, attribs, mod);
|
||||||
|
|
||||||
@@ -420,10 +460,12 @@ void out_SetLoadSection(char const *name, uint32_t type, uint32_t org,
|
|||||||
currentLoadSection = sect;
|
currentLoadSection = sect;
|
||||||
}
|
}
|
||||||
|
|
||||||
void out_EndLoadSection(void)
|
void sect_EndLoadSection(void)
|
||||||
{
|
{
|
||||||
if (!currentLoadSection)
|
if (!currentLoadSection) {
|
||||||
error("Found `ENDL` outside of a `LOAD` block\n");
|
error("Found `ENDL` outside of a `LOAD` block\n");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
changeSection();
|
changeSection();
|
||||||
curOffset += loadOffset;
|
curOffset += loadOffset;
|
||||||
@@ -433,7 +475,7 @@ void out_EndLoadSection(void)
|
|||||||
|
|
||||||
struct Section *sect_GetSymbolSection(void)
|
struct Section *sect_GetSymbolSection(void)
|
||||||
{
|
{
|
||||||
return currentLoadSection ? currentLoadSection : pCurrentSection;
|
return currentLoadSection ? currentLoadSection : currentSection;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@@ -451,7 +493,9 @@ uint32_t sect_GetOutputOffset(void)
|
|||||||
|
|
||||||
void sect_AlignPC(uint8_t alignment, uint16_t offset)
|
void sect_AlignPC(uint8_t alignment, uint16_t offset)
|
||||||
{
|
{
|
||||||
checksection();
|
if (!checksection())
|
||||||
|
return;
|
||||||
|
|
||||||
struct Section *sect = sect_GetSymbolSection();
|
struct Section *sect = sect_GetSymbolSection();
|
||||||
uint16_t alignSize = 1 << alignment; // Size of an aligned "block"
|
uint16_t alignSize = 1 << alignment; // Size of an aligned "block"
|
||||||
|
|
||||||
@@ -477,15 +521,15 @@ void sect_AlignPC(uint8_t alignment, uint16_t offset)
|
|||||||
static void growSection(uint32_t growth)
|
static void growSection(uint32_t growth)
|
||||||
{
|
{
|
||||||
curOffset += growth;
|
curOffset += growth;
|
||||||
if (curOffset + loadOffset > pCurrentSection->size)
|
if (curOffset + loadOffset > currentSection->size)
|
||||||
pCurrentSection->size = curOffset + loadOffset;
|
currentSection->size = curOffset + loadOffset;
|
||||||
if (currentLoadSection && curOffset > currentLoadSection->size)
|
if (currentLoadSection && curOffset > currentLoadSection->size)
|
||||||
currentLoadSection->size = curOffset;
|
currentLoadSection->size = curOffset;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void writebyte(uint8_t byte)
|
static void writebyte(uint8_t byte)
|
||||||
{
|
{
|
||||||
pCurrentSection->data[sect_GetOutputOffset()] = byte;
|
currentSection->data[sect_GetOutputOffset()] = byte;
|
||||||
growSection(1);
|
growSection(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -510,10 +554,19 @@ static void createPatch(enum PatchType type, struct Expression const *expr, uint
|
|||||||
|
|
||||||
void sect_StartUnion(void)
|
void sect_StartUnion(void)
|
||||||
{
|
{
|
||||||
if (!pCurrentSection)
|
// Important info: currently, UNION and LOAD cannot interact, since UNION is prohibited in
|
||||||
fatalerror("UNIONs must be inside a SECTION\n");
|
// "code" sections, whereas LOAD is restricted to them.
|
||||||
if (sect_HasData(pCurrentSection->type))
|
// Therefore, any interactions are NOT TESTED, so lift either of those restrictions at
|
||||||
fatalerror("Cannot use UNION inside of ROM0 or ROMX sections\n");
|
// your own peril! ^^
|
||||||
|
|
||||||
|
if (!currentSection) {
|
||||||
|
error("UNIONs must be inside a SECTION\n");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (sect_HasData(currentSection->type)) {
|
||||||
|
error("Cannot use UNION inside of ROM0 or ROMX sections\n");
|
||||||
|
return;
|
||||||
|
}
|
||||||
struct UnionStackEntry *entry = malloc(sizeof(*entry));
|
struct UnionStackEntry *entry = malloc(sizeof(*entry));
|
||||||
|
|
||||||
if (!entry)
|
if (!entry)
|
||||||
@@ -535,15 +588,19 @@ static void endUnionMember(void)
|
|||||||
|
|
||||||
void sect_NextUnionMember(void)
|
void sect_NextUnionMember(void)
|
||||||
{
|
{
|
||||||
if (!unionStack)
|
if (!unionStack) {
|
||||||
fatalerror("Found NEXTU outside of a UNION construct\n");
|
error("Found NEXTU outside of a UNION construct\n");
|
||||||
|
return;
|
||||||
|
}
|
||||||
endUnionMember();
|
endUnionMember();
|
||||||
}
|
}
|
||||||
|
|
||||||
void sect_EndUnion(void)
|
void sect_EndUnion(void)
|
||||||
{
|
{
|
||||||
if (!unionStack)
|
if (!unionStack) {
|
||||||
fatalerror("Found ENDU outside of a UNION construct\n");
|
error("Found ENDU outside of a UNION construct\n");
|
||||||
|
return;
|
||||||
|
}
|
||||||
endUnionMember();
|
endUnionMember();
|
||||||
curOffset += unionStack->size;
|
curOffset += unionStack->size;
|
||||||
struct UnionStackEntry *next = unionStack->next;
|
struct UnionStackEntry *next = unionStack->next;
|
||||||
@@ -561,36 +618,44 @@ void sect_CheckUnionClosed(void)
|
|||||||
/*
|
/*
|
||||||
* Output an absolute byte
|
* Output an absolute byte
|
||||||
*/
|
*/
|
||||||
void out_AbsByte(uint8_t b)
|
void sect_AbsByte(uint8_t b)
|
||||||
{
|
{
|
||||||
checkcodesection();
|
if (!checkcodesection())
|
||||||
reserveSpace(1);
|
return;
|
||||||
|
if (!reserveSpace(1))
|
||||||
|
return;
|
||||||
|
|
||||||
writebyte(b);
|
writebyte(b);
|
||||||
}
|
}
|
||||||
|
|
||||||
void out_AbsByteGroup(uint8_t const *s, int32_t length)
|
void sect_AbsByteGroup(uint8_t const *s, size_t length)
|
||||||
{
|
{
|
||||||
checkcodesection();
|
if (!checkcodesection())
|
||||||
reserveSpace(length);
|
return;
|
||||||
|
if (!reserveSpace(length))
|
||||||
|
return;
|
||||||
|
|
||||||
while (length--)
|
while (length--)
|
||||||
writebyte(*s++);
|
writebyte(*s++);
|
||||||
}
|
}
|
||||||
|
|
||||||
void out_AbsWordGroup(uint8_t const *s, int32_t length)
|
void sect_AbsWordGroup(uint8_t const *s, size_t length)
|
||||||
{
|
{
|
||||||
checkcodesection();
|
if (!checkcodesection())
|
||||||
reserveSpace(length * 2);
|
return;
|
||||||
|
if (!reserveSpace(length * 2))
|
||||||
|
return;
|
||||||
|
|
||||||
while (length--)
|
while (length--)
|
||||||
writeword(*s++);
|
writeword(*s++);
|
||||||
}
|
}
|
||||||
|
|
||||||
void out_AbsLongGroup(uint8_t const *s, int32_t length)
|
void sect_AbsLongGroup(uint8_t const *s, size_t length)
|
||||||
{
|
{
|
||||||
checkcodesection();
|
if (!checkcodesection())
|
||||||
reserveSpace(length * 4);
|
return;
|
||||||
|
if (!reserveSpace(length * 4))
|
||||||
|
return;
|
||||||
|
|
||||||
while (length--)
|
while (length--)
|
||||||
writelong(*s++);
|
writelong(*s++);
|
||||||
@@ -599,19 +664,20 @@ void out_AbsLongGroup(uint8_t const *s, int32_t length)
|
|||||||
/*
|
/*
|
||||||
* Skip this many bytes
|
* Skip this many bytes
|
||||||
*/
|
*/
|
||||||
void out_Skip(int32_t skip, bool ds)
|
void sect_Skip(uint32_t skip, bool ds)
|
||||||
{
|
{
|
||||||
checksection();
|
if (!checksection())
|
||||||
reserveSpace(skip);
|
return;
|
||||||
|
if (!reserveSpace(skip))
|
||||||
|
return;
|
||||||
|
|
||||||
if (!ds && sect_HasData(pCurrentSection->type))
|
if (!sect_HasData(currentSection->type)) {
|
||||||
warning(WARNING_EMPTY_DATA_DIRECTIVE, "%s directive without data in ROM\n",
|
|
||||||
(skip == 4) ? "DL" : (skip == 2) ? "DW" : "DB");
|
|
||||||
|
|
||||||
if (!sect_HasData(pCurrentSection->type)) {
|
|
||||||
growSection(skip);
|
growSection(skip);
|
||||||
} else {
|
} else {
|
||||||
checkcodesection();
|
if (!ds)
|
||||||
|
warning(WARNING_EMPTY_DATA_DIRECTIVE, "%s directive without data in ROM\n",
|
||||||
|
(skip == 4) ? "DL" : (skip == 2) ? "DW" : "DB");
|
||||||
|
// We know we're in a code SECTION
|
||||||
while (skip--)
|
while (skip--)
|
||||||
writebyte(fillByte);
|
writebyte(fillByte);
|
||||||
}
|
}
|
||||||
@@ -620,10 +686,12 @@ void out_Skip(int32_t skip, bool ds)
|
|||||||
/*
|
/*
|
||||||
* Output a NULL terminated string (excluding the NULL-character)
|
* Output a NULL terminated string (excluding the NULL-character)
|
||||||
*/
|
*/
|
||||||
void out_String(char const *s)
|
void sect_String(char const *s)
|
||||||
{
|
{
|
||||||
checkcodesection();
|
if (!checkcodesection())
|
||||||
reserveSpace(strlen(s));
|
return;
|
||||||
|
if (!reserveSpace(strlen(s)))
|
||||||
|
return;
|
||||||
|
|
||||||
while (*s)
|
while (*s)
|
||||||
writebyte(*s++);
|
writebyte(*s++);
|
||||||
@@ -633,16 +701,18 @@ void out_String(char const *s)
|
|||||||
* Output a relocatable byte. Checking will be done to see if it
|
* Output a relocatable byte. Checking will be done to see if it
|
||||||
* is an absolute value in disguise.
|
* is an absolute value in disguise.
|
||||||
*/
|
*/
|
||||||
void out_RelByte(struct Expression *expr, uint32_t pcShift)
|
void sect_RelByte(struct Expression *expr, uint32_t pcShift)
|
||||||
{
|
{
|
||||||
checkcodesection();
|
if (!checkcodesection())
|
||||||
reserveSpace(1);
|
return;
|
||||||
|
if (!reserveSpace(1))
|
||||||
|
return;
|
||||||
|
|
||||||
if (!rpn_isKnown(expr)) {
|
if (!rpn_isKnown(expr)) {
|
||||||
createPatch(PATCHTYPE_BYTE, expr, pcShift);
|
createPatch(PATCHTYPE_BYTE, expr, pcShift);
|
||||||
writebyte(0);
|
writebyte(0);
|
||||||
} else {
|
} else {
|
||||||
writebyte(expr->nVal);
|
writebyte(expr->val);
|
||||||
}
|
}
|
||||||
rpn_Free(expr);
|
rpn_Free(expr);
|
||||||
}
|
}
|
||||||
@@ -651,10 +721,12 @@ void out_RelByte(struct Expression *expr, uint32_t pcShift)
|
|||||||
* Output several copies of a relocatable byte. Checking will be done to see if
|
* Output several copies of a relocatable byte. Checking will be done to see if
|
||||||
* it is an absolute value in disguise.
|
* it is an absolute value in disguise.
|
||||||
*/
|
*/
|
||||||
void out_RelBytes(uint32_t n, struct Expression *exprs, size_t size)
|
void sect_RelBytes(uint32_t n, struct Expression *exprs, size_t size)
|
||||||
{
|
{
|
||||||
checkcodesection();
|
if (!checkcodesection())
|
||||||
reserveSpace(n);
|
return;
|
||||||
|
if (!reserveSpace(n))
|
||||||
|
return;
|
||||||
|
|
||||||
for (uint32_t i = 0; i < n; i++) {
|
for (uint32_t i = 0; i < n; i++) {
|
||||||
struct Expression *expr = &exprs[i % size];
|
struct Expression *expr = &exprs[i % size];
|
||||||
@@ -663,7 +735,7 @@ void out_RelBytes(uint32_t n, struct Expression *exprs, size_t size)
|
|||||||
createPatch(PATCHTYPE_BYTE, expr, i);
|
createPatch(PATCHTYPE_BYTE, expr, i);
|
||||||
writebyte(0);
|
writebyte(0);
|
||||||
} else {
|
} else {
|
||||||
writebyte(expr->nVal);
|
writebyte(expr->val);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -675,16 +747,18 @@ void out_RelBytes(uint32_t n, struct Expression *exprs, size_t size)
|
|||||||
* Output a relocatable word. Checking will be done to see if
|
* Output a relocatable word. Checking will be done to see if
|
||||||
* it's an absolute value in disguise.
|
* it's an absolute value in disguise.
|
||||||
*/
|
*/
|
||||||
void out_RelWord(struct Expression *expr, uint32_t pcShift)
|
void sect_RelWord(struct Expression *expr, uint32_t pcShift)
|
||||||
{
|
{
|
||||||
checkcodesection();
|
if (!checkcodesection())
|
||||||
reserveSpace(2);
|
return;
|
||||||
|
if (!reserveSpace(2))
|
||||||
|
return;
|
||||||
|
|
||||||
if (!rpn_isKnown(expr)) {
|
if (!rpn_isKnown(expr)) {
|
||||||
createPatch(PATCHTYPE_WORD, expr, pcShift);
|
createPatch(PATCHTYPE_WORD, expr, pcShift);
|
||||||
writeword(0);
|
writeword(0);
|
||||||
} else {
|
} else {
|
||||||
writeword(expr->nVal);
|
writeword(expr->val);
|
||||||
}
|
}
|
||||||
rpn_Free(expr);
|
rpn_Free(expr);
|
||||||
}
|
}
|
||||||
@@ -693,16 +767,18 @@ void out_RelWord(struct Expression *expr, uint32_t pcShift)
|
|||||||
* Output a relocatable longword. Checking will be done to see if
|
* Output a relocatable longword. Checking will be done to see if
|
||||||
* is an absolute value in disguise.
|
* is an absolute value in disguise.
|
||||||
*/
|
*/
|
||||||
void out_RelLong(struct Expression *expr, uint32_t pcShift)
|
void sect_RelLong(struct Expression *expr, uint32_t pcShift)
|
||||||
{
|
{
|
||||||
checkcodesection();
|
if (!checkcodesection())
|
||||||
reserveSpace(2);
|
return;
|
||||||
|
if (!reserveSpace(2))
|
||||||
|
return;
|
||||||
|
|
||||||
if (!rpn_isKnown(expr)) {
|
if (!rpn_isKnown(expr)) {
|
||||||
createPatch(PATCHTYPE_LONG, expr, pcShift);
|
createPatch(PATCHTYPE_LONG, expr, pcShift);
|
||||||
writelong(0);
|
writelong(0);
|
||||||
} else {
|
} else {
|
||||||
writelong(expr->nVal);
|
writelong(expr->val);
|
||||||
}
|
}
|
||||||
rpn_Free(expr);
|
rpn_Free(expr);
|
||||||
}
|
}
|
||||||
@@ -711,10 +787,12 @@ void out_RelLong(struct Expression *expr, uint32_t pcShift)
|
|||||||
* Output a PC-relative relocatable byte. Checking will be done to see if it
|
* Output a PC-relative relocatable byte. Checking will be done to see if it
|
||||||
* is an absolute value in disguise.
|
* is an absolute value in disguise.
|
||||||
*/
|
*/
|
||||||
void out_PCRelByte(struct Expression *expr, uint32_t pcShift)
|
void sect_PCRelByte(struct Expression *expr, uint32_t pcShift)
|
||||||
{
|
{
|
||||||
checkcodesection();
|
if (!checkcodesection())
|
||||||
reserveSpace(1);
|
return;
|
||||||
|
if (!reserveSpace(1))
|
||||||
|
return;
|
||||||
struct Symbol const *pc = sym_GetPC();
|
struct Symbol const *pc = sym_GetPC();
|
||||||
|
|
||||||
if (!rpn_IsDiffConstant(expr, pc)) {
|
if (!rpn_IsDiffConstant(expr, pc)) {
|
||||||
@@ -745,12 +823,14 @@ void out_PCRelByte(struct Expression *expr, uint32_t pcShift)
|
|||||||
/*
|
/*
|
||||||
* Output a binary file
|
* Output a binary file
|
||||||
*/
|
*/
|
||||||
void out_BinaryFile(char const *s, int32_t startPos)
|
void sect_BinaryFile(char const *s, int32_t startPos)
|
||||||
{
|
{
|
||||||
if (startPos < 0) {
|
if (startPos < 0) {
|
||||||
error("Start position cannot be negative (%" PRId32 ")\n", startPos);
|
error("Start position cannot be negative (%" PRId32 ")\n", startPos);
|
||||||
startPos = 0;
|
startPos = 0;
|
||||||
}
|
}
|
||||||
|
if (!checkcodesection())
|
||||||
|
return;
|
||||||
|
|
||||||
char *fullPath = NULL;
|
char *fullPath = NULL;
|
||||||
size_t size = 0;
|
size_t size = 0;
|
||||||
@@ -761,10 +841,10 @@ void out_BinaryFile(char const *s, int32_t startPos)
|
|||||||
free(fullPath);
|
free(fullPath);
|
||||||
|
|
||||||
if (!f) {
|
if (!f) {
|
||||||
if (oGeneratedMissingIncludes) {
|
if (generatedMissingIncludes) {
|
||||||
if (verbose)
|
if (verbose)
|
||||||
printf("Aborting (-MG) on INCBIN file '%s' (%s)\n", s, strerror(errno));
|
printf("Aborting (-MG) on INCBIN file '%s' (%s)\n", s, strerror(errno));
|
||||||
oFailedOnMissingInclude = true;
|
failedOnMissingInclude = true;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
error("Error opening INCBIN file '%s': %s\n", s, strerror(errno));
|
error("Error opening INCBIN file '%s': %s\n", s, strerror(errno));
|
||||||
@@ -774,7 +854,6 @@ void out_BinaryFile(char const *s, int32_t startPos)
|
|||||||
int32_t fsize = -1;
|
int32_t fsize = -1;
|
||||||
int byte;
|
int byte;
|
||||||
|
|
||||||
checkcodesection();
|
|
||||||
if (fseek(f, 0, SEEK_END) != -1) {
|
if (fseek(f, 0, SEEK_END) != -1) {
|
||||||
fsize = ftell(f);
|
fsize = ftell(f);
|
||||||
|
|
||||||
@@ -784,7 +863,8 @@ void out_BinaryFile(char const *s, int32_t startPos)
|
|||||||
}
|
}
|
||||||
|
|
||||||
fseek(f, startPos, SEEK_SET);
|
fseek(f, startPos, SEEK_SET);
|
||||||
reserveSpace(fsize - startPos);
|
if (!reserveSpace(fsize - startPos))
|
||||||
|
goto cleanup;
|
||||||
} else {
|
} else {
|
||||||
if (errno != ESPIPE)
|
if (errno != ESPIPE)
|
||||||
error("Error determining size of INCBIN file '%s': %s\n",
|
error("Error determining size of INCBIN file '%s': %s\n",
|
||||||
@@ -807,7 +887,7 @@ cleanup:
|
|||||||
fclose(f);
|
fclose(f);
|
||||||
}
|
}
|
||||||
|
|
||||||
void out_BinaryFileSlice(char const *s, int32_t start_pos, int32_t length)
|
void sect_BinaryFileSlice(char const *s, int32_t start_pos, int32_t length)
|
||||||
{
|
{
|
||||||
if (start_pos < 0) {
|
if (start_pos < 0) {
|
||||||
error("Start position cannot be negative (%" PRId32 ")\n", start_pos);
|
error("Start position cannot be negative (%" PRId32 ")\n", start_pos);
|
||||||
@@ -818,8 +898,13 @@ void out_BinaryFileSlice(char const *s, int32_t start_pos, int32_t length)
|
|||||||
error("Number of bytes to read cannot be negative (%" PRId32 ")\n", length);
|
error("Number of bytes to read cannot be negative (%" PRId32 ")\n", length);
|
||||||
length = 0;
|
length = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!checkcodesection())
|
||||||
|
return;
|
||||||
if (length == 0) /* Don't even bother with 0-byte slices */
|
if (length == 0) /* Don't even bother with 0-byte slices */
|
||||||
return;
|
return;
|
||||||
|
if (!reserveSpace(length))
|
||||||
|
return;
|
||||||
|
|
||||||
char *fullPath = NULL;
|
char *fullPath = NULL;
|
||||||
size_t size = 0;
|
size_t size = 0;
|
||||||
@@ -830,19 +915,16 @@ void out_BinaryFileSlice(char const *s, int32_t start_pos, int32_t length)
|
|||||||
free(fullPath);
|
free(fullPath);
|
||||||
|
|
||||||
if (!f) {
|
if (!f) {
|
||||||
if (oGeneratedMissingIncludes) {
|
if (generatedMissingIncludes) {
|
||||||
if (verbose)
|
if (verbose)
|
||||||
printf("Aborting (-MG) on INCBIN file '%s' (%s)\n", s, strerror(errno));
|
printf("Aborting (-MG) on INCBIN file '%s' (%s)\n", s, strerror(errno));
|
||||||
oFailedOnMissingInclude = true;
|
failedOnMissingInclude = true;
|
||||||
} else {
|
} else {
|
||||||
error("Error opening INCBIN file '%s': %s\n", s, strerror(errno));
|
error("Error opening INCBIN file '%s': %s\n", s, strerror(errno));
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
checkcodesection();
|
|
||||||
reserveSpace(length);
|
|
||||||
|
|
||||||
int32_t fsize;
|
int32_t fsize;
|
||||||
|
|
||||||
if (fseek(f, 0, SEEK_END) != -1) {
|
if (fseek(f, 0, SEEK_END) != -1) {
|
||||||
@@ -869,9 +951,7 @@ void out_BinaryFileSlice(char const *s, int32_t start_pos, int32_t length)
|
|||||||
(void)fgetc(f);
|
(void)fgetc(f);
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t todo = length;
|
while (length--) {
|
||||||
|
|
||||||
while (todo--) {
|
|
||||||
int byte = fgetc(f);
|
int byte = fgetc(f);
|
||||||
|
|
||||||
if (byte != EOF) {
|
if (byte != EOF) {
|
||||||
@@ -880,7 +960,7 @@ void out_BinaryFileSlice(char const *s, int32_t start_pos, int32_t length)
|
|||||||
error("Error reading INCBIN file '%s': %s\n", s, strerror(errno));
|
error("Error reading INCBIN file '%s': %s\n", s, strerror(errno));
|
||||||
} else {
|
} else {
|
||||||
error("Premature end of file (%" PRId32 " bytes left to read)\n",
|
error("Premature end of file (%" PRId32 " bytes left to read)\n",
|
||||||
todo + 1);
|
length + 1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -891,21 +971,29 @@ cleanup:
|
|||||||
/*
|
/*
|
||||||
* Section stack routines
|
* Section stack routines
|
||||||
*/
|
*/
|
||||||
void out_PushSection(void)
|
void sect_PushSection(void)
|
||||||
{
|
{
|
||||||
struct SectionStackEntry *sect = malloc(sizeof(*sect));
|
struct SectionStackEntry *entry = malloc(sizeof(*entry));
|
||||||
|
|
||||||
if (sect == NULL)
|
if (entry == NULL)
|
||||||
fatalerror("No memory for section stack: %s\n", strerror(errno));
|
fatalerror("No memory for section stack: %s\n", strerror(errno));
|
||||||
sect->section = pCurrentSection;
|
entry->section = currentSection;
|
||||||
sect->scope = sym_GetCurrentSymbolScope();
|
entry->loadSection = currentLoadSection;
|
||||||
sect->offset = curOffset;
|
entry->scope = sym_GetCurrentSymbolScope();
|
||||||
sect->next = sectionStack;
|
entry->offset = curOffset;
|
||||||
sectionStack = sect;
|
entry->loadOffset = loadOffset;
|
||||||
/* TODO: maybe set current section to NULL? */
|
entry->unionStack = unionStack;
|
||||||
|
entry->next = sectionStack;
|
||||||
|
sectionStack = entry;
|
||||||
|
|
||||||
|
// Reset the section scope
|
||||||
|
currentSection = NULL;
|
||||||
|
currentLoadSection = NULL;
|
||||||
|
sym_SetCurrentSymbolScope(NULL);
|
||||||
|
unionStack = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
void out_PopSection(void)
|
void sect_PopSection(void)
|
||||||
{
|
{
|
||||||
if (!sectionStack)
|
if (!sectionStack)
|
||||||
fatalerror("No entries in the section stack\n");
|
fatalerror("No entries in the section stack\n");
|
||||||
@@ -913,14 +1001,35 @@ void out_PopSection(void)
|
|||||||
if (currentLoadSection)
|
if (currentLoadSection)
|
||||||
fatalerror("Cannot change the section within a `LOAD` block!\n");
|
fatalerror("Cannot change the section within a `LOAD` block!\n");
|
||||||
|
|
||||||
struct SectionStackEntry *sect;
|
struct SectionStackEntry *entry = sectionStack;
|
||||||
|
|
||||||
sect = sectionStack;
|
|
||||||
changeSection();
|
changeSection();
|
||||||
pCurrentSection = sect->section;
|
currentSection = entry->section;
|
||||||
sym_SetCurrentSymbolScope(sect->scope);
|
currentLoadSection = entry->loadSection;
|
||||||
curOffset = sect->offset;
|
sym_SetCurrentSymbolScope(entry->scope);
|
||||||
|
curOffset = entry->offset;
|
||||||
|
loadOffset = entry->loadOffset;
|
||||||
|
unionStack = entry->unionStack;
|
||||||
|
|
||||||
sectionStack = sect->next;
|
sectionStack = entry->next;
|
||||||
free(sect);
|
free(entry);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool sect_IsSizeKnown(struct Section const NONNULL(sect))
|
||||||
|
{
|
||||||
|
// SECTION UNION and SECTION FRAGMENT can still grow
|
||||||
|
if (sect->modifier != SECTION_NORMAL)
|
||||||
|
return false;
|
||||||
|
|
||||||
|
// The current section (or current load section if within one) is still growing
|
||||||
|
if (sect == currentSection || sect == currentLoadSection)
|
||||||
|
return false;
|
||||||
|
|
||||||
|
// Any section on the stack is still growing
|
||||||
|
for (struct SectionStackEntry *stack = sectionStack; stack; stack = stack->next) {
|
||||||
|
if (stack->section && !strcmp(sect->name, stack->section->name))
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|||||||
269
src/asm/symbol.c
269
src/asm/symbol.c
@@ -29,8 +29,7 @@
|
|||||||
#include "asm/util.h"
|
#include "asm/util.h"
|
||||||
#include "asm/warning.h"
|
#include "asm/warning.h"
|
||||||
|
|
||||||
#include "extern/err.h"
|
#include "error.h"
|
||||||
|
|
||||||
#include "hashmap.h"
|
#include "hashmap.h"
|
||||||
#include "helpers.h"
|
#include "helpers.h"
|
||||||
#include "version.h"
|
#include "version.h"
|
||||||
@@ -51,16 +50,16 @@ bool sym_IsPC(struct Symbol const *sym)
|
|||||||
}
|
}
|
||||||
|
|
||||||
struct ForEachArgs {
|
struct ForEachArgs {
|
||||||
void (*func)(struct Symbol *symbol, void *arg);
|
void (*func)(struct Symbol *sym, void *arg);
|
||||||
void *arg;
|
void *arg;
|
||||||
};
|
};
|
||||||
|
|
||||||
static void forEachWrapper(void *_symbol, void *_argWrapper)
|
static void forEachWrapper(void *_sym, void *_argWrapper)
|
||||||
{
|
{
|
||||||
struct ForEachArgs *argWrapper = _argWrapper;
|
struct ForEachArgs *argWrapper = _argWrapper;
|
||||||
struct Symbol *symbol = _symbol;
|
struct Symbol *sym = _sym;
|
||||||
|
|
||||||
argWrapper->func(symbol, argWrapper->arg);
|
argWrapper->func(sym, argWrapper->arg);
|
||||||
}
|
}
|
||||||
|
|
||||||
void sym_ForEach(void (*func)(struct Symbol *, void *), void *arg)
|
void sym_ForEach(void (*func)(struct Symbol *, void *), void *arg)
|
||||||
@@ -96,7 +95,6 @@ static char const *Callback__FILE__(void)
|
|||||||
char const *fileName = fstk_GetFileName();
|
char const *fileName = fstk_GetFileName();
|
||||||
size_t j = 1;
|
size_t j = 1;
|
||||||
|
|
||||||
/* TODO: is there a way for a file name to be empty? */
|
|
||||||
assert(fileName[0]);
|
assert(fileName[0]);
|
||||||
/* The assertion above ensures the loop runs at least once */
|
/* The assertion above ensures the loop runs at least once */
|
||||||
for (size_t i = 0; fileName[i]; i++, j++) {
|
for (size_t i = 0; fileName[i]; i++, j++) {
|
||||||
@@ -175,32 +173,32 @@ static void updateSymbolFilename(struct Symbol *sym)
|
|||||||
/* If the old node was referenced, ensure the new one is */
|
/* If the old node was referenced, ensure the new one is */
|
||||||
if (oldSrc && oldSrc->referenced && oldSrc->ID != (uint32_t)-1)
|
if (oldSrc && oldSrc->referenced && oldSrc->ID != (uint32_t)-1)
|
||||||
out_RegisterNode(sym->src);
|
out_RegisterNode(sym->src);
|
||||||
/* TODO: unref the old node, and use `out_ReplaceNode` instead if deleting it */
|
/* TODO: unref the old node, and use `out_ReplaceNode` instead of deleting it */
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Create a new symbol by name
|
* Create a new symbol by name
|
||||||
*/
|
*/
|
||||||
static struct Symbol *createsymbol(char const *s)
|
static struct Symbol *createsymbol(char const *symName)
|
||||||
{
|
{
|
||||||
struct Symbol *symbol = malloc(sizeof(*symbol));
|
struct Symbol *sym = malloc(sizeof(*sym));
|
||||||
|
|
||||||
if (!symbol)
|
if (!sym)
|
||||||
fatalerror("Failed to create symbol '%s': %s\n", s, strerror(errno));
|
fatalerror("Failed to create symbol '%s': %s\n", symName, strerror(errno));
|
||||||
|
|
||||||
if (snprintf(symbol->name, MAXSYMLEN + 1, "%s", s) > MAXSYMLEN)
|
if (snprintf(sym->name, MAXSYMLEN + 1, "%s", symName) > MAXSYMLEN)
|
||||||
warning(WARNING_LONG_STR, "Symbol name is too long: '%s'\n", s);
|
warning(WARNING_LONG_STR, "Symbol name is too long: '%s'\n", symName);
|
||||||
|
|
||||||
symbol->isExported = false;
|
sym->isExported = false;
|
||||||
symbol->isBuiltin = false;
|
sym->isBuiltin = false;
|
||||||
symbol->hasCallback = false;
|
sym->hasCallback = false;
|
||||||
symbol->section = NULL;
|
sym->section = NULL;
|
||||||
setSymbolFilename(symbol);
|
setSymbolFilename(sym);
|
||||||
symbol->ID = -1;
|
sym->ID = -1;
|
||||||
symbol->next = NULL;
|
sym->next = NULL;
|
||||||
|
|
||||||
hash_AddElement(symbols, symbol->name, symbol);
|
hash_AddElement(symbols, sym->name, sym);
|
||||||
return symbol;
|
return sym;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@@ -222,46 +220,45 @@ static void assignStringSymbol(struct Symbol *sym, char const *value)
|
|||||||
{
|
{
|
||||||
char *string = strdup(value);
|
char *string = strdup(value);
|
||||||
|
|
||||||
if (string == NULL)
|
if (!string)
|
||||||
fatalerror("No memory for string equate: %s\n", strerror(errno));
|
fatalerror("No memory for string equate: %s\n", strerror(errno));
|
||||||
|
|
||||||
sym->type = SYM_EQUS;
|
sym->type = SYM_EQUS;
|
||||||
/* TODO: use other fields */
|
|
||||||
sym->macro = string;
|
sym->macro = string;
|
||||||
sym->macroSize = strlen(string);
|
sym->macroSize = strlen(string);
|
||||||
}
|
}
|
||||||
|
|
||||||
struct Symbol *sym_FindExactSymbol(char const *name)
|
struct Symbol *sym_FindExactSymbol(char const *symName)
|
||||||
{
|
{
|
||||||
return hash_GetElement(symbols, name);
|
return hash_GetElement(symbols, symName);
|
||||||
}
|
}
|
||||||
|
|
||||||
struct Symbol *sym_FindUnscopedSymbol(char const *name)
|
struct Symbol *sym_FindUnscopedSymbol(char const *symName)
|
||||||
{
|
{
|
||||||
if (strchr(name, '.')) {
|
if (strchr(symName, '.')) {
|
||||||
error("Expected non-scoped symbol name, not \"%s\"\n", name);
|
error("Expected non-scoped symbol name, not \"%s\"\n", symName);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
return sym_FindExactSymbol(name);
|
return sym_FindExactSymbol(symName);
|
||||||
}
|
}
|
||||||
|
|
||||||
struct Symbol *sym_FindScopedSymbol(char const *name)
|
struct Symbol *sym_FindScopedSymbol(char const *symName)
|
||||||
{
|
{
|
||||||
char const *dotPtr = strchr(name, '.');
|
char const *localName = strchr(symName, '.');
|
||||||
|
|
||||||
if (dotPtr) {
|
if (localName) {
|
||||||
if (strchr(dotPtr + 1, '.'))
|
if (strchr(localName + 1, '.'))
|
||||||
fatalerror("'%s' is a nonsensical reference to a nested local symbol\n",
|
fatalerror("'%s' is a nonsensical reference to a nested local symbol\n",
|
||||||
name);
|
symName);
|
||||||
/* If auto-scoped local label, expand the name */
|
/* If auto-scoped local label, expand the name */
|
||||||
if (dotPtr == name) { /* Meaning, the name begins with the dot */
|
if (localName == symName) { /* Meaning, the name begins with the dot */
|
||||||
char fullname[MAXSYMLEN + 1];
|
char fullName[MAXSYMLEN + 1];
|
||||||
|
|
||||||
fullSymbolName(fullname, sizeof(fullname), name, labelScope);
|
fullSymbolName(fullName, sizeof(fullName), symName, labelScope);
|
||||||
return sym_FindExactSymbol(fullname);
|
return sym_FindExactSymbol(fullName);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return sym_FindExactSymbol(name);
|
return sym_FindExactSymbol(symName);
|
||||||
}
|
}
|
||||||
|
|
||||||
struct Symbol const *sym_GetPC(void)
|
struct Symbol const *sym_GetPC(void)
|
||||||
@@ -279,27 +276,26 @@ static bool isReferenced(struct Symbol const *sym)
|
|||||||
*/
|
*/
|
||||||
void sym_Purge(char const *symName)
|
void sym_Purge(char const *symName)
|
||||||
{
|
{
|
||||||
struct Symbol *symbol = sym_FindScopedSymbol(symName);
|
struct Symbol *sym = sym_FindScopedSymbol(symName);
|
||||||
|
|
||||||
if (!symbol) {
|
if (!sym) {
|
||||||
error("'%s' not defined\n", symName);
|
error("'%s' not defined\n", symName);
|
||||||
} else if (symbol->isBuiltin) {
|
} else if (sym->isBuiltin) {
|
||||||
error("Built-in symbol '%s' cannot be purged\n", symName);
|
error("Built-in symbol '%s' cannot be purged\n", symName);
|
||||||
} else if (isReferenced(symbol)) {
|
} else if (isReferenced(sym)) {
|
||||||
error("Symbol \"%s\" is referenced and thus cannot be purged\n", symName);
|
error("Symbol \"%s\" is referenced and thus cannot be purged\n", symName);
|
||||||
} else {
|
} else {
|
||||||
/* Do not keep a reference to the label's name after purging it */
|
/* Do not keep a reference to the label's name after purging it */
|
||||||
if (symbol->name == labelScope)
|
if (sym->name == labelScope)
|
||||||
labelScope = NULL;
|
sym_SetCurrentSymbolScope(NULL);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* FIXME: this leaks symbol->macro for SYM_EQUS and SYM_MACRO, but this can't
|
* FIXME: this leaks sym->macro for SYM_EQUS and SYM_MACRO, but this can't
|
||||||
* free(symbol->macro) because the expansion may be purging itself.
|
* free(sym->macro) because the expansion may be purging itself.
|
||||||
*/
|
*/
|
||||||
|
hash_RemoveElement(symbols, sym->name);
|
||||||
hash_RemoveElement(symbols, symbol->name);
|
|
||||||
/* TODO: ideally, also unref the file stack nodes */
|
/* TODO: ideally, also unref the file stack nodes */
|
||||||
free(symbol);
|
free(sym);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -334,12 +330,12 @@ uint32_t sym_GetConstantSymValue(struct Symbol const *sym)
|
|||||||
/*
|
/*
|
||||||
* Return a constant symbol's value
|
* Return a constant symbol's value
|
||||||
*/
|
*/
|
||||||
uint32_t sym_GetConstantValue(char const *s)
|
uint32_t sym_GetConstantValue(char const *symName)
|
||||||
{
|
{
|
||||||
struct Symbol const *sym = sym_FindScopedSymbol(s);
|
struct Symbol const *sym = sym_FindScopedSymbol(symName);
|
||||||
|
|
||||||
if (sym == NULL)
|
if (!sym)
|
||||||
error("'%s' not defined\n", s);
|
error("'%s' not defined\n", symName);
|
||||||
else
|
else
|
||||||
return sym_GetConstantSymValue(sym);
|
return sym_GetConstantSymValue(sym);
|
||||||
|
|
||||||
@@ -360,29 +356,29 @@ void sym_SetCurrentSymbolScope(char const *newScope)
|
|||||||
* Create a symbol that will be non-relocatable and ensure that it
|
* Create a symbol that will be non-relocatable and ensure that it
|
||||||
* hasn't already been defined or referenced in a context that would
|
* hasn't already been defined or referenced in a context that would
|
||||||
* require that it be relocatable
|
* require that it be relocatable
|
||||||
* @param symbolName The name of the symbol to create
|
* @param symName The name of the symbol to create
|
||||||
* @param numeric If false, the symbol may not have been referenced earlier
|
* @param numeric If false, the symbol may not have been referenced earlier
|
||||||
*/
|
*/
|
||||||
static struct Symbol *createNonrelocSymbol(char const *symbolName, bool numeric)
|
static struct Symbol *createNonrelocSymbol(char const *symName, bool numeric)
|
||||||
{
|
{
|
||||||
struct Symbol *symbol = sym_FindExactSymbol(symbolName);
|
struct Symbol *sym = sym_FindExactSymbol(symName);
|
||||||
|
|
||||||
if (!symbol) {
|
if (!sym) {
|
||||||
symbol = createsymbol(symbolName);
|
sym = createsymbol(symName);
|
||||||
} else if (sym_IsDefined(symbol)) {
|
} else if (sym_IsDefined(sym)) {
|
||||||
error("'%s' already defined at ", symbolName);
|
error("'%s' already defined at ", symName);
|
||||||
dumpFilename(symbol);
|
dumpFilename(sym);
|
||||||
putc('\n', stderr);
|
putc('\n', stderr);
|
||||||
return NULL; // Don't allow overriding the symbol, that'd be bad!
|
return NULL; // Don't allow overriding the symbol, that'd be bad!
|
||||||
} else if (!numeric) {
|
} else if (!numeric) {
|
||||||
// The symbol has already been referenced, but it's not allowed
|
// The symbol has already been referenced, but it's not allowed
|
||||||
error("'%s' already referenced at ", symbolName);
|
error("'%s' already referenced at ", symName);
|
||||||
dumpFilename(symbol);
|
dumpFilename(sym);
|
||||||
putc('\n', stderr);
|
putc('\n', stderr);
|
||||||
return NULL; // Don't allow overriding the symbol, that'd be bad!
|
return NULL; // Don't allow overriding the symbol, that'd be bad!
|
||||||
}
|
}
|
||||||
|
|
||||||
return symbol;
|
return sym;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@@ -401,6 +397,30 @@ struct Symbol *sym_AddEqu(char const *symName, int32_t value)
|
|||||||
return sym;
|
return sym;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
struct Symbol *sym_RedefEqu(char const *symName, int32_t value)
|
||||||
|
{
|
||||||
|
struct Symbol *sym = sym_FindExactSymbol(symName);
|
||||||
|
|
||||||
|
if (!sym)
|
||||||
|
return sym_AddEqu(symName, value);
|
||||||
|
|
||||||
|
if (sym_IsDefined(sym) && sym->type != SYM_EQU) {
|
||||||
|
error("'%s' already defined as non-EQU at ", symName);
|
||||||
|
dumpFilename(sym);
|
||||||
|
putc('\n', stderr);
|
||||||
|
return NULL;
|
||||||
|
} else if (sym->isBuiltin) {
|
||||||
|
error("Built-in symbol '%s' cannot be redefined\n", symName);
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
updateSymbolFilename(sym);
|
||||||
|
sym->type = SYM_EQU;
|
||||||
|
sym->value = value;
|
||||||
|
|
||||||
|
return sym;
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Add a string equated symbol.
|
* Add a string equated symbol.
|
||||||
*
|
*
|
||||||
@@ -428,10 +448,14 @@ struct Symbol *sym_RedefString(char const *symName, char const *value)
|
|||||||
{
|
{
|
||||||
struct Symbol *sym = sym_FindExactSymbol(symName);
|
struct Symbol *sym = sym_FindExactSymbol(symName);
|
||||||
|
|
||||||
if (!sym) {
|
if (!sym)
|
||||||
sym = createsymbol(symName);
|
return sym_AddString(symName, value);
|
||||||
} else if (sym->type != SYM_EQUS) {
|
|
||||||
|
if (sym->type != SYM_EQUS) {
|
||||||
|
if (sym_IsDefined(sym))
|
||||||
error("'%s' already defined as non-EQUS at ", symName);
|
error("'%s' already defined as non-EQUS at ", symName);
|
||||||
|
else
|
||||||
|
error("'%s' already referenced at ", symName);
|
||||||
dumpFilename(sym);
|
dumpFilename(sym);
|
||||||
putc('\n', stderr);
|
putc('\n', stderr);
|
||||||
return NULL;
|
return NULL;
|
||||||
@@ -440,26 +464,26 @@ struct Symbol *sym_RedefString(char const *symName, char const *value)
|
|||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
updateSymbolFilename(sym);
|
||||||
/*
|
/*
|
||||||
* FIXME: this leaks the previous sym->macro value, but this can't
|
* FIXME: this leaks the previous sym->macro value, but this can't
|
||||||
* free(sym->macro) because the expansion may be redefining itself.
|
* free(sym->macro) because the expansion may be redefining itself.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
assignStringSymbol(sym, value);
|
assignStringSymbol(sym, value);
|
||||||
|
|
||||||
return sym;
|
return sym;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Alter a SET symbols value
|
* Alter a mutable symbol's value
|
||||||
*/
|
*/
|
||||||
struct Symbol *sym_AddSet(char const *symName, int32_t value)
|
struct Symbol *sym_AddVar(char const *symName, int32_t value)
|
||||||
{
|
{
|
||||||
struct Symbol *sym = sym_FindExactSymbol(symName);
|
struct Symbol *sym = sym_FindExactSymbol(symName);
|
||||||
|
|
||||||
if (sym == NULL) {
|
if (!sym) {
|
||||||
sym = createsymbol(symName);
|
sym = createsymbol(symName);
|
||||||
} else if (sym_IsDefined(sym) && sym->type != SYM_SET) {
|
} else if (sym_IsDefined(sym) && sym->type != SYM_VAR) {
|
||||||
error("'%s' already defined as %s at ",
|
error("'%s' already defined as %s at ",
|
||||||
symName, sym->type == SYM_LABEL ? "label" : "constant");
|
symName, sym->type == SYM_LABEL ? "label" : "constant");
|
||||||
dumpFilename(sym);
|
dumpFilename(sym);
|
||||||
@@ -469,7 +493,7 @@ struct Symbol *sym_AddSet(char const *symName, int32_t value)
|
|||||||
updateSymbolFilename(sym);
|
updateSymbolFilename(sym);
|
||||||
}
|
}
|
||||||
|
|
||||||
sym->type = SYM_SET;
|
sym->type = SYM_VAR;
|
||||||
sym->value = value;
|
sym->value = value;
|
||||||
|
|
||||||
return sym;
|
return sym;
|
||||||
@@ -477,18 +501,18 @@ struct Symbol *sym_AddSet(char const *symName, int32_t value)
|
|||||||
|
|
||||||
/*
|
/*
|
||||||
* Add a label (aka "relocatable symbol")
|
* Add a label (aka "relocatable symbol")
|
||||||
* @param name The label's full name (so `.name` is invalid)
|
* @param symName The label's full name (so `.name` is invalid)
|
||||||
* @return The created symbol
|
* @return The created symbol
|
||||||
*/
|
*/
|
||||||
static struct Symbol *addLabel(char const *name)
|
static struct Symbol *addLabel(char const *symName)
|
||||||
{
|
{
|
||||||
assert(name[0] != '.'); /* The symbol name must have been expanded prior */
|
assert(symName[0] != '.'); /* The symbol name must have been expanded prior */
|
||||||
struct Symbol *sym = sym_FindExactSymbol(name);
|
struct Symbol *sym = sym_FindExactSymbol(symName);
|
||||||
|
|
||||||
if (!sym) {
|
if (!sym) {
|
||||||
sym = createsymbol(name);
|
sym = createsymbol(symName);
|
||||||
} else if (sym_IsDefined(sym)) {
|
} else if (sym_IsDefined(sym)) {
|
||||||
error("'%s' already defined at ", name);
|
error("'%s' already defined at ", symName);
|
||||||
dumpFilename(sym);
|
dumpFilename(sym);
|
||||||
putc('\n', stderr);
|
putc('\n', stderr);
|
||||||
return NULL;
|
return NULL;
|
||||||
@@ -503,62 +527,68 @@ static struct Symbol *addLabel(char const *name)
|
|||||||
sym->section = sect_GetSymbolSection();
|
sym->section = sect_GetSymbolSection();
|
||||||
|
|
||||||
if (sym && !sym->section)
|
if (sym && !sym->section)
|
||||||
error("Label \"%s\" created outside of a SECTION\n", name);
|
error("Label \"%s\" created outside of a SECTION\n", symName);
|
||||||
return sym;
|
return sym;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Add a local (.name or Parent.name) relocatable symbol
|
* Add a local (`.name` or `Parent.name`) relocatable symbol
|
||||||
*/
|
*/
|
||||||
struct Symbol *sym_AddLocalLabel(char const *name)
|
struct Symbol *sym_AddLocalLabel(char const *symName)
|
||||||
{
|
{
|
||||||
if (!labelScope) {
|
if (!labelScope) {
|
||||||
error("Local label '%s' in main scope\n", name);
|
error("Local label '%s' in main scope\n", symName);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
assert(!strchr(labelScope, '.')); /* Assuming no dots in `labelScope` */
|
||||||
|
|
||||||
char fullname[MAXSYMLEN + 1];
|
char fullName[MAXSYMLEN + 1];
|
||||||
|
char const *localName = strchr(symName, '.');
|
||||||
|
|
||||||
if (name[0] == '.') {
|
assert(localName); /* There should be at least one dot in `symName` */
|
||||||
/* If symbol is of the form `.name`, expand to the full `Parent.name` name */
|
/* Check for something after the dot in `localName` */
|
||||||
fullSymbolName(fullname, sizeof(fullname), name, labelScope);
|
if (localName[1] == '\0') {
|
||||||
name = fullname; /* Use the expanded name instead */
|
fatalerror("'%s' is a nonsensical reference to an empty local label\n",
|
||||||
|
symName);
|
||||||
|
}
|
||||||
|
/* Check for more than one dot in `localName` */
|
||||||
|
if (strchr(localName + 1, '.'))
|
||||||
|
fatalerror("'%s' is a nonsensical reference to a nested local label\n",
|
||||||
|
symName);
|
||||||
|
|
||||||
|
if (localName == symName) {
|
||||||
|
/* Expand `symName` to the full `labelScope.symName` name */
|
||||||
|
fullSymbolName(fullName, sizeof(fullName), symName, labelScope);
|
||||||
|
symName = fullName;
|
||||||
} else {
|
} else {
|
||||||
size_t i = 0;
|
size_t i = 0;
|
||||||
|
|
||||||
/* Otherwise, check that `Parent` is in fact the current scope */
|
/* Find where `labelScope` and `symName` first differ */
|
||||||
while (labelScope[i] && name[i] == labelScope[i])
|
while (labelScope[i] && symName[i] == labelScope[i])
|
||||||
i++;
|
i++;
|
||||||
/* Assuming no dots in `labelScope` */
|
|
||||||
assert(strchr(&name[i], '.')); /* There should be at least one dot, though */
|
|
||||||
size_t parentLen = i + (strchr(&name[i], '.') - name);
|
|
||||||
|
|
||||||
/*
|
/* Check that `symName` starts with `labelScope` and then a '.' */
|
||||||
* Check that `labelScope[i]` ended the check, guaranteeing that `name` is at least
|
if (labelScope[i] != '\0' || symName[i] != '.') {
|
||||||
* as long, and then that this was the entirety of the `Parent` part of `name`.
|
size_t parentLen = localName - symName;
|
||||||
*/
|
|
||||||
if (labelScope[i] != '\0' || name[i] != '.') {
|
|
||||||
assert(parentLen <= INT_MAX);
|
assert(parentLen <= INT_MAX);
|
||||||
error("Not currently in the scope of '%.*s'\n", (int)parentLen, name);
|
error("Not currently in the scope of '%.*s'\n", (int)parentLen, symName);
|
||||||
}
|
}
|
||||||
if (strchr(&name[parentLen + 1], '.')) /* There will at least be a terminator */
|
|
||||||
fatalerror("'%s' is a nonsensical reference to a nested local label\n",
|
|
||||||
name);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return addLabel(name);
|
return addLabel(symName);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Add a relocatable symbol
|
* Add a relocatable symbol
|
||||||
*/
|
*/
|
||||||
struct Symbol *sym_AddLabel(char const *name)
|
struct Symbol *sym_AddLabel(char const *symName)
|
||||||
{
|
{
|
||||||
struct Symbol *sym = addLabel(name);
|
struct Symbol *sym = addLabel(symName);
|
||||||
|
|
||||||
/* Set the symbol as the new scope */
|
/* Set the symbol as the new scope */
|
||||||
if (sym)
|
if (sym)
|
||||||
labelScope = sym->name;
|
sym_SetCurrentSymbolScope(sym->name);
|
||||||
return sym;
|
return sym;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -653,9 +683,9 @@ struct Symbol *sym_AddMacro(char const *symName, int32_t defLineNo, char *body,
|
|||||||
*/
|
*/
|
||||||
struct Symbol *sym_Ref(char const *symName)
|
struct Symbol *sym_Ref(char const *symName)
|
||||||
{
|
{
|
||||||
struct Symbol *nsym = sym_FindScopedSymbol(symName);
|
struct Symbol *sym = sym_FindScopedSymbol(symName);
|
||||||
|
|
||||||
if (nsym == NULL) {
|
if (!sym) {
|
||||||
char fullname[MAXSYMLEN + 1];
|
char fullname[MAXSYMLEN + 1];
|
||||||
|
|
||||||
if (symName[0] == '.') {
|
if (symName[0] == '.') {
|
||||||
@@ -665,11 +695,11 @@ struct Symbol *sym_Ref(char const *symName)
|
|||||||
symName = fullname;
|
symName = fullname;
|
||||||
}
|
}
|
||||||
|
|
||||||
nsym = createsymbol(symName);
|
sym = createsymbol(symName);
|
||||||
nsym->type = SYM_REF;
|
sym->type = SYM_REF;
|
||||||
}
|
}
|
||||||
|
|
||||||
return nsym;
|
return sym;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@@ -680,9 +710,9 @@ void sym_SetExportAll(bool set)
|
|||||||
exportall = set;
|
exportall = set;
|
||||||
}
|
}
|
||||||
|
|
||||||
static struct Symbol *createBuiltinSymbol(char const *name)
|
static struct Symbol *createBuiltinSymbol(char const *symName)
|
||||||
{
|
{
|
||||||
struct Symbol *sym = createsymbol(name);
|
struct Symbol *sym = createsymbol(symName);
|
||||||
|
|
||||||
sym->isBuiltin = true;
|
sym->isBuiltin = true;
|
||||||
sym->hasCallback = true;
|
sym->hasCallback = true;
|
||||||
@@ -711,7 +741,7 @@ void sym_Init(time_t now)
|
|||||||
__FILE__Symbol->type = SYM_EQUS;
|
__FILE__Symbol->type = SYM_EQUS;
|
||||||
__FILE__Symbol->strCallback = Callback__FILE__;
|
__FILE__Symbol->strCallback = Callback__FILE__;
|
||||||
|
|
||||||
sym_AddSet("_RS", 0)->isBuiltin = true;
|
sym_AddVar("_RS", 0)->isBuiltin = true;
|
||||||
|
|
||||||
#define addNumber(name, val) sym_AddEqu(name, val)->isBuiltin = true
|
#define addNumber(name, val) sym_AddEqu(name, val)->isBuiltin = true
|
||||||
#define addString(name, val) sym_AddString(name, val)->isBuiltin = true
|
#define addString(name, val) sym_AddString(name, val)->isBuiltin = true
|
||||||
@@ -730,7 +760,6 @@ void sym_Init(time_t now)
|
|||||||
now = 0;
|
now = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
const struct tm *time_utc = gmtime(&now);
|
|
||||||
const struct tm *time_local = localtime(&now);
|
const struct tm *time_local = localtime(&now);
|
||||||
|
|
||||||
strftime(savedTIME, sizeof(savedTIME), "\"%H:%M:%S\"", time_local);
|
strftime(savedTIME, sizeof(savedTIME), "\"%H:%M:%S\"", time_local);
|
||||||
@@ -739,6 +768,8 @@ void sym_Init(time_t now)
|
|||||||
sizeof(savedTIMESTAMP_ISO8601_LOCAL), "\"%Y-%m-%dT%H:%M:%S%z\"",
|
sizeof(savedTIMESTAMP_ISO8601_LOCAL), "\"%Y-%m-%dT%H:%M:%S%z\"",
|
||||||
time_local);
|
time_local);
|
||||||
|
|
||||||
|
const struct tm *time_utc = gmtime(&now);
|
||||||
|
|
||||||
strftime(savedTIMESTAMP_ISO8601_UTC,
|
strftime(savedTIMESTAMP_ISO8601_UTC,
|
||||||
sizeof(savedTIMESTAMP_ISO8601_UTC), "\"%Y-%m-%dT%H:%M:%SZ\"",
|
sizeof(savedTIMESTAMP_ISO8601_UTC), "\"%Y-%m-%dT%H:%M:%SZ\"",
|
||||||
time_utc);
|
time_utc);
|
||||||
@@ -758,7 +789,7 @@ void sym_Init(time_t now)
|
|||||||
#undef addNumber
|
#undef addNumber
|
||||||
#undef addString
|
#undef addString
|
||||||
|
|
||||||
labelScope = NULL;
|
sym_SetCurrentSymbolScope(NULL);
|
||||||
anonLabelID = 0;
|
anonLabelID = 0;
|
||||||
|
|
||||||
/* _PI is deprecated */
|
/* _PI is deprecated */
|
||||||
|
|||||||
@@ -67,6 +67,7 @@ size_t readUTF8Char(uint8_t *dest, char const *src)
|
|||||||
if (decode(&state, &codep, src[i]) == 1)
|
if (decode(&state, &codep, src[i]) == 1)
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
|
if (dest)
|
||||||
dest[i] = src[i];
|
dest[i] = src[i];
|
||||||
i++;
|
i++;
|
||||||
|
|
||||||
|
|||||||
@@ -6,6 +6,7 @@
|
|||||||
* SPDX-License-Identifier: MIT
|
* SPDX-License-Identifier: MIT
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#include <inttypes.h>
|
||||||
#include <limits.h>
|
#include <limits.h>
|
||||||
#include <stdarg.h>
|
#include <stdarg.h>
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
@@ -17,18 +18,11 @@
|
|||||||
#include "asm/main.h"
|
#include "asm/main.h"
|
||||||
#include "asm/warning.h"
|
#include "asm/warning.h"
|
||||||
|
|
||||||
#include "extern/err.h"
|
#include "error.h"
|
||||||
|
|
||||||
unsigned int nbErrors = 0;
|
unsigned int nbErrors = 0;
|
||||||
|
|
||||||
enum WarningState {
|
static const enum WarningState defaultWarnings[ARRAY_SIZE(warningStates)] = {
|
||||||
WARNING_DEFAULT,
|
|
||||||
WARNING_DISABLED,
|
|
||||||
WARNING_ENABLED,
|
|
||||||
WARNING_ERROR
|
|
||||||
};
|
|
||||||
|
|
||||||
static enum WarningState const defaultWarnings[NB_WARNINGS] = {
|
|
||||||
[WARNING_ASSERT] = WARNING_ENABLED,
|
[WARNING_ASSERT] = WARNING_ENABLED,
|
||||||
[WARNING_BACKWARDS_FOR] = WARNING_DISABLED,
|
[WARNING_BACKWARDS_FOR] = WARNING_DISABLED,
|
||||||
[WARNING_BUILTIN_ARG] = WARNING_DISABLED,
|
[WARNING_BUILTIN_ARG] = WARNING_DISABLED,
|
||||||
@@ -44,13 +38,17 @@ static enum WarningState const defaultWarnings[NB_WARNINGS] = {
|
|||||||
[WARNING_OBSOLETE] = WARNING_ENABLED,
|
[WARNING_OBSOLETE] = WARNING_ENABLED,
|
||||||
[WARNING_SHIFT] = WARNING_DISABLED,
|
[WARNING_SHIFT] = WARNING_DISABLED,
|
||||||
[WARNING_SHIFT_AMOUNT] = WARNING_DISABLED,
|
[WARNING_SHIFT_AMOUNT] = WARNING_DISABLED,
|
||||||
[WARNING_TRUNCATION] = WARNING_ENABLED,
|
|
||||||
[WARNING_USER] = WARNING_ENABLED,
|
[WARNING_USER] = WARNING_ENABLED,
|
||||||
|
|
||||||
|
[WARNING_NUMERIC_STRING_1] = WARNING_ENABLED,
|
||||||
|
[WARNING_NUMERIC_STRING_2] = WARNING_DISABLED,
|
||||||
|
[WARNING_TRUNCATION_1] = WARNING_ENABLED,
|
||||||
|
[WARNING_TRUNCATION_2] = WARNING_DISABLED,
|
||||||
};
|
};
|
||||||
|
|
||||||
static enum WarningState warningStates[NB_WARNINGS];
|
enum WarningState warningStates[ARRAY_SIZE(warningStates)];
|
||||||
|
|
||||||
static bool warningsAreErrors; /* Set if `-Werror` was specified */
|
bool warningsAreErrors; /* Set if `-Werror` was specified */
|
||||||
|
|
||||||
static enum WarningState warningState(enum WarningID id)
|
static enum WarningState warningState(enum WarningID id)
|
||||||
{
|
{
|
||||||
@@ -71,7 +69,7 @@ static enum WarningState warningState(enum WarningID id)
|
|||||||
return state;
|
return state;
|
||||||
}
|
}
|
||||||
|
|
||||||
static char const *warningFlags[NB_WARNINGS_ALL] = {
|
static const char * const warningFlags[NB_WARNINGS] = {
|
||||||
"assert",
|
"assert",
|
||||||
"backwards-for",
|
"backwards-for",
|
||||||
"builtin-args",
|
"builtin-args",
|
||||||
@@ -87,15 +85,66 @@ static char const *warningFlags[NB_WARNINGS_ALL] = {
|
|||||||
"obsolete",
|
"obsolete",
|
||||||
"shift",
|
"shift",
|
||||||
"shift-amount",
|
"shift-amount",
|
||||||
"truncation",
|
|
||||||
"user",
|
"user",
|
||||||
|
|
||||||
|
// Parametric warnings
|
||||||
|
"numeric-string",
|
||||||
|
"numeric-string",
|
||||||
|
"truncation",
|
||||||
|
"truncation",
|
||||||
|
|
||||||
/* Meta warnings */
|
/* Meta warnings */
|
||||||
"all",
|
"all",
|
||||||
"extra",
|
"extra",
|
||||||
"everything" /* Especially useful for testing */
|
"everything", /* Especially useful for testing */
|
||||||
};
|
};
|
||||||
|
|
||||||
|
static const struct {
|
||||||
|
char const *name;
|
||||||
|
uint8_t nbLevels;
|
||||||
|
uint8_t defaultLevel;
|
||||||
|
} paramWarnings[] = {
|
||||||
|
{ "numeric-string", 2, 1 },
|
||||||
|
{ "truncation", 2, 2 },
|
||||||
|
};
|
||||||
|
|
||||||
|
static bool tryProcessParamWarning(char const *flag, uint8_t param, enum WarningState state)
|
||||||
|
{
|
||||||
|
enum WarningID baseID = PARAM_WARNINGS_START;
|
||||||
|
|
||||||
|
for (size_t i = 0; i < ARRAY_SIZE(paramWarnings); i++) {
|
||||||
|
uint8_t maxParam = paramWarnings[i].nbLevels;
|
||||||
|
|
||||||
|
if (!strcmp(paramWarnings[i].name, flag)) { // Match!
|
||||||
|
// If making the warning an error but param is 0, set to the maximum
|
||||||
|
// This accommodates `-Werror=flag`, but also `-Werror=flag=0`, which is
|
||||||
|
// thus filtered out by the caller.
|
||||||
|
// A param of 0 makes sense for disabling everything, but neither for
|
||||||
|
// enabling nor "erroring". Use the default for those.
|
||||||
|
if (param == 0 && state != WARNING_DISABLED) {
|
||||||
|
param = paramWarnings[i].defaultLevel;
|
||||||
|
} else if (param > maxParam) {
|
||||||
|
if (param != 255) // Don't warn if already capped
|
||||||
|
warnx("Got parameter %" PRIu8
|
||||||
|
" for warning flag \"%s\", but the maximum is %"
|
||||||
|
PRIu8 "; capping.\n",
|
||||||
|
param, flag, maxParam);
|
||||||
|
param = maxParam;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Set the first <param> to enabled/error, and disable the rest
|
||||||
|
for (uint8_t ofs = 0; ofs < maxParam; ofs++) {
|
||||||
|
warningStates[baseID + ofs] =
|
||||||
|
ofs < param ? state : WARNING_DISABLED;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
baseID += maxParam;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
enum MetaWarningCommand {
|
enum MetaWarningCommand {
|
||||||
META_WARNING_DONE = NB_WARNINGS
|
META_WARNING_DONE = NB_WARNINGS
|
||||||
};
|
};
|
||||||
@@ -109,6 +158,9 @@ static uint8_t const _wallCommands[] = {
|
|||||||
WARNING_EMPTY_STRRPL,
|
WARNING_EMPTY_STRRPL,
|
||||||
WARNING_LARGE_CONSTANT,
|
WARNING_LARGE_CONSTANT,
|
||||||
WARNING_LONG_STR,
|
WARNING_LONG_STR,
|
||||||
|
WARNING_NESTED_COMMENT,
|
||||||
|
WARNING_OBSOLETE,
|
||||||
|
WARNING_NUMERIC_STRING_1,
|
||||||
META_WARNING_DONE
|
META_WARNING_DONE
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -117,6 +169,10 @@ static uint8_t const _wextraCommands[] = {
|
|||||||
WARNING_EMPTY_MACRO_ARG,
|
WARNING_EMPTY_MACRO_ARG,
|
||||||
WARNING_MACRO_SHIFT,
|
WARNING_MACRO_SHIFT,
|
||||||
WARNING_NESTED_COMMENT,
|
WARNING_NESTED_COMMENT,
|
||||||
|
WARNING_OBSOLETE,
|
||||||
|
WARNING_NUMERIC_STRING_2,
|
||||||
|
WARNING_TRUNCATION_1,
|
||||||
|
WARNING_TRUNCATION_2,
|
||||||
META_WARNING_DONE
|
META_WARNING_DONE
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -135,7 +191,10 @@ static uint8_t const _weverythingCommands[] = {
|
|||||||
WARNING_OBSOLETE,
|
WARNING_OBSOLETE,
|
||||||
WARNING_SHIFT,
|
WARNING_SHIFT,
|
||||||
WARNING_SHIFT_AMOUNT,
|
WARNING_SHIFT_AMOUNT,
|
||||||
/* WARNING_TRUNCATION, */
|
WARNING_NUMERIC_STRING_1,
|
||||||
|
WARNING_NUMERIC_STRING_2,
|
||||||
|
WARNING_TRUNCATION_1,
|
||||||
|
WARNING_TRUNCATION_2,
|
||||||
/* WARNING_USER, */
|
/* WARNING_USER, */
|
||||||
META_WARNING_DONE
|
META_WARNING_DONE
|
||||||
};
|
};
|
||||||
@@ -146,37 +205,33 @@ static uint8_t const *metaWarningCommands[NB_META_WARNINGS] = {
|
|||||||
_weverythingCommands
|
_weverythingCommands
|
||||||
};
|
};
|
||||||
|
|
||||||
void processWarningFlag(char const *flag)
|
void processWarningFlag(char *flag)
|
||||||
{
|
{
|
||||||
static bool setError = false;
|
static bool setError = false;
|
||||||
|
|
||||||
/* First, try to match against a "meta" warning */
|
/* First, try to match against a "meta" warning */
|
||||||
for (enum WarningID id = NB_WARNINGS; id < NB_WARNINGS_ALL; id++) {
|
for (enum WarningID id = META_WARNINGS_START; id < NB_WARNINGS; id++) {
|
||||||
/* TODO: improve the matching performance? */
|
/* TODO: improve the matching performance? */
|
||||||
if (!strcmp(flag, warningFlags[id])) {
|
if (!strcmp(flag, warningFlags[id])) {
|
||||||
/* We got a match! */
|
/* We got a match! */
|
||||||
if (setError)
|
if (setError)
|
||||||
errx(1, "Cannot make meta warning \"%s\" into an error",
|
errx("Cannot make meta warning \"%s\" into an error",
|
||||||
flag);
|
flag);
|
||||||
|
|
||||||
uint8_t const *ptr =
|
for (uint8_t const *ptr = metaWarningCommands[id - META_WARNINGS_START];
|
||||||
metaWarningCommands[id - NB_WARNINGS];
|
*ptr != META_WARNING_DONE; ptr++) {
|
||||||
|
|
||||||
for (;;) {
|
|
||||||
if (*ptr == META_WARNING_DONE)
|
|
||||||
return;
|
|
||||||
|
|
||||||
/* Warning flag, set without override */
|
/* Warning flag, set without override */
|
||||||
if (warningStates[*ptr] == WARNING_DEFAULT)
|
if (warningStates[*ptr] == WARNING_DEFAULT)
|
||||||
warningStates[*ptr] = WARNING_ENABLED;
|
warningStates[*ptr] = WARNING_ENABLED;
|
||||||
ptr++;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* If it's not a meta warning, specially check against `-Werror` */
|
/* If it's not a meta warning, specially check against `-Werror` */
|
||||||
if (!strncmp(flag, "error", strlen("error"))) {
|
if (!strncmp(flag, "error", strlen("error"))) {
|
||||||
char const *errorFlag = flag + strlen("error");
|
char *errorFlag = flag + strlen("error");
|
||||||
|
|
||||||
switch (*errorFlag) {
|
switch (*errorFlag) {
|
||||||
case '\0':
|
case '\0':
|
||||||
@@ -185,7 +240,7 @@ void processWarningFlag(char const *flag)
|
|||||||
return;
|
return;
|
||||||
|
|
||||||
case '=':
|
case '=':
|
||||||
/* `-Werror=XXX */
|
/* `-Werror=XXX` */
|
||||||
setError = true;
|
setError = true;
|
||||||
processWarningFlag(errorFlag + 1); /* Skip the `=` */
|
processWarningFlag(errorFlag + 1); /* Skip the `=` */
|
||||||
setError = false;
|
setError = false;
|
||||||
@@ -197,14 +252,60 @@ void processWarningFlag(char const *flag)
|
|||||||
|
|
||||||
/* Well, it's either a normal warning or a mistake */
|
/* Well, it's either a normal warning or a mistake */
|
||||||
|
|
||||||
/* Check if this is a negation */
|
|
||||||
bool isNegation = !strncmp(flag, "no-", strlen("no-")) && !setError;
|
|
||||||
char const *rootFlag = isNegation ? flag + strlen("no-") : flag;
|
|
||||||
enum WarningState state = setError ? WARNING_ERROR :
|
enum WarningState state = setError ? WARNING_ERROR :
|
||||||
isNegation ? WARNING_DISABLED : WARNING_ENABLED;
|
/* Not an error, then check if this is a negation */
|
||||||
|
strncmp(flag, "no-", strlen("no-")) ? WARNING_ENABLED
|
||||||
|
: WARNING_DISABLED;
|
||||||
|
char const *rootFlag = state == WARNING_DISABLED ? flag + strlen("no-") : flag;
|
||||||
|
|
||||||
|
// Is this a "parametric" warning?
|
||||||
|
if (state != WARNING_DISABLED) { // The `no-` form cannot be parametrized
|
||||||
|
// First, check if there is an "equals" sign followed by a decimal number
|
||||||
|
char *equals = strchr(rootFlag, '=');
|
||||||
|
|
||||||
|
if (equals && equals[1] != '\0') { // Ignore an equal sign at the very end as well
|
||||||
|
// Is the rest of the string a decimal number?
|
||||||
|
// We want to avoid `strtoul`'s whitespace and sign, so we parse manually
|
||||||
|
uint8_t param = 0;
|
||||||
|
char const *ptr = equals + 1;
|
||||||
|
bool warned = false;
|
||||||
|
|
||||||
|
// The `if`'s condition above ensures that this will run at least once
|
||||||
|
do {
|
||||||
|
// If we don't have a digit, bail
|
||||||
|
if (*ptr < '0' || *ptr > '9')
|
||||||
|
break;
|
||||||
|
// Avoid overflowing!
|
||||||
|
if (param > UINT8_MAX - (*ptr - '0')) {
|
||||||
|
if (!warned)
|
||||||
|
warnx("Invalid warning flag \"%s\": capping parameter at 255\n",
|
||||||
|
flag);
|
||||||
|
warned = true; // Only warn once, cap always
|
||||||
|
param = 255;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
param = param * 10 + (*ptr - '0');
|
||||||
|
|
||||||
|
ptr++;
|
||||||
|
} while (*ptr);
|
||||||
|
|
||||||
|
// If we managed to the end of the string, check that the warning indeed
|
||||||
|
// accepts a parameter
|
||||||
|
if (*ptr == '\0') {
|
||||||
|
if (setError && param == 0) {
|
||||||
|
warnx("Ignoring nonsensical warning flag \"%s\"\n", flag);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
*equals = '\0'; // Truncate the param at the '='
|
||||||
|
if (tryProcessParamWarning(rootFlag, param,
|
||||||
|
param == 0 ? WARNING_DISABLED : state))
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/* Try to match the flag against a "normal" flag */
|
/* Try to match the flag against a "normal" flag */
|
||||||
for (enum WarningID id = 0; id < NB_WARNINGS; id++) {
|
for (enum WarningID id = 0; id < NB_PLAIN_WARNINGS; id++) {
|
||||||
if (!strcmp(rootFlag, warningFlags[id])) {
|
if (!strcmp(rootFlag, warningFlags[id])) {
|
||||||
/* We got a match! */
|
/* We got a match! */
|
||||||
warningStates[id] = state;
|
warningStates[id] = state;
|
||||||
@@ -212,10 +313,15 @@ void processWarningFlag(char const *flag)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Lastly, this might be a "parametric" warning without an equals sign
|
||||||
|
// If it is, treat the param as 1 if enabling, or 0 if disabling
|
||||||
|
if (tryProcessParamWarning(rootFlag, 0, state))
|
||||||
|
return;
|
||||||
|
|
||||||
warnx("Unknown warning `%s`", flag);
|
warnx("Unknown warning `%s`", flag);
|
||||||
}
|
}
|
||||||
|
|
||||||
void printDiag(const char *fmt, va_list args, char const *type,
|
void printDiag(char const *fmt, va_list args, char const *type,
|
||||||
char const *flagfmt, char const *flag)
|
char const *flagfmt, char const *flag)
|
||||||
{
|
{
|
||||||
fputs(type, stderr);
|
fputs(type, stderr);
|
||||||
@@ -225,17 +331,17 @@ void printDiag(const char *fmt, va_list args, char const *type,
|
|||||||
lexer_DumpStringExpansions();
|
lexer_DumpStringExpansions();
|
||||||
}
|
}
|
||||||
|
|
||||||
void error(const char *fmt, ...)
|
void error(char const *fmt, ...)
|
||||||
{
|
{
|
||||||
va_list args;
|
va_list args;
|
||||||
|
|
||||||
va_start(args, fmt);
|
va_start(args, fmt);
|
||||||
printDiag(fmt, args, "ERROR: ", ":\n ", NULL);
|
printDiag(fmt, args, "error: ", ":\n ", NULL);
|
||||||
va_end(args);
|
va_end(args);
|
||||||
nbErrors++;
|
nbErrors++;
|
||||||
}
|
}
|
||||||
|
|
||||||
_Noreturn void fatalerror(const char *fmt, ...)
|
_Noreturn void fatalerror(char const *fmt, ...)
|
||||||
{
|
{
|
||||||
va_list args;
|
va_list args;
|
||||||
|
|
||||||
@@ -258,7 +364,7 @@ void warning(enum WarningID id, char const *fmt, ...)
|
|||||||
return;
|
return;
|
||||||
|
|
||||||
case WARNING_ERROR:
|
case WARNING_ERROR:
|
||||||
printDiag(fmt, args, "ERROR: ", ": [-Werror=%s]\n ", flag);
|
printDiag(fmt, args, "error: ", ": [-Werror=%s]\n ", flag);
|
||||||
va_end(args);
|
va_end(args);
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
|||||||
87
src/error.c
Normal file
87
src/error.c
Normal file
@@ -0,0 +1,87 @@
|
|||||||
|
/*
|
||||||
|
* This file is part of RGBDS.
|
||||||
|
*
|
||||||
|
* Copyright (c) 2005-2021, Rich Felker and RGBDS contributors.
|
||||||
|
*
|
||||||
|
* SPDX-License-Identifier: MIT
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <errno.h>
|
||||||
|
#include <stdarg.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <string.h>
|
||||||
|
|
||||||
|
#include "error.h"
|
||||||
|
#include "platform.h"
|
||||||
|
|
||||||
|
static void vwarn(char const NONNULL(fmt), va_list ap)
|
||||||
|
{
|
||||||
|
fprintf(stderr, "warning: ");
|
||||||
|
vfprintf(stderr, fmt, ap);
|
||||||
|
fputs(": ", stderr);
|
||||||
|
perror(NULL);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void vwarnx(char const NONNULL(fmt), va_list ap)
|
||||||
|
{
|
||||||
|
fprintf(stderr, "warning");
|
||||||
|
fputs(": ", stderr);
|
||||||
|
vfprintf(stderr, fmt, ap);
|
||||||
|
putc('\n', stderr);
|
||||||
|
}
|
||||||
|
|
||||||
|
_Noreturn static void verr(char const NONNULL(fmt), va_list ap)
|
||||||
|
{
|
||||||
|
fprintf(stderr, "error: ");
|
||||||
|
vfprintf(stderr, fmt, ap);
|
||||||
|
fputs(": ", stderr);
|
||||||
|
fputs(strerror(errno), stderr);
|
||||||
|
putc('\n', stderr);
|
||||||
|
exit(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
_Noreturn static void verrx(char const NONNULL(fmt), va_list ap)
|
||||||
|
{
|
||||||
|
fprintf(stderr, "error");
|
||||||
|
fputs(": ", stderr);
|
||||||
|
vfprintf(stderr, fmt, ap);
|
||||||
|
putc('\n', stderr);
|
||||||
|
exit(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
void warn(char const NONNULL(fmt), ...)
|
||||||
|
{
|
||||||
|
va_list ap;
|
||||||
|
|
||||||
|
va_start(ap, fmt);
|
||||||
|
vwarn(fmt, ap);
|
||||||
|
va_end(ap);
|
||||||
|
}
|
||||||
|
|
||||||
|
void warnx(char const NONNULL(fmt), ...)
|
||||||
|
{
|
||||||
|
va_list ap;
|
||||||
|
|
||||||
|
va_start(ap, fmt);
|
||||||
|
vwarnx(fmt, ap);
|
||||||
|
va_end(ap);
|
||||||
|
}
|
||||||
|
|
||||||
|
_Noreturn void err(char const NONNULL(fmt), ...)
|
||||||
|
{
|
||||||
|
va_list ap;
|
||||||
|
|
||||||
|
va_start(ap, fmt);
|
||||||
|
verr(fmt, ap);
|
||||||
|
va_end(ap);
|
||||||
|
}
|
||||||
|
|
||||||
|
_Noreturn void errx(char const NONNULL(fmt), ...)
|
||||||
|
{
|
||||||
|
va_list ap;
|
||||||
|
|
||||||
|
va_start(ap, fmt);
|
||||||
|
verrx(fmt, ap);
|
||||||
|
va_end(ap);
|
||||||
|
}
|
||||||
94
src/extern/err.c
vendored
94
src/extern/err.c
vendored
@@ -1,94 +0,0 @@
|
|||||||
/*
|
|
||||||
* This file is part of RGBDS.
|
|
||||||
*
|
|
||||||
* Copyright (c) 2005-2018, Rich Felker and RGBDS contributors.
|
|
||||||
*
|
|
||||||
* SPDX-License-Identifier: MIT
|
|
||||||
*/
|
|
||||||
|
|
||||||
#include <errno.h>
|
|
||||||
#include <stdarg.h>
|
|
||||||
#include <stdio.h>
|
|
||||||
#include <stdlib.h>
|
|
||||||
#include <string.h>
|
|
||||||
|
|
||||||
#include "extern/err.h"
|
|
||||||
|
|
||||||
void rgbds_vwarn(const char *fmt, va_list ap)
|
|
||||||
{
|
|
||||||
fprintf(stderr, "warning: ");
|
|
||||||
if (fmt) {
|
|
||||||
vfprintf(stderr, fmt, ap);
|
|
||||||
fputs(": ", stderr);
|
|
||||||
}
|
|
||||||
perror(NULL);
|
|
||||||
}
|
|
||||||
|
|
||||||
void rgbds_vwarnx(const char *fmt, va_list ap)
|
|
||||||
{
|
|
||||||
fprintf(stderr, "warning");
|
|
||||||
if (fmt) {
|
|
||||||
fputs(": ", stderr);
|
|
||||||
vfprintf(stderr, fmt, ap);
|
|
||||||
}
|
|
||||||
putc('\n', stderr);
|
|
||||||
}
|
|
||||||
|
|
||||||
_Noreturn void rgbds_verr(int status, const char *fmt, va_list ap)
|
|
||||||
{
|
|
||||||
fprintf(stderr, "error: ");
|
|
||||||
if (fmt) {
|
|
||||||
vfprintf(stderr, fmt, ap);
|
|
||||||
fputs(": ", stderr);
|
|
||||||
}
|
|
||||||
fputs(strerror(errno), stderr);
|
|
||||||
putc('\n', stderr);
|
|
||||||
exit(status);
|
|
||||||
}
|
|
||||||
|
|
||||||
_Noreturn void rgbds_verrx(int status, const char *fmt, va_list ap)
|
|
||||||
{
|
|
||||||
fprintf(stderr, "error");
|
|
||||||
if (fmt) {
|
|
||||||
fputs(": ", stderr);
|
|
||||||
vfprintf(stderr, fmt, ap);
|
|
||||||
}
|
|
||||||
putc('\n', stderr);
|
|
||||||
exit(status);
|
|
||||||
}
|
|
||||||
|
|
||||||
void rgbds_warn(const char *fmt, ...)
|
|
||||||
{
|
|
||||||
va_list ap;
|
|
||||||
|
|
||||||
va_start(ap, fmt);
|
|
||||||
vwarn(fmt, ap);
|
|
||||||
va_end(ap);
|
|
||||||
}
|
|
||||||
|
|
||||||
void rgbds_warnx(const char *fmt, ...)
|
|
||||||
{
|
|
||||||
va_list ap;
|
|
||||||
|
|
||||||
va_start(ap, fmt);
|
|
||||||
vwarnx(fmt, ap);
|
|
||||||
va_end(ap);
|
|
||||||
}
|
|
||||||
|
|
||||||
_Noreturn void rgbds_err(int status, const char *fmt, ...)
|
|
||||||
{
|
|
||||||
va_list ap;
|
|
||||||
|
|
||||||
va_start(ap, fmt);
|
|
||||||
verr(status, fmt, ap);
|
|
||||||
va_end(ap);
|
|
||||||
}
|
|
||||||
|
|
||||||
_Noreturn void rgbds_errx(int status, const char *fmt, ...)
|
|
||||||
{
|
|
||||||
va_list ap;
|
|
||||||
|
|
||||||
va_start(ap, fmt);
|
|
||||||
verrx(status, fmt, ap);
|
|
||||||
va_end(ap);
|
|
||||||
}
|
|
||||||
18
src/extern/getopt.c
vendored
18
src/extern/getopt.c
vendored
@@ -37,7 +37,7 @@ int musl_optind = 1, musl_opterr = 1, musl_optopt;
|
|||||||
int musl_optreset = 0;
|
int musl_optreset = 0;
|
||||||
static int musl_optpos;
|
static int musl_optpos;
|
||||||
|
|
||||||
static void musl_getopt_msg(const char *a, const char *b, const char *c, size_t l)
|
static void musl_getopt_msg(char const *a, char const *b, char const *c, size_t l)
|
||||||
{
|
{
|
||||||
FILE *f = stderr;
|
FILE *f = stderr;
|
||||||
|
|
||||||
@@ -47,7 +47,7 @@ static void musl_getopt_msg(const char *a, const char *b, const char *c, size_t
|
|||||||
putc('\n', f);
|
putc('\n', f);
|
||||||
}
|
}
|
||||||
|
|
||||||
static int getopt(int argc, char *argv[], const char *optstring)
|
static int getopt(int argc, char *argv[], char const *optstring)
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
wchar_t c, d;
|
wchar_t c, d;
|
||||||
@@ -140,9 +140,11 @@ static void permute(char **argv, int dest, int src)
|
|||||||
argv[dest] = tmp;
|
argv[dest] = tmp;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int musl_getopt_long_core(int argc, char **argv, const char *optstring, const struct option *longopts, int *idx, int longonly);
|
static int musl_getopt_long_core(int argc, char **argv, char const *optstring,
|
||||||
|
const struct option *longopts, int *idx, int longonly);
|
||||||
|
|
||||||
static int musl_getopt_long(int argc, char **argv, const char *optstring, const struct option *longopts, int *idx, int longonly)
|
static int musl_getopt_long(int argc, char **argv, char const *optstring,
|
||||||
|
const struct option *longopts, int *idx, int longonly)
|
||||||
{
|
{
|
||||||
int ret, skipped, resumed;
|
int ret, skipped, resumed;
|
||||||
|
|
||||||
@@ -178,7 +180,8 @@ static int musl_getopt_long(int argc, char **argv, const char *optstring, const
|
|||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int musl_getopt_long_core(int argc, char **argv, const char *optstring, const struct option *longopts, int *idx, int longonly)
|
static int musl_getopt_long_core(int argc, char **argv, char const *optstring,
|
||||||
|
const struct option *longopts, int *idx, int longonly)
|
||||||
{
|
{
|
||||||
musl_optarg = 0;
|
musl_optarg = 0;
|
||||||
if (longopts && argv[musl_optind][0] == '-' &&
|
if (longopts && argv[musl_optind][0] == '-' &&
|
||||||
@@ -189,7 +192,7 @@ static int musl_getopt_long_core(int argc, char **argv, const char *optstring, c
|
|||||||
char *arg = 0, *opt, *start = argv[musl_optind] + 1;
|
char *arg = 0, *opt, *start = argv[musl_optind] + 1;
|
||||||
|
|
||||||
for (cnt = i = 0; longopts[i].name; i++) {
|
for (cnt = i = 0; longopts[i].name; i++) {
|
||||||
const char *name = longopts[i].name;
|
char const *name = longopts[i].name;
|
||||||
|
|
||||||
opt = start;
|
opt = start;
|
||||||
if (*opt == '-')
|
if (*opt == '-')
|
||||||
@@ -277,7 +280,8 @@ static int musl_getopt_long_core(int argc, char **argv, const char *optstring, c
|
|||||||
return getopt(argc, argv, optstring);
|
return getopt(argc, argv, optstring);
|
||||||
}
|
}
|
||||||
|
|
||||||
int musl_getopt_long_only(int argc, char **argv, const char *optstring, const struct option *longopts, int *idx)
|
int musl_getopt_long_only(int argc, char **argv, char const *optstring,
|
||||||
|
const struct option *longopts, int *idx)
|
||||||
{
|
{
|
||||||
return musl_getopt_long(argc, argv, optstring, longopts, idx, 1);
|
return musl_getopt_long(argc, argv, optstring, longopts, idx, 1);
|
||||||
}
|
}
|
||||||
|
|||||||
434
src/fix/main.c
434
src/fix/main.c
@@ -25,12 +25,12 @@
|
|||||||
#include "platform.h"
|
#include "platform.h"
|
||||||
#include "version.h"
|
#include "version.h"
|
||||||
|
|
||||||
#define UNSPECIFIED 0x100 // May not be in byte range
|
#define UNSPECIFIED 0x200 // Should not be in byte range
|
||||||
|
|
||||||
#define BANK_SIZE 0x4000
|
#define BANK_SIZE 0x4000
|
||||||
|
|
||||||
/* Short options */
|
/* Short options */
|
||||||
static const char *optstring = "Ccf:i:jk:l:m:n:p:r:st:Vv";
|
static const char *optstring = "Ccf:i:jk:l:m:n:Op:r:st:Vv";
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Equivalent long options
|
* Equivalent long options
|
||||||
@@ -52,6 +52,7 @@ static struct option const longopts[] = {
|
|||||||
{ "old-licensee", required_argument, NULL, 'l' },
|
{ "old-licensee", required_argument, NULL, 'l' },
|
||||||
{ "mbc-type", required_argument, NULL, 'm' },
|
{ "mbc-type", required_argument, NULL, 'm' },
|
||||||
{ "rom-version", required_argument, NULL, 'n' },
|
{ "rom-version", required_argument, NULL, 'n' },
|
||||||
|
{ "overwrite", no_argument, NULL, 'O' },
|
||||||
{ "pad-value", required_argument, NULL, 'p' },
|
{ "pad-value", required_argument, NULL, 'p' },
|
||||||
{ "ram-size", required_argument, NULL, 'r' },
|
{ "ram-size", required_argument, NULL, 'r' },
|
||||||
{ "sgb-compatible", no_argument, NULL, 's' },
|
{ "sgb-compatible", no_argument, NULL, 's' },
|
||||||
@@ -64,7 +65,7 @@ static struct option const longopts[] = {
|
|||||||
static void printUsage(void)
|
static void printUsage(void)
|
||||||
{
|
{
|
||||||
fputs(
|
fputs(
|
||||||
"Usage: rgbfix [-jsVv] [-C | -c] [-f <fix_spec>] [-i <game_id>] [-k <licensee>]\n"
|
"Usage: rgbfix [-jOsVv] [-C | -c] [-f <fix_spec>] [-i <game_id>] [-k <licensee>]\n"
|
||||||
" [-l <licensee_byte>] [-m <mbc_type>] [-n <rom_version>]\n"
|
" [-l <licensee_byte>] [-m <mbc_type>] [-n <rom_version>]\n"
|
||||||
" [-p <pad_value>] [-r <ram_size>] [-t <title_str>] [<file> ...]\n"
|
" [-p <pad_value>] [-r <ram_size>] [-t <title_str>] [<file> ...]\n"
|
||||||
"Useful options:\n"
|
"Useful options:\n"
|
||||||
@@ -79,6 +80,20 @@ static void printUsage(void)
|
|||||||
stderr);
|
stderr);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static uint8_t nbErrors;
|
||||||
|
|
||||||
|
static format_(printf, 1, 2) void report(char const *fmt, ...)
|
||||||
|
{
|
||||||
|
va_list ap;
|
||||||
|
|
||||||
|
va_start(ap, fmt);
|
||||||
|
vfprintf(stderr, fmt, ap);
|
||||||
|
va_end(ap);
|
||||||
|
|
||||||
|
if (nbErrors != UINT8_MAX)
|
||||||
|
nbErrors++;
|
||||||
|
}
|
||||||
|
|
||||||
enum MbcType {
|
enum MbcType {
|
||||||
ROM = 0x00,
|
ROM = 0x00,
|
||||||
ROM_RAM = 0x08,
|
ROM_RAM = 0x08,
|
||||||
@@ -120,6 +135,28 @@ enum MbcType {
|
|||||||
|
|
||||||
HUC1_RAM_BATTERY = 0xFF,
|
HUC1_RAM_BATTERY = 0xFF,
|
||||||
|
|
||||||
|
// "Extended" values (still valid, but not directly actionable)
|
||||||
|
|
||||||
|
// A high byte of 0x01 means TPP1, the low byte is the requested features
|
||||||
|
// This does not include SRAM, which is instead implied by a non-zero SRAM size
|
||||||
|
// Note: Multiple rumble speeds imply rumble
|
||||||
|
TPP1 = 0x100,
|
||||||
|
TPP1_RUMBLE = 0x101,
|
||||||
|
TPP1_MULTIRUMBLE = 0x102, // Should not be possible
|
||||||
|
TPP1_MULTIRUMBLE_RUMBLE = 0x103,
|
||||||
|
TPP1_TIMER = 0x104,
|
||||||
|
TPP1_TIMER_RUMBLE = 0x105,
|
||||||
|
TPP1_TIMER_MULTIRUMBLE = 0x106, // Should not be possible
|
||||||
|
TPP1_TIMER_MULTIRUMBLE_RUMBLE = 0x107,
|
||||||
|
TPP1_BATTERY = 0x108,
|
||||||
|
TPP1_BATTERY_RUMBLE = 0x109,
|
||||||
|
TPP1_BATTERY_MULTIRUMBLE = 0x10A, // Should not be possible
|
||||||
|
TPP1_BATTERY_MULTIRUMBLE_RUMBLE = 0x10B,
|
||||||
|
TPP1_BATTERY_TIMER = 0x10C,
|
||||||
|
TPP1_BATTERY_TIMER_RUMBLE = 0x10D,
|
||||||
|
TPP1_BATTERY_TIMER_MULTIRUMBLE = 0x10E, // Should not be possible
|
||||||
|
TPP1_BATTERY_TIMER_MULTIRUMBLE_RUMBLE = 0x10F,
|
||||||
|
|
||||||
// Error values
|
// Error values
|
||||||
MBC_NONE = UNSPECIFIED, // No MBC specified, do not act on it
|
MBC_NONE = UNSPECIFIED, // No MBC specified, do not act on it
|
||||||
MBC_BAD, // Specified MBC does not exist / syntax error
|
MBC_BAD, // Specified MBC does not exist / syntax error
|
||||||
@@ -127,6 +164,33 @@ enum MbcType {
|
|||||||
MBC_BAD_RANGE, // MBC number out of range
|
MBC_BAD_RANGE, // MBC number out of range
|
||||||
};
|
};
|
||||||
|
|
||||||
|
static void printAcceptedMBCNames(void)
|
||||||
|
{
|
||||||
|
fputs("\tROM ($00) [aka ROM_ONLY]\n", stderr);
|
||||||
|
fputs("\tMBC1 ($01), MBC1+RAM ($02), MBC1+RAM+BATTERY ($03)\n", stderr);
|
||||||
|
fputs("\tMBC2 ($05), MBC2+BATTERY ($06)\n", stderr);
|
||||||
|
fputs("\tROM+RAM ($08) [deprecated], ROM+RAM+BATTERY ($09) [deprecated]\n", stderr);
|
||||||
|
fputs("\tMMM01 ($0B), MMM01+RAM ($0C), MMM01+RAM+BATTERY ($0D)\n", stderr);
|
||||||
|
fputs("\tMBC3+TIMER+BATTERY ($0F), MBC3+TIMER+RAM+BATTERY ($10)\n", stderr);
|
||||||
|
fputs("\tMBC3 ($11), MBC3+RAM ($12), MBC3+RAM+BATTERY ($13)\n", stderr);
|
||||||
|
fputs("\tMBC5 ($19), MBC5+RAM ($1A), MBC5+RAM+BATTERY ($1B)\n", stderr);
|
||||||
|
fputs("\tMBC5+RUMBLE ($1C), MBC5+RUMBLE+RAM ($1D), MBC5+RUMBLE+RAM+BATTERY ($1E)\n", stderr);
|
||||||
|
fputs("\tMBC6 ($20)\n", stderr);
|
||||||
|
fputs("\tMBC7+SENSOR+RUMBLE+RAM+BATTERY ($22)\n", stderr);
|
||||||
|
fputs("\tPOCKET_CAMERA ($FC)\n", stderr);
|
||||||
|
fputs("\tBANDAI_TAMA5 ($FD)\n", stderr);
|
||||||
|
fputs("\tHUC3 ($FE)\n", stderr);
|
||||||
|
fputs("\tHUC1+RAM+BATTERY ($FF)\n", stderr);
|
||||||
|
|
||||||
|
fputs("\n\tTPP1_1.0, TPP1_1.0+RUMBLE, TPP1_1.0+MULTIRUMBLE, TPP1_1.0+TIMER,\n", stderr);
|
||||||
|
fputs("\tTPP1_1.0+TIMER+RUMBLE, TPP1_1.0+TIMER+MULTIRUMBLE, TPP1_1.0+BATTERY,\n", stderr);
|
||||||
|
fputs("\tTPP1_1.0+BATTERY+RUMBLE, TPP1_1.0+BATTERY+MULTIRUMBLE,\n", stderr);
|
||||||
|
fputs("\tTPP1_1.0+BATTERY+TIMER, TPP1_1.0+BATTERY+TIMER+RUMBLE,\n", stderr);
|
||||||
|
fputs("\tTPP1_1.0+BATTERY+TIMER+MULTIRUMBLE\n", stderr);
|
||||||
|
}
|
||||||
|
|
||||||
|
static uint8_t tpp1Rev[2];
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return False on failure
|
* @return False on failure
|
||||||
*/
|
*/
|
||||||
@@ -151,10 +215,22 @@ static bool readMBCSlice(char const **name, char const *expected)
|
|||||||
|
|
||||||
static enum MbcType parseMBC(char const *name)
|
static enum MbcType parseMBC(char const *name)
|
||||||
{
|
{
|
||||||
if (name[0] >= '0' && name[0] <= '9') {
|
if (!strcasecmp(name, "help")) {
|
||||||
|
fputs("Accepted MBC names:\n", stderr);
|
||||||
|
printAcceptedMBCNames();
|
||||||
|
exit(0);
|
||||||
|
}
|
||||||
|
|
||||||
|
if ((name[0] >= '0' && name[0] <= '9') || name[0] == '$') {
|
||||||
|
int base = 0;
|
||||||
|
|
||||||
|
if (name[0] == '$') {
|
||||||
|
name++;
|
||||||
|
base = 16;
|
||||||
|
}
|
||||||
// Parse number, and return it as-is (unless it's too large)
|
// Parse number, and return it as-is (unless it's too large)
|
||||||
char *endptr;
|
char *endptr;
|
||||||
unsigned long mbc = strtoul(name, &endptr, 0);
|
unsigned long mbc = strtoul(name, &endptr, base);
|
||||||
|
|
||||||
if (*endptr)
|
if (*endptr)
|
||||||
return MBC_BAD;
|
return MBC_BAD;
|
||||||
@@ -248,11 +324,51 @@ do { \
|
|||||||
mbc = BANDAI_TAMA5;
|
mbc = BANDAI_TAMA5;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 'T': // TAMA5
|
case 'T': // TAMA5 / TPP1
|
||||||
case 't':
|
case 't':
|
||||||
tryReadSlice("AMA5");
|
switch (*ptr++) {
|
||||||
|
case 'A':
|
||||||
|
tryReadSlice("MA5");
|
||||||
mbc = BANDAI_TAMA5;
|
mbc = BANDAI_TAMA5;
|
||||||
break;
|
break;
|
||||||
|
case 'P':
|
||||||
|
tryReadSlice("P1");
|
||||||
|
// Parse version
|
||||||
|
while (*ptr == ' ' || *ptr == '_')
|
||||||
|
ptr++;
|
||||||
|
// Major
|
||||||
|
char *endptr;
|
||||||
|
unsigned long val = strtoul(ptr, &endptr, 10);
|
||||||
|
|
||||||
|
if (endptr == ptr) {
|
||||||
|
report("error: Failed to parse TPP1 major revision number\n");
|
||||||
|
return MBC_BAD;
|
||||||
|
}
|
||||||
|
ptr = endptr;
|
||||||
|
if (val != 1) {
|
||||||
|
report("error: RGBFIX only supports TPP1 versions 1.0\n");
|
||||||
|
return MBC_BAD;
|
||||||
|
}
|
||||||
|
tpp1Rev[0] = val;
|
||||||
|
tryReadSlice(".");
|
||||||
|
// Minor
|
||||||
|
val = strtoul(ptr, &endptr, 10);
|
||||||
|
if (endptr == ptr) {
|
||||||
|
report("error: Failed to parse TPP1 minor revision number\n");
|
||||||
|
return MBC_BAD;
|
||||||
|
}
|
||||||
|
ptr = endptr;
|
||||||
|
if (val > 0xFF) {
|
||||||
|
report("error: TPP1 minor revision number must be 8-bit\n");
|
||||||
|
return MBC_BAD;
|
||||||
|
}
|
||||||
|
tpp1Rev[1] = val;
|
||||||
|
mbc = TPP1;
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
return MBC_BAD;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
case 'H': // HuC{1, 3}
|
case 'H': // HuC{1, 3}
|
||||||
case 'h':
|
case 'h':
|
||||||
@@ -280,6 +396,7 @@ do { \
|
|||||||
#define TIMER 0x20
|
#define TIMER 0x20
|
||||||
#define RUMBLE 0x10
|
#define RUMBLE 0x10
|
||||||
#define SENSOR 0x08
|
#define SENSOR 0x08
|
||||||
|
#define MULTIRUMBLE 0x04
|
||||||
|
|
||||||
for (;;) {
|
for (;;) {
|
||||||
// Trim off trailing whitespace
|
// Trim off trailing whitespace
|
||||||
@@ -303,6 +420,12 @@ do { \
|
|||||||
features |= BATTERY;
|
features |= BATTERY;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
case 'M':
|
||||||
|
case 'm':
|
||||||
|
tryReadSlice("ULTIRUMBLE");
|
||||||
|
features |= MULTIRUMBLE;
|
||||||
|
break;
|
||||||
|
|
||||||
case 'R': // RAM or RUMBLE
|
case 'R': // RAM or RUMBLE
|
||||||
case 'r':
|
case 'r':
|
||||||
switch (*ptr++) {
|
switch (*ptr++) {
|
||||||
@@ -371,7 +494,9 @@ do { \
|
|||||||
|
|
||||||
case MBC3:
|
case MBC3:
|
||||||
// Handle timer, which also requires battery
|
// Handle timer, which also requires battery
|
||||||
if (features & (TIMER & BATTERY)) {
|
if (features & TIMER) {
|
||||||
|
if (!(features & BATTERY))
|
||||||
|
fprintf(stderr, "warning: MBC3+TIMER implies BATTERY\n");
|
||||||
features &= ~(TIMER | BATTERY); // Reset those bits
|
features &= ~(TIMER | BATTERY); // Reset those bits
|
||||||
mbc = MBC3_TIMER_BATTERY;
|
mbc = MBC3_TIMER_BATTERY;
|
||||||
// RAM is handled below
|
// RAM is handled below
|
||||||
@@ -424,6 +549,22 @@ do { \
|
|||||||
if (features != (RAM | BATTERY)) // HuC1 expects RAM+BATTERY
|
if (features != (RAM | BATTERY)) // HuC1 expects RAM+BATTERY
|
||||||
return MBC_WRONG_FEATURES;
|
return MBC_WRONG_FEATURES;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
case TPP1:
|
||||||
|
if (features & RAM)
|
||||||
|
fprintf(stderr,
|
||||||
|
"warning: TPP1 requests RAM implicitly if given a non-zero RAM size");
|
||||||
|
if (features & BATTERY)
|
||||||
|
mbc |= 0x08;
|
||||||
|
if (features & TIMER)
|
||||||
|
mbc |= 0x04;
|
||||||
|
if (features & MULTIRUMBLE)
|
||||||
|
mbc |= 0x03; // Also set the rumble flag
|
||||||
|
if (features & RUMBLE)
|
||||||
|
mbc |= 0x01;
|
||||||
|
if (features & SENSOR)
|
||||||
|
return MBC_WRONG_FEATURES;
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Trim off trailing whitespace
|
// Trim off trailing whitespace
|
||||||
@@ -497,6 +638,34 @@ static char const *mbcName(enum MbcType type)
|
|||||||
return "HUC3";
|
return "HUC3";
|
||||||
case HUC1_RAM_BATTERY:
|
case HUC1_RAM_BATTERY:
|
||||||
return "HUC1+RAM+BATTERY";
|
return "HUC1+RAM+BATTERY";
|
||||||
|
case TPP1:
|
||||||
|
return "TPP1";
|
||||||
|
case TPP1_RUMBLE:
|
||||||
|
return "TPP1+RUMBLE";
|
||||||
|
case TPP1_MULTIRUMBLE:
|
||||||
|
case TPP1_MULTIRUMBLE_RUMBLE:
|
||||||
|
return "TPP1+MULTIRUMBLE";
|
||||||
|
case TPP1_TIMER:
|
||||||
|
return "TPP1+TIMER";
|
||||||
|
case TPP1_TIMER_RUMBLE:
|
||||||
|
return "TPP1+TIMER+RUMBLE";
|
||||||
|
case TPP1_TIMER_MULTIRUMBLE:
|
||||||
|
case TPP1_TIMER_MULTIRUMBLE_RUMBLE:
|
||||||
|
return "TPP1+TIMER+MULTIRUMBLE";
|
||||||
|
case TPP1_BATTERY:
|
||||||
|
return "TPP1+BATTERY";
|
||||||
|
case TPP1_BATTERY_RUMBLE:
|
||||||
|
return "TPP1+BATTERY+RUMBLE";
|
||||||
|
case TPP1_BATTERY_MULTIRUMBLE:
|
||||||
|
case TPP1_BATTERY_MULTIRUMBLE_RUMBLE:
|
||||||
|
return "TPP1+BATTERY+MULTIRUMBLE";
|
||||||
|
case TPP1_BATTERY_TIMER:
|
||||||
|
return "TPP1+BATTERY+TIMER";
|
||||||
|
case TPP1_BATTERY_TIMER_RUMBLE:
|
||||||
|
return "TPP1+BATTERY+TIMER+RUMBLE";
|
||||||
|
case TPP1_BATTERY_TIMER_MULTIRUMBLE:
|
||||||
|
case TPP1_BATTERY_TIMER_MULTIRUMBLE_RUMBLE:
|
||||||
|
return "TPP1+BATTERY+TIMER+MULTIRUMBLE";
|
||||||
|
|
||||||
// Error values
|
// Error values
|
||||||
case MBC_NONE:
|
case MBC_NONE:
|
||||||
@@ -547,25 +716,30 @@ static bool hasRAM(enum MbcType type)
|
|||||||
case HUC3:
|
case HUC3:
|
||||||
case HUC1_RAM_BATTERY:
|
case HUC1_RAM_BATTERY:
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
|
// TPP1 may or may not have RAM, don't call this function for it
|
||||||
|
case TPP1:
|
||||||
|
case TPP1_RUMBLE:
|
||||||
|
case TPP1_MULTIRUMBLE:
|
||||||
|
case TPP1_MULTIRUMBLE_RUMBLE:
|
||||||
|
case TPP1_TIMER:
|
||||||
|
case TPP1_TIMER_RUMBLE:
|
||||||
|
case TPP1_TIMER_MULTIRUMBLE:
|
||||||
|
case TPP1_TIMER_MULTIRUMBLE_RUMBLE:
|
||||||
|
case TPP1_BATTERY:
|
||||||
|
case TPP1_BATTERY_RUMBLE:
|
||||||
|
case TPP1_BATTERY_MULTIRUMBLE:
|
||||||
|
case TPP1_BATTERY_MULTIRUMBLE_RUMBLE:
|
||||||
|
case TPP1_BATTERY_TIMER:
|
||||||
|
case TPP1_BATTERY_TIMER_RUMBLE:
|
||||||
|
case TPP1_BATTERY_TIMER_MULTIRUMBLE:
|
||||||
|
case TPP1_BATTERY_TIMER_MULTIRUMBLE_RUMBLE:
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
unreachable_();
|
unreachable_();
|
||||||
}
|
}
|
||||||
|
|
||||||
static uint8_t nbErrors;
|
|
||||||
|
|
||||||
static format_(printf, 1, 2) void report(char const *fmt, ...)
|
|
||||||
{
|
|
||||||
va_list ap;
|
|
||||||
|
|
||||||
va_start(ap, fmt);
|
|
||||||
vfprintf(stderr, fmt, ap);
|
|
||||||
va_end(ap);
|
|
||||||
|
|
||||||
if (nbErrors != UINT8_MAX)
|
|
||||||
nbErrors++;
|
|
||||||
}
|
|
||||||
|
|
||||||
static const uint8_t ninLogo[] = {
|
static const uint8_t ninLogo[] = {
|
||||||
0xCE, 0xED, 0x66, 0x66, 0xCC, 0x0D, 0x00, 0x0B,
|
0xCE, 0xED, 0x66, 0x66, 0xCC, 0x0D, 0x00, 0x0B,
|
||||||
0x03, 0x73, 0x00, 0x83, 0x00, 0x0C, 0x00, 0x0D,
|
0x03, 0x73, 0x00, 0x83, 0x00, 0x0C, 0x00, 0x0D,
|
||||||
@@ -575,6 +749,15 @@ static const uint8_t ninLogo[] = {
|
|||||||
0xDD, 0xDC, 0x99, 0x9F, 0xBB, 0xB9, 0x33, 0x3E
|
0xDD, 0xDC, 0x99, 0x9F, 0xBB, 0xB9, 0x33, 0x3E
|
||||||
};
|
};
|
||||||
|
|
||||||
|
static const uint8_t trashLogo[] = {
|
||||||
|
0xFF^0xCE, 0xFF^0xED, 0xFF^0x66, 0xFF^0x66, 0xFF^0xCC, 0xFF^0x0D, 0xFF^0x00, 0xFF^0x0B,
|
||||||
|
0xFF^0x03, 0xFF^0x73, 0xFF^0x00, 0xFF^0x83, 0xFF^0x00, 0xFF^0x0C, 0xFF^0x00, 0xFF^0x0D,
|
||||||
|
0xFF^0x00, 0xFF^0x08, 0xFF^0x11, 0xFF^0x1F, 0xFF^0x88, 0xFF^0x89, 0xFF^0x00, 0xFF^0x0E,
|
||||||
|
0xFF^0xDC, 0xFF^0xCC, 0xFF^0x6E, 0xFF^0xE6, 0xFF^0xDD, 0xFF^0xDD, 0xFF^0xD9, 0xFF^0x99,
|
||||||
|
0xFF^0xBB, 0xFF^0xBB, 0xFF^0x67, 0xFF^0x63, 0xFF^0x6E, 0xFF^0x0E, 0xFF^0xEC, 0xFF^0xCC,
|
||||||
|
0xFF^0xDD, 0xFF^0xDC, 0xFF^0x99, 0xFF^0x9F, 0xFF^0xBB, 0xFF^0xB9, 0xFF^0x33, 0xFF^0x3E
|
||||||
|
};
|
||||||
|
|
||||||
static enum { DMG, BOTH, CGB } model = DMG; // If DMG, byte is left alone
|
static enum { DMG, BOTH, CGB } model = DMG; // If DMG, byte is left alone
|
||||||
#define FIX_LOGO 0x80
|
#define FIX_LOGO 0x80
|
||||||
#define TRASH_LOGO 0x40
|
#define TRASH_LOGO 0x40
|
||||||
@@ -591,6 +774,7 @@ static uint8_t newLicenseeLen;
|
|||||||
static uint16_t oldLicensee = UNSPECIFIED;
|
static uint16_t oldLicensee = UNSPECIFIED;
|
||||||
static enum MbcType cartridgeType = MBC_NONE;
|
static enum MbcType cartridgeType = MBC_NONE;
|
||||||
static uint16_t romVersion = UNSPECIFIED;
|
static uint16_t romVersion = UNSPECIFIED;
|
||||||
|
static bool overwriteRom = false; // If false, warn when overwriting non-zero non-identical bytes
|
||||||
static uint16_t padValue = UNSPECIFIED;
|
static uint16_t padValue = UNSPECIFIED;
|
||||||
static uint16_t ramSize = UNSPECIFIED;
|
static uint16_t ramSize = UNSPECIFIED;
|
||||||
static bool sgb = false; // If false, SGB flags are left alone
|
static bool sgb = false; // If false, SGB flags are left alone
|
||||||
@@ -653,6 +837,47 @@ static ssize_t writeBytes(int fd, void *buf, size_t len)
|
|||||||
return total;
|
return total;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param rom0 A pointer to rom0
|
||||||
|
* @param addr What address to check
|
||||||
|
* @param fixedByte The fixed byte at the address
|
||||||
|
* @param areaName Name to be displayed in the warning message
|
||||||
|
*/
|
||||||
|
static void overwriteByte(uint8_t *rom0, uint16_t addr, uint8_t fixedByte, char const *areaName)
|
||||||
|
{
|
||||||
|
uint8_t origByte = rom0[addr];
|
||||||
|
|
||||||
|
if (!overwriteRom && origByte != 0 && origByte != fixedByte)
|
||||||
|
fprintf(stderr, "warning: Overwrote a non-zero byte in the %s\n", areaName);
|
||||||
|
|
||||||
|
rom0[addr] = fixedByte;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param rom0 A pointer to rom0
|
||||||
|
* @param startAddr What address to begin checking from
|
||||||
|
* @param fixed The fixed bytes at the address
|
||||||
|
* @param size How many bytes to check
|
||||||
|
* @param areaName Name to be displayed in the warning message
|
||||||
|
*/
|
||||||
|
static void overwriteBytes(uint8_t *rom0, uint16_t startAddr, uint8_t const *fixed, uint8_t size,
|
||||||
|
char const *areaName)
|
||||||
|
{
|
||||||
|
if (!overwriteRom) {
|
||||||
|
for (uint8_t i = 0; i < size; i++) {
|
||||||
|
uint8_t origByte = rom0[i + startAddr];
|
||||||
|
|
||||||
|
if (origByte != 0 && origByte != fixed[i]) {
|
||||||
|
fprintf(stderr, "warning: Overwrote a non-zero byte in the %s\n",
|
||||||
|
areaName);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
memcpy(&rom0[startAddr], fixed, size);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param input File descriptor to be used for reading
|
* @param input File descriptor to be used for reading
|
||||||
* @param output File descriptor to be used for writing, may be equal to `input`
|
* @param output File descriptor to be used for writing, may be equal to `input`
|
||||||
@@ -669,56 +894,82 @@ static void processFile(int input, int output, char const *name, off_t fileSize)
|
|||||||
|
|
||||||
uint8_t rom0[BANK_SIZE];
|
uint8_t rom0[BANK_SIZE];
|
||||||
ssize_t rom0Len = readBytes(input, rom0, sizeof(rom0));
|
ssize_t rom0Len = readBytes(input, rom0, sizeof(rom0));
|
||||||
|
// Also used as how many bytes to write back when fixing in-place
|
||||||
|
ssize_t headerSize = (cartridgeType & 0xFF00) == TPP1 ? 0x154 : 0x150;
|
||||||
|
|
||||||
if (rom0Len == -1) {
|
if (rom0Len == -1) {
|
||||||
report("FATAL: Failed to read \"%s\"'s header: %s\n", name, strerror(errno));
|
report("FATAL: Failed to read \"%s\"'s header: %s\n", name, strerror(errno));
|
||||||
return;
|
return;
|
||||||
} else if (rom0Len < 0x150) {
|
} else if (rom0Len < headerSize) {
|
||||||
report("FATAL: \"%s\" too short, expected at least 336 ($150) bytes, got only %ld\n",
|
report("FATAL: \"%s\" too short, expected at least %jd ($%jx) bytes, got only %jd\n",
|
||||||
name, rom0Len);
|
name, (intmax_t)headerSize, (intmax_t)headerSize, (intmax_t)rom0Len);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
// Accept partial reads if the file contains at least the header
|
// Accept partial reads if the file contains at least the header
|
||||||
|
|
||||||
if (fixSpec & (FIX_LOGO | TRASH_LOGO)) {
|
if (fixSpec & (FIX_LOGO | TRASH_LOGO)) {
|
||||||
if (fixSpec & FIX_LOGO) {
|
if (fixSpec & FIX_LOGO)
|
||||||
memcpy(&rom0[0x104], ninLogo, sizeof(ninLogo));
|
overwriteBytes(rom0, 0x0104, ninLogo, sizeof(ninLogo), "Nintendo logo");
|
||||||
} else {
|
else
|
||||||
for (uint8_t i = 0; i < sizeof(ninLogo); i++)
|
overwriteBytes(rom0, 0x0104, trashLogo, sizeof(trashLogo), "Nintendo logo");
|
||||||
rom0[i + 0x104] = ~ninLogo[i];
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (title)
|
if (title)
|
||||||
memcpy(&rom0[0x134], title, titleLen);
|
overwriteBytes(rom0, 0x134, (uint8_t const *)title, titleLen, "title");
|
||||||
|
|
||||||
if (gameID)
|
if (gameID)
|
||||||
memcpy(&rom0[0x13f], gameID, gameIDLen);
|
overwriteBytes(rom0, 0x13F, (uint8_t const *)gameID, gameIDLen, "manufacturer code");
|
||||||
|
|
||||||
if (model != DMG)
|
if (model != DMG)
|
||||||
rom0[0x143] = model == BOTH ? 0x80 : 0xc0;
|
overwriteByte(rom0, 0x143, model == BOTH ? 0x80 : 0xC0, "CGB flag");
|
||||||
|
|
||||||
if (newLicensee)
|
if (newLicensee)
|
||||||
memcpy(&rom0[0x144], newLicensee, newLicenseeLen);
|
overwriteBytes(rom0, 0x144, (uint8_t const *)newLicensee, newLicenseeLen,
|
||||||
|
"new licensee code");
|
||||||
|
|
||||||
if (sgb)
|
if (sgb)
|
||||||
rom0[0x146] = 0x03;
|
overwriteByte(rom0, 0x146, 0x03, "SGB flag");
|
||||||
|
|
||||||
// If a valid MBC was specified...
|
// If a valid MBC was specified...
|
||||||
if (cartridgeType < MBC_NONE)
|
if (cartridgeType < MBC_NONE) {
|
||||||
rom0[0x147] = cartridgeType;
|
uint8_t byte = cartridgeType;
|
||||||
|
|
||||||
|
if ((cartridgeType & 0xFF00) == TPP1) {
|
||||||
|
// Cartridge type isn't directly actionable, translate it
|
||||||
|
byte = 0xBC;
|
||||||
|
// The other TPP1 identification bytes will be written below
|
||||||
|
}
|
||||||
|
overwriteByte(rom0, 0x147, byte, "cartridge type");
|
||||||
|
}
|
||||||
|
|
||||||
|
// ROM size will be written last, after evaluating the file's size
|
||||||
|
|
||||||
|
if ((cartridgeType & 0xFF00) == TPP1) {
|
||||||
|
uint8_t const tpp1Code[2] = {0xC1, 0x65};
|
||||||
|
|
||||||
|
overwriteBytes(rom0, 0x149, tpp1Code, sizeof(tpp1Code), "TPP1 identification code");
|
||||||
|
|
||||||
|
overwriteBytes(rom0, 0x150, tpp1Rev, sizeof(tpp1Rev), "TPP1 revision number");
|
||||||
|
|
||||||
if (ramSize != UNSPECIFIED)
|
if (ramSize != UNSPECIFIED)
|
||||||
rom0[0x149] = ramSize;
|
overwriteByte(rom0, 0x152, ramSize, "RAM size");
|
||||||
|
|
||||||
|
overwriteByte(rom0, 0x153, cartridgeType & 0xFF, "TPP1 feature flags");
|
||||||
|
} else {
|
||||||
|
// Regular mappers
|
||||||
|
|
||||||
|
if (ramSize != UNSPECIFIED)
|
||||||
|
overwriteByte(rom0, 0x149, ramSize, "RAM size");
|
||||||
|
|
||||||
if (!japanese)
|
if (!japanese)
|
||||||
rom0[0x14a] = 0x01;
|
overwriteByte(rom0, 0x14A, 0x01, "destination code");
|
||||||
|
}
|
||||||
|
|
||||||
if (oldLicensee != UNSPECIFIED)
|
if (oldLicensee != UNSPECIFIED)
|
||||||
rom0[0x14b] = oldLicensee;
|
overwriteByte(rom0, 0x14B, oldLicensee, "old licensee code");
|
||||||
|
|
||||||
if (romVersion != UNSPECIFIED)
|
if (romVersion != UNSPECIFIED)
|
||||||
rom0[0x14c] = romVersion;
|
overwriteByte(rom0, 0x14C, romVersion, "mask ROM version number");
|
||||||
|
|
||||||
// Remain to be handled the ROM size, and header checksum.
|
// Remain to be handled the ROM size, and header checksum.
|
||||||
// The latter depends on the former, and so will be handled after it.
|
// The latter depends on the former, and so will be handled after it.
|
||||||
@@ -765,8 +1016,7 @@ static void processFile(int input, int output, char const *name, off_t fileSize)
|
|||||||
static_assert(0x10000 * BANK_SIZE <= SSIZE_MAX, "Max input file size too large for OS");
|
static_assert(0x10000 * BANK_SIZE <= SSIZE_MAX, "Max input file size too large for OS");
|
||||||
if (nbBanks == 0x10000) {
|
if (nbBanks == 0x10000) {
|
||||||
report("FATAL: \"%s\" has more than 65536 banks\n", name);
|
report("FATAL: \"%s\" has more than 65536 banks\n", name);
|
||||||
free(romx);
|
goto cleanup;
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
nbBanks++;
|
nbBanks++;
|
||||||
|
|
||||||
@@ -816,16 +1066,19 @@ static void processFile(int input, int output, char const *name, off_t fileSize)
|
|||||||
if (fixSpec & (FIX_HEADER_SUM | TRASH_HEADER_SUM)) {
|
if (fixSpec & (FIX_HEADER_SUM | TRASH_HEADER_SUM)) {
|
||||||
uint8_t sum = 0;
|
uint8_t sum = 0;
|
||||||
|
|
||||||
for (uint16_t i = 0x134; i < 0x14d; i++)
|
for (uint16_t i = 0x134; i < 0x14D; i++)
|
||||||
sum -= rom0[i] + 1;
|
sum -= rom0[i] + 1;
|
||||||
rom0[0x14d] = fixSpec & TRASH_HEADER_SUM ? ~sum : sum;
|
|
||||||
|
overwriteByte(rom0, 0x14D, fixSpec & TRASH_HEADER_SUM ? ~sum : sum,
|
||||||
|
"header checksum");
|
||||||
}
|
}
|
||||||
|
|
||||||
if (fixSpec & (FIX_GLOBAL_SUM | TRASH_GLOBAL_SUM)) {
|
if (fixSpec & (FIX_GLOBAL_SUM | TRASH_GLOBAL_SUM)) {
|
||||||
// Computation of the global checksum assumes 0s being stored in its place
|
// Computation of the global checksum does not include the checksum bytes
|
||||||
rom0[0x14e] = 0;
|
assert(rom0Len >= 0x14E);
|
||||||
rom0[0x14f] = 0;
|
for (uint16_t i = 0; i < 0x14E; i++)
|
||||||
for (uint16_t i = 0; i < rom0Len; i++)
|
globalSum += rom0[i];
|
||||||
|
for (uint16_t i = 0x150; i < rom0Len; i++)
|
||||||
globalSum += rom0[i];
|
globalSum += rom0[i];
|
||||||
// Pipes have already read ROMX and updated globalSum, but not regular files
|
// Pipes have already read ROMX and updated globalSum, but not regular files
|
||||||
if (input == output) {
|
if (input == output) {
|
||||||
@@ -841,8 +1094,10 @@ static void processFile(int input, int output, char const *name, off_t fileSize)
|
|||||||
|
|
||||||
if (fixSpec & TRASH_GLOBAL_SUM)
|
if (fixSpec & TRASH_GLOBAL_SUM)
|
||||||
globalSum = ~globalSum;
|
globalSum = ~globalSum;
|
||||||
rom0[0x14e] = globalSum >> 8;
|
|
||||||
rom0[0x14f] = globalSum & 0xff;
|
uint8_t bytes[2] = {globalSum >> 8, globalSum & 0xFF};
|
||||||
|
|
||||||
|
overwriteBytes(rom0, 0x14E, bytes, sizeof(bytes), "global checksum");
|
||||||
}
|
}
|
||||||
|
|
||||||
// In case the output depends on the input, reset to the beginning of the file, and only
|
// In case the output depends on the input, reset to the beginning of the file, and only
|
||||||
@@ -850,22 +1105,22 @@ static void processFile(int input, int output, char const *name, off_t fileSize)
|
|||||||
if (input == output) {
|
if (input == output) {
|
||||||
if (lseek(output, 0, SEEK_SET) == (off_t)-1) {
|
if (lseek(output, 0, SEEK_SET) == (off_t)-1) {
|
||||||
report("FATAL: Failed to rewind \"%s\": %s\n", name, strerror(errno));
|
report("FATAL: Failed to rewind \"%s\": %s\n", name, strerror(errno));
|
||||||
goto free_romx;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
// If modifying the file in-place, we only need to edit the header
|
// If modifying the file in-place, we only need to edit the header
|
||||||
// However, padding may have modified ROM0 (added padding), so don't in that case
|
// However, padding may have modified ROM0 (added padding), so don't in that case
|
||||||
if (padValue == UNSPECIFIED)
|
if (padValue == UNSPECIFIED)
|
||||||
rom0Len = 0x150;
|
rom0Len = headerSize;
|
||||||
}
|
}
|
||||||
ssize_t writeLen = writeBytes(output, rom0, rom0Len);
|
ssize_t writeLen = writeBytes(output, rom0, rom0Len);
|
||||||
|
|
||||||
if (writeLen == -1) {
|
if (writeLen == -1) {
|
||||||
report("FATAL: Failed to write \"%s\"'s ROM0: %s\n", name, strerror(errno));
|
report("FATAL: Failed to write \"%s\"'s ROM0: %s\n", name, strerror(errno));
|
||||||
goto free_romx;
|
goto cleanup;
|
||||||
} else if (writeLen < rom0Len) {
|
} else if (writeLen < rom0Len) {
|
||||||
report("FATAL: Could only write %ld of \"%s\"'s %ld ROM0 bytes\n",
|
report("FATAL: Could only write %jd of \"%s\"'s %jd ROM0 bytes\n",
|
||||||
writeLen, name, rom0Len);
|
(intmax_t)writeLen, name, (intmax_t)rom0Len);
|
||||||
goto free_romx;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Output ROMX if it was buffered
|
// Output ROMX if it was buffered
|
||||||
@@ -875,11 +1130,11 @@ static void processFile(int input, int output, char const *name, off_t fileSize)
|
|||||||
writeLen = writeBytes(output, romx, totalRomxLen);
|
writeLen = writeBytes(output, romx, totalRomxLen);
|
||||||
if (writeLen == -1) {
|
if (writeLen == -1) {
|
||||||
report("FATAL: Failed to write \"%s\"'s ROMX: %s\n", name, strerror(errno));
|
report("FATAL: Failed to write \"%s\"'s ROMX: %s\n", name, strerror(errno));
|
||||||
goto free_romx;
|
goto cleanup;
|
||||||
} else if ((size_t)writeLen < totalRomxLen) {
|
} else if ((size_t)writeLen < totalRomxLen) {
|
||||||
report("FATAL: Could only write %ld of \"%s\"'s %ld ROMX bytes\n",
|
report("FATAL: Could only write %jd of \"%s\"'s %zu ROMX bytes\n",
|
||||||
writeLen, name, totalRomxLen);
|
(intmax_t)writeLen, name, totalRomxLen);
|
||||||
goto free_romx;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -889,7 +1144,7 @@ static void processFile(int input, int output, char const *name, off_t fileSize)
|
|||||||
if (lseek(output, 0, SEEK_END) == (off_t)-1) {
|
if (lseek(output, 0, SEEK_END) == (off_t)-1) {
|
||||||
report("FATAL: Failed to seek to end of \"%s\": %s\n",
|
report("FATAL: Failed to seek to end of \"%s\": %s\n",
|
||||||
name, strerror(errno));
|
name, strerror(errno));
|
||||||
goto free_romx;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
memset(bank, padValue, sizeof(bank));
|
memset(bank, padValue, sizeof(bank));
|
||||||
@@ -911,12 +1166,10 @@ static void processFile(int input, int output, char const *name, off_t fileSize)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
free_romx:
|
cleanup:
|
||||||
free(romx);
|
free(romx);
|
||||||
}
|
}
|
||||||
|
|
||||||
#undef trySeek
|
|
||||||
|
|
||||||
static bool processFilename(char const *name)
|
static bool processFilename(char const *name)
|
||||||
{
|
{
|
||||||
nbErrors = 0;
|
nbErrors = 0;
|
||||||
@@ -938,7 +1191,7 @@ static bool processFilename(char const *name)
|
|||||||
if (input == -1) {
|
if (input == -1) {
|
||||||
report("FATAL: Failed to open \"%s\" for reading+writing: %s\n",
|
report("FATAL: Failed to open \"%s\" for reading+writing: %s\n",
|
||||||
name, strerror(errno));
|
name, strerror(errno));
|
||||||
goto fail;
|
goto finish;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (fstat(input, &stat) == -1) {
|
if (fstat(input, &stat) == -1) {
|
||||||
@@ -949,16 +1202,16 @@ static bool processFilename(char const *name)
|
|||||||
} else if (stat.st_size < 0x150) {
|
} else if (stat.st_size < 0x150) {
|
||||||
// This check is in theory redundant with the one in `processFile`, but it
|
// This check is in theory redundant with the one in `processFile`, but it
|
||||||
// prevents passing a file size of 0, which usually indicates pipes
|
// prevents passing a file size of 0, which usually indicates pipes
|
||||||
report("FATAL: \"%s\" too short, expected at least 336 ($150) bytes, got only %ld\n",
|
report("FATAL: \"%s\" too short, expected at least 336 ($150) bytes, got only %jd\n",
|
||||||
name, stat.st_size);
|
name, (intmax_t)stat.st_size);
|
||||||
} else {
|
} else {
|
||||||
processFile(input, input, name, stat.st_size);
|
processFile(input, input, name, stat.st_size);
|
||||||
}
|
}
|
||||||
|
|
||||||
close(input);
|
close(input);
|
||||||
}
|
}
|
||||||
|
finish:
|
||||||
if (nbErrors)
|
if (nbErrors)
|
||||||
fail:
|
|
||||||
fprintf(stderr, "Fixing \"%s\" failed with %u error%s\n",
|
fprintf(stderr, "Fixing \"%s\" failed with %u error%s\n",
|
||||||
name, nbErrors, nbErrors == 1 ? "" : "s");
|
name, nbErrors, nbErrors == 1 ? "" : "s");
|
||||||
return nbErrors;
|
return nbErrors;
|
||||||
@@ -967,7 +1220,7 @@ fail:
|
|||||||
int main(int argc, char *argv[])
|
int main(int argc, char *argv[])
|
||||||
{
|
{
|
||||||
nbErrors = 0;
|
nbErrors = 0;
|
||||||
char ch;
|
int ch;
|
||||||
|
|
||||||
while ((ch = musl_getopt_long_only(argc, argv, optstring, longopts, NULL)) != -1) {
|
while ((ch = musl_getopt_long_only(argc, argv, optstring, longopts, NULL)) != -1) {
|
||||||
switch (ch) {
|
switch (ch) {
|
||||||
@@ -1015,38 +1268,38 @@ do { \
|
|||||||
#define SPEC_H TRASH_HEADER_SUM
|
#define SPEC_H TRASH_HEADER_SUM
|
||||||
#define SPEC_g FIX_GLOBAL_SUM
|
#define SPEC_g FIX_GLOBAL_SUM
|
||||||
#define SPEC_G TRASH_GLOBAL_SUM
|
#define SPEC_G TRASH_GLOBAL_SUM
|
||||||
#define or(new, bad) \
|
#define overrideSpec(cur, bad) \
|
||||||
do { \
|
do { \
|
||||||
if (fixSpec & SPEC_##bad) \
|
if (fixSpec & SPEC_##bad) \
|
||||||
fprintf(stderr, \
|
fprintf(stderr, \
|
||||||
"warning: '" #new "' overriding '" #bad "' in fix spec\n"); \
|
"warning: '" #cur "' overriding '" #bad "' in fix spec\n"); \
|
||||||
fixSpec = (fixSpec & ~SPEC_##bad) | SPEC_##new; \
|
fixSpec = (fixSpec & ~SPEC_##bad) | SPEC_##cur; \
|
||||||
} while (0)
|
} while (0)
|
||||||
case 'l':
|
case 'l':
|
||||||
or(l, L);
|
overrideSpec(l, L);
|
||||||
break;
|
break;
|
||||||
case 'L':
|
case 'L':
|
||||||
or(L, l);
|
overrideSpec(L, l);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 'h':
|
case 'h':
|
||||||
or(h, H);
|
overrideSpec(h, H);
|
||||||
break;
|
break;
|
||||||
case 'H':
|
case 'H':
|
||||||
or(H, h);
|
overrideSpec(H, h);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 'g':
|
case 'g':
|
||||||
or(g, G);
|
overrideSpec(g, G);
|
||||||
break;
|
break;
|
||||||
case 'G':
|
case 'G':
|
||||||
or(G, g);
|
overrideSpec(G, g);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
fprintf(stderr, "warning: Ignoring '%c' in fix spec\n",
|
fprintf(stderr, "warning: Ignoring '%c' in fix spec\n",
|
||||||
*musl_optarg);
|
*musl_optarg);
|
||||||
#undef or
|
#undef overrideSpec
|
||||||
}
|
}
|
||||||
musl_optarg++;
|
musl_optarg++;
|
||||||
}
|
}
|
||||||
@@ -1091,10 +1344,13 @@ do { \
|
|||||||
case 'm':
|
case 'm':
|
||||||
cartridgeType = parseMBC(musl_optarg);
|
cartridgeType = parseMBC(musl_optarg);
|
||||||
if (cartridgeType == MBC_BAD) {
|
if (cartridgeType == MBC_BAD) {
|
||||||
report("error: Unknown MBC \"%s\"\n", musl_optarg);
|
report("error: Unknown MBC \"%s\"\nAccepted MBC names:\n",
|
||||||
} else if (cartridgeType == MBC_WRONG_FEATURES) {
|
|
||||||
report("error: Features incompatible with MBC (\"%s\")\n",
|
|
||||||
musl_optarg);
|
musl_optarg);
|
||||||
|
printAcceptedMBCNames();
|
||||||
|
} else if (cartridgeType == MBC_WRONG_FEATURES) {
|
||||||
|
report("error: Features incompatible with MBC (\"%s\")\nAccepted combinations:\n",
|
||||||
|
musl_optarg);
|
||||||
|
printAcceptedMBCNames();
|
||||||
} else if (cartridgeType == MBC_BAD_RANGE) {
|
} else if (cartridgeType == MBC_BAD_RANGE) {
|
||||||
report("error: Specified MBC ID out of range 0-255: %s\n",
|
report("error: Specified MBC ID out of range 0-255: %s\n",
|
||||||
musl_optarg);
|
musl_optarg);
|
||||||
@@ -1107,6 +1363,10 @@ do { \
|
|||||||
parseByte(romVersion, "n");
|
parseByte(romVersion, "n");
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
case 'O':
|
||||||
|
overwriteRom = true;
|
||||||
|
break;
|
||||||
|
|
||||||
case 'p':
|
case 'p':
|
||||||
parseByte(padValue, "p");
|
parseByte(padValue, "p");
|
||||||
break;
|
break;
|
||||||
@@ -1148,7 +1408,11 @@ do { \
|
|||||||
#undef parseByte
|
#undef parseByte
|
||||||
}
|
}
|
||||||
|
|
||||||
if (ramSize != UNSPECIFIED && cartridgeType < UNSPECIFIED) {
|
if ((cartridgeType & 0xFF00) == TPP1 && !japanese)
|
||||||
|
fprintf(stderr, "warning: TPP1 overwrites region flag for its identification code, ignoring `-j`\n");
|
||||||
|
|
||||||
|
// Check that RAM size is correct for "standard" mappers
|
||||||
|
if (ramSize != UNSPECIFIED && (cartridgeType & 0xFF00) == 0) {
|
||||||
if (cartridgeType == ROM_RAM || cartridgeType == ROM_RAM_BATTERY) {
|
if (cartridgeType == ROM_RAM || cartridgeType == ROM_RAM_BATTERY) {
|
||||||
if (ramSize != 1)
|
if (ramSize != 1)
|
||||||
fprintf(stderr, "warning: MBC \"%s\" should have 2kiB of RAM (-r 1)\n",
|
fprintf(stderr, "warning: MBC \"%s\" should have 2kiB of RAM (-r 1)\n",
|
||||||
|
|||||||
@@ -13,7 +13,7 @@
|
|||||||
.Nd Game Boy header utility and checksum fixer
|
.Nd Game Boy header utility and checksum fixer
|
||||||
.Sh SYNOPSIS
|
.Sh SYNOPSIS
|
||||||
.Nm
|
.Nm
|
||||||
.Op Fl jsVv
|
.Op Fl jOsVv
|
||||||
.Op Fl C | c
|
.Op Fl C | c
|
||||||
.Op Fl f Ar fix_spec
|
.Op Fl f Ar fix_spec
|
||||||
.Op Fl i Ar game_id
|
.Op Fl i Ar game_id
|
||||||
@@ -112,11 +112,21 @@ This value is deprecated and should be set to 0x33 in all new software.
|
|||||||
Set the MBC type
|
Set the MBC type
|
||||||
.Pq Ad 0x147
|
.Pq Ad 0x147
|
||||||
to a given value from 0 to 0xFF.
|
to a given value from 0 to 0xFF.
|
||||||
This value may also be an MBC name from the Pan Docs.
|
.Pp
|
||||||
|
This value may also be an MBC name.
|
||||||
|
The list of accepted names can be obtained by passing
|
||||||
|
.Ql Cm help
|
||||||
|
as the argument.
|
||||||
|
Any amount of whitespace (space and tabs) is allowed around plus signs, and the order of "components" is free, as long as the MBC name is first.
|
||||||
|
There are special considerations to take for the TPP1 mapper; see the
|
||||||
|
.Sx TPP1
|
||||||
|
section below.
|
||||||
.It Fl n Ar rom_version , Fl Fl rom-version Ar rom_version
|
.It Fl n Ar rom_version , Fl Fl rom-version Ar rom_version
|
||||||
Set the ROM version
|
Set the ROM version
|
||||||
.Pq Ad 0x14C
|
.Pq Ad 0x14C
|
||||||
to a given value from 0 to 0xFF.
|
to a given value from 0 to 0xFF.
|
||||||
|
.It Fl O , Fl Fl overwrite
|
||||||
|
Allow overwriting different non-zero bytes in the header without a warning being emitted.
|
||||||
.It Fl p Ar pad_value , Fl Fl pad-value Ar pad_value
|
.It Fl p Ar pad_value , Fl Fl pad-value Ar pad_value
|
||||||
Pad the ROM image to a valid size with a given pad value from 0 to 255 (0xFF).
|
Pad the ROM image to a valid size with a given pad value from 0 to 255 (0xFF).
|
||||||
.Nm
|
.Nm
|
||||||
@@ -179,6 +189,46 @@ sans global checksum:
|
|||||||
.Pp
|
.Pp
|
||||||
.D1 $ rgbfix -cjsv -k A4 -l 0x33 -m 0x1B -p 0xFF -r 3 -t SURVIVALKIDAVKE \
|
.D1 $ rgbfix -cjsv -k A4 -l 0x33 -m 0x1B -p 0xFF -r 3 -t SURVIVALKIDAVKE \
|
||||||
SurvivalKids.gbc
|
SurvivalKids.gbc
|
||||||
|
.Sh TPP1
|
||||||
|
TPP1 is a homebrew mapper designed as a functional superset of the common traditional MBCs, allowing larger ROM and RAM sizes combined with other hardware features.
|
||||||
|
Its specification, as well as more resources, can be found online at
|
||||||
|
.Lk https://github.com/TwitchPlaysPokemon/tpp1 .
|
||||||
|
.Ss MBC name
|
||||||
|
The MBC name for TPP1 is more complex than standard mappers.
|
||||||
|
It must be followed with the revision number, of the form
|
||||||
|
.Ql major.minor ,
|
||||||
|
where both
|
||||||
|
.Ql major
|
||||||
|
and
|
||||||
|
.Ql minor
|
||||||
|
are decimal, 8-bit integers.
|
||||||
|
There may be any amount of spaces or underscores between
|
||||||
|
.Ql TPP1
|
||||||
|
and the revision number.
|
||||||
|
.Nm
|
||||||
|
only supports 1.x revisions, and will reject everything else.
|
||||||
|
.Pp
|
||||||
|
Like other mappers, the name may be followed with a list of optional,
|
||||||
|
.Ql + Ns
|
||||||
|
-separated features; however,
|
||||||
|
.Ql RAM
|
||||||
|
should not be specified, as the TPP1 mapper implicitly requests RAM if a non-zero RAM size is specified.
|
||||||
|
Therefore,
|
||||||
|
.Nm
|
||||||
|
will ignore the
|
||||||
|
.Ql RAM
|
||||||
|
feature on a TPP1 mapper with a warning.
|
||||||
|
.Ss Special considerations
|
||||||
|
TPP1 overwrites the byte at
|
||||||
|
.Ad 0x14A ,
|
||||||
|
usually indicating the region destination
|
||||||
|
.Pq see Fl j ,
|
||||||
|
with one of its three identification bytes.
|
||||||
|
Therefore,
|
||||||
|
.Nm
|
||||||
|
will warn about and ignore
|
||||||
|
.Fl j
|
||||||
|
if used in combination with TPP1.
|
||||||
.Sh BUGS
|
.Sh BUGS
|
||||||
Please report bugs on
|
Please report bugs on
|
||||||
.Lk https://github.com/gbdev/rgbds/issues GitHub .
|
.Lk https://github.com/gbdev/rgbds/issues GitHub .
|
||||||
|
|||||||
764
src/gbz80.7
764
src/gbz80.7
File diff suppressed because it is too large
Load Diff
37
src/gfx/gb.c
37
src/gfx/gb.c
@@ -20,7 +20,7 @@ void transpose_tiles(struct GBImage *gb, int width)
|
|||||||
|
|
||||||
newdata = calloc(gb->size, 1);
|
newdata = calloc(gb->size, 1);
|
||||||
if (!newdata)
|
if (!newdata)
|
||||||
err(1, "%s: Failed to allocate memory for new data", __func__);
|
err("%s: Failed to allocate memory for new data", __func__);
|
||||||
|
|
||||||
for (i = 0; i < gb->size; i++) {
|
for (i = 0; i < gb->size; i++) {
|
||||||
newbyte = i / (8 * depth) * width * 8 * depth;
|
newbyte = i / (8 * depth) * width * 8 * depth;
|
||||||
@@ -37,15 +37,14 @@ void transpose_tiles(struct GBImage *gb, int width)
|
|||||||
|
|
||||||
void raw_to_gb(const struct RawIndexedImage *raw_image, struct GBImage *gb)
|
void raw_to_gb(const struct RawIndexedImage *raw_image, struct GBImage *gb)
|
||||||
{
|
{
|
||||||
int x, y, byte;
|
|
||||||
uint8_t index;
|
uint8_t index;
|
||||||
|
|
||||||
for (y = 0; y < raw_image->height; y++) {
|
for (unsigned int y = 0; y < raw_image->height; y++) {
|
||||||
for (x = 0; x < raw_image->width; x++) {
|
for (unsigned int x = 0; x < raw_image->width; x++) {
|
||||||
index = raw_image->data[y][x];
|
index = raw_image->data[y][x];
|
||||||
index &= (1 << depth) - 1;
|
index &= (1 << depth) - 1;
|
||||||
|
|
||||||
byte = y * depth
|
unsigned int byte = y * depth
|
||||||
+ x / 8 * raw_image->height / 8 * 8 * depth;
|
+ x / 8 * raw_image->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) {
|
||||||
@@ -65,7 +64,7 @@ void output_file(const struct Options *opts, const struct GBImage *gb)
|
|||||||
|
|
||||||
f = fopen(opts->outfile, "wb");
|
f = fopen(opts->outfile, "wb");
|
||||||
if (!f)
|
if (!f)
|
||||||
err(1, "%s: Opening output file '%s' failed", __func__,
|
err("%s: Opening output file '%s' failed", __func__,
|
||||||
opts->outfile);
|
opts->outfile);
|
||||||
|
|
||||||
fwrite(gb->data, 1, gb->size - gb->trim * 8 * depth, f);
|
fwrite(gb->data, 1, gb->size - gb->trim * 8 * depth, f);
|
||||||
@@ -141,7 +140,7 @@ int get_mirrored_tile_index(uint8_t *tile, uint8_t **tiles, int num_tiles,
|
|||||||
|
|
||||||
tile_yflip = malloc(tile_size);
|
tile_yflip = malloc(tile_size);
|
||||||
if (!tile_yflip)
|
if (!tile_yflip)
|
||||||
err(1, "%s: Failed to allocate memory for Y flip of tile",
|
err("%s: Failed to allocate memory for Y flip of tile",
|
||||||
__func__);
|
__func__);
|
||||||
yflip(tile, tile_yflip, tile_size);
|
yflip(tile, tile_yflip, tile_size);
|
||||||
index = get_tile_index(tile_yflip, tiles, num_tiles, tile_size);
|
index = get_tile_index(tile_yflip, tiles, num_tiles, tile_size);
|
||||||
@@ -153,7 +152,7 @@ int get_mirrored_tile_index(uint8_t *tile, uint8_t **tiles, int num_tiles,
|
|||||||
|
|
||||||
tile_xflip = malloc(tile_size);
|
tile_xflip = malloc(tile_size);
|
||||||
if (!tile_xflip)
|
if (!tile_xflip)
|
||||||
err(1, "%s: Failed to allocate memory for X flip of tile",
|
err("%s: Failed to allocate memory for X flip of tile",
|
||||||
__func__);
|
__func__);
|
||||||
xflip(tile, tile_xflip, tile_size);
|
xflip(tile, tile_xflip, tile_size);
|
||||||
index = get_tile_index(tile_xflip, tiles, num_tiles, tile_size);
|
index = get_tile_index(tile_xflip, tiles, num_tiles, tile_size);
|
||||||
@@ -198,13 +197,13 @@ void create_mapfiles(const struct Options *opts, struct GBImage *gb,
|
|||||||
|
|
||||||
tiles = calloc(max_tiles, sizeof(*tiles));
|
tiles = calloc(max_tiles, sizeof(*tiles));
|
||||||
if (!tiles)
|
if (!tiles)
|
||||||
err(1, "%s: Failed to allocate memory for tiles", __func__);
|
err("%s: Failed to allocate memory for tiles", __func__);
|
||||||
num_tiles = 0;
|
num_tiles = 0;
|
||||||
|
|
||||||
if (*opts->tilemapfile) {
|
if (*opts->tilemapfile) {
|
||||||
tilemap->data = calloc(max_tiles, sizeof(*tilemap->data));
|
tilemap->data = calloc(max_tiles, sizeof(*tilemap->data));
|
||||||
if (!tilemap->data)
|
if (!tilemap->data)
|
||||||
err(1, "%s: Failed to allocate memory for tilemap data",
|
err("%s: Failed to allocate memory for tilemap data",
|
||||||
__func__);
|
__func__);
|
||||||
tilemap->size = 0;
|
tilemap->size = 0;
|
||||||
}
|
}
|
||||||
@@ -212,7 +211,7 @@ void create_mapfiles(const struct Options *opts, struct GBImage *gb,
|
|||||||
if (*opts->attrmapfile) {
|
if (*opts->attrmapfile) {
|
||||||
attrmap->data = calloc(max_tiles, sizeof(*attrmap->data));
|
attrmap->data = calloc(max_tiles, sizeof(*attrmap->data));
|
||||||
if (!attrmap->data)
|
if (!attrmap->data)
|
||||||
err(1, "%s: Failed to allocate memory for attrmap data",
|
err("%s: Failed to allocate memory for attrmap data",
|
||||||
__func__);
|
__func__);
|
||||||
attrmap->size = 0;
|
attrmap->size = 0;
|
||||||
}
|
}
|
||||||
@@ -222,9 +221,13 @@ void create_mapfiles(const struct Options *opts, struct GBImage *gb,
|
|||||||
flags = 0;
|
flags = 0;
|
||||||
tile = malloc(tile_size);
|
tile = malloc(tile_size);
|
||||||
if (!tile)
|
if (!tile)
|
||||||
err(1, "%s: Failed to allocate memory for tile",
|
err("%s: Failed to allocate memory for tile",
|
||||||
__func__);
|
__func__);
|
||||||
for (i = 0; i < tile_size; i++) {
|
/*
|
||||||
|
* If the input image doesn't fill the last tile,
|
||||||
|
* `gb_i` will reach `gb_size`.
|
||||||
|
*/
|
||||||
|
for (i = 0; i < tile_size && gb_i < gb_size; i++) {
|
||||||
tile[i] = gb->data[gb_i];
|
tile[i] = gb->data[gb_i];
|
||||||
gb_i++;
|
gb_i++;
|
||||||
}
|
}
|
||||||
@@ -265,7 +268,7 @@ void create_mapfiles(const struct Options *opts, struct GBImage *gb,
|
|||||||
free(gb->data);
|
free(gb->data);
|
||||||
gb->data = malloc(tile_size * num_tiles);
|
gb->data = malloc(tile_size * num_tiles);
|
||||||
if (!gb->data)
|
if (!gb->data)
|
||||||
err(1, "%s: Failed to allocate memory for tile data",
|
err("%s: Failed to allocate memory for tile data",
|
||||||
__func__);
|
__func__);
|
||||||
for (i = 0; i < num_tiles; i++) {
|
for (i = 0; i < num_tiles; i++) {
|
||||||
tile = tiles[i];
|
tile = tiles[i];
|
||||||
@@ -288,7 +291,7 @@ void output_tilemap_file(const struct Options *opts,
|
|||||||
|
|
||||||
f = fopen(opts->tilemapfile, "wb");
|
f = fopen(opts->tilemapfile, "wb");
|
||||||
if (!f)
|
if (!f)
|
||||||
err(1, "%s: Opening tilemap file '%s' failed", __func__,
|
err("%s: Opening tilemap file '%s' failed", __func__,
|
||||||
opts->tilemapfile);
|
opts->tilemapfile);
|
||||||
|
|
||||||
fwrite(tilemap->data, 1, tilemap->size, f);
|
fwrite(tilemap->data, 1, tilemap->size, f);
|
||||||
@@ -305,7 +308,7 @@ void output_attrmap_file(const struct Options *opts,
|
|||||||
|
|
||||||
f = fopen(opts->attrmapfile, "wb");
|
f = fopen(opts->attrmapfile, "wb");
|
||||||
if (!f)
|
if (!f)
|
||||||
err(1, "%s: Opening attrmap file '%s' failed", __func__,
|
err("%s: Opening attrmap file '%s' failed", __func__,
|
||||||
opts->attrmapfile);
|
opts->attrmapfile);
|
||||||
|
|
||||||
fwrite(attrmap->data, 1, attrmap->size, f);
|
fwrite(attrmap->data, 1, attrmap->size, f);
|
||||||
@@ -348,7 +351,7 @@ void output_palette_file(const struct Options *opts,
|
|||||||
|
|
||||||
f = fopen(opts->palfile, "wb");
|
f = fopen(opts->palfile, "wb");
|
||||||
if (!f)
|
if (!f)
|
||||||
err(1, "%s: Opening palette file '%s' failed", __func__,
|
err("%s: Opening palette file '%s' failed", __func__,
|
||||||
opts->palfile);
|
opts->palfile);
|
||||||
|
|
||||||
for (i = 0; i < raw_image->num_colors; i++) {
|
for (i = 0; i < raw_image->num_colors; i++) {
|
||||||
|
|||||||
@@ -167,7 +167,7 @@ int main(int argc, char *argv[])
|
|||||||
opts.infile = argv[argc - 1];
|
opts.infile = argv[argc - 1];
|
||||||
|
|
||||||
if (depth != 1 && depth != 2)
|
if (depth != 1 && depth != 2)
|
||||||
errx(1, "Depth option must be either 1 or 2.");
|
errx("Depth option must be either 1 or 2.");
|
||||||
|
|
||||||
colors = 1 << depth;
|
colors = 1 << depth;
|
||||||
|
|
||||||
@@ -200,17 +200,17 @@ int main(int argc, char *argv[])
|
|||||||
opts.trim = png_options.trim;
|
opts.trim = png_options.trim;
|
||||||
|
|
||||||
if (raw_image->width % 8) {
|
if (raw_image->width % 8) {
|
||||||
errx(1, "Input PNG file %s not sized correctly. The image's width must be a multiple of 8.",
|
errx("Input PNG file %s not sized correctly. The image's width must be a multiple of 8.",
|
||||||
opts.infile);
|
opts.infile);
|
||||||
}
|
}
|
||||||
if (raw_image->width / 8 > 1 && raw_image->height % 8) {
|
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.",
|
errx("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);
|
opts.infile);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (opts.trim &&
|
if (opts.trim &&
|
||||||
opts.trim > (raw_image->width / 8) * (raw_image->height / 8) - 1) {
|
opts.trim > (raw_image->width / 8) * (raw_image->height / 8) - 1) {
|
||||||
errx(1, "Trim (%d) for input raw_image file '%s' too large (max: %u)",
|
errx("Trim (%d) for input raw_image file '%s' too large (max: %u)",
|
||||||
opts.trim, opts.infile,
|
opts.trim, opts.infile,
|
||||||
(raw_image->width / 8) * (raw_image->height / 8) - 1);
|
(raw_image->width / 8) * (raw_image->height / 8) - 1);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -32,7 +32,7 @@ struct RawIndexedImage *input_png_file(const struct Options *opts,
|
|||||||
|
|
||||||
f = fopen(opts->infile, "rb");
|
f = fopen(opts->infile, "rb");
|
||||||
if (!f)
|
if (!f)
|
||||||
err(1, "Opening input png file '%s' failed", opts->infile);
|
err("Opening input png file '%s' failed", opts->infile);
|
||||||
|
|
||||||
initialize_png(&img, f);
|
initialize_png(&img, f);
|
||||||
|
|
||||||
@@ -54,7 +54,7 @@ struct RawIndexedImage *input_png_file(const struct Options *opts,
|
|||||||
raw_image = truecolor_png_to_raw(&img); break;
|
raw_image = truecolor_png_to_raw(&img); break;
|
||||||
default:
|
default:
|
||||||
/* Shouldn't happen, but might as well handle just in case. */
|
/* Shouldn't happen, but might as well handle just in case. */
|
||||||
errx(1, "Input PNG file is of invalid color type.");
|
errx("Input PNG file is of invalid color type.");
|
||||||
}
|
}
|
||||||
|
|
||||||
get_text(&img, png_options);
|
get_text(&img, png_options);
|
||||||
@@ -83,7 +83,7 @@ void output_png_file(const struct Options *opts,
|
|||||||
if (opts->debug) {
|
if (opts->debug) {
|
||||||
outfile = malloc(strlen(opts->infile) + 5);
|
outfile = malloc(strlen(opts->infile) + 5);
|
||||||
if (!outfile)
|
if (!outfile)
|
||||||
err(1, "%s: Failed to allocate memory for outfile",
|
err("%s: Failed to allocate memory for outfile",
|
||||||
__func__);
|
__func__);
|
||||||
strcpy(outfile, opts->infile);
|
strcpy(outfile, opts->infile);
|
||||||
strcat(outfile, ".out");
|
strcat(outfile, ".out");
|
||||||
@@ -93,16 +93,19 @@ void output_png_file(const struct Options *opts,
|
|||||||
|
|
||||||
f = fopen(outfile, "wb");
|
f = fopen(outfile, "wb");
|
||||||
if (!f)
|
if (!f)
|
||||||
err(1, "Opening output png file '%s' failed", outfile);
|
err("Opening output png file '%s' failed", outfile);
|
||||||
|
|
||||||
|
if (opts->debug)
|
||||||
|
free(outfile);
|
||||||
|
|
||||||
img.png = png_create_write_struct(PNG_LIBPNG_VER_STRING,
|
img.png = png_create_write_struct(PNG_LIBPNG_VER_STRING,
|
||||||
NULL, NULL, NULL);
|
NULL, NULL, NULL);
|
||||||
if (!img.png)
|
if (!img.png)
|
||||||
errx(1, "Creating png structure failed");
|
errx("Creating png structure failed");
|
||||||
|
|
||||||
img.info = png_create_info_struct(img.png);
|
img.info = png_create_info_struct(img.png);
|
||||||
if (!img.info)
|
if (!img.info)
|
||||||
errx(1, "Creating png info structure failed");
|
errx("Creating png info structure failed");
|
||||||
|
|
||||||
if (setjmp(png_jmpbuf(img.png)))
|
if (setjmp(png_jmpbuf(img.png)))
|
||||||
exit(1);
|
exit(1);
|
||||||
@@ -115,7 +118,7 @@ void output_png_file(const struct Options *opts,
|
|||||||
|
|
||||||
png_palette = malloc(sizeof(*png_palette) * raw_image->num_colors);
|
png_palette = malloc(sizeof(*png_palette) * raw_image->num_colors);
|
||||||
if (!png_palette)
|
if (!png_palette)
|
||||||
err(1, "%s: Failed to allocate memory for PNG palette",
|
err("%s: Failed to allocate memory for PNG palette",
|
||||||
__func__);
|
__func__);
|
||||||
for (i = 0; i < raw_image->num_colors; i++) {
|
for (i = 0; i < raw_image->num_colors; i++) {
|
||||||
png_palette[i].red = raw_image->palette[i].red;
|
png_palette[i].red = raw_image->palette[i].red;
|
||||||
@@ -135,17 +138,13 @@ void output_png_file(const struct Options *opts,
|
|||||||
|
|
||||||
png_destroy_write_struct(&img.png, &img.info);
|
png_destroy_write_struct(&img.png, &img.info);
|
||||||
fclose(f);
|
fclose(f);
|
||||||
|
|
||||||
if (opts->debug)
|
|
||||||
free(outfile);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void destroy_raw_image(struct RawIndexedImage **raw_image_ptr_ptr)
|
void destroy_raw_image(struct RawIndexedImage **raw_image_ptr_ptr)
|
||||||
{
|
{
|
||||||
int y;
|
|
||||||
struct RawIndexedImage *raw_image = *raw_image_ptr_ptr;
|
struct RawIndexedImage *raw_image = *raw_image_ptr_ptr;
|
||||||
|
|
||||||
for (y = 0; y < raw_image->height; y++)
|
for (unsigned int y = 0; y < raw_image->height; y++)
|
||||||
free(raw_image->data[y]);
|
free(raw_image->data[y]);
|
||||||
|
|
||||||
free(raw_image->data);
|
free(raw_image->data);
|
||||||
@@ -159,11 +158,11 @@ 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)
|
||||||
errx(1, "Creating png structure failed");
|
errx("Creating png structure failed");
|
||||||
|
|
||||||
img->info = png_create_info_struct(img->png);
|
img->info = png_create_info_struct(img->png);
|
||||||
if (!img->info)
|
if (!img->info)
|
||||||
errx(1, "Creating png info structure failed");
|
errx("Creating png info structure failed");
|
||||||
|
|
||||||
if (setjmp(png_jmpbuf(img->png)))
|
if (setjmp(png_jmpbuf(img->png)))
|
||||||
exit(1);
|
exit(1);
|
||||||
@@ -182,7 +181,7 @@ static void read_png(struct PNGImage *img);
|
|||||||
static struct RawIndexedImage *create_raw_image(int width, int height,
|
static struct RawIndexedImage *create_raw_image(int width, int height,
|
||||||
int num_colors);
|
int num_colors);
|
||||||
static void set_raw_image_palette(struct RawIndexedImage *raw_image,
|
static void set_raw_image_palette(struct RawIndexedImage *raw_image,
|
||||||
const png_color *palette, int num_colors);
|
png_color const *palette, int num_colors);
|
||||||
|
|
||||||
static struct RawIndexedImage *indexed_png_to_raw(struct PNGImage *img)
|
static struct RawIndexedImage *indexed_png_to_raw(struct PNGImage *img)
|
||||||
{
|
{
|
||||||
@@ -215,13 +214,13 @@ static struct RawIndexedImage *indexed_png_to_raw(struct PNGImage *img)
|
|||||||
original_palette = palette;
|
original_palette = palette;
|
||||||
palette = malloc(sizeof(*palette) * colors_in_PLTE);
|
palette = malloc(sizeof(*palette) * colors_in_PLTE);
|
||||||
if (!palette)
|
if (!palette)
|
||||||
err(1, "%s: Failed to allocate memory for palette",
|
err("%s: Failed to allocate memory for palette",
|
||||||
__func__);
|
__func__);
|
||||||
colors_in_new_palette = 0;
|
colors_in_new_palette = 0;
|
||||||
old_to_new_palette = malloc(sizeof(*old_to_new_palette)
|
old_to_new_palette = malloc(sizeof(*old_to_new_palette)
|
||||||
* colors_in_PLTE);
|
* colors_in_PLTE);
|
||||||
if (!old_to_new_palette)
|
if (!old_to_new_palette)
|
||||||
err(1, "%s: Failed to allocate memory for new palette",
|
err("%s: Failed to allocate memory for new palette",
|
||||||
__func__);
|
__func__);
|
||||||
|
|
||||||
for (i = 0; i < num_trans; i++) {
|
for (i = 0; i < num_trans; i++) {
|
||||||
@@ -243,7 +242,7 @@ static struct RawIndexedImage *indexed_png_to_raw(struct PNGImage *img)
|
|||||||
sizeof(*palette) *
|
sizeof(*palette) *
|
||||||
colors_in_new_palette);
|
colors_in_new_palette);
|
||||||
if (!palette)
|
if (!palette)
|
||||||
err(1, "%s: Failed to allocate memory for palette",
|
err("%s: Failed to allocate memory for palette",
|
||||||
__func__);
|
__func__);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -291,7 +290,7 @@ static void rgba_png_palette(struct PNGImage *img,
|
|||||||
png_color **palette_ptr_ptr, int *num_colors);
|
png_color **palette_ptr_ptr, int *num_colors);
|
||||||
static struct RawIndexedImage
|
static struct RawIndexedImage
|
||||||
*processed_rgba_png_to_raw(const struct PNGImage *img,
|
*processed_rgba_png_to_raw(const struct PNGImage *img,
|
||||||
const png_color *palette,
|
png_color const *palette,
|
||||||
int colors_in_palette);
|
int colors_in_palette);
|
||||||
|
|
||||||
static struct RawIndexedImage *truecolor_png_to_raw(struct PNGImage *img)
|
static struct RawIndexedImage *truecolor_png_to_raw(struct PNGImage *img)
|
||||||
@@ -352,7 +351,7 @@ static void rgba_PLTE_palette(struct PNGImage *img,
|
|||||||
}
|
}
|
||||||
|
|
||||||
static void update_built_palette(png_color *palette,
|
static void update_built_palette(png_color *palette,
|
||||||
const png_color *pixel_color, png_byte alpha,
|
png_color const *pixel_color, png_byte alpha,
|
||||||
int *num_colors, bool *only_grayscale);
|
int *num_colors, bool *only_grayscale);
|
||||||
static int fit_grayscale_palette(png_color *palette, int *num_colors);
|
static int fit_grayscale_palette(png_color *palette, int *num_colors);
|
||||||
static void order_color_palette(png_color *palette, int num_colors);
|
static void order_color_palette(png_color *palette, int num_colors);
|
||||||
@@ -372,7 +371,7 @@ static void rgba_build_palette(struct PNGImage *img,
|
|||||||
*/
|
*/
|
||||||
*palette_ptr_ptr = calloc(colors, sizeof(**palette_ptr_ptr));
|
*palette_ptr_ptr = calloc(colors, sizeof(**palette_ptr_ptr));
|
||||||
if (!*palette_ptr_ptr)
|
if (!*palette_ptr_ptr)
|
||||||
err(1, "%s: Failed to allocate memory for palette", __func__);
|
err("%s: Failed to allocate memory for palette", __func__);
|
||||||
palette = *palette_ptr_ptr;
|
palette = *palette_ptr_ptr;
|
||||||
*num_colors = 0;
|
*num_colors = 0;
|
||||||
|
|
||||||
@@ -398,7 +397,7 @@ static void rgba_build_palette(struct PNGImage *img,
|
|||||||
}
|
}
|
||||||
|
|
||||||
static void update_built_palette(png_color *palette,
|
static void update_built_palette(png_color *palette,
|
||||||
const png_color *pixel_color, png_byte alpha,
|
png_color const *pixel_color, png_byte alpha,
|
||||||
int *num_colors, bool *only_grayscale)
|
int *num_colors, bool *only_grayscale)
|
||||||
{
|
{
|
||||||
bool color_exists;
|
bool color_exists;
|
||||||
@@ -429,7 +428,7 @@ static void update_built_palette(png_color *palette,
|
|||||||
}
|
}
|
||||||
if (!color_exists) {
|
if (!color_exists) {
|
||||||
if (*num_colors == colors) {
|
if (*num_colors == colors) {
|
||||||
errx(1, "Too many colors in input PNG file to fit into a %d-bit palette (max %d).",
|
errx("Too many colors in input PNG file to fit into a %d-bit palette (max %d).",
|
||||||
depth, colors);
|
depth, colors);
|
||||||
}
|
}
|
||||||
palette[*num_colors] = *pixel_color;
|
palette[*num_colors] = *pixel_color;
|
||||||
@@ -445,9 +444,9 @@ static int fit_grayscale_palette(png_color *palette, int *num_colors)
|
|||||||
int i, shade_index;
|
int i, shade_index;
|
||||||
|
|
||||||
if (!fitted_palette)
|
if (!fitted_palette)
|
||||||
err(1, "%s: Failed to allocate memory for palette", __func__);
|
err("%s: Failed to allocate memory for palette", __func__);
|
||||||
if (!set_indices)
|
if (!set_indices)
|
||||||
err(1, "%s: Failed to allocate memory for indices", __func__);
|
err("%s: Failed to allocate memory for indices", __func__);
|
||||||
|
|
||||||
fitted_palette[0].red = 0xFF;
|
fitted_palette[0].red = 0xFF;
|
||||||
fitted_palette[0].green = 0xFF;
|
fitted_palette[0].green = 0xFF;
|
||||||
@@ -491,7 +490,7 @@ struct ColorWithLuminance {
|
|||||||
int luminance;
|
int luminance;
|
||||||
};
|
};
|
||||||
|
|
||||||
static int compare_luminance(const void *a, const void *b)
|
static int compare_luminance(void const *a, void const *b)
|
||||||
{
|
{
|
||||||
const struct ColorWithLuminance *x, *y;
|
const struct ColorWithLuminance *x, *y;
|
||||||
|
|
||||||
@@ -508,7 +507,7 @@ static void order_color_palette(png_color *palette, int num_colors)
|
|||||||
malloc(sizeof(*palette_with_luminance) * num_colors);
|
malloc(sizeof(*palette_with_luminance) * num_colors);
|
||||||
|
|
||||||
if (!palette_with_luminance)
|
if (!palette_with_luminance)
|
||||||
err(1, "%s: Failed to allocate memory for palette", __func__);
|
err("%s: Failed to allocate memory for palette", __func__);
|
||||||
|
|
||||||
for (i = 0; i < num_colors; i++) {
|
for (i = 0; i < num_colors; i++) {
|
||||||
/*
|
/*
|
||||||
@@ -531,12 +530,12 @@ static void order_color_palette(png_color *palette, int num_colors)
|
|||||||
static void put_raw_image_pixel(struct RawIndexedImage *raw_image,
|
static void put_raw_image_pixel(struct RawIndexedImage *raw_image,
|
||||||
const struct PNGImage *img,
|
const struct PNGImage *img,
|
||||||
int *value_index, int x, int y,
|
int *value_index, int x, int y,
|
||||||
const png_color *palette,
|
png_color const *palette,
|
||||||
int colors_in_palette);
|
int colors_in_palette);
|
||||||
|
|
||||||
static struct RawIndexedImage
|
static struct RawIndexedImage
|
||||||
*processed_rgba_png_to_raw(const struct PNGImage *img,
|
*processed_rgba_png_to_raw(const struct PNGImage *img,
|
||||||
const png_color *palette,
|
png_color const *palette,
|
||||||
int colors_in_palette)
|
int colors_in_palette)
|
||||||
{
|
{
|
||||||
struct RawIndexedImage *raw_image;
|
struct RawIndexedImage *raw_image;
|
||||||
@@ -561,13 +560,13 @@ static struct RawIndexedImage
|
|||||||
return raw_image;
|
return raw_image;
|
||||||
}
|
}
|
||||||
|
|
||||||
static uint8_t palette_index_of(const png_color *palette,
|
static uint8_t palette_index_of(png_color const *palette,
|
||||||
int num_colors, const png_color *color);
|
int num_colors, png_color const *color);
|
||||||
|
|
||||||
static void put_raw_image_pixel(struct RawIndexedImage *raw_image,
|
static void put_raw_image_pixel(struct RawIndexedImage *raw_image,
|
||||||
const struct PNGImage *img,
|
const struct PNGImage *img,
|
||||||
int *value_index, int x, int y,
|
int *value_index, int x, int y,
|
||||||
const png_color *palette,
|
png_color const *palette,
|
||||||
int colors_in_palette)
|
int colors_in_palette)
|
||||||
{
|
{
|
||||||
png_color pixel_color;
|
png_color pixel_color;
|
||||||
@@ -588,8 +587,8 @@ static void put_raw_image_pixel(struct RawIndexedImage *raw_image,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static uint8_t palette_index_of(const png_color *palette,
|
static uint8_t palette_index_of(png_color const *palette,
|
||||||
int num_colors, const png_color *color)
|
int num_colors, png_color const *color)
|
||||||
{
|
{
|
||||||
uint8_t i;
|
uint8_t i;
|
||||||
|
|
||||||
@@ -600,7 +599,7 @@ static uint8_t palette_index_of(const png_color *palette,
|
|||||||
return i;
|
return i;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
errx(1, "The input PNG file contains colors that don't appear in its embedded palette.");
|
errx("The input PNG file contains colors that don't appear in its embedded palette.");
|
||||||
}
|
}
|
||||||
|
|
||||||
static void read_png(struct PNGImage *img)
|
static void read_png(struct PNGImage *img)
|
||||||
@@ -611,12 +610,12 @@ static void read_png(struct PNGImage *img)
|
|||||||
|
|
||||||
img->data = malloc(sizeof(*img->data) * img->height);
|
img->data = malloc(sizeof(*img->data) * img->height);
|
||||||
if (!img->data)
|
if (!img->data)
|
||||||
err(1, "%s: Failed to allocate memory for image data",
|
err("%s: Failed to allocate memory for image data",
|
||||||
__func__);
|
__func__);
|
||||||
for (y = 0; y < img->height; y++) {
|
for (y = 0; y < img->height; y++) {
|
||||||
img->data[y] = malloc(png_get_rowbytes(img->png, img->info));
|
img->data[y] = malloc(png_get_rowbytes(img->png, img->info));
|
||||||
if (!img->data[y])
|
if (!img->data[y])
|
||||||
err(1, "%s: Failed to allocate memory for image data",
|
err("%s: Failed to allocate memory for image data",
|
||||||
__func__);
|
__func__);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -632,7 +631,7 @@ static struct RawIndexedImage *create_raw_image(int width, int height,
|
|||||||
|
|
||||||
raw_image = malloc(sizeof(*raw_image));
|
raw_image = malloc(sizeof(*raw_image));
|
||||||
if (!raw_image)
|
if (!raw_image)
|
||||||
err(1, "%s: Failed to allocate memory for raw image",
|
err("%s: Failed to allocate memory for raw image",
|
||||||
__func__);
|
__func__);
|
||||||
|
|
||||||
raw_image->width = width;
|
raw_image->width = width;
|
||||||
@@ -641,18 +640,18 @@ static struct RawIndexedImage *create_raw_image(int width, int height,
|
|||||||
|
|
||||||
raw_image->palette = malloc(sizeof(*raw_image->palette) * num_colors);
|
raw_image->palette = malloc(sizeof(*raw_image->palette) * num_colors);
|
||||||
if (!raw_image->palette)
|
if (!raw_image->palette)
|
||||||
err(1, "%s: Failed to allocate memory for raw image palette",
|
err("%s: Failed to allocate memory for raw image palette",
|
||||||
__func__);
|
__func__);
|
||||||
|
|
||||||
raw_image->data = malloc(sizeof(*raw_image->data) * height);
|
raw_image->data = malloc(sizeof(*raw_image->data) * height);
|
||||||
if (!raw_image->data)
|
if (!raw_image->data)
|
||||||
err(1, "%s: Failed to allocate memory for raw image data",
|
err("%s: Failed to allocate memory for raw image data",
|
||||||
__func__);
|
__func__);
|
||||||
for (y = 0; y < height; y++) {
|
for (y = 0; y < height; y++) {
|
||||||
raw_image->data[y] = malloc(sizeof(*raw_image->data[y])
|
raw_image->data[y] = malloc(sizeof(*raw_image->data[y])
|
||||||
* width);
|
* width);
|
||||||
if (!raw_image->data[y])
|
if (!raw_image->data[y])
|
||||||
err(1, "%s: Failed to allocate memory for raw image data",
|
err("%s: Failed to allocate memory for raw image data",
|
||||||
__func__);
|
__func__);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -660,12 +659,12 @@ static struct RawIndexedImage *create_raw_image(int width, int height,
|
|||||||
}
|
}
|
||||||
|
|
||||||
static void set_raw_image_palette(struct RawIndexedImage *raw_image,
|
static void set_raw_image_palette(struct RawIndexedImage *raw_image,
|
||||||
const png_color *palette, int num_colors)
|
png_color const *palette, int num_colors)
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
if (num_colors > raw_image->num_colors) {
|
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).",
|
errx("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,
|
raw_image->num_colors >> 1,
|
||||||
num_colors, raw_image->num_colors);
|
num_colors, raw_image->num_colors);
|
||||||
}
|
}
|
||||||
@@ -740,7 +739,7 @@ static void set_text(const struct PNGImage *img,
|
|||||||
|
|
||||||
text = malloc(sizeof(*text));
|
text = malloc(sizeof(*text));
|
||||||
if (!text)
|
if (!text)
|
||||||
err(1, "%s: Failed to allocate memory for PNG text",
|
err("%s: Failed to allocate memory for PNG text",
|
||||||
__func__);
|
__func__);
|
||||||
|
|
||||||
if (png_options->horizontal) {
|
if (png_options->horizontal) {
|
||||||
|
|||||||
@@ -12,8 +12,8 @@
|
|||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <assert.h>
|
#include <assert.h>
|
||||||
|
|
||||||
|
#include "error.h"
|
||||||
#include "hashmap.h"
|
#include "hashmap.h"
|
||||||
#include "extern/err.h"
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* The lower half of the hash is used to index the "master" table,
|
* The lower half of the hash is used to index the "master" table,
|
||||||
@@ -53,7 +53,7 @@ void **hash_AddElement(HashMap map, char const *key, void *element)
|
|||||||
struct HashMapEntry *newEntry = malloc(sizeof(*newEntry));
|
struct HashMapEntry *newEntry = malloc(sizeof(*newEntry));
|
||||||
|
|
||||||
if (!newEntry)
|
if (!newEntry)
|
||||||
err(1, "%s: Failed to allocate new entry", __func__);
|
err("%s: Failed to allocate new entry", __func__);
|
||||||
|
|
||||||
newEntry->hash = hashedKey >> HALF_HASH_NB_BITS;
|
newEntry->hash = hashedKey >> HALF_HASH_NB_BITS;
|
||||||
newEntry->key = key;
|
newEntry->key = key;
|
||||||
|
|||||||
@@ -19,7 +19,7 @@
|
|||||||
#include "link/script.h"
|
#include "link/script.h"
|
||||||
#include "link/output.h"
|
#include "link/output.h"
|
||||||
|
|
||||||
#include "extern/err.h"
|
#include "error.h"
|
||||||
#include "helpers.h"
|
#include "helpers.h"
|
||||||
|
|
||||||
struct MemoryLocation {
|
struct MemoryLocation {
|
||||||
@@ -46,13 +46,13 @@ static void initFreeSpace(void)
|
|||||||
for (enum SectionType type = 0; type < SECTTYPE_INVALID; type++) {
|
for (enum SectionType type = 0; type < SECTTYPE_INVALID; type++) {
|
||||||
memory[type] = malloc(sizeof(*memory[type]) * nbbanks(type));
|
memory[type] = malloc(sizeof(*memory[type]) * nbbanks(type));
|
||||||
if (!memory[type])
|
if (!memory[type])
|
||||||
err(1, "Failed to init free space for region %d", type);
|
err("Failed to init free space for region %d", type);
|
||||||
|
|
||||||
for (uint32_t bank = 0; bank < nbbanks(type); bank++) {
|
for (uint32_t bank = 0; bank < nbbanks(type); bank++) {
|
||||||
memory[type][bank].next =
|
memory[type][bank].next =
|
||||||
malloc(sizeof(*memory[type][0].next));
|
malloc(sizeof(*memory[type][0].next));
|
||||||
if (!memory[type][bank].next)
|
if (!memory[type][bank].next)
|
||||||
err(1, "Failed to init free space for region %d bank %" PRIu32,
|
err("Failed to init free space for region %d bank %" PRIu32,
|
||||||
type, bank);
|
type, bank);
|
||||||
memory[type][bank].next->address = startaddr[type];
|
memory[type][bank].next->address = startaddr[type];
|
||||||
memory[type][bank].next->size = maxsize[type];
|
memory[type][bank].next->size = maxsize[type];
|
||||||
@@ -159,9 +159,28 @@ static bool isLocationSuitable(struct Section const *section,
|
|||||||
static struct FreeSpace *getPlacement(struct Section const *section,
|
static struct FreeSpace *getPlacement(struct Section const *section,
|
||||||
struct MemoryLocation *location)
|
struct MemoryLocation *location)
|
||||||
{
|
{
|
||||||
location->bank = section->isBankFixed
|
static uint16_t curScrambleROM = 1;
|
||||||
? section->bank
|
static uint8_t curScrambleWRAM = 1;
|
||||||
: bankranges[section->type][0];
|
static uint8_t curScrambleSRAM = 1;
|
||||||
|
|
||||||
|
// Determine which bank we should start searching in
|
||||||
|
if (section->isBankFixed) {
|
||||||
|
location->bank = section->bank;
|
||||||
|
} else if (scrambleROMX && section->type == SECTTYPE_ROMX) {
|
||||||
|
location->bank = curScrambleROM++;
|
||||||
|
if (curScrambleROM > scrambleROMX)
|
||||||
|
curScrambleROM = 1;
|
||||||
|
} else if (scrambleWRAMX && section->type == SECTTYPE_WRAMX) {
|
||||||
|
location->bank = curScrambleWRAM++;
|
||||||
|
if (curScrambleWRAM > scrambleWRAMX)
|
||||||
|
curScrambleWRAM = 1;
|
||||||
|
} else if (scrambleSRAM && section->type == SECTTYPE_SRAM) {
|
||||||
|
location->bank = curScrambleSRAM++;
|
||||||
|
if (curScrambleSRAM > scrambleSRAM)
|
||||||
|
curScrambleSRAM = 0;
|
||||||
|
} else {
|
||||||
|
location->bank = bankranges[section->type][0];
|
||||||
|
}
|
||||||
struct FreeSpace *space;
|
struct FreeSpace *space;
|
||||||
|
|
||||||
for (;;) {
|
for (;;) {
|
||||||
@@ -282,7 +301,7 @@ static void placeSection(struct Section *section)
|
|||||||
struct FreeSpace *newSpace = malloc(sizeof(*newSpace));
|
struct FreeSpace *newSpace = malloc(sizeof(*newSpace));
|
||||||
|
|
||||||
if (!newSpace)
|
if (!newSpace)
|
||||||
err(1, "Failed to split new free space");
|
err("Failed to split new free space");
|
||||||
/* Append the new space after the chosen one */
|
/* Append the new space after the chosen one */
|
||||||
newSpace->prev = freeSpace;
|
newSpace->prev = freeSpace;
|
||||||
newSpace->next = freeSpace->next;
|
newSpace->next = freeSpace->next;
|
||||||
@@ -333,16 +352,16 @@ static void placeSection(struct Section *section)
|
|||||||
|
|
||||||
/* If a section failed to go to several places, nothing we can report */
|
/* If a section failed to go to several places, nothing we can report */
|
||||||
if (!section->isBankFixed || !section->isAddressFixed)
|
if (!section->isBankFixed || !section->isAddressFixed)
|
||||||
errx(1, "Unable to place \"%s\" (%s section) %s",
|
errx("Unable to place \"%s\" (%s section) %s",
|
||||||
section->name, typeNames[section->type], where);
|
section->name, typeNames[section->type], where);
|
||||||
/* If the section just can't fit the bank, report that */
|
/* If the section just can't fit the bank, report that */
|
||||||
else if (section->org + section->size > endaddr(section->type) + 1)
|
else if (section->org + section->size > endaddr(section->type) + 1)
|
||||||
errx(1, "Unable to place \"%s\" (%s section) %s: section runs past end of region ($%04" PRIx16 " > $%04" PRIx16 ")",
|
errx("Unable to place \"%s\" (%s section) %s: section runs past end of region ($%04x > $%04x)",
|
||||||
section->name, typeNames[section->type], where,
|
section->name, typeNames[section->type], where,
|
||||||
section->org + section->size, endaddr(section->type) + 1);
|
section->org + section->size, endaddr(section->type) + 1);
|
||||||
/* Otherwise there is overlap with another section */
|
/* Otherwise there is overlap with another section */
|
||||||
else
|
else
|
||||||
errx(1, "Unable to place \"%s\" (%s section) %s: section overlaps with \"%s\"",
|
errx("Unable to place \"%s\" (%s section) %s: section overlaps with \"%s\"",
|
||||||
section->name, typeNames[section->type], where,
|
section->name, typeNames[section->type], where,
|
||||||
out_OverlappingSection(section)->name);
|
out_OverlappingSection(section)->name);
|
||||||
}
|
}
|
||||||
@@ -399,7 +418,7 @@ void assign_AssignSections(void)
|
|||||||
/* Generate linked lists of sections to assign */
|
/* Generate linked lists of sections to assign */
|
||||||
sections = malloc(sizeof(*sections) * nbSectionsToAssign + 1);
|
sections = malloc(sizeof(*sections) * nbSectionsToAssign + 1);
|
||||||
if (!sections)
|
if (!sections)
|
||||||
err(1, "Failed to allocate memory for section assignment");
|
err("Failed to allocate memory for section assignment");
|
||||||
|
|
||||||
initFreeSpace();
|
initFreeSpace();
|
||||||
|
|
||||||
@@ -428,7 +447,7 @@ void assign_AssignSections(void)
|
|||||||
/* Overlaying requires only fully-constrained sections */
|
/* Overlaying requires only fully-constrained sections */
|
||||||
verbosePrint("Assigning other sections...\n");
|
verbosePrint("Assigning other sections...\n");
|
||||||
if (overlayFileName)
|
if (overlayFileName)
|
||||||
errx(1, "All sections must be fixed when using an overlay file; %" PRIu64 " %sn't",
|
errx("All sections must be fixed when using an overlay file; %" PRIu64 " %sn't",
|
||||||
nbSectionsToAssign, nbSectionsToAssign == 1 ? "is" : "are");
|
nbSectionsToAssign, nbSectionsToAssign == 1 ? "is" : "are");
|
||||||
|
|
||||||
/* Assign all remaining sections by decreasing constraint order */
|
/* Assign all remaining sections by decreasing constraint order */
|
||||||
|
|||||||
172
src/link/main.c
172
src/link/main.c
@@ -8,6 +8,7 @@
|
|||||||
|
|
||||||
#include <assert.h>
|
#include <assert.h>
|
||||||
#include <inttypes.h>
|
#include <inttypes.h>
|
||||||
|
#include <limits.h>
|
||||||
#include <stdbool.h>
|
#include <stdbool.h>
|
||||||
#include <stdarg.h>
|
#include <stdarg.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
@@ -24,8 +25,10 @@
|
|||||||
#include "link/patch.h"
|
#include "link/patch.h"
|
||||||
#include "link/output.h"
|
#include "link/output.h"
|
||||||
|
|
||||||
#include "extern/err.h"
|
|
||||||
#include "extern/getopt.h"
|
#include "extern/getopt.h"
|
||||||
|
|
||||||
|
#include "error.h"
|
||||||
|
#include "platform.h"
|
||||||
#include "version.h"
|
#include "version.h"
|
||||||
|
|
||||||
bool isDmgMode; /* -d */
|
bool isDmgMode; /* -d */
|
||||||
@@ -35,6 +38,10 @@ char const *symFileName; /* -n */
|
|||||||
char const *overlayFileName; /* -O */
|
char const *overlayFileName; /* -O */
|
||||||
char const *outputFileName; /* -o */
|
char const *outputFileName; /* -o */
|
||||||
uint8_t padValue; /* -p */
|
uint8_t padValue; /* -p */
|
||||||
|
// Setting these three to 0 disables the functionality
|
||||||
|
uint16_t scrambleROMX = 0; /* -S */
|
||||||
|
uint8_t scrambleWRAMX = 0;
|
||||||
|
uint8_t scrambleSRAM = 0;
|
||||||
bool is32kMode; /* -t */
|
bool is32kMode; /* -t */
|
||||||
bool beVerbose; /* -v */
|
bool beVerbose; /* -v */
|
||||||
bool isWRA0Mode; /* -w */
|
bool isWRA0Mode; /* -w */
|
||||||
@@ -100,11 +107,25 @@ void error(struct FileStackNode const *where, uint32_t lineNo, char const *fmt,
|
|||||||
nbErrors++;
|
nbErrors++;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void argErr(char flag, char const *fmt, ...)
|
||||||
|
{
|
||||||
|
va_list ap;
|
||||||
|
|
||||||
|
fprintf(stderr, "error: Invalid argument for option '%c': ", flag);
|
||||||
|
va_start(ap, fmt);
|
||||||
|
vfprintf(stderr, fmt, ap);
|
||||||
|
va_end(ap);
|
||||||
|
putc('\n', stderr);
|
||||||
|
|
||||||
|
if (nbErrors != UINT32_MAX)
|
||||||
|
nbErrors++;
|
||||||
|
}
|
||||||
|
|
||||||
_Noreturn void fatal(struct FileStackNode const *where, uint32_t lineNo, char const *fmt, ...)
|
_Noreturn void fatal(struct FileStackNode const *where, uint32_t lineNo, char const *fmt, ...)
|
||||||
{
|
{
|
||||||
va_list ap;
|
va_list ap;
|
||||||
|
|
||||||
fputs("fatal: ", stderr);
|
fputs("FATAL: ", stderr);
|
||||||
if (where) {
|
if (where) {
|
||||||
dumpFileStack(where);
|
dumpFileStack(where);
|
||||||
fprintf(stderr, "(%" PRIu32 "): ", lineNo);
|
fprintf(stderr, "(%" PRIu32 "): ", lineNo);
|
||||||
@@ -118,7 +139,7 @@ _Noreturn void fatal(struct FileStackNode const *where, uint32_t lineNo, char co
|
|||||||
nbErrors++;
|
nbErrors++;
|
||||||
|
|
||||||
fprintf(stderr, "Linking aborted after %" PRIu32 " error%s\n", nbErrors,
|
fprintf(stderr, "Linking aborted after %" PRIu32 " error%s\n", nbErrors,
|
||||||
nbErrors != 1 ? "s" : "");
|
nbErrors == 1 ? "" : "s");
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -136,13 +157,13 @@ FILE *openFile(char const *fileName, char const *mode)
|
|||||||
file = fdopen(1, mode);
|
file = fdopen(1, mode);
|
||||||
|
|
||||||
if (!file)
|
if (!file)
|
||||||
err(1, "Could not open file \"%s\"", fileName);
|
err("Could not open file \"%s\"", fileName);
|
||||||
|
|
||||||
return file;
|
return file;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Short options */
|
/* Short options */
|
||||||
static char const *optstring = "dl:m:n:O:o:p:s:tVvwx";
|
static const char *optstring = "dl:m:n:O:o:p:S:s:tVvWwx";
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Equivalent long options
|
* Equivalent long options
|
||||||
@@ -162,6 +183,7 @@ static struct option const longopts[] = {
|
|||||||
{ "overlay", required_argument, NULL, 'O' },
|
{ "overlay", required_argument, NULL, 'O' },
|
||||||
{ "output", required_argument, NULL, 'o' },
|
{ "output", required_argument, NULL, 'o' },
|
||||||
{ "pad", required_argument, NULL, 'p' },
|
{ "pad", required_argument, NULL, 'p' },
|
||||||
|
{ "scramble", required_argument, NULL, 'S' },
|
||||||
{ "smart", required_argument, NULL, 's' },
|
{ "smart", required_argument, NULL, 's' },
|
||||||
{ "tiny", no_argument, NULL, 't' },
|
{ "tiny", no_argument, NULL, 't' },
|
||||||
{ "version", no_argument, NULL, 'V' },
|
{ "version", no_argument, NULL, 'V' },
|
||||||
@@ -178,8 +200,8 @@ static void printUsage(void)
|
|||||||
{
|
{
|
||||||
fputs(
|
fputs(
|
||||||
"Usage: rgblink [-dtVvwx] [-l script] [-m map_file] [-n sym_file]\n"
|
"Usage: rgblink [-dtVvwx] [-l script] [-m map_file] [-n sym_file]\n"
|
||||||
" [-O overlay_file] [-o out_file] [-p pad_value] [-s symbol]\n"
|
" [-O overlay_file] [-o out_file] [-p pad_value]\n"
|
||||||
" <file> ...\n"
|
" [-S spec] [-s symbol] <file> ...\n"
|
||||||
"Useful options:\n"
|
"Useful options:\n"
|
||||||
" -l, --linkerscript <path> set the input linker script\n"
|
" -l, --linkerscript <path> set the input linker script\n"
|
||||||
" -m, --map <path> set the output map file\n"
|
" -m, --map <path> set the output map file\n"
|
||||||
@@ -202,6 +224,131 @@ static void cleanup(void)
|
|||||||
obj_Cleanup();
|
obj_Cleanup();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
enum ScrambledRegion {
|
||||||
|
SCRAMBLE_ROMX,
|
||||||
|
SCRAMBLE_SRAM,
|
||||||
|
SCRAMBLE_WRAMX,
|
||||||
|
|
||||||
|
SCRAMBLE_UNK, // Used for errors
|
||||||
|
};
|
||||||
|
|
||||||
|
struct {
|
||||||
|
char const *name;
|
||||||
|
uint16_t max;
|
||||||
|
} scrambleSpecs[SCRAMBLE_UNK] = {
|
||||||
|
[SCRAMBLE_ROMX] = { "romx", 65535 },
|
||||||
|
[SCRAMBLE_SRAM] = { "sram", 255 },
|
||||||
|
[SCRAMBLE_WRAMX] = { "wramx", 7},
|
||||||
|
};
|
||||||
|
|
||||||
|
static void parseScrambleSpec(char const *spec)
|
||||||
|
{
|
||||||
|
// Skip any leading whitespace
|
||||||
|
spec += strspn(spec, " \t");
|
||||||
|
|
||||||
|
// The argument to `-S` should be a comma-separated list of sections followed by an '='
|
||||||
|
// indicating their scramble limit.
|
||||||
|
while (spec) {
|
||||||
|
// Invariant: we should not be pointing at whitespace at this point
|
||||||
|
assert(*spec != ' ' && *spec != '\t');
|
||||||
|
|
||||||
|
// Remember where the region's name begins and ends
|
||||||
|
char const *regionName = spec;
|
||||||
|
size_t regionNameLen = strcspn(spec, "=, \t");
|
||||||
|
// Length of region name string slice for printing, truncated if too long
|
||||||
|
int regionNamePrintLen = regionNameLen > INT_MAX ? INT_MAX : (int)regionNameLen;
|
||||||
|
|
||||||
|
// If this trips, `spec` must be pointing at a ',' or '=' (or NUL) due to the assert
|
||||||
|
if (regionNameLen == 0) {
|
||||||
|
argErr('S', "Missing region name");
|
||||||
|
|
||||||
|
if (*spec == '\0')
|
||||||
|
break;
|
||||||
|
if (*spec == '=') // Skip the limit, too
|
||||||
|
spec = strchr(&spec[1], ','); // Skip to next comma, if any
|
||||||
|
goto next;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Find the next non-blank char after the region name's end
|
||||||
|
spec += regionNameLen + strspn(&spec[regionNameLen], " \t");
|
||||||
|
if (*spec != '\0' && *spec != ',' && *spec != '=') {
|
||||||
|
argErr('S', "Unexpected '%c' after region name \"%.*s\"",
|
||||||
|
regionNamePrintLen, regionName);
|
||||||
|
// Skip to next ',' or '=' (or NUL) and keep parsing
|
||||||
|
spec += 1 + strcspn(&spec[1], ",=");
|
||||||
|
}
|
||||||
|
|
||||||
|
// Now, determine which region type this is
|
||||||
|
enum ScrambledRegion region = 0;
|
||||||
|
|
||||||
|
for (; region < SCRAMBLE_UNK; region++) {
|
||||||
|
// If the strings match (case-insensitively), we got it!
|
||||||
|
// `strncasecmp` must be used here since `regionName` points
|
||||||
|
// to the entire remaining argument.
|
||||||
|
if (!strncasecmp(scrambleSpecs[region].name, regionName, regionNameLen))
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (region == SCRAMBLE_UNK)
|
||||||
|
argErr('S', "Unknown region \"%.*s\"", regionNamePrintLen, regionName);
|
||||||
|
|
||||||
|
if (*spec == '=') {
|
||||||
|
spec++; // `strtoul` will skip the whitespace on its own
|
||||||
|
unsigned long limit;
|
||||||
|
char *endptr;
|
||||||
|
|
||||||
|
if (*spec == '\0' || *spec == ',') {
|
||||||
|
argErr('S', "Empty limit for region \"%.*s\"",
|
||||||
|
regionNamePrintLen, regionName);
|
||||||
|
goto next;
|
||||||
|
}
|
||||||
|
limit = strtoul(spec, &endptr, 10);
|
||||||
|
endptr += strspn(endptr, " \t");
|
||||||
|
if (*endptr != '\0' && *endptr != ',') {
|
||||||
|
argErr('S', "Invalid non-numeric limit for region \"%.*s\"",
|
||||||
|
regionNamePrintLen, regionName);
|
||||||
|
endptr = strchr(endptr, ',');
|
||||||
|
}
|
||||||
|
spec = endptr;
|
||||||
|
|
||||||
|
if (region != SCRAMBLE_UNK && limit >= scrambleSpecs[region].max) {
|
||||||
|
argErr('S', "Limit for region \"%.*s\" may not exceed %" PRIu16,
|
||||||
|
regionNamePrintLen, regionName, scrambleSpecs[region].max);
|
||||||
|
limit = scrambleSpecs[region].max;
|
||||||
|
}
|
||||||
|
|
||||||
|
switch (region) {
|
||||||
|
case SCRAMBLE_ROMX:
|
||||||
|
scrambleROMX = limit;
|
||||||
|
break;
|
||||||
|
case SCRAMBLE_SRAM:
|
||||||
|
scrambleSRAM = limit;
|
||||||
|
break;
|
||||||
|
case SCRAMBLE_WRAMX:
|
||||||
|
scrambleWRAMX = limit;
|
||||||
|
break;
|
||||||
|
case SCRAMBLE_UNK: // The error has already been reported, do nothing
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
} else if (region == SCRAMBLE_WRAMX) {
|
||||||
|
// Only WRAMX can be implied, since ROMX and SRAM size may vary
|
||||||
|
scrambleWRAMX = 7;
|
||||||
|
} else {
|
||||||
|
argErr('S', "Cannot imply limit for region \"%.*s\"",
|
||||||
|
regionNamePrintLen, regionName);
|
||||||
|
}
|
||||||
|
|
||||||
|
next:
|
||||||
|
if (spec) {
|
||||||
|
assert(*spec == ',' || *spec == '\0');
|
||||||
|
if (*spec == ',')
|
||||||
|
spec += 1 + strspn(&spec[1], " \t");
|
||||||
|
if (*spec == '\0')
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
int main(int argc, char *argv[])
|
int main(int argc, char *argv[])
|
||||||
{
|
{
|
||||||
int optionChar;
|
int optionChar;
|
||||||
@@ -234,15 +381,18 @@ int main(int argc, char *argv[])
|
|||||||
case 'p':
|
case 'p':
|
||||||
value = strtoul(musl_optarg, &endptr, 0);
|
value = strtoul(musl_optarg, &endptr, 0);
|
||||||
if (musl_optarg[0] == '\0' || *endptr != '\0') {
|
if (musl_optarg[0] == '\0' || *endptr != '\0') {
|
||||||
error(NULL, 0, "Invalid argument for option 'p'");
|
argErr('p', "");
|
||||||
value = 0xFF;
|
value = 0xFF;
|
||||||
}
|
}
|
||||||
if (value > 0xFF) {
|
if (value > 0xFF) {
|
||||||
error(NULL, 0, "Argument for 'p' must be a byte (between 0 and 0xFF)");
|
argErr('p', "Argument for 'p' must be a byte (between 0 and 0xFF)");
|
||||||
value = 0xFF;
|
value = 0xFF;
|
||||||
}
|
}
|
||||||
padValue = value;
|
padValue = value;
|
||||||
break;
|
break;
|
||||||
|
case 'S':
|
||||||
|
parseScrambleSpec(musl_optarg);
|
||||||
|
break;
|
||||||
case 's':
|
case 's':
|
||||||
/* FIXME: nobody knows what this does, figure it out */
|
/* FIXME: nobody knows what this does, figure it out */
|
||||||
(void)musl_optarg;
|
(void)musl_optarg;
|
||||||
@@ -275,7 +425,7 @@ int main(int argc, char *argv[])
|
|||||||
|
|
||||||
/* If no input files were specified, the user must have screwed up */
|
/* If no input files were specified, the user must have screwed up */
|
||||||
if (curArgIndex == argc) {
|
if (curArgIndex == argc) {
|
||||||
fputs("fatal: no input files\n", stderr);
|
fputs("FATAL: no input files\n", stderr);
|
||||||
printUsage();
|
printUsage();
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
@@ -304,7 +454,7 @@ int main(int argc, char *argv[])
|
|||||||
patch_ApplyPatches();
|
patch_ApplyPatches();
|
||||||
if (nbErrors) {
|
if (nbErrors) {
|
||||||
fprintf(stderr, "Linking failed with %" PRIu32 " error%s\n",
|
fprintf(stderr, "Linking failed with %" PRIu32 " error%s\n",
|
||||||
nbErrors, nbErrors != 1 ? "s" : "");
|
nbErrors, nbErrors == 1 ? "" : "s");
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
out_WriteFiles();
|
out_WriteFiles();
|
||||||
|
|||||||
@@ -21,7 +21,7 @@
|
|||||||
#include "link/section.h"
|
#include "link/section.h"
|
||||||
#include "link/symbol.h"
|
#include "link/symbol.h"
|
||||||
|
|
||||||
#include "extern/err.h"
|
#include "error.h"
|
||||||
#include "helpers.h"
|
#include "helpers.h"
|
||||||
#include "linkdefs.h"
|
#include "linkdefs.h"
|
||||||
|
|
||||||
@@ -48,8 +48,9 @@ static struct Assertion *assertions;
|
|||||||
do { \
|
do { \
|
||||||
FILE *tmpFile = file; \
|
FILE *tmpFile = file; \
|
||||||
type tmpVal = func(tmpFile); \
|
type tmpVal = func(tmpFile); \
|
||||||
|
/* TODO: maybe mark the condition as `unlikely`; how to do that portably? */ \
|
||||||
if (tmpVal == (errval)) { \
|
if (tmpVal == (errval)) { \
|
||||||
errx(1, __VA_ARGS__, feof(tmpFile) \
|
errx(__VA_ARGS__, feof(tmpFile) \
|
||||||
? "Unexpected end of file" \
|
? "Unexpected end of file" \
|
||||||
: strerror(errno)); \
|
: strerror(errno)); \
|
||||||
} \
|
} \
|
||||||
@@ -86,7 +87,6 @@ static int64_t readlong(FILE *file)
|
|||||||
/**
|
/**
|
||||||
* Helper macro for reading longs from a file, and errors out if it fails to.
|
* Helper macro for reading longs from a file, and errors out if it fails to.
|
||||||
* Not as a function to avoid overhead in the general case.
|
* Not as a function to avoid overhead in the general case.
|
||||||
* TODO: maybe mark the condition as `unlikely`; how to do that portably?
|
|
||||||
* @param var The variable to stash the number into
|
* @param var The variable to stash the number into
|
||||||
* @param file The file to read from. Its position will be advanced
|
* @param file The file to read from. Its position will be advanced
|
||||||
* @param ... A format string and related arguments; note that an extra string
|
* @param ... A format string and related arguments; note that an extra string
|
||||||
@@ -101,7 +101,6 @@ static int64_t readlong(FILE *file)
|
|||||||
* Helper macro for reading bytes from a file, and errors out if it fails to.
|
* Helper macro for reading bytes from a file, and errors out if it fails to.
|
||||||
* Differs from `tryGetc` in that the backing function is fgetc(1).
|
* Differs from `tryGetc` in that the backing function is fgetc(1).
|
||||||
* Not as a function to avoid overhead in the general case.
|
* Not as a function to avoid overhead in the general case.
|
||||||
* TODO: maybe mark the condition as `unlikely`; how to do that portably?
|
|
||||||
* @param var The variable to stash the number into
|
* @param var The variable to stash the number into
|
||||||
* @param file The file to read from. Its position will be advanced
|
* @param file The file to read from. Its position will be advanced
|
||||||
* @param ... A format string and related arguments; note that an extra string
|
* @param ... A format string and related arguments; note that an extra string
|
||||||
@@ -114,7 +113,6 @@ static int64_t readlong(FILE *file)
|
|||||||
* Helper macro for reading bytes from a file, and errors out if it fails to.
|
* Helper macro for reading bytes from a file, and errors out if it fails to.
|
||||||
* Differs from `tryGetc` in that the backing function is fgetc(1).
|
* Differs from `tryGetc` in that the backing function is fgetc(1).
|
||||||
* Not as a function to avoid overhead in the general case.
|
* Not as a function to avoid overhead in the general case.
|
||||||
* TODO: maybe mark the condition as `unlikely`; how to do that portably?
|
|
||||||
* @param var The variable to stash the number into
|
* @param var The variable to stash the number into
|
||||||
* @param file The file to read from. Its position will be advanced
|
* @param file The file to read from. Its position will be advanced
|
||||||
* @param ... A format string and related arguments; note that an extra string
|
* @param ... A format string and related arguments; note that an extra string
|
||||||
@@ -163,7 +161,6 @@ static char *readstr(FILE *file)
|
|||||||
/**
|
/**
|
||||||
* Helper macro for reading bytes from a file, and errors out if it fails to.
|
* Helper macro for reading bytes from a file, and errors out if it fails to.
|
||||||
* Not as a function to avoid overhead in the general case.
|
* Not as a function to avoid overhead in the general case.
|
||||||
* TODO: maybe mark the condition as `unlikely`; how to do that portably?
|
|
||||||
* @param var The variable to stash the string into
|
* @param var The variable to stash the string into
|
||||||
* @param file The file to read from. Its position will be advanced
|
* @param file The file to read from. Its position will be advanced
|
||||||
* @param ... A format string and related arguments; note that an extra string
|
* @param ... A format string and related arguments; note that an extra string
|
||||||
@@ -292,13 +289,13 @@ static void readPatch(FILE *file, struct Patch *patch, char const *fileName, cha
|
|||||||
|
|
||||||
patch->rpnExpression = malloc(sizeof(*patch->rpnExpression) * patch->rpnSize);
|
patch->rpnExpression = malloc(sizeof(*patch->rpnExpression) * patch->rpnSize);
|
||||||
if (!patch->rpnExpression)
|
if (!patch->rpnExpression)
|
||||||
err(1, "%s: Failed to alloc \"%s\"'s patch #%" PRIu32 "'s RPN expression",
|
err("%s: Failed to alloc \"%s\"'s patch #%" PRIu32 "'s RPN expression",
|
||||||
fileName, sectName, i);
|
fileName, sectName, i);
|
||||||
size_t nbElementsRead = fread(patch->rpnExpression, sizeof(*patch->rpnExpression),
|
size_t nbElementsRead = fread(patch->rpnExpression, sizeof(*patch->rpnExpression),
|
||||||
patch->rpnSize, file);
|
patch->rpnSize, file);
|
||||||
|
|
||||||
if (nbElementsRead != patch->rpnSize)
|
if (nbElementsRead != patch->rpnSize)
|
||||||
errx(1, "%s: Cannot read \"%s\"'s patch #%" PRIu32 "'s RPN expression: %s",
|
errx("%s: Cannot read \"%s\"'s patch #%" PRIu32 "'s RPN expression: %s",
|
||||||
fileName, sectName, i,
|
fileName, sectName, i,
|
||||||
feof(file) ? "Unexpected end of file" : strerror(errno));
|
feof(file) ? "Unexpected end of file" : strerror(errno));
|
||||||
}
|
}
|
||||||
@@ -330,7 +327,7 @@ static void readSection(FILE *file, struct Section *section, char const *fileNam
|
|||||||
tryReadlong(tmp, file, "%s: Cannot read \"%s\"'s' size: %s",
|
tryReadlong(tmp, file, "%s: Cannot read \"%s\"'s' size: %s",
|
||||||
fileName, section->name);
|
fileName, section->name);
|
||||||
if (tmp < 0 || tmp > UINT16_MAX)
|
if (tmp < 0 || tmp > UINT16_MAX)
|
||||||
errx(1, "\"%s\"'s section size (%" PRId32 ") is invalid",
|
errx("\"%s\"'s section size (%" PRId32 ") is invalid",
|
||||||
section->name, tmp);
|
section->name, tmp);
|
||||||
section->size = tmp;
|
section->size = tmp;
|
||||||
section->offset = 0;
|
section->offset = 0;
|
||||||
@@ -376,13 +373,13 @@ static void readSection(FILE *file, struct Section *section, char const *fileNam
|
|||||||
uint8_t *data = malloc(sizeof(*data) * section->size + 1);
|
uint8_t *data = malloc(sizeof(*data) * section->size + 1);
|
||||||
|
|
||||||
if (!data)
|
if (!data)
|
||||||
err(1, "%s: Unable to read \"%s\"'s data", fileName,
|
err("%s: Unable to read \"%s\"'s data", fileName,
|
||||||
section->name);
|
section->name);
|
||||||
if (section->size) {
|
if (section->size) {
|
||||||
size_t nbElementsRead = fread(data, sizeof(*data),
|
size_t nbElementsRead = fread(data, sizeof(*data),
|
||||||
section->size, file);
|
section->size, file);
|
||||||
if (nbElementsRead != section->size)
|
if (nbElementsRead != section->size)
|
||||||
errx(1, "%s: Cannot read \"%s\"'s data: %s",
|
errx("%s: Cannot read \"%s\"'s data: %s",
|
||||||
fileName, section->name,
|
fileName, section->name,
|
||||||
feof(file) ? "Unexpected end of file"
|
feof(file) ? "Unexpected end of file"
|
||||||
: strerror(errno));
|
: strerror(errno));
|
||||||
@@ -397,7 +394,7 @@ static void readSection(FILE *file, struct Section *section, char const *fileNam
|
|||||||
malloc(sizeof(*patches) * section->nbPatches + 1);
|
malloc(sizeof(*patches) * section->nbPatches + 1);
|
||||||
|
|
||||||
if (!patches)
|
if (!patches)
|
||||||
err(1, "%s: Unable to read \"%s\"'s patches", fileName, section->name);
|
err("%s: Unable to read \"%s\"'s patches", fileName, section->name);
|
||||||
for (uint32_t i = 0; i < section->nbPatches; i++)
|
for (uint32_t i = 0; i < section->nbPatches; i++)
|
||||||
readPatch(file, &patches[i], fileName, section->name, i, fileNodes);
|
readPatch(file, &patches[i], fileName, section->name, i, fileNodes);
|
||||||
section->patches = patches;
|
section->patches = patches;
|
||||||
@@ -465,7 +462,7 @@ void obj_ReadFile(char const *fileName, unsigned int fileID)
|
|||||||
FILE *file = strcmp("-", fileName) ? fopen(fileName, "rb") : stdin;
|
FILE *file = strcmp("-", fileName) ? fopen(fileName, "rb") : stdin;
|
||||||
|
|
||||||
if (!file)
|
if (!file)
|
||||||
err(1, "Could not open file %s", fileName);
|
err("Could not open file %s", fileName);
|
||||||
|
|
||||||
/* Begin by reading the magic bytes and version number */
|
/* Begin by reading the magic bytes and version number */
|
||||||
unsigned versionNumber;
|
unsigned versionNumber;
|
||||||
@@ -473,13 +470,13 @@ void obj_ReadFile(char const *fileName, unsigned int fileID)
|
|||||||
&versionNumber);
|
&versionNumber);
|
||||||
|
|
||||||
if (matchedElems != 1)
|
if (matchedElems != 1)
|
||||||
errx(1, "\"%s\" is not a RGBDS object file", fileName);
|
errx("\"%s\" is not a RGBDS object file", fileName);
|
||||||
|
|
||||||
verbosePrint("Reading object file %s, version %u\n",
|
verbosePrint("Reading object file %s, version %u\n",
|
||||||
fileName, versionNumber);
|
fileName, versionNumber);
|
||||||
|
|
||||||
if (versionNumber != RGBDS_OBJECT_VERSION_NUMBER)
|
if (versionNumber != RGBDS_OBJECT_VERSION_NUMBER)
|
||||||
errx(1, "\"%s\" is an incompatible version %u object file",
|
errx("\"%s\" is an incompatible version %u object file",
|
||||||
fileName, versionNumber);
|
fileName, versionNumber);
|
||||||
|
|
||||||
uint32_t revNum;
|
uint32_t revNum;
|
||||||
@@ -487,7 +484,7 @@ void obj_ReadFile(char const *fileName, unsigned int fileID)
|
|||||||
tryReadlong(revNum, file, "%s: Cannot read revision number: %s",
|
tryReadlong(revNum, file, "%s: Cannot read revision number: %s",
|
||||||
fileName);
|
fileName);
|
||||||
if (revNum != RGBDS_OBJECT_REV)
|
if (revNum != RGBDS_OBJECT_REV)
|
||||||
errx(1, "%s is a revision 0x%04" PRIx32 " object file; only 0x%04x is supported",
|
errx("%s is a revision 0x%04" PRIx32 " object file; only 0x%04x is supported",
|
||||||
fileName, revNum, RGBDS_OBJECT_REV);
|
fileName, revNum, RGBDS_OBJECT_REV);
|
||||||
|
|
||||||
uint32_t nbSymbols;
|
uint32_t nbSymbols;
|
||||||
@@ -503,7 +500,7 @@ void obj_ReadFile(char const *fileName, unsigned int fileID)
|
|||||||
tryReadlong(nodes[fileID].nbNodes, file, "%s: Cannot read number of nodes: %s", fileName);
|
tryReadlong(nodes[fileID].nbNodes, file, "%s: Cannot read number of nodes: %s", fileName);
|
||||||
nodes[fileID].nodes = calloc(nodes[fileID].nbNodes, sizeof(nodes[fileID].nodes[0]));
|
nodes[fileID].nodes = calloc(nodes[fileID].nbNodes, sizeof(nodes[fileID].nodes[0]));
|
||||||
if (!nodes[fileID].nodes)
|
if (!nodes[fileID].nodes)
|
||||||
err(1, "Failed to get memory for %s's nodes", fileName);
|
err("Failed to get memory for %s's nodes", fileName);
|
||||||
verbosePrint("Reading %u nodes...\n", nodes[fileID].nbNodes);
|
verbosePrint("Reading %u nodes...\n", nodes[fileID].nbNodes);
|
||||||
for (uint32_t i = nodes[fileID].nbNodes; i--; )
|
for (uint32_t i = nodes[fileID].nbNodes; i--; )
|
||||||
readFileStackNode(file, nodes[fileID].nodes, i, fileName);
|
readFileStackNode(file, nodes[fileID].nodes, i, fileName);
|
||||||
@@ -513,12 +510,12 @@ void obj_ReadFile(char const *fileName, unsigned int fileID)
|
|||||||
malloc(sizeof(*fileSymbols) * nbSymbols + 1);
|
malloc(sizeof(*fileSymbols) * nbSymbols + 1);
|
||||||
|
|
||||||
if (!fileSymbols)
|
if (!fileSymbols)
|
||||||
err(1, "Failed to get memory for %s's symbols", fileName);
|
err("Failed to get memory for %s's symbols", fileName);
|
||||||
|
|
||||||
struct SymbolList *symbolList = malloc(sizeof(*symbolList));
|
struct SymbolList *symbolList = malloc(sizeof(*symbolList));
|
||||||
|
|
||||||
if (!symbolList)
|
if (!symbolList)
|
||||||
err(1, "Failed to register %s's symbol list", fileName);
|
err("Failed to register %s's symbol list", fileName);
|
||||||
symbolList->symbolList = fileSymbols;
|
symbolList->symbolList = fileSymbols;
|
||||||
symbolList->nbSymbols = nbSymbols;
|
symbolList->nbSymbols = nbSymbols;
|
||||||
symbolList->next = symbolLists;
|
symbolList->next = symbolLists;
|
||||||
@@ -533,7 +530,7 @@ void obj_ReadFile(char const *fileName, unsigned int fileID)
|
|||||||
struct Symbol *symbol = malloc(sizeof(*symbol));
|
struct Symbol *symbol = malloc(sizeof(*symbol));
|
||||||
|
|
||||||
if (!symbol)
|
if (!symbol)
|
||||||
err(1, "%s: Couldn't create new symbol", fileName);
|
err("%s: Couldn't create new symbol", fileName);
|
||||||
readSymbol(file, symbol, fileName, nodes[fileID].nodes);
|
readSymbol(file, symbol, fileName, nodes[fileID].nodes);
|
||||||
|
|
||||||
fileSymbols[i] = symbol;
|
fileSymbols[i] = symbol;
|
||||||
@@ -552,7 +549,7 @@ void obj_ReadFile(char const *fileName, unsigned int fileID)
|
|||||||
/* Read section */
|
/* Read section */
|
||||||
fileSections[i] = malloc(sizeof(*fileSections[i]));
|
fileSections[i] = malloc(sizeof(*fileSections[i]));
|
||||||
if (!fileSections[i])
|
if (!fileSections[i])
|
||||||
err(1, "%s: Couldn't create new section", fileName);
|
err("%s: Couldn't create new section", fileName);
|
||||||
|
|
||||||
fileSections[i]->nextu = NULL;
|
fileSections[i]->nextu = NULL;
|
||||||
readSection(file, fileSections[i], fileName, nodes[fileID].nodes);
|
readSection(file, fileSections[i], fileName, nodes[fileID].nodes);
|
||||||
@@ -561,7 +558,7 @@ void obj_ReadFile(char const *fileName, unsigned int fileID)
|
|||||||
fileSections[i]->symbols = malloc(nbSymPerSect[i]
|
fileSections[i]->symbols = malloc(nbSymPerSect[i]
|
||||||
* sizeof(*fileSections[i]->symbols));
|
* sizeof(*fileSections[i]->symbols));
|
||||||
if (!fileSections[i]->symbols)
|
if (!fileSections[i]->symbols)
|
||||||
err(1, "%s: Couldn't link to symbols",
|
err("%s: Couldn't link to symbols",
|
||||||
fileName);
|
fileName);
|
||||||
} else {
|
} else {
|
||||||
fileSections[i]->symbols = NULL;
|
fileSections[i]->symbols = NULL;
|
||||||
@@ -612,7 +609,7 @@ void obj_ReadFile(char const *fileName, unsigned int fileID)
|
|||||||
struct Assertion *assertion = malloc(sizeof(*assertion));
|
struct Assertion *assertion = malloc(sizeof(*assertion));
|
||||||
|
|
||||||
if (!assertion)
|
if (!assertion)
|
||||||
err(1, "%s: Couldn't create new assertion", fileName);
|
err("%s: Couldn't create new assertion", fileName);
|
||||||
readAssertion(file, assertion, fileName, i, nodes[fileID].nodes);
|
readAssertion(file, assertion, fileName, i, nodes[fileID].nodes);
|
||||||
linkPatchToPCSect(&assertion->patch, fileSections);
|
linkPatchToPCSect(&assertion->patch, fileSections);
|
||||||
assertion->fileSymbols = fileSymbols;
|
assertion->fileSymbols = fileSymbols;
|
||||||
@@ -643,10 +640,21 @@ void obj_Setup(unsigned int nbFiles)
|
|||||||
nodes = malloc(sizeof(*nodes) * nbFiles);
|
nodes = malloc(sizeof(*nodes) * nbFiles);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void freeNode(struct FileStackNode *node)
|
||||||
|
{
|
||||||
|
if (node->type == NODE_REPT)
|
||||||
|
free(node->iters);
|
||||||
|
else
|
||||||
|
free(node->name);
|
||||||
|
}
|
||||||
|
|
||||||
static void freeSection(struct Section *section, void *arg)
|
static void freeSection(struct Section *section, void *arg)
|
||||||
{
|
{
|
||||||
(void)arg;
|
(void)arg;
|
||||||
|
|
||||||
|
do {
|
||||||
|
struct Section *next = section->nextu;
|
||||||
|
|
||||||
free(section->name);
|
free(section->name);
|
||||||
if (sect_HasData(section->type)) {
|
if (sect_HasData(section->type)) {
|
||||||
free(section->data);
|
free(section->data);
|
||||||
@@ -656,6 +664,9 @@ static void freeSection(struct Section *section, void *arg)
|
|||||||
}
|
}
|
||||||
free(section->symbols);
|
free(section->symbols);
|
||||||
free(section);
|
free(section);
|
||||||
|
|
||||||
|
section = next;
|
||||||
|
} while (section);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void freeSymbol(struct Symbol *symbol)
|
static void freeSymbol(struct Symbol *symbol)
|
||||||
@@ -668,8 +679,7 @@ void obj_Cleanup(void)
|
|||||||
{
|
{
|
||||||
for (unsigned int i = 0; i < nbObjFiles; i++) {
|
for (unsigned int i = 0; i < nbObjFiles; i++) {
|
||||||
for (uint32_t j = 0; j < nodes[i].nbNodes; j++) {
|
for (uint32_t j = 0; j < nodes[i].nbNodes; j++) {
|
||||||
if (nodes[i].nodes[j].type == NODE_REPT)
|
freeNode(&nodes[i].nodes[j]);
|
||||||
free(nodes[i].nodes[j].iters);
|
|
||||||
}
|
}
|
||||||
free(nodes[i].nodes);
|
free(nodes[i].nodes);
|
||||||
}
|
}
|
||||||
@@ -680,16 +690,12 @@ void obj_Cleanup(void)
|
|||||||
sect_ForEach(freeSection, NULL);
|
sect_ForEach(freeSection, NULL);
|
||||||
sect_CleanupSections();
|
sect_CleanupSections();
|
||||||
|
|
||||||
struct SymbolList *list = symbolLists;
|
for (struct SymbolList *list = symbolLists, *next; list; list = next) {
|
||||||
|
next = list->next;
|
||||||
|
|
||||||
while (list) {
|
|
||||||
for (size_t i = 0; i < list->nbSymbols; i++)
|
for (size_t i = 0; i < list->nbSymbols; i++)
|
||||||
freeSymbol(list->symbolList[i]);
|
freeSymbol(list->symbolList[i]);
|
||||||
free(list->symbolList);
|
free(list->symbolList);
|
||||||
|
|
||||||
struct SymbolList *next = list->next;
|
|
||||||
|
|
||||||
free(list);
|
free(list);
|
||||||
list = next;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,6 +6,7 @@
|
|||||||
* SPDX-License-Identifier: MIT
|
* SPDX-License-Identifier: MIT
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#include <assert.h>
|
||||||
#include <inttypes.h>
|
#include <inttypes.h>
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
@@ -15,10 +16,8 @@
|
|||||||
#include "link/section.h"
|
#include "link/section.h"
|
||||||
#include "link/symbol.h"
|
#include "link/symbol.h"
|
||||||
|
|
||||||
#include "extern/err.h"
|
#include "error.h"
|
||||||
|
|
||||||
#include "linkdefs.h"
|
#include "linkdefs.h"
|
||||||
|
|
||||||
#include "platform.h" // MIN_NB_ELMS
|
#include "platform.h" // MIN_NB_ELMS
|
||||||
|
|
||||||
#define BANK_SIZE 0x4000
|
#define BANK_SIZE 0x4000
|
||||||
@@ -33,6 +32,12 @@ struct SortedSection {
|
|||||||
struct SortedSection *next;
|
struct SortedSection *next;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
struct SortedSymbol {
|
||||||
|
struct Symbol const *sym;
|
||||||
|
uint32_t idx;
|
||||||
|
uint16_t addr;
|
||||||
|
};
|
||||||
|
|
||||||
static struct {
|
static struct {
|
||||||
uint32_t nbBanks;
|
uint32_t nbBanks;
|
||||||
struct SortedSections {
|
struct SortedSections {
|
||||||
@@ -70,7 +75,7 @@ void out_AddSection(struct Section const *section)
|
|||||||
uint32_t minNbBanks = targetBank + 1;
|
uint32_t minNbBanks = targetBank + 1;
|
||||||
|
|
||||||
if (minNbBanks > maxNbBanks[section->type])
|
if (minNbBanks > maxNbBanks[section->type])
|
||||||
errx(1, "Section \"%s\" has an invalid bank range (%" PRIu32 " > %" PRIu32 ")",
|
errx("Section \"%s\" has an invalid bank range (%" PRIu32 " > %" PRIu32 ")",
|
||||||
section->name, section->bank,
|
section->name, section->bank,
|
||||||
maxNbBanks[section->type] - 1);
|
maxNbBanks[section->type] - 1);
|
||||||
|
|
||||||
@@ -85,7 +90,7 @@ void out_AddSection(struct Section const *section)
|
|||||||
sections[section->type].nbBanks = minNbBanks;
|
sections[section->type].nbBanks = minNbBanks;
|
||||||
}
|
}
|
||||||
if (!sections[section->type].banks)
|
if (!sections[section->type].banks)
|
||||||
err(1, "Failed to realloc banks");
|
err("Failed to realloc banks");
|
||||||
|
|
||||||
struct SortedSection *newSection = malloc(sizeof(*newSection));
|
struct SortedSection *newSection = malloc(sizeof(*newSection));
|
||||||
struct SortedSection **ptr = section->size
|
struct SortedSection **ptr = section->size
|
||||||
@@ -93,7 +98,7 @@ void out_AddSection(struct Section const *section)
|
|||||||
: §ions[section->type].banks[targetBank].zeroLenSections;
|
: §ions[section->type].banks[targetBank].zeroLenSections;
|
||||||
|
|
||||||
if (!newSection)
|
if (!newSection)
|
||||||
err(1, "Failed to add new section \"%s\"", section->name);
|
err("Failed to add new section \"%s\"", section->name);
|
||||||
newSection->section = section;
|
newSection->section = section;
|
||||||
|
|
||||||
while (*ptr && (*ptr)->section->org < section->org)
|
while (*ptr && (*ptr)->section->org < section->org)
|
||||||
@@ -138,15 +143,15 @@ static uint32_t checkOverlaySize(void)
|
|||||||
fseek(overlayFile, 0, SEEK_SET);
|
fseek(overlayFile, 0, SEEK_SET);
|
||||||
|
|
||||||
if (overlaySize % BANK_SIZE)
|
if (overlaySize % BANK_SIZE)
|
||||||
errx(1, "Overlay file must have a size multiple of 0x4000");
|
errx("Overlay file must have a size multiple of 0x4000");
|
||||||
|
|
||||||
uint32_t nbOverlayBanks = overlaySize / BANK_SIZE;
|
uint32_t nbOverlayBanks = overlaySize / BANK_SIZE;
|
||||||
|
|
||||||
if (is32kMode && nbOverlayBanks != 2)
|
if (is32kMode && nbOverlayBanks != 2)
|
||||||
errx(1, "Overlay must be exactly 0x8000 bytes large");
|
errx("Overlay must be exactly 0x8000 bytes large");
|
||||||
|
|
||||||
if (nbOverlayBanks < 2)
|
if (nbOverlayBanks < 2)
|
||||||
errx(1, "Overlay must be at least 0x8000 bytes large");
|
errx("Overlay must be at least 0x8000 bytes large");
|
||||||
|
|
||||||
return nbOverlayBanks;
|
return nbOverlayBanks;
|
||||||
}
|
}
|
||||||
@@ -171,7 +176,7 @@ static void coverOverlayBanks(uint32_t nbOverlayBanks)
|
|||||||
realloc(sections[SECTTYPE_ROMX].banks,
|
realloc(sections[SECTTYPE_ROMX].banks,
|
||||||
sizeof(*sections[SECTTYPE_ROMX].banks) * nbUncoveredBanks);
|
sizeof(*sections[SECTTYPE_ROMX].banks) * nbUncoveredBanks);
|
||||||
if (!sections[SECTTYPE_ROMX].banks)
|
if (!sections[SECTTYPE_ROMX].banks)
|
||||||
err(1, "Failed to realloc banks for overlay");
|
err("Failed to realloc banks for overlay");
|
||||||
for (uint32_t i = sections[SECTTYPE_ROMX].nbBanks; i < nbUncoveredBanks; i++) {
|
for (uint32_t i = sections[SECTTYPE_ROMX].nbBanks; i < nbUncoveredBanks; i++) {
|
||||||
sections[SECTTYPE_ROMX].banks[i].sections = NULL;
|
sections[SECTTYPE_ROMX].banks[i].sections = NULL;
|
||||||
sections[SECTTYPE_ROMX].banks[i].zeroLenSections = NULL;
|
sections[SECTTYPE_ROMX].banks[i].zeroLenSections = NULL;
|
||||||
@@ -268,69 +273,86 @@ static struct SortedSection const **nextSection(struct SortedSection const **s1,
|
|||||||
return (*s1)->section->org < (*s2)->section->org ? s1 : s2;
|
return (*s1)->section->org < (*s2)->section->org ? s1 : s2;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Comparator function for `qsort` to sort symbols
|
||||||
|
* Symbols are ordered by address, or else by original index for a stable sort
|
||||||
|
*/
|
||||||
|
static int compareSymbols(void const *a, void const *b)
|
||||||
|
{
|
||||||
|
struct SortedSymbol const *sym1 = (struct SortedSymbol const *)a;
|
||||||
|
struct SortedSymbol const *sym2 = (struct SortedSymbol const *)b;
|
||||||
|
|
||||||
|
if (sym1->addr != sym2->addr)
|
||||||
|
return sym1->addr < sym2->addr ? -1 : 1;
|
||||||
|
|
||||||
|
return sym1->idx < sym2->idx ? -1 : sym1->idx > sym2->idx ? 1 : 0;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Write a bank's contents to the sym file
|
* Write a bank's contents to the sym file
|
||||||
* @param bankSections The bank's sections
|
* @param bankSections The bank's sections
|
||||||
*/
|
*/
|
||||||
static void writeSymBank(struct SortedSections const *bankSections)
|
static void writeSymBank(struct SortedSections const *bankSections,
|
||||||
|
enum SectionType type, uint32_t bank)
|
||||||
{
|
{
|
||||||
if (!symFile)
|
if (!symFile)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
struct {
|
uint32_t nbSymbols = 0;
|
||||||
struct SortedSection const *sections;
|
|
||||||
#define sect sections->section /* Fake member as a shortcut */
|
|
||||||
uint32_t i;
|
|
||||||
struct Symbol const *sym;
|
|
||||||
uint16_t addr;
|
|
||||||
} sectList = { .sections = bankSections->sections, .i = 0 },
|
|
||||||
zlSectList = { .sections = bankSections->zeroLenSections, .i = 0 },
|
|
||||||
*minSectList;
|
|
||||||
|
|
||||||
for (;;) {
|
for (struct SortedSection const *ptr = bankSections->zeroLenSections; ptr; ptr = ptr->next) {
|
||||||
while (sectList.sections
|
for (struct Section const *sect = ptr->section; sect; sect = sect->nextu)
|
||||||
&& sectList.i == sectList.sect->nbSymbols) {
|
nbSymbols += sect->nbSymbols;
|
||||||
sectList.sections = sectList.sections->next;
|
|
||||||
sectList.i = 0;
|
|
||||||
}
|
}
|
||||||
while (zlSectList.sections
|
for (struct SortedSection const *ptr = bankSections->sections; ptr; ptr = ptr->next) {
|
||||||
&& zlSectList.i == zlSectList.sect->nbSymbols) {
|
for (struct Section const *sect = ptr->section; sect; sect = sect->nextu)
|
||||||
zlSectList.sections = zlSectList.sections->next;
|
nbSymbols += sect->nbSymbols;
|
||||||
zlSectList.i = 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!sectList.sections && !zlSectList.sections) {
|
if (!nbSymbols)
|
||||||
break;
|
return;
|
||||||
} else if (sectList.sections && zlSectList.sections) {
|
|
||||||
sectList.sym = sectList.sect->symbols[sectList.i];
|
|
||||||
zlSectList.sym = zlSectList.sect->symbols[zlSectList.i];
|
|
||||||
sectList.addr =
|
|
||||||
sectList.sym->offset + sectList.sect->org;
|
|
||||||
zlSectList.addr =
|
|
||||||
zlSectList.sym->offset + zlSectList.sect->org;
|
|
||||||
|
|
||||||
minSectList = sectList.addr < zlSectList.addr
|
struct SortedSymbol *symList = malloc(sizeof(*symList) * nbSymbols);
|
||||||
? §List
|
|
||||||
: &zlSectList;
|
|
||||||
} else if (sectList.sections) {
|
|
||||||
sectList.sym = sectList.sect->symbols[sectList.i];
|
|
||||||
sectList.addr =
|
|
||||||
sectList.sym->offset + sectList.sect->org;
|
|
||||||
|
|
||||||
minSectList = §List;
|
if (!symList)
|
||||||
} else {
|
err("Failed to allocate symbol list");
|
||||||
zlSectList.sym = zlSectList.sect->symbols[zlSectList.i];
|
|
||||||
zlSectList.addr =
|
|
||||||
zlSectList.sym->offset + zlSectList.sect->org;
|
|
||||||
|
|
||||||
minSectList = &zlSectList;
|
uint32_t idx = 0;
|
||||||
|
|
||||||
|
for (struct SortedSection const *ptr = bankSections->zeroLenSections; ptr; ptr = ptr->next) {
|
||||||
|
for (struct Section const *sect = ptr->section; sect; sect = sect->nextu) {
|
||||||
|
for (uint32_t i = 0; i < sect->nbSymbols; i++) {
|
||||||
|
symList[idx].idx = idx;
|
||||||
|
symList[idx].sym = sect->symbols[i];
|
||||||
|
symList[idx].addr = symList[idx].sym->offset + sect->org;
|
||||||
|
idx++;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
for (struct SortedSection const *ptr = bankSections->sections; ptr; ptr = ptr->next) {
|
||||||
|
for (struct Section const *sect = ptr->section; sect; sect = sect->nextu) {
|
||||||
|
for (uint32_t i = 0; i < sect->nbSymbols; i++) {
|
||||||
|
symList[idx].idx = idx;
|
||||||
|
symList[idx].sym = sect->symbols[i];
|
||||||
|
symList[idx].addr = symList[idx].sym->offset + sect->org;
|
||||||
|
idx++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
assert(idx == nbSymbols);
|
||||||
|
|
||||||
|
qsort(symList, nbSymbols, sizeof(*symList), compareSymbols);
|
||||||
|
|
||||||
|
uint32_t symBank = bank + bankranges[type][0];
|
||||||
|
|
||||||
|
for (uint32_t i = 0; i < nbSymbols; i++) {
|
||||||
|
struct SortedSymbol *sym = &symList[i];
|
||||||
|
|
||||||
fprintf(symFile, "%02" PRIx32 ":%04" PRIx16 " %s\n",
|
fprintf(symFile, "%02" PRIx32 ":%04" PRIx16 " %s\n",
|
||||||
minSectList->sect->bank, minSectList->addr,
|
symBank, sym->addr, sym->sym->name);
|
||||||
minSectList->sym->name);
|
|
||||||
minSectList->i++;
|
|
||||||
}
|
}
|
||||||
#undef sect
|
|
||||||
|
free(symList);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -360,7 +382,8 @@ static uint16_t writeMapBank(struct SortedSections const *sectList,
|
|||||||
used += sect->size;
|
used += sect->size;
|
||||||
|
|
||||||
if (sect->size != 0)
|
if (sect->size != 0)
|
||||||
fprintf(mapFile, " SECTION: $%04" PRIx16 "-$%04" PRIx16 " ($%04" PRIx16 " byte%s) [\"%s\"]\n",
|
fprintf(mapFile, " SECTION: $%04" PRIx16 "-$%04x ($%04" PRIx16
|
||||||
|
" byte%s) [\"%s\"]\n",
|
||||||
sect->org, sect->org + sect->size - 1,
|
sect->org, sect->org + sect->size - 1,
|
||||||
sect->size, sect->size == 1 ? "" : "s",
|
sect->size, sect->size == 1 ? "" : "s",
|
||||||
sect->name);
|
sect->name);
|
||||||
@@ -443,7 +466,7 @@ static void writeSymAndMap(void)
|
|||||||
for (uint32_t bank = 0; bank < sections[type].nbBanks; bank++) {
|
for (uint32_t bank = 0; bank < sections[type].nbBanks; bank++) {
|
||||||
struct SortedSections const *sect = §ions[type].banks[bank];
|
struct SortedSections const *sect = §ions[type].banks[bank];
|
||||||
|
|
||||||
writeSymBank(sect);
|
writeSymBank(sect, type, bank);
|
||||||
usedMap[type] += writeMapBank(sect, type, bank);
|
usedMap[type] += writeMapBank(sect, type, bank);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -17,11 +17,10 @@
|
|||||||
#include "link/section.h"
|
#include "link/section.h"
|
||||||
#include "link/symbol.h"
|
#include "link/symbol.h"
|
||||||
|
|
||||||
|
#include "error.h"
|
||||||
#include "linkdefs.h"
|
#include "linkdefs.h"
|
||||||
#include "opmath.h"
|
#include "opmath.h"
|
||||||
|
|
||||||
#include "extern/err.h"
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* This is an "empty"-type stack. Apart from the actual values, we also remember
|
* This is an "empty"-type stack. Apart from the actual values, we also remember
|
||||||
* whether the value is a placeholder inserted for error recovery. This allows
|
* whether the value is a placeholder inserted for error recovery. This allows
|
||||||
@@ -43,7 +42,7 @@ static void initRPNStack(void)
|
|||||||
stack.values = malloc(sizeof(*stack.values) * stack.capacity);
|
stack.values = malloc(sizeof(*stack.values) * stack.capacity);
|
||||||
stack.errorFlags = malloc(sizeof(*stack.errorFlags) * stack.capacity);
|
stack.errorFlags = malloc(sizeof(*stack.errorFlags) * stack.capacity);
|
||||||
if (!stack.values || !stack.errorFlags)
|
if (!stack.values || !stack.errorFlags)
|
||||||
err(1, "Failed to init RPN stack");
|
err("Failed to init RPN stack");
|
||||||
}
|
}
|
||||||
|
|
||||||
static void clearRPNStack(void)
|
static void clearRPNStack(void)
|
||||||
@@ -57,7 +56,7 @@ static void pushRPN(int32_t value, bool comesFromError)
|
|||||||
static const size_t increase_factor = 2;
|
static const size_t increase_factor = 2;
|
||||||
|
|
||||||
if (stack.capacity > SIZE_MAX / increase_factor)
|
if (stack.capacity > SIZE_MAX / increase_factor)
|
||||||
errx(1, "Overflow in RPN stack resize");
|
errx("Overflow in RPN stack resize");
|
||||||
|
|
||||||
stack.capacity *= increase_factor;
|
stack.capacity *= increase_factor;
|
||||||
stack.values =
|
stack.values =
|
||||||
@@ -70,7 +69,7 @@ static void pushRPN(int32_t value, bool comesFromError)
|
|||||||
* the overflow check above. Hence the stringent check below.
|
* the overflow check above. Hence the stringent check below.
|
||||||
*/
|
*/
|
||||||
if (!stack.values || !stack.errorFlags || !stack.capacity)
|
if (!stack.values || !stack.errorFlags || !stack.capacity)
|
||||||
err(1, "Failed to resize RPN stack");
|
err("Failed to resize RPN stack");
|
||||||
}
|
}
|
||||||
|
|
||||||
stack.values[stack.size] = value;
|
stack.values[stack.size] = value;
|
||||||
@@ -112,7 +111,7 @@ static uint32_t getRPNByte(uint8_t const **expression, int32_t *size,
|
|||||||
static struct Symbol const *getSymbol(struct Symbol const * const *symbolList,
|
static struct Symbol const *getSymbol(struct Symbol const * const *symbolList,
|
||||||
uint32_t index)
|
uint32_t index)
|
||||||
{
|
{
|
||||||
assert(index != -1); /* PC needs to be handled specially, not here */
|
assert(index != (uint32_t)-1); /* PC needs to be handled specially, not here */
|
||||||
struct Symbol const *symbol = symbolList[index];
|
struct Symbol const *symbol = symbolList[index];
|
||||||
|
|
||||||
/* If the symbol is defined elsewhere... */
|
/* If the symbol is defined elsewhere... */
|
||||||
@@ -266,6 +265,10 @@ static int32_t computeRPNExpr(struct Patch const *patch,
|
|||||||
value = popRPN();
|
value = popRPN();
|
||||||
value = op_shift_right(popRPN(), value);
|
value = op_shift_right(popRPN(), value);
|
||||||
break;
|
break;
|
||||||
|
case RPN_USHR:
|
||||||
|
value = popRPN();
|
||||||
|
value = op_shift_right_unsigned(popRPN(), value);
|
||||||
|
break;
|
||||||
|
|
||||||
case RPN_BANK_SYM:
|
case RPN_BANK_SYM:
|
||||||
value = 0;
|
value = 0;
|
||||||
@@ -292,6 +295,11 @@ static int32_t computeRPNExpr(struct Patch const *patch,
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
case RPN_BANK_SECT:
|
case RPN_BANK_SECT:
|
||||||
|
/*
|
||||||
|
* `expression` is not guaranteed to be '\0'-terminated. If it is not,
|
||||||
|
* `getRPNByte` will have a fatal internal error.
|
||||||
|
* In either case, `getRPNByte` will not free `expression`.
|
||||||
|
*/
|
||||||
name = (char const *)expression;
|
name = (char const *)expression;
|
||||||
while (getRPNByte(&expression, &size, patch->src, patch->lineNo))
|
while (getRPNByte(&expression, &size, patch->src, patch->lineNo))
|
||||||
;
|
;
|
||||||
@@ -320,6 +328,44 @@ static int32_t computeRPNExpr(struct Patch const *patch,
|
|||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
case RPN_SIZEOF_SECT:
|
||||||
|
/* This has assumptions commented in the `RPN_BANK_SECT` case above. */
|
||||||
|
name = (char const *)expression;
|
||||||
|
while (getRPNByte(&expression, &size, patch->src, patch->lineNo))
|
||||||
|
;
|
||||||
|
|
||||||
|
sect = sect_GetSection(name);
|
||||||
|
|
||||||
|
if (!sect) {
|
||||||
|
error(patch->src, patch->lineNo,
|
||||||
|
"Requested SIZEOF() of section \"%s\", which was not found",
|
||||||
|
name);
|
||||||
|
isError = true;
|
||||||
|
value = 1;
|
||||||
|
} else {
|
||||||
|
value = sect->size;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
|
case RPN_STARTOF_SECT:
|
||||||
|
/* This has assumptions commented in the `RPN_BANK_SECT` case above. */
|
||||||
|
name = (char const *)expression;
|
||||||
|
while (getRPNByte(&expression, &size, patch->src, patch->lineNo))
|
||||||
|
;
|
||||||
|
|
||||||
|
sect = sect_GetSection(name);
|
||||||
|
|
||||||
|
if (!sect) {
|
||||||
|
error(patch->src, patch->lineNo,
|
||||||
|
"Requested STARTOF() of section \"%s\", which was not found",
|
||||||
|
name);
|
||||||
|
isError = true;
|
||||||
|
value = 1;
|
||||||
|
} else {
|
||||||
|
value = sect->org;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
case RPN_HRAM:
|
case RPN_HRAM:
|
||||||
value = popRPN();
|
value = popRPN();
|
||||||
if (!isError && (value < 0
|
if (!isError && (value < 0
|
||||||
@@ -435,6 +481,8 @@ void patch_CheckAssertions(struct Assertion *assert)
|
|||||||
}
|
}
|
||||||
struct Assertion *next = assert->next;
|
struct Assertion *next = assert->next;
|
||||||
|
|
||||||
|
free(assert->patch.rpnExpression);
|
||||||
|
free(assert->message);
|
||||||
free(assert);
|
free(assert);
|
||||||
assert = next;
|
assert = next;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -20,6 +20,7 @@
|
|||||||
.Op Fl O Ar overlay_file
|
.Op Fl O Ar overlay_file
|
||||||
.Op Fl o Ar out_file
|
.Op Fl o Ar out_file
|
||||||
.Op Fl p Ar pad_value
|
.Op Fl p Ar pad_value
|
||||||
|
.Op Fl S Ar spec
|
||||||
.Op Fl s Ar symbol
|
.Op Fl s Ar symbol
|
||||||
.Ar
|
.Ar
|
||||||
.Sh DESCRIPTION
|
.Sh DESCRIPTION
|
||||||
@@ -89,6 +90,14 @@ Has no effect if
|
|||||||
.Fl O
|
.Fl O
|
||||||
is specified.
|
is specified.
|
||||||
The default is 0.
|
The default is 0.
|
||||||
|
.It Fl S Ar spec , Fl Fl scramble Ar spec
|
||||||
|
Enables a different
|
||||||
|
.Dq scrambling
|
||||||
|
algorithm for placing sections.
|
||||||
|
See
|
||||||
|
.Sx Scrambling algorithm
|
||||||
|
below for an explanation and a description of
|
||||||
|
.Ar spec .
|
||||||
.It Fl s Ar symbol , Fl Fl smart Ar symbol
|
.It Fl s Ar symbol , Fl Fl smart Ar symbol
|
||||||
This option is ignored.
|
This option is ignored.
|
||||||
It was supposed to perform smart linking but fell into disrepair, and so has been removed.
|
It was supposed to perform smart linking but fell into disrepair, and so has been removed.
|
||||||
@@ -113,6 +122,56 @@ When making a ROM, be careful that not using this is not a replacement for
|
|||||||
.Xr rgbfix 1 Ap s Fl p
|
.Xr rgbfix 1 Ap s Fl p
|
||||||
option!
|
option!
|
||||||
.El
|
.El
|
||||||
|
.Ss Scrambling algorithm
|
||||||
|
The default section placement algorithm tries to minimize the number of banks used;
|
||||||
|
.Dq scrambling
|
||||||
|
instead places sections into a given pool of banks, trying to minimize the number of sections sharing a given bank.
|
||||||
|
This is useful to catch broken bank assumptions, such as expecting two different sections to land in the same bank (that is not guaranteed unless both are manually assigned the same bank number).
|
||||||
|
.Pp
|
||||||
|
A scrambling spec is a comma-separated list of region specs.
|
||||||
|
A trailing comma is allowed, as well as whitespace between all specs and their components.
|
||||||
|
Each region spec has the following form:
|
||||||
|
.D1 Ar region Ns Op = Ns Ar size
|
||||||
|
.Ar region
|
||||||
|
must be one of the following (case-insensitive), while
|
||||||
|
.Ar size
|
||||||
|
must be a positive decimal integer between 1 and the corresponding maximum.
|
||||||
|
Certain regions allow omitting the size, in which case it defaults to its max value.
|
||||||
|
.Bl -column "Region name" "Max value" "Size optional"
|
||||||
|
Region name Ta Max size Ta Size optional
|
||||||
|
.Cm romx Ta 65535 Ta \&No
|
||||||
|
.Cm sram Ta 255 Ta \&No
|
||||||
|
.Cm wramx Ta 7 Ta Yes
|
||||||
|
.El
|
||||||
|
.Pp
|
||||||
|
A
|
||||||
|
.Ar size
|
||||||
|
of 0 disables scrambling for that region.
|
||||||
|
.Pp
|
||||||
|
For example,
|
||||||
|
.Ql romx=64,wramx=4
|
||||||
|
will scramble
|
||||||
|
.Ic ROMX
|
||||||
|
sections among ROM banks 1 to 64,
|
||||||
|
.Ic WRAMX
|
||||||
|
sections among RAM banks 1 to 4, and will not scramble
|
||||||
|
.Ic SRAM
|
||||||
|
sections.
|
||||||
|
.Pp
|
||||||
|
Later region specs override earlier ones; for example,
|
||||||
|
.Ql romx=42, Romx=0
|
||||||
|
disables scrambling for
|
||||||
|
.Cm romx .
|
||||||
|
.Pp
|
||||||
|
.Cm wramx
|
||||||
|
scrambling is silently ignored if
|
||||||
|
.Fl w
|
||||||
|
is passed (including if implied by
|
||||||
|
.Fl d ) ,
|
||||||
|
as
|
||||||
|
.Ic WRAMX
|
||||||
|
sections will be treated as
|
||||||
|
.Ic WRAM0 .
|
||||||
.Sh EXAMPLES
|
.Sh EXAMPLES
|
||||||
All you need for a basic ROM is an object file, which can be made into a ROM image like so:
|
All you need for a basic ROM is an object file, which can be made into a ROM image like so:
|
||||||
.Pp
|
.Pp
|
||||||
|
|||||||
@@ -17,9 +17,9 @@
|
|||||||
#include "link/script.h"
|
#include "link/script.h"
|
||||||
#include "link/section.h"
|
#include "link/section.h"
|
||||||
|
|
||||||
#include "extern/err.h"
|
#include "error.h"
|
||||||
|
|
||||||
FILE * linkerScript;
|
FILE *linkerScript;
|
||||||
char *includeFileName;
|
char *includeFileName;
|
||||||
|
|
||||||
static uint32_t lineNo;
|
static uint32_t lineNo;
|
||||||
@@ -36,17 +36,16 @@ static uint32_t fileStackIndex;
|
|||||||
static void pushFile(char *newFileName)
|
static void pushFile(char *newFileName)
|
||||||
{
|
{
|
||||||
if (fileStackIndex == UINT32_MAX)
|
if (fileStackIndex == UINT32_MAX)
|
||||||
errx(1, "%s(%" PRIu32 "): INCLUDE recursion limit reached",
|
errx("%s(%" PRIu32 "): INCLUDE recursion limit reached",
|
||||||
linkerScriptName, lineNo);
|
linkerScriptName, lineNo);
|
||||||
|
|
||||||
if (fileStackIndex == fileStackSize) {
|
if (fileStackIndex == fileStackSize) {
|
||||||
if (!fileStackSize) /* Init file stack */
|
if (!fileStackSize) /* Init file stack */
|
||||||
fileStackSize = 4;
|
fileStackSize = 4;
|
||||||
fileStackSize *= 2;
|
fileStackSize *= 2;
|
||||||
fileStack = realloc(fileStack,
|
fileStack = realloc(fileStack, sizeof(*fileStack) * fileStackSize);
|
||||||
sizeof(*fileStack) * fileStackSize);
|
|
||||||
if (!fileStack)
|
if (!fileStack)
|
||||||
err(1, "%s(%" PRIu32 "): Internal INCLUDE error",
|
err("%s(%" PRIu32 "): Internal INCLUDE error",
|
||||||
linkerScriptName, lineNo);
|
linkerScriptName, lineNo);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -57,7 +56,7 @@ static void pushFile(char *newFileName)
|
|||||||
|
|
||||||
linkerScript = fopen(newFileName, "r");
|
linkerScript = fopen(newFileName, "r");
|
||||||
if (!linkerScript)
|
if (!linkerScript)
|
||||||
err(1, "%s(%" PRIu32 "): Could not open \"%s\"",
|
err("%s(%" PRIu32 "): Could not open \"%s\"",
|
||||||
linkerScriptName, lineNo, newFileName);
|
linkerScriptName, lineNo, newFileName);
|
||||||
lineNo = 1;
|
lineNo = 1;
|
||||||
linkerScriptName = newFileName;
|
linkerScriptName = newFileName;
|
||||||
@@ -173,12 +172,12 @@ static char const * const commands[] = {
|
|||||||
[COMMAND_ALIGN] = "ALIGN"
|
[COMMAND_ALIGN] = "ALIGN"
|
||||||
};
|
};
|
||||||
|
|
||||||
static int readChar(FILE *file)
|
static int nextChar(void)
|
||||||
{
|
{
|
||||||
int curchar = getc(file);
|
int curchar = getc(linkerScript);
|
||||||
|
|
||||||
if (curchar == EOF && ferror(file))
|
if (curchar == EOF && ferror(linkerScript))
|
||||||
err(1, "%s(%" PRIu32 "): Unexpected error in %s",
|
err("%s(%" PRIu32 "): Unexpected error in %s",
|
||||||
linkerScriptName, lineNo, __func__);
|
linkerScriptName, lineNo, __func__);
|
||||||
return curchar;
|
return curchar;
|
||||||
}
|
}
|
||||||
@@ -194,14 +193,14 @@ static struct LinkerScriptToken *nextToken(void)
|
|||||||
|
|
||||||
/* Skip initial whitespace... */
|
/* Skip initial whitespace... */
|
||||||
do
|
do
|
||||||
curchar = readChar(linkerScript);
|
curchar = nextChar();
|
||||||
while (isWhiteSpace(curchar));
|
while (isWhiteSpace(curchar));
|
||||||
|
|
||||||
/* If this is a comment, skip to the end of the line */
|
/* If this is a comment, skip to the end of the line */
|
||||||
if (curchar == ';') {
|
if (curchar == ';') {
|
||||||
do
|
do {
|
||||||
curchar = readChar(linkerScript);
|
curchar = nextChar();
|
||||||
while (!isNewline(curchar) && curchar != EOF);
|
} while (!isNewline(curchar) && curchar != EOF);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (curchar == EOF) {
|
if (curchar == EOF) {
|
||||||
@@ -210,9 +209,12 @@ static struct LinkerScriptToken *nextToken(void)
|
|||||||
/* If we have a newline char, this is a newline token */
|
/* If we have a newline char, this is a newline token */
|
||||||
token.type = TOKEN_NEWLINE;
|
token.type = TOKEN_NEWLINE;
|
||||||
|
|
||||||
/* FIXME: This works with CRLF newlines, but not CR-only */
|
if (curchar == '\r') {
|
||||||
if (curchar == '\r')
|
/* Handle CRLF */
|
||||||
readChar(linkerScript); /* Read and discard LF */
|
curchar = nextChar();
|
||||||
|
if (curchar != '\n')
|
||||||
|
ungetc(curchar, linkerScript);
|
||||||
|
}
|
||||||
} else if (curchar == '"') {
|
} else if (curchar == '"') {
|
||||||
/* If we have a string start, this is a string */
|
/* If we have a string start, this is a string */
|
||||||
token.type = TOKEN_STRING;
|
token.type = TOKEN_STRING;
|
||||||
@@ -222,20 +224,35 @@ static struct LinkerScriptToken *nextToken(void)
|
|||||||
size_t capacity = 16; /* Half of the default capacity */
|
size_t capacity = 16; /* Half of the default capacity */
|
||||||
|
|
||||||
do {
|
do {
|
||||||
curchar = readChar(linkerScript);
|
curchar = nextChar();
|
||||||
if (curchar == EOF || isNewline(curchar))
|
if (curchar == EOF || isNewline(curchar)) {
|
||||||
errx(1, "%s(%" PRIu32 "): Unterminated string",
|
errx("%s(%" PRIu32 "): Unterminated string",
|
||||||
linkerScriptName, lineNo);
|
linkerScriptName, lineNo);
|
||||||
else if (curchar == '"')
|
} else if (curchar == '"') {
|
||||||
/* Quotes force a string termination */
|
/* Quotes force a string termination */
|
||||||
curchar = '\0';
|
curchar = '\0';
|
||||||
|
} else if (curchar == '\\') {
|
||||||
|
/* Backslashes are escape sequences */
|
||||||
|
curchar = nextChar();
|
||||||
|
if (curchar == EOF || isNewline(curchar))
|
||||||
|
errx("%s(%" PRIu32 "): Unterminated string",
|
||||||
|
linkerScriptName, lineNo);
|
||||||
|
else if (curchar == 'n')
|
||||||
|
curchar = '\n';
|
||||||
|
else if (curchar == 'r')
|
||||||
|
curchar = '\r';
|
||||||
|
else if (curchar == 't')
|
||||||
|
curchar = '\t';
|
||||||
|
else if (curchar != '\\' && curchar != '"')
|
||||||
|
errx("%s(%" PRIu32 "): Illegal character escape",
|
||||||
|
linkerScriptName, lineNo);
|
||||||
|
}
|
||||||
|
|
||||||
if (size >= capacity || token.attr.string == NULL) {
|
if (size >= capacity || token.attr.string == NULL) {
|
||||||
capacity *= 2;
|
capacity *= 2;
|
||||||
token.attr.string = realloc(token.attr.string,
|
token.attr.string = realloc(token.attr.string, capacity);
|
||||||
capacity);
|
|
||||||
if (!token.attr.string)
|
if (!token.attr.string)
|
||||||
err(1, "%s: Failed to allocate memory for string",
|
err("%s: Failed to allocate memory for string",
|
||||||
__func__);
|
__func__);
|
||||||
}
|
}
|
||||||
token.attr.string[size++] = curchar;
|
token.attr.string[size++] = curchar;
|
||||||
@@ -251,7 +268,7 @@ static struct LinkerScriptToken *nextToken(void)
|
|||||||
capacity *= 2;
|
capacity *= 2;
|
||||||
str = realloc(str, capacity);
|
str = realloc(str, capacity);
|
||||||
if (!str)
|
if (!str)
|
||||||
err(1, "%s: Failed to allocate memory for token",
|
err("%s: Failed to allocate memory for token",
|
||||||
__func__);
|
__func__);
|
||||||
}
|
}
|
||||||
str[size] = toupper(curchar);
|
str[size] = toupper(curchar);
|
||||||
@@ -260,10 +277,9 @@ static struct LinkerScriptToken *nextToken(void)
|
|||||||
if (!curchar)
|
if (!curchar)
|
||||||
break;
|
break;
|
||||||
|
|
||||||
curchar = readChar(linkerScript);
|
curchar = nextChar();
|
||||||
/* Whitespace, a newline or a comment end the token */
|
/* Whitespace, a newline or a comment end the token */
|
||||||
if (isWhiteSpace(curchar) || isNewline(curchar)
|
if (isWhiteSpace(curchar) || isNewline(curchar) || curchar == ';') {
|
||||||
|| curchar == ';') {
|
|
||||||
ungetc(curchar, linkerScript);
|
ungetc(curchar, linkerScript);
|
||||||
curchar = '\0';
|
curchar = '\0';
|
||||||
}
|
}
|
||||||
@@ -282,8 +298,7 @@ static struct LinkerScriptToken *nextToken(void)
|
|||||||
|
|
||||||
if (token.type == TOKEN_INVALID) {
|
if (token.type == TOKEN_INVALID) {
|
||||||
/* Try to match a bank specifier */
|
/* Try to match a bank specifier */
|
||||||
for (enum SectionType type = 0; type < SECTTYPE_INVALID;
|
for (enum SectionType type = 0; type < SECTTYPE_INVALID; type++) {
|
||||||
type++) {
|
|
||||||
if (!strcmp(typeNames[type], str)) {
|
if (!strcmp(typeNames[type], str)) {
|
||||||
token.type = TOKEN_BANK;
|
token.type = TOKEN_BANK;
|
||||||
token.attr.secttype = type;
|
token.attr.secttype = type;
|
||||||
@@ -303,7 +318,7 @@ static struct LinkerScriptToken *nextToken(void)
|
|||||||
if (tryParseNumber(str, &token.attr.number))
|
if (tryParseNumber(str, &token.attr.number))
|
||||||
token.type = TOKEN_NUMBER;
|
token.type = TOKEN_NUMBER;
|
||||||
else
|
else
|
||||||
errx(1, "%s(%" PRIu32 "): Unknown token \"%s\"",
|
errx("%s(%" PRIu32 "): Unknown token \"%s\"",
|
||||||
linkerScriptName, lineNo, str);
|
linkerScriptName, lineNo, str);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -313,8 +328,7 @@ static struct LinkerScriptToken *nextToken(void)
|
|||||||
return &token;
|
return &token;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void processCommand(enum LinkerScriptCommand command, uint16_t arg,
|
static void processCommand(enum LinkerScriptCommand command, uint16_t arg, uint16_t *pc)
|
||||||
uint16_t *pc)
|
|
||||||
{
|
{
|
||||||
switch (command) {
|
switch (command) {
|
||||||
case COMMAND_INVALID:
|
case COMMAND_INVALID:
|
||||||
@@ -331,7 +345,7 @@ static void processCommand(enum LinkerScriptCommand command, uint16_t arg,
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (arg < *pc)
|
if (arg < *pc)
|
||||||
errx(1, "%s(%" PRIu32 "): `%s` cannot be used to go backwards (currently at $%x)",
|
errx("%s(%" PRIu32 "): `%s` cannot be used to go backwards (currently at $%x)",
|
||||||
linkerScriptName, lineNo, commands[command], *pc);
|
linkerScriptName, lineNo, commands[command], *pc);
|
||||||
*pc = arg;
|
*pc = arg;
|
||||||
}
|
}
|
||||||
@@ -380,11 +394,11 @@ struct SectionPlacement *script_NextSection(void)
|
|||||||
|
|
||||||
if (type != SECTTYPE_INVALID) {
|
if (type != SECTTYPE_INVALID) {
|
||||||
if (curaddr[type][bankID] > endaddr(type) + 1)
|
if (curaddr[type][bankID] > endaddr(type) + 1)
|
||||||
errx(1, "%s(%" PRIu32 "): Sections would extend past the end of %s ($%04" PRIx16 " > $%04" PRIx16 ")",
|
errx("%s(%" PRIu32 "): Sections would extend past the end of %s ($%04" PRIx16 " > $%04" PRIx16 ")",
|
||||||
linkerScriptName, lineNo, typeNames[type],
|
linkerScriptName, lineNo, typeNames[type],
|
||||||
curaddr[type][bankID], endaddr(type));
|
curaddr[type][bankID], endaddr(type));
|
||||||
if (curaddr[type][bankID] < startaddr[type])
|
if (curaddr[type][bankID] < startaddr[type])
|
||||||
errx(1, "%s(%" PRIu32 "): PC underflowed ($%04" PRIx16 " < $%04" PRIx16 ")",
|
errx("%s(%" PRIu32 "): PC underflowed ($%04" PRIx16 " < $%04" PRIx16 ")",
|
||||||
linkerScriptName, lineNo,
|
linkerScriptName, lineNo,
|
||||||
curaddr[type][bankID], startaddr[type]);
|
curaddr[type][bankID], startaddr[type]);
|
||||||
}
|
}
|
||||||
@@ -405,7 +419,7 @@ struct SectionPlacement *script_NextSection(void)
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
case TOKEN_NUMBER:
|
case TOKEN_NUMBER:
|
||||||
errx(1, "%s(%" PRIu32 "): stray number \"%" PRIu32 "\"",
|
errx("%s(%" PRIu32 "): stray number \"%" PRIu32 "\"",
|
||||||
linkerScriptName, lineNo,
|
linkerScriptName, lineNo,
|
||||||
token->attr.number);
|
token->attr.number);
|
||||||
|
|
||||||
@@ -418,13 +432,13 @@ struct SectionPlacement *script_NextSection(void)
|
|||||||
parserState = PARSER_LINEEND;
|
parserState = PARSER_LINEEND;
|
||||||
|
|
||||||
if (type == SECTTYPE_INVALID)
|
if (type == SECTTYPE_INVALID)
|
||||||
errx(1, "%s(%" PRIu32 "): Didn't specify a location before the section",
|
errx("%s(%" PRIu32 "): Didn't specify a location before the section",
|
||||||
linkerScriptName, lineNo);
|
linkerScriptName, lineNo);
|
||||||
|
|
||||||
section.section =
|
section.section =
|
||||||
sect_GetSection(token->attr.string);
|
sect_GetSection(token->attr.string);
|
||||||
if (!section.section)
|
if (!section.section)
|
||||||
errx(1, "%s(%" PRIu32 "): Unknown section \"%s\"",
|
errx("%s(%" PRIu32 "): Unknown section \"%s\"",
|
||||||
linkerScriptName, lineNo,
|
linkerScriptName, lineNo,
|
||||||
token->attr.string);
|
token->attr.string);
|
||||||
section.org = curaddr[type][bankID];
|
section.org = curaddr[type][bankID];
|
||||||
@@ -453,14 +467,13 @@ struct SectionPlacement *script_NextSection(void)
|
|||||||
|
|
||||||
if (tokType == TOKEN_COMMAND) {
|
if (tokType == TOKEN_COMMAND) {
|
||||||
if (type == SECTTYPE_INVALID)
|
if (type == SECTTYPE_INVALID)
|
||||||
errx(1, "%s(%" PRIu32 "): Didn't specify a location before the command",
|
errx("%s(%" PRIu32 "): Didn't specify a location before the command",
|
||||||
linkerScriptName, lineNo);
|
linkerScriptName, lineNo);
|
||||||
if (!hasArg)
|
if (!hasArg)
|
||||||
errx(1, "%s(%" PRIu32 "): Command specified without an argument",
|
errx("%s(%" PRIu32 "): Command specified without an argument",
|
||||||
linkerScriptName, lineNo);
|
linkerScriptName, lineNo);
|
||||||
|
|
||||||
processCommand(attr.command, arg,
|
processCommand(attr.command, arg, &curaddr[type][bankID]);
|
||||||
&curaddr[type][bankID]);
|
|
||||||
} else { /* TOKEN_BANK */
|
} else { /* TOKEN_BANK */
|
||||||
type = attr.secttype;
|
type = attr.secttype;
|
||||||
/*
|
/*
|
||||||
@@ -468,16 +481,16 @@ struct SectionPlacement *script_NextSection(void)
|
|||||||
* specifying the number is optional.
|
* specifying the number is optional.
|
||||||
*/
|
*/
|
||||||
if (!hasArg && nbbanks(type) != 1)
|
if (!hasArg && nbbanks(type) != 1)
|
||||||
errx(1, "%s(%" PRIu32 "): Didn't specify a bank number",
|
errx("%s(%" PRIu32 "): Didn't specify a bank number",
|
||||||
linkerScriptName, lineNo);
|
linkerScriptName, lineNo);
|
||||||
else if (!hasArg)
|
else if (!hasArg)
|
||||||
arg = bankranges[type][0];
|
arg = bankranges[type][0];
|
||||||
else if (arg < bankranges[type][0])
|
else if (arg < bankranges[type][0])
|
||||||
errx(1, "%s(%" PRIu32 "): specified bank number is too low (%" PRIu32 " < %" PRIu32 ")",
|
errx("%s(%" PRIu32 "): specified bank number is too low (%" PRIu32 " < %" PRIu32 ")",
|
||||||
linkerScriptName, lineNo,
|
linkerScriptName, lineNo,
|
||||||
arg, bankranges[type][0]);
|
arg, bankranges[type][0]);
|
||||||
else if (arg > bankranges[type][1])
|
else if (arg > bankranges[type][1])
|
||||||
errx(1, "%s(%" PRIu32 "): specified bank number is too high (%" PRIu32 " > %" PRIu32 ")",
|
errx("%s(%" PRIu32 "): specified bank number is too high (%" PRIu32 " > %" PRIu32 ")",
|
||||||
linkerScriptName, lineNo,
|
linkerScriptName, lineNo,
|
||||||
arg, bankranges[type][1]);
|
arg, bankranges[type][1]);
|
||||||
bank = arg;
|
bank = arg;
|
||||||
@@ -497,7 +510,7 @@ struct SectionPlacement *script_NextSection(void)
|
|||||||
|
|
||||||
case PARSER_INCLUDE:
|
case PARSER_INCLUDE:
|
||||||
if (token->type != TOKEN_STRING)
|
if (token->type != TOKEN_STRING)
|
||||||
errx(1, "%s(%" PRIu32 "): Expected a file name after INCLUDE",
|
errx("%s(%" PRIu32 "): Expected a file name after INCLUDE",
|
||||||
linkerScriptName, lineNo);
|
linkerScriptName, lineNo);
|
||||||
|
|
||||||
/* Switch to that file */
|
/* Switch to that file */
|
||||||
@@ -517,7 +530,7 @@ lineend:
|
|||||||
return NULL;
|
return NULL;
|
||||||
parserState = PARSER_LINEEND;
|
parserState = PARSER_LINEEND;
|
||||||
} else if (token->type != TOKEN_NEWLINE)
|
} else if (token->type != TOKEN_NEWLINE)
|
||||||
errx(1, "%s(%" PRIu32 "): Unexpected %s at the end of the line",
|
errx("%s(%" PRIu32 "): Unexpected %s at the end of the line",
|
||||||
linkerScriptName, lineNo,
|
linkerScriptName, lineNo,
|
||||||
tokenTypes[token->type]);
|
tokenTypes[token->type]);
|
||||||
break;
|
break;
|
||||||
|
|||||||
@@ -14,8 +14,7 @@
|
|||||||
#include "link/main.h"
|
#include "link/main.h"
|
||||||
#include "link/section.h"
|
#include "link/section.h"
|
||||||
|
|
||||||
#include "extern/err.h"
|
#include "error.h"
|
||||||
|
|
||||||
#include "hashmap.h"
|
#include "hashmap.h"
|
||||||
|
|
||||||
HashMap sections;
|
HashMap sections;
|
||||||
@@ -44,13 +43,13 @@ static void checkSectUnionCompat(struct Section *target, struct Section *other)
|
|||||||
if (other->isAddressFixed) {
|
if (other->isAddressFixed) {
|
||||||
if (target->isAddressFixed) {
|
if (target->isAddressFixed) {
|
||||||
if (target->org != other->org)
|
if (target->org != other->org)
|
||||||
errx(1, "Section \"%s\" is defined with conflicting addresses $%04"
|
errx("Section \"%s\" is defined with conflicting addresses $%04"
|
||||||
PRIx16 " and $%04" PRIx16,
|
PRIx16 " and $%04" PRIx16,
|
||||||
other->name, target->org, other->org);
|
other->name, target->org, other->org);
|
||||||
} else if (target->isAlignFixed) {
|
} else if (target->isAlignFixed) {
|
||||||
if ((other->org - target->alignOfs) & target->alignMask)
|
if ((other->org - target->alignOfs) & target->alignMask)
|
||||||
errx(1, "Section \"%s\" is defined with conflicting %" PRIu16
|
errx("Section \"%s\" is defined with conflicting %d-byte alignment (offset %"
|
||||||
"-byte alignment (offset %" PRIu16 ") and address $%04" PRIx16,
|
PRIu16 ") and address $%04" PRIx16,
|
||||||
other->name, target->alignMask + 1,
|
other->name, target->alignMask + 1,
|
||||||
target->alignOfs, other->org);
|
target->alignOfs, other->org);
|
||||||
}
|
}
|
||||||
@@ -60,16 +59,15 @@ static void checkSectUnionCompat(struct Section *target, struct Section *other)
|
|||||||
} else if (other->isAlignFixed) {
|
} else if (other->isAlignFixed) {
|
||||||
if (target->isAddressFixed) {
|
if (target->isAddressFixed) {
|
||||||
if ((target->org - other->alignOfs) & other->alignMask)
|
if ((target->org - other->alignOfs) & other->alignMask)
|
||||||
errx(1, "Section \"%s\" is defined with conflicting address $%04"
|
errx("Section \"%s\" is defined with conflicting address $%04"
|
||||||
PRIx16 " and %" PRIu16 "-byte alignment (offset %" PRIu16 ")",
|
PRIx16 " and %d-byte alignment (offset %" PRIu16 ")",
|
||||||
other->name, target->org,
|
other->name, target->org,
|
||||||
other->alignMask + 1, other->alignOfs);
|
other->alignMask + 1, other->alignOfs);
|
||||||
} else if (target->isAlignFixed
|
} else if (target->isAlignFixed
|
||||||
&& (other->alignMask & target->alignOfs)
|
&& (other->alignMask & target->alignOfs)
|
||||||
!= (target->alignMask & other->alignOfs)) {
|
!= (target->alignMask & other->alignOfs)) {
|
||||||
errx(1, "Section \"%s\" is defined with conflicting %" PRIu16
|
errx("Section \"%s\" is defined with conflicting %d-byte alignment (offset %"
|
||||||
"-byte alignment (offset %" PRIu16 ") and %" PRIu16
|
PRIu16 ") and %d-byte alignment (offset %" PRIu16 ")",
|
||||||
"-byte alignment (offset %" PRIu16 ")",
|
|
||||||
other->name, target->alignMask + 1, target->alignOfs,
|
other->name, target->alignMask + 1, target->alignOfs,
|
||||||
other->alignMask + 1, other->alignOfs);
|
other->alignMask + 1, other->alignOfs);
|
||||||
} else if (!target->isAlignFixed || (other->alignMask > target->alignMask)) {
|
} else if (!target->isAlignFixed || (other->alignMask > target->alignMask)) {
|
||||||
@@ -86,14 +84,14 @@ static void checkFragmentCompat(struct Section *target, struct Section *other)
|
|||||||
|
|
||||||
if (target->isAddressFixed) {
|
if (target->isAddressFixed) {
|
||||||
if (target->org != org)
|
if (target->org != org)
|
||||||
errx(1, "Section \"%s\" is defined with conflicting addresses $%04"
|
errx("Section \"%s\" is defined with conflicting addresses $%04"
|
||||||
PRIx16 " and $%04" PRIx16,
|
PRIx16 " and $%04" PRIx16,
|
||||||
other->name, target->org, other->org);
|
other->name, target->org, other->org);
|
||||||
|
|
||||||
} else if (target->isAlignFixed) {
|
} else if (target->isAlignFixed) {
|
||||||
if ((org - target->alignOfs) & target->alignMask)
|
if ((org - target->alignOfs) & target->alignMask)
|
||||||
errx(1, "Section \"%s\" is defined with conflicting %" PRIu16
|
errx("Section \"%s\" is defined with conflicting %d-byte alignment (offset %"
|
||||||
"-byte alignment (offset %" PRIu16 ") and address $%04" PRIx16,
|
PRIu16 ") and address $%04" PRIx16,
|
||||||
other->name, target->alignMask + 1,
|
other->name, target->alignMask + 1,
|
||||||
target->alignOfs, other->org);
|
target->alignOfs, other->org);
|
||||||
}
|
}
|
||||||
@@ -108,16 +106,15 @@ static void checkFragmentCompat(struct Section *target, struct Section *other)
|
|||||||
|
|
||||||
if (target->isAddressFixed) {
|
if (target->isAddressFixed) {
|
||||||
if ((target->org - ofs) & other->alignMask)
|
if ((target->org - ofs) & other->alignMask)
|
||||||
errx(1, "Section \"%s\" is defined with conflicting address $%04"
|
errx("Section \"%s\" is defined with conflicting address $%04"
|
||||||
PRIx16 " and %" PRIu16 "-byte alignment (offset %" PRIu16 ")",
|
PRIx16 " and %d-byte alignment (offset %" PRIu16 ")",
|
||||||
other->name, target->org,
|
other->name, target->org,
|
||||||
other->alignMask + 1, other->alignOfs);
|
other->alignMask + 1, other->alignOfs);
|
||||||
|
|
||||||
} else if (target->isAlignFixed
|
} else if (target->isAlignFixed
|
||||||
&& (other->alignMask & target->alignOfs) != (target->alignMask & ofs)) {
|
&& (other->alignMask & target->alignOfs) != (target->alignMask & ofs)) {
|
||||||
errx(1, "Section \"%s\" is defined with conflicting %" PRIu16
|
errx("Section \"%s\" is defined with conflicting %d-byte alignment (offset %"
|
||||||
"-byte alignment (offset %" PRIu16 ") and %" PRIu16
|
PRIu16 ") and %d-byte alignment (offset %" PRIu16 ")",
|
||||||
"-byte alignment (offset %" PRIu16 ")",
|
|
||||||
other->name, target->alignMask + 1, target->alignOfs,
|
other->name, target->alignMask + 1, target->alignOfs,
|
||||||
other->alignMask + 1, other->alignOfs);
|
other->alignMask + 1, other->alignOfs);
|
||||||
|
|
||||||
@@ -134,7 +131,7 @@ static void mergeSections(struct Section *target, struct Section *other, enum Se
|
|||||||
// Common checks
|
// Common checks
|
||||||
|
|
||||||
if (target->type != other->type)
|
if (target->type != other->type)
|
||||||
errx(1, "Section \"%s\" is defined with conflicting types %s and %s",
|
errx("Section \"%s\" is defined with conflicting types %s and %s",
|
||||||
other->name, typeNames[target->type], typeNames[other->type]);
|
other->name, typeNames[target->type], typeNames[other->type]);
|
||||||
|
|
||||||
if (other->isBankFixed) {
|
if (other->isBankFixed) {
|
||||||
@@ -142,7 +139,7 @@ static void mergeSections(struct Section *target, struct Section *other, enum Se
|
|||||||
target->isBankFixed = true;
|
target->isBankFixed = true;
|
||||||
target->bank = other->bank;
|
target->bank = other->bank;
|
||||||
} else if (target->bank != other->bank) {
|
} else if (target->bank != other->bank) {
|
||||||
errx(1, "Section \"%s\" is defined with conflicting banks %" PRIu32 " and %"
|
errx("Section \"%s\" is defined with conflicting banks %" PRIu32 " and %"
|
||||||
PRIu32, other->name, target->bank, other->bank);
|
PRIu32, other->name, target->bank, other->bank);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -163,8 +160,11 @@ static void mergeSections(struct Section *target, struct Section *other, enum Se
|
|||||||
target->data = realloc(target->data,
|
target->data = realloc(target->data,
|
||||||
sizeof(*target->data) * target->size + 1);
|
sizeof(*target->data) * target->size + 1);
|
||||||
if (!target->data)
|
if (!target->data)
|
||||||
errx(1, "Failed to concatenate \"%s\"'s fragments", target->name);
|
errx("Failed to concatenate \"%s\"'s fragments", target->name);
|
||||||
memcpy(target->data + target->size - other->size, other->data, other->size);
|
memcpy(target->data + target->size - other->size, other->data, other->size);
|
||||||
|
/* Adjust patches' PC offsets */
|
||||||
|
for (uint32_t patchID = 0; patchID < other->nbPatches; patchID++)
|
||||||
|
other->patches[patchID].pcOffset += other->offset;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
@@ -183,14 +183,14 @@ void sect_AddSection(struct Section *section)
|
|||||||
|
|
||||||
if (other) {
|
if (other) {
|
||||||
if (section->modifier != other->modifier)
|
if (section->modifier != other->modifier)
|
||||||
errx(1, "Section \"%s\" defined as %s and %s", section->name,
|
errx("Section \"%s\" defined as %s and %s", section->name,
|
||||||
sectionModNames[section->modifier], sectionModNames[other->modifier]);
|
sectionModNames[section->modifier], sectionModNames[other->modifier]);
|
||||||
else if (section->modifier == SECTION_NORMAL)
|
else if (section->modifier == SECTION_NORMAL)
|
||||||
errx(1, "Section name \"%s\" is already in use", section->name);
|
errx("Section name \"%s\" is already in use", section->name);
|
||||||
else
|
else
|
||||||
mergeSections(other, section, section->modifier);
|
mergeSections(other, section, section->modifier);
|
||||||
} else if (section->modifier == SECTION_UNION && sect_HasData(section->type)) {
|
} else if (section->modifier == SECTION_UNION && sect_HasData(section->type)) {
|
||||||
errx(1, "Section \"%s\" is of type %s, which cannot be unionized",
|
errx("Section \"%s\" is of type %s, which cannot be unionized",
|
||||||
section->name, typeNames[section->type]);
|
section->name, typeNames[section->type]);
|
||||||
} else {
|
} else {
|
||||||
/* If not, add it */
|
/* If not, add it */
|
||||||
@@ -249,7 +249,7 @@ static void doSanityChecks(struct Section *section, void *ptr)
|
|||||||
|
|
||||||
/* Too large an alignment may not be satisfiable */
|
/* Too large an alignment may not be satisfiable */
|
||||||
if (section->isAlignFixed && (section->alignMask & startaddr[section->type]))
|
if (section->isAlignFixed && (section->alignMask & startaddr[section->type]))
|
||||||
fail("%s: %s sections cannot be aligned to $%04" PRIx16 " bytes",
|
fail("%s: %s sections cannot be aligned to $%04x bytes",
|
||||||
section->name, typeNames[section->type], section->alignMask + 1);
|
section->name, typeNames[section->type], section->alignMask + 1);
|
||||||
|
|
||||||
uint32_t minbank = bankranges[section->type][0], maxbank = bankranges[section->type][1];
|
uint32_t minbank = bankranges[section->type][0], maxbank = bankranges[section->type][1];
|
||||||
@@ -289,9 +289,9 @@ static void doSanityChecks(struct Section *section, void *ptr)
|
|||||||
startaddr[section->type], endaddr(section->type));
|
startaddr[section->type], endaddr(section->type));
|
||||||
|
|
||||||
if (section->org + section->size > endaddr(section->type) + 1)
|
if (section->org + section->size > endaddr(section->type) + 1)
|
||||||
fail("Section \"%s\"'s end address %#" PRIx16
|
fail("Section \"%s\"'s end address %#x is greater than last address %#x",
|
||||||
" is greater than last address %#" PRIx16, section->name,
|
section->name, section->org + section->size,
|
||||||
section->org + section->size, endaddr(section->type) + 1);
|
endaddr(section->type) + 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
#undef fail
|
#undef fail
|
||||||
@@ -301,5 +301,5 @@ void sect_DoSanityChecks(void)
|
|||||||
{
|
{
|
||||||
sect_ForEach(doSanityChecks, NULL);
|
sect_ForEach(doSanityChecks, NULL);
|
||||||
if (sanityChecksFailed)
|
if (sanityChecksFailed)
|
||||||
errx(1, "Sanity checks failed");
|
errx("Sanity checks failed");
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -14,7 +14,7 @@
|
|||||||
#include "link/symbol.h"
|
#include "link/symbol.h"
|
||||||
#include "link/main.h"
|
#include "link/main.h"
|
||||||
|
|
||||||
#include "extern/err.h"
|
#include "error.h"
|
||||||
#include "hashmap.h"
|
#include "hashmap.h"
|
||||||
|
|
||||||
HashMap symbols;
|
HashMap symbols;
|
||||||
|
|||||||
15
src/opmath.c
15
src/opmath.c
@@ -86,3 +86,18 @@ int32_t op_shift_right(int32_t value, int32_t amount)
|
|||||||
// undefined, so use a left shift manually sign-extended
|
// undefined, so use a left shift manually sign-extended
|
||||||
return ((uint32_t)value >> amount) | amount_high_bits;
|
return ((uint32_t)value >> amount) | amount_high_bits;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int32_t op_shift_right_unsigned(int32_t value, int32_t amount)
|
||||||
|
{
|
||||||
|
// Repeat the easy cases here to avoid INT_MIN funny business
|
||||||
|
if (amount == 0)
|
||||||
|
return value;
|
||||||
|
if (value == 0 || amount <= -32)
|
||||||
|
return 0;
|
||||||
|
if (amount > 31)
|
||||||
|
return (value < 0) ? -1 : 0;
|
||||||
|
if (amount < 0)
|
||||||
|
return op_shift_left(value, -amount);
|
||||||
|
|
||||||
|
return (uint32_t)value >> amount;
|
||||||
|
}
|
||||||
|
|||||||
@@ -226,13 +226,13 @@ with some bytes being special prefixes for integers and symbols.
|
|||||||
.It Li $04 Ta Li % operator
|
.It Li $04 Ta Li % operator
|
||||||
.It Li $05 Ta Li unary -
|
.It Li $05 Ta Li unary -
|
||||||
.It Li $06 Ta Li ** operator
|
.It Li $06 Ta Li ** operator
|
||||||
.It Li $10 Ta Li | operator
|
.It Li $10 Ta Li \&| operator
|
||||||
.It Li $11 Ta Li & operator
|
.It Li $11 Ta Li & operator
|
||||||
.It Li $12 Ta Li ^ operator
|
.It Li $12 Ta Li ^ operator
|
||||||
.It Li $13 Ta Li unary ~
|
.It Li $13 Ta Li unary ~
|
||||||
.It Li $21 Ta Li && comparison
|
.It Li $21 Ta Li && comparison
|
||||||
.It Li $22 Ta Li || comparison
|
.It Li $22 Ta Li || comparison
|
||||||
.It Li $23 Ta Li unary\ !
|
.It Li $23 Ta Li unary \&!
|
||||||
.It Li $30 Ta Li == comparison
|
.It Li $30 Ta Li == comparison
|
||||||
.It Li $31 Ta Li != comparison
|
.It Li $31 Ta Li != comparison
|
||||||
.It Li $32 Ta Li > comparison
|
.It Li $32 Ta Li > comparison
|
||||||
@@ -241,6 +241,7 @@ with some bytes being special prefixes for integers and symbols.
|
|||||||
.It Li $35 Ta Li <= comparison
|
.It Li $35 Ta Li <= comparison
|
||||||
.It Li $40 Ta Li << operator
|
.It Li $40 Ta Li << operator
|
||||||
.It Li $41 Ta Li >> operator
|
.It Li $41 Ta Li >> operator
|
||||||
|
.It Li $42 Ta Li >>> operator
|
||||||
.It Li $50 Ta Li BANK(symbol) ,
|
.It Li $50 Ta Li BANK(symbol) ,
|
||||||
a
|
a
|
||||||
.Ar LONG
|
.Ar LONG
|
||||||
@@ -248,6 +249,10 @@ Symbol ID follows, where -1 means PC
|
|||||||
.It Li $51 Ta Li BANK(section_name) ,
|
.It Li $51 Ta Li BANK(section_name) ,
|
||||||
a null-terminated string follows.
|
a null-terminated string follows.
|
||||||
.It Li $52 Ta Li Current BANK()
|
.It Li $52 Ta Li Current BANK()
|
||||||
|
.It Li $53 Ta Li SIZEOF(section_name) ,
|
||||||
|
a null-terminated string follows.
|
||||||
|
.It Li $54 Ta Li STARTOF(section_name) ,
|
||||||
|
a null-terminated string follows.
|
||||||
.It Li $60 Ta Li HRAMCheck .
|
.It Li $60 Ta Li HRAMCheck .
|
||||||
Checks if the value is in HRAM, ANDs it with 0xFF.
|
Checks if the value is in HRAM, ANDs it with 0xFF.
|
||||||
.It Li $61 Ta Li RSTCheck .
|
.It Li $61 Ta Li RSTCheck .
|
||||||
|
|||||||
@@ -18,6 +18,10 @@ $ rgbasm \-o bar.o foo.asm
|
|||||||
$ rgblink \-o baz.gb bar.o
|
$ rgblink \-o baz.gb bar.o
|
||||||
$ rgbfix \-v \-p 0 baz.gb
|
$ rgbfix \-v \-p 0 baz.gb
|
||||||
.Ed
|
.Ed
|
||||||
|
Or in a single command line:
|
||||||
|
.Bd -literal -offset indent
|
||||||
|
$ rgbasm \-o - foo.asm | rgblink \-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 ,
|
||||||
|
|||||||
@@ -12,7 +12,14 @@
|
|||||||
#include "helpers.h"
|
#include "helpers.h"
|
||||||
#include "version.h"
|
#include "version.h"
|
||||||
|
|
||||||
const char *get_package_version_string(void)
|
// This variable is passed via `-D` from the Makefile, but not from CMake
|
||||||
|
// (in which `configure_file()` is used on this file to replace some syntax)
|
||||||
|
#ifndef BUILD_VERSION_STRING
|
||||||
|
// CMake-specific syntax here
|
||||||
|
#define BUILD_VERSION_STRING "@GIT_REV@"
|
||||||
|
#endif
|
||||||
|
|
||||||
|
char const *get_package_version_string(void)
|
||||||
{
|
{
|
||||||
// The following conditional should be simplified by the compiler.
|
// The following conditional should be simplified by the compiler.
|
||||||
if (strlen(BUILD_VERSION_STRING) == 0) {
|
if (strlen(BUILD_VERSION_STRING) == 0) {
|
||||||
|
|||||||
3
test/.gitignore
vendored
Normal file
3
test/.gitignore
vendored
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
/pokecrystal/
|
||||||
|
/pokered/
|
||||||
|
/ucity/
|
||||||
@@ -1,3 +1,3 @@
|
|||||||
ERROR: align-large-ofs.asm(2):
|
error: align-large-ofs.asm(2):
|
||||||
Alignment offset (2) must be smaller than alignment size (2)
|
Alignment offset (2) must be smaller than alignment size (2)
|
||||||
error: Assembly aborted (1 error)!
|
error: Assembly aborted (1 error)!
|
||||||
|
|||||||
@@ -1,2 +1,3 @@
|
|||||||
FATAL: align-pc-outside-section.asm(1):
|
error: align-pc-outside-section.asm(1):
|
||||||
Code generation before SECTION directive
|
Cannot output data outside of a SECTION
|
||||||
|
error: Assembly aborted (1 error)!
|
||||||
|
|||||||
@@ -1,3 +1,3 @@
|
|||||||
ERROR: align-unattainable.asm(3):
|
error: align-unattainable.asm(3):
|
||||||
Section "X"'s alignment cannot be attained in WRAM0
|
Section "X"'s alignment cannot be attained in WRAM0
|
||||||
error: Assembly aborted (1 error)!
|
error: Assembly aborted (1 error)!
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
ERROR: anon-label-bad.asm(2):
|
error: anon-label-bad.asm(2):
|
||||||
Label "!0" created outside of a SECTION
|
Label "!0" created outside of a SECTION
|
||||||
ERROR: anon-label-bad.asm(6):
|
error: anon-label-bad.asm(6):
|
||||||
Reference to anonymous label 2 before, when only 1 has been created so far
|
Reference to anonymous label 2 before, when only 1 has been created so far
|
||||||
ERROR: anon-label-bad.asm(18):
|
error: anon-label-bad.asm(18):
|
||||||
syntax error, unexpected :
|
syntax error, unexpected :
|
||||||
error: Assembly aborted (3 errors)!
|
error: Assembly aborted (3 errors)!
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
ERROR: anon-label-bad.asm(2):
|
error: anon-label-bad.asm(2):
|
||||||
Label "!0" created outside of a SECTION
|
Label "!0" created outside of a SECTION
|
||||||
ERROR: anon-label-bad.asm(6):
|
error: anon-label-bad.asm(6):
|
||||||
Reference to anonymous label 2 before, when only 1 has been created so far
|
Reference to anonymous label 2 before, when only 1 has been created so far
|
||||||
ERROR: anon-label-bad.asm(18):
|
error: anon-label-bad.asm(18):
|
||||||
syntax error
|
syntax error
|
||||||
error: Assembly aborted (3 errors)!
|
error: Assembly aborted (3 errors)!
|
||||||
|
|||||||
@@ -1,3 +1,3 @@
|
|||||||
ERROR: assert-nosect-bank.asm(1):
|
error: assert-nosect-bank.asm(1):
|
||||||
PC has no bank outside a section
|
PC has no bank outside a section
|
||||||
error: Assembly aborted (1 error)!
|
error: Assembly aborted (1 error)!
|
||||||
|
|||||||
@@ -1,10 +1,10 @@
|
|||||||
ERROR: assert.asm(4):
|
error: assert.asm(4):
|
||||||
Assertion failed
|
Assertion failed
|
||||||
warning: assert.asm(10): [-Wassert]
|
warning: assert.asm(10): [-Wassert]
|
||||||
Assertion failed
|
Assertion failed
|
||||||
ERROR: assert.asm(18):
|
error: assert.asm(18):
|
||||||
Expected constant expression: 'FloatingBase' is not constant at assembly time
|
Expected constant expression: 'FloatingBase' is not constant at assembly time
|
||||||
ERROR: assert.asm(18):
|
error: assert.asm(18):
|
||||||
Assertion failed
|
Assertion failed
|
||||||
FATAL: assert.asm(21):
|
FATAL: assert.asm(21):
|
||||||
Assertion failed
|
Assertion failed
|
||||||
|
|||||||
@@ -1,3 +1,3 @@
|
|||||||
ERROR: assert@-no-sect.asm(1):
|
error: assert@-no-sect.asm(1):
|
||||||
PC has no value outside a section
|
PC has no value outside a section
|
||||||
error: Assembly aborted (1 error)!
|
error: Assembly aborted (1 error)!
|
||||||
|
|||||||
@@ -1,9 +1,9 @@
|
|||||||
ERROR: bank.asm(13) -> bank.asm::def_sect(8):
|
error: bank.asm(13) -> bank.asm::def_sect(8):
|
||||||
Expected constant expression: Section "ROMX_bad"'s bank is not known
|
Expected constant expression: Section "ROMX_bad"'s bank is not known
|
||||||
ERROR: bank.asm(15) -> bank.asm::def_sect(8):
|
error: bank.asm(15) -> bank.asm::def_sect(8):
|
||||||
Expected constant expression: Section "VRAM_bad"'s bank is not known
|
Expected constant expression: Section "VRAM_bad"'s bank is not known
|
||||||
ERROR: bank.asm(17) -> bank.asm::def_sect(8):
|
error: bank.asm(17) -> bank.asm::def_sect(8):
|
||||||
Expected constant expression: Section "SRAM_bad"'s bank is not known
|
Expected constant expression: Section "SRAM_bad"'s bank is not known
|
||||||
ERROR: bank.asm(20) -> bank.asm::def_sect(8):
|
error: bank.asm(20) -> bank.asm::def_sect(8):
|
||||||
Expected constant expression: Section "WRAMX_bad"'s bank is not known
|
Expected constant expression: Section "WRAMX_bad"'s bank is not known
|
||||||
error: Assembly aborted (4 errors)!
|
error: Assembly aborted (4 errors)!
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
ERROR: block-comment-termination-error.asm(1):
|
error: block-comment-termination-error.asm(1):
|
||||||
Unterminated block comment
|
Unterminated block comment
|
||||||
ERROR: block-comment-termination-error.asm(1):
|
error: block-comment-termination-error.asm(1):
|
||||||
syntax error, unexpected newline
|
syntax error, unexpected end of buffer
|
||||||
error: Assembly aborted (2 errors)!
|
error: Assembly aborted (2 errors)!
|
||||||
|
|||||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user