mirror of
https://github.com/gbdev/rgbds.git
synced 2026-09-15 18:27:06 +00:00
Compare commits
629
Commits
| 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 | ||
|
|
432c769d60 | ||
|
|
9923fa3eee | ||
|
|
750e93be3d | ||
|
|
ee5da4468d | ||
|
|
503c3b5364 | ||
|
|
992be3fd9b | ||
|
|
c755fa3469 | ||
|
|
e78a1d5bfd | ||
|
|
d2f6def2eb | ||
|
|
1ffd7cb5bb | ||
|
|
215e26b478 | ||
|
|
8885f7bcf6 | ||
|
|
5334fc334e | ||
|
|
f97663aa37 | ||
|
|
08bdbd1949 | ||
|
|
5c852c7651 | ||
|
|
6be3584467 | ||
|
|
8c90d9d2d7 | ||
|
|
f69e666b00 | ||
|
|
eba06404f0 | ||
|
|
9558ccea1b | ||
|
|
260d372acd | ||
|
|
4e1b0ce793 | ||
|
|
363ee9578c | ||
|
|
8fa5a4255e | ||
|
|
b3312886fb | ||
|
|
7fc8a65d0a | ||
|
|
c278a361da | ||
|
|
a2f52867ad | ||
|
|
ab79e6bede | ||
|
|
850c78aaf4 | ||
|
|
c08cf783c8 | ||
|
|
25a8518fbf | ||
|
|
49174f4486 | ||
|
|
81327b0d99 | ||
|
|
c0859e64f7 | ||
|
|
3e0b7d428f | ||
|
|
ba3428314b | ||
|
|
bcb78f5d18 | ||
|
|
de7d1facf3 | ||
|
|
310d34c655 | ||
|
|
39c38f9838 | ||
|
|
576b063519 | ||
|
|
596e17ee61 | ||
|
|
363b3d0134 | ||
|
|
c7ed9a275e | ||
|
|
49aac2961d | ||
|
|
3741bd4617 | ||
|
|
937c9888a4 | ||
|
|
61a9bfd33c | ||
|
|
d08bcc455d | ||
|
|
aaa92659ea | ||
|
|
be877134e5 | ||
|
|
d05703c692 | ||
|
|
5dbfafcc55 | ||
|
|
a265b85d9d | ||
|
|
28abf03c0a | ||
|
|
7e7f92f18c | ||
|
|
7461170956 | ||
|
|
57d966d6e0 | ||
|
|
17752d7094 | ||
|
|
4216f0a9b0 | ||
|
|
e3fde986ad | ||
|
|
aa99ed056c | ||
|
|
46d6652df1 | ||
|
|
5406674cdd | ||
|
|
5d2e2e2182 | ||
|
|
a929f36bc5 | ||
|
|
bdb84a901f | ||
|
|
093631ca0b | ||
|
|
7e127a4e52 | ||
|
|
b8093847dc | ||
|
|
8d1b56bcf5 | ||
|
|
5fb7fcf461 | ||
|
|
ee900ae7a3 | ||
|
|
3ca58e13dc | ||
|
|
aaa4e17454 | ||
|
|
a81d383f75 | ||
|
|
60019cf476 | ||
|
|
5a6a44cbc1 | ||
|
|
b61a187b19 | ||
|
|
6382f13647 | ||
|
|
714d39c86f | ||
|
|
f11241c2ae | ||
|
|
cb47ac8b97 | ||
|
|
028e7af7d1 | ||
|
|
e141da1d94 | ||
|
|
35367282e4 | ||
|
|
4c0fa6732e | ||
|
|
e9d9a44687 | ||
|
|
611bd46e0b | ||
|
|
e67254093e | ||
|
|
3ce3d2f662 | ||
|
|
3da9d81071 | ||
|
|
88646093ca | ||
|
|
0a0427afbb | ||
|
|
88048cdcd7 | ||
|
|
c878ff8775 | ||
|
|
a4049a3f1b | ||
|
|
8a75cc5051 | ||
|
|
b674c5fcaa | ||
|
|
a6d3df7ac9 | ||
|
|
365484ef18 | ||
|
|
5e2bd35239 | ||
|
|
6655e04ef0 | ||
|
|
40c6b840f8 | ||
|
|
5d6e0677d9 | ||
|
|
56071599e7 | ||
|
|
c637447d5d | ||
|
|
ac2cefdd87 | ||
|
|
0774f5eb9d | ||
|
|
76d8862900 | ||
|
|
1dafc1c762 | ||
|
|
63d15ac8c9 | ||
|
|
1f579deaff | ||
|
|
fad48326f8 | ||
|
|
e7d6ddf593 | ||
|
|
953f79c0d9 | ||
|
|
3c5e1caa7c | ||
|
|
d4028fff10 | ||
|
|
dd892d61d8 | ||
|
|
a09f2d4115 | ||
|
|
dafef5a953 | ||
|
|
929e2a4490 | ||
|
|
cc1129093d | ||
|
|
72911ada2d | ||
|
|
037bc7abb3 | ||
|
|
5fd636ac4b | ||
|
|
a6d844a9a5 | ||
|
|
bee62076c6 | ||
|
|
cd072d5e6a | ||
|
|
6ef3ee1391 | ||
|
|
c29b616f93 | ||
|
|
39c179aa32 | ||
|
|
5c1ae4ce22 | ||
|
|
efbfeca292 | ||
|
|
7dd34f1572 | ||
|
|
748e7dd4c7 | ||
|
|
d049ffc0f0 | ||
|
|
8c0275480c | ||
|
|
76d6ef8695 | ||
|
|
c67a696a87 | ||
|
|
ee20d9010e | ||
|
|
2bc12447e2 | ||
|
|
cb61da8842 | ||
|
|
122ba6eba5 | ||
|
|
dddff0f450 | ||
|
|
a919f922a1 | ||
|
|
8f20620c16 | ||
|
|
96bce05be2 | ||
|
|
fc2bf3d11d | ||
|
|
8415ce3ed0 | ||
|
|
ebb5aab6db | ||
|
|
464a3a4892 | ||
|
|
88e1cc7302 | ||
|
|
b3c0db218d | ||
|
|
76446e6d00 | ||
|
|
6623b1dc45 | ||
|
|
70bbb098d3 | ||
|
|
1926065377 | ||
|
|
e3d355d976 | ||
|
|
a679e02246 | ||
|
|
592e9b3725 | ||
|
|
effc58241d | ||
|
|
3697065afc | ||
|
|
fa0fa4d5ac | ||
|
|
5acc48fa54 | ||
|
|
1487eebe79 | ||
|
|
993c034039 | ||
|
|
09f16bda4a | ||
|
|
41d544a4eb | ||
|
|
f28b4abafc | ||
|
|
ca1c934629 | ||
|
|
d5a00cf634 | ||
|
|
fb39c3a70e | ||
|
|
15ec6efc28 | ||
|
|
93d83e17dc | ||
|
|
df16e64fc6 | ||
|
|
a4ebb87858 | ||
|
|
5ef8e0a1f6 | ||
|
|
eb4952c188 | ||
|
|
57b734a7df | ||
|
|
5be1c0da62 | ||
|
|
b598911e96 | ||
|
|
cab9cb06a3 | ||
|
|
62bea23c49 | ||
|
|
7ce5cf1595 | ||
|
|
7e3fc1db03 | ||
|
|
77279984a5 | ||
|
|
669a392fcd | ||
|
|
51ce0b038a | ||
|
|
bd244e6865 | ||
|
|
a70ecba06f | ||
|
|
9d2d5cfcfe | ||
|
|
18f3c8ff9a | ||
|
|
895ec5564d | ||
|
|
7bb6f71f0b | ||
|
|
10e3f1a02b | ||
|
|
2a9d52871b | ||
|
|
c4fb5591ee | ||
|
|
c0ce1da4c3 | ||
|
|
aa27e714d4 | ||
|
|
6874f694e5 | ||
|
|
3690546795 | ||
|
|
7bc42d468b | ||
|
|
097999cad3 | ||
|
|
f82edaa7ec | ||
|
|
d8e8b796e7 | ||
|
|
900fd8cabc | ||
|
|
c20ac35074 | ||
|
|
255b8bf9ba | ||
|
|
ad6f17cd93 | ||
|
|
063a22ddf9 | ||
|
|
1d9cc01ae1 | ||
|
|
f31deb5010 | ||
|
|
0956d300c4 | ||
|
|
4ef490f3cb | ||
|
|
8f2a894b88 | ||
|
|
0e40543757 | ||
|
|
ce58f6d6be | ||
|
|
5aabb915ec | ||
|
|
0d9de01f9d | ||
|
|
f5b0eae9cd | ||
|
|
e6552064bf | ||
|
|
861cb552c4 | ||
|
|
417cceb0de | ||
|
|
165bd8cb71 | ||
|
|
e54e02dc77 | ||
|
|
2bf3b08d76 | ||
|
|
21b58b08b8 | ||
|
|
af530859f0 | ||
|
|
58739b0bf2 | ||
|
|
3e4c2fe712 | ||
|
|
bdfce25db0 | ||
|
|
2b6d9cd1e0 | ||
|
|
bf789dd7b3 | ||
|
|
9b6f01047c | ||
|
|
3fe2fa43bb | ||
|
|
ede982b50a | ||
|
|
319d775c13 | ||
|
|
44124319a6 | ||
|
|
462fd7539c | ||
|
|
f16e34b804 | ||
|
|
c3ccdc548e | ||
|
|
fd721ca480 | ||
|
|
eac365aef0 | ||
|
|
4de6266442 | ||
|
|
213d985e17 | ||
|
|
de76dcb8fb | ||
|
|
30fb6bde5e | ||
|
|
4f842a1248 | ||
|
|
cc4d455b8a | ||
|
|
0bb5efebfd | ||
|
|
b6bf7ae620 | ||
|
|
dc96cc6d1e | ||
|
|
642daf1a76 | ||
|
|
84edfb3d88 | ||
|
|
7e620bff81 | ||
|
|
0c55703438 | ||
|
|
6c57ad2226 | ||
|
|
9028fb5391 | ||
|
|
12dc49b60a | ||
|
|
7e1d20acdf | ||
|
|
5230104852 | ||
|
|
55be77be69 | ||
|
|
42b3a17356 | ||
|
|
4e1d79081c | ||
|
|
4ce4fdec71 | ||
|
|
05256946ac | ||
|
|
73396166aa | ||
|
|
4c5d5c7085 | ||
|
|
045a9e8b93 | ||
|
|
4419f0d54f | ||
|
|
b07aa00d5c | ||
|
|
e4f5df1306 | ||
|
|
dc62d60e9b | ||
|
|
71d8aeb4c2 | ||
|
|
0836f67d42 | ||
|
|
176a57a1e9 | ||
|
|
0d02355dbf | ||
|
|
6767d11c23 | ||
|
|
2dd9015dc6 | ||
|
|
217c10ddac | ||
|
|
822e4e7c44 | ||
|
|
0b1d01792d | ||
|
|
01637768cf | ||
|
|
6a8ae643d5 | ||
|
|
fd83d46ba0 | ||
|
|
914856342c | ||
|
|
91889fc14a | ||
|
|
7c8ec5a5ed | ||
|
|
effc6788eb | ||
|
|
f9daf27511 | ||
|
|
06f7387466 | ||
|
|
21e50eeff1 | ||
|
|
fd4cec93cd | ||
|
|
92f2055a6c | ||
|
|
be9b1198e9 | ||
|
|
56bea083f9 | ||
|
|
fdfc02ab96 | ||
|
|
fc7f042ad6 | ||
|
|
761c775043 | ||
|
|
b421c983d6 | ||
|
|
3036b58598 | ||
|
|
2eca43cd2d | ||
|
|
c24694233f | ||
|
|
423a7c4899 | ||
|
|
ee9e45b3d4 | ||
|
|
5a65188ca9 | ||
|
|
930080f556 | ||
|
|
8e7afb0ab3 | ||
|
|
138523570e | ||
|
|
82469ac0fd | ||
|
|
96cb5e10ed | ||
|
|
b224cab3e0 | ||
|
|
7381d7b92f | ||
|
|
dbef51ba05 | ||
|
|
c952dd8a6e | ||
|
|
b65ea64a58 | ||
|
|
542b5d18f1 | ||
|
|
71a0a42cfb | ||
|
|
ac011fe69f | ||
|
|
9e3d7a50e6 | ||
|
|
e33c2ad6a2 | ||
|
|
615f1072d9 | ||
|
|
f7b7a97407 | ||
|
|
ece6853e0f | ||
|
|
b7b03ee451 | ||
|
|
f9b48c0cad | ||
|
|
aa76603da9 | ||
|
|
b83b9825f8 | ||
|
|
d641972cde | ||
|
|
4d1333e124 | ||
|
|
35396e6410 | ||
|
|
8d18b39eee | ||
|
|
ae77893021 | ||
|
|
baeb180acd | ||
|
|
fd02ffb7bd | ||
|
|
62ecdce0b0 | ||
|
|
e4f2fad215 | ||
|
|
3f5f9bcaf0 | ||
|
|
08867b3cec | ||
|
|
9081feab51 | ||
|
|
cf992164f7 | ||
|
|
b27b821e7f | ||
|
|
d9ecaabac1 | ||
|
|
cd747d8175 | ||
|
|
df75fd2ec2 | ||
|
|
adcaf4cd46 | ||
|
|
81a77a9b88 | ||
|
|
6e805cd318 | ||
|
|
e11f25024e | ||
|
|
7c895f8a1b | ||
|
|
38bda7e1bb | ||
|
|
149db9a022 | ||
|
|
fed252bc49 | ||
|
|
61b2fd9816 | ||
|
|
5ad7a93750 | ||
|
|
2ec10012b6 | ||
|
|
e56c6cc291 | ||
|
|
4c9a929a14 | ||
|
|
71f8871702 | ||
|
|
6dc4ce6599 | ||
|
|
3a44cc7722 | ||
|
|
4cfed3c98f | ||
|
|
6af57ff026 | ||
|
|
2e3db9d56a | ||
|
|
f8d9fa87ed | ||
|
|
f53ad359a6 | ||
|
|
84de86beb5 | ||
|
|
04e7af2675 | ||
|
|
4f13a336b9 | ||
|
|
03508119e5 | ||
|
|
03e20138d3 | ||
|
|
dfcba36448 | ||
|
|
8e4a9a5c21 | ||
|
|
a1286e6f0e | ||
|
|
c0808246e5 | ||
|
|
ba051e10fb | ||
|
|
9fee0603b1 | ||
|
|
be8ebe6db9 | ||
|
|
548e3dc31c | ||
|
|
9440086d77 | ||
|
|
ec5a1bc71f | ||
|
|
9742fa731c | ||
|
|
91a3c538d9 | ||
|
|
e98485da3f | ||
|
|
6528a955fe | ||
|
|
431f77127e | ||
|
|
2cc58723cb | ||
|
|
268219d74e | ||
|
|
d09ed3e52e | ||
|
|
421d1f5490 | ||
|
|
66784b7122 | ||
|
|
54f2d99ce7 | ||
|
|
557c799ec9 | ||
|
|
d22a667095 | ||
|
|
30085a5342 | ||
|
|
304e6c4279 | ||
|
|
12458aae6f | ||
|
|
7e5d9683b1 | ||
|
|
210a4a957a | ||
|
|
131ad9b315 | ||
|
|
06b4cf57ab | ||
|
|
dbefdc923a | ||
|
|
37e45de9c1 | ||
|
|
5e63527190 | ||
|
|
0cc9026978 | ||
|
|
bb6a5441ed | ||
|
|
0ffda1bf29 | ||
|
|
56b5f77dc8 | ||
|
|
6eb284f99e | ||
|
|
34c2288fd0 | ||
|
|
304bb9f902 | ||
|
|
14be01880d | ||
|
|
12b7cf3cd4 | ||
|
|
0d7914bff7 | ||
|
|
d2285953d7 | ||
|
|
d2801505c3 | ||
|
|
9d62b4b9bb | ||
|
|
b65b723fa6 | ||
|
|
e05321356b | ||
|
|
0778959e98 | ||
|
|
76331d1c4a | ||
|
|
9e378ec5cf | ||
|
|
f57d33b17a | ||
|
|
c389e8dccb | ||
|
|
90c64a94d1 | ||
|
|
df27af6d1c | ||
|
|
c85b48f23e | ||
|
|
5a9f2b7750 | ||
|
|
fcfecc6e82 | ||
|
|
f863a927c1 | ||
|
|
cb4fbdfcd5 | ||
|
|
c6eacde55e | ||
|
|
daf780c7e6 | ||
|
|
613305d234 | ||
|
|
656432301d | ||
|
|
38a80f2816 | ||
|
|
6563133426 | ||
|
|
762474d3ac | ||
|
|
b1adbcc77c | ||
|
|
dda052da20 | ||
|
|
2d6bdbc1b1 | ||
|
|
0600856167 | ||
|
|
ce47b57b03 | ||
|
|
f3c916ab96 | ||
|
|
ca6fa6d1d7 | ||
|
|
fcd37b52b6 |
@@ -83,3 +83,6 @@
|
|||||||
|
|
||||||
# Parentheses can make the code clearer
|
# Parentheses can make the code clearer
|
||||||
--ignore UNNECESSARY_PARENTHESES
|
--ignore UNNECESSARY_PARENTHESES
|
||||||
|
|
||||||
|
# We don't have `fallthrough;` */
|
||||||
|
--ignore PREFER_FALLTHROUGH
|
||||||
|
|||||||
@@ -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
|
||||||
@@ -0,0 +1,9 @@
|
|||||||
|
[*]
|
||||||
|
root = true
|
||||||
|
indent_style = tab
|
||||||
|
indent_size = tab
|
||||||
|
tab_width = 8
|
||||||
|
charset = utf-8
|
||||||
|
insert_final_newline = true
|
||||||
|
trim_trailing_whitespace = true
|
||||||
|
end_of_line = lf
|
||||||
@@ -0,0 +1,2 @@
|
|||||||
|
# Shell scripts need Unix line endings (see https://github.com/gbdev/rgbds/issues/841)
|
||||||
|
*.sh text eol=lf
|
||||||
@@ -0,0 +1,3 @@
|
|||||||
|
github: avivace
|
||||||
|
patreon: gbdev01
|
||||||
|
open_collective: gbdev
|
||||||
@@ -7,6 +7,14 @@
|
|||||||
sub(/b><\/td/, "th");
|
sub(/b><\/td/, "th");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# The whole page is being generated, so it's not meant to contain any Liquid
|
||||||
|
BEGIN {
|
||||||
|
print "{% raw %}"
|
||||||
|
}
|
||||||
|
END {
|
||||||
|
print "{% endraw %}"
|
||||||
|
}
|
||||||
|
|
||||||
BEGIN {
|
BEGIN {
|
||||||
in_synopsis = 0
|
in_synopsis = 0
|
||||||
}
|
}
|
||||||
@@ -38,48 +46,11 @@ BEGIN {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/<div class="Nd">/ {
|
|
||||||
# Make the description blurb inline, as with terminal output
|
|
||||||
gsub(/div/, "span")
|
|
||||||
}
|
|
||||||
|
|
||||||
BEGIN {
|
|
||||||
pages["gbz80", 7] = 1
|
|
||||||
pages["rgbds", 5] = 1
|
|
||||||
pages["rgbds", 7] = 1
|
|
||||||
pages["rgbasm", 1] = 1
|
|
||||||
pages["rgbasm", 5] = 1
|
|
||||||
pages["rgblink",1] = 1
|
|
||||||
pages["rgblink",5] = 1
|
|
||||||
pages["rgbfix", 1] = 1
|
|
||||||
pages["rgbgfx", 1] = 1
|
|
||||||
}
|
|
||||||
/<a class="Xr">/ {
|
|
||||||
# Link to other pages in the doc
|
|
||||||
for (i in pages) {
|
|
||||||
split(i, page, SUBSEP)
|
|
||||||
name = page[1]
|
|
||||||
section = page[2]
|
|
||||||
gsub(sprintf("<a class=\"Xr\">%s\\(%d\\)", name, section),
|
|
||||||
sprintf("<a class=\"Xr\" href=\"%s.%d.html\">%s(%d)", name, section, name, section))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
{
|
{
|
||||||
# Make long opts (defined using `Fl Fl`) into a single tag
|
# Make long opts (defined using `Fl Fl`) into a single tag
|
||||||
gsub(/<code class="Fl">-<\/code><code class="Fl">/, "<code class=\"Fl\">-")
|
gsub(/<code class="Fl">-<\/code>\s*<code class="Fl">/, "<code class=\"Fl\">-")
|
||||||
}
|
}
|
||||||
|
|
||||||
{
|
{
|
||||||
print
|
print
|
||||||
}
|
}
|
||||||
|
|
||||||
/<head>/ {
|
|
||||||
# Add viewport size <meta> tag for mobile users
|
|
||||||
print " <meta name=\"viewport\" content=\"width=device-width, initial-scale=1\">"
|
|
||||||
}
|
|
||||||
|
|
||||||
/<link/ {
|
|
||||||
# Inject our own style overrides
|
|
||||||
print(" <link rel=\"stylesheet\" href=\"rgbds.css\" type=\"text/css\" media=\"all\"/>")
|
|
||||||
}
|
|
||||||
Executable
+113
@@ -0,0 +1,113 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
usage() {
|
||||||
|
cat <<EOF
|
||||||
|
Usage: $0 [-h] [-r] <rgbds-www> <version>
|
||||||
|
Copy renders from RGBDS repository to rgbds-www documentation
|
||||||
|
Execute from the root folder of the RGBDS repo, checked out at the desired tag
|
||||||
|
<rgbds-www> : Path to the rgbds-www repository
|
||||||
|
<version> : Version to be copied, such as 'v0.4.1' or 'master'
|
||||||
|
|
||||||
|
-h Display this help message
|
||||||
|
-r Update "latest stable" redirection pages and add a new entry to the index
|
||||||
|
(use for releases, not master)
|
||||||
|
EOF
|
||||||
|
}
|
||||||
|
|
||||||
|
is_release=0
|
||||||
|
bad_usage=0
|
||||||
|
while getopts ":hr" opt; do
|
||||||
|
case $opt in
|
||||||
|
r)
|
||||||
|
is_release=1
|
||||||
|
;;
|
||||||
|
h)
|
||||||
|
usage
|
||||||
|
exit 0
|
||||||
|
;;
|
||||||
|
\?)
|
||||||
|
echo "Unknown option '$OPTARG'"
|
||||||
|
bad_usage=1
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
done
|
||||||
|
if [ $bad_usage -ne 0 ]; then
|
||||||
|
usage
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
shift $(($OPTIND - 1))
|
||||||
|
|
||||||
|
|
||||||
|
declare -A PAGES
|
||||||
|
PAGES=(
|
||||||
|
[rgbasm.1.html]=src/asm/rgbasm.1
|
||||||
|
[rgbasm.5.html]=src/asm/rgbasm.5
|
||||||
|
[rgblink.1.html]=src/link/rgblink.1
|
||||||
|
[rgblink.5.html]=src/link/rgblink.5
|
||||||
|
[rgbfix.1.html]=src/fix/rgbfix.1
|
||||||
|
[rgbgfx.1.html]=src/gfx/rgbgfx.1
|
||||||
|
[rgbds.5.html]=src/rgbds.5
|
||||||
|
[rgbds.7.html]=src/rgbds.7
|
||||||
|
[gbz80.7.html]=src/gbz80.7
|
||||||
|
)
|
||||||
|
WWWPATH="/docs"
|
||||||
|
mkdir -p "$1/_documentation/$2"
|
||||||
|
|
||||||
|
# `mandoc` uses a different format for referring to man pages present in the **current** directory.
|
||||||
|
# We want that format for RGBDS man pages, and the other one for the rest;
|
||||||
|
# we thus need to copy all pages to a temporary directory, and process them there.
|
||||||
|
|
||||||
|
# Copy all pages to current dir
|
||||||
|
cp "${PAGES[@]}" .
|
||||||
|
|
||||||
|
for page in "${!PAGES[@]}"; do
|
||||||
|
stem="${page%.html}"
|
||||||
|
manpage="${stem%.?}(${stem#*.})"
|
||||||
|
descr="$(awk -v 'FS=.Nd ' '/.Nd/ { print $2; }' "${PAGES[$page]}")"
|
||||||
|
|
||||||
|
cat >"$1/_documentation/$2/$page" <<EOF
|
||||||
|
---
|
||||||
|
layout: doc
|
||||||
|
title: $manpage [$2]
|
||||||
|
description: RGBDS $2 — $descr
|
||||||
|
---
|
||||||
|
EOF
|
||||||
|
options=fragment,man='%N.%S;https://linux.die.net/man/%S/%N'
|
||||||
|
if [ $stem = rgbasm.5 ]; then
|
||||||
|
options+=,toc
|
||||||
|
fi
|
||||||
|
mandoc -Thtml -I os=Linux -O$options "${PAGES[$page]##*/}" | .github/actions/doc_postproc.awk >> "$1/_documentation/$2/$page"
|
||||||
|
groff -Tpdf -mdoc -wall "${PAGES[$page]##*/}" >"$1/_documentation/$2/$stem.pdf"
|
||||||
|
if [ $is_release -ne 0 ]; then
|
||||||
|
cat - >"$1/_documentation/$page" <<EOF
|
||||||
|
---
|
||||||
|
redirect_to: $WWWPATH/$2/${page%.html}
|
||||||
|
permalink: $WWWPATH/${page%.html}/
|
||||||
|
title: $manpage [latest stable]
|
||||||
|
description: RGBDS latest stable — $descr
|
||||||
|
---
|
||||||
|
EOF
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
|
||||||
|
cat - >"$1/_documentation/$2/index.html" <<EOF
|
||||||
|
---
|
||||||
|
layout: doc_index
|
||||||
|
permalink: /docs/$2/
|
||||||
|
title: RGBDS online manual [$2]
|
||||||
|
description: RGBDS $2 - Online manual
|
||||||
|
---
|
||||||
|
EOF
|
||||||
|
|
||||||
|
|
||||||
|
# If making a release, add a new entry right after `master`
|
||||||
|
if [ $is_release -ne 0 ]; then
|
||||||
|
awk '{ print }
|
||||||
|
/"name": "master"/ { print "\t\t{\"name\": \"'$2'\", \"text\": \"'$2'\" }," }
|
||||||
|
' "$1/_data/doc.json" >"$1/_data/doc.json.tmp"
|
||||||
|
mv "$1/_data/doc.json"{.tmp,}
|
||||||
|
fi
|
||||||
|
|
||||||
|
|
||||||
|
# Clean up
|
||||||
|
rm "${PAGES[@]##*/}"
|
||||||
@@ -1,14 +1,21 @@
|
|||||||
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
|
||||||
;;
|
;;
|
||||||
macos)
|
macos)
|
||||||
brew install libpng pkg-config md5sha1sum
|
brew install bison libpng pkg-config md5sha1sum
|
||||||
|
# For the version check below exclusively, re-do this before building
|
||||||
|
export PATH="/usr/local/opt/bison/bin:$PATH"
|
||||||
;;
|
;;
|
||||||
*)
|
*)
|
||||||
echo "WARNING: Cannot install deps for OS '$1'"
|
echo "WARNING: Cannot install deps for OS '$1'"
|
||||||
;;
|
;;
|
||||||
esac
|
esac
|
||||||
|
|
||||||
yacc --version
|
bison --version
|
||||||
|
make --version
|
||||||
|
cmake --version
|
||||||
|
|||||||
@@ -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
|
||||||
@@ -5,13 +5,21 @@ jobs:
|
|||||||
checkpatch:
|
checkpatch:
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v2
|
- 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: Set up checkpatch
|
- name: Set up checkpatch
|
||||||
|
working-directory: rgbds
|
||||||
run: |
|
run: |
|
||||||
wget 'https://raw.githubusercontent.com/torvalds/linux/master/scripts/checkpatch.pl'
|
wget 'https://raw.githubusercontent.com/torvalds/linux/master/scripts/checkpatch.pl'
|
||||||
chmod +x checkpatch.pl
|
chmod +x checkpatch.pl
|
||||||
touch const_structs.checkpatch
|
wget 'https://raw.githubusercontent.com/torvalds/linux/master/scripts/const_structs.checkpatch'
|
||||||
touch spelling.txt
|
wget 'https://raw.githubusercontent.com/torvalds/linux/master/scripts/spelling.txt'
|
||||||
- name: Checkpatch
|
- name: Checkpatch
|
||||||
|
working-directory: rgbds
|
||||||
run: |
|
run: |
|
||||||
make checkpatch CHECKPATCH=./checkpatch.pl BASE_REF=${{ github.base_ref }} Q=
|
make checkpatch CHECKPATCH=./checkpatch.pl "BASE_REF=${{ github.event.pull_request.base.sha }}" Q= | tee log
|
||||||
|
if grep -q ERROR: log; then exit 1; else exit 0; fi
|
||||||
|
|||||||
@@ -0,0 +1,96 @@
|
|||||||
|
name: "Create release artifacts"
|
||||||
|
on:
|
||||||
|
push:
|
||||||
|
tags:
|
||||||
|
- v[0-9]*
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
windows:
|
||||||
|
runs-on: windows-2019
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v2
|
||||||
|
- name: Get version from tag
|
||||||
|
shell: bash
|
||||||
|
run: | # Turn "refs/tags/vX.Y.Z" into "X.Y.Z"
|
||||||
|
VERSION="${{ github.ref }}"
|
||||||
|
echo "version=${VERSION##*/v}" >> $GITHUB_ENV
|
||||||
|
- name: Get zlib, libpng and bison
|
||||||
|
run: | # TODO: use an array
|
||||||
|
$wc = New-Object System.Net.WebClient
|
||||||
|
$wc.DownloadFile('https://www.zlib.net/zlib1212.zip', 'zlib.zip')
|
||||||
|
$hash = (Get-FileHash "zlib.zip" -Algorithm SHA256).Hash
|
||||||
|
if ($hash -ne '173e89893dcb8b4a150d7731cd72f0602f1d6b45e60e2a54efdf7f3fc3325fd7') {
|
||||||
|
Write-Host "zlib SHA256 mismatch! ($hash)"
|
||||||
|
exit 1
|
||||||
|
}
|
||||||
|
$wc.DownloadFile('https://download.sourceforge.net/libpng/lpng1637.zip', 'libpng.zip')
|
||||||
|
$hash = (Get-FileHash "libpng.zip" -Algorithm SHA256).Hash
|
||||||
|
if ($hash -ne '3b4b1cbd0bae6822f749d39b1ccadd6297f05e2b85a83dd2ce6ecd7d09eabdf2') {
|
||||||
|
Write-Host "libpng SHA256 mismatch! ($hash)"
|
||||||
|
exit 1
|
||||||
|
}
|
||||||
|
$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
|
||||||
|
if ($hash -ne '39c6086ce211d5415500acc5ed2d8939861ca1696aee48909c7f6daf5122b505') {
|
||||||
|
Write-Host "bison SHA256 mismatch! ($hash)"
|
||||||
|
}
|
||||||
|
Expand-Archive -DestinationPath . "zlib.zip"
|
||||||
|
Expand-Archive -DestinationPath . "libpng.zip"
|
||||||
|
Expand-Archive -DestinationPath install_dir "winflexbison.zip"
|
||||||
|
Move-Item zlib-1.2.12 zlib
|
||||||
|
Move-Item lpng1637 libpng
|
||||||
|
- name: Build 32-bit zlib
|
||||||
|
run: | # BUILD_SHARED_LIBS causes the output DLL to be correctly called `zlib1.dll`
|
||||||
|
cmake -S zlib -B zbuild32 -A Win32 -DCMAKE_INSTALL_PREFIX=install_dir -DBUILD_SHARED_LIBS=ON
|
||||||
|
cmake --build zbuild32 --config Release
|
||||||
|
cmake --install zbuild32
|
||||||
|
- name: Build 32-bit libpng
|
||||||
|
run: |
|
||||||
|
cmake -S libpng -B pngbuild32 -A Win32 -DCMAKE_INSTALL_PREFIX=install_dir -DPNG_SHARED=ON -DPNG_STATIC=ON -DPNG_TESTS=OFF
|
||||||
|
cmake --build pngbuild32 --config Release
|
||||||
|
cmake --install pngbuild32
|
||||||
|
- name: Build 32-bit Windows binaries
|
||||||
|
run: |
|
||||||
|
cmake -S . -B build32 -A Win32 -DCMAKE_INSTALL_PREFIX=install_dir -DCMAKE_BUILD_TYPE=Release
|
||||||
|
cmake --build build32 --config Release
|
||||||
|
cmake --install build32
|
||||||
|
- name: Package 32-bit binaries
|
||||||
|
run: |
|
||||||
|
Compress-Archive -LiteralPath @("install_dir/bin/rgbasm.exe", "install_dir/bin/rgblink.exe", "install_dir/bin/rgbfix.exe", "install_dir/bin/rgbgfx.exe", "install_dir/bin/zlib1.dll", "install_dir/bin/libpng16.dll") "rgbds-${{ env.version }}-win32.zip"
|
||||||
|
- name: Build 64-bit zlib
|
||||||
|
run: | # BUILD_SHARED_LIBS causes the output DLL to be correctly called `zlib1.dll`
|
||||||
|
cmake -S zlib -B zbuild64 -A x64 -DCMAKE_INSTALL_PREFIX=install_dir -DBUILD_SHARED_LIBS=ON
|
||||||
|
cmake --build zbuild64 --config Release
|
||||||
|
cmake --install zbuild64
|
||||||
|
- name: Build 64-bit libpng
|
||||||
|
run: |
|
||||||
|
cmake -S libpng -B pngbuild64 -A x64 -DCMAKE_INSTALL_PREFIX=install_dir -DPNG_SHARED=ON -DPNG_STATIC=ON -DPNG_TESTS=OFF
|
||||||
|
cmake --build pngbuild64 --config Release
|
||||||
|
cmake --install pngbuild64
|
||||||
|
- name: Build 64-bit Windows binaries
|
||||||
|
run: |
|
||||||
|
cmake -S . -B build64 -A x64 -DCMAKE_INSTALL_PREFIX=install_dir -DCMAKE_BUILD_TYPE=Release
|
||||||
|
cmake --build build64 --config Release
|
||||||
|
cmake --install build64
|
||||||
|
- name: Package 64-bit binaries
|
||||||
|
run: |
|
||||||
|
Compress-Archive -LiteralPath @("install_dir/bin/rgbasm.exe", "install_dir/bin/rgblink.exe", "install_dir/bin/rgbfix.exe", "install_dir/bin/rgbgfx.exe", "install_dir/bin/zlib1.dll", "install_dir/bin/libpng16.dll") "rgbds-${{ env.version }}-win64.zip"
|
||||||
|
- name: Package sources
|
||||||
|
run: |
|
||||||
|
make dist
|
||||||
|
- name: Release
|
||||||
|
uses: softprops/action-gh-release@v1
|
||||||
|
with:
|
||||||
|
body: |
|
||||||
|
Please ensure that the three assets below work properly.
|
||||||
|
Once that's done, replace this text with the changelog, un-draft the release, and update the `release` branch.
|
||||||
|
By the way, if you forgot to update `include/version.h`, RGBASM's version test is gonna fail in the tag's regression testing! (Use `git push --delete origin <tag>` to delete it)
|
||||||
|
draft: true # Don't publish the release quite yet...
|
||||||
|
prerelease: ${{ contains(github.ref, '-rc') }}
|
||||||
|
files: |
|
||||||
|
rgbds-${{ env.version }}-win32.zip
|
||||||
|
rgbds-${{ env.version }}-win64.zip
|
||||||
|
rgbds-${{ env.version }}.tar.gz
|
||||||
|
fail_on_unmatched_files: true
|
||||||
|
env:
|
||||||
|
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||||
@@ -0,0 +1,53 @@
|
|||||||
|
name: "Create release docs"
|
||||||
|
on:
|
||||||
|
release:
|
||||||
|
types:
|
||||||
|
- released # This avoids triggering on pre-releases
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
build:
|
||||||
|
if: github.repository_owner == 'gbdev'
|
||||||
|
runs-on: ubuntu-18.04
|
||||||
|
steps:
|
||||||
|
- name: Checkout rgbds@release
|
||||||
|
uses: actions/checkout@v2
|
||||||
|
with:
|
||||||
|
path: rgbds
|
||||||
|
- name: Checkout rgbds-www@master
|
||||||
|
uses: actions/checkout@v2
|
||||||
|
with:
|
||||||
|
repository: ${{ github.repository_owner }}/rgbds-www
|
||||||
|
path: rgbds-www
|
||||||
|
# `-O toc` was added in 1.14.5, but the repos only have 1.14.4
|
||||||
|
- name: Build and install mandoc + install groff
|
||||||
|
run: |
|
||||||
|
sudo apt-get -qq update
|
||||||
|
sudo apt-get install -yq groff zlib1g-dev
|
||||||
|
wget 'http://mandoc.bsd.lv/snapshots/mandoc-1.14.5.tar.gz'
|
||||||
|
tar xf mandoc-1.14.5.tar.gz
|
||||||
|
cd mandoc-1.14.5
|
||||||
|
./configure
|
||||||
|
make
|
||||||
|
sudo make install
|
||||||
|
- name: Update pages
|
||||||
|
working-directory: rgbds
|
||||||
|
run: | # The ref appears to be in the format "refs/tags/<version>", so strip that
|
||||||
|
./.github/actions/get-pages.sh -r ../rgbds-www ${GITHUB_REF##*/}
|
||||||
|
- name: Push new pages
|
||||||
|
working-directory: rgbds-www
|
||||||
|
run: |
|
||||||
|
mkdir -p -m 700 ~/.ssh
|
||||||
|
cat > ~/.ssh/id_ed25519 <<<"${{ secrets.SSH_KEY_SECRET }}"
|
||||||
|
chmod 0600 ~/.ssh/id_ed25519
|
||||||
|
eval $(ssh-agent -s)
|
||||||
|
ssh-add ~/.ssh/id_ed25519
|
||||||
|
git config --global user.name "GitHub Action"
|
||||||
|
git config --global user.email "[email protected]"
|
||||||
|
git add -A
|
||||||
|
git commit -m "Create RGBDS ${GITHUB_REF##*/} documentation"
|
||||||
|
if git remote | grep -q origin; then
|
||||||
|
git remote set-url origin [email protected]:${{ github.repository_owner }}/rgbds-www.git
|
||||||
|
else
|
||||||
|
git remote add origin [email protected]:${{ github.repository_owner }}/rgbds-www.git
|
||||||
|
fi
|
||||||
|
git push origin master
|
||||||
+107
-17
@@ -1,16 +1,22 @@
|
|||||||
name: "Regression testing"
|
name: "Regression testing"
|
||||||
on: push
|
on:
|
||||||
|
- push
|
||||||
|
- pull_request
|
||||||
|
|
||||||
jobs:
|
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]
|
||||||
include:
|
buildsys: [make, cmake]
|
||||||
- os: ubuntu-18.04
|
exclude:
|
||||||
|
# `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
|
||||||
|
cc: gcc
|
||||||
|
fail-fast: false
|
||||||
runs-on: ${{ matrix.os }}
|
runs-on: ${{ matrix.os }}
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v2
|
- uses: actions/checkout@v2
|
||||||
@@ -18,12 +24,23 @@ jobs:
|
|||||||
shell: bash
|
shell: bash
|
||||||
run: |
|
run: |
|
||||||
./.github/actions/install_deps.sh ${{ matrix.os }}
|
./.github/actions/install_deps.sh ${{ matrix.os }}
|
||||||
- name: Build
|
# The `export` lines are to allow working on macOS...
|
||||||
run: |
|
# Apple's base version is severely outdated, not even supporting -Wall,
|
||||||
make ${{ matrix.target }} -j Q= CC=${{ matrix.cc }}
|
# but it overrides Homebrew's version nonetheless...
|
||||||
- name: Install
|
- name: Build & install using Make
|
||||||
run: |
|
run: |
|
||||||
|
export PATH="/usr/local/opt/bison/bin:$PATH"
|
||||||
|
make develop -j Q= CC=${{ matrix.cc }}
|
||||||
sudo make install -j Q=
|
sudo make install -j Q=
|
||||||
|
if: matrix.buildsys == 'make'
|
||||||
|
- name: Build & install using CMake
|
||||||
|
run: |
|
||||||
|
export PATH="/usr/local/opt/bison/bin:$PATH"
|
||||||
|
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 -j
|
||||||
|
cp build/src/rgb{asm,link,fix,gfx} .
|
||||||
|
sudo cmake --install build
|
||||||
|
if: matrix.buildsys == 'cmake'
|
||||||
- name: Package binaries
|
- name: Package binaries
|
||||||
run: |
|
run: |
|
||||||
mkdir bins
|
mkdir bins
|
||||||
@@ -31,18 +48,89 @@ jobs:
|
|||||||
- name: Upload binaries
|
- name: Upload binaries
|
||||||
uses: actions/upload-artifact@v1
|
uses: actions/upload-artifact@v1
|
||||||
with:
|
with:
|
||||||
name: rgbds-canary-${{ matrix.os }}-${{ matrix.cc }}
|
name: rgbds-canary-${{ matrix.os }}-${{ matrix.cc }}-${{ matrix.buildsys }}
|
||||||
path: bins
|
path: bins
|
||||||
- name: Test
|
- name: Test
|
||||||
shell: bash
|
shell: bash
|
||||||
run: |
|
run: |
|
||||||
test/run-tests.sh
|
test/run-tests.sh
|
||||||
|
|
||||||
windows-build:
|
windows-testing:
|
||||||
strategy:
|
strategy:
|
||||||
matrix:
|
matrix:
|
||||||
bits: [32, 64]
|
bits: [32, 64]
|
||||||
os: [ubuntu-latest]
|
include:
|
||||||
|
- bits: 32
|
||||||
|
arch: x86
|
||||||
|
platform: Win32
|
||||||
|
- bits: 64
|
||||||
|
arch: x86_x64
|
||||||
|
platform: x64
|
||||||
|
fail-fast: false
|
||||||
|
runs-on: windows-2019
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v2
|
||||||
|
- name: Get zlib, libpng and bison
|
||||||
|
run: | # TODO: use an array
|
||||||
|
$wc = New-Object System.Net.WebClient
|
||||||
|
$wc.DownloadFile('https://www.zlib.net/zlib1212.zip', 'zlib.zip')
|
||||||
|
$hash = (Get-FileHash "zlib.zip" -Algorithm SHA256).Hash
|
||||||
|
if ($hash -ne '173e89893dcb8b4a150d7731cd72f0602f1d6b45e60e2a54efdf7f3fc3325fd7') {
|
||||||
|
Write-Host "zlib SHA256 mismatch! ($hash)"
|
||||||
|
exit 1
|
||||||
|
}
|
||||||
|
$wc.DownloadFile('https://download.sourceforge.net/libpng/lpng1637.zip', 'libpng.zip')
|
||||||
|
$hash = (Get-FileHash "libpng.zip" -Algorithm SHA256).Hash
|
||||||
|
if ($hash -ne '3b4b1cbd0bae6822f749d39b1ccadd6297f05e2b85a83dd2ce6ecd7d09eabdf2') {
|
||||||
|
Write-Host "libpng SHA256 mismatch! ($hash)"
|
||||||
|
exit 1
|
||||||
|
}
|
||||||
|
$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
|
||||||
|
if ($hash -ne '39c6086ce211d5415500acc5ed2d8939861ca1696aee48909c7f6daf5122b505') {
|
||||||
|
Write-Host "bison SHA256 mismatch! ($hash)"
|
||||||
|
}
|
||||||
|
Expand-Archive -DestinationPath . "zlib.zip"
|
||||||
|
Expand-Archive -DestinationPath . "libpng.zip"
|
||||||
|
Expand-Archive -DestinationPath install_dir "winflexbison.zip"
|
||||||
|
Move-Item zlib-1.2.12 zlib
|
||||||
|
Move-Item lpng1637 libpng
|
||||||
|
- name: Build zlib
|
||||||
|
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 --build zbuild --config Release -j
|
||||||
|
cmake --install zbuild
|
||||||
|
- name: Build libpng
|
||||||
|
run: |
|
||||||
|
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 -j
|
||||||
|
cmake --install pngbuild
|
||||||
|
- name: Build Windows binaries
|
||||||
|
run: |
|
||||||
|
cmake -S . -B build -A ${{ matrix.platform }} -DCMAKE_INSTALL_PREFIX=install_dir -DCMAKE_BUILD_TYPE=Release
|
||||||
|
cmake --build build --config Release -j
|
||||||
|
cmake --install build
|
||||||
|
- name: Package binaries
|
||||||
|
shell: bash
|
||||||
|
run: |
|
||||||
|
mkdir bins
|
||||||
|
cp install_dir/bin/{rgbasm.exe,rgblink.exe,rgbfix.exe,rgbgfx.exe,zlib1.dll,libpng16.dll} bins
|
||||||
|
- name: Upload Windows binaries
|
||||||
|
uses: actions/upload-artifact@v1
|
||||||
|
with:
|
||||||
|
name: rgbds-canary-win${{ matrix.bits }}
|
||||||
|
path: bins
|
||||||
|
- name: Test
|
||||||
|
shell: bash
|
||||||
|
run: |
|
||||||
|
cp bins/* .
|
||||||
|
test/run-tests.sh
|
||||||
|
|
||||||
|
windows-xbuild:
|
||||||
|
strategy:
|
||||||
|
matrix:
|
||||||
|
bits: [32, 64]
|
||||||
|
os: [ubuntu-18.04]
|
||||||
include:
|
include:
|
||||||
- bits: 32
|
- bits: 32
|
||||||
arch: i686
|
arch: i686
|
||||||
@@ -50,6 +138,7 @@ jobs:
|
|||||||
- bits: 64
|
- bits: 64
|
||||||
arch: x86-64
|
arch: x86-64
|
||||||
triplet: x86_64-w64-mingw32
|
triplet: x86_64-w64-mingw32
|
||||||
|
fail-fast: false
|
||||||
runs-on: ${{ matrix.os }}
|
runs-on: ${{ matrix.os }}
|
||||||
env:
|
env:
|
||||||
DIST_DIR: win${{ matrix.bits }}
|
DIST_DIR: win${{ matrix.bits }}
|
||||||
@@ -65,7 +154,7 @@ jobs:
|
|||||||
- name: Install libpng dev headers for MinGW
|
- name: Install libpng dev headers for MinGW
|
||||||
run: |
|
run: |
|
||||||
sudo ./.github/actions/mingw-w64-libpng-dev.sh ${{ matrix.triplet }}
|
sudo ./.github/actions/mingw-w64-libpng-dev.sh ${{ matrix.triplet }}
|
||||||
- name: Build Windows binaries
|
- name: Cross-build Windows binaries
|
||||||
run: |
|
run: |
|
||||||
make mingw${{ matrix.bits }} -j Q=
|
make mingw${{ matrix.bits }} -j Q=
|
||||||
- name: Package binaries
|
- name: Package binaries
|
||||||
@@ -81,21 +170,22 @@ jobs:
|
|||||||
- name: Upload Windows binaries
|
- name: Upload Windows binaries
|
||||||
uses: actions/upload-artifact@v1
|
uses: actions/upload-artifact@v1
|
||||||
with:
|
with:
|
||||||
name: rgbds-canary-win${{ matrix.bits }}
|
name: rgbds-canary-mingw-win${{ matrix.bits }}
|
||||||
path: bins
|
path: bins
|
||||||
|
|
||||||
windows-testing:
|
windows-xtesting:
|
||||||
needs: windows-build
|
needs: windows-xbuild
|
||||||
strategy:
|
strategy:
|
||||||
matrix:
|
matrix:
|
||||||
bits: [32, 64]
|
bits: [32, 64]
|
||||||
|
fail-fast: false
|
||||||
runs-on: windows-2019
|
runs-on: windows-2019
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v2
|
- uses: actions/checkout@v2
|
||||||
- name: Retrieve binaries
|
- name: Retrieve binaries
|
||||||
uses: actions/download-artifact@v1
|
uses: actions/download-artifact@v1
|
||||||
with:
|
with:
|
||||||
name: rgbds-canary-win${{ matrix.bits }}
|
name: rgbds-canary-mingw-win${{ matrix.bits }}
|
||||||
path: bins
|
path: bins
|
||||||
- name: Extract binaries
|
- name: Extract binaries
|
||||||
shell: bash
|
shell: bash
|
||||||
|
|||||||
@@ -0,0 +1,66 @@
|
|||||||
|
name: "Update master docs"
|
||||||
|
on:
|
||||||
|
push:
|
||||||
|
branches:
|
||||||
|
- master
|
||||||
|
paths:
|
||||||
|
- .github/actions/get-pages.sh
|
||||||
|
- src/gbz80.7
|
||||||
|
- src/rgbds.5
|
||||||
|
- src/rgbds.7
|
||||||
|
- src/asm/rgbasm.1
|
||||||
|
- src/asm/rgbasm.5
|
||||||
|
- src/link/rgblink.1
|
||||||
|
- src/link/rgblink.5
|
||||||
|
- src/fix/rgbfix.1
|
||||||
|
- src/gfx/rgbgfx.1
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
build:
|
||||||
|
if: github.repository_owner == 'gbdev'
|
||||||
|
runs-on: ubuntu-18.04
|
||||||
|
steps:
|
||||||
|
- name: Checkout rgbds@master
|
||||||
|
uses: actions/checkout@v2
|
||||||
|
with:
|
||||||
|
repository: gbdev/rgbds
|
||||||
|
ref: master
|
||||||
|
path: rgbds
|
||||||
|
- name: Checkout rgbds-www@master
|
||||||
|
uses: actions/checkout@v2
|
||||||
|
with:
|
||||||
|
repository: gbdev/rgbds-www
|
||||||
|
ref: master
|
||||||
|
path: rgbds-www
|
||||||
|
- name: Build and install mandoc + install groff
|
||||||
|
run: |
|
||||||
|
sudo apt-get -qq update
|
||||||
|
sudo apt-get install -yq groff zlib1g-dev
|
||||||
|
wget 'http://mandoc.bsd.lv/snapshots/mandoc-1.14.5.tar.gz'
|
||||||
|
tar xf mandoc-1.14.5.tar.gz
|
||||||
|
cd mandoc-1.14.5
|
||||||
|
./configure
|
||||||
|
make
|
||||||
|
sudo make install
|
||||||
|
- name: Update pages
|
||||||
|
working-directory: rgbds
|
||||||
|
run: |
|
||||||
|
./.github/actions/get-pages.sh ../rgbds-www master
|
||||||
|
- name: Push new pages
|
||||||
|
working-directory: rgbds-www
|
||||||
|
run: |
|
||||||
|
mkdir -p -m 700 ~/.ssh
|
||||||
|
echo "${{ secrets.SSH_KEY_SECRET }}" > ~/.ssh/id_ed25519
|
||||||
|
chmod 0600 ~/.ssh/id_ed25519
|
||||||
|
eval $(ssh-agent -s)
|
||||||
|
ssh-add ~/.ssh/id_ed25519
|
||||||
|
git config --global user.name "GitHub Action"
|
||||||
|
git config --global user.email "[email protected]"
|
||||||
|
git add .
|
||||||
|
git commit -m "Update RGBDS master documentation"
|
||||||
|
if git remote | grep -q origin; then
|
||||||
|
git remote set-url origin [email protected]:gbdev/rgbds-www.git
|
||||||
|
else
|
||||||
|
git remote add origin [email protected]:gbdev/rgbds-www.git
|
||||||
|
fi
|
||||||
|
git push origin master
|
||||||
+7
-10
@@ -1,15 +1,12 @@
|
|||||||
rgbasm
|
/rgbasm
|
||||||
rgblink
|
/rgblink
|
||||||
rgbfix
|
/rgbfix
|
||||||
rgbgfx
|
/rgbgfx
|
||||||
rgbshim.sh
|
/rgbshim.sh
|
||||||
*.o
|
*.o
|
||||||
*.exe
|
*.exe
|
||||||
|
*.dll
|
||||||
.checkpatch-camelcase.*
|
.checkpatch-camelcase.*
|
||||||
CMakeCache.txt
|
CMakeCache.txt
|
||||||
CMakeFiles
|
CMakeFiles/
|
||||||
cmake_install.cmake
|
cmake_install.cmake
|
||||||
|
|
||||||
test/pokecrystal
|
|
||||||
test/pokered
|
|
||||||
test/ucity
|
|
||||||
|
|||||||
+68
-40
@@ -6,35 +6,11 @@
|
|||||||
# SPDX-License-Identifier: MIT
|
# SPDX-License-Identifier: MIT
|
||||||
#
|
#
|
||||||
|
|
||||||
cmake_minimum_required(VERSION 2.8.8)
|
# 3.9 required for LTO checks
|
||||||
|
cmake_minimum_required(VERSION 3.9 FATAL_ERROR)
|
||||||
|
|
||||||
cmake_policy(VERSION ${CMAKE_MAJOR_VERSION}.${CMAKE_MINOR_VERSION})
|
project(rgbds
|
||||||
|
LANGUAGES C)
|
||||||
set(RGBDS_VER 0.4.1)
|
|
||||||
set(RGBDS_DESC "Rednex Game Boy Development System")
|
|
||||||
|
|
||||||
if(CMAKE_VERSION VERSION_LESS 3.0)
|
|
||||||
project(rgbds C)
|
|
||||||
set(PROJECT_VERSION "${RGBDS_VER}")
|
|
||||||
else()
|
|
||||||
if(CMAKE_VERSION VERSION_LESS 3.9)
|
|
||||||
project(rgbds VERSION "${RGBDS_VER}"
|
|
||||||
LANGUAGES C)
|
|
||||||
else()
|
|
||||||
project(rgbds VERSION "${RGBDS_VER}"
|
|
||||||
DESCRIPTION "${RGBDS_DESC}"
|
|
||||||
LANGUAGES C)
|
|
||||||
endif()
|
|
||||||
endif()
|
|
||||||
|
|
||||||
if(CMAKE_VERSION VERSION_LESS 3.9)
|
|
||||||
set(PROJECT_DESCRIPTION "${RGBDS_DESC}")
|
|
||||||
endif()
|
|
||||||
|
|
||||||
set(DEFAULT_BUILD_TYPE "Release")
|
|
||||||
if(NOT CMAKE_BUILD_TYPE)
|
|
||||||
set(CMAKE_BUILD_TYPE "${DEFAULT_BUILD_TYPE}")
|
|
||||||
endif()
|
|
||||||
|
|
||||||
# get real path of source and binary directories
|
# get real path of source and binary directories
|
||||||
get_filename_component(srcdir "${CMAKE_SOURCE_DIR}" REALPATH)
|
get_filename_component(srcdir "${CMAKE_SOURCE_DIR}" REALPATH)
|
||||||
@@ -47,25 +23,77 @@ if(srcdir STREQUAL bindir)
|
|||||||
message(FATAL_ERROR "Terminating configuration")
|
message(FATAL_ERROR "Terminating configuration")
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
find_package(PNG 1.2 REQUIRED)
|
option(SANITIZERS "Build with sanitizers enabled" OFF) # Ignored on MSVC
|
||||||
find_package(BISON REQUIRED)
|
option(MORE_WARNINGS "Turn on more warnings" OFF) # Ignored on MSVC
|
||||||
find_package(FLEX)
|
|
||||||
|
|
||||||
include_directories("${PROJECT_SOURCE_DIR}/include")
|
|
||||||
|
|
||||||
if(MSVC)
|
if(MSVC)
|
||||||
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /W1 /MP -D_CRT_SECURE_NO_WARNINGS")
|
# MSVC's standard library triggers warning C5105,
|
||||||
|
# "macro expansion producing 'defined' has undefined behavior"
|
||||||
|
add_compile_options(/std:c11 /W1 /MP /wd5105)
|
||||||
|
add_definitions(/D_CRT_SECURE_NO_WARNINGS)
|
||||||
else()
|
else()
|
||||||
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall -pedantic")
|
add_compile_options(-Wall -pedantic)
|
||||||
|
add_definitions(-D_POSIX_C_SOURCE=200809L -D_ISOC11_SOURCE)
|
||||||
|
if(SANITIZERS)
|
||||||
|
set(SAN_FLAGS -fsanitize=shift -fsanitize=integer-divide-by-zero
|
||||||
|
-fsanitize=unreachable -fsanitize=vla-bound
|
||||||
|
-fsanitize=signed-integer-overflow -fsanitize=bounds
|
||||||
|
-fsanitize=object-size -fsanitize=bool -fsanitize=enum
|
||||||
|
-fsanitize=alignment -fsanitize=null -fsanitize=address)
|
||||||
|
add_compile_options(${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()
|
||||||
|
|
||||||
|
if(MORE_WARNINGS)
|
||||||
|
add_compile_options(-Werror -Wextra
|
||||||
|
-Walloc-zero -Wcast-align -Wcast-qual -Wduplicated-branches -Wduplicated-cond
|
||||||
|
-Wfloat-equal -Winline -Wlogical-op -Wnested-externs -Wnull-dereference
|
||||||
|
-Wold-style-definition -Wshift-overflow=2 -Wstrict-overflow=5
|
||||||
|
-Wstrict-prototypes -Wstringop-overflow=4 -Wundef -Wuninitialized -Wunused
|
||||||
|
-Wshadow # TODO: -Wshadow=compatible-local ?
|
||||||
|
-Wformat=2 -Wformat-overflow=2 -Wformat-truncation=1
|
||||||
|
-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()
|
||||||
|
|
||||||
if(CMAKE_VERSION VERSION_LESS 3.12)
|
# Use versioning consistent with Makefile
|
||||||
add_definitions(-DBUILD_VERSION_STRING="${PROJECT_VERSION}")
|
# the git revision is used but uses the fallback in an archive
|
||||||
else()
|
|
||||||
add_compile_definitions(BUILD_VERSION_STRING="${PROJECT_VERSION}")
|
find_program(GIT git)
|
||||||
endif()
|
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)
|
||||||
|
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")
|
||||||
|
|
||||||
set(CMAKE_C_STANDARD 11)
|
set(CMAKE_C_STANDARD 11)
|
||||||
set(CMAKE_C_STANDARD_REQUIRED True)
|
set(CMAKE_C_STANDARD_REQUIRED True)
|
||||||
|
|
||||||
add_subdirectory(src)
|
add_subdirectory(src)
|
||||||
|
|
||||||
|
# By default, build in Release mode; Debug mode must be explicitly requested
|
||||||
|
# (You may want to augment it with the options above)
|
||||||
|
if(CMAKE_BUILD_TYPE STREQUAL "Release")
|
||||||
|
message(CHECK_START "Checking if LTO is supported")
|
||||||
|
include(CheckIPOSupported)
|
||||||
|
check_ipo_supported(RESULT enable_lto)
|
||||||
|
if(enable_lto)
|
||||||
|
message(CHECK_PASS "yes")
|
||||||
|
set_property(TARGET rgbasm rgblink rgbfix rgbgfx PROPERTY INTERPROCEDURAL_OPTIMIZATION ON)
|
||||||
|
else()
|
||||||
|
message(CHECK_FAIL "no")
|
||||||
|
endif()
|
||||||
|
endif()
|
||||||
|
|||||||
+2
-3
@@ -1,10 +1,9 @@
|
|||||||
Contributing
|
Contributing
|
||||||
============
|
============
|
||||||
|
|
||||||
RGBDS was created in the late 90's and has received contributions from several
|
RGBDS was created in the late '90s and has received contributions from several
|
||||||
developers since then. It wouldn't have been possible to get to this point
|
developers since then. It wouldn't have been possible to get to this point
|
||||||
without their work and, for that reason, it is always open to the contributions
|
without their work, and it is always open to the contributions of other people.
|
||||||
of other people.
|
|
||||||
|
|
||||||
Reporting Bugs
|
Reporting Bugs
|
||||||
--------------
|
--------------
|
||||||
|
|||||||
+7
-1
@@ -19,6 +19,10 @@ Main contributors
|
|||||||
|
|
||||||
- Antonio Niño Díaz <[email protected]>
|
- Antonio Niño Díaz <[email protected]>
|
||||||
|
|
||||||
|
- Eldred "ISSOtm" Habert <[email protected]>
|
||||||
|
|
||||||
|
- Rangi <http://github.com/Rangi42>
|
||||||
|
|
||||||
Other contributors
|
Other contributors
|
||||||
------------------
|
------------------
|
||||||
|
|
||||||
@@ -30,7 +34,9 @@ Other contributors
|
|||||||
|
|
||||||
- David Brotz <[email protected]>
|
- David Brotz <[email protected]>
|
||||||
|
|
||||||
- Eldred Habert <[email protected]>
|
- Jakub Kądziołka <[email protected]>
|
||||||
|
|
||||||
|
- 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>
|
||||||
|
|
||||||
|
|||||||
+1
-2
@@ -7,8 +7,7 @@
|
|||||||
FROM alpine:latest
|
FROM alpine:latest
|
||||||
RUN apk add --update \
|
RUN apk add --update \
|
||||||
build-base \
|
build-base \
|
||||||
byacc \
|
bison \
|
||||||
flex \
|
|
||||||
libpng-dev
|
libpng-dev
|
||||||
COPY . /rgbds
|
COPY . /rgbds
|
||||||
WORKDIR /rgbds
|
WORKDIR /rgbds
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
The MIT License
|
The MIT License
|
||||||
|
|
||||||
Copyright (c) 1997-2018, Carsten Sorensen and RGBDS contributors.
|
Copyright (c) 1997-2020, Carsten Sorensen and RGBDS contributors.
|
||||||
|
|
||||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
of this software and associated documentation files (the "Software"), to
|
of this software and associated documentation files (the "Software"), to
|
||||||
|
|||||||
@@ -27,52 +27,59 @@ PNGCFLAGS := `${PKG_CONFIG} --cflags libpng`
|
|||||||
PNGLDFLAGS := `${PKG_CONFIG} --libs-only-L libpng`
|
PNGLDFLAGS := `${PKG_CONFIG} --libs-only-L libpng`
|
||||||
PNGLDLIBS := `${PKG_CONFIG} --libs-only-l libpng`
|
PNGLDLIBS := `${PKG_CONFIG} --libs-only-l libpng`
|
||||||
|
|
||||||
|
# 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
|
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
|
||||||
REALLDFLAGS := ${LDFLAGS} ${WARNFLAGS} \
|
REALLDFLAGS := ${LDFLAGS} ${WARNFLAGS} \
|
||||||
-DBUILD_VERSION_STRING=\"${VERSION_STRING}\"
|
-DBUILD_VERSION_STRING=\"${VERSION_STRING}\"
|
||||||
|
|
||||||
YFLAGS :=
|
YFLAGS ?= -Wall
|
||||||
|
|
||||||
YACC := yacc
|
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
|
||||||
|
|
||||||
rgbasm_obj := \
|
rgbasm_obj := \
|
||||||
src/asm/asmy.o \
|
|
||||||
src/asm/charmap.o \
|
src/asm/charmap.o \
|
||||||
|
src/asm/fixpoint.o \
|
||||||
|
src/asm/format.o \
|
||||||
src/asm/fstack.o \
|
src/asm/fstack.o \
|
||||||
src/asm/globlex.o \
|
|
||||||
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/math.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/asm/globlex.o src/asm/lexer.o src/asm/constexpr.o: src/asm/asmy.h
|
src/asm/lexer.o src/asm/main.o: src/asm/parser.h
|
||||||
|
|
||||||
rgblink_obj := \
|
rgblink_obj := \
|
||||||
src/link/assign.o \
|
src/link/assign.o \
|
||||||
@@ -83,22 +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
|
||||||
|
|
||||||
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
|
||||||
@@ -114,21 +122,32 @@ rgbgfx: ${rgbgfx_obj}
|
|||||||
|
|
||||||
# Rules to process files
|
# Rules to process files
|
||||||
|
|
||||||
# We want the yacc invocations to pass through our rules, not default ones
|
# We want the Bison invocation to pass through our rules, not default ones
|
||||||
.y.o:
|
.y.o:
|
||||||
|
|
||||||
# yacc-generated C files have an accompanying header
|
# Bison-generated C files have an accompanying header
|
||||||
.c.h:
|
src/asm/parser.h: src/asm/parser.c
|
||||||
$Qtouch $@
|
$Qtouch $@
|
||||||
|
|
||||||
.y.c:
|
src/asm/parser.c: src/asm/parser.y
|
||||||
$Q${YACC} -d ${YFLAGS} -o $@ $<
|
$QDEFS=; \
|
||||||
|
add_flag(){ \
|
||||||
|
if src/check_bison_ver.sh $$1 $$2; then \
|
||||||
|
DEFS="-D$$3 $$DEFS"; \
|
||||||
|
fi \
|
||||||
|
}; \
|
||||||
|
add_flag 3 5 api.token.raw=true; \
|
||||||
|
add_flag 3 6 parse.error=detailed; \
|
||||||
|
add_flag 3 0 parse.error=verbose; \
|
||||||
|
add_flag 3 0 parse.lac=full; \
|
||||||
|
add_flag 3 0 lr.type=ielr; \
|
||||||
|
echo "DEFS=$$DEFS"; \
|
||||||
|
${BISON} $$DEFS -d ${YFLAGS} -o $@ $<
|
||||||
|
|
||||||
.c.o:
|
.c.o:
|
||||||
$Q${CC} ${REALCFLAGS} ${PNGCFLAGS} -c -o $@ $<
|
$Q${CC} ${REALCFLAGS} ${PNGCFLAGS} -c -o $@ $<
|
||||||
|
|
||||||
# Target used to remove all files generated by other Makefile targets, except
|
# Target used to remove all files generated by other Makefile targets
|
||||||
# for the html documentation.
|
|
||||||
|
|
||||||
clean:
|
clean:
|
||||||
$Q${RM} rgbasm rgbasm.exe
|
$Q${RM} rgbasm rgbasm.exe
|
||||||
@@ -137,16 +156,7 @@ clean:
|
|||||||
$Q${RM} rgbgfx rgbgfx.exe
|
$Q${RM} rgbgfx rgbgfx.exe
|
||||||
$Qfind src/ -name "*.o" -exec rm {} \;
|
$Qfind src/ -name "*.o" -exec rm {} \;
|
||||||
$Q${RM} rgbshim.sh
|
$Q${RM} rgbshim.sh
|
||||||
$Q${RM} src/asm/asmy.c src/asm/asmy.h
|
$Q${RM} src/asm/parser.c src/asm/parser.h
|
||||||
|
|
||||||
# Target used to remove all html files generated by the wwwman target
|
|
||||||
|
|
||||||
cleanwwwman:
|
|
||||||
$Q${RM} docs/rgbds.7.html docs/gbz80.7.html docs/rgbds.5.html
|
|
||||||
$Q${RM} docs/rgbasm.1.html docs/rgbasm.5.html
|
|
||||||
$Q${RM} docs/rgblink.1.html docs/rgblink.5.html
|
|
||||||
$Q${RM} docs/rgbfix.1.html
|
|
||||||
$Q${RM} docs/rgbgfx.1.html
|
|
||||||
|
|
||||||
# Target used to install the binaries and man pages.
|
# Target used to install the binaries and man pages.
|
||||||
|
|
||||||
@@ -182,49 +192,44 @@ 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" \
|
||||||
|
-- src include '!src/extern' '!include/extern' \
|
||||||
| ${CHECKPATCH} - || true; \
|
| ${CHECKPATCH} - || true; \
|
||||||
done
|
done
|
||||||
|
|
||||||
# Target for the project maintainer to easily create web manuals.
|
# Target used to check for suspiciously missing changed files.
|
||||||
# It relies on mandoc: http://mdocml.bsd.lv
|
|
||||||
|
|
||||||
MANDOC := -Thtml -Ios=General -Oman=%N.%S.html -Ostyle=mandoc.css
|
checkdiff:
|
||||||
|
$Qcontrib/checkdiff.bash `git merge-base HEAD ${BASE_REF}`
|
||||||
wwwman:
|
|
||||||
$Qmandoc ${MANDOC} src/rgbds.7 | src/doc_postproc.awk > docs/rgbds.7.html
|
|
||||||
$Qmandoc ${MANDOC} src/gbz80.7 | src/doc_postproc.awk > docs/gbz80.7.html
|
|
||||||
$Qmandoc ${MANDOC} src/rgbds.5 | src/doc_postproc.awk > docs/rgbds.5.html
|
|
||||||
$Qmandoc ${MANDOC} src/asm/rgbasm.1 | src/doc_postproc.awk > docs/rgbasm.1.html
|
|
||||||
$Qmandoc ${MANDOC} src/asm/rgbasm.5 | src/doc_postproc.awk > docs/rgbasm.5.html
|
|
||||||
$Qmandoc ${MANDOC} src/fix/rgbfix.1 | src/doc_postproc.awk > docs/rgbfix.1.html
|
|
||||||
$Qmandoc ${MANDOC} src/link/rgblink.1 | src/doc_postproc.awk > docs/rgblink.1.html
|
|
||||||
$Qmandoc ${MANDOC} src/link/rgblink.5 | src/doc_postproc.awk > docs/rgblink.5.html
|
|
||||||
$Qmandoc ${MANDOC} src/gfx/rgbgfx.1 | src/doc_postproc.awk > docs/rgbgfx.1.html
|
|
||||||
|
|
||||||
# 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 \
|
$Qenv ${MAKE} WARNFLAGS="-Werror -Wextra \
|
||||||
-Wno-sign-compare -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=5 \
|
-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 -DDEVELOP" CFLAGS="-g -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!
|
||||||
@@ -232,11 +237,11 @@ develop:
|
|||||||
# install instructions instead.
|
# install instructions instead.
|
||||||
|
|
||||||
mingw32:
|
mingw32:
|
||||||
$Qmake CC=i686-w64-mingw32-gcc YACC=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 YACC=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:
|
||||||
|
|||||||
+67
-125
@@ -15,160 +15,100 @@ other UNIX tools.
|
|||||||
This toolchain is maintained on `GitHub <https://github.com/rednex/rgbds>`__.
|
This toolchain is maintained on `GitHub <https://github.com/rednex/rgbds>`__.
|
||||||
|
|
||||||
The documentation of this toolchain can be viewed online
|
The documentation of this toolchain can be viewed online
|
||||||
`here <https://rednex.github.io/rgbds/>`__, it is generated from the man pages
|
`here <https://rgbds.gbdev.io/docs/>`__, it is generated from the man pages
|
||||||
found in this repository.
|
found in this repository.
|
||||||
|
|
||||||
|
If you want to contribute or maintain RGBDS, and have questions regarding the code, its organisation, etc. you can find me `on GBDev <https://gbdev.io/chat>`__ or via mail at ``rgbds at eldred dot fr``.
|
||||||
|
|
||||||
1. Installing RGBDS
|
1. Installing RGBDS
|
||||||
-------------------
|
-------------------
|
||||||
|
|
||||||
1.1 Windows
|
The `installation procedure <https://rgbds.gbdev.io/install>`__ is available
|
||||||
~~~~~~~~~~~
|
online for various platforms. `Building from source <https://rgbds.gbdev.io/install/source>`__
|
||||||
|
is possible using ``make`` or ``cmake``; follow the link for more detailed instructions.
|
||||||
Windows builds are available in the releases page on GitHub
|
|
||||||
`here <https://github.com/rednex/rgbds/releases>`__.
|
|
||||||
|
|
||||||
Extract the zip and then add the executable directory to the path. For example:
|
|
||||||
|
|
||||||
::
|
|
||||||
|
|
||||||
path %PATH%;C:\Programs\rgbds-0.3.8-win64\win64
|
|
||||||
|
|
||||||
Alternatively, the RGBDS executables can be simply dropped in the folder of the project they're used in.
|
|
||||||
|
|
||||||
If you require the latest version in development, it should be possible to
|
|
||||||
compile RGBDS with MinGW or Cygwin by following the instructions to build it on
|
|
||||||
UNIX systems.
|
|
||||||
|
|
||||||
1.2 macOS
|
|
||||||
~~~~~~~~~
|
|
||||||
|
|
||||||
You can build RGBDS by following the instructions below. However, if you would
|
|
||||||
prefer not to build RGBDS yourself, you may also install it using
|
|
||||||
`Homebrew <http://brew.sh/>`__.
|
|
||||||
|
|
||||||
To install the latest release, use:
|
|
||||||
|
|
||||||
.. code:: sh
|
|
||||||
|
|
||||||
brew install rgbds
|
|
||||||
|
|
||||||
To install RGBDS with all of the current changes in development (as seen on the
|
|
||||||
``master`` branch on GitHub), use:
|
|
||||||
|
|
||||||
.. code:: sh
|
|
||||||
|
|
||||||
brew install rgbds --HEAD
|
|
||||||
|
|
||||||
1.3 Arch Linux
|
|
||||||
~~~~~~~~~~~~~~
|
|
||||||
|
|
||||||
To install RGBDS through the AUR run
|
|
||||||
|
|
||||||
.. code:: sh
|
|
||||||
|
|
||||||
yaourt -S rgbds
|
|
||||||
|
|
||||||
1.4 Other UNIX-like systems
|
|
||||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
|
||||||
|
|
||||||
No official binaries of RGBDS are distributed for these systems, you must follow
|
|
||||||
the simple instructions below to compile and install it.
|
|
||||||
|
|
||||||
2. Building RGBDS from source
|
|
||||||
-----------------------------
|
|
||||||
|
|
||||||
RGBDS can be built in UNIX-like systems by following the instructions below.
|
|
||||||
|
|
||||||
2.1 Dependencies
|
|
||||||
~~~~~~~~~~~~~~~~
|
|
||||||
|
|
||||||
RGBDS requires yacc, libpng and pkg-config to be installed.
|
|
||||||
|
|
||||||
On macOS, install the latter two with `Homebrew <http://brew.sh/>`__:
|
|
||||||
|
|
||||||
.. code:: sh
|
|
||||||
|
|
||||||
brew install libpng pkg-config
|
|
||||||
|
|
||||||
On other Unixes, use the built-in package manager. For example, on Debian or
|
|
||||||
Ubuntu:
|
|
||||||
|
|
||||||
.. code:: sh
|
|
||||||
|
|
||||||
sudo apt-get install byacc flex pkg-config libpng-dev
|
|
||||||
|
|
||||||
You can test if libpng and pkg-config are installed by running ``pkg-config
|
|
||||||
--cflags libpng``: if the output is a path, then you're good, and if it outputs
|
|
||||||
an error then you need to install them via a package manager.
|
|
||||||
|
|
||||||
2.2 Build process
|
|
||||||
~~~~~~~~~~~~~~~~~
|
|
||||||
|
|
||||||
To build the programs, run in your terminal:
|
|
||||||
|
|
||||||
.. code:: sh
|
.. code:: sh
|
||||||
|
|
||||||
make
|
make
|
||||||
|
sudo make install
|
||||||
Then, to install the compiled programs and manual pages, run (with appropriate
|
|
||||||
privileges, e.g, with ``sudo``):
|
|
||||||
|
|
||||||
.. code:: sh
|
.. code:: sh
|
||||||
|
|
||||||
make install
|
cmake -S . -B build -DCMAKE_BUILD_TYPE=Release
|
||||||
|
cmake --build build
|
||||||
|
cmake --install build
|
||||||
|
|
||||||
After installation, you can read the manuals with the ``man`` command. E.g.,
|
2. RGBDS Folder Organization
|
||||||
|
----------------------------
|
||||||
|
|
||||||
.. code:: sh
|
The RGBDS source code file structure somewhat resembles the following:
|
||||||
|
|
||||||
man 7 rgbds
|
::
|
||||||
|
|
||||||
There are some variables in the Makefile that can be redefined by the user. The
|
.
|
||||||
variables described below can affect installation behavior when given on the
|
├── .github/
|
||||||
make command line. For example, to install RGBDS in your home directory instead
|
│ ├── actions/
|
||||||
of systemwide, run the following:
|
│ │ └── ...
|
||||||
|
│ └── workflows/
|
||||||
|
│ └── ...
|
||||||
|
├── contrib/
|
||||||
|
│ ├── zsh_compl/
|
||||||
|
│ │ └── ...
|
||||||
|
│ └── ...
|
||||||
|
├── include/
|
||||||
|
│ └── ...
|
||||||
|
├── src/
|
||||||
|
│ ├── asm/
|
||||||
|
│ │ └── ...
|
||||||
|
│ ├── extern/
|
||||||
|
│ │ └── ...
|
||||||
|
│ ├── fix/
|
||||||
|
│ │ └── ...
|
||||||
|
│ ├── gfx/
|
||||||
|
│ │ └── ...
|
||||||
|
│ ├── link/
|
||||||
|
│ │ └── ...
|
||||||
|
│ ├── CMakeLists.txt
|
||||||
|
│ └── ...
|
||||||
|
├── test/
|
||||||
|
│ ├── ...
|
||||||
|
│ └── run-tests.sh
|
||||||
|
├── .clang-format
|
||||||
|
├── CMakeLists.txt
|
||||||
|
├── Makefile
|
||||||
|
└── README.rst
|
||||||
|
|
||||||
.. code:: sh
|
.. |clang-format| replace:: ``clang-format``
|
||||||
|
.. _clang-format: https://clang.llvm.org/docs/ClangFormat.html
|
||||||
|
|
||||||
make install PREFIX=$HOME
|
- ``.github/`` - files and scripts related to the integration of the RGBDS codebase with
|
||||||
|
GitHub.
|
||||||
|
|
||||||
To do a verbose build, run:
|
* ``actions/`` - scripts used by workflow files.
|
||||||
|
* ``workflows/`` - CI workflow description files.
|
||||||
|
|
||||||
.. code:: sh
|
- ``contrib/`` - scripts and other resources which may be useful to users and developers of
|
||||||
|
RGBDS.
|
||||||
|
|
||||||
make Q=
|
* ``zsh_compl`` contains tab completion scripts for use with zsh. Put them somewhere in your ``fpath``, and they should auto-load.
|
||||||
|
|
||||||
This is the complete list of user-defined variables:
|
* ``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.
|
||||||
|
|
||||||
- ``PREFIX``: Location where RGBDS will be installed. Defaults to
|
- ``include/`` - header files for each respective C files in `src`.
|
||||||
``/usr/local``.
|
|
||||||
|
|
||||||
- ``bindir``: Location where the binaries will be installed. Defaults to
|
- ``src/`` - source code and manual pages for RGBDS.
|
||||||
``${PREFIX}/bin``.
|
|
||||||
|
|
||||||
- ``mandir``: Location where the manpages will be installed. Defaults to
|
* Note that the code unique to each RGBDS tool is stored in its respective subdirectory
|
||||||
``${PREFIX}/share/man``.
|
(rgbasm -> ``src/asm/``, for example). ``src/extern/`` contains code imported from external sources.
|
||||||
|
|
||||||
- ``DESTDIR``: This is prepended to all paths during the installation. It is
|
- ``test/`` - testing framework used to verify that changes to the code don't break or modify the behavior of RGBDS.
|
||||||
mainly used for packaging.
|
|
||||||
|
|
||||||
- ``Q``: Whether to quiet the build or not. To make the build more verbose,
|
- ``.clang-format`` - code style for automated formatting with |clang-format|_. The C code does not currently follow this style, but all C++ code should.
|
||||||
clear this variable. Defaults to ``@``.
|
|
||||||
|
|
||||||
- ``STRIP``: Whether to strip the installed binaries of debug symbols or not.
|
3. History
|
||||||
Defaults to ``-s``.
|
----------
|
||||||
|
|
||||||
- ``BINMODE``: Permissions of the installed binaries. Defaults to ``755``.
|
- Around 1997, Carsten Sørensen (AKA SurfSmurf) writes ASMotor as a
|
||||||
|
|
||||||
- ``MANMODE``: Permissions of the installed manpages. Defaults to ``644``.
|
|
||||||
|
|
||||||
- ``CHECKPATCH``: Path of the script ``checkpatch.pl`` of the Linux kernel.
|
|
||||||
Defaults to ``../linux/scripts/checkpatch.pl``.
|
|
||||||
|
|
||||||
3 History
|
|
||||||
---------
|
|
||||||
|
|
||||||
- Around 1997, Carsten Sorensen (AKA SurfSmurf) writes ASMotor as a
|
|
||||||
general-purpose assembler/linker system for DOS/Win32
|
general-purpose assembler/linker system for DOS/Win32
|
||||||
|
|
||||||
- Around 1999, Justin Lloyd (AKA Otaku no Zoku) adapts ASMotor to read and
|
- Around 1999, Justin Lloyd (AKA Otaku no Zoku) adapts ASMotor to read and
|
||||||
@@ -184,3 +124,5 @@ This is the complete list of user-defined variables:
|
|||||||
- 2017, Bentley's repository is moved to a neutral name.
|
- 2017, Bentley's repository is moved to a neutral name.
|
||||||
|
|
||||||
- 2018, codebase relicensed under the MIT license.
|
- 2018, codebase relicensed under the MIT license.
|
||||||
|
|
||||||
|
- 2020, repository is moved to the `gbdev <https://github.com/gbdev>`__ organisation. The `rgbds.gbdev.io <https://rgbds.gbdev.io>`__ website serving documentation and downloads is created.
|
||||||
|
|||||||
+67
@@ -0,0 +1,67 @@
|
|||||||
|
Releasing
|
||||||
|
=========
|
||||||
|
|
||||||
|
This describes for the maintainers of RGBDS how to publish a new release on
|
||||||
|
GitHub.
|
||||||
|
|
||||||
|
1. Update, commit, and push `include/version.h <include/version.h>`__ with
|
||||||
|
values for ``PACKAGE_VERSION_MAJOR``, ``PACKAGE_VERSION_MINOR``,
|
||||||
|
``PACKAGE_VERSION_PATCH``, and ``PACKAGE_VERSION_RC``. Only define
|
||||||
|
``PACKAGE_VERSION_RC`` if you are publishing a release candidate! You can
|
||||||
|
use ``git commit -m "Release <version>"`` and ``git push origin master``.
|
||||||
|
|
||||||
|
2. Create a Git tag formatted as ``v<MAJOR>.<MINOR>.<PATCH>``, or
|
||||||
|
``v<MAJOR>.<MINOR>.<PATCH>-rc<RC>`` for a release candidate. ``MAJOR``,
|
||||||
|
``MINOR``, ``PATCH``, and ``RC`` should match their values from
|
||||||
|
`include/version.h <include/version.h>`__. You can use ``git tag <tag>``.
|
||||||
|
|
||||||
|
3. Push the tag to GitHub. You can use ``git push origin <tag>``.
|
||||||
|
|
||||||
|
GitHub Actions will run the `create-release-artifacts.yaml
|
||||||
|
<.github/workflows/create-release-artifacts.yaml>`__ workflow to detect the
|
||||||
|
tag starting with "``v[0-9]``" and automatically do the following:
|
||||||
|
|
||||||
|
1. Build 32-bit and 64-bit RGBDS binaries for Windows with ``cmake``.
|
||||||
|
|
||||||
|
2. Package the binaries into zip files.
|
||||||
|
|
||||||
|
3. Package the source code into a tar.gz file with ``make dist``.
|
||||||
|
|
||||||
|
4. Create a draft GitHub release for the tag, attaching the three
|
||||||
|
packaged files. It will be a prerelease if the tag contains "``-rc``".
|
||||||
|
|
||||||
|
If an error occurred in the above steps, delete the tag and restart the
|
||||||
|
procedure. You can use ``git push --delete origin <tag>`` and
|
||||||
|
``git tag --delete <tag>``.
|
||||||
|
|
||||||
|
4. GitHub Actions will run the `create-release-docs.yml
|
||||||
|
<.github/workflows/create-release-docs.yml>`__ workflow to add the release
|
||||||
|
documentation to `rgbds-www <https://github.com/gbdev/rgbds-www>`__.
|
||||||
|
|
||||||
|
For a release candidate, which creates a prerelease, you will have to
|
||||||
|
take these steps yourself.
|
||||||
|
|
||||||
|
1. Clone `rgbds-www <https://github.com/gbdev/rgbds-www>`__. You can use
|
||||||
|
``git clone https://github.com/gbdev/rgbds-www.git``.
|
||||||
|
|
||||||
|
2. Make sure that you have installed ``groff`` and ``mandoc``. You will
|
||||||
|
need ``mandoc`` 1.14.5 or later to support ``-O toc``.
|
||||||
|
|
||||||
|
3. Run ``.github/actions/get-pages.sh -r <path/to/rgbds-www> <tag>``. This
|
||||||
|
will render the RGBDS documentation as HTML and PDF and copy it to
|
||||||
|
``rgbds-www``.
|
||||||
|
|
||||||
|
If you do not have ``groff`` installed, you can change
|
||||||
|
``groff -Tpdf -mdoc -wall`` to ``mandoc -Tpdf -I os=Linux`` in
|
||||||
|
`.github/actions/get-pages.sh <.github/actions/get-pages.sh>`__ and it
|
||||||
|
will suffice.
|
||||||
|
|
||||||
|
4. Commit and push the documentation. You can use ``git commit -m
|
||||||
|
"Create RGBDS <tag> documentation"`` and ``git push origin master``
|
||||||
|
(within the ``rgbds-www`` directory, not RGBDS).
|
||||||
|
|
||||||
|
5. Write a changelog in the GitHub draft release.
|
||||||
|
|
||||||
|
6. Click the "Publish release" button to publish it!
|
||||||
|
|
||||||
|
7. Update the `release` branch. You can use ``git push origin release``.
|
||||||
Executable
+215
@@ -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
|
||||||
Executable
+181
@@ -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
|
||||||
Executable
+162
@@ -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
|
||||||
Executable
+157
@@ -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
|
||||||
Executable
+85
@@ -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?"
|
||||||
+12
-10
@@ -31,31 +31,33 @@ diff <(xxd $1) <(xxd $2) | while read -r LINE; do
|
|||||||
# Separator between files switches states
|
# Separator between files switches states
|
||||||
echo $LINE
|
echo $LINE
|
||||||
STATE=3
|
STATE=3
|
||||||
elif echo $LINE | grep -Eq '^[0-9]+(,[0-9]+)?c[0-9]+(,[0-9]+)?'; then
|
elif grep -Eq '^[0-9]+(,[0-9]+)?[cd][0-9]+(,[0-9]+)?' <<< "$LINE"; then
|
||||||
# Line info resets the whole thing
|
# Line info resets the whole thing
|
||||||
STATE=1
|
STATE=1
|
||||||
elif [ $STATE -eq 1 -o $STATE -eq 3 ]; then
|
elif [ $STATE -eq 1 -o $STATE -eq 3 ]; then
|
||||||
# Compute the GB address from the ROM offset
|
# Compute the GB address from the ROM offset
|
||||||
OFS=$(echo $LINE | cut -d ' ' -f 2 | tr -d ':')
|
OFS=$(cut -d ' ' -f 2 <<< "$LINE" | tr -d ':')
|
||||||
BANK=$((0x$OFS / 0x4000))
|
BANK=$((0x$OFS / 0x4000))
|
||||||
ADDR=$((0x$OFS % 0x4000 + ($BANK != 0) * 0x4000))
|
ADDR=$((0x$OFS % 0x4000 + ($BANK != 0) * 0x4000))
|
||||||
# Try finding the preceding symbol closest to the diff
|
# Try finding the preceding symbol closest to the diff
|
||||||
if [ $STATE -eq 1 ]; then
|
if [ $STATE -eq 1 ]; then
|
||||||
STATE=2
|
STATE=2
|
||||||
SYMFILE=$(echo $1 | cut -d '.' -f 1).sym
|
SYMFILE=${1%.*}.sym
|
||||||
else
|
else
|
||||||
STATE=4
|
STATE=4
|
||||||
SYMFILE=$(echo $2 | cut -d '.' -f 1).sym
|
SYMFILE=${2%.*}.sym
|
||||||
fi
|
fi
|
||||||
EXTRA=$(if [ -f "$SYMFILE" ]; then
|
EXTRA=$(if [ -f "$SYMFILE" ]; then
|
||||||
# Read the sym file for such a symbol
|
# Read the sym file for such a symbol
|
||||||
# Ignore comment lines, only pick matching bank
|
# Ignore comment lines, only pick matching bank
|
||||||
grep -Fv ';' "$SYMFILE" |
|
# (The bank regex ignores comments already, make `cut` and `tr` process less lines)
|
||||||
grep -Ei $(printf "^%02x:" $BANK) |
|
grep -Ei $(printf "^%02x:" $BANK) "$SYMFILE" |
|
||||||
|
cut -d ';' -f 1 |
|
||||||
|
tr -d "\r" |
|
||||||
while read -r SYMADDR SYM; do
|
while read -r SYMADDR SYM; do
|
||||||
SYMADDR=$((0x$(echo $SYMADDR | cut -d ':' -f 2)))
|
SYMADDR=$((0x${SYMADDR#*:}))
|
||||||
if [ $SYMADDR -le $ADDR ]; then
|
if [ $SYMADDR -le $ADDR ]; then
|
||||||
printf " (%s+%#x)\n" $SYM $(($ADDR - $SYMADDR))
|
printf " (%s+%#x)\n" "$SYM" $(($ADDR - $SYMADDR))
|
||||||
fi
|
fi
|
||||||
# TODO: assumes sorted sym files
|
# TODO: assumes sorted sym files
|
||||||
done | tail -n 1
|
done | tail -n 1
|
||||||
@@ -63,9 +65,9 @@ diff <(xxd $1) <(xxd $2) | while read -r LINE; do
|
|||||||
printf "%02x:%04x %s\n" $BANK $ADDR $EXTRA
|
printf "%02x:%04x %s\n" $BANK $ADDR $EXTRA
|
||||||
fi
|
fi
|
||||||
if [ $STATE -eq 2 -o $STATE -eq 4 ]; then
|
if [ $STATE -eq 2 -o $STATE -eq 4 ]; then
|
||||||
OFS=$(echo $LINE | cut -d ' ' -f 2 | tr -d ':')
|
OFS=$(cut -d ' ' -f 2 <<< "$LINE" | tr -d ':')
|
||||||
BANK=$((0x$OFS / 0x4000))
|
BANK=$((0x$OFS / 0x4000))
|
||||||
ADDR=$((0x$OFS % 0x4000 + ($BANK != 0) * 0x4000))
|
ADDR=$((0x$OFS % 0x4000 + ($BANK != 0) * 0x4000))
|
||||||
printf "%s %02x:%04x: %s\n" "$(echo $LINE | cut -d ' ' -f 1)" $BANK $ADDR "$(echo $LINE | cut -d ' ' -f 3-)"
|
printf "%s %02x:%04x: %s\n" "${LINE:0:1}" $BANK $ADDR "${LINE#*: }"
|
||||||
fi
|
fi
|
||||||
done
|
done
|
||||||
|
|||||||
@@ -0,0 +1,61 @@
|
|||||||
|
#compdef rgbasm
|
||||||
|
|
||||||
|
_rgbasm_warnings() {
|
||||||
|
local warnings=(
|
||||||
|
'error:Turn all warnings into errors'
|
||||||
|
|
||||||
|
'all:Enable most warning messages'
|
||||||
|
'extra:Enable extra, possibly unwanted, messages'
|
||||||
|
'everything:Enable literally everything'
|
||||||
|
|
||||||
|
'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'
|
||||||
|
'charmap-redef:Warn when redefining a charmap mapping'
|
||||||
|
'div:Warn when dividing the smallest int by -1'
|
||||||
|
'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'
|
||||||
|
'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'
|
||||||
|
'shift:Warn when shifting negative values'
|
||||||
|
'shift-amount:Warn when a shift'\''s operand it negative or \> 32'
|
||||||
|
'truncation:Warn when implicit truncation loses bits'
|
||||||
|
'user:Warn when executing the WARN built-in'
|
||||||
|
)
|
||||||
|
# TODO: handle `no-` and `error=` somehow?
|
||||||
|
# TODO: handle `=0|1|2` levels for `numeric-string` and `truncation`?
|
||||||
|
_describe warning warnings
|
||||||
|
}
|
||||||
|
|
||||||
|
local args=(
|
||||||
|
# Arguments are listed here in the same order as in the manual, except for the version
|
||||||
|
'(- : * options)'{-V,--version}'[Print version number]'
|
||||||
|
|
||||||
|
'(-E --export-all)'{-E,--export-all}'[Export all symbols]'
|
||||||
|
'(-h --halt-without-nop)'{-h,--halt-without-nop}'[Avoid outputting a `nop` after `halt`]'
|
||||||
|
'(-L ---preserve-ld)'{-L,--preserve-ld}'[Prevent auto-optimizing `ld` into `ldh`]'
|
||||||
|
'(-v --verbose)'{-v,--verbose}'[Print additional messages regarding progression]'
|
||||||
|
-w'[Disable all warnings]'
|
||||||
|
|
||||||
|
'(-b --binary-digits)'{-b,--binary-digits}'+[Change chars for binary constants]:digit spec:'
|
||||||
|
'*'{-D,--define}'+[Define a string symbol]:name + value (default 1):'
|
||||||
|
'(-g --gfx-chars)'{-g,--gfx-chars}'+[Change chars for gfx constants]:chars spec:'
|
||||||
|
'(-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}'"
|
||||||
|
-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'
|
||||||
|
'(-p --pad-value)'{-p,--pad-value}'+[Set padding byte]:padding byte:'
|
||||||
|
'(-r --recursion-depth)'{-r,--recursion-depth}'+[Set maximum recursion depth]:depth:'
|
||||||
|
'(-W --warning)'{-W,--warning}'+[Toggle warning flags]:warning flag:_rgbasm_warnings'
|
||||||
|
|
||||||
|
":assembly sources:_files -g '*.asm'"
|
||||||
|
)
|
||||||
|
_arguments -s -S : $args
|
||||||
@@ -0,0 +1,60 @@
|
|||||||
|
#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=(
|
||||||
|
# Arguments are listed here in the same order as in the manual, except for the version
|
||||||
|
'(- : * options)'{-V,--version}'[Print version number]'
|
||||||
|
|
||||||
|
'(-C --color-only -c --color-compatible)'{-C,--color-only}'[Mark ROM as GBC-only]'
|
||||||
|
'(-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]'
|
||||||
|
'(-O --overwrite)'{-O,--overwrite}'[Allow overwriting non-zero bytes]'
|
||||||
|
'(-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)'{-f,--fix-spec}'+[Fix or trash some header values]:fix spec:'
|
||||||
|
'(-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:'
|
||||||
|
'(-l --old-licensee)'{-l,--old-licensee}'+[Set old licensee ID]:licensee number:'
|
||||||
|
'(-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:'
|
||||||
|
'(-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:'
|
||||||
|
'(-t --title)'{-t,--title}'+[Set title string]:11-char title string:'
|
||||||
|
|
||||||
|
'*'":ROM files:_files -g '*.{gb,sgb,gbc}'"
|
||||||
|
)
|
||||||
|
_arguments -s -S : $args
|
||||||
@@ -0,0 +1,37 @@
|
|||||||
|
#compdef rgbgfx
|
||||||
|
|
||||||
|
_depths() {
|
||||||
|
local depths=(
|
||||||
|
'1:1bpp'
|
||||||
|
'2:2bpp (native)'
|
||||||
|
)
|
||||||
|
|
||||||
|
_describe 'bit depth' depths
|
||||||
|
}
|
||||||
|
|
||||||
|
local args=(
|
||||||
|
# Arguments are listed here in the same order as in the manual, except for the version
|
||||||
|
'(- : * options)'{-V,--version}'[Print version number]'
|
||||||
|
|
||||||
|
'(-a --attr-map -A --output-attr-map)'{-A,--output-attr-map}'[Shortcut for -a <file>.attrmap]'
|
||||||
|
'(-C --color-curve)'{-C,--color-curve}'[Generate palettes using GBC color curve]'
|
||||||
|
'(-D --debug)'{-D,--debug}'[Enable debug features]'
|
||||||
|
'(-f --fix -F --fix-and-save)'{-f,--fix}'[Fix input PNG into an indexed image]'
|
||||||
|
'(-f --fix -F --fix-and-save)'{-F,--fix-and-save}'[Like -f but also save CLI params within the PNG]'
|
||||||
|
'(-h --horizontal)'{-h,--horizontal}'[Lay out tiles horizontally instead of vertically]'
|
||||||
|
'(-m --mirror-tiles)'{-m,--mirror-tiles}'[Eliminate mirrored tiles from output]'
|
||||||
|
'(-p --palette -P --output-palette)'{-P,--output-palette}'[Shortcut for -p <file>.pal]'
|
||||||
|
'(-t --tilemap -T --output-tilemap)'{-T,--output-tilemap}'[Shortcut for -t <file>.tilemap]'
|
||||||
|
'(-u --unique-tiles)'{-u,--unique-tiles}'[Eliminate redundant tiles]'
|
||||||
|
'(-v --verbose)'{-v,--verbose}'[Enable verbose output]'
|
||||||
|
|
||||||
|
'(-a --attr-map -A --output-attr-map)'{-a,--attr-map}'+[Generate a map of tile attributes (mirroring)]:attrmap file:_files'
|
||||||
|
'(-d --depth)'{-d,--depth}'+[Set bit depth]:bit depth:_depths'
|
||||||
|
'(-o --output)'{-o,--output}'+[Set output file]:output file:_files'
|
||||||
|
'(-p --palette -P --output-palette)'{-p,--palette}"+[Output the image's palette in little-endian native RGB555 format]:palette 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:'
|
||||||
|
|
||||||
|
":input png file:_files -g '*.png'"
|
||||||
|
)
|
||||||
|
_arguments -s -S : $args
|
||||||
@@ -0,0 +1,24 @@
|
|||||||
|
#compdef rgblink
|
||||||
|
|
||||||
|
local args=(
|
||||||
|
# Arguments are listed here in the same order as in the manual, except for the version
|
||||||
|
'(- : * options)'{-V,--version}'[Print version number]'
|
||||||
|
|
||||||
|
'(-d --dmg)'{-d,--dmg}'[Enable DMG mode (-w + no VRAM banking)]'
|
||||||
|
'(-t --tiny)'{-t,--tiny}'[Enable tiny mode, disabling ROM banking]'
|
||||||
|
'(-v --verbose)'{-v,--verbose}'[Enable verbose output]'
|
||||||
|
'(-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'"
|
||||||
|
'(-m --map)'{-m,--map}"+[Produce a map file]:map file:_files -g '*.map'"
|
||||||
|
'(-n --sym)'(-n,--sym)"+[Produce a symbol file]:sym file:_files -g '*.sym'"
|
||||||
|
'(-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}'"
|
||||||
|
'(-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:'
|
||||||
|
|
||||||
|
'*'":object files:_files -g '*.o'"
|
||||||
|
)
|
||||||
|
_arguments -s -S : $args
|
||||||
-1670
File diff suppressed because it is too large
Load Diff
@@ -1,36 +0,0 @@
|
|||||||
<!DOCTYPE html>
|
|
||||||
<html>
|
|
||||||
<head>
|
|
||||||
<meta charset="utf-8"/>
|
|
||||||
<meta http-equiv="Content-Type" content="text/html;charset=UTF-8">
|
|
||||||
<title>General Information</title>
|
|
||||||
<link rel="stylesheet" type="text/css" href="mandoc.css">
|
|
||||||
</head>
|
|
||||||
<body>
|
|
||||||
<h1>RGBDS — Rednex Game Boy Development System</h1>
|
|
||||||
<h2>Table of Contents</h2>
|
|
||||||
<ol>
|
|
||||||
<li>General information
|
|
||||||
<ul>
|
|
||||||
<li><a href="rgbds.7.html">RGBDS general information</a></li>
|
|
||||||
<li><a href="rgbds.5.html">RGBDS object file format</a></li>
|
|
||||||
</ul>
|
|
||||||
<li>Language description
|
|
||||||
<ul>
|
|
||||||
<li><a href="rgbasm.5.html">RGBASM language description</a></li>
|
|
||||||
<li><a href="rgblink.5.html">RGBLINK linkerscript language description</a></li>
|
|
||||||
<li><a href="gbz80.7.html">GBZ80 CPU instruction set description</a></li>
|
|
||||||
</ul>
|
|
||||||
<li>Command line usage
|
|
||||||
<ul>
|
|
||||||
<li><a href="rgbasm.1.html">RGBASM command-line usage</a></li>
|
|
||||||
<li><a href="rgblink.1.html">RGBLINK command-line usage</a></li>
|
|
||||||
<li><a href="rgbfix.1.html">RGBFIX command-line usage</a></li>
|
|
||||||
<li><a href="rgbgfx.1.html">RGBGFX command-line usage</a></li>
|
|
||||||
</ul>
|
|
||||||
</ol>
|
|
||||||
<h2 id="GitHub Repository">GitHub Repository:</h2>
|
|
||||||
<ul>
|
|
||||||
<li><a href="https://github.com/rednex/rgbds">https://github.com/rednex/rgbds</a></li>
|
|
||||||
</ul>
|
|
||||||
</body>
|
|
||||||
-347
@@ -1,347 +0,0 @@
|
|||||||
/* $Id: mandoc.css,v 1.45 2019/03/01 10:57:18 schwarze Exp $ */
|
|
||||||
/*
|
|
||||||
* Standard style sheet for mandoc(1) -Thtml and man.cgi(8).
|
|
||||||
*
|
|
||||||
* Written by Ingo Schwarze <[email protected]>.
|
|
||||||
* I place this file into the public domain.
|
|
||||||
* Permission to use, copy, modify, and distribute it for any purpose
|
|
||||||
* with or without fee is hereby granted, without any conditions.
|
|
||||||
*/
|
|
||||||
|
|
||||||
/* Global defaults. */
|
|
||||||
|
|
||||||
html { max-width: 65em; }
|
|
||||||
body { font-family: Helvetica,Arial,sans-serif; }
|
|
||||||
table { margin-top: 0em;
|
|
||||||
margin-bottom: 0em;
|
|
||||||
border-collapse: collapse; }
|
|
||||||
/* Some browsers set border-color in a browser style for tbody,
|
|
||||||
* but not for table, resulting in inconsistent border styling. */
|
|
||||||
tbody { border-color: inherit; }
|
|
||||||
tr { border-color: inherit; }
|
|
||||||
td { vertical-align: top;
|
|
||||||
padding-left: 0.2em;
|
|
||||||
padding-right: 0.2em;
|
|
||||||
border-color: inherit; }
|
|
||||||
ul, ol, dl { margin-top: 0em;
|
|
||||||
margin-bottom: 0em; }
|
|
||||||
li, dt { margin-top: 1em; }
|
|
||||||
|
|
||||||
.permalink { border-bottom: thin dotted;
|
|
||||||
color: inherit;
|
|
||||||
font: inherit;
|
|
||||||
text-decoration: inherit; }
|
|
||||||
* { clear: both }
|
|
||||||
|
|
||||||
/* Search form and search results. */
|
|
||||||
|
|
||||||
fieldset { border: thin solid silver;
|
|
||||||
border-radius: 1em;
|
|
||||||
text-align: center; }
|
|
||||||
input[name=expr] {
|
|
||||||
width: 25%; }
|
|
||||||
|
|
||||||
table.results { margin-top: 1em;
|
|
||||||
margin-left: 2em;
|
|
||||||
font-size: smaller; }
|
|
||||||
|
|
||||||
/* Header and footer lines. */
|
|
||||||
|
|
||||||
table.head { width: 100%;
|
|
||||||
border-bottom: 1px dotted #808080;
|
|
||||||
margin-bottom: 1em;
|
|
||||||
font-size: smaller; }
|
|
||||||
td.head-vol { text-align: center; }
|
|
||||||
td.head-rtitle {
|
|
||||||
text-align: right; }
|
|
||||||
|
|
||||||
table.foot { width: 100%;
|
|
||||||
border-top: 1px dotted #808080;
|
|
||||||
margin-top: 1em;
|
|
||||||
font-size: smaller; }
|
|
||||||
td.foot-os { text-align: right; }
|
|
||||||
|
|
||||||
/* Sections and paragraphs. */
|
|
||||||
|
|
||||||
.manual-text {
|
|
||||||
margin-left: 3.8em; }
|
|
||||||
.Nd { }
|
|
||||||
section.Sh { }
|
|
||||||
h1.Sh { margin-top: 1.2em;
|
|
||||||
margin-bottom: 0.6em;
|
|
||||||
margin-left: -3.2em;
|
|
||||||
font-size: 110%; }
|
|
||||||
section.Ss { }
|
|
||||||
h2.Ss { margin-top: 1.2em;
|
|
||||||
margin-bottom: 0.6em;
|
|
||||||
margin-left: -1.2em;
|
|
||||||
font-size: 105%; }
|
|
||||||
.Pp { margin: 0.6em 0em; }
|
|
||||||
.Sx { }
|
|
||||||
.Xr { }
|
|
||||||
|
|
||||||
/* Displays and lists. */
|
|
||||||
|
|
||||||
.Bd { }
|
|
||||||
.Bd-indent { margin-left: 3.8em; }
|
|
||||||
|
|
||||||
.Bl-bullet { list-style-type: disc;
|
|
||||||
padding-left: 1em; }
|
|
||||||
.Bl-bullet > li { }
|
|
||||||
.Bl-dash { list-style-type: none;
|
|
||||||
padding-left: 0em; }
|
|
||||||
.Bl-dash > li:before {
|
|
||||||
content: "\2014 "; }
|
|
||||||
.Bl-item { list-style-type: none;
|
|
||||||
padding-left: 0em; }
|
|
||||||
.Bl-item > li { }
|
|
||||||
.Bl-compact > li {
|
|
||||||
margin-top: 0em; }
|
|
||||||
|
|
||||||
.Bl-enum { padding-left: 2em; }
|
|
||||||
.Bl-enum > li { }
|
|
||||||
.Bl-compact > li {
|
|
||||||
margin-top: 0em; }
|
|
||||||
|
|
||||||
.Bl-diag { }
|
|
||||||
.Bl-diag > dt {
|
|
||||||
font-style: normal;
|
|
||||||
font-weight: bold; }
|
|
||||||
.Bl-diag > dd {
|
|
||||||
margin-left: 0em; }
|
|
||||||
.Bl-hang { }
|
|
||||||
.Bl-hang > dt { }
|
|
||||||
.Bl-hang > dd {
|
|
||||||
margin-left: 5.5em; }
|
|
||||||
.Bl-inset { }
|
|
||||||
.Bl-inset > dt { }
|
|
||||||
.Bl-inset > dd {
|
|
||||||
margin-left: 0em; }
|
|
||||||
.Bl-ohang { }
|
|
||||||
.Bl-ohang > dt { }
|
|
||||||
.Bl-ohang > dd {
|
|
||||||
margin-left: 0em; }
|
|
||||||
.Bl-tag { margin-top: 0.6em;
|
|
||||||
margin-left: 5.5em; }
|
|
||||||
.Bl-tag > dt {
|
|
||||||
float: left;
|
|
||||||
margin-top: 0em;
|
|
||||||
margin-left: -5.5em;
|
|
||||||
padding-right: 0.5em;
|
|
||||||
vertical-align: top; }
|
|
||||||
.Bl-tag > dd {
|
|
||||||
clear: right;
|
|
||||||
width: 100%;
|
|
||||||
margin-top: 0em;
|
|
||||||
margin-left: 0em;
|
|
||||||
margin-bottom: 0.6em;
|
|
||||||
vertical-align: top;
|
|
||||||
overflow: auto; }
|
|
||||||
.Bl-compact { margin-top: 0em; }
|
|
||||||
.Bl-compact > dd {
|
|
||||||
margin-bottom: 0em; }
|
|
||||||
.Bl-compact > dt {
|
|
||||||
margin-top: 0em; }
|
|
||||||
|
|
||||||
.Bl-column { }
|
|
||||||
.Bl-column > tbody > tr { }
|
|
||||||
.Bl-column > tbody > tr > td {
|
|
||||||
margin-top: 1em; }
|
|
||||||
.Bl-compact > tbody > tr > td {
|
|
||||||
margin-top: 0em; }
|
|
||||||
|
|
||||||
.Rs { font-style: normal;
|
|
||||||
font-weight: normal; }
|
|
||||||
.RsA { }
|
|
||||||
.RsB { font-style: italic;
|
|
||||||
font-weight: normal; }
|
|
||||||
.RsC { }
|
|
||||||
.RsD { }
|
|
||||||
.RsI { font-style: italic;
|
|
||||||
font-weight: normal; }
|
|
||||||
.RsJ { font-style: italic;
|
|
||||||
font-weight: normal; }
|
|
||||||
.RsN { }
|
|
||||||
.RsO { }
|
|
||||||
.RsP { }
|
|
||||||
.RsQ { }
|
|
||||||
.RsR { }
|
|
||||||
.RsT { text-decoration: underline; }
|
|
||||||
.RsU { }
|
|
||||||
.RsV { }
|
|
||||||
|
|
||||||
.eqn { }
|
|
||||||
.tbl td { vertical-align: middle; }
|
|
||||||
|
|
||||||
.HP { margin-left: 3.8em;
|
|
||||||
text-indent: -3.8em; }
|
|
||||||
|
|
||||||
/* Semantic markup for command line utilities. */
|
|
||||||
|
|
||||||
table.Nm { }
|
|
||||||
code.Nm { font-style: normal;
|
|
||||||
font-weight: bold;
|
|
||||||
font-family: inherit; }
|
|
||||||
.Fl { font-style: normal;
|
|
||||||
font-weight: bold;
|
|
||||||
font-family: inherit; }
|
|
||||||
.Cm { font-style: normal;
|
|
||||||
font-weight: bold;
|
|
||||||
font-family: inherit; }
|
|
||||||
.Ar { font-style: italic;
|
|
||||||
font-weight: normal; }
|
|
||||||
.Op { display: inline; }
|
|
||||||
.Ic { font-style: normal;
|
|
||||||
font-weight: bold;
|
|
||||||
font-family: inherit; }
|
|
||||||
.Ev { font-style: normal;
|
|
||||||
font-weight: normal;
|
|
||||||
font-family: monospace; }
|
|
||||||
.Pa { font-style: italic;
|
|
||||||
font-weight: normal; }
|
|
||||||
|
|
||||||
/* Semantic markup for function libraries. */
|
|
||||||
|
|
||||||
.Lb { }
|
|
||||||
code.In { font-style: normal;
|
|
||||||
font-weight: bold;
|
|
||||||
font-family: inherit; }
|
|
||||||
a.In { }
|
|
||||||
.Fd { font-style: normal;
|
|
||||||
font-weight: bold;
|
|
||||||
font-family: inherit; }
|
|
||||||
.Ft { font-style: italic;
|
|
||||||
font-weight: normal; }
|
|
||||||
.Fn { font-style: normal;
|
|
||||||
font-weight: bold;
|
|
||||||
font-family: inherit; }
|
|
||||||
.Fa { font-style: italic;
|
|
||||||
font-weight: normal; }
|
|
||||||
.Vt { font-style: italic;
|
|
||||||
font-weight: normal; }
|
|
||||||
.Va { font-style: italic;
|
|
||||||
font-weight: normal; }
|
|
||||||
.Dv { font-style: normal;
|
|
||||||
font-weight: normal;
|
|
||||||
font-family: monospace; }
|
|
||||||
.Er { font-style: normal;
|
|
||||||
font-weight: normal;
|
|
||||||
font-family: monospace; }
|
|
||||||
|
|
||||||
/* Various semantic markup. */
|
|
||||||
|
|
||||||
.An { }
|
|
||||||
.Lk { }
|
|
||||||
.Mt { }
|
|
||||||
.Cd { font-style: normal;
|
|
||||||
font-weight: bold;
|
|
||||||
font-family: inherit; }
|
|
||||||
.Ad { font-style: italic;
|
|
||||||
font-weight: normal; }
|
|
||||||
.Ms { font-style: normal;
|
|
||||||
font-weight: bold; }
|
|
||||||
.St { }
|
|
||||||
.Ux { }
|
|
||||||
|
|
||||||
/* Physical markup. */
|
|
||||||
|
|
||||||
.Bf { display: inline; }
|
|
||||||
.No { font-style: normal;
|
|
||||||
font-weight: normal; }
|
|
||||||
.Em { font-style: italic;
|
|
||||||
font-weight: normal; }
|
|
||||||
.Sy { font-style: normal;
|
|
||||||
font-weight: bold; }
|
|
||||||
.Li { font-style: normal;
|
|
||||||
font-weight: normal;
|
|
||||||
font-family: monospace; }
|
|
||||||
|
|
||||||
/* Tooltip support. */
|
|
||||||
|
|
||||||
h1.Sh, h2.Ss { position: relative; }
|
|
||||||
.An, .Ar, .Cd, .Cm, .Dv, .Em, .Er, .Ev, .Fa, .Fd, .Fl, .Fn, .Ft,
|
|
||||||
.Ic, code.In, .Lb, .Lk, .Ms, .Mt, .Nd, code.Nm, .Pa, .Rs,
|
|
||||||
.St, .Sx, .Sy, .Va, .Vt, .Xr {
|
|
||||||
display: inline-block;
|
|
||||||
position: relative; }
|
|
||||||
|
|
||||||
.An::before { content: "An"; }
|
|
||||||
.Ar::before { content: "Ar"; }
|
|
||||||
.Cd::before { content: "Cd"; }
|
|
||||||
.Cm::before { content: "Cm"; }
|
|
||||||
.Dv::before { content: "Dv"; }
|
|
||||||
.Em::before { content: "Em"; }
|
|
||||||
.Er::before { content: "Er"; }
|
|
||||||
.Ev::before { content: "Ev"; }
|
|
||||||
.Fa::before { content: "Fa"; }
|
|
||||||
.Fd::before { content: "Fd"; }
|
|
||||||
.Fl::before { content: "Fl"; }
|
|
||||||
.Fn::before { content: "Fn"; }
|
|
||||||
.Ft::before { content: "Ft"; }
|
|
||||||
.Ic::before { content: "Ic"; }
|
|
||||||
code.In::before { content: "In"; }
|
|
||||||
.Lb::before { content: "Lb"; }
|
|
||||||
.Lk::before { content: "Lk"; }
|
|
||||||
.Ms::before { content: "Ms"; }
|
|
||||||
.Mt::before { content: "Mt"; }
|
|
||||||
.Nd::before { content: "Nd"; }
|
|
||||||
code.Nm::before { content: "Nm"; }
|
|
||||||
.Pa::before { content: "Pa"; }
|
|
||||||
.Rs::before { content: "Rs"; }
|
|
||||||
h1.Sh::before { content: "Sh"; }
|
|
||||||
h2.Ss::before { content: "Ss"; }
|
|
||||||
.St::before { content: "St"; }
|
|
||||||
.Sx::before { content: "Sx"; }
|
|
||||||
.Sy::before { content: "Sy"; }
|
|
||||||
.Va::before { content: "Va"; }
|
|
||||||
.Vt::before { content: "Vt"; }
|
|
||||||
.Xr::before { content: "Xr"; }
|
|
||||||
|
|
||||||
.An::before, .Ar::before, .Cd::before, .Cm::before,
|
|
||||||
.Dv::before, .Em::before, .Er::before, .Ev::before,
|
|
||||||
.Fa::before, .Fd::before, .Fl::before, .Fn::before, .Ft::before,
|
|
||||||
.Ic::before, code.In::before, .Lb::before, .Lk::before,
|
|
||||||
.Ms::before, .Mt::before, .Nd::before, code.Nm::before,
|
|
||||||
.Pa::before, .Rs::before,
|
|
||||||
h1.Sh::before, h2.Ss::before, .St::before, .Sx::before, .Sy::before,
|
|
||||||
.Va::before, .Vt::before, .Xr::before {
|
|
||||||
opacity: 0;
|
|
||||||
transition: .15s ease opacity;
|
|
||||||
pointer-events: none;
|
|
||||||
position: absolute;
|
|
||||||
bottom: 100%;
|
|
||||||
box-shadow: 0 0 .35em #000;
|
|
||||||
padding: .15em .25em;
|
|
||||||
white-space: nowrap;
|
|
||||||
font-family: Helvetica,Arial,sans-serif;
|
|
||||||
font-style: normal;
|
|
||||||
font-weight: bold;
|
|
||||||
color: black;
|
|
||||||
background: #fff; }
|
|
||||||
.An:hover::before, .Ar:hover::before, .Cd:hover::before, .Cm:hover::before,
|
|
||||||
.Dv:hover::before, .Em:hover::before, .Er:hover::before, .Ev:hover::before,
|
|
||||||
.Fa:hover::before, .Fd:hover::before, .Fl:hover::before, .Fn:hover::before,
|
|
||||||
.Ft:hover::before, .Ic:hover::before, code.In:hover::before,
|
|
||||||
.Lb:hover::before, .Lk:hover::before, .Ms:hover::before, .Mt:hover::before,
|
|
||||||
.Nd:hover::before, code.Nm:hover::before, .Pa:hover::before,
|
|
||||||
.Rs:hover::before, h1.Sh:hover::before, h2.Ss:hover::before, .St:hover::before,
|
|
||||||
.Sx:hover::before, .Sy:hover::before, .Va:hover::before, .Vt:hover::before,
|
|
||||||
.Xr:hover::before {
|
|
||||||
opacity: 1;
|
|
||||||
pointer-events: inherit; }
|
|
||||||
|
|
||||||
/* Overrides to avoid excessive margins on small devices. */
|
|
||||||
|
|
||||||
@media (max-width: 37.5em) {
|
|
||||||
.manual-text {
|
|
||||||
margin-left: 0.5em; }
|
|
||||||
h1.Sh, h2.Ss { margin-left: 0em; }
|
|
||||||
.Bd-indent { margin-left: 2em; }
|
|
||||||
.Bl-hang > dd {
|
|
||||||
margin-left: 2em; }
|
|
||||||
.Bl-tag { margin-left: 2em; }
|
|
||||||
.Bl-tag > dt {
|
|
||||||
margin-left: -2em; }
|
|
||||||
.HP { margin-left: 2em;
|
|
||||||
text-indent: -2em; }
|
|
||||||
}
|
|
||||||
@@ -1,295 +0,0 @@
|
|||||||
<!DOCTYPE html>
|
|
||||||
<html>
|
|
||||||
<!-- This is an automatically generated file. Do not edit.
|
|
||||||
This file is part of RGBDS.
|
|
||||||
|
|
||||||
Copyright (c) 2010-2019, Anthony J. Bentley and RGBDS contributors.
|
|
||||||
|
|
||||||
SPDX-License-Identifier: MIT
|
|
||||||
-->
|
|
||||||
<head>
|
|
||||||
<meta name="viewport" content="width=device-width, initial-scale=1">
|
|
||||||
<meta charset="utf-8"/>
|
|
||||||
<link rel="stylesheet" href="mandoc.css" type="text/css" media="all"/>
|
|
||||||
<link rel="stylesheet" href="rgbds.css" type="text/css" media="all"/>
|
|
||||||
<title>RGBASM(1)</title>
|
|
||||||
</head>
|
|
||||||
<body>
|
|
||||||
<table class="head">
|
|
||||||
<tr>
|
|
||||||
<td class="head-ltitle">RGBASM(1)</td>
|
|
||||||
<td class="head-vol">General Commands Manual</td>
|
|
||||||
<td class="head-rtitle">RGBASM(1)</td>
|
|
||||||
</tr>
|
|
||||||
</table>
|
|
||||||
<div class="manual-text">
|
|
||||||
<section class="Sh">
|
|
||||||
<h1 class="Sh" id="NAME"><a class="permalink" href="#NAME">NAME</a></h1>
|
|
||||||
<code class="Nm">rgbasm</code> —
|
|
||||||
<span class="Nd">Game Boy assembler</span>
|
|
||||||
</section>
|
|
||||||
<section class="Sh">
|
|
||||||
<h1 class="Sh" id="SYNOPSIS"><a class="permalink" href="#SYNOPSIS">SYNOPSIS</a></h1>
|
|
||||||
<table class="Nm">
|
|
||||||
<tr>
|
|
||||||
<td><code class="Nm">rgbasm</code></td>
|
|
||||||
<td>[<code class="Fl"><a href="#E">-E</a><a href="#h">h</a><a href="#L">L</a><a href="#V">V</a><a href="#v">v</a><a href="#w">w</a></code>] [<code class="Fl"><a href="#b">-b</a></code>
|
|
||||||
<var class="Ar">chars</var>] [<code class="Fl"><a href="#D">-D</a></code>
|
|
||||||
<var class="Ar">name</var>[=<var class="Ar">value</var>]]
|
|
||||||
[<code class="Fl"><a href="#g">-g</a></code> <var class="Ar">chars</var>]
|
|
||||||
[<code class="Fl"><a href="#i">-i</a></code> <var class="Ar">path</var>]
|
|
||||||
[<code class="Fl"><a href="#M">-M</a></code> <var class="Ar">depend_file</var>]
|
|
||||||
[<code class="Fl"><a href="#M">-M</a><a href="#G">G</a></code>] [<code class="Fl"><a href="#M">-M</a><a href="#P">P</a></code>]
|
|
||||||
[<code class="Fl"><a href="#M">-M</a><a href="#T">T</a></code> <var class="Ar">target_file</var>]
|
|
||||||
[<code class="Fl"><a href="#M">-M</a><a href="#Q">Q</a></code> <var class="Ar">target_file</var>]
|
|
||||||
[<code class="Fl"><a href="#o">-o</a></code> <var class="Ar">out_file</var>]
|
|
||||||
[<code class="Fl"><a href="#p">-p</a></code> <var class="Ar">pad_value</var>]
|
|
||||||
[<code class="Fl"><a href="#r">-r</a></code> <var class="Ar">recursion_depth</var>]
|
|
||||||
[<code class="Fl"><a href="#W">-W</a></code> <var class="Ar">warning</var>]
|
|
||||||
<var class="Ar">file ...</var></td>
|
|
||||||
</tr>
|
|
||||||
</table>
|
|
||||||
</section>
|
|
||||||
<section class="Sh">
|
|
||||||
<h1 class="Sh" id="DESCRIPTION"><a class="permalink" href="#DESCRIPTION">DESCRIPTION</a></h1>
|
|
||||||
The <code class="Nm">rgbasm</code> program creates an RGB object file from an
|
|
||||||
assembly source file. The input <var class="Ar">file</var> can be a file path,
|
|
||||||
or <code class="Cm">-</code> denoting <code class="Cm">stdin</code>.
|
|
||||||
<p class="Pp">Note that options can be abbreviated as long as the abbreviation
|
|
||||||
is unambiguous: <code class="Fl">--verb</code> is
|
|
||||||
<code class="Fl">--verbose</code>, but
|
|
||||||
<code class="Fl">--ver</code> is invalid because it
|
|
||||||
could also be <code class="Fl">--version</code>. The
|
|
||||||
arguments are as follows:</p>
|
|
||||||
<dl class="Bl-tag">
|
|
||||||
<dt><a class="permalink" href="#b"><code class="Fl" id="b">-b</code></a>
|
|
||||||
<var class="Ar">chars</var>,
|
|
||||||
<code class="Fl">--binary-digits</code>
|
|
||||||
<var class="Ar">chars</var></dt>
|
|
||||||
<dd>Change the two characters used for binary constants. The defaults are
|
|
||||||
01.</dd>
|
|
||||||
<dt><a class="permalink" href="#D"><code class="Fl" id="D">-D</code></a>
|
|
||||||
<var class="Ar">name</var>[=<var class="Ar">value</var>],
|
|
||||||
<code class="Fl">-</code> <code class="Fl">-define</code>
|
|
||||||
<var class="Ar">name</var>[=<var class="Ar">value</var>]</dt>
|
|
||||||
<dd>Add a string symbol to the compiled source code. This is equivalent to
|
|
||||||
‘<code class="Li"><var class="Ar">name</var> <code class="Ic">EQUS
|
|
||||||
"</code><var class="Ar">value</var>"</code>’ in code, or
|
|
||||||
‘<code class="Li"><var class="Ar">name</var> <code class="Ic">EQUS
|
|
||||||
"1"</code></code>’ if <var class="Ar">value</var> is not
|
|
||||||
specified.</dd>
|
|
||||||
<dt><a class="permalink" href="#E"><code class="Fl" id="E">-E</code></a>,
|
|
||||||
<code class="Fl">--export-all</code></dt>
|
|
||||||
<dd>Export all labels, including unreferenced and local labels.</dd>
|
|
||||||
<dt><a class="permalink" href="#g"><code class="Fl" id="g">-g</code></a>
|
|
||||||
<var class="Ar">chars</var>,
|
|
||||||
<code class="Fl">--gfx-chars</code>
|
|
||||||
<var class="Ar">chars</var></dt>
|
|
||||||
<dd>Change the four characters used for gfx constants. The defaults are
|
|
||||||
0123.</dd>
|
|
||||||
<dt><a class="permalink" href="#h"><code class="Fl" id="h">-h</code></a>,
|
|
||||||
<code class="Fl">--halt-without-nop</code></dt>
|
|
||||||
<dd>By default, <code class="Nm">rgbasm</code> inserts a
|
|
||||||
<code class="Ic">nop</code> instruction immediately after any
|
|
||||||
<code class="Ic">halt</code> instruction. The <code class="Fl">-h</code>
|
|
||||||
option disables this behavior.</dd>
|
|
||||||
<dt><a class="permalink" href="#i"><code class="Fl" id="i">-i</code></a>
|
|
||||||
<var class="Ar">path</var>,
|
|
||||||
<code class="Fl">--include</code>
|
|
||||||
<var class="Ar">path</var></dt>
|
|
||||||
<dd>Add an include path.</dd>
|
|
||||||
<dt><a class="permalink" href="#L"><code class="Fl" id="L">-L</code></a>,
|
|
||||||
<code class="Fl">--preserve-ld</code></dt>
|
|
||||||
<dd>Disable the optimization that turns loads of the form <code class="Ic">LD
|
|
||||||
[$FF00+n8],A</code> into the opcode <code class="Ic">LDH
|
|
||||||
[$FF00+n8],A</code> in order to have full control of the result in the
|
|
||||||
final ROM.</dd>
|
|
||||||
<dt><a class="permalink" href="#M"><code class="Fl" id="M">-M</code></a>
|
|
||||||
<var class="Ar">depend_file</var>,
|
|
||||||
<code class="Fl">--dependfile</code>
|
|
||||||
<var class="Ar">depend_file</var></dt>
|
|
||||||
<dd>Print <a class="Xr">make(1)</a> dependencies to
|
|
||||||
<var class="Ar">depend_file</var>.</dd>
|
|
||||||
<dt><a class="permalink" href="#MG"><code class="Fl" id="MG">-MG</code></a></dt>
|
|
||||||
<dd>To be used in conjunction with <code class="Fl">-M</code>. This makes
|
|
||||||
<code class="Nm">rgbasm</code> assume that missing files are
|
|
||||||
auto-generated: when <code class="Ic">INCLUDE</code> or
|
|
||||||
<code class="Ic">INCBIN</code> is attempted on a non-existent file, it is
|
|
||||||
added as a dependency, then <code class="Nm">rgbasm</code> exits normally
|
|
||||||
instead of erroring out. This feature is used in automatic updating of
|
|
||||||
makefiles.</dd>
|
|
||||||
<dt><a class="permalink" href="#MP"><code class="Fl" id="MP">-MP</code></a></dt>
|
|
||||||
<dd>When enabled, this causes a phony target to be added for each dependency
|
|
||||||
other than the main file. This prevents <a class="Xr">make(1)</a> from
|
|
||||||
erroring out when dependency files are deleted.</dd>
|
|
||||||
<dt><a class="permalink" href="#MT"><code class="Fl" id="MT">-MT</code></a>
|
|
||||||
<var class="Ar">target_file</var></dt>
|
|
||||||
<dd>Add a target to the rules emitted by <code class="Fl">-M</code>. The exact
|
|
||||||
string provided will be written, including spaces and special characters.
|
|
||||||
<div class="Bd Bd-indent"><code class="Li"><code class="Fl">-MT</code>
|
|
||||||
<code class="Fl">-fileA</code> <code class="Fl">-MT</code>
|
|
||||||
<code class="Fl">-fileB</code></code></div>
|
|
||||||
is equivalent to
|
|
||||||
<div class="Bd Bd-indent"><code class="Li"><code class="Fl">-MT</code>
|
|
||||||
<code class="Fl">-'fileA</code>
|
|
||||||
<code class="Fl">-fileB'</code>.</code></div>
|
|
||||||
If neither this nor <code class="Fl">-MQ</code> is specified, the output
|
|
||||||
file name is used.</dd>
|
|
||||||
<dt><a class="permalink" href="#MQ"><code class="Fl" id="MQ">-MQ</code></a>
|
|
||||||
<var class="Ar">target_file</var></dt>
|
|
||||||
<dd>Same as <code class="Fl">-MT</code>, but additionally escapes any special
|
|
||||||
<a class="Xr">make(1)</a> characters, essentially ‘$’.</dd>
|
|
||||||
<dt><a class="permalink" href="#o"><code class="Fl" id="o">-o</code></a>
|
|
||||||
<var class="Ar">out_file</var>,
|
|
||||||
<code class="Fl">--output</code>
|
|
||||||
<var class="Ar">out_file</var></dt>
|
|
||||||
<dd>Write an object file to the given filename.</dd>
|
|
||||||
<dt><a class="permalink" href="#p"><code class="Fl" id="p">-p</code></a>
|
|
||||||
<var class="Ar">pad_value</var>,
|
|
||||||
<code class="Fl">--pad-value</code>
|
|
||||||
<var class="Ar">pad_value</var></dt>
|
|
||||||
<dd>When padding an image, pad with this value. The default is 0x00.</dd>
|
|
||||||
<dt><a class="permalink" href="#r"><code class="Fl" id="r">-r</code></a>
|
|
||||||
<var class="Ar">recursion_depth</var>,
|
|
||||||
<code class="Fl">--recursion-depth</code>
|
|
||||||
<var class="Ar">recursion_depth</var></dt>
|
|
||||||
<dd>Specifies the recursion depth at which RGBASM will assume being in an
|
|
||||||
infinite loop.</dd>
|
|
||||||
<dt><a class="permalink" href="#V"><code class="Fl" id="V">-V</code></a>,
|
|
||||||
<code class="Fl">--version</code></dt>
|
|
||||||
<dd>Print the version of the program and exit.</dd>
|
|
||||||
<dt><a class="permalink" href="#v"><code class="Fl" id="v">-v</code></a>,
|
|
||||||
<code class="Fl">--verbose</code></dt>
|
|
||||||
<dd>Be verbose.</dd>
|
|
||||||
<dt><a class="permalink" href="#W"><code class="Fl" id="W">-W</code></a>
|
|
||||||
<var class="Ar">warning</var>,
|
|
||||||
<code class="Fl">--warning</code>
|
|
||||||
<var class="Ar">warning</var></dt>
|
|
||||||
<dd>Set warning flag <var class="Ar">warning</var>. A warning message will be
|
|
||||||
printed if <var class="Ar">warning</var> is an unknown warning flag. See
|
|
||||||
the <a class="Sx" href="#DIAGNOSTICS">DIAGNOSTICS</a> section for a list
|
|
||||||
of warnings.</dd>
|
|
||||||
<dt><a class="permalink" href="#w"><code class="Fl" id="w">-w</code></a></dt>
|
|
||||||
<dd>Disable all warning output, even when turned into errors.</dd>
|
|
||||||
</dl>
|
|
||||||
</section>
|
|
||||||
<section class="Sh">
|
|
||||||
<h1 class="Sh" id="DIAGNOSTICS"><a class="permalink" href="#DIAGNOSTICS">DIAGNOSTICS</a></h1>
|
|
||||||
Warnings are diagnostic messages that indicate possibly erroneous behavior that
|
|
||||||
does not necessarily compromise the assembling process. The following options
|
|
||||||
alter the way warnings are processed.
|
|
||||||
<dl class="Bl-tag">
|
|
||||||
<dt><a class="permalink" href="#Werror"><code class="Fl" id="Werror">-Werror</code></a></dt>
|
|
||||||
<dd>Make all warnings into errors.</dd>
|
|
||||||
<dt><a class="permalink" href="#Werror="><code class="Fl" id="Werror=">-Werror=</code></a></dt>
|
|
||||||
<dd>Make the specified warning into an error. A warning's name is appended
|
|
||||||
(example: <code class="Fl">-Werror=obsolete</code>), and this warning is
|
|
||||||
implicitly enabled and turned into an error. This is an error if used with
|
|
||||||
a meta warning, such as <code class="Fl">-Werror=all</code>.</dd>
|
|
||||||
</dl>
|
|
||||||
<p class="Pp">The following warnings are “meta” warnings, that
|
|
||||||
enable a collection of other warnings. If a specific warning is toggled via
|
|
||||||
a meta flag and a specific one, the more specific one takes priority. The
|
|
||||||
position on the command-line acts as a tie breaker, the last one taking
|
|
||||||
effect.</p>
|
|
||||||
<dl class="Bl-tag">
|
|
||||||
<dt><a class="permalink" href="#Wall"><code class="Fl" id="Wall">-Wall</code></a></dt>
|
|
||||||
<dd>This enables warnings that are likely to indicate an error or undesired
|
|
||||||
behavior, and that can easily be fixed.</dd>
|
|
||||||
<dt><a class="permalink" href="#Wextra"><code class="Fl" id="Wextra">-Wextra</code></a></dt>
|
|
||||||
<dd>This enables extra warnings that are less likely to pose a problem, but
|
|
||||||
that may still be wanted.</dd>
|
|
||||||
<dt><a class="permalink" href="#Weverything"><code class="Fl" id="Weverything">-Weverything</code></a></dt>
|
|
||||||
<dd>Enables literally every warning.</dd>
|
|
||||||
</dl>
|
|
||||||
<p class="Pp">The following warnings are actual warning flags; with each
|
|
||||||
description, the corresponding warning flag is included. Note that each of
|
|
||||||
these flag also has a negation (for example,
|
|
||||||
<code class="Fl">-Wempty-entry</code> enables the warning that
|
|
||||||
<code class="Fl">-Wno-empty-entry</code> disables). Only the non-default
|
|
||||||
flag is listed here. Ignoring the “no-” prefix, entries are
|
|
||||||
listed alphabetically.</p>
|
|
||||||
<dl class="Bl-tag">
|
|
||||||
<dt><a class="permalink" href="#Wno-assert"><code class="Fl" id="Wno-assert">-Wno-assert</code></a></dt>
|
|
||||||
<dd>Warns when <code class="Ic">WARN</code><span class="No">-type</span>
|
|
||||||
assertions fail. (See “Aborting the assembly process” in
|
|
||||||
<a class="Xr" href="rgbasm.5.html">rgbasm(5)</a> for <code class="Ic">ASSERT</code>).</dd>
|
|
||||||
<dt><a class="permalink" href="#Wbuiltin-args"><code class="Fl" id="Wbuiltin-args">-Wbuiltin-args</code></a></dt>
|
|
||||||
<dd>Warn about incorrect arguments to built-in functions, such as
|
|
||||||
<code class="Fn">STRSUB</code>() with indexes outside of the string's
|
|
||||||
bounds. This warning is enabled by <code class="Fl">-Wall</code>.</dd>
|
|
||||||
<dt><a class="permalink" href="#Wdiv"><code class="Fl" id="Wdiv">-Wdiv</code></a></dt>
|
|
||||||
<dd>Warn when dividing the smallest negative integer by -1, which yields
|
|
||||||
itself due to integer overflow.</dd>
|
|
||||||
<dt><a class="permalink" href="#Wempty-entry"><code class="Fl" id="Wempty-entry">-Wempty-entry</code></a></dt>
|
|
||||||
<dd>Warn when an empty entry is encountered in a <code class="Ic">db</code>,
|
|
||||||
<code class="Ic">dw</code>, <code class="Ic">dl</code> list. This warning
|
|
||||||
is enabled by <code class="Fl">-Wextra</code>.</dd>
|
|
||||||
<dt><a class="permalink" href="#Wlarge-constant"><code class="Fl" id="Wlarge-constant">-Wlarge-constant</code></a></dt>
|
|
||||||
<dd>Warn when a constant too large to fit in a signed 32-bit integer is
|
|
||||||
encountered. This warning is enabled by
|
|
||||||
<code class="Fl">-Wall</code>.</dd>
|
|
||||||
<dt><a class="permalink" href="#Wlong-string"><code class="Fl" id="Wlong-string">-Wlong-string</code></a></dt>
|
|
||||||
<dd>Warn when a string too long to fit in internal buffers is encountered.
|
|
||||||
This warning is enabled by <code class="Fl">-Wall</code>.</dd>
|
|
||||||
<dt><a class="permalink" href="#Wno-obsolete"><code class="Fl" id="Wno-obsolete">-Wno-obsolete</code></a></dt>
|
|
||||||
<dd>Warn when obsolete constructs such as the <code class="Ic">jp [hl]</code>
|
|
||||||
instruction or <code class="Ic">HOME</code> section type are
|
|
||||||
encountered.</dd>
|
|
||||||
<dt><a class="permalink" href="#Wshift"><code class="Fl" id="Wshift">-Wshift</code></a></dt>
|
|
||||||
<dd>Warn when shifting right a negative value. Use a division by 2^N
|
|
||||||
instead.</dd>
|
|
||||||
<dt><a class="permalink" href="#Wshift-amount"><code class="Fl" id="Wshift-amount">-Wshift-amount</code></a></dt>
|
|
||||||
<dd>Warn when a shift's operand is negative or greater than 32.</dd>
|
|
||||||
<dt><a class="permalink" href="#Wno-truncation"><code class="Fl" id="Wno-truncation">-Wno-truncation</code></a></dt>
|
|
||||||
<dd>Warn when an implicit truncation (for example, <code class="Ic">db</code>)
|
|
||||||
loses some bits.</dd>
|
|
||||||
<dt><a class="permalink" href="#Wno-user"><code class="Fl" id="Wno-user">-Wno-user</code></a></dt>
|
|
||||||
<dd>Warn when the <code class="Ic">WARN</code> built-in is executed. (See
|
|
||||||
“Aborting the assembly process” in
|
|
||||||
<a class="Xr" href="rgbasm.5.html">rgbasm(5)</a> for <code class="Ic">WARN</code>).</dd>
|
|
||||||
</dl>
|
|
||||||
</section>
|
|
||||||
<section class="Sh">
|
|
||||||
<h1 class="Sh" id="EXAMPLES"><a class="permalink" href="#EXAMPLES">EXAMPLES</a></h1>
|
|
||||||
You can assemble a source file in two ways.
|
|
||||||
<p class="Pp">Straightforward way:</p>
|
|
||||||
<div class="Bd Bd-indent"><code class="Li">$ rgbasm -o bar.o
|
|
||||||
foo.asm</code></div>
|
|
||||||
<p class="Pp">Pipes way:</p>
|
|
||||||
<div class="Bd Bd-indent"><code class="Li">$ cat foo.asm | rgbasm -o bar.o
|
|
||||||
-</code></div>
|
|
||||||
<div class="Bd Bd-indent"><code class="Li">$ rgbasm -o bar.o - <
|
|
||||||
foo.asm</code></div>
|
|
||||||
<p class="Pp">The resulting object file is not yet a usable ROM image—it
|
|
||||||
must first be run through <a class="Xr" href="rgblink.1.html">rgblink(1)</a> and then
|
|
||||||
<a class="Xr" href="rgbfix.1.html">rgbfix(1)</a>.</p>
|
|
||||||
</section>
|
|
||||||
<section class="Sh">
|
|
||||||
<h1 class="Sh" id="BUGS"><a class="permalink" href="#BUGS">BUGS</a></h1>
|
|
||||||
Please report bugs on
|
|
||||||
<a class="Lk" href="https://github.com/rednex/rgbds/issues">GitHub</a>.
|
|
||||||
</section>
|
|
||||||
<section class="Sh">
|
|
||||||
<h1 class="Sh" id="SEE_ALSO"><a class="permalink" href="#SEE_ALSO">SEE
|
|
||||||
ALSO</a></h1>
|
|
||||||
<a class="Xr" href="rgbasm.5.html">rgbasm(5)</a>, <a class="Xr" href="rgbfix.1.html">rgbfix(1)</a>,
|
|
||||||
<a class="Xr" href="rgblink.1.html">rgblink(1)</a>, <a class="Xr" href="rgbds.5.html">rgbds(5)</a>,
|
|
||||||
<a class="Xr" href="rgbds.7.html">rgbds(7)</a>, <a class="Xr" href="gbz80.7.html">gbz80(7)</a>
|
|
||||||
</section>
|
|
||||||
<section class="Sh">
|
|
||||||
<h1 class="Sh" id="HISTORY"><a class="permalink" href="#HISTORY">HISTORY</a></h1>
|
|
||||||
<code class="Nm">rgbasm</code> was originally written by Carsten Sørensen
|
|
||||||
as part of the ASMotor package, and was later packaged in RGBDS by Justin
|
|
||||||
Lloyd. It is now maintained by a number of contributors at
|
|
||||||
<a class="Lk" href="https://github.com/rednex/rgbds">https://github.com/rednex/rgbds</a>.
|
|
||||||
</section>
|
|
||||||
</div>
|
|
||||||
<table class="foot">
|
|
||||||
<tr>
|
|
||||||
<td class="foot-date">July 8, 2019</td>
|
|
||||||
<td class="foot-os">General</td>
|
|
||||||
</tr>
|
|
||||||
</table>
|
|
||||||
</body>
|
|
||||||
</html>
|
|
||||||
-1751
File diff suppressed because it is too large
Load Diff
@@ -1,363 +0,0 @@
|
|||||||
<!DOCTYPE html>
|
|
||||||
<html>
|
|
||||||
<!-- This is an automatically generated file. Do not edit.
|
|
||||||
This file is part of RGBDS.
|
|
||||||
|
|
||||||
Copyright (c) 2017-2018, Antonio Nino Diaz and RGBDS contributors.
|
|
||||||
|
|
||||||
SPDX-License-Identifier: MIT
|
|
||||||
-->
|
|
||||||
<head>
|
|
||||||
<meta name="viewport" content="width=device-width, initial-scale=1">
|
|
||||||
<meta charset="utf-8"/>
|
|
||||||
<link rel="stylesheet" href="mandoc.css" type="text/css" media="all"/>
|
|
||||||
<link rel="stylesheet" href="rgbds.css" type="text/css" media="all"/>
|
|
||||||
<title>RGBDS(5)</title>
|
|
||||||
</head>
|
|
||||||
<body>
|
|
||||||
<table class="head">
|
|
||||||
<tr>
|
|
||||||
<td class="head-ltitle">RGBDS(5)</td>
|
|
||||||
<td class="head-vol">File Formats Manual</td>
|
|
||||||
<td class="head-rtitle">RGBDS(5)</td>
|
|
||||||
</tr>
|
|
||||||
</table>
|
|
||||||
<div class="manual-text">
|
|
||||||
<section class="Sh">
|
|
||||||
<h1 class="Sh" id="NAME"><a class="permalink" href="#NAME">NAME</a></h1>
|
|
||||||
<code class="Nm">rgbds</code> —
|
|
||||||
<span class="Nd">object file format documentation</span>
|
|
||||||
</section>
|
|
||||||
<section class="Sh">
|
|
||||||
<h1 class="Sh" id="DESCRIPTION"><a class="permalink" href="#DESCRIPTION">DESCRIPTION</a></h1>
|
|
||||||
This is the description of the object files used by <a class="Xr" href="rgbasm.1.html">rgbasm(1)</a>
|
|
||||||
and <a class="Xr" href="rgblink.1.html">rgblink(1)</a>. <i class="Em">Please note that the
|
|
||||||
specifications may change.</i> This toolchain is in development and new
|
|
||||||
features may require adding more information to the current format, or
|
|
||||||
modifying some fields, which would break compatibility with older versions.
|
|
||||||
</section>
|
|
||||||
<section class="Sh">
|
|
||||||
<h1 class="Sh" id="FILE_STRUCTURE"><a class="permalink" href="#FILE_STRUCTURE">FILE
|
|
||||||
STRUCTURE</a></h1>
|
|
||||||
The following types are used:
|
|
||||||
<p class="Pp"><var class="Ar">LONG</var> is a 32‐bit integer stored in
|
|
||||||
little‐endian format. <var class="Ar">BYTE</var> is an 8‐bit
|
|
||||||
integer. <var class="Ar">STRING</var> is a 0‐terminated string of
|
|
||||||
<var class="Ar">BYTE</var>.</p>
|
|
||||||
<div class="Bd Pp">
|
|
||||||
<pre>
|
|
||||||
; Header
|
|
||||||
|
|
||||||
BYTE ID[4] ; "RGB9"
|
|
||||||
LONG RevisionNumber ; The format's revision number this file uses
|
|
||||||
LONG NumberOfSymbols ; The number of symbols used in this file
|
|
||||||
LONG NumberOfSections ; The number of sections used in this file
|
|
||||||
|
|
||||||
; Symbols
|
|
||||||
|
|
||||||
REPT NumberOfSymbols ; Number of symbols defined in this object file.
|
|
||||||
|
|
||||||
STRING Name ; The name of this symbol. Local symbols are stored
|
|
||||||
; as "Scope.Symbol".
|
|
||||||
|
|
||||||
BYTE Type ; 0 = LOCAL symbol only used in this file.
|
|
||||||
; 1 = IMPORT this symbol from elsewhere
|
|
||||||
; 2 = EXPORT this symbol to other objects.
|
|
||||||
; Bit 7 is independent from the above value, and
|
|
||||||
; encodes whether the section is unionized
|
|
||||||
|
|
||||||
IF (Type & 0x7F) != 1 ; If symbol is defined in this object file.
|
|
||||||
|
|
||||||
STRING FileName ; File where the symbol is defined.
|
|
||||||
|
|
||||||
LONG LineNum ; Line number in the file where the symbol is defined.
|
|
||||||
|
|
||||||
LONG SectionID ; The section number (of this object file) in which
|
|
||||||
; this symbol is defined. If it doesn't belong to any
|
|
||||||
; specific section (like a constant), this field has
|
|
||||||
; the value -1.
|
|
||||||
|
|
||||||
LONG Value ; The symbols value. It's the offset into that
|
|
||||||
; symbol's section.
|
|
||||||
|
|
||||||
ENDC
|
|
||||||
|
|
||||||
ENDR
|
|
||||||
|
|
||||||
; Sections
|
|
||||||
|
|
||||||
REPT NumberOfSections
|
|
||||||
STRING Name ; Name of the section
|
|
||||||
|
|
||||||
LONG Size ; Size in bytes of this section
|
|
||||||
|
|
||||||
BYTE Type ; 0 = WRAM0
|
|
||||||
; 1 = VRAM
|
|
||||||
; 2 = ROMX
|
|
||||||
; 3 = ROM0
|
|
||||||
; 4 = HRAM
|
|
||||||
; 5 = WRAMX
|
|
||||||
; 6 = SRAM
|
|
||||||
; 7 = OAM
|
|
||||||
|
|
||||||
LONG Org ; Address to fix this section at. -1 if the linker should
|
|
||||||
; decide (floating address).
|
|
||||||
|
|
||||||
LONG Bank ; Bank to load this section into. -1 if the linker should
|
|
||||||
; decide (floating bank). This field is only valid for ROMX,
|
|
||||||
; VRAM, WRAMX and SRAM sections.
|
|
||||||
|
|
||||||
BYTE Align ; Alignment of this section, as N bits. 0 when not specified.
|
|
||||||
|
|
||||||
LONG Ofs ; Offset relative to the alignment specified above.
|
|
||||||
; Must be below 1 << Align.
|
|
||||||
|
|
||||||
IF (Type == ROMX) || (Type == ROM0) ; Sections that can contain data.
|
|
||||||
|
|
||||||
BYTE Data[Size] ; Raw data of the section.
|
|
||||||
|
|
||||||
LONG NumberOfPatches ; Number of patches to apply.
|
|
||||||
|
|
||||||
REPT NumberOfPatches
|
|
||||||
|
|
||||||
STRING SourceFile ; Name of the source file (for printing error
|
|
||||||
; messages).
|
|
||||||
|
|
||||||
LONG Offset ; Offset into the section where patch should
|
|
||||||
; be applied (in bytes).
|
|
||||||
|
|
||||||
LONG PCSectionID ; Index within the file of the section in which
|
|
||||||
; PC is located.
|
|
||||||
; This is usually the same section that the
|
|
||||||
; patch should be applied into, except e.g.
|
|
||||||
; with LOAD blocks.
|
|
||||||
|
|
||||||
LONG PCOffset ; PC's offset into the above section.
|
|
||||||
; Used because the section may be floating, so
|
|
||||||
; PC's value is not known to RGBASM.
|
|
||||||
|
|
||||||
BYTE Type ; 0 = BYTE patch.
|
|
||||||
; 1 = little endian WORD patch.
|
|
||||||
; 2 = little endian LONG patch.
|
|
||||||
; 3 = JR offset value BYTE patch.
|
|
||||||
|
|
||||||
LONG RPNSize ; Size of the buffer with the RPN.
|
|
||||||
; expression.
|
|
||||||
|
|
||||||
BYTE RPN[RPNSize] ; RPN expression. Definition below.
|
|
||||||
|
|
||||||
ENDR
|
|
||||||
|
|
||||||
ENDC
|
|
||||||
|
|
||||||
ENDR
|
|
||||||
|
|
||||||
; Assertions
|
|
||||||
|
|
||||||
LONG NumberOfAssertions
|
|
||||||
|
|
||||||
REPT NumberOfAssertions
|
|
||||||
|
|
||||||
STRING SourceFile ; Name of the source file (for printing the failure).
|
|
||||||
|
|
||||||
LONG Offset ; Offset into the section where the assertion is located.
|
|
||||||
|
|
||||||
LONG SectionID ; Index within the file of the section in which PC is
|
|
||||||
; located, or -1 if defined outside a section.
|
|
||||||
|
|
||||||
LONG PCOffset ; PC's offset into the above section.
|
|
||||||
; Used because the section may be floating, so PC's value
|
|
||||||
; is not known to RGBASM.
|
|
||||||
|
|
||||||
BYTE Type ; 0 = Prints the message but allows linking to continue
|
|
||||||
; 1 = Prints the message and evaluates other assertions,
|
|
||||||
; but linking fails afterwards
|
|
||||||
; 2 = Prints the message and immediately fails linking
|
|
||||||
|
|
||||||
LONG RPNSize ; Size of the RPN expression's buffer.
|
|
||||||
|
|
||||||
BYTE RPN[RPNSize] ; RPN expression, same as patches. Assert fails if == 0.
|
|
||||||
|
|
||||||
STRING Message ; A message displayed when the assert fails. If set to
|
|
||||||
; the empty string, a generic message is printed instead.
|
|
||||||
|
|
||||||
ENDR
|
|
||||||
</pre>
|
|
||||||
</div>
|
|
||||||
<section class="Ss">
|
|
||||||
<h2 class="Ss" id="RPN_DATA"><a class="permalink" href="#RPN_DATA">RPN
|
|
||||||
DATA</a></h2>
|
|
||||||
Expressions in the object file are stored as RPN. This is an expression of the
|
|
||||||
form “2 5 +”. This will first push the value “2”
|
|
||||||
to the stack, then “5”. The “+” operator pops two
|
|
||||||
arguments from the stack, adds them, and then pushes the result on the stack,
|
|
||||||
effectively replacing the two top arguments with their sum. In the RGB format,
|
|
||||||
RPN expressions are stored as <var class="Ar">BYTE</var>s with some bytes
|
|
||||||
being special prefixes for integers and symbols.
|
|
||||||
<table class="Bl-column Bd-indent">
|
|
||||||
<tr>
|
|
||||||
<th>Value</th>
|
|
||||||
<th>Meaning</th>
|
|
||||||
</tr>
|
|
||||||
<tr>
|
|
||||||
<td><a class="permalink" href="#$00"><code class="Li" id="$00">$00</code></a></td>
|
|
||||||
<td><a class="permalink" href="#+_operator"><code class="Li" id="+_operator">+
|
|
||||||
operator</code></a></td>
|
|
||||||
</tr>
|
|
||||||
<tr>
|
|
||||||
<td><a class="permalink" href="#$01"><code class="Li" id="$01">$01</code></a></td>
|
|
||||||
<td><a class="permalink" href="#-_operator"><code class="Li" id="-_operator">-
|
|
||||||
operator</code></a></td>
|
|
||||||
</tr>
|
|
||||||
<tr>
|
|
||||||
<td><a class="permalink" href="#$02"><code class="Li" id="$02">$02</code></a></td>
|
|
||||||
<td><a class="permalink" href="#*_operator"><code class="Li" id="*_operator">*
|
|
||||||
operator</code></a></td>
|
|
||||||
</tr>
|
|
||||||
<tr>
|
|
||||||
<td><a class="permalink" href="#$03"><code class="Li" id="$03">$03</code></a></td>
|
|
||||||
<td><a class="permalink" href="#/_operator"><code class="Li" id="/_operator">/
|
|
||||||
operator</code></a></td>
|
|
||||||
</tr>
|
|
||||||
<tr>
|
|
||||||
<td><a class="permalink" href="#$04"><code class="Li" id="$04">$04</code></a></td>
|
|
||||||
<td><a class="permalink" href="#__operator"><code class="Li" id="__operator">%
|
|
||||||
operator</code></a></td>
|
|
||||||
</tr>
|
|
||||||
<tr>
|
|
||||||
<td><a class="permalink" href="#$05"><code class="Li" id="$05">$05</code></a></td>
|
|
||||||
<td><a class="permalink" href="#unary_-"><code class="Li" id="unary_-">unary
|
|
||||||
-</code></a></td>
|
|
||||||
</tr>
|
|
||||||
<tr>
|
|
||||||
<td><a class="permalink" href="#$10"><code class="Li" id="$10">$10</code></a></td>
|
|
||||||
<td>|
|
|
||||||
<a class="permalink" href="#operator"><code class="Li" id="operator">operator</code></a></td>
|
|
||||||
</tr>
|
|
||||||
<tr>
|
|
||||||
<td><a class="permalink" href="#$11"><code class="Li" id="$11">$11</code></a></td>
|
|
||||||
<td><a class="permalink" href="#&_operator"><code class="Li" id="&_operator">&
|
|
||||||
operator</code></a></td>
|
|
||||||
</tr>
|
|
||||||
<tr>
|
|
||||||
<td><a class="permalink" href="#$12"><code class="Li" id="$12">$12</code></a></td>
|
|
||||||
<td><a class="permalink" href="#__operator_2"><code class="Li" id="__operator_2">^
|
|
||||||
operator</code></a></td>
|
|
||||||
</tr>
|
|
||||||
<tr>
|
|
||||||
<td><a class="permalink" href="#$13"><code class="Li" id="$13">$13</code></a></td>
|
|
||||||
<td><a class="permalink" href="#unary_~"><code class="Li" id="unary_~">unary
|
|
||||||
~</code></a></td>
|
|
||||||
</tr>
|
|
||||||
<tr>
|
|
||||||
<td><a class="permalink" href="#$21"><code class="Li" id="$21">$21</code></a></td>
|
|
||||||
<td><a class="permalink" href="#&&_comparison"><code class="Li" id="&&_comparison">&&
|
|
||||||
comparison</code></a></td>
|
|
||||||
</tr>
|
|
||||||
<tr>
|
|
||||||
<td><a class="permalink" href="#$22"><code class="Li" id="$22">$22</code></a></td>
|
|
||||||
<td><a class="permalink" href="#___comparison"><code class="Li" id="___comparison">||
|
|
||||||
comparison</code></a></td>
|
|
||||||
</tr>
|
|
||||||
<tr>
|
|
||||||
<td><a class="permalink" href="#$23"><code class="Li" id="$23">$23</code></a></td>
|
|
||||||
<td><a class="permalink" href="#unary__!"><code class="Li" id="unary__!">unary !</code></a></td>
|
|
||||||
</tr>
|
|
||||||
<tr>
|
|
||||||
<td><a class="permalink" href="#$30"><code class="Li" id="$30">$30</code></a></td>
|
|
||||||
<td><a class="permalink" href="#==_comparison"><code class="Li" id="==_comparison">==
|
|
||||||
comparison</code></a></td>
|
|
||||||
</tr>
|
|
||||||
<tr>
|
|
||||||
<td><a class="permalink" href="#$31"><code class="Li" id="$31">$31</code></a></td>
|
|
||||||
<td><a class="permalink" href="#!=_comparison"><code class="Li" id="!=_comparison">!=
|
|
||||||
comparison</code></a></td>
|
|
||||||
</tr>
|
|
||||||
<tr>
|
|
||||||
<td><a class="permalink" href="#$32"><code class="Li" id="$32">$32</code></a></td>
|
|
||||||
<td><a class="permalink" href="#__comparison"><code class="Li" id="__comparison">>
|
|
||||||
comparison</code></a></td>
|
|
||||||
</tr>
|
|
||||||
<tr>
|
|
||||||
<td><a class="permalink" href="#$33"><code class="Li" id="$33">$33</code></a></td>
|
|
||||||
<td><a class="permalink" href="#__comparison_2"><code class="Li" id="__comparison_2"><
|
|
||||||
comparison</code></a></td>
|
|
||||||
</tr>
|
|
||||||
<tr>
|
|
||||||
<td><a class="permalink" href="#$34"><code class="Li" id="$34">$34</code></a></td>
|
|
||||||
<td><a class="permalink" href="#_=_comparison"><code class="Li" id="_=_comparison">>=
|
|
||||||
comparison</code></a></td>
|
|
||||||
</tr>
|
|
||||||
<tr>
|
|
||||||
<td><a class="permalink" href="#$35"><code class="Li" id="$35">$35</code></a></td>
|
|
||||||
<td><a class="permalink" href="#_=_comparison_2"><code class="Li" id="_=_comparison_2"><=
|
|
||||||
comparison</code></a></td>
|
|
||||||
</tr>
|
|
||||||
<tr>
|
|
||||||
<td><a class="permalink" href="#$40"><code class="Li" id="$40">$40</code></a></td>
|
|
||||||
<td><a class="permalink" href="#___operator"><code class="Li" id="___operator"><<
|
|
||||||
operator</code></a></td>
|
|
||||||
</tr>
|
|
||||||
<tr>
|
|
||||||
<td><a class="permalink" href="#$41"><code class="Li" id="$41">$41</code></a></td>
|
|
||||||
<td><a class="permalink" href="#___operator_2"><code class="Li" id="___operator_2">>>
|
|
||||||
operator</code></a></td>
|
|
||||||
</tr>
|
|
||||||
<tr>
|
|
||||||
<td><a class="permalink" href="#$50"><code class="Li" id="$50">$50</code></a></td>
|
|
||||||
<td><a class="permalink" href="#BANK(symbol)"><code class="Li" id="BANK(symbol)">BANK(symbol)</code></a>,
|
|
||||||
a <var class="Ar">LONG</var> Symbol ID follows.</td>
|
|
||||||
</tr>
|
|
||||||
<tr>
|
|
||||||
<td><a class="permalink" href="#$51"><code class="Li" id="$51">$51</code></a></td>
|
|
||||||
<td><a class="permalink" href="#BANK(section_name)"><code class="Li" id="BANK(section_name)">BANK(section_name)</code></a>,
|
|
||||||
a null-terminated string follows.</td>
|
|
||||||
</tr>
|
|
||||||
<tr>
|
|
||||||
<td><a class="permalink" href="#$52"><code class="Li" id="$52">$52</code></a></td>
|
|
||||||
<td><a class="permalink" href="#Current_BANK()"><code class="Li" id="Current_BANK()">Current
|
|
||||||
BANK()</code></a></td>
|
|
||||||
</tr>
|
|
||||||
<tr>
|
|
||||||
<td><a class="permalink" href="#$60"><code class="Li" id="$60">$60</code></a></td>
|
|
||||||
<td><a class="permalink" href="#HRAMCheck"><code class="Li" id="HRAMCheck">HRAMCheck</code></a>.
|
|
||||||
Checks if the value is in HRAM, ANDs it with 0xFF.</td>
|
|
||||||
</tr>
|
|
||||||
<tr>
|
|
||||||
<td><a class="permalink" href="#$61"><code class="Li" id="$61">$61</code></a></td>
|
|
||||||
<td><a class="permalink" href="#RSTCheck"><code class="Li" id="RSTCheck">RSTCheck</code></a>.
|
|
||||||
Checks if the value is a RST vector, ORs it with 0xC7.</td>
|
|
||||||
</tr>
|
|
||||||
<tr>
|
|
||||||
<td><a class="permalink" href="#$80"><code class="Li" id="$80">$80</code></a></td>
|
|
||||||
<td><var class="Ar">LONG</var> integer follows.</td>
|
|
||||||
</tr>
|
|
||||||
<tr>
|
|
||||||
<td><a class="permalink" href="#$81"><code class="Li" id="$81">$81</code></a></td>
|
|
||||||
<td><var class="Ar">LONG</var> symbol ID follows.</td>
|
|
||||||
</tr>
|
|
||||||
</table>
|
|
||||||
</section>
|
|
||||||
</section>
|
|
||||||
<section class="Sh">
|
|
||||||
<h1 class="Sh" id="SEE_ALSO"><a class="permalink" href="#SEE_ALSO">SEE
|
|
||||||
ALSO</a></h1>
|
|
||||||
<a class="Xr" href="rgbasm.1.html">rgbasm(1)</a>, <a class="Xr" href="rgblink.1.html">rgblink(1)</a>,
|
|
||||||
<a class="Xr" href="rgbds.7.html">rgbds(7)</a>, <a class="Xr" href="gbz80.7.html">gbz80(7)</a>
|
|
||||||
</section>
|
|
||||||
<section class="Sh">
|
|
||||||
<h1 class="Sh" id="HISTORY"><a class="permalink" href="#HISTORY">HISTORY</a></h1>
|
|
||||||
<code class="Nm">rgbds</code> was originally written by Carsten Sørensen
|
|
||||||
as part of the ASMotor package, and was later packaged in RGBDS by Justin
|
|
||||||
Lloyd. It is now maintained by a number of contributors at
|
|
||||||
<a class="Lk" href="https://github.com/rednex/rgbds">https://github.com/rednex/rgbds</a>.
|
|
||||||
</section>
|
|
||||||
</div>
|
|
||||||
<table class="foot">
|
|
||||||
<tr>
|
|
||||||
<td class="foot-date">January 26, 2018</td>
|
|
||||||
<td class="foot-os">General</td>
|
|
||||||
</tr>
|
|
||||||
</table>
|
|
||||||
</body>
|
|
||||||
</html>
|
|
||||||
@@ -1,80 +0,0 @@
|
|||||||
<!DOCTYPE html>
|
|
||||||
<html>
|
|
||||||
<!-- This is an automatically generated file. Do not edit.
|
|
||||||
This file is part of RGBDS.
|
|
||||||
|
|
||||||
Copyright (c) 2010-2018, Anthony J. Bentley and RGBDS contributors.
|
|
||||||
|
|
||||||
SPDX-License-Identifier: MIT
|
|
||||||
-->
|
|
||||||
<head>
|
|
||||||
<meta name="viewport" content="width=device-width, initial-scale=1">
|
|
||||||
<meta charset="utf-8"/>
|
|
||||||
<link rel="stylesheet" href="mandoc.css" type="text/css" media="all"/>
|
|
||||||
<link rel="stylesheet" href="rgbds.css" type="text/css" media="all"/>
|
|
||||||
<title>RGBDS(7)</title>
|
|
||||||
</head>
|
|
||||||
<body>
|
|
||||||
<table class="head">
|
|
||||||
<tr>
|
|
||||||
<td class="head-ltitle">RGBDS(7)</td>
|
|
||||||
<td class="head-vol">Miscellaneous Information Manual</td>
|
|
||||||
<td class="head-rtitle">RGBDS(7)</td>
|
|
||||||
</tr>
|
|
||||||
</table>
|
|
||||||
<div class="manual-text">
|
|
||||||
<section class="Sh">
|
|
||||||
<h1 class="Sh" id="NAME"><a class="permalink" href="#NAME">NAME</a></h1>
|
|
||||||
<code class="Nm">rgbds</code> —
|
|
||||||
<span class="Nd">Rednex Game Boy Development System</span>
|
|
||||||
</section>
|
|
||||||
<section class="Sh">
|
|
||||||
<h1 class="Sh" id="EXAMPLES"><a class="permalink" href="#EXAMPLES">EXAMPLES</a></h1>
|
|
||||||
To get a working ROM image from a single assembly source file:
|
|
||||||
<div class="Bd Pp Bd-indent">
|
|
||||||
<pre>
|
|
||||||
$ rgbasm -o bar.o foo.asm
|
|
||||||
$ rgblink -o baz.gb bar.o
|
|
||||||
$ rgbfix -v -p 0 baz.gb
|
|
||||||
</pre>
|
|
||||||
</div>
|
|
||||||
</section>
|
|
||||||
<section class="Sh">
|
|
||||||
<h1 class="Sh" id="SEE_ALSO"><a class="permalink" href="#SEE_ALSO">SEE
|
|
||||||
ALSO</a></h1>
|
|
||||||
<a class="Xr" href="rgbasm.1.html">rgbasm(1)</a>, <a class="Xr" href="rgbfix.1.html">rgbfix(1)</a>,
|
|
||||||
<a class="Xr" href="rgblink.1.html">rgblink(1)</a>, <a class="Xr" href="rgbds.5.html">rgbds(5)</a>,
|
|
||||||
<a class="Xr" href="gbz80.7.html">gbz80(7)</a>
|
|
||||||
</section>
|
|
||||||
<section class="Sh">
|
|
||||||
<h1 class="Sh" id="HISTORY"><a class="permalink" href="#HISTORY">HISTORY</a></h1>
|
|
||||||
<dl class="Bl-ohang">
|
|
||||||
<dt></dt>
|
|
||||||
<dd>1997, Carsten Sørensen (AKA SurfSmurf) writes ASMotor as a
|
|
||||||
general-purpose assembler/linker system for DOS/Win32.</dd>
|
|
||||||
<dt></dt>
|
|
||||||
<dd>1999, Justin Lloyd (AKA Otaku no Zoku) adapts ASMotor to read and produce
|
|
||||||
GBZ80 assembly/machine code, and releases this version as RGBDS.</dd>
|
|
||||||
<dt></dt>
|
|
||||||
<dd>2009, Vegard Nossum adapts the code to be more UNIX-like and releases this
|
|
||||||
version as rgbds-linux on GitHub.</dd>
|
|
||||||
<dt></dt>
|
|
||||||
<dd>2010, Anthony J. Bentley forks that repository. The fork becomes the
|
|
||||||
reference implementation of rgbds.</dd>
|
|
||||||
<dt></dt>
|
|
||||||
<dd>2017, Bentley's repository is moved to a neutral name. It is now
|
|
||||||
maintained by a number of contributors at
|
|
||||||
<a class="Lk" href="https://github.com/rednex/rgbds">https://github.com/rednex/rgbds</a>.</dd>
|
|
||||||
<dt></dt>
|
|
||||||
<dd>2018, codebase relicensed under the MIT license.</dd>
|
|
||||||
</dl>
|
|
||||||
</section>
|
|
||||||
</div>
|
|
||||||
<table class="foot">
|
|
||||||
<tr>
|
|
||||||
<td class="foot-date">March 7, 2018</td>
|
|
||||||
<td class="foot-os">General</td>
|
|
||||||
</tr>
|
|
||||||
</table>
|
|
||||||
</body>
|
|
||||||
</html>
|
|
||||||
@@ -1,63 +0,0 @@
|
|||||||
/* Overrides to default mandoc styling for HTML renders of RGBDS man pages */
|
|
||||||
|
|
||||||
html {
|
|
||||||
/* Reduce contrast */
|
|
||||||
background-color: #f8f8f8;
|
|
||||||
color: #222;
|
|
||||||
|
|
||||||
/* Override `mandoc.css`'s sowe can put it on <body> instead */
|
|
||||||
max-width: none;
|
|
||||||
}
|
|
||||||
|
|
||||||
body {
|
|
||||||
/* Center body horizontally (requires <html> to span full width) */
|
|
||||||
margin: 0 auto;
|
|
||||||
/* `mandoc.css`'s default, but it's applied to <html> there */
|
|
||||||
max-width: 65em;
|
|
||||||
|
|
||||||
/* Improve readability */
|
|
||||||
font-size: 16px;
|
|
||||||
line-height: 1.4;
|
|
||||||
text-align: justify;
|
|
||||||
|
|
||||||
/* Prevent text from bumping sides on mobile devices */
|
|
||||||
padding: 10px 20px 10px 10px;
|
|
||||||
}
|
|
||||||
@media print {
|
|
||||||
body {
|
|
||||||
/* Max width doesn't make sense for print */
|
|
||||||
max-width: none;
|
|
||||||
/* Make font slightly smaller for printing */
|
|
||||||
font-size: 14px;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
code, pre {
|
|
||||||
font-size: smaller;
|
|
||||||
}
|
|
||||||
|
|
||||||
pre {
|
|
||||||
/* Avoid horizontal page scrolling on mobile */
|
|
||||||
overflow: auto;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Separate lines in tables */
|
|
||||||
table.Bl-column {
|
|
||||||
border-collapse: collapse;
|
|
||||||
}
|
|
||||||
table.Bl-column tr:not(:first-child) > td,
|
|
||||||
table.Bl-column tr:not(:first-child) > th {
|
|
||||||
border-top: 1px solid #aaa;
|
|
||||||
}
|
|
||||||
|
|
||||||
table.Bl-column th {
|
|
||||||
/* Apply `.Sy` style to table headers */
|
|
||||||
font-style: normal;
|
|
||||||
font-weight: bold;
|
|
||||||
}
|
|
||||||
|
|
||||||
table.Bl-column td,
|
|
||||||
table.Bl-column th {
|
|
||||||
/* Add horizontal spacing between columns */
|
|
||||||
padding: 2px 7px 0;
|
|
||||||
}
|
|
||||||
@@ -1,220 +0,0 @@
|
|||||||
<!DOCTYPE html>
|
|
||||||
<html>
|
|
||||||
<!-- This is an automatically generated file. Do not edit.
|
|
||||||
This file is part of RGBDS.
|
|
||||||
|
|
||||||
Copyright (c) 2010-2017, Anthony J. Bentley and RGBDS contributors.
|
|
||||||
|
|
||||||
SPDX-License-Identifier: MIT
|
|
||||||
-->
|
|
||||||
<head>
|
|
||||||
<meta name="viewport" content="width=device-width, initial-scale=1">
|
|
||||||
<meta charset="utf-8"/>
|
|
||||||
<link rel="stylesheet" href="mandoc.css" type="text/css" media="all"/>
|
|
||||||
<link rel="stylesheet" href="rgbds.css" type="text/css" media="all"/>
|
|
||||||
<title>RGBFIX(1)</title>
|
|
||||||
</head>
|
|
||||||
<body>
|
|
||||||
<table class="head">
|
|
||||||
<tr>
|
|
||||||
<td class="head-ltitle">RGBFIX(1)</td>
|
|
||||||
<td class="head-vol">General Commands Manual</td>
|
|
||||||
<td class="head-rtitle">RGBFIX(1)</td>
|
|
||||||
</tr>
|
|
||||||
</table>
|
|
||||||
<div class="manual-text">
|
|
||||||
<section class="Sh">
|
|
||||||
<h1 class="Sh" id="NAME"><a class="permalink" href="#NAME">NAME</a></h1>
|
|
||||||
<code class="Nm">rgbfix</code> —
|
|
||||||
<span class="Nd">Game Boy header utility and checksum fixer</span>
|
|
||||||
</section>
|
|
||||||
<section class="Sh">
|
|
||||||
<h1 class="Sh" id="SYNOPSIS"><a class="permalink" href="#SYNOPSIS">SYNOPSIS</a></h1>
|
|
||||||
<table class="Nm">
|
|
||||||
<tr>
|
|
||||||
<td><code class="Nm">rgbfix</code></td>
|
|
||||||
<td>[<code class="Fl"><a href="#j">-j</a><a href="#s">s</a><a href="#V">V</a><a href="#v">v</a></code>] [<code class="Fl"><a href="#C">-C</a></code> |
|
|
||||||
<code class="Fl"><a href="#c">-c</a></code>] [<code class="Fl"><a href="#f">-f</a></code>
|
|
||||||
<var class="Ar">fix_spec</var>] [<code class="Fl"><a href="#i">-i</a></code>
|
|
||||||
<var class="Ar">game_id</var>] [<code class="Fl"><a href="#k">-k</a></code>
|
|
||||||
<var class="Ar">licensee_str</var>] [<code class="Fl"><a href="#l">-l</a></code>
|
|
||||||
<var class="Ar">licensee_id</var>] [<code class="Fl"><a href="#m">-m</a></code>
|
|
||||||
<var class="Ar">mbc_type</var>] [<code class="Fl"><a href="#n">-n</a></code>
|
|
||||||
<var class="Ar">rom_version</var>] [<code class="Fl"><a href="#p">-p</a></code>
|
|
||||||
<var class="Ar">pad_value</var>] [<code class="Fl"><a href="#r">-r</a></code>
|
|
||||||
<var class="Ar">ram_size</var>] [<code class="Fl"><a href="#t">-t</a></code>
|
|
||||||
<var class="Ar">title_str</var>] <var class="Ar">file</var></td>
|
|
||||||
</tr>
|
|
||||||
</table>
|
|
||||||
</section>
|
|
||||||
<section class="Sh">
|
|
||||||
<h1 class="Sh" id="DESCRIPTION"><a class="permalink" href="#DESCRIPTION">DESCRIPTION</a></h1>
|
|
||||||
The <code class="Nm">rgbfix</code> program changes headers of Game Boy ROM
|
|
||||||
images. It also performs other correctness operations, such as padding.
|
|
||||||
<p class="Pp">Note that options can be abbreviated as long as the abbreviation
|
|
||||||
is unambiguous: <code class="Fl">--verb</code> is
|
|
||||||
<code class="Fl">--verbose</code>, but
|
|
||||||
<code class="Fl">--ver</code> is invalid because it
|
|
||||||
could also be <code class="Fl">--version</code>. The
|
|
||||||
arguments are as follows:</p>
|
|
||||||
<dl class="Bl-tag">
|
|
||||||
<dt><a class="permalink" href="#C"><code class="Fl" id="C">-C</code></a>,
|
|
||||||
<code class="Fl">--color-only</code></dt>
|
|
||||||
<dd>Set the Game Boy Color–only flag: <span class="Ad">0x143</span> =
|
|
||||||
0xC0. If both this and the <code class="Fl">-c</code> flag are set, this
|
|
||||||
takes precedence.</dd>
|
|
||||||
<dt><a class="permalink" href="#c"><code class="Fl" id="c">-c</code></a>,
|
|
||||||
<code class="Fl">--color-compatible</code></dt>
|
|
||||||
<dd>Set the Game Boy Color–compatible flag:
|
|
||||||
<span class="Ad">0x143</span> = 0x80. If both this and the
|
|
||||||
<code class="Fl">-C</code> flag are set, <code class="Fl">-C</code> takes
|
|
||||||
precedence.</dd>
|
|
||||||
<dt><a class="permalink" href="#f"><code class="Fl" id="f">-f</code></a>
|
|
||||||
<var class="Ar">fix_spec</var>,
|
|
||||||
<code class="Fl">--fix-spec</code>
|
|
||||||
<var class="Ar">fix_spec</var></dt>
|
|
||||||
<dd>Fix certain header values that the Game Boy checks for correctness.
|
|
||||||
Alternatively, intentionally trash these values by writing their binary
|
|
||||||
inverse instead. <var class="Ar">fix_spec</var> is a string containing any
|
|
||||||
combination of the following characters:
|
|
||||||
<p class="Pp"></p>
|
|
||||||
<dl class="Bl-tag Bl-compact">
|
|
||||||
<dt><a class="permalink" href="#l"><code class="Cm" id="l">l</code></a></dt>
|
|
||||||
<dd>Fix the Nintendo logo
|
|
||||||
(<span class="Ad">0x104</span>–<span class="Ad">0x133</span>).</dd>
|
|
||||||
<dt><a class="permalink" href="#L"><code class="Cm" id="L">L</code></a></dt>
|
|
||||||
<dd>Trash the Nintendo logo.</dd>
|
|
||||||
<dt><a class="permalink" href="#h"><code class="Cm" id="h">h</code></a></dt>
|
|
||||||
<dd>Fix the header checksum (<span class="Ad">0x14D</span>).</dd>
|
|
||||||
<dt><a class="permalink" href="#H"><code class="Cm" id="H">H</code></a></dt>
|
|
||||||
<dd>Trash the header checksum.</dd>
|
|
||||||
<dt><a class="permalink" href="#g"><code class="Cm" id="g">g</code></a></dt>
|
|
||||||
<dd>Fix the global checksum
|
|
||||||
(<span class="Ad">0x14E</span>–<span class="Ad">0x14F</span>).</dd>
|
|
||||||
<dt><a class="permalink" href="#G"><code class="Cm" id="G">G</code></a></dt>
|
|
||||||
<dd>Trash the global checksum.</dd>
|
|
||||||
</dl>
|
|
||||||
</dd>
|
|
||||||
<dt><a class="permalink" href="#i"><code class="Fl" id="i">-i</code></a>
|
|
||||||
<var class="Ar">game_id</var>,
|
|
||||||
<code class="Fl">--game-id</code>
|
|
||||||
<var class="Ar">game_id</var></dt>
|
|
||||||
<dd>Set the game ID string
|
|
||||||
(<span class="Ad">0x13F</span>–<span class="Ad">0x142</span>) to a
|
|
||||||
given string of exactly 4 characters. If both this and the title are set,
|
|
||||||
the game ID will overwrite the overlapping portion of the title.</dd>
|
|
||||||
<dt><a class="permalink" href="#j"><code class="Fl" id="j">-j</code></a>,
|
|
||||||
<code class="Fl">--non-japanese</code></dt>
|
|
||||||
<dd>Set the non-Japanese region flag: <span class="Ad">0x14A</span> = 1.</dd>
|
|
||||||
<dt><a class="permalink" href="#k"><code class="Fl" id="k">-k</code></a>
|
|
||||||
<var class="Ar">licensee_str</var>,
|
|
||||||
<code class="Fl">--new-licensee</code>
|
|
||||||
<var class="Ar">licensee_str</var></dt>
|
|
||||||
<dd>Set the new licensee string
|
|
||||||
(<span class="Ad">0x144</span>–<span class="Ad">0x145</span>) to a
|
|
||||||
given string, truncated to at most two characters.</dd>
|
|
||||||
<dt><a class="permalink" href="#l_2"><code class="Fl" id="l_2">-l</code></a>
|
|
||||||
<var class="Ar">licensee_id</var>,
|
|
||||||
<code class="Fl">--old-licensee</code>
|
|
||||||
<var class="Ar">licensee_id</var></dt>
|
|
||||||
<dd>Set the old licensee code, <span class="Ad">0x14B</span>, to a given value
|
|
||||||
from 0 to 0xFF. This value is deprecated and should be set to 0x33 in all
|
|
||||||
new software.</dd>
|
|
||||||
<dt><a class="permalink" href="#m"><code class="Fl" id="m">-m</code></a>
|
|
||||||
<var class="Ar">mbc_type</var>,
|
|
||||||
<code class="Fl">--mbc-type</code>
|
|
||||||
<var class="Ar">mbc_type</var></dt>
|
|
||||||
<dd>Set the MBC type, <span class="Ad">0x147</span>, to a given value from 0
|
|
||||||
to 0xFF.</dd>
|
|
||||||
<dt><a class="permalink" href="#n"><code class="Fl" id="n">-n</code></a>
|
|
||||||
<var class="Ar">rom_version</var>,
|
|
||||||
<code class="Fl">--rom-version</code>
|
|
||||||
<var class="Ar">rom_version</var></dt>
|
|
||||||
<dd>Set the ROM version, <span class="Ad">0x14C</span>, to a given value from
|
|
||||||
0 to 0xFF.</dd>
|
|
||||||
<dt><a class="permalink" href="#p"><code class="Fl" id="p">-p</code></a>
|
|
||||||
<var class="Ar">pad_value</var>,
|
|
||||||
<code class="Fl">--pad-value</code>
|
|
||||||
<var class="Ar">pad_value</var></dt>
|
|
||||||
<dd>Pad the image to a valid size with a given pad value from 0 to 0xFF.
|
|
||||||
<code class="Nm">rgbfix</code> will automatically pick a size from 32 KiB,
|
|
||||||
64 KiB, 128 KiB, ..., 8192 KiB. The cartridge size byte
|
|
||||||
(<span class="Ad">0x148</span>) will be changed to reflect this new
|
|
||||||
size.</dd>
|
|
||||||
<dt><a class="permalink" href="#r"><code class="Fl" id="r">-r</code></a>
|
|
||||||
<var class="Ar">ram_size</var>,
|
|
||||||
<code class="Fl">--ram-size</code>
|
|
||||||
<var class="Ar">ram_size</var></dt>
|
|
||||||
<dd>Set the RAM size, <span class="Ad">0x149</span>, to a given value from 0
|
|
||||||
to 0xFF.</dd>
|
|
||||||
<dt><a class="permalink" href="#s"><code class="Fl" id="s">-s</code></a>,
|
|
||||||
<code class="Fl">--sgb-compatible</code></dt>
|
|
||||||
<dd>Set the SGB flag: <span class="Ad">0x146</span> = 3. This flag will be
|
|
||||||
ignored by the SGB unless the old licensee code is 0x33!</dd>
|
|
||||||
<dt><a class="permalink" href="#t"><code class="Fl" id="t">-t</code></a>
|
|
||||||
<var class="Ar">title</var>,
|
|
||||||
<code class="Fl">--title</code>
|
|
||||||
<var class="Ar">title</var></dt>
|
|
||||||
<dd>Set the title string
|
|
||||||
(<span class="Ad">0x134</span>–<span class="Ad">0x143</span>) to a
|
|
||||||
given string, truncated to at most 16 characters. It is recommended to use
|
|
||||||
15 characters instead, to avoid clashing with the CGB flag
|
|
||||||
(<code class="Fl">-c</code> or <code class="Fl">-C</code>). If both this
|
|
||||||
and the game ID are set, the game ID will overwrite the overlapping
|
|
||||||
portion of the title.</dd>
|
|
||||||
<dt><a class="permalink" href="#V"><code class="Fl" id="V">-V</code></a>,
|
|
||||||
<code class="Fl">--version</code></dt>
|
|
||||||
<dd>Print the version of the program and exit.</dd>
|
|
||||||
<dt><a class="permalink" href="#v"><code class="Fl" id="v">-v</code></a>,
|
|
||||||
<code class="Fl">--validate</code></dt>
|
|
||||||
<dd>Equivalent to <code class="Fl">-f</code> <code class="Cm">lhg</code>.</dd>
|
|
||||||
</dl>
|
|
||||||
</section>
|
|
||||||
<section class="Sh">
|
|
||||||
<h1 class="Sh" id="EXAMPLES"><a class="permalink" href="#EXAMPLES">EXAMPLES</a></h1>
|
|
||||||
Most values in the ROM header are only cosmetic. The bare minimum requirements
|
|
||||||
for a workable program are the header checksum, the Nintendo logo, and (if
|
|
||||||
needed) the CGB/SGB flags. It is a good idea to pad the image to a valid size
|
|
||||||
as well (“valid” meaning a power of 2, times 32 KiB).
|
|
||||||
<p class="Pp">The following will make a plain, non-color Game Boy game without
|
|
||||||
checking for a valid size:</p>
|
|
||||||
<p class="Pp"></p>
|
|
||||||
<div class="Bd Bd-indent">$ rgbfix -v foo.gb</div>
|
|
||||||
<p class="Pp">The following will make a SGB-enabled, color-enabled game with a
|
|
||||||
title of “foobar”, and pad it to a valid size. (The Game Boy
|
|
||||||
itself does not use the title, but some emulators or ROM managers do.)</p>
|
|
||||||
<p class="Pp"></p>
|
|
||||||
<div class="Bd Bd-indent">$ rgbfix -vcs -l 0x33 -p 255 -t foobar baz.gb</div>
|
|
||||||
<p class="Pp">The following will duplicate the header (sans global checksum) of
|
|
||||||
the game “Survival Kids”:</p>
|
|
||||||
<p class="Pp"></p>
|
|
||||||
<div class="Bd Bd-indent">$ rgbfix -cjsv -k A4 -l 0x33 -m 0x1B -p 0xFF -r 3 -t
|
|
||||||
SURVIVALKIDAVKE SurvivalKids.gbc</div>
|
|
||||||
</section>
|
|
||||||
<section class="Sh">
|
|
||||||
<h1 class="Sh" id="BUGS"><a class="permalink" href="#BUGS">BUGS</a></h1>
|
|
||||||
Please report bugs on
|
|
||||||
<a class="Lk" href="https://github.com/rednex/rgbds/issues">GitHub</a>.
|
|
||||||
</section>
|
|
||||||
<section class="Sh">
|
|
||||||
<h1 class="Sh" id="SEE_ALSO"><a class="permalink" href="#SEE_ALSO">SEE
|
|
||||||
ALSO</a></h1>
|
|
||||||
<a class="Xr" href="rgbasm.1.html">rgbasm(1)</a>, <a class="Xr" href="rgblink.1.html">rgblink(1)</a>,
|
|
||||||
<a class="Xr" href="rgbds.7.html">rgbds(7)</a>
|
|
||||||
</section>
|
|
||||||
<section class="Sh">
|
|
||||||
<h1 class="Sh" id="HISTORY"><a class="permalink" href="#HISTORY">HISTORY</a></h1>
|
|
||||||
<code class="Nm">rgbfix</code> was originally released by Carsten
|
|
||||||
Sørensen as a standalone program called gbfix, and was later packaged
|
|
||||||
in RGBDS by Justin Lloyd. It is now maintained by a number of contributors at
|
|
||||||
<a class="Lk" href="https://github.com/rednex/rgbds">https://github.com/rednex/rgbds</a>.
|
|
||||||
</section>
|
|
||||||
</div>
|
|
||||||
<table class="foot">
|
|
||||||
<tr>
|
|
||||||
<td class="foot-date">December 5, 2019</td>
|
|
||||||
<td class="foot-os">General</td>
|
|
||||||
</tr>
|
|
||||||
</table>
|
|
||||||
</body>
|
|
||||||
</html>
|
|
||||||
@@ -1,220 +0,0 @@
|
|||||||
<!DOCTYPE html>
|
|
||||||
<html>
|
|
||||||
<!-- This is an automatically generated file. Do not edit.
|
|
||||||
This file is part of RGBDS.
|
|
||||||
|
|
||||||
Copyright (c) 2013-2018, stag019 and RGBDS contributors.
|
|
||||||
|
|
||||||
SPDX-License-Identifier: MIT
|
|
||||||
-->
|
|
||||||
<head>
|
|
||||||
<meta name="viewport" content="width=device-width, initial-scale=1">
|
|
||||||
<meta charset="utf-8"/>
|
|
||||||
<link rel="stylesheet" href="mandoc.css" type="text/css" media="all"/>
|
|
||||||
<link rel="stylesheet" href="rgbds.css" type="text/css" media="all"/>
|
|
||||||
<title>RGBGFX(1)</title>
|
|
||||||
</head>
|
|
||||||
<body>
|
|
||||||
<table class="head">
|
|
||||||
<tr>
|
|
||||||
<td class="head-ltitle">RGBGFX(1)</td>
|
|
||||||
<td class="head-vol">General Commands Manual</td>
|
|
||||||
<td class="head-rtitle">RGBGFX(1)</td>
|
|
||||||
</tr>
|
|
||||||
</table>
|
|
||||||
<div class="manual-text">
|
|
||||||
<section class="Sh">
|
|
||||||
<h1 class="Sh" id="NAME"><a class="permalink" href="#NAME">NAME</a></h1>
|
|
||||||
<code class="Nm">rgbgfx</code> —
|
|
||||||
<span class="Nd">Game Boy graphics converter</span>
|
|
||||||
</section>
|
|
||||||
<section class="Sh">
|
|
||||||
<h1 class="Sh" id="SYNOPSIS"><a class="permalink" href="#SYNOPSIS">SYNOPSIS</a></h1>
|
|
||||||
<table class="Nm">
|
|
||||||
<tr>
|
|
||||||
<td><code class="Nm">rgbgfx</code></td>
|
|
||||||
<td>[<code class="Fl"><a href="#C">-C</a><a href="#D">D</a><a href="#h">h</a><a href="#m">m</a><a href="#u">u</a><a href="#V">V</a><a href="#v">v</a></code>] [<code class="Fl"><a href="#f">-f</a></code> |
|
|
||||||
<code class="Fl"><a href="#F">-F</a></code>] [<code class="Fl"><a href="#a">-a</a></code>
|
|
||||||
<var class="Ar">attrmap</var> | <code class="Fl"><a href="#A">-A</a></code>]
|
|
||||||
[<code class="Fl"><a href="#d">-d</a></code> <var class="Ar">depth</var>]
|
|
||||||
[<code class="Fl"><a href="#o">-o</a></code> <var class="Ar">out_file</var>]
|
|
||||||
[<code class="Fl"><a href="#p">-p</a></code> <var class="Ar">pal_file</var> |
|
|
||||||
<code class="Fl"><a href="#P">-P</a></code>] [<code class="Fl"><a href="#t">-t</a></code>
|
|
||||||
<var class="Ar">tilemap</var> | <code class="Fl"><a href="#T">-T</a></code>]
|
|
||||||
[<code class="Fl"><a href="#x">-x</a></code> <var class="Ar">tiles</var>]
|
|
||||||
<var class="Ar">file</var></td>
|
|
||||||
</tr>
|
|
||||||
</table>
|
|
||||||
</section>
|
|
||||||
<section class="Sh">
|
|
||||||
<h1 class="Sh" id="DESCRIPTION"><a class="permalink" href="#DESCRIPTION">DESCRIPTION</a></h1>
|
|
||||||
The <code class="Nm">rgbgfx</code> program converts PNG images into the Nintendo
|
|
||||||
Game Boy's planar tile format.
|
|
||||||
<p class="Pp">The resulting colors and their palette indices are determined
|
|
||||||
differently depending on the input PNG file:</p>
|
|
||||||
<ul class="Bl-dash">
|
|
||||||
<li>If the file has an embedded palette, that palette's color and order are
|
|
||||||
used.</li>
|
|
||||||
<li>If not, and the image only contains shades of gray, rgbgfx maps them to
|
|
||||||
the indices appropriate for each shade. Any undetermined indices are set
|
|
||||||
to respective default shades of gray. For example: if the bit depth is 2
|
|
||||||
and the image contains light gray and black, they become the second and
|
|
||||||
fourth colors, and the first and third colors get set to default white and
|
|
||||||
dark gray. If the image has multiple shades that map to the same index,
|
|
||||||
the palette is instead determined as if the image had color.</li>
|
|
||||||
<li>If the image has color (or the grayscale method failed), the colors are
|
|
||||||
sorted from lightest to darkest.</li>
|
|
||||||
</ul>
|
|
||||||
<p class="Pp">The input image may not contain more colors than the selected bit
|
|
||||||
depth allows. Transparent pixels are set to palette index 0.</p>
|
|
||||||
</section>
|
|
||||||
<section class="Sh">
|
|
||||||
<h1 class="Sh" id="ARGUMENTS"><a class="permalink" href="#ARGUMENTS">ARGUMENTS</a></h1>
|
|
||||||
Note that options can be abbreviated as long as the abbreviation is unambiguous:
|
|
||||||
<code class="Fl">--verb</code> is
|
|
||||||
<code class="Fl">-</code> <code class="Fl">-verbose</code>, but
|
|
||||||
<code class="Fl">--ver</code> is invalid because it
|
|
||||||
could also be <code class="Fl">--version</code>. The
|
|
||||||
arguments are as follows:
|
|
||||||
<dl class="Bl-tag">
|
|
||||||
<dt><a class="permalink" href="#a"><code class="Fl" id="a">-a</code></a>
|
|
||||||
<var class="Ar">attrmap,</var>
|
|
||||||
<code class="Fl">--attr-map</code>
|
|
||||||
<var class="Ar">attrmap</var></dt>
|
|
||||||
<dd>Generate a file of tile mirroring attributes for OAM or (CGB-only)
|
|
||||||
background tiles. For each tile in the input file, a byte is written
|
|
||||||
representing the dimensions that the associated tile in the output file
|
|
||||||
should be mirrored. Useful in combination with <code class="Fl">-m</code>
|
|
||||||
to keep track the mirror direction of mirrored duplicate tiles.</dd>
|
|
||||||
<dt><a class="permalink" href="#A"><code class="Fl" id="A">-A</code></a>,
|
|
||||||
<code class="Fl">--output-attr-map</code></dt>
|
|
||||||
<dd>Same as <code class="Fl">-a</code>, but the attrmap file output name is
|
|
||||||
made by taking the input filename, removing the file extension, and
|
|
||||||
appending <span class="Pa">.attrmap</span>.</dd>
|
|
||||||
<dt><a class="permalink" href="#C"><code class="Fl" id="C">-C</code></a>,
|
|
||||||
<code class="Fl">--color-curve</code></dt>
|
|
||||||
<dd>Use the color curve of the Game Boy Color when generating palettes.</dd>
|
|
||||||
<dt><a class="permalink" href="#D"><code class="Fl" id="D">-D</code></a>,
|
|
||||||
<code class="Fl">--debug</code></dt>
|
|
||||||
<dd>Debug features are enabled.</dd>
|
|
||||||
<dt><a class="permalink" href="#d"><code class="Fl" id="d">-d</code></a>
|
|
||||||
<var class="Ar">depth</var>,
|
|
||||||
<code class="Fl">--depth</code>
|
|
||||||
<var class="Ar">depth</var></dt>
|
|
||||||
<dd>The bit depth of the output image (either 1 or 2). By default, the bit
|
|
||||||
depth is 2 (two bits per pixel).</dd>
|
|
||||||
<dt><a class="permalink" href="#f"><code class="Fl" id="f">-f</code></a>,
|
|
||||||
<code class="Fl">--fix</code></dt>
|
|
||||||
<dd>Fix the input PNG file to be a correctly indexed image.</dd>
|
|
||||||
<dt><a class="permalink" href="#F"><code class="Fl" id="F">-F</code></a>,
|
|
||||||
<code class="Fl">--fix-and-save</code></dt>
|
|
||||||
<dd>Same as <code class="Fl">-f</code>, but additionally, the supplied command
|
|
||||||
line parameters are saved within the PNG and will be loaded and
|
|
||||||
automatically used next time.</dd>
|
|
||||||
<dt><a class="permalink" href="#h"><code class="Fl" id="h">-h</code></a>,
|
|
||||||
<code class="Fl">--horizontal</code></dt>
|
|
||||||
<dd>Lay out tiles horizontally rather than vertically.</dd>
|
|
||||||
<dt><a class="permalink" href="#m"><code class="Fl" id="m">-m</code></a>,
|
|
||||||
<code class="Fl">--mirror-tiles</code></dt>
|
|
||||||
<dd>Truncate tiles by checking for tiles that are mirrored versions of others
|
|
||||||
and omitting these from the output file. Useful with tilemaps and attrmaps
|
|
||||||
together to keep track of the duplicated tiles and the dimension mirrored.
|
|
||||||
Tiles are checked for horizontal, vertical, and horizontal-vertical
|
|
||||||
mirroring. Implies <code class="Fl">-u</code>.</dd>
|
|
||||||
<dt><a class="permalink" href="#o"><code class="Fl" id="o">-o</code></a>
|
|
||||||
<var class="Ar">out_file</var>,
|
|
||||||
<code class="Fl">--output</code>
|
|
||||||
<var class="Ar">out_file</var></dt>
|
|
||||||
<dd>The name of the output file.</dd>
|
|
||||||
<dt><a class="permalink" href="#p"><code class="Fl" id="p">-p</code></a>
|
|
||||||
<var class="Ar">pal_file</var>,
|
|
||||||
<code class="Fl">--palette</code>
|
|
||||||
<var class="Ar">pal_file</var></dt>
|
|
||||||
<dd>Output the image's palette in standard GBC palette format: bytes (8 bytes
|
|
||||||
for two bits per pixel, 4 bytes for one bit per pixel) containing the
|
|
||||||
RGB15 values in little-endian byte order. If the palette contains too few
|
|
||||||
colors, the remaining entries are set to black.</dd>
|
|
||||||
<dt><a class="permalink" href="#P"><code class="Fl" id="P">-P</code></a>,
|
|
||||||
<code class="Fl">--output-palette</code></dt>
|
|
||||||
<dd>Same as <code class="Fl">-p</code>, but the palette file output name is
|
|
||||||
made by taking the input PNG file's filename, removing the file extension,
|
|
||||||
and appending <span class="Pa">.pal</span>.</dd>
|
|
||||||
<dt><a class="permalink" href="#t"><code class="Fl" id="t">-t</code></a>
|
|
||||||
<var class="Ar">tilemap</var>,
|
|
||||||
<code class="Fl">--tilemap</code>
|
|
||||||
<var class="Ar">tilemap</var></dt>
|
|
||||||
<dd>Generate a file of tile indices. For each tile in the input file, a byte
|
|
||||||
is written representing the index of the associated tile in the output
|
|
||||||
file. Useful in combination with <code class="Fl">-u</code> or
|
|
||||||
<code class="Fl">-m</code> to keep track of duplicate tiles.</dd>
|
|
||||||
<dt><a class="permalink" href="#T"><code class="Fl" id="T">-T</code></a>,
|
|
||||||
<code class="Fl">--output-tilemap</code></dt>
|
|
||||||
<dd>Same as <code class="Fl">-t</code>, but the tilemap file output name is
|
|
||||||
made by taking the input filename, removing the file extension, and
|
|
||||||
appending <span class="Pa">.tilemap</span>.</dd>
|
|
||||||
<dt><a class="permalink" href="#u"><code class="Fl" id="u">-u</code></a>,
|
|
||||||
<code class="Fl">--unique-tiles</code></dt>
|
|
||||||
<dd>Truncate tiles by checking for tiles that are exact duplicates of others
|
|
||||||
and omitting these from the output file. Useful with tilemaps to keep
|
|
||||||
track of the duplicated tiles.</dd>
|
|
||||||
<dt><a class="permalink" href="#V"><code class="Fl" id="V">-V</code></a>,
|
|
||||||
<code class="Fl">--version</code></dt>
|
|
||||||
<dd>Print the version of the program and exit.</dd>
|
|
||||||
<dt><a class="permalink" href="#v"><code class="Fl" id="v">-v</code></a>,
|
|
||||||
<code class="Fl">--verbose</code></dt>
|
|
||||||
<dd>Verbose. Print errors when the command line parameters and the parameters
|
|
||||||
in the PNG file don't match.</dd>
|
|
||||||
<dt><a class="permalink" href="#x"><code class="Fl" id="x">-x</code></a>
|
|
||||||
<var class="Ar">tiles</var>,
|
|
||||||
<code class="Fl">--trim-end</code>
|
|
||||||
<var class="Ar">tiles</var></dt>
|
|
||||||
<dd>Trim the end of the output file by this many tiles.</dd>
|
|
||||||
</dl>
|
|
||||||
</section>
|
|
||||||
<section class="Sh">
|
|
||||||
<h1 class="Sh" id="EXAMPLES"><a class="permalink" href="#EXAMPLES">EXAMPLES</a></h1>
|
|
||||||
The following will take a PNG file with a bit depth of 1, 2, or 8, and output
|
|
||||||
planar 2bpp data:
|
|
||||||
<p class="Pp"></p>
|
|
||||||
<div class="Bd Bd-indent">$ rgbgfx -o out.2bpp in.png</div>
|
|
||||||
<p class="Pp">The following creates a planar 2bpp file with only unique tiles,
|
|
||||||
and its tilemap <span class="Pa">out.tilemap</span>:</p>
|
|
||||||
<p class="Pp"></p>
|
|
||||||
<div class="Bd Bd-indent">$ rgbgfx -T -u -o out.2bpp in.png</div>
|
|
||||||
<p class="Pp">The following creates a planar 2bpp file with only unique tiles
|
|
||||||
<span class="Pa">accounting for tile mirroring</span> and its associated
|
|
||||||
tilemap <span class="Pa">out.tilemap</span> and attrmap
|
|
||||||
<span class="Pa">out.attrmap</span>:</p>
|
|
||||||
<p class="Pp"></p>
|
|
||||||
<div class="Bd Bd-indent">$ rgbgfx -A -T -m -o out.2bpp in.png</div>
|
|
||||||
<p class="Pp">The following will do nothing:</p>
|
|
||||||
<p class="Pp"></p>
|
|
||||||
<div class="Bd Bd-indent">$ rgbgfx in.png</div>
|
|
||||||
</section>
|
|
||||||
<section class="Sh">
|
|
||||||
<h1 class="Sh" id="BUGS"><a class="permalink" href="#BUGS">BUGS</a></h1>
|
|
||||||
Please report bugs on
|
|
||||||
<a class="Lk" href="https://github.com/rednex/rgbds/issues">GitHub</a>.
|
|
||||||
</section>
|
|
||||||
<section class="Sh">
|
|
||||||
<h1 class="Sh" id="SEE_ALSO"><a class="permalink" href="#SEE_ALSO">SEE
|
|
||||||
ALSO</a></h1>
|
|
||||||
<a class="Xr" href="rgbds.7.html">rgbds(7)</a>, <a class="Xr" href="rgbasm.1.html">rgbasm(1)</a>,
|
|
||||||
<a class="Xr" href="rgblink.1.html">rgblink(1)</a>, <a class="Xr" href="rgbfix.1.html">rgbfix(1)</a>,
|
|
||||||
<a class="Xr" href="gbz80.7.html">gbz80(7)</a>
|
|
||||||
</section>
|
|
||||||
<section class="Sh">
|
|
||||||
<h1 class="Sh" id="HISTORY"><a class="permalink" href="#HISTORY">HISTORY</a></h1>
|
|
||||||
<code class="Nm">rgbgfx</code> was created by <span class="An">stag019</span> to
|
|
||||||
be included in RGBDS. It is now maintained by a number of contributors at
|
|
||||||
<a class="Lk" href="https://github.com/rednex/rgbds">https://github.com/rednex/rgbds</a>.
|
|
||||||
</section>
|
|
||||||
</div>
|
|
||||||
<table class="foot">
|
|
||||||
<tr>
|
|
||||||
<td class="foot-date">December 5, 2019</td>
|
|
||||||
<td class="foot-os">General</td>
|
|
||||||
</tr>
|
|
||||||
</table>
|
|
||||||
</body>
|
|
||||||
</html>
|
|
||||||
@@ -1,192 +0,0 @@
|
|||||||
<!DOCTYPE html>
|
|
||||||
<html>
|
|
||||||
<!-- This is an automatically generated file. Do not edit.
|
|
||||||
This file is part of RGBDS.
|
|
||||||
|
|
||||||
Copyright (c) 2010-2019, Anthony J. Bentley and RGBDS contributors.
|
|
||||||
|
|
||||||
SPDX-License-Identifier: MIT
|
|
||||||
-->
|
|
||||||
<head>
|
|
||||||
<meta name="viewport" content="width=device-width, initial-scale=1">
|
|
||||||
<meta charset="utf-8"/>
|
|
||||||
<link rel="stylesheet" href="mandoc.css" type="text/css" media="all"/>
|
|
||||||
<link rel="stylesheet" href="rgbds.css" type="text/css" media="all"/>
|
|
||||||
<title>RGBLINK(1)</title>
|
|
||||||
</head>
|
|
||||||
<body>
|
|
||||||
<table class="head">
|
|
||||||
<tr>
|
|
||||||
<td class="head-ltitle">RGBLINK(1)</td>
|
|
||||||
<td class="head-vol">General Commands Manual</td>
|
|
||||||
<td class="head-rtitle">RGBLINK(1)</td>
|
|
||||||
</tr>
|
|
||||||
</table>
|
|
||||||
<div class="manual-text">
|
|
||||||
<section class="Sh">
|
|
||||||
<h1 class="Sh" id="NAME"><a class="permalink" href="#NAME">NAME</a></h1>
|
|
||||||
<code class="Nm">rgblink</code> —
|
|
||||||
<span class="Nd">Game Boy linker</span>
|
|
||||||
</section>
|
|
||||||
<section class="Sh">
|
|
||||||
<h1 class="Sh" id="SYNOPSIS"><a class="permalink" href="#SYNOPSIS">SYNOPSIS</a></h1>
|
|
||||||
<table class="Nm">
|
|
||||||
<tr>
|
|
||||||
<td><code class="Nm">rgblink</code></td>
|
|
||||||
<td>[<code class="Fl"><a href="#d">-d</a><a href="#t">t</a><a href="#V">V</a><a href="#v">v</a><a href="#w">w</a><a href="#x">x</a></code>] [<code class="Fl"><a href="#l">-l</a></code>
|
|
||||||
<var class="Ar">linker_script</var>] [<code class="Fl"><a href="#m">-m</a></code>
|
|
||||||
<var class="Ar">map_file</var>] [<code class="Fl"><a href="#n">-n</a></code>
|
|
||||||
<var class="Ar">sym_file</var>] [<code class="Fl"><a href="#O">-O</a></code>
|
|
||||||
<var class="Ar">overlay_file</var>] [<code class="Fl"><a href="#o">-o</a></code>
|
|
||||||
<var class="Ar">out_file</var>] [<code class="Fl"><a href="#p">-p</a></code>
|
|
||||||
<var class="Ar">pad_value</var>] [<code class="Fl"><a href="#s">-s</a></code>
|
|
||||||
<var class="Ar">symbol</var>] <var class="Ar">file ...</var></td>
|
|
||||||
</tr>
|
|
||||||
</table>
|
|
||||||
</section>
|
|
||||||
<section class="Sh">
|
|
||||||
<h1 class="Sh" id="DESCRIPTION"><a class="permalink" href="#DESCRIPTION">DESCRIPTION</a></h1>
|
|
||||||
The <code class="Nm">rgblink</code> program links RGB object files, typically
|
|
||||||
created by <a class="Xr" href="rgbasm.1.html">rgbasm(1)</a>, into a single Game Boy ROM file. The
|
|
||||||
format is documented in <a class="Xr" href="rgbds.5.html">rgbds(5)</a>.
|
|
||||||
<p class="Pp">ROM0 sections are placed in the first 16 KiB of the output ROM,
|
|
||||||
and ROMX sections are placed in any 16 KiB “bank” except the
|
|
||||||
first. If your ROM will only be 32 KiB, you can use the
|
|
||||||
<code class="Fl">-t</code> option to change this.</p>
|
|
||||||
<p class="Pp">Similarly, WRAM0 sections are placed in the first 4 KiB of WRAM
|
|
||||||
(“bank 0”), and WRAMX sections are placed in any bank of the
|
|
||||||
last 4 KiB. If your ROM doesn't use banked WRAM, you can use the
|
|
||||||
<code class="Fl">-w</code> option to change this.</p>
|
|
||||||
<p class="Pp">Also, if your ROM is designed for a monochrome Game Boy, you can
|
|
||||||
make sure that you don't use any incompatible section by using the
|
|
||||||
<code class="Fl">-d</code> option, which implies <code class="Fl">-w</code>
|
|
||||||
but also prohibits the use of banked VRAM.</p>
|
|
||||||
<p class="Pp">Note that options can be abbreviated as long as the abbreviation
|
|
||||||
is unambiguous: <code class="Fl">--verb</code> is
|
|
||||||
<code class="Fl">--verbose</code>, but
|
|
||||||
<code class="Fl">--ver</code> is invalid because it
|
|
||||||
could also be <code class="Fl">--version</code>. The
|
|
||||||
arguments are as follows:</p>
|
|
||||||
<dl class="Bl-tag">
|
|
||||||
<dt><a class="permalink" href="#d"><code class="Fl" id="d">-d</code></a>,
|
|
||||||
<code class="Fl">--dmg</code></dt>
|
|
||||||
<dd>Enable DMG mode. Prohibit the use of sections that doesn't exist on a DMG,
|
|
||||||
such as VRAM bank 1. This option automatically enables
|
|
||||||
<code class="Fl">-w</code>.</dd>
|
|
||||||
<dt><a class="permalink" href="#l"><code class="Fl" id="l">-l</code></a>
|
|
||||||
<var class="Ar">linker_script,</var>
|
|
||||||
<code class="Fl">--linkerscript</code>
|
|
||||||
<var class="Ar">linker_script</var></dt>
|
|
||||||
<dd>Specify a linker script file that tells the linker how sections must be
|
|
||||||
placed in the ROM. The attributes assigned in the linker script must be
|
|
||||||
consistent with any assigned in the code. See <a class="Xr" href="rgblink.5.html">rgblink(5)</a>
|
|
||||||
for more information about the linker script format.</dd>
|
|
||||||
<dt><a class="permalink" href="#m"><code class="Fl" id="m">-m</code></a>
|
|
||||||
<var class="Ar">map_file</var>,
|
|
||||||
<code class="Fl">--map</code>
|
|
||||||
<var class="Ar">map_file</var></dt>
|
|
||||||
<dd>Write a map file to the given filename, listing how sections and symbols
|
|
||||||
were assigned.</dd>
|
|
||||||
<dt><a class="permalink" href="#n"><code class="Fl" id="n">-n</code></a>
|
|
||||||
<var class="Ar">sym_file</var>,
|
|
||||||
<code class="Fl">--sym</code>
|
|
||||||
<var class="Ar">sym_file</var></dt>
|
|
||||||
<dd>Write a symbol file to the given filename, listing the address of all
|
|
||||||
exported symbols. Several external programs can use this information, for
|
|
||||||
example to help debugging ROMs.</dd>
|
|
||||||
<dt><a class="permalink" href="#O"><code class="Fl" id="O">-O</code></a>
|
|
||||||
<var class="Ar">overlay_file</var>,
|
|
||||||
<code class="Fl">--overlay</code>
|
|
||||||
<var class="Ar">overlay_file</var></dt>
|
|
||||||
<dd>If specified, sections will be overlaid "on top" of the provided
|
|
||||||
ROM image. In that case, all sections must be fixed. This may be used to
|
|
||||||
patch an existing binary.</dd>
|
|
||||||
<dt><a class="permalink" href="#o"><code class="Fl" id="o">-o</code></a>
|
|
||||||
<var class="Ar">out_file</var>,
|
|
||||||
<code class="Fl">--output</code>
|
|
||||||
<var class="Ar">out_file</var></dt>
|
|
||||||
<dd>Write the ROM image to the given file.</dd>
|
|
||||||
<dt><a class="permalink" href="#p"><code class="Fl" id="p">-p</code></a>
|
|
||||||
<var class="Ar">pad_value</var>,
|
|
||||||
<code class="Fl">--pad</code>
|
|
||||||
<var class="Ar">pad_value</var></dt>
|
|
||||||
<dd>When inserting padding between sections, pad with this value. Has no
|
|
||||||
effect if <code class="Fl">-O</code> is specified. The default is 0.</dd>
|
|
||||||
<dt><a class="permalink" href="#s"><code class="Fl" id="s">-s</code></a>
|
|
||||||
<var class="Ar">symbol</var>,
|
|
||||||
<code class="Fl">--smart</code>
|
|
||||||
<var class="Ar">symbol</var></dt>
|
|
||||||
<dd>This option is ignored. It was supposed to perform smart linking but fell
|
|
||||||
into disrepair, and so has been removed. It will be reimplemented at some
|
|
||||||
point.</dd>
|
|
||||||
<dt><a class="permalink" href="#t"><code class="Fl" id="t">-t</code></a>,
|
|
||||||
<code class="Fl">--tiny</code></dt>
|
|
||||||
<dd>Expand the ROM0 section size from 16 KiB to the full 32 KiB assigned to
|
|
||||||
ROM. ROMX sections that are fixed to a bank other than 1 become errors,
|
|
||||||
other ROMX sections are treated as ROM0. Useful for ROMs that fit in 32
|
|
||||||
KiB.</dd>
|
|
||||||
<dt><a class="permalink" href="#V"><code class="Fl" id="V">-V</code></a>,
|
|
||||||
<code class="Fl">--version</code></dt>
|
|
||||||
<dd>Print the version of the program and exit.</dd>
|
|
||||||
<dt><a class="permalink" href="#v"><code class="Fl" id="v">-v</code></a>,
|
|
||||||
<code class="Fl">--verbose</code></dt>
|
|
||||||
<dd>Verbose: enable printing more information to standard error.</dd>
|
|
||||||
<dt><a class="permalink" href="#w"><code class="Fl" id="w">-w</code></a>,
|
|
||||||
<code class="Fl">--wramx</code></dt>
|
|
||||||
<dd>Expand the WRAM0 section size from 4 KiB to the full 8 KiB assigned to
|
|
||||||
WRAM. WRAMX sections that are fixed to a bank other than 1 become errors,
|
|
||||||
other WRAMX sections are treated as WRAM0.</dd>
|
|
||||||
<dt><a class="permalink" href="#x"><code class="Fl" id="x">-x</code></a>,
|
|
||||||
<code class="Fl">--nopad</code></dt>
|
|
||||||
<dd>Disables padding the end of the final file. This option automatically
|
|
||||||
enables <code class="Fl">-t</code>. You can use this when not not making a
|
|
||||||
ROM. When making a ROM, be careful that not using this is not a
|
|
||||||
replacement for <a class="Xr" href="rgbfix.1.html">rgbfix(1)</a>'s <code class="Fl">-p</code>
|
|
||||||
option!</dd>
|
|
||||||
</dl>
|
|
||||||
</section>
|
|
||||||
<section class="Sh">
|
|
||||||
<h1 class="Sh" id="EXAMPLES"><a class="permalink" href="#EXAMPLES">EXAMPLES</a></h1>
|
|
||||||
All you need for a basic ROM is an object file, which can be made into a ROM
|
|
||||||
image like so:
|
|
||||||
<p class="Pp"></p>
|
|
||||||
<div class="Bd Bd-indent">$ rgblink -o bar.gb foo.o</div>
|
|
||||||
<p class="Pp">The resulting <var class="Ar">bar.gb</var> will not have correct
|
|
||||||
checksums (unless you put them in the assembly source). You should use
|
|
||||||
<a class="Xr" href="rgbfix.1.html">rgbfix(1)</a> to fix these so that the program will actually
|
|
||||||
run in a Game Boy:</p>
|
|
||||||
<p class="Pp"></p>
|
|
||||||
<div class="Bd Bd-indent"><code class="Li">$ rgbfix -v bar.gb</code></div>
|
|
||||||
<p class="Pp">Here is a more complete example:</p>
|
|
||||||
<p class="Pp"></p>
|
|
||||||
<div class="Bd Bd-indent"><code class="Li">$ rgblink -o bin/game.gb -n
|
|
||||||
bin/game.sym -p 0xFF obj/title.o obj/engine.o</code></div>
|
|
||||||
</section>
|
|
||||||
<section class="Sh">
|
|
||||||
<h1 class="Sh" id="BUGS"><a class="permalink" href="#BUGS">BUGS</a></h1>
|
|
||||||
Please report bugs on
|
|
||||||
<a class="Lk" href="https://github.com/rednex/rgbds/issues">GitHub</a>.
|
|
||||||
</section>
|
|
||||||
<section class="Sh">
|
|
||||||
<h1 class="Sh" id="SEE_ALSO"><a class="permalink" href="#SEE_ALSO">SEE
|
|
||||||
ALSO</a></h1>
|
|
||||||
<a class="Xr" href="rgbasm.1.html">rgbasm(1)</a>, <a class="Xr" href="rgblink.5.html">rgblink(5)</a>,
|
|
||||||
<a class="Xr" href="rgbfix.1.html">rgbfix(1)</a>, <a class="Xr" href="rgbds.5.html">rgbds(5)</a>,
|
|
||||||
<a class="Xr" href="rgbds.7.html">rgbds(7)</a>
|
|
||||||
</section>
|
|
||||||
<section class="Sh">
|
|
||||||
<h1 class="Sh" id="HISTORY"><a class="permalink" href="#HISTORY">HISTORY</a></h1>
|
|
||||||
<code class="Nm">rgblink</code> was originally written by Carsten
|
|
||||||
Sørensen as part of the ASMotor package, and was later packaged in
|
|
||||||
RGBDS by Justin Lloyd. It is now maintained by a number of contributors at
|
|
||||||
<a class="Lk" href="https://github.com/rednex/rgbds">https://github.com/rednex/rgbds</a>.
|
|
||||||
</section>
|
|
||||||
</div>
|
|
||||||
<table class="foot">
|
|
||||||
<tr>
|
|
||||||
<td class="foot-date">November 26, 2019</td>
|
|
||||||
<td class="foot-os">General</td>
|
|
||||||
</tr>
|
|
||||||
</table>
|
|
||||||
</body>
|
|
||||||
</html>
|
|
||||||
@@ -1,111 +0,0 @@
|
|||||||
<!DOCTYPE html>
|
|
||||||
<html>
|
|
||||||
<!-- This is an automatically generated file. Do not edit.
|
|
||||||
This file is part of RGBDS.
|
|
||||||
|
|
||||||
Copyright (c) 2017-2018, Antonio Nino Diaz and RGBDS contributors.
|
|
||||||
|
|
||||||
SPDX-License-Identifier: MIT
|
|
||||||
-->
|
|
||||||
<head>
|
|
||||||
<meta name="viewport" content="width=device-width, initial-scale=1">
|
|
||||||
<meta charset="utf-8"/>
|
|
||||||
<link rel="stylesheet" href="mandoc.css" type="text/css" media="all"/>
|
|
||||||
<link rel="stylesheet" href="rgbds.css" type="text/css" media="all"/>
|
|
||||||
<title>RGBLINK(5)</title>
|
|
||||||
</head>
|
|
||||||
<body>
|
|
||||||
<table class="head">
|
|
||||||
<tr>
|
|
||||||
<td class="head-ltitle">RGBLINK(5)</td>
|
|
||||||
<td class="head-vol">File Formats Manual</td>
|
|
||||||
<td class="head-rtitle">RGBLINK(5)</td>
|
|
||||||
</tr>
|
|
||||||
</table>
|
|
||||||
<div class="manual-text">
|
|
||||||
<section class="Sh">
|
|
||||||
<h1 class="Sh" id="NAME"><a class="permalink" href="#NAME">NAME</a></h1>
|
|
||||||
<code class="Nm">rgblink</code> —
|
|
||||||
<span class="Nd">linker script file format</span>
|
|
||||||
</section>
|
|
||||||
<section class="Sh">
|
|
||||||
<h1 class="Sh" id="DESCRIPTION"><a class="permalink" href="#DESCRIPTION">DESCRIPTION</a></h1>
|
|
||||||
The linker script is an external file that allows the user to specify the order
|
|
||||||
of sections at link time and in a centralized manner.
|
|
||||||
<p class="Pp">A linker script consists on a series of banks followed by a list
|
|
||||||
of sections and, optionally, commands. They can be lowercase or uppercase,
|
|
||||||
it is ignored. Any line can contain a comment starting with
|
|
||||||
‘<code class="Li">;</code>’ that ends at the end of the
|
|
||||||
line:</p>
|
|
||||||
<div class="Bd Pp Bd-indent">
|
|
||||||
<pre>
|
|
||||||
ROMX $F ; This is a comment
|
|
||||||
"Functions to read array"
|
|
||||||
ALIGN 8
|
|
||||||
"Array aligned to 256 bytes"
|
|
||||||
|
|
||||||
WRAMX 2
|
|
||||||
"Some variables"
|
|
||||||
</pre>
|
|
||||||
</div>
|
|
||||||
<p class="Pp">Numbers can be in decimal or hexadecimal format (the prefix is
|
|
||||||
‘<code class="Li">$</code>’). It is an error if any section
|
|
||||||
name or command is found before setting a bank.</p>
|
|
||||||
<p class="Pp">Files can be included by using the <code class="Ic">INCLUDE</code>
|
|
||||||
keyword, followed by a string with the path of the file that has to be
|
|
||||||
included.</p>
|
|
||||||
<p class="Pp">The possible bank types are: <code class="Cm">ROM0</code>,
|
|
||||||
<code class="Cm">ROMX</code>, <code class="Cm">VRAM</code>,
|
|
||||||
<code class="Cm">SRAM</code>, <code class="Cm">WRAM0</code>,
|
|
||||||
<code class="Cm">WRAMX</code>, <code class="Cm">OAM</code> and
|
|
||||||
<code class="Cm">HRAM</code>. Unless there is a single bank, which can occur
|
|
||||||
with types <code class="Cm">ROMX</code>, <code class="Cm">VRAM</code>,
|
|
||||||
<code class="Cm">SRAM</code> and <code class="Cm">WRAMX</code>, it is needed
|
|
||||||
to specify a bank number after the type.</p>
|
|
||||||
<p class="Pp">When a new bank statement is found, sections found after it will
|
|
||||||
be placed right from the beginning of that bank. If the linker script
|
|
||||||
switches to a different bank and then comes back to a previous one, it will
|
|
||||||
continue from the last address that was used.</p>
|
|
||||||
<p class="Pp">The only two commands are <code class="Ic">ORG</code> and
|
|
||||||
<code class="Ic">ALIGN</code>:</p>
|
|
||||||
<ul class="Bl-bullet">
|
|
||||||
<li><a class="permalink" href="#ORG"><code class="Ic" id="ORG">ORG</code></a>
|
|
||||||
sets the address in which new sections will be placed. It can not be lower
|
|
||||||
than the current address.</li>
|
|
||||||
<li><a class="permalink" href="#ALIGN"><code class="Ic" id="ALIGN">ALIGN</code></a>
|
|
||||||
will increase the address until it is aligned to the specified boundary
|
|
||||||
(it tries to set to 0 the number of bits specified after the command:
|
|
||||||
‘<code class="Li">ALIGN 8</code>’ will align to $100).</li>
|
|
||||||
</ul>
|
|
||||||
<p class="Pp"><b class="Sy">Note:</b> The bank, alignment, address and type of
|
|
||||||
sections can be specified both in the source code and in the linker script.
|
|
||||||
For a section to be able to be placed with the linker script, the bank,
|
|
||||||
address and alignment must be left unassigned in the source code or be
|
|
||||||
compatible with what is specified in the linker script. For example,
|
|
||||||
‘<code class="Li">ALIGN[8]</code>’ in the source code is
|
|
||||||
compatible with ‘<code class="Li">ORG $F00</code>’ in the
|
|
||||||
linker script.</p>
|
|
||||||
</section>
|
|
||||||
<section class="Sh">
|
|
||||||
<h1 class="Sh" id="SEE_ALSO"><a class="permalink" href="#SEE_ALSO">SEE
|
|
||||||
ALSO</a></h1>
|
|
||||||
<a class="Xr" href="rgbasm.1.html">rgbasm(1)</a>, <a class="Xr" href="rgblink.1.html">rgblink(1)</a>,
|
|
||||||
<a class="Xr" href="rgbfix.1.html">rgbfix(1)</a>, <a class="Xr" href="rgbds.5.html">rgbds(5)</a>,
|
|
||||||
<a class="Xr" href="rgbds.7.html">rgbds(7)</a>
|
|
||||||
</section>
|
|
||||||
<section class="Sh">
|
|
||||||
<h1 class="Sh" id="HISTORY"><a class="permalink" href="#HISTORY">HISTORY</a></h1>
|
|
||||||
<code class="Nm">rgblink</code> was originally written by Carsten
|
|
||||||
Sørensen as part of the ASMotor package, and was later packaged in
|
|
||||||
RGBDS by Justin Lloyd. It is now maintained by a number of contributors at
|
|
||||||
<a class="Lk" href="https://github.com/rednex/rgbds">https://github.com/rednex/rgbds</a>.
|
|
||||||
</section>
|
|
||||||
</div>
|
|
||||||
<table class="foot">
|
|
||||||
<tr>
|
|
||||||
<td class="foot-date">November 26, 2019</td>
|
|
||||||
<td class="foot-os">General</td>
|
|
||||||
</tr>
|
|
||||||
</table>
|
|
||||||
</body>
|
|
||||||
</html>
|
|
||||||
@@ -1,42 +0,0 @@
|
|||||||
/*
|
|
||||||
* This file is part of RGBDS.
|
|
||||||
*
|
|
||||||
* Copyright (c) 1997-2018, Carsten Sorensen and RGBDS contributors.
|
|
||||||
*
|
|
||||||
* SPDX-License-Identifier: MIT
|
|
||||||
*/
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Contains some assembler-wide defines and externs
|
|
||||||
*/
|
|
||||||
|
|
||||||
#ifndef RGBDS_ASM_ASM_H
|
|
||||||
#define RGBDS_ASM_ASM_H
|
|
||||||
|
|
||||||
#include <stdbool.h>
|
|
||||||
#include <stdint.h>
|
|
||||||
#include <stdio.h>
|
|
||||||
#include <stdlib.h>
|
|
||||||
|
|
||||||
#include "asm/localasm.h"
|
|
||||||
#include "asm/symbol.h"
|
|
||||||
|
|
||||||
#define MAXUNIONS 128
|
|
||||||
#define MAXMACROARGS 99999
|
|
||||||
#define MAXINCPATHS 128
|
|
||||||
|
|
||||||
extern int32_t nLineNo;
|
|
||||||
extern uint32_t nTotalLines;
|
|
||||||
extern uint32_t nIFDepth;
|
|
||||||
extern bool skipElif;
|
|
||||||
extern uint32_t nUnionDepth;
|
|
||||||
extern uint32_t unionStart[MAXUNIONS];
|
|
||||||
extern uint32_t unionSize[MAXUNIONS];
|
|
||||||
extern char tzCurrentFileName[_MAX_PATH + 1];
|
|
||||||
extern struct Section *pCurrentSection;
|
|
||||||
extern bool oDontExpandStrings;
|
|
||||||
|
|
||||||
size_t symvaluetostring(char *dest, size_t maxLength, char *sym,
|
|
||||||
const char *mode);
|
|
||||||
|
|
||||||
#endif /* RGBDS_ASM_ASM_H */
|
|
||||||
+6
-29
@@ -11,36 +11,13 @@
|
|||||||
|
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
|
|
||||||
#define MAXCHARMAPS 512
|
struct Charmap *charmap_New(char const *name, char const *baseName);
|
||||||
#define CHARMAPLENGTH 16
|
void charmap_Delete(struct Charmap *charmap);
|
||||||
#define MAXCHARNODES (MAXCHARMAPS * CHARMAPLENGTH + 1)
|
void charmap_Set(char const *name);
|
||||||
|
|
||||||
/*
|
|
||||||
* A node for trie structure.
|
|
||||||
*/
|
|
||||||
struct Charnode {
|
|
||||||
uint8_t code; /* the value in a key-value pair. */
|
|
||||||
uint8_t isCode; /* has 1 if it's a code node, not just a bridge node. */
|
|
||||||
struct Charnode *next[256]; /* each index representing the next possible
|
|
||||||
* character from its current state.
|
|
||||||
*/
|
|
||||||
};
|
|
||||||
|
|
||||||
struct Charmap {
|
|
||||||
char name[MAXSYMLEN + 1];
|
|
||||||
int32_t charCount; /* user-side count. */
|
|
||||||
int32_t nodeCount; /* node-side count. */
|
|
||||||
struct Charnode nodes[MAXCHARNODES]; /* first node is reserved for the
|
|
||||||
* root node in charmap.
|
|
||||||
*/
|
|
||||||
};
|
|
||||||
|
|
||||||
void charmap_InitMain(void);
|
|
||||||
struct Charmap *charmap_New(const char *name, const char *baseName);
|
|
||||||
void charmap_Set(const char *name);
|
|
||||||
void charmap_Push(void);
|
void charmap_Push(void);
|
||||||
void charmap_Pop(void);
|
void charmap_Pop(void);
|
||||||
int32_t charmap_Add(char *input, uint8_t output);
|
void charmap_Add(char *mapping, uint8_t value);
|
||||||
int32_t charmap_Convert(char **input);
|
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 */
|
||||||
|
|||||||
@@ -0,0 +1,31 @@
|
|||||||
|
/*
|
||||||
|
* This file is part of RGBDS.
|
||||||
|
*
|
||||||
|
* Copyright (c) 1997-2021, Carsten Sorensen and RGBDS contributors.
|
||||||
|
*
|
||||||
|
* SPDX-License-Identifier: MIT
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef RGBDS_ASM_FIXPOINT_H
|
||||||
|
#define RGBDS_ASM_FIXPOINT_H
|
||||||
|
|
||||||
|
#include <stdint.h>
|
||||||
|
|
||||||
|
int32_t fix_Callback_PI(void);
|
||||||
|
void fix_Print(int32_t i);
|
||||||
|
int32_t fix_Sin(int32_t i);
|
||||||
|
int32_t fix_Cos(int32_t i);
|
||||||
|
int32_t fix_Tan(int32_t i);
|
||||||
|
int32_t fix_ASin(int32_t i);
|
||||||
|
int32_t fix_ACos(int32_t i);
|
||||||
|
int32_t fix_ATan(int32_t i);
|
||||||
|
int32_t fix_ATan2(int32_t i, int32_t j);
|
||||||
|
int32_t fix_Mul(int32_t i, int32_t j);
|
||||||
|
int32_t fix_Div(int32_t i, int32_t j);
|
||||||
|
int32_t fix_Pow(int32_t i, int32_t j);
|
||||||
|
int32_t fix_Log(int32_t i, int32_t j);
|
||||||
|
int32_t fix_Round(int32_t i);
|
||||||
|
int32_t fix_Ceil(int32_t i);
|
||||||
|
int32_t fix_Floor(int32_t i);
|
||||||
|
|
||||||
|
#endif /* RGBDS_ASM_FIXPOINT_H */
|
||||||
@@ -0,0 +1,63 @@
|
|||||||
|
/*
|
||||||
|
* This file is part of RGBDS.
|
||||||
|
*
|
||||||
|
* Copyright (c) 2020, RGBDS contributors.
|
||||||
|
*
|
||||||
|
* SPDX-License-Identifier: MIT
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef RGBDS_FORMAT_SPEC_H
|
||||||
|
#define RGBDS_FORMAT_SPEC_H
|
||||||
|
|
||||||
|
#include <stdbool.h>
|
||||||
|
#include <stdint.h>
|
||||||
|
|
||||||
|
enum FormatState {
|
||||||
|
FORMAT_SIGN, // expects '+' or ' ' (optional)
|
||||||
|
FORMAT_PREFIX, // expects '#' (optional)
|
||||||
|
FORMAT_ALIGN, // expects '-' (optional)
|
||||||
|
FORMAT_WIDTH, // expects '0'-'9', max 255 (optional) (leading '0' indicates pad)
|
||||||
|
FORMAT_FRAC, // got '.', expects '0'-'9', max 255 (optional)
|
||||||
|
FORMAT_DONE, // got [duXxbofs] (required)
|
||||||
|
FORMAT_INVALID, // got unexpected character
|
||||||
|
};
|
||||||
|
|
||||||
|
struct FormatSpec {
|
||||||
|
enum FormatState state;
|
||||||
|
int sign;
|
||||||
|
bool prefix;
|
||||||
|
bool alignLeft;
|
||||||
|
bool padZero;
|
||||||
|
size_t width;
|
||||||
|
bool hasFrac;
|
||||||
|
size_t fracWidth;
|
||||||
|
int type;
|
||||||
|
bool valid;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct StrFmtArg {
|
||||||
|
union {
|
||||||
|
uint32_t number;
|
||||||
|
char *string;
|
||||||
|
};
|
||||||
|
bool isNumeric;
|
||||||
|
};
|
||||||
|
|
||||||
|
#define INITIAL_STRFMT_ARG_SIZE 4
|
||||||
|
struct StrFmtArgList {
|
||||||
|
char *format;
|
||||||
|
size_t nbArgs;
|
||||||
|
size_t capacity;
|
||||||
|
struct StrFmtArg *args;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct FormatSpec fmt_NewSpec(void);
|
||||||
|
bool fmt_IsEmpty(struct FormatSpec const *fmt);
|
||||||
|
bool fmt_IsValid(struct FormatSpec const *fmt);
|
||||||
|
bool fmt_IsFinished(struct FormatSpec const *fmt);
|
||||||
|
void fmt_UseCharacter(struct FormatSpec *fmt, int c);
|
||||||
|
void fmt_FinishCharacters(struct FormatSpec *fmt);
|
||||||
|
void fmt_PrintString(char *buf, size_t bufLen, struct FormatSpec const *fmt, char const *value);
|
||||||
|
void fmt_PrintNumber(char *buf, size_t bufLen, struct FormatSpec const *fmt, uint32_t value);
|
||||||
|
|
||||||
|
#endif /* RGBDS_FORMAT_SPEC_H */
|
||||||
+56
-29
@@ -13,44 +13,71 @@
|
|||||||
#ifndef RGBDS_ASM_FSTACK_H
|
#ifndef RGBDS_ASM_FSTACK_H
|
||||||
#define RGBDS_ASM_FSTACK_H
|
#define RGBDS_ASM_FSTACK_H
|
||||||
|
|
||||||
|
#include <stdbool.h>
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
|
||||||
#include "asm/asm.h"
|
|
||||||
#include "asm/lexer.h"
|
#include "asm/lexer.h"
|
||||||
|
|
||||||
#include "types.h"
|
|
||||||
|
struct FileStackNode {
|
||||||
|
struct FileStackNode *parent; /* Pointer to parent node, for error reporting */
|
||||||
|
/* Line at which the parent context was exited; meaningless for the root level */
|
||||||
|
uint32_t lineNo;
|
||||||
|
|
||||||
|
struct FileStackNode *next; /* Next node in the output linked list */
|
||||||
|
bool referenced; /* If referenced, don't free! */
|
||||||
|
uint32_t ID; /* Set only if referenced: ID within the object file, -1 if not output yet */
|
||||||
|
|
||||||
|
enum {
|
||||||
|
NODE_REPT,
|
||||||
|
NODE_FILE,
|
||||||
|
NODE_MACRO,
|
||||||
|
} type;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct FileStackReptNode { /* NODE_REPT */
|
||||||
|
struct FileStackNode node;
|
||||||
|
uint32_t reptDepth;
|
||||||
|
/* WARNING: if changing this type, change overflow check in `fstk_Init` */
|
||||||
|
uint32_t iters[]; /* REPT iteration counts since last named node, in reverse depth order */
|
||||||
|
};
|
||||||
|
|
||||||
|
struct FileStackNamedNode { /* NODE_FILE, NODE_MACRO */
|
||||||
|
struct FileStackNode node;
|
||||||
|
char name[]; /* File name for files, file::macro name for macros */
|
||||||
|
};
|
||||||
|
|
||||||
|
extern size_t maxRecursionDepth;
|
||||||
|
|
||||||
struct MacroArgs;
|
struct MacroArgs;
|
||||||
|
|
||||||
struct sContext {
|
void fstk_Dump(struct FileStackNode const *node, uint32_t lineNo);
|
||||||
YY_BUFFER_STATE FlexHandle;
|
void fstk_DumpCurrent(void);
|
||||||
struct Symbol const *pMacro;
|
struct FileStackNode *fstk_GetFileStack(void);
|
||||||
struct sContext *pNext;
|
/* The lifetime of the returned chars is until reaching the end of that file */
|
||||||
char tzFileName[_MAX_PATH + 1];
|
char const *fstk_GetFileName(void);
|
||||||
struct MacroArgs *macroArgs;
|
|
||||||
uint32_t uniqueID;
|
|
||||||
int32_t nLine;
|
|
||||||
uint32_t nStatus;
|
|
||||||
FILE *pFile;
|
|
||||||
char *pREPTBlock;
|
|
||||||
uint32_t nREPTBlockCount;
|
|
||||||
uint32_t nREPTBlockSize;
|
|
||||||
int32_t nREPTBodyFirstLine;
|
|
||||||
int32_t nREPTBodyLastLine;
|
|
||||||
};
|
|
||||||
|
|
||||||
extern unsigned int nMaxRecursionDepth;
|
void fstk_AddIncludePath(char const *s);
|
||||||
|
/**
|
||||||
|
* @param path The user-provided file name
|
||||||
|
* @param fullPath The address of a pointer, which will be made to point at the full path
|
||||||
|
* The pointer's value must be a valid argument to `realloc`, including NULL
|
||||||
|
* @param size Current size of the buffer, or 0 if the pointer is NULL
|
||||||
|
* @return True if the file was found, false if no path worked
|
||||||
|
*/
|
||||||
|
bool fstk_FindFile(char const *path, char **fullPath, size_t *size);
|
||||||
|
|
||||||
void fstk_RunInclude(char *tzFileName);
|
bool yywrap(void);
|
||||||
void fstk_Init(char *s);
|
void fstk_RunInclude(char const *path);
|
||||||
void fstk_Dump(void);
|
void fstk_RunMacro(char const *macroName, struct MacroArgs *args);
|
||||||
void fstk_DumpToStr(char *buf, size_t len);
|
void fstk_RunRept(uint32_t count, int32_t reptLineNo, char *body, size_t size);
|
||||||
void fstk_DumpStringExpansions(void);
|
void fstk_RunFor(char const *symName, int32_t start, int32_t stop, int32_t step,
|
||||||
void fstk_AddIncludePath(char *s);
|
int32_t reptLineNo, char *body, size_t size);
|
||||||
void fstk_RunMacro(char *s, struct MacroArgs *args);
|
void fstk_StopRept(void);
|
||||||
void fstk_RunRept(uint32_t count, int32_t nReptLineNo);
|
bool fstk_Break(void);
|
||||||
FILE *fstk_FindFile(char const *fname, char **incPathUsed);
|
|
||||||
int32_t fstk_GetLine(void);
|
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 */
|
||||||
|
|||||||
+80
-64
@@ -9,78 +9,94 @@
|
|||||||
#ifndef RGBDS_ASM_LEXER_H
|
#ifndef RGBDS_ASM_LEXER_H
|
||||||
#define RGBDS_ASM_LEXER_H
|
#define RGBDS_ASM_LEXER_H
|
||||||
|
|
||||||
#include <stdint.h>
|
#include <stdbool.h>
|
||||||
#include <stdio.h>
|
|
||||||
|
|
||||||
#define LEXHASHSIZE (1 << 11)
|
|
||||||
#define MAXSTRLEN 255
|
#define MAXSTRLEN 255
|
||||||
|
|
||||||
struct sLexInitString {
|
struct LexerState;
|
||||||
char *tzName;
|
extern struct LexerState *lexerState;
|
||||||
uint32_t nToken;
|
extern struct LexerState *lexerStateEOL;
|
||||||
|
|
||||||
|
static inline struct LexerState *lexer_GetState(void)
|
||||||
|
{
|
||||||
|
return lexerState;
|
||||||
|
}
|
||||||
|
|
||||||
|
static inline void lexer_SetState(struct LexerState *state)
|
||||||
|
{
|
||||||
|
lexerState = state;
|
||||||
|
}
|
||||||
|
|
||||||
|
static inline void lexer_SetStateAtEOL(struct LexerState *state)
|
||||||
|
{
|
||||||
|
lexerStateEOL = state;
|
||||||
|
}
|
||||||
|
|
||||||
|
extern char binDigits[2];
|
||||||
|
extern char gfxDigits[4];
|
||||||
|
|
||||||
|
static inline void lexer_SetBinDigits(char const digits[2])
|
||||||
|
{
|
||||||
|
binDigits[0] = digits[0];
|
||||||
|
binDigits[1] = digits[1];
|
||||||
|
}
|
||||||
|
|
||||||
|
static inline void lexer_SetGfxDigits(char const digits[4])
|
||||||
|
{
|
||||||
|
gfxDigits[0] = digits[0];
|
||||||
|
gfxDigits[1] = digits[1];
|
||||||
|
gfxDigits[2] = digits[2];
|
||||||
|
gfxDigits[3] = digits[3];
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* `path` is referenced, but not held onto..!
|
||||||
|
*/
|
||||||
|
struct LexerState *lexer_OpenFile(char const *path);
|
||||||
|
struct LexerState *lexer_OpenFileView(char const *path, char *buf, size_t size, uint32_t lineNo);
|
||||||
|
void lexer_RestartRept(uint32_t lineNo);
|
||||||
|
void lexer_DeleteState(struct LexerState *state);
|
||||||
|
void lexer_Init(void);
|
||||||
|
|
||||||
|
enum LexerMode {
|
||||||
|
LEXER_NORMAL,
|
||||||
|
LEXER_RAW,
|
||||||
|
LEXER_SKIP_TO_ELIF,
|
||||||
|
LEXER_SKIP_TO_ENDC,
|
||||||
|
LEXER_SKIP_TO_ENDR
|
||||||
};
|
};
|
||||||
|
|
||||||
struct sLexFloat {
|
void lexer_SetMode(enum LexerMode mode);
|
||||||
uint32_t (*Callback)(char *s, uint32_t size);
|
void lexer_ToggleStringExpansion(bool enable);
|
||||||
uint32_t nToken;
|
|
||||||
|
uint32_t lexer_GetIFDepth(void);
|
||||||
|
void lexer_IncIFDepth(void);
|
||||||
|
void lexer_DecIFDepth(void);
|
||||||
|
bool lexer_RanIFBlock(void);
|
||||||
|
bool lexer_ReachedELSEBlock(void);
|
||||||
|
void lexer_RunIFBlock(void);
|
||||||
|
void lexer_ReachELSEBlock(void);
|
||||||
|
|
||||||
|
struct CaptureBody {
|
||||||
|
uint32_t lineNo;
|
||||||
|
char *body;
|
||||||
|
size_t size;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct yy_buffer_state {
|
void lexer_CheckRecursionDepth(void);
|
||||||
/* Actual starting address */
|
char const *lexer_GetFileName(void);
|
||||||
char *pBufferRealStart;
|
uint32_t lexer_GetLineNo(void);
|
||||||
/* Address where the data is initially written after a safety margin */
|
uint32_t lexer_GetColNo(void);
|
||||||
char *pBufferStart;
|
void lexer_DumpStringExpansions(void);
|
||||||
char *pBuffer;
|
|
||||||
size_t nBufferSize;
|
|
||||||
uint32_t oAtLineStart;
|
|
||||||
};
|
|
||||||
|
|
||||||
enum eLexerState {
|
|
||||||
LEX_STATE_NORMAL,
|
|
||||||
LEX_STATE_MACROARGS
|
|
||||||
};
|
|
||||||
|
|
||||||
struct sStringExpansionPos {
|
|
||||||
char *tzName;
|
|
||||||
char *pBuffer;
|
|
||||||
char *pBufferPos;
|
|
||||||
struct sStringExpansionPos *pParent;
|
|
||||||
};
|
|
||||||
|
|
||||||
#define INITIAL 0
|
|
||||||
#define macroarg 3
|
|
||||||
|
|
||||||
typedef struct yy_buffer_state *YY_BUFFER_STATE;
|
|
||||||
|
|
||||||
void setup_lexer(void);
|
|
||||||
|
|
||||||
void yy_set_state(enum eLexerState i);
|
|
||||||
YY_BUFFER_STATE yy_create_buffer(FILE *f);
|
|
||||||
YY_BUFFER_STATE yy_scan_bytes(char const *mem, uint32_t size);
|
|
||||||
void yy_delete_buffer(YY_BUFFER_STATE buf);
|
|
||||||
void yy_switch_to_buffer(YY_BUFFER_STATE buf);
|
|
||||||
uint32_t lex_FloatAlloc(const struct sLexFloat *tok);
|
|
||||||
void lex_FloatAddRange(uint32_t id, uint16_t start, uint16_t end);
|
|
||||||
void lex_FloatDeleteRange(uint32_t id, uint16_t start, uint16_t end);
|
|
||||||
void lex_FloatAddFirstRange(uint32_t id, uint16_t start, uint16_t end);
|
|
||||||
void lex_FloatDeleteFirstRange(uint32_t id, uint16_t start, uint16_t end);
|
|
||||||
void lex_FloatAddSecondRange(uint32_t id, uint16_t start, uint16_t end);
|
|
||||||
void lex_FloatDeleteSecondRange(uint32_t id, uint16_t start, uint16_t end);
|
|
||||||
void lex_Init(void);
|
|
||||||
void lex_AddStrings(const struct sLexInitString *lex);
|
|
||||||
void lex_SetBuffer(char *buffer, uint32_t len);
|
|
||||||
void lex_BeginStringExpansion(const char *tzName);
|
|
||||||
int yywrap(void);
|
|
||||||
int yylex(void);
|
int yylex(void);
|
||||||
void yyunput(char c);
|
bool lexer_CaptureRept(struct CaptureBody *capture);
|
||||||
void yyunputstr(const char *s);
|
bool lexer_CaptureMacroBody(struct CaptureBody *capture);
|
||||||
void yyskipbytes(uint32_t count);
|
|
||||||
void yyunputbytes(uint32_t count);
|
|
||||||
|
|
||||||
extern YY_BUFFER_STATE pCurrentBuffer;
|
#define INITIAL_DS_ARG_SIZE 2
|
||||||
extern struct sStringExpansionPos *pCurrentStringExpansion;
|
struct DsArgList {
|
||||||
|
size_t nbArgs;
|
||||||
void upperstring(char *s);
|
size_t capacity;
|
||||||
void lowerstring(char *s);
|
struct Expression *args;
|
||||||
|
};
|
||||||
|
|
||||||
#endif /* RGBDS_ASM_LEXER_H */
|
#endif /* RGBDS_ASM_LEXER_H */
|
||||||
|
|||||||
@@ -1,131 +0,0 @@
|
|||||||
/*
|
|
||||||
* This file is part of RGBDS.
|
|
||||||
*
|
|
||||||
* Copyright (c) 1997-2018, Carsten Sorensen and RGBDS contributors.
|
|
||||||
*
|
|
||||||
* SPDX-License-Identifier: MIT
|
|
||||||
*/
|
|
||||||
|
|
||||||
#ifndef RGBDS_ASM_LOCALASM_H
|
|
||||||
#define RGBDS_ASM_LOCALASM_H
|
|
||||||
|
|
||||||
/*
|
|
||||||
* GB Z80 instruction groups
|
|
||||||
*
|
|
||||||
* n3 = 3-bit
|
|
||||||
* n = 8-bit
|
|
||||||
* nn = 16-bit
|
|
||||||
*
|
|
||||||
* ADC A,n : 0xCE
|
|
||||||
* ADC A,r : 0x88|r
|
|
||||||
* ADD A,n : 0xC6
|
|
||||||
* ADD A,r : 0x80|r
|
|
||||||
* ADD HL,ss : 0x09|(ss<<4)
|
|
||||||
* ADD SP,n : 0xE8
|
|
||||||
* AND A,n : 0xE6
|
|
||||||
* AND A,r : 0xA0|r
|
|
||||||
* BIT n3,r : 0xCB 0x40|(n3<<3)|r
|
|
||||||
* CALL cc,nn : 0xC4|(cc<<3)
|
|
||||||
* CALL nn : 0xCD
|
|
||||||
* CCF : 0x3F
|
|
||||||
* CP A,n : 0xFE
|
|
||||||
* CP A,r : 0xB8|r
|
|
||||||
* CPL : 0x2F
|
|
||||||
* DAA : 0x27
|
|
||||||
* DEC r : 0x05|(r<<3)
|
|
||||||
* DEC ss : 0x0B|(ss<<4)
|
|
||||||
* DI : 0xF3
|
|
||||||
* EI : 0xFB
|
|
||||||
* HALT : 0x76
|
|
||||||
* INC r : 0x04|(r<<3)
|
|
||||||
* INC ss : 0x03|(ss<<4)
|
|
||||||
* JP HL : 0xE9
|
|
||||||
* JP cc,nn : 0xC2|(cc<<3)
|
|
||||||
* JP nn : 0xC3|(cc<<3)
|
|
||||||
* JR n : 0x18
|
|
||||||
* JR cc,n : 0x20|(cc<<3)
|
|
||||||
* LD (nn),SP : 0x08
|
|
||||||
* LD ($FF00+C),A : 0xE2
|
|
||||||
* LD ($FF00+n),A : 0xE0
|
|
||||||
* LD (nn),A : 0xEA
|
|
||||||
* LD (rr),A : 0x02|(rr<<4) // HL+ and HL- included
|
|
||||||
* LD A,($FF00+C) : 0xF2
|
|
||||||
* LD A,($FF00+n) : 0xF0
|
|
||||||
* LD A,(nn) : 0xFA
|
|
||||||
* LD A,(rr) : 0x0A|(rr<<4) // HL+ and HL- included
|
|
||||||
* LD HL,SP+n : 0xF8
|
|
||||||
* LD SP,HL : 0xF9
|
|
||||||
* LD r,n : 0x06|(r<<3)
|
|
||||||
* LD r,r' : 0x40|(r<<3)|r' // NOTE: LD (HL),(HL) not allowed
|
|
||||||
* LD ss,nn : 0x01|(ss<<4)
|
|
||||||
* NOP : 0x00
|
|
||||||
* OR A,n : 0xF6
|
|
||||||
* OR A,r : 0xB0|r
|
|
||||||
* POP tt : 0xC1|(tt<<4)
|
|
||||||
* PUSH tt : 0xC5|(tt<<4)
|
|
||||||
* RES n3,r : 0xCB 0x80|(n3<<3)|r
|
|
||||||
* RET : 0xC9
|
|
||||||
* RET cc : 0xC0|(cc<<3)
|
|
||||||
* RETI : 0xD9
|
|
||||||
* RL r : 0xCB 0x10|r
|
|
||||||
* RLA : 0x17
|
|
||||||
* RLC r : 0xCB 0x00|r
|
|
||||||
* RLCA : 0x07
|
|
||||||
* RR r : 0xCB 0x18|r
|
|
||||||
* RRA : 0x1F
|
|
||||||
* RRC r : 0xCB 0x08|r
|
|
||||||
* RRCA : 0x0F
|
|
||||||
* RST n : 0xC7|n
|
|
||||||
* SBC A,n : 0xDE
|
|
||||||
* SBC A,r : 0x98|r
|
|
||||||
* SCF : 0x37
|
|
||||||
* SET n3,r : 0xCB 0xC0|(n8<<3)|r
|
|
||||||
* SLA r : 0xCB 0x20|r
|
|
||||||
* SRA r : 0xCB 0x28|r
|
|
||||||
* SRL r : 0xCB 0x38|r
|
|
||||||
* STOP : 0x10 0x00
|
|
||||||
* SUB A,n : 0xD6
|
|
||||||
* SUB A,r : 0x90|r
|
|
||||||
* SWAP r : 0xCB 0x30|r
|
|
||||||
* XOR A,n : 0xEE
|
|
||||||
* XOR A,r : 0xA8|r
|
|
||||||
*/
|
|
||||||
|
|
||||||
/* "r" defs */
|
|
||||||
enum {
|
|
||||||
REG_B = 0,
|
|
||||||
REG_C,
|
|
||||||
REG_D,
|
|
||||||
REG_E,
|
|
||||||
REG_H,
|
|
||||||
REG_L,
|
|
||||||
REG_HL_IND,
|
|
||||||
REG_A
|
|
||||||
};
|
|
||||||
|
|
||||||
/* "rr" defs */
|
|
||||||
enum {
|
|
||||||
REG_BC_IND = 0,
|
|
||||||
REG_DE_IND,
|
|
||||||
REG_HL_INDINC,
|
|
||||||
REG_HL_INDDEC,
|
|
||||||
};
|
|
||||||
|
|
||||||
/* "ss" defs (SP) and "tt" defs (AF) */
|
|
||||||
enum {
|
|
||||||
REG_BC = 0,
|
|
||||||
REG_DE = 1,
|
|
||||||
REG_HL = 2,
|
|
||||||
REG_SP = 3,
|
|
||||||
REG_AF = 3
|
|
||||||
};
|
|
||||||
|
|
||||||
/* "cc" defs */
|
|
||||||
enum {
|
|
||||||
CC_NZ = 0,
|
|
||||||
CC_Z,
|
|
||||||
CC_NC,
|
|
||||||
CC_C
|
|
||||||
};
|
|
||||||
|
|
||||||
#endif /* RGBDS_ASM_LOCALASM_H */
|
|
||||||
+4
-1
@@ -10,6 +10,7 @@
|
|||||||
#define RGBDS_MACRO_H
|
#define RGBDS_MACRO_H
|
||||||
|
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
|
#include <stdbool.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
|
||||||
#include "asm/warning.h"
|
#include "asm/warning.h"
|
||||||
@@ -24,11 +25,13 @@ 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 const *macro_GetAllArgs(void);
|
||||||
|
|
||||||
uint32_t macro_GetUniqueID(void);
|
uint32_t macro_GetUniqueID(void);
|
||||||
char const *macro_GetUniqueIDStr(void);
|
char const *macro_GetUniqueIDStr(void);
|
||||||
void macro_SetUniqueID(uint32_t id);
|
void macro_SetUniqueID(uint32_t id);
|
||||||
void macro_ShiftCurrentArgs(void);
|
uint32_t macro_UseNewUniqueID(void);
|
||||||
|
void macro_ShiftCurrentArgs(int32_t count);
|
||||||
uint32_t macro_NbArgs(void);
|
uint32_t macro_NbArgs(void);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
+6
-32
@@ -1,7 +1,7 @@
|
|||||||
/*
|
/*
|
||||||
* This file is part of RGBDS.
|
* This file is part of RGBDS.
|
||||||
*
|
*
|
||||||
* Copyright (c) 1997-2018, Carsten Sorensen and RGBDS contributors.
|
* Copyright (c) 1997-2021, Carsten Sorensen and RGBDS contributors.
|
||||||
*
|
*
|
||||||
* SPDX-License-Identifier: MIT
|
* SPDX-License-Identifier: MIT
|
||||||
*/
|
*/
|
||||||
@@ -15,41 +15,15 @@
|
|||||||
|
|
||||||
#include "helpers.h"
|
#include "helpers.h"
|
||||||
|
|
||||||
struct sOptions {
|
|
||||||
char binary[2];
|
|
||||||
char gbgfx[4];
|
|
||||||
int32_t fillchar;
|
|
||||||
};
|
|
||||||
|
|
||||||
extern char *tzNewMacro;
|
|
||||||
extern uint32_t ulNewMacroSize;
|
|
||||||
extern int32_t nGBGfxID;
|
|
||||||
extern int32_t nBinaryID;
|
|
||||||
|
|
||||||
extern uint32_t curOffset; /* Offset into the current section */
|
|
||||||
|
|
||||||
extern struct sOptions DefaultOptions;
|
|
||||||
extern struct sOptions CurrentOptions;
|
|
||||||
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;
|
||||||
|
|
||||||
void opt_Push(void);
|
|
||||||
void opt_Pop(void);
|
|
||||||
void opt_Parse(char *s);
|
|
||||||
|
|
||||||
#define YY_FATAL_ERROR fatalerror
|
|
||||||
|
|
||||||
#ifdef YYLMAX
|
|
||||||
#undef YYLMAX
|
|
||||||
#endif
|
|
||||||
#define YYLMAX 65536
|
|
||||||
|
|
||||||
#endif /* RGBDS_MAIN_H */
|
#endif /* RGBDS_MAIN_H */
|
||||||
|
|||||||
@@ -1,29 +0,0 @@
|
|||||||
/*
|
|
||||||
* This file is part of RGBDS.
|
|
||||||
*
|
|
||||||
* Copyright (c) 1997-2018, Carsten Sorensen and RGBDS contributors.
|
|
||||||
*
|
|
||||||
* SPDX-License-Identifier: MIT
|
|
||||||
*/
|
|
||||||
|
|
||||||
#ifndef RGBDS_ASM_MATH_H
|
|
||||||
#define RGBDS_ASM_MATH_H
|
|
||||||
|
|
||||||
#include <stdint.h>
|
|
||||||
|
|
||||||
void math_DefinePI(void);
|
|
||||||
void math_Print(int32_t i);
|
|
||||||
int32_t math_Sin(int32_t i);
|
|
||||||
int32_t math_Cos(int32_t i);
|
|
||||||
int32_t math_Tan(int32_t i);
|
|
||||||
int32_t math_ASin(int32_t i);
|
|
||||||
int32_t math_ACos(int32_t i);
|
|
||||||
int32_t math_ATan(int32_t i);
|
|
||||||
int32_t math_ATan2(int32_t i, int32_t j);
|
|
||||||
int32_t math_Mul(int32_t i, int32_t j);
|
|
||||||
int32_t math_Div(int32_t i, int32_t j);
|
|
||||||
int32_t math_Round(int32_t i);
|
|
||||||
int32_t math_Ceil(int32_t i);
|
|
||||||
int32_t math_Floor(int32_t i);
|
|
||||||
|
|
||||||
#endif /* RGBDS_ASM_MATH_H */
|
|
||||||
@@ -0,0 +1,25 @@
|
|||||||
|
/*
|
||||||
|
* This file is part of RGBDS.
|
||||||
|
*
|
||||||
|
* Copyright (c) 2021, Eldred Habert and RGBDS contributors.
|
||||||
|
*
|
||||||
|
* SPDX-License-Identifier: MIT
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef RGBDS_OPT_H
|
||||||
|
#define RGBDS_OPT_H
|
||||||
|
|
||||||
|
#include <stdbool.h>
|
||||||
|
#include <stdint.h>
|
||||||
|
|
||||||
|
void opt_B(char const chars[2]);
|
||||||
|
void opt_G(char const chars[4]);
|
||||||
|
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_Push(void);
|
||||||
|
void opt_Pop(void);
|
||||||
|
|
||||||
|
#endif
|
||||||
@@ -14,13 +14,15 @@
|
|||||||
#include "linkdefs.h"
|
#include "linkdefs.h"
|
||||||
|
|
||||||
struct Expression;
|
struct Expression;
|
||||||
|
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_ReplaceNode(struct FileStackNode *node);
|
||||||
void out_SetFileName(char *s);
|
void out_SetFileName(char *s);
|
||||||
void out_CreatePatch(uint32_t type, struct Expression const *expr,
|
void out_CreatePatch(uint32_t type, struct Expression const *expr, uint32_t ofs, uint32_t pcShift);
|
||||||
uint32_t ofs);
|
|
||||||
bool out_CreateAssert(enum AssertionType type, struct Expression const *expr,
|
bool out_CreateAssert(enum AssertionType type, struct Expression const *expr,
|
||||||
char const *message, uint32_t ofs);
|
char const *message, uint32_t ofs);
|
||||||
void out_WriteObject(void);
|
void out_WriteObject(void);
|
||||||
|
|||||||
+18
-15
@@ -17,23 +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
|
||||||
};
|
};
|
||||||
|
|
||||||
/* FIXME: Should be defined in `asmy.h`, but impossible with POSIX Yacc */
|
|
||||||
extern int32_t nPCOffset;
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* 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;
|
||||||
}
|
}
|
||||||
@@ -46,9 +43,11 @@ static inline bool rpn_isSymbol(const struct Expression *expr)
|
|||||||
return expr->isSymbol;
|
return expr->isSymbol;
|
||||||
}
|
}
|
||||||
|
|
||||||
void rpn_Symbol(struct Expression *expr, char *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);
|
||||||
|
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);
|
||||||
@@ -57,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 */
|
||||||
|
|||||||
+44
-28
@@ -13,21 +13,26 @@
|
|||||||
#include <stdbool.h>
|
#include <stdbool.h>
|
||||||
|
|
||||||
#include "linkdefs.h"
|
#include "linkdefs.h"
|
||||||
|
#include "platform.h" // NONNULL
|
||||||
|
|
||||||
|
extern uint8_t fillByte;
|
||||||
|
|
||||||
struct Expression;
|
struct Expression;
|
||||||
|
|
||||||
struct Section {
|
struct Section {
|
||||||
char *pzName;
|
char *name;
|
||||||
enum SectionType nType;
|
enum SectionType type;
|
||||||
enum SectionModifier modifier;
|
enum SectionModifier modifier;
|
||||||
|
struct FileStackNode *src; /* Where the section was defined */
|
||||||
|
uint32_t fileLine; /* Line where the section was defined */
|
||||||
uint32_t size;
|
uint32_t size;
|
||||||
uint32_t nOrg;
|
uint32_t org;
|
||||||
uint32_t nBank;
|
uint32_t bank;
|
||||||
uint8_t nAlign;
|
uint8_t align; // Exactly as specified in `ALIGN[]`
|
||||||
uint16_t alignOfs;
|
uint16_t alignOfs;
|
||||||
struct Section *pNext;
|
struct Section *next;
|
||||||
struct Patch *pPatches;
|
struct Patch *patches;
|
||||||
uint8_t *tData;
|
uint8_t *data;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct SectionSpec {
|
struct SectionSpec {
|
||||||
@@ -36,31 +41,42 @@ struct SectionSpec {
|
|||||||
uint16_t alignOfs;
|
uint16_t alignOfs;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct Section *out_FindSectionByName(const char *pzName);
|
extern struct Section *currentSection;
|
||||||
void out_NewSection(char const *pzName, 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,
|
||||||
void out_EndLoadSection(void);
|
struct SectionSpec const *attributes, enum SectionModifier mod);
|
||||||
|
void sect_EndLoadSection(void);
|
||||||
|
|
||||||
struct Section *sect_GetSymbolSection(void);
|
struct Section *sect_GetSymbolSection(void);
|
||||||
|
uint32_t sect_GetSymbolOffset(void);
|
||||||
uint32_t sect_GetOutputOffset(void);
|
uint32_t sect_GetOutputOffset(void);
|
||||||
void sect_AlignPC(uint8_t alignment, uint16_t offset);
|
void sect_AlignPC(uint8_t alignment, uint16_t offset);
|
||||||
|
|
||||||
void out_AbsByte(uint8_t b);
|
void sect_StartUnion(void);
|
||||||
void out_AbsByteGroup(uint8_t const *s, int32_t length);
|
void sect_NextUnionMember(void);
|
||||||
void out_Skip(int32_t skip, bool ds);
|
void sect_EndUnion(void);
|
||||||
void out_String(char const *s);
|
void sect_CheckUnionClosed(void);
|
||||||
void out_RelByte(struct Expression *expr);
|
|
||||||
void out_RelBytes(struct Expression *expr, uint32_t n);
|
|
||||||
void out_RelWord(struct Expression *expr);
|
|
||||||
void out_RelLong(struct Expression *expr);
|
|
||||||
void out_PCRelByte(struct Expression *expr);
|
|
||||||
void out_BinaryFile(char const *s);
|
|
||||||
void out_BinaryFileSlice(char const *s, int32_t start_pos, int32_t length);
|
|
||||||
|
|
||||||
void out_PushSection(void);
|
void sect_AbsByte(uint8_t b);
|
||||||
void out_PopSection(void);
|
void sect_AbsByteGroup(uint8_t const *s, size_t length);
|
||||||
|
void sect_AbsWordGroup(uint8_t const *s, size_t length);
|
||||||
|
void sect_AbsLongGroup(uint8_t const *s, size_t length);
|
||||||
|
void sect_Skip(uint32_t skip, bool ds);
|
||||||
|
void sect_String(char const *s);
|
||||||
|
void sect_RelByte(struct Expression *expr, uint32_t pcShift);
|
||||||
|
void sect_RelBytes(uint32_t n, struct Expression *exprs, size_t size);
|
||||||
|
void sect_RelWord(struct Expression *expr, uint32_t pcShift);
|
||||||
|
void sect_RelLong(struct Expression *expr, uint32_t pcShift);
|
||||||
|
void sect_PCRelByte(struct Expression *expr, uint32_t pcShift);
|
||||||
|
void sect_BinaryFile(char const *s, int32_t startPos);
|
||||||
|
void sect_BinaryFileSlice(char const *s, int32_t start_pos, int32_t length);
|
||||||
|
|
||||||
|
void sect_PushSection(void);
|
||||||
|
void sect_PopSection(void);
|
||||||
|
|
||||||
|
bool sect_IsSizeKnown(struct Section const NONNULL(name));
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
+46
-27
@@ -12,18 +12,18 @@
|
|||||||
#include <stdbool.h>
|
#include <stdbool.h>
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
#include <time.h>
|
||||||
|
|
||||||
#include "asm/section.h"
|
#include "asm/section.h"
|
||||||
|
|
||||||
#include "types.h"
|
#include "platform.h" // MIN_NB_ELMS
|
||||||
|
|
||||||
#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
|
||||||
@@ -34,20 +34,22 @@ struct Symbol {
|
|||||||
enum SymbolType type;
|
enum SymbolType type;
|
||||||
bool isExported; /* Whether the symbol is to be exported */
|
bool isExported; /* Whether the symbol is to be exported */
|
||||||
bool isBuiltin; /* Whether the symbol is a built-in */
|
bool isBuiltin; /* Whether the symbol is a built-in */
|
||||||
struct Symbol const *scope;
|
|
||||||
struct Section *section;
|
struct Section *section;
|
||||||
char fileName[_MAX_PATH + 1]; /* File where the symbol was defined. */
|
struct FileStackNode *src; /* Where the symbol was defined */
|
||||||
uint32_t fileLine; /* Line where the symbol was defined. */
|
uint32_t fileLine; /* Line where the symbol was defined */
|
||||||
|
|
||||||
|
bool hasCallback;
|
||||||
union {
|
union {
|
||||||
struct { /* If sym_IsNumeric */
|
/* If sym_IsNumeric */
|
||||||
int32_t value;
|
int32_t value;
|
||||||
int32_t (*callback)(void);
|
int32_t (*numCallback)(void);
|
||||||
};
|
/* For SYM_MACRO and SYM_EQUS; TODO: have separate fields */
|
||||||
struct { /* For SYM_MACRO */
|
struct {
|
||||||
uint32_t macroSize;
|
size_t macroSize;
|
||||||
char *macro;
|
char *macro;
|
||||||
};
|
};
|
||||||
|
/* 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) */
|
||||||
@@ -71,15 +73,14 @@ static inline bool sym_IsConstant(struct Symbol const *sym)
|
|||||||
if (sym->type == SYM_LABEL) {
|
if (sym->type == SYM_LABEL) {
|
||||||
struct Section const *sect = sym_GetSection(sym);
|
struct Section const *sect = sym_GetSection(sym);
|
||||||
|
|
||||||
return sect && sect->nOrg != -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)
|
||||||
@@ -102,6 +103,8 @@ static inline bool sym_IsExported(struct Symbol const *sym)
|
|||||||
*/
|
*/
|
||||||
static inline char const *sym_GetStringValue(struct Symbol const *sym)
|
static inline char const *sym_GetStringValue(struct Symbol const *sym)
|
||||||
{
|
{
|
||||||
|
if (sym->hasCallback)
|
||||||
|
return sym->strCallback();
|
||||||
return sym->macro;
|
return sym->macro;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -109,23 +112,39 @@ void sym_ForEach(void (*func)(struct Symbol *, void *), void *arg);
|
|||||||
|
|
||||||
int32_t sym_GetValue(struct Symbol const *sym);
|
int32_t sym_GetValue(struct Symbol const *sym);
|
||||||
void sym_SetExportAll(bool set);
|
void sym_SetExportAll(bool set);
|
||||||
struct Symbol *sym_AddLocalReloc(char const *symName);
|
struct Symbol *sym_AddLocalLabel(char const *symName);
|
||||||
struct Symbol *sym_AddReloc(char const *symName);
|
struct Symbol *sym_AddLabel(char const *symName);
|
||||||
|
struct Symbol *sym_AddAnonLabel(void);
|
||||||
|
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_GetConstantValue(char const *s);
|
uint32_t sym_GetConstantSymValue(struct Symbol const *sym);
|
||||||
struct Symbol *sym_FindSymbol(char const *symName);
|
uint32_t sym_GetConstantValue(char const *symName);
|
||||||
struct Symbol *sym_AddMacro(char const *symName, int32_t defLineNo);
|
/*
|
||||||
|
* Find a symbol by exact name, bypassing expansion checks
|
||||||
|
*/
|
||||||
|
struct Symbol *sym_FindExactSymbol(char const *symName);
|
||||||
|
/*
|
||||||
|
* Find a symbol by exact name; may not be scoped, produces an error if it is
|
||||||
|
*/
|
||||||
|
struct Symbol *sym_FindUnscopedSymbol(char const *symName);
|
||||||
|
/*
|
||||||
|
* Find a symbol, possibly scoped, by name
|
||||||
|
*/
|
||||||
|
struct Symbol *sym_FindScopedSymbol(char const *symName);
|
||||||
|
struct Symbol const *sym_GetPC(void);
|
||||||
|
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);
|
||||||
struct Symbol *sym_AddString(char const *symName, char const *value);
|
struct Symbol *sym_AddString(char const *symName, char const *value);
|
||||||
uint32_t sym_GetDefinedValue(char const *s);
|
struct Symbol *sym_RedefString(char const *symName, char const *value);
|
||||||
void sym_Purge(char const *symName);
|
void sym_Purge(char const *symName);
|
||||||
void sym_Init(void);
|
void sym_Init(time_t now);
|
||||||
|
|
||||||
/* Functions to save and restore the current symbol scope. */
|
/* Functions to save and restore the current symbol scope. */
|
||||||
struct Symbol *sym_GetCurrentSymbolScope(void);
|
char const *sym_GetCurrentSymbolScope(void);
|
||||||
void sym_SetCurrentSymbolScope(struct Symbol *newScope);
|
void sym_SetCurrentSymbolScope(char const *newScope);
|
||||||
|
|
||||||
#endif /* RGBDS_SYMBOL_H */
|
#endif /* RGBDS_SYMBOL_H */
|
||||||
|
|||||||
+6
-2
@@ -11,7 +11,11 @@
|
|||||||
|
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
|
|
||||||
uint32_t calchash(const char *s);
|
char const *printChar(int c);
|
||||||
int32_t readUTF8Char(char *dest, char *src);
|
|
||||||
|
/*
|
||||||
|
* @return The number of bytes read, or 0 if invalid data was found
|
||||||
|
*/
|
||||||
|
size_t readUTF8Char(uint8_t *dest, char const *src);
|
||||||
|
|
||||||
#endif /* RGBDS_UTIL_H */
|
#endif /* RGBDS_UTIL_H */
|
||||||
|
|||||||
+48
-21
@@ -13,38 +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,
|
WARNING_ASSERT, // Assertions
|
||||||
WARNING_BUILTIN_ARG,
|
WARNING_BACKWARDS_FOR, // `for` loop with backwards range
|
||||||
WARNING_DIV,
|
WARNING_BUILTIN_ARG, // Invalid args to builtins
|
||||||
WARNING_EMPTY_DATA_DIRECTIVE,
|
WARNING_CHARMAP_REDEF, // Charmap entry re-definition
|
||||||
WARNING_EMPTY_ENTRY,
|
WARNING_DIV, // Division undefined behavior
|
||||||
WARNING_LARGE_CONSTANT,
|
WARNING_EMPTY_DATA_DIRECTIVE, // `db`, `dw` or `dl` directive without data in ROM
|
||||||
WARNING_LONG_STR,
|
WARNING_EMPTY_MACRO_ARG, // Empty macro argument
|
||||||
WARNING_OBSOLETE,
|
WARNING_EMPTY_STRRPL, // Empty second argument in `STRRPL`
|
||||||
WARNING_SHIFT,
|
WARNING_LARGE_CONSTANT, // Constants too large
|
||||||
WARNING_SHIFT_AMOUNT,
|
WARNING_LONG_STR, // String too long for internal buffers
|
||||||
WARNING_TRUNCATION,
|
WARNING_MACRO_SHIFT, // Shift past available arguments in macro
|
||||||
WARNING_USER,
|
WARNING_NESTED_COMMENT, // Comment-start delimiter in a block comment
|
||||||
|
WARNING_OBSOLETE, // Obsolete things
|
||||||
|
WARNING_SHIFT, // Shifting undefined behavior
|
||||||
|
WARNING_SHIFT_AMOUNT, // Strange shift amount
|
||||||
|
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, ...);
|
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
|
||||||
@@ -53,7 +80,7 @@ void warning(enum WarningID id, const char *fmt, ...);
|
|||||||
* It is also used when the assembler goes into an invalid state (for example,
|
* It is also used when the assembler goes into an invalid state (for example,
|
||||||
* when it fails to allocate memory).
|
* when it fails to allocate memory).
|
||||||
*/
|
*/
|
||||||
noreturn_ void fatalerror(const char *fmt, ...);
|
_Noreturn void fatalerror(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
|
||||||
@@ -61,6 +88,6 @@ noreturn_ void fatalerror(const char *fmt, ...);
|
|||||||
* 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 yyerror(const char *fmt, ...);
|
void error(char const *fmt, ...) format_(printf, 1, 2);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -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 */
|
||||||
Vendored
-44
@@ -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 */
|
|
||||||
Vendored
+5
-4
@@ -26,17 +26,18 @@
|
|||||||
#ifndef RGBDS_EXTERN_GETOPT_H
|
#ifndef RGBDS_EXTERN_GETOPT_H
|
||||||
#define RGBDS_EXTERN_GETOPT_H
|
#define RGBDS_EXTERN_GETOPT_H
|
||||||
|
|
||||||
extern char *optarg;
|
extern char *musl_optarg;
|
||||||
extern int optind, opterr, optopt, 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
|
||||||
|
|||||||
Vendored
+1
-1
@@ -9,6 +9,6 @@
|
|||||||
#ifndef EXTERN_UTF8DECODER_H
|
#ifndef EXTERN_UTF8DECODER_H
|
||||||
#define EXTERN_UTF8DECODER_H
|
#define EXTERN_UTF8DECODER_H
|
||||||
|
|
||||||
uint32_t decode(uint32_t *state, uint32_t *codep, uint32_t byte);
|
uint32_t decode(uint32_t *state, uint32_t *codep, uint8_t byte);
|
||||||
|
|
||||||
#endif /* EXTERN_UTF8DECODER_H */
|
#endif /* EXTERN_UTF8DECODER_H */
|
||||||
|
|||||||
+3
-3
@@ -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;
|
||||||
|
|||||||
+10
-2
@@ -29,9 +29,9 @@ typedef struct HashMapEntry *HashMap[HASHMAP_NB_BUCKETS];
|
|||||||
* @param map The HashMap to add the element to
|
* @param map The HashMap to add the element to
|
||||||
* @param key The key with which the element will be stored and retrieved
|
* @param key The key with which the element will be stored and retrieved
|
||||||
* @param element The element to add
|
* @param element The element to add
|
||||||
* @return True if a collision occurred (for statistics)
|
* @return A pointer to the pointer to the element.
|
||||||
*/
|
*/
|
||||||
bool hash_AddElement(HashMap map, char const *key, void *element);
|
void **hash_AddElement(HashMap map, char const *key, void *element);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Removes an element from a hashmap.
|
* Removes an element from a hashmap.
|
||||||
@@ -41,6 +41,14 @@ bool hash_AddElement(HashMap map, char const *key, void *element);
|
|||||||
*/
|
*/
|
||||||
bool hash_RemoveElement(HashMap map, char const *key);
|
bool hash_RemoveElement(HashMap map, char const *key);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Finds an element in a hashmap, and returns a pointer to its value field.
|
||||||
|
* @param map The map to consider the elements of
|
||||||
|
* @param key The key to search an element for
|
||||||
|
* @return A pointer to the pointer to the element, or NULL if not found.
|
||||||
|
*/
|
||||||
|
void **hash_GetNode(HashMap const map, char const *key);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Finds an element in a hashmap.
|
* Finds an element in a hashmap.
|
||||||
* @param map The map to consider the elements of
|
* @param map The map to consider the elements of
|
||||||
|
|||||||
+74
-12
@@ -1,7 +1,7 @@
|
|||||||
/*
|
/*
|
||||||
* This file is part of RGBDS.
|
* This file is part of RGBDS.
|
||||||
*
|
*
|
||||||
* Copyright (c) 2014-2018, RGBDS contributors.
|
* Copyright (c) 2014-2020, RGBDS contributors.
|
||||||
*
|
*
|
||||||
* SPDX-License-Identifier: MIT
|
* SPDX-License-Identifier: MIT
|
||||||
*/
|
*/
|
||||||
@@ -9,26 +9,88 @@
|
|||||||
#ifndef HELPERS_H
|
#ifndef HELPERS_H
|
||||||
#define HELPERS_H
|
#define HELPERS_H
|
||||||
|
|
||||||
#ifdef __GNUC__
|
// Of course, MSVC does not support C11, so no _Noreturn there...
|
||||||
/* GCC or compatible */
|
#ifdef _MSC_VER
|
||||||
|
#define _Noreturn __declspec(noreturn)
|
||||||
|
#endif
|
||||||
|
|
||||||
|
// Ideally, we'd use `__has_attribute` and `__has_builtin`, but these were only introduced in GCC 9
|
||||||
|
#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 noreturn_ __attribute__ ((noreturn))
|
#define attr_(...) __attribute__ ((__VA_ARGS__))
|
||||||
#define trap_ __builtin_trap()
|
// In release builds, define "unreachable" as such, but trap in debug builds
|
||||||
|
#ifdef NDEBUG
|
||||||
|
#define unreachable_ __builtin_unreachable
|
||||||
|
#else
|
||||||
|
#define unreachable_ __builtin_trap
|
||||||
|
#endif
|
||||||
#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 noreturn_
|
#define attr_(...)
|
||||||
#define unused_
|
// This seems to generate similar code to __builtin_unreachable, despite different semantics
|
||||||
#define trap_
|
// Note that executing this is undefined behavior (declared _Noreturn, but does return)
|
||||||
|
static inline _Noreturn unreachable_(void) {}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifndef DEVELOP
|
// Use builtins whenever possible, and shim them otherwise
|
||||||
#define DEVELOP 0
|
#ifdef __GNUC__ // GCC or compatible
|
||||||
|
#define ctz __builtin_ctz
|
||||||
|
#define clz __builtin_clz
|
||||||
|
|
||||||
|
#elif defined(_MSC_VER)
|
||||||
|
#include <assert.h>
|
||||||
|
#include <intrin.h>
|
||||||
|
#pragma intrinsic(_BitScanReverse, _BitScanForward)
|
||||||
|
static inline int ctz(unsigned int x)
|
||||||
|
{
|
||||||
|
unsigned long cnt;
|
||||||
|
|
||||||
|
assert(x != 0);
|
||||||
|
_BitScanForward(&cnt, x);
|
||||||
|
return cnt;
|
||||||
|
}
|
||||||
|
static inline int clz(unsigned int x)
|
||||||
|
{
|
||||||
|
unsigned long cnt;
|
||||||
|
|
||||||
|
assert(x != 0);
|
||||||
|
_BitScanReverse(&cnt, x);
|
||||||
|
return 31 - cnt;
|
||||||
|
}
|
||||||
|
|
||||||
|
#else
|
||||||
|
#include <limits.h>
|
||||||
|
static inline int ctz(unsigned int x)
|
||||||
|
{
|
||||||
|
int cnt = 0;
|
||||||
|
|
||||||
|
while (!(x & 1)) {
|
||||||
|
x >>= 1;
|
||||||
|
cnt++;
|
||||||
|
}
|
||||||
|
return cnt;
|
||||||
|
}
|
||||||
|
|
||||||
|
static inline int clz(unsigned int x)
|
||||||
|
{
|
||||||
|
int cnt = 0;
|
||||||
|
|
||||||
|
while (x <= UINT_MAX / 2) {
|
||||||
|
x <<= 1;
|
||||||
|
cnt++;
|
||||||
|
}
|
||||||
|
return cnt;
|
||||||
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/* Macros for stringification */
|
// Macros for stringification
|
||||||
#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 */
|
||||||
|
|||||||
+35
-2
@@ -24,20 +24,53 @@ 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;
|
||||||
extern bool disablePadding;
|
extern bool disablePadding;
|
||||||
|
|
||||||
|
struct FileStackNode {
|
||||||
|
struct FileStackNode *parent;
|
||||||
|
/* Line at which the parent context was exited; meaningless for the root level */
|
||||||
|
uint32_t lineNo;
|
||||||
|
|
||||||
|
enum {
|
||||||
|
NODE_REPT,
|
||||||
|
NODE_FILE,
|
||||||
|
NODE_MACRO,
|
||||||
|
} type;
|
||||||
|
union {
|
||||||
|
char *name; /* NODE_FILE, NODE_MACRO */
|
||||||
|
struct { /* NODE_REPT */
|
||||||
|
uint32_t reptDepth;
|
||||||
|
uint32_t *iters;
|
||||||
|
};
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
/* Helper macro for printing verbose-mode messages */
|
/* Helper macro for printing verbose-mode messages */
|
||||||
#define verbosePrint(...) do { \
|
#define verbosePrint(...) do { \
|
||||||
if (beVerbose) \
|
if (beVerbose) \
|
||||||
fprintf(stderr, __VA_ARGS__); \
|
fprintf(stderr, __VA_ARGS__); \
|
||||||
} while (0)
|
} while (0)
|
||||||
|
|
||||||
void error(char const *fmt, ...);
|
/**
|
||||||
|
* Dump a file stack to stderr
|
||||||
|
* @param node The leaf node to dump the context of
|
||||||
|
*/
|
||||||
|
char const *dumpFileStack(struct FileStackNode const *node);
|
||||||
|
|
||||||
noreturn_ void fatal(char const *fmt, ...);
|
void warning(struct FileStackNode const *where, uint32_t lineNo,
|
||||||
|
char const *fmt, ...) format_(printf, 3, 4);
|
||||||
|
|
||||||
|
void error(struct FileStackNode const *where, uint32_t lineNo,
|
||||||
|
char const *fmt, ...) format_(printf, 3, 4);
|
||||||
|
|
||||||
|
_Noreturn void fatal(struct FileStackNode const *where, uint32_t lineNo,
|
||||||
|
char const *fmt, ...) format_(printf, 3, 4);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Opens a file if specified, and aborts on error.
|
* Opens a file if specified, and aborts on error.
|
||||||
|
|||||||
@@ -14,8 +14,9 @@
|
|||||||
/**
|
/**
|
||||||
* Read an object (.o) file, and add its info to the data structures.
|
* Read an object (.o) file, and add its info to the data structures.
|
||||||
* @param fileName A path to the object file to be read
|
* @param fileName A path to the object file to be read
|
||||||
|
* @param i The ID of the file
|
||||||
*/
|
*/
|
||||||
void obj_ReadFile(char const *fileName);
|
void obj_ReadFile(char const *fileName, unsigned int i);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Perform validation on the object files' contents
|
* Perform validation on the object files' contents
|
||||||
@@ -27,6 +28,12 @@ void obj_DoSanityChecks(void);
|
|||||||
*/
|
*/
|
||||||
void obj_CheckAssertions(void);
|
void obj_CheckAssertions(void);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets up object file reading
|
||||||
|
* @param nbFiles The number of object files that will be read
|
||||||
|
*/
|
||||||
|
void obj_Setup(unsigned int nbFiles);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* `free`s all object memory that was allocated.
|
* `free`s all object memory that was allocated.
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -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;
|
||||||
|
|||||||
@@ -19,6 +19,7 @@
|
|||||||
|
|
||||||
#include "linkdefs.h"
|
#include "linkdefs.h"
|
||||||
|
|
||||||
|
struct FileStackNode;
|
||||||
struct Section;
|
struct Section;
|
||||||
|
|
||||||
struct AttachedSymbol {
|
struct AttachedSymbol {
|
||||||
@@ -27,12 +28,13 @@ struct AttachedSymbol {
|
|||||||
};
|
};
|
||||||
|
|
||||||
struct Patch {
|
struct Patch {
|
||||||
char *fileName;
|
struct FileStackNode const *src;
|
||||||
int32_t offset;
|
uint32_t lineNo;
|
||||||
|
uint32_t offset;
|
||||||
uint32_t pcSectionID;
|
uint32_t pcSectionID;
|
||||||
uint32_t pcOffset;
|
uint32_t pcOffset;
|
||||||
enum PatchType type;
|
enum PatchType type;
|
||||||
int32_t rpnSize;
|
uint32_t rpnSize;
|
||||||
uint8_t *rpnExpression;
|
uint8_t *rpnExpression;
|
||||||
|
|
||||||
struct Section const *pcSection;
|
struct Section const *pcSection;
|
||||||
|
|||||||
@@ -16,12 +16,14 @@
|
|||||||
|
|
||||||
#include "linkdefs.h"
|
#include "linkdefs.h"
|
||||||
|
|
||||||
|
struct FileStackNode;
|
||||||
|
|
||||||
struct Symbol {
|
struct Symbol {
|
||||||
/* Info contained in the object files */
|
/* Info contained in the object files */
|
||||||
char *name;
|
char *name;
|
||||||
enum ExportLevel type;
|
enum ExportLevel type;
|
||||||
char const *objFileName;
|
char const *objFileName;
|
||||||
char *fileName;
|
struct FileStackNode const *src;
|
||||||
int32_t lineNo;
|
int32_t lineNo;
|
||||||
int32_t sectionID;
|
int32_t sectionID;
|
||||||
union {
|
union {
|
||||||
|
|||||||
+33
-29
@@ -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 5U
|
#define RGBDS_OBJECT_REV 9U
|
||||||
|
|
||||||
enum AssertionType {
|
enum AssertionType {
|
||||||
ASSERT_WARN,
|
ASSERT_WARN,
|
||||||
@@ -23,41 +23,45 @@ enum AssertionType {
|
|||||||
};
|
};
|
||||||
|
|
||||||
enum RPNCommand {
|
enum RPNCommand {
|
||||||
RPN_ADD = 0x00,
|
RPN_ADD = 0x00,
|
||||||
RPN_SUB = 0x01,
|
RPN_SUB = 0x01,
|
||||||
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_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,
|
||||||
RPN_LOGGT = 0x32,
|
RPN_LOGGT = 0x32,
|
||||||
RPN_LOGLT = 0x33,
|
RPN_LOGLT = 0x33,
|
||||||
RPN_LOGGE = 0x34,
|
RPN_LOGGE = 0x34,
|
||||||
RPN_LOGLE = 0x35,
|
RPN_LOGLE = 0x35,
|
||||||
|
|
||||||
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,
|
||||||
|
|
||||||
RPN_CONST = 0x80,
|
RPN_CONST = 0x80,
|
||||||
RPN_SYM = 0x81
|
RPN_SYM = 0x81
|
||||||
};
|
};
|
||||||
|
|
||||||
enum SectionType {
|
enum SectionType {
|
||||||
|
|||||||
@@ -0,0 +1,21 @@
|
|||||||
|
/*
|
||||||
|
* This file is part of RGBDS.
|
||||||
|
*
|
||||||
|
* Copyright (c) 1997-2021, RGBDS contributors.
|
||||||
|
*
|
||||||
|
* SPDX-License-Identifier: MIT
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef RGBDS_OP_MATH_H
|
||||||
|
#define RGBDS_OP_MATH_H
|
||||||
|
|
||||||
|
#include <stdint.h>
|
||||||
|
|
||||||
|
int32_t op_divide(int32_t dividend, int32_t divisor);
|
||||||
|
int32_t op_modulo(int32_t dividend, int32_t divisor);
|
||||||
|
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_right(int32_t value, int32_t amount);
|
||||||
|
int32_t op_shift_right_unsigned(int32_t value, int32_t amount);
|
||||||
|
|
||||||
|
#endif /* RGBDS_OP_MATH_H */
|
||||||
+42
-1
@@ -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>
|
||||||
@@ -32,4 +33,44 @@
|
|||||||
# define S_ISDIR(mode) (((mode) & S_IFMT) == S_IFDIR)
|
# define S_ISDIR(mode) (((mode) & S_IFMT) == S_IFDIR)
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
/* MSVC doesn't use POSIX types or defines for `read` */
|
||||||
|
#ifdef _MSC_VER
|
||||||
|
# include <io.h>
|
||||||
|
# define STDIN_FILENO 0
|
||||||
|
# define STDOUT_FILENO 1
|
||||||
|
# define STDERR_FILENO 2
|
||||||
|
# define ssize_t int
|
||||||
|
# define SSIZE_MAX INT_MAX
|
||||||
|
#else
|
||||||
|
# include <fcntl.h>
|
||||||
|
# include <unistd.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/* MSVC doesn't support `[static N]` for array arguments from C99 */
|
||||||
|
#ifdef _MSC_VER
|
||||||
|
# define MIN_NB_ELMS(N)
|
||||||
|
# define NONNULL(ptr) *ptr
|
||||||
|
#else
|
||||||
|
# define MIN_NB_ELMS(N) static (N)
|
||||||
|
# define NONNULL(ptr) ptr[static 1]
|
||||||
|
#endif
|
||||||
|
|
||||||
|
// MSVC uses a different name for O_RDWR, and needs an additional _O_BINARY flag
|
||||||
|
#ifdef _MSC_VER
|
||||||
|
# include <fcntl.h>
|
||||||
|
# define O_RDWR _O_RDWR
|
||||||
|
# define S_ISREG(field) ((field) & _S_IFREG)
|
||||||
|
# define O_BINARY _O_BINARY
|
||||||
|
#elif !defined(O_BINARY) // Cross-compilers define O_BINARY
|
||||||
|
# define O_BINARY 0 // POSIX says we shouldn't care!
|
||||||
|
#endif // _MSC_VER
|
||||||
|
|
||||||
|
// Windows has stdin and stdout open as text by default, which we may not want
|
||||||
|
#if defined(_MSC_VER) || defined(__MINGW32__)
|
||||||
|
# include <io.h>
|
||||||
|
# define setmode(fd, mode) _setmode(fd, mode)
|
||||||
|
#else
|
||||||
|
# define setmode(fd, mode) ((void)0)
|
||||||
|
#endif
|
||||||
|
|
||||||
#endif /* RGBDS_PLATFORM_H */
|
#endif /* RGBDS_PLATFORM_H */
|
||||||
|
|||||||
@@ -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 */
|
|
||||||
+5
-5
@@ -1,7 +1,7 @@
|
|||||||
/*
|
/*
|
||||||
* This file is part of RGBDS.
|
* This file is part of RGBDS.
|
||||||
*
|
*
|
||||||
* Copyright (c) 2017-2018, Antonio Nino Diaz and RGBDS contributors.
|
* Copyright (c) 2017-2021, Antonio Nino Diaz and RGBDS contributors.
|
||||||
*
|
*
|
||||||
* SPDX-License-Identifier: MIT
|
* SPDX-License-Identifier: MIT
|
||||||
*/
|
*/
|
||||||
@@ -9,10 +9,10 @@
|
|||||||
#ifndef EXTERN_VERSION_H
|
#ifndef EXTERN_VERSION_H
|
||||||
#define EXTERN_VERSION_H
|
#define EXTERN_VERSION_H
|
||||||
|
|
||||||
#define PACKAGE_VERSION_MAJOR (0)
|
#define PACKAGE_VERSION_MAJOR 0
|
||||||
#define PACKAGE_VERSION_MINOR (4)
|
#define PACKAGE_VERSION_MINOR 5
|
||||||
#define PACKAGE_VERSION_PATCH (1)
|
#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 */
|
||||||
|
|||||||
@@ -0,0 +1,2 @@
|
|||||||
|
# Generated by CMake
|
||||||
|
/.version.c
|
||||||
+58
-28
@@ -6,37 +6,53 @@
|
|||||||
# 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"
|
||||||
)
|
)
|
||||||
|
|
||||||
BISON_TARGET(ASMy "asm/asmy.y"
|
find_package(PkgConfig)
|
||||||
"${PROJECT_SOURCE_DIR}/src/asm/asmy.c"
|
if(MSVC OR NOT PKG_CONFIG_FOUND)
|
||||||
DEFINES_FILE "${PROJECT_SOURCE_DIR}/src/asm/asmy.h"
|
# fallback to find_package
|
||||||
)
|
find_package(PNG REQUIRED)
|
||||||
|
|
||||||
# Lexer is not present yet
|
|
||||||
if(False) # FLEX_FOUND
|
|
||||||
FLEX_TARGET(Lexer "asm/lexer.l"
|
|
||||||
"${PROJECT_SOURCE_DIR}/src/asm/lexer.c"
|
|
||||||
)
|
|
||||||
ADD_FLEX_BISON_DEPENDENCY(Lexer ASMy)
|
|
||||||
set(Lexer_SOURCE "${FLEX_Lexer_OUTPUTS}")
|
|
||||||
else()
|
else()
|
||||||
set(Lexer_SOURCE "asm/lexer.c")
|
pkg_check_modules(LIBPNG REQUIRED libpng)
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
|
find_package(BISON REQUIRED)
|
||||||
|
set(BISON_FLAGS "-Wall")
|
||||||
|
# Set sompe optimization flags on versions that support them
|
||||||
|
if(BISON_VERSION VERSION_GREATER_EQUAL "3.5")
|
||||||
|
set(BISON_FLAGS "${BISON_FLAGS} -Dapi.token.raw=true")
|
||||||
|
endif()
|
||||||
|
if(BISON_VERSION VERSION_GREATER_EQUAL "3.6")
|
||||||
|
set(BISON_FLAGS "${BISON_FLAGS} -Dparse.error=detailed")
|
||||||
|
elseif(BISON_VERSION VERSION_GREATER_EQUAL "3.0")
|
||||||
|
set(BISON_FLAGS "${BISON_FLAGS} -Dparse.error=verbose")
|
||||||
|
endif()
|
||||||
|
if(BISON_VERSION VERSION_GREATER_EQUAL "3.0")
|
||||||
|
set(BISON_FLAGS "${BISON_FLAGS} -Dparse.lac=full")
|
||||||
|
set(BISON_FLAGS "${BISON_FLAGS} -Dlr.type=ielr")
|
||||||
|
endif()
|
||||||
|
BISON_TARGET(PARSER "asm/parser.y"
|
||||||
|
"${PROJECT_SOURCE_DIR}/src/asm/parser.c"
|
||||||
|
COMPILE_FLAGS "${BISON_FLAGS}"
|
||||||
|
DEFINES_FILE "${PROJECT_SOURCE_DIR}/src/asm/parser.h"
|
||||||
|
)
|
||||||
|
|
||||||
set(rgbasm_src
|
set(rgbasm_src
|
||||||
"${BISON_ASMy_OUTPUT_SOURCE}"
|
"${BISON_PARSER_OUTPUT_SOURCE}"
|
||||||
"${Lexer_SOURCE}"
|
|
||||||
"asm/charmap.c"
|
"asm/charmap.c"
|
||||||
|
"asm/fixpoint.c"
|
||||||
|
"asm/format.c"
|
||||||
"asm/fstack.c"
|
"asm/fstack.c"
|
||||||
"asm/globlex.c"
|
"asm/lexer.c"
|
||||||
"asm/macro.c"
|
"asm/macro.c"
|
||||||
"asm/main.c"
|
"asm/main.c"
|
||||||
"asm/math.c"
|
"asm/opt.c"
|
||||||
"asm/output.c"
|
"asm/output.c"
|
||||||
"asm/rpn.c"
|
"asm/rpn.c"
|
||||||
"asm/section.c"
|
"asm/section.c"
|
||||||
@@ -46,6 +62,7 @@ set(rgbasm_src
|
|||||||
"extern/utf8decoder.c"
|
"extern/utf8decoder.c"
|
||||||
"hashmap.c"
|
"hashmap.c"
|
||||||
"linkdefs.c"
|
"linkdefs.c"
|
||||||
|
"opmath.c"
|
||||||
)
|
)
|
||||||
|
|
||||||
set(rgbfix_src
|
set(rgbfix_src
|
||||||
@@ -69,6 +86,7 @@ set(rgblink_src
|
|||||||
"link/symbol.c"
|
"link/symbol.c"
|
||||||
"hashmap.c"
|
"hashmap.c"
|
||||||
"linkdefs.c"
|
"linkdefs.c"
|
||||||
|
"opmath.c"
|
||||||
)
|
)
|
||||||
|
|
||||||
foreach(PROG "asm" "fix" "gfx" "link")
|
foreach(PROG "asm" "fix" "gfx" "link")
|
||||||
@@ -79,10 +97,26 @@ foreach(PROG "asm" "fix" "gfx" "link")
|
|||||||
install(TARGETS rgb${PROG} RUNTIME DESTINATION bin)
|
install(TARGETS rgb${PROG} RUNTIME DESTINATION bin)
|
||||||
endforeach()
|
endforeach()
|
||||||
|
|
||||||
if(CMAKE_VERSION VERSION_LESS 2.8.12)
|
set(MANDIR "share/man")
|
||||||
add_definitions(${PNG_DEFINITIONS})
|
set(man1 "asm/rgbasm.1"
|
||||||
include_directories(${PNG_INCLUDE_DIRS})
|
"fix/rgbfix.1"
|
||||||
target_link_libraries(rgbgfx ${PNG_LIBRARIES})
|
"gfx/rgbgfx.1"
|
||||||
|
"link/rgblink.1")
|
||||||
|
set(man5 "asm/rgbasm.5"
|
||||||
|
"link/rgblink.5"
|
||||||
|
"rgbds.5")
|
||||||
|
set(man7 "gbz80.7"
|
||||||
|
"rgbds.7")
|
||||||
|
|
||||||
|
foreach(SECTION "man1" "man5" "man7")
|
||||||
|
set(DEST "${MANDIR}/${SECTION}")
|
||||||
|
install(FILES ${${SECTION}} DESTINATION ${DEST})
|
||||||
|
endforeach()
|
||||||
|
|
||||||
|
if(LIBPNG_FOUND) # pkg-config
|
||||||
|
target_include_directories(rgbgfx PRIVATE ${LIBPNG_INCLUDE_DIRS})
|
||||||
|
target_link_directories(rgbgfx PRIVATE ${LIBPNG_LIBRARY_DIRS})
|
||||||
|
target_link_libraries(rgbgfx PRIVATE ${LIBPNG_LIBRARIES})
|
||||||
else()
|
else()
|
||||||
target_compile_definitions(rgbgfx PRIVATE ${PNG_DEFINITIONS})
|
target_compile_definitions(rgbgfx PRIVATE ${PNG_DEFINITIONS})
|
||||||
target_include_directories(rgbgfx PRIVATE ${PNG_INCLUDE_DIRS})
|
target_include_directories(rgbgfx PRIVATE ${PNG_INCLUDE_DIRS})
|
||||||
@@ -92,9 +126,5 @@ endif()
|
|||||||
include(CheckLibraryExists)
|
include(CheckLibraryExists)
|
||||||
check_library_exists("m" "sin" "" HAS_LIBM)
|
check_library_exists("m" "sin" "" HAS_LIBM)
|
||||||
if(HAS_LIBM)
|
if(HAS_LIBM)
|
||||||
if(CMAKE_VERSION VERSION_LESS 2.8.12)
|
target_link_libraries(rgbasm PRIVATE "m")
|
||||||
target_link_libraries(rgbasm LINK_PRIVATE "m")
|
|
||||||
else()
|
|
||||||
target_link_libraries(rgbasm PRIVATE "m")
|
|
||||||
endif()
|
|
||||||
endif()
|
endif()
|
||||||
|
|||||||
+2
-2
@@ -1,2 +1,2 @@
|
|||||||
asmy.c
|
/parser.c
|
||||||
asmy.h
|
/parser.h
|
||||||
|
|||||||
-2020
File diff suppressed because it is too large
Load Diff
+160
-137
@@ -13,7 +13,6 @@
|
|||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
#include "asm/asm.h"
|
|
||||||
#include "asm/charmap.h"
|
#include "asm/charmap.h"
|
||||||
#include "asm/main.h"
|
#include "asm/main.h"
|
||||||
#include "asm/output.h"
|
#include "asm/output.h"
|
||||||
@@ -22,38 +21,64 @@
|
|||||||
|
|
||||||
#include "hashmap.h"
|
#include "hashmap.h"
|
||||||
|
|
||||||
#define CHARMAP_HASH_SIZE (1 << 9)
|
/*
|
||||||
|
* Charmaps are stored using a structure known as "trie".
|
||||||
|
* Essentially a tree, where each nodes stores a single character's worth of info:
|
||||||
|
* whether there exists a mapping that ends at the current character,
|
||||||
|
*/
|
||||||
|
struct Charnode {
|
||||||
|
bool isTerminal; /* Whether there exists a mapping that ends here */
|
||||||
|
uint8_t value; /* If the above is true, its corresponding value */
|
||||||
|
/* This MUST be indexes and not pointers, because pointers get invalidated by `realloc`!! */
|
||||||
|
size_t next[255]; /* Indexes of where to go next, 0 = nowhere */
|
||||||
|
};
|
||||||
|
|
||||||
struct CharmapStackEntry {
|
#define INITIAL_CAPACITY 32
|
||||||
struct Charmap *charmap;
|
|
||||||
struct CharmapStackEntry *next;
|
struct Charmap {
|
||||||
|
char *name;
|
||||||
|
size_t usedNodes; /* How many nodes are being used */
|
||||||
|
size_t capacity; /* How many nodes have been allocated */
|
||||||
|
struct Charnode nodes[]; /* first node is reserved for the root node */
|
||||||
};
|
};
|
||||||
|
|
||||||
static HashMap charmaps;
|
static HashMap charmaps;
|
||||||
|
|
||||||
static struct Charmap *mainCharmap;
|
/*
|
||||||
static struct Charmap *currentCharmap;
|
* Store pointers to hashmap nodes, so that there is only one pointer to the memory block
|
||||||
|
* that gets reallocated.
|
||||||
|
*/
|
||||||
|
static struct Charmap **currentCharmap;
|
||||||
|
|
||||||
|
struct CharmapStackEntry {
|
||||||
|
struct Charmap **charmap;
|
||||||
|
struct CharmapStackEntry *next;
|
||||||
|
};
|
||||||
|
|
||||||
struct CharmapStackEntry *charmapStack;
|
struct CharmapStackEntry *charmapStack;
|
||||||
|
|
||||||
static inline 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);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void CopyNode(struct Charmap *dest,
|
static void resizeCharmap(struct Charmap **map, size_t capacity)
|
||||||
const struct Charmap *src,
|
|
||||||
int nodeIdx)
|
|
||||||
{
|
{
|
||||||
dest->nodes[nodeIdx].code = src->nodes[nodeIdx].code;
|
*map = realloc(*map, sizeof(**map) + sizeof(*(*map)->nodes) * capacity);
|
||||||
dest->nodes[nodeIdx].isCode = src->nodes[nodeIdx].isCode;
|
|
||||||
for (int i = 0; i < 256; i++)
|
if (!*map)
|
||||||
if (src->nodes[nodeIdx].next[i])
|
fatalerror("Failed to %s charmap: %s\n",
|
||||||
dest->nodes[nodeIdx].next[i] = dest->nodes +
|
*map ? "create" : "resize", strerror(errno));
|
||||||
(src->nodes[nodeIdx].next[i] - src->nodes);
|
(**map).capacity = capacity;
|
||||||
}
|
}
|
||||||
|
|
||||||
struct Charmap *charmap_New(const char *name, const char *baseName)
|
static void initNode(struct Charnode *node)
|
||||||
|
{
|
||||||
|
node->isTerminal = false;
|
||||||
|
memset(node->next, 0, sizeof(node->next));
|
||||||
|
}
|
||||||
|
|
||||||
|
struct Charmap *charmap_New(char const *name, char const *baseName)
|
||||||
{
|
{
|
||||||
struct Charmap *base = NULL;
|
struct Charmap *base = NULL;
|
||||||
|
|
||||||
@@ -61,46 +86,46 @@ struct Charmap *charmap_New(const char *name, const char *baseName)
|
|||||||
base = charmap_Get(baseName);
|
base = charmap_Get(baseName);
|
||||||
|
|
||||||
if (base == NULL)
|
if (base == NULL)
|
||||||
yyerror("Base charmap '%s' doesn't exist", baseName);
|
error("Base charmap '%s' doesn't exist\n", baseName);
|
||||||
}
|
}
|
||||||
|
|
||||||
struct Charmap *charmap = charmap_Get(name);
|
struct Charmap *charmap = charmap_Get(name);
|
||||||
|
|
||||||
if (charmap != NULL) {
|
if (charmap) {
|
||||||
yyerror("Charmap '%s' already exists", name);
|
error("Charmap '%s' already exists\n", name);
|
||||||
return NULL;
|
return charmap;
|
||||||
}
|
}
|
||||||
|
|
||||||
charmap = malloc(sizeof(*charmap));
|
|
||||||
if (charmap == NULL)
|
|
||||||
fatalerror("Failed to create charmap: %s", strerror(errno));
|
|
||||||
|
|
||||||
/* Init the new charmap's fields */
|
/* Init the new charmap's fields */
|
||||||
snprintf(charmap->name, sizeof(charmap->name), "%s", name);
|
if (base) {
|
||||||
if (base != NULL) {
|
resizeCharmap(&charmap, base->capacity);
|
||||||
charmap->charCount = base->charCount;
|
charmap->usedNodes = base->usedNodes;
|
||||||
charmap->nodeCount = base->nodeCount;
|
|
||||||
|
|
||||||
for (int i = 0; i < MAXCHARNODES; i++)
|
memcpy(charmap->nodes, base->nodes, sizeof(base->nodes[0]) * charmap->usedNodes);
|
||||||
CopyNode(charmap, base, i);
|
|
||||||
} else {
|
} else {
|
||||||
charmap->charCount = 0;
|
resizeCharmap(&charmap, INITIAL_CAPACITY);
|
||||||
charmap->nodeCount = 0;
|
charmap->usedNodes = 1;
|
||||||
memset(charmap->nodes, 0, sizeof(charmap->nodes));
|
initNode(&charmap->nodes[0]); /* Init the root node */
|
||||||
}
|
}
|
||||||
|
charmap->name = strdup(name);
|
||||||
|
|
||||||
hash_AddElement(charmaps, charmap->name, charmap);
|
currentCharmap = (struct Charmap **)hash_AddElement(charmaps, charmap->name, charmap);
|
||||||
currentCharmap = charmap;
|
|
||||||
|
|
||||||
return charmap;
|
return charmap;
|
||||||
}
|
}
|
||||||
|
|
||||||
void charmap_Set(const char *name)
|
void charmap_Delete(struct Charmap *charmap)
|
||||||
{
|
{
|
||||||
struct Charmap *charmap = charmap_Get(name);
|
free(charmap->name);
|
||||||
|
free(charmap);
|
||||||
|
}
|
||||||
|
|
||||||
|
void charmap_Set(char const *name)
|
||||||
|
{
|
||||||
|
struct Charmap **charmap = (struct Charmap **)hash_GetNode(charmaps, name);
|
||||||
|
|
||||||
if (charmap == NULL)
|
if (charmap == NULL)
|
||||||
yyerror("Charmap '%s' doesn't exist", name);
|
error("Charmap '%s' doesn't exist\n", name);
|
||||||
else
|
else
|
||||||
currentCharmap = charmap;
|
currentCharmap = charmap;
|
||||||
}
|
}
|
||||||
@@ -109,9 +134,9 @@ void charmap_Push(void)
|
|||||||
{
|
{
|
||||||
struct CharmapStackEntry *stackEntry;
|
struct CharmapStackEntry *stackEntry;
|
||||||
|
|
||||||
stackEntry = malloc(sizeof(struct CharmapStackEntry));
|
stackEntry = malloc(sizeof(*stackEntry));
|
||||||
if (stackEntry == NULL)
|
if (stackEntry == NULL)
|
||||||
fatalerror("No memory for charmap stack");
|
fatalerror("Failed to alloc charmap stack entry: %s\n", strerror(errno));
|
||||||
|
|
||||||
stackEntry->charmap = currentCharmap;
|
stackEntry->charmap = currentCharmap;
|
||||||
stackEntry->next = charmapStack;
|
stackEntry->next = charmapStack;
|
||||||
@@ -121,8 +146,10 @@ void charmap_Push(void)
|
|||||||
|
|
||||||
void charmap_Pop(void)
|
void charmap_Pop(void)
|
||||||
{
|
{
|
||||||
if (charmapStack == NULL)
|
if (charmapStack == NULL) {
|
||||||
fatalerror("No entries in the charmap stack");
|
error("No entries in the charmap stack\n");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
struct CharmapStackEntry *top = charmapStack;
|
struct CharmapStackEntry *top = charmapStack;
|
||||||
|
|
||||||
@@ -131,111 +158,107 @@ void charmap_Pop(void)
|
|||||||
free(top);
|
free(top);
|
||||||
}
|
}
|
||||||
|
|
||||||
void charmap_InitMain(void)
|
void charmap_Add(char *mapping, uint8_t value)
|
||||||
{
|
{
|
||||||
mainCharmap = charmap_New("main", NULL);
|
struct Charmap *charmap = *currentCharmap;
|
||||||
}
|
struct Charnode *node = &charmap->nodes[0];
|
||||||
|
|
||||||
int32_t charmap_Add(char *input, uint8_t output)
|
for (uint8_t c; *mapping; mapping++) {
|
||||||
{
|
c = *mapping - 1;
|
||||||
int32_t i;
|
|
||||||
uint8_t v;
|
|
||||||
|
|
||||||
struct Charmap *charmap = currentCharmap;
|
if (node->next[c]) {
|
||||||
struct Charnode *curr_node, *temp_node;
|
node = &charmap->nodes[node->next[c]];
|
||||||
|
|
||||||
if (charmap->charCount >= MAXCHARMAPS || strlen(input) > CHARMAPLENGTH)
|
|
||||||
return -1;
|
|
||||||
|
|
||||||
curr_node = &charmap->nodes[0];
|
|
||||||
|
|
||||||
for (i = 0; (v = (uint8_t)input[i]); i++) {
|
|
||||||
if (curr_node->next[v]) {
|
|
||||||
curr_node = curr_node->next[v];
|
|
||||||
} else {
|
} else {
|
||||||
temp_node = &charmap->nodes[charmap->nodeCount + 1];
|
/* Register next available node */
|
||||||
|
node->next[c] = charmap->usedNodes;
|
||||||
|
/* If no more nodes are available, get new ones */
|
||||||
|
if (charmap->usedNodes == charmap->capacity) {
|
||||||
|
charmap->capacity *= 2;
|
||||||
|
resizeCharmap(currentCharmap, charmap->capacity);
|
||||||
|
charmap = *currentCharmap;
|
||||||
|
}
|
||||||
|
|
||||||
curr_node->next[v] = temp_node;
|
/* Switch to and init new node */
|
||||||
curr_node = temp_node;
|
node = &charmap->nodes[charmap->usedNodes++];
|
||||||
|
initNode(node);
|
||||||
++charmap->nodeCount;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* prevent duplicated keys by accepting only first key-value pair. */
|
if (node->isTerminal)
|
||||||
if (curr_node->isCode)
|
warning(WARNING_CHARMAP_REDEF, "Overriding charmap mapping\n");
|
||||||
return charmap->charCount;
|
|
||||||
|
|
||||||
curr_node->code = output;
|
node->isTerminal = true;
|
||||||
curr_node->isCode = 1;
|
node->value = value;
|
||||||
|
|
||||||
return ++charmap->charCount;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t charmap_Convert(char **input)
|
size_t charmap_Convert(char const *input, uint8_t *output)
|
||||||
{
|
{
|
||||||
struct Charmap *charmap = currentCharmap;
|
uint8_t *start = output;
|
||||||
struct Charnode *charnode;
|
|
||||||
|
|
||||||
char *output;
|
while (charmap_ConvertNext(&input, &output))
|
||||||
char outchar[8];
|
;
|
||||||
|
|
||||||
int32_t i, match, length;
|
return output - start;
|
||||||
uint8_t v, foundCode;
|
}
|
||||||
|
|
||||||
output = malloc(strlen(*input));
|
size_t charmap_ConvertNext(char const **input, uint8_t **output)
|
||||||
if (output == NULL)
|
{
|
||||||
fatalerror("Not enough memory for buffer");
|
/*
|
||||||
|
* The goal is to match the longest mapping possible.
|
||||||
length = 0;
|
* For that, advance through the trie with each character read.
|
||||||
|
* If that would lead to a dead end, rewind characters until the last match, and output.
|
||||||
while (**input) {
|
* If no match, read a UTF-8 codepoint and output that.
|
||||||
charnode = &charmap->nodes[0];
|
*/
|
||||||
|
struct Charmap const *charmap = *currentCharmap;
|
||||||
/*
|
struct Charnode const *node = &charmap->nodes[0];
|
||||||
* Find the longest valid match which has been registered in
|
struct Charnode const *match = NULL;
|
||||||
* charmap, possibly yielding multiple or no matches.
|
size_t rewindDistance = 0;
|
||||||
* The longest match is taken, meaning partial matches shorter
|
|
||||||
* than the longest one are ignored.
|
for (;;) {
|
||||||
*/
|
uint8_t c = **input - 1;
|
||||||
for (i = match = 0; (v = (*input)[i]);) {
|
|
||||||
if (!charnode->next[v])
|
if (**input && node->next[c]) {
|
||||||
break;
|
// Consume that char
|
||||||
|
(*input)++;
|
||||||
charnode = charnode->next[v];
|
rewindDistance++;
|
||||||
i++;
|
|
||||||
|
// Advance to next node (index starts at 1)
|
||||||
if (charnode->isCode) {
|
node = &charmap->nodes[node->next[c]];
|
||||||
match = i;
|
if (node->isTerminal) {
|
||||||
foundCode = charnode->code;
|
// This node matches, register it
|
||||||
}
|
match = node;
|
||||||
}
|
rewindDistance = 0; // If no longer match is found, rewind here
|
||||||
|
}
|
||||||
if (match) {
|
|
||||||
output[length] = foundCode;
|
} else {
|
||||||
|
// We are at a dead end (either because we reached the end of input, or of
|
||||||
length++;
|
// the trie), so rewind up to the last match, and output.
|
||||||
} else {
|
*input -= rewindDistance; // This will rewind all the way if no match found
|
||||||
/*
|
|
||||||
* put a utf-8 character
|
if (match) { // A match was found, use it
|
||||||
* if failed to find a match.
|
if (output)
|
||||||
*/
|
*(*output)++ = match->value;
|
||||||
match = readUTF8Char(outchar, *input);
|
|
||||||
|
return 1;
|
||||||
if (match) {
|
|
||||||
memcpy(output + length, *input, match);
|
} else if (**input) { // No match found, but there is some input left
|
||||||
} else {
|
// This will write the codepoint's value to `output`, little-endian
|
||||||
output[length] = 0;
|
size_t codepointLen = readUTF8Char(output ? *output : NULL,
|
||||||
match = 1;
|
*input);
|
||||||
}
|
|
||||||
|
if (codepointLen == 0)
|
||||||
length += match;
|
error("Input string is not valid UTF-8!\n");
|
||||||
}
|
|
||||||
|
// OK because UTF-8 has no NUL in multi-byte chars
|
||||||
*input += match;
|
*input += codepointLen;
|
||||||
}
|
if (output)
|
||||||
|
*output += codepointLen;
|
||||||
*input = output;
|
|
||||||
|
return codepointLen;
|
||||||
return length;
|
|
||||||
|
} else { // End of input
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,170 @@
|
|||||||
|
/*
|
||||||
|
* This file is part of RGBDS.
|
||||||
|
*
|
||||||
|
* Copyright (c) 1997-2021, Carsten Sorensen and RGBDS contributors.
|
||||||
|
*
|
||||||
|
* SPDX-License-Identifier: MIT
|
||||||
|
*/
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Fixed-point math routines
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <inttypes.h>
|
||||||
|
#include <math.h>
|
||||||
|
#include <stdint.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
|
||||||
|
#include "asm/fixpoint.h"
|
||||||
|
#include "asm/symbol.h"
|
||||||
|
#include "asm/warning.h"
|
||||||
|
|
||||||
|
#define fix2double(i) ((double)((i) / 65536.0))
|
||||||
|
#define double2fix(d) ((int32_t)round((d) * 65536.0))
|
||||||
|
|
||||||
|
// pi radians == 32768 fixed-point "degrees"
|
||||||
|
#define fdeg2rad(f) ((f) * (M_PI / 32768.0))
|
||||||
|
#define rad2fdeg(r) ((r) * (32768.0 / M_PI))
|
||||||
|
|
||||||
|
#ifndef M_PI
|
||||||
|
#define M_PI 3.14159265358979323846
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Return the _PI symbol value
|
||||||
|
*/
|
||||||
|
int32_t fix_Callback_PI(void)
|
||||||
|
{
|
||||||
|
warning(WARNING_OBSOLETE, "`_PI` is deprecated; use 3.14159\n");
|
||||||
|
|
||||||
|
return double2fix(M_PI);
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Print a fixed point value
|
||||||
|
*/
|
||||||
|
void fix_Print(int32_t i)
|
||||||
|
{
|
||||||
|
uint32_t u = i;
|
||||||
|
char const *sign = "";
|
||||||
|
|
||||||
|
if (i < 0) {
|
||||||
|
u = -u;
|
||||||
|
sign = "-";
|
||||||
|
}
|
||||||
|
|
||||||
|
printf("%s%" PRIu32 ".%05" PRIu32, sign, u >> 16,
|
||||||
|
((uint32_t)(fix2double(u) * 100000 + 0.5)) % 100000);
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Calculate sine
|
||||||
|
*/
|
||||||
|
int32_t fix_Sin(int32_t i)
|
||||||
|
{
|
||||||
|
return double2fix(sin(fdeg2rad(fix2double(i))));
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Calculate cosine
|
||||||
|
*/
|
||||||
|
int32_t fix_Cos(int32_t i)
|
||||||
|
{
|
||||||
|
return double2fix(cos(fdeg2rad(fix2double(i))));
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Calculate tangent
|
||||||
|
*/
|
||||||
|
int32_t fix_Tan(int32_t i)
|
||||||
|
{
|
||||||
|
return double2fix(tan(fdeg2rad(fix2double(i))));
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Calculate arcsine
|
||||||
|
*/
|
||||||
|
int32_t fix_ASin(int32_t i)
|
||||||
|
{
|
||||||
|
return double2fix(rad2fdeg(asin(fix2double(i))));
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Calculate arccosine
|
||||||
|
*/
|
||||||
|
int32_t fix_ACos(int32_t i)
|
||||||
|
{
|
||||||
|
return double2fix(rad2fdeg(acos(fix2double(i))));
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Calculate arctangent
|
||||||
|
*/
|
||||||
|
int32_t fix_ATan(int32_t i)
|
||||||
|
{
|
||||||
|
return double2fix(rad2fdeg(atan(fix2double(i))));
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Calculate atan2
|
||||||
|
*/
|
||||||
|
int32_t fix_ATan2(int32_t i, int32_t j)
|
||||||
|
{
|
||||||
|
return double2fix(rad2fdeg(atan2(fix2double(i), fix2double(j))));
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Multiplication
|
||||||
|
*/
|
||||||
|
int32_t fix_Mul(int32_t i, int32_t j)
|
||||||
|
{
|
||||||
|
return double2fix(fix2double(i) * fix2double(j));
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Division
|
||||||
|
*/
|
||||||
|
int32_t fix_Div(int32_t i, int32_t j)
|
||||||
|
{
|
||||||
|
return double2fix(fix2double(i) / fix2double(j));
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Power
|
||||||
|
*/
|
||||||
|
int32_t fix_Pow(int32_t i, int32_t j)
|
||||||
|
{
|
||||||
|
return double2fix(pow(fix2double(i), fix2double(j)));
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Logarithm
|
||||||
|
*/
|
||||||
|
int32_t fix_Log(int32_t i, int32_t j)
|
||||||
|
{
|
||||||
|
return double2fix(log(fix2double(i)) / log(fix2double(j)));
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Round
|
||||||
|
*/
|
||||||
|
int32_t fix_Round(int32_t i)
|
||||||
|
{
|
||||||
|
return double2fix(round(fix2double(i)));
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Ceil
|
||||||
|
*/
|
||||||
|
int32_t fix_Ceil(int32_t i)
|
||||||
|
{
|
||||||
|
return double2fix(ceil(fix2double(i)));
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Floor
|
||||||
|
*/
|
||||||
|
int32_t fix_Floor(int32_t i)
|
||||||
|
{
|
||||||
|
return double2fix(floor(fix2double(i)));
|
||||||
|
}
|
||||||
@@ -0,0 +1,296 @@
|
|||||||
|
/*
|
||||||
|
* This file is part of RGBDS.
|
||||||
|
*
|
||||||
|
* Copyright (c) 2020, RGBDS contributors.
|
||||||
|
*
|
||||||
|
* SPDX-License-Identifier: MIT
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <assert.h>
|
||||||
|
#include <inttypes.h>
|
||||||
|
#include <math.h>
|
||||||
|
#include <stdbool.h>
|
||||||
|
#include <stdint.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <string.h>
|
||||||
|
|
||||||
|
#include "asm/format.h"
|
||||||
|
#include "asm/warning.h"
|
||||||
|
|
||||||
|
struct FormatSpec fmt_NewSpec(void)
|
||||||
|
{
|
||||||
|
struct FormatSpec fmt = {0};
|
||||||
|
|
||||||
|
return fmt;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool fmt_IsEmpty(struct FormatSpec const *fmt)
|
||||||
|
{
|
||||||
|
return !fmt->state;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool fmt_IsValid(struct FormatSpec const *fmt)
|
||||||
|
{
|
||||||
|
return fmt->valid || fmt->state == FORMAT_DONE;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool fmt_IsFinished(struct FormatSpec const *fmt)
|
||||||
|
{
|
||||||
|
return fmt->state >= FORMAT_DONE;
|
||||||
|
}
|
||||||
|
|
||||||
|
void fmt_UseCharacter(struct FormatSpec *fmt, int c)
|
||||||
|
{
|
||||||
|
if (fmt->state == FORMAT_INVALID)
|
||||||
|
return;
|
||||||
|
|
||||||
|
switch (c) {
|
||||||
|
/* sign */
|
||||||
|
case ' ':
|
||||||
|
case '+':
|
||||||
|
if (fmt->state > FORMAT_SIGN)
|
||||||
|
goto invalid;
|
||||||
|
fmt->state = FORMAT_PREFIX;
|
||||||
|
fmt->sign = c;
|
||||||
|
break;
|
||||||
|
|
||||||
|
/* prefix */
|
||||||
|
case '#':
|
||||||
|
if (fmt->state > FORMAT_PREFIX)
|
||||||
|
goto invalid;
|
||||||
|
fmt->state = FORMAT_ALIGN;
|
||||||
|
fmt->prefix = true;
|
||||||
|
break;
|
||||||
|
|
||||||
|
/* align */
|
||||||
|
case '-':
|
||||||
|
if (fmt->state > FORMAT_ALIGN)
|
||||||
|
goto invalid;
|
||||||
|
fmt->state = FORMAT_WIDTH;
|
||||||
|
fmt->alignLeft = true;
|
||||||
|
break;
|
||||||
|
|
||||||
|
/* pad and width */
|
||||||
|
case '0':
|
||||||
|
if (fmt->state < FORMAT_WIDTH)
|
||||||
|
fmt->padZero = true;
|
||||||
|
/* fallthrough */
|
||||||
|
case '1':
|
||||||
|
case '2':
|
||||||
|
case '3':
|
||||||
|
case '4':
|
||||||
|
case '5':
|
||||||
|
case '6':
|
||||||
|
case '7':
|
||||||
|
case '8':
|
||||||
|
case '9':
|
||||||
|
if (fmt->state < FORMAT_WIDTH) {
|
||||||
|
fmt->state = FORMAT_WIDTH;
|
||||||
|
fmt->width = c - '0';
|
||||||
|
} else if (fmt->state == FORMAT_WIDTH) {
|
||||||
|
fmt->width = fmt->width * 10 + (c - '0');
|
||||||
|
} else if (fmt->state == FORMAT_FRAC) {
|
||||||
|
fmt->fracWidth = fmt->fracWidth * 10 + (c - '0');
|
||||||
|
} else {
|
||||||
|
goto invalid;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
|
case '.':
|
||||||
|
if (fmt->state > FORMAT_WIDTH)
|
||||||
|
goto invalid;
|
||||||
|
fmt->state = FORMAT_FRAC;
|
||||||
|
fmt->hasFrac = true;
|
||||||
|
break;
|
||||||
|
|
||||||
|
/* type */
|
||||||
|
case 'd':
|
||||||
|
case 'u':
|
||||||
|
case 'X':
|
||||||
|
case 'x':
|
||||||
|
case 'b':
|
||||||
|
case 'o':
|
||||||
|
case 'f':
|
||||||
|
case 's':
|
||||||
|
if (fmt->state >= FORMAT_DONE)
|
||||||
|
goto invalid;
|
||||||
|
fmt->state = FORMAT_DONE;
|
||||||
|
fmt->valid = true;
|
||||||
|
fmt->type = c;
|
||||||
|
break;
|
||||||
|
|
||||||
|
default:
|
||||||
|
invalid:
|
||||||
|
fmt->state = FORMAT_INVALID;
|
||||||
|
fmt->valid = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void fmt_FinishCharacters(struct FormatSpec *fmt)
|
||||||
|
{
|
||||||
|
if (!fmt_IsValid(fmt))
|
||||||
|
fmt->state = FORMAT_INVALID;
|
||||||
|
}
|
||||||
|
|
||||||
|
void fmt_PrintString(char *buf, size_t bufLen, struct FormatSpec const *fmt, char const *value)
|
||||||
|
{
|
||||||
|
if (fmt->sign)
|
||||||
|
error("Formatting string with sign flag '%c'\n", fmt->sign);
|
||||||
|
if (fmt->prefix)
|
||||||
|
error("Formatting string with prefix flag '#'\n");
|
||||||
|
if (fmt->padZero)
|
||||||
|
error("Formatting string with padding flag '0'\n");
|
||||||
|
if (fmt->hasFrac)
|
||||||
|
error("Formatting string with fractional width\n");
|
||||||
|
if (fmt->type != 's')
|
||||||
|
error("Formatting string as type '%c'\n", fmt->type);
|
||||||
|
|
||||||
|
size_t len = strlen(value);
|
||||||
|
size_t totalLen = fmt->width > len ? fmt->width : len;
|
||||||
|
|
||||||
|
if (totalLen > bufLen - 1) { /* bufLen includes terminator */
|
||||||
|
error("Formatted string value too long\n");
|
||||||
|
totalLen = bufLen - 1;
|
||||||
|
if (len > totalLen)
|
||||||
|
len = totalLen;
|
||||||
|
}
|
||||||
|
assert(len < bufLen && totalLen < bufLen && len <= totalLen);
|
||||||
|
|
||||||
|
size_t padLen = totalLen - len;
|
||||||
|
|
||||||
|
if (fmt->alignLeft) {
|
||||||
|
memcpy(buf, value, len);
|
||||||
|
for (size_t i = len; i < totalLen; i++)
|
||||||
|
buf[i] = ' ';
|
||||||
|
} else {
|
||||||
|
for (size_t i = 0; i < padLen; i++)
|
||||||
|
buf[i] = ' ';
|
||||||
|
memcpy(buf + padLen, value, len);
|
||||||
|
}
|
||||||
|
|
||||||
|
buf[totalLen] = '\0';
|
||||||
|
}
|
||||||
|
|
||||||
|
void fmt_PrintNumber(char *buf, size_t bufLen, struct FormatSpec const *fmt, uint32_t value)
|
||||||
|
{
|
||||||
|
if (fmt->type != 'X' && fmt->type != 'x' && fmt->type != 'b' && fmt->type != 'o'
|
||||||
|
&& fmt->prefix)
|
||||||
|
error("Formatting type '%c' with prefix flag '#'\n", fmt->type);
|
||||||
|
if (fmt->type != 'f' && fmt->hasFrac)
|
||||||
|
error("Formatting type '%c' with fractional width\n", fmt->type);
|
||||||
|
if (fmt->type == 's')
|
||||||
|
error("Formatting number as type 's'\n");
|
||||||
|
|
||||||
|
char sign = fmt->sign; /* 0 or ' ' or '+' */
|
||||||
|
|
||||||
|
if (fmt->type == 'd' || fmt->type == 'f') {
|
||||||
|
int32_t v = value;
|
||||||
|
|
||||||
|
if (v < 0 && v != INT32_MIN) {
|
||||||
|
sign = '-';
|
||||||
|
value = -v;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
char prefix = !fmt->prefix ? 0
|
||||||
|
: fmt->type == 'X' ? '$'
|
||||||
|
: fmt->type == 'x' ? '$'
|
||||||
|
: fmt->type == 'b' ? '%'
|
||||||
|
: fmt->type == 'o' ? '&'
|
||||||
|
: 0;
|
||||||
|
|
||||||
|
char valueBuf[262]; /* Max 5 digits + decimal + 255 fraction digits + terminator */
|
||||||
|
|
||||||
|
if (fmt->type == 'b') {
|
||||||
|
/* Special case for binary */
|
||||||
|
char *ptr = valueBuf;
|
||||||
|
|
||||||
|
do {
|
||||||
|
*ptr++ = (value & 1) + '0';
|
||||||
|
value >>= 1;
|
||||||
|
} while (value);
|
||||||
|
|
||||||
|
*ptr = '\0';
|
||||||
|
|
||||||
|
/* Reverse the digits */
|
||||||
|
size_t valueLen = ptr - valueBuf;
|
||||||
|
|
||||||
|
for (size_t i = 0, j = valueLen - 1; i < j; i++, j--) {
|
||||||
|
char c = valueBuf[i];
|
||||||
|
|
||||||
|
valueBuf[i] = valueBuf[j];
|
||||||
|
valueBuf[j] = c;
|
||||||
|
}
|
||||||
|
} else if (fmt->type == 'f') {
|
||||||
|
/* Special case for fixed-point */
|
||||||
|
|
||||||
|
/* Default fractional width (C's is 6 for "%f"; here 5 is enough) */
|
||||||
|
size_t fracWidth = fmt->hasFrac ? fmt->fracWidth : 5;
|
||||||
|
|
||||||
|
if (fracWidth > 255) {
|
||||||
|
error("Fractional width %zu too long, limiting to 255\n",
|
||||||
|
fracWidth);
|
||||||
|
fracWidth = 255;
|
||||||
|
}
|
||||||
|
|
||||||
|
snprintf(valueBuf, sizeof(valueBuf), "%.*f", (int)fracWidth, value / 65536.0);
|
||||||
|
} else {
|
||||||
|
char const *spec = fmt->type == 'd' ? "%" PRId32
|
||||||
|
: fmt->type == 'u' ? "%" PRIu32
|
||||||
|
: fmt->type == 'X' ? "%" PRIX32
|
||||||
|
: fmt->type == 'x' ? "%" PRIx32
|
||||||
|
: fmt->type == 'o' ? "%" PRIo32
|
||||||
|
: "%" PRId32;
|
||||||
|
|
||||||
|
snprintf(valueBuf, sizeof(valueBuf), spec, value);
|
||||||
|
}
|
||||||
|
|
||||||
|
size_t len = strlen(valueBuf);
|
||||||
|
size_t numLen = !!sign + !!prefix + len;
|
||||||
|
size_t totalLen = fmt->width > numLen ? fmt->width : numLen;
|
||||||
|
|
||||||
|
if (totalLen > bufLen - 1) { /* bufLen includes terminator */
|
||||||
|
error("Formatted numeric value too long\n");
|
||||||
|
totalLen = bufLen - 1;
|
||||||
|
if (numLen > totalLen) {
|
||||||
|
len -= numLen - totalLen;
|
||||||
|
numLen = totalLen;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
assert(numLen < bufLen && totalLen < bufLen && numLen <= totalLen && len <= numLen);
|
||||||
|
|
||||||
|
size_t padLen = totalLen - numLen;
|
||||||
|
size_t pos = 0;
|
||||||
|
|
||||||
|
if (fmt->alignLeft) {
|
||||||
|
if (sign)
|
||||||
|
buf[pos++] = sign;
|
||||||
|
if (prefix)
|
||||||
|
buf[pos++] = prefix;
|
||||||
|
memcpy(buf + pos, valueBuf, len);
|
||||||
|
for (size_t i = pos + len; i < totalLen; i++)
|
||||||
|
buf[i] = ' ';
|
||||||
|
} else {
|
||||||
|
if (fmt->padZero) {
|
||||||
|
/* sign, then prefix, then zero padding */
|
||||||
|
if (sign)
|
||||||
|
buf[pos++] = sign;
|
||||||
|
if (prefix)
|
||||||
|
buf[pos++] = prefix;
|
||||||
|
for (size_t i = 0; i < padLen; i++)
|
||||||
|
buf[pos++] = '0';
|
||||||
|
} else {
|
||||||
|
/* space padding, then sign, then prefix */
|
||||||
|
for (size_t i = 0; i < padLen; i++)
|
||||||
|
buf[pos++] = ' ';
|
||||||
|
if (sign)
|
||||||
|
buf[pos++] = sign;
|
||||||
|
if (prefix)
|
||||||
|
buf[pos++] = prefix;
|
||||||
|
}
|
||||||
|
memcpy(buf + pos, valueBuf, len);
|
||||||
|
}
|
||||||
|
|
||||||
|
buf[totalLen] = '\0';
|
||||||
|
}
|
||||||
+469
-444
File diff suppressed because it is too large
Load Diff
@@ -1,704 +0,0 @@
|
|||||||
/*
|
|
||||||
* This file is part of RGBDS.
|
|
||||||
*
|
|
||||||
* Copyright (c) 1997-2018, Carsten Sorensen and RGBDS contributors.
|
|
||||||
*
|
|
||||||
* SPDX-License-Identifier: MIT
|
|
||||||
*/
|
|
||||||
|
|
||||||
#include <math.h>
|
|
||||||
#include <stdbool.h>
|
|
||||||
#include <stdint.h>
|
|
||||||
#include <stdio.h>
|
|
||||||
#include <stdlib.h>
|
|
||||||
#include <string.h>
|
|
||||||
|
|
||||||
#include "asm/asm.h"
|
|
||||||
#include "asm/lexer.h"
|
|
||||||
#include "asm/macro.h"
|
|
||||||
#include "asm/main.h"
|
|
||||||
#include "asm/rpn.h"
|
|
||||||
#include "asm/section.h"
|
|
||||||
#include "asm/warning.h"
|
|
||||||
|
|
||||||
#include "helpers.h"
|
|
||||||
|
|
||||||
#include "asmy.h"
|
|
||||||
|
|
||||||
bool oDontExpandStrings;
|
|
||||||
int32_t nGBGfxID = -1;
|
|
||||||
int32_t nBinaryID = -1;
|
|
||||||
|
|
||||||
static int32_t gbgfx2bin(char ch)
|
|
||||||
{
|
|
||||||
int32_t i;
|
|
||||||
|
|
||||||
for (i = 0; i <= 3; i++) {
|
|
||||||
if (CurrentOptions.gbgfx[i] == ch)
|
|
||||||
return i;
|
|
||||||
}
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
static int32_t binary2bin(char ch)
|
|
||||||
{
|
|
||||||
int32_t i;
|
|
||||||
|
|
||||||
for (i = 0; i <= 1; i++) {
|
|
||||||
if (CurrentOptions.binary[i] == ch)
|
|
||||||
return i;
|
|
||||||
}
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
static int32_t char2bin(char ch)
|
|
||||||
{
|
|
||||||
if (ch >= 'a' && ch <= 'f')
|
|
||||||
return (ch - 'a' + 10);
|
|
||||||
|
|
||||||
if (ch >= 'A' && ch <= 'F')
|
|
||||||
return (ch - 'A' + 10);
|
|
||||||
|
|
||||||
if (ch >= '0' && ch <= '9')
|
|
||||||
return (ch - '0');
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
typedef int32_t(*x2bin) (char ch);
|
|
||||||
|
|
||||||
static int32_t ascii2bin(char *s)
|
|
||||||
{
|
|
||||||
char *start = s;
|
|
||||||
uint32_t radix = 10;
|
|
||||||
uint32_t result = 0;
|
|
||||||
x2bin convertfunc = char2bin;
|
|
||||||
|
|
||||||
switch (*s) {
|
|
||||||
case '$':
|
|
||||||
radix = 16;
|
|
||||||
s++;
|
|
||||||
convertfunc = char2bin;
|
|
||||||
break;
|
|
||||||
case '&':
|
|
||||||
radix = 8;
|
|
||||||
s++;
|
|
||||||
convertfunc = char2bin;
|
|
||||||
break;
|
|
||||||
case '`':
|
|
||||||
radix = 4;
|
|
||||||
s++;
|
|
||||||
convertfunc = gbgfx2bin;
|
|
||||||
break;
|
|
||||||
case '%':
|
|
||||||
radix = 2;
|
|
||||||
s++;
|
|
||||||
convertfunc = binary2bin;
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
/* Handle below */
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
const uint32_t max_q = UINT32_MAX / radix;
|
|
||||||
const uint32_t max_r = UINT32_MAX % radix;
|
|
||||||
|
|
||||||
if (*s == '\0') {
|
|
||||||
/*
|
|
||||||
* There are no digits after the radix prefix
|
|
||||||
* (or the string is empty, which shouldn't happen).
|
|
||||||
*/
|
|
||||||
yyerror("Invalid integer constant");
|
|
||||||
} else if (radix == 4) {
|
|
||||||
int32_t size = 0;
|
|
||||||
int32_t c;
|
|
||||||
|
|
||||||
while (*s != '\0') {
|
|
||||||
c = convertfunc(*s++);
|
|
||||||
result = result * 2 + ((c & 2) << 7) + (c & 1);
|
|
||||||
size++;
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Extending a graphics constant longer than 8 pixels,
|
|
||||||
* the Game Boy tile width, produces a nonsensical result.
|
|
||||||
*/
|
|
||||||
if (size > 8) {
|
|
||||||
warning(WARNING_LARGE_CONSTANT, "Graphics constant '%s' is too long",
|
|
||||||
start);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
bool overflow = false;
|
|
||||||
|
|
||||||
while (*s != '\0') {
|
|
||||||
int32_t digit = convertfunc(*s++);
|
|
||||||
|
|
||||||
if (result > max_q
|
|
||||||
|| (result == max_q && digit > max_r)) {
|
|
||||||
overflow = true;
|
|
||||||
}
|
|
||||||
result = result * radix + digit;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (overflow)
|
|
||||||
warning(WARNING_LARGE_CONSTANT, "Integer constant '%s' is too large",
|
|
||||||
start);
|
|
||||||
}
|
|
||||||
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
uint32_t ParseFixedPoint(char *s, uint32_t size)
|
|
||||||
{
|
|
||||||
uint32_t i;
|
|
||||||
uint32_t dot = 0;
|
|
||||||
|
|
||||||
for (i = 0; i < size; i++) {
|
|
||||||
if (s[i] == '.') {
|
|
||||||
dot++;
|
|
||||||
|
|
||||||
if (dot == 2)
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
yyskipbytes(i);
|
|
||||||
|
|
||||||
yylval.nConstValue = (int32_t)(atof(s) * 65536);
|
|
||||||
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
uint32_t ParseNumber(char *s, uint32_t size)
|
|
||||||
{
|
|
||||||
char dest[256];
|
|
||||||
|
|
||||||
if (size > 255)
|
|
||||||
fatalerror("Number token too long");
|
|
||||||
|
|
||||||
strncpy(dest, s, size);
|
|
||||||
dest[size] = 0;
|
|
||||||
yylval.nConstValue = ascii2bin(dest);
|
|
||||||
|
|
||||||
yyskipbytes(size);
|
|
||||||
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
* If the symbol name ends before the end of the macro arg,
|
|
||||||
* return a pointer to the rest of the macro arg.
|
|
||||||
* Otherwise, return NULL.
|
|
||||||
*/
|
|
||||||
char const *AppendMacroArg(char whichArg, char *dest, size_t *destIndex)
|
|
||||||
{
|
|
||||||
char const *marg;
|
|
||||||
|
|
||||||
if (whichArg == '@')
|
|
||||||
marg = macro_GetUniqueIDStr();
|
|
||||||
else if (whichArg >= '1' && whichArg <= '9')
|
|
||||||
marg = macro_GetArg(whichArg - '0');
|
|
||||||
else
|
|
||||||
fatalerror("Invalid macro argument '\\%c' in symbol", whichArg);
|
|
||||||
|
|
||||||
if (!marg)
|
|
||||||
fatalerror("Macro argument '\\%c' not defined", whichArg);
|
|
||||||
|
|
||||||
char ch;
|
|
||||||
|
|
||||||
while ((ch = *marg) != 0) {
|
|
||||||
if ((ch >= 'a' && ch <= 'z')
|
|
||||||
|| (ch >= 'A' && ch <= 'Z')
|
|
||||||
|| (ch >= '0' && ch <= '9')
|
|
||||||
|| ch == '_'
|
|
||||||
|| ch == '@'
|
|
||||||
|| ch == '#'
|
|
||||||
|| ch == '.') {
|
|
||||||
if (*destIndex >= MAXSYMLEN)
|
|
||||||
fatalerror("Symbol too long");
|
|
||||||
|
|
||||||
dest[*destIndex] = ch;
|
|
||||||
(*destIndex)++;
|
|
||||||
} else {
|
|
||||||
return marg;
|
|
||||||
}
|
|
||||||
|
|
||||||
marg++;
|
|
||||||
}
|
|
||||||
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
uint32_t ParseSymbol(char *src, uint32_t size)
|
|
||||||
{
|
|
||||||
char dest[MAXSYMLEN + 1];
|
|
||||||
size_t srcIndex = 0;
|
|
||||||
size_t destIndex = 0;
|
|
||||||
char const *rest = NULL;
|
|
||||||
|
|
||||||
while (srcIndex < size) {
|
|
||||||
char ch = src[srcIndex++];
|
|
||||||
|
|
||||||
if (ch == '\\') {
|
|
||||||
/*
|
|
||||||
* We don't check if srcIndex is still less than size,
|
|
||||||
* but that can only fail to be true when the
|
|
||||||
* following char is neither '@' nor a digit.
|
|
||||||
* In that case, AppendMacroArg() will catch the error.
|
|
||||||
*/
|
|
||||||
ch = src[srcIndex++];
|
|
||||||
|
|
||||||
rest = AppendMacroArg(ch, dest, &destIndex);
|
|
||||||
/* If the symbol's end was in the middle of the token */
|
|
||||||
if (rest)
|
|
||||||
break;
|
|
||||||
} else {
|
|
||||||
if (destIndex >= MAXSYMLEN)
|
|
||||||
fatalerror("Symbol too long");
|
|
||||||
dest[destIndex++] = ch;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
dest[destIndex] = 0;
|
|
||||||
|
|
||||||
/* Tell the lexer we read all bytes that we did */
|
|
||||||
yyskipbytes(srcIndex);
|
|
||||||
|
|
||||||
/*
|
|
||||||
* If an escape's expansion left some chars after the symbol's end,
|
|
||||||
* such as the `::` in a `Backup\1` expanded to `BackupCamX::`,
|
|
||||||
* put those into the buffer.
|
|
||||||
* Note that this NEEDS to be done after the `yyskipbytes` above.
|
|
||||||
*/
|
|
||||||
if (rest)
|
|
||||||
yyunputstr(rest);
|
|
||||||
|
|
||||||
/* If the symbol is an EQUS, expand it */
|
|
||||||
if (!oDontExpandStrings) {
|
|
||||||
struct Symbol const *sym = sym_FindSymbol(dest);
|
|
||||||
|
|
||||||
if (sym && sym->type == SYM_EQUS) {
|
|
||||||
char const *s;
|
|
||||||
|
|
||||||
lex_BeginStringExpansion(dest);
|
|
||||||
|
|
||||||
/* Feed the symbol's contents into the buffer */
|
|
||||||
yyunputstr(s = sym_GetStringValue(sym));
|
|
||||||
|
|
||||||
/* Lines inserted this way shall not increase nLineNo */
|
|
||||||
while (*s) {
|
|
||||||
if (*s++ == '\n')
|
|
||||||
nLineNo--;
|
|
||||||
}
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
strcpy(yylval.tzSym, dest);
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
uint32_t PutMacroArg(char *src, uint32_t size)
|
|
||||||
{
|
|
||||||
char const *s;
|
|
||||||
|
|
||||||
yyskipbytes(size);
|
|
||||||
if ((size == 2 && src[1] >= '1' && src[1] <= '9')) {
|
|
||||||
s = macro_GetArg(src[1] - '0');
|
|
||||||
|
|
||||||
if (s != NULL)
|
|
||||||
yyunputstr(s);
|
|
||||||
else
|
|
||||||
yyerror("Macro argument '\\%c' not defined", src[1]);
|
|
||||||
} else {
|
|
||||||
yyerror("Invalid macro argument '\\%c'", src[1]);
|
|
||||||
}
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
uint32_t PutUniqueID(char *src, uint32_t size)
|
|
||||||
{
|
|
||||||
(void)src;
|
|
||||||
char const *s;
|
|
||||||
|
|
||||||
yyskipbytes(size);
|
|
||||||
|
|
||||||
s = macro_GetUniqueIDStr();
|
|
||||||
|
|
||||||
if (s != NULL)
|
|
||||||
yyunputstr(s);
|
|
||||||
else
|
|
||||||
yyerror("Macro unique label string not defined");
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
enum {
|
|
||||||
T_LEX_MACROARG = 3000,
|
|
||||||
T_LEX_MACROUNIQUE
|
|
||||||
};
|
|
||||||
|
|
||||||
const struct sLexInitString lexer_strings[] = {
|
|
||||||
{"adc", T_Z80_ADC},
|
|
||||||
{"add", T_Z80_ADD},
|
|
||||||
{"and", T_Z80_AND},
|
|
||||||
{"bit", T_Z80_BIT},
|
|
||||||
{"call", T_Z80_CALL},
|
|
||||||
{"ccf", T_Z80_CCF},
|
|
||||||
{"cpl", T_Z80_CPL},
|
|
||||||
{"cp", T_Z80_CP},
|
|
||||||
{"daa", T_Z80_DAA},
|
|
||||||
{"dec", T_Z80_DEC},
|
|
||||||
{"di", T_Z80_DI},
|
|
||||||
{"ei", T_Z80_EI},
|
|
||||||
{"halt", T_Z80_HALT},
|
|
||||||
{"inc", T_Z80_INC},
|
|
||||||
{"jp", T_Z80_JP},
|
|
||||||
{"jr", T_Z80_JR},
|
|
||||||
{"ld", T_Z80_LD},
|
|
||||||
{"ldi", T_Z80_LDI},
|
|
||||||
{"ldd", T_Z80_LDD},
|
|
||||||
{"ldio", T_Z80_LDIO},
|
|
||||||
{"ldh", T_Z80_LDIO},
|
|
||||||
{"nop", T_Z80_NOP},
|
|
||||||
{"or", T_Z80_OR},
|
|
||||||
{"pop", T_Z80_POP},
|
|
||||||
{"push", T_Z80_PUSH},
|
|
||||||
{"res", T_Z80_RES},
|
|
||||||
{"reti", T_Z80_RETI},
|
|
||||||
{"ret", T_Z80_RET},
|
|
||||||
{"rlca", T_Z80_RLCA},
|
|
||||||
{"rlc", T_Z80_RLC},
|
|
||||||
{"rla", T_Z80_RLA},
|
|
||||||
{"rl", T_Z80_RL},
|
|
||||||
{"rrc", T_Z80_RRC},
|
|
||||||
{"rrca", T_Z80_RRCA},
|
|
||||||
{"rra", T_Z80_RRA},
|
|
||||||
{"rr", T_Z80_RR},
|
|
||||||
{"rst", T_Z80_RST},
|
|
||||||
{"sbc", T_Z80_SBC},
|
|
||||||
{"scf", T_Z80_SCF},
|
|
||||||
{"set", T_POP_SET},
|
|
||||||
{"sla", T_Z80_SLA},
|
|
||||||
{"sra", T_Z80_SRA},
|
|
||||||
{"srl", T_Z80_SRL},
|
|
||||||
{"stop", T_Z80_STOP},
|
|
||||||
{"sub", T_Z80_SUB},
|
|
||||||
{"swap", T_Z80_SWAP},
|
|
||||||
{"xor", T_Z80_XOR},
|
|
||||||
|
|
||||||
{"nz", T_CC_NZ},
|
|
||||||
{"z", T_CC_Z},
|
|
||||||
{"nc", T_CC_NC},
|
|
||||||
/* Handled in list of registers */
|
|
||||||
/* { "c", T_TOKEN_C }, */
|
|
||||||
|
|
||||||
{"[bc]", T_MODE_BC_IND},
|
|
||||||
{"[de]", T_MODE_DE_IND},
|
|
||||||
{"[hl]", T_MODE_HL_IND},
|
|
||||||
{"[hl+]", T_MODE_HL_INDINC},
|
|
||||||
{"[hl-]", T_MODE_HL_INDDEC},
|
|
||||||
{"[hli]", T_MODE_HL_INDINC},
|
|
||||||
{"[hld]", T_MODE_HL_INDDEC},
|
|
||||||
{"af", T_MODE_AF},
|
|
||||||
{"bc", T_MODE_BC},
|
|
||||||
{"de", T_MODE_DE},
|
|
||||||
{"hl", T_MODE_HL},
|
|
||||||
{"sp", T_MODE_SP},
|
|
||||||
{"[c]", T_MODE_C_IND},
|
|
||||||
{"[$ff00+c]", T_MODE_C_IND},
|
|
||||||
{"[$ff00 + c]", T_MODE_C_IND},
|
|
||||||
|
|
||||||
{"a", T_TOKEN_A},
|
|
||||||
{"b", T_TOKEN_B},
|
|
||||||
{"c", T_TOKEN_C},
|
|
||||||
{"d", T_TOKEN_D},
|
|
||||||
{"e", T_TOKEN_E},
|
|
||||||
{"h", T_TOKEN_H},
|
|
||||||
{"l", T_TOKEN_L},
|
|
||||||
|
|
||||||
{"||", T_OP_LOGICOR},
|
|
||||||
{"&&", T_OP_LOGICAND},
|
|
||||||
{"==", T_OP_LOGICEQU},
|
|
||||||
{">", T_OP_LOGICGT},
|
|
||||||
{"<", T_OP_LOGICLT},
|
|
||||||
{">=", T_OP_LOGICGE},
|
|
||||||
{"<=", T_OP_LOGICLE},
|
|
||||||
{"!=", T_OP_LOGICNE},
|
|
||||||
{"!", T_OP_LOGICNOT},
|
|
||||||
{"|", T_OP_OR},
|
|
||||||
{"^", T_OP_XOR},
|
|
||||||
{"&", T_OP_AND},
|
|
||||||
{"<<", T_OP_SHL},
|
|
||||||
{">>", T_OP_SHR},
|
|
||||||
{"+", T_OP_ADD},
|
|
||||||
{"-", T_OP_SUB},
|
|
||||||
{"*", T_OP_MUL},
|
|
||||||
{"/", T_OP_DIV},
|
|
||||||
{"%", T_OP_MOD},
|
|
||||||
{"~", T_OP_NOT},
|
|
||||||
|
|
||||||
{"def", T_OP_DEF},
|
|
||||||
|
|
||||||
{"fragment", T_POP_FRAGMENT},
|
|
||||||
{"bank", T_OP_BANK},
|
|
||||||
{"align", T_OP_ALIGN},
|
|
||||||
|
|
||||||
{"round", T_OP_ROUND},
|
|
||||||
{"ceil", T_OP_CEIL},
|
|
||||||
{"floor", T_OP_FLOOR},
|
|
||||||
{"div", T_OP_FDIV},
|
|
||||||
{"mul", T_OP_FMUL},
|
|
||||||
{"sin", T_OP_SIN},
|
|
||||||
{"cos", T_OP_COS},
|
|
||||||
{"tan", T_OP_TAN},
|
|
||||||
{"asin", T_OP_ASIN},
|
|
||||||
{"acos", T_OP_ACOS},
|
|
||||||
{"atan", T_OP_ATAN},
|
|
||||||
{"atan2", T_OP_ATAN2},
|
|
||||||
|
|
||||||
{"high", T_OP_HIGH},
|
|
||||||
{"low", T_OP_LOW},
|
|
||||||
{"isconst", T_OP_ISCONST},
|
|
||||||
|
|
||||||
{"strcmp", T_OP_STRCMP},
|
|
||||||
{"strin", T_OP_STRIN},
|
|
||||||
{"strsub", T_OP_STRSUB},
|
|
||||||
{"strlen", T_OP_STRLEN},
|
|
||||||
{"strcat", T_OP_STRCAT},
|
|
||||||
{"strupr", T_OP_STRUPR},
|
|
||||||
{"strlwr", T_OP_STRLWR},
|
|
||||||
|
|
||||||
{"include", T_POP_INCLUDE},
|
|
||||||
{"printt", T_POP_PRINTT},
|
|
||||||
{"printi", T_POP_PRINTI},
|
|
||||||
{"printv", T_POP_PRINTV},
|
|
||||||
{"printf", T_POP_PRINTF},
|
|
||||||
{"export", T_POP_EXPORT},
|
|
||||||
{"xdef", T_POP_XDEF},
|
|
||||||
{"global", T_POP_GLOBAL},
|
|
||||||
{"ds", T_POP_DS},
|
|
||||||
{"db", T_POP_DB},
|
|
||||||
{"dw", T_POP_DW},
|
|
||||||
{"dl", T_POP_DL},
|
|
||||||
{"section", T_POP_SECTION},
|
|
||||||
{"purge", T_POP_PURGE},
|
|
||||||
|
|
||||||
{"rsreset", T_POP_RSRESET},
|
|
||||||
{"rsset", T_POP_RSSET},
|
|
||||||
|
|
||||||
{"incbin", T_POP_INCBIN},
|
|
||||||
{"charmap", T_POP_CHARMAP},
|
|
||||||
{"newcharmap", T_POP_NEWCHARMAP},
|
|
||||||
{"setcharmap", T_POP_SETCHARMAP},
|
|
||||||
{"pushc", T_POP_PUSHC},
|
|
||||||
{"popc", T_POP_POPC},
|
|
||||||
|
|
||||||
{"fail", T_POP_FAIL},
|
|
||||||
{"warn", T_POP_WARN},
|
|
||||||
{"fatal", T_POP_FATAL},
|
|
||||||
{"assert", T_POP_ASSERT},
|
|
||||||
{"static_assert", T_POP_STATIC_ASSERT},
|
|
||||||
|
|
||||||
{"macro", T_POP_MACRO},
|
|
||||||
/* Not needed but we have it here just to protect the name */
|
|
||||||
{"endm", T_POP_ENDM},
|
|
||||||
{"shift", T_POP_SHIFT},
|
|
||||||
|
|
||||||
{"rept", T_POP_REPT},
|
|
||||||
/* Not needed but we have it here just to protect the name */
|
|
||||||
{"endr", T_POP_ENDR},
|
|
||||||
|
|
||||||
{"load", T_POP_LOAD},
|
|
||||||
{"endl", T_POP_ENDL},
|
|
||||||
|
|
||||||
{"if", T_POP_IF},
|
|
||||||
{"else", T_POP_ELSE},
|
|
||||||
{"elif", T_POP_ELIF},
|
|
||||||
{"endc", T_POP_ENDC},
|
|
||||||
|
|
||||||
{"union", T_POP_UNION},
|
|
||||||
{"nextu", T_POP_NEXTU},
|
|
||||||
{"endu", T_POP_ENDU},
|
|
||||||
|
|
||||||
{"wram0", T_SECT_WRAM0},
|
|
||||||
{"vram", T_SECT_VRAM},
|
|
||||||
{"romx", T_SECT_ROMX},
|
|
||||||
{"rom0", T_SECT_ROM0},
|
|
||||||
{"hram", T_SECT_HRAM},
|
|
||||||
{"wramx", T_SECT_WRAMX},
|
|
||||||
{"sram", T_SECT_SRAM},
|
|
||||||
{"oam", T_SECT_OAM},
|
|
||||||
|
|
||||||
{"rb", T_POP_RB},
|
|
||||||
{"rw", T_POP_RW},
|
|
||||||
{"equ", T_POP_EQU},
|
|
||||||
{"equs", T_POP_EQUS},
|
|
||||||
|
|
||||||
/* Handled before in list of CPU instructions */
|
|
||||||
/* {"set", T_POP_SET}, */
|
|
||||||
{"=", T_POP_EQUAL},
|
|
||||||
|
|
||||||
{"pushs", T_POP_PUSHS},
|
|
||||||
{"pops", T_POP_POPS},
|
|
||||||
{"pusho", T_POP_PUSHO},
|
|
||||||
{"popo", T_POP_POPO},
|
|
||||||
|
|
||||||
{"opt", T_POP_OPT},
|
|
||||||
|
|
||||||
{NULL, 0}
|
|
||||||
};
|
|
||||||
|
|
||||||
const struct sLexFloat tNumberToken = {
|
|
||||||
ParseNumber,
|
|
||||||
T_NUMBER
|
|
||||||
};
|
|
||||||
|
|
||||||
const struct sLexFloat tFixedPointToken = {
|
|
||||||
ParseFixedPoint,
|
|
||||||
T_NUMBER
|
|
||||||
};
|
|
||||||
|
|
||||||
const struct sLexFloat tIDToken = {
|
|
||||||
ParseSymbol,
|
|
||||||
T_ID
|
|
||||||
};
|
|
||||||
|
|
||||||
const struct sLexFloat tMacroArgToken = {
|
|
||||||
PutMacroArg,
|
|
||||||
T_LEX_MACROARG
|
|
||||||
};
|
|
||||||
|
|
||||||
const struct sLexFloat tMacroUniqueToken = {
|
|
||||||
PutUniqueID,
|
|
||||||
T_LEX_MACROUNIQUE
|
|
||||||
};
|
|
||||||
|
|
||||||
void setup_lexer(void)
|
|
||||||
{
|
|
||||||
uint32_t id;
|
|
||||||
|
|
||||||
lex_Init();
|
|
||||||
lex_AddStrings(lexer_strings);
|
|
||||||
|
|
||||||
//Macro arguments
|
|
||||||
|
|
||||||
id = lex_FloatAlloc(&tMacroArgToken);
|
|
||||||
lex_FloatAddFirstRange(id, '\\', '\\');
|
|
||||||
lex_FloatAddSecondRange(id, '1', '9');
|
|
||||||
id = lex_FloatAlloc(&tMacroUniqueToken);
|
|
||||||
lex_FloatAddFirstRange(id, '\\', '\\');
|
|
||||||
lex_FloatAddSecondRange(id, '@', '@');
|
|
||||||
|
|
||||||
//Decimal constants
|
|
||||||
|
|
||||||
id = lex_FloatAlloc(&tNumberToken);
|
|
||||||
lex_FloatAddFirstRange(id, '0', '9');
|
|
||||||
lex_FloatAddSecondRange(id, '0', '9');
|
|
||||||
lex_FloatAddRange(id, '0', '9');
|
|
||||||
|
|
||||||
//Binary constants
|
|
||||||
|
|
||||||
id = lex_FloatAlloc(&tNumberToken);
|
|
||||||
nBinaryID = id;
|
|
||||||
lex_FloatAddFirstRange(id, '%', '%');
|
|
||||||
lex_FloatAddSecondRange(id, CurrentOptions.binary[0],
|
|
||||||
CurrentOptions.binary[0]);
|
|
||||||
lex_FloatAddSecondRange(id, CurrentOptions.binary[1],
|
|
||||||
CurrentOptions.binary[1]);
|
|
||||||
lex_FloatAddRange(id, CurrentOptions.binary[0],
|
|
||||||
CurrentOptions.binary[0]);
|
|
||||||
lex_FloatAddRange(id, CurrentOptions.binary[1],
|
|
||||||
CurrentOptions.binary[1]);
|
|
||||||
|
|
||||||
//Octal constants
|
|
||||||
|
|
||||||
id = lex_FloatAlloc(&tNumberToken);
|
|
||||||
lex_FloatAddFirstRange(id, '&', '&');
|
|
||||||
lex_FloatAddSecondRange(id, '0', '7');
|
|
||||||
lex_FloatAddRange(id, '0', '7');
|
|
||||||
|
|
||||||
//Gameboy gfx constants
|
|
||||||
|
|
||||||
id = lex_FloatAlloc(&tNumberToken);
|
|
||||||
nGBGfxID = id;
|
|
||||||
lex_FloatAddFirstRange(id, '`', '`');
|
|
||||||
lex_FloatAddSecondRange(id, CurrentOptions.gbgfx[0],
|
|
||||||
CurrentOptions.gbgfx[0]);
|
|
||||||
lex_FloatAddSecondRange(id, CurrentOptions.gbgfx[1],
|
|
||||||
CurrentOptions.gbgfx[1]);
|
|
||||||
lex_FloatAddSecondRange(id, CurrentOptions.gbgfx[2],
|
|
||||||
CurrentOptions.gbgfx[2]);
|
|
||||||
lex_FloatAddSecondRange(id, CurrentOptions.gbgfx[3],
|
|
||||||
CurrentOptions.gbgfx[3]);
|
|
||||||
lex_FloatAddRange(id, CurrentOptions.gbgfx[0], CurrentOptions.gbgfx[0]);
|
|
||||||
lex_FloatAddRange(id, CurrentOptions.gbgfx[1], CurrentOptions.gbgfx[1]);
|
|
||||||
lex_FloatAddRange(id, CurrentOptions.gbgfx[2], CurrentOptions.gbgfx[2]);
|
|
||||||
lex_FloatAddRange(id, CurrentOptions.gbgfx[3], CurrentOptions.gbgfx[3]);
|
|
||||||
|
|
||||||
//Hex constants
|
|
||||||
|
|
||||||
id = lex_FloatAlloc(&tNumberToken);
|
|
||||||
lex_FloatAddFirstRange(id, '$', '$');
|
|
||||||
lex_FloatAddSecondRange(id, '0', '9');
|
|
||||||
lex_FloatAddSecondRange(id, 'A', 'F');
|
|
||||||
lex_FloatAddSecondRange(id, 'a', 'f');
|
|
||||||
lex_FloatAddRange(id, '0', '9');
|
|
||||||
lex_FloatAddRange(id, 'A', 'F');
|
|
||||||
lex_FloatAddRange(id, 'a', 'f');
|
|
||||||
|
|
||||||
//ID 's
|
|
||||||
|
|
||||||
id = lex_FloatAlloc(&tIDToken);
|
|
||||||
lex_FloatAddFirstRange(id, 'a', 'z');
|
|
||||||
lex_FloatAddFirstRange(id, 'A', 'Z');
|
|
||||||
lex_FloatAddFirstRange(id, '_', '_');
|
|
||||||
lex_FloatAddSecondRange(id, '.', '.');
|
|
||||||
lex_FloatAddSecondRange(id, 'a', 'z');
|
|
||||||
lex_FloatAddSecondRange(id, 'A', 'Z');
|
|
||||||
lex_FloatAddSecondRange(id, '0', '9');
|
|
||||||
lex_FloatAddSecondRange(id, '_', '_');
|
|
||||||
lex_FloatAddSecondRange(id, '\\', '\\');
|
|
||||||
lex_FloatAddSecondRange(id, '@', '@');
|
|
||||||
lex_FloatAddSecondRange(id, '#', '#');
|
|
||||||
lex_FloatAddRange(id, '.', '.');
|
|
||||||
lex_FloatAddRange(id, 'a', 'z');
|
|
||||||
lex_FloatAddRange(id, 'A', 'Z');
|
|
||||||
lex_FloatAddRange(id, '0', '9');
|
|
||||||
lex_FloatAddRange(id, '_', '_');
|
|
||||||
lex_FloatAddRange(id, '\\', '\\');
|
|
||||||
lex_FloatAddRange(id, '@', '@');
|
|
||||||
lex_FloatAddRange(id, '#', '#');
|
|
||||||
|
|
||||||
//Local ID
|
|
||||||
|
|
||||||
id = lex_FloatAlloc(&tIDToken);
|
|
||||||
lex_FloatAddFirstRange(id, '.', '.');
|
|
||||||
lex_FloatAddSecondRange(id, 'a', 'z');
|
|
||||||
lex_FloatAddSecondRange(id, 'A', 'Z');
|
|
||||||
lex_FloatAddSecondRange(id, '_', '_');
|
|
||||||
lex_FloatAddRange(id, 'a', 'z');
|
|
||||||
lex_FloatAddRange(id, 'A', 'Z');
|
|
||||||
lex_FloatAddRange(id, '0', '9');
|
|
||||||
lex_FloatAddRange(id, '_', '_');
|
|
||||||
lex_FloatAddRange(id, '\\', '\\');
|
|
||||||
lex_FloatAddRange(id, '@', '@');
|
|
||||||
lex_FloatAddRange(id, '#', '#');
|
|
||||||
|
|
||||||
// "@"
|
|
||||||
|
|
||||||
id = lex_FloatAlloc(&tIDToken);
|
|
||||||
lex_FloatAddFirstRange(id, '@', '@');
|
|
||||||
|
|
||||||
//Fixed point constants
|
|
||||||
|
|
||||||
id = lex_FloatAlloc(&tFixedPointToken);
|
|
||||||
lex_FloatAddFirstRange(id, '.', '.');
|
|
||||||
lex_FloatAddFirstRange(id, '0', '9');
|
|
||||||
lex_FloatAddSecondRange(id, '.', '.');
|
|
||||||
lex_FloatAddSecondRange(id, '0', '9');
|
|
||||||
lex_FloatAddRange(id, '.', '.');
|
|
||||||
lex_FloatAddRange(id, '0', '9');
|
|
||||||
}
|
|
||||||
+2427
-901
File diff suppressed because it is too large
Load Diff
+75
-13
@@ -2,14 +2,16 @@
|
|||||||
#include <assert.h>
|
#include <assert.h>
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
#include <inttypes.h>
|
#include <inttypes.h>
|
||||||
|
#include <stdbool.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
#include "asm/asm.h"
|
|
||||||
#include "asm/macro.h"
|
#include "asm/macro.h"
|
||||||
#include "asm/warning.h"
|
#include "asm/warning.h"
|
||||||
|
|
||||||
|
#define MAXMACROARGS 99999
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Your average macro invocation does not go past the tens, but some go further
|
* Your average macro invocation does not go past the tens, but some go further
|
||||||
* This ensures that sane and slightly insane invocations suffer no penalties,
|
* This ensures that sane and slightly insane invocations suffer no penalties,
|
||||||
@@ -29,13 +31,14 @@ struct MacroArgs {
|
|||||||
sizeof(((struct MacroArgs){0}).args[0]) * (nbArgs))
|
sizeof(((struct MacroArgs){0}).args[0]) * (nbArgs))
|
||||||
|
|
||||||
static struct MacroArgs *macroArgs = NULL;
|
static struct MacroArgs *macroArgs = NULL;
|
||||||
static uint32_t uniqueID = -1;
|
static uint32_t uniqueID = 0;
|
||||||
|
static uint32_t maxUniqueID = 0;
|
||||||
/*
|
/*
|
||||||
* The initialization is somewhat harmful, since it is never used, but it
|
* The initialization is somewhat harmful, since it is never used, but it
|
||||||
* guarantees the size of the buffer will be correct. I was unable to find a
|
* guarantees the size of the buffer will be correct. I was unable to find a
|
||||||
* better solution, but if you have one, please feel free!
|
* better solution, but if you have one, please feel free!
|
||||||
*/
|
*/
|
||||||
static char uniqueIDBuf[] = "_" EXPAND_AND_STR(UINT32_MAX);
|
static char uniqueIDBuf[] = "_u4294967295"; // UINT32_MAX
|
||||||
static char *uniqueIDPtr = NULL;
|
static char *uniqueIDPtr = NULL;
|
||||||
|
|
||||||
struct MacroArgs *macro_GetCurrentArgs(void)
|
struct MacroArgs *macro_GetCurrentArgs(void)
|
||||||
@@ -48,7 +51,7 @@ struct MacroArgs *macro_NewArgs(void)
|
|||||||
struct MacroArgs *args = malloc(SIZEOF_ARGS(INITIAL_ARG_SIZE));
|
struct MacroArgs *args = malloc(SIZEOF_ARGS(INITIAL_ARG_SIZE));
|
||||||
|
|
||||||
if (!args)
|
if (!args)
|
||||||
fatalerror("Unable to register macro arguments: %s", strerror(errno));
|
fatalerror("Unable to register macro arguments: %s\n", strerror(errno));
|
||||||
|
|
||||||
args->nbArgs = 0;
|
args->nbArgs = 0;
|
||||||
args->shift = 0;
|
args->shift = 0;
|
||||||
@@ -59,17 +62,18 @@ struct MacroArgs *macro_NewArgs(void)
|
|||||||
void macro_AppendArg(struct MacroArgs **argPtr, char *s)
|
void macro_AppendArg(struct MacroArgs **argPtr, char *s)
|
||||||
{
|
{
|
||||||
#define macArgs (*argPtr)
|
#define macArgs (*argPtr)
|
||||||
|
if (s[0] == '\0')
|
||||||
|
warning(WARNING_EMPTY_MACRO_ARG, "Empty macro argument\n");
|
||||||
if (macArgs->nbArgs == MAXMACROARGS)
|
if (macArgs->nbArgs == MAXMACROARGS)
|
||||||
yyerror("A maximum of " EXPAND_AND_STR(MAXMACROARGS)
|
error("A maximum of " EXPAND_AND_STR(MAXMACROARGS) " arguments is allowed\n");
|
||||||
" arguments is allowed");
|
|
||||||
if (macArgs->nbArgs >= macArgs->capacity) {
|
if (macArgs->nbArgs >= macArgs->capacity) {
|
||||||
macArgs->capacity *= 2;
|
macArgs->capacity *= 2;
|
||||||
/* Check that overflow didn't roll us back */
|
/* Check that overflow didn't roll us back */
|
||||||
if (macArgs->capacity <= macArgs->nbArgs)
|
if (macArgs->capacity <= macArgs->nbArgs)
|
||||||
fatalerror("Failed to add new macro argument: possible capacity overflow");
|
fatalerror("Failed to add new macro argument: capacity overflow\n");
|
||||||
macArgs = realloc(macArgs, SIZEOF_ARGS(macArgs->capacity));
|
macArgs = realloc(macArgs, SIZEOF_ARGS(macArgs->capacity));
|
||||||
if (!macArgs)
|
if (!macArgs)
|
||||||
fatalerror("Error adding new macro argument: %s", strerror(errno));
|
fatalerror("Error adding new macro argument: %s\n", strerror(errno));
|
||||||
}
|
}
|
||||||
macArgs->args[macArgs->nbArgs++] = s;
|
macArgs->args[macArgs->nbArgs++] = s;
|
||||||
#undef macArgs
|
#undef macArgs
|
||||||
@@ -88,12 +92,49 @@ void macro_FreeArgs(struct MacroArgs *args)
|
|||||||
|
|
||||||
char const *macro_GetArg(uint32_t i)
|
char const *macro_GetArg(uint32_t i)
|
||||||
{
|
{
|
||||||
|
if (!macroArgs)
|
||||||
|
return NULL;
|
||||||
|
|
||||||
uint32_t realIndex = i + macroArgs->shift - 1;
|
uint32_t realIndex = i + macroArgs->shift - 1;
|
||||||
|
|
||||||
return realIndex >= macroArgs->nbArgs ? NULL
|
return realIndex >= macroArgs->nbArgs ? NULL
|
||||||
: macroArgs->args[realIndex];
|
: macroArgs->args[realIndex];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
char const *macro_GetAllArgs(void)
|
||||||
|
{
|
||||||
|
if (!macroArgs)
|
||||||
|
return NULL;
|
||||||
|
|
||||||
|
if (macroArgs->shift >= macroArgs->nbArgs)
|
||||||
|
return "";
|
||||||
|
|
||||||
|
size_t len = 0;
|
||||||
|
|
||||||
|
for (uint32_t i = macroArgs->shift; i < macroArgs->nbArgs; i++)
|
||||||
|
len += strlen(macroArgs->args[i]) + 1; /* 1 for comma */
|
||||||
|
|
||||||
|
char *str = malloc(len + 1); /* 1 for '\0' */
|
||||||
|
char *ptr = str;
|
||||||
|
|
||||||
|
if (!str)
|
||||||
|
fatalerror("Failed to allocate memory for expanding '\\#': %s\n", strerror(errno));
|
||||||
|
|
||||||
|
for (uint32_t i = macroArgs->shift; i < macroArgs->nbArgs; i++) {
|
||||||
|
size_t n = strlen(macroArgs->args[i]);
|
||||||
|
|
||||||
|
memcpy(ptr, macroArgs->args[i], n);
|
||||||
|
ptr += n;
|
||||||
|
|
||||||
|
/* Commas go between args and after a last empty arg */
|
||||||
|
if (i < macroArgs->nbArgs - 1 || n == 0)
|
||||||
|
*ptr++ = ','; /* no space after comma */
|
||||||
|
}
|
||||||
|
*ptr = '\0';
|
||||||
|
|
||||||
|
return str;
|
||||||
|
}
|
||||||
|
|
||||||
uint32_t macro_GetUniqueID(void)
|
uint32_t macro_GetUniqueID(void)
|
||||||
{
|
{
|
||||||
return uniqueID;
|
return uniqueID;
|
||||||
@@ -107,19 +148,40 @@ char const *macro_GetUniqueIDStr(void)
|
|||||||
void macro_SetUniqueID(uint32_t id)
|
void macro_SetUniqueID(uint32_t id)
|
||||||
{
|
{
|
||||||
uniqueID = id;
|
uniqueID = id;
|
||||||
if (id == -1) {
|
if (id == 0) {
|
||||||
uniqueIDPtr = NULL;
|
uniqueIDPtr = NULL;
|
||||||
} else {
|
} else {
|
||||||
|
if (uniqueID > maxUniqueID)
|
||||||
|
maxUniqueID = uniqueID;
|
||||||
/* The buffer is guaranteed to be the correct size */
|
/* The buffer is guaranteed to be the correct size */
|
||||||
sprintf(uniqueIDBuf, "_%" PRIu32, id);
|
/* This is a valid label fragment, but not a valid numeric */
|
||||||
|
sprintf(uniqueIDBuf, "_u%" PRIu32, id);
|
||||||
uniqueIDPtr = uniqueIDBuf;
|
uniqueIDPtr = uniqueIDBuf;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void macro_ShiftCurrentArgs(void)
|
uint32_t macro_UseNewUniqueID(void)
|
||||||
{
|
{
|
||||||
if (macroArgs->shift != macroArgs->nbArgs)
|
macro_SetUniqueID(++maxUniqueID);
|
||||||
macroArgs->shift++;
|
return maxUniqueID;
|
||||||
|
}
|
||||||
|
|
||||||
|
void macro_ShiftCurrentArgs(int32_t count)
|
||||||
|
{
|
||||||
|
if (!macroArgs) {
|
||||||
|
error("Cannot shift macro arguments outside of a macro\n");
|
||||||
|
} else if (count > 0 && ((uint32_t)count > macroArgs->nbArgs
|
||||||
|
|| macroArgs->shift > macroArgs->nbArgs - count)) {
|
||||||
|
warning(WARNING_MACRO_SHIFT,
|
||||||
|
"Cannot shift macro arguments past their end\n");
|
||||||
|
macroArgs->shift = macroArgs->nbArgs;
|
||||||
|
} else if (count < 0 && macroArgs->shift < (uint32_t)-count) {
|
||||||
|
warning(WARNING_MACRO_SHIFT,
|
||||||
|
"Cannot shift macro arguments past their beginning\n");
|
||||||
|
macroArgs->shift = 0;
|
||||||
|
} else {
|
||||||
|
macroArgs->shift += count;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
uint32_t macro_NbArgs(void)
|
uint32_t macro_NbArgs(void)
|
||||||
|
|||||||
+151
-370
@@ -6,6 +6,7 @@
|
|||||||
* SPDX-License-Identifier: MIT
|
* SPDX-License-Identifier: MIT
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#include <ctype.h>
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
#include <float.h>
|
#include <float.h>
|
||||||
#include <inttypes.h>
|
#include <inttypes.h>
|
||||||
@@ -17,249 +18,59 @@
|
|||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <time.h>
|
#include <time.h>
|
||||||
|
|
||||||
#include "asm/symbol.h"
|
#include "asm/charmap.h"
|
||||||
|
#include "asm/format.h"
|
||||||
#include "asm/fstack.h"
|
#include "asm/fstack.h"
|
||||||
#include "asm/lexer.h"
|
#include "asm/lexer.h"
|
||||||
#include "asm/output.h"
|
|
||||||
#include "asm/main.h"
|
#include "asm/main.h"
|
||||||
#include "asm/charmap.h"
|
#include "asm/opt.h"
|
||||||
|
#include "asm/output.h"
|
||||||
|
#include "asm/rpn.h"
|
||||||
|
#include "asm/symbol.h"
|
||||||
#include "asm/warning.h"
|
#include "asm/warning.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"
|
||||||
|
|
||||||
extern int yyparse(void);
|
#ifdef __clang__
|
||||||
|
#if __has_feature(address_sanitizer) && !defined(__SANITIZE_ADDRESS__)
|
||||||
|
#define __SANITIZE_ADDRESS__
|
||||||
|
#endif /* __has_feature(address_sanitizer) && !defined(__SANITIZE_ADDRESS__) */
|
||||||
|
#endif /* __clang__ */
|
||||||
|
|
||||||
size_t cldefines_index;
|
#ifdef __SANITIZE_ADDRESS__
|
||||||
size_t cldefines_numindices;
|
// There are known, non-trivial to fix leaks. We would still like to have `make develop'
|
||||||
size_t cldefines_bufsize;
|
// detect memory corruption, though.
|
||||||
const size_t cldefine_entrysize = 2 * sizeof(void *);
|
char const *__asan_default_options(void) { return "detect_leaks=0"; }
|
||||||
char **cldefines;
|
|
||||||
|
|
||||||
clock_t nStartClock, nEndClock;
|
|
||||||
uint32_t nTotalLines, nIFDepth, nUnionDepth;
|
|
||||||
bool skipElif;
|
|
||||||
uint32_t unionStart[128], unionSize[128];
|
|
||||||
|
|
||||||
int32_t nLineNo;
|
|
||||||
uint32_t curOffset;
|
|
||||||
|
|
||||||
#if defined(YYDEBUG) && YYDEBUG
|
|
||||||
extern int yydebug;
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
// 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...
|
||||||
|
int yyparse(void);
|
||||||
|
|
||||||
FILE * dependfile;
|
FILE * dependfile;
|
||||||
bool oGeneratedMissingIncludes;
|
bool generatedMissingIncludes;
|
||||||
bool oFailedOnMissingInclude;
|
bool failedOnMissingInclude;
|
||||||
bool oGeneratePhonyDeps;
|
bool generatePhonyDeps;
|
||||||
char *tzTargetFileName;
|
char *targetFileName;
|
||||||
|
|
||||||
/*
|
|
||||||
* Option stack
|
|
||||||
*/
|
|
||||||
|
|
||||||
struct sOptions DefaultOptions;
|
|
||||||
struct sOptions CurrentOptions;
|
|
||||||
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. */
|
||||||
|
|
||||||
struct sOptionStackEntry {
|
|
||||||
struct sOptions Options;
|
|
||||||
struct sOptionStackEntry *pNext;
|
|
||||||
};
|
|
||||||
|
|
||||||
struct sOptionStackEntry *pOptionStack;
|
|
||||||
|
|
||||||
void opt_SetCurrentOptions(struct sOptions *pOpt)
|
|
||||||
{
|
|
||||||
if (nGBGfxID != -1) {
|
|
||||||
lex_FloatDeleteRange(nGBGfxID, CurrentOptions.gbgfx[0],
|
|
||||||
CurrentOptions.gbgfx[0]);
|
|
||||||
lex_FloatDeleteRange(nGBGfxID, CurrentOptions.gbgfx[1],
|
|
||||||
CurrentOptions.gbgfx[1]);
|
|
||||||
lex_FloatDeleteRange(nGBGfxID, CurrentOptions.gbgfx[2],
|
|
||||||
CurrentOptions.gbgfx[2]);
|
|
||||||
lex_FloatDeleteRange(nGBGfxID, CurrentOptions.gbgfx[3],
|
|
||||||
CurrentOptions.gbgfx[3]);
|
|
||||||
lex_FloatDeleteSecondRange(nGBGfxID, CurrentOptions.gbgfx[0],
|
|
||||||
CurrentOptions.gbgfx[0]);
|
|
||||||
lex_FloatDeleteSecondRange(nGBGfxID, CurrentOptions.gbgfx[1],
|
|
||||||
CurrentOptions.gbgfx[1]);
|
|
||||||
lex_FloatDeleteSecondRange(nGBGfxID, CurrentOptions.gbgfx[2],
|
|
||||||
CurrentOptions.gbgfx[2]);
|
|
||||||
lex_FloatDeleteSecondRange(nGBGfxID, CurrentOptions.gbgfx[3],
|
|
||||||
CurrentOptions.gbgfx[3]);
|
|
||||||
}
|
|
||||||
if (nBinaryID != -1) {
|
|
||||||
lex_FloatDeleteRange(nBinaryID, CurrentOptions.binary[0],
|
|
||||||
CurrentOptions.binary[0]);
|
|
||||||
lex_FloatDeleteRange(nBinaryID, CurrentOptions.binary[1],
|
|
||||||
CurrentOptions.binary[1]);
|
|
||||||
lex_FloatDeleteSecondRange(nBinaryID, CurrentOptions.binary[0],
|
|
||||||
CurrentOptions.binary[0]);
|
|
||||||
lex_FloatDeleteSecondRange(nBinaryID, CurrentOptions.binary[1],
|
|
||||||
CurrentOptions.binary[1]);
|
|
||||||
}
|
|
||||||
CurrentOptions = *pOpt;
|
|
||||||
|
|
||||||
if (nGBGfxID != -1) {
|
|
||||||
lex_FloatAddRange(nGBGfxID, CurrentOptions.gbgfx[0],
|
|
||||||
CurrentOptions.gbgfx[0]);
|
|
||||||
lex_FloatAddRange(nGBGfxID, CurrentOptions.gbgfx[1],
|
|
||||||
CurrentOptions.gbgfx[1]);
|
|
||||||
lex_FloatAddRange(nGBGfxID, CurrentOptions.gbgfx[2],
|
|
||||||
CurrentOptions.gbgfx[2]);
|
|
||||||
lex_FloatAddRange(nGBGfxID, CurrentOptions.gbgfx[3],
|
|
||||||
CurrentOptions.gbgfx[3]);
|
|
||||||
lex_FloatAddSecondRange(nGBGfxID, CurrentOptions.gbgfx[0],
|
|
||||||
CurrentOptions.gbgfx[0]);
|
|
||||||
lex_FloatAddSecondRange(nGBGfxID, CurrentOptions.gbgfx[1],
|
|
||||||
CurrentOptions.gbgfx[1]);
|
|
||||||
lex_FloatAddSecondRange(nGBGfxID, CurrentOptions.gbgfx[2],
|
|
||||||
CurrentOptions.gbgfx[2]);
|
|
||||||
lex_FloatAddSecondRange(nGBGfxID, CurrentOptions.gbgfx[3],
|
|
||||||
CurrentOptions.gbgfx[3]);
|
|
||||||
}
|
|
||||||
if (nBinaryID != -1) {
|
|
||||||
lex_FloatAddRange(nBinaryID, CurrentOptions.binary[0],
|
|
||||||
CurrentOptions.binary[0]);
|
|
||||||
lex_FloatAddRange(nBinaryID, CurrentOptions.binary[1],
|
|
||||||
CurrentOptions.binary[1]);
|
|
||||||
lex_FloatAddSecondRange(nBinaryID, CurrentOptions.binary[0],
|
|
||||||
CurrentOptions.binary[0]);
|
|
||||||
lex_FloatAddSecondRange(nBinaryID, CurrentOptions.binary[1],
|
|
||||||
CurrentOptions.binary[1]);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void opt_Parse(char *s)
|
|
||||||
{
|
|
||||||
struct sOptions newopt;
|
|
||||||
|
|
||||||
newopt = CurrentOptions;
|
|
||||||
|
|
||||||
switch (s[0]) {
|
|
||||||
case 'g':
|
|
||||||
if (strlen(&s[1]) == 4) {
|
|
||||||
newopt.gbgfx[0] = s[1];
|
|
||||||
newopt.gbgfx[1] = s[2];
|
|
||||||
newopt.gbgfx[2] = s[3];
|
|
||||||
newopt.gbgfx[3] = s[4];
|
|
||||||
} else {
|
|
||||||
yyerror("Must specify exactly 4 characters for option 'g'");
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
case 'b':
|
|
||||||
if (strlen(&s[1]) == 2) {
|
|
||||||
newopt.binary[0] = s[1];
|
|
||||||
newopt.binary[1] = s[2];
|
|
||||||
} else {
|
|
||||||
yyerror("Must specify exactly 2 characters for option 'b'");
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
case 'z':
|
|
||||||
warning(WARNING_OBSOLETE, "Option 'z' is a deprecated alias for 'p'");
|
|
||||||
/* fallthrough */
|
|
||||||
case 'p':
|
|
||||||
if (strlen(&s[1]) <= 2) {
|
|
||||||
int result;
|
|
||||||
unsigned int fillchar;
|
|
||||||
|
|
||||||
result = sscanf(&s[1], "%x", &fillchar);
|
|
||||||
if (result != EOF && result != 1)
|
|
||||||
yyerror("Invalid argument for option 'z'");
|
|
||||||
else
|
|
||||||
newopt.fillchar = fillchar;
|
|
||||||
} else {
|
|
||||||
yyerror("Invalid argument for option 'z'");
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
yyerror("Unknown option");
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
opt_SetCurrentOptions(&newopt);
|
|
||||||
}
|
|
||||||
|
|
||||||
void opt_Push(void)
|
|
||||||
{
|
|
||||||
struct sOptionStackEntry *pOpt;
|
|
||||||
|
|
||||||
pOpt = malloc(sizeof(struct sOptionStackEntry));
|
|
||||||
|
|
||||||
if (pOpt == NULL)
|
|
||||||
fatalerror("No memory for option stack");
|
|
||||||
|
|
||||||
pOpt->Options = CurrentOptions;
|
|
||||||
pOpt->pNext = pOptionStack;
|
|
||||||
pOptionStack = pOpt;
|
|
||||||
}
|
|
||||||
|
|
||||||
void opt_Pop(void)
|
|
||||||
{
|
|
||||||
if (pOptionStack == NULL)
|
|
||||||
fatalerror("No entries in the option stack");
|
|
||||||
|
|
||||||
struct sOptionStackEntry *pOpt;
|
|
||||||
|
|
||||||
pOpt = pOptionStack;
|
|
||||||
opt_SetCurrentOptions(&(pOpt->Options));
|
|
||||||
pOptionStack = pOpt->pNext;
|
|
||||||
free(pOpt);
|
|
||||||
}
|
|
||||||
|
|
||||||
void opt_AddDefine(char *s)
|
|
||||||
{
|
|
||||||
char *value, *equals;
|
|
||||||
|
|
||||||
if (cldefines_index >= cldefines_numindices) {
|
|
||||||
/* Check for overflows */
|
|
||||||
if ((cldefines_numindices * 2) < cldefines_numindices)
|
|
||||||
fatalerror("No memory for command line defines");
|
|
||||||
|
|
||||||
if ((cldefines_bufsize * 2) < cldefines_bufsize)
|
|
||||||
fatalerror("No memory for command line defines");
|
|
||||||
|
|
||||||
cldefines_numindices *= 2;
|
|
||||||
cldefines_bufsize *= 2;
|
|
||||||
|
|
||||||
cldefines = realloc(cldefines, cldefines_bufsize);
|
|
||||||
if (!cldefines)
|
|
||||||
fatalerror("No memory for command line defines");
|
|
||||||
}
|
|
||||||
equals = strchr(s, '=');
|
|
||||||
if (equals) {
|
|
||||||
*equals = '\0';
|
|
||||||
value = equals + 1;
|
|
||||||
} else {
|
|
||||||
value = "1";
|
|
||||||
}
|
|
||||||
cldefines[cldefines_index++] = s;
|
|
||||||
cldefines[cldefines_index++] = value;
|
|
||||||
}
|
|
||||||
|
|
||||||
static void opt_ParseDefines(void)
|
|
||||||
{
|
|
||||||
uint32_t i;
|
|
||||||
|
|
||||||
for (i = 0; i < cldefines_index; i += 2)
|
|
||||||
sym_AddString(cldefines[i], cldefines[i + 1]);
|
|
||||||
}
|
|
||||||
|
|
||||||
/* 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 */
|
||||||
@@ -273,7 +84,7 @@ static char *make_escape(const char *str)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* Short options */
|
/* Short options */
|
||||||
static char const *optstring = "b:D:Eg:hi:LM:o:p:r:VvW:w";
|
static const char *optstring = "b:D:Eg:hi:LM:o:p:r:VvW:w";
|
||||||
|
|
||||||
/* Variables for the long-only options */
|
/* Variables for the long-only options */
|
||||||
static int depType; /* Variants of `-M` */
|
static int depType; /* Variants of `-M` */
|
||||||
@@ -315,7 +126,7 @@ static void print_usage(void)
|
|||||||
fputs(
|
fputs(
|
||||||
"Usage: rgbasm [-EhLVvw] [-b chars] [-D name[=value]] [-g chars] [-i path]\n"
|
"Usage: rgbasm [-EhLVvw] [-b chars] [-D name[=value]] [-g chars] [-i path]\n"
|
||||||
" [-M depend_file] [-MG] [-MP] [-MT target_file] [-MQ target_file]\n"
|
" [-M depend_file] [-MG] [-MP] [-MT target_file] [-MQ target_file]\n"
|
||||||
" [-o out_file] [-p pad_value] [-r depth] [-W warning] <file> ...\n"
|
" [-o out_file] [-p pad_value] [-r depth] [-W warning] <file>\n"
|
||||||
"Useful options:\n"
|
"Useful options:\n"
|
||||||
" -E, --export-all export all labels\n"
|
" -E, --export-all export all labels\n"
|
||||||
" -M, --dependfile <path> set the output dependency file\n"
|
" -M, --dependfile <path> set the output dependency file\n"
|
||||||
@@ -324,130 +135,139 @@ static void print_usage(void)
|
|||||||
" -V, --version print RGBASM version and exit\n"
|
" -V, --version print RGBASM version and exit\n"
|
||||||
" -W, --warning <warning> enable or disable warnings\n"
|
" -W, --warning <warning> enable or disable warnings\n"
|
||||||
"\n"
|
"\n"
|
||||||
"For help, use `man rgbasm' or go to https://rednex.github.io/rgbds/\n",
|
"For help, use `man rgbasm' or go to https://rgbds.gbdev.io/docs/\n",
|
||||||
stderr);
|
stderr);
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
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;
|
||||||
|
|
||||||
struct sOptions newopt;
|
time_t now = time(NULL);
|
||||||
|
char const *sourceDateEpoch = getenv("SOURCE_DATE_EPOCH");
|
||||||
|
|
||||||
char *tzMainfile;
|
/*
|
||||||
|
* Support SOURCE_DATE_EPOCH for reproducible builds
|
||||||
|
* https://reproducible-builds.org/docs/source-date-epoch/
|
||||||
|
*/
|
||||||
|
if (sourceDateEpoch)
|
||||||
|
now = (time_t)strtoul(sourceDateEpoch, NULL, 0);
|
||||||
|
|
||||||
dependfile = NULL;
|
dependfile = NULL;
|
||||||
|
|
||||||
/* Initial number of allocated elements in array */
|
// Perform some init for below
|
||||||
cldefines_numindices = 32;
|
sym_Init(now);
|
||||||
cldefines_bufsize = cldefines_numindices * cldefine_entrysize;
|
|
||||||
cldefines = malloc(cldefines_bufsize);
|
|
||||||
if (!cldefines)
|
|
||||||
fatalerror("No memory for command line defines");
|
|
||||||
|
|
||||||
#if defined(YYDEBUG) && YYDEBUG
|
// Set defaults
|
||||||
yydebug = 1;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
nMaxRecursionDepth = 64;
|
generatePhonyDeps = false;
|
||||||
oGeneratePhonyDeps = false;
|
generatedMissingIncludes = false;
|
||||||
oGeneratedMissingIncludes = false;
|
failedOnMissingInclude = false;
|
||||||
oFailedOnMissingInclude = false;
|
targetFileName = NULL;
|
||||||
tzTargetFileName = NULL;
|
|
||||||
size_t nTargetFileNameLen = 0;
|
|
||||||
|
|
||||||
DefaultOptions.gbgfx[0] = '0';
|
opt_B("01");
|
||||||
DefaultOptions.gbgfx[1] = '1';
|
opt_G("0123");
|
||||||
DefaultOptions.gbgfx[2] = '2';
|
opt_P(0);
|
||||||
DefaultOptions.gbgfx[3] = '3';
|
optimizeLoads = true;
|
||||||
DefaultOptions.binary[0] = '0';
|
|
||||||
DefaultOptions.binary[1] = '1';
|
|
||||||
DefaultOptions.fillchar = 0;
|
|
||||||
optimizeloads = true;
|
|
||||||
haltnop = true;
|
haltnop = true;
|
||||||
verbose = false;
|
verbose = false;
|
||||||
warnings = true;
|
warnings = true;
|
||||||
bool exportall = false;
|
sym_SetExportAll(false);
|
||||||
|
uint32_t maxDepth = 64;
|
||||||
|
size_t targetFileNameLen = 0;
|
||||||
|
|
||||||
opt_SetCurrentOptions(&DefaultOptions);
|
while ((ch = musl_getopt_long_only(argc, argv, optstring, longopts, NULL)) != -1) {
|
||||||
|
|
||||||
newopt = CurrentOptions;
|
|
||||||
|
|
||||||
while ((ch = musl_getopt_long_only(argc, argv, optstring, longopts,
|
|
||||||
NULL)) != -1) {
|
|
||||||
switch (ch) {
|
switch (ch) {
|
||||||
case 'b':
|
case 'b':
|
||||||
if (strlen(optarg) == 2) {
|
if (strlen(musl_optarg) == 2)
|
||||||
newopt.binary[0] = optarg[1];
|
opt_B(&musl_optarg[1]);
|
||||||
newopt.binary[1] = optarg[2];
|
else
|
||||||
} else {
|
errx("Must specify exactly 2 characters for option 'b'");
|
||||||
errx(1, "Must specify exactly 2 characters for option 'b'");
|
|
||||||
}
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
char *equals;
|
||||||
case 'D':
|
case 'D':
|
||||||
opt_AddDefine(optarg);
|
equals = strchr(musl_optarg, '=');
|
||||||
break;
|
if (equals) {
|
||||||
case 'E':
|
*equals = '\0';
|
||||||
exportall = true;
|
sym_AddString(musl_optarg, equals + 1);
|
||||||
break;
|
|
||||||
case 'g':
|
|
||||||
if (strlen(optarg) == 4) {
|
|
||||||
newopt.gbgfx[0] = optarg[1];
|
|
||||||
newopt.gbgfx[1] = optarg[2];
|
|
||||||
newopt.gbgfx[2] = optarg[3];
|
|
||||||
newopt.gbgfx[3] = optarg[4];
|
|
||||||
} else {
|
} else {
|
||||||
errx(1, "Must specify exactly 4 characters for option 'g'");
|
sym_AddString(musl_optarg, "1");
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
case 'E':
|
||||||
|
sym_SetExportAll(true);
|
||||||
|
break;
|
||||||
|
|
||||||
|
case 'g':
|
||||||
|
if (strlen(musl_optarg) == 4)
|
||||||
|
opt_G(&musl_optarg[1]);
|
||||||
|
else
|
||||||
|
errx("Must specify exactly 4 characters for option 'g'");
|
||||||
|
break;
|
||||||
|
|
||||||
case 'h':
|
case 'h':
|
||||||
haltnop = false;
|
haltnop = false;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 'i':
|
case 'i':
|
||||||
fstk_AddIncludePath(optarg);
|
fstk_AddIncludePath(musl_optarg);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 'L':
|
case 'L':
|
||||||
optimizeloads = false;
|
optimizeLoads = false;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 'M':
|
case 'M':
|
||||||
if (!strcmp("-", optarg))
|
if (!strcmp("-", musl_optarg))
|
||||||
dependfile = stdout;
|
dependfile = stdout;
|
||||||
else
|
else
|
||||||
dependfile = fopen(optarg, "w");
|
dependfile = fopen(musl_optarg, "w");
|
||||||
if (dependfile == NULL)
|
if (dependfile == NULL)
|
||||||
err(1, "Could not open dependfile %s",
|
err("Could not open dependfile %s", musl_optarg);
|
||||||
optarg);
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 'o':
|
case 'o':
|
||||||
out_SetFileName(optarg);
|
out_SetFileName(musl_optarg);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
unsigned long fill;
|
||||||
case 'p':
|
case 'p':
|
||||||
newopt.fillchar = strtoul(optarg, &ep, 0);
|
fill = strtoul(musl_optarg, &ep, 0);
|
||||||
|
|
||||||
if (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 (newopt.fillchar < 0 || newopt.fillchar > 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);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 'r':
|
case 'r':
|
||||||
nMaxRecursionDepth = strtoul(optarg, &ep, 0);
|
maxDepth = strtoul(musl_optarg, &ep, 0);
|
||||||
|
|
||||||
if (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':
|
||||||
printf("rgbasm %s\n", get_package_version_string());
|
printf("rgbasm %s\n", get_package_version_string());
|
||||||
exit(0);
|
exit(0);
|
||||||
case 'v':
|
case 'v':
|
||||||
verbose = true;
|
verbose = true;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 'W':
|
case 'W':
|
||||||
processWarningFlag(optarg);
|
processWarningFlag(musl_optarg);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 'w':
|
case 'w':
|
||||||
warnings = false;
|
warnings = false;
|
||||||
break;
|
break;
|
||||||
@@ -456,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 (optind == argc)
|
newTarget = musl_optarg;
|
||||||
errx(1, "-M%c takes a target file name argument",
|
|
||||||
depType);
|
|
||||||
ep = 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 =
|
err("Cannot append new file to target file list");
|
||||||
malloc(nTargetFileNameLen + 1);
|
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 +
|
targetFileNameLen += newTargetLen;
|
||||||
strlen(tzTargetFileName);
|
targetFileName[targetFileNameLen - 1] = ' ';
|
||||||
*ptr++ = ' ';
|
|
||||||
*ptr = '\0';
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
@@ -500,86 +310,57 @@ int main(int argc, char *argv[])
|
|||||||
/* NOTREACHED */
|
/* NOTREACHED */
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
argc -= optind;
|
|
||||||
argv += optind;
|
|
||||||
|
|
||||||
if (tzTargetFileName == NULL)
|
if (targetFileName == NULL)
|
||||||
tzTargetFileName = tzObjectname;
|
targetFileName = objectName;
|
||||||
|
else
|
||||||
|
targetFileName[targetFileNameLen - 1] = '\0'; // Overwrite the last space
|
||||||
|
|
||||||
opt_SetCurrentOptions(&newopt);
|
if (argc == musl_optind) {
|
||||||
|
fputs("FATAL: No input files\n", stderr);
|
||||||
DefaultOptions = CurrentOptions;
|
print_usage();
|
||||||
|
} else if (argc != musl_optind + 1) {
|
||||||
if (argc == 0) {
|
fputs("FATAL: More than one input file given\n", stderr);
|
||||||
fputs("FATAL: no input files\n", stderr);
|
|
||||||
print_usage();
|
print_usage();
|
||||||
}
|
}
|
||||||
|
|
||||||
tzMainfile = argv[argc - 1];
|
char const *mainFileName = argv[musl_optind];
|
||||||
|
|
||||||
setup_lexer();
|
|
||||||
|
|
||||||
if (verbose)
|
if (verbose)
|
||||||
printf("Assembling %s\n", tzMainfile);
|
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, tzMainfile);
|
fprintf(dependfile, "%s: %s\n", targetFileName, mainFileName);
|
||||||
}
|
}
|
||||||
|
|
||||||
nStartClock = clock();
|
charmap_New("main", NULL);
|
||||||
|
|
||||||
nLineNo = 1;
|
// Init lexer and file stack, prodiving file info
|
||||||
nTotalLines = 0;
|
lexer_Init();
|
||||||
nIFDepth = 0;
|
fstk_Init(mainFileName, maxDepth);
|
||||||
skipElif = true;
|
|
||||||
nUnionDepth = 0;
|
|
||||||
sym_Init();
|
|
||||||
sym_SetExportAll(exportall);
|
|
||||||
fstk_Init(tzMainfile);
|
|
||||||
opt_ParseDefines();
|
|
||||||
charmap_InitMain();
|
|
||||||
|
|
||||||
yy_set_state(LEX_STATE_NORMAL);
|
// Perform parse (yyparse is auto-generated from `parser.y`)
|
||||||
opt_SetCurrentOptions(&DefaultOptions);
|
if (yyparse() != 0 && nbErrors == 0)
|
||||||
|
nbErrors = 1;
|
||||||
|
|
||||||
if (yyparse() != 0 || nbErrors != 0)
|
|
||||||
errx(1, "Assembly aborted (%u errors)!", nbErrors);
|
|
||||||
if (dependfile)
|
if (dependfile)
|
||||||
fclose(dependfile);
|
fclose(dependfile);
|
||||||
|
|
||||||
if (nIFDepth != 0)
|
sect_CheckUnionClosed();
|
||||||
errx(1, "Unterminated IF construct (%" PRIu32 " levels)!",
|
|
||||||
nIFDepth);
|
|
||||||
|
|
||||||
if (nUnionDepth != 0) {
|
if (nbErrors != 0)
|
||||||
errx(1, "Unterminated UNION construct (%" PRIu32 " levels)!",
|
errx("Assembly aborted (%u error%s)!", nbErrors,
|
||||||
nUnionDepth);
|
nbErrors == 1 ? "" : "s");
|
||||||
}
|
|
||||||
|
|
||||||
double timespent;
|
// If parse aborted due to missing an include, and `-MG` was given, exit normally
|
||||||
|
if (failedOnMissingInclude)
|
||||||
nEndClock = clock();
|
|
||||||
timespent = ((double)(nEndClock - nStartClock))
|
|
||||||
/ (double)CLOCKS_PER_SEC;
|
|
||||||
if (verbose) {
|
|
||||||
printf("Success! %" PRIu32 " lines in %d.%02d seconds ",
|
|
||||||
nTotalLines, (int)timespent,
|
|
||||||
((int)(timespent * 100.0)) % 100);
|
|
||||||
if (timespent < FLT_MIN_EXP)
|
|
||||||
printf("(INFINITY lines/minute)\n");
|
|
||||||
else
|
|
||||||
printf("(%d lines/minute)\n",
|
|
||||||
(int)(60 / timespent * nTotalLines));
|
|
||||||
}
|
|
||||||
|
|
||||||
if (oFailedOnMissingInclude)
|
|
||||||
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;
|
||||||
}
|
}
|
||||||
|
|||||||
-147
@@ -1,147 +0,0 @@
|
|||||||
/*
|
|
||||||
* This file is part of RGBDS.
|
|
||||||
*
|
|
||||||
* Copyright (c) 1997-2018, Carsten Sorensen and RGBDS contributors.
|
|
||||||
*
|
|
||||||
* SPDX-License-Identifier: MIT
|
|
||||||
*/
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Fixedpoint math routines
|
|
||||||
*/
|
|
||||||
|
|
||||||
#include <inttypes.h>
|
|
||||||
#include <math.h>
|
|
||||||
#include <stdint.h>
|
|
||||||
#include <stdio.h>
|
|
||||||
|
|
||||||
#include "asm/mymath.h"
|
|
||||||
#include "asm/symbol.h"
|
|
||||||
|
|
||||||
#define fx2double(i) ((double)((i) / 65536.0))
|
|
||||||
#define double2fx(d) ((int32_t)((d) * 65536.0))
|
|
||||||
|
|
||||||
#ifndef M_PI
|
|
||||||
#define M_PI 3.14159265358979323846
|
|
||||||
#endif
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Define the _PI symbol
|
|
||||||
*/
|
|
||||||
void math_DefinePI(void)
|
|
||||||
{
|
|
||||||
sym_AddEqu("_PI", double2fx(M_PI));
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Print a fixed point value
|
|
||||||
*/
|
|
||||||
void math_Print(int32_t i)
|
|
||||||
{
|
|
||||||
uint32_t u = i;
|
|
||||||
const char *sign = "";
|
|
||||||
|
|
||||||
if (i < 0) {
|
|
||||||
u = -u;
|
|
||||||
sign = "-";
|
|
||||||
}
|
|
||||||
|
|
||||||
printf("%s%" PRIu32 ".%05" PRIu32, sign, u >> 16,
|
|
||||||
((uint32_t)(fx2double(u) * 100000 + 0.5)) % 100000);
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Calculate sine
|
|
||||||
*/
|
|
||||||
int32_t math_Sin(int32_t i)
|
|
||||||
{
|
|
||||||
return double2fx(sin(fx2double(i) * 2 * M_PI / 65536));
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Calculate cosine
|
|
||||||
*/
|
|
||||||
int32_t math_Cos(int32_t i)
|
|
||||||
{
|
|
||||||
return double2fx(cos(fx2double(i) * 2 * M_PI / 65536));
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Calculate tangent
|
|
||||||
*/
|
|
||||||
int32_t math_Tan(int32_t i)
|
|
||||||
{
|
|
||||||
return double2fx(tan(fx2double(i) * 2 * M_PI / 65536));
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Calculate arcsine
|
|
||||||
*/
|
|
||||||
int32_t math_ASin(int32_t i)
|
|
||||||
{
|
|
||||||
return double2fx(asin(fx2double(i)) / 2 / M_PI * 65536);
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Calculate arccosine
|
|
||||||
*/
|
|
||||||
int32_t math_ACos(int32_t i)
|
|
||||||
{
|
|
||||||
return double2fx(acos(fx2double(i)) / 2 / M_PI * 65536);
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Calculate arctangent
|
|
||||||
*/
|
|
||||||
int32_t math_ATan(int32_t i)
|
|
||||||
{
|
|
||||||
return double2fx(atan(fx2double(i)) / 2 / M_PI * 65536);
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Calculate atan2
|
|
||||||
*/
|
|
||||||
int32_t math_ATan2(int32_t i, int32_t j)
|
|
||||||
{
|
|
||||||
return double2fx(atan2(fx2double(i), fx2double(j)) / 2 / M_PI * 65536);
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Multiplication
|
|
||||||
*/
|
|
||||||
int32_t math_Mul(int32_t i, int32_t j)
|
|
||||||
{
|
|
||||||
return double2fx(fx2double(i) * fx2double(j));
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Division
|
|
||||||
*/
|
|
||||||
int32_t math_Div(int32_t i, int32_t j)
|
|
||||||
{
|
|
||||||
return double2fx(fx2double(i) / fx2double(j));
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Round
|
|
||||||
*/
|
|
||||||
int32_t math_Round(int32_t i)
|
|
||||||
{
|
|
||||||
return double2fx(round(fx2double(i)));
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Ceil
|
|
||||||
*/
|
|
||||||
int32_t math_Ceil(int32_t i)
|
|
||||||
{
|
|
||||||
return double2fx(ceil(fx2double(i)));
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Floor
|
|
||||||
*/
|
|
||||||
int32_t math_Floor(int32_t i)
|
|
||||||
{
|
|
||||||
return double2fx(floor(fx2double(i)));
|
|
||||||
}
|
|
||||||
+221
@@ -0,0 +1,221 @@
|
|||||||
|
#include <ctype.h>
|
||||||
|
#include <errno.h>
|
||||||
|
#include <stdbool.h>
|
||||||
|
#include <stdint.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <string.h>
|
||||||
|
|
||||||
|
#include "asm/fstack.h"
|
||||||
|
#include "asm/lexer.h"
|
||||||
|
#include "asm/main.h"
|
||||||
|
#include "asm/section.h"
|
||||||
|
#include "asm/warning.h"
|
||||||
|
|
||||||
|
struct OptStackEntry {
|
||||||
|
char binary[2];
|
||||||
|
char gbgfx[4];
|
||||||
|
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;
|
||||||
|
};
|
||||||
|
|
||||||
|
static struct OptStackEntry *stack = NULL;
|
||||||
|
|
||||||
|
void opt_B(char const chars[2])
|
||||||
|
{
|
||||||
|
lexer_SetBinDigits(chars);
|
||||||
|
}
|
||||||
|
|
||||||
|
void opt_G(char const chars[4])
|
||||||
|
{
|
||||||
|
lexer_SetGfxDigits(chars);
|
||||||
|
}
|
||||||
|
|
||||||
|
void opt_P(uint8_t 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)
|
||||||
|
{
|
||||||
|
switch (s[0]) {
|
||||||
|
case 'b':
|
||||||
|
if (strlen(&s[1]) == 2)
|
||||||
|
opt_B(&s[1]);
|
||||||
|
else
|
||||||
|
error("Must specify exactly 2 characters for option 'b'\n");
|
||||||
|
break;
|
||||||
|
|
||||||
|
case 'g':
|
||||||
|
if (strlen(&s[1]) == 4)
|
||||||
|
opt_G(&s[1]);
|
||||||
|
else
|
||||||
|
error("Must specify exactly 4 characters for option 'g'\n");
|
||||||
|
break;
|
||||||
|
|
||||||
|
case 'p':
|
||||||
|
if (strlen(&s[1]) <= 2) {
|
||||||
|
int result;
|
||||||
|
unsigned int fillchar;
|
||||||
|
|
||||||
|
result = sscanf(&s[1], "%x", &fillchar);
|
||||||
|
if (result != EOF && result != 1)
|
||||||
|
error("Invalid argument for option 'p'\n");
|
||||||
|
else
|
||||||
|
opt_P(fillchar);
|
||||||
|
} else {
|
||||||
|
error("Invalid argument for option 'p'\n");
|
||||||
|
}
|
||||||
|
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:
|
||||||
|
error("Unknown option '%c'\n", s[0]);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void opt_Push(void)
|
||||||
|
{
|
||||||
|
struct OptStackEntry *entry = malloc(sizeof(*entry));
|
||||||
|
|
||||||
|
if (entry == NULL)
|
||||||
|
fatalerror("Failed to alloc option stack entry: %s\n", strerror(errno));
|
||||||
|
|
||||||
|
// Both of these pulled from lexer.h
|
||||||
|
entry->binary[0] = binDigits[0];
|
||||||
|
entry->binary[1] = binDigits[1];
|
||||||
|
|
||||||
|
entry->gbgfx[0] = gfxDigits[0];
|
||||||
|
entry->gbgfx[1] = gfxDigits[1];
|
||||||
|
entry->gbgfx[2] = gfxDigits[2];
|
||||||
|
entry->gbgfx[3] = gfxDigits[3];
|
||||||
|
|
||||||
|
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;
|
||||||
|
stack = entry;
|
||||||
|
}
|
||||||
|
|
||||||
|
void opt_Pop(void)
|
||||||
|
{
|
||||||
|
if (stack == NULL) {
|
||||||
|
error("No entries in the option stack\n");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
struct OptStackEntry *entry = stack;
|
||||||
|
|
||||||
|
opt_B(entry->binary);
|
||||||
|
opt_G(entry->gbgfx);
|
||||||
|
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;
|
||||||
|
free(entry);
|
||||||
|
}
|
||||||
+289
-134
@@ -12,12 +12,12 @@
|
|||||||
|
|
||||||
#include <assert.h>
|
#include <assert.h>
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
|
#include <inttypes.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
#include "asm/asm.h"
|
|
||||||
#include "asm/charmap.h"
|
#include "asm/charmap.h"
|
||||||
#include "asm/fstack.h"
|
#include "asm/fstack.h"
|
||||||
#include "asm/main.h"
|
#include "asm/main.h"
|
||||||
@@ -27,20 +27,20 @@
|
|||||||
#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 {
|
||||||
char tzFilename[_MAX_PATH + 1];
|
struct FileStackNode const *src;
|
||||||
uint32_t nOffset;
|
uint32_t lineNo;
|
||||||
|
uint32_t offset;
|
||||||
struct Section *pcSection;
|
struct Section *pcSection;
|
||||||
uint32_t pcOffset;
|
uint32_t pcOffset;
|
||||||
uint8_t nType;
|
uint8_t type;
|
||||||
uint32_t nRPNSize;
|
uint32_t rpnSize;
|
||||||
uint8_t *pRPN;
|
uint8_t *rpn;
|
||||||
struct Patch *pNext;
|
struct Patch *next;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct Assertion {
|
struct Assertion {
|
||||||
@@ -50,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;
|
||||||
@@ -62,19 +61,17 @@ static uint32_t nbSymbols = 0; /* Length of the above list */
|
|||||||
|
|
||||||
static struct Assertion *assertions = NULL;
|
static struct Assertion *assertions = NULL;
|
||||||
|
|
||||||
|
static struct FileStackNode *fileStackNodes = NULL;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Count the number of sections used in this object
|
* Count the number of sections used in this object
|
||||||
*/
|
*/
|
||||||
static uint32_t countsections(void)
|
static uint32_t countSections(void)
|
||||||
{
|
{
|
||||||
struct Section *pSect;
|
|
||||||
uint32_t count = 0;
|
uint32_t count = 0;
|
||||||
|
|
||||||
pSect = pSectionList;
|
for (struct Section const *sect = sectionList; sect; sect = sect->next)
|
||||||
while (pSect) {
|
|
||||||
count++;
|
count++;
|
||||||
pSect = pSect->pNext;
|
|
||||||
}
|
|
||||||
|
|
||||||
return count;
|
return count;
|
||||||
}
|
}
|
||||||
@@ -82,12 +79,12 @@ static uint32_t countsections(void)
|
|||||||
/*
|
/*
|
||||||
* Count the number of patches used in this object
|
* Count the number of patches used in this object
|
||||||
*/
|
*/
|
||||||
static uint32_t countpatches(struct Section const *pSect)
|
static uint32_t countPatches(struct Section const *sect)
|
||||||
{
|
{
|
||||||
uint32_t r = 0;
|
uint32_t r = 0;
|
||||||
|
|
||||||
for (struct Patch const *patch = pSect->pPatches; patch != NULL;
|
for (struct Patch const *patch = sect->patches; patch != NULL;
|
||||||
patch = patch->pNext)
|
patch = patch->next)
|
||||||
r++;
|
r++;
|
||||||
|
|
||||||
return r;
|
return r;
|
||||||
@@ -96,7 +93,7 @@ static uint32_t countpatches(struct Section const *pSect)
|
|||||||
/**
|
/**
|
||||||
* Count the number of assertions used in this object
|
* Count the number of assertions used in this object
|
||||||
*/
|
*/
|
||||||
static uint32_t countasserts(void)
|
static uint32_t countAsserts(void)
|
||||||
{
|
{
|
||||||
struct Assertion *assert = assertions;
|
struct Assertion *assert = assertions;
|
||||||
uint32_t count = 0;
|
uint32_t count = 0;
|
||||||
@@ -111,128 +108,198 @@ static uint32_t countasserts(void)
|
|||||||
/*
|
/*
|
||||||
* Write a long to a file (little-endian)
|
* Write a long to a file (little-endian)
|
||||||
*/
|
*/
|
||||||
static void fputlong(uint32_t i, FILE *f)
|
static void putlong(uint32_t i, FILE *f)
|
||||||
{
|
{
|
||||||
fputc(i, f);
|
putc(i, f);
|
||||||
fputc(i >> 8, f);
|
putc(i >> 8, f);
|
||||||
fputc(i >> 16, f);
|
putc(i >> 16, f);
|
||||||
fputc(i >> 24, f);
|
putc(i >> 24, f);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Write a NULL-terminated string to a file
|
* Write a NULL-terminated string to a file
|
||||||
*/
|
*/
|
||||||
static void fputstring(char const *s, FILE *f)
|
static void putstring(char const *s, FILE *f)
|
||||||
{
|
{
|
||||||
while (*s)
|
while (*s)
|
||||||
fputc(*s++, f);
|
putc(*s++, f);
|
||||||
fputc(0, f);
|
putc(0, f);
|
||||||
|
}
|
||||||
|
|
||||||
|
static uint32_t getNbFileStackNodes(void)
|
||||||
|
{
|
||||||
|
return fileStackNodes ? fileStackNodes->ID + 1 : 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
void out_RegisterNode(struct FileStackNode *node)
|
||||||
|
{
|
||||||
|
/* If node is not already registered, register it (and parents), and give it a unique ID */
|
||||||
|
while (node->ID == (uint32_t)-1) {
|
||||||
|
node->ID = getNbFileStackNodes();
|
||||||
|
if (node->ID == (uint32_t)-1)
|
||||||
|
fatalerror("Reached too many file stack nodes; try splitting the file up\n");
|
||||||
|
node->next = fileStackNodes;
|
||||||
|
fileStackNodes = node;
|
||||||
|
|
||||||
|
/* Also register the node's parents */
|
||||||
|
node = node->parent;
|
||||||
|
if (!node)
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void out_ReplaceNode(struct FileStackNode *node)
|
||||||
|
{
|
||||||
|
(void)node;
|
||||||
|
#if 0
|
||||||
|
This is code intended to replace a node, which is pretty useless until ref counting is added...
|
||||||
|
|
||||||
|
struct FileStackNode **ptr = &fileStackNodes;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* The linked list is supposed to have decrementing IDs, so iterate with less memory reads,
|
||||||
|
* to hopefully hit the cache less. A debug check is added after, in case a change is made
|
||||||
|
* that breaks this assumption.
|
||||||
|
*/
|
||||||
|
for (uint32_t i = fileStackNodes->ID; i != node->ID; i--)
|
||||||
|
ptr = &(*ptr)->next;
|
||||||
|
assert((*ptr)->ID == node->ID);
|
||||||
|
|
||||||
|
node->next = (*ptr)->next;
|
||||||
|
assert(!node->next || node->next->ID == node->ID - 1); /* Catch inconsistencies early */
|
||||||
|
/* TODO: unreference the node */
|
||||||
|
*ptr = node;
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Return a section's ID
|
* Return a section's ID
|
||||||
*/
|
*/
|
||||||
static uint32_t getsectid(struct Section const *pSect)
|
static uint32_t getsectid(struct Section const *sect)
|
||||||
{
|
{
|
||||||
struct Section const *sec;
|
struct Section const *sec = sectionList;
|
||||||
uint32_t ID = 0;
|
uint32_t ID = 0;
|
||||||
|
|
||||||
sec = pSectionList;
|
|
||||||
|
|
||||||
while (sec) {
|
while (sec) {
|
||||||
if (sec == pSect)
|
if (sec == sect)
|
||||||
return ID;
|
return ID;
|
||||||
ID++;
|
ID++;
|
||||||
sec = sec->pNext;
|
sec = sec->next;
|
||||||
}
|
}
|
||||||
|
|
||||||
fatalerror("Unknown section '%s'", pSect->pzName);
|
fatalerror("Unknown section '%s'\n", sect->name);
|
||||||
}
|
}
|
||||||
|
|
||||||
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;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Write a patch to a file
|
* Write a patch to a file
|
||||||
*/
|
*/
|
||||||
static void writepatch(struct Patch const *pPatch, FILE *f)
|
static void writepatch(struct Patch const *patch, FILE *f)
|
||||||
{
|
{
|
||||||
fputstring(pPatch->tzFilename, f);
|
assert(patch->src->ID != (uint32_t)-1);
|
||||||
fputlong(pPatch->nOffset, f);
|
putlong(patch->src->ID, f);
|
||||||
fputlong(getSectIDIfAny(pPatch->pcSection), f);
|
putlong(patch->lineNo, f);
|
||||||
fputlong(pPatch->pcOffset, f);
|
putlong(patch->offset, f);
|
||||||
fputc(pPatch->nType, f);
|
putlong(getSectIDIfAny(patch->pcSection), f);
|
||||||
fputlong(pPatch->nRPNSize, f);
|
putlong(patch->pcOffset, f);
|
||||||
fwrite(pPatch->pRPN, 1, pPatch->nRPNSize, f);
|
putc(patch->type, f);
|
||||||
|
putlong(patch->rpnSize, f);
|
||||||
|
fwrite(patch->rpn, 1, patch->rpnSize, f);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Write a section to a file
|
* Write a section to a file
|
||||||
*/
|
*/
|
||||||
static void writesection(struct Section const *pSect, FILE *f)
|
static void writesection(struct Section const *sect, FILE *f)
|
||||||
{
|
{
|
||||||
fputstring(pSect->pzName, f);
|
putstring(sect->name, f);
|
||||||
|
|
||||||
fputlong(pSect->size, f);
|
putlong(sect->size, f);
|
||||||
|
|
||||||
bool isUnion = pSect->modifier == SECTION_UNION;
|
bool isUnion = sect->modifier == SECTION_UNION;
|
||||||
bool isFragment = pSect->modifier == SECTION_FRAGMENT;
|
bool isFragment = sect->modifier == SECTION_FRAGMENT;
|
||||||
|
|
||||||
fputc(pSect->nType | isUnion << 7 | isFragment << 6, f);
|
putc(sect->type | isUnion << 7 | isFragment << 6, f);
|
||||||
|
|
||||||
fputlong(pSect->nOrg, f);
|
putlong(sect->org, f);
|
||||||
fputlong(pSect->nBank, f);
|
putlong(sect->bank, f);
|
||||||
fputc(pSect->nAlign, f);
|
putc(sect->align, f);
|
||||||
fputlong(pSect->alignOfs, f);
|
putlong(sect->alignOfs, f);
|
||||||
|
|
||||||
if (sect_HasData(pSect->nType)) {
|
if (sect_HasData(sect->type)) {
|
||||||
fwrite(pSect->tData, 1, pSect->size, f);
|
fwrite(sect->data, 1, sect->size, f);
|
||||||
fputlong(countpatches(pSect), f);
|
putlong(countPatches(sect), f);
|
||||||
|
|
||||||
for (struct Patch const *patch = pSect->pPatches; patch != NULL;
|
for (struct Patch const *patch = sect->patches; patch != NULL;
|
||||||
patch = patch->pNext)
|
patch = patch->next)
|
||||||
writepatch(patch, f);
|
writepatch(patch, 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
|
||||||
*/
|
*/
|
||||||
static void writesymbol(struct Symbol const *sym, FILE *f)
|
static void writesymbol(struct Symbol const *sym, FILE *f)
|
||||||
{
|
{
|
||||||
fputstring(sym->name, f);
|
putstring(sym->name, f);
|
||||||
if (!sym_IsDefined(sym)) {
|
if (!sym_IsDefined(sym)) {
|
||||||
fputc(SYMTYPE_IMPORT, f);
|
putc(SYMTYPE_IMPORT, f);
|
||||||
} else {
|
} else {
|
||||||
fputc(sym->isExported ? SYMTYPE_EXPORT : SYMTYPE_LOCAL, f);
|
assert(sym->src->ID != (uint32_t)-1);
|
||||||
fputstring(sym->fileName, f);
|
|
||||||
fputlong(sym->fileLine, f);
|
putc(sym->isExported ? SYMTYPE_EXPORT : SYMTYPE_LOCAL, f);
|
||||||
fputlong(getSectIDIfAny(sym_GetSection(sym)), f);
|
putlong(sym->src->ID, f);
|
||||||
fputlong(sym->value, f);
|
putlong(sym->fileLine, f);
|
||||||
|
putlong(getSectIDIfAny(sym_GetSection(sym)), f);
|
||||||
|
putlong(sym->value, f);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void registerSymbol(struct Symbol *sym)
|
||||||
|
{
|
||||||
|
*objectSymbolsTail = sym;
|
||||||
|
objectSymbolsTail = &sym->next;
|
||||||
|
out_RegisterNode(sym->src);
|
||||||
|
if (nbSymbols == (uint32_t)-1)
|
||||||
|
fatalerror("Registered too many symbols (%" PRIu32
|
||||||
|
"); try splitting up your files\n", (uint32_t)-1);
|
||||||
|
sym->ID = nbSymbols++;
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Returns a symbol's ID within the object file
|
* Returns a symbol's ID within the object file
|
||||||
* If the symbol does not have one, one is assigned by registering the symbol
|
* If the symbol does not have one, one is assigned by registering the symbol
|
||||||
*/
|
*/
|
||||||
static uint32_t getSymbolID(struct Symbol *sym)
|
static uint32_t getSymbolID(struct Symbol *sym)
|
||||||
{
|
{
|
||||||
if (sym->ID == -1) {
|
if (sym->ID == (uint32_t)-1 && !sym_IsPC(sym))
|
||||||
sym->ID = nbSymbols++;
|
registerSymbol(sym);
|
||||||
|
|
||||||
*objectSymbolsTail = sym;
|
|
||||||
objectSymbolsTail = &sym->next;
|
|
||||||
}
|
|
||||||
return sym->ID;
|
return sym->ID;
|
||||||
}
|
}
|
||||||
|
|
||||||
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++]
|
||||||
@@ -240,6 +307,11 @@ static void writerpn(uint8_t *rpnexpr, uint32_t *rpnptr, uint8_t *rpn,
|
|||||||
uint8_t rpndata = popbyte();
|
uint8_t rpndata = popbyte();
|
||||||
|
|
||||||
switch (rpndata) {
|
switch (rpndata) {
|
||||||
|
struct Symbol *sym;
|
||||||
|
uint32_t value;
|
||||||
|
uint8_t b;
|
||||||
|
size_t i;
|
||||||
|
|
||||||
case RPN_CONST:
|
case RPN_CONST:
|
||||||
writebyte(RPN_CONST);
|
writebyte(RPN_CONST);
|
||||||
writebyte(popbyte());
|
writebyte(popbyte());
|
||||||
@@ -247,32 +319,38 @@ static void writerpn(uint8_t *rpnexpr, uint32_t *rpnptr, uint8_t *rpn,
|
|||||||
writebyte(popbyte());
|
writebyte(popbyte());
|
||||||
writebyte(popbyte());
|
writebyte(popbyte());
|
||||||
break;
|
break;
|
||||||
case RPN_SYM:
|
|
||||||
{
|
|
||||||
for (unsigned int i = -1; (tzSym[++i] = popbyte()); )
|
|
||||||
;
|
|
||||||
struct Symbol *sym = sym_FindSymbol(tzSym);
|
|
||||||
uint32_t value;
|
|
||||||
|
|
||||||
|
case RPN_SYM:
|
||||||
|
i = 0;
|
||||||
|
do {
|
||||||
|
symName[i] = popbyte();
|
||||||
|
} while (symName[i++]);
|
||||||
|
|
||||||
|
// The symbol name is always written expanded
|
||||||
|
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);
|
||||||
}
|
}
|
||||||
|
|
||||||
writebyte(value & 0xFF);
|
writebyte(value & 0xFF);
|
||||||
writebyte(value >> 8);
|
writebyte(value >> 8);
|
||||||
writebyte(value >> 16);
|
writebyte(value >> 16);
|
||||||
writebyte(value >> 24);
|
writebyte(value >> 24);
|
||||||
break;
|
break;
|
||||||
}
|
|
||||||
case RPN_BANK_SYM:
|
case RPN_BANK_SYM:
|
||||||
{
|
i = 0;
|
||||||
for (unsigned int i = -1; (tzSym[++i] = popbyte()); )
|
do {
|
||||||
;
|
symName[i] = popbyte();
|
||||||
struct Symbol *sym = sym_FindSymbol(tzSym);
|
} while (symName[i++]);
|
||||||
uint32_t value = getSymbolID(sym);
|
|
||||||
|
// The symbol name is always written expanded
|
||||||
|
sym = sym_FindExactSymbol(symName);
|
||||||
|
value = getSymbolID(sym);
|
||||||
|
|
||||||
writebyte(RPN_BANK_SYM);
|
writebyte(RPN_BANK_SYM);
|
||||||
writebyte(value & 0xFF);
|
writebyte(value & 0xFF);
|
||||||
@@ -280,18 +358,31 @@ static void writerpn(uint8_t *rpnexpr, uint32_t *rpnptr, uint8_t *rpn,
|
|||||||
writebyte(value >> 16);
|
writebyte(value >> 16);
|
||||||
writebyte(value >> 24);
|
writebyte(value >> 24);
|
||||||
break;
|
break;
|
||||||
}
|
|
||||||
case RPN_BANK_SECT:
|
|
||||||
{
|
|
||||||
uint8_t b;
|
|
||||||
|
|
||||||
|
case RPN_BANK_SECT:
|
||||||
writebyte(RPN_BANK_SECT);
|
writebyte(RPN_BANK_SECT);
|
||||||
do {
|
do {
|
||||||
b = popbyte();
|
b = popbyte();
|
||||||
writebyte(b);
|
writebyte(b);
|
||||||
} 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;
|
||||||
@@ -303,42 +394,61 @@ static void writerpn(uint8_t *rpnexpr, uint32_t *rpnptr, uint8_t *rpn,
|
|||||||
|
|
||||||
/*
|
/*
|
||||||
* Allocate a new patch structure and link it into the list
|
* Allocate a new patch structure and link it into the list
|
||||||
|
* WARNING: all patches are assumed to eventually be written, so the file stack node is registered
|
||||||
*/
|
*/
|
||||||
static struct Patch *allocpatch(uint32_t type, struct Expression const *expr,
|
static struct Patch *allocpatch(uint32_t type, struct Expression const *expr, uint32_t ofs)
|
||||||
uint32_t ofs)
|
|
||||||
{
|
{
|
||||||
struct Patch *pPatch = malloc(sizeof(struct Patch));
|
struct Patch *patch = malloc(sizeof(struct Patch));
|
||||||
|
uint32_t rpnSize = expr->isKnown ? 5 : expr->rpnPatchSize;
|
||||||
|
struct FileStackNode *node = fstk_GetFileStack();
|
||||||
|
|
||||||
if (!pPatch)
|
if (!patch)
|
||||||
fatalerror("No memory for patch: %s", strerror(errno));
|
fatalerror("No memory for patch: %s\n", strerror(errno));
|
||||||
pPatch->pRPN = malloc(sizeof(*pPatch->pRPN) * expr->nRPNPatchSize);
|
|
||||||
|
|
||||||
if (!pPatch->pRPN)
|
patch->rpn = malloc(sizeof(*patch->rpn) * rpnSize);
|
||||||
fatalerror("No memory for patch's RPN expression: %s",
|
if (!patch->rpn)
|
||||||
strerror(errno));
|
fatalerror("No memory for patch's RPN rpnSize: %s\n", strerror(errno));
|
||||||
|
|
||||||
pPatch->nRPNSize = 0;
|
patch->type = type;
|
||||||
pPatch->nType = type;
|
patch->src = node;
|
||||||
fstk_DumpToStr(pPatch->tzFilename, sizeof(pPatch->tzFilename));
|
out_RegisterNode(node);
|
||||||
pPatch->nOffset = ofs;
|
patch->lineNo = lexer_GetLineNo();
|
||||||
pPatch->pcSection = sect_GetSymbolSection();
|
patch->offset = ofs;
|
||||||
pPatch->pcOffset = curOffset;
|
patch->pcSection = sect_GetSymbolSection();
|
||||||
|
patch->pcOffset = sect_GetSymbolOffset();
|
||||||
|
|
||||||
writerpn(pPatch->pRPN, &pPatch->nRPNSize, expr->tRPN, expr->nRPNLength);
|
/* If the rpnSize's value is known, output a constant RPN rpnSize directly */
|
||||||
assert(pPatch->nRPNSize == expr->nRPNPatchSize);
|
if (expr->isKnown) {
|
||||||
|
patch->rpnSize = rpnSize;
|
||||||
|
/* Make sure to update `rpnSize` above if modifying this! */
|
||||||
|
patch->rpn[0] = RPN_CONST;
|
||||||
|
patch->rpn[1] = (uint32_t)(expr->val) & 0xFF;
|
||||||
|
patch->rpn[2] = (uint32_t)(expr->val) >> 8;
|
||||||
|
patch->rpn[3] = (uint32_t)(expr->val) >> 16;
|
||||||
|
patch->rpn[4] = (uint32_t)(expr->val) >> 24;
|
||||||
|
} else {
|
||||||
|
patch->rpnSize = 0;
|
||||||
|
writerpn(patch->rpn, &patch->rpnSize, expr->rpn, expr->rpnLength);
|
||||||
|
}
|
||||||
|
assert(patch->rpnSize == rpnSize);
|
||||||
|
|
||||||
return pPatch;
|
return patch;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Create a new patch (includes the rpn expr)
|
* Create a new patch (includes the rpn expr)
|
||||||
*/
|
*/
|
||||||
void out_CreatePatch(uint32_t type, struct Expression const *expr, uint32_t ofs)
|
void out_CreatePatch(uint32_t type, struct Expression const *expr, uint32_t ofs, uint32_t pcShift)
|
||||||
{
|
{
|
||||||
struct Patch *pPatch = allocpatch(type, expr, ofs);
|
struct Patch *patch = allocpatch(type, expr, ofs);
|
||||||
|
|
||||||
pPatch->pNext = pCurrentSection->pPatches;
|
// If the patch had a quantity of bytes output before it,
|
||||||
pCurrentSection->pPatches = pPatch;
|
// PC is not at the patch's location, but at the location
|
||||||
|
// before those bytes.
|
||||||
|
patch->pcOffset -= pcShift;
|
||||||
|
|
||||||
|
patch->next = currentSection->patches;
|
||||||
|
currentSection->patches = patch;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -368,16 +478,40 @@ bool out_CreateAssert(enum AssertionType type, struct Expression const *expr,
|
|||||||
static void writeassert(struct Assertion *assert, FILE *f)
|
static void writeassert(struct Assertion *assert, FILE *f)
|
||||||
{
|
{
|
||||||
writepatch(assert->patch, f);
|
writepatch(assert->patch, f);
|
||||||
fputstring(assert->message, f);
|
putstring(assert->message, f);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void registerExportedSymbol(struct Symbol *symbol, void *arg)
|
static void freeassert(struct Assertion *assert)
|
||||||
{
|
{
|
||||||
(void)arg;
|
free(assert->patch->rpn);
|
||||||
if (sym_IsExported(symbol) && symbol->ID == -1) {
|
free(assert->patch);
|
||||||
*objectSymbolsTail = symbol;
|
free(assert);
|
||||||
objectSymbolsTail = &symbol->next;
|
}
|
||||||
nbSymbols++;
|
|
||||||
|
static void writeFileStackNode(struct FileStackNode const *node, FILE *f)
|
||||||
|
{
|
||||||
|
putlong(node->parent ? node->parent->ID : (uint32_t)-1, f);
|
||||||
|
putlong(node->lineNo, f);
|
||||||
|
putc(node->type, f);
|
||||||
|
if (node->type != NODE_REPT) {
|
||||||
|
putstring(((struct FileStackNamedNode const *)node)->name, f);
|
||||||
|
} else {
|
||||||
|
struct FileStackReptNode const *reptNode = (struct FileStackReptNode const *)node;
|
||||||
|
|
||||||
|
putlong(reptNode->reptDepth, f);
|
||||||
|
/* Iters are stored by decreasing depth, so reverse the order for output */
|
||||||
|
for (uint32_t i = reptNode->reptDepth; i--; )
|
||||||
|
putlong(reptNode->iters[i], f);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static void registerUnregisteredSymbol(struct Symbol *symbol, void *arg)
|
||||||
|
{
|
||||||
|
(void)arg; // sym_ForEach requires a void* parameter, but we are not using it.
|
||||||
|
|
||||||
|
// Check for symbol->src, to skip any built-in symbol from rgbasm
|
||||||
|
if (symbol->src && symbol->ID == (uint32_t)-1) {
|
||||||
|
registerSymbol(symbol);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -386,30 +520,51 @@ static void registerExportedSymbol(struct Symbol *symbol, void *arg)
|
|||||||
*/
|
*/
|
||||||
void out_WriteObject(void)
|
void out_WriteObject(void)
|
||||||
{
|
{
|
||||||
FILE *f = fopen(tzObjectname, "wb");
|
FILE *f;
|
||||||
|
if (strcmp(objectName, "-") != 0)
|
||||||
|
f = fopen(objectName, "wb");
|
||||||
|
else
|
||||||
|
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 exported symbols that weren't written above */
|
/* Also write symbols that weren't written above */
|
||||||
sym_ForEach(registerExportedSymbol, NULL);
|
sym_ForEach(registerUnregisteredSymbol, NULL);
|
||||||
|
|
||||||
fprintf(f, RGBDS_OBJECT_VERSION_STRING, RGBDS_OBJECT_VERSION_NUMBER);
|
fprintf(f, RGBDS_OBJECT_VERSION_STRING, RGBDS_OBJECT_VERSION_NUMBER);
|
||||||
fputlong(RGBDS_OBJECT_REV, f);
|
putlong(RGBDS_OBJECT_REV, f);
|
||||||
|
|
||||||
fputlong(nbSymbols, f);
|
putlong(nbSymbols, f);
|
||||||
fputlong(countsections(), f);
|
putlong(countSections(), f);
|
||||||
|
|
||||||
|
putlong(getNbFileStackNodes(), f);
|
||||||
|
for (struct FileStackNode const *node = fileStackNodes; node; node = node->next) {
|
||||||
|
writeFileStackNode(node, f);
|
||||||
|
if (node->next && node->next->ID != node->ID - 1)
|
||||||
|
fatalerror("Internal error: fstack node #%" PRIu32 " follows #%" PRIu32
|
||||||
|
". Please report this to the developers!\n",
|
||||||
|
node->next->ID, node->ID);
|
||||||
|
}
|
||||||
|
|
||||||
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->pNext)
|
for (struct Section *sect = sectionList; sect; sect = sect->next) {
|
||||||
writesection(sect, f);
|
writesection(sect, f);
|
||||||
|
freesection(sect);
|
||||||
|
}
|
||||||
|
|
||||||
|
putlong(countAsserts(), f);
|
||||||
|
struct Assertion *assert = assertions;
|
||||||
|
|
||||||
|
while (assert != NULL) {
|
||||||
|
struct Assertion *next = assert->next;
|
||||||
|
|
||||||
fputlong(countasserts(), f);
|
|
||||||
for (struct Assertion *assert = assertions; assert;
|
|
||||||
assert = assert->next)
|
|
||||||
writeassert(assert, f);
|
writeassert(assert, f);
|
||||||
|
freeassert(assert);
|
||||||
|
assert = next;
|
||||||
|
}
|
||||||
|
|
||||||
fclose(f);
|
fclose(f);
|
||||||
}
|
}
|
||||||
@@ -419,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);
|
||||||
}
|
}
|
||||||
|
|||||||
+2267
File diff suppressed because it is too large
Load Diff
+62
-22
@@ -1,11 +1,11 @@
|
|||||||
.\"
|
.\"
|
||||||
.\" This file is part of RGBDS.
|
.\" This file is part of RGBDS.
|
||||||
.\"
|
.\"
|
||||||
.\" Copyright (c) 2010-2019, Anthony J. Bentley and RGBDS contributors.
|
.\" Copyright (c) 2010-2021, Anthony J. Bentley and RGBDS contributors.
|
||||||
.\"
|
.\"
|
||||||
.\" SPDX-License-Identifier: MIT
|
.\" SPDX-License-Identifier: MIT
|
||||||
.\"
|
.\"
|
||||||
.Dd July 8, 2019
|
.Dd March 28, 2021
|
||||||
.Dt RGBASM 1
|
.Dt RGBASM 1
|
||||||
.Os
|
.Os
|
||||||
.Sh NAME
|
.Sh NAME
|
||||||
@@ -112,9 +112,9 @@ from erroring out when dependency files are deleted.
|
|||||||
Add a target to the rules emitted by
|
Add a target to the rules emitted by
|
||||||
.Fl M .
|
.Fl M .
|
||||||
The exact string provided will be written, including spaces and special characters.
|
The exact string provided will be written, including spaces and special characters.
|
||||||
.Dl Fl MT fileA Fl MT fileB
|
.Dl Fl MT No fileA Fl MT No fileB
|
||||||
is equivalent to
|
is equivalent to
|
||||||
.Dl Fl MT 'fileA fileB' .
|
.Dl Fl MT No 'fileA fileB' .
|
||||||
If neither this nor
|
If neither this nor
|
||||||
.Fl MQ
|
.Fl MQ
|
||||||
is specified, the output file name is used.
|
is specified, the output file name is used.
|
||||||
@@ -179,9 +179,9 @@ Enables literally every warning.
|
|||||||
.Pp
|
.Pp
|
||||||
The following warnings are actual warning flags; with each description, the corresponding warning flag is included.
|
The following warnings are actual warning flags; with each description, the corresponding warning flag is included.
|
||||||
Note that each of these flag also has a negation (for example,
|
Note that each of these flag also has a negation (for example,
|
||||||
.Fl Wempty-entry
|
.Fl Wcharmap-redef
|
||||||
enables the warning that
|
enables the warning that
|
||||||
.Fl Wno-empty-entry
|
.Fl Wno-charmap-redef
|
||||||
disables).
|
disables).
|
||||||
Only the non-default flag is listed here.
|
Only the non-default flag is listed here.
|
||||||
Ignoring the
|
Ignoring the
|
||||||
@@ -189,7 +189,7 @@ Ignoring the
|
|||||||
prefix, entries are listed alphabetically.
|
prefix, entries are listed alphabetically.
|
||||||
.Bl -tag -width Ds
|
.Bl -tag -width Ds
|
||||||
.It Fl Wno-assert
|
.It Fl Wno-assert
|
||||||
Warns when
|
Warn when
|
||||||
.Ic WARN Ns No -type
|
.Ic WARN Ns No -type
|
||||||
assertions fail. (See
|
assertions fail. (See
|
||||||
.Dq Aborting the assembly process
|
.Dq Aborting the assembly process
|
||||||
@@ -197,20 +197,34 @@ in
|
|||||||
.Xr rgbasm 5
|
.Xr rgbasm 5
|
||||||
for
|
for
|
||||||
.Ic ASSERT ) .
|
.Ic ASSERT ) .
|
||||||
|
.It Fl Wbackwards-for
|
||||||
|
Warn when
|
||||||
|
.Ic FOR
|
||||||
|
loops have their start and stop values switched according to the step value.
|
||||||
|
This warning is enabled by
|
||||||
|
.Fl Wall .
|
||||||
.It Fl Wbuiltin-args
|
.It Fl Wbuiltin-args
|
||||||
Warn about incorrect arguments to built-in functions, such as
|
Warn about incorrect arguments to built-in functions, such as
|
||||||
.Fn STRSUB
|
.Fn STRSUB
|
||||||
with indexes outside of the string's bounds.
|
with indexes outside of the string's bounds.
|
||||||
This warning is enabled by
|
This warning is enabled by
|
||||||
.Fl Wall .
|
.Fl Wall .
|
||||||
|
.It Fl Wcharmap-redef
|
||||||
|
Warn when re-defining a charmap mapping.
|
||||||
|
This warning is enabled by
|
||||||
|
.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-entry
|
.It Fl Wempty-macro-arg
|
||||||
Warn when an empty entry is encountered in a
|
Warn when a macro argument is empty.
|
||||||
.Ic db , dw , dl
|
|
||||||
list.
|
|
||||||
This warning is enabled by
|
This warning is enabled by
|
||||||
.Fl Wextra .
|
.Fl Wextra .
|
||||||
|
.It Fl Wempty-strrpl
|
||||||
|
Warn when
|
||||||
|
.Fn STRRPL
|
||||||
|
is called with an empty string as its second argument (the substring to replace).
|
||||||
|
This warning is enabled by
|
||||||
|
.Fl Wall .
|
||||||
.It Fl Wlarge-constant
|
.It Fl Wlarge-constant
|
||||||
Warn when a constant too large to fit in a signed 32-bit integer is encountered.
|
Warn when a constant too large to fit in a signed 32-bit integer is encountered.
|
||||||
This warning is enabled by
|
This warning is enabled by
|
||||||
@@ -219,21 +233,47 @@ This warning is enabled by
|
|||||||
Warn when a string too long to fit in internal buffers is encountered.
|
Warn when a string too long to fit in internal buffers is encountered.
|
||||||
This warning is enabled by
|
This warning is enabled by
|
||||||
.Fl Wall .
|
.Fl Wall .
|
||||||
|
.It Fl Wmacro-shift
|
||||||
|
Warn when shifting macro arguments past their limits.
|
||||||
|
This warning is enabled by
|
||||||
|
.Fl Wextra .
|
||||||
.It Fl Wno-obsolete
|
.It Fl Wno-obsolete
|
||||||
Warn when obsolete constructs such as the
|
Warn when obsolete constructs such as the
|
||||||
.Ic jp [hl]
|
.Ic _PI
|
||||||
instruction or
|
constant or
|
||||||
.Ic HOME
|
.Ic PRINTT
|
||||||
section type 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
|
||||||
@@ -260,7 +300,7 @@ and then
|
|||||||
.Xr rgbfix 1 .
|
.Xr rgbfix 1 .
|
||||||
.Sh BUGS
|
.Sh BUGS
|
||||||
Please report bugs on
|
Please report bugs on
|
||||||
.Lk https://github.com/rednex/rgbds/issues GitHub .
|
.Lk https://github.com/gbdev/rgbds/issues GitHub .
|
||||||
.Sh SEE ALSO
|
.Sh SEE ALSO
|
||||||
.Xr rgbasm 5 ,
|
.Xr rgbasm 5 ,
|
||||||
.Xr rgbfix 1 ,
|
.Xr rgbfix 1 ,
|
||||||
@@ -272,4 +312,4 @@ Please report bugs on
|
|||||||
.Nm
|
.Nm
|
||||||
was originally written by Carsten S\(/orensen as part of the ASMotor package, and was later packaged in RGBDS by Justin Lloyd.
|
was originally written by Carsten S\(/orensen as part of the ASMotor package, and was later packaged in RGBDS by Justin Lloyd.
|
||||||
It is now maintained by a number of contributors at
|
It is now maintained by a number of contributors at
|
||||||
.Lk https://github.com/rednex/rgbds .
|
.Lk https://github.com/gbdev/rgbds .
|
||||||
|
|||||||
+920
-400
File diff suppressed because it is too large
Load Diff
+307
-206
@@ -13,17 +13,21 @@
|
|||||||
#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 <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
#include "asm/asm.h"
|
|
||||||
#include "asm/main.h"
|
#include "asm/main.h"
|
||||||
|
#include "asm/output.h"
|
||||||
#include "asm/rpn.h"
|
#include "asm/rpn.h"
|
||||||
#include "asm/section.h"
|
#include "asm/section.h"
|
||||||
#include "asm/symbol.h"
|
#include "asm/symbol.h"
|
||||||
#include "asm/warning.h"
|
#include "asm/warning.h"
|
||||||
|
|
||||||
|
#include "opmath.h"
|
||||||
|
|
||||||
/* Makes an expression "not known", also setting its error message */
|
/* Makes an expression "not known", also setting its error message */
|
||||||
#define makeUnknown(expr_, ...) do { \
|
#define makeUnknown(expr_, ...) do { \
|
||||||
struct Expression *_expr = expr_; \
|
struct Expression *_expr = expr_; \
|
||||||
@@ -31,7 +35,7 @@
|
|||||||
/* If we had `asprintf` this would be great, but alas. */ \
|
/* If we had `asprintf` this would be great, but alas. */ \
|
||||||
_expr->reason = malloc(128); /* Use an initial reasonable size */ \
|
_expr->reason = malloc(128); /* Use an initial reasonable size */ \
|
||||||
if (!_expr->reason) \
|
if (!_expr->reason) \
|
||||||
fatalerror("Can't allocate err string: %s", strerror(errno)); \
|
fatalerror("Can't allocate err string: %s\n", strerror(errno)); \
|
||||||
int size = snprintf(_expr->reason, 128, __VA_ARGS__); \
|
int size = snprintf(_expr->reason, 128, __VA_ARGS__); \
|
||||||
if (size >= 128) { /* If this wasn't enough, try again */ \
|
if (size >= 128) { /* If this wasn't enough, try again */ \
|
||||||
_expr->reason = realloc(_expr->reason, size + 1); \
|
_expr->reason = realloc(_expr->reason, size + 1); \
|
||||||
@@ -42,46 +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 */
|
||||||
else if (expr->nRPNCapacity >= MAXRPNLEN)
|
while (expr->rpnCapacity - expr->rpnLength < size) {
|
||||||
/*
|
if (expr->rpnCapacity >= MAXRPNLEN)
|
||||||
* To avoid generating humongous object files, cap the
|
/*
|
||||||
* size of RPN expressions
|
* To avoid generating humongous object files, cap the
|
||||||
*/
|
* size of RPN expressions
|
||||||
fatalerror("RPN expression cannot grow larger than %lu bytes",
|
*/
|
||||||
(unsigned long)MAXRPNLEN);
|
fatalerror("RPN expression cannot grow larger than "
|
||||||
else if (expr->nRPNCapacity > MAXRPNLEN / 2)
|
EXPAND_AND_STR(MAXRPNLEN) " bytes\n");
|
||||||
expr->nRPNCapacity = MAXRPNLEN;
|
else if (expr->rpnCapacity > MAXRPNLEN / 2)
|
||||||
else
|
expr->rpnCapacity = MAXRPNLEN;
|
||||||
expr->nRPNCapacity *= 2;
|
else
|
||||||
expr->tRPN = realloc(expr->tRPN, expr->nRPNCapacity);
|
expr->rpnCapacity *= 2;
|
||||||
|
}
|
||||||
|
expr->rpn = realloc(expr->rpn, expr->rpnCapacity);
|
||||||
|
|
||||||
if (!expr->tRPN)
|
if (!expr->rpn)
|
||||||
fatalerror("Failed to grow RPN expression: %s",
|
fatalerror("Failed to grow RPN expression: %s\n", strerror(errno));
|
||||||
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;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@@ -89,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);
|
||||||
}
|
}
|
||||||
@@ -100,43 +105,31 @@ 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 *tzSym)
|
void rpn_Symbol(struct Expression *expr, char const *symName)
|
||||||
{
|
{
|
||||||
struct Symbol *sym = sym_FindSymbol(tzSym);
|
struct Symbol *sym = sym_FindScopedSymbol(symName);
|
||||||
|
|
||||||
if (sym_IsPC(sym) && !sect_GetSymbolSection()) {
|
if (sym_IsPC(sym) && !sect_GetSymbolSection()) {
|
||||||
yyerror("PC has no value outside a section");
|
error("PC has no value outside a section\n");
|
||||||
rpn_Number(expr, 0);
|
rpn_Number(expr, 0);
|
||||||
} else if (!sym || !sym_IsConstant(sym)) {
|
} else if (!sym || !sym_IsConstant(sym)) {
|
||||||
rpn_Init(expr);
|
rpn_Init(expr);
|
||||||
expr->isSymbol = true;
|
expr->isSymbol = true;
|
||||||
|
|
||||||
sym_Ref(tzSym);
|
makeUnknown(expr, sym_IsPC(sym) ? "PC is not constant at assembly time"
|
||||||
makeUnknown(expr, sym_IsPC(sym)
|
: "'%s' is not constant at assembly time", symName);
|
||||||
? "PC is not constant at assembly time"
|
sym = sym_Ref(symName);
|
||||||
: "'%s' is not constant at assembly time",
|
expr->rpnPatchSize += 5; /* 1-byte opcode + 4-byte symbol ID */
|
||||||
tzSym);
|
|
||||||
expr->nRPNPatchSize += 5; /* 1-byte opcode + 4-byte symbol ID */
|
|
||||||
|
|
||||||
size_t nameLen = strlen(tzSym) + 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, tzSym, nameLen);
|
memcpy(ptr, sym->name, nameLen);
|
||||||
|
|
||||||
/* RGBLINK assumes PC is at the byte being computed... */
|
|
||||||
if (sym_IsPC(sym) && nPCOffset) {
|
|
||||||
struct Expression pc = *expr, offset;
|
|
||||||
|
|
||||||
rpn_Number(&offset, nPCOffset);
|
|
||||||
rpn_BinaryOp(RPN_SUB, expr, &pc, &offset);
|
|
||||||
if (!rpn_isKnown(expr))
|
|
||||||
expr->isSymbol = true;
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
rpn_Number(expr, sym_GetConstantValue(tzSym));
|
rpn_Number(expr, sym_GetConstantValue(symName));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -144,21 +137,21 @@ void rpn_BankSelf(struct Expression *expr)
|
|||||||
{
|
{
|
||||||
rpn_Init(expr);
|
rpn_Init(expr);
|
||||||
|
|
||||||
if (!pCurrentSection) {
|
if (!currentSection) {
|
||||||
yyerror("PC has no bank outside a section");
|
error("PC has no bank outside a section\n");
|
||||||
expr->nVal = 1;
|
expr->val = 1;
|
||||||
} else if (pCurrentSection->nBank == -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->nBank;
|
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_FindSymbol(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)) {
|
||||||
@@ -168,46 +161,83 @@ void rpn_BankSymbol(struct Expression *expr, char const *tzSym)
|
|||||||
|
|
||||||
rpn_Init(expr);
|
rpn_Init(expr);
|
||||||
if (sym && !sym_IsLabel(sym)) {
|
if (sym && !sym_IsLabel(sym)) {
|
||||||
yyerror("BANK argument must be a label");
|
error("BANK argument must be a label\n");
|
||||||
} else {
|
} else {
|
||||||
sym_Ref(tzSym);
|
sym = sym_Ref(symName);
|
||||||
if (!sym)
|
assert(sym); // If the symbol didn't exist, it should have been created
|
||||||
/* If the symbol didn't exist, `sym_Ref` created it */
|
|
||||||
sym = sym_FindSymbol(tzSym);
|
|
||||||
|
|
||||||
if (sym_GetSection(sym) && sym_GetSection(sym)->nBank != -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)->nBank;
|
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(tzSym) + 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);
|
||||||
*ptr++ = RPN_BANK_SYM;
|
*ptr++ = RPN_BANK_SYM;
|
||||||
memcpy(ptr, tzSym, nameLen);
|
memcpy(ptr, sym->name, nameLen);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
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->nBank != -1) {
|
if (section && section->bank != (uint32_t)-1) {
|
||||||
expr->nVal = pSection->nBank;
|
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);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -217,14 +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) {
|
||||||
yyerror("Source address $%" PRIx32 " not between $FF00 to $FFFF",
|
error("Source address $%" PRIx32 " not between $FF00 to $FFFF\n", expr->val);
|
||||||
expr->nVal);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -234,94 +263,127 @@ 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)
|
||||||
yyerror("Invalid address $%" PRIx32 " for RST",
|
error("Invalid address $%" PRIx32 " for RST\n", expr->val);
|
||||||
expr->nVal);
|
|
||||||
/* 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;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static int32_t shift(int32_t shiftee, int32_t amount)
|
struct Symbol const *rpn_SymbolOf(struct Expression const *expr)
|
||||||
{
|
|
||||||
if (amount >= 0) {
|
|
||||||
// Left shift
|
|
||||||
if (amount >= 32) {
|
|
||||||
warning(WARNING_SHIFT_AMOUNT, "Shifting left by large amount %" PRId32,
|
|
||||||
amount);
|
|
||||||
return 0;
|
|
||||||
|
|
||||||
} else {
|
|
||||||
/*
|
|
||||||
* Use unsigned to force a bitwise shift
|
|
||||||
* Casting back is OK because the types implement two's
|
|
||||||
* complement behavior
|
|
||||||
*/
|
|
||||||
return (uint32_t)shiftee << amount;
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
// Right shift
|
|
||||||
amount = -amount;
|
|
||||||
if (amount >= 32) {
|
|
||||||
warning(WARNING_SHIFT_AMOUNT, "Shifting right by large amount %" PRId32,
|
|
||||||
amount);
|
|
||||||
return shiftee < 0 ? -1 : 0;
|
|
||||||
|
|
||||||
} else if (shiftee >= 0) {
|
|
||||||
return shiftee >> amount;
|
|
||||||
|
|
||||||
} else {
|
|
||||||
/*
|
|
||||||
* The C standard leaves shifting right negative values
|
|
||||||
* undefined, so use a left shift manually sign-extended
|
|
||||||
*/
|
|
||||||
return (uint32_t)shiftee >> amount
|
|
||||||
| -(UINT32_C(1) << (32 - amount));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
static struct Symbol const *symbolOf(struct Expression const *expr)
|
|
||||||
{
|
{
|
||||||
if (!rpn_isSymbol(expr))
|
if (!rpn_isSymbol(expr))
|
||||||
return NULL;
|
return NULL;
|
||||||
return sym_FindSymbol((char *)expr->tRPN + 1);
|
return sym_FindScopedSymbol((char const *)expr->rpn + 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool rpn_IsDiffConstant(struct Expression const *src, struct Symbol const *sym)
|
||||||
|
{
|
||||||
|
/* Check if both expressions only refer to a single symbol */
|
||||||
|
struct Symbol const *sym1 = rpn_SymbolOf(src);
|
||||||
|
|
||||||
|
if (!sym1 || !sym || sym1->type != SYM_LABEL || sym->type != SYM_LABEL)
|
||||||
|
return false;
|
||||||
|
|
||||||
|
struct Section const *section1 = sym_GetSection(sym1);
|
||||||
|
struct Section const *section2 = sym_GetSection(sym);
|
||||||
|
return section1 && (section1 == section2);
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool isDiffConstant(struct Expression const *src1,
|
static bool isDiffConstant(struct Expression const *src1,
|
||||||
struct Expression const *src2)
|
struct Expression const *src2)
|
||||||
{
|
{
|
||||||
/* Check if both expressions only refer to a single symbol */
|
return rpn_IsDiffConstant(src1, rpn_SymbolOf(src2));
|
||||||
struct Symbol const *symbol1 = symbolOf(src1);
|
}
|
||||||
struct Symbol const *symbol2 = symbolOf(src2);
|
|
||||||
|
|
||||||
if (!symbol1 || !symbol2
|
/**
|
||||||
|| symbol1->type != SYM_LABEL || symbol2->type != SYM_LABEL)
|
* Attempts to compute a constant binary AND from non-constant operands
|
||||||
return false;
|
* 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;
|
||||||
|
|
||||||
return sym_GetSection(symbol1) == sym_GetSection(symbol2);
|
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;
|
||||||
@@ -329,89 +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, "Shifting left by negative amount %" PRId32,
|
warning(WARNING_SHIFT_AMOUNT,
|
||||||
src2->nVal);
|
"Shifting left by negative amount %" PRId32 "\n",
|
||||||
|
src2->val);
|
||||||
|
|
||||||
expr->nVal = shift(src1->nVal, src2->nVal);
|
if (src2->val >= 32)
|
||||||
|
warning(WARNING_SHIFT_AMOUNT,
|
||||||
|
"Shifting left by large amount %" PRId32 "\n", src2->val);
|
||||||
|
|
||||||
|
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 negative value %" PRId32,
|
warning(WARNING_SHIFT,
|
||||||
src1->nVal);
|
"Shifting right negative value %" PRId32 "\n", src1->val);
|
||||||
|
|
||||||
if (src2->nVal < 0)
|
if (src2->val < 0)
|
||||||
warning(WARNING_SHIFT_AMOUNT, "Shifting right by negative amount %" PRId32,
|
warning(WARNING_SHIFT_AMOUNT,
|
||||||
src2->nVal);
|
"Shifting right by negative amount %" PRId32 "\n",
|
||||||
|
src2->val);
|
||||||
|
|
||||||
expr->nVal = shift(src1->nVal, -src2->nVal);
|
if (src2->val >= 32)
|
||||||
|
warning(WARNING_SHIFT_AMOUNT,
|
||||||
|
"Shifting right by large amount %" PRId32 "\n",
|
||||||
|
src2->val);
|
||||||
|
|
||||||
|
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");
|
fatalerror("Division by zero\n");
|
||||||
|
|
||||||
if (src1->nVal == INT32_MIN
|
if (src1->val == INT32_MIN && src2->val == -1) {
|
||||||
&& src2->nVal == -1) {
|
warning(WARNING_DIV,
|
||||||
warning(WARNING_DIV, "Division of min value by -1");
|
"Division of %" PRId32 " by -1 yields %" PRId32 "\n",
|
||||||
expr->nVal = INT32_MIN;
|
INT32_MIN, INT32_MIN);
|
||||||
|
expr->val = INT32_MIN;
|
||||||
} else {
|
} else {
|
||||||
expr->nVal = 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("Division by zero");
|
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 = src1->nVal % src2->nVal;
|
expr->val = op_modulo(src1->val, src2->val);
|
||||||
|
break;
|
||||||
|
case RPN_EXP:
|
||||||
|
if (src2->val < 0)
|
||||||
|
fatalerror("Exponentiation by negative power\n");
|
||||||
|
|
||||||
|
if (src1->val == INT32_MIN && src2->val == -1)
|
||||||
|
expr->val = 0;
|
||||||
|
else
|
||||||
|
expr->val = op_exponent(src1->val, src2->val);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case RPN_UNSUB:
|
case RPN_UNSUB:
|
||||||
@@ -420,31 +516,36 @@ 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:
|
||||||
case RPN_SYM:
|
case RPN_SYM:
|
||||||
fatalerror("%d is not a binary operator", op);
|
fatalerror("%d is not a binary operator\n", op);
|
||||||
}
|
}
|
||||||
|
|
||||||
} else if (op == RPN_SUB && isDiffConstant(src1, src2)) {
|
} else if (op == RPN_SUB && isDiffConstant(src1, src2)) {
|
||||||
struct Symbol const *symbol1 = symbolOf(src1);
|
struct Symbol const *symbol1 = rpn_SymbolOf(src1);
|
||||||
struct Symbol const *symbol2 = 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));
|
||||||
|
|
||||||
@@ -453,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) {
|
||||||
@@ -481,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;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -492,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));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -507,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));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -519,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;
|
||||||
}
|
}
|
||||||
@@ -530,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;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -543,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;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+678
-372
File diff suppressed because it is too large
Load Diff
+471
-254
@@ -13,41 +13,35 @@
|
|||||||
#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 <string.h>
|
#include <string.h>
|
||||||
#include <time.h>
|
#include <time.h>
|
||||||
|
|
||||||
#include "asm/asm.h"
|
#include "asm/fixpoint.h"
|
||||||
#include "asm/fstack.h"
|
#include "asm/fstack.h"
|
||||||
#include "asm/macro.h"
|
#include "asm/macro.h"
|
||||||
#include "asm/main.h"
|
#include "asm/main.h"
|
||||||
#include "asm/mymath.h"
|
#include "asm/output.h"
|
||||||
#include "asm/section.h"
|
#include "asm/section.h"
|
||||||
#include "asm/symbol.h"
|
#include "asm/symbol.h"
|
||||||
#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"
|
||||||
|
|
||||||
HashMap symbols;
|
HashMap symbols;
|
||||||
|
|
||||||
static struct Symbol *symbolScope; /* Current section symbol scope */
|
static char const *labelScope; /* Current section's label scope */
|
||||||
static struct Symbol *PCSymbol;
|
static struct Symbol *PCSymbol;
|
||||||
static char savedTIME[256];
|
static char savedTIME[256];
|
||||||
static char savedDATE[256];
|
static char savedDATE[256];
|
||||||
static char savedTIMESTAMP_ISO8601_LOCAL[256];
|
static char savedTIMESTAMP_ISO8601_LOCAL[256];
|
||||||
static char savedTIMESTAMP_ISO8601_UTC[256];
|
static char savedTIMESTAMP_ISO8601_UTC[256];
|
||||||
static char savedDAY[3];
|
|
||||||
static char savedMONTH[3];
|
|
||||||
static char savedYEAR[20];
|
|
||||||
static char savedHOUR[3];
|
|
||||||
static char savedMINUTE[3];
|
|
||||||
static char savedSECOND[3];
|
|
||||||
static bool exportall;
|
static bool exportall;
|
||||||
|
|
||||||
bool sym_IsPC(struct Symbol const *sym)
|
bool sym_IsPC(struct Symbol const *sym)
|
||||||
@@ -56,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)
|
||||||
@@ -77,19 +71,61 @@ void sym_ForEach(void (*func)(struct Symbol *, void *), void *arg)
|
|||||||
|
|
||||||
static int32_t Callback_NARG(void)
|
static int32_t Callback_NARG(void)
|
||||||
{
|
{
|
||||||
|
if (!macro_GetCurrentArgs()) {
|
||||||
|
error("_NARG does not make sense outside of a macro\n");
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
return macro_NbArgs();
|
return macro_NbArgs();
|
||||||
}
|
}
|
||||||
|
|
||||||
static int32_t Callback__LINE__(void)
|
static int32_t Callback__LINE__(void)
|
||||||
{
|
{
|
||||||
return nLineNo;
|
return lexer_GetLineNo();
|
||||||
|
}
|
||||||
|
|
||||||
|
static char const *Callback__FILE__(void)
|
||||||
|
{
|
||||||
|
/*
|
||||||
|
* FIXME: this is dangerous, and here's why this is CURRENTLY okay. It's still bad, fix it.
|
||||||
|
* There are only two call sites for this; one copies the contents directly, the other is
|
||||||
|
* EQUS expansions, which cannot straddle file boundaries. So this should be fine.
|
||||||
|
*/
|
||||||
|
static char *buf = NULL;
|
||||||
|
static size_t bufsize = 0;
|
||||||
|
char const *fileName = fstk_GetFileName();
|
||||||
|
size_t j = 1;
|
||||||
|
|
||||||
|
assert(fileName[0]);
|
||||||
|
/* The assertion above ensures the loop runs at least once */
|
||||||
|
for (size_t i = 0; fileName[i]; i++, j++) {
|
||||||
|
/* Account for the extra backslash inserted below */
|
||||||
|
if (fileName[i] == '"')
|
||||||
|
j++;
|
||||||
|
/* Ensure there will be enough room; DO NOT PRINT ANYTHING ABOVE THIS!! */
|
||||||
|
if (j + 2 >= bufsize) { /* Always keep room for 2 tail chars */
|
||||||
|
bufsize = bufsize ? bufsize * 2 : 64;
|
||||||
|
buf = realloc(buf, bufsize);
|
||||||
|
if (!buf)
|
||||||
|
fatalerror("Failed to grow buffer for file name: %s\n",
|
||||||
|
strerror(errno));
|
||||||
|
}
|
||||||
|
/* Escape quotes, since we're returning a string */
|
||||||
|
if (fileName[i] == '"')
|
||||||
|
buf[j - 1] = '\\';
|
||||||
|
buf[j] = fileName[i];
|
||||||
|
}
|
||||||
|
/* Write everything after the loop, to ensure the buffer has been allocated */
|
||||||
|
buf[0] = '"';
|
||||||
|
buf[j++] = '"';
|
||||||
|
buf[j] = '\0';
|
||||||
|
return buf;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int32_t CallbackPC(void)
|
static int32_t CallbackPC(void)
|
||||||
{
|
{
|
||||||
struct Section const *section = sect_GetSymbolSection();
|
struct Section const *section = sect_GetSymbolSection();
|
||||||
|
|
||||||
return section ? section->nOrg + curOffset : 0;
|
return section ? section->org + sect_GetSymbolOffset() : 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@@ -97,51 +133,72 @@ static int32_t CallbackPC(void)
|
|||||||
*/
|
*/
|
||||||
int32_t sym_GetValue(struct Symbol const *sym)
|
int32_t sym_GetValue(struct Symbol const *sym)
|
||||||
{
|
{
|
||||||
if (sym_IsNumeric(sym) && sym->callback)
|
if (sym_IsNumeric(sym) && sym->hasCallback)
|
||||||
return sym->callback();
|
return sym->numCallback();
|
||||||
|
|
||||||
if (sym->type == SYM_LABEL)
|
if (sym->type == SYM_LABEL)
|
||||||
/* TODO: do not use section's org directly */
|
/* TODO: do not use section's org directly */
|
||||||
return sym->value + sym_GetSection(sym)->nOrg;
|
return sym->value + sym_GetSection(sym)->org;
|
||||||
|
|
||||||
return sym->value;
|
return sym->value;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void dumpFilename(struct Symbol const *sym)
|
||||||
|
{
|
||||||
|
if (sym->src)
|
||||||
|
fstk_Dump(sym->src, sym->fileLine);
|
||||||
|
else if (sym->fileLine == 0)
|
||||||
|
fputs("<command-line>", stderr);
|
||||||
|
else
|
||||||
|
fputs("<builtin>", stderr);
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Set a symbol's definition filename and line
|
||||||
|
*/
|
||||||
|
static void setSymbolFilename(struct Symbol *sym)
|
||||||
|
{
|
||||||
|
sym->src = fstk_GetFileStack();
|
||||||
|
sym->fileLine = sym->src ? lexer_GetLineNo() : 0; // This is (NULL, 1) for built-ins
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Update a symbol's definition filename and line
|
* Update a symbol's definition filename and line
|
||||||
*/
|
*/
|
||||||
static void updateSymbolFilename(struct Symbol *sym)
|
static void updateSymbolFilename(struct Symbol *sym)
|
||||||
{
|
{
|
||||||
if (snprintf(sym->fileName, _MAX_PATH + 1, "%s",
|
struct FileStackNode *oldSrc = sym->src;
|
||||||
tzCurrentFileName) > _MAX_PATH)
|
|
||||||
fatalerror("%s: File name is too long: '%s'", __func__,
|
setSymbolFilename(sym);
|
||||||
tzCurrentFileName);
|
/* If the old node was referenced, ensure the new one is */
|
||||||
sym->fileLine = fstk_GetLine();
|
if (oldSrc && oldSrc->referenced && oldSrc->ID != (uint32_t)-1)
|
||||||
|
out_RegisterNode(sym->src);
|
||||||
|
/* 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", 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'", 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->scope = NULL;
|
sym->hasCallback = false;
|
||||||
symbol->section = NULL;
|
sym->section = NULL;
|
||||||
updateSymbolFilename(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;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@@ -149,48 +206,69 @@ static struct Symbol *createsymbol(char const *s)
|
|||||||
* the name with the parent symbol's name.
|
* the name with the parent symbol's name.
|
||||||
*/
|
*/
|
||||||
static void fullSymbolName(char *output, size_t outputSize,
|
static void fullSymbolName(char *output, size_t outputSize,
|
||||||
char const *localName, const struct Symbol *scope)
|
char const *localName, char const *scopeName)
|
||||||
{
|
{
|
||||||
const struct Symbol *parent = scope->scope ? scope->scope : scope;
|
int ret = snprintf(output, outputSize, "%s%s", scopeName, localName);
|
||||||
int n = snprintf(output, outputSize, "%s%s", parent->name, localName);
|
|
||||||
|
|
||||||
if (n >= (int)outputSize)
|
if (ret < 0)
|
||||||
fatalerror("Symbol name is too long: '%s%s'", parent->name,
|
fatalerror("snprintf error when expanding symbol name: %s", strerror(errno));
|
||||||
localName);
|
else if ((size_t)ret >= outputSize)
|
||||||
|
fatalerror("Symbol name is too long: '%s%s'\n", scopeName, localName);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
static void assignStringSymbol(struct Symbol *sym, char const *value)
|
||||||
* Find a symbol by name and scope
|
|
||||||
*/
|
|
||||||
static struct Symbol *findsymbol(char const *s, struct Symbol const *scope)
|
|
||||||
{
|
{
|
||||||
char fullname[MAXSYMLEN + 1];
|
char *string = strdup(value);
|
||||||
|
|
||||||
if (s[0] == '.' && scope) {
|
if (!string)
|
||||||
fullSymbolName(fullname, sizeof(fullname), s, scope);
|
fatalerror("No memory for string equate: %s\n", strerror(errno));
|
||||||
s = fullname;
|
|
||||||
|
sym->type = SYM_EQUS;
|
||||||
|
sym->macro = string;
|
||||||
|
sym->macroSize = strlen(string);
|
||||||
|
}
|
||||||
|
|
||||||
|
struct Symbol *sym_FindExactSymbol(char const *symName)
|
||||||
|
{
|
||||||
|
return hash_GetElement(symbols, symName);
|
||||||
|
}
|
||||||
|
|
||||||
|
struct Symbol *sym_FindUnscopedSymbol(char const *symName)
|
||||||
|
{
|
||||||
|
if (strchr(symName, '.')) {
|
||||||
|
error("Expected non-scoped symbol name, not \"%s\"\n", symName);
|
||||||
|
return NULL;
|
||||||
}
|
}
|
||||||
|
return sym_FindExactSymbol(symName);
|
||||||
char const *separator = strchr(s, '.');
|
|
||||||
|
|
||||||
if (separator && strchr(separator + 1, '.'))
|
|
||||||
fatalerror("'%s' is a nonsensical reference to a nested local symbol",
|
|
||||||
s);
|
|
||||||
|
|
||||||
return hash_GetElement(symbols, s);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
struct Symbol *sym_FindScopedSymbol(char const *symName)
|
||||||
* Find a symbol by name, with automatically determined scope
|
|
||||||
*/
|
|
||||||
struct Symbol *sym_FindSymbol(char const *symName)
|
|
||||||
{
|
{
|
||||||
return findsymbol(symName, symName[0] == '.' ? symbolScope : NULL);
|
char const *localName = strchr(symName, '.');
|
||||||
|
|
||||||
|
if (localName) {
|
||||||
|
if (strchr(localName + 1, '.'))
|
||||||
|
fatalerror("'%s' is a nonsensical reference to a nested local symbol\n",
|
||||||
|
symName);
|
||||||
|
/* If auto-scoped local label, expand the name */
|
||||||
|
if (localName == symName) { /* Meaning, the name begins with the dot */
|
||||||
|
char fullName[MAXSYMLEN + 1];
|
||||||
|
|
||||||
|
fullSymbolName(fullName, sizeof(fullName), symName, labelScope);
|
||||||
|
return sym_FindExactSymbol(fullName);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return sym_FindExactSymbol(symName);
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline bool isReferenced(struct Symbol const *sym)
|
struct Symbol const *sym_GetPC(void)
|
||||||
{
|
{
|
||||||
return sym->ID != -1;
|
return PCSymbol;
|
||||||
|
}
|
||||||
|
|
||||||
|
static bool isReferenced(struct Symbol const *sym)
|
||||||
|
{
|
||||||
|
return sym->ID != (uint32_t)-1;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@@ -198,21 +276,26 @@ static inline bool isReferenced(struct Symbol const *sym)
|
|||||||
*/
|
*/
|
||||||
void sym_Purge(char const *symName)
|
void sym_Purge(char const *symName)
|
||||||
{
|
{
|
||||||
struct Symbol *scope = symName[0] == '.' ? symbolScope : NULL;
|
struct Symbol *sym = sym_FindScopedSymbol(symName);
|
||||||
struct Symbol *symbol = findsymbol(symName, scope);
|
|
||||||
|
|
||||||
if (!symbol) {
|
if (!sym) {
|
||||||
yyerror("'%s' not defined", symName);
|
error("'%s' not defined\n", symName);
|
||||||
} else if (symbol->isBuiltin) {
|
} else if (sym->isBuiltin) {
|
||||||
yyerror("Built-in symbol '%s' cannot be purged", symName);
|
error("Built-in symbol '%s' cannot be purged\n", symName);
|
||||||
} else if (isReferenced(symbol)) {
|
} else if (isReferenced(sym)) {
|
||||||
yyerror("Symbol \"%s\" is referenced and thus cannot be purged",
|
error("Symbol \"%s\" is referenced and thus cannot be purged\n", symName);
|
||||||
symName);
|
|
||||||
} else {
|
} else {
|
||||||
hash_RemoveElement(symbols, symbol->name);
|
/* Do not keep a reference to the label's name after purging it */
|
||||||
if (symbol->type == SYM_MACRO)
|
if (sym->name == labelScope)
|
||||||
free(symbol->macro);
|
sym_SetCurrentSymbolScope(NULL);
|
||||||
free(symbol);
|
|
||||||
|
/*
|
||||||
|
* FIXME: this leaks sym->macro for SYM_EQUS and SYM_MACRO, but this can't
|
||||||
|
* free(sym->macro) because the expansion may be purging itself.
|
||||||
|
*/
|
||||||
|
hash_RemoveElement(symbols, sym->name);
|
||||||
|
/* TODO: ideally, also unref the file stack nodes */
|
||||||
|
free(sym);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -221,27 +304,23 @@ uint32_t sym_GetPCValue(void)
|
|||||||
struct Section const *sect = sect_GetSymbolSection();
|
struct Section const *sect = sect_GetSymbolSection();
|
||||||
|
|
||||||
if (!sect)
|
if (!sect)
|
||||||
yyerror("PC has no value outside a section");
|
error("PC has no value outside a section\n");
|
||||||
else if (sect->nOrg == -1)
|
else if (sect->org == (uint32_t)-1)
|
||||||
yyerror("Expected constant PC but section is not fixed");
|
error("Expected constant PC but section is not fixed\n");
|
||||||
else
|
else
|
||||||
return CallbackPC();
|
return CallbackPC();
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Return a constant symbols value
|
* Return a constant symbol's value, assuming it's defined
|
||||||
*/
|
*/
|
||||||
uint32_t sym_GetConstantValue(char const *s)
|
uint32_t sym_GetConstantSymValue(struct Symbol const *sym)
|
||||||
{
|
{
|
||||||
struct Symbol const *sym = sym_FindSymbol(s);
|
if (sym == PCSymbol)
|
||||||
|
|
||||||
if (sym == NULL)
|
|
||||||
yyerror("'%s' not defined", s);
|
|
||||||
else if (sym == PCSymbol)
|
|
||||||
return sym_GetPCValue();
|
return sym_GetPCValue();
|
||||||
else if (!sym_IsConstant(sym))
|
else if (!sym_IsConstant(sym))
|
||||||
yyerror("\"%s\" does not have a constant value", s);
|
error("\"%s\" does not have a constant value\n", sym->name);
|
||||||
else
|
else
|
||||||
return sym_GetValue(sym);
|
return sym_GetValue(sym);
|
||||||
|
|
||||||
@@ -249,48 +328,57 @@ uint32_t sym_GetConstantValue(char const *s)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Return a defined symbols value... aborts if not defined yet
|
* Return a constant symbol's value
|
||||||
*/
|
*/
|
||||||
uint32_t sym_GetDefinedValue(char const *s)
|
uint32_t sym_GetConstantValue(char const *symName)
|
||||||
{
|
{
|
||||||
struct Symbol const *sym = sym_FindSymbol(s);
|
struct Symbol const *sym = sym_FindScopedSymbol(symName);
|
||||||
|
|
||||||
if (sym == NULL || !sym_IsDefined(sym))
|
if (!sym)
|
||||||
yyerror("'%s' not defined", s);
|
error("'%s' not defined\n", symName);
|
||||||
else if (!sym_IsNumeric(sym))
|
|
||||||
yyerror("'%s' is a macro or string symbol", s);
|
|
||||||
else
|
else
|
||||||
return sym_GetValue(sym);
|
return sym_GetConstantSymValue(sym);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
struct Symbol *sym_GetCurrentSymbolScope(void)
|
char const *sym_GetCurrentSymbolScope(void)
|
||||||
{
|
{
|
||||||
return symbolScope;
|
return labelScope;
|
||||||
}
|
}
|
||||||
|
|
||||||
void sym_SetCurrentSymbolScope(struct Symbol *newScope)
|
void sym_SetCurrentSymbolScope(char const *newScope)
|
||||||
{
|
{
|
||||||
symbolScope = newScope;
|
labelScope = 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 symName The name of the symbol to create
|
||||||
|
* @param numeric If false, the symbol may not have been referenced earlier
|
||||||
*/
|
*/
|
||||||
static struct Symbol *createNonrelocSymbol(char const *symbolName)
|
static struct Symbol *createNonrelocSymbol(char const *symName, bool numeric)
|
||||||
{
|
{
|
||||||
struct Symbol *symbol = findsymbol(symbolName, NULL);
|
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)) {
|
||||||
yyerror("'%s' already defined at %s(%" PRIu32 ")", symbolName,
|
error("'%s' already defined at ", symName);
|
||||||
symbol->fileName, symbol->fileLine);
|
dumpFilename(sym);
|
||||||
|
putc('\n', stderr);
|
||||||
|
return NULL; // Don't allow overriding the symbol, that'd be bad!
|
||||||
|
} else if (!numeric) {
|
||||||
|
// The symbol has already been referenced, but it's not allowed
|
||||||
|
error("'%s' already referenced at ", symName);
|
||||||
|
dumpFilename(sym);
|
||||||
|
putc('\n', stderr);
|
||||||
|
return NULL; // Don't allow overriding the symbol, that'd be bad!
|
||||||
|
}
|
||||||
|
|
||||||
return symbol;
|
return sym;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@@ -298,10 +386,36 @@ static struct Symbol *createNonrelocSymbol(char const *symbolName)
|
|||||||
*/
|
*/
|
||||||
struct Symbol *sym_AddEqu(char const *symName, int32_t value)
|
struct Symbol *sym_AddEqu(char const *symName, int32_t value)
|
||||||
{
|
{
|
||||||
struct Symbol *sym = createNonrelocSymbol(symName);
|
struct Symbol *sym = createNonrelocSymbol(symName, true);
|
||||||
|
|
||||||
|
if (!sym)
|
||||||
|
return NULL;
|
||||||
|
|
||||||
sym->type = SYM_EQU;
|
sym->type = SYM_EQU;
|
||||||
sym->callback = NULL;
|
sym->value = value;
|
||||||
|
|
||||||
|
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;
|
sym->value = value;
|
||||||
|
|
||||||
return sym;
|
return sym;
|
||||||
@@ -321,117 +435,205 @@ struct Symbol *sym_AddEqu(char const *symName, int32_t value)
|
|||||||
*/
|
*/
|
||||||
struct Symbol *sym_AddString(char const *symName, char const *value)
|
struct Symbol *sym_AddString(char const *symName, char const *value)
|
||||||
{
|
{
|
||||||
struct Symbol *sym = createNonrelocSymbol(symName);
|
struct Symbol *sym = createNonrelocSymbol(symName, false);
|
||||||
size_t len = strlen(value);
|
|
||||||
char *string = malloc(len + 1);
|
|
||||||
|
|
||||||
if (string == NULL)
|
if (!sym)
|
||||||
fatalerror("No memory for string equate");
|
return NULL;
|
||||||
strcpy(string, value);
|
|
||||||
|
|
||||||
sym->type = SYM_EQUS;
|
assignStringSymbol(sym, value);
|
||||||
/* TODO: use other fields */
|
return sym;
|
||||||
sym->macroSize = len;
|
}
|
||||||
sym->macro = string;
|
|
||||||
|
struct Symbol *sym_RedefString(char const *symName, char const *value)
|
||||||
|
{
|
||||||
|
struct Symbol *sym = sym_FindExactSymbol(symName);
|
||||||
|
|
||||||
|
if (!sym)
|
||||||
|
return sym_AddString(symName, value);
|
||||||
|
|
||||||
|
if (sym->type != SYM_EQUS) {
|
||||||
|
if (sym_IsDefined(sym))
|
||||||
|
error("'%s' already defined as non-EQUS at ", symName);
|
||||||
|
else
|
||||||
|
error("'%s' already referenced 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);
|
||||||
|
/*
|
||||||
|
* FIXME: this leaks the previous sym->macro value, but this can't
|
||||||
|
* free(sym->macro) because the expansion may be redefining itself.
|
||||||
|
*/
|
||||||
|
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 = findsymbol(symName, NULL);
|
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) {
|
||||||
yyerror("'%s' already defined as %s at %s(%" PRIu32 ")",
|
error("'%s' already defined as %s at ",
|
||||||
symName, sym->type == SYM_LABEL ? "label" : "constant",
|
symName, sym->type == SYM_LABEL ? "label" : "constant");
|
||||||
sym->fileName, sym->fileLine);
|
dumpFilename(sym);
|
||||||
else
|
putc('\n', stderr);
|
||||||
/* TODO: can the scope be incorrect when talking over refs? */
|
return sym;
|
||||||
|
} else {
|
||||||
updateSymbolFilename(sym);
|
updateSymbolFilename(sym);
|
||||||
|
}
|
||||||
|
|
||||||
sym->type = SYM_SET;
|
sym->type = SYM_VAR;
|
||||||
sym->callback = NULL;
|
|
||||||
sym->value = value;
|
sym->value = value;
|
||||||
|
|
||||||
return sym;
|
return sym;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Add a local (.name) relocatable symbol
|
* Add a label (aka "relocatable symbol")
|
||||||
|
* @param symName The label's full name (so `.name` is invalid)
|
||||||
|
* @return The created symbol
|
||||||
*/
|
*/
|
||||||
struct Symbol *sym_AddLocalReloc(char const *symName)
|
static struct Symbol *addLabel(char const *symName)
|
||||||
{
|
{
|
||||||
if (!symbolScope) {
|
assert(symName[0] != '.'); /* The symbol name must have been expanded prior */
|
||||||
yyerror("Local label '%s' in main scope", symName);
|
struct Symbol *sym = sym_FindExactSymbol(symName);
|
||||||
|
|
||||||
|
if (!sym) {
|
||||||
|
sym = createsymbol(symName);
|
||||||
|
} else if (sym_IsDefined(sym)) {
|
||||||
|
error("'%s' already defined at ", symName);
|
||||||
|
dumpFilename(sym);
|
||||||
|
putc('\n', stderr);
|
||||||
|
return NULL;
|
||||||
|
} else {
|
||||||
|
updateSymbolFilename(sym);
|
||||||
|
}
|
||||||
|
/* If the symbol already exists as a ref, just "take over" it */
|
||||||
|
sym->type = SYM_LABEL;
|
||||||
|
sym->value = sect_GetSymbolOffset();
|
||||||
|
if (exportall)
|
||||||
|
sym->isExported = true;
|
||||||
|
sym->section = sect_GetSymbolSection();
|
||||||
|
|
||||||
|
if (sym && !sym->section)
|
||||||
|
error("Label \"%s\" created outside of a SECTION\n", symName);
|
||||||
|
return sym;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Add a local (`.name` or `Parent.name`) relocatable symbol
|
||||||
|
*/
|
||||||
|
struct Symbol *sym_AddLocalLabel(char const *symName)
|
||||||
|
{
|
||||||
|
if (!labelScope) {
|
||||||
|
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, '.');
|
||||||
|
|
||||||
fullSymbolName(fullname, sizeof(fullname), symName, symbolScope);
|
assert(localName); /* There should be at least one dot in `symName` */
|
||||||
return sym_AddReloc(fullname);
|
/* Check for something after the dot in `localName` */
|
||||||
|
if (localName[1] == '\0') {
|
||||||
|
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 {
|
||||||
|
size_t i = 0;
|
||||||
|
|
||||||
|
/* Find where `labelScope` and `symName` first differ */
|
||||||
|
while (labelScope[i] && symName[i] == labelScope[i])
|
||||||
|
i++;
|
||||||
|
|
||||||
|
/* Check that `symName` starts with `labelScope` and then a '.' */
|
||||||
|
if (labelScope[i] != '\0' || symName[i] != '.') {
|
||||||
|
size_t parentLen = localName - symName;
|
||||||
|
|
||||||
|
assert(parentLen <= INT_MAX);
|
||||||
|
error("Not currently in the scope of '%.*s'\n", (int)parentLen, symName);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return addLabel(symName);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Add a relocatable symbol
|
* Add a relocatable symbol
|
||||||
*/
|
*/
|
||||||
struct Symbol *sym_AddReloc(char const *symName)
|
struct Symbol *sym_AddLabel(char const *symName)
|
||||||
{
|
{
|
||||||
struct Symbol const *scope = NULL;
|
struct Symbol *sym = addLabel(symName);
|
||||||
char *localPtr = strchr(symName, '.');
|
|
||||||
|
|
||||||
if (localPtr != NULL) {
|
|
||||||
if (!symbolScope) {
|
|
||||||
yyerror("Local label in main scope");
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
scope = symbolScope->scope ? symbolScope->scope : symbolScope;
|
|
||||||
uint32_t parentLen = localPtr - symName;
|
|
||||||
|
|
||||||
if (strchr(localPtr + 1, '.') != NULL)
|
|
||||||
fatalerror("'%s' is a nonsensical reference to a nested local symbol",
|
|
||||||
symName);
|
|
||||||
else if (strlen(scope->name) != parentLen
|
|
||||||
|| strncmp(symName, scope->name, parentLen) != 0)
|
|
||||||
yyerror("Not currently in the scope of '%.*s'",
|
|
||||||
parentLen, symName);
|
|
||||||
}
|
|
||||||
|
|
||||||
struct Symbol *sym = findsymbol(symName, scope);
|
|
||||||
|
|
||||||
if (!sym)
|
|
||||||
sym = createsymbol(symName);
|
|
||||||
else if (sym_IsDefined(sym))
|
|
||||||
yyerror("'%s' already defined in %s(%" PRIu32 ")", symName,
|
|
||||||
sym->fileName, sym->fileLine);
|
|
||||||
/* If the symbol already exists as a ref, just "take over" it */
|
|
||||||
|
|
||||||
sym->type = SYM_LABEL;
|
|
||||||
sym->callback = NULL;
|
|
||||||
sym->value = curOffset;
|
|
||||||
|
|
||||||
if (exportall)
|
|
||||||
sym->isExported = true;
|
|
||||||
|
|
||||||
sym->scope = scope;
|
|
||||||
sym->section = sect_GetSymbolSection();
|
|
||||||
/* Labels need to be assigned a section, except PC */
|
|
||||||
if (!sym->section && strcmp(symName, "@"))
|
|
||||||
yyerror("Label \"%s\" created outside of a SECTION",
|
|
||||||
symName);
|
|
||||||
|
|
||||||
updateSymbolFilename(sym);
|
|
||||||
|
|
||||||
/* Set the symbol as the new scope */
|
/* Set the symbol as the new scope */
|
||||||
/* TODO: don't do this for local labels */
|
if (sym)
|
||||||
symbolScope = findsymbol(symName, scope);
|
sym_SetCurrentSymbolScope(sym->name);
|
||||||
return symbolScope;
|
return sym;
|
||||||
|
}
|
||||||
|
|
||||||
|
static uint32_t anonLabelID;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Add an anonymous label
|
||||||
|
*/
|
||||||
|
struct Symbol *sym_AddAnonLabel(void)
|
||||||
|
{
|
||||||
|
if (anonLabelID == UINT32_MAX) {
|
||||||
|
error("Only %" PRIu32 " anonymous labels can be created!", anonLabelID);
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
char name[MAXSYMLEN + 1];
|
||||||
|
|
||||||
|
sym_WriteAnonLabelName(name, 0, true); // The direction is important!!
|
||||||
|
anonLabelID++;
|
||||||
|
return addLabel(name);
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Write an anonymous label's name to a buffer
|
||||||
|
*/
|
||||||
|
void sym_WriteAnonLabelName(char buf[MIN_NB_ELMS(MAXSYMLEN + 1)], uint32_t ofs, bool neg)
|
||||||
|
{
|
||||||
|
uint32_t id = 0;
|
||||||
|
|
||||||
|
if (neg) {
|
||||||
|
if (ofs > anonLabelID)
|
||||||
|
error("Reference to anonymous label %" PRIu32 " before, when only %" PRIu32
|
||||||
|
" ha%s been created so far\n",
|
||||||
|
ofs, anonLabelID, anonLabelID == 1 ? "s" : "ve");
|
||||||
|
else
|
||||||
|
id = anonLabelID - ofs;
|
||||||
|
} else {
|
||||||
|
ofs--; // We're referencing symbols that haven't been created yet...
|
||||||
|
if (ofs > UINT32_MAX - anonLabelID)
|
||||||
|
error("Reference to anonymous label %" PRIu32 " after, when only %" PRIu32
|
||||||
|
" may still be created\n", ofs + 1, UINT32_MAX - anonLabelID);
|
||||||
|
else
|
||||||
|
id = anonLabelID + ofs;
|
||||||
|
}
|
||||||
|
|
||||||
|
sprintf(buf, "!%u", id);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@@ -439,7 +641,12 @@ struct Symbol *sym_AddReloc(char const *symName)
|
|||||||
*/
|
*/
|
||||||
void sym_Export(char const *symName)
|
void sym_Export(char const *symName)
|
||||||
{
|
{
|
||||||
struct Symbol *sym = sym_FindSymbol(symName);
|
if (symName[0] == '!') {
|
||||||
|
error("Anonymous labels cannot be exported\n");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
struct Symbol *sym = sym_FindScopedSymbol(symName);
|
||||||
|
|
||||||
/* If the symbol doesn't exist, create a ref that can be purged */
|
/* If the symbol doesn't exist, create a ref that can be purged */
|
||||||
if (!sym)
|
if (!sym)
|
||||||
@@ -450,14 +657,17 @@ void sym_Export(char const *symName)
|
|||||||
/*
|
/*
|
||||||
* Add a macro definition
|
* Add a macro definition
|
||||||
*/
|
*/
|
||||||
struct Symbol *sym_AddMacro(char const *symName, int32_t defLineNo)
|
struct Symbol *sym_AddMacro(char const *symName, int32_t defLineNo, char *body, size_t size)
|
||||||
{
|
{
|
||||||
struct Symbol *sym = createNonrelocSymbol(symName);
|
struct Symbol *sym = createNonrelocSymbol(symName, false);
|
||||||
|
|
||||||
|
if (!sym)
|
||||||
|
return NULL;
|
||||||
|
|
||||||
sym->type = SYM_MACRO;
|
sym->type = SYM_MACRO;
|
||||||
sym->macroSize = ulNewMacroSize;
|
sym->macroSize = size;
|
||||||
sym->macro = tzNewMacro;
|
sym->macro = body;
|
||||||
updateSymbolFilename(sym);
|
setSymbolFilename(sym); /* TODO: is this really necessary? */
|
||||||
/*
|
/*
|
||||||
* The symbol is created at the line after the `endm`,
|
* The symbol is created at the line after the `endm`,
|
||||||
* override this with the actual definition line
|
* override this with the actual definition line
|
||||||
@@ -473,29 +683,23 @@ struct Symbol *sym_AddMacro(char const *symName, int32_t defLineNo)
|
|||||||
*/
|
*/
|
||||||
struct Symbol *sym_Ref(char const *symName)
|
struct Symbol *sym_Ref(char const *symName)
|
||||||
{
|
{
|
||||||
struct Symbol *nsym = sym_FindSymbol(symName);
|
struct Symbol *sym = sym_FindScopedSymbol(symName);
|
||||||
|
|
||||||
if (nsym == NULL) {
|
if (!sym) {
|
||||||
char fullname[MAXSYMLEN + 1];
|
char fullname[MAXSYMLEN + 1];
|
||||||
struct Symbol const *scope = NULL;
|
|
||||||
|
|
||||||
if (symName[0] == '.') {
|
if (symName[0] == '.') {
|
||||||
if (!symbolScope)
|
if (!labelScope)
|
||||||
fatalerror("Local label reference '%s' in main scope",
|
fatalerror("Local label reference '%s' in main scope\n", symName);
|
||||||
symName);
|
fullSymbolName(fullname, sizeof(fullname), symName, labelScope);
|
||||||
scope = symbolScope->scope ? symbolScope->scope
|
|
||||||
: symbolScope;
|
|
||||||
fullSymbolName(fullname, sizeof(fullname), symName,
|
|
||||||
symbolScope);
|
|
||||||
symName = fullname;
|
symName = fullname;
|
||||||
}
|
}
|
||||||
|
|
||||||
nsym = createsymbol(symName);
|
sym = createsymbol(symName);
|
||||||
nsym->type = SYM_REF;
|
sym->type = SYM_REF;
|
||||||
nsym->scope = scope;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return nsym;
|
return sym;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@@ -506,39 +710,49 @@ void sym_SetExportAll(bool set)
|
|||||||
exportall = set;
|
exportall = set;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
static struct Symbol *createBuiltinSymbol(char const *symName)
|
||||||
* Returns a pointer to the first non-zero character in a string
|
|
||||||
* Non-'0', not non-'\0'.
|
|
||||||
*/
|
|
||||||
static inline char const *removeLeadingZeros(char const *ptr)
|
|
||||||
{
|
{
|
||||||
while (*ptr == '0')
|
struct Symbol *sym = createsymbol(symName);
|
||||||
ptr++;
|
|
||||||
return ptr;
|
sym->isBuiltin = true;
|
||||||
|
sym->hasCallback = true;
|
||||||
|
sym->src = NULL;
|
||||||
|
sym->fileLine = 1; // This is 0 for CLI-defined symbols
|
||||||
|
return sym;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Initialize the symboltable
|
* Initialize the symboltable
|
||||||
*/
|
*/
|
||||||
void sym_Init(void)
|
void sym_Init(time_t now)
|
||||||
{
|
{
|
||||||
struct Symbol *_NARGSymbol = sym_AddEqu("_NARG", 0);
|
PCSymbol = createBuiltinSymbol("@");
|
||||||
struct Symbol *__LINE__Symbol = sym_AddEqu("__LINE__", 0);
|
struct Symbol *_NARGSymbol = createBuiltinSymbol("_NARG");
|
||||||
|
struct Symbol *__LINE__Symbol = createBuiltinSymbol("__LINE__");
|
||||||
|
struct Symbol *__FILE__Symbol = createBuiltinSymbol("__FILE__");
|
||||||
|
|
||||||
PCSymbol = sym_AddReloc("@"),
|
PCSymbol->type = SYM_LABEL;
|
||||||
PCSymbol->isBuiltin = true;
|
PCSymbol->section = NULL;
|
||||||
PCSymbol->callback = CallbackPC;
|
PCSymbol->numCallback = CallbackPC;
|
||||||
_NARGSymbol->isBuiltin = true;
|
_NARGSymbol->type = SYM_EQU;
|
||||||
_NARGSymbol->callback = Callback_NARG;
|
_NARGSymbol->numCallback = Callback_NARG;
|
||||||
__LINE__Symbol->isBuiltin = true;
|
__LINE__Symbol->type = SYM_EQU;
|
||||||
__LINE__Symbol->callback = Callback__LINE__;
|
__LINE__Symbol->numCallback = Callback__LINE__;
|
||||||
sym_AddSet("_RS", 0)->isBuiltin = true;
|
__FILE__Symbol->type = SYM_EQUS;
|
||||||
|
__FILE__Symbol->strCallback = Callback__FILE__;
|
||||||
|
|
||||||
sym_AddEqu("__RGBDS_MAJOR__", PACKAGE_VERSION_MAJOR)->isBuiltin = true;
|
sym_AddVar("_RS", 0)->isBuiltin = true;
|
||||||
sym_AddEqu("__RGBDS_MINOR__", PACKAGE_VERSION_MINOR)->isBuiltin = true;
|
|
||||||
sym_AddEqu("__RGBDS_PATCH__", PACKAGE_VERSION_PATCH)->isBuiltin = true;
|
|
||||||
|
|
||||||
time_t now = time(NULL);
|
#define addNumber(name, val) sym_AddEqu(name, val)->isBuiltin = true
|
||||||
|
#define addString(name, val) sym_AddString(name, val)->isBuiltin = true
|
||||||
|
|
||||||
|
addString("__RGBDS_VERSION__", get_package_version_string());
|
||||||
|
addNumber("__RGBDS_MAJOR__", PACKAGE_VERSION_MAJOR);
|
||||||
|
addNumber("__RGBDS_MINOR__", PACKAGE_VERSION_MINOR);
|
||||||
|
addNumber("__RGBDS_PATCH__", PACKAGE_VERSION_PATCH);
|
||||||
|
#ifdef PACKAGE_VERSION_RC
|
||||||
|
addNumber("__RGBDS_RC__", PACKAGE_VERSION_RC);
|
||||||
|
#endif
|
||||||
|
|
||||||
if (now == (time_t)-1) {
|
if (now == (time_t)-1) {
|
||||||
warn("Couldn't determine current time");
|
warn("Couldn't determine current time");
|
||||||
@@ -546,7 +760,6 @@ void sym_Init(void)
|
|||||||
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);
|
||||||
@@ -555,32 +768,36 @@ void sym_Init(void)
|
|||||||
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);
|
||||||
|
|
||||||
strftime(savedYEAR, sizeof(savedYEAR), "%Y", time_utc);
|
|
||||||
strftime(savedMONTH, sizeof(savedMONTH), "%m", time_utc);
|
|
||||||
strftime(savedDAY, sizeof(savedDAY), "%d", time_utc);
|
|
||||||
strftime(savedHOUR, sizeof(savedHOUR), "%H", time_utc);
|
|
||||||
strftime(savedMINUTE, sizeof(savedMINUTE), "%M", time_utc);
|
|
||||||
strftime(savedSECOND, sizeof(savedSECOND), "%S", time_utc);
|
|
||||||
|
|
||||||
#define addString(name, val) sym_AddString(name, val)->isBuiltin = true
|
|
||||||
addString("__TIME__", savedTIME);
|
addString("__TIME__", savedTIME);
|
||||||
addString("__DATE__", savedDATE);
|
addString("__DATE__", savedDATE);
|
||||||
addString("__ISO_8601_LOCAL__", savedTIMESTAMP_ISO8601_LOCAL);
|
addString("__ISO_8601_LOCAL__", savedTIMESTAMP_ISO8601_LOCAL);
|
||||||
addString("__ISO_8601_UTC__", savedTIMESTAMP_ISO8601_UTC);
|
addString("__ISO_8601_UTC__", savedTIMESTAMP_ISO8601_UTC);
|
||||||
/* This cannot start with zeros */
|
|
||||||
addString("__UTC_YEAR__", savedYEAR);
|
addNumber("__UTC_YEAR__", time_utc->tm_year + 1900);
|
||||||
addString("__UTC_MONTH__", removeLeadingZeros(savedMONTH));
|
addNumber("__UTC_MONTH__", time_utc->tm_mon + 1);
|
||||||
addString("__UTC_DAY__", removeLeadingZeros(savedDAY));
|
addNumber("__UTC_DAY__", time_utc->tm_mday);
|
||||||
addString("__UTC_HOUR__", removeLeadingZeros(savedHOUR));
|
addNumber("__UTC_HOUR__", time_utc->tm_hour);
|
||||||
addString("__UTC_MINUTE__", removeLeadingZeros(savedMINUTE));
|
addNumber("__UTC_MINUTE__", time_utc->tm_min);
|
||||||
addString("__UTC_SECOND__", removeLeadingZeros(savedSECOND));
|
addNumber("__UTC_SECOND__", time_utc->tm_sec);
|
||||||
|
|
||||||
|
#undef addNumber
|
||||||
#undef addString
|
#undef addString
|
||||||
|
|
||||||
symbolScope = NULL;
|
sym_SetCurrentSymbolScope(NULL);
|
||||||
|
anonLabelID = 0;
|
||||||
|
|
||||||
math_DefinePI();
|
/* _PI is deprecated */
|
||||||
|
struct Symbol *_PISymbol = createBuiltinSymbol("_PI");
|
||||||
|
|
||||||
|
_PISymbol->type = SYM_EQU;
|
||||||
|
_PISymbol->src = NULL;
|
||||||
|
_PISymbol->fileLine = 0;
|
||||||
|
_PISymbol->hasCallback = true;
|
||||||
|
_PISymbol->numCallback = fix_Callback_PI;
|
||||||
}
|
}
|
||||||
|
|||||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user