mirror of
https://github.com/gbdev/rgbds.git
synced 2026-08-27 17:15:18 +00:00
Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
76c1995559 | ||
|
|
ae84570f04 | ||
|
|
094a31ef8c | ||
|
|
291dcf3b6c | ||
|
|
a890bd072b | ||
|
|
2f6c808ccb | ||
|
|
e80907abd0 | ||
|
|
25d39155d3 | ||
|
|
77021d229b | ||
|
|
1b250b90b2 | ||
|
|
e2b4723489 | ||
|
|
2507413162 | ||
|
|
e023a84d04 | ||
|
|
34c127d9c3 | ||
|
|
9a930988c2 | ||
|
|
8c4204c542 | ||
|
|
663c1930ec | ||
|
|
30ccf43f44 | ||
|
|
fdc17adbcb | ||
|
|
cc196954f3 | ||
|
|
55b6cfff84 | ||
|
|
1fc73b04eb | ||
|
|
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 | ||
|
|
8c0adb63a1 | ||
|
|
f5b0c701a6 | ||
|
|
874bd92604 | ||
|
|
69a8c62863 | ||
|
|
5481af5093 | ||
|
|
6355d0598b | ||
|
|
1145d10996 | ||
|
|
32231e3f7e | ||
|
|
29314f76f7 | ||
|
|
8e92383fa3 | ||
|
|
e51701acaa | ||
|
|
0793e9effe | ||
|
|
c25b0be085 | ||
|
|
1f2f797cb9 | ||
|
|
aca00e4fce | ||
|
|
cf80293d9b | ||
|
|
6d53753c66 | ||
|
|
79f293c3d7 | ||
|
|
8c765883fb | ||
|
|
83aa456d05 | ||
|
|
819c36943e | ||
|
|
8b60efa149 | ||
|
|
240fca0861 | ||
|
|
f996186fae | ||
|
|
69a41d8ef9 | ||
|
|
b958820bce | ||
|
|
7624bd524c | ||
|
|
663f0ca3b0 | ||
|
|
f88d9e728d | ||
|
|
71fa62c9d1 | ||
|
|
5c6069dbe9 | ||
|
|
d517d2d6b4 | ||
|
|
80218fa109 | ||
|
|
fee8a58b77 | ||
|
|
fd52a6f046 | ||
|
|
89fb372326 | ||
|
|
a828f82414 | ||
|
|
4d0d6664d7 | ||
|
|
5c24de3dc4 | ||
|
|
363458c3bc | ||
|
|
b299f6fb3b | ||
|
|
645473e336 | ||
|
|
bdf397bba7 | ||
|
|
781a65ee49 | ||
|
|
c135e2c6a0 | ||
|
|
12693081c9 | ||
|
|
7c22954fd5 | ||
|
|
8958e352df | ||
|
|
573003113b | ||
|
|
8b1351fc3e | ||
|
|
106ef895ee | ||
|
|
7f9bd12f76 | ||
|
|
5fe3a0adb6 | ||
|
|
cdb4c5f553 | ||
|
|
57639f3765 | ||
|
|
9bec983923 | ||
|
|
2220f19fa7 | ||
|
|
2a734ecba2 | ||
|
|
d21015e34a | ||
|
|
023a3c037f | ||
|
|
828edb7403 | ||
|
|
a034ce0478 | ||
|
|
d6cd5823e3 | ||
|
|
5dd941b311 | ||
|
|
f9f27d6f5a | ||
|
|
5ea8490e2b | ||
|
|
5863cd10b8 | ||
|
|
40f8e33e6c | ||
|
|
0157ba63d3 | ||
|
|
9e3d8b22cb | ||
|
|
665412c073 | ||
|
|
2b0c34ecb5 | ||
|
|
b0ec8468e6 | ||
|
|
e82ad21704 | ||
|
|
e098bf47ba | ||
|
|
190678107b | ||
|
|
9f82fa4cf7 | ||
|
|
562835308b | ||
|
|
927c65e863 | ||
|
|
5b6c1569a4 | ||
|
|
65121e6d5d | ||
|
|
82e0e4ffaf | ||
|
|
ffb199a26a | ||
|
|
175933d2b1 | ||
|
|
c86e6fef0a | ||
|
|
1e3ce2a36f | ||
|
|
153915dc2f | ||
|
|
ced38bc6ee | ||
|
|
4e96cf9875 | ||
|
|
80170eb6eb | ||
|
|
bdad1499fe | ||
|
|
1f5ca39559 | ||
|
|
5013b64f55 | ||
|
|
7eb73d766e | ||
|
|
bcfeb49d6b | ||
|
|
702d9e0542 | ||
|
|
c0aff678e9 | ||
|
|
a3d8836671 | ||
|
|
db1eb8fbcb | ||
|
|
95f347dc6a | ||
|
|
6579120d9e | ||
|
|
84cd9f2db9 | ||
|
|
06fe27c516 | ||
|
|
5039af6af1 | ||
|
|
4df74d44ec | ||
|
|
9113647d41 | ||
|
|
26af2bff5e | ||
|
|
3c304f3acf | ||
|
|
e308130e23 | ||
|
|
713eef9ef2 | ||
|
|
7635a2fc74 | ||
|
|
6889334521 | ||
|
|
d1e82e50cb | ||
|
|
7955447ca4 | ||
|
|
51e225cd75 | ||
|
|
187f88aa50 | ||
|
|
caddd61f17 | ||
|
|
29629245a4 | ||
|
|
666b9f8f7b | ||
|
|
7deb8d3e8a | ||
|
|
cb0a882a31 | ||
|
|
df2c0dc2f9 | ||
|
|
062fa5392b | ||
|
|
baeec2315f | ||
|
|
92134d7684 | ||
|
|
4877bb783c | ||
|
|
275b8e15ff | ||
|
|
e123b6dec7 | ||
|
|
cb52ae0f26 | ||
|
|
46a402f7d7 | ||
|
|
e233c5d256 | ||
|
|
fe824e0068 | ||
|
|
66512ed8d2 | ||
|
|
fb58166e5d | ||
|
|
0759c98d91 | ||
|
|
402ffbf0c5 | ||
|
|
8191e5eb27 | ||
|
|
03967bd623 | ||
|
|
eb445271df | ||
|
|
af22cf182b | ||
|
|
5a0fcda4c8 | ||
|
|
29623c4146 | ||
|
|
ebda8255ff | ||
|
|
deb91f679d | ||
|
|
fb5e768142 | ||
|
|
ecf44c784c | ||
|
|
5bca1172ff | ||
|
|
136446fccb | ||
|
|
49bca8d588 | ||
|
|
7ddbe44b21 | ||
|
|
af60e7f74a | ||
|
|
2f16e82cf7 | ||
|
|
7b54312d97 | ||
|
|
5b98beec8b | ||
|
|
6662c86d5e | ||
|
|
2f466c2939 | ||
|
|
61897d8b52 | ||
|
|
a259f53b52 | ||
|
|
ffdb1fbfe5 | ||
|
|
4b33b4b387 | ||
|
|
8fcdcb1731 | ||
|
|
55b911654c | ||
|
|
7c8eba9fd2 | ||
|
|
23effcc3f0 | ||
|
|
ea0c5581a5 | ||
|
|
2ea329c920 | ||
|
|
3948795d49 | ||
|
|
13e4920122 | ||
|
|
88b1121037 | ||
|
|
d2a97e934b | ||
|
|
cb3997d8c9 | ||
|
|
c7320a49a9 | ||
|
|
8d9a896166 | ||
|
|
81a057416f | ||
|
|
361326e06c | ||
|
|
0d31afaff8 | ||
|
|
48ad3973a9 | ||
|
|
f6f25296a0 | ||
|
|
cb62076f8c | ||
|
|
8034e567f1 | ||
|
|
59546c8980 | ||
|
|
eee0e6adc8 | ||
|
|
fa10ee4356 | ||
|
|
5bc8d51a9e | ||
|
|
361d6cf517 | ||
|
|
6800609fa7 | ||
|
|
dac13ba4bb | ||
|
|
702075eba6 | ||
|
|
3b62bd0bce | ||
|
|
4cc24f4369 | ||
|
|
cfe21876e5 | ||
|
|
ef2bfe4ea0 | ||
|
|
14731c0a1d | ||
|
|
93747af215 | ||
|
|
76efd26da0 | ||
|
|
cf2001de5f | ||
|
|
6d00877231 | ||
|
|
6755a0912b | ||
|
|
b6ac23be3d | ||
|
|
e941cafedb | ||
|
|
03fe077b41 | ||
|
|
12ef879860 | ||
|
|
179e047474 | ||
|
|
d497190aa1 | ||
|
|
e078c1e793 | ||
|
|
7471f46a07 | ||
|
|
8cee3c3c3e | ||
|
|
97bcbf5d84 | ||
|
|
3fce9ed9a4 | ||
|
|
21ffcc74db | ||
|
|
9e99db9a8e | ||
|
|
5fd38c5f67 | ||
|
|
03ed914714 | ||
|
|
42faffe6f3 | ||
|
|
bc80e910ed | ||
|
|
30a95d735a | ||
|
|
f01a227470 | ||
|
|
91b65c9380 | ||
|
|
18c47843f1 | ||
|
|
d5fe377c11 | ||
|
|
ed4a613473 | ||
|
|
112098514d | ||
|
|
31aa1ea474 | ||
|
|
96b6e4a76e | ||
|
|
001b95d12a | ||
|
|
3b2c862320 | ||
|
|
230f849229 | ||
|
|
c37253fe5a | ||
|
|
0ed8d3859d | ||
|
|
6963d77f8a | ||
|
|
02ea52f453 | ||
|
|
cdabc057a0 | ||
|
|
eb0d75711a | ||
|
|
f121119283 | ||
|
|
d9c1b66931 | ||
|
|
2f60e0a59e | ||
|
|
ffe9e92b48 | ||
|
|
aa90a53f34 | ||
|
|
598c923506 | ||
|
|
8c4b473d6f | ||
|
|
a4fe274c25 | ||
|
|
34597ce6a0 | ||
|
|
4a2af807b2 | ||
|
|
d0ec35628f | ||
|
|
bfdbd00092 | ||
|
|
d0278d8663 | ||
|
|
632bc2aaec | ||
|
|
1ca59f25d0 | ||
|
|
1d0c8fa113 | ||
|
|
1d70c989be | ||
|
|
818a0d0296 | ||
|
|
ab1eb146c9 | ||
|
|
63054ae0fd | ||
|
|
155040240d | ||
|
|
d466cab1e8 | ||
|
|
4e8b34f42e | ||
|
|
5014f55c48 | ||
|
|
1d78cd0f03 | ||
|
|
52d62c6b21 | ||
|
|
b4a73f33ce | ||
|
|
f9c25608e9 | ||
|
|
9fb9e63554 | ||
|
|
9ce8a9f5f0 | ||
|
|
cc59730c5b | ||
|
|
0a04904b75 | ||
|
|
9ed6e9af65 | ||
|
|
c424a9bf5a | ||
|
|
9d811e1267 | ||
|
|
af6f62701c | ||
|
|
299574221e | ||
|
|
fe0c269382 | ||
|
|
579a324ce7 | ||
|
|
7903c14993 | ||
|
|
b42a04c24e | ||
|
|
ea52e45335 | ||
|
|
9687e6e1dd | ||
|
|
ee34200e5f | ||
|
|
295fc6c619 | ||
|
|
28473d314a | ||
|
|
35f7340dc9 | ||
|
|
b76567e7d1 | ||
|
|
652db60ad6 | ||
|
|
a7cb0a166a | ||
|
|
f363541611 | ||
|
|
fa1fba7fd9 | ||
|
|
d73fa09774 | ||
|
|
b1cd730db2 | ||
|
|
359a048b6e | ||
|
|
f2be601a13 | ||
|
|
4d2379b3df | ||
|
|
fd32b2252f | ||
|
|
d15915ef14 | ||
|
|
877e0e0b91 | ||
|
|
da1d9f68c7 | ||
|
|
24f41ef897 | ||
|
|
09dff85d5b | ||
|
|
20e5685c1a | ||
|
|
ac6232bc87 | ||
|
|
b16ec83a33 | ||
|
|
ed72baca2a | ||
|
|
edb562d2e5 | ||
|
|
6d4b128611 | ||
|
|
e2e01e84fa | ||
|
|
93ee417567 | ||
|
|
44cdcd12c3 | ||
|
|
ed06981f57 | ||
|
|
ec6c42e9d6 | ||
|
|
b11d121c48 | ||
|
|
cdf6000618 | ||
|
|
2e8094b712 | ||
|
|
a9cb4f8245 | ||
|
|
1bd41bf79a | ||
|
|
08ab34cf57 | ||
|
|
7bb55469fe | ||
|
|
a29dd738f2 | ||
|
|
4a98b41d57 | ||
|
|
6fc5097278 | ||
|
|
12f2f654dd | ||
|
|
0649b360fb | ||
|
|
f1f314270d | ||
|
|
1fb9f90f0f | ||
|
|
bfa8da78a6 | ||
|
|
fb81733b2b | ||
|
|
e7eac583da | ||
|
|
cd107855e7 | ||
|
|
ab9307ac61 | ||
|
|
e3ef194b4f | ||
|
|
ab4ca9ad8c | ||
|
|
3fb5648880 | ||
|
|
a7c0616cd8 | ||
|
|
51d5ff0567 | ||
|
|
0665146dcd | ||
|
|
1f8422575e | ||
|
|
61c381a62c | ||
|
|
56d5f1588a | ||
|
|
c05334dfc1 | ||
|
|
09d6c7a54f | ||
|
|
4fe44447a2 | ||
|
|
23c600eef5 | ||
|
|
50f091ab7c | ||
|
|
7437f7eb85 | ||
|
|
d6a99981d6 | ||
|
|
71fe652556 | ||
|
|
89917ef688 | ||
|
|
097e4c9799 | ||
|
|
2c37a1e971 | ||
|
|
2c52364978 | ||
|
|
10140f74dc | ||
|
|
558e8f46ff | ||
|
|
9ccb71205a | ||
|
|
e50bcaa272 | ||
|
|
86a28e8201 | ||
|
|
95cd0c6e53 | ||
|
|
23ab245cec | ||
|
|
eb82476591 | ||
|
|
f1f70d250a | ||
|
|
98a221d6b6 | ||
|
|
fb22d12b0f | ||
|
|
83249ed69f | ||
|
|
1534df0b3c | ||
|
|
ece9177f5a | ||
|
|
8a90d74340 | ||
|
|
5a06fad31e | ||
|
|
add07259f4 | ||
|
|
36ca18bc7b | ||
|
|
6003be3fae | ||
|
|
6d9399e3a0 | ||
|
|
676800476d | ||
|
|
4dfa3157e5 | ||
|
|
f26cfa2d94 | ||
|
|
d3328406a2 | ||
|
|
3564b3f9ea | ||
|
|
b81faeccfa | ||
|
|
1c4cb2cd2d | ||
|
|
6959b76749 | ||
|
|
8a1e920e23 | ||
|
|
606519c515 | ||
|
|
34618e0294 | ||
|
|
373762dedc | ||
|
|
b30dfb166b | ||
|
|
36db3257f3 | ||
|
|
cad23465a5 | ||
|
|
d23401316e | ||
|
|
b49e025703 | ||
|
|
e4f4706508 | ||
|
|
02fe73d1f3 | ||
|
|
74f43d4e09 | ||
|
|
54ed050ecf | ||
|
|
f262d3b34b | ||
|
|
32f7860a4e | ||
|
|
b62832e94d | ||
|
|
e5820312d4 | ||
|
|
f710f21ad8 | ||
|
|
90fefb468b | ||
|
|
21f4cafef5 | ||
|
|
b1d4be66e4 | ||
|
|
ef43ae0eea | ||
|
|
9976a139de | ||
|
|
5718354500 | ||
|
|
2d7d9eef9f | ||
|
|
a290e19f46 | ||
|
|
92a2be62fe | ||
|
|
5410dba4f4 | ||
|
|
d93ad2e650 | ||
|
|
68410d35d3 | ||
|
|
ceae4a44f3 | ||
|
|
ea003487aa | ||
|
|
401fd8b56b | ||
|
|
191ee4ba1f | ||
|
|
58556f91f7 | ||
|
|
faa7893761 | ||
|
|
648df0dc7d | ||
|
|
44173dbe8b | ||
|
|
7233f568a7 | ||
|
|
197f1e9b7b | ||
|
|
7063f66b2d | ||
|
|
6e59bcb60e | ||
|
|
0649e6d65f | ||
|
|
072c965ba5 | ||
|
|
122f5fe12e | ||
|
|
a40d599cd7 | ||
|
|
babf36e96e | ||
|
|
d6a43f6a53 | ||
|
|
ff8e38fcc6 | ||
|
|
192f2de704 | ||
|
|
c568b3a976 | ||
|
|
9c818ef3e1 | ||
|
|
5aea30f40d | ||
|
|
09c9395ff8 | ||
|
|
81047afb4b | ||
|
|
f1441cc962 | ||
|
|
50804d661a | ||
|
|
9b895e8a0a | ||
|
|
4600f70fef | ||
|
|
9e33cc998f | ||
|
|
5496c2e76f | ||
|
|
bf75971a3a | ||
|
|
8a59994c0d | ||
|
|
f2e1b7d868 | ||
|
|
8c91b31ae6 | ||
|
|
302b210470 | ||
|
|
5bd0076233 | ||
|
|
0e24adcafd | ||
|
|
696feae32e | ||
|
|
323738e7b8 | ||
|
|
a1d132cd35 | ||
|
|
f7c2665e14 | ||
|
|
ae0b95ec6d | ||
|
|
cdd8200936 | ||
|
|
694075e840 | ||
|
|
d76f994318 | ||
|
|
11b7052f94 | ||
|
|
e93d65d736 | ||
|
|
0f4d543aeb | ||
|
|
dab5f59ed9 | ||
|
|
22a6a82642 | ||
|
|
7b592eff8a | ||
|
|
4be81d9ffd | ||
|
|
55fbecee49 | ||
|
|
f36a3d5b2a | ||
|
|
c5e8e4ff83 | ||
|
|
ccc666c1e4 | ||
|
|
89eda89838 | ||
|
|
17b9838c8f | ||
|
|
889dd83798 | ||
|
|
38a372f25f | ||
|
|
2e6f5ac679 | ||
|
|
7a45fc68d9 | ||
|
|
1288737c0d | ||
|
|
5902306271 | ||
|
|
2fe4521a96 | ||
|
|
74673436a1 | ||
|
|
481748c279 | ||
|
|
9faa5c7a9e | ||
|
|
6fbb25c0da | ||
|
|
65fc42cce5 | ||
|
|
736b7727b6 | ||
|
|
fa920f8449 | ||
|
|
01aa56606f | ||
|
|
bddd5bc678 | ||
|
|
f6b7e39ce7 | ||
|
|
1363dd8f34 | ||
|
|
8214f0c09d | ||
|
|
ff7c46f5a6 | ||
|
|
b44f5825a5 | ||
|
|
631910bd67 | ||
|
|
37089ef940 | ||
|
|
4ef27a0d23 | ||
|
|
476ccc9f6b | ||
|
|
89dc14fcaf | ||
|
|
1ca2f12d24 | ||
|
|
20b2f5ee2f | ||
|
|
3cc67c48cf | ||
|
|
f9a04696f2 | ||
|
|
e0e8170fe6 | ||
|
|
9b40663d54 | ||
|
|
a517f900e4 | ||
|
|
350f40300c | ||
|
|
d3db5f0d76 | ||
|
|
7e3af4b3cd | ||
|
|
dfb3072381 | ||
|
|
02191135a0 | ||
|
|
dc2c97fe0c | ||
|
|
6068b565f5 | ||
|
|
a21cef7190 | ||
|
|
461ef6cea5 | ||
|
|
e05199ca1e | ||
|
|
12d82eb768 | ||
|
|
05becf3f4b | ||
|
|
3cc7981c82 | ||
|
|
8f287eeef9 | ||
|
|
ce05cb5683 | ||
|
|
17945a7377 | ||
|
|
3a1b47129e | ||
|
|
6ffa751090 | ||
|
|
c3641321d7 | ||
|
|
446173f0cb | ||
|
|
e27f381842 | ||
|
|
a3ee76dddd | ||
|
|
995265c549 | ||
|
|
03629b74d9 | ||
|
|
b069278e98 | ||
|
|
9738c88f95 | ||
|
|
a21ea30be0 | ||
|
|
64752da42d | ||
|
|
e3e18063c6 | ||
|
|
e400eac42b | ||
|
|
a6bf77718c | ||
|
|
c2787a9ea9 | ||
|
|
e33e6e2413 | ||
|
|
3cb56c5a2e | ||
|
|
91984cb7e7 | ||
|
|
b8d5dd1824 | ||
|
|
88b66f2941 | ||
|
|
3c7e59b9e1 | ||
|
|
c4471e3300 | ||
|
|
16111f46ef | ||
|
|
b019b03946 | ||
|
|
605acd24ba | ||
|
|
c8630eee95 | ||
|
|
4040555532 | ||
|
|
defb221c98 | ||
|
|
e7dc094e56 | ||
|
|
dfdb107105 | ||
|
|
9f598dfdb7 | ||
|
|
38110a833d | ||
|
|
484d15dbb2 | ||
|
|
1decf5d0d4 | ||
|
|
74e9de1b71 | ||
|
|
015d2b0830 | ||
|
|
c75a9539ba | ||
|
|
ca6149abcf | ||
|
|
b3120aea25 | ||
|
|
54e5bf0f0c | ||
|
|
847cae5b95 | ||
|
|
df15c97b6e | ||
|
|
0d97b58265 | ||
|
|
f7bc61e874 | ||
|
|
8d5a53f529 | ||
|
|
20f9492899 | ||
|
|
3cd1d46a1b | ||
|
|
88eceec257 | ||
|
|
d00ec024a2 | ||
|
|
0bcd53778a | ||
|
|
7592eaf42b | ||
|
|
12ed9e044a | ||
|
|
0a3af87aee | ||
|
|
4dee999f68 | ||
|
|
9a4941c794 | ||
|
|
2d0fd71159 | ||
|
|
327582be31 | ||
|
|
21aea281bd | ||
|
|
975f85260d | ||
|
|
f29d768989 | ||
|
|
9bd7ecad4c | ||
|
|
cc458a9693 | ||
|
|
d2bd9a2368 | ||
|
|
b909a5063a | ||
|
|
b2c1f6122e | ||
|
|
a761e98e18 | ||
|
|
e12e7b2acc | ||
|
|
f927c41abb | ||
|
|
249acace08 | ||
|
|
fa37922ca7 | ||
|
|
021990b8e0 | ||
|
|
540564694c | ||
|
|
8da4feb83c | ||
|
|
23f5e9dacc | ||
|
|
6ff9435e0a | ||
|
|
40006c6152 | ||
|
|
b256e4c2e3 | ||
|
|
a37a09c09c | ||
|
|
8ece231d8b | ||
|
|
e7de0745ad | ||
|
|
7af2d5dfe1 | ||
|
|
2f2f14bf80 | ||
|
|
c59cb6a828 | ||
|
|
06aaf5b571 | ||
|
|
65d7909466 | ||
|
|
861192c332 | ||
|
|
c63af05427 | ||
|
|
d07ba6971b | ||
|
|
4b40d63dfd | ||
|
|
a99b7f6902 | ||
|
|
b3391f699f | ||
|
|
5a3c12cc6b | ||
|
|
a05fd9b818 | ||
|
|
6c1ec59a5b | ||
|
|
e25a4b0abc | ||
|
|
a060f135b8 | ||
|
|
f5d3087e9b | ||
|
|
2795404cd7 | ||
|
|
16fac50db4 | ||
|
|
3806eb3139 | ||
|
|
bad66e54fa | ||
|
|
5cb6c4af4b | ||
|
|
69f79f8598 | ||
|
|
573011a99e | ||
|
|
d778b8e71c | ||
|
|
432a7574c9 | ||
|
|
4d2598e7bf | ||
|
|
2e565bcb4e | ||
|
|
62ecb6da0b | ||
|
|
46fcebe2b5 | ||
|
|
ab1901eeac | ||
|
|
29d2fc6ebc | ||
|
|
efe4599bd8 | ||
|
|
4fc1e41b16 | ||
|
|
e771d60ec0 | ||
|
|
e2de106d71 | ||
|
|
adea89f3eb | ||
|
|
361015497c | ||
|
|
5e9c433a24 | ||
|
|
587159448a | ||
|
|
64158cf513 | ||
|
|
a567365d7c | ||
|
|
57bf220e40 | ||
|
|
e6e3cc474d | ||
|
|
33c984e456 | ||
|
|
458f79f44f | ||
|
|
34e04b0327 | ||
|
|
cf7bb9e99f | ||
|
|
1af5343e29 | ||
|
|
a5e3a7cbc9 | ||
|
|
df065dbbcb | ||
|
|
fac7247483 | ||
|
|
60050af186 | ||
|
|
11c47570ce | ||
|
|
f8b4cc52f6 | ||
|
|
748943f6fc | ||
|
|
d945c5811c | ||
|
|
6fe2741f2d | ||
|
|
24d7cfe0f9 | ||
|
|
630933b148 | ||
|
|
e8a16c6f53 | ||
|
|
2cb50730a1 | ||
|
|
efae6c7fd2 | ||
|
|
8a559beeb8 | ||
|
|
7149fc1e39 | ||
|
|
2e695334c1 | ||
|
|
e2b4554a5c | ||
|
|
ef87dd5a6e | ||
|
|
4f126b37d0 | ||
|
|
1b4187e51f | ||
|
|
0daec91683 | ||
|
|
cbaaec98ca | ||
|
|
895d1d5813 | ||
|
|
e99a651165 | ||
|
|
0ae69b3114 | ||
|
|
95ccc48d0c | ||
|
|
29253046d5 | ||
|
|
340362d984 | ||
|
|
85ece88268 | ||
|
|
516e4578ea | ||
|
|
9829be1045 | ||
|
|
b28a16c0da | ||
|
|
4d13d57491 | ||
|
|
be6bc7460b | ||
|
|
efdd42c6a8 | ||
|
|
c1a97f6541 | ||
|
|
ea4276c7ac | ||
|
|
7bce97f817 | ||
|
|
483a63156b | ||
|
|
5a4bbe4985 | ||
|
|
f86dbafad0 | ||
|
|
8744d360a3 | ||
|
|
b6bd57a764 | ||
|
|
f2b55527d5 | ||
|
|
84a6899c6c | ||
|
|
8cffe22295 | ||
|
|
0c85240b97 | ||
|
|
58ab88da82 | ||
|
|
3e219dee36 | ||
|
|
6ad5bd2325 | ||
|
|
2a97535e75 | ||
|
|
0e0e12a769 | ||
|
|
3bebedf1f8 | ||
|
|
2ed937db2c | ||
|
|
d243bd04ef | ||
|
|
3623638be7 | ||
|
|
8ea3669a64 | ||
|
|
8fe5293077 | ||
|
|
825fa915ee | ||
|
|
885e8ea24a | ||
|
|
898f75ce57 | ||
|
|
b8af100c63 | ||
|
|
3075945367 | ||
|
|
d602ebfde5 | ||
|
|
305512a2b7 | ||
|
|
a6b244b12e | ||
|
|
ceabbeaa2f | ||
|
|
3995852cc5 | ||
|
|
9793bcba6f | ||
|
|
0727eb4374 | ||
|
|
f8f67fcbce | ||
|
|
abeca2d305 | ||
|
|
a7dc86001c | ||
|
|
c071586ae5 | ||
|
|
c6187be210 | ||
|
|
f9f3bb7761 | ||
|
|
1a5c423984 | ||
|
|
b382dffdec | ||
|
|
33e9eb098c | ||
|
|
e77ebfe38a | ||
|
|
698ed9d5fc | ||
|
|
b07a8501d6 | ||
|
|
f779e724e2 | ||
|
|
494b98e46a | ||
|
|
d1ff057889 | ||
|
|
292302c6d1 | ||
|
|
b55fead749 | ||
|
|
844e027a18 | ||
|
|
0fb80cd7a9 | ||
|
|
311b412f5d | ||
|
|
975200834e | ||
|
|
c8fa799883 | ||
|
|
7f37eef218 | ||
|
|
8521e45edc | ||
|
|
7bd082563d | ||
|
|
de32e245c9 | ||
|
|
f5164325d2 | ||
|
|
959bfe2a9d | ||
|
|
d24cf11ad4 | ||
|
|
8d89ba39d4 | ||
|
|
b04596a32b | ||
|
|
8e8865940a | ||
|
|
3c14f9760f | ||
|
|
3c15b141e0 | ||
|
|
72f801283d | ||
|
|
2ffaf72e39 | ||
|
|
f41c532400 | ||
|
|
ec76431c51 | ||
|
|
71961a88a0 | ||
|
|
ba944527ec | ||
|
|
87c9d819a1 | ||
|
|
13c0684497 | ||
|
|
c24cab6d1d | ||
|
|
0cbe6abbd5 | ||
|
|
fe6e5e445b | ||
|
|
781c90b940 | ||
|
|
e7a8bb1140 | ||
|
|
f1c13af703 | ||
|
|
90bc8d9110 | ||
|
|
193cc06561 | ||
|
|
f3b475453f | ||
|
|
0c71f5a4e9 | ||
|
|
4b0dfd4f4a | ||
|
|
2d117f68c9 | ||
|
|
8954858bf7 | ||
|
|
4877e6dbba | ||
|
|
ec171c5f00 | ||
|
|
840ddcecd2 | ||
|
|
c00f7409ee | ||
|
|
92449a4fe4 | ||
|
|
4e2a035838 | ||
|
|
df25fa73af | ||
|
|
03bb2d04c3 | ||
|
|
4dc376b0ee | ||
|
|
3dec5698db | ||
|
|
f8bbe9be48 | ||
|
|
4d01b2d5ac | ||
|
|
086f02c1d9 | ||
|
|
8ed6c32ae7 | ||
|
|
d0e0525302 | ||
|
|
318c981c00 | ||
|
|
5c7db42fc4 | ||
|
|
4be92e14e6 | ||
|
|
1b155d9d4c | ||
|
|
f9a1aba0d8 | ||
|
|
fe65e07cb6 | ||
|
|
bb12806da1 | ||
|
|
fa36042131 | ||
|
|
efaad99f25 | ||
|
|
62d820c261 | ||
|
|
a53d795361 | ||
|
|
2e60c4dd2e | ||
|
|
ce8a13a562 | ||
|
|
ff2321a8ce | ||
|
|
4228e3e890 | ||
|
|
023b574fc5 | ||
|
|
a77df57f1c | ||
|
|
8f553e89ce | ||
|
|
b7810ffdb3 | ||
|
|
0d3401058d | ||
|
|
6e123ccc36 | ||
|
|
f2724df566 | ||
|
|
646d71d927 | ||
|
|
9b9b41e605 | ||
|
|
907ccfb280 | ||
|
|
fcd7c117e7 | ||
|
|
323922d854 | ||
|
|
f97e3bad33 | ||
|
|
64415555f1 | ||
|
|
ab2aef3f2b | ||
|
|
947db1e21b | ||
|
|
cde607c09c | ||
|
|
739b113f57 | ||
|
|
64585eebf6 | ||
|
|
1050acc290 | ||
|
|
466bb9ed0b | ||
|
|
581133ecce |
@@ -0,0 +1,88 @@
|
|||||||
|
# Configuration for checkpatch.pl
|
||||||
|
# ===============================
|
||||||
|
|
||||||
|
# Enable more tests
|
||||||
|
--strict
|
||||||
|
|
||||||
|
# Quiet
|
||||||
|
--quiet
|
||||||
|
|
||||||
|
# No per-file summary
|
||||||
|
--no-summary
|
||||||
|
|
||||||
|
# Don't expect the Linux kernel tree
|
||||||
|
--no-tree
|
||||||
|
|
||||||
|
# Show file line, not input line
|
||||||
|
--showfile
|
||||||
|
|
||||||
|
# Don't expect SPDX tag in the first line of a file
|
||||||
|
--ignore SPDX_LICENSE_TAG
|
||||||
|
|
||||||
|
# Don't expect Signed-off-by lines in commit messages
|
||||||
|
--no-signoff
|
||||||
|
|
||||||
|
# List of ignored rules
|
||||||
|
# ---------------------
|
||||||
|
|
||||||
|
# There's no BIT macro
|
||||||
|
--ignore BIT_MACRO
|
||||||
|
|
||||||
|
# Don't complain when bools are used in structs
|
||||||
|
--ignore BOOL_MEMBER
|
||||||
|
|
||||||
|
# Allow CamelCase
|
||||||
|
--ignore CAMELCASE
|
||||||
|
|
||||||
|
# Comparing to NULL explicitly isn't a bad thing
|
||||||
|
--ignore COMPARISON_TO_NULL
|
||||||
|
|
||||||
|
# Causes false positives
|
||||||
|
--ignore COMPLEX_MACRO
|
||||||
|
|
||||||
|
# Don't complain about structs not being const
|
||||||
|
--ignore CONST_STRUCT
|
||||||
|
|
||||||
|
# Don't complain about printing "warning:" without the function name, as warning
|
||||||
|
# printing is relevant to the code being parsed, not RGBDS' code
|
||||||
|
--ignore EMBEDDED_FUNCTION_NAME
|
||||||
|
|
||||||
|
# Do not check the format of commit messages
|
||||||
|
--ignore GIT_COMMIT_ID
|
||||||
|
|
||||||
|
# Do not check for global initializers (this is specific to the kernel)
|
||||||
|
--ignore GLOBAL_INITIALISERS
|
||||||
|
|
||||||
|
# Don't complain about initializing statics (this is specific to the kernel)
|
||||||
|
--ignore INITIALISED_STATIC
|
||||||
|
|
||||||
|
# We don't have a MAINTAINERS file, don't complain about it.
|
||||||
|
--ignore FILE_PATH_CHANGES
|
||||||
|
|
||||||
|
# Writing the continuation on the start of the line can make it clearer
|
||||||
|
--ignore LOGICAL_CONTINUATIONS
|
||||||
|
|
||||||
|
# Don't complain if a line that contains a string is too long. It's better to
|
||||||
|
# have a really long line that can be found with grep.
|
||||||
|
--ignore LONG_LINE_STRING
|
||||||
|
|
||||||
|
# Don't complain when files are modified in 'include/asm'
|
||||||
|
--ignore MODIFIED_INCLUDE_ASM
|
||||||
|
|
||||||
|
# Allow new typedefs
|
||||||
|
--ignore NEW_TYPEDEFS
|
||||||
|
|
||||||
|
# We allow lines ending with parentheses for the usage prints
|
||||||
|
--ignore OPEN_ENDED_LINE
|
||||||
|
|
||||||
|
# Prefer stdint.h types over kernel types
|
||||||
|
--ignore PREFER_KERNEL_TYPES
|
||||||
|
|
||||||
|
# Don't ask to replace sscanf by kstrto
|
||||||
|
--ignore SSCANF_TO_KSTRTO
|
||||||
|
|
||||||
|
# Parentheses can make the code clearer
|
||||||
|
--ignore UNNECESSARY_PARENTHESES
|
||||||
|
|
||||||
|
# We don't have `fallthrough;` */
|
||||||
|
--ignore PREFER_FALLTHROUGH
|
||||||
@@ -0,0 +1,7 @@
|
|||||||
|
# This file is part of RGBDS.
|
||||||
|
#
|
||||||
|
# Copyright (c) 2018-2019, Phil Smith and RGBDS contributors.
|
||||||
|
#
|
||||||
|
# SPDX-License-Identifier: MIT
|
||||||
|
.git
|
||||||
|
docs
|
||||||
@@ -0,0 +1,3 @@
|
|||||||
|
github: avivace
|
||||||
|
patreon: gbdev01
|
||||||
|
open_collective: gbdev
|
||||||
Executable
+56
@@ -0,0 +1,56 @@
|
|||||||
|
#!/usr/bin/awk -f
|
||||||
|
|
||||||
|
/^\s+<td><b class="Sy">.+<\/b><\/td>$/ {
|
||||||
|
# Assuming that all cells whose contents are bold are heading cells,
|
||||||
|
# use the HTML tag for those
|
||||||
|
sub(/td><b class="Sy"/, "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 {
|
||||||
|
in_synopsis = 0
|
||||||
|
}
|
||||||
|
/<table class="Nm">/ {
|
||||||
|
in_synopsis = 1
|
||||||
|
}
|
||||||
|
/<\/table>/ {
|
||||||
|
# Resets synopsis state even when already reset, but whatever
|
||||||
|
in_synopsis = 0
|
||||||
|
}
|
||||||
|
/<code class="Fl">-[a-zA-Z]/ {
|
||||||
|
# Add links to arg descr in synopsis section
|
||||||
|
if (in_synopsis) {
|
||||||
|
while (match($0, /<code class="Fl">-[a-zA-Z]+/)) {
|
||||||
|
# 123456789012345678 -> 18 chars
|
||||||
|
optchars = substr($0, RSTART + 18, RLENGTH - 18)
|
||||||
|
i = length(optchars)
|
||||||
|
while (i) {
|
||||||
|
end = RSTART + 18 + i
|
||||||
|
i -= 1
|
||||||
|
len = i ? 1 : 2
|
||||||
|
$0 = sprintf("%s<a href=\"#%s\">%s</a>%s",
|
||||||
|
substr($0, 0, end - len - 1),
|
||||||
|
substr($0, end - 1, 1),
|
||||||
|
substr($0, end - len, len),
|
||||||
|
substr($0, end))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
{
|
||||||
|
# Make long opts (defined using `Fl Fl`) into a single tag
|
||||||
|
gsub(/<code class="Fl">-<\/code>\s*<code class="Fl">/, "<code class=\"Fl\">-")
|
||||||
|
}
|
||||||
|
|
||||||
|
{
|
||||||
|
print
|
||||||
|
}
|
||||||
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[@]##*/}"
|
||||||
Executable
+18
@@ -0,0 +1,18 @@
|
|||||||
|
case `echo $1 | cut -d '-' -f 1` in
|
||||||
|
ubuntu)
|
||||||
|
sudo apt-get -qq update
|
||||||
|
sudo apt-get install -yq bison libpng-dev pkg-config
|
||||||
|
;;
|
||||||
|
macos)
|
||||||
|
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'"
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
|
||||||
|
bison --version
|
||||||
|
make --version
|
||||||
|
cmake --version
|
||||||
@@ -0,0 +1,17 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
source mingw-env @TRIPLE@
|
||||||
|
echo LAST IS: $last
|
||||||
|
|
||||||
|
# check if last arg is a path to configure, else use parent
|
||||||
|
for last; do true; done
|
||||||
|
if test -x "${last}/configure"; then
|
||||||
|
config_path="$last"
|
||||||
|
else
|
||||||
|
config_path=".."
|
||||||
|
fi
|
||||||
|
|
||||||
|
${config_path}/configure \
|
||||||
|
--host=@TRIPLE@ --target=@TRIPLE@ --build="$CHOST" \
|
||||||
|
--prefix=/usr/@TRIPLE@ --libdir=/usr/@TRIPLE@/lib --includedir=/usr/@TRIPLE@/include \
|
||||||
|
--enable-shared --enable-static "$@"
|
||||||
@@ -0,0 +1,16 @@
|
|||||||
|
#!/bin/sh
|
||||||
|
|
||||||
|
_arch=$1
|
||||||
|
|
||||||
|
default_mingw_pp_flags="-D_FORTIFY_SOURCE=2"
|
||||||
|
default_mingw_compiler_flags="$default_mingw_pp_flags -O2 -pipe -fno-plt -fexceptions --param=ssp-buffer-size=4"
|
||||||
|
default_mingw_linker_flags="-Wl,-O1,--sort-common,--as-needed -fstack-protector"
|
||||||
|
|
||||||
|
export CPPFLAGS="${MINGW_CPPFLAGS:-$default_mingw_pp_flags $CPPFLAGS}"
|
||||||
|
export CFLAGS="${MINGW_CFLAGS:-$default_mingw_compiler_flags $CFLAGS}"
|
||||||
|
export CXXFLAGS="${MINGW_CXXFLAGS:-$default_mingw_compiler_flags $CXXFLAGS}"
|
||||||
|
export LDFLAGS="${MINGW_LDFLAGS:-$default_mingw_linker_flags $LDFLAGS}"
|
||||||
|
|
||||||
|
mingw_prefix=/usr/${_arch}
|
||||||
|
export PKG_CONFIG_SYSROOT_DIR="${mingw_prefix}"
|
||||||
|
export PKG_CONFIG_LIBDIR="${mingw_prefix}/lib/pkgconfig:${mingw_prefix}/share/pkgconfig"
|
||||||
Executable
+44
@@ -0,0 +1,44 @@
|
|||||||
|
#!/bin/sh
|
||||||
|
|
||||||
|
# This script was written by ISSOtm while looking at Arch Linux's PKGBUILD for
|
||||||
|
# the corresponding package. (And its dependencies)
|
||||||
|
# https://aur.archlinux.org/packages/mingw-w64-libpng/
|
||||||
|
|
||||||
|
set -e
|
||||||
|
|
||||||
|
pngver=1.6.37
|
||||||
|
_apngver=$pngver
|
||||||
|
_arch="$1"
|
||||||
|
|
||||||
|
|
||||||
|
## Install mingw-configure and mingw-env (both build dependencies)
|
||||||
|
|
||||||
|
install -m 755 .github/actions/mingw-env.sh /usr/bin/mingw-env
|
||||||
|
|
||||||
|
sed "s|@TRIPLE@|${_arch}|g" .github/actions/mingw-configure.sh > ${_arch}-configure
|
||||||
|
install -m 755 ${_arch}-configure /usr/bin/
|
||||||
|
|
||||||
|
|
||||||
|
## Grab sources and check them
|
||||||
|
|
||||||
|
wget http://downloads.sourceforge.net/sourceforge/libpng/libpng-$pngver.tar.xz
|
||||||
|
wget http://downloads.sourceforge.net/project/apng/libpng/libpng16/libpng-$_apngver-apng.patch.gz
|
||||||
|
sha256sum -c .github/actions/mingw-w64-libpng-dev.sha256sums
|
||||||
|
|
||||||
|
## Extract sources
|
||||||
|
|
||||||
|
tar -xf libpng-$pngver.tar.xz
|
||||||
|
gunzip libpng-$_apngver-apng.patch.gz
|
||||||
|
|
||||||
|
|
||||||
|
## Start building!
|
||||||
|
|
||||||
|
cd libpng-$pngver
|
||||||
|
# Patch in apng support
|
||||||
|
patch -p0 ../libpng-$_apngver-apng.patch
|
||||||
|
|
||||||
|
mkdir -p build-${_arch}
|
||||||
|
cd build-${_arch}
|
||||||
|
${_arch}-configure LDFLAGS=-static-libgcc
|
||||||
|
make
|
||||||
|
make install
|
||||||
@@ -0,0 +1,2 @@
|
|||||||
|
10d9e0cb60e2b387a79b355eb7527c0bee2ed8cbd12cf04417cabc4d6976683c libpng-1.6.37-apng.patch.gz
|
||||||
|
505e70834d35383537b6491e7ae8641f1a4bed1876dbfe361201fc80868d88ca libpng-1.6.37.tar.xz
|
||||||
@@ -0,0 +1,25 @@
|
|||||||
|
name: "Code style checking"
|
||||||
|
on: pull_request
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
checkpatch:
|
||||||
|
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: Set up checkpatch
|
||||||
|
working-directory: rgbds
|
||||||
|
run: |
|
||||||
|
wget 'https://raw.githubusercontent.com/torvalds/linux/master/scripts/checkpatch.pl'
|
||||||
|
chmod +x checkpatch.pl
|
||||||
|
wget 'https://raw.githubusercontent.com/torvalds/linux/master/scripts/const_structs.checkpatch'
|
||||||
|
wget 'https://raw.githubusercontent.com/torvalds/linux/master/scripts/spelling.txt'
|
||||||
|
- name: Checkpatch
|
||||||
|
working-directory: rgbds
|
||||||
|
run: |
|
||||||
|
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,52 @@
|
|||||||
|
name: "Create release docs"
|
||||||
|
on:
|
||||||
|
release:
|
||||||
|
types:
|
||||||
|
- released # This avoids triggering on pre-releases
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
build:
|
||||||
|
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
|
||||||
@@ -0,0 +1,200 @@
|
|||||||
|
name: "Regression testing"
|
||||||
|
on:
|
||||||
|
- push
|
||||||
|
- pull_request
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
unix-testing:
|
||||||
|
strategy:
|
||||||
|
matrix:
|
||||||
|
os: [ubuntu-20.04, ubuntu-18.04, ubuntu-16.04, macos-10.15]
|
||||||
|
cc: [gcc, clang]
|
||||||
|
buildsys: [make, cmake]
|
||||||
|
include:
|
||||||
|
- os: ubuntu-18.04
|
||||||
|
cc: gcc
|
||||||
|
target: develop
|
||||||
|
cmakevars: -DSANITIZERS=ON -DMORE_WARNINGS=ON -DCMAKE_BUILD_TYPE=Debug
|
||||||
|
- os: ubuntu-20.04
|
||||||
|
cc: gcc
|
||||||
|
target: develop
|
||||||
|
cmakevars: -DSANITIZERS=ON -DMORE_WARNINGS=ON -DCMAKE_BUILD_TYPE=Debug
|
||||||
|
fail-fast: false
|
||||||
|
runs-on: ${{ matrix.os }}
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v2
|
||||||
|
- name: Install deps
|
||||||
|
shell: bash
|
||||||
|
run: |
|
||||||
|
./.github/actions/install_deps.sh ${{ matrix.os }}
|
||||||
|
# The `export` lines are to allow working on macOS...
|
||||||
|
# Apple's base version is severely outdated, not even supporting -Wall,
|
||||||
|
# but it overrides Homebrew's version nonetheless...
|
||||||
|
- name: Build & install using Make
|
||||||
|
run: |
|
||||||
|
export PATH="/usr/local/opt/bison/bin:$PATH"
|
||||||
|
make ${{ matrix.target }} -j Q= CC=${{ matrix.cc }}
|
||||||
|
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=Release -DCMAKE_C_COMPILER=${{ matrix.cc }} ${{ matrix.cmakevars }}
|
||||||
|
cmake --build build
|
||||||
|
cp build/src/rgb{asm,link,fix,gfx} .
|
||||||
|
sudo cmake --install build
|
||||||
|
if: matrix.buildsys == 'cmake'
|
||||||
|
- name: Package binaries
|
||||||
|
run: |
|
||||||
|
mkdir bins
|
||||||
|
cp rgb{asm,link,fix,gfx} bins
|
||||||
|
- name: Upload binaries
|
||||||
|
uses: actions/upload-artifact@v1
|
||||||
|
with:
|
||||||
|
name: rgbds-canary-${{ matrix.os }}-${{ matrix.cc }}-${{ matrix.buildsys }}
|
||||||
|
path: bins
|
||||||
|
- name: Test
|
||||||
|
shell: bash
|
||||||
|
run: |
|
||||||
|
test/run-tests.sh
|
||||||
|
|
||||||
|
windows-testing:
|
||||||
|
strategy:
|
||||||
|
matrix:
|
||||||
|
bits: [32, 64]
|
||||||
|
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/zlib1211.zip', 'zlib.zip')
|
||||||
|
$hash = (Get-FileHash "zlib.zip" -Algorithm SHA256).Hash
|
||||||
|
if ($hash -ne 'd7510a8ee1918b7d0cad197a089c0a2cd4d6df05fee22389f67f115e738b178d') {
|
||||||
|
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.23/win_flex_bison-2.5.23.zip', 'winflexbison.zip')
|
||||||
|
$hash = (Get-FileHash "winflexbison.zip" -Algorithm SHA256).Hash
|
||||||
|
if ($hash -ne '6AA5C8EA662DA1550020A5804C28BE63FFAA53486DA9F6842E24C379EC422DFC') {
|
||||||
|
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.11 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
|
||||||
|
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
|
||||||
|
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
|
||||||
|
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:
|
||||||
|
- bits: 32
|
||||||
|
arch: i686
|
||||||
|
triplet: i686-w64-mingw32
|
||||||
|
- bits: 64
|
||||||
|
arch: x86-64
|
||||||
|
triplet: x86_64-w64-mingw32
|
||||||
|
fail-fast: false
|
||||||
|
runs-on: ${{ matrix.os }}
|
||||||
|
env:
|
||||||
|
DIST_DIR: win${{ matrix.bits }}
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v2
|
||||||
|
- name: Install deps
|
||||||
|
shell: bash
|
||||||
|
run: |
|
||||||
|
./.github/actions/install_deps.sh ${{ matrix.os }}
|
||||||
|
- name: Install MinGW
|
||||||
|
run: |
|
||||||
|
sudo apt-get install gcc-mingw-w64-${{ matrix.arch }} mingw-w64-tools libz-mingw-w64-dev
|
||||||
|
- name: Install libpng dev headers for MinGW
|
||||||
|
run: |
|
||||||
|
sudo ./.github/actions/mingw-w64-libpng-dev.sh ${{ matrix.triplet }}
|
||||||
|
- name: Cross-build Windows binaries
|
||||||
|
run: |
|
||||||
|
make mingw${{ matrix.bits }} -j Q=
|
||||||
|
- name: Package binaries
|
||||||
|
run: |
|
||||||
|
mkdir bins
|
||||||
|
mv rgbasm bins/rgbasm.exe
|
||||||
|
mv rgblink bins/rgblink.exe
|
||||||
|
mv rgbfix bins/rgbfix.exe
|
||||||
|
mv rgbgfx bins/rgbgfx.exe
|
||||||
|
cp /usr/${{ matrix.triplet }}/lib/zlib1.dll bins
|
||||||
|
cp /usr/${{ matrix.triplet }}/bin/libpng16-16.dll bins
|
||||||
|
if [ ${{ matrix.bits }} -eq 32 ]; then cp /usr/lib/gcc/${{ matrix.triplet }}/7.3-win32/libgcc_s_sjlj-1.dll bins; fi
|
||||||
|
- name: Upload Windows binaries
|
||||||
|
uses: actions/upload-artifact@v1
|
||||||
|
with:
|
||||||
|
name: rgbds-canary-mingw-win${{ matrix.bits }}
|
||||||
|
path: bins
|
||||||
|
|
||||||
|
windows-xtesting:
|
||||||
|
needs: windows-xbuild
|
||||||
|
strategy:
|
||||||
|
matrix:
|
||||||
|
bits: [32, 64]
|
||||||
|
fail-fast: false
|
||||||
|
runs-on: windows-2019
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v2
|
||||||
|
- name: Retrieve binaries
|
||||||
|
uses: actions/download-artifact@v1
|
||||||
|
with:
|
||||||
|
name: rgbds-canary-mingw-win${{ matrix.bits }}
|
||||||
|
path: bins
|
||||||
|
- name: Extract binaries
|
||||||
|
shell: bash
|
||||||
|
run: |
|
||||||
|
cp bins/* .
|
||||||
|
- name: Run tests
|
||||||
|
shell: bash
|
||||||
|
run: |
|
||||||
|
test/run-tests.sh
|
||||||
@@ -0,0 +1,65 @@
|
|||||||
|
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:
|
||||||
|
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
|
||||||
@@ -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/zlib1211.zip', 'zlib.zip')
|
||||||
|
$hash = (Get-FileHash "zlib.zip" -Algorithm SHA256).Hash
|
||||||
|
if ($hash -ne 'd7510a8ee1918b7d0cad197a089c0a2cd4d6df05fee22389f67f115e738b178d') {
|
||||||
|
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.23/win_flex_bison-2.5.23.zip', 'winflexbison.zip')
|
||||||
|
$hash = (Get-FileHash "winflexbison.zip" -Algorithm SHA256).Hash
|
||||||
|
if ($hash -ne '6AA5C8EA662DA1550020A5804C28BE63FFAA53486DA9F6842E24C379EC422DFC') {
|
||||||
|
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.11 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 }}
|
||||||
+10
-1
@@ -2,6 +2,15 @@ rgbasm
|
|||||||
rgblink
|
rgblink
|
||||||
rgbfix
|
rgbfix
|
||||||
rgbgfx
|
rgbgfx
|
||||||
|
rgbshim.sh
|
||||||
*.o
|
*.o
|
||||||
*.exe
|
*.exe
|
||||||
*.html
|
*.dll
|
||||||
|
.checkpatch-camelcase.*
|
||||||
|
CMakeCache.txt
|
||||||
|
CMakeFiles
|
||||||
|
cmake_install.cmake
|
||||||
|
|
||||||
|
test/pokecrystal
|
||||||
|
test/pokered
|
||||||
|
test/ucity
|
||||||
|
|||||||
@@ -1,13 +0,0 @@
|
|||||||
#!/bin/sh
|
|
||||||
|
|
||||||
if [ $TRAVIS_OS_NAME = "osx" ]; then
|
|
||||||
brew update
|
|
||||||
brew install libpng pkg-config
|
|
||||||
else # linux
|
|
||||||
sudo apt-get -qq update
|
|
||||||
sudo apt-get install -y -q bison flex libpng-dev pkg-config
|
|
||||||
fi
|
|
||||||
|
|
||||||
echo "Dependencies:"
|
|
||||||
yacc --version
|
|
||||||
flex --version
|
|
||||||
-16
@@ -1,16 +0,0 @@
|
|||||||
language: c
|
|
||||||
sudo: required
|
|
||||||
install:
|
|
||||||
- ./.travis-deps.sh
|
|
||||||
os:
|
|
||||||
- linux
|
|
||||||
- osx
|
|
||||||
compiler:
|
|
||||||
- clang
|
|
||||||
- gcc
|
|
||||||
script:
|
|
||||||
- make
|
|
||||||
- sudo make install
|
|
||||||
after_success:
|
|
||||||
- pushd test/asm/ && ./test.sh && popd
|
|
||||||
- pushd test/link/ && ./test.sh && popd
|
|
||||||
@@ -0,0 +1,97 @@
|
|||||||
|
#
|
||||||
|
# This file is part of RGBDS.
|
||||||
|
#
|
||||||
|
# Copyright (c) 2020 RGBDS contributors.
|
||||||
|
#
|
||||||
|
# SPDX-License-Identifier: MIT
|
||||||
|
#
|
||||||
|
|
||||||
|
# 3.9 required for LTO checks
|
||||||
|
cmake_minimum_required(VERSION 3.9 FATAL_ERROR)
|
||||||
|
|
||||||
|
project(rgbds
|
||||||
|
LANGUAGES C)
|
||||||
|
|
||||||
|
# get real path of source and binary directories
|
||||||
|
get_filename_component(srcdir "${CMAKE_SOURCE_DIR}" REALPATH)
|
||||||
|
get_filename_component(bindir "${CMAKE_BINARY_DIR}" REALPATH)
|
||||||
|
|
||||||
|
# reject in-source builds, may conflict with Makefile
|
||||||
|
if(srcdir STREQUAL bindir)
|
||||||
|
message("RGBDS should not be built in the source directory.")
|
||||||
|
message("Instead, create a separate build directory and specify to CMake the path to the source directory.")
|
||||||
|
message(FATAL_ERROR "Terminating configuration")
|
||||||
|
endif()
|
||||||
|
|
||||||
|
option(SANITIZERS "Build with sanitizers enabled" OFF) # Ignored on MSVC
|
||||||
|
option(MORE_WARNINGS "Turn on more warnings" OFF) # Ignored on MSVC
|
||||||
|
option(TRACE_PARSER "Trace parser execution" OFF)
|
||||||
|
option(TRACE_LEXER "Trace lexer execution" OFF)
|
||||||
|
|
||||||
|
if(MSVC)
|
||||||
|
# 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()
|
||||||
|
add_compile_options(-Wall -pedantic)
|
||||||
|
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)
|
||||||
|
add_compile_options(${SAN_FLAGS})
|
||||||
|
link_libraries(${SAN_FLAGS})
|
||||||
|
endif()
|
||||||
|
|
||||||
|
if(MORE_WARNINGS)
|
||||||
|
add_compile_options(-Werror -Wextra -Wno-type-limits
|
||||||
|
-Wno-sign-compare -Wvla -Wformat -Wformat-security -Wformat-overflow=2
|
||||||
|
-Wformat-truncation=1 -Wformat-y2k -Wswitch-enum -Wunused
|
||||||
|
-Wuninitialized -Wunknown-pragmas -Wstrict-overflow=5
|
||||||
|
-Wstringop-overflow=4 -Walloc-zero -Wduplicated-cond
|
||||||
|
-Wfloat-equal -Wshadow -Wcast-qual -Wcast-align -Wlogical-op
|
||||||
|
-Wnested-externs -Wno-aggressive-loop-optimizations -Winline
|
||||||
|
-Wundef -Wstrict-prototypes -Wold-style-definition)
|
||||||
|
endif()
|
||||||
|
endif()
|
||||||
|
|
||||||
|
# Use versioning consistent with Makefile
|
||||||
|
# the git revision is used but uses the fallback in an archive
|
||||||
|
|
||||||
|
execute_process(COMMAND git describe --tags --dirty --always
|
||||||
|
OUTPUT_VARIABLE GIT_REV
|
||||||
|
ERROR_QUIET)
|
||||||
|
string(STRIP "${GIT_REV}" GIT_REV)
|
||||||
|
|
||||||
|
include_directories("${PROJECT_SOURCE_DIR}/include")
|
||||||
|
|
||||||
|
add_definitions(-DBUILD_VERSION_STRING="${GIT_REV}")
|
||||||
|
|
||||||
|
set(CMAKE_C_STANDARD 11)
|
||||||
|
set(CMAKE_C_STANDARD_REQUIRED True)
|
||||||
|
|
||||||
|
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()
|
||||||
|
|
||||||
|
if(TRACE_PARSER)
|
||||||
|
target_compile_definitions(rgbasm PRIVATE -DYYDEBUG)
|
||||||
|
endif()
|
||||||
|
|
||||||
|
if(TRACE_LEXER)
|
||||||
|
target_compile_definitions(rgbasm PRIVATE -DLEXER_DEBUG)
|
||||||
|
endif()
|
||||||
@@ -0,0 +1,96 @@
|
|||||||
|
Contributing
|
||||||
|
============
|
||||||
|
|
||||||
|
RGBDS was created in the late 90's and has received contributions from several
|
||||||
|
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
|
||||||
|
of other people.
|
||||||
|
|
||||||
|
Reporting Bugs
|
||||||
|
--------------
|
||||||
|
|
||||||
|
Bug reports are essential to improve RGBDS and they are always welcome. If you
|
||||||
|
want to report a bug:
|
||||||
|
|
||||||
|
1. Make sure that there isn't a similar issue already reported
|
||||||
|
`here <https://github.com/rednex/rgbds/issues>`__.
|
||||||
|
|
||||||
|
2. Figure out a way of reproducing it reliably.
|
||||||
|
|
||||||
|
3. If there is a piece of code that triggers the bug, try to reduce it to the
|
||||||
|
smallest file you can.
|
||||||
|
|
||||||
|
4. Create a new `issue <https://github.com/rednex/rgbds/issues>`__.
|
||||||
|
|
||||||
|
Of course, it may not always be possible to give an accurate bug report, but it
|
||||||
|
always helps to fix it.
|
||||||
|
|
||||||
|
Requesting new features
|
||||||
|
-----------------------
|
||||||
|
|
||||||
|
If you come up with a good idea that could be implemented, you can propose it to
|
||||||
|
be done.
|
||||||
|
|
||||||
|
1. Create a new `issue <https://github.com/rednex/rgbds/issues>`__.
|
||||||
|
|
||||||
|
2. Try to be as accurate as possible. Describe what you need and why you need
|
||||||
|
it, maybe with examples.
|
||||||
|
|
||||||
|
Please understand that the contributors are doing it in their free time, so
|
||||||
|
simple requests are more likely to catch the interest of a contributor than
|
||||||
|
complicated ones. If you really need something to be done, and you think you can
|
||||||
|
implement it yourself, you can always contribute to RGBDS with your own code.
|
||||||
|
|
||||||
|
Contributing code
|
||||||
|
-----------------
|
||||||
|
|
||||||
|
If you want to contribute with your own code, whether it is to fix a current
|
||||||
|
issue or to add something that nobody had requested, you should first consider
|
||||||
|
if your change is going to be small (and likely to be accepted as-is) or big
|
||||||
|
(and will have to go through some rework).
|
||||||
|
|
||||||
|
Big changes will most likely require some discussion, so open an
|
||||||
|
`issue <https://github.com/rednex/rgbds/issues>`__ and explain what you want to
|
||||||
|
do and how you intend to do it. If you already have a prototype, it's always a
|
||||||
|
good idea to show it. Tests help, too.
|
||||||
|
|
||||||
|
If you are going to work on a specific issue that involves a lot of work, it is
|
||||||
|
always a good idea to leave a message, just in case someone else is interested
|
||||||
|
but doesn't know that there's someone working on it.
|
||||||
|
|
||||||
|
Note that you must contribute all your changes under the MIT License. If you are
|
||||||
|
just modifying a file, you don't need to do anything (maybe update the copyright
|
||||||
|
years). If you are adding new files, you need to use the correct header with the
|
||||||
|
copyright and the reference to the MIT License.
|
||||||
|
|
||||||
|
1. Fork this repository.
|
||||||
|
|
||||||
|
2. Checkout the ``master`` branch.
|
||||||
|
|
||||||
|
3. Create a new branch to work on. You could still work on ``master``, but it's
|
||||||
|
easier that way.
|
||||||
|
|
||||||
|
4. Compile your changes with ``make develop`` instead of just ``make``. This
|
||||||
|
target checks for additional warnings. Your patches shouldn't introduce any
|
||||||
|
new warning (but it may be possible to remove some warning checks if it makes
|
||||||
|
the code much easier).
|
||||||
|
|
||||||
|
5. Follow the Linux kernel coding style, which can be found in the file
|
||||||
|
``Documentation/process/coding-style.rst`` in the Linux kernel repository.
|
||||||
|
Note that the coding style isn't written in stone, if there is a good reason
|
||||||
|
to deviate from it, it should be fine.
|
||||||
|
|
||||||
|
6. Download the files ``checkpatch.pl``, ``const_structs.checkpatch`` and
|
||||||
|
``spelling.txt`` from the folder ``scripts`` in the Linux kernel repository.
|
||||||
|
|
||||||
|
7. To use ``checkpatch.pl`` you can use ``make checkpatch``, which will check
|
||||||
|
the coding style of all patches between the current one and the upstream
|
||||||
|
code. By default, the Makefile expects the script (and associate files) to be
|
||||||
|
located in ``../linux/scripts/``, but you can place them anywhere you like as
|
||||||
|
long as you specify it when executing the command:
|
||||||
|
``make checkpatch CHECKPATCH=../path/to/folder``.
|
||||||
|
|
||||||
|
8. Create a pull request against the branch ``master``.
|
||||||
|
|
||||||
|
9. Be prepared to get some comments about your code and to modify it. Tip: Use
|
||||||
|
``git rebase -i origin/master`` to modify chains of commits.
|
||||||
@@ -0,0 +1,53 @@
|
|||||||
|
Contributors to RGBDS
|
||||||
|
=====================
|
||||||
|
|
||||||
|
Original author
|
||||||
|
---------------
|
||||||
|
|
||||||
|
- Carsten Elton Sørensen <[email protected]>
|
||||||
|
|
||||||
|
Main contributors
|
||||||
|
-----------------
|
||||||
|
|
||||||
|
- Justin Lloyd <[email protected]>
|
||||||
|
|
||||||
|
- Vegard Nossum <[email protected]>
|
||||||
|
|
||||||
|
- Anthony J. Bentley <[email protected]>
|
||||||
|
|
||||||
|
- stag019 <[email protected]>
|
||||||
|
|
||||||
|
- Antonio Niño Díaz <[email protected]>
|
||||||
|
|
||||||
|
Other contributors
|
||||||
|
------------------
|
||||||
|
|
||||||
|
- Ben Hetherington <[email protected]>
|
||||||
|
|
||||||
|
- Björn Höhrmann <[email protected]>
|
||||||
|
|
||||||
|
- Christophe Staïesse <[email protected]>
|
||||||
|
|
||||||
|
- David Brotz <[email protected]>
|
||||||
|
|
||||||
|
- Eldred Habert <[email protected]>
|
||||||
|
|
||||||
|
- The Musl C library <http://www.musl-libc.org>
|
||||||
|
|
||||||
|
- obskyr <[email protected]>
|
||||||
|
|
||||||
|
- The OpenBSD Project <http://www.openbsd.org>
|
||||||
|
|
||||||
|
- Quint Guvernator <[email protected]>
|
||||||
|
|
||||||
|
- Rangi <http://github.com/Rangi42>
|
||||||
|
|
||||||
|
- Sanqui <[email protected]>
|
||||||
|
|
||||||
|
- YamaArashi <[email protected]>
|
||||||
|
|
||||||
|
- yenatch <[email protected]>
|
||||||
|
|
||||||
|
- phs <[email protected]>
|
||||||
|
|
||||||
|
- jidoc01 <[email protected]>
|
||||||
+24
@@ -0,0 +1,24 @@
|
|||||||
|
# This file is part of RGBDS.
|
||||||
|
#
|
||||||
|
# Copyright (c) 2018-2019, Phil Smith and RGBDS contributors.
|
||||||
|
#
|
||||||
|
# SPDX-License-Identifier: MIT
|
||||||
|
# docker build -t rgbds:vX.X.X-alpine
|
||||||
|
FROM alpine:latest
|
||||||
|
RUN apk add --update \
|
||||||
|
build-base \
|
||||||
|
bison \
|
||||||
|
libpng-dev
|
||||||
|
COPY . /rgbds
|
||||||
|
WORKDIR /rgbds
|
||||||
|
RUN make Q='' all
|
||||||
|
|
||||||
|
FROM alpine:latest
|
||||||
|
RUN apk add --update \
|
||||||
|
libpng
|
||||||
|
COPY --from=0 \
|
||||||
|
/rgbds/rgbasm \
|
||||||
|
/rgbds/rgbfix \
|
||||||
|
/rgbds/rgblink \
|
||||||
|
/rgbds/rgbgfx \
|
||||||
|
/bin/
|
||||||
@@ -1,6 +0,0 @@
|
|||||||
# GNU Make 3.x doesn't support the "!=" shell syntax, so here's an alternative
|
|
||||||
|
|
||||||
PKG_CONFIG = pkg-config
|
|
||||||
PNGFLAGS = $(shell ${PKG_CONFIG} --cflags libpng)
|
|
||||||
|
|
||||||
include Makefile
|
|
||||||
@@ -0,0 +1,21 @@
|
|||||||
|
The MIT License
|
||||||
|
|
||||||
|
Copyright (c) 1997-2020, Carsten Sorensen and RGBDS contributors.
|
||||||
|
|
||||||
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
of this software and associated documentation files (the "Software"), to
|
||||||
|
deal in the Software without restriction, including without limitation the
|
||||||
|
rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
|
||||||
|
sell copies of the Software, and to permit persons to whom the Software is
|
||||||
|
furnished to do so, subject to the following conditions:
|
||||||
|
|
||||||
|
The above copyright notice and this permission notice shall be included in
|
||||||
|
all copies or substantial portions of the Software.
|
||||||
|
|
||||||
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||||
|
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
|
||||||
|
IN THE SOFTWARE.
|
||||||
-74
@@ -1,74 +0,0 @@
|
|||||||
# Original code
|
|
||||||
|
|
||||||
Copyright (C) 1997 Carsten Sorensen <surfsmurf@matilde.demon.co.uk>
|
|
||||||
|
|
||||||
The ASMotor package (xAsm, xLink, RGBFix, examples and documentation) is
|
|
||||||
freeware and distributed as is. The author retains his copyright and right to
|
|
||||||
modify the specifications and operation of the software without notice.
|
|
||||||
|
|
||||||
In other words this means I encourage you to...
|
|
||||||
|
|
||||||
- use it for whatever purpose even professional work without me charging you a
|
|
||||||
penny
|
|
||||||
- copy it to another person (wholly or in part, though I'm sure he'd appreciate
|
|
||||||
the whole package) in whatever form you find suitable
|
|
||||||
- mass-distribute the ASMotor package if it is complete (xAsm, xLink, RGBFix and
|
|
||||||
documentation).
|
|
||||||
- contact me if you have any problems
|
|
||||||
|
|
||||||
This also means you can't...
|
|
||||||
|
|
||||||
- blame me for loss of profit, data, sleep, food or other nasty things through
|
|
||||||
the use or distribution of ASMotor. If you choose to use ASMotor you do so at
|
|
||||||
your own risk.
|
|
||||||
- expect me to be able to help you should you have a problem related or not to
|
|
||||||
ASMotor.
|
|
||||||
|
|
||||||
# Otaku no Zoku's modifications
|
|
||||||
|
|
||||||
Copyright (C) 1999 Justin Lloyd <jlloyd@imf.la> (?)
|
|
||||||
|
|
||||||
```
|
|
||||||
DO WHATEVER PUBLIC LICENSE*
|
|
||||||
TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
|
|
||||||
|
|
||||||
0. You can do whatever you want to with the work.
|
|
||||||
1. You cannot stop anybody from doing whatever they want to with the work.
|
|
||||||
2. You cannot revoke anybody elses DO WHATEVER PUBLIC LICENSE in the work.
|
|
||||||
|
|
||||||
This program is free software. It comes without any warranty, to
|
|
||||||
the extent permitted by applicable law. You can redistribute it
|
|
||||||
and/or modify it under the terms of the DO WHATEVER PUBLIC LICENSE
|
|
||||||
|
|
||||||
Software originally created by Justin Lloyd @ http://otakunozoku.com/
|
|
||||||
```
|
|
||||||
|
|
||||||
# rgbds-linux
|
|
||||||
|
|
||||||
Copyright (C) 2009 Vegard Nossum <vegard.nossum@gmail.com>
|
|
||||||
|
|
||||||
# Current
|
|
||||||
|
|
||||||
rgbasm and rgblink are derived from Justin Lloyd's RGBDS.
|
|
||||||
|
|
||||||
rgbfix was rewritten from scratch by Anthony J. Bentley, and is released
|
|
||||||
under the ISC license; see the source file for the text of the license.
|
|
||||||
|
|
||||||
rgbgfx was written by stag019, and is released under the ISC license.
|
|
||||||
|
|
||||||
Some files of rgblink were written by Antonio Niño Díaz, and they are relased
|
|
||||||
under the ISC license. The affected files have the appropriate license in the
|
|
||||||
header of the file.
|
|
||||||
|
|
||||||
The UTF-8 decoder in src/asm/charmap.c was written by Björn Höhrmann and is
|
|
||||||
released under the MIT license. The remainder of charmap.c was written by
|
|
||||||
stag019, and is released under the ISC license.
|
|
||||||
|
|
||||||
extern/err.c is derived from the Musl C library, http://www.musl-libc.org,
|
|
||||||
and is released under the MIT license.
|
|
||||||
|
|
||||||
extern/reallocarray.c is derived from the OpenBSD Project,
|
|
||||||
http://www.openbsd.org, and is released under the ISC license.
|
|
||||||
|
|
||||||
extern/strl.c is derived from the OpenBSD Project, http://www.openbsd.org,
|
|
||||||
and is released under the BSD license.
|
|
||||||
@@ -1,75 +1,160 @@
|
|||||||
PKG_CONFIG = pkg-config
|
#
|
||||||
WARNFLAGS = -Wall -Werror
|
# This file is part of RGBDS.
|
||||||
PNGFLAGS != ${PKG_CONFIG} --cflags libpng
|
#
|
||||||
REALCFLAGS = ${CFLAGS} ${WARNFLAGS} ${PNGFLAGS} -Iinclude -g \
|
# Copyright (c) 1997-2018, Carsten Sorensen and RGBDS contributors.
|
||||||
-std=c99 -D_POSIX_C_SOURCE=200809L
|
#
|
||||||
|
# SPDX-License-Identifier: MIT
|
||||||
|
#
|
||||||
|
|
||||||
LFLAGS := --nounistd
|
.SUFFIXES:
|
||||||
|
.SUFFIXES: .h .y .c .o
|
||||||
YACC := yacc
|
|
||||||
FLEX := flex
|
|
||||||
RM := rm -rf
|
|
||||||
|
|
||||||
# User-defined variables
|
# User-defined variables
|
||||||
PREFIX = /usr/local
|
|
||||||
bindir = ${PREFIX}/bin
|
|
||||||
mandir = ${PREFIX}/man
|
|
||||||
Q = @
|
|
||||||
STRIP = -s
|
|
||||||
BINMODE = 555
|
|
||||||
MANMODE = 444
|
|
||||||
|
|
||||||
rgbasm_obj = \
|
Q := @
|
||||||
src/asm/asmy.o \
|
PREFIX := /usr/local
|
||||||
src/asm/charmap.o \
|
bindir := ${PREFIX}/bin
|
||||||
src/asm/fstack.o \
|
mandir := ${PREFIX}/share/man
|
||||||
src/asm/globlex.o \
|
STRIP := -s
|
||||||
src/asm/lexer.o \
|
BINMODE := 755
|
||||||
src/asm/main.o \
|
MANMODE := 644
|
||||||
src/asm/math.o \
|
CHECKPATCH := ../linux/scripts/checkpatch.pl
|
||||||
src/asm/output.o \
|
|
||||||
src/asm/rpn.o \
|
|
||||||
src/asm/symbol.o \
|
|
||||||
src/asm/locallex.o \
|
|
||||||
src/extern/err.o \
|
|
||||||
src/extern/reallocarray.o \
|
|
||||||
src/extern/strlcpy.o \
|
|
||||||
src/extern/strlcat.o
|
|
||||||
|
|
||||||
rgblink_obj = \
|
# Other variables
|
||||||
src/link/assign.o \
|
|
||||||
src/link/lexer.o \
|
|
||||||
src/link/library.o \
|
|
||||||
src/link/main.o \
|
|
||||||
src/link/mapfile.o \
|
|
||||||
src/link/object.o \
|
|
||||||
src/link/output.o \
|
|
||||||
src/link/patch.o \
|
|
||||||
src/link/parser.o \
|
|
||||||
src/link/script.o \
|
|
||||||
src/link/symbol.o \
|
|
||||||
src/extern/err.o
|
|
||||||
|
|
||||||
rgbfix_obj = \
|
PKG_CONFIG := pkg-config
|
||||||
src/fix/main.o \
|
PNGCFLAGS := `${PKG_CONFIG} --cflags libpng`
|
||||||
src/extern/err.o
|
PNGLDFLAGS := `${PKG_CONFIG} --libs-only-L libpng`
|
||||||
|
PNGLDLIBS := `${PKG_CONFIG} --libs-only-l libpng`
|
||||||
|
|
||||||
rgbgfx_obj = \
|
# Note: if this comes up empty, `version.c` will automatically fall back to last release number
|
||||||
src/gfx/gb.o \
|
VERSION_STRING := `git describe --tags --dirty --always 2>/dev/null`
|
||||||
src/gfx/main.o \
|
|
||||||
src/gfx/makepng.o \
|
WARNFLAGS := -Wall
|
||||||
src/extern/err.o
|
|
||||||
|
# Overridable CFLAGS
|
||||||
|
CFLAGS ?= -O3 -flto -DNDEBUG
|
||||||
|
# Non-overridable CFLAGS
|
||||||
|
REALCFLAGS := ${CFLAGS} ${WARNFLAGS} -std=gnu11 -D_POSIX_C_SOURCE=200809L \
|
||||||
|
-Iinclude
|
||||||
|
# Overridable LDFLAGS
|
||||||
|
LDFLAGS ?=
|
||||||
|
# Non-overridable LDFLAGS
|
||||||
|
REALLDFLAGS := ${LDFLAGS} ${WARNFLAGS} \
|
||||||
|
-DBUILD_VERSION_STRING=\"${VERSION_STRING}\"
|
||||||
|
|
||||||
|
YFLAGS ?= -Wall
|
||||||
|
|
||||||
|
BISON := bison
|
||||||
|
RM := rm -rf
|
||||||
|
|
||||||
|
# Rules to build the RGBDS binaries
|
||||||
|
|
||||||
all: rgbasm rgblink rgbfix rgbgfx
|
all: rgbasm rgblink rgbfix rgbgfx
|
||||||
|
|
||||||
|
rgbasm_obj := \
|
||||||
|
src/asm/charmap.o \
|
||||||
|
src/asm/fixpoint.o \
|
||||||
|
src/asm/format.o \
|
||||||
|
src/asm/fstack.o \
|
||||||
|
src/asm/lexer.o \
|
||||||
|
src/asm/macro.o \
|
||||||
|
src/asm/main.o \
|
||||||
|
src/asm/parser.o \
|
||||||
|
src/asm/opt.o \
|
||||||
|
src/asm/output.o \
|
||||||
|
src/asm/rpn.o \
|
||||||
|
src/asm/section.o \
|
||||||
|
src/asm/symbol.o \
|
||||||
|
src/asm/util.o \
|
||||||
|
src/asm/warning.o \
|
||||||
|
src/extern/err.o \
|
||||||
|
src/extern/getopt.o \
|
||||||
|
src/extern/utf8decoder.o \
|
||||||
|
src/hashmap.o \
|
||||||
|
src/linkdefs.o \
|
||||||
|
src/opmath.o
|
||||||
|
|
||||||
|
src/asm/lexer.o src/asm/main.o: src/asm/parser.h
|
||||||
|
|
||||||
|
rgblink_obj := \
|
||||||
|
src/link/assign.o \
|
||||||
|
src/link/main.o \
|
||||||
|
src/link/object.o \
|
||||||
|
src/link/output.o \
|
||||||
|
src/link/patch.o \
|
||||||
|
src/link/script.o \
|
||||||
|
src/link/section.o \
|
||||||
|
src/link/symbol.o \
|
||||||
|
src/extern/err.o \
|
||||||
|
src/extern/getopt.o \
|
||||||
|
src/hashmap.o \
|
||||||
|
src/linkdefs.o \
|
||||||
|
src/opmath.o
|
||||||
|
|
||||||
|
rgbfix_obj := \
|
||||||
|
src/fix/main.o \
|
||||||
|
src/extern/err.o \
|
||||||
|
src/extern/getopt.o
|
||||||
|
|
||||||
|
rgbgfx_obj := \
|
||||||
|
src/gfx/gb.o \
|
||||||
|
src/gfx/main.o \
|
||||||
|
src/gfx/makepng.o \
|
||||||
|
src/extern/err.o \
|
||||||
|
src/extern/getopt.o
|
||||||
|
|
||||||
|
rgbasm: ${rgbasm_obj}
|
||||||
|
$Q${CC} ${REALLDFLAGS} -o $@ ${rgbasm_obj} ${REALCFLAGS} src/version.c -lm
|
||||||
|
|
||||||
|
rgblink: ${rgblink_obj}
|
||||||
|
$Q${CC} ${REALLDFLAGS} -o $@ ${rgblink_obj} ${REALCFLAGS} src/version.c
|
||||||
|
|
||||||
|
rgbfix: ${rgbfix_obj}
|
||||||
|
$Q${CC} ${REALLDFLAGS} -o $@ ${rgbfix_obj} ${REALCFLAGS} src/version.c
|
||||||
|
|
||||||
|
rgbgfx: ${rgbgfx_obj}
|
||||||
|
$Q${CC} ${REALLDFLAGS} ${PNGLDFLAGS} -o $@ ${rgbgfx_obj} ${REALCFLAGS} src/version.c ${PNGLDLIBS}
|
||||||
|
|
||||||
|
# Rules to process files
|
||||||
|
|
||||||
|
# We want the Bison invocation to pass through our rules, not default ones
|
||||||
|
.y.o:
|
||||||
|
|
||||||
|
# Bison-generated C files have an accompanying header
|
||||||
|
src/asm/parser.h: src/asm/parser.c
|
||||||
|
$Qtouch $@
|
||||||
|
|
||||||
|
src/asm/parser.c: src/asm/parser.y
|
||||||
|
$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:
|
||||||
|
$Q${CC} ${REALCFLAGS} ${PNGCFLAGS} -c -o $@ $<
|
||||||
|
|
||||||
|
# Target used to remove all files generated by other Makefile targets
|
||||||
|
|
||||||
clean:
|
clean:
|
||||||
$Q${RM} rgbds.7.html gbz80.7.html rgbds.5.html
|
$Q${RM} rgbasm rgbasm.exe
|
||||||
$Q${RM} rgbasm rgbasm.exe ${rgbasm_obj} rgbasm.1.html rgbasm.5.html
|
$Q${RM} rgblink rgblink.exe
|
||||||
$Q${RM} rgblink rgblink.exe ${rgblink_obj} rgblink.1.html rgblink.5.html
|
$Q${RM} rgbfix rgbfix.exe
|
||||||
$Q${RM} rgbfix rgbfix.exe ${rgbfix_obj} rgbfix.1.html
|
$Q${RM} rgbgfx rgbgfx.exe
|
||||||
$Q${RM} rgbgfx rgbgfx.exe ${rgbgfx_obj} rgbgfx.1.html
|
$Qfind src/ -name "*.o" -exec rm {} \;
|
||||||
$Q${RM} src/asm/asmy.c src/asm/asmy.h
|
$Q${RM} rgbshim.sh
|
||||||
$Q${RM} src/link/lexer.c src/link/parser.c src/link/parser.h
|
$Q${RM} src/asm/parser.c src/asm/parser.h
|
||||||
|
|
||||||
|
# Target used to install the binaries and man pages.
|
||||||
|
|
||||||
install: all
|
install: all
|
||||||
$Qmkdir -p ${DESTDIR}${bindir}
|
$Qmkdir -p ${DESTDIR}${bindir}
|
||||||
@@ -80,78 +165,83 @@ install: all
|
|||||||
$Qmkdir -p ${DESTDIR}${mandir}/man1 ${DESTDIR}${mandir}/man5 ${DESTDIR}${mandir}/man7
|
$Qmkdir -p ${DESTDIR}${mandir}/man1 ${DESTDIR}${mandir}/man5 ${DESTDIR}${mandir}/man7
|
||||||
$Qinstall -m ${MANMODE} src/rgbds.7 ${DESTDIR}${mandir}/man7/rgbds.7
|
$Qinstall -m ${MANMODE} src/rgbds.7 ${DESTDIR}${mandir}/man7/rgbds.7
|
||||||
$Qinstall -m ${MANMODE} src/gbz80.7 ${DESTDIR}${mandir}/man7/gbz80.7
|
$Qinstall -m ${MANMODE} src/gbz80.7 ${DESTDIR}${mandir}/man7/gbz80.7
|
||||||
$Qinstall -m ${MANMODE} src/rgbds.5 ${DESTDIR}${mandir}/man7/rgbds.5
|
$Qinstall -m ${MANMODE} src/rgbds.5 ${DESTDIR}${mandir}/man5/rgbds.5
|
||||||
$Qinstall -m ${MANMODE} src/asm/rgbasm.1 ${DESTDIR}${mandir}/man1/rgbasm.1
|
$Qinstall -m ${MANMODE} src/asm/rgbasm.1 ${DESTDIR}${mandir}/man1/rgbasm.1
|
||||||
$Qinstall -m ${MANMODE} src/asm/rgbasm.5 ${DESTDIR}${mandir}/man1/rgbasm.5
|
$Qinstall -m ${MANMODE} src/asm/rgbasm.5 ${DESTDIR}${mandir}/man5/rgbasm.5
|
||||||
$Qinstall -m ${MANMODE} src/fix/rgbfix.1 ${DESTDIR}${mandir}/man1/rgbfix.1
|
$Qinstall -m ${MANMODE} src/fix/rgbfix.1 ${DESTDIR}${mandir}/man1/rgbfix.1
|
||||||
$Qinstall -m ${MANMODE} src/link/rgblink.1 ${DESTDIR}${mandir}/man1/rgblink.1
|
$Qinstall -m ${MANMODE} src/link/rgblink.1 ${DESTDIR}${mandir}/man1/rgblink.1
|
||||||
$Qinstall -m ${MANMODE} src/link/rgblink.5 ${DESTDIR}${mandir}/man5/rgblink.5
|
$Qinstall -m ${MANMODE} src/link/rgblink.5 ${DESTDIR}${mandir}/man5/rgblink.5
|
||||||
$Qinstall -m ${MANMODE} src/gfx/rgbgfx.1 ${DESTDIR}${mandir}/man1/rgbgfx.1
|
$Qinstall -m ${MANMODE} src/gfx/rgbgfx.1 ${DESTDIR}${mandir}/man1/rgbgfx.1
|
||||||
|
|
||||||
rgbasm: ${rgbasm_obj}
|
# Target used to check the coding style of the whole codebase.
|
||||||
$Q${CC} ${REALCFLAGS} -o $@ ${rgbasm_obj} -lm
|
# `extern/` is excluded, as it contains external code that should not be patched
|
||||||
|
# to meet our coding style, so applying upstream patches is easier.
|
||||||
|
# `.y` files aren't checked, unfortunately...
|
||||||
|
|
||||||
rgblink: ${rgblink_obj}
|
checkcodebase:
|
||||||
$Q${CC} ${REALCFLAGS} -o $@ ${rgblink_obj}
|
$Qfor file in `git ls-files | grep -E '(\.c|\.h)$$' | grep -Ev '(src|include)/extern/'`; do \
|
||||||
|
${CHECKPATCH} -f "$$file"; \
|
||||||
|
done
|
||||||
|
|
||||||
rgbfix: ${rgbfix_obj}
|
# Target used to check the coding style of the patches from the upstream branch
|
||||||
$Q${CC} ${REALCFLAGS} -o $@ ${rgbfix_obj}
|
# to the HEAD. Runs checkpatch once for each commit between the current HEAD and
|
||||||
|
# the first common commit between the HEAD and origin/master.
|
||||||
|
# `.y` files aren't checked, unfortunately...
|
||||||
|
|
||||||
rgbgfx: ${rgbgfx_obj}
|
BASE_REF:= origin/master
|
||||||
$Q${CC} ${REALCFLAGS} -o $@ ${rgbgfx_obj} `${PKG_CONFIG} --libs libpng`
|
checkpatch:
|
||||||
|
$Qeval COMMON_COMMIT=$$(git merge-base HEAD ${BASE_REF}); \
|
||||||
|
for commit in `git rev-list $$COMMON_COMMIT..HEAD`; do \
|
||||||
|
echo "[*] Analyzing commit '$$commit'"; \
|
||||||
|
git format-patch --stdout "$$commit~..$$commit" \
|
||||||
|
-- src include '!src/extern' '!include/extern' \
|
||||||
|
| ${CHECKPATCH} - || true; \
|
||||||
|
done
|
||||||
|
|
||||||
.y.c:
|
# This target is used during development in order to prevent adding new issues
|
||||||
$Q${YACC} -d ${YFLAGS} -o $@ $<
|
# to the source code. All warnings are treated as errors in order to block the
|
||||||
|
# compilation and make the continous integration infrastructure return failure.
|
||||||
|
|
||||||
.l.o:
|
develop:
|
||||||
$Q${RM} $*.c
|
$Qenv $(MAKE) -j WARNFLAGS="-Werror -Wall -Wextra -Wpedantic -Wno-type-limits \
|
||||||
$Q${FLEX} ${LFLAGS} -o $*.c $<
|
-Wno-sign-compare -Wvla -Wformat -Wformat-security -Wformat-overflow=2 \
|
||||||
$Q${CC} ${REALCFLAGS} -c -o $@ $*.c
|
-Wformat-truncation=1 -Wformat-y2k -Wswitch-enum -Wunused \
|
||||||
$Q${RM} $*.c
|
-Wuninitialized -Wunknown-pragmas -Wstrict-overflow=4 \
|
||||||
|
-Wstringop-overflow=4 -Walloc-zero -Wduplicated-cond \
|
||||||
|
-Wfloat-equal -Wshadow -Wcast-qual -Wcast-align -Wlogical-op \
|
||||||
|
-Wnested-externs -Wno-aggressive-loop-optimizations -Winline \
|
||||||
|
-Wundef -Wstrict-prototypes -Wold-style-definition \
|
||||||
|
-fsanitize=shift -fsanitize=integer-divide-by-zero \
|
||||||
|
-fsanitize=unreachable -fsanitize=vla-bound \
|
||||||
|
-fsanitize=signed-integer-overflow -fsanitize=bounds \
|
||||||
|
-fsanitize=object-size -fsanitize=bool -fsanitize=enum \
|
||||||
|
-fsanitize=alignment -fsanitize=null" CFLAGS="-ggdb3 -O0"
|
||||||
|
|
||||||
.c.o:
|
# Targets for the project maintainer to easily create Windows exes.
|
||||||
$Q${CC} ${REALCFLAGS} -c -o $@ $<
|
|
||||||
|
|
||||||
src/asm/locallex.o src/asm/globlex.o src/asm/lexer.o: src/asm/asmy.h
|
|
||||||
src/asm/asmy.h: src/asm/asmy.c
|
|
||||||
|
|
||||||
src/link/lexer.o : src/link/parser.h
|
|
||||||
src/link/parser.h : src/link/parser.c
|
|
||||||
|
|
||||||
# Below is a target for the project maintainer to easily create win32 exes.
|
|
||||||
# This is not for Windows users!
|
# This is not for Windows users!
|
||||||
# If you're building on Windows with Cygwin or Mingw, just follow the Unix
|
# If you're building on Windows with Cygwin or Mingw, just follow the Unix
|
||||||
# install instructions instead.
|
# install instructions instead.
|
||||||
mingw:
|
|
||||||
$Q${RM} win32 win64
|
|
||||||
$Qmkdir win32 win64
|
|
||||||
$Qenv make clean
|
|
||||||
$Qenv PKG_CONFIG_PATH=/usr/i686-w64-mingw32/sys-root/mingw/lib/pkgconfig/ \
|
|
||||||
make CC=i686-w64-mingw32-gcc YACC=bison WARNFLAGS= -j
|
|
||||||
$Qmv rgbasm win32/rgbasm.exe
|
|
||||||
$Qmv rgblink win32/rgblink.exe
|
|
||||||
$Qmv rgbfix win32/rgbfix.exe
|
|
||||||
$Qmv rgbgfx win32/rgbgfx.exe
|
|
||||||
$Qenv make clean
|
|
||||||
$Qenv PKG_CONFIG_PATH=/usr/x86_64-w64-mingw32/sys-root/mingw/lib/pkgconfig/ \
|
|
||||||
make CC=x86_64-w64-mingw32-gcc YACC=bison WARNFLAGS= -j
|
|
||||||
$Qmv rgbasm win64/rgbasm.exe
|
|
||||||
$Qmv rgblink win64/rgblink.exe
|
|
||||||
$Qmv rgbfix win64/rgbfix.exe
|
|
||||||
$Qmv rgbgfx win64/rgbgfx.exe
|
|
||||||
$Qenv make clean
|
|
||||||
|
|
||||||
# Below is a target for the project maintainer to easily create web manuals.
|
mingw32:
|
||||||
# It relies on mandoc: http://mdocml.bsd.lv
|
$Qmake CC=i686-w64-mingw32-gcc BISON=bison \
|
||||||
MANDOC = -Thtml -Ios=General -Oman=%N.%S.html -Ostyle=manual.css
|
PKG_CONFIG=i686-w64-mingw32-pkg-config -j
|
||||||
|
|
||||||
wwwman:
|
mingw64:
|
||||||
$Qmandoc ${MANDOC} src/rgbds.7 > rgbds.7.html
|
$Qmake CC=x86_64-w64-mingw32-gcc BISON=bison \
|
||||||
$Qmandoc ${MANDOC} src/gbz80.7 > gbz80.7.html
|
PKG_CONFIG=x86_64-w64-mingw32-pkg-config -j
|
||||||
$Qmandoc ${MANDOC} src/rgbds.5 > rgbds.5.html
|
|
||||||
$Qmandoc ${MANDOC} src/asm/rgbasm.1 > rgbasm.1.html
|
wine-shim:
|
||||||
$Qmandoc ${MANDOC} src/asm/rgbasm.5 > rgbasm.5.html
|
$Qecho '#!/bin/bash' > rgbshim.sh
|
||||||
$Qmandoc ${MANDOC} src/fix/rgbfix.1 > rgbfix.1.html
|
$Qecho 'WINEDEBUG=-all wine $$0.exe "$${@:1}"' >> rgbshim.sh
|
||||||
$Qmandoc ${MANDOC} src/link/rgblink.1 > rgblink.1.html
|
$Qchmod +x rgbshim.sh
|
||||||
$Qmandoc ${MANDOC} src/link/rgblink.5 > rgblink.5.html
|
$Qln -s rgbshim.sh rgbasm
|
||||||
$Qmandoc ${MANDOC} src/gfx/rgbgfx.1 > rgbgfx.1.html
|
$Qln -s rgbshim.sh rgblink
|
||||||
|
$Qln -s rgbshim.sh rgbfix
|
||||||
|
$Qln -s rgbshim.sh rgbgfx
|
||||||
|
|
||||||
|
# Target for the project maintainer to produce distributable release tarballs
|
||||||
|
# of the source code.
|
||||||
|
|
||||||
|
dist:
|
||||||
|
$Qgit ls-files | sed s~^~$${PWD##*/}/~ \
|
||||||
|
| tar -czf rgbds-`git describe --tags | cut -c 2-`.tar.gz -C .. -T -
|
||||||
|
|||||||
@@ -1,158 +0,0 @@
|
|||||||
# RGBDS
|
|
||||||
|
|
||||||
RGBDS (Rednex Game Boy Development System) is a free assembler/linker package
|
|
||||||
for the Game Boy and Game Boy Color. It consists of:
|
|
||||||
|
|
||||||
- rgbasm (assembler)
|
|
||||||
- rgblink (linker)
|
|
||||||
- rgbfix (checksum/header fixer)
|
|
||||||
- rgbgfx (PNG‐to‐Game Boy graphics converter)
|
|
||||||
|
|
||||||
This is a fork of the original RGBDS which aims to make the programs more like
|
|
||||||
other UNIX tools.
|
|
||||||
|
|
||||||
This toolchain is maintained on [GitHub](https://github.com/rednex/rgbds), as
|
|
||||||
well as its [documentation](https://github.com/rednex/rednex.github.io).
|
|
||||||
|
|
||||||
The documentation of this toolchain can be viewed online
|
|
||||||
[here](https://rednex.github.io/), it is generated from the man pages found in
|
|
||||||
this repository.
|
|
||||||
|
|
||||||
## 1. Installing RGBDS
|
|
||||||
|
|
||||||
### 1.1 Windows
|
|
||||||
|
|
||||||
Windows builds are available in the releases page on GitHub:
|
|
||||||
|
|
||||||
https://github.com/rednex/rgbds/releases
|
|
||||||
|
|
||||||
Copy the `.exe` files to `C:\Windows\` or similar.
|
|
||||||
|
|
||||||
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:
|
|
||||||
|
|
||||||
```sh
|
|
||||||
brew install rgbds
|
|
||||||
```
|
|
||||||
|
|
||||||
To install RGBDS with all of the current changes in development (as seen on the
|
|
||||||
`master` branch on GitHub), use:
|
|
||||||
|
|
||||||
```sh
|
|
||||||
brew install rgbds --HEAD
|
|
||||||
```
|
|
||||||
|
|
||||||
### 1.3 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, flex, libpng and pkg-config to be installed.
|
|
||||||
|
|
||||||
On macOS, install the latter two with [Homebrew](http://brew.sh/):
|
|
||||||
|
|
||||||
```sh
|
|
||||||
brew install libpng pkg-config
|
|
||||||
```
|
|
||||||
|
|
||||||
On other Unixes, use the built-in package manager. For example, on Debian or
|
|
||||||
Ubuntu:
|
|
||||||
|
|
||||||
```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:
|
|
||||||
|
|
||||||
```sh
|
|
||||||
make
|
|
||||||
```
|
|
||||||
|
|
||||||
Then, to install the compiled programs and manual pages, run (with appropriate
|
|
||||||
privileges, e.g, with `sudo`):
|
|
||||||
|
|
||||||
|
|
||||||
```sh
|
|
||||||
make install
|
|
||||||
```
|
|
||||||
|
|
||||||
After installation, you can read the manuals with the `man` command. E.g.,
|
|
||||||
|
|
||||||
```sh
|
|
||||||
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
|
|
||||||
make command line. For example, to install RGBDS in your home directory instead
|
|
||||||
of systemwide, run the following:
|
|
||||||
|
|
||||||
```sh
|
|
||||||
mkdir -p $HOME/{bin,man/man1,man/man7}
|
|
||||||
make install PREFIX=$HOME
|
|
||||||
```
|
|
||||||
|
|
||||||
To do a verbose build, run:
|
|
||||||
|
|
||||||
```sh
|
|
||||||
make Q=
|
|
||||||
```
|
|
||||||
|
|
||||||
This is the complete list of user-defined variables:
|
|
||||||
|
|
||||||
- `PREFIX`: Location where RGBDS will be installed. Defaults to `/usr/local`.
|
|
||||||
|
|
||||||
- `bindir`: Location where the binaries will be installed. Defaults to `${PREFIX}/bin`.
|
|
||||||
|
|
||||||
- `mandir`: Location where the manpages will be installed. Defaults to `${PREFIX}/man`.
|
|
||||||
|
|
||||||
- `DESTDIR`: This is prepended to all paths during the installation. It is
|
|
||||||
mainly used for packaging.
|
|
||||||
|
|
||||||
- `Q`: Whether to quiet the build or not. To make the build more verbose, clear
|
|
||||||
this variable. Defaults to `@`.
|
|
||||||
|
|
||||||
- `STRIP`: Whether to strip the installed binaries of debug symbols or not.
|
|
||||||
Defaults to `-s`.
|
|
||||||
|
|
||||||
- `BINMODE`: Permissions of the installed binaries. Defaults to `555`.
|
|
||||||
|
|
||||||
- `MANMODE`: Permissions of the installed manpages. Defaults to `444`.
|
|
||||||
|
|
||||||
## 3 History
|
|
||||||
|
|
||||||
- Around 1997, Carsten Sorensen (AKA SurfSmurf) writes ASMotor as a
|
|
||||||
general-purpose assembler/linker system for DOS/Win32
|
|
||||||
|
|
||||||
- Around 1999, Justin Lloyd (AKA Otaku no Zoku) adapts ASMotor to read and
|
|
||||||
produce GBZ80 assembly/machine code, and releases this version as RGBDS.
|
|
||||||
|
|
||||||
- 2009, Vegard Nossum adapts the code to be more UNIX-like and releases this
|
|
||||||
version as rgbds-linux on [GitHub](https://github.com/vegard/rgbds-linux).
|
|
||||||
|
|
||||||
- 2010, Anthony J. Bentley forks that repository. The fork becomes the reference
|
|
||||||
implementation of rgbds.
|
|
||||||
|
|
||||||
- 2017, Bentley's repository is moved to a neutral name.
|
|
||||||
+115
@@ -0,0 +1,115 @@
|
|||||||
|
RGBDS
|
||||||
|
=====
|
||||||
|
|
||||||
|
RGBDS (Rednex Game Boy Development System) is a free assembler/linker package
|
||||||
|
for the Game Boy and Game Boy Color. It consists of:
|
||||||
|
|
||||||
|
- rgbasm (assembler)
|
||||||
|
- rgblink (linker)
|
||||||
|
- rgbfix (checksum/header fixer)
|
||||||
|
- rgbgfx (PNG‐to‐Game Boy graphics converter)
|
||||||
|
|
||||||
|
This is a fork of the original RGBDS which aims to make the programs more like
|
||||||
|
other UNIX tools.
|
||||||
|
|
||||||
|
This toolchain is maintained on `GitHub <https://github.com/rednex/rgbds>`__.
|
||||||
|
|
||||||
|
The documentation of this toolchain can be viewed online
|
||||||
|
`here <https://rgbds.gbdev.io/docs/>`__, it is generated from the man pages
|
||||||
|
found in this repository.
|
||||||
|
|
||||||
|
1. Installing RGBDS
|
||||||
|
-------------------
|
||||||
|
|
||||||
|
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.
|
||||||
|
|
||||||
|
.. code:: sh
|
||||||
|
|
||||||
|
make
|
||||||
|
sudo make install
|
||||||
|
|
||||||
|
.. code:: sh
|
||||||
|
|
||||||
|
cmake -S . -B build -DCMAKE_BUILD_TYPE=Release
|
||||||
|
cmake --build build
|
||||||
|
cmake --install build
|
||||||
|
|
||||||
|
2. RGBDS Folder Organization
|
||||||
|
----------------------------
|
||||||
|
|
||||||
|
The RGBDS source code file structure somewhat resembles the following:
|
||||||
|
|
||||||
|
::
|
||||||
|
|
||||||
|
.
|
||||||
|
├── .github/
|
||||||
|
│ ├── actions/
|
||||||
|
│ │ └── ...
|
||||||
|
│ └── workflows/
|
||||||
|
│ └── ...
|
||||||
|
├── contrib/
|
||||||
|
│ ├── zsh_compl/
|
||||||
|
│ │ └── ...
|
||||||
|
│ └── ...
|
||||||
|
├── include/
|
||||||
|
│ └── ...
|
||||||
|
├── src/
|
||||||
|
│ ├── asm/
|
||||||
|
│ │ └── ...
|
||||||
|
│ ├── extern/
|
||||||
|
│ │ └── ...
|
||||||
|
│ ├── fix/
|
||||||
|
│ │ └── ...
|
||||||
|
│ ├── gfx/
|
||||||
|
│ │ └── ...
|
||||||
|
│ ├── link/
|
||||||
|
│ │ └── ...
|
||||||
|
│ ├── CMakeLists.txt
|
||||||
|
│ └── ...
|
||||||
|
├── test/
|
||||||
|
│ ├── ...
|
||||||
|
│ └── run-tests.sh
|
||||||
|
├── CMakeLists.txt
|
||||||
|
├── Makefile
|
||||||
|
└── README.rst
|
||||||
|
|
||||||
|
- ``.github/`` - files and scripts related to the integration of the RGBDS codebase with
|
||||||
|
GitHub.
|
||||||
|
|
||||||
|
- ``contrib/`` - scripts and other resources which may be useful to users and developers of
|
||||||
|
RGBDS.
|
||||||
|
|
||||||
|
* ``zsh_compl`` contains tab completion scripts for use with zsh. Put them somewhere in your ``fpath``, and they should auto-load.
|
||||||
|
|
||||||
|
- ``include/`` - header files for each respective C files in `src`.
|
||||||
|
|
||||||
|
- ``src/`` - source code and manual pages for RGBDS.
|
||||||
|
|
||||||
|
* Note that the code unique to each RGBDS tool is stored in its respective subdirectory
|
||||||
|
(rgbasm -> ``src/asm/``, for example). ``src/extern/`` contains code imported from external sources.
|
||||||
|
|
||||||
|
- ``test/`` - testing framework used to verify that changes to the code don't break or modify the behavior of RGBDS.
|
||||||
|
|
||||||
|
3. History
|
||||||
|
----------
|
||||||
|
|
||||||
|
- Around 1997, Carsten Sørensen (AKA SurfSmurf) writes ASMotor as a
|
||||||
|
general-purpose assembler/linker system for DOS/Win32
|
||||||
|
|
||||||
|
- Around 1999, Justin Lloyd (AKA Otaku no Zoku) adapts ASMotor to read and
|
||||||
|
produce GBZ80 assembly/machine code, and releases this version as RGBDS.
|
||||||
|
|
||||||
|
- 2009, Vegard Nossum adapts the code to be more UNIX-like and releases
|
||||||
|
this version as rgbds-linux on
|
||||||
|
`GitHub <https://github.com/vegard/rgbds-linux>`__.
|
||||||
|
|
||||||
|
- 2010, Anthony J. Bentley forks that repository. The fork becomes the reference
|
||||||
|
implementation of rgbds.
|
||||||
|
|
||||||
|
- 2017, Bentley's repository is moved to a neutral name.
|
||||||
|
|
||||||
|
- 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.
|
||||||
Executable
+73
@@ -0,0 +1,73 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
# SPDX-License-Identifier: MIT
|
||||||
|
#
|
||||||
|
# Copyright (c) 2020 Eldred Habert
|
||||||
|
#
|
||||||
|
# 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.
|
||||||
|
|
||||||
|
STATE=0
|
||||||
|
diff <(xxd $1) <(xxd $2) | while read -r LINE; do
|
||||||
|
if [ $STATE -eq 0 ]; then
|
||||||
|
# Discard first line (line info)
|
||||||
|
STATE=1
|
||||||
|
elif [ "$LINE" = '---' ]; then
|
||||||
|
# Separator between files switches states
|
||||||
|
echo $LINE
|
||||||
|
STATE=3
|
||||||
|
elif grep -Eq '^[0-9]+(,[0-9]+)?[cd][0-9]+(,[0-9]+)?' <<< "$LINE"; then
|
||||||
|
# Line info resets the whole thing
|
||||||
|
STATE=1
|
||||||
|
elif [ $STATE -eq 1 -o $STATE -eq 3 ]; then
|
||||||
|
# Compute the GB address from the ROM offset
|
||||||
|
OFS=$(cut -d ' ' -f 2 <<< "$LINE" | tr -d ':')
|
||||||
|
BANK=$((0x$OFS / 0x4000))
|
||||||
|
ADDR=$((0x$OFS % 0x4000 + ($BANK != 0) * 0x4000))
|
||||||
|
# Try finding the preceding symbol closest to the diff
|
||||||
|
if [ $STATE -eq 1 ]; then
|
||||||
|
STATE=2
|
||||||
|
SYMFILE=${1%.*}.sym
|
||||||
|
else
|
||||||
|
STATE=4
|
||||||
|
SYMFILE=${2%.*}.sym
|
||||||
|
fi
|
||||||
|
EXTRA=$(if [ -f "$SYMFILE" ]; then
|
||||||
|
# Read the sym file for such a symbol
|
||||||
|
# Ignore comment lines, only pick matching bank
|
||||||
|
# (The bank regex ignores comments already, make `cut` and `tr` process less lines)
|
||||||
|
grep -Ei $(printf "^%02x:" $BANK) "$SYMFILE" |
|
||||||
|
cut -d ';' -f 1 |
|
||||||
|
tr -d "\r" |
|
||||||
|
while read -r SYMADDR SYM; do
|
||||||
|
SYMADDR=$((0x${SYMADDR#*:}))
|
||||||
|
if [ $SYMADDR -le $ADDR ]; then
|
||||||
|
printf " (%s+%#x)\n" "$SYM" $(($ADDR - $SYMADDR))
|
||||||
|
fi
|
||||||
|
# TODO: assumes sorted sym files
|
||||||
|
done | tail -n 1
|
||||||
|
fi)
|
||||||
|
printf "%02x:%04x %s\n" $BANK $ADDR $EXTRA
|
||||||
|
fi
|
||||||
|
if [ $STATE -eq 2 -o $STATE -eq 4 ]; then
|
||||||
|
OFS=$(cut -d ' ' -f 2 <<< "$LINE" | tr -d ':')
|
||||||
|
BANK=$((0x$OFS / 0x4000))
|
||||||
|
ADDR=$((0x$OFS % 0x4000 + ($BANK != 0) * 0x4000))
|
||||||
|
printf "%s %02x:%04x: %s\n" "${LINE:0:1}" $BANK $ADDR "${LINE#*: }"
|
||||||
|
fi
|
||||||
|
done
|
||||||
@@ -0,0 +1,49 @@
|
|||||||
|
#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'
|
||||||
|
'builtin-args:Report incorrect args to built-in funcs'
|
||||||
|
'div:Warn when dividing the smallest int by -1'
|
||||||
|
'empty-entry:Warn on empty entries in db, dw, dl args'
|
||||||
|
'large-constant:Warn on constants too large for a signed 32-bit int'
|
||||||
|
'long-string:Warn on strings too long'
|
||||||
|
'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 truncations lose bits'
|
||||||
|
'user:Warn when executing the WARN built-in'
|
||||||
|
)
|
||||||
|
# TODO: handle `no-` and `error=` somehow?
|
||||||
|
_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)'{-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}"
|
||||||
|
'(-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,25 @@
|
|||||||
|
#compdef rgbfix
|
||||||
|
|
||||||
|
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-only}'[Mark ROM as GBC-only]'
|
||||||
|
'(-c --color-compatible)'{-c,--color-compatible}'[Mark ROM as GBC-compatible]'
|
||||||
|
'(-j --non-japanese)'{-j,--non-japanese}'[Set the non-Japanese region flag]'
|
||||||
|
'(-s --sgb-compatible)'{-s,--sgb-compatible}'[Set the SGB flag]'
|
||||||
|
'(-f --fix-spec -v --validate)'{-v,--validate}'[Shorthand for -f lhg]'
|
||||||
|
|
||||||
|
'(-f --fix-spec -v --validate)'{-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 flags byte:'
|
||||||
|
'(-n --rom-version)'{-n,--rom-version}'+[Set ROM version]:rom version byte:'
|
||||||
|
'(-p --pad-value)'{-p,--pad-value}'+[Pad to next valid size using this byte as padding]:padding byte:'
|
||||||
|
'(-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 files:_files -g '*.png'"
|
||||||
|
)
|
||||||
|
_arguments -s -S : $args
|
||||||
@@ -0,0 +1,22 @@
|
|||||||
|
#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]'
|
||||||
|
|
||||||
|
'(-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 --smart)'{-s,--smart}'+[!BROKEN! Perform smart linking from this symbol]:symbol name:'
|
||||||
|
|
||||||
|
'*'":object files:_files -g '*.o'"
|
||||||
|
)
|
||||||
|
_arguments -s -S : $args
|
||||||
@@ -1,35 +0,0 @@
|
|||||||
/* asm.h
|
|
||||||
*
|
|
||||||
* Contains some assembler-wide defines and externs
|
|
||||||
*
|
|
||||||
* Copyright 1997 Carsten Sorensen
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
|
|
||||||
#ifndef RGBDS_ASM_ASM_H
|
|
||||||
#define RGBDS_ASM_ASM_H
|
|
||||||
|
|
||||||
#include <stdbool.h>
|
|
||||||
#include <stdio.h>
|
|
||||||
#include <stdlib.h>
|
|
||||||
|
|
||||||
#include "types.h"
|
|
||||||
#include "asm/symbol.h"
|
|
||||||
|
|
||||||
#include "asm/localasm.h"
|
|
||||||
|
|
||||||
extern SLONG nLineNo;
|
|
||||||
extern ULONG nTotalLines;
|
|
||||||
extern ULONG nPC;
|
|
||||||
extern ULONG nPass;
|
|
||||||
extern ULONG nIFDepth;
|
|
||||||
extern char tzCurrentFileName[_MAX_PATH + 1];
|
|
||||||
extern struct Section *pCurrentSection;
|
|
||||||
extern struct sSymbol *tHashedSymbols[HASHSIZE];
|
|
||||||
extern struct sSymbol *pPCSymbol;
|
|
||||||
extern bool oDontExpandStrings;
|
|
||||||
|
|
||||||
#define MAXMACROARGS 256
|
|
||||||
#define MAXINCPATHS 128
|
|
||||||
|
|
||||||
#endif /* // ASM_H */
|
|
||||||
+17
-13
@@ -1,18 +1,22 @@
|
|||||||
|
/*
|
||||||
|
* This file is part of RGBDS.
|
||||||
|
*
|
||||||
|
* Copyright (c) 1997-2018, Carsten Sorensen and RGBDS contributors.
|
||||||
|
*
|
||||||
|
* SPDX-License-Identifier: MIT
|
||||||
|
*/
|
||||||
|
|
||||||
#ifndef RGBDS_ASM_CHARMAP_H
|
#ifndef RGBDS_ASM_CHARMAP_H
|
||||||
#define RGBDS_ASM_CHARMAP_H
|
#define RGBDS_ASM_CHARMAP_H
|
||||||
|
|
||||||
#define MAXCHARMAPS 512
|
#include <stdint.h>
|
||||||
#define CHARMAPLENGTH 16
|
|
||||||
|
|
||||||
struct Charmap {
|
struct Charmap *charmap_New(const char *name, const char *baseName);
|
||||||
int count;
|
void charmap_Delete(struct Charmap *charmap);
|
||||||
char input[MAXCHARMAPS][CHARMAPLENGTH + 1];
|
void charmap_Set(const char *name);
|
||||||
char output[MAXCHARMAPS];
|
void charmap_Push(void);
|
||||||
};
|
void charmap_Pop(void);
|
||||||
|
void charmap_Add(char *mapping, uint8_t value);
|
||||||
|
size_t charmap_Convert(char const *input, uint8_t *output);
|
||||||
|
|
||||||
int readUTF8Char(char *destination, char *source);
|
#endif /* RGBDS_ASM_CHARMAP_H */
|
||||||
void charmap_Sort();
|
|
||||||
int charmap_Add(char *input, UBYTE output);
|
|
||||||
int charmap_Convert(char **input);
|
|
||||||
|
|
||||||
#endif
|
|
||||||
|
|||||||
@@ -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 <stdint.h>
|
||||||
|
#include <stdbool.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;
|
||||||
|
uint8_t width;
|
||||||
|
bool hasFrac;
|
||||||
|
uint8_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 */
|
||||||
+68
-31
@@ -1,46 +1,83 @@
|
|||||||
/* fstack.h
|
/*
|
||||||
|
* This file is part of RGBDS.
|
||||||
*
|
*
|
||||||
* Contains some assembler-wide defines and externs
|
* Copyright (c) 1997-2018, Carsten Sorensen and RGBDS contributors.
|
||||||
*
|
|
||||||
* Copyright 1997 Carsten Sorensen
|
|
||||||
*
|
*
|
||||||
|
* SPDX-License-Identifier: MIT
|
||||||
|
*/
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Contains some assembler-wide defines and externs
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#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 <stdio.h>
|
#include <stdio.h>
|
||||||
|
|
||||||
#include "asm/asm.h"
|
|
||||||
#include "types.h"
|
|
||||||
#include "asm/lexer.h"
|
#include "asm/lexer.h"
|
||||||
|
|
||||||
struct sContext {
|
#include "types.h"
|
||||||
YY_BUFFER_STATE FlexHandle;
|
|
||||||
struct sSymbol *pMacro;
|
struct FileStackNode {
|
||||||
struct sContext *pNext;
|
struct FileStackNode *parent; /* Pointer to parent node, for error reporting */
|
||||||
char tzFileName[_MAX_PATH + 1];
|
/* Line at which the parent context was exited; meaningless for the root level */
|
||||||
char *tzMacroArgs[MAXMACROARGS + 1];
|
uint32_t lineNo;
|
||||||
SLONG nLine;
|
|
||||||
ULONG nStatus;
|
struct FileStackNode *next; /* Next node in the output linked list */
|
||||||
FILE *pFile;
|
bool referenced; /* If referenced, don't free! */
|
||||||
char *pREPTBlock;
|
uint32_t ID; /* Set only if referenced: ID within the object file, -1 if not output yet */
|
||||||
ULONG nREPTBlockCount;
|
|
||||||
ULONG nREPTBlockSize;
|
enum {
|
||||||
|
NODE_REPT,
|
||||||
|
NODE_FILE,
|
||||||
|
NODE_MACRO,
|
||||||
|
} type;
|
||||||
};
|
};
|
||||||
|
|
||||||
void
|
struct FileStackReptNode { /* NODE_REPT */
|
||||||
fstk_RunInclude(char *);
|
struct FileStackNode node;
|
||||||
extern void fstk_RunMacroArg(SLONG s);
|
uint32_t reptDepth;
|
||||||
void
|
/* WARNING: if changing this type, change overflow check in `fstk_Init` */
|
||||||
fstk_Init(char *);
|
uint32_t iters[]; /* REPT iteration counts since last named node, in reverse depth order */
|
||||||
extern void fstk_Dump(void);
|
};
|
||||||
extern void fstk_AddIncludePath(char *s);
|
|
||||||
extern ULONG fstk_RunMacro(char *s);
|
|
||||||
extern void fstk_RunRept(ULONG count);
|
|
||||||
FILE *
|
|
||||||
fstk_FindFile(char *);
|
|
||||||
|
|
||||||
extern int yywrap(void);
|
struct FileStackNamedNode { /* NODE_FILE, NODE_MACRO */
|
||||||
|
struct FileStackNode node;
|
||||||
|
char name[]; /* File name for files, file::macro name for macros */
|
||||||
|
};
|
||||||
|
|
||||||
#endif
|
extern size_t nMaxRecursionDepth;
|
||||||
|
|
||||||
|
struct MacroArgs;
|
||||||
|
|
||||||
|
void fstk_Dump(struct FileStackNode const *node, uint32_t lineNo);
|
||||||
|
void fstk_DumpCurrent(void);
|
||||||
|
struct FileStackNode *fstk_GetFileStack(void);
|
||||||
|
/* The lifetime of the returned chars is until reaching the end of that file */
|
||||||
|
char const *fstk_GetFileName(void);
|
||||||
|
|
||||||
|
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);
|
||||||
|
|
||||||
|
bool yywrap(void);
|
||||||
|
void fstk_RunInclude(char const *path);
|
||||||
|
void fstk_RunMacro(char const *macroName, struct MacroArgs *args);
|
||||||
|
void fstk_RunRept(uint32_t count, int32_t nReptLineNo, char *body, size_t size);
|
||||||
|
void fstk_RunFor(char const *symName, int32_t start, int32_t stop, int32_t step,
|
||||||
|
int32_t reptLineNo, char *body, size_t size);
|
||||||
|
void fstk_StopRept(void);
|
||||||
|
bool fstk_Break(void);
|
||||||
|
|
||||||
|
void fstk_Init(char const *mainPath, size_t maxRecursionDepth);
|
||||||
|
|
||||||
|
#endif /* RGBDS_ASM_FSTACK_H */
|
||||||
|
|||||||
+89
-53
@@ -1,65 +1,101 @@
|
|||||||
|
/*
|
||||||
|
* This file is part of RGBDS.
|
||||||
|
*
|
||||||
|
* Copyright (c) 1997-2018, Carsten Sorensen and RGBDS contributors.
|
||||||
|
*
|
||||||
|
* SPDX-License-Identifier: MIT
|
||||||
|
*/
|
||||||
|
|
||||||
#ifndef RGBDS_ASM_LEXER_H
|
#ifndef RGBDS_ASM_LEXER_H
|
||||||
#define RGBDS_ASM_LEXER_H
|
#define RGBDS_ASM_LEXER_H
|
||||||
|
|
||||||
#include <stdio.h>
|
#include <stdbool.h>
|
||||||
|
|
||||||
#include "types.h"
|
#define MAXSTRLEN 255
|
||||||
|
|
||||||
#define LEXHASHSIZE (1 << 11)
|
struct LexerState;
|
||||||
#define MAXSTRLEN 255
|
extern struct LexerState *lexerState;
|
||||||
|
extern struct LexerState *lexerStateEOL;
|
||||||
|
|
||||||
struct sLexInitString {
|
static inline struct LexerState *lexer_GetState(void)
|
||||||
char *tzName;
|
{
|
||||||
ULONG nToken;
|
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 *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);
|
||||||
ULONG(*Callback) (char *s, ULONG size);
|
void lexer_ToggleStringExpansion(bool enable);
|
||||||
ULONG 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 {
|
char const *lexer_GetFileName(void);
|
||||||
char *pBufferRealStart; // actual starting address
|
uint32_t lexer_GetLineNo(void);
|
||||||
char *pBufferStart; // address where the data is initially written
|
uint32_t lexer_GetColNo(void);
|
||||||
// after the "safety margin"
|
void lexer_DumpStringExpansions(void);
|
||||||
char *pBuffer;
|
int yylex(void);
|
||||||
ULONG nBufferSize;
|
void lexer_CaptureRept(struct CaptureBody *capture);
|
||||||
ULONG oAtLineStart;
|
void lexer_CaptureMacroBody(struct CaptureBody *capture);
|
||||||
|
|
||||||
|
#define INITIAL_DS_ARG_SIZE 2
|
||||||
|
struct DsArgList {
|
||||||
|
size_t nbArgs;
|
||||||
|
size_t capacity;
|
||||||
|
struct Expression *args;
|
||||||
};
|
};
|
||||||
|
|
||||||
enum eLexerState {
|
#endif /* RGBDS_ASM_LEXER_H */
|
||||||
LEX_STATE_NORMAL,
|
|
||||||
LEX_STATE_MACROARGS
|
|
||||||
};
|
|
||||||
#define INITIAL 0
|
|
||||||
#define macroarg 3
|
|
||||||
|
|
||||||
typedef struct yy_buffer_state *YY_BUFFER_STATE;
|
|
||||||
|
|
||||||
extern void yy_set_state(enum eLexerState i);
|
|
||||||
extern YY_BUFFER_STATE yy_create_buffer(FILE * f);
|
|
||||||
extern YY_BUFFER_STATE yy_scan_bytes(char *mem, ULONG size);
|
|
||||||
extern void yy_delete_buffer(YY_BUFFER_STATE);
|
|
||||||
extern void yy_switch_to_buffer(YY_BUFFER_STATE);
|
|
||||||
extern ULONG lex_FloatAlloc(struct sLexFloat * tok);
|
|
||||||
extern void lex_FloatAddRange(ULONG id, UWORD start, UWORD end);
|
|
||||||
extern void lex_FloatDeleteRange(ULONG id, UWORD start, UWORD end);
|
|
||||||
extern void lex_FloatAddFirstRange(ULONG id, UWORD start, UWORD end);
|
|
||||||
extern void lex_FloatDeleteFirstRange(ULONG id, UWORD start, UWORD end);
|
|
||||||
extern void lex_FloatAddSecondRange(ULONG id, UWORD start, UWORD end);
|
|
||||||
extern void lex_FloatDeleteSecondRange(ULONG id, UWORD start, UWORD end);
|
|
||||||
extern void lex_Init(void);
|
|
||||||
extern void lex_AddStrings(struct sLexInitString * lex);
|
|
||||||
extern void lex_SetBuffer(char *buffer, ULONG len);
|
|
||||||
extern ULONG yylex(void);
|
|
||||||
extern void yyunput(char c);
|
|
||||||
extern void yyunputstr(char *s);
|
|
||||||
extern void yyskipbytes(ULONG count);
|
|
||||||
extern void yyunputbytes(ULONG count);
|
|
||||||
|
|
||||||
extern YY_BUFFER_STATE pCurrentBuffer;
|
|
||||||
|
|
||||||
extern void upperstring(char *s);
|
|
||||||
extern void lowerstring(char *s);
|
|
||||||
|
|
||||||
#endif
|
|
||||||
|
|||||||
@@ -1,134 +0,0 @@
|
|||||||
/* 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
|
|
||||||
|
|
||||||
*/
|
|
||||||
|
|
||||||
#define MAXSECTIONSIZE 0x4000
|
|
||||||
|
|
||||||
#define NAME_DB "db"
|
|
||||||
#define NAME_DW "dw"
|
|
||||||
#define NAME_RB "rb"
|
|
||||||
#define NAME_RW "rw"
|
|
||||||
|
|
||||||
/* "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 */
|
|
||||||
|
|
||||||
enum {
|
|
||||||
REG_BC = 0,
|
|
||||||
REG_DE,
|
|
||||||
REG_HL,
|
|
||||||
REG_SP
|
|
||||||
};
|
|
||||||
/* "tt" defs */
|
|
||||||
|
|
||||||
/*
|
|
||||||
#define REG_BC 0
|
|
||||||
#define REG_DE 1
|
|
||||||
#define REG_HL 2
|
|
||||||
*/
|
|
||||||
#define REG_AF 3
|
|
||||||
|
|
||||||
/* "cc" defs */
|
|
||||||
|
|
||||||
enum {
|
|
||||||
CC_NZ = 0,
|
|
||||||
CC_Z,
|
|
||||||
CC_NC,
|
|
||||||
CC_C
|
|
||||||
};
|
|
||||||
@@ -0,0 +1,37 @@
|
|||||||
|
/*
|
||||||
|
* This file is part of RGBDS.
|
||||||
|
*
|
||||||
|
* Copyright (c) 2020, Carsten Sorensen and RGBDS contributors.
|
||||||
|
*
|
||||||
|
* SPDX-License-Identifier: MIT
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef RGBDS_MACRO_H
|
||||||
|
#define RGBDS_MACRO_H
|
||||||
|
|
||||||
|
#include <stdint.h>
|
||||||
|
#include <stdbool.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
|
||||||
|
#include "asm/warning.h"
|
||||||
|
|
||||||
|
#include "helpers.h"
|
||||||
|
|
||||||
|
struct MacroArgs;
|
||||||
|
|
||||||
|
struct MacroArgs *macro_GetCurrentArgs(void);
|
||||||
|
struct MacroArgs *macro_NewArgs(void);
|
||||||
|
void macro_AppendArg(struct MacroArgs **args, char *s);
|
||||||
|
void macro_UseNewArgs(struct MacroArgs *args);
|
||||||
|
void macro_FreeArgs(struct MacroArgs *args);
|
||||||
|
char const *macro_GetArg(uint32_t i);
|
||||||
|
char *macro_GetAllArgs(void);
|
||||||
|
|
||||||
|
uint32_t macro_GetUniqueID(void);
|
||||||
|
char const *macro_GetUniqueIDStr(void);
|
||||||
|
void macro_SetUniqueID(uint32_t id);
|
||||||
|
uint32_t macro_UseNewUniqueID(void);
|
||||||
|
void macro_ShiftCurrentArgs(int32_t count);
|
||||||
|
uint32_t macro_NbArgs(void);
|
||||||
|
|
||||||
|
#endif
|
||||||
+27
-30
@@ -1,40 +1,37 @@
|
|||||||
#ifndef RGBDS_MAIN_H
|
/*
|
||||||
#define RGBDS_MAIN_H
|
* This file is part of RGBDS.
|
||||||
|
*
|
||||||
|
* Copyright (c) 1997-2021, Carsten Sorensen and RGBDS contributors.
|
||||||
|
*
|
||||||
|
* SPDX-License-Identifier: MIT
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef RGBDS_MAIN_H
|
||||||
|
#define RGBDS_MAIN_H
|
||||||
|
|
||||||
#include <stdbool.h>
|
#include <stdbool.h>
|
||||||
#include "extern/stdnoreturn.h"
|
#include <stdint.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
|
||||||
struct sOptions {
|
#include "helpers.h"
|
||||||
char gbgfx[4];
|
|
||||||
char binary[2];
|
|
||||||
SLONG fillchar;
|
|
||||||
bool verbose;
|
|
||||||
bool haltnop;
|
|
||||||
bool exportall;
|
|
||||||
bool warnings; /* true to enable warnings, false to disable them. */
|
|
||||||
//-1 == random
|
|
||||||
};
|
|
||||||
|
|
||||||
extern char *tzNewMacro;
|
extern bool haltnop;
|
||||||
extern ULONG ulNewMacroSize;
|
extern bool optimizeloads;
|
||||||
extern SLONG nGBGfxID;
|
extern bool verbose;
|
||||||
extern SLONG nBinaryID;
|
extern bool warnings; /* True to enable warnings, false to disable them. */
|
||||||
|
|
||||||
extern struct sOptions DefaultOptions;
|
extern FILE *dependfile;
|
||||||
extern struct sOptions CurrentOptions;
|
extern char *tzTargetFileName;
|
||||||
extern void opt_Push(void);
|
extern bool oGeneratedMissingIncludes;
|
||||||
extern void opt_Pop(void);
|
extern bool oFailedOnMissingInclude;
|
||||||
extern void opt_Parse(char *s);
|
extern bool oGeneratePhonyDeps;
|
||||||
|
|
||||||
noreturn void fatalerror(const char *fmt, ...);
|
/* TODO: are these really needed? */
|
||||||
void yyerror(const char *fmt, ...);
|
#define YY_FATAL_ERROR fatalerror
|
||||||
void warning(const char *fmt, ...);
|
|
||||||
|
|
||||||
#define YY_FATAL_ERROR fatalerror
|
#ifdef YYLMAX
|
||||||
|
#undef YYLMAX
|
||||||
#ifdef YYLMAX
|
|
||||||
#undef YYLMAX
|
|
||||||
#endif
|
#endif
|
||||||
#define YYLMAX 65536
|
#define YYLMAX 65536
|
||||||
|
|
||||||
#endif
|
#endif /* RGBDS_MAIN_H */
|
||||||
|
|||||||
@@ -1,61 +0,0 @@
|
|||||||
#ifndef RGBDS_ASM_LINK_H
|
|
||||||
#define RGBDS_ASM_LINK_H
|
|
||||||
|
|
||||||
enum {
|
|
||||||
RPN_ADD = 0,
|
|
||||||
RPN_SUB,
|
|
||||||
RPN_MUL,
|
|
||||||
RPN_DIV,
|
|
||||||
RPN_MOD,
|
|
||||||
RPN_UNSUB,
|
|
||||||
|
|
||||||
RPN_OR,
|
|
||||||
RPN_AND,
|
|
||||||
RPN_XOR,
|
|
||||||
RPN_UNNOT,
|
|
||||||
|
|
||||||
RPN_LOGAND,
|
|
||||||
RPN_LOGOR,
|
|
||||||
RPN_LOGUNNOT,
|
|
||||||
|
|
||||||
RPN_LOGEQ,
|
|
||||||
RPN_LOGNE,
|
|
||||||
RPN_LOGGT,
|
|
||||||
RPN_LOGLT,
|
|
||||||
RPN_LOGGE,
|
|
||||||
RPN_LOGLE,
|
|
||||||
|
|
||||||
RPN_SHL,
|
|
||||||
RPN_SHR,
|
|
||||||
|
|
||||||
RPN_BANK,
|
|
||||||
|
|
||||||
RPN_HRAM,
|
|
||||||
|
|
||||||
RPN_CONST = 0x80,
|
|
||||||
RPN_SYM = 0x81
|
|
||||||
};
|
|
||||||
|
|
||||||
enum {
|
|
||||||
SECT_WRAM0 = 0,
|
|
||||||
SECT_VRAM,
|
|
||||||
SECT_ROMX,
|
|
||||||
SECT_ROM0,
|
|
||||||
SECT_HRAM,
|
|
||||||
SECT_WRAMX,
|
|
||||||
SECT_SRAM,
|
|
||||||
SECT_OAM
|
|
||||||
};
|
|
||||||
|
|
||||||
enum {
|
|
||||||
SYM_LOCAL = 0,
|
|
||||||
SYM_IMPORT,
|
|
||||||
SYM_EXPORT
|
|
||||||
};
|
|
||||||
|
|
||||||
enum {
|
|
||||||
PATCH_BYTE = 0,
|
|
||||||
PATCH_WORD_L,
|
|
||||||
PATCH_LONG_L
|
|
||||||
};
|
|
||||||
#endif
|
|
||||||
@@ -1,21 +0,0 @@
|
|||||||
#ifndef RGBDS_ASM_MATH_H
|
|
||||||
#define RGBDS_ASM_MATH_H
|
|
||||||
|
|
||||||
#include "types.h"
|
|
||||||
|
|
||||||
void math_DefinePI(void);
|
|
||||||
void math_Print(SLONG i);
|
|
||||||
SLONG math_Sin(SLONG i);
|
|
||||||
SLONG math_Cos(SLONG i);
|
|
||||||
SLONG math_Tan(SLONG i);
|
|
||||||
SLONG math_ASin(SLONG i);
|
|
||||||
SLONG math_ACos(SLONG i);
|
|
||||||
SLONG math_ATan(SLONG i);
|
|
||||||
SLONG math_ATan2(SLONG i, SLONG j);
|
|
||||||
SLONG math_Mul(SLONG i, SLONG j);
|
|
||||||
SLONG math_Div(SLONG i, SLONG j);
|
|
||||||
SLONG math_Round(SLONG i);
|
|
||||||
SLONG math_Ceil(SLONG i);
|
|
||||||
SLONG math_Floor(SLONG i);
|
|
||||||
|
|
||||||
#endif
|
|
||||||
@@ -0,0 +1,22 @@
|
|||||||
|
/*
|
||||||
|
* 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
|
||||||
|
|
||||||
|
|
||||||
|
void opt_B(char chars[2]);
|
||||||
|
void opt_G(char chars[4]);
|
||||||
|
void opt_P(uint8_t fill);
|
||||||
|
void opt_Parse(char const *option);
|
||||||
|
|
||||||
|
void opt_Push(void);
|
||||||
|
void opt_Pop(void);
|
||||||
|
|
||||||
|
|
||||||
|
#endif
|
||||||
+22
-32
@@ -1,40 +1,30 @@
|
|||||||
|
/*
|
||||||
|
* This file is part of RGBDS.
|
||||||
|
*
|
||||||
|
* Copyright (c) 1997-2018, Carsten Sorensen and RGBDS contributors.
|
||||||
|
*
|
||||||
|
* SPDX-License-Identifier: MIT
|
||||||
|
*/
|
||||||
|
|
||||||
#ifndef RGBDS_ASM_OUTPUT_H
|
#ifndef RGBDS_ASM_OUTPUT_H
|
||||||
#define RGBDS_ASM_OUTPUT_H
|
#define RGBDS_ASM_OUTPUT_H
|
||||||
|
|
||||||
#include "asm/rpn.h"
|
#include <stdint.h>
|
||||||
#include "types.h"
|
|
||||||
|
|
||||||
struct Section {
|
#include "linkdefs.h"
|
||||||
char *pzName;
|
|
||||||
UBYTE nType;
|
|
||||||
ULONG nPC;
|
|
||||||
ULONG nOrg;
|
|
||||||
ULONG nBank;
|
|
||||||
ULONG nAlign;
|
|
||||||
struct Section *pNext;
|
|
||||||
struct Patch *pPatches;
|
|
||||||
struct Charmap *charmap;
|
|
||||||
UBYTE *tData;
|
|
||||||
};
|
|
||||||
|
|
||||||
void out_PrepPass2(void);
|
struct Expression;
|
||||||
|
struct FileStackNode;
|
||||||
|
|
||||||
|
extern char *tzObjectname;
|
||||||
|
extern struct Section *pSectionList, *pCurrentSection;
|
||||||
|
|
||||||
|
void out_RegisterNode(struct FileStackNode *node);
|
||||||
|
void out_ReplaceNode(struct FileStackNode *node);
|
||||||
void out_SetFileName(char *s);
|
void out_SetFileName(char *s);
|
||||||
void out_NewSection(char *pzName, ULONG secttype);
|
void out_CreatePatch(uint32_t type, struct Expression const *expr, uint32_t ofs, uint32_t pcShift);
|
||||||
void out_NewAbsSection(char *pzName, ULONG secttype, SLONG org, SLONG bank);
|
bool out_CreateAssert(enum AssertionType type, struct Expression const *expr,
|
||||||
void out_NewAlignedSection(char *pzName, ULONG secttype, SLONG alignment, SLONG bank);
|
char const *message, uint32_t ofs);
|
||||||
void out_AbsByte(int b);
|
|
||||||
void out_AbsByteGroup(char *s, int length);
|
|
||||||
void out_RelByte(struct Expression * expr);
|
|
||||||
void out_RelWord(struct Expression * expr);
|
|
||||||
void out_PCRelByte(struct Expression * expr);
|
|
||||||
void out_WriteObject(void);
|
void out_WriteObject(void);
|
||||||
void out_Skip(int skip);
|
|
||||||
void out_BinaryFile(char *s);
|
|
||||||
void out_BinaryFileSlice(char *s, SLONG start_pos, SLONG length);
|
|
||||||
void out_String(char *s);
|
|
||||||
void out_AbsLong(SLONG b);
|
|
||||||
void out_RelLong(struct Expression * expr);
|
|
||||||
void out_PushSection(void);
|
|
||||||
void out_PopSection(void);
|
|
||||||
|
|
||||||
#endif
|
#endif /* RGBDS_ASM_OUTPUT_H */
|
||||||
|
|||||||
+59
-74
@@ -1,81 +1,66 @@
|
|||||||
|
/*
|
||||||
|
* This file is part of RGBDS.
|
||||||
|
*
|
||||||
|
* Copyright (c) 1997-2018, Carsten Sorensen and RGBDS contributors.
|
||||||
|
*
|
||||||
|
* SPDX-License-Identifier: MIT
|
||||||
|
*/
|
||||||
|
|
||||||
#ifndef RGBDS_ASM_RPN_H
|
#ifndef RGBDS_ASM_RPN_H
|
||||||
#define RGBDS_ASM_RPN_H
|
#define RGBDS_ASM_RPN_H
|
||||||
|
|
||||||
|
#include <stdint.h>
|
||||||
|
#include <stdbool.h>
|
||||||
|
|
||||||
|
#include "linkdefs.h"
|
||||||
|
|
||||||
|
#define MAXRPNLEN 1048576
|
||||||
|
|
||||||
struct Expression {
|
struct Expression {
|
||||||
SLONG nVal;
|
int32_t nVal; // If the expression's value is known, it's here
|
||||||
UBYTE tRPN[256];
|
char *reason; // Why the expression is not known, if it isn't
|
||||||
ULONG nRPNLength;
|
bool isKnown; // Whether the expression's value is known
|
||||||
ULONG nRPNOut;
|
bool isSymbol; // Whether the expression represents a symbol
|
||||||
ULONG isReloc;
|
uint8_t *tRPN; // Array of bytes serializing the RPN expression
|
||||||
ULONG isPCRel;
|
uint32_t nRPNCapacity; // Size of the `tRPN` buffer
|
||||||
|
uint32_t nRPNLength; // Used size of the `tRPN` buffer
|
||||||
|
uint32_t nRPNPatchSize; // Size the expression will take in the obj file
|
||||||
};
|
};
|
||||||
|
|
||||||
ULONG rpn_isReloc(struct Expression * expr);
|
/*
|
||||||
ULONG rpn_isPCRelative(struct Expression * expr);
|
* Determines if an expression is known at assembly time
|
||||||
void rpn_Symbol(struct Expression * expr, char *tzSym);
|
*/
|
||||||
void rpn_Number(struct Expression * expr, ULONG i);
|
static inline bool rpn_isKnown(const struct Expression *expr)
|
||||||
void rpn_LOGNOT(struct Expression * expr, struct Expression * src1);
|
{
|
||||||
void
|
return expr->isKnown;
|
||||||
rpn_LOGOR(struct Expression * expr, struct Expression * src1,
|
}
|
||||||
struct Expression * src2);
|
|
||||||
void
|
|
||||||
rpn_LOGAND(struct Expression * expr, struct Expression * src1,
|
|
||||||
struct Expression * src2);
|
|
||||||
void
|
|
||||||
rpn_LOGEQU(struct Expression * expr, struct Expression * src1,
|
|
||||||
struct Expression * src2);
|
|
||||||
void
|
|
||||||
rpn_LOGGT(struct Expression * expr, struct Expression * src1,
|
|
||||||
struct Expression * src2);
|
|
||||||
void
|
|
||||||
rpn_LOGLT(struct Expression * expr, struct Expression * src1,
|
|
||||||
struct Expression * src2);
|
|
||||||
void
|
|
||||||
rpn_LOGGE(struct Expression * expr, struct Expression * src1,
|
|
||||||
struct Expression * src2);
|
|
||||||
void
|
|
||||||
rpn_LOGLE(struct Expression * expr, struct Expression * src1,
|
|
||||||
struct Expression * src2);
|
|
||||||
void
|
|
||||||
rpn_LOGNE(struct Expression * expr, struct Expression * src1,
|
|
||||||
struct Expression * src2);
|
|
||||||
void
|
|
||||||
rpn_ADD(struct Expression * expr, struct Expression * src1,
|
|
||||||
struct Expression * src2);
|
|
||||||
void
|
|
||||||
rpn_SUB(struct Expression * expr, struct Expression * src1,
|
|
||||||
struct Expression * src2);
|
|
||||||
void
|
|
||||||
rpn_XOR(struct Expression * expr, struct Expression * src1,
|
|
||||||
struct Expression * src2);
|
|
||||||
void
|
|
||||||
rpn_OR(struct Expression * expr, struct Expression * src1,
|
|
||||||
struct Expression * src2);
|
|
||||||
void
|
|
||||||
rpn_AND(struct Expression * expr, struct Expression * src1,
|
|
||||||
struct Expression * src2);
|
|
||||||
void
|
|
||||||
rpn_SHL(struct Expression * expr, struct Expression * src1,
|
|
||||||
struct Expression * src2);
|
|
||||||
void
|
|
||||||
rpn_SHR(struct Expression * expr, struct Expression * src1,
|
|
||||||
struct Expression * src2);
|
|
||||||
void
|
|
||||||
rpn_MUL(struct Expression * expr, struct Expression * src1,
|
|
||||||
struct Expression * src2);
|
|
||||||
void
|
|
||||||
rpn_DIV(struct Expression * expr, struct Expression * src1,
|
|
||||||
struct Expression * src2);
|
|
||||||
void
|
|
||||||
rpn_MOD(struct Expression * expr, struct Expression * src1,
|
|
||||||
struct Expression * src2);
|
|
||||||
void rpn_HIGH(struct Expression * expr, struct Expression * src);
|
|
||||||
void rpn_LOW(struct Expression * expr, struct Expression * src);
|
|
||||||
void rpn_UNNEG(struct Expression * expr, struct Expression * src);
|
|
||||||
void rpn_UNNOT(struct Expression * expr, struct Expression * src);
|
|
||||||
UWORD rpn_PopByte(struct Expression * expr);
|
|
||||||
void rpn_Bank(struct Expression * expr, char *tzSym);
|
|
||||||
void rpn_Reset(struct Expression * expr);
|
|
||||||
void rpn_CheckHRAM(struct Expression * expr, struct Expression * src1);
|
|
||||||
|
|
||||||
#endif
|
/*
|
||||||
|
* Determines if an expression is a symbol suitable for const diffing
|
||||||
|
*/
|
||||||
|
static inline bool rpn_isSymbol(const struct Expression *expr)
|
||||||
|
{
|
||||||
|
return expr->isSymbol;
|
||||||
|
}
|
||||||
|
|
||||||
|
void rpn_Symbol(struct Expression *expr, char const *tzSym);
|
||||||
|
void rpn_Number(struct Expression *expr, uint32_t i);
|
||||||
|
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 *sym);
|
||||||
|
void rpn_BinaryOp(enum RPNCommand op, struct Expression *expr,
|
||||||
|
const struct Expression *src1,
|
||||||
|
const struct Expression *src2);
|
||||||
|
void rpn_HIGH(struct Expression *expr, const struct Expression *src);
|
||||||
|
void rpn_LOW(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_UNNOT(struct Expression *expr, const struct Expression *src);
|
||||||
|
void rpn_BankSymbol(struct Expression *expr, char const *tzSym);
|
||||||
|
void rpn_BankSection(struct Expression *expr, char const *tzSectionName);
|
||||||
|
void rpn_BankSelf(struct Expression *expr);
|
||||||
|
void rpn_Free(struct Expression *expr);
|
||||||
|
void rpn_CheckHRAM(struct Expression *expr, const struct Expression *src);
|
||||||
|
void rpn_CheckRST(struct Expression *expr, const struct Expression *src);
|
||||||
|
|
||||||
|
#endif /* RGBDS_ASM_RPN_H */
|
||||||
|
|||||||
@@ -0,0 +1,79 @@
|
|||||||
|
/*
|
||||||
|
* This file is part of RGBDS.
|
||||||
|
*
|
||||||
|
* Copyright (c) 2020, Carsten Sorensen and RGBDS contributors.
|
||||||
|
*
|
||||||
|
* SPDX-License-Identifier: MIT
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef RGBDS_SECTION_H
|
||||||
|
#define RGBDS_SECTION_H
|
||||||
|
|
||||||
|
#include <stdint.h>
|
||||||
|
#include <stdbool.h>
|
||||||
|
|
||||||
|
#include "linkdefs.h"
|
||||||
|
|
||||||
|
extern uint8_t fillByte;
|
||||||
|
|
||||||
|
struct Expression;
|
||||||
|
|
||||||
|
struct Section {
|
||||||
|
char *name;
|
||||||
|
enum SectionType type;
|
||||||
|
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 org;
|
||||||
|
uint32_t bank;
|
||||||
|
uint8_t align;
|
||||||
|
uint16_t alignOfs;
|
||||||
|
struct Section *next;
|
||||||
|
struct Patch *patches;
|
||||||
|
uint8_t *data;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct SectionSpec {
|
||||||
|
uint32_t bank;
|
||||||
|
uint8_t alignment;
|
||||||
|
uint16_t alignOfs;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct Section *out_FindSectionByName(const char *name);
|
||||||
|
void out_NewSection(char const *name, uint32_t secttype, uint32_t org,
|
||||||
|
struct SectionSpec const *attributes,
|
||||||
|
enum SectionModifier mod);
|
||||||
|
void out_SetLoadSection(char const *name, uint32_t secttype, uint32_t org,
|
||||||
|
struct SectionSpec const *attributes,
|
||||||
|
enum SectionModifier mod);
|
||||||
|
void out_EndLoadSection(void);
|
||||||
|
|
||||||
|
struct Section *sect_GetSymbolSection(void);
|
||||||
|
uint32_t sect_GetSymbolOffset(void);
|
||||||
|
uint32_t sect_GetOutputOffset(void);
|
||||||
|
void sect_AlignPC(uint8_t alignment, uint16_t offset);
|
||||||
|
|
||||||
|
void sect_StartUnion(void);
|
||||||
|
void sect_NextUnionMember(void);
|
||||||
|
void sect_EndUnion(void);
|
||||||
|
void sect_CheckUnionClosed(void);
|
||||||
|
|
||||||
|
void out_AbsByte(uint8_t b);
|
||||||
|
void out_AbsByteGroup(uint8_t const *s, int32_t length);
|
||||||
|
void out_AbsWordGroup(uint8_t const *s, int32_t length);
|
||||||
|
void out_AbsLongGroup(uint8_t const *s, int32_t length);
|
||||||
|
void out_Skip(int32_t skip, bool ds);
|
||||||
|
void out_String(char const *s);
|
||||||
|
void out_RelByte(struct Expression *expr, uint32_t pcShift);
|
||||||
|
void out_RelBytes(uint32_t n, struct Expression *exprs, size_t size);
|
||||||
|
void out_RelWord(struct Expression *expr, uint32_t pcShift);
|
||||||
|
void out_RelLong(struct Expression *expr, uint32_t pcShift);
|
||||||
|
void out_PCRelByte(struct Expression *expr, uint32_t pcShift);
|
||||||
|
void out_BinaryFile(char const *s, int32_t startPos);
|
||||||
|
void out_BinaryFileSlice(char const *s, int32_t start_pos, int32_t length);
|
||||||
|
|
||||||
|
void out_PushSection(void);
|
||||||
|
void out_PopSection(void);
|
||||||
|
|
||||||
|
#endif
|
||||||
+143
-66
@@ -1,75 +1,152 @@
|
|||||||
|
/*
|
||||||
|
* This file is part of RGBDS.
|
||||||
|
*
|
||||||
|
* Copyright (c) 1997-2020, Carsten Sorensen and RGBDS contributors.
|
||||||
|
*
|
||||||
|
* SPDX-License-Identifier: MIT
|
||||||
|
*/
|
||||||
|
|
||||||
#ifndef RGBDS_SYMBOL_H
|
#ifndef RGBDS_SYMBOL_H
|
||||||
#define RGBDS_SYMBOL_H
|
#define RGBDS_SYMBOL_H
|
||||||
|
|
||||||
|
#include <stdbool.h>
|
||||||
|
#include <stdint.h>
|
||||||
|
#include <string.h>
|
||||||
|
#include <time.h>
|
||||||
|
|
||||||
|
#include "asm/section.h"
|
||||||
|
|
||||||
|
#include "platform.h" // MIN_NB_ELMS
|
||||||
#include "types.h"
|
#include "types.h"
|
||||||
|
|
||||||
#define HASHSIZE (1 << 16)
|
#define HASHSIZE (1 << 16)
|
||||||
#define MAXSYMLEN 256
|
#define MAXSYMLEN 256
|
||||||
|
|
||||||
struct sSymbol {
|
enum SymbolType {
|
||||||
char tzName[MAXSYMLEN + 1];
|
SYM_LABEL,
|
||||||
SLONG nValue;
|
SYM_EQU,
|
||||||
ULONG nType;
|
SYM_SET,
|
||||||
struct sSymbol *pScope;
|
SYM_MACRO,
|
||||||
struct sSymbol *pNext;
|
SYM_EQUS,
|
||||||
struct Section *pSection;
|
SYM_REF // Forward reference to a label
|
||||||
ULONG ulMacroSize;
|
|
||||||
char *pMacro;
|
|
||||||
SLONG(*Callback) (struct sSymbol *);
|
|
||||||
};
|
};
|
||||||
#define SYMF_RELOC 0x001 /* symbol will be reloc'ed during
|
|
||||||
* linking, it's absolute value is
|
|
||||||
* unknown */
|
|
||||||
#define SYMF_EQU 0x002 /* symbol is defined using EQU, will
|
|
||||||
* not be changed during linking */
|
|
||||||
#define SYMF_SET 0x004 /* symbol is (re)defined using SET,
|
|
||||||
* will not be changed during linking */
|
|
||||||
#define SYMF_EXPORT 0x008 /* symbol should be exported */
|
|
||||||
#define SYMF_IMPORT 0x010 /* symbol is imported, it's value is
|
|
||||||
* unknown */
|
|
||||||
#define SYMF_LOCAL 0x020 /* symbol is a local symbol */
|
|
||||||
#define SYMF_DEFINED 0x040 /* symbol has been defined, not only
|
|
||||||
* referenced */
|
|
||||||
#define SYMF_MACRO 0x080 /* symbol is a macro */
|
|
||||||
#define SYMF_STRING 0x100 /* symbol is a stringsymbol */
|
|
||||||
#define SYMF_CONST 0x200 /* symbol has a constant value, will
|
|
||||||
* not be changed during linking */
|
|
||||||
|
|
||||||
ULONG calchash(char *s);
|
struct Symbol {
|
||||||
void sym_SetExportAll(BBOOL set);
|
char name[MAXSYMLEN + 1];
|
||||||
void sym_PrepPass1(void);
|
enum SymbolType type;
|
||||||
void sym_PrepPass2(void);
|
bool isExported; /* Whether the symbol is to be exported */
|
||||||
void sym_AddLocalReloc(char *tzSym);
|
bool isBuiltin; /* Whether the symbol is a built-in */
|
||||||
void sym_AddReloc(char *tzSym);
|
struct Section *section;
|
||||||
void sym_Export(char *tzSym);
|
struct FileStackNode *src; /* Where the symbol was defined */
|
||||||
void sym_PrintSymbolTable(void);
|
uint32_t fileLine; /* Line where the symbol was defined */
|
||||||
struct sSymbol *sym_FindMacro(char *s);
|
|
||||||
void sym_InitNewMacroArgs(void);
|
|
||||||
void sym_AddNewMacroArg(char *s);
|
|
||||||
void sym_SaveCurrentMacroArgs(char *save[]);
|
|
||||||
void sym_RestoreCurrentMacroArgs(char *save[]);
|
|
||||||
void sym_UseNewMacroArgs(void);
|
|
||||||
void sym_FreeCurrentMacroArgs(void);
|
|
||||||
void sym_AddEqu(char *tzSym, SLONG value);
|
|
||||||
void sym_AddSet(char *tzSym, SLONG value);
|
|
||||||
void sym_Init(void);
|
|
||||||
ULONG sym_GetConstantValue(char *s);
|
|
||||||
ULONG sym_isConstant(char *s);
|
|
||||||
struct sSymbol *sym_FindSymbol(char *tzName);
|
|
||||||
void sym_Global(char *tzSym);
|
|
||||||
char *sym_FindMacroArg(SLONG i);
|
|
||||||
char *sym_GetStringValue(char *tzSym);
|
|
||||||
void sym_UseCurrentMacroArgs(void);
|
|
||||||
void sym_SetMacroArgID(ULONG nMacroCount);
|
|
||||||
ULONG sym_isString(char *tzSym);
|
|
||||||
void sym_AddMacro(char *tzSym);
|
|
||||||
void sym_ShiftCurrentMacroArgs(void);
|
|
||||||
void sym_AddString(char *tzSym, char *tzValue);
|
|
||||||
ULONG sym_GetValue(char *s);
|
|
||||||
ULONG sym_GetDefinedValue(char *s);
|
|
||||||
ULONG sym_isDefined(char *tzName);
|
|
||||||
void sym_Purge(char *tzName);
|
|
||||||
ULONG sym_isConstDefined(char *tzName);
|
|
||||||
int sym_IsRelocDiffDefined(char *tzSym1, char *tzSym2);
|
|
||||||
|
|
||||||
#endif
|
bool hasCallback;
|
||||||
|
union {
|
||||||
|
/* If sym_IsNumeric */
|
||||||
|
int32_t value;
|
||||||
|
int32_t (*numCallback)(void);
|
||||||
|
/* For SYM_MACRO */
|
||||||
|
struct {
|
||||||
|
size_t macroSize;
|
||||||
|
char *macro;
|
||||||
|
};
|
||||||
|
/* For SYM_EQUS, TODO: separate "base" fields from SYM_MACRO */
|
||||||
|
char const *(*strCallback)(void); /* For SYM_EQUS */
|
||||||
|
};
|
||||||
|
|
||||||
|
uint32_t ID; /* ID of the symbol in the object file (-1 if none) */
|
||||||
|
struct Symbol *next; /* Next object to output in the object file */
|
||||||
|
};
|
||||||
|
|
||||||
|
bool sym_IsPC(struct Symbol const *sym);
|
||||||
|
|
||||||
|
static inline bool sym_IsDefined(struct Symbol const *sym)
|
||||||
|
{
|
||||||
|
return sym->type != SYM_REF;
|
||||||
|
}
|
||||||
|
|
||||||
|
static inline struct Section *sym_GetSection(struct Symbol const *sym)
|
||||||
|
{
|
||||||
|
return sym_IsPC(sym) ? sect_GetSymbolSection() : sym->section;
|
||||||
|
}
|
||||||
|
|
||||||
|
static inline bool sym_IsConstant(struct Symbol const *sym)
|
||||||
|
{
|
||||||
|
if (sym->type == SYM_LABEL) {
|
||||||
|
struct Section const *sect = sym_GetSection(sym);
|
||||||
|
|
||||||
|
return sect && sect->org != (uint32_t)-1;
|
||||||
|
}
|
||||||
|
return sym->type == SYM_EQU || sym->type == SYM_SET;
|
||||||
|
}
|
||||||
|
|
||||||
|
static inline bool sym_IsNumeric(struct Symbol const *sym)
|
||||||
|
{
|
||||||
|
return sym->type == SYM_LABEL || sym->type == SYM_EQU
|
||||||
|
|| sym->type == SYM_SET;
|
||||||
|
}
|
||||||
|
|
||||||
|
static inline bool sym_IsLabel(struct Symbol const *sym)
|
||||||
|
{
|
||||||
|
return sym->type == SYM_LABEL || sym->type == SYM_REF;
|
||||||
|
}
|
||||||
|
|
||||||
|
static inline bool sym_IsLocal(struct Symbol const *sym)
|
||||||
|
{
|
||||||
|
return sym_IsLabel(sym) && strchr(sym->name, '.');
|
||||||
|
}
|
||||||
|
|
||||||
|
static inline bool sym_IsExported(struct Symbol const *sym)
|
||||||
|
{
|
||||||
|
return sym->isExported;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Get a string equate's value
|
||||||
|
*/
|
||||||
|
static inline char const *sym_GetStringValue(struct Symbol const *sym)
|
||||||
|
{
|
||||||
|
if (sym->hasCallback)
|
||||||
|
return sym->strCallback();
|
||||||
|
return sym->macro;
|
||||||
|
}
|
||||||
|
|
||||||
|
void sym_ForEach(void (*func)(struct Symbol *, void *), void *arg);
|
||||||
|
|
||||||
|
int32_t sym_GetValue(struct Symbol const *sym);
|
||||||
|
void sym_SetExportAll(bool set);
|
||||||
|
struct Symbol *sym_AddLocalLabel(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);
|
||||||
|
struct Symbol *sym_AddEqu(char const *symName, int32_t value);
|
||||||
|
struct Symbol *sym_AddSet(char const *symName, int32_t value);
|
||||||
|
uint32_t sym_GetPCValue(void);
|
||||||
|
uint32_t sym_GetConstantSymValue(struct Symbol const *sym);
|
||||||
|
uint32_t sym_GetConstantValue(char const *s);
|
||||||
|
/*
|
||||||
|
* Find a symbol by exact name, bypassing expansion checks
|
||||||
|
*/
|
||||||
|
struct Symbol *sym_FindExactSymbol(char const *name);
|
||||||
|
/*
|
||||||
|
* Find a symbol by exact name; may not be scoped, produces an error if it is
|
||||||
|
*/
|
||||||
|
struct Symbol *sym_FindUnscopedSymbol(char const *name);
|
||||||
|
/*
|
||||||
|
* Find a symbol, possibly scoped, by name
|
||||||
|
*/
|
||||||
|
struct Symbol *sym_FindScopedSymbol(char const *name);
|
||||||
|
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_AddString(char const *symName, char const *value);
|
||||||
|
struct Symbol *sym_RedefString(char const *symName, char const *value);
|
||||||
|
void sym_Purge(char const *symName);
|
||||||
|
void sym_Init(time_t now);
|
||||||
|
|
||||||
|
/* Functions to save and restore the current symbol scope. */
|
||||||
|
char const *sym_GetCurrentSymbolScope(void);
|
||||||
|
void sym_SetCurrentSymbolScope(char const *newScope);
|
||||||
|
|
||||||
|
#endif /* RGBDS_SYMBOL_H */
|
||||||
|
|||||||
@@ -0,0 +1,21 @@
|
|||||||
|
/*
|
||||||
|
* This file is part of RGBDS.
|
||||||
|
*
|
||||||
|
* Copyright (c) 1997-2019, Carsten Sorensen and RGBDS contributors.
|
||||||
|
*
|
||||||
|
* SPDX-License-Identifier: MIT
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef RGBDS_UTIL_H
|
||||||
|
#define RGBDS_UTIL_H
|
||||||
|
|
||||||
|
#include <stdint.h>
|
||||||
|
|
||||||
|
uint32_t calchash(const char *s);
|
||||||
|
char const *print(int c);
|
||||||
|
/*
|
||||||
|
* @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 */
|
||||||
@@ -0,0 +1,70 @@
|
|||||||
|
/*
|
||||||
|
* This file is part of RGBDS.
|
||||||
|
*
|
||||||
|
* Copyright (c) 2019, Eldred Habert and RGBDS contributors.
|
||||||
|
*
|
||||||
|
* SPDX-License-Identifier: MIT
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef WARNING_H
|
||||||
|
#define WARNING_H
|
||||||
|
|
||||||
|
#include "helpers.h"
|
||||||
|
|
||||||
|
extern unsigned int nbErrors;
|
||||||
|
|
||||||
|
enum WarningID {
|
||||||
|
WARNING_ASSERT, /* Assertions */
|
||||||
|
WARNING_BUILTIN_ARG, /* Invalid args to builtins */
|
||||||
|
WARNING_CHARMAP_REDEF, /* Charmap entry re-definition */
|
||||||
|
WARNING_DIV, /* Division undefined behavior */
|
||||||
|
WARNING_EMPTY_DATA_DIRECTIVE, /* `db`, `dw` or `dl` directive without data in ROM */
|
||||||
|
WARNING_EMPTY_MACRO_ARG, /* Empty macro argument */
|
||||||
|
WARNING_EMPTY_STRRPL, /* Empty second argument in `STRRPL` */
|
||||||
|
WARNING_LARGE_CONSTANT, /* Constants too large */
|
||||||
|
WARNING_LONG_STR, /* String too long for internal buffers */
|
||||||
|
WARNING_MACRO_SHIFT, /* Shift past available arguments in macro */
|
||||||
|
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_TRUNCATION, /* Implicit truncation loses some bits */
|
||||||
|
WARNING_USER, /* User warnings */
|
||||||
|
|
||||||
|
NB_WARNINGS,
|
||||||
|
|
||||||
|
/* Warnings past this point are "meta" warnings */
|
||||||
|
WARNING_ALL = NB_WARNINGS,
|
||||||
|
WARNING_EXTRA,
|
||||||
|
WARNING_EVERYTHING,
|
||||||
|
|
||||||
|
NB_WARNINGS_ALL
|
||||||
|
#define NB_META_WARNINGS (NB_WARNINGS_ALL - NB_WARNINGS)
|
||||||
|
};
|
||||||
|
|
||||||
|
void processWarningFlag(char const *flag);
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Used to warn the user about problems that don't prevent the generation of
|
||||||
|
* valid code.
|
||||||
|
*/
|
||||||
|
void warning(enum WarningID id, const char *fmt, ...) format_(printf, 2, 3);
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Used for errors that compromise the whole assembly process by affecting the
|
||||||
|
* following code, potencially making the assembler generate errors caused by
|
||||||
|
* the first one and unrelated to the code that the assembler complains about.
|
||||||
|
* It is also used when the assembler goes into an invalid state (for example,
|
||||||
|
* when it fails to allocate memory).
|
||||||
|
*/
|
||||||
|
_Noreturn void fatalerror(const char *fmt, ...) format_(printf, 1, 2);
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Used for errors that make it impossible to assemble correctly, but don't
|
||||||
|
* affect the following code. The code will fail to assemble but the user will
|
||||||
|
* get a list of all errors at the end, making it easier to fix all of them at
|
||||||
|
* once.
|
||||||
|
*/
|
||||||
|
void error(const char *fmt, ...) format_(printf, 1, 2);
|
||||||
|
|
||||||
|
#endif
|
||||||
Vendored
+23
-12
@@ -1,12 +1,23 @@
|
|||||||
|
/*
|
||||||
|
* This file is part of RGBDS.
|
||||||
|
*
|
||||||
|
* Copyright (c) 1997-2018, RGBDS contributors.
|
||||||
|
*
|
||||||
|
* SPDX-License-Identifier: MIT
|
||||||
|
*/
|
||||||
|
|
||||||
#ifndef EXTERN_ERR_H
|
#ifndef EXTERN_ERR_H
|
||||||
#define EXTERN_ERR_H
|
#define EXTERN_ERR_H
|
||||||
|
|
||||||
#ifdef ERR_IN_LIBC
|
#ifdef ERR_IN_LIBC
|
||||||
|
|
||||||
#include <err.h>
|
#include <err.h>
|
||||||
#else
|
|
||||||
|
#else /* ERR_IN_LIBC */
|
||||||
|
|
||||||
#include <stdarg.h>
|
#include <stdarg.h>
|
||||||
#include "extern/stdnoreturn.h"
|
|
||||||
|
#include "helpers.h"
|
||||||
|
|
||||||
#define warn rgbds_warn
|
#define warn rgbds_warn
|
||||||
#define vwarn rgbds_vwarn
|
#define vwarn rgbds_vwarn
|
||||||
@@ -18,16 +29,16 @@
|
|||||||
#define errx rgbds_errx
|
#define errx rgbds_errx
|
||||||
#define verrx rgbds_verrx
|
#define verrx rgbds_verrx
|
||||||
|
|
||||||
void warn(const char *, ...);
|
void warn(const char *fmt, ...) format_(printf, 1, 2);
|
||||||
void vwarn(const char *, va_list);
|
void vwarn(const char *fmt, va_list ap) format_(printf, 1, 0);
|
||||||
void warnx(const char *, ...);
|
void warnx(const char *fmt, ...) format_(printf, 1, 2);
|
||||||
void vwarnx(const char *, va_list);
|
void vwarnx(const char *fmt, va_list ap) format_(printf, 1, 0);
|
||||||
|
|
||||||
noreturn void err(int, const char *, ...);
|
_Noreturn void err(int status, const char *fmt, ...) format_(printf, 2, 3);
|
||||||
noreturn void verr(int, const char *, va_list);
|
_Noreturn void verr(int status, const char *fmt, va_list ap) format_(printf, 2, 0);
|
||||||
noreturn void errx(int, const char *, ...);
|
_Noreturn void errx(int status, const char *fmt, ...) format_(printf, 2, 3);
|
||||||
noreturn void verrx(int, const char *, va_list);
|
_Noreturn void verrx(int status, const char *fmt, va_list ap) format_(printf, 2, 0);
|
||||||
|
|
||||||
#endif
|
#endif /* ERR_IN_LIBC */
|
||||||
|
|
||||||
#endif
|
#endif /* EXTERN_ERR_H */
|
||||||
|
|||||||
Vendored
+45
@@ -0,0 +1,45 @@
|
|||||||
|
/*
|
||||||
|
* Copyright © 2005-2020 Rich Felker, et al.
|
||||||
|
*
|
||||||
|
* 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.
|
||||||
|
*/
|
||||||
|
|
||||||
|
/* This implementation was taken from musl and modified for RGBDS */
|
||||||
|
|
||||||
|
#ifndef RGBDS_EXTERN_GETOPT_H
|
||||||
|
#define RGBDS_EXTERN_GETOPT_H
|
||||||
|
|
||||||
|
extern char *musl_optarg;
|
||||||
|
extern int musl_optind, musl_opterr, musl_optopt, musl_optreset;
|
||||||
|
|
||||||
|
struct option {
|
||||||
|
const char *name;
|
||||||
|
int has_arg;
|
||||||
|
int *flag;
|
||||||
|
int val;
|
||||||
|
};
|
||||||
|
|
||||||
|
int musl_getopt_long_only(int, char **, const char *, const struct option *, int *);
|
||||||
|
|
||||||
|
#define no_argument 0
|
||||||
|
#define required_argument 1
|
||||||
|
#define optional_argument 2
|
||||||
|
|
||||||
|
#endif
|
||||||
Vendored
-14
@@ -1,14 +0,0 @@
|
|||||||
#ifndef EXTERN_REALLOCARRAY_H
|
|
||||||
#define EXTERN_REALLOCARRAY_H
|
|
||||||
|
|
||||||
#ifdef REALLOCARRAY_IN_LIBC
|
|
||||||
#include <stdlib.h>
|
|
||||||
#else
|
|
||||||
|
|
||||||
#define reallocarray rgbds_reallocarray
|
|
||||||
|
|
||||||
void *reallocarray(void *, size_t, size_t);
|
|
||||||
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#endif
|
|
||||||
Vendored
-16
@@ -1,16 +0,0 @@
|
|||||||
#if __STDC_VERSION__ >= 201112L
|
|
||||||
/* C11 or newer */
|
|
||||||
#define noreturn _Noreturn
|
|
||||||
#elif __cplusplus >= 201103L
|
|
||||||
/* C++11 or newer */
|
|
||||||
#define noreturn [[noreturn]]
|
|
||||||
#elif __GNUC__ > 2 || (__GNUC__ == 2 && (__GNUC_MINOR__ >= 5))
|
|
||||||
/* GCC 2.5 or newer */
|
|
||||||
#define noreturn __attribute__ ((noreturn))
|
|
||||||
#elif _MSC_VER >= 1310
|
|
||||||
/* MS Visual Studio 2003/.NET Framework 1.1 or newer */
|
|
||||||
#define noreturn _declspec( noreturn)
|
|
||||||
#else
|
|
||||||
/* unsupported, but no need to throw a fit */
|
|
||||||
#define noreturn
|
|
||||||
#endif
|
|
||||||
Vendored
-13
@@ -1,13 +0,0 @@
|
|||||||
#ifndef STRL_H
|
|
||||||
#define STRL_H
|
|
||||||
|
|
||||||
#ifdef STRL_IN_LIBC
|
|
||||||
#include <string.h>
|
|
||||||
#else
|
|
||||||
#define strlcpy rgbds_strlcpy
|
|
||||||
#define strlcat rgbds_strlcat
|
|
||||||
size_t strlcpy(char *, const char *, size_t);
|
|
||||||
size_t strlcat(char *, const char *, size_t);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#endif
|
|
||||||
Vendored
+14
@@ -0,0 +1,14 @@
|
|||||||
|
/*
|
||||||
|
* This file is part of RGBDS.
|
||||||
|
*
|
||||||
|
* Copyright (c) 2018, Antonio Nino Diaz and RGBDS contributors.
|
||||||
|
*
|
||||||
|
* SPDX-License-Identifier: MIT
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef EXTERN_UTF8DECODER_H
|
||||||
|
#define EXTERN_UTF8DECODER_H
|
||||||
|
|
||||||
|
uint32_t decode(uint32_t *state, uint32_t *codep, uint8_t byte);
|
||||||
|
|
||||||
|
#endif /* EXTERN_UTF8DECODER_H */
|
||||||
+23
-17
@@ -1,17 +1,9 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright © 2013 stag019 <stag019@gmail.com>
|
* This file is part of RGBDS.
|
||||||
*
|
*
|
||||||
* Permission to use, copy, modify, and distribute this software for any
|
* Copyright (c) 2013-2018, stag019 and RGBDS contributors.
|
||||||
* purpose with or without fee is hereby granted, provided that the above
|
|
||||||
* copyright notice and this permission notice appear in all copies.
|
|
||||||
*
|
*
|
||||||
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
* SPDX-License-Identifier: MIT
|
||||||
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
|
||||||
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
|
||||||
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
|
||||||
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
|
||||||
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
|
||||||
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#ifndef RGBDS_GFX_GB_H
|
#ifndef RGBDS_GFX_GB_H
|
||||||
@@ -20,11 +12,25 @@
|
|||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
#include "gfx/main.h"
|
#include "gfx/main.h"
|
||||||
|
|
||||||
void png_to_gb(struct PNGImage png, struct GBImage *gb);
|
#define XFLIP 0x40
|
||||||
void output_file(struct Options opts, struct GBImage gb);
|
#define YFLIP 0x20
|
||||||
int get_tile_index(uint8_t *tile, uint8_t **tiles, int num_tiles, int tile_size);
|
|
||||||
void create_tilemap(struct Options opts, struct GBImage *gb, struct Tilemap *tilemap);
|
void raw_to_gb(const struct RawIndexedImage *raw_image, struct GBImage *gb);
|
||||||
void output_tilemap_file(struct Options opts, struct Tilemap tilemap);
|
void output_file(const struct Options *opts, const struct GBImage *gb);
|
||||||
void output_palette_file(struct Options opts, struct PNGImage png);
|
int get_tile_index(uint8_t *tile, uint8_t **tiles, int num_tiles,
|
||||||
|
int tile_size);
|
||||||
|
uint8_t reverse_bits(uint8_t b);
|
||||||
|
void xflip(uint8_t *tile, uint8_t *tile_xflip, int tile_size);
|
||||||
|
void yflip(uint8_t *tile, uint8_t *tile_yflip, int tile_size);
|
||||||
|
int get_mirrored_tile_index(uint8_t *tile, uint8_t **tiles, int num_tiles,
|
||||||
|
int tile_size, int *flags);
|
||||||
|
void create_mapfiles(const struct Options *opts, struct GBImage *gb,
|
||||||
|
struct Mapfile *tilemap, struct Mapfile *attrmap);
|
||||||
|
void output_tilemap_file(const struct Options *opts,
|
||||||
|
const struct Mapfile *tilemap);
|
||||||
|
void output_attrmap_file(const struct Options *opts,
|
||||||
|
const struct Mapfile *attrmap);
|
||||||
|
void output_palette_file(const struct Options *opts,
|
||||||
|
const struct RawIndexedImage *raw_image);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
+38
-22
@@ -1,17 +1,9 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright © 2013 stag019 <stag019@gmail.com>
|
* This file is part of RGBDS.
|
||||||
*
|
*
|
||||||
* Permission to use, copy, modify, and distribute this software for any
|
* Copyright (c) 2013-2018, stag019 and RGBDS contributors.
|
||||||
* purpose with or without fee is hereby granted, provided that the above
|
|
||||||
* copyright notice and this permission notice appear in all copies.
|
|
||||||
*
|
*
|
||||||
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
* SPDX-License-Identifier: MIT
|
||||||
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
|
||||||
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
|
||||||
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
|
||||||
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
|
||||||
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
|
||||||
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#ifndef RGBDS_GFX_MAIN_H
|
#ifndef RGBDS_GFX_MAIN_H
|
||||||
@@ -29,30 +21,54 @@ struct Options {
|
|||||||
bool hardfix;
|
bool hardfix;
|
||||||
bool fix;
|
bool fix;
|
||||||
bool horizontal;
|
bool horizontal;
|
||||||
|
bool mirror;
|
||||||
bool unique;
|
bool unique;
|
||||||
|
bool colorcurve;
|
||||||
int trim;
|
int trim;
|
||||||
char *mapfile;
|
char *tilemapfile;
|
||||||
bool mapout;
|
bool tilemapout;
|
||||||
|
char *attrmapfile;
|
||||||
|
bool attrmapout;
|
||||||
char *palfile;
|
char *palfile;
|
||||||
bool palout;
|
bool palout;
|
||||||
char *outfile;
|
char *outfile;
|
||||||
char *infile;
|
char *infile;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
struct RGBColor {
|
||||||
|
uint8_t red;
|
||||||
|
uint8_t green;
|
||||||
|
uint8_t blue;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct ImageOptions {
|
||||||
|
bool horizontal;
|
||||||
|
int trim;
|
||||||
|
char *tilemapfile;
|
||||||
|
bool tilemapout;
|
||||||
|
char *attrmapfile;
|
||||||
|
bool attrmapout;
|
||||||
|
char *palfile;
|
||||||
|
bool palout;
|
||||||
|
};
|
||||||
|
|
||||||
struct PNGImage {
|
struct PNGImage {
|
||||||
png_struct *png;
|
png_struct *png;
|
||||||
png_info *info;
|
png_info *info;
|
||||||
|
|
||||||
png_byte **data;
|
png_byte **data;
|
||||||
int width;
|
int width;
|
||||||
int height;
|
int height;
|
||||||
png_byte depth;
|
png_byte depth;
|
||||||
png_byte type;
|
png_byte type;
|
||||||
bool horizontal;
|
};
|
||||||
int trim;
|
|
||||||
char *mapfile;
|
struct RawIndexedImage {
|
||||||
bool mapout;
|
uint8_t **data;
|
||||||
char *palfile;
|
struct RGBColor *palette;
|
||||||
bool palout;
|
int num_colors;
|
||||||
|
unsigned int width;
|
||||||
|
unsigned int height;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct GBImage {
|
struct GBImage {
|
||||||
@@ -62,14 +78,14 @@ struct GBImage {
|
|||||||
int trim;
|
int trim;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct Tilemap {
|
struct Mapfile {
|
||||||
uint8_t *data;
|
uint8_t *data;
|
||||||
int size;
|
int size;
|
||||||
};
|
};
|
||||||
|
|
||||||
int depth, colors;
|
extern int depth, colors;
|
||||||
|
|
||||||
#include "gfx/makepng.h"
|
#include "gfx/makepng.h"
|
||||||
#include "gfx/gb.h"
|
#include "gfx/gb.h"
|
||||||
|
|
||||||
#endif
|
#endif /* RGBDS_GFX_MAIN_H */
|
||||||
|
|||||||
+10
-17
@@ -1,17 +1,9 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright © 2013 stag019 <stag019@gmail.com>
|
* This file is part of RGBDS.
|
||||||
*
|
*
|
||||||
* Permission to use, copy, modify, and distribute this software for any
|
* Copyright (c) 2013-2018, stag019 and RGBDS contributors.
|
||||||
* purpose with or without fee is hereby granted, provided that the above
|
|
||||||
* copyright notice and this permission notice appear in all copies.
|
|
||||||
*
|
*
|
||||||
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
* SPDX-License-Identifier: MIT
|
||||||
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
|
||||||
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
|
||||||
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
|
||||||
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
|
||||||
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
|
||||||
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#ifndef RGBDS_GFX_PNG_H
|
#ifndef RGBDS_GFX_PNG_H
|
||||||
@@ -19,10 +11,11 @@
|
|||||||
|
|
||||||
#include "gfx/main.h"
|
#include "gfx/main.h"
|
||||||
|
|
||||||
void input_png_file(struct Options opts, struct PNGImage *img);
|
struct RawIndexedImage *input_png_file(const struct Options *opts,
|
||||||
void get_text(struct PNGImage *png);
|
struct ImageOptions *png_options);
|
||||||
void set_text(struct PNGImage *png);
|
void output_png_file(const struct Options *opts,
|
||||||
void output_png_file(struct Options opts, struct PNGImage *png);
|
const struct ImageOptions *png_options,
|
||||||
void free_png_data(struct PNGImage *png);
|
const struct RawIndexedImage *raw_image);
|
||||||
|
void destroy_raw_image(struct RawIndexedImage **raw_image_ptr_ptr);
|
||||||
|
|
||||||
#endif
|
#endif /* RGBDS_GFX_PNG_H */
|
||||||
|
|||||||
@@ -0,0 +1,79 @@
|
|||||||
|
/*
|
||||||
|
* This file is part of RGBDS.
|
||||||
|
*
|
||||||
|
* Copyright (c) 1997-2019, Carsten Sorensen and RGBDS contributors.
|
||||||
|
*
|
||||||
|
* SPDX-License-Identifier: MIT
|
||||||
|
*/
|
||||||
|
|
||||||
|
/* Generic hashmap implementation (C++ templates are calling...) */
|
||||||
|
#ifndef RGBDS_LINK_HASHMAP_H
|
||||||
|
#define RGBDS_LINK_HASHMAP_H
|
||||||
|
|
||||||
|
#include <assert.h>
|
||||||
|
#include <stdbool.h>
|
||||||
|
|
||||||
|
#define HASH_NB_BITS 32
|
||||||
|
#define HALF_HASH_NB_BITS 16
|
||||||
|
static_assert(HALF_HASH_NB_BITS * 2 == HASH_NB_BITS, "");
|
||||||
|
#define HASHMAP_NB_BUCKETS (1 << HALF_HASH_NB_BITS)
|
||||||
|
|
||||||
|
/* HashMapEntry is internal, please do not attempt to use it */
|
||||||
|
typedef struct HashMapEntry *HashMap[HASHMAP_NB_BUCKETS];
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Adds an element to a hashmap.
|
||||||
|
* @warning Adding a new element with an already-present key will not cause an
|
||||||
|
* error, this must be handled externally.
|
||||||
|
* @warning Inserting a NULL will make `hash_GetElement`'s return ambiguous!
|
||||||
|
* @param map The HashMap to add the element to
|
||||||
|
* @param key The key with which the element will be stored and retrieved
|
||||||
|
* @param element The element to add
|
||||||
|
* @return True if a collision occurred (for statistics)
|
||||||
|
*/
|
||||||
|
bool hash_AddElement(HashMap map, char const *key, void *element);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Replaces an element with an already-present key in a hashmap.
|
||||||
|
* @warning Inserting a NULL will make `hash_GetElement`'s return ambiguous!
|
||||||
|
* @param map The HashMap to replace the element in
|
||||||
|
* @param key The key with which the element will be stored and retrieved
|
||||||
|
* @param element The element to replace
|
||||||
|
* @return True if the element was found and replaced
|
||||||
|
*/
|
||||||
|
bool hash_ReplaceElement(HashMap const map, char const *key, void *element);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Removes an element from a hashmap.
|
||||||
|
* @param map The HashMap to remove the element from
|
||||||
|
* @param key The key to search the element with
|
||||||
|
* @return True if the element was found and removed
|
||||||
|
*/
|
||||||
|
bool hash_RemoveElement(HashMap map, char const *key);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Finds an element in a hashmap.
|
||||||
|
* @param map The map to consider the elements of
|
||||||
|
* @param key The key to search an element for
|
||||||
|
* @return A pointer to the element, or NULL if not found. (NULL can be returned
|
||||||
|
* if such an element was added, but that sounds pretty silly.)
|
||||||
|
*/
|
||||||
|
void *hash_GetElement(HashMap const map, char const *key);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Executes a function on each element in a hashmap.
|
||||||
|
* @param map The map to consider the elements of
|
||||||
|
* @param func The function to run. The first argument will be the element,
|
||||||
|
* the second will be `arg`.
|
||||||
|
* @param arg An argument to be passed to all function calls
|
||||||
|
*/
|
||||||
|
void hash_ForEach(HashMap const map, void (*func)(void *, void *), void *arg);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Cleanly empties a hashmap from its contents.
|
||||||
|
* This does not `free` the data structure itself!
|
||||||
|
* @param map The map to empty
|
||||||
|
*/
|
||||||
|
void hash_EmptyMap(HashMap map);
|
||||||
|
|
||||||
|
#endif /* RGBDS_LINK_HASHMAP_H */
|
||||||
@@ -0,0 +1,91 @@
|
|||||||
|
/*
|
||||||
|
* This file is part of RGBDS.
|
||||||
|
*
|
||||||
|
* Copyright (c) 2014-2020, RGBDS contributors.
|
||||||
|
*
|
||||||
|
* SPDX-License-Identifier: MIT
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef HELPERS_H
|
||||||
|
#define HELPERS_H
|
||||||
|
|
||||||
|
// Of course, MSVC does not support C11, so no _Noreturn there...
|
||||||
|
#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) \
|
||||||
|
__attribute__ ((format (archetype, str_index, first_arg)))
|
||||||
|
// 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
|
||||||
|
// Unsupported, but no need to throw a fit
|
||||||
|
#define format_(archetype, str_index, first_arg)
|
||||||
|
// This seems to generate similar code to __builtin_unreachable, despite different semantics
|
||||||
|
// Note that executing this is undefined behavior (declared _Noreturn, but does return)
|
||||||
|
static inline _Noreturn unreachable_(void) {}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
// Use builtins whenever possible, and shim them otherwise
|
||||||
|
#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
|
||||||
|
// FIXME: these are rarely used, and need testing...
|
||||||
|
#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
|
||||||
|
|
||||||
|
// Macros for stringification
|
||||||
|
#define STR(x) #x
|
||||||
|
#define EXPAND_AND_STR(x) STR(x)
|
||||||
|
|
||||||
|
#endif /* HELPERS_H */
|
||||||
+20
-43
@@ -1,50 +1,27 @@
|
|||||||
|
/*
|
||||||
|
* This file is part of RGBDS.
|
||||||
|
*
|
||||||
|
* Copyright (c) 1997-2019, Carsten Sorensen and RGBDS contributors.
|
||||||
|
*
|
||||||
|
* SPDX-License-Identifier: MIT
|
||||||
|
*/
|
||||||
|
|
||||||
|
/* Assigning all sections a place */
|
||||||
#ifndef RGBDS_LINK_ASSIGN_H
|
#ifndef RGBDS_LINK_ASSIGN_H
|
||||||
#define RGBDS_LINK_ASSIGN_H
|
#define RGBDS_LINK_ASSIGN_H
|
||||||
|
|
||||||
#include "mylink.h"
|
#include <stdint.h>
|
||||||
#include "types.h"
|
|
||||||
|
|
||||||
enum eBankCount {
|
extern uint64_t nbSectionsToAssign;
|
||||||
BANK_COUNT_ROM0 = 1,
|
|
||||||
BANK_COUNT_ROMX = 511,
|
|
||||||
BANK_COUNT_WRAM0 = 1,
|
|
||||||
BANK_COUNT_WRAMX = 7,
|
|
||||||
BANK_COUNT_VRAM = 2,
|
|
||||||
BANK_COUNT_OAM = 1,
|
|
||||||
BANK_COUNT_HRAM = 1,
|
|
||||||
BANK_COUNT_SRAM = 16
|
|
||||||
};
|
|
||||||
|
|
||||||
enum eBankDefine {
|
/**
|
||||||
BANK_ROM0 = 0,
|
* Assigns all sections a slice of the address space
|
||||||
BANK_ROMX = BANK_ROM0 + BANK_COUNT_ROM0,
|
*/
|
||||||
BANK_WRAM0 = BANK_ROMX + BANK_COUNT_ROMX,
|
void assign_AssignSections(void);
|
||||||
BANK_WRAMX = BANK_WRAM0 + BANK_COUNT_WRAM0,
|
|
||||||
BANK_VRAM = BANK_WRAMX + BANK_COUNT_WRAMX,
|
|
||||||
BANK_OAM = BANK_VRAM + BANK_COUNT_VRAM,
|
|
||||||
BANK_HRAM = BANK_OAM + BANK_COUNT_OAM,
|
|
||||||
BANK_SRAM = BANK_HRAM + BANK_COUNT_HRAM
|
|
||||||
};
|
|
||||||
|
|
||||||
#define MAXBANKS (BANK_COUNT_ROM0 + BANK_COUNT_ROMX + BANK_COUNT_WRAM0 + BANK_COUNT_WRAMX \
|
/**
|
||||||
+ BANK_COUNT_VRAM + BANK_COUNT_OAM + BANK_COUNT_HRAM + BANK_COUNT_SRAM)
|
* `free`s all assignment memory that was allocated.
|
||||||
|
*/
|
||||||
|
void assign_Cleanup(void);
|
||||||
|
|
||||||
extern SLONG area_Avail(SLONG bank);
|
#endif /* RGBDS_LINK_ASSIGN_H */
|
||||||
extern void AssignSections(void);
|
|
||||||
extern void CreateSymbolTable(void);
|
|
||||||
extern SLONG MaxBankUsed;
|
|
||||||
extern SLONG MaxAvail[MAXBANKS];
|
|
||||||
|
|
||||||
int
|
|
||||||
IsSectionNameInUse(const char *name);
|
|
||||||
|
|
||||||
void
|
|
||||||
SetLinkerscriptName(char *tzLinkerscriptFile);
|
|
||||||
|
|
||||||
int
|
|
||||||
IsSectionSameTypeBankAndFloating(const char *name, enum eSectionType type, int bank);
|
|
||||||
|
|
||||||
unsigned int
|
|
||||||
AssignSectionAddressAndBankByName(const char *name, unsigned int address, int bank);
|
|
||||||
|
|
||||||
#endif
|
|
||||||
|
|||||||
@@ -1,6 +0,0 @@
|
|||||||
#ifndef RGBDS_LINK_LIBRARY_H
|
|
||||||
#define RGBDS_LINK_LIBRARY_H
|
|
||||||
|
|
||||||
extern void AddNeededModules(void);
|
|
||||||
|
|
||||||
#endif
|
|
||||||
+81
-4
@@ -1,9 +1,86 @@
|
|||||||
|
/*
|
||||||
|
* This file is part of RGBDS.
|
||||||
|
*
|
||||||
|
* Copyright (c) 1997-2019, Carsten Sorensen and RGBDS contributors.
|
||||||
|
*
|
||||||
|
* SPDX-License-Identifier: MIT
|
||||||
|
*/
|
||||||
|
|
||||||
|
/* Declarations that all modules use, as well as `main` and related */
|
||||||
#ifndef RGBDS_LINK_MAIN_H
|
#ifndef RGBDS_LINK_MAIN_H
|
||||||
#define RGBDS_LINK_MAIN_H
|
#define RGBDS_LINK_MAIN_H
|
||||||
|
|
||||||
#include "types.h"
|
#include <stdint.h>
|
||||||
|
#include <stdbool.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
|
||||||
extern SLONG fillchar;
|
#include "helpers.h"
|
||||||
extern char *smartlinkstartsymbol;
|
|
||||||
|
|
||||||
#endif
|
/* Variables related to CLI options */
|
||||||
|
extern bool isDmgMode;
|
||||||
|
extern char *linkerScriptName;
|
||||||
|
extern char const *mapFileName;
|
||||||
|
extern char const *symFileName;
|
||||||
|
extern char const *overlayFileName;
|
||||||
|
extern char const *outputFileName;
|
||||||
|
extern uint8_t padValue;
|
||||||
|
extern bool is32kMode;
|
||||||
|
extern bool beVerbose;
|
||||||
|
extern bool isWRA0Mode;
|
||||||
|
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 */
|
||||||
|
#define verbosePrint(...) do { \
|
||||||
|
if (beVerbose) \
|
||||||
|
fprintf(stderr, __VA_ARGS__); \
|
||||||
|
} while (0)
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Dump a file stack to stderr
|
||||||
|
* @param node The leaf node to dump the context of
|
||||||
|
*/
|
||||||
|
char const *dumpFileStack(struct FileStackNode const *node);
|
||||||
|
|
||||||
|
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.
|
||||||
|
* @param fileName The name of the file to open; if NULL, no file will be opened
|
||||||
|
* @param mode The mode to open the file with
|
||||||
|
* @return A pointer to a valid FILE structure, or NULL if fileName was NULL
|
||||||
|
*/
|
||||||
|
FILE *openFile(char const *fileName, char const *mode);
|
||||||
|
|
||||||
|
#define closeFile(file) do { \
|
||||||
|
FILE *tmp = file; \
|
||||||
|
if (tmp) \
|
||||||
|
fclose(tmp); \
|
||||||
|
} while (0)
|
||||||
|
|
||||||
|
#endif /* RGBDS_LINK_MAIN_H */
|
||||||
|
|||||||
@@ -1,11 +0,0 @@
|
|||||||
#ifndef RGBDS_LINK_MAPFILE_H
|
|
||||||
#define RGBDS_LINK_MAPFILE_H
|
|
||||||
|
|
||||||
extern void SetMapfileName(char *name);
|
|
||||||
extern void SetSymfileName(char *name);
|
|
||||||
extern void CloseMapfile(void);
|
|
||||||
extern void MapfileWriteSection(struct sSection * pSect);
|
|
||||||
extern void MapfileInitBank(SLONG bank);
|
|
||||||
extern void MapfileCloseBank(SLONG slack);
|
|
||||||
|
|
||||||
#endif
|
|
||||||
@@ -1,114 +0,0 @@
|
|||||||
#ifndef RGBDS_LINK_LINK_H
|
|
||||||
#define RGBDS_LINK_LINK_H
|
|
||||||
|
|
||||||
#ifndef _MAX_PATH
|
|
||||||
#define _MAX_PATH 512
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#include "types.h"
|
|
||||||
|
|
||||||
extern SLONG options;
|
|
||||||
#define OPT_TINY 0x01
|
|
||||||
#define OPT_SMART_C_LINK 0x02
|
|
||||||
#define OPT_OVERLAY 0x04
|
|
||||||
#define OPT_CONTWRAM 0x08
|
|
||||||
#define OPT_DMG_MODE 0x10
|
|
||||||
|
|
||||||
enum eRpnData {
|
|
||||||
RPN_ADD = 0,
|
|
||||||
RPN_SUB,
|
|
||||||
RPN_MUL,
|
|
||||||
RPN_DIV,
|
|
||||||
RPN_MOD,
|
|
||||||
RPN_UNSUB,
|
|
||||||
|
|
||||||
RPN_OR,
|
|
||||||
RPN_AND,
|
|
||||||
RPN_XOR,
|
|
||||||
RPN_UNNOT,
|
|
||||||
|
|
||||||
RPN_LOGAND,
|
|
||||||
RPN_LOGOR,
|
|
||||||
RPN_LOGUNNOT,
|
|
||||||
|
|
||||||
RPN_LOGEQ,
|
|
||||||
RPN_LOGNE,
|
|
||||||
RPN_LOGGT,
|
|
||||||
RPN_LOGLT,
|
|
||||||
RPN_LOGGE,
|
|
||||||
RPN_LOGLE,
|
|
||||||
|
|
||||||
RPN_SHL,
|
|
||||||
RPN_SHR,
|
|
||||||
|
|
||||||
RPN_BANK,
|
|
||||||
|
|
||||||
RPN_HRAM,
|
|
||||||
|
|
||||||
RPN_CONST = 0x80,
|
|
||||||
RPN_SYM = 0x81
|
|
||||||
};
|
|
||||||
|
|
||||||
enum eSectionType {
|
|
||||||
SECT_WRAM0,
|
|
||||||
SECT_VRAM,
|
|
||||||
SECT_ROMX,
|
|
||||||
SECT_ROM0,
|
|
||||||
SECT_HRAM,
|
|
||||||
SECT_WRAMX,
|
|
||||||
SECT_SRAM,
|
|
||||||
SECT_OAM
|
|
||||||
};
|
|
||||||
|
|
||||||
struct sSection {
|
|
||||||
SLONG nBank;
|
|
||||||
SLONG nOrg;
|
|
||||||
SLONG nAlign;
|
|
||||||
BBOOL oAssigned;
|
|
||||||
|
|
||||||
char *pzName;
|
|
||||||
SLONG nByteSize;
|
|
||||||
enum eSectionType Type;
|
|
||||||
UBYTE *pData;
|
|
||||||
SLONG nNumberOfSymbols;
|
|
||||||
struct sSymbol **tSymbols;
|
|
||||||
struct sPatch *pPatches;
|
|
||||||
struct sSection *pNext;
|
|
||||||
};
|
|
||||||
|
|
||||||
enum eSymbolType {
|
|
||||||
SYM_LOCAL,
|
|
||||||
SYM_IMPORT,
|
|
||||||
SYM_EXPORT
|
|
||||||
};
|
|
||||||
|
|
||||||
struct sSymbol {
|
|
||||||
char *pzName;
|
|
||||||
enum eSymbolType Type;
|
|
||||||
/* the following 3 items only valid when Type!=SYM_IMPORT */
|
|
||||||
SLONG nSectionID; /* internal to object.c */
|
|
||||||
struct sSection *pSection;
|
|
||||||
SLONG nOffset;
|
|
||||||
};
|
|
||||||
|
|
||||||
enum ePatchType {
|
|
||||||
PATCH_BYTE = 0,
|
|
||||||
PATCH_WORD_L,
|
|
||||||
PATCH_LONG_L
|
|
||||||
};
|
|
||||||
|
|
||||||
struct sPatch {
|
|
||||||
char *pzFilename;
|
|
||||||
SLONG nLineNo;
|
|
||||||
SLONG nOffset;
|
|
||||||
enum ePatchType Type;
|
|
||||||
SLONG nRPNSize;
|
|
||||||
UBYTE *pRPN;
|
|
||||||
struct sPatch *pNext;
|
|
||||||
BBOOL oRelocPatch;
|
|
||||||
};
|
|
||||||
|
|
||||||
extern struct sSection *pSections;
|
|
||||||
extern struct sSection *pLibSections;
|
|
||||||
|
|
||||||
#endif
|
|
||||||
+40
-4
@@ -1,6 +1,42 @@
|
|||||||
#ifndef RGBDS_LINK_OBJECT_H
|
/*
|
||||||
#define RGBDS_LINK_OBJECT_H
|
* This file is part of RGBDS.
|
||||||
|
*
|
||||||
|
* Copyright (c) 1997-2019, Carsten Sorensen and RGBDS contributors.
|
||||||
|
*
|
||||||
|
* SPDX-License-Identifier: MIT
|
||||||
|
*/
|
||||||
|
|
||||||
extern void obj_Readfile(char *tzObjectfile);
|
/* Declarations related to processing of object (.o) files */
|
||||||
|
|
||||||
#endif
|
#ifndef RGBDS_LINK_OBJECT_H
|
||||||
|
#define RGBDS_LINK_OBJECT_H
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 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 i The ID of the file
|
||||||
|
*/
|
||||||
|
void obj_ReadFile(char const *fileName, unsigned int i);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Perform validation on the object files' contents
|
||||||
|
*/
|
||||||
|
void obj_DoSanityChecks(void);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Evaluate all assertions
|
||||||
|
*/
|
||||||
|
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.
|
||||||
|
*/
|
||||||
|
void obj_Cleanup(void);
|
||||||
|
|
||||||
|
#endif /* RGBDS_LINK_OBJECT_H */
|
||||||
|
|||||||
+33
-6
@@ -1,8 +1,35 @@
|
|||||||
#ifndef RGBDS_LINK_OUTPUT_H
|
/*
|
||||||
#define RGBDS_LINK_OUTPUT_H
|
* This file is part of RGBDS.
|
||||||
|
*
|
||||||
|
* Copyright (c) 1997-2019, Carsten Sorensen and RGBDS contributors.
|
||||||
|
*
|
||||||
|
* SPDX-License-Identifier: MIT
|
||||||
|
*/
|
||||||
|
|
||||||
void out_Setname(char *tzOutputfile);
|
/* Outputting the result of linking */
|
||||||
void out_SetOverlayname(char *tzOverlayfile);
|
#ifndef RGBDS_LINK_OUTPUT_H
|
||||||
void Output(void);
|
#define RGBDS_LINK_OUTPUT_H
|
||||||
|
|
||||||
#endif
|
#include <stdint.h>
|
||||||
|
|
||||||
|
#include "link/section.h"
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Registers a section for output.
|
||||||
|
* @param section The section to add
|
||||||
|
*/
|
||||||
|
void out_AddSection(struct Section const *section);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Finds an assigned section overlapping another one.
|
||||||
|
* @param section The section that is being overlapped
|
||||||
|
* @return A section overlapping it
|
||||||
|
*/
|
||||||
|
struct Section const *out_OverlappingSection(struct Section const *section);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Writes all output (bin, sym, map) files.
|
||||||
|
*/
|
||||||
|
void out_WriteFiles(void);
|
||||||
|
|
||||||
|
#endif /* RGBDS_LINK_OUTPUT_H */
|
||||||
|
|||||||
+39
-4
@@ -1,9 +1,44 @@
|
|||||||
|
/*
|
||||||
|
* This file is part of RGBDS.
|
||||||
|
*
|
||||||
|
* Copyright (c) 1997-2019, Carsten Sorensen and RGBDS contributors.
|
||||||
|
*
|
||||||
|
* SPDX-License-Identifier: MIT
|
||||||
|
*/
|
||||||
|
|
||||||
|
/* Applying patches to SECTIONs */
|
||||||
#ifndef RGBDS_LINK_PATCH_H
|
#ifndef RGBDS_LINK_PATCH_H
|
||||||
#define RGBDS_LINK_PATCH_H
|
#define RGBDS_LINK_PATCH_H
|
||||||
|
|
||||||
#include "types.h"
|
#include <stdbool.h>
|
||||||
|
#include <stdint.h>
|
||||||
|
|
||||||
void Patch(void);
|
#include "link/section.h"
|
||||||
extern SLONG nPC;
|
|
||||||
|
|
||||||
#endif
|
#include "linkdefs.h"
|
||||||
|
|
||||||
|
struct Assertion {
|
||||||
|
struct Patch patch;
|
||||||
|
// enum AssertionType type; The `patch`'s field is instead re-used
|
||||||
|
char *message;
|
||||||
|
/*
|
||||||
|
* This would be redundant with `.section->fileSymbols`... but
|
||||||
|
* `section` is sometimes NULL!
|
||||||
|
*/
|
||||||
|
struct Symbol **fileSymbols;
|
||||||
|
|
||||||
|
struct Assertion *next;
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Checks all assertions
|
||||||
|
* @return true if assertion failed
|
||||||
|
*/
|
||||||
|
void patch_CheckAssertions(struct Assertion *assertion);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Applies all SECTIONs' patches to them
|
||||||
|
*/
|
||||||
|
void patch_ApplyPatches(void);
|
||||||
|
|
||||||
|
#endif /* RGBDS_LINK_PATCH_H */
|
||||||
|
|||||||
+22
-23
@@ -1,37 +1,36 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (C) 2017 Antonio Nino Diaz <antonio_nd@outlook.com>
|
* This file is part of RGBDS.
|
||||||
*
|
*
|
||||||
* Permission to use, copy, modify, and distribute this software for any
|
* Copyright (c) 1997-2019, Carsten Sorensen and RGBDS contributors.
|
||||||
* purpose with or without fee is hereby granted, provided that the above
|
|
||||||
* copyright notice and this permission notice appear in all copies.
|
|
||||||
*
|
*
|
||||||
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
* SPDX-License-Identifier: MIT
|
||||||
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
|
||||||
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
|
||||||
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
|
||||||
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
|
||||||
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
|
||||||
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
/* Parsing a linker script */
|
||||||
#ifndef RGBDS_LINK_SCRIPT_H
|
#ifndef RGBDS_LINK_SCRIPT_H
|
||||||
#define RGBDS_LINK_SCRIPT_H
|
#define RGBDS_LINK_SCRIPT_H
|
||||||
|
|
||||||
#include "extern/stdnoreturn.h"
|
#include <stdint.h>
|
||||||
|
|
||||||
noreturn void script_fatalerror(const char *fmt, ...);
|
extern FILE * linkerScript;
|
||||||
|
|
||||||
void script_Parse(const char *path);
|
struct SectionPlacement {
|
||||||
|
struct Section *section;
|
||||||
|
uint16_t org;
|
||||||
|
uint32_t bank;
|
||||||
|
};
|
||||||
|
|
||||||
void script_IncludeFile(const char *path);
|
extern uint64_t script_lineNo;
|
||||||
int script_IncludeDepthGet(void);
|
|
||||||
void script_IncludePop(void);
|
|
||||||
|
|
||||||
void script_InitSections(void);
|
/**
|
||||||
void script_SetCurrentSectionType(const char *type, unsigned int bank);
|
* Parses the linker script to return the next section constraint
|
||||||
void script_SetAddress(unsigned int addr);
|
* @return A pointer to a struct, or NULL on EOF. The pointer shouldn't be freed
|
||||||
void script_SetAlignment(unsigned int alignment);
|
*/
|
||||||
void script_OutputSection(const char *section_name);
|
struct SectionPlacement *script_NextSection(void);
|
||||||
|
|
||||||
#endif
|
/**
|
||||||
|
* `free`s all assignment memory that was allocated.
|
||||||
|
*/
|
||||||
|
void script_Cleanup(void);
|
||||||
|
|
||||||
|
#endif /* RGBDS_LINK_SCRIPT_H */
|
||||||
|
|||||||
@@ -0,0 +1,100 @@
|
|||||||
|
/*
|
||||||
|
* This file is part of RGBDS.
|
||||||
|
*
|
||||||
|
* Copyright (c) 1997-2019, Carsten Sorensen and RGBDS contributors.
|
||||||
|
*
|
||||||
|
* SPDX-License-Identifier: MIT
|
||||||
|
*/
|
||||||
|
|
||||||
|
/* Declarations manipulating symbols */
|
||||||
|
#ifndef RGBDS_LINK_SECTION_H
|
||||||
|
#define RGBDS_LINK_SECTION_H
|
||||||
|
|
||||||
|
/* GUIDELINE: external code MUST NOT BE AWARE of the data structure used!! */
|
||||||
|
|
||||||
|
#include <stdint.h>
|
||||||
|
#include <stdbool.h>
|
||||||
|
|
||||||
|
#include "link/main.h"
|
||||||
|
|
||||||
|
#include "linkdefs.h"
|
||||||
|
|
||||||
|
struct FileStackNode;
|
||||||
|
struct Section;
|
||||||
|
|
||||||
|
struct AttachedSymbol {
|
||||||
|
struct Symbol *symbol;
|
||||||
|
struct AttachedSymbol *next;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct Patch {
|
||||||
|
struct FileStackNode const *src;
|
||||||
|
uint32_t lineNo;
|
||||||
|
uint32_t offset;
|
||||||
|
uint32_t pcSectionID;
|
||||||
|
uint32_t pcOffset;
|
||||||
|
enum PatchType type;
|
||||||
|
uint32_t rpnSize;
|
||||||
|
uint8_t *rpnExpression;
|
||||||
|
|
||||||
|
struct Section const *pcSection;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct Section {
|
||||||
|
/* Info contained in the object files */
|
||||||
|
char *name;
|
||||||
|
uint16_t size;
|
||||||
|
uint16_t offset;
|
||||||
|
enum SectionType type;
|
||||||
|
enum SectionModifier modifier;
|
||||||
|
bool isAddressFixed;
|
||||||
|
uint16_t org;
|
||||||
|
bool isBankFixed;
|
||||||
|
uint32_t bank;
|
||||||
|
bool isAlignFixed;
|
||||||
|
uint16_t alignMask;
|
||||||
|
uint16_t alignOfs;
|
||||||
|
uint8_t *data; /* Array of size `size`*/
|
||||||
|
uint32_t nbPatches;
|
||||||
|
struct Patch *patches;
|
||||||
|
/* Extra info computed during linking */
|
||||||
|
struct Symbol **fileSymbols;
|
||||||
|
uint32_t nbSymbols;
|
||||||
|
struct Symbol const **symbols;
|
||||||
|
struct Section *nextu; /* The next "component" of this unionized sect */
|
||||||
|
};
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Execute a callback for each section currently registered.
|
||||||
|
* This is to avoid exposing the data structure in which sections are stored.
|
||||||
|
* @param callback The function to call for each structure;
|
||||||
|
* the first argument will be a pointer to the structure,
|
||||||
|
* the second argument will be the pointer `arg`.
|
||||||
|
* @param arg A pointer which will be passed to all calls to `callback`.
|
||||||
|
*/
|
||||||
|
void sect_ForEach(void (*callback)(struct Section *, void *), void *arg);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Registers a section to be processed.
|
||||||
|
* @param section The section to register.
|
||||||
|
*/
|
||||||
|
void sect_AddSection(struct Section *section);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Finds a section by its name.
|
||||||
|
* @param name The name of the section to look for
|
||||||
|
* @return A pointer to the section, or NULL if it wasn't found
|
||||||
|
*/
|
||||||
|
struct Section *sect_GetSection(char const *name);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* `free`s all section memory that was allocated.
|
||||||
|
*/
|
||||||
|
void sect_CleanupSections(void);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Checks if all sections meet reasonable criteria, such as max size
|
||||||
|
*/
|
||||||
|
void sect_DoSanityChecks(void);
|
||||||
|
|
||||||
|
#endif /* RGBDS_LINK_SECTION_H */
|
||||||
+56
-6
@@ -1,11 +1,61 @@
|
|||||||
|
/*
|
||||||
|
* This file is part of RGBDS.
|
||||||
|
*
|
||||||
|
* Copyright (c) 1997-2019, Carsten Sorensen and RGBDS contributors.
|
||||||
|
*
|
||||||
|
* SPDX-License-Identifier: MIT
|
||||||
|
*/
|
||||||
|
|
||||||
|
/* Declarations manipulating symbols */
|
||||||
#ifndef RGBDS_LINK_SYMBOL_H
|
#ifndef RGBDS_LINK_SYMBOL_H
|
||||||
#define RGBDS_LINK_SYMBOL_H
|
#define RGBDS_LINK_SYMBOL_H
|
||||||
|
|
||||||
#include "types.h"
|
/* GUIDELINE: external code MUST NOT BE AWARE of the data structure used!! */
|
||||||
|
|
||||||
void sym_Init(void);
|
#include <stdint.h>
|
||||||
void sym_CreateSymbol(char *tzName, SLONG nValue, SLONG nBank);
|
|
||||||
SLONG sym_GetValue(char *tzName);
|
|
||||||
SLONG sym_GetBank(char *tzName);
|
|
||||||
|
|
||||||
#endif
|
#include "linkdefs.h"
|
||||||
|
|
||||||
|
struct FileStackNode;
|
||||||
|
|
||||||
|
struct Symbol {
|
||||||
|
/* Info contained in the object files */
|
||||||
|
char *name;
|
||||||
|
enum ExportLevel type;
|
||||||
|
char const *objFileName;
|
||||||
|
struct FileStackNode const *src;
|
||||||
|
int32_t lineNo;
|
||||||
|
int32_t sectionID;
|
||||||
|
union {
|
||||||
|
int32_t offset;
|
||||||
|
int32_t value;
|
||||||
|
};
|
||||||
|
/* Extra info computed during linking */
|
||||||
|
struct Section *section;
|
||||||
|
};
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Execute a callback for each symbol currently registered.
|
||||||
|
* This is done to avoid exposing the data structure in which symbol are stored.
|
||||||
|
* @param callback The function to call for each symbol;
|
||||||
|
* the first argument will be a pointer to the symbol,
|
||||||
|
* the second argument will be the pointer `arg`.
|
||||||
|
* @param arg A pointer which will be passed to all calls to `callback`.
|
||||||
|
*/
|
||||||
|
void sym_ForEach(void (*callback)(struct Symbol *, void *), void *arg);
|
||||||
|
|
||||||
|
void sym_AddSymbol(struct Symbol *symbol);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Finds a symbol in all the defined symbols.
|
||||||
|
* @param name The name of the symbol to look for
|
||||||
|
* @return A pointer to the symbol, or NULL if not found.
|
||||||
|
*/
|
||||||
|
struct Symbol *sym_GetSymbol(char const *name);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* `free`s all symbol memory that was allocated.
|
||||||
|
*/
|
||||||
|
void sym_CleanupSymbols(void);
|
||||||
|
|
||||||
|
#endif /* RGBDS_LINK_SYMBOL_H */
|
||||||
|
|||||||
@@ -0,0 +1,152 @@
|
|||||||
|
/*
|
||||||
|
* This file is part of RGBDS.
|
||||||
|
*
|
||||||
|
* Copyright (c) 1997-2018, Carsten Sorensen and RGBDS contributors.
|
||||||
|
*
|
||||||
|
* SPDX-License-Identifier: MIT
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef RGBDS_LINKDEFS_H
|
||||||
|
#define RGBDS_LINKDEFS_H
|
||||||
|
|
||||||
|
#include <stdbool.h>
|
||||||
|
#include <stdint.h>
|
||||||
|
|
||||||
|
#define RGBDS_OBJECT_VERSION_STRING "RGB%1u"
|
||||||
|
#define RGBDS_OBJECT_VERSION_NUMBER 9U
|
||||||
|
#define RGBDS_OBJECT_REV 7U
|
||||||
|
|
||||||
|
enum AssertionType {
|
||||||
|
ASSERT_WARN,
|
||||||
|
ASSERT_ERROR,
|
||||||
|
ASSERT_FATAL
|
||||||
|
};
|
||||||
|
|
||||||
|
enum RPNCommand {
|
||||||
|
RPN_ADD = 0x00,
|
||||||
|
RPN_SUB = 0x01,
|
||||||
|
RPN_MUL = 0x02,
|
||||||
|
RPN_DIV = 0x03,
|
||||||
|
RPN_MOD = 0x04,
|
||||||
|
RPN_UNSUB = 0x05,
|
||||||
|
RPN_EXP = 0x06,
|
||||||
|
|
||||||
|
RPN_OR = 0x10,
|
||||||
|
RPN_AND = 0x11,
|
||||||
|
RPN_XOR = 0x12,
|
||||||
|
RPN_UNNOT = 0x13,
|
||||||
|
|
||||||
|
RPN_LOGAND = 0x21,
|
||||||
|
RPN_LOGOR = 0x22,
|
||||||
|
RPN_LOGUNNOT = 0x23,
|
||||||
|
|
||||||
|
RPN_LOGEQ = 0x30,
|
||||||
|
RPN_LOGNE = 0x31,
|
||||||
|
RPN_LOGGT = 0x32,
|
||||||
|
RPN_LOGLT = 0x33,
|
||||||
|
RPN_LOGGE = 0x34,
|
||||||
|
RPN_LOGLE = 0x35,
|
||||||
|
|
||||||
|
RPN_SHL = 0x40,
|
||||||
|
RPN_SHR = 0x41,
|
||||||
|
|
||||||
|
RPN_BANK_SYM = 0x50,
|
||||||
|
RPN_BANK_SECT = 0x51,
|
||||||
|
RPN_BANK_SELF = 0x52,
|
||||||
|
|
||||||
|
RPN_HRAM = 0x60,
|
||||||
|
RPN_RST = 0x61,
|
||||||
|
|
||||||
|
RPN_CONST = 0x80,
|
||||||
|
RPN_SYM = 0x81
|
||||||
|
};
|
||||||
|
|
||||||
|
enum SectionType {
|
||||||
|
SECTTYPE_WRAM0,
|
||||||
|
SECTTYPE_VRAM,
|
||||||
|
SECTTYPE_ROMX,
|
||||||
|
SECTTYPE_ROM0,
|
||||||
|
SECTTYPE_HRAM,
|
||||||
|
SECTTYPE_WRAMX,
|
||||||
|
SECTTYPE_SRAM,
|
||||||
|
SECTTYPE_OAM,
|
||||||
|
|
||||||
|
SECTTYPE_INVALID
|
||||||
|
};
|
||||||
|
|
||||||
|
enum SectionModifier {
|
||||||
|
SECTION_NORMAL,
|
||||||
|
SECTION_UNION,
|
||||||
|
SECTION_FRAGMENT
|
||||||
|
};
|
||||||
|
|
||||||
|
extern char const * const sectionModNames[];
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Tells whether a section has data in its object file definition,
|
||||||
|
* depending on type.
|
||||||
|
* @param type The section's type
|
||||||
|
* @return `true` if the section's definition includes data
|
||||||
|
*/
|
||||||
|
static inline bool sect_HasData(enum SectionType type)
|
||||||
|
{
|
||||||
|
return type == SECTTYPE_ROM0 || type == SECTTYPE_ROMX;
|
||||||
|
}
|
||||||
|
|
||||||
|
enum ExportLevel {
|
||||||
|
SYMTYPE_LOCAL,
|
||||||
|
SYMTYPE_IMPORT,
|
||||||
|
SYMTYPE_EXPORT
|
||||||
|
};
|
||||||
|
|
||||||
|
enum PatchType {
|
||||||
|
PATCHTYPE_BYTE,
|
||||||
|
PATCHTYPE_WORD,
|
||||||
|
PATCHTYPE_LONG,
|
||||||
|
PATCHTYPE_JR,
|
||||||
|
|
||||||
|
PATCHTYPE_INVALID
|
||||||
|
};
|
||||||
|
|
||||||
|
#define BANK_MIN_ROM0 0
|
||||||
|
#define BANK_MAX_ROM0 0
|
||||||
|
#define BANK_MIN_ROMX 1
|
||||||
|
#define BANK_MAX_ROMX 511
|
||||||
|
#define BANK_MIN_VRAM 0
|
||||||
|
#define BANK_MAX_VRAM 1
|
||||||
|
#define BANK_MIN_SRAM 0
|
||||||
|
#define BANK_MAX_SRAM 15
|
||||||
|
#define BANK_MIN_WRAM0 0
|
||||||
|
#define BANK_MAX_WRAM0 0
|
||||||
|
#define BANK_MIN_WRAMX 1
|
||||||
|
#define BANK_MAX_WRAMX 7
|
||||||
|
#define BANK_MIN_OAM 0
|
||||||
|
#define BANK_MAX_OAM 0
|
||||||
|
#define BANK_MIN_HRAM 0
|
||||||
|
#define BANK_MAX_HRAM 0
|
||||||
|
|
||||||
|
extern uint16_t startaddr[];
|
||||||
|
extern uint16_t maxsize[];
|
||||||
|
extern uint32_t bankranges[][2];
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Computes a memory region's end address (last byte), eg. 0x7FFF
|
||||||
|
* @return The address of the last byte in that memory region
|
||||||
|
*/
|
||||||
|
static inline uint16_t endaddr(enum SectionType type)
|
||||||
|
{
|
||||||
|
return startaddr[type] + maxsize[type] - 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Computes a memory region's number of banks
|
||||||
|
* @return The number of banks, 1 for regions without banking
|
||||||
|
*/
|
||||||
|
static inline uint32_t nbbanks(enum SectionType type)
|
||||||
|
{
|
||||||
|
return bankranges[type][1] - bankranges[type][0] + 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
extern char const * const typeNames[SECTTYPE_INVALID];
|
||||||
|
|
||||||
|
#endif /* RGBDS_LINKDEFS_H */
|
||||||
@@ -0,0 +1,20 @@
|
|||||||
|
/*
|
||||||
|
* 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);
|
||||||
|
|
||||||
|
#endif /* RGBDS_OP_MATH_H */
|
||||||
@@ -0,0 +1,73 @@
|
|||||||
|
/*
|
||||||
|
* This file is part of RGBDS.
|
||||||
|
*
|
||||||
|
* Copyright (c) 2020 RGBDS contributors.
|
||||||
|
*
|
||||||
|
* SPDX-License-Identifier: MIT
|
||||||
|
*/
|
||||||
|
|
||||||
|
/* platform-specific hacks */
|
||||||
|
|
||||||
|
#ifndef RGBDS_PLATFORM_H
|
||||||
|
#define RGBDS_PLATFORM_H
|
||||||
|
|
||||||
|
/* MSVC doesn't have strncasecmp, use a suitable replacement */
|
||||||
|
#ifdef _MSC_VER
|
||||||
|
# include <string.h>
|
||||||
|
# define strncasecmp _strnicmp
|
||||||
|
#else
|
||||||
|
# include <strings.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/* MSVC has deprecated strdup in favor of _strdup */
|
||||||
|
#ifdef _MSC_VER
|
||||||
|
# define strdup _strdup
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/* MSVC prefixes the names of S_* macros with underscores,
|
||||||
|
and doesn't define any S_IS* macros. Define them ourselves */
|
||||||
|
#ifdef _MSC_VER
|
||||||
|
# define S_IFMT _S_IFMT
|
||||||
|
# define S_IFDIR _S_IFDIR
|
||||||
|
# define S_ISDIR(mode) (((mode) & S_IFMT) == S_IFDIR)
|
||||||
|
#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)
|
||||||
|
#else
|
||||||
|
# define MIN_NB_ELMS(N) static (N)
|
||||||
|
#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 */
|
||||||
+10
-10
@@ -1,16 +1,16 @@
|
|||||||
|
/*
|
||||||
|
* This file is part of RGBDS.
|
||||||
|
*
|
||||||
|
* Copyright (c) 1997-2018, Carsten Sorensen and RGBDS contributors.
|
||||||
|
*
|
||||||
|
* SPDX-License-Identifier: MIT
|
||||||
|
*/
|
||||||
|
|
||||||
#ifndef RGBDS_TYPES_H
|
#ifndef RGBDS_TYPES_H
|
||||||
#define RGBDS_TYPES_H
|
#define RGBDS_TYPES_H
|
||||||
|
|
||||||
#ifndef _MAX_PATH
|
#ifndef _MAX_PATH
|
||||||
#define _MAX_PATH 512
|
#define _MAX_PATH 512
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
typedef unsigned char UBYTE;
|
#endif /* RGBDS_TYPES_H */
|
||||||
typedef signed char SBYTE;
|
|
||||||
typedef unsigned short UWORD;
|
|
||||||
typedef signed short SWORD;
|
|
||||||
typedef unsigned long ULONG;
|
|
||||||
typedef signed long SLONG;
|
|
||||||
typedef signed char BBOOL;
|
|
||||||
|
|
||||||
#endif
|
|
||||||
|
|||||||
@@ -0,0 +1,19 @@
|
|||||||
|
/*
|
||||||
|
* This file is part of RGBDS.
|
||||||
|
*
|
||||||
|
* Copyright (c) 2017-2021, Antonio Nino Diaz and RGBDS contributors.
|
||||||
|
*
|
||||||
|
* SPDX-License-Identifier: MIT
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef EXTERN_VERSION_H
|
||||||
|
#define EXTERN_VERSION_H
|
||||||
|
|
||||||
|
#define PACKAGE_VERSION_MAJOR 0
|
||||||
|
#define PACKAGE_VERSION_MINOR 5
|
||||||
|
#define PACKAGE_VERSION_PATCH 0
|
||||||
|
#define PACKAGE_VERSION_RC 2
|
||||||
|
|
||||||
|
const char *get_package_version_string(void);
|
||||||
|
|
||||||
|
#endif /* EXTERN_VERSION_H */
|
||||||
@@ -0,0 +1,128 @@
|
|||||||
|
#
|
||||||
|
# This file is part of RGBDS.
|
||||||
|
#
|
||||||
|
# Copyright (c) 2020 RGBDS contributors.
|
||||||
|
#
|
||||||
|
# SPDX-License-Identifier: MIT
|
||||||
|
#
|
||||||
|
|
||||||
|
set(common_src
|
||||||
|
"extern/err.c"
|
||||||
|
"extern/getopt.c"
|
||||||
|
"version.c"
|
||||||
|
)
|
||||||
|
|
||||||
|
find_package(PkgConfig)
|
||||||
|
if(MSVC OR NOT PKG_CONFIG_FOUND)
|
||||||
|
# fallback to find_package
|
||||||
|
find_package(PNG REQUIRED)
|
||||||
|
else()
|
||||||
|
pkg_check_modules(LIBPNG REQUIRED libpng)
|
||||||
|
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
|
||||||
|
"${BISON_PARSER_OUTPUT_SOURCE}"
|
||||||
|
"asm/charmap.c"
|
||||||
|
"asm/fixpoint.c"
|
||||||
|
"asm/format.c"
|
||||||
|
"asm/fstack.c"
|
||||||
|
"asm/lexer.c"
|
||||||
|
"asm/macro.c"
|
||||||
|
"asm/main.c"
|
||||||
|
"asm/opt.c"
|
||||||
|
"asm/output.c"
|
||||||
|
"asm/rpn.c"
|
||||||
|
"asm/section.c"
|
||||||
|
"asm/symbol.c"
|
||||||
|
"asm/util.c"
|
||||||
|
"asm/warning.c"
|
||||||
|
"extern/utf8decoder.c"
|
||||||
|
"hashmap.c"
|
||||||
|
"linkdefs.c"
|
||||||
|
"opmath.c"
|
||||||
|
)
|
||||||
|
|
||||||
|
set(rgbfix_src
|
||||||
|
"fix/main.c"
|
||||||
|
)
|
||||||
|
|
||||||
|
set(rgbgfx_src
|
||||||
|
"gfx/gb.c"
|
||||||
|
"gfx/main.c"
|
||||||
|
"gfx/makepng.c"
|
||||||
|
)
|
||||||
|
|
||||||
|
set(rgblink_src
|
||||||
|
"link/assign.c"
|
||||||
|
"link/main.c"
|
||||||
|
"link/object.c"
|
||||||
|
"link/output.c"
|
||||||
|
"link/patch.c"
|
||||||
|
"link/script.c"
|
||||||
|
"link/section.c"
|
||||||
|
"link/symbol.c"
|
||||||
|
"hashmap.c"
|
||||||
|
"linkdefs.c"
|
||||||
|
"opmath.c"
|
||||||
|
)
|
||||||
|
|
||||||
|
foreach(PROG "asm" "fix" "gfx" "link")
|
||||||
|
add_executable(rgb${PROG}
|
||||||
|
${rgb${PROG}_src}
|
||||||
|
${common_src}
|
||||||
|
)
|
||||||
|
install(TARGETS rgb${PROG} RUNTIME DESTINATION bin)
|
||||||
|
endforeach()
|
||||||
|
|
||||||
|
set(MANDIR "share/man")
|
||||||
|
set(man1 "asm/rgbasm.1"
|
||||||
|
"fix/rgbfix.1"
|
||||||
|
"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()
|
||||||
|
target_compile_definitions(rgbgfx PRIVATE ${PNG_DEFINITIONS})
|
||||||
|
target_include_directories(rgbgfx PRIVATE ${PNG_INCLUDE_DIRS})
|
||||||
|
target_link_libraries(rgbgfx PRIVATE ${PNG_LIBRARIES})
|
||||||
|
endif()
|
||||||
|
|
||||||
|
include(CheckLibraryExists)
|
||||||
|
check_library_exists("m" "sin" "" HAS_LIBM)
|
||||||
|
if(HAS_LIBM)
|
||||||
|
target_link_libraries(rgbasm PRIVATE "m")
|
||||||
|
endif()
|
||||||
+2
-2
@@ -1,2 +1,2 @@
|
|||||||
asmy.c
|
/parser.c
|
||||||
asmy.h
|
/parser.h
|
||||||
|
|||||||
-1682
File diff suppressed because it is too large
Load Diff
+221
-193
@@ -1,218 +1,246 @@
|
|||||||
/*
|
/*
|
||||||
* UTF-8 decoder copyright © 2008–2009 Björn Höhrmann <bjoern@hoehrmann.de>
|
* This file is part of RGBDS.
|
||||||
* http://bjoern.hoehrmann.de/utf-8/decoder/dfa/
|
|
||||||
*
|
*
|
||||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
* Copyright (c) 2013-2018, stag019 and RGBDS contributors.
|
||||||
* of this software and associated documentation files (the "Software"), to
|
|
||||||
* deal in the Software without restriction, including without limitation the
|
|
||||||
* rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
|
|
||||||
* sell copies of the Software, and to permit persons to whom the Software is
|
|
||||||
* furnished to do so, subject to the following conditions:
|
|
||||||
*
|
*
|
||||||
* The above copyright notice and this permission notice shall be included in
|
* SPDX-License-Identifier: MIT
|
||||||
* all copies or substantial portions of the Software.
|
|
||||||
*
|
|
||||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
||||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
||||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
||||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
||||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
|
||||||
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
|
|
||||||
* IN THE SOFTWARE.
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#include <errno.h>
|
||||||
|
#include <stdbool.h>
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
|
|
||||||
static const uint8_t utf8d[] = {
|
|
||||||
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, // 00..1f
|
|
||||||
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, // 20..3f
|
|
||||||
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, // 40..5f
|
|
||||||
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, // 60..7f
|
|
||||||
1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9, // 80..9f
|
|
||||||
7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7, // a0..bf
|
|
||||||
8,8,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2, // c0..df
|
|
||||||
0xa,0x3,0x3,0x3,0x3,0x3,0x3,0x3,0x3,0x3,0x3,0x3,0x3,0x4,0x3,0x3, // e0..ef
|
|
||||||
0xb,0x6,0x6,0x6,0x5,0x8,0x8,0x8,0x8,0x8,0x8,0x8,0x8,0x8,0x8,0x8, // f0..ff
|
|
||||||
0x0,0x1,0x2,0x3,0x5,0x8,0x7,0x1,0x1,0x1,0x4,0x6,0x1,0x1,0x1,0x1, // s0..s0
|
|
||||||
1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,1,1,1,1,1,0,1,0,1,1,1,1,1,1, // s1..s2
|
|
||||||
1,2,1,1,1,1,1,2,1,2,1,1,1,1,1,1,1,1,1,1,1,1,1,2,1,1,1,1,1,1,1,1, // s3..s4
|
|
||||||
1,2,1,1,1,1,1,1,1,2,1,1,1,1,1,1,1,1,1,1,1,1,1,3,1,3,1,1,1,1,1,1, // s5..s6
|
|
||||||
1,3,1,1,1,1,1,3,1,3,1,1,1,1,1,1,1,3,1,1,1,1,1,1,1,1,1,1,1,1,1,1, // s7..s8
|
|
||||||
};
|
|
||||||
|
|
||||||
uint32_t
|
|
||||||
decode(uint32_t* state, uint32_t* codep, uint32_t byte) {
|
|
||||||
uint32_t type = utf8d[byte];
|
|
||||||
|
|
||||||
*codep = (*state != 0) ?
|
|
||||||
(byte & 0x3fu) | (*codep << 6) :
|
|
||||||
(0xff >> type) & (byte);
|
|
||||||
|
|
||||||
*state = utf8d[256 + *state*16 + type];
|
|
||||||
return *state;
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Copyright © 2013 stag019 <stag019@gmail.com>
|
|
||||||
*
|
|
||||||
* Permission to use, copy, modify, and distribute this software for any
|
|
||||||
* purpose with or without fee is hereby granted, provided that the above
|
|
||||||
* copyright notice and this permission notice appear in all copies.
|
|
||||||
*
|
|
||||||
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
|
||||||
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
|
||||||
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
|
||||||
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
|
||||||
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
|
||||||
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
|
||||||
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
#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"
|
||||||
|
#include "asm/util.h"
|
||||||
|
#include "asm/warning.h"
|
||||||
|
|
||||||
struct Charmap globalCharmap = {0};
|
#include "hashmap.h"
|
||||||
|
|
||||||
extern struct Section *pCurrentSection;
|
/*
|
||||||
|
* 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 */
|
||||||
|
};
|
||||||
|
|
||||||
int
|
#define INITIAL_CAPACITY 32
|
||||||
readUTF8Char(char *dest, char *src)
|
|
||||||
{
|
|
||||||
uint32_t state;
|
|
||||||
uint32_t codep;
|
|
||||||
int i;
|
|
||||||
|
|
||||||
for (i = 0, state = 0;; i++) {
|
struct Charmap {
|
||||||
if (decode(&state, &codep, (uint8_t)src[i]) == 1) {
|
char *name;
|
||||||
fatalerror("invalid UTF-8 character");
|
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 */
|
||||||
|
};
|
||||||
|
|
||||||
dest[i] = src[i];
|
static HashMap charmaps;
|
||||||
|
|
||||||
i++;
|
static struct Charmap *currentCharmap;
|
||||||
if (state == 0) {
|
|
||||||
dest[i] = '\0';
|
|
||||||
return i;
|
|
||||||
}
|
|
||||||
dest[i] = src[i];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
int
|
|
||||||
charmap_Add(char *input, UBYTE output)
|
|
||||||
{
|
|
||||||
int i;
|
|
||||||
size_t input_length;
|
|
||||||
char temp1i[CHARMAPLENGTH + 1], temp2i[CHARMAPLENGTH + 1], temp1o = 0,
|
|
||||||
temp2o = 0;
|
|
||||||
|
|
||||||
|
struct CharmapStackEntry {
|
||||||
struct Charmap *charmap;
|
struct Charmap *charmap;
|
||||||
|
struct CharmapStackEntry *next;
|
||||||
|
};
|
||||||
|
|
||||||
if (pCurrentSection) {
|
struct CharmapStackEntry *charmapStack;
|
||||||
if (pCurrentSection->charmap) {
|
|
||||||
charmap = pCurrentSection->charmap;
|
|
||||||
} else {
|
|
||||||
if ((charmap = calloc(1, sizeof(struct Charmap))) ==
|
|
||||||
NULL) {
|
|
||||||
fatalerror("Not enough memory for charmap");
|
|
||||||
}
|
|
||||||
pCurrentSection->charmap = charmap;
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
charmap = &globalCharmap;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (nPass == 2) {
|
static inline struct Charmap *charmap_Get(const char *name)
|
||||||
return charmap->count;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (charmap->count > MAXCHARMAPS || strlen(input) > CHARMAPLENGTH) {
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
input_length = strlen(input);
|
|
||||||
if (input_length > 1) {
|
|
||||||
i = 0;
|
|
||||||
while (i < charmap->count + 1) {
|
|
||||||
if (input_length > strlen(charmap->input[i])) {
|
|
||||||
memcpy(temp1i, charmap->input[i],
|
|
||||||
CHARMAPLENGTH + 1);
|
|
||||||
memcpy(charmap->input[i], input, input_length);
|
|
||||||
temp1o = charmap->output[i];
|
|
||||||
charmap->output[i] = output;
|
|
||||||
i++;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
i++;
|
|
||||||
}
|
|
||||||
while (i < charmap->count + 1) {
|
|
||||||
memcpy(temp2i, charmap->input[i], CHARMAPLENGTH + 1);
|
|
||||||
memcpy(charmap->input[i], temp1i, CHARMAPLENGTH + 1);
|
|
||||||
memcpy(temp1i, temp2i, CHARMAPLENGTH + 1);
|
|
||||||
temp2o = charmap->output[i];
|
|
||||||
charmap->output[i] = temp1o;
|
|
||||||
temp1o = temp2o;
|
|
||||||
i++;
|
|
||||||
}
|
|
||||||
memcpy(charmap->input[charmap->count + 1], temp1i,
|
|
||||||
CHARMAPLENGTH + 1);
|
|
||||||
charmap->output[charmap->count + 1] = temp1o;
|
|
||||||
} else {
|
|
||||||
memcpy(charmap->input[charmap->count], input, input_length);
|
|
||||||
charmap->output[charmap->count] = output;
|
|
||||||
}
|
|
||||||
return ++charmap->count;
|
|
||||||
}
|
|
||||||
|
|
||||||
int
|
|
||||||
charmap_Convert(char **input)
|
|
||||||
{
|
{
|
||||||
struct Charmap *charmap;
|
return hash_GetElement(charmaps, name);
|
||||||
|
}
|
||||||
char outchar[CHARMAPLENGTH + 1];
|
|
||||||
char *buffer;
|
static inline struct Charmap *resizeCharmap(struct Charmap *map, size_t capacity)
|
||||||
int i, j, length;
|
{
|
||||||
|
struct Charmap *new = realloc(map, sizeof(*map) + sizeof(*map->nodes) * capacity);
|
||||||
if (pCurrentSection && pCurrentSection->charmap) {
|
|
||||||
charmap = pCurrentSection->charmap;
|
if (!new)
|
||||||
} else {
|
fatalerror("Failed to %s charmap: %s\n",
|
||||||
charmap = &globalCharmap;
|
map ? "create" : "resize", strerror(errno));
|
||||||
}
|
new->capacity = capacity;
|
||||||
|
return new;
|
||||||
if ((buffer = malloc(strlen(*input))) == NULL) {
|
}
|
||||||
fatalerror("Not enough memory for buffer");
|
|
||||||
}
|
static inline void initNode(struct Charnode *node)
|
||||||
|
{
|
||||||
length = 0;
|
node->isTerminal = false;
|
||||||
while (**input) {
|
memset(node->next, 0, sizeof(node->next));
|
||||||
j = 0;
|
}
|
||||||
for (i = 0; i < charmap->count; i++) {
|
|
||||||
j = strlen(charmap->input[i]);
|
struct Charmap *charmap_New(const char *name, const char *baseName)
|
||||||
if (memcmp(*input, charmap->input[i], j) == 0) {
|
{
|
||||||
outchar[0] = charmap->output[i];
|
struct Charmap *base = NULL;
|
||||||
outchar[1] = 0;
|
|
||||||
break;
|
if (baseName != NULL) {
|
||||||
}
|
base = charmap_Get(baseName);
|
||||||
j = 0;
|
|
||||||
}
|
if (base == NULL)
|
||||||
if (!j) {
|
error("Base charmap '%s' doesn't exist\n", baseName);
|
||||||
j = readUTF8Char(outchar, *input);
|
}
|
||||||
}
|
|
||||||
if (!outchar[0]) {
|
struct Charmap *charmap = charmap_Get(name);
|
||||||
buffer[length++] = 0;
|
|
||||||
} else {
|
if (charmap) {
|
||||||
for (i = 0; outchar[i]; i++) {
|
error("Charmap '%s' already exists\n", name);
|
||||||
buffer[length++] = outchar[i];
|
return charmap;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
*input += j;
|
/* Init the new charmap's fields */
|
||||||
}
|
if (base) {
|
||||||
*input = buffer;
|
charmap = resizeCharmap(NULL, base->capacity);
|
||||||
return length;
|
charmap->usedNodes = base->usedNodes;
|
||||||
|
|
||||||
|
memcpy(charmap->nodes, base->nodes, sizeof(base->nodes[0]) * charmap->usedNodes);
|
||||||
|
} else {
|
||||||
|
charmap = resizeCharmap(NULL, INITIAL_CAPACITY);
|
||||||
|
charmap->usedNodes = 1;
|
||||||
|
initNode(&charmap->nodes[0]); /* Init the root node */
|
||||||
|
}
|
||||||
|
charmap->name = strdup(name);
|
||||||
|
|
||||||
|
hash_AddElement(charmaps, charmap->name, charmap);
|
||||||
|
currentCharmap = charmap;
|
||||||
|
|
||||||
|
return charmap;
|
||||||
|
}
|
||||||
|
|
||||||
|
void charmap_Delete(struct Charmap *charmap)
|
||||||
|
{
|
||||||
|
free(charmap->name);
|
||||||
|
free(charmap);
|
||||||
|
}
|
||||||
|
|
||||||
|
void charmap_Set(const char *name)
|
||||||
|
{
|
||||||
|
struct Charmap *charmap = charmap_Get(name);
|
||||||
|
|
||||||
|
if (charmap == NULL)
|
||||||
|
error("Charmap '%s' doesn't exist\n", name);
|
||||||
|
else
|
||||||
|
currentCharmap = charmap;
|
||||||
|
}
|
||||||
|
|
||||||
|
void charmap_Push(void)
|
||||||
|
{
|
||||||
|
struct CharmapStackEntry *stackEntry;
|
||||||
|
|
||||||
|
stackEntry = malloc(sizeof(*stackEntry));
|
||||||
|
if (stackEntry == NULL)
|
||||||
|
fatalerror("Failed to alloc charmap stack entry: %s\n", strerror(errno));
|
||||||
|
|
||||||
|
stackEntry->charmap = currentCharmap;
|
||||||
|
stackEntry->next = charmapStack;
|
||||||
|
|
||||||
|
charmapStack = stackEntry;
|
||||||
|
}
|
||||||
|
|
||||||
|
void charmap_Pop(void)
|
||||||
|
{
|
||||||
|
if (charmapStack == NULL) {
|
||||||
|
error("No entries in the charmap stack\n");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
struct CharmapStackEntry *top = charmapStack;
|
||||||
|
|
||||||
|
currentCharmap = top->charmap;
|
||||||
|
charmapStack = top->next;
|
||||||
|
free(top);
|
||||||
|
}
|
||||||
|
|
||||||
|
void charmap_Add(char *mapping, uint8_t value)
|
||||||
|
{
|
||||||
|
struct Charnode *node = ¤tCharmap->nodes[0];
|
||||||
|
|
||||||
|
for (uint8_t c; *mapping; mapping++) {
|
||||||
|
c = *mapping - 1;
|
||||||
|
|
||||||
|
if (node->next[c]) {
|
||||||
|
node = ¤tCharmap->nodes[node->next[c]];
|
||||||
|
} else {
|
||||||
|
/* Register next available node */
|
||||||
|
node->next[c] = currentCharmap->usedNodes;
|
||||||
|
/* If no more nodes are available, get new ones */
|
||||||
|
if (currentCharmap->usedNodes == currentCharmap->capacity) {
|
||||||
|
currentCharmap->capacity *= 2;
|
||||||
|
currentCharmap = resizeCharmap(currentCharmap, currentCharmap->capacity);
|
||||||
|
hash_ReplaceElement(charmaps, currentCharmap->name, currentCharmap);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Switch to and init new node */
|
||||||
|
node = ¤tCharmap->nodes[currentCharmap->usedNodes++];
|
||||||
|
initNode(node);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (node->isTerminal)
|
||||||
|
warning(WARNING_CHARMAP_REDEF, "Overriding charmap mapping\n");
|
||||||
|
|
||||||
|
node->isTerminal = true;
|
||||||
|
node->value = value;
|
||||||
|
}
|
||||||
|
|
||||||
|
size_t charmap_Convert(char const *input, uint8_t *output)
|
||||||
|
{
|
||||||
|
/*
|
||||||
|
* The goal is to match the longest mapping possible.
|
||||||
|
* 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.
|
||||||
|
* If no match, read a UTF-8 codepoint and output that.
|
||||||
|
*/
|
||||||
|
size_t outputLen = 0;
|
||||||
|
struct Charnode const *node = ¤tCharmap->nodes[0];
|
||||||
|
struct Charnode const *match = NULL;
|
||||||
|
size_t rewindDistance = 0;
|
||||||
|
|
||||||
|
for (;;) {
|
||||||
|
/* We still want NULs to reach the `else` path, to give a chance to rewind */
|
||||||
|
uint8_t c = *input - 1;
|
||||||
|
|
||||||
|
if (*input && node->next[c]) {
|
||||||
|
input++; /* Consume that char */
|
||||||
|
rewindDistance++;
|
||||||
|
|
||||||
|
node = ¤tCharmap->nodes[node->next[c]];
|
||||||
|
if (node->isTerminal) {
|
||||||
|
match = node;
|
||||||
|
rewindDistance = 0; /* Rewind from after the match */
|
||||||
|
}
|
||||||
|
|
||||||
|
} else {
|
||||||
|
input -= rewindDistance; /* Rewind */
|
||||||
|
rewindDistance = 0;
|
||||||
|
node = ¤tCharmap->nodes[0];
|
||||||
|
|
||||||
|
if (match) { /* Arrived at a dead end with a match found */
|
||||||
|
*output++ = match->value;
|
||||||
|
outputLen++;
|
||||||
|
match = NULL; /* Reset match for next round */
|
||||||
|
|
||||||
|
} else if (*input) { /* No match found */
|
||||||
|
size_t codepointLen = readUTF8Char(output, input);
|
||||||
|
|
||||||
|
if (codepointLen == 0) {
|
||||||
|
error("Input string is not valid UTF-8!\n");
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
input += codepointLen; /* OK because UTF-8 has no NUL in multi-byte chars */
|
||||||
|
output += codepointLen;
|
||||||
|
outputLen += codepointLen;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!*input)
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return outputLen;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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;
|
||||||
|
const char *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,299 @@
|
|||||||
|
/*
|
||||||
|
* This file is part of RGBDS.
|
||||||
|
*
|
||||||
|
* Copyright (c) 2020, RGBDS contributors.
|
||||||
|
*
|
||||||
|
* SPDX-License-Identifier: MIT
|
||||||
|
*/
|
||||||
|
|
||||||
|
#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 + 1 > bufLen) /* bufLen includes terminator */
|
||||||
|
error("Formatted string value too long\n");
|
||||||
|
|
||||||
|
size_t padLen = fmt->width > len ? fmt->width - len : 0;
|
||||||
|
|
||||||
|
if (fmt->alignLeft) {
|
||||||
|
strncpy(buf, value, len < bufLen ? len : bufLen);
|
||||||
|
for (size_t i = 0; i < totalLen && len + i < bufLen; i++)
|
||||||
|
buf[len + i] = ' ';
|
||||||
|
} else {
|
||||||
|
for (size_t i = 0; i < padLen && i < bufLen; i++)
|
||||||
|
buf[i] = ' ';
|
||||||
|
if (bufLen > padLen)
|
||||||
|
strncpy(buf + padLen, value, bufLen - padLen - 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
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) */
|
||||||
|
uint8_t fracWidth = fmt->hasFrac ? fmt->fracWidth : 5;
|
||||||
|
|
||||||
|
if (fracWidth) {
|
||||||
|
char spec[16]; /* Max "%" + 5-char PRIu32 + ".%0255.f" + terminator */
|
||||||
|
|
||||||
|
snprintf(spec, sizeof(spec), "%%" PRIu32 ".%%0%d.f", fracWidth);
|
||||||
|
snprintf(valueBuf, sizeof(valueBuf), spec, value >> 16,
|
||||||
|
(value % 65536) / 65536.0 * pow(10, fracWidth) + 0.5);
|
||||||
|
} else {
|
||||||
|
snprintf(valueBuf, sizeof(valueBuf), "%" PRIu32, value >> 16);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
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 = len;
|
||||||
|
|
||||||
|
if (sign)
|
||||||
|
numLen++;
|
||||||
|
if (prefix)
|
||||||
|
numLen++;
|
||||||
|
|
||||||
|
size_t totalLen = fmt->width > numLen ? fmt->width : numLen;
|
||||||
|
|
||||||
|
if (totalLen + 1 > bufLen) /* bufLen includes terminator */
|
||||||
|
error("Formatted numeric value too long\n");
|
||||||
|
|
||||||
|
size_t padLen = fmt->width > numLen ? fmt->width - numLen : 0;
|
||||||
|
|
||||||
|
if (fmt->alignLeft) {
|
||||||
|
size_t pos = 0;
|
||||||
|
|
||||||
|
if (sign && pos < bufLen)
|
||||||
|
buf[pos++] = sign;
|
||||||
|
if (prefix && pos < bufLen)
|
||||||
|
buf[pos++] = prefix;
|
||||||
|
|
||||||
|
strcpy(buf + pos, valueBuf);
|
||||||
|
pos += len;
|
||||||
|
|
||||||
|
for (size_t i = 0; i < totalLen && pos + i < bufLen; i++)
|
||||||
|
buf[pos + i] = ' ';
|
||||||
|
} else {
|
||||||
|
size_t pos = 0;
|
||||||
|
|
||||||
|
if (fmt->padZero) {
|
||||||
|
/* sign, then prefix, then zero padding */
|
||||||
|
if (sign && pos < bufLen)
|
||||||
|
buf[pos++] = sign;
|
||||||
|
if (prefix && pos < bufLen)
|
||||||
|
buf[pos++] = prefix;
|
||||||
|
for (size_t i = 0; i < padLen && pos < bufLen; i++)
|
||||||
|
buf[pos++] = '0';
|
||||||
|
} else {
|
||||||
|
/* space padding, then sign, then prefix */
|
||||||
|
for (size_t i = 0; i < padLen && pos < bufLen; i++)
|
||||||
|
buf[pos++] = ' ';
|
||||||
|
if (sign && pos < bufLen)
|
||||||
|
buf[pos++] = sign;
|
||||||
|
if (prefix && pos < bufLen)
|
||||||
|
buf[pos++] = prefix;
|
||||||
|
}
|
||||||
|
if (bufLen > pos)
|
||||||
|
strcpy(buf + pos, valueBuf);
|
||||||
|
}
|
||||||
|
|
||||||
|
buf[totalLen] = '\0';
|
||||||
|
}
|
||||||
+512
-304
@@ -1,366 +1,574 @@
|
|||||||
/*
|
/*
|
||||||
* FileStack routines
|
* This file is part of RGBDS.
|
||||||
|
*
|
||||||
|
* Copyright (c) 1997-2018, Carsten Sorensen and RGBDS contributors.
|
||||||
|
*
|
||||||
|
* SPDX-License-Identifier: MIT
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#include <sys/stat.h>
|
||||||
|
#include <assert.h>
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
#include <limits.h>
|
#include <inttypes.h>
|
||||||
|
#include <stdint.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <string.h>
|
|
||||||
|
|
||||||
#include "asm/symbol.h"
|
|
||||||
#include "asm/fstack.h"
|
#include "asm/fstack.h"
|
||||||
#include "types.h"
|
#include "asm/macro.h"
|
||||||
#include "asm/main.h"
|
#include "asm/main.h"
|
||||||
#include "asm/lexer.h"
|
#include "asm/symbol.h"
|
||||||
#include "extern/err.h"
|
#include "asm/warning.h"
|
||||||
#include "extern/strl.h"
|
#include "platform.h" /* S_ISDIR (stat macro) */
|
||||||
|
|
||||||
#ifndef PATH_MAX
|
#define MAXINCPATHS 128
|
||||||
#define PATH_MAX 256
|
|
||||||
|
#ifdef LEXER_DEBUG
|
||||||
|
#define dbgPrint(...) fprintf(stderr, "[fstack] " __VA_ARGS__)
|
||||||
|
#else
|
||||||
|
#define dbgPrint(...)
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
struct sContext *pFileStack;
|
struct Context {
|
||||||
struct sSymbol *pCurrentMacro;
|
struct Context *parent;
|
||||||
YY_BUFFER_STATE CurrentFlexHandle;
|
struct FileStackNode *fileInfo;
|
||||||
FILE *pCurrentFile;
|
struct LexerState *lexerState;
|
||||||
ULONG nCurrentStatus;
|
uint32_t uniqueID;
|
||||||
char tzCurrentFileName[_MAX_PATH + 1];
|
struct MacroArgs *macroArgs; /* Macro args are *saved* here */
|
||||||
char IncludePaths[MAXINCPATHS][_MAX_PATH + 1];
|
uint32_t nbReptIters;
|
||||||
SLONG NextIncPath = 0;
|
int32_t forValue;
|
||||||
ULONG nMacroCount;
|
int32_t forStep;
|
||||||
|
char *forName;
|
||||||
|
};
|
||||||
|
|
||||||
char *pCurrentREPTBlock;
|
static struct Context *contextStack;
|
||||||
ULONG nCurrentREPTBlockSize;
|
static size_t contextDepth = 0;
|
||||||
ULONG nCurrentREPTBlockCount;
|
#define DEFAULT_MAX_DEPTH 64
|
||||||
|
size_t nMaxRecursionDepth;
|
||||||
|
|
||||||
ULONG ulMacroReturnValue;
|
static unsigned int nbIncPaths = 0;
|
||||||
|
static char const *includePaths[MAXINCPATHS];
|
||||||
|
|
||||||
/*
|
static const char *dumpNodeAndParents(struct FileStackNode const *node)
|
||||||
* defines for nCurrentStatus
|
|
||||||
*/
|
|
||||||
#define STAT_isInclude 0
|
|
||||||
#define STAT_isMacro 1
|
|
||||||
#define STAT_isMacroArg 2
|
|
||||||
#define STAT_isREPTBlock 3
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Context push and pop
|
|
||||||
*/
|
|
||||||
void
|
|
||||||
pushcontext(void)
|
|
||||||
{
|
{
|
||||||
struct sContext **ppFileStack;
|
char const *name;
|
||||||
|
|
||||||
ppFileStack = &pFileStack;
|
if (node->type == NODE_REPT) {
|
||||||
while (*ppFileStack)
|
assert(node->parent); /* REPT nodes should always have a parent */
|
||||||
ppFileStack = &((*ppFileStack)->pNext);
|
struct FileStackReptNode const *reptInfo = (struct FileStackReptNode const *)node;
|
||||||
|
|
||||||
if ((*ppFileStack = malloc(sizeof(struct sContext))) != NULL) {
|
name = dumpNodeAndParents(node->parent);
|
||||||
(*ppFileStack)->FlexHandle = CurrentFlexHandle;
|
fprintf(stderr, "(%" PRIu32 ") -> %s", node->lineNo, name);
|
||||||
(*ppFileStack)->pNext = NULL;
|
for (uint32_t i = reptInfo->reptDepth; i--; )
|
||||||
strcpy((char *) (*ppFileStack)->tzFileName,
|
fprintf(stderr, "::REPT~%" PRIu32, reptInfo->iters[i]);
|
||||||
(char *) tzCurrentFileName);
|
} else {
|
||||||
(*ppFileStack)->nLine = nLineNo;
|
name = ((struct FileStackNamedNode const *)node)->name;
|
||||||
switch ((*ppFileStack)->nStatus = nCurrentStatus) {
|
if (node->parent) {
|
||||||
case STAT_isMacroArg:
|
dumpNodeAndParents(node->parent);
|
||||||
case STAT_isMacro:
|
fprintf(stderr, "(%" PRIu32 ") -> %s", node->lineNo, name);
|
||||||
sym_SaveCurrentMacroArgs((*ppFileStack)->tzMacroArgs);
|
} else {
|
||||||
(*ppFileStack)->pMacro = pCurrentMacro;
|
fputs(name, stderr);
|
||||||
break;
|
|
||||||
case STAT_isInclude:
|
|
||||||
(*ppFileStack)->pFile = pCurrentFile;
|
|
||||||
break;
|
|
||||||
case STAT_isREPTBlock:
|
|
||||||
sym_SaveCurrentMacroArgs((*ppFileStack)->tzMacroArgs);
|
|
||||||
(*ppFileStack)->pREPTBlock = pCurrentREPTBlock;
|
|
||||||
(*ppFileStack)->nREPTBlockSize = nCurrentREPTBlockSize;
|
|
||||||
(*ppFileStack)->nREPTBlockCount =
|
|
||||||
nCurrentREPTBlockCount;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
nLineNo = 0;
|
|
||||||
} else
|
|
||||||
fatalerror("No memory for context");
|
|
||||||
}
|
|
||||||
|
|
||||||
int
|
|
||||||
popcontext(void)
|
|
||||||
{
|
|
||||||
struct sContext *pLastFile, **ppLastFile;
|
|
||||||
|
|
||||||
if (nCurrentStatus == STAT_isREPTBlock) {
|
|
||||||
if (--nCurrentREPTBlockCount) {
|
|
||||||
yy_delete_buffer(CurrentFlexHandle);
|
|
||||||
CurrentFlexHandle =
|
|
||||||
yy_scan_bytes(pCurrentREPTBlock,
|
|
||||||
nCurrentREPTBlockSize);
|
|
||||||
yy_switch_to_buffer(CurrentFlexHandle);
|
|
||||||
sym_UseCurrentMacroArgs();
|
|
||||||
sym_SetMacroArgID(nMacroCount++);
|
|
||||||
sym_UseNewMacroArgs();
|
|
||||||
return (0);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if ((pLastFile = pFileStack) != NULL) {
|
return name;
|
||||||
ppLastFile = &pFileStack;
|
|
||||||
while (pLastFile->pNext) {
|
|
||||||
ppLastFile = &(pLastFile->pNext);
|
|
||||||
pLastFile = *ppLastFile;
|
|
||||||
}
|
|
||||||
|
|
||||||
yy_delete_buffer(CurrentFlexHandle);
|
|
||||||
nLineNo = pLastFile->nLine;
|
|
||||||
if (nCurrentStatus == STAT_isInclude)
|
|
||||||
fclose(pCurrentFile);
|
|
||||||
if (nCurrentStatus == STAT_isMacro) {
|
|
||||||
sym_FreeCurrentMacroArgs();
|
|
||||||
nLineNo += 1;
|
|
||||||
}
|
|
||||||
if (nCurrentStatus == STAT_isREPTBlock)
|
|
||||||
nLineNo += 1;
|
|
||||||
|
|
||||||
CurrentFlexHandle = pLastFile->FlexHandle;
|
|
||||||
strcpy((char *) tzCurrentFileName,
|
|
||||||
(char *) pLastFile->tzFileName);
|
|
||||||
switch (nCurrentStatus = pLastFile->nStatus) {
|
|
||||||
case STAT_isMacroArg:
|
|
||||||
case STAT_isMacro:
|
|
||||||
sym_RestoreCurrentMacroArgs(pLastFile->tzMacroArgs);
|
|
||||||
pCurrentMacro = pLastFile->pMacro;
|
|
||||||
break;
|
|
||||||
case STAT_isInclude:
|
|
||||||
pCurrentFile = pLastFile->pFile;
|
|
||||||
break;
|
|
||||||
case STAT_isREPTBlock:
|
|
||||||
sym_RestoreCurrentMacroArgs(pLastFile->tzMacroArgs);
|
|
||||||
pCurrentREPTBlock = pLastFile->pREPTBlock;
|
|
||||||
nCurrentREPTBlockSize = pLastFile->nREPTBlockSize;
|
|
||||||
nCurrentREPTBlockCount = pLastFile->nREPTBlockCount;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
free(*ppLastFile);
|
|
||||||
*ppLastFile = NULL;
|
|
||||||
yy_switch_to_buffer(CurrentFlexHandle);
|
|
||||||
return (0);
|
|
||||||
} else
|
|
||||||
return (1);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int
|
void fstk_Dump(struct FileStackNode const *node, uint32_t lineNo)
|
||||||
yywrap(void)
|
|
||||||
{
|
{
|
||||||
return (popcontext());
|
dumpNodeAndParents(node);
|
||||||
|
fprintf(stderr, "(%" PRIu32 ")", lineNo);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
void fstk_DumpCurrent(void)
|
||||||
* Dump the context stack to stderr
|
|
||||||
*/
|
|
||||||
void
|
|
||||||
fstk_Dump(void)
|
|
||||||
{
|
{
|
||||||
struct sContext *pLastFile;
|
if (!contextStack) {
|
||||||
|
fputs("at top level", stderr);
|
||||||
pLastFile = pFileStack;
|
|
||||||
|
|
||||||
while (pLastFile) {
|
|
||||||
fprintf(stderr, "%s(%ld) -> ", pLastFile->tzFileName,
|
|
||||||
pLastFile->nLine);
|
|
||||||
pLastFile = pLastFile->pNext;
|
|
||||||
}
|
|
||||||
|
|
||||||
fprintf(stderr, "%s(%ld)", tzCurrentFileName, nLineNo);
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Extra includepath stuff
|
|
||||||
*/
|
|
||||||
void
|
|
||||||
fstk_AddIncludePath(char *s)
|
|
||||||
{
|
|
||||||
if (NextIncPath == MAXINCPATHS) {
|
|
||||||
fatalerror("Too many include directories passed from command line");
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
fstk_Dump(contextStack->fileInfo, lexer_GetLineNo());
|
||||||
|
}
|
||||||
|
|
||||||
if (strlcpy(IncludePaths[NextIncPath++], s, _MAX_PATH) >= _MAX_PATH) {
|
struct FileStackNode *fstk_GetFileStack(void)
|
||||||
fatalerror("Include path too long '%s'",s);
|
{
|
||||||
|
if (!contextStack)
|
||||||
|
return NULL;
|
||||||
|
|
||||||
|
struct FileStackNode *node = contextStack->fileInfo;
|
||||||
|
|
||||||
|
/* Mark node and all of its parents as referenced if not already so they don't get freed */
|
||||||
|
while (node && !node->referenced) {
|
||||||
|
node->ID = -1;
|
||||||
|
node->referenced = true;
|
||||||
|
node = node->parent;
|
||||||
|
}
|
||||||
|
return contextStack->fileInfo;
|
||||||
|
}
|
||||||
|
|
||||||
|
char const *fstk_GetFileName(void)
|
||||||
|
{
|
||||||
|
/* Iterating via the nodes themselves skips nested REPTs */
|
||||||
|
struct FileStackNode const *node = contextStack->fileInfo;
|
||||||
|
|
||||||
|
while (node->type != NODE_FILE)
|
||||||
|
node = node->parent;
|
||||||
|
return ((struct FileStackNamedNode const *)node)->name;
|
||||||
|
}
|
||||||
|
|
||||||
|
void fstk_AddIncludePath(char const *path)
|
||||||
|
{
|
||||||
|
if (path[0] == '\0')
|
||||||
return;
|
return;
|
||||||
|
if (nbIncPaths >= MAXINCPATHS) {
|
||||||
|
error("Too many include directories passed from command line\n");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
size_t len = strlen(path);
|
||||||
|
size_t allocSize = len + (path[len - 1] != '/') + 1;
|
||||||
|
char *str = malloc(allocSize);
|
||||||
|
|
||||||
|
if (!str) {
|
||||||
|
/* Attempt to continue without that path */
|
||||||
|
error("Failed to allocate new include path: %s\n", strerror(errno));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
memcpy(str, path, len);
|
||||||
|
char *end = str + len - 1;
|
||||||
|
|
||||||
|
if (*end++ != '/')
|
||||||
|
*end++ = '/';
|
||||||
|
*end = '\0';
|
||||||
|
includePaths[nbIncPaths++] = str;
|
||||||
|
}
|
||||||
|
|
||||||
|
static void printDep(char const *path)
|
||||||
|
{
|
||||||
|
if (dependfile) {
|
||||||
|
fprintf(dependfile, "%s: %s\n", tzTargetFileName, path);
|
||||||
|
if (oGeneratePhonyDeps)
|
||||||
|
fprintf(dependfile, "%s:\n", path);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
FILE *
|
static bool isPathValid(char const *path)
|
||||||
fstk_FindFile(char *fname)
|
|
||||||
{
|
{
|
||||||
char path[PATH_MAX];
|
struct stat statbuf;
|
||||||
int i;
|
|
||||||
FILE *f;
|
|
||||||
|
|
||||||
if ((f = fopen(fname, "rb")) != NULL || errno != ENOENT) {
|
if (stat(path, &statbuf) != 0)
|
||||||
return f;
|
return false;
|
||||||
|
|
||||||
|
/* Reject directories */
|
||||||
|
return !S_ISDIR(statbuf.st_mode);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool fstk_FindFile(char const *path, char **fullPath, size_t *size)
|
||||||
|
{
|
||||||
|
if (!*size) {
|
||||||
|
*size = 64; /* This is arbitrary, really */
|
||||||
|
*fullPath = realloc(*fullPath, *size);
|
||||||
|
if (!*fullPath)
|
||||||
|
error("realloc error during include path search: %s\n",
|
||||||
|
strerror(errno));
|
||||||
}
|
}
|
||||||
|
|
||||||
for (i = 0; i < NextIncPath; ++i) {
|
if (*fullPath) {
|
||||||
if (strlcpy(path, IncludePaths[i], sizeof path) >=
|
for (size_t i = 0; i <= nbIncPaths; ++i) {
|
||||||
sizeof path) {
|
char const *incPath = i ? includePaths[i - 1] : "";
|
||||||
continue;
|
int len = snprintf(*fullPath, *size, "%s%s", incPath, path);
|
||||||
}
|
|
||||||
if (strlcat(path, fname, sizeof path) >= sizeof path) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
if ((f = fopen(path, "rb")) != NULL || errno != ENOENT) {
|
if (len < 0) {
|
||||||
return f;
|
error("snprintf error during include path search: %s\n",
|
||||||
|
strerror(errno));
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Oh how I wish `asnprintf` was standard... */
|
||||||
|
if ((size_t)len >= *size) { /* `len` doesn't include the terminator, `size` does */
|
||||||
|
*size = len + 1;
|
||||||
|
*fullPath = realloc(*fullPath, *size);
|
||||||
|
if (!*fullPath) {
|
||||||
|
error("realloc error during include path search: %s\n",
|
||||||
|
strerror(errno));
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
len = sprintf(*fullPath, "%s%s", incPath, path);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (isPathValid(*fullPath)) {
|
||||||
|
printDep(*fullPath);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
errno = ENOENT;
|
errno = ENOENT;
|
||||||
return NULL;
|
if (oGeneratedMissingIncludes)
|
||||||
|
printDep(path);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool yywrap(void)
|
||||||
|
{
|
||||||
|
uint32_t nIFDepth = lexer_GetIFDepth();
|
||||||
|
|
||||||
|
if (nIFDepth != 0)
|
||||||
|
fatalerror("Ended block with %" PRIu32 " unterminated IF construct%s\n",
|
||||||
|
nIFDepth, nIFDepth == 1 ? "" : "s");
|
||||||
|
|
||||||
|
if (contextStack->fileInfo->type == NODE_REPT) { /* The context is a REPT block, which may loop */
|
||||||
|
struct FileStackReptNode *fileInfo = (struct FileStackReptNode *)contextStack->fileInfo;
|
||||||
|
|
||||||
|
/* If the node is referenced, we can't edit it; duplicate it */
|
||||||
|
if (contextStack->fileInfo->referenced) {
|
||||||
|
size_t size = sizeof(*fileInfo) + sizeof(fileInfo->iters[0]) * fileInfo->reptDepth;
|
||||||
|
struct FileStackReptNode *copy = malloc(size);
|
||||||
|
|
||||||
|
if (!copy)
|
||||||
|
fatalerror("Failed to duplicate REPT file node: %s\n", strerror(errno));
|
||||||
|
/* Copy all info but the referencing */
|
||||||
|
memcpy(copy, fileInfo, size);
|
||||||
|
copy->node.next = NULL;
|
||||||
|
copy->node.referenced = false;
|
||||||
|
|
||||||
|
fileInfo = copy;
|
||||||
|
contextStack->fileInfo = (struct FileStackNode *)fileInfo;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* If this is a FOR, update the symbol value */
|
||||||
|
if (contextStack->forName && fileInfo->iters[0] <= contextStack->nbReptIters) {
|
||||||
|
contextStack->forValue += contextStack->forStep;
|
||||||
|
struct Symbol *sym = sym_AddSet(contextStack->forName,
|
||||||
|
contextStack->forValue);
|
||||||
|
|
||||||
|
/* This error message will refer to the current iteration */
|
||||||
|
if (sym->type != SYM_SET)
|
||||||
|
fatalerror("Failed to update FOR symbol value\n");
|
||||||
|
}
|
||||||
|
/* Advance to the next iteration */
|
||||||
|
fileInfo->iters[0]++;
|
||||||
|
/* If this wasn't the last iteration, wrap instead of popping */
|
||||||
|
if (fileInfo->iters[0] <= contextStack->nbReptIters) {
|
||||||
|
lexer_RestartRept(contextStack->fileInfo->lineNo);
|
||||||
|
contextStack->uniqueID = macro_UseNewUniqueID();
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
} else if (!contextStack->parent) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
dbgPrint("Popping context\n");
|
||||||
|
|
||||||
|
struct Context *context = contextStack;
|
||||||
|
|
||||||
|
contextStack = contextStack->parent;
|
||||||
|
assert(contextDepth != 0); // This is never supposed to underflow
|
||||||
|
contextDepth--;
|
||||||
|
|
||||||
|
lexer_DeleteState(context->lexerState);
|
||||||
|
/* Restore args if a macro (not REPT) saved them */
|
||||||
|
if (context->fileInfo->type == NODE_MACRO) {
|
||||||
|
dbgPrint("Restoring macro args %p\n", (void *)contextStack->macroArgs);
|
||||||
|
macro_UseNewArgs(contextStack->macroArgs);
|
||||||
|
}
|
||||||
|
/* Free the file stack node */
|
||||||
|
if (!context->fileInfo->referenced)
|
||||||
|
free(context->fileInfo);
|
||||||
|
/* Free the FOR symbol name */
|
||||||
|
free(context->forName);
|
||||||
|
/* Free the entry and make its parent the current entry */
|
||||||
|
free(context);
|
||||||
|
|
||||||
|
lexer_SetState(contextStack->lexerState);
|
||||||
|
macro_SetUniqueID(contextStack->uniqueID);
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Set up an include file for parsing
|
* Make sure not to switch the lexer state before calling this, so the saved line no is correct
|
||||||
|
* BE CAREFUL!! This modifies the file stack directly, you should have set up the file info first
|
||||||
|
* Callers should set contextStack->lexerState after this so it is not NULL
|
||||||
*/
|
*/
|
||||||
void
|
static void newContext(struct FileStackNode *fileInfo)
|
||||||
fstk_RunInclude(char *tzFileName)
|
|
||||||
{
|
{
|
||||||
FILE *f;
|
if (++contextDepth >= nMaxRecursionDepth)
|
||||||
|
fatalerror("Recursion limit (%zu) exceeded\n", nMaxRecursionDepth);
|
||||||
|
struct Context *context = malloc(sizeof(*context));
|
||||||
|
|
||||||
f = fstk_FindFile(tzFileName);
|
if (!context)
|
||||||
|
fatalerror("Failed to allocate memory for new context: %s\n", strerror(errno));
|
||||||
|
fileInfo->parent = contextStack->fileInfo;
|
||||||
|
fileInfo->lineNo = 0; /* Init to a default value, see struct definition for info */
|
||||||
|
fileInfo->referenced = false;
|
||||||
|
fileInfo->lineNo = lexer_GetLineNo();
|
||||||
|
context->fileInfo = fileInfo;
|
||||||
|
context->forName = NULL;
|
||||||
|
/*
|
||||||
|
* Link new entry to its parent so it's reachable later
|
||||||
|
* ERRORS SHOULD NOT OCCUR AFTER THIS!!
|
||||||
|
*/
|
||||||
|
context->parent = contextStack;
|
||||||
|
contextStack = context;
|
||||||
|
}
|
||||||
|
|
||||||
if (f == NULL) {
|
void fstk_RunInclude(char const *path)
|
||||||
err(1, "Unable to open included file '%s'",
|
{
|
||||||
tzFileName);
|
dbgPrint("Including path \"%s\"\n", path);
|
||||||
|
|
||||||
|
char *fullPath = NULL;
|
||||||
|
size_t size = 0;
|
||||||
|
|
||||||
|
if (!fstk_FindFile(path, &fullPath, &size)) {
|
||||||
|
free(fullPath);
|
||||||
|
if (oGeneratedMissingIncludes) {
|
||||||
|
if (verbose)
|
||||||
|
printf("Aborting (-MG) on INCLUDE file '%s' (%s)\n",
|
||||||
|
path, strerror(errno));
|
||||||
|
oFailedOnMissingInclude = true;
|
||||||
|
} else {
|
||||||
|
error("Unable to open included file '%s': %s\n", path, strerror(errno));
|
||||||
|
}
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
dbgPrint("Full path: \"%s\"\n", fullPath);
|
||||||
|
|
||||||
|
struct FileStackNamedNode *fileInfo = malloc(sizeof(*fileInfo) + size);
|
||||||
|
|
||||||
|
if (!fileInfo) {
|
||||||
|
error("Failed to alloc file info for INCLUDE: %s\n", strerror(errno));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
fileInfo->node.type = NODE_FILE;
|
||||||
|
strcpy(fileInfo->name, fullPath);
|
||||||
|
free(fullPath);
|
||||||
|
|
||||||
|
newContext((struct FileStackNode *)fileInfo);
|
||||||
|
contextStack->lexerState = lexer_OpenFile(fileInfo->name);
|
||||||
|
if (!contextStack->lexerState)
|
||||||
|
fatalerror("Failed to set up lexer for file include\n");
|
||||||
|
lexer_SetStateAtEOL(contextStack->lexerState);
|
||||||
|
/* We're back at top-level, so most things are reset */
|
||||||
|
contextStack->uniqueID = 0;
|
||||||
|
macro_SetUniqueID(0);
|
||||||
|
}
|
||||||
|
|
||||||
|
void fstk_RunMacro(char const *macroName, struct MacroArgs *args)
|
||||||
|
{
|
||||||
|
dbgPrint("Running macro \"%s\"\n", macroName);
|
||||||
|
|
||||||
|
struct Symbol *macro = sym_FindExactSymbol(macroName);
|
||||||
|
|
||||||
|
if (!macro) {
|
||||||
|
error("Macro \"%s\" not defined\n", macroName);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (macro->type != SYM_MACRO) {
|
||||||
|
error("\"%s\" is not a macro\n", macroName);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
contextStack->macroArgs = macro_GetCurrentArgs();
|
||||||
|
|
||||||
|
/* Compute total length of this node's name: <base name>::<macro> */
|
||||||
|
size_t reptNameLen = 0;
|
||||||
|
struct FileStackNode const *node = macro->src;
|
||||||
|
|
||||||
|
if (node->type == NODE_REPT) {
|
||||||
|
struct FileStackReptNode const *reptNode = (struct FileStackReptNode const *)node;
|
||||||
|
|
||||||
|
/* 4294967295 = 2^32 - 1, aka UINT32_MAX */
|
||||||
|
reptNameLen += reptNode->reptDepth * strlen("::REPT~4294967295");
|
||||||
|
/* Look for next named node */
|
||||||
|
do {
|
||||||
|
node = node->parent;
|
||||||
|
} while (node->type == NODE_REPT);
|
||||||
|
}
|
||||||
|
struct FileStackNamedNode const *baseNode = (struct FileStackNamedNode const *)node;
|
||||||
|
size_t baseLen = strlen(baseNode->name);
|
||||||
|
size_t macroNameLen = strlen(macro->name);
|
||||||
|
struct FileStackNamedNode *fileInfo = malloc(sizeof(*fileInfo) + baseLen
|
||||||
|
+ reptNameLen + 2 + macroNameLen + 1);
|
||||||
|
|
||||||
|
if (!fileInfo) {
|
||||||
|
error("Failed to alloc file info for \"%s\": %s\n", macro->name, strerror(errno));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
fileInfo->node.type = NODE_MACRO;
|
||||||
|
/* Print the name... */
|
||||||
|
char *dest = fileInfo->name;
|
||||||
|
|
||||||
|
memcpy(dest, baseNode->name, baseLen);
|
||||||
|
dest += baseLen;
|
||||||
|
if (node->type == NODE_REPT) {
|
||||||
|
struct FileStackReptNode const *reptNode = (struct FileStackReptNode const *)node;
|
||||||
|
|
||||||
|
for (uint32_t i = reptNode->reptDepth; i--; ) {
|
||||||
|
int nbChars = sprintf(dest, "::REPT~%" PRIu32, reptNode->iters[i]);
|
||||||
|
|
||||||
|
if (nbChars < 0)
|
||||||
|
fatalerror("Failed to write macro invocation info: %s\n",
|
||||||
|
strerror(errno));
|
||||||
|
dest += nbChars;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
*dest++ = ':';
|
||||||
|
*dest++ = ':';
|
||||||
|
memcpy(dest, macro->name, macroNameLen + 1);
|
||||||
|
|
||||||
|
newContext((struct FileStackNode *)fileInfo);
|
||||||
|
contextStack->lexerState = lexer_OpenFileView(macro->macro, macro->macroSize,
|
||||||
|
macro->fileLine);
|
||||||
|
if (!contextStack->lexerState)
|
||||||
|
fatalerror("Failed to set up lexer for macro invocation\n");
|
||||||
|
lexer_SetStateAtEOL(contextStack->lexerState);
|
||||||
|
contextStack->uniqueID = macro_UseNewUniqueID();
|
||||||
|
macro_UseNewArgs(args);
|
||||||
|
}
|
||||||
|
|
||||||
|
static bool newReptContext(int32_t reptLineNo, char *body, size_t size)
|
||||||
|
{
|
||||||
|
uint32_t reptDepth = contextStack->fileInfo->type == NODE_REPT
|
||||||
|
? ((struct FileStackReptNode *)contextStack->fileInfo)->reptDepth
|
||||||
|
: 0;
|
||||||
|
struct FileStackReptNode *fileInfo = malloc(sizeof(*fileInfo)
|
||||||
|
+ (reptDepth + 1) * sizeof(fileInfo->iters[0]));
|
||||||
|
|
||||||
|
if (!fileInfo) {
|
||||||
|
error("Failed to alloc file info for REPT: %s\n", strerror(errno));
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
fileInfo->node.type = NODE_REPT;
|
||||||
|
fileInfo->reptDepth = reptDepth + 1;
|
||||||
|
fileInfo->iters[0] = 1;
|
||||||
|
if (reptDepth)
|
||||||
|
/* Copy all parent iter counts */
|
||||||
|
memcpy(&fileInfo->iters[1],
|
||||||
|
((struct FileStackReptNode *)contextStack->fileInfo)->iters,
|
||||||
|
reptDepth * sizeof(fileInfo->iters[0]));
|
||||||
|
|
||||||
|
newContext((struct FileStackNode *)fileInfo);
|
||||||
|
/* Correct our line number, which currently points to the `ENDR` line */
|
||||||
|
contextStack->fileInfo->lineNo = reptLineNo;
|
||||||
|
|
||||||
|
contextStack->lexerState = lexer_OpenFileView(body, size, reptLineNo);
|
||||||
|
if (!contextStack->lexerState)
|
||||||
|
fatalerror("Failed to set up lexer for REPT block\n");
|
||||||
|
lexer_SetStateAtEOL(contextStack->lexerState);
|
||||||
|
contextStack->uniqueID = macro_UseNewUniqueID();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
void fstk_RunRept(uint32_t count, int32_t reptLineNo, char *body, size_t size)
|
||||||
|
{
|
||||||
|
dbgPrint("Running REPT(%" PRIu32 ")\n", count);
|
||||||
|
|
||||||
|
if (count == 0)
|
||||||
|
return;
|
||||||
|
if (!newReptContext(reptLineNo, body, size))
|
||||||
|
return;
|
||||||
|
|
||||||
|
contextStack->nbReptIters = count;
|
||||||
|
contextStack->forName = NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
void fstk_RunFor(char const *symName, int32_t start, int32_t stop, int32_t step,
|
||||||
|
int32_t reptLineNo, char *body, size_t size)
|
||||||
|
{
|
||||||
|
dbgPrint("Running FOR(\"%s\", %" PRId32 ", %" PRId32 ", %" PRId32 ")\n",
|
||||||
|
symName, start, stop, step);
|
||||||
|
|
||||||
|
struct Symbol *sym = sym_AddSet(symName, start);
|
||||||
|
|
||||||
|
if (sym->type != SYM_SET)
|
||||||
|
return;
|
||||||
|
|
||||||
|
uint32_t count = 0;
|
||||||
|
|
||||||
|
if (step > 0 && start < stop)
|
||||||
|
count = (stop - start - 1) / step + 1;
|
||||||
|
else if (step < 0 && stop < start)
|
||||||
|
count = (start - stop - 1) / -step + 1;
|
||||||
|
else if (step == 0)
|
||||||
|
error("FOR cannot have a step value of 0\n");
|
||||||
|
|
||||||
|
if (count == 0)
|
||||||
|
return;
|
||||||
|
if (!newReptContext(reptLineNo, body, size))
|
||||||
|
return;
|
||||||
|
|
||||||
|
contextStack->nbReptIters = count;
|
||||||
|
contextStack->forValue = start;
|
||||||
|
contextStack->forStep = step;
|
||||||
|
contextStack->forName = strdup(symName);
|
||||||
|
if (!contextStack->forName)
|
||||||
|
fatalerror("Not enough memory for FOR symbol name: %s\n", strerror(errno));
|
||||||
|
}
|
||||||
|
|
||||||
|
void fstk_StopRept(void)
|
||||||
|
{
|
||||||
|
/* Prevent more iterations */
|
||||||
|
contextStack->nbReptIters = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool fstk_Break(void)
|
||||||
|
{
|
||||||
|
dbgPrint("Breaking out of REPT/FOR\n");
|
||||||
|
|
||||||
|
if (contextStack->fileInfo->type != NODE_REPT) {
|
||||||
|
error("BREAK can only be used inside a REPT/FOR block\n");
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
pushcontext();
|
fstk_StopRept();
|
||||||
nLineNo = 1;
|
return true;
|
||||||
nCurrentStatus = STAT_isInclude;
|
|
||||||
strcpy(tzCurrentFileName, tzFileName);
|
|
||||||
pCurrentFile = f;
|
|
||||||
CurrentFlexHandle = yy_create_buffer(pCurrentFile);
|
|
||||||
yy_switch_to_buffer(CurrentFlexHandle);
|
|
||||||
|
|
||||||
//Dirty hack to give the INCLUDE directive a linefeed
|
|
||||||
|
|
||||||
yyunput('\n');
|
|
||||||
nLineNo -= 1;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
void fstk_Init(char const *mainPath, size_t maxRecursionDepth)
|
||||||
* Set up a macro for parsing
|
|
||||||
*/
|
|
||||||
ULONG
|
|
||||||
fstk_RunMacro(char *s)
|
|
||||||
{
|
{
|
||||||
struct sSymbol *sym;
|
struct LexerState *state = lexer_OpenFile(mainPath);
|
||||||
|
|
||||||
if ((sym = sym_FindMacro(s)) != NULL) {
|
if (!state)
|
||||||
pushcontext();
|
fatalerror("Failed to open main file!\n");
|
||||||
sym_SetMacroArgID(nMacroCount++);
|
lexer_SetState(state);
|
||||||
nLineNo = -1;
|
char const *fileName = lexer_GetFileName();
|
||||||
sym_UseNewMacroArgs();
|
size_t len = strlen(fileName);
|
||||||
nCurrentStatus = STAT_isMacro;
|
struct Context *context = malloc(sizeof(*contextStack));
|
||||||
strcpy(tzCurrentFileName, s);
|
struct FileStackNamedNode *fileInfo = malloc(sizeof(*fileInfo) + len + 1);
|
||||||
if (sym->pMacro == NULL)
|
|
||||||
return 0;
|
|
||||||
pCurrentMacro = sym;
|
|
||||||
CurrentFlexHandle =
|
|
||||||
yy_scan_bytes(pCurrentMacro->pMacro,
|
|
||||||
strlen(pCurrentMacro->pMacro));
|
|
||||||
yy_switch_to_buffer(CurrentFlexHandle);
|
|
||||||
return (1);
|
|
||||||
} else
|
|
||||||
return (0);
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
if (!context)
|
||||||
* Set up a macroargument for parsing
|
fatalerror("Failed to allocate memory for main context: %s\n", strerror(errno));
|
||||||
*/
|
if (!fileInfo)
|
||||||
void
|
fatalerror("Failed to allocate memory for main file info: %s\n", strerror(errno));
|
||||||
fstk_RunMacroArg(SLONG s)
|
|
||||||
{
|
|
||||||
char *sym;
|
|
||||||
|
|
||||||
if (s == '@')
|
context->fileInfo = (struct FileStackNode *)fileInfo;
|
||||||
s = -1;
|
/* lineNo and reptIter are unused on the top-level context */
|
||||||
else
|
context->fileInfo->parent = NULL;
|
||||||
s -= '0';
|
context->fileInfo->lineNo = 0; // This still gets written to the object file, so init it
|
||||||
|
context->fileInfo->referenced = false;
|
||||||
|
context->fileInfo->type = NODE_FILE;
|
||||||
|
memcpy(fileInfo->name, fileName, len + 1);
|
||||||
|
|
||||||
if ((sym = sym_FindMacroArg(s)) != NULL) {
|
context->parent = NULL;
|
||||||
pushcontext();
|
context->lexerState = state;
|
||||||
nCurrentStatus = STAT_isMacroArg;
|
context->uniqueID = 0;
|
||||||
sprintf(tzCurrentFileName, "%c", (UBYTE) s);
|
macro_SetUniqueID(0);
|
||||||
CurrentFlexHandle = yy_scan_bytes(sym, strlen(sym));
|
context->nbReptIters = 0;
|
||||||
yy_switch_to_buffer(CurrentFlexHandle);
|
context->forValue = 0;
|
||||||
} else
|
context->forStep = 0;
|
||||||
fatalerror("No such macroargument");
|
context->forName = NULL;
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
/* Now that it's set up properly, register the context */
|
||||||
* Set up a stringequate for parsing
|
contextStack = context;
|
||||||
*/
|
|
||||||
void
|
|
||||||
fstk_RunString(char *s)
|
|
||||||
{
|
|
||||||
struct sSymbol *pSym;
|
|
||||||
|
|
||||||
if ((pSym = sym_FindSymbol(s)) != NULL) {
|
/*
|
||||||
pushcontext();
|
* Check that max recursion depth won't allow overflowing node `malloc`s
|
||||||
nCurrentStatus = STAT_isMacroArg;
|
* This assumes that the rept node is larger
|
||||||
strcpy(tzCurrentFileName, s);
|
*/
|
||||||
CurrentFlexHandle =
|
#define DEPTH_LIMIT ((SIZE_MAX - sizeof(struct FileStackReptNode)) / sizeof(uint32_t))
|
||||||
yy_scan_bytes(pSym->pMacro, strlen(pSym->pMacro));
|
if (maxRecursionDepth > DEPTH_LIMIT) {
|
||||||
yy_switch_to_buffer(CurrentFlexHandle);
|
error("Recursion depth may not be higher than %zu, defaulting to "
|
||||||
} else
|
EXPAND_AND_STR(DEFAULT_MAX_DEPTH) "\n", DEPTH_LIMIT);
|
||||||
yyerror("No such string symbol '%s'", s);
|
nMaxRecursionDepth = DEFAULT_MAX_DEPTH;
|
||||||
}
|
} else {
|
||||||
|
nMaxRecursionDepth = maxRecursionDepth;
|
||||||
/*
|
|
||||||
* Set up a repeat block for parsing
|
|
||||||
*/
|
|
||||||
void
|
|
||||||
fstk_RunRept(ULONG count)
|
|
||||||
{
|
|
||||||
if (count) {
|
|
||||||
pushcontext();
|
|
||||||
sym_UseCurrentMacroArgs();
|
|
||||||
sym_SetMacroArgID(nMacroCount++);
|
|
||||||
sym_UseNewMacroArgs();
|
|
||||||
nCurrentREPTBlockCount = count;
|
|
||||||
nCurrentStatus = STAT_isREPTBlock;
|
|
||||||
nCurrentREPTBlockSize = ulNewMacroSize;
|
|
||||||
pCurrentREPTBlock = tzNewMacro;
|
|
||||||
CurrentFlexHandle =
|
|
||||||
yy_scan_bytes(pCurrentREPTBlock, nCurrentREPTBlockSize);
|
|
||||||
yy_switch_to_buffer(CurrentFlexHandle);
|
|
||||||
}
|
}
|
||||||
}
|
/* Make sure that the default of 64 is OK, though */
|
||||||
|
assert(DEPTH_LIMIT >= DEFAULT_MAX_DEPTH);
|
||||||
/*
|
#undef DEPTH_LIMIT
|
||||||
* Initialize the filestack routines
|
|
||||||
*/
|
|
||||||
void
|
|
||||||
fstk_Init(char *s)
|
|
||||||
{
|
|
||||||
char tzFileName[_MAX_PATH + 1];
|
|
||||||
|
|
||||||
char tzSymFileName[_MAX_PATH + 1 + 2];
|
|
||||||
snprintf(tzSymFileName, sizeof(tzSymFileName), "\"%s\"", s);
|
|
||||||
sym_AddString("__FILE__", tzSymFileName);
|
|
||||||
|
|
||||||
strcpy(tzFileName, s);
|
|
||||||
pFileStack = NULL;
|
|
||||||
pCurrentFile = fopen(tzFileName, "rb");
|
|
||||||
if (pCurrentFile == NULL) {
|
|
||||||
err(1, "Unable to open file '%s'", tzFileName);
|
|
||||||
}
|
|
||||||
|
|
||||||
nMacroCount = 0;
|
|
||||||
nCurrentStatus = STAT_isInclude;
|
|
||||||
strcpy(tzCurrentFileName, tzFileName);
|
|
||||||
CurrentFlexHandle = yy_create_buffer(pCurrentFile);
|
|
||||||
yy_switch_to_buffer(CurrentFlexHandle);
|
|
||||||
nLineNo = 1;
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,516 +0,0 @@
|
|||||||
#include "asm/asm.h"
|
|
||||||
#include "asm/symbol.h"
|
|
||||||
#include "asm/rpn.h"
|
|
||||||
#include "asm/symbol.h"
|
|
||||||
#include "asm/main.h"
|
|
||||||
#include "asm/lexer.h"
|
|
||||||
|
|
||||||
#include "asmy.h"
|
|
||||||
|
|
||||||
#include <stdbool.h>
|
|
||||||
#include <stdio.h>
|
|
||||||
#include <stdlib.h>
|
|
||||||
#include <math.h>
|
|
||||||
#include <string.h>
|
|
||||||
|
|
||||||
bool oDontExpandStrings = false;
|
|
||||||
SLONG nGBGfxID = -1;
|
|
||||||
SLONG nBinaryID = -1;
|
|
||||||
|
|
||||||
SLONG
|
|
||||||
gbgfx2bin(char ch)
|
|
||||||
{
|
|
||||||
SLONG i;
|
|
||||||
|
|
||||||
for (i = 0; i <= 3; i += 1) {
|
|
||||||
if (CurrentOptions.gbgfx[i] == ch) {
|
|
||||||
return (i);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return (0);
|
|
||||||
}
|
|
||||||
|
|
||||||
SLONG
|
|
||||||
binary2bin(char ch)
|
|
||||||
{
|
|
||||||
SLONG i;
|
|
||||||
|
|
||||||
for (i = 0; i <= 1; i += 1) {
|
|
||||||
if (CurrentOptions.binary[i] == ch) {
|
|
||||||
return (i);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return (0);
|
|
||||||
}
|
|
||||||
|
|
||||||
SLONG
|
|
||||||
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 SLONG(*x2bin) (char ch);
|
|
||||||
|
|
||||||
SLONG
|
|
||||||
ascii2bin(char *s)
|
|
||||||
{
|
|
||||||
SLONG radix = 10;
|
|
||||||
SLONG result = 0;
|
|
||||||
x2bin convertfunc = char2bin;
|
|
||||||
|
|
||||||
switch (*s) {
|
|
||||||
case '$':
|
|
||||||
radix = 16;
|
|
||||||
s += 1;
|
|
||||||
convertfunc = char2bin;
|
|
||||||
break;
|
|
||||||
case '&':
|
|
||||||
radix = 8;
|
|
||||||
s += 1;
|
|
||||||
convertfunc = char2bin;
|
|
||||||
break;
|
|
||||||
case '`':
|
|
||||||
radix = 4;
|
|
||||||
s += 1;
|
|
||||||
convertfunc = gbgfx2bin;
|
|
||||||
break;
|
|
||||||
case '%':
|
|
||||||
radix = 2;
|
|
||||||
s += 1;
|
|
||||||
convertfunc = binary2bin;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (radix == 4) {
|
|
||||||
SLONG c;
|
|
||||||
|
|
||||||
while (*s != '\0') {
|
|
||||||
c = convertfunc(*s++);
|
|
||||||
result = result * 2 + ((c & 2) << 7) + (c & 1);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
while (*s != '\0')
|
|
||||||
result = result * radix + convertfunc(*s++);
|
|
||||||
}
|
|
||||||
|
|
||||||
return (result);
|
|
||||||
}
|
|
||||||
|
|
||||||
ULONG
|
|
||||||
ParseFixedPoint(char *s, ULONG size)
|
|
||||||
{
|
|
||||||
//char dest[256];
|
|
||||||
ULONG i = 0, dot = 0;
|
|
||||||
|
|
||||||
while (size && dot != 2) {
|
|
||||||
if (s[i] == '.')
|
|
||||||
dot += 1;
|
|
||||||
|
|
||||||
if (dot < 2) {
|
|
||||||
//dest[i] = s[i];
|
|
||||||
size -= 1;
|
|
||||||
i += 1;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
//dest[i] = 0;
|
|
||||||
|
|
||||||
yyunputbytes(size);
|
|
||||||
|
|
||||||
yylval.nConstValue = (SLONG) (atof(s) * 65536);
|
|
||||||
|
|
||||||
return (1);
|
|
||||||
}
|
|
||||||
|
|
||||||
ULONG
|
|
||||||
ParseNumber(char *s, ULONG size)
|
|
||||||
{
|
|
||||||
char dest[256];
|
|
||||||
|
|
||||||
strncpy(dest, s, size);
|
|
||||||
dest[size] = 0;
|
|
||||||
yylval.nConstValue = ascii2bin(dest);
|
|
||||||
|
|
||||||
return (1);
|
|
||||||
}
|
|
||||||
|
|
||||||
ULONG
|
|
||||||
ParseSymbol(char *src, ULONG size)
|
|
||||||
{
|
|
||||||
char dest[MAXSYMLEN + 1];
|
|
||||||
int copied = 0, size_backup = size;
|
|
||||||
|
|
||||||
while (size && copied < MAXSYMLEN) {
|
|
||||||
if (*src == '\\') {
|
|
||||||
char *marg;
|
|
||||||
|
|
||||||
src += 1;
|
|
||||||
size -= 1;
|
|
||||||
|
|
||||||
if (*src == '@')
|
|
||||||
marg = sym_FindMacroArg(-1);
|
|
||||||
else if (*src >= '0' && *src <= '9')
|
|
||||||
marg = sym_FindMacroArg(*src - '0');
|
|
||||||
else {
|
|
||||||
fatalerror("Malformed ID");
|
|
||||||
return (0);
|
|
||||||
}
|
|
||||||
|
|
||||||
src += 1;
|
|
||||||
size -= 1;
|
|
||||||
|
|
||||||
if (marg) {
|
|
||||||
while (*marg)
|
|
||||||
dest[copied++] = *marg++;
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
dest[copied++] = *src++;
|
|
||||||
size -= 1;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (copied > MAXSYMLEN)
|
|
||||||
fatalerror("Symbol too long");
|
|
||||||
|
|
||||||
dest[copied] = 0;
|
|
||||||
|
|
||||||
if (!oDontExpandStrings && sym_isString(dest)) {
|
|
||||||
char *s;
|
|
||||||
|
|
||||||
yyskipbytes(size_backup);
|
|
||||||
yyunputstr(s = sym_GetStringValue(dest));
|
|
||||||
|
|
||||||
while (*s) {
|
|
||||||
if (*s++ == '\n') {
|
|
||||||
nLineNo -= 1;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return (0);
|
|
||||||
} else {
|
|
||||||
strcpy(yylval.tzString, dest);
|
|
||||||
return (1);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
ULONG
|
|
||||||
PutMacroArg(char *src, ULONG size)
|
|
||||||
{
|
|
||||||
char *s;
|
|
||||||
|
|
||||||
yyskipbytes(size);
|
|
||||||
if ((size == 2 && src[1] >= '1' && src[1] <= '9')) {
|
|
||||||
if ((s = sym_FindMacroArg(src[1] - '0')) != NULL) {
|
|
||||||
yyunputstr(s);
|
|
||||||
} else {
|
|
||||||
yyerror("Macro argument not defined");
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
yyerror("Invalid macro argument");
|
|
||||||
}
|
|
||||||
return (0);
|
|
||||||
}
|
|
||||||
|
|
||||||
ULONG
|
|
||||||
PutUniqueArg(char *src, ULONG size)
|
|
||||||
{
|
|
||||||
char *s;
|
|
||||||
|
|
||||||
yyskipbytes(size);
|
|
||||||
if ((s = sym_FindMacroArg(-1)) != NULL) {
|
|
||||||
yyunputstr(s);
|
|
||||||
} else {
|
|
||||||
yyerror("Macro unique label string not defined");
|
|
||||||
}
|
|
||||||
return (0);
|
|
||||||
}
|
|
||||||
|
|
||||||
enum {
|
|
||||||
T_LEX_MACROARG = 3000,
|
|
||||||
T_LEX_MACROUNIQUE
|
|
||||||
};
|
|
||||||
|
|
||||||
extern struct sLexInitString localstrings[];
|
|
||||||
|
|
||||||
struct sLexInitString staticstrings[] = {
|
|
||||||
{"||", 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},
|
|
||||||
|
|
||||||
{"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},
|
|
||||||
|
|
||||||
{"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},
|
|
||||||
{"printv", T_POP_PRINTV},
|
|
||||||
{"printf", T_POP_PRINTF},
|
|
||||||
{"export", T_POP_EXPORT},
|
|
||||||
{"xdef", T_POP_EXPORT},
|
|
||||||
{"import", T_POP_IMPORT},
|
|
||||||
{"xref", T_POP_IMPORT},
|
|
||||||
{"global", T_POP_GLOBAL},
|
|
||||||
{"ds", T_POP_DS},
|
|
||||||
{NAME_DB, T_POP_DB},
|
|
||||||
{NAME_DW, T_POP_DW},
|
|
||||||
{"section", T_POP_SECTION},
|
|
||||||
{"purge", T_POP_PURGE},
|
|
||||||
|
|
||||||
{"rsreset", T_POP_RSRESET},
|
|
||||||
{"rsset", T_POP_RSSET},
|
|
||||||
|
|
||||||
{"incbin", T_POP_INCBIN},
|
|
||||||
{"charmap", T_POP_CHARMAP},
|
|
||||||
|
|
||||||
{"fail", T_POP_FAIL},
|
|
||||||
{"warn", T_POP_WARN},
|
|
||||||
|
|
||||||
{"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},
|
|
||||||
|
|
||||||
{"if", T_POP_IF},
|
|
||||||
{"else", T_POP_ELSE},
|
|
||||||
{"endc", T_POP_ENDC},
|
|
||||||
|
|
||||||
{"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},
|
|
||||||
|
|
||||||
/* Deprecated section type names */
|
|
||||||
{"home", T_SECT_HOME},
|
|
||||||
{"code", T_SECT_CODE},
|
|
||||||
{"data", T_SECT_DATA},
|
|
||||||
{"bss", T_SECT_BSS},
|
|
||||||
|
|
||||||
{NAME_RB, T_POP_RB},
|
|
||||||
{NAME_RW, T_POP_RW},
|
|
||||||
{"equ", T_POP_EQU},
|
|
||||||
{"equs", T_POP_EQUS},
|
|
||||||
|
|
||||||
{"set", T_POP_SET},
|
|
||||||
{"=", T_POP_SET},
|
|
||||||
|
|
||||||
{"pushs", T_POP_PUSHS},
|
|
||||||
{"pops", T_POP_POPS},
|
|
||||||
{"pusho", T_POP_PUSHO},
|
|
||||||
{"popo", T_POP_POPO},
|
|
||||||
|
|
||||||
{"opt", T_POP_OPT},
|
|
||||||
|
|
||||||
{NULL, 0}
|
|
||||||
};
|
|
||||||
|
|
||||||
struct sLexFloat tNumberToken = {
|
|
||||||
ParseNumber,
|
|
||||||
T_NUMBER
|
|
||||||
};
|
|
||||||
|
|
||||||
struct sLexFloat tFixedPointToken = {
|
|
||||||
ParseFixedPoint,
|
|
||||||
T_NUMBER
|
|
||||||
};
|
|
||||||
|
|
||||||
struct sLexFloat tIDToken = {
|
|
||||||
ParseSymbol,
|
|
||||||
T_ID
|
|
||||||
};
|
|
||||||
|
|
||||||
struct sLexFloat tMacroArgToken = {
|
|
||||||
PutMacroArg,
|
|
||||||
T_LEX_MACROARG
|
|
||||||
};
|
|
||||||
|
|
||||||
struct sLexFloat tMacroUniqueToken = {
|
|
||||||
PutUniqueArg,
|
|
||||||
T_LEX_MACROUNIQUE
|
|
||||||
};
|
|
||||||
|
|
||||||
void
|
|
||||||
setuplex(void)
|
|
||||||
{
|
|
||||||
ULONG id;
|
|
||||||
|
|
||||||
lex_Init();
|
|
||||||
lex_AddStrings(staticstrings);
|
|
||||||
lex_AddStrings(localstrings);
|
|
||||||
|
|
||||||
//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
|
|
||||||
|
|
||||||
nBinaryID = id = lex_FloatAlloc(&tNumberToken);
|
|
||||||
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
|
|
||||||
|
|
||||||
nGBGfxID = id = lex_FloatAlloc(&tNumberToken);
|
|
||||||
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, '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, '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
|
|
||||||
|
|
||||||
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');
|
|
||||||
|
|
||||||
}
|
|
||||||
+2595
-671
File diff suppressed because it is too large
Load Diff
@@ -1,89 +0,0 @@
|
|||||||
#include "asm/symbol.h"
|
|
||||||
#include "asm/lexer.h"
|
|
||||||
#include "asm/rpn.h"
|
|
||||||
|
|
||||||
#include "asmy.h"
|
|
||||||
|
|
||||||
struct sLexInitString localstrings[] = {
|
|
||||||
{"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},
|
|
||||||
|
|
||||||
/* Handled by globallex.c */
|
|
||||||
/* { "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},
|
|
||||||
/* { "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},
|
|
||||||
{"[sp]", T_MODE_SP_IND},
|
|
||||||
{"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},
|
|
||||||
|
|
||||||
{"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},
|
|
||||||
|
|
||||||
{NULL, 0}
|
|
||||||
};
|
|
||||||
+190
@@ -0,0 +1,190 @@
|
|||||||
|
|
||||||
|
#include <assert.h>
|
||||||
|
#include <errno.h>
|
||||||
|
#include <inttypes.h>
|
||||||
|
#include <stdbool.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <string.h>
|
||||||
|
|
||||||
|
#include "asm/macro.h"
|
||||||
|
#include "asm/warning.h"
|
||||||
|
|
||||||
|
#define MAXMACROARGS 99999
|
||||||
|
|
||||||
|
/*
|
||||||
|
* 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,
|
||||||
|
* and the rest is insane and thus will assume responsibility.
|
||||||
|
* Additionally, ~300 bytes (on x64) of memory per level of nesting has been
|
||||||
|
* deemed reasonable. (Halve that on x86.)
|
||||||
|
*/
|
||||||
|
#define INITIAL_ARG_SIZE 32
|
||||||
|
struct MacroArgs {
|
||||||
|
unsigned int nbArgs;
|
||||||
|
unsigned int shift;
|
||||||
|
unsigned int capacity;
|
||||||
|
char *args[];
|
||||||
|
};
|
||||||
|
|
||||||
|
#define SIZEOF_ARGS(nbArgs) (sizeof(struct MacroArgs) + \
|
||||||
|
sizeof(((struct MacroArgs){0}).args[0]) * (nbArgs))
|
||||||
|
|
||||||
|
static struct MacroArgs *macroArgs = NULL;
|
||||||
|
static uint32_t uniqueID = 0;
|
||||||
|
static uint32_t maxUniqueID = 0;
|
||||||
|
/*
|
||||||
|
* 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
|
||||||
|
* better solution, but if you have one, please feel free!
|
||||||
|
*/
|
||||||
|
static char uniqueIDBuf[] = "_u4294967295"; // UINT32_MAX
|
||||||
|
static char *uniqueIDPtr = NULL;
|
||||||
|
|
||||||
|
struct MacroArgs *macro_GetCurrentArgs(void)
|
||||||
|
{
|
||||||
|
return macroArgs;
|
||||||
|
}
|
||||||
|
|
||||||
|
struct MacroArgs *macro_NewArgs(void)
|
||||||
|
{
|
||||||
|
struct MacroArgs *args = malloc(SIZEOF_ARGS(INITIAL_ARG_SIZE));
|
||||||
|
|
||||||
|
if (!args)
|
||||||
|
fatalerror("Unable to register macro arguments: %s\n", strerror(errno));
|
||||||
|
|
||||||
|
args->nbArgs = 0;
|
||||||
|
args->shift = 0;
|
||||||
|
args->capacity = INITIAL_ARG_SIZE;
|
||||||
|
return args;
|
||||||
|
}
|
||||||
|
|
||||||
|
void macro_AppendArg(struct MacroArgs **argPtr, char *s)
|
||||||
|
{
|
||||||
|
#define macArgs (*argPtr)
|
||||||
|
if (s[0] == '\0')
|
||||||
|
warning(WARNING_EMPTY_MACRO_ARG, "Empty macro argument\n");
|
||||||
|
if (macArgs->nbArgs == MAXMACROARGS)
|
||||||
|
error("A maximum of " EXPAND_AND_STR(MAXMACROARGS) " arguments is allowed\n");
|
||||||
|
if (macArgs->nbArgs >= macArgs->capacity) {
|
||||||
|
macArgs->capacity *= 2;
|
||||||
|
/* Check that overflow didn't roll us back */
|
||||||
|
if (macArgs->capacity <= macArgs->nbArgs)
|
||||||
|
fatalerror("Failed to add new macro argument: capacity overflow\n");
|
||||||
|
macArgs = realloc(macArgs, SIZEOF_ARGS(macArgs->capacity));
|
||||||
|
if (!macArgs)
|
||||||
|
fatalerror("Error adding new macro argument: %s\n", strerror(errno));
|
||||||
|
}
|
||||||
|
macArgs->args[macArgs->nbArgs++] = s;
|
||||||
|
#undef macArgs
|
||||||
|
}
|
||||||
|
|
||||||
|
void macro_UseNewArgs(struct MacroArgs *args)
|
||||||
|
{
|
||||||
|
macroArgs = args;
|
||||||
|
}
|
||||||
|
|
||||||
|
void macro_FreeArgs(struct MacroArgs *args)
|
||||||
|
{
|
||||||
|
for (uint32_t i = 0; i < macroArgs->nbArgs; i++)
|
||||||
|
free(args->args[i]);
|
||||||
|
}
|
||||||
|
|
||||||
|
char const *macro_GetArg(uint32_t i)
|
||||||
|
{
|
||||||
|
if (!macroArgs)
|
||||||
|
return NULL;
|
||||||
|
|
||||||
|
uint32_t realIndex = i + macroArgs->shift - 1;
|
||||||
|
|
||||||
|
return realIndex >= macroArgs->nbArgs ? NULL
|
||||||
|
: macroArgs->args[realIndex];
|
||||||
|
}
|
||||||
|
|
||||||
|
char *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)
|
||||||
|
{
|
||||||
|
return uniqueID;
|
||||||
|
}
|
||||||
|
|
||||||
|
char const *macro_GetUniqueIDStr(void)
|
||||||
|
{
|
||||||
|
return uniqueIDPtr;
|
||||||
|
}
|
||||||
|
|
||||||
|
void macro_SetUniqueID(uint32_t id)
|
||||||
|
{
|
||||||
|
uniqueID = id;
|
||||||
|
if (id == 0) {
|
||||||
|
uniqueIDPtr = NULL;
|
||||||
|
} else {
|
||||||
|
if (uniqueID > maxUniqueID)
|
||||||
|
maxUniqueID = uniqueID;
|
||||||
|
/* The buffer is guaranteed to be the correct size */
|
||||||
|
/* This is a valid label fragment, but not a valid numeric */
|
||||||
|
sprintf(uniqueIDBuf, "_u%" PRIu32, id);
|
||||||
|
uniqueIDPtr = uniqueIDBuf;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
uint32_t macro_UseNewUniqueID(void)
|
||||||
|
{
|
||||||
|
macro_SetUniqueID(++maxUniqueID);
|
||||||
|
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)
|
||||||
|
{
|
||||||
|
return macroArgs->nbArgs - macroArgs->shift;
|
||||||
|
}
|
||||||
+301
-394
@@ -1,460 +1,367 @@
|
|||||||
|
/*
|
||||||
|
* This file is part of RGBDS.
|
||||||
|
*
|
||||||
|
* Copyright (c) 1997-2018, Carsten Sorensen and RGBDS contributors.
|
||||||
|
*
|
||||||
|
* SPDX-License-Identifier: MIT
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <ctype.h>
|
||||||
|
#include <errno.h>
|
||||||
|
#include <float.h>
|
||||||
|
#include <inttypes.h>
|
||||||
#include <math.h>
|
#include <math.h>
|
||||||
#include <stdarg.h>
|
#include <stdarg.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
#include <stdint.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <time.h>
|
#include <time.h>
|
||||||
#include <unistd.h>
|
|
||||||
|
|
||||||
#include "asm/symbol.h"
|
#include "asm/charmap.h"
|
||||||
|
#include "asm/format.h"
|
||||||
#include "asm/fstack.h"
|
#include "asm/fstack.h"
|
||||||
#include "asm/output.h"
|
#include "asm/lexer.h"
|
||||||
#include "asm/main.h"
|
#include "asm/main.h"
|
||||||
|
#include "asm/opt.h"
|
||||||
|
#include "asm/output.h"
|
||||||
|
#include "asm/rpn.h"
|
||||||
|
#include "asm/symbol.h"
|
||||||
|
#include "asm/warning.h"
|
||||||
|
#include "parser.h"
|
||||||
|
|
||||||
#include "extern/err.h"
|
#include "extern/err.h"
|
||||||
#include "extern/reallocarray.h"
|
#include "extern/getopt.h"
|
||||||
|
|
||||||
|
#include "helpers.h"
|
||||||
|
#include "version.h"
|
||||||
|
|
||||||
|
// 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);
|
int yyparse(void);
|
||||||
void setuplex(void);
|
|
||||||
|
|
||||||
int cldefines_index;
|
|
||||||
int cldefines_size;
|
|
||||||
char **cldefines;
|
|
||||||
|
|
||||||
clock_t nStartClock, nEndClock;
|
|
||||||
SLONG nLineNo;
|
|
||||||
ULONG nTotalLines, nPass, nPC, nIFDepth, nErrors;
|
|
||||||
|
|
||||||
|
#if defined(YYDEBUG) && YYDEBUG
|
||||||
extern int yydebug;
|
extern int yydebug;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
FILE * dependfile;
|
||||||
|
bool oGeneratedMissingIncludes;
|
||||||
|
bool oFailedOnMissingInclude;
|
||||||
|
bool oGeneratePhonyDeps;
|
||||||
|
char *tzTargetFileName;
|
||||||
|
|
||||||
|
bool haltnop;
|
||||||
|
bool optimizeloads;
|
||||||
|
bool verbose;
|
||||||
|
bool warnings; /* True to enable warnings, false to disable them. */
|
||||||
|
|
||||||
|
/* Escapes Make-special chars from a string */
|
||||||
|
static char *make_escape(const char *str)
|
||||||
|
{
|
||||||
|
char * const escaped_str = malloc(strlen(str) * 2 + 1);
|
||||||
|
char *dest = escaped_str;
|
||||||
|
|
||||||
|
if (escaped_str == NULL)
|
||||||
|
err(1, "%s: Failed to allocate memory", __func__);
|
||||||
|
|
||||||
|
while (*str) {
|
||||||
|
/* All dollars needs to be doubled */
|
||||||
|
if (*str == '$')
|
||||||
|
*dest++ = '$';
|
||||||
|
*dest++ = *str++;
|
||||||
|
}
|
||||||
|
*dest = '\0';
|
||||||
|
|
||||||
|
return escaped_str;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Short options */
|
||||||
|
static const char *optstring = "b:D:Eg:hi:LM:o:p:r:VvW:w";
|
||||||
|
|
||||||
|
/* Variables for the long-only options */
|
||||||
|
static int depType; /* Variants of `-M` */
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Option stack
|
* Equivalent long options
|
||||||
|
* Please keep in the same order as short opts
|
||||||
|
*
|
||||||
|
* Also, make sure long opts don't create ambiguity:
|
||||||
|
* A long opt's name should start with the same letter as its short opt,
|
||||||
|
* except if it doesn't create any ambiguity (`verbose` versus `version`).
|
||||||
|
* This is because long opt matching, even to a single char, is prioritized
|
||||||
|
* over short opt matching
|
||||||
*/
|
*/
|
||||||
|
static struct option const longopts[] = {
|
||||||
struct sOptions DefaultOptions;
|
{ "binary-digits", required_argument, NULL, 'b' },
|
||||||
struct sOptions CurrentOptions;
|
{ "define", required_argument, NULL, 'D' },
|
||||||
|
{ "export-all", no_argument, NULL, 'E' },
|
||||||
struct sOptionStackEntry {
|
{ "gfx-chars", required_argument, NULL, 'g' },
|
||||||
struct sOptions Options;
|
{ "halt-without-nop", no_argument, NULL, 'h' },
|
||||||
struct sOptionStackEntry *pNext;
|
{ "include", required_argument, NULL, 'i' },
|
||||||
|
{ "preserve-ld", no_argument, NULL, 'L' },
|
||||||
|
{ "dependfile", required_argument, NULL, 'M' },
|
||||||
|
{ "MG", no_argument, &depType, 'G' },
|
||||||
|
{ "MP", no_argument, &depType, 'P' },
|
||||||
|
{ "MT", required_argument, &depType, 'T' },
|
||||||
|
{ "MQ", required_argument, &depType, 'Q' },
|
||||||
|
{ "output", required_argument, NULL, 'o' },
|
||||||
|
{ "pad-value", required_argument, NULL, 'p' },
|
||||||
|
{ "recursion-depth", required_argument, NULL, 'r' },
|
||||||
|
{ "version", no_argument, NULL, 'V' },
|
||||||
|
{ "verbose", no_argument, NULL, 'v' },
|
||||||
|
{ "warning", required_argument, NULL, 'W' },
|
||||||
|
{ NULL, no_argument, NULL, 0 }
|
||||||
};
|
};
|
||||||
|
|
||||||
struct sOptionStackEntry *pOptionStack = NULL;
|
static void print_usage(void)
|
||||||
|
|
||||||
void
|
|
||||||
opt_SetCurrentOptions(struct sOptions * pOpt)
|
|
||||||
{
|
{
|
||||||
if (nGBGfxID != -1) {
|
fputs(
|
||||||
lex_FloatDeleteRange(nGBGfxID, CurrentOptions.gbgfx[0],
|
"Usage: rgbasm [-EhLVvw] [-b chars] [-D name[=value]] [-g chars] [-i path]\n"
|
||||||
CurrentOptions.gbgfx[0]);
|
" [-M depend_file] [-MG] [-MP] [-MT target_file] [-MQ target_file]\n"
|
||||||
lex_FloatDeleteRange(nGBGfxID, CurrentOptions.gbgfx[1],
|
" [-o out_file] [-p pad_value] [-r depth] [-W warning] <file>\n"
|
||||||
CurrentOptions.gbgfx[1]);
|
"Useful options:\n"
|
||||||
lex_FloatDeleteRange(nGBGfxID, CurrentOptions.gbgfx[2],
|
" -E, --export-all export all labels\n"
|
||||||
CurrentOptions.gbgfx[2]);
|
" -M, --dependfile <path> set the output dependency file\n"
|
||||||
lex_FloatDeleteRange(nGBGfxID, CurrentOptions.gbgfx[3],
|
" -o, --output <path> set the output object file\n"
|
||||||
CurrentOptions.gbgfx[3]);
|
" -p, --pad-value <value> set the value to use for `ds'\n"
|
||||||
lex_FloatDeleteSecondRange(nGBGfxID, CurrentOptions.gbgfx[0],
|
" -V, --version print RGBASM version and exit\n"
|
||||||
CurrentOptions.gbgfx[0]);
|
" -W, --warning <warning> enable or disable warnings\n"
|
||||||
lex_FloatDeleteSecondRange(nGBGfxID, CurrentOptions.gbgfx[1],
|
"\n"
|
||||||
CurrentOptions.gbgfx[1]);
|
"For help, use `man rgbasm' or go to https://rgbds.gbdev.io/docs/\n",
|
||||||
lex_FloatDeleteSecondRange(nGBGfxID, CurrentOptions.gbgfx[2],
|
stderr);
|
||||||
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 {
|
|
||||||
errx(1, "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 {
|
|
||||||
errx(1, "Must specify exactly 2 characters for option "
|
|
||||||
"'b'");
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
case 'z':
|
|
||||||
if (strlen(&s[1]) <= 2) {
|
|
||||||
int result;
|
|
||||||
|
|
||||||
result = sscanf(&s[1], "%lx", &newopt.fillchar);
|
|
||||||
if (!((result == EOF) || (result == 1))) {
|
|
||||||
errx(1, "Invalid argument for option 'z'");
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
errx(1, "Invalid argument for option 'z'");
|
|
||||||
exit(1);
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
fatalerror("Unknown option");
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
opt_SetCurrentOptions(&newopt);
|
|
||||||
}
|
|
||||||
|
|
||||||
void
|
|
||||||
opt_Push(void)
|
|
||||||
{
|
|
||||||
struct sOptionStackEntry *pOpt;
|
|
||||||
|
|
||||||
if ((pOpt = malloc(sizeof(struct sOptionStackEntry))) != NULL) {
|
|
||||||
pOpt->Options = CurrentOptions;
|
|
||||||
pOpt->pNext = pOptionStack;
|
|
||||||
pOptionStack = pOpt;
|
|
||||||
} else
|
|
||||||
fatalerror("No memory for option stack");
|
|
||||||
}
|
|
||||||
|
|
||||||
void
|
|
||||||
opt_Pop(void)
|
|
||||||
{
|
|
||||||
if (pOptionStack) {
|
|
||||||
struct sOptionStackEntry *pOpt;
|
|
||||||
|
|
||||||
pOpt = pOptionStack;
|
|
||||||
opt_SetCurrentOptions(&(pOpt->Options));
|
|
||||||
pOptionStack = pOpt->pNext;
|
|
||||||
free(pOpt);
|
|
||||||
} else
|
|
||||||
fatalerror("No entries in the option stack");
|
|
||||||
}
|
|
||||||
|
|
||||||
void
|
|
||||||
opt_AddDefine(char *s)
|
|
||||||
{
|
|
||||||
char *value, *equals;
|
|
||||||
if(cldefines_index >= cldefines_size)
|
|
||||||
{
|
|
||||||
cldefines_size *= 2;
|
|
||||||
cldefines = reallocarray(cldefines, cldefines_size,
|
|
||||||
2 * sizeof(void *));
|
|
||||||
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;
|
|
||||||
}
|
|
||||||
|
|
||||||
void
|
|
||||||
opt_ParseDefines()
|
|
||||||
{
|
|
||||||
int i;
|
|
||||||
|
|
||||||
for(i = 0; i < cldefines_index; i += 2)
|
|
||||||
{
|
|
||||||
sym_AddString(cldefines[i], cldefines[i + 1]);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Error handling
|
|
||||||
*/
|
|
||||||
void
|
|
||||||
verror(const char *fmt, va_list args)
|
|
||||||
{
|
|
||||||
fprintf(stderr, "ERROR: ");
|
|
||||||
fstk_Dump();
|
|
||||||
fprintf(stderr, ":\n\t");
|
|
||||||
vfprintf(stderr, fmt, args);
|
|
||||||
fprintf(stderr, "\n");
|
|
||||||
nErrors += 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
void
|
|
||||||
yyerror(const char *fmt, ...)
|
|
||||||
{
|
|
||||||
va_list args;
|
|
||||||
va_start(args, fmt);
|
|
||||||
verror(fmt, args);
|
|
||||||
va_end(args);
|
|
||||||
}
|
|
||||||
|
|
||||||
void
|
|
||||||
fatalerror(const char *fmt, ...)
|
|
||||||
{
|
|
||||||
va_list args;
|
|
||||||
va_start(args, fmt);
|
|
||||||
verror(fmt, args);
|
|
||||||
va_end(args);
|
|
||||||
exit(5);
|
|
||||||
}
|
|
||||||
|
|
||||||
void
|
|
||||||
warning(const char *fmt, ...)
|
|
||||||
{
|
|
||||||
if (!CurrentOptions.warnings)
|
|
||||||
return;
|
|
||||||
|
|
||||||
va_list args;
|
|
||||||
va_start(args, fmt);
|
|
||||||
|
|
||||||
fprintf(stderr, "warning: ");
|
|
||||||
fstk_Dump();
|
|
||||||
fprintf(stderr, ":\n\t");
|
|
||||||
vfprintf(stderr, fmt, args);
|
|
||||||
fprintf(stderr, "\n");
|
|
||||||
|
|
||||||
va_end(args);
|
|
||||||
}
|
|
||||||
|
|
||||||
static void
|
|
||||||
usage(void)
|
|
||||||
{
|
|
||||||
printf(
|
|
||||||
"Usage: rgbasm [-hvE] [-b chars] [-Dname[=value]] [-g chars] [-i path]\n"
|
|
||||||
" [-o outfile] [-p pad_value] file.asm\n");
|
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
int
|
int main(int argc, char *argv[])
|
||||||
main(int argc, char *argv[])
|
|
||||||
{
|
{
|
||||||
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);
|
||||||
|
|
||||||
cldefines_size = 32;
|
dependfile = NULL;
|
||||||
cldefines = reallocarray(cldefines, cldefines_size,
|
|
||||||
2 * sizeof(void *));
|
|
||||||
if(!cldefines)
|
|
||||||
{
|
|
||||||
fatalerror("No memory for command line defines");
|
|
||||||
}
|
|
||||||
|
|
||||||
if (argc == 1)
|
#if defined(YYDEBUG) && YYDEBUG
|
||||||
usage();
|
yydebug = 1;
|
||||||
|
#endif
|
||||||
|
|
||||||
/* yydebug=1; */
|
// Perform some init for below
|
||||||
|
sym_Init(now);
|
||||||
|
|
||||||
DefaultOptions.gbgfx[0] = '0';
|
// Set defaults
|
||||||
DefaultOptions.gbgfx[1] = '1';
|
|
||||||
DefaultOptions.gbgfx[2] = '2';
|
|
||||||
DefaultOptions.gbgfx[3] = '3';
|
|
||||||
DefaultOptions.binary[0] = '0';
|
|
||||||
DefaultOptions.binary[1] = '1';
|
|
||||||
DefaultOptions.fillchar = 0;
|
|
||||||
DefaultOptions.verbose = false;
|
|
||||||
DefaultOptions.haltnop = true;
|
|
||||||
DefaultOptions.exportall = false;
|
|
||||||
DefaultOptions.warnings = true;
|
|
||||||
|
|
||||||
opt_SetCurrentOptions(&DefaultOptions);
|
oGeneratePhonyDeps = false;
|
||||||
|
oGeneratedMissingIncludes = false;
|
||||||
|
oFailedOnMissingInclude = false;
|
||||||
|
tzTargetFileName = NULL;
|
||||||
|
|
||||||
newopt = CurrentOptions;
|
opt_B("01");
|
||||||
|
opt_G("0123");
|
||||||
|
opt_P(0);
|
||||||
|
optimizeloads = true;
|
||||||
|
haltnop = true;
|
||||||
|
verbose = false;
|
||||||
|
warnings = true;
|
||||||
|
sym_SetExportAll(false);
|
||||||
|
uint32_t maxRecursionDepth = 64;
|
||||||
|
size_t nTargetFileNameLen = 0;
|
||||||
|
|
||||||
while ((ch = getopt(argc, argv, "b:D:g:hi:o:p:vEw")) != -1) {
|
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(1, "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 'g':
|
*equals = '\0';
|
||||||
if (strlen(optarg) == 4) {
|
sym_AddString(musl_optarg, equals + 1);
|
||||||
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 "
|
sym_AddString(musl_optarg, "1");
|
||||||
"option 'g'");
|
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case 'h':
|
|
||||||
newopt.haltnop = false;
|
|
||||||
break;
|
|
||||||
case 'i':
|
|
||||||
fstk_AddIncludePath(optarg);
|
|
||||||
break;
|
|
||||||
case 'o':
|
|
||||||
out_SetFileName(optarg);
|
|
||||||
break;
|
|
||||||
case 'p':
|
|
||||||
newopt.fillchar = strtoul(optarg, &ep, 0);
|
|
||||||
if (optarg[0] == '\0' || *ep != '\0') {
|
|
||||||
errx(1, "Invalid argument for option 'p'");
|
|
||||||
}
|
|
||||||
if (newopt.fillchar < 0 || newopt.fillchar > 0xFF) {
|
|
||||||
errx(1, "Argument for option 'p' must be "
|
|
||||||
"between 0 and 0xFF");
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
case 'v':
|
|
||||||
newopt.verbose = true;
|
|
||||||
break;
|
|
||||||
case 'E':
|
case 'E':
|
||||||
newopt.exportall = true;
|
sym_SetExportAll(true);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
case 'g':
|
||||||
|
if (strlen(musl_optarg) == 4)
|
||||||
|
opt_G(&musl_optarg[1]);
|
||||||
|
else
|
||||||
|
errx(1, "Must specify exactly 4 characters for option 'g'");
|
||||||
|
break;
|
||||||
|
|
||||||
|
case 'h':
|
||||||
|
haltnop = false;
|
||||||
|
break;
|
||||||
|
|
||||||
|
case 'i':
|
||||||
|
fstk_AddIncludePath(musl_optarg);
|
||||||
|
break;
|
||||||
|
|
||||||
|
case 'L':
|
||||||
|
optimizeloads = false;
|
||||||
|
break;
|
||||||
|
|
||||||
|
case 'M':
|
||||||
|
if (!strcmp("-", musl_optarg))
|
||||||
|
dependfile = stdout;
|
||||||
|
else
|
||||||
|
dependfile = fopen(musl_optarg, "w");
|
||||||
|
if (dependfile == NULL)
|
||||||
|
err(1, "Could not open dependfile %s", musl_optarg);
|
||||||
|
break;
|
||||||
|
|
||||||
|
case 'o':
|
||||||
|
out_SetFileName(musl_optarg);
|
||||||
|
break;
|
||||||
|
|
||||||
|
unsigned long fill;
|
||||||
|
case 'p':
|
||||||
|
fill = strtoul(musl_optarg, &ep, 0);
|
||||||
|
|
||||||
|
if (musl_optarg[0] == '\0' || *ep != '\0')
|
||||||
|
errx(1, "Invalid argument for option 'p'");
|
||||||
|
|
||||||
|
if (fill < 0 || fill > 0xFF)
|
||||||
|
errx(1, "Argument for option 'p' must be between 0 and 0xFF");
|
||||||
|
|
||||||
|
opt_P(fill);
|
||||||
|
break;
|
||||||
|
|
||||||
|
case 'r':
|
||||||
|
maxRecursionDepth = strtoul(musl_optarg, &ep, 0);
|
||||||
|
|
||||||
|
if (musl_optarg[0] == '\0' || *ep != '\0')
|
||||||
|
errx(1, "Invalid argument for option 'r'");
|
||||||
|
break;
|
||||||
|
|
||||||
|
case 'V':
|
||||||
|
printf("rgbasm %s\n", get_package_version_string());
|
||||||
|
exit(0);
|
||||||
|
case 'v':
|
||||||
|
verbose = true;
|
||||||
|
break;
|
||||||
|
|
||||||
|
case 'W':
|
||||||
|
processWarningFlag(musl_optarg);
|
||||||
|
break;
|
||||||
|
|
||||||
case 'w':
|
case 'w':
|
||||||
newopt.warnings = false;
|
warnings = false;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
/* Long-only options */
|
||||||
|
case 0:
|
||||||
|
switch (depType) {
|
||||||
|
case 'G':
|
||||||
|
oGeneratedMissingIncludes = true;
|
||||||
|
break;
|
||||||
|
|
||||||
|
case 'P':
|
||||||
|
oGeneratePhonyDeps = true;
|
||||||
|
break;
|
||||||
|
|
||||||
|
case 'Q':
|
||||||
|
case 'T':
|
||||||
|
if (musl_optind == argc)
|
||||||
|
errx(1, "-M%c takes a target file name argument", depType);
|
||||||
|
ep = musl_optarg;
|
||||||
|
if (depType == 'Q')
|
||||||
|
ep = make_escape(ep);
|
||||||
|
|
||||||
|
nTargetFileNameLen += strlen(ep) + 1;
|
||||||
|
if (!tzTargetFileName) {
|
||||||
|
/* On first alloc, make an empty str */
|
||||||
|
tzTargetFileName = malloc(nTargetFileNameLen + 1);
|
||||||
|
if (tzTargetFileName)
|
||||||
|
*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')
|
||||||
|
free(ep);
|
||||||
|
char *ptr = tzTargetFileName + strlen(tzTargetFileName);
|
||||||
|
|
||||||
|
*ptr++ = ' ';
|
||||||
|
*ptr = '\0';
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
|
/* Unrecognized options */
|
||||||
default:
|
default:
|
||||||
usage();
|
print_usage();
|
||||||
|
/* NOTREACHED */
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
argc -= optind;
|
|
||||||
argv += optind;
|
|
||||||
|
|
||||||
opt_SetCurrentOptions(&newopt);
|
if (tzTargetFileName == NULL)
|
||||||
|
tzTargetFileName = tzObjectname;
|
||||||
|
|
||||||
DefaultOptions = CurrentOptions;
|
if (argc == musl_optind) {
|
||||||
|
fputs("FATAL: No input files\n", stderr);
|
||||||
if (argc == 0)
|
print_usage();
|
||||||
usage();
|
} else if (argc != musl_optind + 1) {
|
||||||
|
fputs("FATAL: More than one input file given\n", stderr);
|
||||||
tzMainfile = argv[argc - 1];
|
print_usage();
|
||||||
|
|
||||||
setuplex();
|
|
||||||
|
|
||||||
if (CurrentOptions.verbose) {
|
|
||||||
printf("Assembling %s\n", tzMainfile);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
nStartClock = clock();
|
char const *mainFileName = argv[musl_optind];
|
||||||
|
|
||||||
nLineNo = 1;
|
if (verbose)
|
||||||
nTotalLines = 0;
|
printf("Assembling %s\n", mainFileName);
|
||||||
nIFDepth = 0;
|
|
||||||
nPC = 0;
|
|
||||||
nPass = 1;
|
|
||||||
nErrors = 0;
|
|
||||||
sym_PrepPass1();
|
|
||||||
sym_SetExportAll(CurrentOptions.exportall);
|
|
||||||
fstk_Init(tzMainfile);
|
|
||||||
opt_ParseDefines();
|
|
||||||
|
|
||||||
if (CurrentOptions.verbose) {
|
if (dependfile) {
|
||||||
printf("Pass 1...\n");
|
if (!tzTargetFileName)
|
||||||
|
errx(1, "Dependency files can only be created if a target file is specified with either -o, -MQ or -MT\n");
|
||||||
|
|
||||||
|
fprintf(dependfile, "%s: %s\n", tzTargetFileName, mainFileName);
|
||||||
}
|
}
|
||||||
|
|
||||||
yy_set_state(LEX_STATE_NORMAL);
|
charmap_New("main", NULL);
|
||||||
opt_SetCurrentOptions(&DefaultOptions);
|
|
||||||
|
|
||||||
if (yyparse() != 0 || nErrors != 0) {
|
// Init lexer and file stack, prodiving file info
|
||||||
errx(1, "Assembly aborted in pass 1 (%ld errors)!", nErrors);
|
lexer_Init();
|
||||||
}
|
fstk_Init(mainFileName, maxRecursionDepth);
|
||||||
|
|
||||||
if (nIFDepth != 0) {
|
// Perform parse (yyparse is auto-generated from `parser.y`)
|
||||||
errx(1, "Unterminated IF construct (%ld levels)!", nIFDepth);
|
if (yyparse() != 0 && nbErrors == 0)
|
||||||
}
|
nbErrors = 1;
|
||||||
|
|
||||||
nTotalLines = 0;
|
if (dependfile)
|
||||||
nLineNo = 1;
|
fclose(dependfile);
|
||||||
nIFDepth = 0;
|
|
||||||
nPC = 0;
|
|
||||||
nPass = 2;
|
|
||||||
nErrors = 0;
|
|
||||||
sym_PrepPass2();
|
|
||||||
out_PrepPass2();
|
|
||||||
fstk_Init(tzMainfile);
|
|
||||||
yy_set_state(LEX_STATE_NORMAL);
|
|
||||||
opt_SetCurrentOptions(&DefaultOptions);
|
|
||||||
opt_ParseDefines();
|
|
||||||
|
|
||||||
if (CurrentOptions.verbose) {
|
sect_CheckUnionClosed();
|
||||||
printf("Pass 2...\n");
|
|
||||||
}
|
|
||||||
|
|
||||||
if (yyparse() != 0 || nErrors != 0) {
|
if (nbErrors != 0)
|
||||||
errx(1, "Assembly aborted in pass 2 (%ld errors)!", nErrors);
|
errx(1, "Assembly aborted (%u error%s)!", nbErrors,
|
||||||
}
|
nbErrors == 1 ? "" : "s");
|
||||||
|
|
||||||
double timespent;
|
// If parse aborted due to missing an include, and `-MG` was given, exit normally
|
||||||
|
if (oFailedOnMissingInclude)
|
||||||
|
return 0;
|
||||||
|
|
||||||
nEndClock = clock();
|
/* If no path specified, don't write file */
|
||||||
timespent = ((double)(nEndClock - nStartClock))
|
if (tzObjectname != NULL)
|
||||||
/ (double)CLOCKS_PER_SEC;
|
out_WriteObject();
|
||||||
if (CurrentOptions.verbose) {
|
|
||||||
printf("Success! %ld lines in %d.%02d seconds ", nTotalLines,
|
|
||||||
(int) timespent, ((int) (timespent * 100.0)) % 100);
|
|
||||||
if (timespent == 0)
|
|
||||||
printf("(INFINITY lines/minute)\n");
|
|
||||||
else
|
|
||||||
printf("(%d lines/minute)\n",
|
|
||||||
(int) (60 / timespent * nTotalLines));
|
|
||||||
}
|
|
||||||
out_WriteObject();
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|||||||
-148
@@ -1,148 +0,0 @@
|
|||||||
/*
|
|
||||||
* Fixedpoint math routines
|
|
||||||
*/
|
|
||||||
|
|
||||||
#include <math.h>
|
|
||||||
#include <stdio.h>
|
|
||||||
|
|
||||||
#include "types.h"
|
|
||||||
#include "asm/mymath.h"
|
|
||||||
#include "asm/symbol.h"
|
|
||||||
|
|
||||||
#define fix2double(i) ((double)(i/65536.0))
|
|
||||||
#define double2fix(d) ((SLONG)(d*65536.0))
|
|
||||||
#ifndef PI
|
|
||||||
#define PI (acos(-1))
|
|
||||||
#endif
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Define the _PI symbol
|
|
||||||
*/
|
|
||||||
void
|
|
||||||
math_DefinePI(void)
|
|
||||||
{
|
|
||||||
sym_AddEqu("_PI", double2fix(PI));
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Print a fixed point value
|
|
||||||
*/
|
|
||||||
void
|
|
||||||
math_Print(SLONG i)
|
|
||||||
{
|
|
||||||
if (i >= 0)
|
|
||||||
printf("%ld.%05ld", i >> 16,
|
|
||||||
((SLONG) (fix2double(i) * 100000 + 0.5)) % 100000);
|
|
||||||
else
|
|
||||||
printf("-%ld.%05ld", (-i) >> 16,
|
|
||||||
((SLONG) (fix2double(-i) * 100000 + 0.5)) % 100000);
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Calculate sine
|
|
||||||
*/
|
|
||||||
SLONG
|
|
||||||
math_Sin(SLONG i)
|
|
||||||
{
|
|
||||||
return (double2fix(sin(fix2double(i) * 2 * PI / 65536)));
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Calculate cosine
|
|
||||||
*/
|
|
||||||
SLONG
|
|
||||||
math_Cos(SLONG i)
|
|
||||||
{
|
|
||||||
return (double2fix(cos(fix2double(i) * 2 * PI / 65536)));
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Calculate tangent
|
|
||||||
*/
|
|
||||||
SLONG
|
|
||||||
math_Tan(SLONG i)
|
|
||||||
{
|
|
||||||
return (double2fix(tan(fix2double(i) * 2 * PI / 65536)));
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Calculate arcsine
|
|
||||||
*/
|
|
||||||
SLONG
|
|
||||||
math_ASin(SLONG i)
|
|
||||||
{
|
|
||||||
return (double2fix(asin(fix2double(i)) / 2 / PI * 65536));
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Calculate arccosine
|
|
||||||
*/
|
|
||||||
SLONG
|
|
||||||
math_ACos(SLONG i)
|
|
||||||
{
|
|
||||||
return (double2fix(acos(fix2double(i)) / 2 / PI * 65536));
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Calculate arctangent
|
|
||||||
*/
|
|
||||||
SLONG
|
|
||||||
math_ATan(SLONG i)
|
|
||||||
{
|
|
||||||
return (double2fix(atan(fix2double(i)) / 2 / PI * 65536));
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Calculate atan2
|
|
||||||
*/
|
|
||||||
SLONG
|
|
||||||
math_ATan2(SLONG i, SLONG j)
|
|
||||||
{
|
|
||||||
return (double2fix
|
|
||||||
(atan2(fix2double(i), fix2double(j)) / 2 / PI * 65536));
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Multiplication
|
|
||||||
*/
|
|
||||||
SLONG
|
|
||||||
math_Mul(SLONG i, SLONG j)
|
|
||||||
{
|
|
||||||
return (double2fix(fix2double(i) * fix2double(j)));
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Division
|
|
||||||
*/
|
|
||||||
SLONG
|
|
||||||
math_Div(SLONG i, SLONG j)
|
|
||||||
{
|
|
||||||
return (double2fix(fix2double(i) / fix2double(j)));
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Round
|
|
||||||
*/
|
|
||||||
SLONG
|
|
||||||
math_Round(SLONG i)
|
|
||||||
{
|
|
||||||
return double2fix(round(fix2double(i)));
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Ceil
|
|
||||||
*/
|
|
||||||
SLONG
|
|
||||||
math_Ceil(SLONG i)
|
|
||||||
{
|
|
||||||
return double2fix(ceil(fix2double(i)));
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Floor
|
|
||||||
*/
|
|
||||||
SLONG
|
|
||||||
math_Floor(SLONG i)
|
|
||||||
{
|
|
||||||
return double2fix(floor(fix2double(i)));
|
|
||||||
}
|
|
||||||
+111
@@ -0,0 +1,111 @@
|
|||||||
|
|
||||||
|
#include <errno.h>
|
||||||
|
#include <stdbool.h>
|
||||||
|
#include <stdint.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <string.h>
|
||||||
|
|
||||||
|
#include "asm/lexer.h"
|
||||||
|
#include "asm/section.h"
|
||||||
|
#include "asm/warning.h"
|
||||||
|
|
||||||
|
struct OptStackEntry {
|
||||||
|
char binary[2];
|
||||||
|
char gbgfx[4];
|
||||||
|
int32_t fillByte;
|
||||||
|
struct OptStackEntry *next;
|
||||||
|
};
|
||||||
|
|
||||||
|
static struct OptStackEntry *stack = NULL;
|
||||||
|
|
||||||
|
void opt_B(char chars[2])
|
||||||
|
{
|
||||||
|
lexer_SetBinDigits(chars);
|
||||||
|
}
|
||||||
|
|
||||||
|
void opt_G(char chars[4])
|
||||||
|
{
|
||||||
|
lexer_SetGfxDigits(chars);
|
||||||
|
}
|
||||||
|
|
||||||
|
void opt_P(uint8_t fill)
|
||||||
|
{
|
||||||
|
fillByte = fill;
|
||||||
|
}
|
||||||
|
|
||||||
|
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;
|
||||||
|
|
||||||
|
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->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);
|
||||||
|
stack = entry->next;
|
||||||
|
free(entry);
|
||||||
|
}
|
||||||
+396
-756
File diff suppressed because it is too large
Load Diff
+2223
File diff suppressed because it is too large
Load Diff
+237
-47
@@ -1,86 +1,278 @@
|
|||||||
.\" Copyright © 2010 Anthony J. Bentley <[email protected]>
|
|
||||||
.\"
|
.\"
|
||||||
.\" Permission to use, copy, modify, and distribute this software for any
|
.\" This file is part of RGBDS.
|
||||||
.\" purpose with or without fee is hereby granted, provided that the above
|
|
||||||
.\" copyright notice and this permission notice appear in all copies.
|
|
||||||
.\"
|
.\"
|
||||||
.\" THE SOFTWARE IS PROVIDED “AS IS” AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
.\" Copyright (c) 2010-2021, Anthony J. Bentley and RGBDS contributors.
|
||||||
.\" WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
|
||||||
.\" MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
|
||||||
.\" ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
|
||||||
.\" WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
|
||||||
.\" ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
|
||||||
.\" OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
|
||||||
.\"
|
.\"
|
||||||
.Dd April 17, 2017
|
.\" SPDX-License-Identifier: MIT
|
||||||
|
.\"
|
||||||
|
.Dd March 28, 2021
|
||||||
.Dt RGBASM 1
|
.Dt RGBASM 1
|
||||||
.Os RGBDS Manual
|
.Os
|
||||||
.Sh NAME
|
.Sh NAME
|
||||||
.Nm rgbasm
|
.Nm rgbasm
|
||||||
.Nd Game Boy assembler
|
.Nd Game Boy assembler
|
||||||
.Sh SYNOPSIS
|
.Sh SYNOPSIS
|
||||||
.Nm rgbasm
|
.Nm
|
||||||
.Op Fl Ehvw
|
.Op Fl EhLVvw
|
||||||
.Op Fl b Ar chars
|
.Op Fl b Ar chars
|
||||||
.Op Fl D Ar name Ns Op = Ns Ar value
|
.Op Fl D Ar name Ns Op = Ns Ar value
|
||||||
.Op Fl g Ar chars
|
.Op Fl g Ar chars
|
||||||
.Op Fl i Ar path
|
.Op Fl i Ar path
|
||||||
.Op Fl o Ar outfile
|
.Op Fl M Ar depend_file
|
||||||
|
.Op Fl MG
|
||||||
|
.Op Fl MP
|
||||||
|
.Op Fl MT Ar target_file
|
||||||
|
.Op Fl MQ Ar target_file
|
||||||
|
.Op Fl o Ar out_file
|
||||||
.Op Fl p Ar pad_value
|
.Op Fl p Ar pad_value
|
||||||
.Ar file
|
.Op Fl r Ar recursion_depth
|
||||||
|
.Op Fl W Ar warning
|
||||||
|
.Ar
|
||||||
.Sh DESCRIPTION
|
.Sh DESCRIPTION
|
||||||
The
|
The
|
||||||
.Nm
|
.Nm
|
||||||
program creates an object file from an assembly source file.
|
program creates an RGB object file from an assembly source file.
|
||||||
Its arguments are as follows:
|
The input
|
||||||
|
.Ar file
|
||||||
|
can be a file path, or
|
||||||
|
.Cm \-
|
||||||
|
denoting
|
||||||
|
.Cm stdin .
|
||||||
|
.Pp
|
||||||
|
Note that options can be abbreviated as long as the abbreviation is unambiguous:
|
||||||
|
.Fl Fl verb
|
||||||
|
is
|
||||||
|
.Fl Fl verbose ,
|
||||||
|
but
|
||||||
|
.Fl Fl ver
|
||||||
|
is invalid because it could also be
|
||||||
|
.Fl Fl version .
|
||||||
|
The arguments are as follows:
|
||||||
.Bl -tag -width Ds
|
.Bl -tag -width Ds
|
||||||
.It Fl b Ar chars
|
.It Fl b Ar chars , Fl Fl binary-digits Ar chars
|
||||||
Change the two characters used for binary constants.
|
Change the two characters used for binary constants.
|
||||||
The defaults are 01.
|
The defaults are 01.
|
||||||
.It Fl D Ar name Ns Op = Ns Ar value
|
.It Fl D Ar name Ns Oo = Ns Ar value Oc , Fl Fl define Ar name Ns Oo = Ns Ar value Oc
|
||||||
Add string symbol to the compiled source code. This is equivalent to
|
Add a string symbol to the compiled source code.
|
||||||
.Ar name
|
This is equivalent to
|
||||||
.Cm EQUS
|
.Ql Ar name Ic EQUS \(dq Ns Ar value Ns \(dq
|
||||||
.Qq Ar "value"
|
in code, or
|
||||||
in code. If a value is not specified, a value of 1 is given.
|
.Ql Ar name Ic EQUS \(dq1\(dq
|
||||||
.It Fl E
|
if
|
||||||
|
.Ar value
|
||||||
|
is not specified.
|
||||||
|
.It Fl E , Fl Fl export-all
|
||||||
Export all labels, including unreferenced and local labels.
|
Export all labels, including unreferenced and local labels.
|
||||||
.It Fl g Ar chars
|
.It Fl g Ar chars , Fl Fl gfx-chars Ar chars
|
||||||
Change the four characters used for binary constants.
|
Change the four characters used for gfx constants.
|
||||||
The defaults are 0123.
|
The defaults are 0123.
|
||||||
.It Fl h
|
.It Fl h , Fl Fl halt-without-nop
|
||||||
By default,
|
By default,
|
||||||
.Nm
|
.Nm
|
||||||
inserts a
|
inserts a
|
||||||
.Sq nop
|
.Ic nop
|
||||||
instruction immediately after any
|
instruction immediately after any
|
||||||
.Sq halt
|
.Ic halt
|
||||||
instruction.
|
instruction.
|
||||||
The
|
The
|
||||||
.Fl h
|
.Fl h
|
||||||
option disables this behavior.
|
option disables this behavior.
|
||||||
.It Fl i Ar path
|
.It Fl i Ar path , Fl Fl include Ar path
|
||||||
Add an include path.
|
Add an include path.
|
||||||
.It Fl o Ar outfile
|
.It Fl L , Fl Fl preserve-ld
|
||||||
|
Disable the optimization that turns loads of the form
|
||||||
|
.Ic LD [$FF00+n8],A
|
||||||
|
into the opcode
|
||||||
|
.Ic LD [H $FF00+n8],A
|
||||||
|
in order to have full control of the result in the final ROM.
|
||||||
|
.It Fl M Ar depend_file , Fl Fl dependfile Ar depend_file
|
||||||
|
Print
|
||||||
|
.Xr make 1
|
||||||
|
dependencies to
|
||||||
|
.Ar depend_file .
|
||||||
|
.It Fl MG
|
||||||
|
To be used in conjunction with
|
||||||
|
.Fl M .
|
||||||
|
This makes
|
||||||
|
.Nm
|
||||||
|
assume that missing files are auto-generated: when
|
||||||
|
.Ic INCLUDE
|
||||||
|
or
|
||||||
|
.Ic INCBIN
|
||||||
|
is attempted on a non-existent file, it is added as a dependency, then
|
||||||
|
.Nm
|
||||||
|
exits normally instead of erroring out.
|
||||||
|
This feature is used in automatic updating of makefiles.
|
||||||
|
.It Fl MP
|
||||||
|
When enabled, this causes a phony target to be added for each dependency other than the main file.
|
||||||
|
This prevents
|
||||||
|
.Xr make 1
|
||||||
|
from erroring out when dependency files are deleted.
|
||||||
|
.It Fl MT Ar target_file
|
||||||
|
Add a target to the rules emitted by
|
||||||
|
.Fl M .
|
||||||
|
The exact string provided will be written, including spaces and special characters.
|
||||||
|
.Dl Fl MT No fileA Fl MT No fileB
|
||||||
|
is equivalent to
|
||||||
|
.Dl Fl MT No 'fileA fileB' .
|
||||||
|
If neither this nor
|
||||||
|
.Fl MQ
|
||||||
|
is specified, the output file name is used.
|
||||||
|
.It Fl MQ Ar target_file
|
||||||
|
Same as
|
||||||
|
.Fl MT ,
|
||||||
|
but additionally escapes any special
|
||||||
|
.Xr make 1
|
||||||
|
characters, essentially
|
||||||
|
.Sq $ .
|
||||||
|
.It Fl o Ar out_file , Fl Fl output Ar out_file
|
||||||
Write an object file to the given filename.
|
Write an object file to the given filename.
|
||||||
.It Fl p Ar pad_value
|
.It Fl p Ar pad_value , Fl Fl pad-value Ar pad_value
|
||||||
When padding an image, pad with this value.
|
When padding an image, pad with this value.
|
||||||
The default is 0x00.
|
The default is 0x00.
|
||||||
.It Fl v
|
.It Fl r Ar recursion_depth , Fl Fl recursion-depth Ar recursion_depth
|
||||||
|
Specifies the recursion depth at which RGBASM will assume being in an infinite loop.
|
||||||
|
.It Fl V , Fl Fl version
|
||||||
|
Print the version of the program and exit.
|
||||||
|
.It Fl v , Fl Fl verbose
|
||||||
Be verbose.
|
Be verbose.
|
||||||
|
.It Fl W Ar warning , Fl Fl warning Ar warning
|
||||||
|
Set warning flag
|
||||||
|
.Ar warning .
|
||||||
|
A warning message will be printed if
|
||||||
|
.Ar warning
|
||||||
|
is an unknown warning flag.
|
||||||
|
See the
|
||||||
|
.Sx DIAGNOSTICS
|
||||||
|
section for a list of warnings.
|
||||||
.It Fl w
|
.It Fl w
|
||||||
Disable warning output.
|
Disable all warning output, even when turned into errors.
|
||||||
|
.El
|
||||||
|
.Sh DIAGNOSTICS
|
||||||
|
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.
|
||||||
|
.Bl -tag -width Ds
|
||||||
|
.It Fl Werror
|
||||||
|
Make all warnings into errors.
|
||||||
|
.It Fl Werror=
|
||||||
|
Make the specified warning into an error.
|
||||||
|
A warning's name is appended
|
||||||
|
.Pq example: Fl Werror=obsolete ,
|
||||||
|
and this warning is implicitly enabled and turned into an error.
|
||||||
|
This is an error if used with a meta warning, such as
|
||||||
|
.Fl Werror=all .
|
||||||
|
.El
|
||||||
|
.Pp
|
||||||
|
The following warnings are
|
||||||
|
.Dq 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.
|
||||||
|
.Bl -tag -width Ds
|
||||||
|
.It Fl Wall
|
||||||
|
This enables warnings that are likely to indicate an error or undesired behavior, and that can easily be fixed.
|
||||||
|
.It Fl Wextra
|
||||||
|
This enables extra warnings that are less likely to pose a problem, but that may still be wanted.
|
||||||
|
.It Fl Weverything
|
||||||
|
Enables literally every warning.
|
||||||
|
.El
|
||||||
|
.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,
|
||||||
|
.Fl Wcharmap-redef
|
||||||
|
enables the warning that
|
||||||
|
.Fl Wno-charmap-redef
|
||||||
|
disables).
|
||||||
|
Only the non-default flag is listed here.
|
||||||
|
Ignoring the
|
||||||
|
.Dq no-
|
||||||
|
prefix, entries are listed alphabetically.
|
||||||
|
.Bl -tag -width Ds
|
||||||
|
.It Fl Wno-assert
|
||||||
|
Warns when
|
||||||
|
.Ic WARN Ns No -type
|
||||||
|
assertions fail. (See
|
||||||
|
.Dq Aborting the assembly process
|
||||||
|
in
|
||||||
|
.Xr rgbasm 5
|
||||||
|
for
|
||||||
|
.Ic ASSERT ) .
|
||||||
|
.It Fl Wbuiltin-args
|
||||||
|
Warn about incorrect arguments to built-in functions, such as
|
||||||
|
.Fn STRSUB
|
||||||
|
with indexes outside of the string's bounds.
|
||||||
|
This warning is enabled by
|
||||||
|
.Fl Wall .
|
||||||
|
.It Fl Wcharmap-redef
|
||||||
|
Warn when re-defining a charmap mapping.
|
||||||
|
This warning is enabled by
|
||||||
|
.Fl Wall .
|
||||||
|
.It Fl Wdiv
|
||||||
|
Warn when dividing the smallest negative integer by -1, which yields itself due to integer overflow.
|
||||||
|
.It Fl Wempty-macro-arg
|
||||||
|
Warn when a macro argument is empty.
|
||||||
|
This warning is enabled by
|
||||||
|
.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
|
||||||
|
Warn when a constant too large to fit in a signed 32-bit integer is encountered.
|
||||||
|
This warning is enabled by
|
||||||
|
.Fl Wall .
|
||||||
|
.It Fl Wlong-string
|
||||||
|
Warn when a string too long to fit in internal buffers is encountered.
|
||||||
|
This warning is enabled by
|
||||||
|
.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
|
||||||
|
Warn when obsolete constructs such as the
|
||||||
|
.Ic _PI
|
||||||
|
constant or
|
||||||
|
.Ic PRINTT
|
||||||
|
directive are encountered.
|
||||||
|
.It Fl Wshift
|
||||||
|
Warn when shifting right a negative value.
|
||||||
|
Use a division by 2^N instead.
|
||||||
|
.It Fl Wshift-amount
|
||||||
|
Warn when a shift's operand is negative or greater than 32.
|
||||||
|
.It Fl Wno-truncation
|
||||||
|
Warn when an implicit truncation (for example,
|
||||||
|
.Ic LD [B @] )
|
||||||
|
loses some bits.
|
||||||
|
.It Fl Wno-user
|
||||||
|
Warn when the
|
||||||
|
.Ic WARN
|
||||||
|
built-in is executed. (See
|
||||||
|
.Dq Aborting the assembly process
|
||||||
|
in
|
||||||
|
.Xr rgbasm 5
|
||||||
|
for
|
||||||
|
.Ic WARN ) .
|
||||||
.El
|
.El
|
||||||
.Sh EXAMPLES
|
.Sh EXAMPLES
|
||||||
Assembling a basic source file is simple:
|
You can assemble a source file in two ways.
|
||||||
.Pp
|
.Pp
|
||||||
.D1 $ rgbasm -o bar.o foo.asm
|
Straightforward way:
|
||||||
|
.Dl $ rgbasm -o bar.o foo.asm
|
||||||
.Pp
|
.Pp
|
||||||
The resulting object file is not yet a usable ROM image \(em it must first be
|
Pipes way:
|
||||||
run through
|
.Dl $ cat foo.asm | rgbasm -o bar.o -
|
||||||
|
.Dl $ rgbasm -o bar.o - < foo.asm
|
||||||
|
.Pp
|
||||||
|
The resulting object file is not yet a usable ROM image\(emit must first be run through
|
||||||
.Xr rgblink 1
|
.Xr rgblink 1
|
||||||
and
|
and then
|
||||||
.Xr rgbfix 1 .
|
.Xr rgbfix 1 .
|
||||||
|
.Sh BUGS
|
||||||
|
Please report bugs on
|
||||||
|
.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 ,
|
||||||
@@ -88,10 +280,8 @@ and
|
|||||||
.Xr rgbds 5 ,
|
.Xr rgbds 5 ,
|
||||||
.Xr rgbds 7 ,
|
.Xr rgbds 7 ,
|
||||||
.Xr gbz80 7
|
.Xr gbz80 7
|
||||||
.Pp
|
|
||||||
.Lk https://rednex.github.io/rgbds/asm.htm rgbasm assembly commands
|
|
||||||
.Sh HISTORY
|
.Sh HISTORY
|
||||||
.Nm
|
.Nm
|
||||||
was originally written by Carsten S\(/orensen as part of the ASMotor package,
|
was originally written by Carsten S\(/orensen as part of the ASMotor package, and was later packaged in RGBDS by Justin Lloyd.
|
||||||
and was later packaged in RGBDS by Justin Lloyd. It is now maintained by a
|
It is now maintained by a number of contributors at
|
||||||
number of contributors at https://github.com/rednex/rgbds.
|
.Lk https://github.com/gbdev/rgbds .
|
||||||
|
|||||||
+1732
-785
File diff suppressed because it is too large
Load Diff
+477
-317
@@ -1,367 +1,527 @@
|
|||||||
|
/*
|
||||||
|
* This file is part of RGBDS.
|
||||||
|
*
|
||||||
|
* Copyright (c) 1997-2018, Carsten Sorensen and RGBDS contributors.
|
||||||
|
*
|
||||||
|
* SPDX-License-Identifier: MIT
|
||||||
|
*/
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Controls RPN expressions for objectfiles
|
* Controls RPN expressions for objectfiles
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#include <assert.h>
|
||||||
|
#include <errno.h>
|
||||||
|
#include <inttypes.h>
|
||||||
|
#include <stdint.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
#include <stdlib.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
#include "asm/mylink.h"
|
|
||||||
#include "types.h"
|
|
||||||
#include "asm/symbol.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/symbol.h"
|
||||||
|
#include "asm/warning.h"
|
||||||
|
|
||||||
void
|
#include "opmath.h"
|
||||||
mergetwoexpressions(struct Expression * expr, struct Expression * src1,
|
|
||||||
struct Expression * src2)
|
/* Makes an expression "not known", also setting its error message */
|
||||||
|
#define makeUnknown(expr_, ...) do { \
|
||||||
|
struct Expression *_expr = expr_; \
|
||||||
|
_expr->isKnown = false; \
|
||||||
|
/* If we had `asprintf` this would be great, but alas. */ \
|
||||||
|
_expr->reason = malloc(128); /* Use an initial reasonable size */ \
|
||||||
|
if (!_expr->reason) \
|
||||||
|
fatalerror("Can't allocate err string: %s\n", strerror(errno)); \
|
||||||
|
int size = snprintf(_expr->reason, 128, __VA_ARGS__); \
|
||||||
|
if (size >= 128) { /* If this wasn't enough, try again */ \
|
||||||
|
_expr->reason = realloc(_expr->reason, size + 1); \
|
||||||
|
sprintf(_expr->reason, __VA_ARGS__); \
|
||||||
|
} \
|
||||||
|
} while (0)
|
||||||
|
|
||||||
|
static uint8_t *reserveSpace(struct Expression *expr, uint32_t size)
|
||||||
{
|
{
|
||||||
*expr = *src1;
|
/* This assumes the RPN length is always less than the capacity */
|
||||||
memcpy(&(expr->tRPN[expr->nRPNLength]), src2->tRPN, src2->nRPNLength);
|
if (expr->nRPNCapacity - expr->nRPNLength < size) {
|
||||||
|
/* If there isn't enough room to reserve the space, realloc */
|
||||||
|
if (!expr->tRPN)
|
||||||
|
expr->nRPNCapacity = 256; /* Initial size */
|
||||||
|
while (expr->nRPNCapacity - expr->nRPNLength < size) {
|
||||||
|
if (expr->nRPNCapacity >= MAXRPNLEN)
|
||||||
|
/*
|
||||||
|
* To avoid generating humongous object files, cap the
|
||||||
|
* size of RPN expressions
|
||||||
|
*/
|
||||||
|
fatalerror("RPN expression cannot grow larger than "
|
||||||
|
EXPAND_AND_STR(MAXRPNLEN) " bytes\n");
|
||||||
|
else if (expr->nRPNCapacity > MAXRPNLEN / 2)
|
||||||
|
expr->nRPNCapacity = MAXRPNLEN;
|
||||||
|
else
|
||||||
|
expr->nRPNCapacity *= 2;
|
||||||
|
}
|
||||||
|
expr->tRPN = realloc(expr->tRPN, expr->nRPNCapacity);
|
||||||
|
|
||||||
expr->nRPNLength += src2->nRPNLength;
|
if (!expr->tRPN)
|
||||||
expr->isReloc |= src2->isReloc;
|
fatalerror("Failed to grow RPN expression: %s\n", strerror(errno));
|
||||||
expr->isPCRel |= src2->isPCRel;
|
}
|
||||||
}
|
|
||||||
#define joinexpr() mergetwoexpressions(expr,src1,src2)
|
|
||||||
|
|
||||||
/*
|
uint8_t *ptr = expr->tRPN + expr->nRPNLength;
|
||||||
* Add a byte to the RPN expression
|
|
||||||
*/
|
expr->nRPNLength += size;
|
||||||
void
|
return ptr;
|
||||||
pushbyte(struct Expression * expr, int b)
|
|
||||||
{
|
|
||||||
expr->tRPN[expr->nRPNLength++] = b & 0xFF;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Reset the RPN module
|
* Init the RPN expression
|
||||||
*/
|
*/
|
||||||
void
|
static void rpn_Init(struct Expression *expr)
|
||||||
rpn_Reset(struct Expression * expr)
|
|
||||||
{
|
{
|
||||||
expr->nRPNLength = expr->nRPNOut = expr->isReloc = expr->isPCRel = 0;
|
expr->reason = NULL;
|
||||||
|
expr->isKnown = true;
|
||||||
|
expr->isSymbol = false;
|
||||||
|
expr->tRPN = NULL;
|
||||||
|
expr->nRPNCapacity = 0;
|
||||||
|
expr->nRPNLength = 0;
|
||||||
|
expr->nRPNPatchSize = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Returns the next rpn byte in expression
|
* Free the RPN expression
|
||||||
*/
|
*/
|
||||||
UWORD
|
void rpn_Free(struct Expression *expr)
|
||||||
rpn_PopByte(struct Expression * expr)
|
|
||||||
{
|
{
|
||||||
if (expr->nRPNOut == expr->nRPNLength) {
|
free(expr->tRPN);
|
||||||
return (0xDEAD);
|
free(expr->reason);
|
||||||
} else
|
rpn_Init(expr);
|
||||||
return (expr->tRPN[expr->nRPNOut++]);
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Determine if the current expression is relocatable
|
|
||||||
*/
|
|
||||||
ULONG
|
|
||||||
rpn_isReloc(struct Expression * expr)
|
|
||||||
{
|
|
||||||
return (expr->isReloc);
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Determine if the current expression can be pc-relative
|
|
||||||
*/
|
|
||||||
ULONG
|
|
||||||
rpn_isPCRelative(struct Expression * expr)
|
|
||||||
{
|
|
||||||
return (expr->isPCRel);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Add symbols, constants and operators to expression
|
* Add symbols, constants and operators to expression
|
||||||
*/
|
*/
|
||||||
void
|
void rpn_Number(struct Expression *expr, uint32_t i)
|
||||||
rpn_Number(struct Expression * expr, ULONG i)
|
|
||||||
{
|
{
|
||||||
rpn_Reset(expr);
|
rpn_Init(expr);
|
||||||
pushbyte(expr, RPN_CONST);
|
|
||||||
pushbyte(expr, i);
|
|
||||||
pushbyte(expr, i >> 8);
|
|
||||||
pushbyte(expr, i >> 16);
|
|
||||||
pushbyte(expr, i >> 24);
|
|
||||||
expr->nVal = i;
|
expr->nVal = i;
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void rpn_Symbol(struct Expression *expr, char const *tzSym)
|
||||||
rpn_Symbol(struct Expression * expr, char *tzSym)
|
|
||||||
{
|
{
|
||||||
if (!sym_isConstant(tzSym)) {
|
struct Symbol *sym = sym_FindScopedSymbol(tzSym);
|
||||||
struct sSymbol *psym;
|
|
||||||
|
|
||||||
rpn_Reset(expr);
|
if (sym_IsPC(sym) && !sect_GetSymbolSection()) {
|
||||||
|
error("PC has no value outside a section\n");
|
||||||
|
rpn_Number(expr, 0);
|
||||||
|
} else if (!sym || !sym_IsConstant(sym)) {
|
||||||
|
rpn_Init(expr);
|
||||||
|
expr->isSymbol = true;
|
||||||
|
|
||||||
psym = sym_FindSymbol(tzSym);
|
makeUnknown(expr, sym_IsPC(sym) ? "PC is not constant at assembly time"
|
||||||
|
: "'%s' is not constant at assembly time", tzSym);
|
||||||
|
sym = sym_Ref(tzSym);
|
||||||
|
expr->nRPNPatchSize += 5; /* 1-byte opcode + 4-byte symbol ID */
|
||||||
|
|
||||||
if (psym == NULL || psym->pSection == pCurrentSection
|
size_t nameLen = strlen(sym->name) + 1; /* Don't forget NUL! */
|
||||||
|| psym->pSection == NULL)
|
uint8_t *ptr = reserveSpace(expr, nameLen + 1);
|
||||||
expr->isPCRel = 1;
|
*ptr++ = RPN_SYM;
|
||||||
expr->isReloc = 1;
|
memcpy(ptr, sym->name, nameLen);
|
||||||
pushbyte(expr, RPN_SYM);
|
} else {
|
||||||
while (*tzSym)
|
|
||||||
pushbyte(expr, *tzSym++);
|
|
||||||
pushbyte(expr, 0);
|
|
||||||
} else
|
|
||||||
rpn_Number(expr, sym_GetConstantValue(tzSym));
|
rpn_Number(expr, sym_GetConstantValue(tzSym));
|
||||||
}
|
|
||||||
|
|
||||||
void
|
|
||||||
rpn_Bank(struct Expression * expr, char *tzSym)
|
|
||||||
{
|
|
||||||
if (!sym_isConstant(tzSym)) {
|
|
||||||
rpn_Reset(expr);
|
|
||||||
|
|
||||||
/* Check that the symbol exists by evaluating and discarding the value. */
|
|
||||||
sym_GetValue(tzSym);
|
|
||||||
|
|
||||||
expr->isReloc = 1;
|
|
||||||
pushbyte(expr, RPN_BANK);
|
|
||||||
while (*tzSym)
|
|
||||||
pushbyte(expr, *tzSym++);
|
|
||||||
pushbyte(expr, 0);
|
|
||||||
} else
|
|
||||||
yyerror("BANK argument must be a relocatable identifier");
|
|
||||||
}
|
|
||||||
|
|
||||||
void
|
|
||||||
rpn_CheckHRAM(struct Expression * expr, struct Expression * src)
|
|
||||||
{
|
|
||||||
*expr = *src;
|
|
||||||
pushbyte(expr, RPN_HRAM);
|
|
||||||
}
|
|
||||||
|
|
||||||
void
|
|
||||||
rpn_LOGNOT(struct Expression * expr, struct Expression * src)
|
|
||||||
{
|
|
||||||
*expr = *src;
|
|
||||||
pushbyte(expr, RPN_LOGUNNOT);
|
|
||||||
}
|
|
||||||
|
|
||||||
void
|
|
||||||
rpn_LOGOR(struct Expression * expr, struct Expression * src1,
|
|
||||||
struct Expression * src2)
|
|
||||||
{
|
|
||||||
joinexpr();
|
|
||||||
expr->nVal = (expr->nVal || src2->nVal);
|
|
||||||
pushbyte(expr, RPN_LOGOR);
|
|
||||||
}
|
|
||||||
|
|
||||||
void
|
|
||||||
rpn_LOGAND(struct Expression * expr, struct Expression * src1,
|
|
||||||
struct Expression * src2)
|
|
||||||
{
|
|
||||||
joinexpr();
|
|
||||||
expr->nVal = (expr->nVal && src2->nVal);
|
|
||||||
pushbyte(expr, RPN_LOGAND);
|
|
||||||
}
|
|
||||||
|
|
||||||
void
|
|
||||||
rpn_HIGH(struct Expression * expr, struct Expression * src)
|
|
||||||
{
|
|
||||||
*expr = *src;
|
|
||||||
|
|
||||||
expr->nVal = (expr->nVal >> 8) & 0xFF;
|
|
||||||
|
|
||||||
pushbyte(expr, RPN_CONST);
|
|
||||||
pushbyte(expr, 8);
|
|
||||||
pushbyte(expr, 0);
|
|
||||||
pushbyte(expr, 0);
|
|
||||||
pushbyte(expr, 0);
|
|
||||||
|
|
||||||
pushbyte(expr, RPN_SHR);
|
|
||||||
|
|
||||||
pushbyte(expr, RPN_CONST);
|
|
||||||
pushbyte(expr, 0xFF);
|
|
||||||
pushbyte(expr, 0);
|
|
||||||
pushbyte(expr, 0);
|
|
||||||
pushbyte(expr, 0);
|
|
||||||
|
|
||||||
pushbyte(expr, RPN_AND);
|
|
||||||
}
|
|
||||||
|
|
||||||
void
|
|
||||||
rpn_LOW(struct Expression * expr, struct Expression * src)
|
|
||||||
{
|
|
||||||
*expr = *src;
|
|
||||||
|
|
||||||
expr->nVal = expr->nVal & 0xFF;
|
|
||||||
|
|
||||||
pushbyte(expr, RPN_CONST);
|
|
||||||
pushbyte(expr, 0xFF);
|
|
||||||
pushbyte(expr, 0);
|
|
||||||
pushbyte(expr, 0);
|
|
||||||
pushbyte(expr, 0);
|
|
||||||
|
|
||||||
pushbyte(expr, RPN_AND);
|
|
||||||
}
|
|
||||||
|
|
||||||
void
|
|
||||||
rpn_LOGEQU(struct Expression * expr, struct Expression * src1,
|
|
||||||
struct Expression * src2)
|
|
||||||
{
|
|
||||||
joinexpr();
|
|
||||||
expr->nVal = (expr->nVal == src2->nVal);
|
|
||||||
pushbyte(expr, RPN_LOGEQ);
|
|
||||||
}
|
|
||||||
|
|
||||||
void
|
|
||||||
rpn_LOGGT(struct Expression * expr, struct Expression * src1,
|
|
||||||
struct Expression * src2)
|
|
||||||
{
|
|
||||||
joinexpr();
|
|
||||||
expr->nVal = (expr->nVal > src2->nVal);
|
|
||||||
pushbyte(expr, RPN_LOGGT);
|
|
||||||
}
|
|
||||||
|
|
||||||
void
|
|
||||||
rpn_LOGLT(struct Expression * expr, struct Expression * src1,
|
|
||||||
struct Expression * src2)
|
|
||||||
{
|
|
||||||
joinexpr();
|
|
||||||
expr->nVal = (expr->nVal < src2->nVal);
|
|
||||||
pushbyte(expr, RPN_LOGLT);
|
|
||||||
}
|
|
||||||
|
|
||||||
void
|
|
||||||
rpn_LOGGE(struct Expression * expr, struct Expression * src1,
|
|
||||||
struct Expression * src2)
|
|
||||||
{
|
|
||||||
joinexpr();
|
|
||||||
expr->nVal = (expr->nVal >= src2->nVal);
|
|
||||||
pushbyte(expr, RPN_LOGGE);
|
|
||||||
}
|
|
||||||
|
|
||||||
void
|
|
||||||
rpn_LOGLE(struct Expression * expr, struct Expression * src1,
|
|
||||||
struct Expression * src2)
|
|
||||||
{
|
|
||||||
joinexpr();
|
|
||||||
expr->nVal = (expr->nVal <= src2->nVal);
|
|
||||||
pushbyte(expr, RPN_LOGLE);
|
|
||||||
}
|
|
||||||
|
|
||||||
void
|
|
||||||
rpn_LOGNE(struct Expression * expr, struct Expression * src1,
|
|
||||||
struct Expression * src2)
|
|
||||||
{
|
|
||||||
joinexpr();
|
|
||||||
expr->nVal = (expr->nVal != src2->nVal);
|
|
||||||
pushbyte(expr, RPN_LOGNE);
|
|
||||||
}
|
|
||||||
|
|
||||||
void
|
|
||||||
rpn_ADD(struct Expression * expr, struct Expression * src1,
|
|
||||||
struct Expression * src2)
|
|
||||||
{
|
|
||||||
joinexpr();
|
|
||||||
expr->nVal = (expr->nVal + src2->nVal);
|
|
||||||
pushbyte(expr, RPN_ADD);
|
|
||||||
}
|
|
||||||
|
|
||||||
void
|
|
||||||
rpn_SUB(struct Expression * expr, struct Expression * src1,
|
|
||||||
struct Expression * src2)
|
|
||||||
{
|
|
||||||
joinexpr();
|
|
||||||
expr->nVal = (expr->nVal - src2->nVal);
|
|
||||||
pushbyte(expr, RPN_SUB);
|
|
||||||
}
|
|
||||||
|
|
||||||
void
|
|
||||||
rpn_XOR(struct Expression * expr, struct Expression * src1,
|
|
||||||
struct Expression * src2)
|
|
||||||
{
|
|
||||||
joinexpr();
|
|
||||||
expr->nVal = (expr->nVal ^ src2->nVal);
|
|
||||||
pushbyte(expr, RPN_XOR);
|
|
||||||
}
|
|
||||||
|
|
||||||
void
|
|
||||||
rpn_OR(struct Expression * expr, struct Expression * src1,
|
|
||||||
struct Expression * src2)
|
|
||||||
{
|
|
||||||
joinexpr();
|
|
||||||
expr->nVal = (expr->nVal | src2->nVal);
|
|
||||||
pushbyte(expr, RPN_OR);
|
|
||||||
}
|
|
||||||
|
|
||||||
void
|
|
||||||
rpn_AND(struct Expression * expr, struct Expression * src1,
|
|
||||||
struct Expression * src2)
|
|
||||||
{
|
|
||||||
joinexpr();
|
|
||||||
expr->nVal = (expr->nVal & src2->nVal);
|
|
||||||
pushbyte(expr, RPN_AND);
|
|
||||||
}
|
|
||||||
|
|
||||||
void
|
|
||||||
rpn_SHL(struct Expression * expr, struct Expression * src1,
|
|
||||||
struct Expression * src2)
|
|
||||||
{
|
|
||||||
joinexpr();
|
|
||||||
expr->nVal = (expr->nVal << src2->nVal);
|
|
||||||
pushbyte(expr, RPN_SHL);
|
|
||||||
}
|
|
||||||
|
|
||||||
void
|
|
||||||
rpn_SHR(struct Expression * expr, struct Expression * src1,
|
|
||||||
struct Expression * src2)
|
|
||||||
{
|
|
||||||
joinexpr();
|
|
||||||
expr->nVal = (expr->nVal >> src2->nVal);
|
|
||||||
pushbyte(expr, RPN_SHR);
|
|
||||||
}
|
|
||||||
|
|
||||||
void
|
|
||||||
rpn_MUL(struct Expression * expr, struct Expression * src1,
|
|
||||||
struct Expression * src2)
|
|
||||||
{
|
|
||||||
joinexpr();
|
|
||||||
expr->nVal = (expr->nVal * src2->nVal);
|
|
||||||
pushbyte(expr, RPN_MUL);
|
|
||||||
}
|
|
||||||
|
|
||||||
void
|
|
||||||
rpn_DIV(struct Expression * expr, struct Expression * src1,
|
|
||||||
struct Expression * src2)
|
|
||||||
{
|
|
||||||
joinexpr();
|
|
||||||
if (src2->nVal == 0) {
|
|
||||||
fatalerror("division by zero");
|
|
||||||
}
|
}
|
||||||
expr->nVal = (expr->nVal / src2->nVal);
|
|
||||||
pushbyte(expr, RPN_DIV);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void rpn_BankSelf(struct Expression *expr)
|
||||||
rpn_MOD(struct Expression * expr, struct Expression * src1,
|
|
||||||
struct Expression * src2)
|
|
||||||
{
|
{
|
||||||
joinexpr();
|
rpn_Init(expr);
|
||||||
if (src2->nVal == 0) {
|
|
||||||
fatalerror("division by zero");
|
if (!pCurrentSection) {
|
||||||
|
error("PC has no bank outside a section\n");
|
||||||
|
expr->nVal = 1;
|
||||||
|
} else if (pCurrentSection->bank == (uint32_t)-1) {
|
||||||
|
makeUnknown(expr, "Current section's bank is not known");
|
||||||
|
expr->nRPNPatchSize++;
|
||||||
|
*reserveSpace(expr, 1) = RPN_BANK_SELF;
|
||||||
|
} else {
|
||||||
|
expr->nVal = pCurrentSection->bank;
|
||||||
}
|
}
|
||||||
expr->nVal = (expr->nVal % src2->nVal);
|
|
||||||
pushbyte(expr, RPN_MOD);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void rpn_BankSymbol(struct Expression *expr, char const *tzSym)
|
||||||
rpn_UNNEG(struct Expression * expr, struct Expression * src)
|
|
||||||
{
|
{
|
||||||
*expr = *src;
|
struct Symbol const *sym = sym_FindScopedSymbol(tzSym);
|
||||||
expr->nVal = -expr->nVal;
|
|
||||||
pushbyte(expr, RPN_UNSUB);
|
/* The @ symbol is treated differently. */
|
||||||
|
if (sym_IsPC(sym)) {
|
||||||
|
rpn_BankSelf(expr);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
rpn_Init(expr);
|
||||||
|
if (sym && !sym_IsLabel(sym)) {
|
||||||
|
error("BANK argument must be a label\n");
|
||||||
|
} else {
|
||||||
|
sym = sym_Ref(tzSym);
|
||||||
|
assert(sym); // If the symbol didn't exist, it should have been created
|
||||||
|
|
||||||
|
if (sym_GetSection(sym) && sym_GetSection(sym)->bank != (uint32_t)-1) {
|
||||||
|
/* Symbol's section is known and bank is fixed */
|
||||||
|
expr->nVal = sym_GetSection(sym)->bank;
|
||||||
|
} else {
|
||||||
|
makeUnknown(expr, "\"%s\"'s bank is not known", tzSym);
|
||||||
|
expr->nRPNPatchSize += 5; /* opcode + 4-byte sect ID */
|
||||||
|
|
||||||
|
size_t nameLen = strlen(sym->name) + 1; /* Room for NUL! */
|
||||||
|
uint8_t *ptr = reserveSpace(expr, nameLen + 1);
|
||||||
|
*ptr++ = RPN_BANK_SYM;
|
||||||
|
memcpy(ptr, sym->name, nameLen);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void rpn_BankSection(struct Expression *expr, char const *tzSectionName)
|
||||||
rpn_UNNOT(struct Expression * expr, struct Expression * src)
|
{
|
||||||
|
rpn_Init(expr);
|
||||||
|
|
||||||
|
struct Section *pSection = out_FindSectionByName(tzSectionName);
|
||||||
|
|
||||||
|
if (pSection && pSection->bank != (uint32_t)-1) {
|
||||||
|
expr->nVal = pSection->bank;
|
||||||
|
} else {
|
||||||
|
makeUnknown(expr, "Section \"%s\"'s bank is not known",
|
||||||
|
tzSectionName);
|
||||||
|
|
||||||
|
size_t nameLen = strlen(tzSectionName) + 1; /* Room for NUL! */
|
||||||
|
uint8_t *ptr = reserveSpace(expr, nameLen + 1);
|
||||||
|
|
||||||
|
expr->nRPNPatchSize += nameLen + 1;
|
||||||
|
*ptr++ = RPN_BANK_SECT;
|
||||||
|
memcpy(ptr, tzSectionName, nameLen);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void rpn_CheckHRAM(struct Expression *expr, const struct Expression *src)
|
||||||
{
|
{
|
||||||
*expr = *src;
|
*expr = *src;
|
||||||
expr->nVal = expr->nVal ^ 0xFFFFFFFF;
|
expr->isSymbol = false;
|
||||||
pushbyte(expr, RPN_UNNOT);
|
|
||||||
|
if (!rpn_isKnown(expr)) {
|
||||||
|
expr->nRPNPatchSize++;
|
||||||
|
*reserveSpace(expr, 1) = RPN_HRAM;
|
||||||
|
} else if (expr->nVal >= 0xFF00 && expr->nVal <= 0xFFFF) {
|
||||||
|
/* That range is valid, but only keep the lower byte */
|
||||||
|
expr->nVal &= 0xFF;
|
||||||
|
} else if (expr->nVal < 0 || expr->nVal > 0xFF) {
|
||||||
|
error("Source address $%" PRIx32 " not between $FF00 to $FFFF\n", expr->nVal);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void rpn_CheckRST(struct Expression *expr, const struct Expression *src)
|
||||||
|
{
|
||||||
|
*expr = *src;
|
||||||
|
|
||||||
|
if (rpn_isKnown(expr)) {
|
||||||
|
/* A valid RST address must be masked with 0x38 */
|
||||||
|
if (expr->nVal & ~0x38)
|
||||||
|
error("Invalid address $%" PRIx32 " for RST\n", expr->nVal);
|
||||||
|
/* The target is in the "0x38" bits, all other bits are set */
|
||||||
|
expr->nVal |= 0xC7;
|
||||||
|
} else {
|
||||||
|
expr->nRPNPatchSize++;
|
||||||
|
*reserveSpace(expr, 1) = RPN_RST;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void rpn_LOGNOT(struct Expression *expr, const struct Expression *src)
|
||||||
|
{
|
||||||
|
*expr = *src;
|
||||||
|
expr->isSymbol = false;
|
||||||
|
|
||||||
|
if (rpn_isKnown(expr)) {
|
||||||
|
expr->nVal = !expr->nVal;
|
||||||
|
} else {
|
||||||
|
expr->nRPNPatchSize++;
|
||||||
|
*reserveSpace(expr, 1) = RPN_LOGUNNOT;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
struct Symbol const *rpn_SymbolOf(struct Expression const *expr)
|
||||||
|
{
|
||||||
|
if (!rpn_isSymbol(expr))
|
||||||
|
return NULL;
|
||||||
|
return sym_FindScopedSymbol((char *)expr->tRPN + 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,
|
||||||
|
struct Expression const *src2)
|
||||||
|
{
|
||||||
|
return rpn_IsDiffConstant(src1, rpn_SymbolOf(src2));
|
||||||
|
}
|
||||||
|
|
||||||
|
void rpn_BinaryOp(enum RPNCommand op, struct Expression *expr,
|
||||||
|
const struct Expression *src1, const struct Expression *src2)
|
||||||
|
{
|
||||||
|
expr->isSymbol = false;
|
||||||
|
|
||||||
|
/* First, check if the expression is known */
|
||||||
|
expr->isKnown = src1->isKnown && src2->isKnown;
|
||||||
|
if (expr->isKnown) {
|
||||||
|
rpn_Init(expr); /* Init the expression to something sane */
|
||||||
|
|
||||||
|
/* If both expressions are known, just compute the value */
|
||||||
|
uint32_t uleft = src1->nVal, uright = src2->nVal;
|
||||||
|
|
||||||
|
switch (op) {
|
||||||
|
case RPN_LOGOR:
|
||||||
|
expr->nVal = src1->nVal || src2->nVal;
|
||||||
|
break;
|
||||||
|
case RPN_LOGAND:
|
||||||
|
expr->nVal = src1->nVal && src2->nVal;
|
||||||
|
break;
|
||||||
|
case RPN_LOGEQ:
|
||||||
|
expr->nVal = src1->nVal == src2->nVal;
|
||||||
|
break;
|
||||||
|
case RPN_LOGGT:
|
||||||
|
expr->nVal = src1->nVal > src2->nVal;
|
||||||
|
break;
|
||||||
|
case RPN_LOGLT:
|
||||||
|
expr->nVal = src1->nVal < src2->nVal;
|
||||||
|
break;
|
||||||
|
case RPN_LOGGE:
|
||||||
|
expr->nVal = src1->nVal >= src2->nVal;
|
||||||
|
break;
|
||||||
|
case RPN_LOGLE:
|
||||||
|
expr->nVal = src1->nVal <= src2->nVal;
|
||||||
|
break;
|
||||||
|
case RPN_LOGNE:
|
||||||
|
expr->nVal = src1->nVal != src2->nVal;
|
||||||
|
break;
|
||||||
|
case RPN_ADD:
|
||||||
|
expr->nVal = uleft + uright;
|
||||||
|
break;
|
||||||
|
case RPN_SUB:
|
||||||
|
expr->nVal = uleft - uright;
|
||||||
|
break;
|
||||||
|
case RPN_XOR:
|
||||||
|
expr->nVal = src1->nVal ^ src2->nVal;
|
||||||
|
break;
|
||||||
|
case RPN_OR:
|
||||||
|
expr->nVal = src1->nVal | src2->nVal;
|
||||||
|
break;
|
||||||
|
case RPN_AND:
|
||||||
|
expr->nVal = src1->nVal & src2->nVal;
|
||||||
|
break;
|
||||||
|
case RPN_SHL:
|
||||||
|
if (src2->nVal < 0)
|
||||||
|
warning(WARNING_SHIFT_AMOUNT,
|
||||||
|
"Shifting left by negative amount %" PRId32 "\n",
|
||||||
|
src2->nVal);
|
||||||
|
|
||||||
|
if (src2->nVal >= 32)
|
||||||
|
warning(WARNING_SHIFT_AMOUNT,
|
||||||
|
"Shifting left by large amount %" PRId32 "\n",
|
||||||
|
src2->nVal);
|
||||||
|
|
||||||
|
expr->nVal = op_shift_left(src1->nVal, src2->nVal);
|
||||||
|
break;
|
||||||
|
case RPN_SHR:
|
||||||
|
if (src1->nVal < 0)
|
||||||
|
warning(WARNING_SHIFT, "Shifting right negative value %"
|
||||||
|
PRId32 "\n",
|
||||||
|
src1->nVal);
|
||||||
|
|
||||||
|
if (src2->nVal < 0)
|
||||||
|
warning(WARNING_SHIFT_AMOUNT,
|
||||||
|
"Shifting right by negative amount %" PRId32 "\n",
|
||||||
|
src2->nVal);
|
||||||
|
|
||||||
|
if (src2->nVal >= 32)
|
||||||
|
warning(WARNING_SHIFT_AMOUNT,
|
||||||
|
"Shifting right by large amount %" PRId32 "\n",
|
||||||
|
src2->nVal);
|
||||||
|
|
||||||
|
expr->nVal = op_shift_right(src1->nVal, src2->nVal);
|
||||||
|
break;
|
||||||
|
case RPN_MUL:
|
||||||
|
expr->nVal = uleft * uright;
|
||||||
|
break;
|
||||||
|
case RPN_DIV:
|
||||||
|
if (src2->nVal == 0)
|
||||||
|
fatalerror("Division by zero\n");
|
||||||
|
|
||||||
|
if (src1->nVal == INT32_MIN && src2->nVal == -1) {
|
||||||
|
warning(WARNING_DIV, "Division of %" PRId32 " by -1 yields %"
|
||||||
|
PRId32 "\n", INT32_MIN, INT32_MIN);
|
||||||
|
expr->nVal = INT32_MIN;
|
||||||
|
} else {
|
||||||
|
expr->nVal = op_divide(src1->nVal, src2->nVal);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case RPN_MOD:
|
||||||
|
if (src2->nVal == 0)
|
||||||
|
fatalerror("Modulo by zero\n");
|
||||||
|
|
||||||
|
if (src1->nVal == INT32_MIN && src2->nVal == -1)
|
||||||
|
expr->nVal = 0;
|
||||||
|
else
|
||||||
|
expr->nVal = op_modulo(src1->nVal, src2->nVal);
|
||||||
|
break;
|
||||||
|
case RPN_EXP:
|
||||||
|
if (src2->nVal < 0)
|
||||||
|
fatalerror("Exponentiation by negative power\n");
|
||||||
|
|
||||||
|
if (src1->nVal == INT32_MIN && src2->nVal == -1)
|
||||||
|
expr->nVal = 0;
|
||||||
|
else
|
||||||
|
expr->nVal = op_exponent(src1->nVal, src2->nVal);
|
||||||
|
break;
|
||||||
|
|
||||||
|
case RPN_UNSUB:
|
||||||
|
case RPN_UNNOT:
|
||||||
|
case RPN_LOGUNNOT:
|
||||||
|
case RPN_BANK_SYM:
|
||||||
|
case RPN_BANK_SECT:
|
||||||
|
case RPN_BANK_SELF:
|
||||||
|
case RPN_HRAM:
|
||||||
|
case RPN_RST:
|
||||||
|
case RPN_CONST:
|
||||||
|
case RPN_SYM:
|
||||||
|
fatalerror("%d is not a binary operator\n", op);
|
||||||
|
}
|
||||||
|
|
||||||
|
} else if (op == RPN_SUB && isDiffConstant(src1, src2)) {
|
||||||
|
struct Symbol const *symbol1 = rpn_SymbolOf(src1);
|
||||||
|
struct Symbol const *symbol2 = rpn_SymbolOf(src2);
|
||||||
|
|
||||||
|
expr->nVal = sym_GetValue(symbol1) - sym_GetValue(symbol2);
|
||||||
|
expr->isKnown = true;
|
||||||
|
} else {
|
||||||
|
/* If it's not known, start computing the RPN expression */
|
||||||
|
|
||||||
|
/* Convert the left-hand expression if it's constant */
|
||||||
|
if (src1->isKnown) {
|
||||||
|
uint32_t lval = src1->nVal;
|
||||||
|
uint8_t bytes[] = {RPN_CONST, lval, lval >> 8,
|
||||||
|
lval >> 16, lval >> 24};
|
||||||
|
expr->nRPNPatchSize = sizeof(bytes);
|
||||||
|
expr->tRPN = NULL;
|
||||||
|
expr->nRPNCapacity = 0;
|
||||||
|
expr->nRPNLength = 0;
|
||||||
|
memcpy(reserveSpace(expr, sizeof(bytes)), bytes,
|
||||||
|
sizeof(bytes));
|
||||||
|
|
||||||
|
/* Use the other expression's un-const reason */
|
||||||
|
expr->reason = src2->reason;
|
||||||
|
free(src1->reason);
|
||||||
|
} else {
|
||||||
|
/* Otherwise just reuse its RPN buffer */
|
||||||
|
expr->nRPNPatchSize = src1->nRPNPatchSize;
|
||||||
|
expr->tRPN = src1->tRPN;
|
||||||
|
expr->nRPNCapacity = src1->nRPNCapacity;
|
||||||
|
expr->nRPNLength = src1->nRPNLength;
|
||||||
|
expr->reason = src1->reason;
|
||||||
|
free(src2->reason);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Now, merge the right expression into the left one */
|
||||||
|
uint8_t *ptr = src2->tRPN; /* Pointer to the right RPN */
|
||||||
|
uint32_t len = src2->nRPNLength; /* Size of the right RPN */
|
||||||
|
uint32_t patchSize = src2->nRPNPatchSize;
|
||||||
|
|
||||||
|
/* If the right expression is constant, merge a shim instead */
|
||||||
|
uint32_t rval = src2->nVal;
|
||||||
|
uint8_t bytes[] = {RPN_CONST, rval, rval >> 8, rval >> 16,
|
||||||
|
rval >> 24};
|
||||||
|
if (src2->isKnown) {
|
||||||
|
ptr = bytes;
|
||||||
|
len = sizeof(bytes);
|
||||||
|
patchSize = sizeof(bytes);
|
||||||
|
}
|
||||||
|
/* Copy the right RPN and append the operator */
|
||||||
|
uint8_t *buf = reserveSpace(expr, len + 1);
|
||||||
|
|
||||||
|
memcpy(buf, ptr, len);
|
||||||
|
buf[len] = op;
|
||||||
|
|
||||||
|
free(src2->tRPN); /* If there was none, this is `free(NULL)` */
|
||||||
|
expr->nRPNPatchSize += patchSize + 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void rpn_HIGH(struct Expression *expr, const struct Expression *src)
|
||||||
|
{
|
||||||
|
*expr = *src;
|
||||||
|
expr->isSymbol = false;
|
||||||
|
|
||||||
|
if (rpn_isKnown(expr)) {
|
||||||
|
expr->nVal = (uint32_t)expr->nVal >> 8 & 0xFF;
|
||||||
|
} else {
|
||||||
|
uint8_t bytes[] = {RPN_CONST, 8, 0, 0, 0, RPN_SHR,
|
||||||
|
RPN_CONST, 0xFF, 0, 0, 0, RPN_AND};
|
||||||
|
expr->nRPNPatchSize += sizeof(bytes);
|
||||||
|
memcpy(reserveSpace(expr, sizeof(bytes)), bytes, sizeof(bytes));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void rpn_LOW(struct Expression *expr, const struct Expression *src)
|
||||||
|
{
|
||||||
|
*expr = *src;
|
||||||
|
expr->isSymbol = false;
|
||||||
|
|
||||||
|
if (rpn_isKnown(expr)) {
|
||||||
|
expr->nVal = expr->nVal & 0xFF;
|
||||||
|
} else {
|
||||||
|
uint8_t bytes[] = {RPN_CONST, 0xFF, 0, 0, 0, RPN_AND};
|
||||||
|
|
||||||
|
expr->nRPNPatchSize += sizeof(bytes);
|
||||||
|
memcpy(reserveSpace(expr, sizeof(bytes)), bytes, sizeof(bytes));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void rpn_ISCONST(struct Expression *expr, const struct Expression *src)
|
||||||
|
{
|
||||||
|
rpn_Init(expr);
|
||||||
|
expr->nVal = rpn_isKnown(src);
|
||||||
|
expr->isKnown = true;
|
||||||
|
expr->isSymbol = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
void rpn_UNNEG(struct Expression *expr, const struct Expression *src)
|
||||||
|
{
|
||||||
|
*expr = *src;
|
||||||
|
expr->isSymbol = false;
|
||||||
|
|
||||||
|
if (rpn_isKnown(expr)) {
|
||||||
|
expr->nVal = -(uint32_t)expr->nVal;
|
||||||
|
} else {
|
||||||
|
expr->nRPNPatchSize++;
|
||||||
|
*reserveSpace(expr, 1) = RPN_UNSUB;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void rpn_UNNOT(struct Expression *expr, const struct Expression *src)
|
||||||
|
{
|
||||||
|
*expr = *src;
|
||||||
|
expr->isSymbol = false;
|
||||||
|
|
||||||
|
if (rpn_isKnown(expr)) {
|
||||||
|
expr->nVal = ~expr->nVal;
|
||||||
|
} else {
|
||||||
|
expr->nRPNPatchSize++;
|
||||||
|
*reserveSpace(expr, 1) = RPN_UNNOT;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,925 @@
|
|||||||
|
|
||||||
|
#include <assert.h>
|
||||||
|
#include <errno.h>
|
||||||
|
#include <inttypes.h>
|
||||||
|
#include <stdbool.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <string.h>
|
||||||
|
|
||||||
|
#include "asm/fstack.h"
|
||||||
|
#include "asm/main.h"
|
||||||
|
#include "asm/output.h"
|
||||||
|
#include "asm/rpn.h"
|
||||||
|
#include "asm/section.h"
|
||||||
|
#include "asm/symbol.h"
|
||||||
|
#include "asm/warning.h"
|
||||||
|
|
||||||
|
#include "extern/err.h"
|
||||||
|
#include "platform.h" // strdup
|
||||||
|
|
||||||
|
uint8_t fillByte;
|
||||||
|
|
||||||
|
struct SectionStackEntry {
|
||||||
|
struct Section *section;
|
||||||
|
char const *scope; /* Section's symbol scope */
|
||||||
|
uint32_t offset;
|
||||||
|
struct SectionStackEntry *next;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct SectionStackEntry *sectionStack;
|
||||||
|
uint32_t curOffset; /* Offset into the current section (see sect_GetSymbolOffset) */
|
||||||
|
static struct Section *currentLoadSection = NULL;
|
||||||
|
int32_t loadOffset; /* Offset into the LOAD section's parent (see sect_GetOutputOffset) */
|
||||||
|
|
||||||
|
struct UnionStackEntry {
|
||||||
|
uint32_t start;
|
||||||
|
uint32_t size;
|
||||||
|
struct UnionStackEntry *next;
|
||||||
|
} *unionStack = NULL;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* A quick check to see if we have an initialized section
|
||||||
|
*/
|
||||||
|
static inline void checksection(void)
|
||||||
|
{
|
||||||
|
if (pCurrentSection == NULL)
|
||||||
|
fatalerror("Code generation before SECTION directive\n");
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* A quick check to see if we have an initialized section that can contain
|
||||||
|
* this much initialized data
|
||||||
|
*/
|
||||||
|
static inline void checkcodesection(void)
|
||||||
|
{
|
||||||
|
checksection();
|
||||||
|
|
||||||
|
if (!sect_HasData(pCurrentSection->type))
|
||||||
|
fatalerror("Section '%s' cannot contain code or data (not ROM0 or ROMX)\n",
|
||||||
|
pCurrentSection->name);
|
||||||
|
}
|
||||||
|
|
||||||
|
static inline void checkSectionSize(struct Section const *sect, uint32_t size)
|
||||||
|
{
|
||||||
|
uint32_t maxSize = maxsize[sect->type];
|
||||||
|
|
||||||
|
if (size > maxSize)
|
||||||
|
fatalerror("Section '%s' grew too big (max size = 0x%" PRIX32
|
||||||
|
" bytes, reached 0x%" PRIX32 ").\n", sect->name, maxSize, size);
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Check if the section has grown too much.
|
||||||
|
*/
|
||||||
|
static inline void reserveSpace(uint32_t delta_size)
|
||||||
|
{
|
||||||
|
/*
|
||||||
|
* This check is here to trap broken code that generates sections that
|
||||||
|
* are too big and to prevent the assembler from generating huge object
|
||||||
|
* files or trying to allocate too much memory.
|
||||||
|
* A check at the linking stage is still necessary.
|
||||||
|
*/
|
||||||
|
checkSectionSize(pCurrentSection, curOffset + loadOffset + delta_size);
|
||||||
|
if (currentLoadSection)
|
||||||
|
checkSectionSize(currentLoadSection, curOffset + delta_size);
|
||||||
|
}
|
||||||
|
|
||||||
|
struct Section *out_FindSectionByName(const char *name)
|
||||||
|
{
|
||||||
|
for (struct Section *sect = pSectionList; sect; sect = sect->next) {
|
||||||
|
if (strcmp(name, sect->name) == 0)
|
||||||
|
return sect;
|
||||||
|
}
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
#define mask(align) ((1U << (align)) - 1)
|
||||||
|
#define fail(...) \
|
||||||
|
do { \
|
||||||
|
error(__VA_ARGS__); \
|
||||||
|
nbSectErrors++; \
|
||||||
|
} while (0)
|
||||||
|
|
||||||
|
static unsigned int mergeSectUnion(struct Section *sect, enum SectionType type, uint32_t org,
|
||||||
|
uint8_t alignment, uint16_t alignOffset)
|
||||||
|
{
|
||||||
|
assert(alignment < 16); // Should be ensured by the caller
|
||||||
|
unsigned int nbSectErrors = 0;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Unionized sections only need "compatible" constraints, and they end up with the strictest
|
||||||
|
* combination of both.
|
||||||
|
*/
|
||||||
|
if (sect_HasData(type))
|
||||||
|
fail("Cannot declare ROM sections as UNION\n");
|
||||||
|
|
||||||
|
if (org != (uint32_t)-1) {
|
||||||
|
/* If both are fixed, they must be the same */
|
||||||
|
if (sect->org != (uint32_t)-1 && sect->org != org)
|
||||||
|
fail("Section already declared as fixed at different address $%04"
|
||||||
|
PRIx32 "\n", sect->org);
|
||||||
|
else if (sect->align != 0 && (mask(sect->align) & (org - sect->alignOfs)))
|
||||||
|
fail("Section already declared as aligned to %u bytes (offset %"
|
||||||
|
PRIu16 ")\n", 1U << sect->align, sect->alignOfs);
|
||||||
|
else
|
||||||
|
/* Otherwise, just override */
|
||||||
|
sect->org = org;
|
||||||
|
|
||||||
|
} else if (alignment != 0) {
|
||||||
|
/* Make sure any fixed address given is compatible */
|
||||||
|
if (sect->org != (uint32_t)-1) {
|
||||||
|
if ((sect->org - alignOffset) & mask(alignment))
|
||||||
|
fail("Section already declared as fixed at incompatible address $%04"
|
||||||
|
PRIx32 "\n", sect->org);
|
||||||
|
/* Check if alignment offsets are compatible */
|
||||||
|
} else if ((alignOffset & mask(sect->align))
|
||||||
|
!= (sect->alignOfs & mask(alignment))) {
|
||||||
|
fail("Section already declared with incompatible %" PRIu8
|
||||||
|
"-byte alignment (offset %" PRIu16 ")\n",
|
||||||
|
sect->align, sect->alignOfs);
|
||||||
|
} else if (alignment > sect->align) {
|
||||||
|
// If the section is not fixed, its alignment is the largest of both
|
||||||
|
sect->align = alignment;
|
||||||
|
sect->alignOfs = alignOffset;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return nbSectErrors;
|
||||||
|
}
|
||||||
|
|
||||||
|
static unsigned int mergeFragments(struct Section *sect, enum SectionType type, uint32_t org,
|
||||||
|
uint8_t alignment, uint16_t alignOffset)
|
||||||
|
{
|
||||||
|
(void)type;
|
||||||
|
assert(alignment < 16); // Should be ensured by the caller
|
||||||
|
unsigned int nbSectErrors = 0;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Fragments only need "compatible" constraints, and they end up with the strictest
|
||||||
|
* combination of both.
|
||||||
|
* The merging is however performed at the *end* of the original section!
|
||||||
|
*/
|
||||||
|
if (org != (uint32_t)-1) {
|
||||||
|
uint16_t curOrg = org - sect->size;
|
||||||
|
|
||||||
|
/* If both are fixed, they must be the same */
|
||||||
|
if (sect->org != (uint32_t)-1 && sect->org != curOrg)
|
||||||
|
fail("Section already declared as fixed at incompatible address $%04"
|
||||||
|
PRIx32 " (cur addr = %04" PRIx32 ")\n",
|
||||||
|
sect->org, sect->org + sect->size);
|
||||||
|
else if (sect->align != 0 && (mask(sect->align) & (curOrg - sect->alignOfs)))
|
||||||
|
fail("Section already declared as aligned to %u bytes (offset %"
|
||||||
|
PRIu16 ")\n", 1U << sect->align, sect->alignOfs);
|
||||||
|
else
|
||||||
|
/* Otherwise, just override */
|
||||||
|
sect->org = curOrg;
|
||||||
|
|
||||||
|
} else if (alignment != 0) {
|
||||||
|
int32_t curOfs = (alignOffset - sect->size) % (1U << alignment);
|
||||||
|
|
||||||
|
if (curOfs < 0)
|
||||||
|
curOfs += 1U << alignment;
|
||||||
|
|
||||||
|
/* Make sure any fixed address given is compatible */
|
||||||
|
if (sect->org != (uint32_t)-1) {
|
||||||
|
if ((sect->org - curOfs) & mask(alignment))
|
||||||
|
fail("Section already declared as fixed at incompatible address $%04"
|
||||||
|
PRIx32 "\n", sect->org);
|
||||||
|
/* Check if alignment offsets are compatible */
|
||||||
|
} else if ((curOfs & mask(sect->align)) != (sect->alignOfs & mask(alignment))) {
|
||||||
|
fail("Section already declared with incompatible %" PRIu8
|
||||||
|
"-byte alignment (offset %" PRIu16 ")\n",
|
||||||
|
sect->align, sect->alignOfs);
|
||||||
|
} else if (alignment > sect->align) {
|
||||||
|
// If the section is not fixed, its alignment is the largest of both
|
||||||
|
sect->align = alignment;
|
||||||
|
sect->alignOfs = curOfs;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return nbSectErrors;
|
||||||
|
}
|
||||||
|
|
||||||
|
static void mergeSections(struct Section *sect, enum SectionType type, uint32_t org, uint32_t bank,
|
||||||
|
uint8_t alignment, uint16_t alignOffset, enum SectionModifier mod)
|
||||||
|
{
|
||||||
|
unsigned int nbSectErrors = 0;
|
||||||
|
|
||||||
|
if (type != sect->type)
|
||||||
|
fail("Section already exists but with type %s\n", typeNames[sect->type]);
|
||||||
|
|
||||||
|
if (sect->modifier != mod) {
|
||||||
|
fail("Section already declared as %s section\n", sectionModNames[sect->modifier]);
|
||||||
|
} else {
|
||||||
|
switch (mod) {
|
||||||
|
case SECTION_UNION:
|
||||||
|
case SECTION_FRAGMENT:
|
||||||
|
nbSectErrors += (mod == SECTION_UNION ? mergeSectUnion : mergeFragments)
|
||||||
|
(sect, type, org, alignment, alignOffset);
|
||||||
|
|
||||||
|
// Common checks
|
||||||
|
|
||||||
|
/* If the section's bank is unspecified, override it */
|
||||||
|
if (sect->bank == (uint32_t)-1)
|
||||||
|
sect->bank = bank;
|
||||||
|
/* If both specify a bank, it must be the same one */
|
||||||
|
else if (bank != (uint32_t)-1 && sect->bank != bank)
|
||||||
|
fail("Section already declared with different bank %" PRIu32 "\n",
|
||||||
|
sect->bank);
|
||||||
|
break;
|
||||||
|
|
||||||
|
case SECTION_NORMAL:
|
||||||
|
fail("Section already defined previously at ");
|
||||||
|
fstk_Dump(sect->src, sect->fileLine);
|
||||||
|
putc('\n', stderr);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (nbSectErrors)
|
||||||
|
fatalerror("Cannot create section \"%s\" (%u error%s)\n",
|
||||||
|
sect->name, nbSectErrors, nbSectErrors == 1 ? "" : "s");
|
||||||
|
}
|
||||||
|
|
||||||
|
#undef fail
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Create a new section, not yet in the list.
|
||||||
|
*/
|
||||||
|
static struct Section *createSection(char const *name, enum SectionType type,
|
||||||
|
uint32_t org, uint32_t bank, uint8_t alignment,
|
||||||
|
uint16_t alignOffset, enum SectionModifier mod)
|
||||||
|
{
|
||||||
|
struct Section *sect = malloc(sizeof(*sect));
|
||||||
|
|
||||||
|
if (sect == NULL)
|
||||||
|
fatalerror("Not enough memory for section: %s\n", strerror(errno));
|
||||||
|
|
||||||
|
sect->name = strdup(name);
|
||||||
|
if (sect->name == NULL)
|
||||||
|
fatalerror("Not enough memory for section name: %s\n", strerror(errno));
|
||||||
|
|
||||||
|
sect->type = type;
|
||||||
|
sect->modifier = mod;
|
||||||
|
sect->src = fstk_GetFileStack();
|
||||||
|
sect->fileLine = lexer_GetLineNo();
|
||||||
|
sect->size = 0;
|
||||||
|
sect->org = org;
|
||||||
|
sect->bank = bank;
|
||||||
|
sect->align = alignment;
|
||||||
|
sect->alignOfs = alignOffset;
|
||||||
|
sect->next = NULL;
|
||||||
|
sect->patches = NULL;
|
||||||
|
|
||||||
|
/* It is only needed to allocate memory for ROM sections. */
|
||||||
|
if (sect_HasData(type)) {
|
||||||
|
sect->data = malloc(maxsize[type]);
|
||||||
|
if (sect->data == NULL)
|
||||||
|
fatalerror("Not enough memory for section: %s\n", strerror(errno));
|
||||||
|
} else {
|
||||||
|
sect->data = NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
return sect;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Find a section by name and type. If it doesn't exist, create it.
|
||||||
|
*/
|
||||||
|
static struct Section *getSection(char const *name, enum SectionType type, uint32_t org,
|
||||||
|
struct SectionSpec const *attrs, enum SectionModifier mod)
|
||||||
|
{
|
||||||
|
uint32_t bank = attrs->bank;
|
||||||
|
uint8_t alignment = attrs->alignment;
|
||||||
|
uint16_t alignOffset = attrs->alignOfs;
|
||||||
|
|
||||||
|
// First, validate parameters, and normalize them if applicable
|
||||||
|
|
||||||
|
if (bank != (uint32_t)-1) {
|
||||||
|
if (type != SECTTYPE_ROMX && type != SECTTYPE_VRAM
|
||||||
|
&& type != SECTTYPE_SRAM && type != SECTTYPE_WRAMX)
|
||||||
|
error("BANK only allowed for ROMX, WRAMX, SRAM, or VRAM sections\n");
|
||||||
|
else if (bank < bankranges[type][0]
|
||||||
|
|| bank > bankranges[type][1])
|
||||||
|
error("%s bank value $%04" PRIx32 " out of range ($%04" PRIx32 " to $%04"
|
||||||
|
PRIx32 ")\n", typeNames[type], bank,
|
||||||
|
bankranges[type][0], bankranges[type][1]);
|
||||||
|
} else if (nbbanks(type) == 1) {
|
||||||
|
// If the section type only has a single bank, implicitly force it
|
||||||
|
bank = bankranges[type][0];
|
||||||
|
}
|
||||||
|
|
||||||
|
if (alignOffset >= 1 << alignment) {
|
||||||
|
error("Alignment offset (%" PRIu16 ") must be smaller than alignment size (%u)\n",
|
||||||
|
alignOffset, 1U << alignment);
|
||||||
|
alignOffset = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (org != (uint32_t)-1) {
|
||||||
|
if (org < startaddr[type] || org > endaddr(type))
|
||||||
|
error("Section \"%s\"'s fixed address %#" PRIx32
|
||||||
|
" is outside of range [%#" PRIx16 "; %#" PRIx16 "]\n",
|
||||||
|
name, org, startaddr[type], endaddr(type));
|
||||||
|
}
|
||||||
|
|
||||||
|
if (alignment != 0) {
|
||||||
|
if (alignment > 16) {
|
||||||
|
error("Alignment must be between 0 and 16, not %u\n", alignment);
|
||||||
|
alignment = 16;
|
||||||
|
}
|
||||||
|
/* It doesn't make sense to have both alignment and org set */
|
||||||
|
uint32_t mask = mask(alignment);
|
||||||
|
|
||||||
|
if (org != (uint32_t)-1) {
|
||||||
|
if ((org - alignOffset) & mask)
|
||||||
|
error("Section \"%s\"'s fixed address doesn't match its alignment\n",
|
||||||
|
name);
|
||||||
|
alignment = 0; /* Ignore it if it's satisfied */
|
||||||
|
} else if (startaddr[type] & mask) {
|
||||||
|
error("Section \"%s\"'s alignment cannot be attained in %s\n",
|
||||||
|
name, typeNames[type]);
|
||||||
|
} else if (alignment == 16) {
|
||||||
|
// Treat an alignment of 16 as being fixed at address 0
|
||||||
|
alignment = 0;
|
||||||
|
org = 0;
|
||||||
|
// The address is known to be valid, since the alignment is
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Check if another section exists with the same name; merge if yes, otherwise create one
|
||||||
|
|
||||||
|
struct Section *sect = out_FindSectionByName(name);
|
||||||
|
|
||||||
|
if (sect) {
|
||||||
|
mergeSections(sect, type, org, bank, alignment, alignOffset, mod);
|
||||||
|
} else {
|
||||||
|
sect = createSection(name, type, org, bank, alignment, alignOffset, mod);
|
||||||
|
// Add the new section to the list (order doesn't matter)
|
||||||
|
sect->next = pSectionList;
|
||||||
|
pSectionList = sect;
|
||||||
|
}
|
||||||
|
|
||||||
|
return sect;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Set the current section
|
||||||
|
*/
|
||||||
|
static void changeSection(void)
|
||||||
|
{
|
||||||
|
if (unionStack)
|
||||||
|
fatalerror("Cannot change the section within a UNION\n");
|
||||||
|
|
||||||
|
sym_SetCurrentSymbolScope(NULL);
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Set the current section by name and type
|
||||||
|
*/
|
||||||
|
void out_NewSection(char const *name, uint32_t type, uint32_t org,
|
||||||
|
struct SectionSpec const *attribs, enum SectionModifier mod)
|
||||||
|
{
|
||||||
|
if (currentLoadSection)
|
||||||
|
fatalerror("Cannot change the section within a `LOAD` block\n");
|
||||||
|
|
||||||
|
for (struct SectionStackEntry *stack = sectionStack; stack; stack = stack->next) {
|
||||||
|
if (stack->section && !strcmp(name, stack->section->name))
|
||||||
|
fatalerror("Section '%s' is already on the stack\n", name);
|
||||||
|
}
|
||||||
|
|
||||||
|
struct Section *sect = getSection(name, type, org, attribs, mod);
|
||||||
|
|
||||||
|
changeSection();
|
||||||
|
curOffset = mod == SECTION_UNION ? 0 : sect->size;
|
||||||
|
pCurrentSection = sect;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Set the current section by name and type
|
||||||
|
*/
|
||||||
|
void out_SetLoadSection(char const *name, uint32_t type, uint32_t org,
|
||||||
|
struct SectionSpec const *attribs,
|
||||||
|
enum SectionModifier mod)
|
||||||
|
{
|
||||||
|
checkcodesection();
|
||||||
|
|
||||||
|
if (currentLoadSection)
|
||||||
|
fatalerror("`LOAD` blocks cannot be nested\n");
|
||||||
|
|
||||||
|
if (sect_HasData(type))
|
||||||
|
error("`LOAD` blocks cannot create a ROM section\n");
|
||||||
|
|
||||||
|
struct Section *sect = getSection(name, type, org, attribs, mod);
|
||||||
|
|
||||||
|
changeSection();
|
||||||
|
loadOffset = curOffset - (mod == SECTION_UNION ? 0 : sect->size);
|
||||||
|
curOffset -= loadOffset;
|
||||||
|
currentLoadSection = sect;
|
||||||
|
}
|
||||||
|
|
||||||
|
void out_EndLoadSection(void)
|
||||||
|
{
|
||||||
|
if (!currentLoadSection)
|
||||||
|
error("Found `ENDL` outside of a `LOAD` block\n");
|
||||||
|
|
||||||
|
changeSection();
|
||||||
|
curOffset += loadOffset;
|
||||||
|
loadOffset = 0;
|
||||||
|
currentLoadSection = NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
struct Section *sect_GetSymbolSection(void)
|
||||||
|
{
|
||||||
|
return currentLoadSection ? currentLoadSection : pCurrentSection;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* The offset into the section above
|
||||||
|
*/
|
||||||
|
uint32_t sect_GetSymbolOffset(void)
|
||||||
|
{
|
||||||
|
return curOffset;
|
||||||
|
}
|
||||||
|
|
||||||
|
uint32_t sect_GetOutputOffset(void)
|
||||||
|
{
|
||||||
|
return curOffset + loadOffset;
|
||||||
|
}
|
||||||
|
|
||||||
|
void sect_AlignPC(uint8_t alignment, uint16_t offset)
|
||||||
|
{
|
||||||
|
checksection();
|
||||||
|
struct Section *sect = sect_GetSymbolSection();
|
||||||
|
uint16_t alignSize = 1 << alignment; // Size of an aligned "block"
|
||||||
|
|
||||||
|
if (sect->org != (uint32_t)-1) {
|
||||||
|
if ((sym_GetPCValue() - offset) % alignSize)
|
||||||
|
error("Section's fixed address fails required alignment (PC = $%04" PRIx32
|
||||||
|
")\n", sym_GetPCValue());
|
||||||
|
} else if (sect->align != 0) {
|
||||||
|
if ((((sect->alignOfs + curOffset) % (1 << sect->align)) - offset) % alignSize) {
|
||||||
|
error("Section's alignment fails required alignment (offset from section start = $%04"
|
||||||
|
PRIx32 ")\n", curOffset);
|
||||||
|
} else if (alignment > sect->align) {
|
||||||
|
sect->align = alignment;
|
||||||
|
sect->alignOfs = (offset - curOffset) % alignSize;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
sect->align = alignment;
|
||||||
|
// We need `(sect->alignOfs + curOffset) % alignSize == offset
|
||||||
|
sect->alignOfs = (offset - curOffset) % alignSize;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static inline void growSection(uint32_t growth)
|
||||||
|
{
|
||||||
|
curOffset += growth;
|
||||||
|
if (curOffset + loadOffset > pCurrentSection->size)
|
||||||
|
pCurrentSection->size = curOffset + loadOffset;
|
||||||
|
if (currentLoadSection && curOffset > currentLoadSection->size)
|
||||||
|
currentLoadSection->size = curOffset;
|
||||||
|
}
|
||||||
|
|
||||||
|
static inline void writebyte(uint8_t byte)
|
||||||
|
{
|
||||||
|
pCurrentSection->data[sect_GetOutputOffset()] = byte;
|
||||||
|
growSection(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
static inline void writeword(uint16_t b)
|
||||||
|
{
|
||||||
|
writebyte(b & 0xFF);
|
||||||
|
writebyte(b >> 8);
|
||||||
|
}
|
||||||
|
|
||||||
|
static inline void writelong(uint32_t b)
|
||||||
|
{
|
||||||
|
writebyte(b & 0xFF);
|
||||||
|
writebyte(b >> 8);
|
||||||
|
writebyte(b >> 16);
|
||||||
|
writebyte(b >> 24);
|
||||||
|
}
|
||||||
|
|
||||||
|
static inline void createPatch(enum PatchType type, struct Expression const *expr,
|
||||||
|
uint32_t pcShift)
|
||||||
|
{
|
||||||
|
out_CreatePatch(type, expr, sect_GetOutputOffset(), pcShift);
|
||||||
|
}
|
||||||
|
|
||||||
|
void sect_StartUnion(void)
|
||||||
|
{
|
||||||
|
if (!pCurrentSection)
|
||||||
|
fatalerror("UNIONs must be inside a SECTION\n");
|
||||||
|
if (sect_HasData(pCurrentSection->type))
|
||||||
|
fatalerror("Cannot use UNION inside of ROM0 or ROMX sections\n");
|
||||||
|
struct UnionStackEntry *entry = malloc(sizeof(*entry));
|
||||||
|
|
||||||
|
if (!entry)
|
||||||
|
fatalerror("Failed to allocate new union stack entry: %s\n", strerror(errno));
|
||||||
|
entry->start = curOffset;
|
||||||
|
entry->size = 0;
|
||||||
|
entry->next = unionStack;
|
||||||
|
unionStack = entry;
|
||||||
|
}
|
||||||
|
|
||||||
|
static void endUnionMember(void)
|
||||||
|
{
|
||||||
|
uint32_t memberSize = curOffset - unionStack->start;
|
||||||
|
|
||||||
|
if (memberSize > unionStack->size)
|
||||||
|
unionStack->size = memberSize;
|
||||||
|
curOffset = unionStack->start;
|
||||||
|
}
|
||||||
|
|
||||||
|
void sect_NextUnionMember(void)
|
||||||
|
{
|
||||||
|
if (!unionStack)
|
||||||
|
fatalerror("Found NEXTU outside of a UNION construct\n");
|
||||||
|
endUnionMember();
|
||||||
|
}
|
||||||
|
|
||||||
|
void sect_EndUnion(void)
|
||||||
|
{
|
||||||
|
if (!unionStack)
|
||||||
|
fatalerror("Found ENDU outside of a UNION construct\n");
|
||||||
|
endUnionMember();
|
||||||
|
curOffset += unionStack->size;
|
||||||
|
struct UnionStackEntry *next = unionStack->next;
|
||||||
|
|
||||||
|
free(unionStack);
|
||||||
|
unionStack = next;
|
||||||
|
}
|
||||||
|
|
||||||
|
void sect_CheckUnionClosed(void)
|
||||||
|
{
|
||||||
|
if (unionStack)
|
||||||
|
error("Unterminated UNION construct!\n");
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Output an absolute byte
|
||||||
|
*/
|
||||||
|
void out_AbsByte(uint8_t b)
|
||||||
|
{
|
||||||
|
checkcodesection();
|
||||||
|
reserveSpace(1);
|
||||||
|
|
||||||
|
writebyte(b);
|
||||||
|
}
|
||||||
|
|
||||||
|
void out_AbsByteGroup(uint8_t const *s, int32_t length)
|
||||||
|
{
|
||||||
|
checkcodesection();
|
||||||
|
reserveSpace(length);
|
||||||
|
|
||||||
|
while (length--)
|
||||||
|
writebyte(*s++);
|
||||||
|
}
|
||||||
|
|
||||||
|
void out_AbsWordGroup(uint8_t const *s, int32_t length)
|
||||||
|
{
|
||||||
|
checkcodesection();
|
||||||
|
reserveSpace(length * 2);
|
||||||
|
|
||||||
|
while (length--)
|
||||||
|
writeword(*s++);
|
||||||
|
}
|
||||||
|
|
||||||
|
void out_AbsLongGroup(uint8_t const *s, int32_t length)
|
||||||
|
{
|
||||||
|
checkcodesection();
|
||||||
|
reserveSpace(length * 4);
|
||||||
|
|
||||||
|
while (length--)
|
||||||
|
writelong(*s++);
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Skip this many bytes
|
||||||
|
*/
|
||||||
|
void out_Skip(int32_t skip, bool ds)
|
||||||
|
{
|
||||||
|
checksection();
|
||||||
|
reserveSpace(skip);
|
||||||
|
|
||||||
|
if (!ds && sect_HasData(pCurrentSection->type))
|
||||||
|
warning(WARNING_EMPTY_DATA_DIRECTIVE, "%s directive without data in ROM\n",
|
||||||
|
(skip == 4) ? "DL" : (skip == 2) ? "DW" : "DB");
|
||||||
|
|
||||||
|
if (!sect_HasData(pCurrentSection->type)) {
|
||||||
|
growSection(skip);
|
||||||
|
} else {
|
||||||
|
checkcodesection();
|
||||||
|
while (skip--)
|
||||||
|
writebyte(fillByte);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Output a NULL terminated string (excluding the NULL-character)
|
||||||
|
*/
|
||||||
|
void out_String(char const *s)
|
||||||
|
{
|
||||||
|
checkcodesection();
|
||||||
|
reserveSpace(strlen(s));
|
||||||
|
|
||||||
|
while (*s)
|
||||||
|
writebyte(*s++);
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Output a relocatable byte. Checking will be done to see if it
|
||||||
|
* is an absolute value in disguise.
|
||||||
|
*/
|
||||||
|
void out_RelByte(struct Expression *expr, uint32_t pcShift)
|
||||||
|
{
|
||||||
|
checkcodesection();
|
||||||
|
reserveSpace(1);
|
||||||
|
|
||||||
|
if (!rpn_isKnown(expr)) {
|
||||||
|
createPatch(PATCHTYPE_BYTE, expr, pcShift);
|
||||||
|
writebyte(0);
|
||||||
|
} else {
|
||||||
|
writebyte(expr->nVal);
|
||||||
|
}
|
||||||
|
rpn_Free(expr);
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Output several copies of a relocatable byte. Checking will be done to see if
|
||||||
|
* it is an absolute value in disguise.
|
||||||
|
*/
|
||||||
|
void out_RelBytes(uint32_t n, struct Expression *exprs, size_t size)
|
||||||
|
{
|
||||||
|
checkcodesection();
|
||||||
|
reserveSpace(n);
|
||||||
|
|
||||||
|
for (uint32_t i = 0; i < n; i++) {
|
||||||
|
struct Expression *expr = &exprs[i % size];
|
||||||
|
|
||||||
|
if (!rpn_isKnown(expr)) {
|
||||||
|
createPatch(PATCHTYPE_BYTE, expr, i);
|
||||||
|
writebyte(0);
|
||||||
|
} else {
|
||||||
|
writebyte(expr->nVal);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
for (size_t i = 0; i < size; i++)
|
||||||
|
rpn_Free(&exprs[i]);
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Output a relocatable word. Checking will be done to see if
|
||||||
|
* it's an absolute value in disguise.
|
||||||
|
*/
|
||||||
|
void out_RelWord(struct Expression *expr, uint32_t pcShift)
|
||||||
|
{
|
||||||
|
checkcodesection();
|
||||||
|
reserveSpace(2);
|
||||||
|
|
||||||
|
if (!rpn_isKnown(expr)) {
|
||||||
|
createPatch(PATCHTYPE_WORD, expr, pcShift);
|
||||||
|
writeword(0);
|
||||||
|
} else {
|
||||||
|
writeword(expr->nVal);
|
||||||
|
}
|
||||||
|
rpn_Free(expr);
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Output a relocatable longword. Checking will be done to see if
|
||||||
|
* is an absolute value in disguise.
|
||||||
|
*/
|
||||||
|
void out_RelLong(struct Expression *expr, uint32_t pcShift)
|
||||||
|
{
|
||||||
|
checkcodesection();
|
||||||
|
reserveSpace(2);
|
||||||
|
|
||||||
|
if (!rpn_isKnown(expr)) {
|
||||||
|
createPatch(PATCHTYPE_LONG, expr, pcShift);
|
||||||
|
writelong(0);
|
||||||
|
} else {
|
||||||
|
writelong(expr->nVal);
|
||||||
|
}
|
||||||
|
rpn_Free(expr);
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Output a PC-relative relocatable byte. Checking will be done to see if it
|
||||||
|
* is an absolute value in disguise.
|
||||||
|
*/
|
||||||
|
void out_PCRelByte(struct Expression *expr, uint32_t pcShift)
|
||||||
|
{
|
||||||
|
checkcodesection();
|
||||||
|
reserveSpace(1);
|
||||||
|
struct Symbol const *pc = sym_GetPC();
|
||||||
|
|
||||||
|
if (!rpn_IsDiffConstant(expr, pc)) {
|
||||||
|
createPatch(PATCHTYPE_JR, expr, pcShift);
|
||||||
|
writebyte(0);
|
||||||
|
} else {
|
||||||
|
struct Symbol const *sym = rpn_SymbolOf(expr);
|
||||||
|
/* The offset wraps (jump from ROM to HRAM, for example) */
|
||||||
|
int16_t offset;
|
||||||
|
|
||||||
|
/* Offset is relative to the byte *after* the operand */
|
||||||
|
if (sym == pc)
|
||||||
|
offset = -2; /* PC as operand to `jr` is lower than reference PC by 2 */
|
||||||
|
else
|
||||||
|
offset = sym_GetValue(sym) - (sym_GetValue(pc) + 1);
|
||||||
|
|
||||||
|
if (offset < -128 || offset > 127) {
|
||||||
|
error("jr target out of reach (expected -129 < %" PRId16 " < 128)\n",
|
||||||
|
offset);
|
||||||
|
writebyte(0);
|
||||||
|
} else {
|
||||||
|
writebyte(offset);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
rpn_Free(expr);
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Output a binary file
|
||||||
|
*/
|
||||||
|
void out_BinaryFile(char const *s, int32_t startPos)
|
||||||
|
{
|
||||||
|
if (startPos < 0) {
|
||||||
|
error("Start position cannot be negative (%" PRId32 ")\n", startPos);
|
||||||
|
startPos = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
char *fullPath = NULL;
|
||||||
|
size_t size = 0;
|
||||||
|
FILE *f = NULL;
|
||||||
|
|
||||||
|
if (fstk_FindFile(s, &fullPath, &size))
|
||||||
|
f = fopen(fullPath, "rb");
|
||||||
|
free(fullPath);
|
||||||
|
|
||||||
|
if (!f) {
|
||||||
|
if (oGeneratedMissingIncludes) {
|
||||||
|
if (verbose)
|
||||||
|
printf("Aborting (-MG) on INCBIN file '%s' (%s)\n", s, strerror(errno));
|
||||||
|
oFailedOnMissingInclude = true;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
error("Error opening INCBIN file '%s': %s\n", s, strerror(errno));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
int32_t fsize = -1;
|
||||||
|
int byte;
|
||||||
|
|
||||||
|
checkcodesection();
|
||||||
|
if (fseek(f, 0, SEEK_END) != -1) {
|
||||||
|
fsize = ftell(f);
|
||||||
|
|
||||||
|
if (startPos > fsize) {
|
||||||
|
error("Specified start position is greater than length of file\n");
|
||||||
|
fclose(f);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
fseek(f, startPos, SEEK_SET);
|
||||||
|
reserveSpace(fsize - startPos);
|
||||||
|
} else {
|
||||||
|
if (errno != ESPIPE)
|
||||||
|
error("Error determining size of INCBIN file '%s': %s\n",
|
||||||
|
s, strerror(errno));
|
||||||
|
/* The file isn't seekable, so we'll just skip bytes */
|
||||||
|
while (startPos--)
|
||||||
|
(void)fgetc(f);
|
||||||
|
}
|
||||||
|
|
||||||
|
while ((byte = fgetc(f)) != EOF) {
|
||||||
|
if (fsize == -1)
|
||||||
|
growSection(1);
|
||||||
|
writebyte(byte);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (ferror(f))
|
||||||
|
error("Error reading INCBIN file '%s': %s\n", s, strerror(errno));
|
||||||
|
|
||||||
|
fclose(f);
|
||||||
|
}
|
||||||
|
|
||||||
|
void out_BinaryFileSlice(char const *s, int32_t start_pos, int32_t length)
|
||||||
|
{
|
||||||
|
if (start_pos < 0) {
|
||||||
|
error("Start position cannot be negative (%" PRId32 ")\n", start_pos);
|
||||||
|
start_pos = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (length < 0) {
|
||||||
|
error("Number of bytes to read cannot be negative (%" PRId32 ")\n", length);
|
||||||
|
length = 0;
|
||||||
|
}
|
||||||
|
if (length == 0) /* Don't even bother with 0-byte slices */
|
||||||
|
return;
|
||||||
|
|
||||||
|
char *fullPath = NULL;
|
||||||
|
size_t size = 0;
|
||||||
|
FILE *f = NULL;
|
||||||
|
|
||||||
|
if (fstk_FindFile(s, &fullPath, &size))
|
||||||
|
f = fopen(fullPath, "rb");
|
||||||
|
|
||||||
|
if (!f) {
|
||||||
|
free(fullPath);
|
||||||
|
if (oGeneratedMissingIncludes) {
|
||||||
|
if (verbose)
|
||||||
|
printf("Aborting (-MG) on INCBIN file '%s' (%s)\n", s, strerror(errno));
|
||||||
|
oFailedOnMissingInclude = true;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
error("Error opening INCBIN file '%s': %s\n", s, strerror(errno));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
checkcodesection();
|
||||||
|
reserveSpace(length);
|
||||||
|
|
||||||
|
int32_t fsize;
|
||||||
|
|
||||||
|
if (fseek(f, 0, SEEK_END) != -1) {
|
||||||
|
fsize = ftell(f);
|
||||||
|
|
||||||
|
if (start_pos > fsize) {
|
||||||
|
error("Specified start position is greater than length of file\n");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ((start_pos + length) > fsize) {
|
||||||
|
error("Specified range in INCBIN is out of bounds (%" PRIu32 " + %" PRIu32
|
||||||
|
" > %" PRIu32 ")\n", start_pos, length, fsize);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
fseek(f, start_pos, SEEK_SET);
|
||||||
|
} else {
|
||||||
|
if (errno != ESPIPE)
|
||||||
|
error("Error determining size of INCBIN file '%s': %s\n",
|
||||||
|
s, strerror(errno));
|
||||||
|
/* The file isn't seekable, so we'll just skip bytes */
|
||||||
|
while (start_pos--)
|
||||||
|
(void)fgetc(f);
|
||||||
|
}
|
||||||
|
|
||||||
|
int32_t todo = length;
|
||||||
|
|
||||||
|
while (todo--) {
|
||||||
|
int byte = fgetc(f);
|
||||||
|
|
||||||
|
if (byte != EOF) {
|
||||||
|
writebyte(byte);
|
||||||
|
} else if (ferror(f)) {
|
||||||
|
error("Error reading INCBIN file '%s': %s\n", s, strerror(errno));
|
||||||
|
} else {
|
||||||
|
error("Premature end of file (%" PRId32 " bytes left to read)\n",
|
||||||
|
todo + 1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fclose(f);
|
||||||
|
free(fullPath);
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Section stack routines
|
||||||
|
*/
|
||||||
|
void out_PushSection(void)
|
||||||
|
{
|
||||||
|
struct SectionStackEntry *sect = malloc(sizeof(*sect));
|
||||||
|
|
||||||
|
if (sect == NULL)
|
||||||
|
fatalerror("No memory for section stack: %s\n", strerror(errno));
|
||||||
|
sect->section = pCurrentSection;
|
||||||
|
sect->scope = sym_GetCurrentSymbolScope();
|
||||||
|
sect->offset = curOffset;
|
||||||
|
sect->next = sectionStack;
|
||||||
|
sectionStack = sect;
|
||||||
|
/* TODO: maybe set current section to NULL? */
|
||||||
|
}
|
||||||
|
|
||||||
|
void out_PopSection(void)
|
||||||
|
{
|
||||||
|
if (!sectionStack)
|
||||||
|
fatalerror("No entries in the section stack\n");
|
||||||
|
|
||||||
|
if (currentLoadSection)
|
||||||
|
fatalerror("Cannot change the section within a `LOAD` block!\n");
|
||||||
|
|
||||||
|
struct SectionStackEntry *sect;
|
||||||
|
|
||||||
|
sect = sectionStack;
|
||||||
|
changeSection();
|
||||||
|
pCurrentSection = sect->section;
|
||||||
|
sym_SetCurrentSymbolScope(sect->scope);
|
||||||
|
curOffset = sect->offset;
|
||||||
|
|
||||||
|
sectionStack = sect->next;
|
||||||
|
free(sect);
|
||||||
|
}
|
||||||
+599
-681
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,83 @@
|
|||||||
|
/*
|
||||||
|
* This file is part of RGBDS.
|
||||||
|
*
|
||||||
|
* Copyright (c) 1997-2019, Carsten Sorensen and RGBDS contributors.
|
||||||
|
*
|
||||||
|
* SPDX-License-Identifier: MIT
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <ctype.h>
|
||||||
|
#include <stdint.h>
|
||||||
|
|
||||||
|
#include "asm/main.h"
|
||||||
|
#include "asm/util.h"
|
||||||
|
#include "asm/warning.h"
|
||||||
|
|
||||||
|
#include "extern/utf8decoder.h"
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Calculate the hash value for a string.
|
||||||
|
* Uses the djb2 algorithm (xor version).
|
||||||
|
* http://www.cse.yorku.ca/~oz/hash.html
|
||||||
|
*/
|
||||||
|
uint32_t calchash(const char *s)
|
||||||
|
{
|
||||||
|
uint32_t hash = 5381;
|
||||||
|
|
||||||
|
while (*s != 0)
|
||||||
|
hash = (hash * 33) ^ (*s++);
|
||||||
|
|
||||||
|
return hash;
|
||||||
|
}
|
||||||
|
|
||||||
|
char const *print(int c)
|
||||||
|
{
|
||||||
|
static char buf[5]; /* '\xNN' + '\0' */
|
||||||
|
|
||||||
|
if (c == EOF)
|
||||||
|
return "EOF";
|
||||||
|
|
||||||
|
if (isprint(c)) {
|
||||||
|
buf[0] = c;
|
||||||
|
buf[1] = '\0';
|
||||||
|
return buf;
|
||||||
|
}
|
||||||
|
|
||||||
|
buf[0] = '\\';
|
||||||
|
switch (c) {
|
||||||
|
case '\n':
|
||||||
|
buf[1] = 'n';
|
||||||
|
break;
|
||||||
|
case '\r':
|
||||||
|
buf[1] = 'r';
|
||||||
|
break;
|
||||||
|
case '\t':
|
||||||
|
buf[1] = 't';
|
||||||
|
break;
|
||||||
|
|
||||||
|
default: /* Print as hex */
|
||||||
|
buf[1] = 'x';
|
||||||
|
sprintf(&buf[2], "%02hhx", (uint8_t)c);
|
||||||
|
return buf;
|
||||||
|
}
|
||||||
|
buf[2] = '\0';
|
||||||
|
return buf;
|
||||||
|
}
|
||||||
|
|
||||||
|
size_t readUTF8Char(uint8_t *dest, char const *src)
|
||||||
|
{
|
||||||
|
uint32_t state = 0;
|
||||||
|
uint32_t codep;
|
||||||
|
size_t i = 0;
|
||||||
|
|
||||||
|
for (;;) {
|
||||||
|
if (decode(&state, &codep, src[i]) == 1)
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
dest[i] = src[i];
|
||||||
|
i++;
|
||||||
|
|
||||||
|
if (state == 0)
|
||||||
|
return i;
|
||||||
|
}
|
||||||
|
}
|
||||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user