mirror of
https://github.com/d0k3/GodMode9.git
synced 2025-06-26 13:42:47 +00:00
Compare commits
534 Commits
Author | SHA1 | Date | |
---|---|---|---|
|
cf1cb1cfc5 | ||
|
9ae4351bce | ||
|
99f1abd7a4 | ||
|
15eb3b1ebe | ||
|
4424c37a89 | ||
|
bc84780036 | ||
|
712df196f1 | ||
|
a20c955e2a | ||
|
7b20581fce | ||
|
ba0272ff5d | ||
|
50270a820c | ||
|
61c79e3e3f | ||
|
ab222de6b1 | ||
|
143fcf0d6b | ||
|
157848c770 | ||
|
8cde50e091 | ||
|
105f4ae5f7 | ||
|
9e7df4c52d | ||
|
208f12bde7 | ||
|
7b6b478582 | ||
|
eee63dd155 | ||
|
dab90a9162 | ||
|
26990ca23a | ||
|
338a2aa98a | ||
|
399740b50e | ||
|
ad8b5e0a8c | ||
|
14b390a943 | ||
|
031762a1fe | ||
|
8b362c977a | ||
|
11b05d7a3d | ||
|
3008bfed61 | ||
|
f7a9b3eec8 | ||
|
e1fa23a031 | ||
|
8006fbd5db | ||
|
b4f04d3620 | ||
|
eb37a21354 | ||
|
a68d7d0cb7 | ||
|
87f9b82cd3 | ||
|
a293c008d5 | ||
|
780016933c | ||
|
041ff61d41 | ||
|
1fd15657d8 | ||
|
0971b3d9fa | ||
|
b7c97af144 | ||
|
723529e2d8 | ||
|
b5fca3bc7e | ||
|
620e5061c5 | ||
|
5aaac66eef | ||
|
439e06334b | ||
|
8303440c19 | ||
|
93ee590cad | ||
|
cae3d272d3 | ||
|
64414e12ab | ||
|
9514755989 | ||
|
ccd21984b2 | ||
|
a23ba0e14b | ||
|
3710ed975b | ||
|
9416ec5ac0 | ||
|
c9d792cb27 | ||
|
096e6c3cb7 | ||
|
b11194397a | ||
|
658c9b491c | ||
|
f611b31c0c | ||
|
c13bba4cfe | ||
|
d95a606ec2 | ||
|
586d30fafa | ||
|
682b570ef7 | ||
|
8d1557191f | ||
|
cb11db6f1b | ||
|
1554aac4e1 | ||
|
fdbca10773 | ||
|
1f8de2af99 | ||
|
1b8bd121b6 | ||
|
ba10ce96c3 | ||
|
25bf8b3f93 | ||
|
07cb94d99a | ||
|
1ffbca7d46 | ||
|
942e67e507 | ||
|
830479f50c | ||
|
0275a85121 | ||
|
3eb92754bc | ||
|
77fc7af2f2 | ||
|
b366200d4b | ||
|
13eb4f8869 | ||
|
55385a5502 | ||
|
0dbe70928f | ||
|
7feeb51a65 | ||
|
c966acc851 | ||
|
e042886db4 | ||
|
ddf577b88c | ||
|
3124d944a6 | ||
|
27e316571d | ||
|
0e46d4fca8 | ||
|
33d59f6d3a | ||
|
d85023b173 | ||
|
4dc96d37e8 | ||
|
c9b6a335f7 | ||
|
33a115b75c | ||
|
ef161bce42 | ||
|
d8d43c14f3 | ||
|
37c8c50097 | ||
|
c2d96c0d9c | ||
|
41d36c620f | ||
|
4b5ac1a8e0 | ||
|
be289b4c55 | ||
|
3bfb9ef6ec | ||
|
1f96b5e9e6 | ||
|
8427e0776c | ||
|
61c17e491f | ||
|
236d2dc09c | ||
|
8680358aa1 | ||
|
7e01954e48 | ||
|
0825139cb2 | ||
|
9f431a5fde | ||
|
cc99734fac | ||
|
6799b24730 | ||
|
adb8ad260f | ||
|
5c2ab6958c | ||
|
7af76b91bb | ||
|
ce50bd63a8 | ||
|
1a27dcb1e8 | ||
|
c20911047a | ||
|
fd8c5d1897 | ||
|
0bbbc7c324 | ||
|
9f52deedad | ||
|
60f2c5192d | ||
|
f2e52bd1c7 | ||
|
dfb2dff352 | ||
|
1cb72a87e1 | ||
|
3952de3a1e | ||
|
294890057f | ||
|
4e00b8b7b6 | ||
|
ddfdf81cf7 | ||
|
8b5af2c22f | ||
|
445688c5fb | ||
|
8fa85437dd | ||
|
2cd6acb31e | ||
|
c70a7db0f3 | ||
|
7bdd01738a | ||
|
152c6c4d5a | ||
|
32936345a6 | ||
|
30c5e1fd67 | ||
|
3f7eb872b8 | ||
|
bea16124a4 | ||
|
71e3b6f73c | ||
|
ee43fe328f | ||
|
31389687ab | ||
|
eadc1ab6b9 | ||
|
9ecb90a2ba | ||
|
a6e20c641a | ||
|
c4b3b582a7 | ||
|
c31737c257 | ||
|
2f61722aa4 | ||
|
ab4316fd4e | ||
|
24195c319a | ||
|
f9408a9c10 | ||
|
8114a0bd26 | ||
|
7620310b73 | ||
|
1e9fb36582 | ||
|
9191a3244f | ||
|
af5e1a218e | ||
|
667a1bf2c0 | ||
|
48347c947a | ||
|
e41b098843 | ||
|
58fb9913d5 | ||
|
899c8a8816 | ||
|
203cf7f9e3 | ||
|
8ebb74b0bc | ||
|
af14376c84 | ||
|
647d5722aa | ||
|
25a22d30d0 | ||
|
2f2b7faeb4 | ||
|
efcfed31b3 | ||
|
7f6f6db410 | ||
|
e9599aad1c | ||
|
46a9a5819a | ||
|
65f6748dc1 | ||
|
d63db4bc6d | ||
|
cadd21508f | ||
|
01dd46ced3 | ||
|
e95e0fe90c | ||
|
608cf39e12 | ||
|
df4619b213 | ||
|
cebc43792e | ||
|
89be93384d | ||
|
145bf6de54 | ||
|
355519285a | ||
|
ae32e63074 | ||
|
d5db8c7216 | ||
|
f2876b2a61 | ||
|
3b59b0bbfb | ||
|
bd7658a808 | ||
|
7c01e1dfe9 | ||
|
8e2d1d465e | ||
|
d010f2858b | ||
|
d682a65df6 | ||
|
1f2514f19e | ||
|
a2e574a451 | ||
|
9189320e8b | ||
|
896d548851 | ||
|
df9b84fc66 | ||
|
f7c229b424 | ||
|
253cb2849c | ||
|
158fa78a5d | ||
|
62fd3e93c5 | ||
|
ffeb551a3f | ||
|
c7f10be1b4 | ||
|
f48bb58bac | ||
|
15bf632143 | ||
|
50e3e1f19a | ||
|
99b69754b2 | ||
|
4af0268e5a | ||
|
e5ffa885b6 | ||
|
f0ad45dd60 | ||
|
6eb546dfab | ||
|
18e6d9f0db | ||
|
0af181ac6a | ||
|
3aa9a1633a | ||
|
ce498103e1 | ||
|
7edf8a998b | ||
|
68a4ceac5b | ||
|
0038e7d0ab | ||
|
03007c2b42 | ||
|
8375434093 | ||
|
bf767f2c01 | ||
|
4dc5661d58 | ||
|
8863979a99 | ||
|
0ee1368153 | ||
|
a051b07791 | ||
|
596e7e499c | ||
|
d4d8c9a0ff | ||
|
7fb194caea | ||
|
521fb25075 | ||
|
829880994f | ||
|
e744be504b | ||
|
e7fdf993a7 | ||
|
89c5107733 | ||
|
9766a0be5e | ||
|
24d2a4ea5b | ||
|
214edfc399 | ||
|
cb870d2b02 | ||
|
d8aeb056cb | ||
|
b8798f2aff | ||
|
e559c2b4a1 | ||
|
32b6838d32 | ||
|
8fcdde29c8 | ||
|
77f1f94e13 | ||
|
e568348086 | ||
|
6116545fef | ||
|
e916476563 | ||
|
d2c47b7977 | ||
|
8a7448995f | ||
|
07c009de72 | ||
|
f96daa407a | ||
|
f835469e19 | ||
|
2791b42f6e | ||
|
d7444e144a | ||
|
3973ce57df | ||
|
929cc7fdcf | ||
|
698ad9d891 | ||
|
6b54290cf2 | ||
|
79768acef7 | ||
|
4e9721db9b | ||
|
5e307a3f32 | ||
|
6487307cf0 | ||
|
5905fb84fb | ||
|
30f0b004c2 | ||
|
f20d2657fa | ||
|
eb265e9575 | ||
|
8ee0fac6c4 | ||
|
6e0b6d2d0a | ||
|
75cae95509 | ||
|
519855de5b | ||
|
6b6fe4741d | ||
|
fd4fd14ee7 | ||
|
8ffe774f77 | ||
|
127008a274 | ||
|
6e63fdf4bf | ||
|
c70546d5ca | ||
|
2b94b585eb | ||
|
b51fc388c2 | ||
|
11c3a4a71b | ||
|
fd93df60c5 | ||
|
77b83bc89e | ||
|
2fd6915075 | ||
|
244d24ee2a | ||
|
d6e09c9c15 | ||
|
da1dff7cd7 | ||
|
43753535d7 | ||
|
a7ce125d7f | ||
|
73dc54a754 | ||
|
2793daa55f | ||
|
182f1ebe43 | ||
|
da28c0ef40 | ||
|
c265e3ac2f | ||
|
1e92163245 | ||
|
2aba1afb2e | ||
|
52034cd41f | ||
|
6541e52f05 | ||
|
e763cbaf72 | ||
|
978c4f8b86 | ||
|
ccc0ddf300 | ||
|
f7b7459d9f | ||
|
d27cfc71e1 | ||
|
4e04849860 | ||
|
e0e72142bc | ||
|
4e38973384 | ||
|
2760bb4a38 | ||
|
130ff694e2 | ||
|
98c1b25bb0 | ||
|
940284c8da | ||
|
ce9f0a25ef | ||
|
e4b98e0932 | ||
|
12bc19cc43 | ||
|
9f50d2f03c | ||
|
42f7fcfb7b | ||
|
6fb60e007a | ||
|
622d0b053c | ||
|
e446bdbfa5 | ||
|
9e1b5e0be2 | ||
|
7729605f9a | ||
|
e58760231a | ||
|
479fed35ef | ||
|
23a7ea7fd3 | ||
|
da412226be | ||
|
cfae228bcf | ||
|
a145e8d4a9 | ||
|
499e301b7b | ||
|
624ac571e4 | ||
|
1889f4fd57 | ||
|
f184ad5701 | ||
|
cfe535f20b | ||
|
cf7fa9e401 | ||
|
2e463c6b84 | ||
|
2b05453685 | ||
|
1ceba1ed6f | ||
|
ae583300e6 | ||
|
9e72c098b9 | ||
|
c847618048 | ||
|
422e54dca4 | ||
|
0f42426115 | ||
|
915cb2d13e | ||
|
4890e4116f | ||
|
5d61bebb25 | ||
|
744ab6934b | ||
|
b32b63da27 | ||
|
6d8226ac5e | ||
|
a4270eda56 | ||
|
f24db1442e | ||
|
0ec73520e6 | ||
|
dc746f69c5 | ||
|
c1b04d85d4 | ||
|
2f24f37e7b | ||
|
c51d8a7191 | ||
|
0308dfdebc | ||
|
f624850465 | ||
|
aea79aa634 | ||
|
bef427dfdb | ||
|
84d5f800a9 | ||
|
d2f596e7a3 | ||
|
48d8c48d12 | ||
|
004341e1ef | ||
|
fa741b265b | ||
|
38d9a23427 | ||
|
7b0a101f13 | ||
|
f60a4c1f63 | ||
|
fd48c95deb | ||
|
556c75c337 | ||
|
ac4ec6ee90 | ||
|
2ceafc545b | ||
|
a3cc272e63 | ||
|
01bc082ca0 | ||
|
beb2a881cd | ||
|
d4cd60eccf | ||
|
2372340e6d | ||
|
392b59976b | ||
|
00c0dac479 | ||
|
5799d99c4c | ||
|
760052f20d | ||
|
e7948d9a2f | ||
|
891c0c2a36 | ||
|
1633961707 | ||
|
0e701ea719 | ||
|
a9624b6d81 | ||
|
ea26510402 | ||
|
622fb38223 | ||
|
85c43795c3 | ||
|
47312797e2 | ||
|
53708e64dc | ||
|
380d3ced7a | ||
|
db9b2cf8ec | ||
|
97fed0a284 | ||
|
85960298e4 | ||
|
50770616d7 | ||
|
f8b9332728 | ||
|
1026a60597 | ||
|
7322e31f43 | ||
|
0283692e83 | ||
|
0b3b5529f2 | ||
|
fd5320b86f | ||
|
3e25393284 | ||
|
398c7fd14c | ||
|
2ef408f4af | ||
|
1a0fe17b6c | ||
|
c8a7c63963 | ||
|
e6b63f328b | ||
|
cb4ea7217a | ||
|
524a86e9a4 | ||
|
d6c6f56526 | ||
|
88751ab96a | ||
|
07b2a2beb6 | ||
|
3061da4dcc | ||
|
506a3d3089 | ||
|
3c8fe0f69d | ||
|
e87f69dc20 | ||
|
8f588fa8bc | ||
|
3cbbd53850 | ||
|
e7e800d44f | ||
|
9a7ff738be | ||
|
4e61bcaa50 | ||
|
ccb8531ce6 | ||
|
d928591a80 | ||
|
1403dc8ef9 | ||
|
dc9dc794b0 | ||
|
ab110bf73d | ||
|
87d4152d4e | ||
|
bd74ad00d8 | ||
|
04bf6438de | ||
|
40b4e3f541 | ||
|
ee86ffeb03 | ||
|
73e3a18ea8 | ||
|
ff491f2993 | ||
|
ae5584aca0 | ||
|
b45bb966df | ||
|
648275c097 | ||
|
f179caaef3 | ||
|
ca7944ce04 | ||
|
8b098fa91a | ||
|
256f2465d8 | ||
|
a42dbedf82 | ||
|
6823e15584 | ||
|
bb5182cae3 | ||
|
6dc89d7107 | ||
|
50e97d2dab | ||
|
73d8d14bd5 | ||
|
dbd8b8aca8 | ||
|
ca8c2070f5 | ||
|
f4fc17f145 | ||
|
7d3a5270f1 | ||
|
9cc31b6f56 | ||
|
c3152838db | ||
|
2f64a8046a | ||
|
cadc7e6982 | ||
|
ff9fde1561 | ||
|
85a189b3b6 | ||
|
df21331218 | ||
|
77f857ab64 | ||
|
dad662610d | ||
|
54caa3588e | ||
|
36c03e578c | ||
|
500333b011 | ||
|
bc66cd0ccf | ||
|
08b53f71e1 | ||
|
a6734af45d | ||
|
46a5735f5c | ||
|
ad9a9bd5a0 | ||
|
79aa9191f7 | ||
|
70757e3385 | ||
|
b52bf3b9a5 | ||
|
1b04ca4fa1 | ||
|
bf45ee3900 | ||
|
bcff09a389 | ||
|
f5a877d00b | ||
|
5e56cd2f77 | ||
|
016eac6982 | ||
|
2f86686388 | ||
|
e70b8ab116 | ||
|
987b820c4a | ||
|
9ab9c01aae | ||
|
602b6fc7df | ||
|
796457e54c | ||
|
c86ebe4baa | ||
|
151e6389ac | ||
|
afd2c6593c | ||
|
6a95643edb | ||
|
ce71e56a52 | ||
|
10425bfa03 | ||
|
d4e7f092fa | ||
|
d762c390af | ||
|
539099db81 | ||
|
21fdb9543a | ||
|
f51a48c39e | ||
|
89e9aceaaf | ||
|
1e2b45941b | ||
|
c644820e41 | ||
|
732165153b | ||
|
d50e6b88ae | ||
|
82d6e94789 | ||
|
10ec95b8fe | ||
|
a04c2beb3c | ||
|
0906b4e6d8 | ||
|
e8c853a384 | ||
|
223d327fca | ||
|
d4ea225677 | ||
|
75a23a15c3 | ||
|
f13a5c6e4f | ||
|
71d0cecf20 | ||
|
9f25b6cf25 | ||
|
e7de8b9ca3 | ||
|
449a89277e | ||
|
2b8d4fcc04 | ||
|
762edd5432 | ||
|
f58bb6e61b | ||
|
e477ec0a18 | ||
|
0286d9cde9 | ||
|
bfc3363012 | ||
|
8f24ccec0c | ||
|
5c138e1219 | ||
|
2d807915e6 | ||
|
9c4ff77476 | ||
|
29b05aee54 | ||
|
619242ef96 | ||
|
a05cc1ff56 | ||
|
cbe473450f | ||
|
b8b2c026ac | ||
|
79a00b09f9 | ||
|
14c97a7f6b | ||
|
31fd7f88e9 | ||
|
e7a1a72333 | ||
|
760238e3f4 | ||
|
e44d266d94 | ||
|
3446a43127 | ||
|
9467bd6050 | ||
|
e75c25e41d |
40
.github/ISSUE_TEMPLATE/bug_report.md
vendored
Normal file
40
.github/ISSUE_TEMPLATE/bug_report.md
vendored
Normal file
@ -0,0 +1,40 @@
|
|||||||
|
---
|
||||||
|
name: Bug report
|
||||||
|
about: Report a bug you found in GodMode9
|
||||||
|
title: "[BUG] ..."
|
||||||
|
labels: bug
|
||||||
|
assignees: ''
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
---
|
||||||
|
name: Bug report
|
||||||
|
about: Report a bug you found
|
||||||
|
title: "[BUG] ..."
|
||||||
|
labels: bug
|
||||||
|
assignees: ''
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
**So you want to report a bug?**
|
||||||
|
Hold on, there are ways you could make things easier for us:
|
||||||
|
* Give a clear description of the bug (what happened?).
|
||||||
|
* Give us clear steps to reproduce (when/how did it happen?).
|
||||||
|
* Give us info about your system (where did it happen?).
|
||||||
|
* A photograph or even a short video of the bug happening is always helpful!
|
||||||
|
|
||||||
|
**Info about your system**
|
||||||
|
Include this info to make our work easier:
|
||||||
|
* Console type (O3DS/N3DS)
|
||||||
|
* Anything special about your console? (defects, custom modifications,...)
|
||||||
|
* Bootloader (boot9strap/fastboot3ds)
|
||||||
|
* Did you chainload GodMode9 via Luma?
|
||||||
|
* Helpful hint: *if you followed the Guide, boot9strap is your bootloader and Luma is your chainloader.*
|
||||||
|
|
||||||
|
**Help yourself**
|
||||||
|
*Especially for any kind of boot issue ("GodMode9 doesn't boot")*, but also in many other cases these steps make a lot of sense and we will ask you to do them anyways:
|
||||||
|
* Check your SD card (using h2testw, f.e.) or try a different one (you wouldn't believe how common failing/fake SD cards are, and what kinds of bugs are caused by them).
|
||||||
|
* Switch to fastboot3DS using [https://github.com/d0k3/OpenFirmInstaller](OpenFirmInstaller).
|
||||||
|
|
||||||
|
**Have you actually read this?**
|
||||||
|
[] I have read the information above
|
17
.github/ISSUE_TEMPLATE/feature_request.md
vendored
Normal file
17
.github/ISSUE_TEMPLATE/feature_request.md
vendored
Normal file
@ -0,0 +1,17 @@
|
|||||||
|
---
|
||||||
|
name: Feature request
|
||||||
|
about: Suggest an idea for this GodMode9
|
||||||
|
title: "[FEATURE REQUEST] ..."
|
||||||
|
labels: feature request
|
||||||
|
assignees: ''
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
**Got a great idea on how to improve GodMode9?**
|
||||||
|
That's always appreciated. Please make sure you add all the required info here.
|
||||||
|
|
||||||
|
**Describe the feature you'd like**
|
||||||
|
Add a clear and concise description of what you want to happen.
|
||||||
|
|
||||||
|
**Describe alternatives you've considered**
|
||||||
|
Add a clear and concise description of any alternative solutions or features you've considered.
|
42
.github/workflows/ci.yml
vendored
Normal file
42
.github/workflows/ci.yml
vendored
Normal file
@ -0,0 +1,42 @@
|
|||||||
|
name: CI
|
||||||
|
|
||||||
|
on: [push, pull_request]
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
build:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
container: devkitpro/devkitarm
|
||||||
|
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v1
|
||||||
|
|
||||||
|
- name: Fix apt sources
|
||||||
|
run: |
|
||||||
|
apt-get update
|
||||||
|
apt-get -y install dirmngr
|
||||||
|
echo 'deb http://us.archive.ubuntu.com/ubuntu/ bionic main' >> /etc/apt/sources.list
|
||||||
|
apt-key adv --keyserver keyserver.ubuntu.com --recv-keys 3B4FE6ACC0B21F32
|
||||||
|
apt-get update
|
||||||
|
|
||||||
|
- name: Install and update packages
|
||||||
|
run: |
|
||||||
|
apt-get -y install python3 python3-pip p7zip-full libarchive13
|
||||||
|
python3 --version
|
||||||
|
python3 -m pip install --upgrade pip setuptools
|
||||||
|
python3 -m pip install cryptography git+https://github.com/TuxSH/firmtool.git
|
||||||
|
|
||||||
|
- name: Build Project
|
||||||
|
run: make release -j$(nproc)
|
||||||
|
|
||||||
|
- name: Prepare build artifact
|
||||||
|
working-directory: release
|
||||||
|
run: |
|
||||||
|
ZIPNAME=$(ls GodMode9-*.zip)
|
||||||
|
rm $ZIPNAME
|
||||||
|
echo "OUTNAME=${ZIPNAME%.zip}" >> $GITHUB_ENV
|
||||||
|
|
||||||
|
- uses: actions/upload-artifact@v4
|
||||||
|
with:
|
||||||
|
name: ${{ env.OUTNAME }}
|
||||||
|
path: release/*
|
||||||
|
if-no-files-found: error
|
14
.gitignore
vendored
14
.gitignore
vendored
@ -1,9 +1,11 @@
|
|||||||
# Object files
|
# Object files
|
||||||
|
*.d
|
||||||
*.o
|
*.o
|
||||||
*.ko
|
*.ko
|
||||||
*.obj
|
*.obj
|
||||||
*.elf
|
*.elf
|
||||||
*.map
|
*.map
|
||||||
|
*.dis
|
||||||
|
|
||||||
# Precompiled Headers
|
# Precompiled Headers
|
||||||
*.gch
|
*.gch
|
||||||
@ -34,15 +36,23 @@
|
|||||||
|
|
||||||
# OS leftovers
|
# OS leftovers
|
||||||
desktop.ini
|
desktop.ini
|
||||||
|
.DS_Store
|
||||||
|
|
||||||
# Sublime files
|
# Sublime files
|
||||||
*.sublime-*
|
*.sublime-*
|
||||||
|
|
||||||
|
# Visual Studio Code files
|
||||||
|
.vscode
|
||||||
|
|
||||||
# Build directories
|
# Build directories
|
||||||
|
/build
|
||||||
/output
|
/output
|
||||||
/release
|
/release
|
||||||
|
|
||||||
|
# Build leftovers
|
||||||
|
/data/README_internal.md
|
||||||
|
|
||||||
# User additions
|
# User additions
|
||||||
/data/aeskeydb.bin
|
|
||||||
/data/aeskeydb_.bin
|
|
||||||
/zzz_backup
|
/zzz_backup
|
||||||
|
/arm9/source/language.inl
|
||||||
|
*.trf
|
||||||
|
16
.travis._yml
16
.travis._yml
@ -1,16 +0,0 @@
|
|||||||
language: c
|
|
||||||
|
|
||||||
before_install:
|
|
||||||
- wget http://sourceforge.net/projects/devkitpro/files/Automated%20Installer/devkitARMupdate.pl
|
|
||||||
- export DEVKITPRO=/home/travis/devkitPro
|
|
||||||
- export DEVKITARM=${DEVKITPRO}/devkitARM
|
|
||||||
|
|
||||||
install:
|
|
||||||
- sudo perl devkitARMupdate.pl
|
|
||||||
- sudo apt-get -qq install python p7zip-full
|
|
||||||
- sudo pip install --upgrade pip setuptools
|
|
||||||
- sudo pip install cryptography
|
|
||||||
- sudo pip install git+https://github.com/TuxSH/firmtool.git
|
|
||||||
|
|
||||||
script:
|
|
||||||
- make release
|
|
80
Makefile
80
Makefile
@ -13,16 +13,34 @@ export DBUILTL := $(shell date +'%Y-%m-%d %H:%M:%S')
|
|||||||
|
|
||||||
export OUTDIR := output
|
export OUTDIR := output
|
||||||
export RELDIR := release
|
export RELDIR := release
|
||||||
|
export COMMON_DIR := ../common
|
||||||
|
|
||||||
# Definitions for initial RAM disk
|
# Definitions for initial RAM disk
|
||||||
VRAM_OUT := $(OUTDIR)/vram0.tar
|
VRAM_TAR := $(OUTDIR)/vram0.tar
|
||||||
VRAM_DATA := data
|
VRAM_DATA := data/*
|
||||||
VRAM_FLAGS := --make-new --path-limit 99 --size-limit 3145728
|
VRAM_FLAGS := --make-new --path-limit 99
|
||||||
|
ifeq ($(NTRBOOT),1)
|
||||||
|
VRAM_SCRIPTS := resources/gm9/scripts/*
|
||||||
|
endif
|
||||||
|
|
||||||
|
# Definitions for translation files
|
||||||
|
JSON_FOLDER := resources/languages
|
||||||
|
TRF_FOLDER := resources/gm9/languages
|
||||||
|
|
||||||
|
SOURCE_JSON := $(JSON_FOLDER)/source.json
|
||||||
|
LANGUAGE_INL := arm9/source/language.inl
|
||||||
|
|
||||||
|
JSON_FILES := $(filter-out $(SOURCE_JSON),$(wildcard $(JSON_FOLDER)/*.json))
|
||||||
|
TRF_FILES := $(subst $(JSON_FOLDER),$(TRF_FOLDER),$(JSON_FILES:.json=.trf))
|
||||||
|
|
||||||
ifeq ($(OS),Windows_NT)
|
ifeq ($(OS),Windows_NT)
|
||||||
PY3 := py -3
|
ifeq ($(TERM),cygwin)
|
||||||
|
PY3 := py -3 # Windows / CMD/PowerShell
|
||||||
|
else
|
||||||
|
PY3 := py # Windows / MSYS2
|
||||||
|
endif
|
||||||
else
|
else
|
||||||
PY3 := python3
|
PY3 := python3 # Unix-like
|
||||||
endif
|
endif
|
||||||
|
|
||||||
# Definitions for ARM binaries
|
# Definitions for ARM binaries
|
||||||
@ -30,22 +48,25 @@ export INCLUDE := -I"$(shell pwd)/common"
|
|||||||
|
|
||||||
export ASFLAGS := -g -x assembler-with-cpp $(INCLUDE)
|
export ASFLAGS := -g -x assembler-with-cpp $(INCLUDE)
|
||||||
export CFLAGS := -DDBUILTS="\"$(DBUILTS)\"" -DDBUILTL="\"$(DBUILTL)\"" -DVERSION="\"$(VERSION)\"" -DFLAVOR="\"$(FLAVOR)\"" \
|
export CFLAGS := -DDBUILTS="\"$(DBUILTS)\"" -DDBUILTL="\"$(DBUILTL)\"" -DVERSION="\"$(VERSION)\"" -DFLAVOR="\"$(FLAVOR)\"" \
|
||||||
-g -O2 -Wall -Wextra -Wpedantic -Wcast-align -Wformat=2 -Wno-main \
|
-g -Os -Wall -Wextra -Wcast-align -Wformat=2 -Wno-main \
|
||||||
-fomit-frame-pointer -ffast-math -std=gnu11 \
|
-fomit-frame-pointer -ffast-math -std=gnu11 -MMD -MP \
|
||||||
-Wno-unused-function -Wno-format-truncation $(INCLUDE) -ffunction-sections -fdata-sections
|
-Wno-unused-function -Wno-format-truncation -Wno-format-nonliteral $(INCLUDE) -ffunction-sections -fdata-sections
|
||||||
export LDFLAGS := -Tlink.ld -nostartfiles -Wl,--gc-sections,-z,max-page-size=512
|
export LDFLAGS := -Tlink.ld -nostartfiles -Wl,--gc-sections,-z,max-page-size=4096
|
||||||
ELF := arm9/arm9.elf arm11/arm11.elf
|
ELF := arm9/arm9_code.elf arm9/arm9_data.elf arm11/arm11.elf
|
||||||
|
|
||||||
.PHONY: all firm vram0 elf release clean
|
.PHONY: all firm $(VRAM_TAR) elf release clean
|
||||||
all: firm
|
all: firm
|
||||||
|
|
||||||
clean:
|
clean:
|
||||||
@set -e; for elf in $(ELF); do \
|
@set -e; for elf in $(ELF); do \
|
||||||
$(MAKE) --no-print-directory -C $$(dirname $$elf) clean; \
|
$(MAKE) --no-print-directory -C $$(dirname $$elf) clean; \
|
||||||
done
|
done
|
||||||
@rm -rf $(OUTDIR) $(RELDIR) $(FIRM) $(FIRMD) $(VRAM_OUT)
|
@rm -rf $(OUTDIR) $(RELDIR) $(FIRM) $(FIRMD) $(VRAM_TAR) $(LANGUAGE_INL) $(TRF_FILES)
|
||||||
|
|
||||||
release: clean
|
unmarked_readme: .FORCE
|
||||||
|
@$(PY3) utils/unmark.py -f README.md data/README_internal.md
|
||||||
|
|
||||||
|
release: clean unmarked_readme
|
||||||
@$(MAKE) --no-print-directory firm
|
@$(MAKE) --no-print-directory firm
|
||||||
@$(MAKE) --no-print-directory firm NTRBOOT=1
|
@$(MAKE) --no-print-directory firm NTRBOOT=1
|
||||||
|
|
||||||
@ -64,29 +85,44 @@ release: clean
|
|||||||
@cp $(OUTDIR)/$(FLAVOR)_dev.firm.sha $(RELDIR)/
|
@cp $(OUTDIR)/$(FLAVOR)_dev.firm.sha $(RELDIR)/
|
||||||
@cp $(ELF) $(RELDIR)/elf
|
@cp $(ELF) $(RELDIR)/elf
|
||||||
@cp $(CURDIR)/README.md $(RELDIR)
|
@cp $(CURDIR)/README.md $(RELDIR)
|
||||||
|
@cp $(CURDIR)/resources/lua-doc.md $(RELDIR)/lua-doc.md
|
||||||
@cp -R $(CURDIR)/resources/gm9 $(RELDIR)/gm9
|
@cp -R $(CURDIR)/resources/gm9 $(RELDIR)/gm9
|
||||||
@cp -R $(CURDIR)/resources/sample $(RELDIR)/sample
|
@cp -R $(CURDIR)/resources/sample $(RELDIR)/sample
|
||||||
|
|
||||||
@-7za a $(RELDIR)/$(FLAVOR)-$(VERSION)-$(DBUILTS).zip ./$(RELDIR)/*
|
@-7za a $(RELDIR)/$(FLAVOR)-$(VERSION)-$(DBUILTS).zip ./$(RELDIR)/*
|
||||||
|
|
||||||
vram0:
|
$(VRAM_TAR): $(SPLASH) $(OVERRIDE_FONT) $(VRAM_DATA) $(VRAM_SCRIPTS)
|
||||||
@mkdir -p "$(OUTDIR)"
|
@mkdir -p "$(@D)"
|
||||||
@echo "Creating $(VRAM_OUT)"
|
@echo "Creating $@"
|
||||||
@$(PY3) utils/add2tar.py $(VRAM_FLAGS) $(VRAM_OUT) $(shell ls -d $(SPLASH) $(OVERRIDE_FONT) $(VRAM_DATA)/*)
|
@$(PY3) utils/add2tar.py $(VRAM_FLAGS) $(VRAM_TAR) $(shell ls -d -1 $^)
|
||||||
|
|
||||||
|
$(LANGUAGE_INL): $(SOURCE_JSON)
|
||||||
|
@echo "Creating $@"
|
||||||
|
@$(PY3) utils/transcp.py $< $@
|
||||||
|
|
||||||
|
$(TRF_FOLDER)/%.trf: $(JSON_FOLDER)/%.json
|
||||||
|
@$(PY3) utils/transriff.py $< $@
|
||||||
|
|
||||||
%.elf: .FORCE
|
%.elf: .FORCE
|
||||||
@echo "Building $@"
|
@echo "Building $@"
|
||||||
@$(MAKE) --no-print-directory -C $(@D)
|
@$(MAKE) --no-print-directory -C $(@D) $(@F)
|
||||||
|
|
||||||
firm: $(ELF) vram0
|
# Indicate a few explicit dependencies:
|
||||||
@test `wc -c <$(VRAM_OUT)` -le 3145728
|
# The ARM9 data section depends on the VRAM drive
|
||||||
|
arm9/arm9_data.elf: $(VRAM_TAR) $(LANGUAGE_INL)
|
||||||
|
# And the code section depends on the data section being built already
|
||||||
|
arm9/arm9_code.elf: arm9/arm9_data.elf
|
||||||
|
|
||||||
|
firm: $(ELF) $(TRF_FILES)
|
||||||
@mkdir -p $(call dirname,"$(FIRM)") $(call dirname,"$(FIRMD)")
|
@mkdir -p $(call dirname,"$(FIRM)") $(call dirname,"$(FIRMD)")
|
||||||
@echo "[FLAVOR] $(FLAVOR)"
|
@echo "[FLAVOR] $(FLAVOR)"
|
||||||
@echo "[VERSION] $(VERSION)"
|
@echo "[VERSION] $(VERSION)"
|
||||||
@echo "[BUILD] $(DBUILTL)"
|
@echo "[BUILD] $(DBUILTL)"
|
||||||
@echo "[FIRM] $(FIRM)"
|
@echo "[FIRM] $(FIRM)"
|
||||||
@firmtool build $(FIRM) $(FTFLAGS) -g -A 0x18000000 -D $(ELF) $(VRAM_OUT) -C NDMA XDMA memcpy
|
@$(PY3) -m firmtool build $(FIRM) $(FTFLAGS) -g -D $(ELF) -C NDMA NDMA XDMA
|
||||||
@echo "[FIRM] $(FIRMD)"
|
@echo "[FIRM] $(FIRMD)"
|
||||||
@firmtool build $(FIRMD) $(FTDFLAGS) -g -A 0x18000000 -D $(ELF) $(VRAM_OUT) -C NDMA XDMA memcpy
|
@$(PY3) -m firmtool build $(FIRMD) $(FTDFLAGS) -g -D $(ELF) -C NDMA NDMA XDMA
|
||||||
|
|
||||||
|
vram0: $(VRAM_TAR) .FORCE # legacy target name
|
||||||
|
|
||||||
.FORCE:
|
.FORCE:
|
||||||
|
38
Makefile.build
Executable file
38
Makefile.build
Executable file
@ -0,0 +1,38 @@
|
|||||||
|
|
||||||
|
LIBS ?=
|
||||||
|
|
||||||
|
OBJECTS := $(patsubst $(SOURCE)/%.s, $(BUILD)/%.o, \
|
||||||
|
$(patsubst $(SOURCE)/%.c, $(BUILD)/%.o, \
|
||||||
|
$(call rwildcard, $(SOURCE), *.s *.c)))
|
||||||
|
|
||||||
|
OBJECTS_COMMON := $(patsubst $(COMMON_DIR)/%.c, $(BUILD)/%.cmn.o, \
|
||||||
|
$(call rwildcard, $(COMMON_DIR), *.c))
|
||||||
|
|
||||||
|
.PHONY: all
|
||||||
|
all: $(TARGET).elf
|
||||||
|
|
||||||
|
.PHONY: clean
|
||||||
|
clean:
|
||||||
|
@rm -rf $(BUILD) $(TARGET).elf $(TARGET).dis $(TARGET).map
|
||||||
|
|
||||||
|
$(TARGET).elf: $(OBJECTS) $(OBJECTS_COMMON)
|
||||||
|
@mkdir -p "$(@D)"
|
||||||
|
@$(CC) $(LDFLAGS) $^ -o $@ $(LIBS)
|
||||||
|
@$(OBJDUMP) -S -h $@ > $@.dis
|
||||||
|
|
||||||
|
$(BUILD)/%.cmn.o: $(COMMON_DIR)/%.c
|
||||||
|
@mkdir -p "$(@D)"
|
||||||
|
@echo "[$(PROCESSOR)] $<"
|
||||||
|
@$(CC) -c $(CFLAGS) -o $@ $<
|
||||||
|
|
||||||
|
$(BUILD)/%.o: $(SOURCE)/%.c
|
||||||
|
@mkdir -p "$(@D)"
|
||||||
|
@echo "[$(PROCESSOR)] $<"
|
||||||
|
@$(CC) -c $(CFLAGS) -o $@ $<
|
||||||
|
|
||||||
|
$(BUILD)/%.o: $(SOURCE)/%.s
|
||||||
|
@mkdir -p "$(@D)"
|
||||||
|
@echo "[$(PROCESSOR)] $<"
|
||||||
|
@$(CC) -c $(ASFLAGS) -o $@ $<
|
||||||
|
|
||||||
|
include $(call rwildcard, $(BUILD), *.d)
|
@ -1,3 +1,4 @@
|
|||||||
|
export OBJDUMP := arm-none-eabi-objdump
|
||||||
|
|
||||||
dirname = $(shell dirname $(1))
|
dirname = $(shell dirname $(1))
|
||||||
|
|
||||||
@ -13,18 +14,24 @@ ifeq ($(FLAVOR),SafeMode9)
|
|||||||
else ifeq ($(FLAVOR),GodMode64)
|
else ifeq ($(FLAVOR),GodMode64)
|
||||||
OVERRIDE_FONT := resources/fonts/font_c64_8x8.pbm
|
OVERRIDE_FONT := resources/fonts/font_c64_8x8.pbm
|
||||||
CFLAGS += -DDEFAULT_FONT=\"font_c64_8x8.pbm\"
|
CFLAGS += -DDEFAULT_FONT=\"font_c64_8x8.pbm\"
|
||||||
CFLAGS += -DCOLOR_STD_FONT=0xD5717B
|
CFLAGS += -DCOLOR_STD_FONT="RGB(0x7B, 0x71, 0xD5)"
|
||||||
CFLAGS += -DCOLOR_STD_BG=0xA43041
|
CFLAGS += -DCOLOR_STD_BG="RGB(0x41, 0x30, 0xA4)"
|
||||||
else ifeq ($(FLAVOR),BrickedMode9)
|
else ifeq ($(FLAVOR),BrickedMode9)
|
||||||
OVERRIDE_FONT := resources/fonts/font_nbraille_4x6.pbm
|
OVERRIDE_FONT := resources/fonts/font_nbraille_4x6.pbm
|
||||||
CFLAGS += -DDEFAULT_FONT=\"font_nbraille_4x6.pbm\"
|
CFLAGS += -DDEFAULT_FONT=\"font_nbraille_4x6.pbm\"
|
||||||
CFLAGS += -DCOLOR_STD_FONT=0x00FFFF
|
CFLAGS += -DCOLOR_STD_FONT="RGB(0xFF, 0xFF, 0x00)"
|
||||||
CFLAGS += -DCOLOR_STD_BG=0xFF0000
|
CFLAGS += -DCOLOR_STD_BG="RGB(0x00, 0x00, 0xFF)"
|
||||||
else ifeq ($(FLAVOR),ZuishMode9)
|
else ifeq ($(FLAVOR),ZuishMode9)
|
||||||
OVERRIDE_FONT := resources/fonts/font_zuish_8x8.pbm
|
OVERRIDE_FONT := resources/fonts/font_zuish_8x8.pbm
|
||||||
CFLAGS += -DDEFAULT_FONT=\"font_zuish_8x8.pbm\"
|
CFLAGS += -DDEFAULT_FONT=\"font_zuish_8x8.pbm\"
|
||||||
endif
|
endif
|
||||||
|
|
||||||
|
ifeq ($(LARGEDLC),1)
|
||||||
|
CFLAGS += -DTITLE_MAX_CONTENTS=1536
|
||||||
|
else
|
||||||
|
CFLAGS += -DTITLE_MAX_CONTENTS=1024
|
||||||
|
endif
|
||||||
|
|
||||||
ifeq ($(SALTMODE),1)
|
ifeq ($(SALTMODE),1)
|
||||||
CFLAGS += -DSALTMODE
|
CFLAGS += -DSALTMODE
|
||||||
endif
|
endif
|
||||||
@ -61,6 +68,14 @@ ifdef SD_TIMEOUT
|
|||||||
CFLAGS += -DSD_TIMEOUT=$(SD_TIMEOUT)
|
CFLAGS += -DSD_TIMEOUT=$(SD_TIMEOUT)
|
||||||
endif
|
endif
|
||||||
|
|
||||||
|
ifeq ($(NO_LUA),1)
|
||||||
|
CFLAGS += -DNO_LUA
|
||||||
|
endif
|
||||||
|
|
||||||
|
ifdef N_PANES
|
||||||
|
CFLAGS += -DN_PANES=$(N_PANES)
|
||||||
|
endif
|
||||||
|
|
||||||
ifeq ($(MONITOR_HEAP),1)
|
ifeq ($(MONITOR_HEAP),1)
|
||||||
CFLAGS += -DMONITOR_HEAP
|
CFLAGS += -DMONITOR_HEAP
|
||||||
endif
|
endif
|
||||||
|
79
README.md
79
README.md
@ -11,11 +11,11 @@ __As always, be smart, keep backups, just to be safe__.
|
|||||||
|
|
||||||
|
|
||||||
## Quick start guide
|
## Quick start guide
|
||||||
These short instructions apply to all users who have [boot9strap](https://github.com/SciresM/boot9strap) and [Luma3DS](https://github.com/AuroraWright/Luma3DS) installed (Luma3DS set up with standard paths), which will be the majority of all GodMode9 users. Here's how to set it up quickly:
|
The recommended bootloader for use with GodMode9 is [fastboot3DS](https://github.com/derrekr/fastboot3DS). There are [known issues for some users](https://github.com/d0k3/GodMode9/issues/466) when using the standard setup based on [boot9strap](https://github.com/SciresM/boot9strap) and [Luma3DS](https://github.com/AuroraWright/Luma3DS). If you insist on using that setup follow the instructions found in a [certain guide](https://3ds.hacks.guide). Here's how to set up GodMode9 (and fastboot3DS) up quickly:
|
||||||
* Rename `GodMode9.firm` (from the release archive) to `X_GodMode9.firm` (change `X` to the button of your choice) and put it into `sd:/luma/payloads/`
|
* Download [OpenFirmInstaller](https://github.com/d0k3/OpenFirmInstaller/releases/tag/v0.0.9) and follow the quick setup instructions found there.
|
||||||
* Copy the `gm9` folder from the release archive to your SD card. Then, get good versions of `seeddb.bin` and `encTitleKeys.bin` from somewhere (don't ask me!) and put these two files into `sd:/gm9/support` (optional but recommended for full functionality).
|
* Copy the `gm9` folder from the release archive to your SD card. Then, get good versions of `seeddb.bin` and `encTitleKeys.bin` from somewhere (don't ask me!) and put these two files into `sd:/gm9/support` (optional but recommended for full functionality).
|
||||||
* It is also recommended you setup the RTC clock if you're running GodMode9 for the first time. Find the option via HOME button -> `More...`. Also keep in mind that you should fix your system OS clock afterwards.
|
* It is also recommended you setup the RTC clock if you're running GodMode9 for the first time. Find the option via HOME button -> `More...`. Also keep in mind that you should fix your system OS clock afterwards. While you're in the `More...` menu, you may also set screen brightness to a fixed value of your choosing and manually calibrate the touch screen (*not recommended* - try the automatic configuration first).
|
||||||
* Helpful hint #1: Go [here](https://3ds.guide/godmode9-usage) for step by steps on doing some common tasks in GodMode9. Especially users coming from Decrypt9WIP or Hourglass9 may find this to be helpful.
|
* Helpful hint #1: Go [here](https://3ds.hacks.guide/godmode9-usage) for step by steps on doing some common tasks in GodMode9. Especially users coming from Decrypt9WIP or Hourglass9 may find this to be helpful.
|
||||||
* Helpful hint #2: __Never unlock the red write permission level unless you know exactly what you're doing__. You will notice that prompt when it comes up, it features a completely red screen. It is recommended you stay on the yellow permission level or below at all times to be completely safe. Also read more on the write permissions system below.
|
* Helpful hint #2: __Never unlock the red write permission level unless you know exactly what you're doing__. You will notice that prompt when it comes up, it features a completely red screen. It is recommended you stay on the yellow permission level or below at all times to be completely safe. Also read more on the write permissions system below.
|
||||||
|
|
||||||
You may now run GodMode9 via holding the X Button (or any other button you chose) at startup. See below for a list of stuff you can do with it.
|
You may now run GodMode9 via holding the X Button (or any other button you chose) at startup. See below for a list of stuff you can do with it.
|
||||||
@ -31,7 +31,7 @@ GodMode9 is designed to be intuitive, buttons leading to the results you'd expec
|
|||||||
* __\<R> button__: The \<R> button is the 'switch' button. It switches buttons to their secondary function. Notable exceptions are \<R+L> for a screenshot (works almost anywhere), \<R+LEFT> / \<R+RIGHT> to switch panes and \<R+DOWN> to reload the file listing.
|
* __\<R> button__: The \<R> button is the 'switch' button. It switches buttons to their secondary function. Notable exceptions are \<R+L> for a screenshot (works almost anywhere), \<R+LEFT> / \<R+RIGHT> to switch panes and \<R+DOWN> to reload the file listing.
|
||||||
* __\<START> button__: Use the \<START> button to reboot from GodMode9. Use \<R+START> to poweroff your 3DS.
|
* __\<START> button__: Use the \<START> button to reboot from GodMode9. Use \<R+START> to poweroff your 3DS.
|
||||||
* __\<SELECT> button__: The \<SELECT> button clears or restores the clipboard (depending on if it's empty or not).
|
* __\<SELECT> button__: The \<SELECT> button clears or restores the clipboard (depending on if it's empty or not).
|
||||||
* __\<HOME> button__: The \<HOME> button enters the HOME menu, including the scripts / payloads submenus, options for formatting the SD, setting the RTC, and more.
|
* __\<HOME> button__: The \<HOME> button enters the HOME menu, including the scripts / payloads submenus, options for formatting the SD, setting the RTC, and more. The \<POWER> button is an alternative way of entering the HOME menu.
|
||||||
* __\<R+UP> combo__: This little known keycombo, when held at startup, pauses the GodMode9 boot so that you can stare at the splash screen for a little longer.
|
* __\<R+UP> combo__: This little known keycombo, when held at startup, pauses the GodMode9 boot so that you can stare at the splash screen for a little longer.
|
||||||
* __\<R+LEFT> combo__: If you have installed GodMode9 as your bootloader, this keycombo enters the bootmenu. Hold on startup! If you built GodMode9 as SALTMODE and have it as a bootloader, the keycombo is simply the \<START> button.
|
* __\<R+LEFT> combo__: If you have installed GodMode9 as your bootloader, this keycombo enters the bootmenu. Hold on startup! If you built GodMode9 as SALTMODE and have it as a bootloader, the keycombo is simply the \<START> button.
|
||||||
|
|
||||||
@ -39,9 +39,9 @@ GodMode9 is designed to be intuitive, buttons leading to the results you'd expec
|
|||||||
## How to build this / developer info
|
## How to build this / developer info
|
||||||
Build `GodMode9.firm` via `make firm`. This requires [firmtool](https://github.com/TuxSH/firmtool), [Python 3.5+](https://www.python.org/downloads/) and [devkitARM](https://sourceforge.net/projects/devkitpro/) installed).
|
Build `GodMode9.firm` via `make firm`. This requires [firmtool](https://github.com/TuxSH/firmtool), [Python 3.5+](https://www.python.org/downloads/) and [devkitARM](https://sourceforge.net/projects/devkitpro/) installed).
|
||||||
|
|
||||||
You may run `make release` to get a nice, release-ready package of all required files. To build __SafeMode9__ (a bricksafe variant of GodMode9, with limited write permissions) instead of GodMode9, compile with `make FLAVOR=SafeMode9`. To switch screens, compile with `make SWITCH_SCREENS=1`. For additional customization, you may choose the internal font by replacing `font_default.pbm` inside the `data` directory. You may also hardcode the brightness via `make FIXED_BRIGHTNESS=x`, whereas `x` is a value between 0...15.
|
You may run `make release` to get a nice, release-ready package of all required files. To build __SafeMode9__ (a bricksafe variant of GodMode9, with limited write permissions) instead of GodMode9, compile with `make FLAVOR=SafeMode9`. To switch screens, compile with `make SWITCH_SCREENS=1`. For additional customization, you may choose the internal font by replacing `font_default.frf` inside the `data` directory. You may also hardcode the brightness via `make FIXED_BRIGHTNESS=x`, whereas `x` is a value between 0...15.
|
||||||
|
|
||||||
Further customization is possible by hardcoding `aeskeydb.bin` (just put the file into the `data` folder when compiling). All files put into the `data` folder will turn up in the `V:` drive, but keep in mind there's a hard 3MB limit for all files inside, including overhead. A standalone script runner is compiled by providing `autorun.gm9` (again, in the `data` folder) and building with `make SCRIPT_RUNNER=1`.
|
Further customization is possible by hardcoding `aeskeydb.bin` (just put the file into the `data` folder when compiling). All files put into the `data` folder will turn up in the `V:` drive, but keep in mind there's a hard 223.5KiB limit for all files inside, including overhead. A standalone script runner is compiled by providing `autorun.lua` or `autorun.gm9` (again, in the `data` folder) and building with `make SCRIPT_RUNNER=1`. There's more possibility for customization, read the Makefiles to learn more.
|
||||||
|
|
||||||
To build a .firm signed with SPI boot keys (for ntrboot and the like), run `make NTRBOOT=1`. You may need to rename the output files if the ntrboot installer you use uses hardcoded filenames. Some features such as boot9 / boot11 access are not currently available from the ntrboot environment.
|
To build a .firm signed with SPI boot keys (for ntrboot and the like), run `make NTRBOOT=1`. You may need to rename the output files if the ntrboot installer you use uses hardcoded filenames. Some features such as boot9 / boot11 access are not currently available from the ntrboot environment.
|
||||||
|
|
||||||
@ -61,10 +61,14 @@ GodMode9 provides a write permissions system, which will protect you from accide
|
|||||||
|
|
||||||
## Support files
|
## Support files
|
||||||
For certain functionality, GodMode9 may need 'support files'. Support files should be placed into either `0:/gm9/support` or `1:/gm9/support`. Support files contain additional information that is required in decryption operations. A list of support files, and what they do, is found below. Please don't ask for support files - find them yourself.
|
For certain functionality, GodMode9 may need 'support files'. Support files should be placed into either `0:/gm9/support` or `1:/gm9/support`. Support files contain additional information that is required in decryption operations. A list of support files, and what they do, is found below. Please don't ask for support files - find them yourself.
|
||||||
* __`aeskeydb.bin`__: This should contain 0x25keyX, 0x18keyX and 0x1BkeyX to enable decryption of 7x / Secure3 / Secure4 encrypted NCCH files, 0x11key95 / 0x11key96 for FIRM decrypt support and 0x11keyOTP / 0x11keyIVOTP for 'secret' sector 0x96 crypto support. Entrypoints other than [boot9strap](https://github.com/SciresM/boot9strap) or [fastboot3ds](https://github.com/derrekr/fastboot3DS) may require a aeskeydb.bin file. A known perfect `aeskeydb.bin` can be found somewhere on the net, is exactly 1024 byte big and has an MD5 of A5B28945A7C051D7A0CD18AF0E580D1B. Have fun hunting!
|
* __`aeskeydb.bin`__: This should contain 0x25keyX, 0x18keyX and 0x1BkeyX to enable decryption of 7x / Secure3 / Secure4 encrypted NCCH files, 0x11key95 / 0x11key96 for FIRM decrypt support and 0x11keyOTP / 0x11keyIVOTP for 'secret' sector 0x96 crypto support. Entrypoints other than [boot9strap](https://github.com/SciresM/boot9strap) or [fastboot3ds](https://github.com/derrekr/fastboot3DS) may require a aeskeydb.bin file. This is now included in standard releases of GM9. No need to hunt down the file!
|
||||||
* __`seeddb.bin`__: This file is required to decrypt and mount seed encrypted NCCHs and CIAs if the seed in question is not installed to your NAND. Note that your seeddb.bin must also contain the seed for the specific game you need to decrypt.
|
* __`seeddb.bin`__: This file is optional and required to decrypt and mount seed-encrypted NCCHs and CIAs (if the seed in question is not installed to your NAND). Note that your seeddb.bin must also contain the seed for the specific game you need to decrypt.
|
||||||
* __`encTitleKeys.bin`__ / __`decTitleKeys.bin`__: These files are optional and provide titlekeys, which are required to create updatable CIAs from NCCH / NCSD files. CIAs created without these files will still work, but won't be updatable from eShop.
|
* __`encTitleKeys.bin`__ / __`decTitleKeys.bin`__: These files are optional and provide titlekeys, which are required to decrypt and install contents downloaded from CDN (for DSi and 3DS content).
|
||||||
|
|
||||||
|
### Fonts and translations
|
||||||
|
GodMode9 also supports custom fonts and translations as support files. These both use custom formats, fonts use FRF (Font RIFF) files which can be created using the `fontriff.py` Python script in the 'utils' folder. Translations use TRF (Translation RIFF) files from the `transriff.py` script. Examples of the inputs to these scripts can be found in the 'fonts' and 'languages' folders of the 'resources' folder respectively.
|
||||||
|
|
||||||
|
TRF files can be placed in `0:/gm9/languages` to show in the language menu accessible from the HOME menu and shown on first load. Official translations are provided from the community via the [GodMode9 Crowdin](https://crowdin.com/project/GodMode9). Languages can use a special font by having an FRF with the same name, for example `en.trf` and `en.frf`.
|
||||||
|
|
||||||
## Drives in GodMode9
|
## Drives in GodMode9
|
||||||
GodMode9 provides access to system data via drives, a listing of what each drive contains and additional info follows below. Some of these drives are removable (such as drive `7:`), some will only turn up if they are available (drive `8:` and everything associated with EmuNAND, f.e.). Information on the 3DS console file system is also found on [3Dbrew.org](https://3dbrew.org/wiki/Flash_Filesystem).
|
GodMode9 provides access to system data via drives, a listing of what each drive contains and additional info follows below. Some of these drives are removable (such as drive `7:`), some will only turn up if they are available (drive `8:` and everything associated with EmuNAND, f.e.). Information on the 3DS console file system is also found on [3Dbrew.org](https://3dbrew.org/wiki/Flash_Filesystem).
|
||||||
@ -86,12 +90,22 @@ GodMode9 provides access to system data via drives, a listing of what each drive
|
|||||||
* __`C: GAMECART`__: This is read-only and provides access to the game cartridge currently inserted into the cart slot. This can be used for dumps of CTR and TWL mode cartridges. Flash cards are supported only to a limited extent.
|
* __`C: GAMECART`__: This is read-only and provides access to the game cartridge currently inserted into the cart slot. This can be used for dumps of CTR and TWL mode cartridges. Flash cards are supported only to a limited extent.
|
||||||
* __`G: GAME IMAGE`__: CIA/NCSD/NCCH/EXEFS/ROMFS/FIRM images can be accessed via this drive when mounted. This is read-only.
|
* __`G: GAME IMAGE`__: CIA/NCSD/NCCH/EXEFS/ROMFS/FIRM images can be accessed via this drive when mounted. This is read-only.
|
||||||
* __`K: AESKEYDB IMAGE`__: An `aeskeydb.bin` image can be mounted and accessed via this drive. The drive shows all keys inside the aeskeydb.bin. This is read-only.
|
* __`K: AESKEYDB IMAGE`__: An `aeskeydb.bin` image can be mounted and accessed via this drive. The drive shows all keys inside the aeskeydb.bin. This is read-only.
|
||||||
* __`T: TICKET.DB IMAGE`__: Ticket database files can be mounted and accessed via this drive. This provides easy and quick access to all tickets inside the `ticket.db`. This is read-only.
|
* __`T: TICKET.DB IMAGE / BDRI IMAGE`__: Ticket database files can be mounted and accessed via this drive. This provides easy and quick access to all tickets inside the `ticket.db`. This drive also provides access to other BDRI images, such as the Title database (`title.db`).
|
||||||
* __`M: MEMORY VIRTUAL`__: This provides access to various memory regions. This is protected by a special write permission, and caution is advised when doing modifications inside this drive. This drive also gives access to `boot9.bin`, `boot11.bin` (boot9strap only) and `otp.mem` (sighaxed systems only).
|
* __`M: MEMORY VIRTUAL`__: This provides access to various memory regions. This is protected by a special write permission, and caution is advised when doing modifications inside this drive. This drive also gives access to `boot9.bin`, `boot11.bin` (boot9strap only) and `otp.mem` (sighaxed systems only).
|
||||||
* __`V: VRAM VIRTUAL`__: This drive resides in the first VRAM bank and contains files essential to GodMode9. The font (in PBM format), the splash logo (in PNG format) and the readme file are found there, as well as any file that is provided inside the `data` folder at build time. This is read-only.
|
* __`V: VRAM VIRTUAL`__: This drive resides in part of ARM9 internal memory and contains files essential to GodMode9. The font (in FRF format), the splash logo (in PNG format) and the readme file are found there, as well as any file that is provided inside the `data` folder at build time. This is read-only.
|
||||||
|
* __`Y: TITLE MANAGER`__: The title manager is accessed via the HOME menu and provides easy access to all installed titles.
|
||||||
* __`Z: LAST SEARCH`__: After a search operation, search results are found inside this drive. The drive can be accessed at a later point to return to the former search results.
|
* __`Z: LAST SEARCH`__: After a search operation, search results are found inside this drive. The drive can be accessed at a later point to return to the former search results.
|
||||||
|
|
||||||
|
|
||||||
|
## Digital preservation
|
||||||
|
GodMode9 is one of the most important tools for digital preservation of 3DS content data. Here's some stuff you should know:
|
||||||
|
* __Dumping game cartridges (size < 4GiB)__: Game cartridges turn up inside the `C:` drive (see above). For most carts all you need to do is copy the `.3DS` game image to some place of your choice. Game images dumped by GodMode9 contain no identifying info such as private headers or savegames. Private headers can be dumped in a separate image.
|
||||||
|
* __Dumping game cartridges (size = 4GiB)__: Everything written above applies here as well. However, the FAT32 file system (which is what the 3DS uses) is limited to _4GiB - 1byte_. Take note that the `.3DS` game image, as provided by GodMode9 actually misses the last byte in these cases. That byte is 0xFF and unused in all known cases. It is not required for playing the image. If you need to check, we also provide split files (`.000`, `.001)`, which contain all the data. If you need a valid checksum for the `.3DS` game image, append a 0xFF byte before checking.
|
||||||
|
* __Building CIAs (all types)__: You may convert compatible file types (game images, installed content, CDN content) to the CIA installable format using the A button menu. To get a list of installed content, press HOME, select `Title manager` and choose a drive. Take note that `standard` built CIAs are decrypted by default (decryption allows better compression by ZIP and 7Z). If you should need an encrypted CIA for some reason, apply the encryption to the CIA afterwards.
|
||||||
|
* __Building CIAs (legit type)__: Installed content can be built as `legit` or `standard` CIA. Legit CIAs preserve more of the original data and are thus recommended for preservation purposes. When building legit CIAs, GodMode9 keeps the original crypto and tries to find a genuine, signature-valid ticket. If it doesn't find one on your system, it will use a generic ticket instead. If it only finds a personalized one, it still offers to use a generic ticket. It is not recommended to use personalized tickets - only choose this if you know what you're doing.
|
||||||
|
* __Checking CIAs__: You may also check your CIA files with the builtin `CIA checker tool`. Legit CIAs with generic tickets are identified as `Universal Pirate Legit`, which is the recommended preservation format where `Universal Legit` is not available. Note: apart from system titles, `Universal Legit` is only available for a handful of preinstalled games from special edition 3DS consoles.
|
||||||
|
|
||||||
|
|
||||||
## What you can do with GodMode9
|
## What you can do with GodMode9
|
||||||
With the possibilites GodMode9 provides, not everything may be obvious at first glance. In short, __GodMode9 includes improved versions of basically everything that Decrypt9 has, and more__. Any kind of dumps and injections are handled via standard copy operations and more specific operations are found inside the A button menu. The A button menu also works for batch operations when multiple files are selected. For your convenience a (incomplete!) list of what GodMode9 can do follows below.
|
With the possibilites GodMode9 provides, not everything may be obvious at first glance. In short, __GodMode9 includes improved versions of basically everything that Decrypt9 has, and more__. Any kind of dumps and injections are handled via standard copy operations and more specific operations are found inside the A button menu. The A button menu also works for batch operations when multiple files are selected. For your convenience a (incomplete!) list of what GodMode9 can do follows below.
|
||||||
|
|
||||||
@ -100,16 +114,17 @@ With the possibilites GodMode9 provides, not everything may be obvious at first
|
|||||||
* __Make screenshots__: Press R+L anywhere. Screenshots are stored in PNG format.
|
* __Make screenshots__: Press R+L anywhere. Screenshots are stored in PNG format.
|
||||||
* __Use multiple panes__: Press R+left|right. This enables you to stay in one location in the first pane and open another in the second pane.
|
* __Use multiple panes__: Press R+left|right. This enables you to stay in one location in the first pane and open another in the second pane.
|
||||||
* __Search drives and folders__: Just press R+A on the drive / folder you want to search.
|
* __Search drives and folders__: Just press R+A on the drive / folder you want to search.
|
||||||
* __Compare and verify files__: Press the A button on the first file, select `Calculate SHA-256`. Do the same for the second file. If the two files are identical, you will get a message about them being identical. On the SDCARD drive (`0:`) you can also write a SHA file, so you can check for any modifications at a later point.
|
* __Compare and verify files__: Press the A button on the first file, select `Calculate SHA-256`. Do the same for the second file. If the two files are identical, you will get a message about them being identical. On the SDCARD drive (`0:`) you can also write an SHA file, so you can check for any modifications at a later point.
|
||||||
* __Hexview and hexedit any file__: Press the A button on a file and select `Show in Hexeditor`. A button again enables edit mode, hold the A button and press arrow buttons to edit bytes. You will get an additional confirmation prompt to take over changes. Take note that for certain files, write permissions can't be enabled.
|
* __Hexview and hexedit any file__: Press the A button on a file and select `Show in Hexeditor`. A button again enables edit mode, hold the A button and press arrow buttons to edit bytes. You will get an additional confirmation prompt to take over changes. Take note that for certain files, write permissions can't be enabled.
|
||||||
* __View text files in a text viewer__: Press the A button on a file and select `Show in Textviewer` (only shows up for actual text files). You can enable wordwrapped mode via R+Y, and navigate around the file via R+X and the dpad.
|
* __View text files in a text viewer__: Press the A button on a file and select `Show in Textviewer` (only shows up for actual text files). You can enable wordwrapped mode via R+Y, and navigate around the file via R+X and the dpad.
|
||||||
* __Chainload FIRM payloads__: Press the A button on a FIRM file, select `FIRM options` -> `Boot FIRM`. Keep in mind you should not run FIRMs from dubious sources and that the write permissions system is no longer in place after booting a payload.
|
* __Chainload FIRM payloads__: Press the A button on a FIRM file, select `FIRM options` -> `Boot FIRM`. Keep in mind you should not run FIRMs from dubious sources and that the write permissions system is no longer in place after booting a payload.
|
||||||
* __Chainload FIRM payloads from a neat menu__: The `payloads` menu is found inside the HOME button menu. It provides any FIRM found in `0:/gm9/payloads` for quick chainloading.
|
* __Chainload FIRM payloads from a neat menu__: The `payloads` menu is found inside the HOME button menu. It provides any FIRM found in `0:/gm9/payloads` for quick chainloading.
|
||||||
* __Inject a file to another file__: Put exactly one file (the file to be injected from) into the clipboard (via the Y button). Press A on the file to be injected to. There will be an option to inject the first file into it.
|
* __Inject a file to another file__: Put exactly one file (the file to be injected from) into the clipboard (via the Y button). Press A on the file to be injected to. There will be an option to inject the first file into it.
|
||||||
|
|
||||||
### Scripting functionality
|
### Scripting functionality
|
||||||
* __Run .gm9 scripts from anywhere on your SD card__: You can run scripts in .gm9 format via the A button menu. .gm9 scripts use a shell-like language and can be edited in any text editor. For an overview of usable commands have a look into the sample scripts included in the release archive. *Don't run scripts from untrusted sources.*
|
* __Run .lua scripts from anywhere on your SD card__: You can run Lua scripts via the A button menu. For an overview of usable commands have a look into the documentation and sample scripts included in the release archive. *Don't run scripts from untrusted sources.*
|
||||||
* __Run .gm9 scripts via a neat menu__: Press the HOME button, select `More...` -> `Scripts...`. Any script you put into `0:/gm9/scripts` (subdirs included) will be found here. Scripts ran via this method won't have the confirmation at the beginning either.
|
* __Run Lua scripts via a neat menu__: Press the HOME button, select `More...` -> `Lua scripts...`. Any script you put into `0:/gm9/luascripts` (subdirs included) will be found here. Scripts ran via this method won't have the confirmation at the beginning either.
|
||||||
|
* __Run legacy .gm9 scripts__: The old format of .gm9 scripts is still available, but is deprecated and will see no further development.
|
||||||
|
|
||||||
### SD card handling
|
### SD card handling
|
||||||
* __Format your SD card / setup an EmuNAND__: Press the HOME button, select `More...` -> `SD format menu`. This also allows to setup a RedNAND (single/multi) or GW type EmuNAND on your SD card. You will get a warning prompt and an unlock sequence before any operation starts.
|
* __Format your SD card / setup an EmuNAND__: Press the HOME button, select `More...` -> `SD format menu`. This also allows to setup a RedNAND (single/multi) or GW type EmuNAND on your SD card. You will get a warning prompt and an unlock sequence before any operation starts.
|
||||||
@ -119,16 +134,18 @@ With the possibilites GodMode9 provides, not everything may be obvious at first
|
|||||||
* __Set (and use) the RTC clock__: For correct modification / creation dates in your file system, you need to setup the RTC clock first. Press the HOME Button and select `More...` to find the option. Keep in mind that modifying the RTC clock means you should also fix system OS time afterwards.
|
* __Set (and use) the RTC clock__: For correct modification / creation dates in your file system, you need to setup the RTC clock first. Press the HOME Button and select `More...` to find the option. Keep in mind that modifying the RTC clock means you should also fix system OS time afterwards.
|
||||||
|
|
||||||
### Game file handling
|
### Game file handling
|
||||||
* __List titles installed on your system__: Press R+A on a /title dir or a subdir below that. This will also work directly for `CTRNAND`, `TWLN` and `A:`/`B:` drives. This will list all titles installed in the selected location. Works best with the below two features.
|
* __List titles installed on your system__: Press HOME and select `Title manager`. This will also work via R+A for `CTRNAND` and `A:`/`B:` drives. This will list all titles installed in the selected location.
|
||||||
* __Build CIAs from NCCH / NCSD (.3DS) / TMD (installed contents)__: Press A on the file you want converted and the option will be shown. Installed contents are found (among others) in `1:/titles/`(SysNAND) and `A:/titles/`(SD installed). Where applicable, you will also be able to generate legit CIAs. Note: this works also from a file search and title listing.
|
* __Install titles to your system__: Just press A on any file you want installed and select `Install game image` from the submenu. Works with NCCH / NCSD / CIA / DSiWare SRLs / 3DS CDN TMDs / DSi CDN TMDs / NUS TMDs.
|
||||||
|
* __(Batch) Uninstall titles from your system__: Most easily done via the HOME menu `Title manager`. Just select one or more titles and find the option inside the `Manage title...` submenu.
|
||||||
|
* __Build CIAs from NCCH / NCSD (.3DS) / SRL / TMD__: Press A on the file you want converted and the option will be shown. Installed contents are found most easily via the HOME menu `Title manager`. Where applicable, you will also be able to generate legit CIAs. Note: this works also from a file search and title listing.
|
||||||
* __Dump CXIs / NDS from TMD (installed contents)__: This works the same as building CIAs, but dumps decrypted CXIs or NDS rom dumps instead. Note: this works also from a file search and title listing.
|
* __Dump CXIs / NDS from TMD (installed contents)__: This works the same as building CIAs, but dumps decrypted CXIs or NDS rom dumps instead. Note: this works also from a file search and title listing.
|
||||||
* __Decrypt, encrypt and verify NCCH / NCSD / CIA / BOSS / FIRM images__: Options are found inside the A button menu. You will be able to decrypt/encrypt to the standard output directory or (where applicable) in place.
|
* __Decrypt, encrypt and verify NCCH / NCSD / CIA / BOSS / FIRM images__: Options are found inside the A button menu. You will be able to decrypt/encrypt to the standard output directory or (where applicable) in place.
|
||||||
* __Decrypt content downloaded from CDN / NUS__: Press A on the file you want decrypted. For this to work, you need at least a TMD file (`encTitlekeys.bin` / `decTitlekeys.bin` also required, see _Support files_ below) or a CETK file. Either keep the names provided by CDN / NUS, or rename the downloaded content to `(anything).nus` or `(anything).cdn` and the CETK to `(anything).cetk`.
|
* __Decrypt content downloaded from CDN / NUS__: Press A on the file you want decrypted. For this to work, you need at least a TMD file (`encTitlekeys.bin` / `decTitlekeys.bin` also required, see _Support files_ below) or a CETK file. Either keep the names provided by CDN / NUS, or rename the downloaded content to `(anything).nus` or `(anything).cdn` and the CETK to `(anything).cetk`.
|
||||||
* __Batch mode for the above operations__: Just select multiple files of the same type via the L button, then press the A button on one of the selected files.
|
* __Batch mode for the above operations__: Just select multiple files of the same type via the L button, then press the A button on one of the selected files.
|
||||||
* __Access any file inside NCCH / NCSD / CIA / FIRM / NDS images__: Just mount the file via the A button menu and browse to the file you want. For CDN / NUS content, prior decryption is required for full access.
|
* __Access any file inside NCCH / NCSD / CIA / FIRM / NDS images__: Just mount the file via the A button menu and browse to the file you want. For CDN / NUS content, prior decryption is required for full access.
|
||||||
* __Rename your NCCH / NCSD / CIA / NDS / GBA files to proper names__: Find this feature inside the A button menu. Proper names include title id, game name, product code and region.
|
* __Rename your NCCH / NCSD / CIA / NDS / GBA files to proper names__: Find this feature inside the A button menu. Proper names include title id, game name, product code and region.
|
||||||
* __Trim NCCH / NCSD / NDS / FIRM / NAND images__: This feature is found inside the A button menu. It allows you to trim excess data from supported file types. *Warning: Excess data may not be empty, bonus drives are stored there for NAND images, NCSD card2 images store savedata there, for FIRMs parts of the A9LH exploit may be stored there*.
|
* __Trim NCCH / NCSD / NDS / GBA / FIRM / NAND images__: This feature is found inside the A button menu. It allows you to trim excess data from supported file types. *Warning: Excess data may not be empty, bonus drives are stored there for NAND images, NCSD card2 images store savedata there, for FIRMs parts of the A9LH exploit may be stored there*.
|
||||||
* __Dump 3DS / NDS / DSi type retail game cartridges__: Insert the cartridge and take a look inside the `C:` drive. You may also dump private headers from 3DS game cartridges.
|
* __Dump 3DS / NDS / DSi type retail game cartridges__: Insert the cartridge and take a look inside the `C:` drive. You may also dump private headers from 3DS game cartridges. The `C:` drive also gives you read/write access to the saves on the cartridges. Note: For 4GiB cartridges, the last byte is not included in the .3ds file dump. This is due to restrictrions of the FAT32 file system.
|
||||||
|
|
||||||
### NAND handling
|
### NAND handling
|
||||||
* __Directly mount and access NAND dumps or standard FAT images__: Just press the A button on these files to get the option. You can only mount NAND dumps from the same console.
|
* __Directly mount and access NAND dumps or standard FAT images__: Just press the A button on these files to get the option. You can only mount NAND dumps from the same console.
|
||||||
@ -138,14 +155,14 @@ With the possibilites GodMode9 provides, not everything may be obvious at first
|
|||||||
* __Embed an essential backup right into a NAND dump__: This is available in the A button menu for NAND dumps. Essential backups contain NAND header, `movable.sed`, `LocalFriendCodeSeed_B`, `SecureInfo_A`, NAND CID and OTP. If your local SysNAND does not contain an embedded backup, you will be asked to do one at startup. To update the essential SysNAND backup at a later point in time, press A on `S:/nand.bin` and select `NAND image options...` -> `Update embedded backup`.
|
* __Embed an essential backup right into a NAND dump__: This is available in the A button menu for NAND dumps. Essential backups contain NAND header, `movable.sed`, `LocalFriendCodeSeed_B`, `SecureInfo_A`, NAND CID and OTP. If your local SysNAND does not contain an embedded backup, you will be asked to do one at startup. To update the essential SysNAND backup at a later point in time, press A on `S:/nand.bin` and select `NAND image options...` -> `Update embedded backup`.
|
||||||
* __Install an AES key database to your NAND__: For `aeskeydb.bin` files the option is found in `aeskeydb.bin options` -> `Install aeskeydb.bin`. Only the recommended key database can be installed (see above). With an installed key database, it is possible to run the GodMode9 bootloader completely from NAND.
|
* __Install an AES key database to your NAND__: For `aeskeydb.bin` files the option is found in `aeskeydb.bin options` -> `Install aeskeydb.bin`. Only the recommended key database can be installed (see above). With an installed key database, it is possible to run the GodMode9 bootloader completely from NAND.
|
||||||
* __Install FIRM files to your NAND__: Found inside the A button menu for FIRM files, select `FIRM options` -> `Install FIRM`. __Use this with caution__ - installing an incompatible FIRM file will lead to a __brick__. The FIRMs signature will automagically be replaced with a sighax signature to ensure compatibility.
|
* __Install FIRM files to your NAND__: Found inside the A button menu for FIRM files, select `FIRM options` -> `Install FIRM`. __Use this with caution__ - installing an incompatible FIRM file will lead to a __brick__. The FIRMs signature will automagically be replaced with a sighax signature to ensure compatibility.
|
||||||
* __Actually use that extra NAND space__: You can setup a __bonus drive__ via the HOME menu, which will be available via drive letter `8:`. (Only available on systems that have the extra space.)
|
* __Actually use that extra NAND space__: You can set up a __bonus drive__ via the HOME menu, which will be available via drive letter `8:`. (Only available on systems that have the extra space.)
|
||||||
* __Fix certain problems on your NANDs__: You can fix CMACs for a whole drive (works on `A:`, `B:`, `S:` and `E:`) via an entry in the R+A button menu, or even restore borked NAND headers back to a functional state (inside the A button menu of borked NANDs and available for `S:/nand_hdr.bin`). Recommended only for advanced users!
|
* __Fix certain problems on your NANDs__: You can fix CMACs for a whole drive (works on `A:`, `B:`, `S:` and `E:`) via an entry in the R+A button menu, or even restore borked NAND headers back to a functional state (inside the A button menu of borked NANDs and available for `S:/nand_hdr.bin`). Recommended only for advanced users!
|
||||||
|
|
||||||
### System file handling
|
### System file handling
|
||||||
* __Check and fix CMACs (for any file that has them)__: The option will turn up in the A button menu if it is available for a given file (f.e. system savegames, `ticket.db`, etc...). This can also be done for multiple files at once if they are marked.
|
* __Check and fix CMACs (for any file that has them)__: The option will turn up in the A button menu if it is available for a given file (f.e. system savegames, `ticket.db`, etc...). This can also be done for multiple files at once if they are marked.
|
||||||
* __Mount ticket.db files and dump tickets__: Mount the file via the A button menu. Tickets are sorted into `eshop` (stuff from eshop), `system` (system tickets), `unknown` (typically empty) and `hidden` (hidden tickets, found via a deeper scan) categories. All tickets displayed are legit, fake tickets are ignored
|
* __Mount ticket.db files and dump tickets__: Mount the file via the A button menu. Tickets are sorted into `eshop` (stuff from eshop), `system` (system tickets), `unknown` (typically empty) and `hidden` (hidden tickets, found via a deeper scan) categories. All tickets displayed are legit, fake tickets are ignored
|
||||||
* __Inject any NCCH CXI file into Health & Safety__: The option is found inside the A button menu for any NCCH CXI file. NCCH CXIs are found, f.e. inside of CIAs. Keep in mind there is a (system internal) size restriction on H&S injectable apps.
|
* __Inject any NCCH CXI file into Health & Safety__: The option is found inside the A button menu for any NCCH CXI file. NCCH CXIs are found, f.e. inside of CIAs. Keep in mind there is a (system internal) size restriction on H&S injectable apps.
|
||||||
* __Inject and dump GBA VC saves__: Find the options to do this inside the A button menu for `agbsave.bin` in the `S:` drive. Keep in mind that you need to start the specific GBA game on your console before dumping / injecting the save.
|
* __Inject and dump GBA VC saves__: Find the options to do this inside the A button menu for `agbsave.bin` in the `S:` drive. Keep in mind that you need to start the specific GBA game on your console before dumping / injecting the save. _To inject a save it needs to be in the clipboard_.
|
||||||
* __Dump a copy of boot9, boot11 & your OTP__: This works on sighax, via boot9strap only. These files are found inside the `M:` drive and can be copied from there to any other place.
|
* __Dump a copy of boot9, boot11 & your OTP__: This works on sighax, via boot9strap only. These files are found inside the `M:` drive and can be copied from there to any other place.
|
||||||
|
|
||||||
### Support file handling
|
### Support file handling
|
||||||
@ -156,6 +173,8 @@ With the possibilites GodMode9 provides, not everything may be obvious at first
|
|||||||
## License
|
## License
|
||||||
You may use this under the terms of the GNU General Public License GPL v2 or under the terms of any later revisions of the GPL. Refer to the provided `LICENSE.txt` file for further information.
|
You may use this under the terms of the GNU General Public License GPL v2 or under the terms of any later revisions of the GPL. Refer to the provided `LICENSE.txt` file for further information.
|
||||||
|
|
||||||
|
## Contact info
|
||||||
|
You can chat directly with us via IRC @ #GodMode9 on [libera.chat](https://web.libera.chat/#GodMode9) or [Discord](https://discord.gg/BRcbvtFxX4)!
|
||||||
|
|
||||||
## Credits
|
## Credits
|
||||||
This tool would not have been possible without the help of numerous people. Thanks go to (in no particular order)...
|
This tool would not have been possible without the help of numerous people. Thanks go to (in no particular order)...
|
||||||
@ -165,7 +184,13 @@ This tool would not have been possible without the help of numerous people. Than
|
|||||||
* **Wolfvak** for ARM11 code, FIRM binary launcher, exception handlers, PCX code, Makefile and for help on countless other occasions
|
* **Wolfvak** for ARM11 code, FIRM binary launcher, exception handlers, PCX code, Makefile and for help on countless other occasions
|
||||||
* **SciresM** for helping me figure out RomFS and for boot9strap
|
* **SciresM** for helping me figure out RomFS and for boot9strap
|
||||||
* **SciresM**, **Myria**, **Normmatt**, **TuxSH** and **hedgeberg** for figuring out sighax and giving us access to bootrom
|
* **SciresM**, **Myria**, **Normmatt**, **TuxSH** and **hedgeberg** for figuring out sighax and giving us access to bootrom
|
||||||
* **ihaveamac** for first developing the simple CIA generation method and for being of great help in porting it
|
* **ihaveamac** for implementing Lua support, and first developing the simple CIA generation method and for being of great help in porting it
|
||||||
|
* **DarkRTA** for linker support during the implementation of Lua
|
||||||
|
* **luigoalma** for fixing Lua to compile without issues
|
||||||
|
* **Gruetzig** for re-implementing the Lua os module
|
||||||
|
* **wwylele** and **aspargas2** for documenting and implementing the DISA, DIFF, and BDRI formats
|
||||||
|
* **dratini0** for savefile management, based on [TWLSaveTool](https://github.com/TuxSH/TWLSaveTool/)
|
||||||
|
* **Pk11** for unicode support and her ongoing work on GodMode9 translations and translation support
|
||||||
* **b1l1s** for helping me figure out A9LH compatibility
|
* **b1l1s** for helping me figure out A9LH compatibility
|
||||||
* **Gelex** and **AuroraWright** for helping me figure out various things
|
* **Gelex** and **AuroraWright** for helping me figure out various things
|
||||||
* **stuckpixel** for the new 6x10 font and help on various things
|
* **stuckpixel** for the new 6x10 font and help on various things
|
||||||
@ -174,12 +199,16 @@ This tool would not have been possible without the help of numerous people. Than
|
|||||||
* **profi200** for always useful advice and helpful hints on various things
|
* **profi200** for always useful advice and helpful hints on various things
|
||||||
* **windows-server-2003** for the initial implementation of if-else-goto in .gm9 scripts
|
* **windows-server-2003** for the initial implementation of if-else-goto in .gm9 scripts
|
||||||
* **Kazuma77** for pushing forward scripting, for testing and for always useful advice
|
* **Kazuma77** for pushing forward scripting, for testing and for always useful advice
|
||||||
|
* **TurdPooCharger** for being one of the most meticulous software testers around
|
||||||
* **JaySea**, **YodaDaCoda**, **liomajor**, **Supster131**, **imanoob**, **Kasher_CS** and countless others from freenode #Cakey and the GBAtemp forums for testing, feedback and helpful hints
|
* **JaySea**, **YodaDaCoda**, **liomajor**, **Supster131**, **imanoob**, **Kasher_CS** and countless others from freenode #Cakey and the GBAtemp forums for testing, feedback and helpful hints
|
||||||
* **Shadowhand** for being awesome and [hosting my nightlies](https://d0k3.secretalgorithm.com/)
|
* **Shadowhand** for being awesome and [hosting my nightlies](https://d0k3.secretalgorithm.com/)
|
||||||
* **Plailect** for putting his trust in my tools and recommending this in [The Guide](https://3ds.guide/)
|
* **Plailect** for putting his trust in my tools and recommending this in [The Guide](https://3ds.guide/)
|
||||||
* **SirNapkin1334** for testing, bug reports and for hosting the official [GodMode9 Discord channel](https://discord.gg/EGu6Qxw)
|
* **SirNapkin1334** for testing, bug reports and for hosting the original GodMode9 Discord server
|
||||||
|
* **Lilith Valentine** for testing and helpful advice
|
||||||
* **Project Nayuki** for [qrcodegen](https://github.com/nayuki/QR-Code-generator)
|
* **Project Nayuki** for [qrcodegen](https://github.com/nayuki/QR-Code-generator)
|
||||||
* **Amazingmax fonts** for the Amazdoom font
|
* **Amazingmax fonts** for the Amazdoom font
|
||||||
|
* **TakWolf** for [fusion-pixel-font](https://github.com/TakWolf/fusion-pixel-font) used for Chinese and Korean
|
||||||
|
* The fine folks on **the official GodMode9 IRC channel and Discord server**
|
||||||
* The fine folks on **freenode #Cakey**
|
* The fine folks on **freenode #Cakey**
|
||||||
* All **[3dbrew.org](https://www.3dbrew.org/wiki/Main_Page) editors**
|
* All **[3dbrew.org](https://www.3dbrew.org/wiki/Main_Page) editors**
|
||||||
* Everyone I possibly forgot, if you think you deserve to be mentioned, just contact me!
|
* Everyone I possibly forgot, if you think you deserve to be mentioned, just contact us!
|
||||||
|
@ -1,41 +1,17 @@
|
|||||||
PROCESSOR := ARM11
|
PROCESSOR := ARM11
|
||||||
|
|
||||||
TARGET := $(shell basename $(CURDIR))
|
TARGET := $(shell basename "$(CURDIR)")
|
||||||
|
|
||||||
SOURCE := source
|
SOURCE := source
|
||||||
BUILD := build
|
BUILD := build
|
||||||
|
|
||||||
SUBARCH := -D$(PROCESSOR) -mcpu=mpcore -mtune=mpcore -mfloat-abi=soft -marm
|
SUBARCH := -D$(PROCESSOR) -march=armv6k -mtune=mpcore -marm -mfloat-abi=hard -mfpu=vfpv2 -mtp=soft
|
||||||
INCDIRS := source
|
INCDIRS := source
|
||||||
INCLUDE := $(foreach dir,$(INCDIRS),-I"$(shell pwd)/$(dir)")
|
INCLUDE := $(foreach dir,$(INCDIRS),-I"$(shell pwd)/$(dir)")
|
||||||
|
|
||||||
ASFLAGS += $(SUBARCH) $(INCLUDE)
|
ASFLAGS += $(SUBARCH) $(INCLUDE)
|
||||||
CFLAGS += $(SUBARCH) $(INCLUDE)
|
CFLAGS += $(SUBARCH) $(INCLUDE) -flto
|
||||||
LDFLAGS += $(SUBARCH) -Wl,-Map,$(TARGET).map
|
LDFLAGS += $(SUBARCH) -Wl,--use-blx,-Map,$(TARGET).map -flto
|
||||||
|
|
||||||
include ../Makefile.common
|
include ../Makefile.common
|
||||||
|
include ../Makefile.build
|
||||||
OBJECTS = $(patsubst $(SOURCE)/%.s, $(BUILD)/%.o, \
|
|
||||||
$(patsubst $(SOURCE)/%.c, $(BUILD)/%.o, \
|
|
||||||
$(call rwildcard, $(SOURCE), *.s *.c)))
|
|
||||||
|
|
||||||
.PHONY: all
|
|
||||||
all: $(TARGET).elf
|
|
||||||
|
|
||||||
.PHONY: clean
|
|
||||||
clean:
|
|
||||||
@rm -rf $(BUILD) $(TARGET).elf $(TARGET).map
|
|
||||||
|
|
||||||
$(TARGET).elf: $(OBJECTS)
|
|
||||||
@mkdir -p "$(@D)"
|
|
||||||
@$(CC) $(LDFLAGS) $^ -o $@
|
|
||||||
|
|
||||||
$(BUILD)/%.o: $(SOURCE)/%.c
|
|
||||||
@mkdir -p "$(@D)"
|
|
||||||
@echo "[$(PROCESSOR)] $<"
|
|
||||||
@$(CC) -c $(CFLAGS) -o $@ $<
|
|
||||||
|
|
||||||
$(BUILD)/%.o: $(SOURCE)/%.s
|
|
||||||
@mkdir -p "$(@D)"
|
|
||||||
@echo "[$(PROCESSOR)] $<"
|
|
||||||
@$(CC) -c $(ASFLAGS) -o $@ $<
|
|
||||||
|
@ -1,17 +1,57 @@
|
|||||||
OUTPUT_FORMAT("elf32-littlearm", "elf32-bigarm", "elf32-littlearm")
|
OUTPUT_FORMAT("elf32-littlearm", "elf32-bigarm", "elf32-littlearm")
|
||||||
OUTPUT_ARCH(arm)
|
OUTPUT_ARCH(arm)
|
||||||
|
|
||||||
ENTRY(__boot)
|
ENTRY(__boot)
|
||||||
|
|
||||||
|
MEMORY
|
||||||
|
{
|
||||||
|
AXIWRAM (RWX) : ORIGIN = 0x1FF80000, LENGTH = 96K
|
||||||
|
HIGHRAM (RWX) : ORIGIN = 0xFFFF0000, LENGTH = 4K
|
||||||
|
}
|
||||||
|
|
||||||
SECTIONS
|
SECTIONS
|
||||||
{
|
{
|
||||||
. = 0x1FF80000;
|
.text : ALIGN(4K)
|
||||||
|
{
|
||||||
|
__text_pa = LOADADDR(.text);
|
||||||
|
__text_va = ABSOLUTE(.);
|
||||||
|
*(.text*)
|
||||||
|
. = ALIGN(4K);
|
||||||
|
__text_va_end = .;
|
||||||
|
} >AXIWRAM
|
||||||
|
|
||||||
.text : ALIGN(4) { *(.text.boot) *(.text*); . = ALIGN(4); }
|
.data : ALIGN(4K)
|
||||||
.rodata : ALIGN(4) { *(.rodata*); . = ALIGN(4); }
|
{
|
||||||
.data : ALIGN(4) { *(.data*); . = ALIGN(8); *(.bss* COMMON); . = ALIGN(8); }
|
__data_pa = LOADADDR(.data);
|
||||||
.bss : ALIGN(4) { __bss_start = .; *(.bss*); __bss_end = .; }
|
__data_va = ABSOLUTE(.);
|
||||||
|
*(.data*)
|
||||||
|
. = ALIGN(4K);
|
||||||
|
__data_va_end = .;
|
||||||
|
} >AXIWRAM
|
||||||
|
|
||||||
. = ALIGN(4);
|
.rodata : ALIGN(4K)
|
||||||
|
{
|
||||||
|
__rodata_pa = LOADADDR(.rodata);
|
||||||
|
__rodata_va = ABSOLUTE(.);
|
||||||
|
*(.rodata*)
|
||||||
|
. = ALIGN(4K);
|
||||||
|
__rodata_va_end = .;
|
||||||
|
} >AXIWRAM
|
||||||
|
|
||||||
__stack_top = 0x1FFFE000;
|
.shared (NOLOAD) : ALIGN(4K)
|
||||||
|
{
|
||||||
|
__shared_pa = LOADADDR(.shared);
|
||||||
|
__shared_va = ABSOLUTE(.);
|
||||||
|
*(.shared*)
|
||||||
|
. = ALIGN(4K);
|
||||||
|
__shared_va_end = .;
|
||||||
|
} >AXIWRAM
|
||||||
|
|
||||||
|
.bss (NOLOAD) : ALIGN(4K)
|
||||||
|
{
|
||||||
|
__bss_pa = LOADADDR(.bss);
|
||||||
|
__bss_va = ABSOLUTE(.);
|
||||||
|
*(.bss*)
|
||||||
|
. = ALIGN(4K);
|
||||||
|
__bss_va_end = .;
|
||||||
|
} >AXIWRAM
|
||||||
}
|
}
|
||||||
|
300
arm11/source/arm/gic.c
Normal file
300
arm11/source/arm/gic.c
Normal file
@ -0,0 +1,300 @@
|
|||||||
|
/*
|
||||||
|
* This file is part of GodMode9
|
||||||
|
* Copyright (C) 2017-2019 Wolfvak
|
||||||
|
*
|
||||||
|
* This program is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 2 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <common.h>
|
||||||
|
#include <arm.h>
|
||||||
|
|
||||||
|
#include <stdatomic.h>
|
||||||
|
|
||||||
|
#include "arm/gic.h"
|
||||||
|
|
||||||
|
#include "system/event.h"
|
||||||
|
|
||||||
|
/* Generic Interrupt Controller Registers */
|
||||||
|
#define REG_GIC(cpu, o, t) REG_ARM_PMR(0x200 + ((cpu) * 0x100) + (o), t)
|
||||||
|
|
||||||
|
#define REG_GIC_CONTROL(c) (*REG_GIC(c, 0x00, u32))
|
||||||
|
#define REG_GIC_PRIOMASK(c) (*REG_GIC(c, 0x04, u32))
|
||||||
|
#define REG_GIC_POI(c) (*REG_GIC(c, 0x08, u32))
|
||||||
|
#define REG_GIC_IRQACK(c) (*REG_GIC(c, 0x0C, u32))
|
||||||
|
#define REG_GIC_IRQEND(c) (*REG_GIC(c, 0x10, u32))
|
||||||
|
#define REG_GIC_LASTPRIO(c) (*REG_GIC(c, 0x14, u32))
|
||||||
|
#define REG_GIC_PENDING(c) (*REG_GIC(c, 0x18, u32))
|
||||||
|
|
||||||
|
#define GIC_THIS_CPU_ALIAS (-1)
|
||||||
|
#define GIC_IRQ_SPURIOUS (1023)
|
||||||
|
|
||||||
|
/* Interrupt Distributor Registers */
|
||||||
|
#define REG_DIC(off, type) REG_ARM_PMR(0x1000 + (off), type)
|
||||||
|
|
||||||
|
#define REG_DIC_CONTROL (*REG_DIC(0x00, u32))
|
||||||
|
#define REG_DIC_TYPE (*REG_DIC(0x04, u32))
|
||||||
|
#define REG_DIC_SETENABLE REG_DIC(0x100, u32) // 32 intcfg per reg
|
||||||
|
#define REG_DIC_CLRENABLE REG_DIC(0x180, u32)
|
||||||
|
#define REG_DIC_SETPENDING REG_DIC(0x200, u32)
|
||||||
|
#define REG_DIC_CLRPENDING REG_DIC(0x280, u32)
|
||||||
|
#define REG_DIC_PRIORITY REG_DIC(0x400, u8) // 1 intcfg per reg (in upper 4 bits)
|
||||||
|
#define REG_DIC_TARGETCPU REG_DIC(0x800, u8) // 1 intcfg per reg
|
||||||
|
#define REG_DIC_CFGREG REG_DIC(0xC00, u32) // 16 intcfg per reg
|
||||||
|
#define REG_DIC_SOFTINT (*REG_DIC(0xF00, u32))
|
||||||
|
|
||||||
|
// used only on reset routines
|
||||||
|
#define REG_DIC_PRIORITY32 REG_DIC(0x400, u32) // 4 intcfg per reg (in upper 4 bits)
|
||||||
|
#define REG_DIC_TARGETCPU32 REG_DIC(0x800, u32) // 4 intcfg per reg
|
||||||
|
|
||||||
|
#define GIC_PRIO_NEVER32 \
|
||||||
|
(GIC_PRIO_NEVER | (GIC_PRIO_NEVER << 8) | \
|
||||||
|
(GIC_PRIO_NEVER << 16) | (GIC_PRIO_NEVER << 24))
|
||||||
|
#define GIC_PRIO_HIGH32 \
|
||||||
|
(GIC_PRIO_HIGHEST | (GIC_PRIO_HIGHEST << 8) | \
|
||||||
|
(GIC_PRIO_HIGHEST << 16) | (GIC_PRIO_HIGHEST << 24))
|
||||||
|
|
||||||
|
/* CPU source ID is present in Interrupt Acknowledge register? */
|
||||||
|
#define IRQN_SRC_MASK (0x7 << 10)
|
||||||
|
|
||||||
|
/* Interrupt Handling */
|
||||||
|
#define LOCAL_IRQS (32)
|
||||||
|
#define DIC_MAX_IRQ (LOCAL_IRQS + MAX_IRQ)
|
||||||
|
|
||||||
|
#define COREMASK_VALID(x) (((x) > 0) && ((x) < BIT(MAX_CPU)))
|
||||||
|
|
||||||
|
#define IRQN_IS_VALID(n) ((n) < DIC_MAX_IRQ)
|
||||||
|
|
||||||
|
static gicIrqHandler gicIrqHandlers[DIC_MAX_IRQ];
|
||||||
|
static _Atomic(u32) gicIrqPending[DIC_MAX_IRQ / 32];
|
||||||
|
|
||||||
|
static struct {
|
||||||
|
u8 tgt;
|
||||||
|
u8 prio;
|
||||||
|
} gicIrqConfig[DIC_MAX_IRQ];
|
||||||
|
|
||||||
|
// gets used whenever a NULL pointer is passed to gicEnableInterrupt
|
||||||
|
static void gicDummyHandler(u32 irqn) { (void)irqn; return; }
|
||||||
|
|
||||||
|
static const struct {
|
||||||
|
u8 low, high, mode;
|
||||||
|
} gicDefaultIrqCfg[] = {
|
||||||
|
{ .low = 0x00, .high = 0x1F, .mode = GIC_RISINGEDGE_NN },
|
||||||
|
{ .low = 0x20, .high = 0x23, .mode = GIC_LEVELHIGH_1N },
|
||||||
|
{ .low = 0x24, .high = 0x24, .mode = GIC_RISINGEDGE_1N },
|
||||||
|
{ .low = 0x25, .high = 0x27, .mode = GIC_LEVELHIGH_1N },
|
||||||
|
{ .low = 0x28, .high = 0x2D, .mode = GIC_RISINGEDGE_1N },
|
||||||
|
{ .low = 0x30, .high = 0x3B, .mode = GIC_LEVELHIGH_1N },
|
||||||
|
{ .low = 0x40, .high = 0x4E, .mode = GIC_RISINGEDGE_1N },
|
||||||
|
{ .low = 0x4F, .high = 0x4F, .mode = GIC_LEVELHIGH_1N },
|
||||||
|
{ .low = 0x50, .high = 0x57, .mode = GIC_RISINGEDGE_1N },
|
||||||
|
{ .low = 0x58, .high = 0x58, .mode = GIC_LEVELHIGH_1N },
|
||||||
|
{ .low = 0x59, .high = 0x75, .mode = GIC_RISINGEDGE_1N },
|
||||||
|
{ .low = 0x76, .high = 0x77, .mode = GIC_LEVELHIGH_1N },
|
||||||
|
{ .low = 0x78, .high = 0x78, .mode = GIC_RISINGEDGE_1N },
|
||||||
|
{ .low = 0x79, .high = 0x7d, .mode = GIC_LEVELHIGH_1N },
|
||||||
|
};
|
||||||
|
|
||||||
|
static u8 gicGetDefaultIrqCfg(u32 irqn) {
|
||||||
|
for (unsigned i = 0; i < countof(gicDefaultIrqCfg); i++) {
|
||||||
|
if ((irqn >= gicDefaultIrqCfg[i].low) && (irqn <= gicDefaultIrqCfg[i].high))
|
||||||
|
return gicDefaultIrqCfg[i].mode;
|
||||||
|
}
|
||||||
|
// TODO: would it be considerably faster to use bsearch?
|
||||||
|
return GIC_RISINGEDGE_1N;
|
||||||
|
}
|
||||||
|
|
||||||
|
void gicTopHandler(void)
|
||||||
|
{
|
||||||
|
while(1) {
|
||||||
|
u32 irqn, irqsource, index, mask;
|
||||||
|
|
||||||
|
/**
|
||||||
|
If more than one of these CPUs reads the Interrupt Acknowledge Register at the
|
||||||
|
same time, they can all acknowledge the same interrupt. The interrupt service
|
||||||
|
routine must ensure that only one of them tries to process the interrupt, with the
|
||||||
|
others returning after writing the ID to the End of Interrupt Register.
|
||||||
|
*/
|
||||||
|
irqsource = REG_GIC_IRQACK(GIC_THIS_CPU_ALIAS);
|
||||||
|
|
||||||
|
if (irqsource == GIC_IRQ_SPURIOUS) // no further processing is needed
|
||||||
|
break;
|
||||||
|
|
||||||
|
irqn = irqsource & ~IRQN_SRC_MASK;
|
||||||
|
|
||||||
|
index = irqn / 32;
|
||||||
|
mask = BIT(irqn % 32);
|
||||||
|
atomic_fetch_or(&gicIrqPending[index], mask);
|
||||||
|
|
||||||
|
(gicIrqHandlers[irqn])(irqsource);
|
||||||
|
// if the id is < 16, the source CPU can be obtained from irqn
|
||||||
|
// if the handler isn't set, it'll try to branch to 0 and trigger a prefetch abort
|
||||||
|
|
||||||
|
REG_GIC_IRQEND(GIC_THIS_CPU_ALIAS) = irqsource;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void gicGlobalReset(void)
|
||||||
|
{
|
||||||
|
u32 dic_type;
|
||||||
|
unsigned gicn, intn;
|
||||||
|
|
||||||
|
dic_type = REG_DIC_TYPE;
|
||||||
|
|
||||||
|
// number of local controllers
|
||||||
|
gicn = ((dic_type >> 5) & 3) + 1;
|
||||||
|
|
||||||
|
// number of interrupt lines (up to 224 external + 32 fixed internal per CPU)
|
||||||
|
intn = ((dic_type & 7) + 1) * 32;
|
||||||
|
|
||||||
|
// clamp it down to the amount of CPUs designed to handle
|
||||||
|
if (gicn > MAX_CPU)
|
||||||
|
gicn = MAX_CPU;
|
||||||
|
|
||||||
|
// clear the interrupt handler and config table
|
||||||
|
getEventIRQ()->reset();
|
||||||
|
memset(gicIrqHandlers, 0, sizeof(gicIrqHandlers));
|
||||||
|
memset(gicIrqConfig, 0, sizeof(gicIrqConfig));
|
||||||
|
|
||||||
|
// disable all MP11 GICs
|
||||||
|
for (unsigned i = 0; i < gicn; i++)
|
||||||
|
REG_GIC_CONTROL(i) = 0;
|
||||||
|
|
||||||
|
// disable the main DIC
|
||||||
|
REG_DIC_CONTROL = 0;
|
||||||
|
|
||||||
|
// clear all external interrupts
|
||||||
|
for (unsigned i = 1; i < (intn / 32); i++) {
|
||||||
|
REG_DIC_CLRENABLE[i] = ~0;
|
||||||
|
REG_DIC_CLRPENDING[i] = ~0;
|
||||||
|
}
|
||||||
|
|
||||||
|
// reset all external priorities to highest by default
|
||||||
|
// clear target processor regs
|
||||||
|
for (unsigned i = 4; i < (intn / 4); i++) {
|
||||||
|
REG_DIC_PRIORITY32[i] = GIC_PRIO_HIGH32;
|
||||||
|
REG_DIC_TARGETCPU32[i] = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
// set all interrupts to active level triggered in N-N model
|
||||||
|
for (unsigned i = 16; i < (intn / 16); i++)
|
||||||
|
REG_DIC_CFGREG[i] = 0;
|
||||||
|
|
||||||
|
// re enable the main DIC
|
||||||
|
REG_DIC_CONTROL = 1;
|
||||||
|
|
||||||
|
for (unsigned i = 0; i < gicn; i++) {
|
||||||
|
// compare all priority bits
|
||||||
|
REG_GIC_POI(i) = 3;
|
||||||
|
|
||||||
|
// don't mask any interrupt with low priority
|
||||||
|
REG_GIC_PRIOMASK(i) = 0xF0;
|
||||||
|
|
||||||
|
// enable all the MP11 GICs
|
||||||
|
REG_GIC_CONTROL(i) = 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void gicLocalReset(void)
|
||||||
|
{
|
||||||
|
u32 irq_s;
|
||||||
|
|
||||||
|
// disable all local interrupts
|
||||||
|
REG_DIC_CLRENABLE[0] = ~0;
|
||||||
|
REG_DIC_CLRPENDING[0] = ~0;
|
||||||
|
|
||||||
|
for (unsigned i = 0; i < 4; i++) {
|
||||||
|
REG_DIC_PRIORITY32[i] = GIC_PRIO_HIGH32;
|
||||||
|
// local IRQs are always unmasked by default
|
||||||
|
|
||||||
|
// REG_DIC_TARGETCPU[i] = 0;
|
||||||
|
// not needed, always read as corresponding MP11 core
|
||||||
|
}
|
||||||
|
|
||||||
|
// ack until it gets a spurious IRQ
|
||||||
|
do {
|
||||||
|
irq_s = REG_GIC_PENDING(GIC_THIS_CPU_ALIAS);
|
||||||
|
REG_GIC_IRQEND(GIC_THIS_CPU_ALIAS) = irq_s;
|
||||||
|
} while(irq_s != GIC_IRQ_SPURIOUS);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void gicSetIrqCfg(u32 irqn) {
|
||||||
|
u32 smt, cfg;
|
||||||
|
|
||||||
|
smt = irqn & 15;
|
||||||
|
cfg = REG_DIC_CFGREG[irqn / 16];
|
||||||
|
cfg &= ~(3 << smt);
|
||||||
|
cfg |= gicGetDefaultIrqCfg(irqn) << smt;
|
||||||
|
REG_DIC_CFGREG[irqn / 16] = cfg;
|
||||||
|
}
|
||||||
|
|
||||||
|
void gicSetInterruptConfig(u32 irqn, u32 coremask, u32 prio, gicIrqHandler handler)
|
||||||
|
{
|
||||||
|
if (handler == NULL) // maybe add runtime ptr checks here too?
|
||||||
|
handler = gicDummyHandler;
|
||||||
|
|
||||||
|
gicIrqConfig[irqn].tgt = coremask;
|
||||||
|
gicIrqConfig[irqn].prio = prio;
|
||||||
|
gicIrqHandlers[irqn] = handler;
|
||||||
|
}
|
||||||
|
|
||||||
|
void gicClearInterruptConfig(u32 irqn)
|
||||||
|
{
|
||||||
|
memset(&gicIrqConfig[irqn], 0, sizeof(gicIrqConfig[irqn]));
|
||||||
|
gicIrqHandlers[irqn] = NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
void gicEnableInterrupt(u32 irqn)
|
||||||
|
{
|
||||||
|
REG_DIC_PRIORITY[irqn] = gicIrqConfig[irqn].prio;
|
||||||
|
REG_DIC_TARGETCPU[irqn] = gicIrqConfig[irqn].tgt;
|
||||||
|
gicSetIrqCfg(irqn);
|
||||||
|
|
||||||
|
REG_DIC_CLRPENDING[irqn / 32] |= BIT(irqn & 0x1F);
|
||||||
|
REG_DIC_SETENABLE[irqn / 32] |= BIT(irqn & 0x1F);
|
||||||
|
}
|
||||||
|
|
||||||
|
void gicDisableInterrupt(u32 irqn)
|
||||||
|
{
|
||||||
|
REG_DIC_CLRENABLE[irqn / 32] |= BIT(irqn & 0x1F);
|
||||||
|
REG_DIC_CLRPENDING[irqn / 32] |= BIT(irqn & 0x1F);
|
||||||
|
}
|
||||||
|
|
||||||
|
void gicTriggerSoftInterrupt(u32 softirq)
|
||||||
|
{
|
||||||
|
REG_DIC_SOFTINT = softirq;
|
||||||
|
}
|
||||||
|
|
||||||
|
static void irqEvReset(void) {
|
||||||
|
memset(&gicIrqPending, 0, sizeof(gicIrqPending));
|
||||||
|
}
|
||||||
|
|
||||||
|
static u32 irqEvTest(u32 param, u32 clear) {
|
||||||
|
u32 index, tstmask, clrmask;
|
||||||
|
|
||||||
|
if (param >= DIC_MAX_IRQ)
|
||||||
|
bkpt;
|
||||||
|
index = param / 32;
|
||||||
|
tstmask = BIT(param % 32);
|
||||||
|
clrmask = clear ? tstmask : 0;
|
||||||
|
return !!(atomic_fetch_and(&gicIrqPending[index], ~clrmask) & tstmask);
|
||||||
|
}
|
||||||
|
|
||||||
|
static const EventInterface evIRQ = {
|
||||||
|
.reset = irqEvReset,
|
||||||
|
.test = irqEvTest
|
||||||
|
};
|
||||||
|
|
||||||
|
const EventInterface *getEventIRQ(void) {
|
||||||
|
return &evIRQ;
|
||||||
|
}
|
112
arm11/source/arm/gic.h
Normal file
112
arm11/source/arm/gic.h
Normal file
@ -0,0 +1,112 @@
|
|||||||
|
/*
|
||||||
|
* This file is part of GodMode9
|
||||||
|
* Copyright (C) 2017-2020 Wolfvak
|
||||||
|
*
|
||||||
|
* This program is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 2 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <common.h>
|
||||||
|
#include <arm.h>
|
||||||
|
|
||||||
|
typedef void (*gicIrqHandler)(u32 irqn);
|
||||||
|
|
||||||
|
enum {
|
||||||
|
GIC_LEVELHIGH_NN = 0, // no interrupts use level high triggers so far
|
||||||
|
GIC_LEVELHIGH_1N = 1,
|
||||||
|
|
||||||
|
GIC_RISINGEDGE_NN = 2,
|
||||||
|
GIC_RISINGEDGE_1N = 3
|
||||||
|
|
||||||
|
// With the 1-N model, an interrupt that is taken on any CPU clears the Pending
|
||||||
|
// status on all CPUs.
|
||||||
|
// With the N-N model, all CPUs receive the interrupt independently. The Pending
|
||||||
|
// status is cleared only for the CPU that takes it, not for the other CPUs
|
||||||
|
};
|
||||||
|
|
||||||
|
enum {
|
||||||
|
GIC_PRIO0 = 0x00,
|
||||||
|
GIC_PRIO1 = 0x10,
|
||||||
|
GIC_PRIO2 = 0x20,
|
||||||
|
GIC_PRIO3 = 0x30,
|
||||||
|
GIC_PRIO4 = 0x40,
|
||||||
|
GIC_PRIO5 = 0x50,
|
||||||
|
GIC_PRIO6 = 0x60,
|
||||||
|
GIC_PRIO7 = 0x70,
|
||||||
|
GIC_PRIO14 = 0xE0,
|
||||||
|
GIC_PRIO15 = 0xF0,
|
||||||
|
};
|
||||||
|
|
||||||
|
#define GIC_PRIO_HIGHEST GIC_PRIO0
|
||||||
|
#define GIC_PRIO_LOWEST GIC_PRIO14
|
||||||
|
#define GIC_PRIO_NEVER GIC_PRIO15
|
||||||
|
|
||||||
|
void gicGlobalReset(void);
|
||||||
|
void gicLocalReset(void);
|
||||||
|
|
||||||
|
/*
|
||||||
|
Notes from https://static.docs.arm.com/ddi0360/f/DDI0360F_arm11_mpcore_r2p0_trm.pdf
|
||||||
|
|
||||||
|
INTERRUPT ENABLE:
|
||||||
|
Interrupts 0-15 fields are read as one, that is, always enabled, and write to these fields
|
||||||
|
have no effect.
|
||||||
|
Notpresent interrupts (depending on the Interrupt Controller Type Register and
|
||||||
|
interrupt number field) related fields are read as zero and writes to these fields have no
|
||||||
|
effect.
|
||||||
|
|
||||||
|
INTERRUPT PRIORITY:
|
||||||
|
The first four registers are aliased for each MP11 CPU, that is, the priority set for
|
||||||
|
ID0-15 and ID29-31 can be different for each MP11 CPU. The priority of IPIs ID0-15
|
||||||
|
depends on the receiving CPU, not the sending CPU.
|
||||||
|
|
||||||
|
INTERRUPT CPU TARGET:
|
||||||
|
For MP11 CPU n, CPU targets 29, 30 and 31 are read as (1 << n). Writes are ignored.
|
||||||
|
For IT0-IT28, these fields are read as zero and writes are ignored.
|
||||||
|
|
||||||
|
INTERRUPT CONFIGURATION:
|
||||||
|
For ID0-ID15, bit 1 of the configuration pair is always read as one, that is, rising edge
|
||||||
|
sensitive.
|
||||||
|
For ID0-ID15, bit 0 (software model) can be configured and applies to the interrupts
|
||||||
|
sent from the writing MP11 CPU.
|
||||||
|
For ID29, and ID30, the configuration pair is always read as b10, that is rising edge
|
||||||
|
sensitive and N-N software model because these IDs are allocated to timer and
|
||||||
|
watchdog interrupts that are CPU-specific
|
||||||
|
*/
|
||||||
|
|
||||||
|
#define COREMASK_ALL (BIT(MAX_CPU) - 1)
|
||||||
|
|
||||||
|
void gicSetInterruptConfig(u32 irqn, u32 coremask, u32 prio, gicIrqHandler handler);
|
||||||
|
void gicClearInterruptConfig(u32 irqn);
|
||||||
|
|
||||||
|
void gicEnableInterrupt(u32 irqn);
|
||||||
|
void gicDisableInterrupt(u32 irqn);
|
||||||
|
|
||||||
|
enum {
|
||||||
|
GIC_SOFTIRQ_LIST = 0,
|
||||||
|
GIC_SOFTIRQ_OTHERS = 1, // all except self
|
||||||
|
GIC_SOFTIRQ_SELF = 2,
|
||||||
|
};
|
||||||
|
|
||||||
|
#define GIC_SOFTIRQ_SOURCE(n) (((n) >> 10) & 0xF)
|
||||||
|
#define GIC_SOFTIRQ_ID(n) ((n) & 0x3FF)
|
||||||
|
|
||||||
|
#define GIC_SOFTIRQ_FMT(id, filter, coremask) \
|
||||||
|
((id) | ((coremask) << 16) | ((filter) << 24))
|
||||||
|
// id & 0xf, coremask & 3, filter & 3
|
||||||
|
// coremask is only used with filter == GIC_SOFTIRQ_LIST
|
||||||
|
|
||||||
|
#define GIC_SOFTIRQ_SRC(x) (((x) >> 10) % MAX_CPU)
|
||||||
|
|
||||||
|
void gicTriggerSoftInterrupt(u32 softirq);
|
279
arm11/source/arm/mmu.c
Executable file
279
arm11/source/arm/mmu.c
Executable file
@ -0,0 +1,279 @@
|
|||||||
|
/*
|
||||||
|
* This file is part of GodMode9
|
||||||
|
* Copyright (C) 2018-2019 Wolfvak
|
||||||
|
*
|
||||||
|
* This program is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 2 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <types.h>
|
||||||
|
#include <common.h>
|
||||||
|
|
||||||
|
#include <arm.h>
|
||||||
|
|
||||||
|
#include "arm/mmu.h"
|
||||||
|
|
||||||
|
/* Virtual Memory Mapper */
|
||||||
|
#define L1_VA_IDX(v) (((v) >> 20) & 0xFFF)
|
||||||
|
#define L2_VA_IDX(v) (((v) >> 12) & 0xFF)
|
||||||
|
|
||||||
|
#define SECT_ADDR_SHIFT (20)
|
||||||
|
#define COARSE_ADDR_SHIFT (10)
|
||||||
|
#define PAGE_ADDR_SHIFT (12)
|
||||||
|
#define LPAGE_ADDR_SHIFT (16)
|
||||||
|
|
||||||
|
#define SECT_SIZE (BIT(SECT_ADDR_SHIFT))
|
||||||
|
#define COARSE_SIZE (BIT(COARSE_ADDR_SHIFT))
|
||||||
|
#define PAGE_SIZE (BIT(PAGE_ADDR_SHIFT))
|
||||||
|
#define LPAGE_SIZE (BIT(LPAGE_ADDR_SHIFT))
|
||||||
|
|
||||||
|
#define SECT_MASK (~(SECT_SIZE - 1))
|
||||||
|
#define COARSE_MASK (~(COARSE_SIZE - 1))
|
||||||
|
#define PAGE_MASK (~(PAGE_SIZE - 1))
|
||||||
|
#define LPAGE_MASK (~(LPAGE_SIZE - 1))
|
||||||
|
|
||||||
|
#define DESCRIPTOR_L1_UNMAPPED (0)
|
||||||
|
#define DESCRIPTOR_L1_COARSE (1)
|
||||||
|
#define DESCRIPTOR_L1_SECTION (2)
|
||||||
|
#define DESCRIPTOR_L1_RESERVED (3)
|
||||||
|
|
||||||
|
#define DESCRIPTOR_L2_UNMAPPED (0)
|
||||||
|
#define DESCRIPTOR_L2_LARGEPAGE (1)
|
||||||
|
#define DESCRIPTOR_L2_PAGE_EXEC (2)
|
||||||
|
#define DESCRIPTOR_L2_PAGE_NX (3)
|
||||||
|
|
||||||
|
#define DESCRIPTOR_TYPE_MASK (3)
|
||||||
|
|
||||||
|
enum {
|
||||||
|
L1_UNMAPPED,
|
||||||
|
L1_COARSE,
|
||||||
|
L1_SECTION,
|
||||||
|
L1_RESERVED,
|
||||||
|
|
||||||
|
L2_UNMAPPED,
|
||||||
|
L2_LARGEPAGE,
|
||||||
|
L2_PAGE,
|
||||||
|
};
|
||||||
|
|
||||||
|
typedef struct {
|
||||||
|
u32 desc[4096];
|
||||||
|
} __attribute__((aligned(16384))) mmuLevel1Table;
|
||||||
|
|
||||||
|
typedef struct {
|
||||||
|
u32 desc[256];
|
||||||
|
} __attribute__((aligned(1024))) mmuLevel2Table;
|
||||||
|
|
||||||
|
static mmuLevel1Table mmuGlobalTT;
|
||||||
|
|
||||||
|
// simple watermark allocator for 2nd level page tables
|
||||||
|
#define MAX_SECOND_LEVEL (8)
|
||||||
|
static mmuLevel2Table mmuCoarseTables[MAX_SECOND_LEVEL];
|
||||||
|
static u32 mmuCoarseAllocated = 0;
|
||||||
|
static mmuLevel2Table *mmuAllocateLevel2Table(void)
|
||||||
|
{
|
||||||
|
return &mmuCoarseTables[mmuCoarseAllocated++];
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// functions to convert from internal page flag format to ARM
|
||||||
|
|
||||||
|
// {TEX, CB} pairs
|
||||||
|
static const u8 mmuTypeLUT[MMU_MEMORY_TYPES][2] = {
|
||||||
|
[MMU_STRONG_ORDER] = {0, 0},
|
||||||
|
[MMU_UNCACHEABLE] = {1, 0},
|
||||||
|
[MMU_DEV_SHARED] = {0, 1},
|
||||||
|
[MMU_DEV_NONSHARED] = {2, 0},
|
||||||
|
[MMU_CACHE_WT] = {0, 2},
|
||||||
|
[MMU_CACHE_WB] = {1, 3},
|
||||||
|
[MMU_CACHE_WBA] = {1, 3},
|
||||||
|
};
|
||||||
|
|
||||||
|
static u32 mmuGetTEX(u32 f)
|
||||||
|
{ return mmuTypeLUT[MMU_FLAGS_TYPE(f)][0]; }
|
||||||
|
static u32 mmuGetCB(u32 f)
|
||||||
|
{ return mmuTypeLUT[MMU_FLAGS_TYPE(f)][1]; }
|
||||||
|
static u32 mmuGetNX(u32 f)
|
||||||
|
{ return MMU_FLAGS_NOEXEC(f) ? 1 : 0; }
|
||||||
|
static u32 mmuGetShared(u32 f)
|
||||||
|
{ return MMU_FLAGS_SHARED(f) ? 1 : 0; }
|
||||||
|
|
||||||
|
// access permissions
|
||||||
|
static const u8 mmuAccessLUT[MMU_ACCESS_TYPES] = {
|
||||||
|
[MMU_NO_ACCESS] = 0,
|
||||||
|
[MMU_READ_ONLY] = 0x21,
|
||||||
|
[MMU_READ_WRITE] = 0x01,
|
||||||
|
};
|
||||||
|
|
||||||
|
static u32 mmuGetAP(u32 f)
|
||||||
|
{ return mmuAccessLUT[MMU_FLAGS_ACCESS(f)]; }
|
||||||
|
|
||||||
|
// other misc helper functions
|
||||||
|
static unsigned mmuWalkTT(u32 va)
|
||||||
|
{
|
||||||
|
mmuLevel2Table *coarsepd;
|
||||||
|
u32 desc = mmuGlobalTT.desc[L1_VA_IDX(va)];
|
||||||
|
|
||||||
|
switch(desc & DESCRIPTOR_TYPE_MASK) {
|
||||||
|
case DESCRIPTOR_L1_UNMAPPED:
|
||||||
|
return L1_UNMAPPED;
|
||||||
|
|
||||||
|
case DESCRIPTOR_L1_COARSE:
|
||||||
|
break;
|
||||||
|
|
||||||
|
case DESCRIPTOR_L1_SECTION:
|
||||||
|
return L1_SECTION;
|
||||||
|
|
||||||
|
case DESCRIPTOR_L1_RESERVED:
|
||||||
|
return L1_RESERVED;
|
||||||
|
}
|
||||||
|
|
||||||
|
coarsepd = (mmuLevel2Table*)(desc & COARSE_MASK);
|
||||||
|
desc = coarsepd->desc[L2_VA_IDX(va)];
|
||||||
|
|
||||||
|
switch(desc & DESCRIPTOR_TYPE_MASK) {
|
||||||
|
default:
|
||||||
|
case DESCRIPTOR_L2_UNMAPPED:
|
||||||
|
return L2_UNMAPPED;
|
||||||
|
|
||||||
|
case DESCRIPTOR_L2_LARGEPAGE:
|
||||||
|
return L2_LARGEPAGE;
|
||||||
|
|
||||||
|
case DESCRIPTOR_L2_PAGE_NX:
|
||||||
|
case DESCRIPTOR_L2_PAGE_EXEC:
|
||||||
|
return L2_PAGE;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static mmuLevel2Table *mmuCoarseFix(u32 va)
|
||||||
|
{
|
||||||
|
u32 type;
|
||||||
|
mmuLevel2Table *coarsepd;
|
||||||
|
|
||||||
|
type = mmuWalkTT(va);
|
||||||
|
switch(type) {
|
||||||
|
case L1_UNMAPPED:
|
||||||
|
coarsepd = mmuAllocateLevel2Table();
|
||||||
|
mmuGlobalTT.desc[L1_VA_IDX(va)] = (u32)coarsepd | DESCRIPTOR_L1_COARSE;
|
||||||
|
break;
|
||||||
|
|
||||||
|
case L2_UNMAPPED:
|
||||||
|
coarsepd = (mmuLevel2Table*)(mmuGlobalTT.desc[L1_VA_IDX(va)] & COARSE_MASK);
|
||||||
|
break;
|
||||||
|
|
||||||
|
default:
|
||||||
|
coarsepd = NULL;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
return coarsepd;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/* Sections */
|
||||||
|
static u32 mmuSectionFlags(u32 f)
|
||||||
|
{ // converts the internal format to the hardware L1 section format
|
||||||
|
return (mmuGetShared(f) << 16) | (mmuGetTEX(f) << 12) |
|
||||||
|
(mmuGetAP(f) << 10) | (mmuGetNX(f) << 4) |
|
||||||
|
(mmuGetCB(f) << 2) | DESCRIPTOR_L1_SECTION;
|
||||||
|
}
|
||||||
|
|
||||||
|
static void mmuMapSection(u32 va, u32 pa, u32 flags)
|
||||||
|
{
|
||||||
|
mmuGlobalTT.desc[L1_VA_IDX(va)] = pa | mmuSectionFlags(flags);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/* Pages */
|
||||||
|
static u32 mmuPageFlags(u32 f)
|
||||||
|
{
|
||||||
|
return (mmuGetShared(f) << 10) | (mmuGetTEX(f) << 6) |
|
||||||
|
(mmuGetAP(f) << 4) | (mmuGetCB(f) << 2) |
|
||||||
|
(mmuGetNX(f) ? DESCRIPTOR_L2_PAGE_NX : DESCRIPTOR_L2_PAGE_EXEC);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void mmuMapPage(u32 va, u32 pa, u32 flags)
|
||||||
|
{
|
||||||
|
mmuLevel2Table *l2 = mmuCoarseFix(va);
|
||||||
|
l2->desc[L2_VA_IDX(va)] = pa | mmuPageFlags(flags);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
static bool mmuMappingFits(u32 va, u32 pa, u32 sz, u32 alignment)
|
||||||
|
{
|
||||||
|
return !((va | pa | sz) & (alignment));
|
||||||
|
}
|
||||||
|
|
||||||
|
u32 mmuMapArea(u32 va, u32 pa, u32 size, u32 flags)
|
||||||
|
{
|
||||||
|
static const struct {
|
||||||
|
u32 size;
|
||||||
|
void (*mapfn)(u32,u32,u32);
|
||||||
|
} VMappers[] = {
|
||||||
|
{
|
||||||
|
.size = BIT(SECT_ADDR_SHIFT),
|
||||||
|
.mapfn = mmuMapSection,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
.size = BIT(PAGE_ADDR_SHIFT),
|
||||||
|
.mapfn = mmuMapPage,
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
|
while(size > 0) {
|
||||||
|
size_t i = 0;
|
||||||
|
for (i = 0; i < countof(VMappers); i++) {
|
||||||
|
u32 pgsize = VMappers[i].size;
|
||||||
|
|
||||||
|
if (mmuMappingFits(va, pa, size, pgsize-1)) {
|
||||||
|
(VMappers[i].mapfn)(va, pa, flags);
|
||||||
|
|
||||||
|
va += pgsize;
|
||||||
|
pa += pgsize;
|
||||||
|
size -= pgsize;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
/* alternatively return the unmapped remaining size:
|
||||||
|
if (i == countof(VMappers))
|
||||||
|
return size;
|
||||||
|
*/
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
void mmuInvalidate(void)
|
||||||
|
{
|
||||||
|
ARM_MCR(p15, 0, 0, c8, c7, 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
void mmuInvalidateVA(u32 addr)
|
||||||
|
{
|
||||||
|
ARM_MCR(p15, 0, addr, c8, c7, 2);
|
||||||
|
}
|
||||||
|
|
||||||
|
void mmuInitRegisters(void)
|
||||||
|
{
|
||||||
|
u32 ttbr0 = (u32)(&mmuGlobalTT) | 0x12;
|
||||||
|
|
||||||
|
// Set up TTBR0/1 and the TTCR
|
||||||
|
ARM_MCR(p15, 0, ttbr0, c2, c0, 0);
|
||||||
|
ARM_MCR(p15, 0, 0, c2, c0, 1);
|
||||||
|
ARM_MCR(p15, 0, 0, c2, c0, 2);
|
||||||
|
|
||||||
|
// Set up the DACR
|
||||||
|
ARM_MCR(p15, 0, 0x55555555, c3, c0, 0);
|
||||||
|
|
||||||
|
// Invalidate the unified TLB
|
||||||
|
ARM_MCR(p15, 0, 0, c8, c7, 0);
|
||||||
|
}
|
54
arm11/source/arm/mmu.h
Executable file
54
arm11/source/arm/mmu.h
Executable file
@ -0,0 +1,54 @@
|
|||||||
|
/*
|
||||||
|
* This file is part of GodMode9
|
||||||
|
* Copyright (C) 2018-2019 Wolfvak
|
||||||
|
*
|
||||||
|
* This program is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 2 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <types.h>
|
||||||
|
|
||||||
|
enum {
|
||||||
|
MMU_STRONG_ORDER = 0,
|
||||||
|
MMU_UNCACHEABLE,
|
||||||
|
MMU_DEV_SHARED,
|
||||||
|
MMU_DEV_NONSHARED,
|
||||||
|
MMU_CACHE_WT,
|
||||||
|
MMU_CACHE_WB,
|
||||||
|
MMU_CACHE_WBA,
|
||||||
|
MMU_MEMORY_TYPES,
|
||||||
|
};
|
||||||
|
|
||||||
|
enum {
|
||||||
|
MMU_NO_ACCESS = 0,
|
||||||
|
MMU_READ_ONLY,
|
||||||
|
MMU_READ_WRITE,
|
||||||
|
MMU_ACCESS_TYPES,
|
||||||
|
};
|
||||||
|
|
||||||
|
#define MMU_FLAGS(t, ap, nx, s) ((s) << 25 | (nx) << 24 | (ap) << 8 | (t))
|
||||||
|
|
||||||
|
#define MMU_FLAGS_TYPE(f) ((f) & 0xFF)
|
||||||
|
#define MMU_FLAGS_ACCESS(f) (((f) >> 8) & 0xFF)
|
||||||
|
|
||||||
|
#define MMU_FLAGS_NOEXEC(f) ((f) & BIT(24))
|
||||||
|
#define MMU_FLAGS_SHARED(f) ((f) & BIT(25))
|
||||||
|
|
||||||
|
u32 mmuMapArea(u32 va, u32 pa, u32 size, u32 flags);
|
||||||
|
|
||||||
|
void mmuInvalidate(void);
|
||||||
|
void mmuInvalidateVA(u32 addr); // DO NOT USE
|
||||||
|
|
||||||
|
void mmuInitRegisters(void);
|
32
arm11/source/arm/scu.c
Executable file
32
arm11/source/arm/scu.c
Executable file
@ -0,0 +1,32 @@
|
|||||||
|
/*
|
||||||
|
* This file is part of GodMode9
|
||||||
|
* Copyright (C) 2018-2019 Wolfvak
|
||||||
|
*
|
||||||
|
* This program is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 2 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <types.h>
|
||||||
|
#include <arm.h>
|
||||||
|
|
||||||
|
#define REG_SCU_CNT (*REG_ARM_PMR(0x00, u32))
|
||||||
|
#define REG_SCU_CFG (*REG_ARM_PMR(0x04, u32))
|
||||||
|
#define REG_SCU_CPU (*REG_ARM_PMR(0x08, u32))
|
||||||
|
#define REG_SCU_INV (*REG_ARM_PMR(0x0C, u32))
|
||||||
|
|
||||||
|
void SCU_Init(void)
|
||||||
|
{
|
||||||
|
REG_SCU_CNT = 0x1FFE;
|
||||||
|
REG_SCU_INV = 0xFFFF;
|
||||||
|
REG_SCU_CNT = 0x3FFF;
|
||||||
|
}
|
23
arm11/source/arm/scu.h
Executable file
23
arm11/source/arm/scu.h
Executable file
@ -0,0 +1,23 @@
|
|||||||
|
/*
|
||||||
|
* This file is part of GodMode9
|
||||||
|
* Copyright (C) 2018-2019 Wolfvak
|
||||||
|
*
|
||||||
|
* This program is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 2 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <types.h>
|
||||||
|
|
||||||
|
void SCU_Init(void);
|
47
arm11/source/arm/timer.c
Executable file
47
arm11/source/arm/timer.c
Executable file
@ -0,0 +1,47 @@
|
|||||||
|
/*
|
||||||
|
* This file is part of GodMode9
|
||||||
|
* Copyright (C) 2019 Wolfvak
|
||||||
|
*
|
||||||
|
* This program is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 2 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <types.h>
|
||||||
|
#include <arm.h>
|
||||||
|
|
||||||
|
#include "arm/gic.h"
|
||||||
|
#include "arm/timer.h"
|
||||||
|
|
||||||
|
#define TIMER_INTERRUPT (0x1E)
|
||||||
|
|
||||||
|
#define REG_TIMER(c, n) REG_ARM_PMR(0x700 + ((c) * 0x100) + (n), u32)
|
||||||
|
#define TIMER_THIS_CPU (-1)
|
||||||
|
|
||||||
|
#define REG_TIMER_LOAD(c) *REG_TIMER((c), 0x00)
|
||||||
|
#define REG_TIMER_COUNT(c) *REG_TIMER((c), 0x04)
|
||||||
|
#define REG_TIMER_CNT(c) *REG_TIMER((c), 0x08)
|
||||||
|
#define REG_TIMER_IRQ(c) *REG_TIMER((c), 0x0C)
|
||||||
|
|
||||||
|
#define TIMER_CNT_SCALE(n) ((n) << 8)
|
||||||
|
#define TIMER_CNT_INT_EN BIT(2)
|
||||||
|
#define TIMER_CNT_RELOAD BIT(1)
|
||||||
|
#define TIMER_CNT_ENABLE BIT(0)
|
||||||
|
|
||||||
|
void TIMER_WaitTicks(u32 ticks)
|
||||||
|
{
|
||||||
|
REG_TIMER_IRQ(TIMER_THIS_CPU) = 1;
|
||||||
|
REG_TIMER_CNT(TIMER_THIS_CPU) = 0;
|
||||||
|
REG_TIMER_LOAD(TIMER_THIS_CPU) = ticks;
|
||||||
|
REG_TIMER_CNT(TIMER_THIS_CPU) = TIMER_CNT_ENABLE;
|
||||||
|
while(REG_TIMER_COUNT(TIMER_THIS_CPU));
|
||||||
|
}
|
36
arm11/source/arm/timer.h
Executable file
36
arm11/source/arm/timer.h
Executable file
@ -0,0 +1,36 @@
|
|||||||
|
/*
|
||||||
|
* This file is part of GodMode9
|
||||||
|
* Copyright (C) 2019 Wolfvak
|
||||||
|
*
|
||||||
|
* This program is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 2 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <types.h>
|
||||||
|
|
||||||
|
// The timer interval is calculated using the following equation:
|
||||||
|
// T = [(PRESCALER_value + 1) * (Load_value + 1) * 2] / CPU_CLK
|
||||||
|
// therefore
|
||||||
|
// Load_value = [(CPU_CLK / 2) * (T / (PRESCALER_value + 1))] - 1
|
||||||
|
|
||||||
|
#define BASE_CLKRATE (268111856 / 2)
|
||||||
|
|
||||||
|
#define CLK_MS_TO_TICKS(m) (((BASE_CLKRATE / 1000) * (m)) - 1)
|
||||||
|
|
||||||
|
void TIMER_WaitTicks(u32 ticks);
|
||||||
|
|
||||||
|
static inline void TIMER_WaitMS(u32 ms) {
|
||||||
|
TIMER_WaitTicks(CLK_MS_TO_TICKS(ms));
|
||||||
|
}
|
219
arm11/source/arm/xrq.c
Normal file
219
arm11/source/arm/xrq.c
Normal file
@ -0,0 +1,219 @@
|
|||||||
|
/*
|
||||||
|
* This file is part of GodMode9
|
||||||
|
* Copyright (C) 2019 Wolfvak
|
||||||
|
*
|
||||||
|
* This program is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 2 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
// kinda hardcoded and all over the place, but it needs to stay simple
|
||||||
|
|
||||||
|
#include <types.h>
|
||||||
|
#include <arm.h>
|
||||||
|
|
||||||
|
#include <vram.h>
|
||||||
|
|
||||||
|
static const u8 num_font[16*8];
|
||||||
|
|
||||||
|
#define SCREEN ((u16*)(VRAM_TOP_LA))
|
||||||
|
|
||||||
|
void draw_char(u16 *fb, int c, int x, int y)
|
||||||
|
{
|
||||||
|
for (int _y = 0; _y < 8; _y++) {
|
||||||
|
for (int _x = 0; _x < 8; _x++) {
|
||||||
|
u16 *fbpos = fb + (240 - (y + _y)) + (240 * (x + _x));
|
||||||
|
|
||||||
|
u8 mask = (num_font[(c * 8) + _y] >> (8 - _x)) & 1;
|
||||||
|
|
||||||
|
if (mask)
|
||||||
|
*fbpos = ~0;
|
||||||
|
else
|
||||||
|
*fbpos = 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void draw_hex(u16 *fb, u32 num, int x, int y)
|
||||||
|
{
|
||||||
|
x += 7*8;
|
||||||
|
for (int i = 0; i < 8; i++) {
|
||||||
|
draw_char(fb, num & 0xf, x, y);
|
||||||
|
num >>= 4;
|
||||||
|
x -= 8;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void do_exception(u32 type, u32 *regs)
|
||||||
|
{
|
||||||
|
for (int i = 0; i < 400*240; i++)
|
||||||
|
SCREEN[i] = 0;
|
||||||
|
|
||||||
|
draw_hex(SCREEN, type, 8, 16);
|
||||||
|
|
||||||
|
for (int i = 0; i < 20; i += 2) {
|
||||||
|
draw_hex(SCREEN, i, 8, 32 + (i * 4));
|
||||||
|
draw_hex(SCREEN, regs[i], 80, 32 + (i * 4));
|
||||||
|
|
||||||
|
draw_hex(SCREEN, i + 1, 208, 32 + (i * 4));
|
||||||
|
draw_hex(SCREEN, regs[i + 1], 280, 32 + (i * 4));
|
||||||
|
}
|
||||||
|
|
||||||
|
while(1)
|
||||||
|
ARM_WFI();
|
||||||
|
}
|
||||||
|
|
||||||
|
static const u8 num_font[] = {
|
||||||
|
0b00000000,
|
||||||
|
0b00011000,
|
||||||
|
0b00100100,
|
||||||
|
0b00101100,
|
||||||
|
0b00110100,
|
||||||
|
0b00100100,
|
||||||
|
0b00011000,
|
||||||
|
0b00000000, // 0
|
||||||
|
|
||||||
|
0b00000000,
|
||||||
|
0b00011000,
|
||||||
|
0b00101000,
|
||||||
|
0b00001000,
|
||||||
|
0b00001000,
|
||||||
|
0b00001000,
|
||||||
|
0b00111100,
|
||||||
|
0b00000000, // 1
|
||||||
|
|
||||||
|
0b00000000,
|
||||||
|
0b00011000,
|
||||||
|
0b00100100,
|
||||||
|
0b00000100,
|
||||||
|
0b00001000,
|
||||||
|
0b00010000,
|
||||||
|
0b00111100,
|
||||||
|
0b00000000, // 2
|
||||||
|
|
||||||
|
0b00000000,
|
||||||
|
0b00111000,
|
||||||
|
0b00000100,
|
||||||
|
0b00011000,
|
||||||
|
0b00000100,
|
||||||
|
0b00000100,
|
||||||
|
0b00111000,
|
||||||
|
0b00000000, // 3
|
||||||
|
|
||||||
|
0b00000000,
|
||||||
|
0b00100100,
|
||||||
|
0b00100100,
|
||||||
|
0b00111100,
|
||||||
|
0b00000100,
|
||||||
|
0b00000100,
|
||||||
|
0b00000100,
|
||||||
|
0b00000000, // 4
|
||||||
|
|
||||||
|
0b00000000,
|
||||||
|
0b00111100,
|
||||||
|
0b00100000,
|
||||||
|
0b00111000,
|
||||||
|
0b00000100,
|
||||||
|
0b00000100,
|
||||||
|
0b00111000,
|
||||||
|
0b00000000, // 5
|
||||||
|
|
||||||
|
0b00000000,
|
||||||
|
0b00011100,
|
||||||
|
0b00100000,
|
||||||
|
0b00111000,
|
||||||
|
0b00100100,
|
||||||
|
0b00100100,
|
||||||
|
0b00011000,
|
||||||
|
0b00000000, // 6
|
||||||
|
|
||||||
|
0b00000000,
|
||||||
|
0b00111100,
|
||||||
|
0b00000100,
|
||||||
|
0b00000100,
|
||||||
|
0b00001000,
|
||||||
|
0b00010000,
|
||||||
|
0b00010000,
|
||||||
|
0b00000000, // 7
|
||||||
|
|
||||||
|
0b00000000,
|
||||||
|
0b00011000,
|
||||||
|
0b00100100,
|
||||||
|
0b00011000,
|
||||||
|
0b00100100,
|
||||||
|
0b00100100,
|
||||||
|
0b00011000,
|
||||||
|
0b00000000, // 8
|
||||||
|
|
||||||
|
0b00000000,
|
||||||
|
0b00011000,
|
||||||
|
0b00100100,
|
||||||
|
0b00011100,
|
||||||
|
0b00000100,
|
||||||
|
0b00000100,
|
||||||
|
0b00111000,
|
||||||
|
0b00000000, // 9
|
||||||
|
|
||||||
|
0b00000000,
|
||||||
|
0b00011000,
|
||||||
|
0b00100100,
|
||||||
|
0b00111100,
|
||||||
|
0b00100100,
|
||||||
|
0b00100100,
|
||||||
|
0b00100100,
|
||||||
|
0b00000000, // A
|
||||||
|
|
||||||
|
0b00000000,
|
||||||
|
0b00111000,
|
||||||
|
0b00100100,
|
||||||
|
0b00111000,
|
||||||
|
0b00100100,
|
||||||
|
0b00100100,
|
||||||
|
0b00111000,
|
||||||
|
0b00000000, // B
|
||||||
|
|
||||||
|
0b00000000,
|
||||||
|
0b00011100,
|
||||||
|
0b00100000,
|
||||||
|
0b00100000,
|
||||||
|
0b00100000,
|
||||||
|
0b00100000,
|
||||||
|
0b00011100,
|
||||||
|
0b00000000, // C
|
||||||
|
|
||||||
|
0b00000000,
|
||||||
|
0b00110000,
|
||||||
|
0b00101000,
|
||||||
|
0b00100100,
|
||||||
|
0b00100100,
|
||||||
|
0b00101000,
|
||||||
|
0b00110000,
|
||||||
|
0b00000000, // C
|
||||||
|
|
||||||
|
0b00000000,
|
||||||
|
0b00111100,
|
||||||
|
0b00100000,
|
||||||
|
0b00111100,
|
||||||
|
0b00100000,
|
||||||
|
0b00100000,
|
||||||
|
0b00111100,
|
||||||
|
0b00000000, // E
|
||||||
|
|
||||||
|
0b00000000,
|
||||||
|
0b00111100,
|
||||||
|
0b00100000,
|
||||||
|
0b00111100,
|
||||||
|
0b00100000,
|
||||||
|
0b00100000,
|
||||||
|
0b00100000,
|
||||||
|
0b00000000, // F
|
||||||
|
};
|
21
arm11/source/arm/xrq.h
Normal file
21
arm11/source/arm/xrq.h
Normal file
@ -0,0 +1,21 @@
|
|||||||
|
/*
|
||||||
|
* This file is part of GodMode9
|
||||||
|
* Copyright (C) 2020 Wolfvak
|
||||||
|
*
|
||||||
|
* This program is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 2 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
u32 xrqInstallVectorTable(void);
|
129
arm11/source/arm/xrqVectors.s
Normal file
129
arm11/source/arm/xrqVectors.s
Normal file
@ -0,0 +1,129 @@
|
|||||||
|
/*
|
||||||
|
* This file is part of GodMode9
|
||||||
|
* Copyright (C) 2017-2019 Wolfvak
|
||||||
|
*
|
||||||
|
* This program is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 2 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
/*
|
||||||
|
* This is almost the same as the ARM9 exception handler,
|
||||||
|
* but with a few extra register dumps (DFSR, IFSR and FAR)
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <arm.h>
|
||||||
|
|
||||||
|
.arm
|
||||||
|
.align 3
|
||||||
|
|
||||||
|
.macro TRAP_ENTRY xrq
|
||||||
|
msr cpsr_f, #(\xrq << 29)
|
||||||
|
b xrqMain
|
||||||
|
.endm
|
||||||
|
|
||||||
|
xrqVectorTable:
|
||||||
|
ldr pc, =xrqReset
|
||||||
|
ldr pc, =xrqUndefined
|
||||||
|
ldr pc, =xrqSVC
|
||||||
|
ldr pc, =xrqPrefetchAbort
|
||||||
|
ldr pc, =xrqDataAbort
|
||||||
|
b . @ ignore the reserved exception
|
||||||
|
ldr pc, =xrqIRQ
|
||||||
|
ldr pc, =xrqFIQ
|
||||||
|
.pool
|
||||||
|
xrqVectorTableEnd:
|
||||||
|
|
||||||
|
xrqReset:
|
||||||
|
TRAP_ENTRY 0
|
||||||
|
|
||||||
|
xrqUndefined:
|
||||||
|
TRAP_ENTRY 1
|
||||||
|
|
||||||
|
xrqSVC:
|
||||||
|
TRAP_ENTRY 2
|
||||||
|
|
||||||
|
xrqPrefetchAbort:
|
||||||
|
TRAP_ENTRY 3
|
||||||
|
|
||||||
|
xrqDataAbort:
|
||||||
|
TRAP_ENTRY 4
|
||||||
|
|
||||||
|
xrqFIQ:
|
||||||
|
TRAP_ENTRY 7
|
||||||
|
|
||||||
|
xrqMain:
|
||||||
|
clrex
|
||||||
|
cpsid aif
|
||||||
|
|
||||||
|
ldr sp, =(xrqStackTop - 32*4)
|
||||||
|
stmia sp, {r0-r7}
|
||||||
|
|
||||||
|
mrs r1, cpsr
|
||||||
|
lsr r0, r1, #29
|
||||||
|
|
||||||
|
mrs r2, spsr
|
||||||
|
str lr, [sp, #15*4]
|
||||||
|
str r2, [sp, #16*4]
|
||||||
|
|
||||||
|
ands r2, r2, #SR_PMODE_MASK
|
||||||
|
orreq r2, r2, #SR_SYS_MODE
|
||||||
|
orr r2, r2, #(0x10 | SR_NOINT)
|
||||||
|
|
||||||
|
add r3, sp, #8*4
|
||||||
|
msr cpsr_c, r2
|
||||||
|
stmia r3!, {r8-r14}
|
||||||
|
msr cpsr_c, r1
|
||||||
|
|
||||||
|
mrc p15, 0, r4, c5, c0, 0 @ data fault status register
|
||||||
|
mrc p15, 0, r5, c5, c0, 1 @ instruction fault status register
|
||||||
|
mrc p15, 0, r6, c6, c0, 0 @ data fault address
|
||||||
|
add r3, r3, #2*4 @ skip saved PC and CPSR
|
||||||
|
stmia r3!, {r4, r5, r6}
|
||||||
|
|
||||||
|
mov r1, sp
|
||||||
|
bl do_exception
|
||||||
|
|
||||||
|
|
||||||
|
xrqIRQ:
|
||||||
|
clrex
|
||||||
|
sub lr, lr, #4 @ Fix return address
|
||||||
|
srsfd sp!, #SR_SVC_MODE @ Store IRQ mode LR and SPSR on the SVC stack
|
||||||
|
cps #SR_SVC_MODE @ Switch to SVC mode
|
||||||
|
push {r0-r4, r12, lr} @ Preserve registers
|
||||||
|
|
||||||
|
and r4, sp, #7 @ Fix SP to be 8byte aligned
|
||||||
|
sub sp, sp, r4
|
||||||
|
|
||||||
|
bl gicTopHandler
|
||||||
|
|
||||||
|
add sp, sp, r4
|
||||||
|
|
||||||
|
pop {r0-r4, r12, lr}
|
||||||
|
rfeia sp! @ Return from exception
|
||||||
|
|
||||||
|
@ u32 xrqInstallVectorTable(void)
|
||||||
|
.global xrqInstallVectorTable
|
||||||
|
.type xrqInstallVectorTable, %function
|
||||||
|
xrqInstallVectorTable:
|
||||||
|
ldr r0, =xrqPage
|
||||||
|
ldr r1, =xrqVectorTable
|
||||||
|
mov r2, #(xrqVectorTableEnd - xrqVectorTable)
|
||||||
|
b memcpy
|
||||||
|
|
||||||
|
.section .bss.xrqPage
|
||||||
|
.align 12
|
||||||
|
.global xrqPage
|
||||||
|
xrqPage:
|
||||||
|
.space 8192 @ reserve two 4K aligned pages for vectors and abort stack
|
||||||
|
.global xrqStackTop
|
||||||
|
xrqStackTop:
|
@ -1,35 +1,107 @@
|
|||||||
|
/*
|
||||||
|
* This file is part of GodMode9
|
||||||
|
* Copyright (C) 2017-2019 Wolfvak
|
||||||
|
*
|
||||||
|
* This program is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 2 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
.section .text.boot
|
.section .text.boot
|
||||||
.align 4
|
.align 4
|
||||||
|
|
||||||
#include <arm.h>
|
#include <arm.h>
|
||||||
|
|
||||||
|
#define STACK_SZ (8192)
|
||||||
|
|
||||||
.global __boot
|
.global __boot
|
||||||
__boot:
|
__boot:
|
||||||
cpsid aif, #(SR_SVC_MODE)
|
cpsid aif, #SR_SVC_MODE
|
||||||
|
clrex
|
||||||
|
|
||||||
|
@ Writeback and invalidate all DCache
|
||||||
|
@ Invalidate all caches
|
||||||
|
@ Data Synchronization Barrier
|
||||||
mov r0, #0
|
mov r0, #0
|
||||||
|
mcr p15, 0, r0, c7, c10, 0
|
||||||
mcr p15, 0, r0, c7, c7, 0
|
mcr p15, 0, r0, c7, c7, 0
|
||||||
mcr p15, 0, r0, c7, c14, 0
|
|
||||||
mcr p15, 0, r0, c7, c10, 4
|
mcr p15, 0, r0, c7, c10, 4
|
||||||
|
|
||||||
ldr sp, =__stack_top
|
@ Reset control registers
|
||||||
|
|
||||||
@ Reset values
|
|
||||||
ldr r0, =0x00054078
|
ldr r0, =0x00054078
|
||||||
ldr r1, =0x0000000F
|
ldr r1, =0x0000000F
|
||||||
ldr r2, =0x00000000
|
ldr r2, =0x00F00000
|
||||||
|
|
||||||
mcr p15, 0, r0, c1, c0, 0
|
mcr p15, 0, r0, c1, c0, 0
|
||||||
mcr p15, 0, r1, c1, c0, 1
|
mcr p15, 0, r1, c1, c0, 1
|
||||||
mcr p15, 0, r2, c1, c0, 2
|
mcr p15, 0, r2, c1, c0, 2
|
||||||
|
|
||||||
ldr r0, =__bss_start
|
@ VFPv2 init
|
||||||
ldr r1, =__bss_end
|
@ https://github.com/derrekr/fastboot3DS/blob/f63c967369451b1fd0078e649cf0010fe10a62fd/source/arm11/start.s#L195
|
||||||
|
mov r0, #0
|
||||||
|
mov r1, #0xF00000 @ Give full access to cp10/11 in user and privileged mode
|
||||||
|
mov r2, #0x40000000 @ Clear exception bits and enable VFP11
|
||||||
|
mov r3, #0x3C00000 @ Round towards zero (RZ) mode, flush-to-zero mode, default NaN mode
|
||||||
|
mcr p15, 0, r1, c1, c0, 2 @ Write Coprocessor Access Control Register
|
||||||
|
mcr p15, 0, r0, c7, c5, 4 @ Flush Prefetch Buffer
|
||||||
|
fmxr fpexc, r2 @ Write Floating-point exception register
|
||||||
|
fmxr fpscr, r3 @ Write Floating-Point Status and Control Register
|
||||||
|
|
||||||
|
|
||||||
|
@ Get CPU ID
|
||||||
|
mrc p15, 0, r12, c0, c0, 5
|
||||||
|
ands r12, r12, #3
|
||||||
|
|
||||||
|
@ Setup stack according to CPU ID
|
||||||
|
ldr sp, =(_stack_base + STACK_SZ)
|
||||||
|
ldr r0, =STACK_SZ
|
||||||
|
mla sp, r0, r12, sp
|
||||||
|
|
||||||
|
beq corezero_start
|
||||||
|
|
||||||
|
cmp r12, #MAX_CPU
|
||||||
|
blo coresmp_start
|
||||||
|
|
||||||
|
1:
|
||||||
|
wfi
|
||||||
|
b 1b
|
||||||
|
|
||||||
|
corezero_start:
|
||||||
|
@ assumes the .bss section size is 128 byte aligned (or zero)
|
||||||
|
ldr r0, =__bss_pa
|
||||||
|
ldr r1, =__bss_va_end @ calculate the length of .bss using the VA start and end
|
||||||
|
ldr r2, =__bss_va
|
||||||
|
sub r1, r1, r2
|
||||||
|
add r1, r0, r1 @ fixup to be PA start and end
|
||||||
mov r2, #0
|
mov r2, #0
|
||||||
|
mov r3, #0
|
||||||
|
mov r4, #0
|
||||||
|
mov r5, #0
|
||||||
.Lclearbss:
|
.Lclearbss:
|
||||||
cmp r0, r1
|
cmp r0, r1
|
||||||
strlt r2, [r0], #4
|
.rept (128 / 16) @ 16 bytes copied per block
|
||||||
blt .Lclearbss
|
stmloia r0!, {r2-r5}
|
||||||
|
.endr
|
||||||
|
blo .Lclearbss
|
||||||
|
|
||||||
bl main
|
bl SYS_CoreZeroInit
|
||||||
b __boot
|
|
||||||
|
coresmp_start:
|
||||||
|
bl SYS_CoreInit
|
||||||
|
ldr lr, =MainLoop
|
||||||
|
bx lr
|
||||||
|
|
||||||
|
.section .bss.stack
|
||||||
|
.align 12 @ make sure stack is aligned to a page boundary
|
||||||
|
.global _stack_base
|
||||||
|
_stack_base:
|
||||||
|
.space (MAX_CPU * STACK_SZ)
|
||||||
|
@ -1,51 +0,0 @@
|
|||||||
#include <types.h>
|
|
||||||
#include <cpu.h>
|
|
||||||
#include <gic.h>
|
|
||||||
|
|
||||||
#include <string.h>
|
|
||||||
|
|
||||||
#define IRQVECTOR_BASE ((vu32*)0x1FFFFFA0)
|
|
||||||
|
|
||||||
extern void (*main_irq_handler)(void);
|
|
||||||
irq_handler GIC_Handlers[128];
|
|
||||||
|
|
||||||
void GIC_Reset(void)
|
|
||||||
{
|
|
||||||
u32 irq_s;
|
|
||||||
|
|
||||||
REG_GIC_CONTROL = 0;
|
|
||||||
memset(GIC_Handlers, 0, sizeof(GIC_Handlers));
|
|
||||||
|
|
||||||
REG_DIC_CONTROL = 0;
|
|
||||||
for (int i = 0; i < 4; i++) {
|
|
||||||
REG_DIC_CLRENABLE[i] = ~0;
|
|
||||||
REG_DIC_CLRPENDING[i] = ~0;
|
|
||||||
}
|
|
||||||
for (int i = 0; i < 32; i++) REG_DIC_PRIORITY[i] = 0;
|
|
||||||
for (int i = 32; i < 128; i++) REG_DIC_TARGETPROC[i] = 0;
|
|
||||||
for (int i = 0; i < 8; i++) REG_DIC_CFGREG[i] = ~0;
|
|
||||||
REG_DIC_CONTROL = 1;
|
|
||||||
|
|
||||||
REG_DIC_CLRENABLE[0] = ~0;
|
|
||||||
for (int i = 0; i < 32; i++) REG_DIC_PRIORITY[i] = 0;
|
|
||||||
for (int i = 0; i < 2; i++) REG_DIC_CFGREG[i] = ~0;
|
|
||||||
REG_GIC_POI = 3;
|
|
||||||
REG_GIC_PRIOMASK = 0xF << 4;
|
|
||||||
REG_GIC_CONTROL = 1;
|
|
||||||
|
|
||||||
do {
|
|
||||||
irq_s = REG_GIC_PENDING;
|
|
||||||
REG_GIC_IRQEND = irq_s;
|
|
||||||
} while(irq_s != 1023);
|
|
||||||
|
|
||||||
IRQVECTOR_BASE[1] = (u32)&main_irq_handler;
|
|
||||||
IRQVECTOR_BASE[0] = 0xE51FF004;
|
|
||||||
}
|
|
||||||
|
|
||||||
void GIC_SetIRQ(u32 irq, irq_handler handler)
|
|
||||||
{
|
|
||||||
GIC_Handlers[irq] = handler;
|
|
||||||
REG_DIC_CLRPENDING[irq >> 5] |= BIT(irq & 0x1F);
|
|
||||||
REG_DIC_SETENABLE[irq >> 5] |= BIT(irq & 0x1F);
|
|
||||||
REG_DIC_TARGETPROC[irq] = 1;
|
|
||||||
}
|
|
@ -1,27 +0,0 @@
|
|||||||
#pragma once
|
|
||||||
#include <types.h>
|
|
||||||
|
|
||||||
typedef void (*irq_handler)(void);
|
|
||||||
|
|
||||||
#define REG_GIC_BASE (0x17E00100) // MPCore PMR
|
|
||||||
#define REG_DIC_BASE (0x17E01000)
|
|
||||||
|
|
||||||
#define REG_GIC_CONTROL (*(vu32*)(REG_GIC_BASE + 0x00))
|
|
||||||
#define REG_GIC_PRIOMASK (*(vu32*)(REG_GIC_BASE + 0x04))
|
|
||||||
#define REG_GIC_POI (*(vu32*)(REG_GIC_BASE + 0x08))
|
|
||||||
#define REG_GIC_IRQACK (*(vu32*)(REG_GIC_BASE + 0x0C))
|
|
||||||
#define REG_GIC_IRQEND (*(vu32*)(REG_GIC_BASE + 0x10))
|
|
||||||
#define REG_GIC_LASTPRIO (*(vu32*)(REG_GIC_BASE + 0x14))
|
|
||||||
#define REG_GIC_PENDING (*(vu32*)(REG_GIC_BASE + 0x18))
|
|
||||||
|
|
||||||
#define REG_DIC_CONTROL (*(vu32*)(REG_DIC_BASE + 0x00))
|
|
||||||
#define REG_DIC_SETENABLE ((vu32*)(REG_DIC_BASE + 0x100))
|
|
||||||
#define REG_DIC_CLRENABLE ((vu32*)(REG_DIC_BASE + 0x180))
|
|
||||||
#define REG_DIC_SETPENDING ((vu32*)(REG_DIC_BASE + 0x200))
|
|
||||||
#define REG_DIC_CLRPENDING ((vu32*)(REG_DIC_BASE + 0x280))
|
|
||||||
#define REG_DIC_PRIORITY ((vu32*)(REG_DIC_BASE + 0x400))
|
|
||||||
#define REG_DIC_TARGETPROC ((vu8*) (REG_DIC_BASE + 0x800))
|
|
||||||
#define REG_DIC_CFGREG ((vu32*)(REG_DIC_BASE + 0xC00))
|
|
||||||
|
|
||||||
void GIC_SetIRQ(u32 irq_id, irq_handler hndl);
|
|
||||||
void GIC_Reset(void);
|
|
@ -1,184 +0,0 @@
|
|||||||
#include <vram.h>
|
|
||||||
#include <gpulcd.h>
|
|
||||||
#include <types.h>
|
|
||||||
|
|
||||||
void LCD_SetBrightness(u32 screen, u8 brightness)
|
|
||||||
{
|
|
||||||
vu32 *lcd_reg;
|
|
||||||
if (screen & 1) {
|
|
||||||
lcd_reg = LCD_CFG(0xA40);
|
|
||||||
} else {
|
|
||||||
lcd_reg = LCD_CFG(0x240);
|
|
||||||
}
|
|
||||||
*lcd_reg = brightness;
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
void LCD_Initialize(u8 brightness)
|
|
||||||
{
|
|
||||||
*LCD_CFG(0x014) = 0x00000001;
|
|
||||||
*LCD_CFG(0x00C) &= 0xFFFEFFFE;
|
|
||||||
*LCD_CFG(0x240) = brightness;
|
|
||||||
*LCD_CFG(0xA40) = brightness;
|
|
||||||
*LCD_CFG(0x244) = 0x1023E;
|
|
||||||
*LCD_CFG(0xA44) = 0x1023E;
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
void LCD_Deinitialize(void)
|
|
||||||
{
|
|
||||||
*LCD_CFG(0x244) = 0;
|
|
||||||
*LCD_CFG(0xA44) = 0;
|
|
||||||
*LCD_CFG(0x00C) = 0;
|
|
||||||
*LCD_CFG(0x014) = 0;
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
void GPU_PSCFill(u32 start, u32 end, u32 fv)
|
|
||||||
{
|
|
||||||
u32 mp;
|
|
||||||
if (start > end)
|
|
||||||
return;
|
|
||||||
|
|
||||||
start = GPU_ADDR(start);
|
|
||||||
end = GPU_ADDR(end);
|
|
||||||
mp = (start+end)/2;
|
|
||||||
|
|
||||||
*GPU_PSC0(PSC_SADDR) = start;
|
|
||||||
*GPU_PSC0(PSC_EADDR) = mp;
|
|
||||||
*GPU_PSC0(PSC_FILL) = fv;
|
|
||||||
|
|
||||||
*GPU_PSC1(PSC_SADDR) = mp;
|
|
||||||
*GPU_PSC1(PSC_EADDR) = end;
|
|
||||||
*GPU_PSC1(PSC_FILL) = fv;
|
|
||||||
|
|
||||||
*GPU_PSC0(PSC_CNT) = PSC_START | PSC_32BIT;
|
|
||||||
*GPU_PSC1(PSC_CNT) = PSC_START | PSC_32BIT;
|
|
||||||
|
|
||||||
while(!((*GPU_PSC0(PSC_CNT) & PSC_DONE) && (*GPU_PSC1(PSC_CNT) & PSC_DONE)));
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
void GPU_SetFramebuffers(const u32 *framebuffers)
|
|
||||||
{
|
|
||||||
*GPU_PDC0(0x68) = framebuffers[0];
|
|
||||||
*GPU_PDC0(0x6C) = framebuffers[1];
|
|
||||||
*GPU_PDC0(0x94) = framebuffers[2];
|
|
||||||
*GPU_PDC0(0x98) = framebuffers[3];
|
|
||||||
*GPU_PDC1(0x68) = framebuffers[4];
|
|
||||||
*GPU_PDC1(0x6C) = framebuffers[5];
|
|
||||||
*GPU_PDC0(0x78) = 0;
|
|
||||||
*GPU_PDC1(0x78) = 0;
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
void GPU_SetFramebufferMode(u32 screen, u8 mode)
|
|
||||||
{
|
|
||||||
u32 stride, cfg;
|
|
||||||
vu32 *fbcfg_reg, *fbstr_reg;
|
|
||||||
|
|
||||||
mode &= 7;
|
|
||||||
screen &= 1;
|
|
||||||
cfg = PDC_FIXSTRIP | mode;
|
|
||||||
if (screen) {
|
|
||||||
fbcfg_reg = GPU_PDC1(0x70);
|
|
||||||
fbstr_reg = GPU_PDC1(0x90);
|
|
||||||
} else {
|
|
||||||
fbcfg_reg = GPU_PDC0(0x70);
|
|
||||||
fbstr_reg = GPU_PDC0(0x90);
|
|
||||||
cfg |= PDC_MAINSCREEN;
|
|
||||||
}
|
|
||||||
|
|
||||||
switch(mode) {
|
|
||||||
case PDC_RGBA8:
|
|
||||||
stride = 960;
|
|
||||||
break;
|
|
||||||
case PDC_RGB24:
|
|
||||||
stride = 720;
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
stride = 480;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
*fbcfg_reg = cfg;
|
|
||||||
*fbstr_reg = stride;
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
void GPU_Init(void)
|
|
||||||
{
|
|
||||||
LCD_Initialize(0x20);
|
|
||||||
|
|
||||||
if (*GPU_CNT != 0x1007F) {
|
|
||||||
*GPU_CNT = 0x1007F;
|
|
||||||
*GPU_PDC0(0x00) = 0x000001C2;
|
|
||||||
*GPU_PDC0(0x04) = 0x000000D1;
|
|
||||||
*GPU_PDC0(0x08) = 0x000001C1;
|
|
||||||
*GPU_PDC0(0x0C) = 0x000001C1;
|
|
||||||
*GPU_PDC0(0x10) = 0x00000000;
|
|
||||||
*GPU_PDC0(0x14) = 0x000000CF;
|
|
||||||
*GPU_PDC0(0x18) = 0x000000D1;
|
|
||||||
*GPU_PDC0(0x1C) = 0x01C501C1;
|
|
||||||
*GPU_PDC0(0x20) = 0x00010000;
|
|
||||||
*GPU_PDC0(0x24) = 0x0000019D;
|
|
||||||
*GPU_PDC0(0x28) = 0x00000002;
|
|
||||||
*GPU_PDC0(0x2C) = 0x00000192;
|
|
||||||
*GPU_PDC0(0x30) = 0x00000192;
|
|
||||||
*GPU_PDC0(0x34) = 0x00000192;
|
|
||||||
*GPU_PDC0(0x38) = 0x00000001;
|
|
||||||
*GPU_PDC0(0x3C) = 0x00000002;
|
|
||||||
*GPU_PDC0(0x40) = 0x01960192;
|
|
||||||
*GPU_PDC0(0x44) = 0x00000000;
|
|
||||||
*GPU_PDC0(0x48) = 0x00000000;
|
|
||||||
*GPU_PDC0(0x5C) = 0x00F00190;
|
|
||||||
*GPU_PDC0(0x60) = 0x01C100D1;
|
|
||||||
*GPU_PDC0(0x64) = 0x01920002;
|
|
||||||
*GPU_PDC0(0x68) = VRAM_START;
|
|
||||||
*GPU_PDC0(0x6C) = VRAM_START;
|
|
||||||
*GPU_PDC0(0x70) = 0x00080340;
|
|
||||||
*GPU_PDC0(0x74) = 0x00010501;
|
|
||||||
*GPU_PDC0(0x78) = 0x00000000;
|
|
||||||
*GPU_PDC0(0x90) = 0x000003C0;
|
|
||||||
*GPU_PDC0(0x94) = VRAM_START;
|
|
||||||
*GPU_PDC0(0x98) = VRAM_START;
|
|
||||||
*GPU_PDC0(0x9C) = 0x00000000;
|
|
||||||
|
|
||||||
for (u32 i=0; i<256; i++)
|
|
||||||
*GPU_PDC0(0x84) = 0x10101 * i;
|
|
||||||
|
|
||||||
*GPU_PDC1(0x00) = 0x000001C2;
|
|
||||||
*GPU_PDC1(0x04) = 0x000000D1;
|
|
||||||
*GPU_PDC1(0x08) = 0x000001C1;
|
|
||||||
*GPU_PDC1(0x0C) = 0x000001C1;
|
|
||||||
*GPU_PDC1(0x10) = 0x000000CD;
|
|
||||||
*GPU_PDC1(0x14) = 0x000000CF;
|
|
||||||
*GPU_PDC1(0x18) = 0x000000D1;
|
|
||||||
*GPU_PDC1(0x1C) = 0x01C501C1;
|
|
||||||
*GPU_PDC1(0x20) = 0x00010000;
|
|
||||||
*GPU_PDC1(0x24) = 0x0000019D;
|
|
||||||
*GPU_PDC1(0x28) = 0x00000052;
|
|
||||||
*GPU_PDC1(0x2C) = 0x00000192;
|
|
||||||
*GPU_PDC1(0x30) = 0x00000192;
|
|
||||||
*GPU_PDC1(0x34) = 0x0000004F;
|
|
||||||
*GPU_PDC1(0x38) = 0x00000050;
|
|
||||||
*GPU_PDC1(0x3C) = 0x00000052;
|
|
||||||
*GPU_PDC1(0x40) = 0x01980194;
|
|
||||||
*GPU_PDC1(0x44) = 0x00000000;
|
|
||||||
*GPU_PDC1(0x48) = 0x00000011;
|
|
||||||
*GPU_PDC1(0x5C) = 0x00F00140;
|
|
||||||
*GPU_PDC1(0x60) = 0x01C100d1;
|
|
||||||
*GPU_PDC1(0x64) = 0x01920052;
|
|
||||||
*GPU_PDC1(0x68) = VRAM_START;
|
|
||||||
*GPU_PDC1(0x6C) = VRAM_START;
|
|
||||||
*GPU_PDC1(0x70) = 0x00080300;
|
|
||||||
*GPU_PDC1(0x74) = 0x00010501;
|
|
||||||
*GPU_PDC1(0x78) = 0x00000000;
|
|
||||||
*GPU_PDC1(0x90) = 0x000003C0;
|
|
||||||
*GPU_PDC1(0x9C) = 0x00000000;
|
|
||||||
|
|
||||||
for (u32 i=0; i<256; i++)
|
|
||||||
*GPU_PDC1(0x84) = 0x10101 * i;
|
|
||||||
}
|
|
||||||
return;
|
|
||||||
}
|
|
@ -1,47 +0,0 @@
|
|||||||
#pragma once
|
|
||||||
#include <types.h>
|
|
||||||
|
|
||||||
#define GPU_ADDR(x) ((x)>>3)
|
|
||||||
#define GPU_BOX(w,h) ((w) | (h)<<16)
|
|
||||||
|
|
||||||
#define GPU_CNT ((vu32*)(0x10141200))
|
|
||||||
|
|
||||||
|
|
||||||
#define LCD_CFG(x) ((vu32*)(0x10202000 + (x)))
|
|
||||||
void LCD_SetBrightness(u32 screen, u8 brightness);
|
|
||||||
void LCD_Deinitialize(void);
|
|
||||||
|
|
||||||
#define GPU_PSC0(x) ((vu32*)(0x10400010 + (x)))
|
|
||||||
#define GPU_PSC1(x) ((vu32*)(0x10400020 + (x)))
|
|
||||||
|
|
||||||
#define PSC_SADDR (0x00)
|
|
||||||
#define PSC_EADDR (0x04)
|
|
||||||
#define PSC_FILL (0x08)
|
|
||||||
#define PSC_CNT (0x0C)
|
|
||||||
|
|
||||||
#define PSC_START (BIT(0))
|
|
||||||
#define PSC_DONE (BIT(1))
|
|
||||||
#define PSC_32BIT (2<<8)
|
|
||||||
#define PSC_24BIT (1<<8)
|
|
||||||
#define PSC_16BIT (0<<8)
|
|
||||||
|
|
||||||
void GPU_PSCWait(void);
|
|
||||||
void GPU_PSCFill(u32 start, u32 end, u32 fv);
|
|
||||||
|
|
||||||
|
|
||||||
#define GPU_PDC0(x) ((vu32*)(0x10400400 + (x)))
|
|
||||||
#define GPU_PDC1(x) ((vu32*)(0x10400500 + (x)))
|
|
||||||
|
|
||||||
#define PDC_RGBA8 (0<<0)
|
|
||||||
#define PDC_RGB24 (1<<0)
|
|
||||||
#define PDC_RGB565 (2<<0)
|
|
||||||
#define PDC_RGB5A1 (3<<0)
|
|
||||||
#define PDC_RGBA4 (4<<0)
|
|
||||||
|
|
||||||
#define PDC_PARALLAX (BIT(5))
|
|
||||||
#define PDC_MAINSCREEN (BIT(6))
|
|
||||||
#define PDC_FIXSTRIP (BIT(7))
|
|
||||||
|
|
||||||
void GPU_SetFramebuffers(const u32 *framebuffers);
|
|
||||||
void GPU_SetFramebufferMode(u32 screen, u8 mode);
|
|
||||||
void GPU_Init();
|
|
146
arm11/source/hw/codec.c
Executable file
146
arm11/source/hw/codec.c
Executable file
@ -0,0 +1,146 @@
|
|||||||
|
// Somewhat based on xerpi's CODEC driver for Linux
|
||||||
|
/*
|
||||||
|
* This file is part of GodMode9
|
||||||
|
* Copyright (C) 2017 Sergi Granell, Paul LaMendola
|
||||||
|
* Copyright (C) 2019 Wolfvak
|
||||||
|
*
|
||||||
|
* This program is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 2 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <common.h>
|
||||||
|
#include <types.h>
|
||||||
|
|
||||||
|
#include <hid_map.h>
|
||||||
|
|
||||||
|
#include "hw/codec.h"
|
||||||
|
#include <spi.h>
|
||||||
|
|
||||||
|
#define CPAD_THRESH_X (750)
|
||||||
|
#define CPAD_THRESH_Y (150)
|
||||||
|
|
||||||
|
/* SPI stuff */
|
||||||
|
static void CODEC_WriteRead(u32 *txb, u8 txl, u32 *rxb, u8 rxl)
|
||||||
|
{
|
||||||
|
SPI_XferInfo xfers[2];
|
||||||
|
|
||||||
|
xfers[0].buf = txb;
|
||||||
|
xfers[0].len = txl;
|
||||||
|
xfers[0].read = false;
|
||||||
|
|
||||||
|
xfers[1].buf = rxb;
|
||||||
|
xfers[1].len = rxl;
|
||||||
|
xfers[1].read = true;
|
||||||
|
|
||||||
|
SPI_DoXfer(SPI_DEV_CODEC, xfers, 2, true);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void CODEC_RegSelect(u8 reg)
|
||||||
|
{
|
||||||
|
SPI_XferInfo xfer;
|
||||||
|
u32 cmd;
|
||||||
|
|
||||||
|
cmd = reg << 8;
|
||||||
|
|
||||||
|
xfer.buf = &cmd;
|
||||||
|
xfer.len = 2;
|
||||||
|
xfer.read = false;
|
||||||
|
|
||||||
|
SPI_DoXfer(SPI_DEV_CODEC, &xfer, 1, true);
|
||||||
|
}
|
||||||
|
|
||||||
|
static u8 CODEC_RegRead(u8 reg)
|
||||||
|
{
|
||||||
|
u32 cmd, ret;
|
||||||
|
cmd = (reg << 1) | 1;
|
||||||
|
CODEC_WriteRead(&cmd, 1, &ret, 1);
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
static void CODEC_RegReadBuf(u8 reg, u32 *out, u8 size)
|
||||||
|
{
|
||||||
|
u32 cmd = (reg << 1) | 1;
|
||||||
|
CODEC_WriteRead(&cmd, 1, out, size);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void CODEC_RegWrite(u8 reg, u8 val)
|
||||||
|
{
|
||||||
|
SPI_XferInfo xfer;
|
||||||
|
u32 cmd;
|
||||||
|
|
||||||
|
cmd = (val << 8) | (reg << 1);
|
||||||
|
|
||||||
|
xfer.buf = &cmd;
|
||||||
|
xfer.len = 2;
|
||||||
|
xfer.read = false;
|
||||||
|
|
||||||
|
SPI_DoXfer(SPI_DEV_CODEC, &xfer, 1, true);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void CODEC_RegMask(u8 reg, u8 mask0, u8 mask1)
|
||||||
|
{
|
||||||
|
CODEC_RegWrite(reg, (CODEC_RegRead(reg) & ~mask1) | (mask0 & mask1));
|
||||||
|
}
|
||||||
|
|
||||||
|
// elder god magic
|
||||||
|
void CODEC_Init(void)
|
||||||
|
{
|
||||||
|
CODEC_RegSelect(0x67);
|
||||||
|
CODEC_RegWrite(0x24, 0x98);
|
||||||
|
CODEC_RegWrite(0x26, 0x00);
|
||||||
|
CODEC_RegWrite(0x25, 0x43);
|
||||||
|
CODEC_RegWrite(0x24, 0x18);
|
||||||
|
CODEC_RegWrite(0x17, 0x43);
|
||||||
|
CODEC_RegWrite(0x19, 0x69);
|
||||||
|
CODEC_RegWrite(0x1B, 0x80);
|
||||||
|
CODEC_RegWrite(0x27, 0x11);
|
||||||
|
CODEC_RegWrite(0x26, 0xEC);
|
||||||
|
CODEC_RegWrite(0x24, 0x18);
|
||||||
|
CODEC_RegWrite(0x25, 0x53);
|
||||||
|
|
||||||
|
CODEC_RegMask(0x26, 0x80, 0x80);
|
||||||
|
CODEC_RegMask(0x24, 0x00, 0x80);
|
||||||
|
CODEC_RegMask(0x25, 0x10, 0x3C);
|
||||||
|
}
|
||||||
|
|
||||||
|
void CODEC_GetRawData(u32 *buffer)
|
||||||
|
{
|
||||||
|
CODEC_RegSelect(0xFB);
|
||||||
|
CODEC_RegReadBuf(1, buffer, 0x34);
|
||||||
|
}
|
||||||
|
|
||||||
|
void CODEC_Get(CODEC_Input *input)
|
||||||
|
{
|
||||||
|
u32 raw_data_buf[0x34 / 4];
|
||||||
|
u8 *raw_data = (u8*)raw_data_buf;
|
||||||
|
s16 cpad_x, cpad_y;
|
||||||
|
bool ts_pressed;
|
||||||
|
|
||||||
|
CODEC_GetRawData(raw_data_buf);
|
||||||
|
|
||||||
|
cpad_x = ((raw_data[0x24] << 8 | raw_data[0x25]) & 0xFFF) - 2048;
|
||||||
|
cpad_y = ((raw_data[0x14] << 8 | raw_data[0x15]) & 0xFFF) - 2048;
|
||||||
|
|
||||||
|
// X axis is inverted
|
||||||
|
input->cpad_x = (abs(cpad_x) > CPAD_THRESH_X) ? -cpad_x : 0;
|
||||||
|
input->cpad_y = (abs(cpad_y) > CPAD_THRESH_Y) ? cpad_y : 0;
|
||||||
|
|
||||||
|
ts_pressed = !(raw_data[0] & BIT(4));
|
||||||
|
if (ts_pressed) {
|
||||||
|
input->ts_x = (raw_data[0] << 8) | raw_data[1];
|
||||||
|
input->ts_y = (raw_data[10] << 8) | raw_data[11];
|
||||||
|
} else {
|
||||||
|
input->ts_x = 0xFFFF;
|
||||||
|
input->ts_y = 0xFFFF;
|
||||||
|
}
|
||||||
|
}
|
32
arm11/source/hw/codec.h
Executable file
32
arm11/source/hw/codec.h
Executable file
@ -0,0 +1,32 @@
|
|||||||
|
/*
|
||||||
|
* This file is part of GodMode9
|
||||||
|
* Copyright (C) 2017 Sergi Granell, Paul LaMendola
|
||||||
|
* Copyright (C) 2019 Wolfvak
|
||||||
|
*
|
||||||
|
* This program is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 2 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <types.h>
|
||||||
|
|
||||||
|
typedef struct {
|
||||||
|
s16 cpad_x, cpad_y;
|
||||||
|
u16 ts_x, ts_y;
|
||||||
|
} CODEC_Input;
|
||||||
|
|
||||||
|
void CODEC_Init(void);
|
||||||
|
|
||||||
|
void CODEC_GetRawData(u32 *buffer);
|
||||||
|
void CODEC_Get(CODEC_Input *input);
|
34
arm11/source/hw/gpio.h
Executable file
34
arm11/source/hw/gpio.h
Executable file
@ -0,0 +1,34 @@
|
|||||||
|
/*
|
||||||
|
* This file is part of GodMode9
|
||||||
|
* Copyright (C) 2017 derrek, profi200
|
||||||
|
* Copyright (C) 2019 Wolfvak
|
||||||
|
*
|
||||||
|
* This program is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <types.h>
|
||||||
|
|
||||||
|
#define REG_GPIO ((vu16*)(0x10100000 + 0x47000))
|
||||||
|
|
||||||
|
static inline void GPIO_setBit(u16 reg, u8 bitNum)
|
||||||
|
{
|
||||||
|
REG_GPIO[reg] |= 1u<<bitNum;
|
||||||
|
}
|
||||||
|
|
||||||
|
static inline void GPIO_clearBit(u16 reg, u8 bitNum)
|
||||||
|
{
|
||||||
|
REG_GPIO[reg] &= ~(1u<<bitNum);
|
||||||
|
}
|
304
arm11/source/hw/gpulcd.c
Normal file
304
arm11/source/hw/gpulcd.c
Normal file
@ -0,0 +1,304 @@
|
|||||||
|
/*
|
||||||
|
* This file is part of GodMode9
|
||||||
|
* Copyright (C) 2017-2019 Wolfvak
|
||||||
|
*
|
||||||
|
* This program is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 2 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <common.h>
|
||||||
|
#include <types.h>
|
||||||
|
#include <vram.h>
|
||||||
|
#include <arm.h>
|
||||||
|
|
||||||
|
#include "arm/timer.h"
|
||||||
|
|
||||||
|
#include "hw/i2c.h"
|
||||||
|
#include "hw/mcu.h"
|
||||||
|
#include "hw/gpulcd.h"
|
||||||
|
|
||||||
|
#include "system/event.h"
|
||||||
|
|
||||||
|
static struct
|
||||||
|
{
|
||||||
|
u16 lcdIds; // Bits 0-7 top screen, 8-15 bottom screen.
|
||||||
|
bool lcdIdsRead;
|
||||||
|
u8 lcdPower; // 1 = on. Bit 4 top light, bit 2 bottom light, bit 0 LCDs.
|
||||||
|
u8 lcdLights[2]; // LCD backlight brightness. Top, bottom.
|
||||||
|
u32 framebufs[2]; // For each screen
|
||||||
|
u8 doubleBuf[2]; // Top, bottom, 1 = enable.
|
||||||
|
u16 strides[2]; // Top, bottom
|
||||||
|
u32 formats[2]; // Top, bottom
|
||||||
|
} g_gfxState = {0};
|
||||||
|
|
||||||
|
static void setupDisplayController(u8 lcd);
|
||||||
|
static void resetLcdsMaybe(void);
|
||||||
|
static void waitLcdsReady(void);
|
||||||
|
|
||||||
|
static u32 gxModeWidth(unsigned c) {
|
||||||
|
switch(c) {
|
||||||
|
case 0: return 4;
|
||||||
|
case 1: return 3;
|
||||||
|
default: return 2;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
unsigned GFX_init(GfxFbFmt mode)
|
||||||
|
{
|
||||||
|
unsigned err = 0;
|
||||||
|
|
||||||
|
REG_CFG11_GPUPROT = 0;
|
||||||
|
|
||||||
|
// Reset
|
||||||
|
REG_PDN_GPU_CNT = PDN_GPU_CNT_CLK_E;
|
||||||
|
ARM_WaitCycles(12);
|
||||||
|
REG_PDN_GPU_CNT = PDN_GPU_CNT_CLK_E | PDN_GPU_CNT_RST_ALL;
|
||||||
|
REG_GX_GPU_CLK = 0x100;
|
||||||
|
REG_GX_PSC_VRAM = 0;
|
||||||
|
REG_GX_PSC_FILL0_CNT = 0;
|
||||||
|
REG_GX_PSC_FILL1_CNT = 0;
|
||||||
|
REG_GX_PPF_CNT = 0;
|
||||||
|
|
||||||
|
// LCD framebuffer setup.
|
||||||
|
|
||||||
|
g_gfxState.strides[0] = 240 * gxModeWidth(mode);
|
||||||
|
g_gfxState.strides[1] = 240 * gxModeWidth(mode);
|
||||||
|
|
||||||
|
g_gfxState.framebufs[0] = VRAM_TOP_LA;
|
||||||
|
g_gfxState.framebufs[1] = VRAM_BOT_A;
|
||||||
|
|
||||||
|
g_gfxState.formats[0] = mode | BIT(6) | BIT(9);
|
||||||
|
g_gfxState.formats[1] = mode | BIT(9);
|
||||||
|
|
||||||
|
setupDisplayController(0);
|
||||||
|
setupDisplayController(1);
|
||||||
|
REG_LCD_PDC0_SWAP = 0; // Select framebuf 0.
|
||||||
|
REG_LCD_PDC1_SWAP = 0;
|
||||||
|
REG_LCD_PDC0_CNT = PDC_CNT_OUT_E | PDC_CNT_I_MASK_ERR | PDC_CNT_I_MASK_H | PDC_CNT_E; // Start
|
||||||
|
REG_LCD_PDC1_CNT = PDC_CNT_OUT_E | PDC_CNT_I_MASK_ERR | PDC_CNT_I_MASK_H | PDC_CNT_E;
|
||||||
|
|
||||||
|
// LCD reg setup.
|
||||||
|
REG_LCD_ABL0_FILL = 1u<<24; // Force blackscreen
|
||||||
|
REG_LCD_ABL1_FILL = 1u<<24; // Force blackscreen
|
||||||
|
REG_LCD_PARALLAX_CNT = 0;
|
||||||
|
REG_LCD_PARALLAX_PWM = 0xA390A39;
|
||||||
|
REG_LCD_RST = 0;
|
||||||
|
REG_LCD_UNK00C = 0x10001;
|
||||||
|
|
||||||
|
// Clear used VRAM
|
||||||
|
REG_GX_PSC_FILL0_S_ADDR = VRAM_TOP_LA >> 3;
|
||||||
|
REG_GX_PSC_FILL0_E_ADDR = VRAM_END >> 3;
|
||||||
|
REG_GX_PSC_FILL0_VAL = 0;
|
||||||
|
REG_GX_PSC_FILL0_CNT = BIT(9) | BIT(0);
|
||||||
|
|
||||||
|
// Backlight and other stuff.
|
||||||
|
REG_LCD_ABL0_LIGHT = 0;
|
||||||
|
REG_LCD_ABL0_CNT = 0;
|
||||||
|
REG_LCD_ABL0_LIGHT_PWM = 0;
|
||||||
|
REG_LCD_ABL1_LIGHT = 0;
|
||||||
|
REG_LCD_ABL1_CNT = 0;
|
||||||
|
REG_LCD_ABL1_LIGHT_PWM = 0;
|
||||||
|
|
||||||
|
REG_LCD_RST = 1;
|
||||||
|
REG_LCD_UNK00C = 0;
|
||||||
|
TIMER_WaitMS(10);
|
||||||
|
resetLcdsMaybe();
|
||||||
|
MCU_controlLCDPower(2u); // Power on LCDs.
|
||||||
|
if(eventWait(getEventMCU(), 0x3Fu<<24, 0x3Fu<<24) != 2u<<24) __builtin_trap();
|
||||||
|
|
||||||
|
waitLcdsReady();
|
||||||
|
REG_LCD_ABL0_LIGHT_PWM = 0x1023E;
|
||||||
|
REG_LCD_ABL1_LIGHT_PWM = 0x1023E;
|
||||||
|
MCU_controlLCDPower(0x28u); // Power on backlights.
|
||||||
|
if(eventWait(getEventMCU(), 0x3Fu<<24, 0x3Fu<<24) != 0x28u<<24) __builtin_trap();
|
||||||
|
g_gfxState.lcdPower = 0x15; // All on.
|
||||||
|
|
||||||
|
// Make sure the fills finished.
|
||||||
|
REG_LCD_ABL0_FILL = 0;
|
||||||
|
REG_LCD_ABL1_FILL = 0;
|
||||||
|
|
||||||
|
// GPU stuff.
|
||||||
|
REG_GX_GPU_CLK = 0x70100;
|
||||||
|
*((vu32*)0x10400050) = 0x22221200;
|
||||||
|
*((vu32*)0x10400054) = 0xFF2;
|
||||||
|
|
||||||
|
GFX_setBrightness(0x80, 0x80);
|
||||||
|
|
||||||
|
return err;
|
||||||
|
}
|
||||||
|
|
||||||
|
static u16 getLcdIds(void)
|
||||||
|
{
|
||||||
|
u16 ids;
|
||||||
|
|
||||||
|
if(!g_gfxState.lcdIdsRead)
|
||||||
|
{
|
||||||
|
g_gfxState.lcdIdsRead = true;
|
||||||
|
|
||||||
|
u16 top, bot;
|
||||||
|
I2C_writeReg(I2C_DEV_LCD0, 0x40, 0xFF);
|
||||||
|
I2C_readRegBuf(I2C_DEV_LCD0, 0x40, (u8*)&top, 2);
|
||||||
|
I2C_writeReg(I2C_DEV_LCD1, 0x40, 0xFF);
|
||||||
|
I2C_readRegBuf(I2C_DEV_LCD1, 0x40, (u8*)&bot, 2);
|
||||||
|
|
||||||
|
ids = top>>8;
|
||||||
|
ids |= bot & 0xFF00u;
|
||||||
|
g_gfxState.lcdIds = ids;
|
||||||
|
}
|
||||||
|
else ids = g_gfxState.lcdIds;
|
||||||
|
|
||||||
|
return ids;
|
||||||
|
}
|
||||||
|
|
||||||
|
static void resetLcdsMaybe(void)
|
||||||
|
{
|
||||||
|
const u16 ids = getLcdIds();
|
||||||
|
|
||||||
|
// Top screen
|
||||||
|
if(ids & 0xFFu) I2C_writeReg(I2C_DEV_LCD0, 0xFE, 0xAA);
|
||||||
|
else
|
||||||
|
{
|
||||||
|
I2C_writeReg(I2C_DEV_LCD0, 0x11, 0x10);
|
||||||
|
I2C_writeReg(I2C_DEV_LCD0, 0x50, 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Bottom screen
|
||||||
|
if(ids>>8) I2C_writeReg(I2C_DEV_LCD1, 0xFE, 0xAA);
|
||||||
|
else I2C_writeReg(I2C_DEV_LCD1, 0x11, 0x10);
|
||||||
|
|
||||||
|
I2C_writeReg(I2C_DEV_LCD0, 0x60, 0);
|
||||||
|
I2C_writeReg(I2C_DEV_LCD1, 0x60, 0);
|
||||||
|
I2C_writeReg(I2C_DEV_LCD0, 1, 0x10);
|
||||||
|
I2C_writeReg(I2C_DEV_LCD1, 1, 0x10);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void waitLcdsReady(void)
|
||||||
|
{
|
||||||
|
const u16 ids = getLcdIds();
|
||||||
|
|
||||||
|
if((ids & 0xFFu) == 0 || (ids>>8) == 0) // Unknown LCD?
|
||||||
|
{
|
||||||
|
TIMER_WaitMS(150);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
u32 i = 0;
|
||||||
|
do
|
||||||
|
{
|
||||||
|
u16 top, bot;
|
||||||
|
I2C_writeReg(I2C_DEV_LCD0, 0x40, 0x62);
|
||||||
|
I2C_readRegBuf(I2C_DEV_LCD0, 0x40, (u8*)&top, 2);
|
||||||
|
I2C_writeReg(I2C_DEV_LCD1, 0x40, 0x62);
|
||||||
|
I2C_readRegBuf(I2C_DEV_LCD1, 0x40, (u8*)&bot, 2);
|
||||||
|
|
||||||
|
if((top>>8) == 1 && (bot>>8) == 1) break;
|
||||||
|
|
||||||
|
TIMER_WaitMS(33);
|
||||||
|
} while(i++ < 10);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void GFX_powerOnBacklights(GfxBlight mask)
|
||||||
|
{
|
||||||
|
g_gfxState.lcdPower |= mask;
|
||||||
|
|
||||||
|
mask <<= 1;
|
||||||
|
MCU_controlLCDPower(mask); // Power on backlights.
|
||||||
|
eventWait(getEventMCU(), 0x3F<<24, 0x3F<<24);
|
||||||
|
/*if(mcuEventWait(0x3Fu<<24) != (u32)mask<<24)
|
||||||
|
__builtin_trap();*/
|
||||||
|
}
|
||||||
|
|
||||||
|
void GFX_powerOffBacklights(GfxBlight mask)
|
||||||
|
{
|
||||||
|
g_gfxState.lcdPower &= ~mask;
|
||||||
|
|
||||||
|
MCU_controlLCDPower(mask); // Power off backlights.
|
||||||
|
eventWait(getEventMCU(), 0x3F<<24, 0x3F<<24);
|
||||||
|
/*if(mcuEventWait(0x3Fu<<24) != (u32)mask<<24)
|
||||||
|
__builtin_trap();*/
|
||||||
|
}
|
||||||
|
|
||||||
|
u8 GFX_getBrightness(void)
|
||||||
|
{
|
||||||
|
return REG_LCD_ABL0_LIGHT;
|
||||||
|
}
|
||||||
|
|
||||||
|
void GFX_setBrightness(u8 top, u8 bot)
|
||||||
|
{
|
||||||
|
g_gfxState.lcdLights[0] = top;
|
||||||
|
g_gfxState.lcdLights[1] = bot;
|
||||||
|
REG_LCD_ABL0_LIGHT = top;
|
||||||
|
REG_LCD_ABL1_LIGHT = bot;
|
||||||
|
}
|
||||||
|
|
||||||
|
void GFX_setForceBlack(bool top, bool bot)
|
||||||
|
{
|
||||||
|
REG_LCD_ABL0_FILL = (u32)top<<24; // Force blackscreen
|
||||||
|
REG_LCD_ABL1_FILL = (u32)bot<<24; // Force blackscreen
|
||||||
|
}
|
||||||
|
|
||||||
|
static void setupDisplayController(u8 lcd)
|
||||||
|
{
|
||||||
|
if(lcd > 1) return;
|
||||||
|
|
||||||
|
static const u32 displayCfgs[2][24] =
|
||||||
|
{
|
||||||
|
{
|
||||||
|
// PDC0 regs 0-0x4C.
|
||||||
|
450, 209, 449, 449, 0, 207, 209, 453<<16 | 449,
|
||||||
|
1<<16 | 0, 413, 2, 402, 402, 402, 1, 2,
|
||||||
|
406<<16 | 402, 0, 0<<4 | 0, 0<<16 | 0xFF<<8 | 0,
|
||||||
|
// PDC0 regs 0x5C-0x64.
|
||||||
|
400<<16 | 240, // Width and height.
|
||||||
|
449<<16 | 209,
|
||||||
|
402<<16 | 2,
|
||||||
|
// PDC0 reg 0x9C.
|
||||||
|
0<<16 | 0
|
||||||
|
},
|
||||||
|
{
|
||||||
|
// PDC1 regs 0-0x4C.
|
||||||
|
450, 209, 449, 449, 205, 207, 209, 453<<16 | 449,
|
||||||
|
1<<16 | 0, 413, 82, 402, 402, 79, 80, 82,
|
||||||
|
408<<16 | 404, 0, 1<<4 | 1, 0<<16 | 0<<8 | 0xFF,
|
||||||
|
// PDC1 regs 0x5C-0x64.
|
||||||
|
320<<16 | 240, // Width and height.
|
||||||
|
449<<16 | 209,
|
||||||
|
402<<16 | 82,
|
||||||
|
// PDC1 reg 0x9C.
|
||||||
|
0<<16 | 0
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
const u32 *const cfg = displayCfgs[lcd];
|
||||||
|
vu32 *const regs = (vu32*)(GX_REGS_BASE + 0x400 + (0x100u * lcd));
|
||||||
|
|
||||||
|
for (unsigned i = 0; i < 0x50/4; i++)
|
||||||
|
regs[i] = cfg[i];
|
||||||
|
|
||||||
|
for (unsigned i = 0; i < 0xC/4; i++)
|
||||||
|
regs[23 + i] = cfg[20 + i];
|
||||||
|
|
||||||
|
regs[36] = g_gfxState.strides[lcd]; // PDC reg 0x90 stride.
|
||||||
|
regs[39] = cfg[23]; // PDC reg 0x9C.
|
||||||
|
|
||||||
|
// PDC regs 0x68, 0x6C, 0x94, 0x98 and 0x70.
|
||||||
|
regs[26] = g_gfxState.framebufs[lcd]; // Framebuffer A first address.
|
||||||
|
regs[27] = g_gfxState.framebufs[lcd]; // Framebuffer A second address.
|
||||||
|
regs[37] = g_gfxState.framebufs[lcd]; // Framebuffer B first address.
|
||||||
|
regs[38] = g_gfxState.framebufs[lcd]; // Framebuffer B second address.
|
||||||
|
regs[28] = g_gfxState.formats[lcd]; // Format
|
||||||
|
|
||||||
|
regs[32] = 0; // Gamma table index 0.
|
||||||
|
for(u32 i = 0; i < 256; i++) regs[33] = 0x10101u * i;
|
||||||
|
}
|
186
arm11/source/hw/gpulcd.h
Normal file
186
arm11/source/hw/gpulcd.h
Normal file
@ -0,0 +1,186 @@
|
|||||||
|
/*
|
||||||
|
* This file is part of GodMode9
|
||||||
|
* Copyright (C) 2017-2019 Wolfvak
|
||||||
|
*
|
||||||
|
* This program is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 2 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
#include <types.h>
|
||||||
|
|
||||||
|
#define VBLANK_INTERRUPT (0x2A)
|
||||||
|
|
||||||
|
enum
|
||||||
|
{
|
||||||
|
PDN_GPU_CNT_RST_REGS = 1u, // And more?
|
||||||
|
PDN_GPU_CNT_RST_PSC = 1u<<1, // ?
|
||||||
|
PDN_GPU_CNT_RST_GEOSHADER = 1u<<2, // ?
|
||||||
|
PDN_GPU_CNT_RST_RASTERIZER = 1u<<3, // ?
|
||||||
|
PDN_GPU_CNT_RST_PPF = 1u<<4,
|
||||||
|
PDN_GPU_CNT_RST_PDC = 1u<<5, // ?
|
||||||
|
PDN_GPU_CNT_RST_PDC2 = 1u<<6, // Maybe pixel pipeline or so?
|
||||||
|
|
||||||
|
PDN_GPU_CNT_RST_ALL = (PDN_GPU_CNT_RST_PDC2<<1) - 1
|
||||||
|
};
|
||||||
|
|
||||||
|
typedef enum
|
||||||
|
{
|
||||||
|
GFX_RGBA8 = 0, ///< RGBA8. (4 bytes)
|
||||||
|
GFX_BGR8 = 1, ///< BGR8. (3 bytes)
|
||||||
|
GFX_RGB565 = 2, ///< RGB565. (2 bytes)
|
||||||
|
GFX_RGB5A1 = 3, ///< RGB5A1. (2 bytes)
|
||||||
|
GFX_RGBA4 = 4 ///< RGBA4. (2 bytes)
|
||||||
|
} GfxFbFmt;
|
||||||
|
|
||||||
|
typedef enum
|
||||||
|
{
|
||||||
|
GFX_EVENT_PSC0 = 0u,
|
||||||
|
GFX_EVENT_PSC1 = 1u,
|
||||||
|
GFX_EVENT_PDC0 = 2u,
|
||||||
|
GFX_EVENT_PDC1 = 3u,
|
||||||
|
GFX_EVENT_PPF = 4u,
|
||||||
|
GFX_EVENT_P3D = 5u
|
||||||
|
} GfxEvent;
|
||||||
|
|
||||||
|
typedef enum
|
||||||
|
{
|
||||||
|
GFX_BLIGHT_BOT = 1u<<2,
|
||||||
|
GFX_BLIGHT_TOP = 1u<<4,
|
||||||
|
GFX_BLIGHT_BOTH = GFX_BLIGHT_TOP | GFX_BLIGHT_BOT
|
||||||
|
} GfxBlight;
|
||||||
|
|
||||||
|
#define REG_CFG11_GPUPROT *((vu16*)(0x10140140))
|
||||||
|
#define REG_PDN_GPU_CNT *((vu32*)(0x10141200))
|
||||||
|
#define PDN_GPU_CNT_CLK_E (1u<<16)
|
||||||
|
#define PDN_VRAM_CNT_CLK_E (1u)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
#define GX_REGS_BASE (0x10400000)
|
||||||
|
#define REG_GX_GPU_CLK *((vu32*)(GX_REGS_BASE + 0x0004)) // ?
|
||||||
|
|
||||||
|
// PSC (memory fill) regs.
|
||||||
|
#define REG_GX_PSC_FILL0_S_ADDR *((vu32*)(GX_REGS_BASE + 0x0010)) // Start address
|
||||||
|
#define REG_GX_PSC_FILL0_E_ADDR *((vu32*)(GX_REGS_BASE + 0x0014)) // End address
|
||||||
|
#define REG_GX_PSC_FILL0_VAL *((vu32*)(GX_REGS_BASE + 0x0018)) // Fill value
|
||||||
|
#define REG_GX_PSC_FILL0_CNT *((vu32*)(GX_REGS_BASE + 0x001C))
|
||||||
|
|
||||||
|
#define REG_GX_PSC_FILL1_S_ADDR *((vu32*)(GX_REGS_BASE + 0x0020))
|
||||||
|
#define REG_GX_PSC_FILL1_E_ADDR *((vu32*)(GX_REGS_BASE + 0x0024))
|
||||||
|
#define REG_GX_PSC_FILL1_VAL *((vu32*)(GX_REGS_BASE + 0x0028))
|
||||||
|
#define REG_GX_PSC_FILL1_CNT *((vu32*)(GX_REGS_BASE + 0x002C))
|
||||||
|
|
||||||
|
#define REG_GX_PSC_VRAM *((vu32*)(GX_REGS_BASE + 0x0030)) // gsp mudule only changes bit 8-11.
|
||||||
|
#define REG_GX_PSC_STAT *((vu32*)(GX_REGS_BASE + 0x0034))
|
||||||
|
|
||||||
|
// PDC0/1 regs see lcd.h.
|
||||||
|
|
||||||
|
// PPF (transfer engine) regs.
|
||||||
|
#define REG_GX_PPF_IN_ADDR *((vu32*)(GX_REGS_BASE + 0x0C00))
|
||||||
|
#define REG_GX_PPF_OUT_ADDR *((vu32*)(GX_REGS_BASE + 0x0C04))
|
||||||
|
#define REG_GX_PPF_DT_OUTDIM *((vu32*)(GX_REGS_BASE + 0x0C08)) // Display transfer output dimensions.
|
||||||
|
#define REG_GX_PPF_DT_INDIM *((vu32*)(GX_REGS_BASE + 0x0C0C)) // Display transfer input dimensions.
|
||||||
|
#define REG_GX_PPF_FlAGS *((vu32*)(GX_REGS_BASE + 0x0C10))
|
||||||
|
#define REG_GX_PPF_UNK14 *((vu32*)(GX_REGS_BASE + 0x0C14)) // Transfer interval?
|
||||||
|
#define REG_GX_PPF_CNT *((vu32*)(GX_REGS_BASE + 0x0C18))
|
||||||
|
#define REG_GX_PPF_IRQ_POS *((vu32*)(GX_REGS_BASE + 0x0C1C)) // ?
|
||||||
|
#define REG_GX_PPF_LEN *((vu32*)(GX_REGS_BASE + 0x0C20)) // Texture copy size in bytes.
|
||||||
|
#define REG_GX_PPF_TC_INDIM *((vu32*)(GX_REGS_BASE + 0x0C24)) // Texture copy input width and gap in 16 byte units.
|
||||||
|
#define REG_GX_PPF_TC_OUTDIM *((vu32*)(GX_REGS_BASE + 0x0C28)) // Texture copy output width and gap in 16 byte units.
|
||||||
|
|
||||||
|
// P3D (GPU internal) regs. See gpu_regs.h.
|
||||||
|
#define REG_GX_P3D(reg) *((vu32*)(GX_REGS_BASE + 0x1000 + ((reg) * 4)))
|
||||||
|
|
||||||
|
// LCD/ABL regs.
|
||||||
|
#define LCD_REGS_BASE (0x10202000)
|
||||||
|
#define REG_LCD_PARALLAX_CNT *((vu32*)(LCD_REGS_BASE + 0x000)) // Controls PWM for the parallax barrier?
|
||||||
|
#define REG_LCD_PARALLAX_PWM *((vu32*)(LCD_REGS_BASE + 0x004)) // Frequency/other PWM stuff maybe?
|
||||||
|
#define REG_LCD_UNK00C *((vu32*)(LCD_REGS_BASE + 0x00C)) // Wtf is "FIX"?
|
||||||
|
#define REG_LCD_RST *((vu32*)(LCD_REGS_BASE + 0x014)) // Reset active low.
|
||||||
|
|
||||||
|
#define REG_LCD_ABL0_CNT *((vu32*)(LCD_REGS_BASE + 0x200)) // Bit 0 enables ABL aka power saving mode.
|
||||||
|
#define REG_LCD_ABL0_FILL *((vu32*)(LCD_REGS_BASE + 0x204))
|
||||||
|
#define REG_LCD_ABL0_LIGHT *((vu32*)(LCD_REGS_BASE + 0x240))
|
||||||
|
#define REG_LCD_ABL0_LIGHT_PWM *((vu32*)(LCD_REGS_BASE + 0x244))
|
||||||
|
|
||||||
|
#define REG_LCD_ABL1_CNT *((vu32*)(LCD_REGS_BASE + 0xA00)) // Bit 0 enables ABL aka power saving mode.
|
||||||
|
#define REG_LCD_ABL1_FILL *((vu32*)(LCD_REGS_BASE + 0xA04))
|
||||||
|
#define REG_LCD_ABL1_LIGHT *((vu32*)(LCD_REGS_BASE + 0xA40))
|
||||||
|
#define REG_LCD_ABL1_LIGHT_PWM *((vu32*)(LCD_REGS_BASE + 0xA44))
|
||||||
|
|
||||||
|
|
||||||
|
// Technically these regs belong in gx.h but they are used for LCD configuration so...
|
||||||
|
// Pitfall warning: The 3DS LCDs are physically rotated 90° CCW.
|
||||||
|
|
||||||
|
// PDC0 (top screen display controller) regs.
|
||||||
|
#define REG_LCD_PDC0_HTOTAL *((vu32*)(GX_REGS_BASE + 0x400))
|
||||||
|
#define REG_LCD_PDC0_VTOTAL *((vu32*)(GX_REGS_BASE + 0x424))
|
||||||
|
#define REG_LCD_PDC0_HPOS *((const vu32*)(GX_REGS_BASE + 0x450))
|
||||||
|
#define REG_LCD_PDC0_VPOS *((const vu32*)(GX_REGS_BASE + 0x454))
|
||||||
|
#define REG_LCD_PDC0_FB_A1 *((vu32*)(GX_REGS_BASE + 0x468))
|
||||||
|
#define REG_LCD_PDC0_FB_A2 *((vu32*)(GX_REGS_BASE + 0x46C))
|
||||||
|
#define REG_LCD_PDC0_FMT *((vu32*)(GX_REGS_BASE + 0x470))
|
||||||
|
#define REG_LCD_PDC0_CNT *((vu32*)(GX_REGS_BASE + 0x474))
|
||||||
|
#define REG_LCD_PDC0_SWAP *((vu32*)(GX_REGS_BASE + 0x478))
|
||||||
|
#define REG_LCD_PDC0_STAT *((const vu32*)(GX_REGS_BASE + 0x47C))
|
||||||
|
#define REG_LCD_PDC0_GTBL_IDX *((vu32*)(GX_REGS_BASE + 0x480)) // Gamma table index.
|
||||||
|
#define REG_LCD_PDC0_GTBL_FIFO *((vu32*)(GX_REGS_BASE + 0x484)) // Gamma table FIFO.
|
||||||
|
#define REG_LCD_PDC0_STRIDE *((vu32*)(GX_REGS_BASE + 0x490))
|
||||||
|
#define REG_LCD_PDC0_FB_B1 *((vu32*)(GX_REGS_BASE + 0x494))
|
||||||
|
#define REG_LCD_PDC0_FB_B2 *((vu32*)(GX_REGS_BASE + 0x498))
|
||||||
|
|
||||||
|
// PDC1 (bottom screen display controller) regs.
|
||||||
|
#define REG_LCD_PDC1_HTOTAL *((vu32*)(GX_REGS_BASE + 0x500))
|
||||||
|
#define REG_LCD_PDC1_VTOTAL *((vu32*)(GX_REGS_BASE + 0x524))
|
||||||
|
#define REG_LCD_PDC1_HPOS *((const vu32*)(GX_REGS_BASE + 0x550))
|
||||||
|
#define REG_LCD_PDC1_VPOS *((const vu32*)(GX_REGS_BASE + 0x554))
|
||||||
|
#define REG_LCD_PDC1_FB_A1 *((vu32*)(GX_REGS_BASE + 0x568))
|
||||||
|
#define REG_LCD_PDC1_FB_A2 *((vu32*)(GX_REGS_BASE + 0x56C))
|
||||||
|
#define REG_LCD_PDC1_FMT *((vu32*)(GX_REGS_BASE + 0x570))
|
||||||
|
#define REG_LCD_PDC1_CNT *((vu32*)(GX_REGS_BASE + 0x574))
|
||||||
|
#define REG_LCD_PDC1_SWAP *((vu32*)(GX_REGS_BASE + 0x578))
|
||||||
|
#define REG_LCD_PDC1_STAT *((const vu32*)(GX_REGS_BASE + 0x57C))
|
||||||
|
#define REG_LCD_PDC1_GTBL_IDX *((vu32*)(GX_REGS_BASE + 0x580)) // Gamma table index.
|
||||||
|
#define REG_LCD_PDC1_GTBL_FIFO *((vu32*)(GX_REGS_BASE + 0x584)) // Gamma table FIFO.
|
||||||
|
#define REG_LCD_PDC1_STRIDE *((vu32*)(GX_REGS_BASE + 0x590))
|
||||||
|
#define REG_LCD_PDC1_FB_B1 *((vu32*)(GX_REGS_BASE + 0x594))
|
||||||
|
#define REG_LCD_PDC1_FB_B2 *((vu32*)(GX_REGS_BASE + 0x598))
|
||||||
|
|
||||||
|
|
||||||
|
// REG_LCD_PDC_CNT
|
||||||
|
#define PDC_CNT_E (1u)
|
||||||
|
#define PDC_CNT_I_MASK_H (1u<<8) // Disables H(Blank?) IRQs.
|
||||||
|
#define PDC_CNT_I_MASK_V (1u<<9) // Disables VBlank IRQs.
|
||||||
|
#define PDC_CNT_I_MASK_ERR (1u<<10) // Disables error IRQs. What kind of errors?
|
||||||
|
#define PDC_CNT_OUT_E (1u<<16) // Output enable?
|
||||||
|
|
||||||
|
// REG_LCD_PDC_SWAP
|
||||||
|
// Masks
|
||||||
|
#define PDC_SWAP_NEXT (1u) // Next framebuffer.
|
||||||
|
#define PDC_SWAP_CUR (1u<<4) // Currently displaying framebuffer?
|
||||||
|
// Bits
|
||||||
|
#define PDC_SWAP_RST_FIFO (1u<<8) // Which FIFO?
|
||||||
|
#define PDC_SWAP_I_H (1u<<16) // H(Blank?) IRQ bit.
|
||||||
|
#define PDC_SWAP_I_V (1u<<17) // VBlank IRQ bit.
|
||||||
|
#define PDC_SWAP_I_ERR (1u<<18) // Error IRQ bit?
|
||||||
|
#define PDC_SWAP_I_ALL (PDC_SWAP_I_ERR | PDC_SWAP_I_V | PDC_SWAP_I_H)
|
||||||
|
|
||||||
|
|
||||||
|
unsigned GFX_init(GfxFbFmt mode);
|
||||||
|
void GFX_setForceBlack(bool top, bool bot);
|
||||||
|
void GFX_powerOnBacklights(GfxBlight mask);
|
||||||
|
void GFX_powerOffBacklights(GfxBlight mask);
|
||||||
|
|
||||||
|
u8 GFX_getBrightness(void);
|
||||||
|
void GFX_setBrightness(u8 top, u8 bot);
|
65
arm11/source/hw/hid.c
Executable file
65
arm11/source/hw/hid.c
Executable file
@ -0,0 +1,65 @@
|
|||||||
|
/*
|
||||||
|
* This file is part of GodMode9
|
||||||
|
* Copyright (C) 2019 Wolfvak
|
||||||
|
*
|
||||||
|
* This program is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 2 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <common.h>
|
||||||
|
#include <types.h>
|
||||||
|
#include <hid_map.h>
|
||||||
|
|
||||||
|
#include "hw/codec.h"
|
||||||
|
#include "hw/hid.h"
|
||||||
|
#include "hw/mcu.h"
|
||||||
|
|
||||||
|
#define REG_HID (~(*(vu16*)(0x10146000)) & BUTTON_ANY)
|
||||||
|
|
||||||
|
static u32 HID_ConvertCPAD(s16 cpad_x, s16 cpad_y)
|
||||||
|
{
|
||||||
|
u32 ret = 0;
|
||||||
|
|
||||||
|
if (cpad_x > 0) {
|
||||||
|
ret |= BUTTON_RIGHT;
|
||||||
|
} else if (cpad_x < 0) {
|
||||||
|
ret |= BUTTON_LEFT;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (cpad_y > 0) {
|
||||||
|
ret |= BUTTON_UP;
|
||||||
|
} else if (cpad_y < 0) {
|
||||||
|
ret |= BUTTON_DOWN;
|
||||||
|
}
|
||||||
|
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
u64 HID_GetState(void)
|
||||||
|
{
|
||||||
|
CODEC_Input codec;
|
||||||
|
u64 ret = 0;
|
||||||
|
|
||||||
|
CODEC_Get(&codec);
|
||||||
|
|
||||||
|
ret = REG_HID | mcuGetSpecialHID();
|
||||||
|
if (!(ret & BUTTON_ARROW))
|
||||||
|
ret |= HID_ConvertCPAD(codec.cpad_x, codec.cpad_y);
|
||||||
|
|
||||||
|
if (codec.ts_x <= 0xFFF)
|
||||||
|
ret |= BUTTON_TOUCH;
|
||||||
|
|
||||||
|
ret |= (((u64)codec.ts_x << 16) | (u64)codec.ts_y) << 32;
|
||||||
|
|
||||||
|
return ret;
|
||||||
|
}
|
24
arm11/source/hw/hid.h
Executable file
24
arm11/source/hw/hid.h
Executable file
@ -0,0 +1,24 @@
|
|||||||
|
/*
|
||||||
|
* This file is part of GodMode9
|
||||||
|
* Copyright (C) 2019 Wolfvak
|
||||||
|
*
|
||||||
|
* This program is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 2 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <types.h>
|
||||||
|
#include <hid_map.h>
|
||||||
|
|
||||||
|
u64 HID_GetState(void);
|
214
arm11/source/hw/i2c.c
Normal file
214
arm11/source/hw/i2c.c
Normal file
@ -0,0 +1,214 @@
|
|||||||
|
/*
|
||||||
|
* This file is part of fastboot 3DS
|
||||||
|
* Copyright (C) 2017 derrek, profi200
|
||||||
|
*
|
||||||
|
* This program is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <stdbool.h>
|
||||||
|
|
||||||
|
#include <types.h>
|
||||||
|
#include "hw/i2c.h"
|
||||||
|
|
||||||
|
|
||||||
|
#define I2C1_REGS_BASE (0x10161000)
|
||||||
|
|
||||||
|
#define I2C2_REGS_BASE (0x10144000)
|
||||||
|
|
||||||
|
#define I2C3_REGS_BASE (0x10148000)
|
||||||
|
|
||||||
|
|
||||||
|
typedef struct
|
||||||
|
{
|
||||||
|
vu8 REG_I2C_DATA;
|
||||||
|
vu8 REG_I2C_CNT;
|
||||||
|
vu16 REG_I2C_CNTEX;
|
||||||
|
vu16 REG_I2C_SCL;
|
||||||
|
} I2cRegs;
|
||||||
|
|
||||||
|
static const struct
|
||||||
|
{
|
||||||
|
u8 busId;
|
||||||
|
u8 devAddr;
|
||||||
|
} i2cDevTable[] =
|
||||||
|
{
|
||||||
|
{0, 0x4A},
|
||||||
|
{0, 0x7A},
|
||||||
|
{0, 0x78},
|
||||||
|
{1, 0x4A},
|
||||||
|
{1, 0x78},
|
||||||
|
{1, 0x2C},
|
||||||
|
{1, 0x2E},
|
||||||
|
{1, 0x40},
|
||||||
|
{1, 0x44},
|
||||||
|
{2, 0xD6},
|
||||||
|
{2, 0xD0},
|
||||||
|
{2, 0xD2},
|
||||||
|
{2, 0xA4},
|
||||||
|
{2, 0x9A},
|
||||||
|
{2, 0xA0},
|
||||||
|
{1, 0xEE},
|
||||||
|
{0, 0x40},
|
||||||
|
{2, 0x54}
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
static void i2cWaitBusy(I2cRegs *const regs)
|
||||||
|
{
|
||||||
|
while(regs->REG_I2C_CNT & I2C_ENABLE);
|
||||||
|
}
|
||||||
|
|
||||||
|
static I2cRegs* i2cGetBusRegsBase(u8 busId)
|
||||||
|
{
|
||||||
|
I2cRegs *base;
|
||||||
|
switch(busId)
|
||||||
|
{
|
||||||
|
case 0:
|
||||||
|
base = (I2cRegs*)I2C1_REGS_BASE;
|
||||||
|
break;
|
||||||
|
case 1:
|
||||||
|
base = (I2cRegs*)I2C2_REGS_BASE;
|
||||||
|
break;
|
||||||
|
case 2:
|
||||||
|
base = (I2cRegs*)I2C3_REGS_BASE;
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
base = NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
return base;
|
||||||
|
}
|
||||||
|
|
||||||
|
void I2C_init(void)
|
||||||
|
{
|
||||||
|
I2cRegs *regs = i2cGetBusRegsBase(0); // Bus 1
|
||||||
|
i2cWaitBusy(regs);
|
||||||
|
regs->REG_I2C_CNTEX = 2; // ?
|
||||||
|
regs->REG_I2C_SCL = 1280; // ?
|
||||||
|
|
||||||
|
regs = i2cGetBusRegsBase(1); // Bus 2
|
||||||
|
i2cWaitBusy(regs);
|
||||||
|
regs->REG_I2C_CNTEX = 2; // ?
|
||||||
|
regs->REG_I2C_SCL = 1280; // ?
|
||||||
|
|
||||||
|
regs = i2cGetBusRegsBase(2); // Bus 3
|
||||||
|
i2cWaitBusy(regs);
|
||||||
|
regs->REG_I2C_CNTEX = 2; // ?
|
||||||
|
regs->REG_I2C_SCL = 1280; // ?
|
||||||
|
}
|
||||||
|
|
||||||
|
static bool i2cStartTransfer(int devId, u8 regAddr, bool read, I2cRegs *const regs)
|
||||||
|
{
|
||||||
|
const u8 devAddr = i2cDevTable[devId].devAddr;
|
||||||
|
|
||||||
|
|
||||||
|
u32 i = 0;
|
||||||
|
for(; i < 8; i++)
|
||||||
|
{
|
||||||
|
i2cWaitBusy(regs);
|
||||||
|
|
||||||
|
// Select device and start.
|
||||||
|
regs->REG_I2C_DATA = devAddr;
|
||||||
|
regs->REG_I2C_CNT = I2C_ENABLE | I2C_IRQ_ENABLE | I2C_START;
|
||||||
|
i2cWaitBusy(regs);
|
||||||
|
if(!I2C_GET_ACK(regs->REG_I2C_CNT)) // If ack flag is 0 it failed.
|
||||||
|
{
|
||||||
|
regs->REG_I2C_CNT = I2C_ENABLE | I2C_IRQ_ENABLE | I2C_ERROR | I2C_STOP;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Select register and change direction to write.
|
||||||
|
regs->REG_I2C_DATA = regAddr;
|
||||||
|
regs->REG_I2C_CNT = I2C_ENABLE | I2C_IRQ_ENABLE | I2C_DIRE_WRITE;
|
||||||
|
i2cWaitBusy(regs);
|
||||||
|
if(!I2C_GET_ACK(regs->REG_I2C_CNT)) // If ack flag is 0 it failed.
|
||||||
|
{
|
||||||
|
regs->REG_I2C_CNT = I2C_ENABLE | I2C_IRQ_ENABLE | I2C_ERROR | I2C_STOP;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Select device in read mode for read transfer.
|
||||||
|
if(read)
|
||||||
|
{
|
||||||
|
regs->REG_I2C_DATA = devAddr | 1u; // Set bit 0 for read.
|
||||||
|
regs->REG_I2C_CNT = I2C_ENABLE | I2C_IRQ_ENABLE | I2C_START;
|
||||||
|
i2cWaitBusy(regs);
|
||||||
|
if(!I2C_GET_ACK(regs->REG_I2C_CNT)) // If ack flag is 0 it failed.
|
||||||
|
{
|
||||||
|
regs->REG_I2C_CNT = I2C_ENABLE | I2C_IRQ_ENABLE | I2C_ERROR | I2C_STOP;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(i < 8) return true;
|
||||||
|
else return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool I2C_readRegBuf(int devId, u8 regAddr, u8 *out, u32 size)
|
||||||
|
{
|
||||||
|
const u8 busId = i2cDevTable[devId].busId;
|
||||||
|
I2cRegs *const regs = i2cGetBusRegsBase(busId);
|
||||||
|
|
||||||
|
|
||||||
|
if(!i2cStartTransfer(devId, regAddr, true, regs)) return false;
|
||||||
|
|
||||||
|
while(--size)
|
||||||
|
{
|
||||||
|
regs->REG_I2C_CNT = I2C_ENABLE | I2C_IRQ_ENABLE | I2C_DIRE_READ | I2C_ACK;
|
||||||
|
i2cWaitBusy(regs);
|
||||||
|
*out++ = regs->REG_I2C_DATA;
|
||||||
|
}
|
||||||
|
|
||||||
|
regs->REG_I2C_CNT = I2C_ENABLE | I2C_IRQ_ENABLE | I2C_DIRE_READ | I2C_STOP;
|
||||||
|
i2cWaitBusy(regs);
|
||||||
|
*out = regs->REG_I2C_DATA; // Last byte
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool I2C_writeRegBuf(int devId, u8 regAddr, const u8 *in, u32 size)
|
||||||
|
{
|
||||||
|
const u8 busId = i2cDevTable[devId].busId;
|
||||||
|
I2cRegs *const regs = i2cGetBusRegsBase(busId);
|
||||||
|
|
||||||
|
|
||||||
|
if(!i2cStartTransfer(devId, regAddr, false, regs)) return false;
|
||||||
|
|
||||||
|
while(--size)
|
||||||
|
{
|
||||||
|
regs->REG_I2C_DATA = *in++;
|
||||||
|
regs->REG_I2C_CNT = I2C_ENABLE | I2C_IRQ_ENABLE | I2C_DIRE_WRITE;
|
||||||
|
i2cWaitBusy(regs);
|
||||||
|
if(!I2C_GET_ACK(regs->REG_I2C_CNT)) // If ack flag is 0 it failed.
|
||||||
|
{
|
||||||
|
regs->REG_I2C_CNT = I2C_ENABLE | I2C_IRQ_ENABLE | I2C_ERROR | I2C_STOP;
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
regs->REG_I2C_DATA = *in;
|
||||||
|
regs->REG_I2C_CNT = I2C_ENABLE | I2C_IRQ_ENABLE | I2C_DIRE_WRITE | I2C_STOP;
|
||||||
|
i2cWaitBusy(regs);
|
||||||
|
if(!I2C_GET_ACK(regs->REG_I2C_CNT)) // If ack flag is 0 it failed.
|
||||||
|
{
|
||||||
|
regs->REG_I2C_CNT = I2C_ENABLE | I2C_IRQ_ENABLE | I2C_ERROR | I2C_STOP;
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
77
arm11/source/hw/i2c.h
Normal file
77
arm11/source/hw/i2c.h
Normal file
@ -0,0 +1,77 @@
|
|||||||
|
/*
|
||||||
|
* This file is part of fastboot 3DS
|
||||||
|
* Copyright (C) 2017 derrek, profi200
|
||||||
|
*
|
||||||
|
* This program is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <stdbool.h>
|
||||||
|
#include <types.h>
|
||||||
|
|
||||||
|
|
||||||
|
#define I2C_STOP (1u)
|
||||||
|
#define I2C_START (1u<<1)
|
||||||
|
#define I2C_ERROR (1u<<2)
|
||||||
|
#define I2C_ACK (1u<<4)
|
||||||
|
#define I2C_DIRE_WRITE (0u)
|
||||||
|
#define I2C_DIRE_READ (1u<<5)
|
||||||
|
#define I2C_IRQ_ENABLE (1u<<6)
|
||||||
|
#define I2C_ENABLE (1u<<7)
|
||||||
|
|
||||||
|
#define I2C_DEV_LCD0 5
|
||||||
|
#define I2C_DEV_LCD1 6
|
||||||
|
|
||||||
|
#define I2C_GET_ACK(reg) ((bool)((reg)>>4 & 1u))
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Initializes the I2C buses. Call this only once.
|
||||||
|
*/
|
||||||
|
void I2C_init(void);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Reads data from a I2C register to a buffer.
|
||||||
|
*
|
||||||
|
* @param[in] devId The device ID. Use the enum above.
|
||||||
|
* @param[in] regAddr The register address.
|
||||||
|
* @param out The output buffer pointer.
|
||||||
|
* @param[in] size The read size.
|
||||||
|
*
|
||||||
|
* @return Returns true on success and false on failure.
|
||||||
|
*/
|
||||||
|
bool I2C_readRegBuf(int devId, u8 regAddr, u8 *out, u32 size);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Writes a buffer to a I2C register.
|
||||||
|
*
|
||||||
|
* @param[in] devId The device ID. Use the enum above.
|
||||||
|
* @param[in] regAddr The register address.
|
||||||
|
* @param[in] in The input buffer pointer.
|
||||||
|
* @param[in] size The write size.
|
||||||
|
*
|
||||||
|
* @return Returns true on success and false on failure.
|
||||||
|
*/
|
||||||
|
bool I2C_writeRegBuf(int devId, u8 regAddr, const u8 *in, u32 size);
|
||||||
|
|
||||||
|
static inline u8 I2C_readReg(int devId, u8 regAddr) {
|
||||||
|
u8 v;
|
||||||
|
I2C_readRegBuf(devId, regAddr, &v, 1);
|
||||||
|
return v;
|
||||||
|
}
|
||||||
|
|
||||||
|
static inline void I2C_writeReg(int devId, u8 regAddr, u8 v) {
|
||||||
|
I2C_writeRegBuf(devId, regAddr, &v, 1);
|
||||||
|
}
|
198
arm11/source/hw/mcu.c
Executable file
198
arm11/source/hw/mcu.c
Executable file
@ -0,0 +1,198 @@
|
|||||||
|
/*
|
||||||
|
* This file is part of GodMode9
|
||||||
|
* Copyright (C) 2019 Wolfvak
|
||||||
|
*
|
||||||
|
* This program is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 2 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <hid_map.h>
|
||||||
|
#include <types.h>
|
||||||
|
#include <arm.h>
|
||||||
|
|
||||||
|
#include <stdatomic.h>
|
||||||
|
|
||||||
|
#include "common.h"
|
||||||
|
|
||||||
|
#include "arm/timer.h"
|
||||||
|
|
||||||
|
#include "hw/gpio.h"
|
||||||
|
#include "hw/gpulcd.h"
|
||||||
|
#include "hw/mcu.h"
|
||||||
|
|
||||||
|
#include "system/event.h"
|
||||||
|
|
||||||
|
#define MCUEV_HID_MASK ( \
|
||||||
|
MCUEV_HID_PWR_DOWN | MCUEV_HID_PWR_HOLD | \
|
||||||
|
MCUEV_HID_HOME_DOWN | MCUEV_HID_HOME_UP | MCUEV_HID_WIFI_SWITCH)
|
||||||
|
|
||||||
|
enum {
|
||||||
|
MCUREG_VOLUME_SLIDER = 0x09,
|
||||||
|
|
||||||
|
MCUREG_BATTERY_LEVEL = 0x0B,
|
||||||
|
MCUREG_CONSOLE_STATE = 0x0F,
|
||||||
|
|
||||||
|
MCUREG_INT_MASK = 0x10,
|
||||||
|
MCUREG_INT_EN = 0x18,
|
||||||
|
|
||||||
|
MCUREG_LCD_STATE = 0x22,
|
||||||
|
|
||||||
|
MCUREG_LED_WIFI = 0x2A,
|
||||||
|
MCUREG_LED_CAMERA = 0x2B,
|
||||||
|
MCUREG_LED_SLIDER = 0x2C,
|
||||||
|
MCUREG_LED_STATUS = 0x2D,
|
||||||
|
|
||||||
|
MCUREG_RTC = 0x30,
|
||||||
|
};
|
||||||
|
|
||||||
|
typedef struct {
|
||||||
|
u8 delay;
|
||||||
|
u8 smoothing;
|
||||||
|
u8 loop_delay;
|
||||||
|
u8 unk;
|
||||||
|
u32 red[8];
|
||||||
|
u32 green[8];
|
||||||
|
u32 blue[8];
|
||||||
|
} PACKED_STRUCT mcuStatusLED;
|
||||||
|
|
||||||
|
static u8 volumeSliderValue;
|
||||||
|
static u32 shellState;
|
||||||
|
static _Atomic(u32) pendingEvents;
|
||||||
|
|
||||||
|
static void mcuEventUpdate(void)
|
||||||
|
{
|
||||||
|
u32 mask;
|
||||||
|
|
||||||
|
// lazily update the mask on each test attempt
|
||||||
|
if (!getEventIRQ()->test(MCU_INTERRUPT, true))
|
||||||
|
return;
|
||||||
|
|
||||||
|
// reading the pending mask automagically acknowledges
|
||||||
|
// the interrupts so all of them must be processed in one go
|
||||||
|
mcuReadRegBuf(MCUREG_INT_MASK, (u8*)&mask, sizeof(mask));
|
||||||
|
|
||||||
|
if (mask & MCUEV_HID_VOLUME_SLIDER)
|
||||||
|
volumeSliderValue = mcuReadReg(MCUREG_VOLUME_SLIDER);
|
||||||
|
|
||||||
|
if (mask & MCUEV_HID_SHELL_OPEN) {
|
||||||
|
mcuResetLEDs();
|
||||||
|
shellState = SHELL_OPEN;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (mask & MCUEV_HID_SHELL_CLOSE) {
|
||||||
|
shellState = SHELL_CLOSED;
|
||||||
|
}
|
||||||
|
|
||||||
|
atomic_fetch_or(&pendingEvents, mask);
|
||||||
|
}
|
||||||
|
|
||||||
|
u8 mcuGetVolumeSlider(void)
|
||||||
|
{
|
||||||
|
mcuEventUpdate();
|
||||||
|
return volumeSliderValue;
|
||||||
|
}
|
||||||
|
|
||||||
|
u32 mcuGetSpecialHID(void)
|
||||||
|
{
|
||||||
|
u32 ret = 0, pend = getEventMCU()->test(MCUEV_HID_MASK, MCUEV_HID_MASK);
|
||||||
|
|
||||||
|
// hopefully gets unrolled
|
||||||
|
if (pend & (MCUEV_HID_PWR_DOWN | MCUEV_HID_PWR_HOLD))
|
||||||
|
ret |= BUTTON_POWER;
|
||||||
|
if (pend & MCUEV_HID_HOME_DOWN)
|
||||||
|
ret |= BUTTON_HOME;
|
||||||
|
if (pend & MCUEV_HID_HOME_UP)
|
||||||
|
ret &= ~BUTTON_HOME;
|
||||||
|
return ret | shellState;
|
||||||
|
}
|
||||||
|
|
||||||
|
void mcuSetStatusLED(u32 period_ms, u32 color)
|
||||||
|
{
|
||||||
|
u32 r, g, b, delay;
|
||||||
|
mcuStatusLED ledState;
|
||||||
|
|
||||||
|
delay = clamp((period_ms * 0x200) / 1000, 1, 0xFF);
|
||||||
|
|
||||||
|
ledState.delay = delay;
|
||||||
|
ledState.smoothing = delay;
|
||||||
|
ledState.loop_delay = 0x10;
|
||||||
|
ledState.unk = 0;
|
||||||
|
|
||||||
|
// all colors look like 0x00ZZ00ZZ
|
||||||
|
// in order to alternate between
|
||||||
|
// LED "off" and the wanted color
|
||||||
|
r = (color >> 16) & 0xFF;
|
||||||
|
r |= r << 16;
|
||||||
|
for (int i = 0; i < 8; i++)
|
||||||
|
ledState.red[i] = r;
|
||||||
|
|
||||||
|
g = (color >> 8) & 0xFF;
|
||||||
|
g |= g << 16;
|
||||||
|
for (int i = 0; i < 8; i++)
|
||||||
|
ledState.green[i] = g;
|
||||||
|
|
||||||
|
b = color & 0xFF;
|
||||||
|
b |= b << 16;
|
||||||
|
for (int i = 0; i < 8; i++)
|
||||||
|
ledState.blue[i] = b;
|
||||||
|
|
||||||
|
mcuWriteRegBuf(MCUREG_LED_STATUS, (const u8*)&ledState, sizeof(ledState));
|
||||||
|
}
|
||||||
|
|
||||||
|
void mcuResetLEDs(void)
|
||||||
|
{
|
||||||
|
mcuWriteReg(MCUREG_LED_WIFI, 0);
|
||||||
|
mcuWriteReg(MCUREG_LED_CAMERA, 0);
|
||||||
|
mcuWriteReg(MCUREG_LED_SLIDER, 0);
|
||||||
|
mcuSetStatusLED(0, 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
void mcuReset(void)
|
||||||
|
{
|
||||||
|
u32 intmask = 0;
|
||||||
|
|
||||||
|
atomic_init(&pendingEvents, 0);
|
||||||
|
|
||||||
|
// set register mask and clear any pending registers
|
||||||
|
mcuWriteRegBuf(MCUREG_INT_EN, (const u8*)&intmask, sizeof(intmask));
|
||||||
|
mcuReadRegBuf(MCUREG_INT_MASK, (u8*)&intmask, sizeof(intmask));
|
||||||
|
|
||||||
|
mcuResetLEDs();
|
||||||
|
|
||||||
|
volumeSliderValue = mcuReadReg(MCUREG_VOLUME_SLIDER);
|
||||||
|
shellState = SHELL_OPEN;
|
||||||
|
// assume the shell is always open on boot
|
||||||
|
// knowing the average 3DS user, there will be plenty
|
||||||
|
// of laughs when this comes back to bite us in the rear
|
||||||
|
|
||||||
|
GPIO_setBit(19, 9);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void evReset(void) {
|
||||||
|
atomic_store(&pendingEvents, 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
static u32 evTest(u32 mask, u32 clear) {
|
||||||
|
mcuEventUpdate();
|
||||||
|
return atomic_fetch_and(&pendingEvents, ~clear) & mask;
|
||||||
|
}
|
||||||
|
|
||||||
|
static const EventInterface evMCU = {
|
||||||
|
.reset = evReset,
|
||||||
|
.test = evTest
|
||||||
|
};
|
||||||
|
|
||||||
|
const EventInterface *getEventMCU(void) {
|
||||||
|
return &evMCU;
|
||||||
|
}
|
||||||
|
|
73
arm11/source/hw/mcu.h
Executable file
73
arm11/source/hw/mcu.h
Executable file
@ -0,0 +1,73 @@
|
|||||||
|
/*
|
||||||
|
* This file is part of GodMode9
|
||||||
|
* Copyright (C) 2019 Wolfvak
|
||||||
|
*
|
||||||
|
* This program is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 2 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <types.h>
|
||||||
|
|
||||||
|
#include "arm/timer.h"
|
||||||
|
#include "hw/i2c.h"
|
||||||
|
|
||||||
|
#define MCU_INTERRUPT (0x71)
|
||||||
|
#define I2C_MCU_DEVICE (3)
|
||||||
|
|
||||||
|
enum {
|
||||||
|
MCUEV_HID_PWR_DOWN = BIT(0),
|
||||||
|
MCUEV_HID_PWR_HOLD = BIT(1),
|
||||||
|
MCUEV_HID_HOME_DOWN = BIT(2),
|
||||||
|
MCUEV_HID_HOME_UP = BIT(3),
|
||||||
|
MCUEV_HID_WIFI_SWITCH = BIT(4),
|
||||||
|
MCUEV_HID_SHELL_CLOSE = BIT(5),
|
||||||
|
MCUEV_HID_SHELL_OPEN = BIT(6),
|
||||||
|
MCUEV_HID_VOLUME_SLIDER = BIT(22),
|
||||||
|
};
|
||||||
|
|
||||||
|
u8 mcuGetVolumeSlider(void);
|
||||||
|
u32 mcuGetSpecialHID(void);
|
||||||
|
|
||||||
|
void mcuSetStatusLED(u32 period_ms, u32 color);
|
||||||
|
void mcuResetLEDs(void);
|
||||||
|
|
||||||
|
void mcuReset(void);
|
||||||
|
|
||||||
|
static inline u8 mcuReadReg(u8 addr)
|
||||||
|
{
|
||||||
|
u8 val;
|
||||||
|
I2C_readRegBuf(I2C_MCU_DEVICE, addr, &val, 1);
|
||||||
|
return val;
|
||||||
|
}
|
||||||
|
|
||||||
|
static inline bool mcuReadRegBuf(u8 addr, u8 *buf, u32 size)
|
||||||
|
{
|
||||||
|
return I2C_readRegBuf(I2C_MCU_DEVICE, addr, buf, size);
|
||||||
|
}
|
||||||
|
|
||||||
|
static inline bool mcuWriteReg(u8 addr, u8 val)
|
||||||
|
{
|
||||||
|
return I2C_writeRegBuf(I2C_MCU_DEVICE, addr, &val, 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
static inline bool mcuWriteRegBuf(u8 addr, const u8 *buf, u32 size)
|
||||||
|
{
|
||||||
|
return I2C_writeRegBuf(I2C_MCU_DEVICE, addr, buf, size);
|
||||||
|
}
|
||||||
|
|
||||||
|
static inline void MCU_controlLCDPower(u8 bits)
|
||||||
|
{
|
||||||
|
mcuWriteReg(0x22u, bits);
|
||||||
|
}
|
93
arm11/source/hw/nvram.c
Executable file
93
arm11/source/hw/nvram.c
Executable file
@ -0,0 +1,93 @@
|
|||||||
|
/*
|
||||||
|
* This file is part of GodMode9
|
||||||
|
* Copyright (C) 2019 Wolfvak
|
||||||
|
*
|
||||||
|
* This program is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 2 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <types.h>
|
||||||
|
|
||||||
|
#include <spi.h>
|
||||||
|
#include "hw/nvram.h"
|
||||||
|
|
||||||
|
// returns manuf id, memory type and size
|
||||||
|
// size = (1 << id[2]) ?
|
||||||
|
// apparently unreliable on some Sanyo chips?
|
||||||
|
#define CMD_RDID 0x9F
|
||||||
|
|
||||||
|
#define CMD_READ 0x03
|
||||||
|
#define CMD_WREN 0x06
|
||||||
|
#define CMD_WRDI 0x04
|
||||||
|
|
||||||
|
#define CMD_RDSR 0x05
|
||||||
|
|
||||||
|
#define CMD_DPD 0xB9 // deep power down
|
||||||
|
#define CMD_RDP 0xAB // release from deep power down
|
||||||
|
|
||||||
|
static u32 NVRAM_SendStatusCommand(u32 cmd, u32 width)
|
||||||
|
{
|
||||||
|
u32 ret;
|
||||||
|
SPI_XferInfo xfer[2];
|
||||||
|
|
||||||
|
xfer[0].buf = &cmd;
|
||||||
|
xfer[0].len = 1;
|
||||||
|
xfer[0].read = false;
|
||||||
|
|
||||||
|
xfer[1].buf = &ret;
|
||||||
|
xfer[1].len = width;
|
||||||
|
xfer[1].read = true;
|
||||||
|
|
||||||
|
ret = 0;
|
||||||
|
SPI_DoXfer(SPI_DEV_NVRAM, xfer, 2, true);
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
u32 NVRAM_Status(void)
|
||||||
|
{
|
||||||
|
return NVRAM_SendStatusCommand(CMD_RDSR, 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
u32 NVRAM_ReadID(void)
|
||||||
|
{
|
||||||
|
return NVRAM_SendStatusCommand(CMD_RDID, 3);
|
||||||
|
}
|
||||||
|
|
||||||
|
void NVRAM_DeepStandby(void)
|
||||||
|
{
|
||||||
|
NVRAM_SendStatusCommand(CMD_DPD, 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
void NVRAM_Wakeup(void)
|
||||||
|
{
|
||||||
|
NVRAM_SendStatusCommand(CMD_RDP, 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
void NVRAM_Read(u32 address, u32 *buffer, u32 len)
|
||||||
|
{
|
||||||
|
SPI_XferInfo xfer[2];
|
||||||
|
u32 cmd;
|
||||||
|
|
||||||
|
address &= BIT(24) - 1;
|
||||||
|
cmd = __builtin_bswap32(address) | CMD_READ;
|
||||||
|
|
||||||
|
xfer[0].buf = &cmd;
|
||||||
|
xfer[0].len = 4;
|
||||||
|
xfer[0].read = false;
|
||||||
|
|
||||||
|
xfer[1].buf = buffer;
|
||||||
|
xfer[1].len = len;
|
||||||
|
xfer[1].read = true;
|
||||||
|
|
||||||
|
SPI_DoXfer(SPI_DEV_NVRAM, xfer, 2, true);
|
||||||
|
}
|
34
arm11/source/hw/nvram.h
Executable file
34
arm11/source/hw/nvram.h
Executable file
@ -0,0 +1,34 @@
|
|||||||
|
/*
|
||||||
|
* This file is part of GodMode9
|
||||||
|
* Copyright (C) 2019 Wolfvak
|
||||||
|
*
|
||||||
|
* This program is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 2 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <types.h>
|
||||||
|
|
||||||
|
#include <spi.h>
|
||||||
|
|
||||||
|
#define NVRAM_SR_WIP BIT(0) // work in progress / busy
|
||||||
|
#define NVRAM_SR_WEL BIT(1) // write enable latch
|
||||||
|
|
||||||
|
u32 NVRAM_Status(void);
|
||||||
|
u32 NVRAM_ReadID(void);
|
||||||
|
|
||||||
|
void NVRAM_Read(u32 offset, u32 *buffer, u32 len);
|
||||||
|
|
||||||
|
void NVRAM_DeepStandby(void);
|
||||||
|
void NVRAM_Wakeup(void);
|
@ -1,46 +0,0 @@
|
|||||||
.section .text
|
|
||||||
.arm
|
|
||||||
|
|
||||||
#include <arm.h>
|
|
||||||
|
|
||||||
#define MPCORE_PMR (0x17E00000)
|
|
||||||
#define IRQ_SPURIOUS (1023)
|
|
||||||
#define IRQ_COUNT (128)
|
|
||||||
|
|
||||||
.global main_irq_handler
|
|
||||||
.type main_irq_handler, %function
|
|
||||||
main_irq_handler:
|
|
||||||
sub lr, lr, #4 @ Fix return address
|
|
||||||
srsfd sp!, #0x13 @ Store IRQ mode LR and SPSR on the SVC stack
|
|
||||||
cps #0x13 @ Switch to SVC mode
|
|
||||||
push {r0-r3, r12, lr} @ Preserve registers
|
|
||||||
|
|
||||||
1:
|
|
||||||
ldr lr, =MPCORE_PMR
|
|
||||||
ldr r0, [lr, #0x10C] @ Get pending interrupt
|
|
||||||
|
|
||||||
ldr r1, =IRQ_SPURIOUS
|
|
||||||
cmp r0, r1
|
|
||||||
beq 3f @ Spurious interrupt, no interrupts pending
|
|
||||||
|
|
||||||
cmp r0, #IRQ_COUNT
|
|
||||||
bhs 2f @ Invalid interrupt ID
|
|
||||||
|
|
||||||
ldr r12, =GIC_Handlers
|
|
||||||
ldr r12, [r12, r0, lsl #2]
|
|
||||||
cmp r12, #0
|
|
||||||
beq 2f
|
|
||||||
|
|
||||||
push {r0, r12}
|
|
||||||
blx r12
|
|
||||||
pop {r0, r12}
|
|
||||||
|
|
||||||
2:
|
|
||||||
ldr lr, =MPCORE_PMR
|
|
||||||
str r0, [lr, #0x110] @ End of interrupt
|
|
||||||
b 1b @ Check for any other pending interrupts
|
|
||||||
|
|
||||||
3:
|
|
||||||
pop {r0-r3, r12, lr} @ Restore registers
|
|
||||||
rfeia sp! @ Return From Exception
|
|
||||||
|
|
@ -1,97 +1,229 @@
|
|||||||
#include <cpu.h>
|
/*
|
||||||
#include <pxi.h>
|
* This file is part of GodMode9
|
||||||
#include <gic.h>
|
* Copyright (C) 2019 Wolfvak
|
||||||
#include <gpulcd.h>
|
*
|
||||||
#include <vram.h>
|
* This program is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 2 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <common.h>
|
||||||
#include <types.h>
|
#include <types.h>
|
||||||
|
#include <shmem.h>
|
||||||
|
#include <arm.h>
|
||||||
|
#include <pxi.h>
|
||||||
|
|
||||||
vu32 *entrypoint = (vu32*)0x1FFFFFFC;
|
#include "arm/gic.h"
|
||||||
|
|
||||||
void PXI_IRQHandler(void)
|
#include "hw/hid.h"
|
||||||
|
#include "hw/gpulcd.h"
|
||||||
|
#include "hw/i2c.h"
|
||||||
|
#include "hw/mcu.h"
|
||||||
|
#include "hw/nvram.h"
|
||||||
|
|
||||||
|
#include "system/sys.h"
|
||||||
|
#include "system/event.h"
|
||||||
|
|
||||||
|
static const u8 brightness_lvls[] = {
|
||||||
|
0x10, 0x17, 0x1E, 0x25,
|
||||||
|
0x2C, 0x34, 0x3C, 0x44,
|
||||||
|
0x4D, 0x56, 0x60, 0x6B,
|
||||||
|
0x79, 0x8C, 0xA7, 0xD2
|
||||||
|
};
|
||||||
|
|
||||||
|
#ifndef FIXED_BRIGHTNESS
|
||||||
|
static int prev_bright_lvl;
|
||||||
|
static bool auto_brightness;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
static SystemSHMEM __attribute__((section(".shared"))) sharedMem;
|
||||||
|
|
||||||
|
static void vblankUpdate(void)
|
||||||
{
|
{
|
||||||
// char pxi_buf[PXI_MAXBUFLEN] = {0};
|
if (!getEventIRQ()->test(VBLANK_INTERRUPT, true))
|
||||||
u32 pxi_args[PXI_FIFO_LEN] = {0};
|
return;
|
||||||
u8 pxi_cmd;
|
|
||||||
|
|
||||||
pxi_cmd = PXI_GetRemote();
|
#ifndef FIXED_BRIGHTNESS
|
||||||
switch (pxi_cmd) {
|
int cur_bright_lvl = (mcuGetVolumeSlider() >> 2) % countof(brightness_lvls);
|
||||||
default:
|
if ((cur_bright_lvl != prev_bright_lvl) && auto_brightness) {
|
||||||
break;
|
prev_bright_lvl = cur_bright_lvl;
|
||||||
|
u8 br = brightness_lvls[cur_bright_lvl];
|
||||||
|
GFX_setBrightness(br, br);
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
case PXI_SCREENINIT:
|
// handle shell events
|
||||||
{
|
static const u32 mcuEvShell = MCUEV_HID_SHELL_OPEN | MCUEV_HID_SHELL_CLOSE;
|
||||||
GPU_Init();
|
u32 shell = getEventMCU()->test(mcuEvShell, mcuEvShell);
|
||||||
GPU_PSCFill(VRAM_START, VRAM_END, 0);
|
if (shell & MCUEV_HID_SHELL_CLOSE) {
|
||||||
GPU_SetFramebuffers((u32[]){VRAM_TOP_LA, VRAM_TOP_LB,
|
GFX_powerOffBacklights(GFX_BLIGHT_BOTH);
|
||||||
VRAM_TOP_RA, VRAM_TOP_RB,
|
} else if (shell & MCUEV_HID_SHELL_OPEN) {
|
||||||
VRAM_BOT_A, VRAM_BOT_B});
|
GFX_powerOnBacklights(GFX_BLIGHT_BOTH);
|
||||||
|
}
|
||||||
|
|
||||||
GPU_SetFramebufferMode(0, PDC_RGB24);
|
sharedMem.hidState.full = HID_GetState();
|
||||||
GPU_SetFramebufferMode(1, PDC_RGB24);
|
|
||||||
|
|
||||||
PXI_SetRemote(PXI_BUSY);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
case PXI_BRIGHTNESS:
|
|
||||||
{
|
|
||||||
PXI_RecvArray(pxi_args, 1);
|
|
||||||
PXI_SetRemote(PXI_BUSY);
|
|
||||||
LCD_SetBrightness(0, pxi_args[0]);
|
|
||||||
LCD_SetBrightness(1, pxi_args[0]);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* New CMD template:
|
|
||||||
case CMD_ID:
|
|
||||||
{
|
|
||||||
<var declarations/assignments>
|
|
||||||
<receive args from PXI FIFO>
|
|
||||||
<if necessary, copy stuff to pxi_buf>
|
|
||||||
PXI_SetRemote(PXI_BUSY);
|
|
||||||
<execute the command>
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
}
|
|
||||||
|
|
||||||
PXI_SetRemote(PXI_READY);
|
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
vu16 *CFG11_MPCORE_CLKCNT = (vu16*)(0x10141300);
|
static u32 pxiRxUpdate(u32 *args)
|
||||||
vu16 *CFG11_SOCINFO = (vu16*)(0x10140FFC);
|
|
||||||
|
|
||||||
void main(void)
|
|
||||||
{
|
{
|
||||||
u32 entry;
|
u32 msg, lo, hi;
|
||||||
|
|
||||||
if ((*CFG11_SOCINFO & 2) && (!(*CFG11_MPCORE_CLKCNT & 1))) {
|
if (!getEventIRQ()->test(PXI_RX_INTERRUPT, true))
|
||||||
GIC_Reset();
|
return PXICMD_NONE;
|
||||||
GIC_SetIRQ(88, NULL);
|
|
||||||
CPU_EnableIRQ();
|
|
||||||
*CFG11_MPCORE_CLKCNT = 0x8001;
|
|
||||||
do {
|
|
||||||
asm("wfi\n\t");
|
|
||||||
} while(!(*CFG11_MPCORE_CLKCNT & 0x8000));
|
|
||||||
CPU_DisableIRQ();
|
|
||||||
}
|
|
||||||
|
|
||||||
PXI_Reset();
|
msg = PXI_Recv();
|
||||||
GIC_Reset();
|
lo = msg & 0xFFFF;
|
||||||
GIC_SetIRQ(IRQ_PXI_SYNC, PXI_IRQHandler);
|
hi = msg >> 16;
|
||||||
PXI_EnableIRQ();
|
|
||||||
CPU_EnableIRQ();
|
|
||||||
|
|
||||||
PXI_SetRemote(PXI_READY);
|
PXI_RecvArray(args, hi);
|
||||||
|
return lo;
|
||||||
*entrypoint = 0;
|
}
|
||||||
while((entry=*entrypoint) == 0);
|
|
||||||
|
void __attribute__((noreturn)) MainLoop(void)
|
||||||
CPU_DisableIRQ();
|
{
|
||||||
PXI_DisableIRQ();
|
bool runPxiCmdProcessor = true;
|
||||||
PXI_Reset();
|
|
||||||
GIC_Reset();
|
#ifdef FIXED_BRIGHTNESS
|
||||||
|
u8 fixed_bright_lvl = brightness_lvls[clamp(FIXED_BRIGHTNESS, 0, countof(brightness_lvls)-1)];
|
||||||
((void (*)())(entry))();
|
GFX_setBrightness(fixed_bright_lvl, fixed_bright_lvl);
|
||||||
|
#else
|
||||||
|
prev_bright_lvl = -1;
|
||||||
|
auto_brightness = true;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
// initialize state stuff
|
||||||
|
getEventIRQ()->reset();
|
||||||
|
getEventMCU()->reset();
|
||||||
|
memset(&sharedMem, 0, sizeof(sharedMem));
|
||||||
|
|
||||||
|
// configure interrupts
|
||||||
|
gicSetInterruptConfig(PXI_RX_INTERRUPT, BIT(0), GIC_PRIO0, NULL);
|
||||||
|
gicSetInterruptConfig(VBLANK_INTERRUPT, BIT(0), GIC_PRIO0, NULL);
|
||||||
|
gicSetInterruptConfig(MCU_INTERRUPT, BIT(0), GIC_PRIO0, NULL);
|
||||||
|
|
||||||
|
// enable interrupts
|
||||||
|
gicEnableInterrupt(MCU_INTERRUPT);
|
||||||
|
|
||||||
|
// perform gpu init after initializing mcu but before
|
||||||
|
// enabling the pxi system and the vblank handler
|
||||||
|
GFX_init(GFX_RGB565);
|
||||||
|
|
||||||
|
gicEnableInterrupt(PXI_RX_INTERRUPT);
|
||||||
|
gicEnableInterrupt(VBLANK_INTERRUPT);
|
||||||
|
|
||||||
|
// ARM9 won't try anything funny until this point
|
||||||
|
PXI_Barrier(PXI_BOOT_BARRIER);
|
||||||
|
|
||||||
|
// Process commands until the ARM9 tells
|
||||||
|
// us it's time to boot something else
|
||||||
|
// also handles VBlank events as needed
|
||||||
|
do {
|
||||||
|
u32 pxiCmd, pxiReply, args[PXI_MAX_ARGS];
|
||||||
|
|
||||||
|
vblankUpdate();
|
||||||
|
pxiCmd = pxiRxUpdate(args);
|
||||||
|
|
||||||
|
switch(pxiCmd) {
|
||||||
|
// ignore args and just wait until the next event
|
||||||
|
case PXICMD_NONE:
|
||||||
|
ARM_WFI();
|
||||||
|
break;
|
||||||
|
|
||||||
|
// revert to legacy boot mode
|
||||||
|
case PXICMD_LEGACY_BOOT:
|
||||||
|
runPxiCmdProcessor = false;
|
||||||
|
pxiReply = 0;
|
||||||
|
break;
|
||||||
|
|
||||||
|
// returns the shared memory address
|
||||||
|
case PXICMD_GET_SHMEM_ADDRESS:
|
||||||
|
pxiReply = (u32)&sharedMem;
|
||||||
|
break;
|
||||||
|
|
||||||
|
// takes in a single argument word and performs either an
|
||||||
|
// I2C read or write depending on the value of the top bit
|
||||||
|
case PXICMD_I2C_OP:
|
||||||
|
{
|
||||||
|
u32 devId, regAddr, size;
|
||||||
|
|
||||||
|
devId = (args[0] & 0xff);
|
||||||
|
regAddr = (args[0] >> 8) & 0xFF;
|
||||||
|
size = (args[0] >> 16) % SHMEM_BUFFER_SIZE;
|
||||||
|
|
||||||
|
if (args[0] & BIT(31)) {
|
||||||
|
pxiReply = I2C_writeRegBuf(devId, regAddr, sharedMem.dataBuffer.b, size);
|
||||||
|
} else {
|
||||||
|
pxiReply = I2C_readRegBuf(devId, regAddr, sharedMem.dataBuffer.b, size);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
// checks whether the NVRAM chip is online (not doing any work)
|
||||||
|
case PXICMD_NVRAM_ONLINE:
|
||||||
|
pxiReply = (NVRAM_Status() & NVRAM_SR_WIP) == 0;
|
||||||
|
break;
|
||||||
|
|
||||||
|
// reads data from the NVRAM chip
|
||||||
|
case PXICMD_NVRAM_READ:
|
||||||
|
NVRAM_Read(args[0], sharedMem.dataBuffer.w, args[1]);
|
||||||
|
pxiReply = 0;
|
||||||
|
break;
|
||||||
|
|
||||||
|
// sets the notification LED with the given color and period
|
||||||
|
case PXICMD_SET_NOTIFY_LED:
|
||||||
|
mcuSetStatusLED(args[0], args[1]);
|
||||||
|
pxiReply = 0;
|
||||||
|
break;
|
||||||
|
|
||||||
|
// sets the LCDs brightness (if FIXED_BRIGHTNESS is disabled)
|
||||||
|
case PXICMD_SET_BRIGHTNESS:
|
||||||
|
{
|
||||||
|
pxiReply = GFX_getBrightness();
|
||||||
|
#ifndef FIXED_BRIGHTNESS
|
||||||
|
s32 newbrightness = (s32)args[0];
|
||||||
|
if ((newbrightness > 0) && (newbrightness < 0x100)) {
|
||||||
|
GFX_setBrightness(newbrightness, newbrightness);
|
||||||
|
auto_brightness = false;
|
||||||
|
} else {
|
||||||
|
prev_bright_lvl = -1;
|
||||||
|
auto_brightness = true;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
// replies -1 on default
|
||||||
|
default:
|
||||||
|
pxiReply = 0xFFFFFFFF;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (pxiCmd != PXICMD_NONE)
|
||||||
|
PXI_Send(pxiReply); // was a command sent from the ARM9, send a response
|
||||||
|
} while(runPxiCmdProcessor);
|
||||||
|
|
||||||
|
// perform deinit in reverse order
|
||||||
|
gicDisableInterrupt(VBLANK_INTERRUPT);
|
||||||
|
gicDisableInterrupt(PXI_RX_INTERRUPT);
|
||||||
|
|
||||||
|
// unconditionally reinitialize the screens
|
||||||
|
// in RGB24 framebuffer mode
|
||||||
|
GFX_init(GFX_BGR8);
|
||||||
|
|
||||||
|
gicDisableInterrupt(MCU_INTERRUPT);
|
||||||
|
|
||||||
|
// Wait for the ARM9 to do its firmlaunch setup
|
||||||
|
PXI_Barrier(PXI_FIRMLAUNCH_BARRIER);
|
||||||
|
|
||||||
|
SYS_CoreZeroShutdown();
|
||||||
|
SYS_CoreShutdown();
|
||||||
}
|
}
|
||||||
|
26
arm11/source/system/event.h
Normal file
26
arm11/source/system/event.h
Normal file
@ -0,0 +1,26 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <types.h>
|
||||||
|
|
||||||
|
typedef struct {
|
||||||
|
void (*reset)(void);
|
||||||
|
u32 (*test)(u32 param, u32 clear);
|
||||||
|
} EventInterface;
|
||||||
|
|
||||||
|
const EventInterface *getEventIRQ(void);
|
||||||
|
const EventInterface *getEventMCU(void);
|
||||||
|
|
||||||
|
static inline void eventReset(const EventInterface *ei) {
|
||||||
|
ei->reset();
|
||||||
|
}
|
||||||
|
|
||||||
|
static inline u32 eventTest(const EventInterface *ei, u32 param, u32 clear) {
|
||||||
|
return ei->test(param, clear);
|
||||||
|
}
|
||||||
|
|
||||||
|
static inline u32 eventWait(const EventInterface *ei, u32 param, u32 clear) {
|
||||||
|
while(1) {
|
||||||
|
u32 ret = ei->test(param, clear);
|
||||||
|
if (ret) return ret;
|
||||||
|
}
|
||||||
|
}
|
35
arm11/source/system/sections.h
Executable file
35
arm11/source/system/sections.h
Executable file
@ -0,0 +1,35 @@
|
|||||||
|
/*
|
||||||
|
* This file is part of GodMode9
|
||||||
|
* Copyright (C) 2019 Wolfvak
|
||||||
|
*
|
||||||
|
* This program is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 2 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <types.h>
|
||||||
|
|
||||||
|
#define DEF_SECT_(n) extern u32 __##n##_pa, __##n##_va, __##n##_va_end;
|
||||||
|
DEF_SECT_(text)
|
||||||
|
DEF_SECT_(data)
|
||||||
|
DEF_SECT_(rodata)
|
||||||
|
DEF_SECT_(bss)
|
||||||
|
DEF_SECT_(shared)
|
||||||
|
#undef DEF_SECT_
|
||||||
|
|
||||||
|
#define SECTION_VA(n) ((u32)&__##n##_va)
|
||||||
|
#define SECTION_PA(n) ((u32)&__##n##_pa)
|
||||||
|
#define SECTION_LEN(n) (((u32)(&__##n##_va_end) - (u32)(&__##n##_va)))
|
||||||
|
|
||||||
|
#define SECTION_TRI(n) SECTION_VA(n), SECTION_PA(n), SECTION_LEN(n)
|
176
arm11/source/system/sys.c
Executable file
176
arm11/source/system/sys.c
Executable file
@ -0,0 +1,176 @@
|
|||||||
|
/*
|
||||||
|
* This file is part of GodMode9
|
||||||
|
* Copyright (C) 2019 Wolfvak
|
||||||
|
*
|
||||||
|
* This program is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 2 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <types.h>
|
||||||
|
#include <vram.h>
|
||||||
|
#include <arm.h>
|
||||||
|
#include <pxi.h>
|
||||||
|
|
||||||
|
#include "arm/gic.h"
|
||||||
|
#include "arm/mmu.h"
|
||||||
|
#include "arm/scu.h"
|
||||||
|
#include "arm/xrq.h"
|
||||||
|
|
||||||
|
#include "hw/codec.h"
|
||||||
|
#include "hw/gpulcd.h"
|
||||||
|
#include "hw/i2c.h"
|
||||||
|
#include "hw/mcu.h"
|
||||||
|
#include <spi.h>
|
||||||
|
|
||||||
|
#include "system/sections.h"
|
||||||
|
|
||||||
|
#define CFG11_MPCORE_CLKCNT ((vu16*)(0x10141300))
|
||||||
|
#define CFG11_SOCINFO ((vu16*)(0x10140FFC))
|
||||||
|
|
||||||
|
#define LEGACY_BOOT_ENTRYPOINT ((vu32*)0x1FFFFFFC)
|
||||||
|
#define LEGACY_BOOT_ROUTINE_SMP (0x0001004C)
|
||||||
|
|
||||||
|
static bool SYS_IsNewConsole(void)
|
||||||
|
{
|
||||||
|
return (*CFG11_SOCINFO & 2) != 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
static bool SYS_ClkMultEnabled(void)
|
||||||
|
{
|
||||||
|
return (*CFG11_MPCORE_CLKCNT & 1) != 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
static void SYS_EnableClkMult(void)
|
||||||
|
{
|
||||||
|
// magic bit twiddling to enable extra FCRAM
|
||||||
|
// only done on N3DS and when it hasn't been done yet
|
||||||
|
// state might get a bit messed up so it has to be done
|
||||||
|
// as early as possible in the initialization chain
|
||||||
|
if (SYS_IsNewConsole() && !SYS_ClkMultEnabled()) {
|
||||||
|
gicSetInterruptConfig(88, BIT(0), GIC_PRIO_HIGHEST, NULL);
|
||||||
|
gicEnableInterrupt(88);
|
||||||
|
*CFG11_MPCORE_CLKCNT = 0x8001;
|
||||||
|
do {
|
||||||
|
ARM_WFI();
|
||||||
|
} while(!(*CFG11_MPCORE_CLKCNT & 0x8000));
|
||||||
|
gicDisableInterrupt(88);
|
||||||
|
gicClearInterruptConfig(88);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void SYS_CoreZeroInit(void)
|
||||||
|
{
|
||||||
|
gicGlobalReset();
|
||||||
|
|
||||||
|
*LEGACY_BOOT_ENTRYPOINT = 0;
|
||||||
|
|
||||||
|
SYS_EnableClkMult();
|
||||||
|
|
||||||
|
SCU_Init();
|
||||||
|
|
||||||
|
// Map all sections here
|
||||||
|
mmuMapArea(SECTION_TRI(text), MMU_FLAGS(MMU_CACHE_WT, MMU_READ_ONLY, 0, 1));
|
||||||
|
mmuMapArea(SECTION_TRI(data), MMU_FLAGS(MMU_CACHE_WBA, MMU_READ_WRITE, 1, 1));
|
||||||
|
mmuMapArea(SECTION_TRI(rodata), MMU_FLAGS(MMU_CACHE_WT, MMU_READ_ONLY, 1, 1));
|
||||||
|
mmuMapArea(SECTION_TRI(bss), MMU_FLAGS(MMU_CACHE_WBA, MMU_READ_WRITE, 1, 1));
|
||||||
|
mmuMapArea(SECTION_TRI(shared), MMU_FLAGS(MMU_STRONG_ORDER, MMU_READ_WRITE, 1, 1));
|
||||||
|
|
||||||
|
// High exception vectors
|
||||||
|
mmuMapArea(0xFFFF0000, xrqInstallVectorTable(), 4UL << 10, MMU_FLAGS(MMU_CACHE_WT, MMU_READ_ONLY, 0, 0));
|
||||||
|
|
||||||
|
// BootROM
|
||||||
|
mmuMapArea(0x00010000, 0x00010000, 32UL << 10, MMU_FLAGS(MMU_CACHE_WT, MMU_READ_ONLY, 0, 1));
|
||||||
|
|
||||||
|
// IO Registers
|
||||||
|
mmuMapArea(0x10100000, 0x10100000, 4UL << 20, MMU_FLAGS(MMU_DEV_SHARED, MMU_READ_WRITE, 1, 1));
|
||||||
|
|
||||||
|
// MPCore Private Memory Region
|
||||||
|
mmuMapArea(0x17E00000, 0x17E00000, 8UL << 10, MMU_FLAGS(MMU_DEV_SHARED, MMU_READ_WRITE, 1, 1));
|
||||||
|
|
||||||
|
// VRAM
|
||||||
|
mmuMapArea(0x18000000, 0x18000000, 6UL << 20, MMU_FLAGS(MMU_CACHE_WT, MMU_READ_WRITE, 1, 1));
|
||||||
|
|
||||||
|
// FCRAM
|
||||||
|
if (SYS_IsNewConsole()) {
|
||||||
|
mmuMapArea(0x20000000, 0x20000000, 256UL << 20, MMU_FLAGS(MMU_CACHE_WB, MMU_READ_WRITE, 1, 1));
|
||||||
|
} else {
|
||||||
|
mmuMapArea(0x20000000, 0x20000000, 128UL << 20, MMU_FLAGS(MMU_CACHE_WB, MMU_READ_WRITE, 1, 1));
|
||||||
|
}
|
||||||
|
|
||||||
|
// screen init magicks
|
||||||
|
TIMER_WaitMS(64);
|
||||||
|
|
||||||
|
// Initialize peripherals
|
||||||
|
PXI_Reset();
|
||||||
|
|
||||||
|
I2C_init();
|
||||||
|
mcuReset();
|
||||||
|
|
||||||
|
SPI_Init();
|
||||||
|
CODEC_Init();
|
||||||
|
}
|
||||||
|
|
||||||
|
void SYS_CoreInit(void)
|
||||||
|
{
|
||||||
|
// Reset local GIC registers
|
||||||
|
gicLocalReset();
|
||||||
|
|
||||||
|
// Set up MMU registers
|
||||||
|
mmuInitRegisters();
|
||||||
|
|
||||||
|
// Enable fancy ARM11 features
|
||||||
|
ARM_SetACR(ARM_GetACR() |
|
||||||
|
ACR_RETSTK | ACR_DBPRED | ACR_SBPRED | ACR_FOLDING | ACR_SMP);
|
||||||
|
|
||||||
|
ARM_SetCR(ARM_GetCR() |
|
||||||
|
CR_MMU | CR_CACHES | CR_FLOWPRED | CR_HIGHVEC | CR_DSUBPAGE);
|
||||||
|
|
||||||
|
ARM_DSB();
|
||||||
|
|
||||||
|
ARM_EnableInterrupts();
|
||||||
|
}
|
||||||
|
|
||||||
|
void SYS_CoreZeroShutdown(void)
|
||||||
|
{
|
||||||
|
ARM_DisableInterrupts();
|
||||||
|
gicGlobalReset();
|
||||||
|
}
|
||||||
|
|
||||||
|
void __attribute__((noreturn)) SYS_CoreShutdown(void)
|
||||||
|
{
|
||||||
|
u32 core = ARM_CoreID();
|
||||||
|
|
||||||
|
ARM_DisableInterrupts();
|
||||||
|
|
||||||
|
gicLocalReset();
|
||||||
|
|
||||||
|
ARM_WbInvDC();
|
||||||
|
ARM_InvIC();
|
||||||
|
ARM_DSB();
|
||||||
|
|
||||||
|
ARM_SetCR(ARM_GetCR() & ~(CR_MMU | CR_CACHES | CR_FLOWPRED));
|
||||||
|
ARM_SetACR(ARM_GetACR() &
|
||||||
|
~(ACR_RETSTK | ACR_DBPRED | ACR_SBPRED | ACR_FOLDING | ACR_SMP));
|
||||||
|
|
||||||
|
SPI_Deinit();
|
||||||
|
|
||||||
|
if (!core) {
|
||||||
|
while(*LEGACY_BOOT_ENTRYPOINT == 0);
|
||||||
|
((void (*)(void))(*LEGACY_BOOT_ENTRYPOINT))();
|
||||||
|
} else {
|
||||||
|
// Branch to bootrom function that does SMP reinit magic
|
||||||
|
// (waits for IPI + branches to word @ 0x1FFFFFDC)
|
||||||
|
((void (*)(void))LEGACY_BOOT_ROUTINE_SMP)();
|
||||||
|
}
|
||||||
|
__builtin_unreachable();
|
||||||
|
}
|
38
arm11/source/system/sys.h
Executable file
38
arm11/source/system/sys.h
Executable file
@ -0,0 +1,38 @@
|
|||||||
|
/*
|
||||||
|
* This file is part of GodMode9
|
||||||
|
* Copyright (C) 2019 Wolfvak
|
||||||
|
*
|
||||||
|
* This program is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 2 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <types.h>
|
||||||
|
|
||||||
|
/*
|
||||||
|
how to run the SYS_Core(Zero){Init,Shutdown} functions:
|
||||||
|
for init:
|
||||||
|
- FIRST run CoreZeroInit ONCE
|
||||||
|
- all cores must run CoreInit ONCE
|
||||||
|
|
||||||
|
for shutdown:
|
||||||
|
- all non-zero cores must call CoreShutdown
|
||||||
|
- core zero must call CoreZeroShutdown, then CoreShutdown
|
||||||
|
*/
|
||||||
|
|
||||||
|
void SYS_CoreZeroInit(void);
|
||||||
|
void SYS_CoreInit(void);
|
||||||
|
|
||||||
|
void SYS_CoreZeroShutdown(void);
|
||||||
|
void __attribute__((noreturn)) SYS_CoreShutdown(void);
|
@ -1,41 +1,24 @@
|
|||||||
PROCESSOR := ARM9
|
PROCESSOR := ARM9
|
||||||
|
|
||||||
TARGET := $(shell basename $(CURDIR))
|
TARGET := $(shell basename "$(CURDIR)")
|
||||||
|
|
||||||
SOURCE := source
|
SOURCE := source
|
||||||
BUILD := build
|
BUILD := build
|
||||||
|
|
||||||
SUBARCH := -D$(PROCESSOR) -mcpu=arm946e-s -mtune=arm946e-s -mfloat-abi=soft -mthumb
|
SUBARCH := -D$(PROCESSOR) -march=armv5te -mtune=arm946e-s -mthumb -mfloat-abi=soft
|
||||||
INCDIRS := source source/common source/filesys source/crypto source/fatfs source/nand source/virtual source/game source/gamecart source/lodepng source/qrcodegen source/system source/utils
|
INCDIRS := source source/common source/filesys source/crypto source/fatfs source/nand source/virtual source/game source/gamecart source/lodepng source/lua source/qrcodegen source/system source/utils
|
||||||
INCLUDE := $(foreach dir,$(INCDIRS),-I"$(shell pwd)/$(dir)")
|
INCLUDE := $(foreach dir,$(INCDIRS),-I"$(shell pwd)/$(dir)")
|
||||||
|
|
||||||
ASFLAGS += $(SUBARCH) $(INCLUDE)
|
ASFLAGS += $(SUBARCH) $(INCLUDE)
|
||||||
CFLAGS += $(SUBARCH) $(INCLUDE)
|
CFLAGS += $(SUBARCH) $(INCLUDE) -fno-builtin-memcpy -flto
|
||||||
LDFLAGS += $(SUBARCH) -Wl,-Map,$(TARGET).map
|
LDFLAGS += $(SUBARCH) -Wl,--use-blx,-Map,$(TARGET).map -flto
|
||||||
|
LIBS += -lm
|
||||||
|
|
||||||
include ../Makefile.common
|
include ../Makefile.common
|
||||||
|
include ../Makefile.build
|
||||||
|
|
||||||
OBJECTS = $(patsubst $(SOURCE)/%.s, $(BUILD)/%.o, \
|
arm9_data.elf: arm9.elf
|
||||||
$(patsubst $(SOURCE)/%.c, $(BUILD)/%.o, \
|
$(OBJCOPY) -O elf32-littlearm -j .rodata* -j .data* -j .bss* $< $@
|
||||||
$(call rwildcard, $(SOURCE), *.s *.c)))
|
|
||||||
|
|
||||||
.PHONY: all
|
arm9_code.elf: arm9.elf
|
||||||
all: $(TARGET).elf
|
$(OBJCOPY) -O elf32-littlearm -j .text* -j .vectors* $< $@
|
||||||
|
|
||||||
.PHONY: clean
|
|
||||||
clean:
|
|
||||||
@rm -rf $(BUILD) $(TARGET).elf $(TARGET).map
|
|
||||||
|
|
||||||
$(TARGET).elf: $(OBJECTS)
|
|
||||||
@mkdir -p "$(@D)"
|
|
||||||
@$(CC) $(LDFLAGS) $^ -o $@
|
|
||||||
|
|
||||||
$(BUILD)/%.o: $(SOURCE)/%.c
|
|
||||||
@mkdir -p "$(@D)"
|
|
||||||
@echo "[$(PROCESSOR)] $<"
|
|
||||||
@$(CC) -c $(CFLAGS) -o $@ $<
|
|
||||||
|
|
||||||
$(BUILD)/%.o: $(SOURCE)/%.s
|
|
||||||
@mkdir -p "$(@D)"
|
|
||||||
@echo "[$(PROCESSOR)] $<"
|
|
||||||
@$(CC) -c $(ASFLAGS) -o $@ $<
|
|
||||||
|
51
arm9/link.ld
51
arm9/link.ld
@ -2,19 +2,52 @@ OUTPUT_FORMAT("elf32-littlearm", "elf32-bigarm", "elf32-littlearm")
|
|||||||
OUTPUT_ARCH(arm)
|
OUTPUT_ARCH(arm)
|
||||||
ENTRY(_start)
|
ENTRY(_start)
|
||||||
|
|
||||||
|
MEMORY
|
||||||
|
{
|
||||||
|
VECTORS (RX) : ORIGIN = 0x08000000, LENGTH = 64
|
||||||
|
CODEMEM (RX) : ORIGIN = 0x08000040, LENGTH = 512K - 64
|
||||||
|
BOOTROM (R) : ORIGIN = 0x08080000, LENGTH = 128K /* BootROM mirrors, don't touch! */
|
||||||
|
DATAMEM (RW) : ORIGIN = 0x080A0000, LENGTH = 384K
|
||||||
|
}
|
||||||
|
|
||||||
SECTIONS
|
SECTIONS
|
||||||
{
|
{
|
||||||
. = 0x08006000;
|
.vectors : ALIGN(4) {
|
||||||
__start__ = ABSOLUTE(.);
|
__vectors_lma = LOADADDR(.vectors);
|
||||||
|
__vectors_vma = ABSOLUTE(.);
|
||||||
|
KEEP(*(.vectors));
|
||||||
|
. = ALIGN(4);
|
||||||
|
__vectors_len = ABSOLUTE(.) - __vectors_vma;
|
||||||
|
} >VECTORS AT>CODEMEM
|
||||||
|
|
||||||
.text.start : ALIGN(4) { *(.text.start) }
|
.text : ALIGN(4) {
|
||||||
.text : ALIGN(4) { *(.text*) }
|
__text_s = ABSOLUTE(.);
|
||||||
.rodata : ALIGN(4) { *(.rodata*) }
|
*(.text.start);
|
||||||
.data : ALIGN(4) { *(.data*) }
|
*(.text*);
|
||||||
.bss : ALIGN(4) { __bss_start = .; *(.bss* COMMON); __bss_end = .;}
|
. = ALIGN(4);
|
||||||
|
__text_e = ABSOLUTE(.);
|
||||||
|
} >CODEMEM
|
||||||
|
|
||||||
. = ALIGN(4);
|
.rodata : ALIGN(4) {
|
||||||
|
*(.rodata*);
|
||||||
|
. = ALIGN(4);
|
||||||
|
__exidx_start = .;
|
||||||
|
*(.ARM.exidx* .gnu.linkonce.armexidx.*)
|
||||||
|
__exidx_end = .;
|
||||||
|
. = ALIGN(4);
|
||||||
|
} >DATAMEM
|
||||||
|
|
||||||
|
.data : ALIGN(4) {
|
||||||
|
*(.data*);
|
||||||
|
. = ALIGN(4);
|
||||||
|
} >DATAMEM
|
||||||
|
|
||||||
|
.bss (NOLOAD) : ALIGN(4) {
|
||||||
|
__bss_start = .;
|
||||||
|
*(.bss*);
|
||||||
|
. = ALIGN(4);
|
||||||
|
__bss_end = .;
|
||||||
|
} >DATAMEM
|
||||||
|
|
||||||
__end__ = ABSOLUTE(.);
|
__end__ = ABSOLUTE(.);
|
||||||
__code_size__ = __end__ - __start__;
|
|
||||||
}
|
}
|
||||||
|
32
arm9/source/common/asmfunc.h
Normal file
32
arm9/source/common/asmfunc.h
Normal file
@ -0,0 +1,32 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
/*
|
||||||
|
* This file is part of fastboot 3DS
|
||||||
|
* Copyright (C) 2017 derrek, profi200
|
||||||
|
*
|
||||||
|
* This program is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#if !__ASSEMBLER__
|
||||||
|
#error Only include this in assembly files!
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
.macro ASM_FUNC name
|
||||||
|
.section .text.\name, "ax", %progbits
|
||||||
|
.global \name
|
||||||
|
.type \name %function
|
||||||
|
.align 2
|
||||||
|
\name:
|
||||||
|
.endm
|
@ -1,7 +1,9 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
|
#define RGB(r,g,b) \
|
||||||
#define RGB(r,g,b) ((int) ((b)<<16|(g)<<8|(r)))
|
(((u32)(r) >> 3) << 11 | \
|
||||||
|
((u32)(g) >> 2) << 5 | \
|
||||||
|
((u32)(b) >> 3))
|
||||||
|
|
||||||
// a base set of colors below
|
// a base set of colors below
|
||||||
#define COLOR_BLACK RGB(0x00, 0x00, 0x00)
|
#define COLOR_BLACK RGB(0x00, 0x00, 0x00)
|
||||||
@ -44,6 +46,7 @@
|
|||||||
#define COLOR_FILE COLOR_TINTEDGREEN
|
#define COLOR_FILE COLOR_TINTEDGREEN
|
||||||
#define COLOR_DIR COLOR_TINTEDBLUE
|
#define COLOR_DIR COLOR_TINTEDBLUE
|
||||||
#define COLOR_ROOT COLOR_GREY
|
#define COLOR_ROOT COLOR_GREY
|
||||||
|
#define COLOR_ENTRY(e) (((e)->marked) ? COLOR_MARKED : ((e)->type == T_DIR) ? COLOR_DIR : ((e)->type == T_FILE) ? COLOR_FILE : ((e)->type == T_ROOT) ? COLOR_ROOT : COLOR_GREY)
|
||||||
|
|
||||||
// hex viewer colors
|
// hex viewer colors
|
||||||
#define COLOR_HVOFFS RGB(0x40, 0x60, 0x50)
|
#define COLOR_HVOFFS RGB(0x40, 0x60, 0x50)
|
||||||
|
@ -1,60 +1,194 @@
|
|||||||
#include "hid.h"
|
#include "hid.h"
|
||||||
#include "i2c.h"
|
#include "i2c.h"
|
||||||
#include "timer.h"
|
#include "timer.h"
|
||||||
#include "power.h" // for brightness slider
|
#include "colors.h"
|
||||||
#include "screenshot.h" // for screenshots
|
#include "screenshot.h" // for screenshots
|
||||||
|
|
||||||
|
#include "arm.h"
|
||||||
|
#include "fixp.h"
|
||||||
|
#include "shmem.h"
|
||||||
|
|
||||||
|
#define HID_TOUCH_MAXPOINT (0x1000)
|
||||||
|
#define HID_TOUCH_MIDPOINT (HID_TOUCH_MAXPOINT / 2)
|
||||||
|
|
||||||
|
|
||||||
|
static void SetNotificationLED(u32 period_ms, u32 rgb565_color)
|
||||||
|
{
|
||||||
|
u32 rgb888_color =
|
||||||
|
((rgb565_color >> 11) << (16+3) |
|
||||||
|
(rgb565_color >> 5) << (8+2) |
|
||||||
|
(rgb565_color << 3));
|
||||||
|
u32 args[] = {period_ms, rgb888_color};
|
||||||
|
PXI_DoCMD(PXICMD_SET_NOTIFY_LED, args, 2);
|
||||||
|
}
|
||||||
|
|
||||||
|
// there's some weird thing going on when reading this
|
||||||
|
// with an LDRD instruction so for now they'll be two
|
||||||
|
// separate things - hopefully LTO won't get in the way
|
||||||
|
u32 HID_ReadState(void)
|
||||||
|
{
|
||||||
|
return ARM_GetSHMEM()->hidState.keys;
|
||||||
|
}
|
||||||
|
|
||||||
|
u32 HID_ReadRawTouchState(void)
|
||||||
|
{
|
||||||
|
return ARM_GetSHMEM()->hidState.touch;
|
||||||
|
}
|
||||||
|
|
||||||
|
// ts_mult indicates a scalar for each axis
|
||||||
|
// if |ts_mult| > 1 => point must be "scaled out"
|
||||||
|
// if |ts_mult| < 1 => point must be "scaled in"
|
||||||
|
// if ts_mult < 0 => axis is inverted
|
||||||
|
static fixp_t ts_mult[2];
|
||||||
|
|
||||||
|
// ts_org indicates the coordinate system origin
|
||||||
|
static int ts_org[2];
|
||||||
|
|
||||||
|
bool HID_TouchCalibratedTransform(u32 ts, u16 *x, u16 *y)
|
||||||
|
{
|
||||||
|
int xc, yc;
|
||||||
|
int tx, ty;
|
||||||
|
|
||||||
|
if (ts & BIT(31))
|
||||||
|
return false;
|
||||||
|
|
||||||
|
tx = HID_RAW_TX(ts) - HID_TOUCH_MIDPOINT;
|
||||||
|
ty = HID_RAW_TY(ts) - HID_TOUCH_MIDPOINT;
|
||||||
|
|
||||||
|
xc = FIXP_TO_INT(fixp_round(tx * ts_mult[0])) + ts_org[0];
|
||||||
|
yc = FIXP_TO_INT(fixp_round(ty * ts_mult[1])) + ts_org[1];
|
||||||
|
|
||||||
|
*x = clamp(xc, 0, (ts_org[0] * 2) - 1);
|
||||||
|
*y = clamp(yc, 0, (ts_org[1] * 2) - 1);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool HID_ReadTouchState(u16 *x, u16 *y)
|
||||||
|
{
|
||||||
|
return HID_TouchCalibratedTransform(HID_ReadRawTouchState(), x, y);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool HID_SetCalibrationData(const HID_CalibrationData *calibs, u32 point_cnt, u32 screen_w, u32 screen_h)
|
||||||
|
{
|
||||||
|
u32 mid_x, mid_y;
|
||||||
|
fixp_t avg_x, avg_y;
|
||||||
|
|
||||||
|
if (!screen_w || !screen_h || point_cnt <= 0 || point_cnt > 7)
|
||||||
|
return false;
|
||||||
|
|
||||||
|
mid_x = screen_w / 2;
|
||||||
|
mid_y = screen_h / 2;
|
||||||
|
|
||||||
|
avg_x = 0;
|
||||||
|
avg_y = 0;
|
||||||
|
for (u32 i = 0; i < point_cnt; i++) {
|
||||||
|
const HID_CalibrationData *data = &calibs[i];
|
||||||
|
fixp_t screen_x, screen_y, touch_x, touch_y;
|
||||||
|
|
||||||
|
// translate the [0, screen_w] x [0, screen_h] system
|
||||||
|
// to [-screen_w/2, screen_w/2] x [-screen_h/2, screen_h/2]
|
||||||
|
screen_x = INT_TO_FIXP(data->screen_x - mid_x);
|
||||||
|
screen_y = INT_TO_FIXP(data->screen_y - mid_y);
|
||||||
|
|
||||||
|
// same thing for raw touchscreen data
|
||||||
|
touch_x = INT_TO_FIXP(HID_RAW_TX(data->ts_raw) - HID_TOUCH_MIDPOINT);
|
||||||
|
touch_y = INT_TO_FIXP(HID_RAW_TY(data->ts_raw) - HID_TOUCH_MIDPOINT);
|
||||||
|
|
||||||
|
// if the data retrieved came right in the middle, it's invalid
|
||||||
|
if (!screen_x || !screen_y || !touch_x || !touch_y)
|
||||||
|
return false;
|
||||||
|
|
||||||
|
// prevent integer overflows by dividing in this step
|
||||||
|
avg_x += fixp_quotient(screen_x, touch_x * point_cnt);
|
||||||
|
avg_y += fixp_quotient(screen_y, touch_y * point_cnt);
|
||||||
|
}
|
||||||
|
|
||||||
|
// set state variables
|
||||||
|
ts_mult[0] = avg_x;
|
||||||
|
ts_mult[1] = avg_y;
|
||||||
|
ts_org[0] = mid_x;
|
||||||
|
ts_org[1] = mid_y;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
const TouchBox* TouchBoxGet(u32* id, const u16 x, const u16 y, const TouchBox* tbs, const u32 tbn) {
|
||||||
|
// check if inside touchbox
|
||||||
|
for (u32 i = 0; !tbn || (i < tbn); i++) {
|
||||||
|
const TouchBox* tb = tbs + i;
|
||||||
|
if (tb->id == 0) break;
|
||||||
|
if ((x >= tb->x) && (y >= tb->y) &&
|
||||||
|
(x < tb->x + tb->w) && (y < tb->y + tb->h)) {
|
||||||
|
if (id) *id = tb->id;
|
||||||
|
return tb; // we know const is discarded here
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (id) *id = 0;
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
u32 InputWait(u32 timeout_sec) {
|
u32 InputWait(u32 timeout_sec) {
|
||||||
static u64 delay = 0;
|
static u64 delay = 0;
|
||||||
u32 pad_state_old = HID_STATE;
|
|
||||||
u32 cart_state_old = CART_STATE;
|
|
||||||
u32 sd_state_old = SD_STATE;
|
|
||||||
u64 timer = timer_start();
|
u64 timer = timer_start();
|
||||||
u64 timer_mcu = timer;
|
|
||||||
delay = (delay) ? 72 : 128;
|
u32 oldpad = HID_ReadState();
|
||||||
while (true) {
|
u32 oldcart = CART_STATE;
|
||||||
u32 pad_state = HID_STATE;
|
u32 oldsd = SD_STATE;
|
||||||
if (timeout_sec && (timer_sec(timer) >= timeout_sec))
|
|
||||||
return TIMEOUT_HID; // HID timeout
|
// enable notification LED if shell is closed
|
||||||
if (!(pad_state & BUTTON_ANY)) { // no buttons pressed
|
// (this means we're waiting for user input)
|
||||||
u32 cart_state = CART_STATE;
|
if (oldpad & SHELL_CLOSED) {
|
||||||
if (cart_state != cart_state_old)
|
SetNotificationLED(1000, COLOR_GREEN);
|
||||||
return cart_state ? CART_INSERT : CART_EJECT;
|
while (HID_ReadState() & SHELL_CLOSED);
|
||||||
u32 sd_state = SD_STATE;
|
}
|
||||||
if (sd_state != sd_state_old)
|
|
||||||
return sd_state ? SD_INSERT : SD_EJECT;
|
delay = delay ? 144 : 256;
|
||||||
u8 special_key;
|
|
||||||
if ((timer_msec(timer_mcu) >= 64) && (I2C_readRegBuf(I2C_DEV_MCU, 0x10, &special_key, 1))) {
|
do {
|
||||||
CheckBrightness();
|
u32 newpad = HID_ReadState();
|
||||||
if (special_key == 0x01)
|
|
||||||
return pad_state | BUTTON_POWER;
|
// handle closed shell (wait for open)
|
||||||
else if (special_key == 0x04)
|
if (newpad & SHELL_CLOSED) {
|
||||||
return pad_state | BUTTON_HOME;
|
while (HID_ReadState() & SHELL_CLOSED);
|
||||||
timer_mcu = timer_start();
|
continue;
|
||||||
}
|
}
|
||||||
pad_state_old = pad_state;
|
|
||||||
|
// no buttons pressed, check for I/O changes instead
|
||||||
|
if (!(newpad & ~(SHELL_OPEN|SHELL_CLOSED))) {
|
||||||
|
u32 state = CART_STATE;
|
||||||
|
if (state != oldcart)
|
||||||
|
return state ? CART_INSERT : CART_EJECT;
|
||||||
|
|
||||||
|
state = SD_STATE;
|
||||||
|
if (state != oldsd)
|
||||||
|
return state ? SD_INSERT : SD_EJECT;
|
||||||
|
|
||||||
|
oldpad = 0;
|
||||||
delay = 0;
|
delay = 0;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if ((pad_state == pad_state_old) &&
|
|
||||||
(!(pad_state & BUTTON_ARROW) ||
|
// special case for dpad keys
|
||||||
|
// if any of those are held, don't wait for key changes
|
||||||
|
// but do insert a small latency to make
|
||||||
|
// sure any menus don't go flying off
|
||||||
|
if ((newpad == oldpad) &&
|
||||||
|
(!(newpad & BUTTON_ARROW) ||
|
||||||
(delay && (timer_msec(timer) < delay))))
|
(delay && (timer_msec(timer) < delay))))
|
||||||
continue;
|
continue;
|
||||||
// make sure the key is pressed
|
|
||||||
u32 t_pressed = 0;
|
// screenshot handling
|
||||||
for(; (t_pressed < 0x13000) && (pad_state == HID_STATE); t_pressed++);
|
if ((newpad & BUTTON_ANY) == (BUTTON_R1 | BUTTON_L1))
|
||||||
if (t_pressed >= 0x13000) {
|
CreateScreenshot();
|
||||||
if ((pad_state & BUTTON_ANY) == (BUTTON_R1 | BUTTON_L1))
|
|
||||||
CreateScreenshot(); // screenshot handling
|
return newpad;
|
||||||
return pad_state;
|
} while (!timeout_sec || (timeout_sec && (timer_sec(timer) < timeout_sec)));
|
||||||
}
|
|
||||||
}
|
return TIMEOUT_HID;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool CheckButton(u32 button) {
|
bool CheckButton(u32 button) {
|
||||||
u32 t_pressed = 0;
|
return (HID_ReadState() & button) == button;
|
||||||
for(; (t_pressed < 0x13000) && ((HID_STATE & button) == button); t_pressed++);
|
|
||||||
return (t_pressed >= 0x13000);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void ButtonToString(u32 button, char* str) {
|
void ButtonToString(u32 button, char* str) {
|
||||||
|
@ -2,40 +2,41 @@
|
|||||||
|
|
||||||
#include "common.h"
|
#include "common.h"
|
||||||
|
|
||||||
|
#include "hid_map.h"
|
||||||
|
|
||||||
// see: http://3dbrew.org/wiki/CONFIG9_Registers
|
// see: http://3dbrew.org/wiki/CONFIG9_Registers
|
||||||
// see: http://3dbrew.org/wiki/EMMC_Registers
|
// see: http://3dbrew.org/wiki/EMMC_Registers
|
||||||
#define HID_STATE (~(*(volatile u32*)0x10146000) & BUTTON_ANY)
|
|
||||||
#define CART_STATE (~(*(volatile u8*)0x10000010) & 0x1)
|
#define CART_STATE (~(*(volatile u8*)0x10000010) & 0x1)
|
||||||
#define SD_STATE ((*(volatile u16*)0x1000601C) & (0x1<<5))
|
#define SD_STATE ((*(volatile u16*)0x1000601C) & (0x1<<5))
|
||||||
|
|
||||||
|
#define HID_RAW_TX(t) ((s32)(((t) / (1 << 16)) & 0xFFF))
|
||||||
|
#define HID_RAW_TY(t) ((s32)((t) & 0xFFF))
|
||||||
|
|
||||||
#define BUTTON_A (1 << 0)
|
u32 HID_ReadState(void);
|
||||||
#define BUTTON_B (1 << 1)
|
|
||||||
#define BUTTON_SELECT (1 << 2)
|
|
||||||
#define BUTTON_START (1 << 3)
|
|
||||||
#define BUTTON_RIGHT (1 << 4)
|
|
||||||
#define BUTTON_LEFT (1 << 5)
|
|
||||||
#define BUTTON_UP (1 << 6)
|
|
||||||
#define BUTTON_DOWN (1 << 7)
|
|
||||||
#define BUTTON_R1 (1 << 8)
|
|
||||||
#define BUTTON_L1 (1 << 9)
|
|
||||||
#define BUTTON_X (1 << 10)
|
|
||||||
#define BUTTON_Y (1 << 11)
|
|
||||||
#define BUTTON_ANY 0x00000FFF
|
|
||||||
#define BUTTON_ARROW (BUTTON_RIGHT|BUTTON_LEFT|BUTTON_UP|BUTTON_DOWN)
|
|
||||||
|
|
||||||
// special buttons / cart / sd
|
// ts_raw is the raw touchscreen value obtained when pressing down
|
||||||
#define BUTTON_POWER (1 << 12)
|
// the touchscreen at the screen coordinates [screen_x, screen_y]
|
||||||
#define BUTTON_HOME (1 << 13)
|
// note: no point can be at the center
|
||||||
#define CART_INSERT (1 << 14)
|
typedef struct {
|
||||||
#define CART_EJECT (1 << 15)
|
u32 ts_raw;
|
||||||
#define SD_INSERT (1 << 16)
|
int screen_x, screen_y;
|
||||||
#define SD_EJECT (1 << 17)
|
} HID_CalibrationData;
|
||||||
#define TIMEOUT_HID (1 << 31)
|
|
||||||
|
|
||||||
// strings for button conversion
|
u32 HID_ReadRawTouchState(void);
|
||||||
#define BUTTON_STRINGS "A", "B", "SELECT", "START", "RIGHT", "LEFT", "UP", "DOWN", "R", "L", "X", "Y"
|
bool HID_ReadTouchState(u16 *x, u16 *y);
|
||||||
|
bool HID_TouchCalibratedTransform(u32 ts, u16 *x, u16 *y);
|
||||||
|
bool HID_SetCalibrationData(const HID_CalibrationData *calibs, u32 point_cnt, u32 screen_w, u32 screen_h);
|
||||||
|
|
||||||
|
typedef struct {
|
||||||
|
u16 x;
|
||||||
|
u16 y;
|
||||||
|
u16 w;
|
||||||
|
u16 h;
|
||||||
|
u32 id; // shouldn't be zero
|
||||||
|
} TouchBox;
|
||||||
|
|
||||||
|
// abstraction for HID_ReadTouchState, also returns touchbox id (if any)
|
||||||
|
const TouchBox* TouchBoxGet(u32* id, const u16 x, const u16 y, const TouchBox* tbs, const u32 tbn);
|
||||||
|
|
||||||
u32 InputWait(u32 timeout_sec);
|
u32 InputWait(u32 timeout_sec);
|
||||||
bool CheckButton(u32 button);
|
bool CheckButton(u32 button);
|
||||||
|
70
arm9/source/common/memcpy.s
Normal file
70
arm9/source/common/memcpy.s
Normal file
@ -0,0 +1,70 @@
|
|||||||
|
@ memcpy_arm946e-s - hand written reimplementation of memcpy to be sequential
|
||||||
|
@ Written in 2019 by luigoalma <luigoalma at gmail dot com>
|
||||||
|
@ To the extent possible under law, the author(s) have dedicated all copyright and related and neighboring rights to this software to the public domain worldwide. This software is distributed without any warranty.
|
||||||
|
@ For a copy of CC0 Public Domain Dedication, see <https://creativecommons.org/publicdomain/zero/1.0/>.
|
||||||
|
.cpu arm946e-s
|
||||||
|
.arch armv5te
|
||||||
|
.arm
|
||||||
|
.section .text.memcpy, "ax", %progbits
|
||||||
|
.align 2
|
||||||
|
.global memcpy
|
||||||
|
.syntax unified
|
||||||
|
.type memcpy, %function
|
||||||
|
memcpy:
|
||||||
|
@ r0 = dest
|
||||||
|
@ r1 = src
|
||||||
|
@ r2 = length
|
||||||
|
@ check if length 0 and return if so
|
||||||
|
cmp r2, #0
|
||||||
|
bxeq lr
|
||||||
|
push {r0,r4-r9,lr}
|
||||||
|
@ pre-fetch data
|
||||||
|
pld [r1]
|
||||||
|
@ alignment check with word size
|
||||||
|
@ if not aligned but both are in the same misalignment, fix it up
|
||||||
|
@ otherwise jump to basic loop
|
||||||
|
orr r12, r0, r1
|
||||||
|
ands r12, r12, #3
|
||||||
|
beq .L1
|
||||||
|
mov r12, r0, LSL#30
|
||||||
|
cmp r12, r1, LSL#30
|
||||||
|
bne .L6
|
||||||
|
.L0:
|
||||||
|
ldrb r3, [r1], #1
|
||||||
|
strb r3, [r0], #1
|
||||||
|
subs r2, r2, #1
|
||||||
|
popeq {r0,r4-r9,pc}
|
||||||
|
adds r12, r12, #0x40000000
|
||||||
|
bne .L0
|
||||||
|
.L1:
|
||||||
|
@ check if length higher than 32
|
||||||
|
@ if so, do the 32 byte block copy loop,
|
||||||
|
@ until there's nothing left or remainder to copy is less than 32
|
||||||
|
movs r3, r2, LSR#5
|
||||||
|
beq .L3
|
||||||
|
.L2:
|
||||||
|
ldm r1!, {r4-r9,r12,lr}
|
||||||
|
stm r0!, {r4-r9,r12,lr}
|
||||||
|
subs r3, r3, #1
|
||||||
|
bne .L2
|
||||||
|
ands r2, r2, #0x1F
|
||||||
|
popeq {r0,r4-r9,pc}
|
||||||
|
.L3:
|
||||||
|
@ copy in word size the remaining data,
|
||||||
|
@ and finish off with basic loop if can't copy all by word size.
|
||||||
|
movs r3, r2, LSR#2
|
||||||
|
beq .L6
|
||||||
|
.L4:
|
||||||
|
ldr r12, [r1], #4
|
||||||
|
str r12, [r0], #4
|
||||||
|
subs r3, r3, #1
|
||||||
|
bne .L4
|
||||||
|
ands r2, r2, #0x3
|
||||||
|
.L5: @ the basic loop
|
||||||
|
popeq {r0,r4-r9,pc}
|
||||||
|
.L6:
|
||||||
|
ldrb r3, [r1], #1
|
||||||
|
strb r3, [r0], #1
|
||||||
|
subs r2, r2, #1
|
||||||
|
b .L5
|
||||||
|
.size memcpy, .-memcpy
|
26
arm9/source/common/mmio.h
Normal file
26
arm9/source/common/mmio.h
Normal file
@ -0,0 +1,26 @@
|
|||||||
|
/*
|
||||||
|
* This file is part of fastboot 3DS
|
||||||
|
* Copyright (C) 2019 Aurora Wright, TuxSH, derrek, profi200
|
||||||
|
*
|
||||||
|
* This program is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
// Based on https://github.com/AuroraWright/Luma3DS/blob/master/arm9/source/alignedseqmemcpy.s
|
||||||
|
|
||||||
|
#include "common.h"
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
void iomemcpy(vu32 *restrict dst, const vu32 *restrict src, u32 size);
|
||||||
|
void iomemset(vu32 *ptr, u32 value, u32 size);
|
87
arm9/source/common/mmio.s
Normal file
87
arm9/source/common/mmio.s
Normal file
@ -0,0 +1,87 @@
|
|||||||
|
/*
|
||||||
|
* This file is part of fastboot 3DS
|
||||||
|
* Copyright (C) 2019 Aurora Wright, TuxSH, derrek, profi200
|
||||||
|
*
|
||||||
|
* This program is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
@ Based on https://github.com/AuroraWright/Luma3DS/blob/master/arm9/source/alignedseqmemcpy.s
|
||||||
|
|
||||||
|
#include "asmfunc.h"
|
||||||
|
|
||||||
|
.arm
|
||||||
|
.cpu arm946e-s
|
||||||
|
.fpu softvfp
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@ void iomemcpy(vu32 *restrict dst, const vu32 *restrict src, u32 size)
|
||||||
|
ASM_FUNC iomemcpy
|
||||||
|
bics r12, r2, #31
|
||||||
|
beq iomemcpy_test_words
|
||||||
|
stmfd sp!, {r4-r10}
|
||||||
|
iomemcpy_blocks_lp:
|
||||||
|
ldmia r1!, {r3-r10}
|
||||||
|
stmia r0!, {r3-r10}
|
||||||
|
subs r12, #32
|
||||||
|
bne iomemcpy_blocks_lp
|
||||||
|
ldmfd sp!, {r4-r10}
|
||||||
|
iomemcpy_test_words:
|
||||||
|
ands r12, r2, #28
|
||||||
|
beq iomemcpy_halfword_byte
|
||||||
|
iomemcpy_words_lp:
|
||||||
|
ldr r3, [r1], #4
|
||||||
|
str r3, [r0], #4
|
||||||
|
subs r12, #4
|
||||||
|
bne iomemcpy_words_lp
|
||||||
|
iomemcpy_halfword_byte:
|
||||||
|
tst r2, #2
|
||||||
|
ldrneh r3, [r1], #2
|
||||||
|
strneh r3, [r0], #2
|
||||||
|
tst r2, #1
|
||||||
|
ldrneb r3, [r1]
|
||||||
|
strneb r3, [r0]
|
||||||
|
bx lr
|
||||||
|
|
||||||
|
|
||||||
|
@ void iomemset(vu32 *ptr, u32 value, u32 size)
|
||||||
|
ASM_FUNC iomemset
|
||||||
|
bics r12, r2, #31
|
||||||
|
beq iomemset_test_words
|
||||||
|
stmfd sp!, {r4-r9}
|
||||||
|
mov r3, r1
|
||||||
|
mov r4, r1
|
||||||
|
mov r5, r1
|
||||||
|
mov r6, r1
|
||||||
|
mov r7, r1
|
||||||
|
mov r8, r1
|
||||||
|
mov r9, r1
|
||||||
|
iomemset_blocks_lp:
|
||||||
|
stmia r0!, {r1, r3-r9}
|
||||||
|
subs r12, #32
|
||||||
|
bne iomemset_blocks_lp
|
||||||
|
ldmfd sp!, {r4-r9}
|
||||||
|
iomemset_test_words:
|
||||||
|
ands r12, r2, #28
|
||||||
|
beq iomemset_halfword_byte
|
||||||
|
iomemset_words_lp:
|
||||||
|
str r1, [r0], #4
|
||||||
|
subs r12, #4
|
||||||
|
bne iomemset_words_lp
|
||||||
|
iomemset_halfword_byte:
|
||||||
|
tst r2, #2
|
||||||
|
strneh r1, [r0], #2
|
||||||
|
tst r2, #1
|
||||||
|
strneb r1, [r0]
|
||||||
|
bx lr
|
@ -1,24 +1,18 @@
|
|||||||
|
#include "arm.h"
|
||||||
#include "power.h"
|
#include "power.h"
|
||||||
#include "i2c.h"
|
#include "i2c.h"
|
||||||
#include "cache.h"
|
|
||||||
#include "pxi.h"
|
#include "pxi.h"
|
||||||
|
|
||||||
static const u8 br_settings[] = {0x10, 0x17, 0x1E, 0x25, 0x2C, 0x34, 0x3C, 0x44, 0x4D, 0x56, 0x60, 0x6B, 0x79, 0x8C, 0xA7, 0xD2};
|
u32 SetScreenBrightness(int level) {
|
||||||
static int prev_brightness = -1;
|
u32 arg;
|
||||||
void CheckBrightness() {
|
|
||||||
u8 curSlider;
|
if (level != BRIGHTNESS_AUTOMATIC) {
|
||||||
#ifndef FIXED_BRIGHTNESS
|
arg = clamp(level, BRIGHTNESS_MIN, BRIGHTNESS_MAX);
|
||||||
I2C_readRegBuf(I2C_DEV_MCU, 0x09, &curSlider, 1);
|
} else {
|
||||||
// Volume Slider value is always between 0x00 and 0x3F
|
arg = 0;
|
||||||
curSlider >>= 2;
|
|
||||||
#else
|
|
||||||
curSlider = FIXED_BRIGHTNESS;
|
|
||||||
#endif
|
|
||||||
if (curSlider != prev_brightness) {
|
|
||||||
PXI_DoCMD(PXI_BRIGHTNESS, (u32[]){br_settings[curSlider]}, 1);
|
|
||||||
prev_brightness = curSlider;
|
|
||||||
}
|
}
|
||||||
return;
|
|
||||||
|
return PXI_DoCMD(PXICMD_SET_BRIGHTNESS, &arg, 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
u32 GetBatteryPercent() {
|
u32 GetBatteryPercent() {
|
||||||
@ -35,15 +29,17 @@ bool IsCharging() {
|
|||||||
|
|
||||||
void Reboot() {
|
void Reboot() {
|
||||||
I2C_writeReg(I2C_DEV_MCU, 0x22, 1 << 0); // poweroff LCD to prevent MCU hangs
|
I2C_writeReg(I2C_DEV_MCU, 0x22, 1 << 0); // poweroff LCD to prevent MCU hangs
|
||||||
flushEntireDCache();
|
ARM_WbDC();
|
||||||
if (I2C_writeReg(I2C_DEV_MCU, 0x20, 1 << 2))
|
ARM_DSB();
|
||||||
while(true);
|
I2C_writeReg(I2C_DEV_MCU, 0x20, 1 << 2);
|
||||||
|
while(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
void PowerOff()
|
void PowerOff()
|
||||||
{
|
{
|
||||||
I2C_writeReg(I2C_DEV_MCU, 0x22, 1 << 0); // poweroff LCD to prevent MCU hangs
|
I2C_writeReg(I2C_DEV_MCU, 0x22, 1 << 0); // poweroff LCD to prevent MCU hangs
|
||||||
flushEntireDCache();
|
ARM_WbDC();
|
||||||
if (I2C_writeReg(I2C_DEV_MCU, 0x20, 1 << 0))
|
ARM_DSB();
|
||||||
while (true);
|
I2C_writeReg(I2C_DEV_MCU, 0x20, 1 << 0);
|
||||||
|
while(true);
|
||||||
}
|
}
|
||||||
|
@ -2,7 +2,11 @@
|
|||||||
|
|
||||||
#include "common.h"
|
#include "common.h"
|
||||||
|
|
||||||
void CheckBrightness();
|
#define BRIGHTNESS_AUTOMATIC (-1)
|
||||||
|
#define BRIGHTNESS_MIN (10)
|
||||||
|
#define BRIGHTNESS_MAX (210)
|
||||||
|
|
||||||
|
u32 SetScreenBrightness(int level);
|
||||||
u32 GetBatteryPercent();
|
u32 GetBatteryPercent();
|
||||||
bool IsCharging();
|
bool IsCharging();
|
||||||
void Reboot();
|
void Reboot();
|
||||||
|
@ -7,23 +7,23 @@ bool is_valid_dstime(DsTime* dstime) {
|
|||||||
(DSTIMEGET(dstime, bcd_m) >= 60) ||
|
(DSTIMEGET(dstime, bcd_m) >= 60) ||
|
||||||
(DSTIMEGET(dstime, bcd_s) >= 60))
|
(DSTIMEGET(dstime, bcd_s) >= 60))
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
// check the date...
|
// check the date...
|
||||||
u32 year = 2000 + DSTIMEGET(dstime, bcd_Y);
|
u32 year = 2000 + DSTIMEGET(dstime, bcd_Y);
|
||||||
u32 month = DSTIMEGET(dstime, bcd_M);
|
u32 month = DSTIMEGET(dstime, bcd_M);
|
||||||
u32 day = DSTIMEGET(dstime, bcd_D);
|
u32 day = DSTIMEGET(dstime, bcd_D);
|
||||||
|
|
||||||
// date: year & month
|
// date: year & month
|
||||||
if ((year >= 2100) || (month == 0) || (month > 12))
|
if ((year >= 2100) || (month == 0) || (month > 12))
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
// date: day
|
// date: day
|
||||||
// see: https://github.com/devkitPro/libnds/blob/9678bf09389cb1fcdc99dfa0357ec0cbe51dd0b7/source/arm7/clock.c#L224-L262
|
// see: https://github.com/devkitPro/libnds/blob/9678bf09389cb1fcdc99dfa0357ec0cbe51dd0b7/source/arm7/clock.c#L224-L262
|
||||||
u32 months_lastday[1+12] = { 0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };
|
u32 months_lastday[1+12] = { 0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };
|
||||||
u32 leap = (((year % 4 == 0) && (year % 100 != 0)) || (year % 400 == 0)) ? 1 : 0;
|
u32 leap = (((year % 4 == 0) && (year % 100 != 0)) || (year % 400 == 0)) ? 1 : 0;
|
||||||
u32 days_in_month = months_lastday[month] + ((month == 2) ? leap : 0);
|
u32 days_in_month = months_lastday[month] + ((month == 2) ? leap : 0);
|
||||||
if (day > days_in_month) return false;
|
if (day > days_in_month) return false;
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -16,8 +16,8 @@ typedef struct {
|
|||||||
u8 bcd_D;
|
u8 bcd_D;
|
||||||
u8 bcd_M;
|
u8 bcd_M;
|
||||||
u8 bcd_Y;
|
u8 bcd_Y;
|
||||||
u8 leap_count;
|
u8 leap_count;
|
||||||
} __attribute__((packed)) DsTime;
|
} PACKED_STRUCT DsTime;
|
||||||
|
|
||||||
bool is_valid_dstime(DsTime* dstime);
|
bool is_valid_dstime(DsTime* dstime);
|
||||||
bool get_dstime(DsTime* dstime);
|
bool get_dstime(DsTime* dstime);
|
||||||
|
@ -4,60 +4,63 @@
|
|||||||
#include "vff.h"
|
#include "vff.h"
|
||||||
#include "png.h"
|
#include "png.h"
|
||||||
|
|
||||||
|
static void Screenshot_Transpose(u16 *dest, const u16 *fb, u32 w, u32 stride)
|
||||||
|
{
|
||||||
|
for (u32 y = 0; y < SCREEN_HEIGHT; y++) {
|
||||||
|
for (u32 x = 0; x < w; x++)
|
||||||
|
*(dest++) = GetColor(fb, x, y);
|
||||||
|
dest += stride;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void CreateScreenshot() {
|
void CreateScreenshot(void) {
|
||||||
const u32 snap_size = SCREEN_SIZE_TOP * 2, snap_width = SCREEN_WIDTH_TOP, snap_height = SCREEN_HEIGHT * 2;
|
u8 *png;
|
||||||
u8 *png_data = NULL;
|
u16 *buffer;
|
||||||
size_t png_size;
|
|
||||||
|
|
||||||
char filename[64];
|
|
||||||
DsTime dstime;
|
DsTime dstime;
|
||||||
|
size_t png_size;
|
||||||
|
char filename[64];
|
||||||
|
u32 snapbuf_size, snap_w, snap_h, bot_offset;
|
||||||
|
|
||||||
|
snapbuf_size = (SCREEN_WIDTH_TOP * SCREEN_HEIGHT * BYTES_PER_PIXEL) * 2;
|
||||||
|
snap_w = SCREEN_WIDTH_TOP;
|
||||||
|
snap_h = SCREEN_HEIGHT * 2;
|
||||||
|
|
||||||
fvx_rmkdir(OUTPUT_PATH);
|
fvx_rmkdir(OUTPUT_PATH);
|
||||||
get_dstime(&dstime);
|
get_dstime(&dstime);
|
||||||
snprintf(filename, 64, OUTPUT_PATH "/snap_%02X%02X%02X%02X%02X%02X.png",
|
snprintf(filename, sizeof(filename), OUTPUT_PATH "/snap_%02X%02X%02X%02X%02X%02X.png",
|
||||||
dstime.bcd_Y, dstime.bcd_M, dstime.bcd_D,
|
dstime.bcd_Y, dstime.bcd_M, dstime.bcd_D,
|
||||||
dstime.bcd_h, dstime.bcd_m, dstime.bcd_s);
|
dstime.bcd_h, dstime.bcd_m, dstime.bcd_s);
|
||||||
|
filename[63] = '\0';
|
||||||
|
|
||||||
u8* buffer = (u8*) malloc(snap_size);
|
buffer = malloc(snapbuf_size);
|
||||||
if (!buffer) return;
|
if (!buffer) return;
|
||||||
|
|
||||||
u8* buffer_t = buffer;
|
for (unsigned i = snapbuf_size/4; i < snapbuf_size/2; i++)
|
||||||
u8* buffer_b = buffer + SCREEN_SIZE_TOP;
|
buffer[i] = RGB(0x1F, 0x1F, 0x1F); // gray background
|
||||||
|
|
||||||
memset(buffer, 0x1F, snap_size); // gray background
|
bot_offset = (SCREEN_WIDTH_TOP * SCREEN_HEIGHT) + 40;
|
||||||
|
|
||||||
for (u32 x = 0; x < 400; x++) {
|
Screenshot_Transpose(buffer, TOP_SCREEN, SCREEN_WIDTH_TOP, 0);
|
||||||
for (u32 y = 0; y < 240; y++) {
|
Screenshot_Transpose(buffer + bot_offset, BOT_SCREEN, SCREEN_WIDTH_BOT, 80);
|
||||||
buffer_t[(y * SCREEN_WIDTH_TOP + x) * 3 + 0] = *(TOP_SCREEN + (((x * 240) + (239 - y)) * 3) + 2);
|
|
||||||
buffer_t[(y * SCREEN_WIDTH_TOP + x) * 3 + 1] = *(TOP_SCREEN + (((x * 240) + (239 - y)) * 3) + 1);
|
|
||||||
buffer_t[(y * SCREEN_WIDTH_TOP + x) * 3 + 2] = *(TOP_SCREEN + (((x * 240) + (239 - y)) * 3) + 0);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
for (u32 x = 0; x < 320; x++) {
|
png = PNG_Compress(buffer, snap_w, snap_h, &png_size);
|
||||||
for (u32 y = 0; y < 240; y++) {
|
|
||||||
buffer_b[(y * SCREEN_WIDTH_TOP + x + 40) * 3 + 0] = *(BOT_SCREEN + (((x * 240) + (239 - y)) * 3) + 2);
|
|
||||||
buffer_b[(y * SCREEN_WIDTH_TOP + x + 40) * 3 + 1] = *(BOT_SCREEN + (((x * 240) + (239 - y)) * 3) + 1);
|
|
||||||
buffer_b[(y * SCREEN_WIDTH_TOP + x + 40) * 3 + 2] = *(BOT_SCREEN + (((x * 240) + (239 - y)) * 3) + 0);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
png_data = PNG_Compress(buffer, snap_width, snap_height, &png_size);
|
if (png && png_size) {
|
||||||
|
u16 *buffer_top = buffer, *buffer_bottom = buffer + bot_offset;
|
||||||
if (png_data && png_size) {
|
|
||||||
fvx_qwrite(filename, png_data, 0, png_size, NULL);
|
|
||||||
|
|
||||||
// "snap effect"
|
// "snap effect"
|
||||||
memcpy(buffer_b, BOT_SCREEN, SCREEN_SIZE_BOT);
|
memcpy(buffer_bottom, BOT_SCREEN, SCREEN_SIZE_BOT);
|
||||||
memcpy(buffer_t, TOP_SCREEN, SCREEN_SIZE_TOP);
|
memcpy(buffer_top, TOP_SCREEN, SCREEN_SIZE_TOP);
|
||||||
memset(BOT_SCREEN, 0, SCREEN_SIZE_BOT);
|
memset(BOT_SCREEN, 0, SCREEN_SIZE_BOT);
|
||||||
memset(TOP_SCREEN, 0, SCREEN_SIZE_TOP);
|
memset(TOP_SCREEN, 0, SCREEN_SIZE_TOP);
|
||||||
memcpy(BOT_SCREEN, buffer_b, SCREEN_SIZE_BOT);
|
|
||||||
memcpy(TOP_SCREEN, buffer_t, SCREEN_SIZE_TOP);
|
fvx_qwrite(filename, png, 0, png_size, NULL);
|
||||||
|
|
||||||
|
memcpy(BOT_SCREEN, buffer_bottom, SCREEN_SIZE_BOT);
|
||||||
|
memcpy(TOP_SCREEN, buffer_top, SCREEN_SIZE_TOP);
|
||||||
}
|
}
|
||||||
// what to do on error...?
|
// what to do on error...?
|
||||||
|
|
||||||
free(buffer);
|
free(buffer);
|
||||||
if (png_data) free(png_data);
|
free(png);
|
||||||
}
|
}
|
||||||
|
@ -1,3 +1,3 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
void CreateScreenshot();
|
void CreateScreenshot(void);
|
||||||
|
@ -2,8 +2,8 @@
|
|||||||
|
|
||||||
#include "common.h"
|
#include "common.h"
|
||||||
|
|
||||||
const u8 sig_nand_firm_retail[256];
|
extern const u8 sig_nand_firm_retail[256];
|
||||||
const u8 sig_nand_firm_retail_alt[256];
|
extern const u8 sig_nand_firm_retail_alt[256];
|
||||||
const u8 sig_nand_firm_dev[256];
|
extern const u8 sig_nand_firm_dev[256];
|
||||||
const u8 sig_nand_ncsd_retail[256];
|
extern const u8 sig_nand_ncsd_retail[256];
|
||||||
const u8 sig_nand_ncsd_dev[256];
|
extern const u8 sig_nand_ncsd_dev[256];
|
||||||
|
388
arm9/source/common/swkbd.c
Normal file
388
arm9/source/common/swkbd.c
Normal file
@ -0,0 +1,388 @@
|
|||||||
|
#include <stdarg.h>
|
||||||
|
|
||||||
|
#include "language.h"
|
||||||
|
#include "swkbd.h"
|
||||||
|
#include "timer.h"
|
||||||
|
#include "hid.h"
|
||||||
|
#include "utf.h"
|
||||||
|
|
||||||
|
|
||||||
|
static inline char to_uppercase(char c) {
|
||||||
|
if ((c >= 'a') && (c <= 'z')) c += ('A'-'a');
|
||||||
|
return c;
|
||||||
|
}
|
||||||
|
|
||||||
|
static bool BuildKeyboard(TouchBox* swkbd, const char* keys, const u8* layout) {
|
||||||
|
// count # of rows
|
||||||
|
u32 n_rows = 0;
|
||||||
|
for (u32 i = 0;; i++) {
|
||||||
|
if (layout[i] == 0) {
|
||||||
|
n_rows++;
|
||||||
|
if (layout[i+1] == 0) break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// set p_y start position
|
||||||
|
u32 height = (n_rows) ? (n_rows * SWKBD_STDKEY_HEIGHT) + ((n_rows-1) * SWKDB_KEY_SPACING) : 0;
|
||||||
|
u32 p_y = SCREEN_HEIGHT - height - SWKBD_STDKEY_HEIGHT - SWKDB_KEY_SPACING;
|
||||||
|
|
||||||
|
// set up the textbox
|
||||||
|
TouchBox* txtbox = swkbd;
|
||||||
|
txtbox->x = (SCREEN_WIDTH_BOT - SWKBD_TEXTBOX_WIDTH) / 2;
|
||||||
|
txtbox->y = p_y - 30;
|
||||||
|
txtbox->w = SWKBD_TEXTBOX_WIDTH;
|
||||||
|
txtbox->h = 30;
|
||||||
|
txtbox->id = KEY_TXTBOX;
|
||||||
|
|
||||||
|
// set button positions
|
||||||
|
TouchBox* tb = swkbd + 1;
|
||||||
|
for (u32 l = 0, k = 0; layout[l] != 0; ) {
|
||||||
|
// calculate width of current row
|
||||||
|
u32 n_keys = layout[l++];
|
||||||
|
u32 width = (n_keys * SWKBD_STDKEY_WIDTH) + ((n_keys-1) * SWKDB_KEY_SPACING);
|
||||||
|
for (u32 i = 0; layout[l+i] != 0; i++)
|
||||||
|
width = width - SWKBD_STDKEY_WIDTH + layout[l+i];
|
||||||
|
|
||||||
|
// set p_x start position
|
||||||
|
if (width > SCREEN_WIDTH_BOT) return false;
|
||||||
|
u32 p_x = (SCREEN_WIDTH_BOT - width) / 2;
|
||||||
|
|
||||||
|
// set up touchboxes
|
||||||
|
for (u32 i = 0; i < n_keys; i++) {
|
||||||
|
tb->id = keys[k++];
|
||||||
|
tb->x = p_x;
|
||||||
|
tb->y = p_y;
|
||||||
|
tb->w = ((tb->id >= 0x80) || (tb->id == (u32) ' ')) ? layout[l++] : SWKBD_STDKEY_WIDTH;
|
||||||
|
tb->h = SWKBD_STDKEY_HEIGHT;
|
||||||
|
|
||||||
|
p_x += tb->w + SWKDB_KEY_SPACING;
|
||||||
|
tb++;
|
||||||
|
}
|
||||||
|
|
||||||
|
// next row
|
||||||
|
if (layout[l++] != 0) return false;
|
||||||
|
p_y += SWKBD_STDKEY_HEIGHT + SWKDB_KEY_SPACING;
|
||||||
|
}
|
||||||
|
|
||||||
|
// set last touchbox zero (so the end can be detected)
|
||||||
|
memset(tb, 0, sizeof(TouchBox));
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
static void DrawKey(const TouchBox* key, const bool pressed, const u32 uppercase) {
|
||||||
|
const char* keystrs[] = { SWKBD_KEYSTR };
|
||||||
|
const u32 color = (pressed) ? COLOR_SWKBD_PRESSED :
|
||||||
|
(key->id == KEY_ENTER) ? COLOR_SWKBD_ENTER :
|
||||||
|
((key->id == KEY_CAPS) && (uppercase > 1)) ? COLOR_SWKBD_CAPS :
|
||||||
|
COLOR_SWKBD_NORMAL;
|
||||||
|
|
||||||
|
// don't even try to draw the textbox
|
||||||
|
if (key->id == KEY_TXTBOX) return;
|
||||||
|
|
||||||
|
char keystr[16];
|
||||||
|
if (key->id >= 0x80) snprintf(keystr, sizeof(keystr), "%s", keystrs[key->id - 0x80]);
|
||||||
|
else {
|
||||||
|
keystr[0] = (uppercase) ? to_uppercase(key->id) : key->id;
|
||||||
|
keystr[1] = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
const u32 width = GetDrawStringWidth(keystr);
|
||||||
|
const u32 f_offs_x = (key->w - width) / 2;
|
||||||
|
const u32 f_offs_y = (key->h - FONT_HEIGHT_EXT) / 2;
|
||||||
|
|
||||||
|
DrawRectangle(BOT_SCREEN, key->x, key->y, key->w, key->h, color);
|
||||||
|
DrawString(BOT_SCREEN, keystr, key->x + f_offs_x, key->y + f_offs_y, COLOR_SWKBD_CHARS, color);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void DrawKeyBoardBox(TouchBox* swkbd, u32 color) {
|
||||||
|
// we need to make sure to skip the textbox here(first entry)
|
||||||
|
|
||||||
|
// calculate / draw keyboard box
|
||||||
|
u16 x0 = SCREEN_WIDTH_BOT, x1 = 0;
|
||||||
|
u16 y0 = SCREEN_HEIGHT, y1 = 0;
|
||||||
|
for (TouchBox* tb = swkbd + 1; tb->id != 0; tb++) {
|
||||||
|
if (tb->x < x0) x0 = tb->x;
|
||||||
|
if (tb->y < y0) y0 = tb->y;
|
||||||
|
if ((tb->x + tb->w) > x1) x1 = tb->x + tb->w;
|
||||||
|
if ((tb->y + tb->h) > y1) y1 = tb->y + tb->h;
|
||||||
|
}
|
||||||
|
DrawRectangle(BOT_SCREEN, 0, y0-1, SCREEN_WIDTH_BOT, y1-y0+2, COLOR_STD_BG);
|
||||||
|
DrawRectangle(BOT_SCREEN, x0-1, y0-1, x1-x0+2, y1-y0+2, color);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void DrawKeyBoard(TouchBox* swkbd, const u32 uppercase) {
|
||||||
|
// we need to make sure to skip the textbox here(first entry)
|
||||||
|
|
||||||
|
// draw keyboard
|
||||||
|
for (TouchBox* tb = swkbd + 1; tb->id != 0; tb++) {
|
||||||
|
DrawKey(tb, false, uppercase);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static void DrawTextBox(const TouchBox* txtbox, const char* inputstr, const u32 cursor, u32* scroll) {
|
||||||
|
const u32 input_shown_length = (txtbox->w / FONT_WIDTH_EXT) - 2;
|
||||||
|
const u32 inputstr_size = strlen(inputstr); // we rely on a zero terminated string
|
||||||
|
const u16 x = txtbox->x;
|
||||||
|
const u16 y = txtbox->y;
|
||||||
|
|
||||||
|
// fix scroll
|
||||||
|
if (cursor < *scroll) {
|
||||||
|
*scroll = cursor;
|
||||||
|
} else {
|
||||||
|
int scroll_adjust = -input_shown_length;
|
||||||
|
for (u32 i = *scroll; i < cursor; i++) {
|
||||||
|
if (i >= inputstr_size || (inputstr[i] & 0xC0) != 0x80) scroll_adjust++;
|
||||||
|
}
|
||||||
|
|
||||||
|
for (int i = 0; i < scroll_adjust; i++)
|
||||||
|
*scroll += *scroll >= inputstr_size ? 1 : GetCharSize(inputstr + *scroll);
|
||||||
|
}
|
||||||
|
|
||||||
|
u32 input_shown_size = 0;
|
||||||
|
for (u32 i = 0; i < input_shown_length || (*scroll + input_shown_size < inputstr_size && (inputstr[*scroll + input_shown_size] & 0xC0) == 0x80); input_shown_size++) {
|
||||||
|
if (*scroll + input_shown_size >= inputstr_size || (inputstr[*scroll + input_shown_size] & 0xC0) != 0x80) i++;
|
||||||
|
}
|
||||||
|
|
||||||
|
// draw input string
|
||||||
|
DrawStringF(BOT_SCREEN, x, y, COLOR_STD_FONT, COLOR_STD_BG, "%c%-*.*s%c",
|
||||||
|
(*scroll) ? '<' : '|',
|
||||||
|
(int) input_shown_size,
|
||||||
|
(int) input_shown_size,
|
||||||
|
(*scroll > inputstr_size) ? "" : inputstr + *scroll,
|
||||||
|
(inputstr_size - (s32) *scroll > input_shown_size) ? '>' : '|'
|
||||||
|
);
|
||||||
|
|
||||||
|
// draw cursor
|
||||||
|
u16 cpos = 0;
|
||||||
|
for (u16 i = *scroll; i < cursor; i++) {
|
||||||
|
if (i >= inputstr_size || (inputstr[i] & 0xC0) != 0x80) cpos++;
|
||||||
|
}
|
||||||
|
|
||||||
|
DrawStringF(BOT_SCREEN, x-(FONT_WIDTH_EXT/2), y+10, COLOR_STD_FONT, COLOR_STD_BG, "%-*.*s^%-*.*s",
|
||||||
|
(int) (1 + cpos),
|
||||||
|
(int) (1 + cpos),
|
||||||
|
"",
|
||||||
|
(int) (input_shown_length - cpos),
|
||||||
|
(int) (input_shown_length - cpos),
|
||||||
|
""
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void MoveTextBoxCursor(const TouchBox* txtbox, const char* inputstr, const u32 max_size, u32* cursor, u32* scroll) {
|
||||||
|
const u32 input_shown = (txtbox->w / FONT_WIDTH_EXT) - 2;
|
||||||
|
const u64 scroll_cooldown = 144;
|
||||||
|
u64 timer = timer_start();
|
||||||
|
u32 id = 0;
|
||||||
|
u16 x, y;
|
||||||
|
|
||||||
|
// process touch input
|
||||||
|
while(HID_ReadTouchState(&x, &y)) {
|
||||||
|
const TouchBox* tb = TouchBoxGet(&id, x, y, txtbox, 0);
|
||||||
|
if (id == KEY_TXTBOX) {
|
||||||
|
u16 x_tb = x - tb->x;
|
||||||
|
|
||||||
|
const u32 inputstr_size = strlen(inputstr);
|
||||||
|
const u16 cpos_x = (x_tb < (FONT_WIDTH_EXT/2)) ? 0 : (x_tb - (FONT_WIDTH_EXT/2)) / FONT_WIDTH_EXT;
|
||||||
|
u16 cpos_length = 0;
|
||||||
|
u16 cpos_size = 0;
|
||||||
|
while ((cpos_length < cpos_x && cpos_length < input_shown) || (*scroll + cpos_size < inputstr_size && (inputstr[*scroll + cpos_size] & 0xC0) == 0x80)) {
|
||||||
|
if (*scroll + cpos_size >= inputstr_size || (inputstr[*scroll + cpos_size] & 0xC0) != 0x80) cpos_length++;
|
||||||
|
cpos_size++;
|
||||||
|
}
|
||||||
|
|
||||||
|
u32 cursor_next = *scroll + cpos_size;
|
||||||
|
// move cursor to position pointed to
|
||||||
|
if (*cursor != cursor_next) {
|
||||||
|
if (cursor_next < max_size) *cursor = cursor_next;
|
||||||
|
DrawTextBox(txtbox, inputstr, *cursor, scroll);
|
||||||
|
timer = timer_start();
|
||||||
|
}
|
||||||
|
// move beyound visible field
|
||||||
|
if (timer_msec(timer) >= scroll_cooldown) {
|
||||||
|
if ((cpos_length == 0) && (*scroll > 0))
|
||||||
|
*scroll -= GetPrevCharSize(inputstr + *scroll);
|
||||||
|
else if ((cpos_length >= input_shown) && (*cursor < (max_size-1)))
|
||||||
|
*scroll += GetCharSize(inputstr + *scroll);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static char KeyboardWait(TouchBox* swkbd, bool uppercase) {
|
||||||
|
u32 id = 0;
|
||||||
|
u16 x, y;
|
||||||
|
|
||||||
|
// wait for touch input (handle key input, too)
|
||||||
|
while (true) {
|
||||||
|
u32 pressed = InputWait(0);
|
||||||
|
if (pressed & BUTTON_B) return KEY_ESCAPE;
|
||||||
|
else if (pressed & BUTTON_A) return KEY_ENTER;
|
||||||
|
else if (pressed & BUTTON_X) return KEY_BKSPC;
|
||||||
|
else if (pressed & BUTTON_Y) return KEY_INSERT;
|
||||||
|
else if (pressed & BUTTON_R1) return KEY_CAPS;
|
||||||
|
else if (pressed & BUTTON_RIGHT) return KEY_RIGHT;
|
||||||
|
else if (pressed & BUTTON_LEFT) return KEY_LEFT;
|
||||||
|
else if (pressed & BUTTON_SELECT) return KEY_SWITCH;
|
||||||
|
else if (pressed & BUTTON_TOUCH) break;
|
||||||
|
}
|
||||||
|
|
||||||
|
// process touch input
|
||||||
|
while(HID_ReadTouchState(&x, &y)) {
|
||||||
|
const TouchBox* tb = TouchBoxGet(&id, x, y, swkbd, 0);
|
||||||
|
if (tb) {
|
||||||
|
if (id == KEY_TXTBOX) break; // immediately break on textbox
|
||||||
|
DrawKey(tb, true, uppercase);
|
||||||
|
while(HID_ReadTouchState(&x, &y) && (tb == TouchBoxGet(NULL, x, y, swkbd, 0)));
|
||||||
|
DrawKey(tb, false, uppercase);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return (uppercase) ? to_uppercase((char) id) : (char) id;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool ShowKeyboard(char* inputstr, const u32 max_size, const char *format, ...) {
|
||||||
|
static const char keys_alphabet[] = { SWKBD_KEYS_ALPHABET };
|
||||||
|
static const char keys_special[] = { SWKBD_KEYS_SPECIAL };
|
||||||
|
static const char keys_numpad[] = { SWKBD_KEYS_NUMPAD };
|
||||||
|
static const u8 layout_alphabet[] = { SWKBD_LAYOUT_ALPHABET };
|
||||||
|
static const u8 layout_special[] = { SWKBD_LAYOUT_SPECIAL };
|
||||||
|
static const u8 layout_numpad[] = { SWKBD_LAYOUT_NUMPAD };
|
||||||
|
TouchBox swkbd_alphabet[64];
|
||||||
|
TouchBox swkbd_special[32];
|
||||||
|
TouchBox swkbd_numpad[32];
|
||||||
|
TouchBox* textbox = swkbd_alphabet; // always use this textbox
|
||||||
|
|
||||||
|
static bool show_instr = true;
|
||||||
|
const char* instr = STR_KEYBOARD_CONTROLS_DETAILS;
|
||||||
|
if (show_instr) {
|
||||||
|
ShowPrompt(false, "%s", instr);
|
||||||
|
show_instr = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
// generate keyboards
|
||||||
|
if (!BuildKeyboard(swkbd_alphabet, keys_alphabet, layout_alphabet)) return false;
|
||||||
|
if (!BuildKeyboard(swkbd_special, keys_special, layout_special)) return false;
|
||||||
|
if (!BuildKeyboard(swkbd_numpad, keys_numpad, layout_numpad)) return false;
|
||||||
|
|
||||||
|
// (instructional) text
|
||||||
|
char str[512]; // arbitrary limit, should be more than enough
|
||||||
|
va_list va;
|
||||||
|
va_start(va, format);
|
||||||
|
vsnprintf(str, sizeof(str), format, va);
|
||||||
|
va_end(va);
|
||||||
|
u32 str_width = GetDrawStringWidth(str);
|
||||||
|
if (str_width < (24 * FONT_WIDTH_EXT)) str_width = 24 * FONT_WIDTH_EXT;
|
||||||
|
u32 str_x = (str_width >= SCREEN_WIDTH_BOT) ? 0 : (SCREEN_WIDTH_BOT - str_width) / 2;
|
||||||
|
ClearScreen(BOT_SCREEN, COLOR_STD_BG);
|
||||||
|
DrawStringF(BOT_SCREEN, str_x, 20, COLOR_STD_FONT, COLOR_STD_BG, "%s", str);
|
||||||
|
|
||||||
|
// wait for all keys released
|
||||||
|
while (HID_ReadState() & BUTTON_ANY);
|
||||||
|
|
||||||
|
// handle keyboard
|
||||||
|
u32 uppercase = 0; // 1 -> uppercase once, 2 -> uppercase always
|
||||||
|
u32 scroll = 0;
|
||||||
|
u32 cursor = 0;
|
||||||
|
u32 inputstr_size = strnlen(inputstr, max_size);
|
||||||
|
TouchBox* swkbd_prev = NULL;
|
||||||
|
TouchBox* swkbd = swkbd_alphabet;
|
||||||
|
bool ret = false;
|
||||||
|
while (true) {
|
||||||
|
// draw keyboard if required
|
||||||
|
if (swkbd != swkbd_prev) {
|
||||||
|
DrawKeyBoardBox(swkbd, COLOR_SWKBD_BOX);
|
||||||
|
DrawKeyBoard(swkbd, uppercase);
|
||||||
|
DrawTextBox(textbox, inputstr, cursor, &scroll);
|
||||||
|
swkbd_prev = swkbd;
|
||||||
|
}
|
||||||
|
|
||||||
|
// handle user input
|
||||||
|
char key = KeyboardWait(swkbd, uppercase);
|
||||||
|
if (key == KEY_INSERT) key = ' '; // impromptu replacement
|
||||||
|
if (key == KEY_TXTBOX) {
|
||||||
|
MoveTextBoxCursor(textbox, inputstr, max_size, &cursor, &scroll);
|
||||||
|
} else if (key == KEY_CAPS) {
|
||||||
|
uppercase = (uppercase + 1) % 3;
|
||||||
|
DrawKeyBoard(swkbd, uppercase);
|
||||||
|
continue;
|
||||||
|
} else if (key == KEY_ENTER) {
|
||||||
|
ret = true;
|
||||||
|
break;
|
||||||
|
} else if (key == KEY_ESCAPE) {
|
||||||
|
break;
|
||||||
|
} else if (key == KEY_BKSPC) {
|
||||||
|
if (cursor) {
|
||||||
|
int size = GetPrevCharSize(inputstr + cursor);
|
||||||
|
if (cursor <= inputstr_size) {
|
||||||
|
memmove(inputstr + cursor - size, inputstr + cursor, inputstr_size - cursor + size);
|
||||||
|
inputstr_size -= size;
|
||||||
|
}
|
||||||
|
cursor -= size;
|
||||||
|
}
|
||||||
|
} else if (key == KEY_LEFT) {
|
||||||
|
if (cursor) cursor -= GetPrevCharSize(inputstr + cursor);
|
||||||
|
} else if (key == KEY_RIGHT) {
|
||||||
|
int size = cursor > inputstr_size ? 1 : GetCharSize(inputstr + cursor);
|
||||||
|
if (cursor + size < max_size) cursor += size;
|
||||||
|
} else if (key == KEY_ALPHA) {
|
||||||
|
swkbd = swkbd_alphabet;
|
||||||
|
} else if (key == KEY_SPECIAL) {
|
||||||
|
swkbd = swkbd_special;
|
||||||
|
} else if (key == KEY_NUMPAD) {
|
||||||
|
swkbd = swkbd_numpad;
|
||||||
|
} else if (key == KEY_SWITCH) {
|
||||||
|
ClearScreen(BOT_SCREEN, COLOR_STD_BG);
|
||||||
|
return ShowStringPrompt(inputstr, max_size, "%s", str);
|
||||||
|
} else if (key == KEY_UNICODE) {
|
||||||
|
if (cursor > 3 && cursor <= inputstr_size) {
|
||||||
|
u16 codepoint = 0;
|
||||||
|
for (char *c = inputstr + cursor - 4; c < inputstr + cursor; c++) {
|
||||||
|
if ((*c >= '0' && *c <= '9') || (*c >= 'A' && *c <= 'F') || (*c >= 'a' && *c <= 'f')) {
|
||||||
|
codepoint <<= 4;
|
||||||
|
codepoint |= *c - (*c <= '9' ? '0' : ((*c <= 'F' ? 'A' : 'a') - 10));
|
||||||
|
} else {
|
||||||
|
codepoint = 0;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if(codepoint != 0) {
|
||||||
|
char character[5] = {0};
|
||||||
|
u16 input[2] = {codepoint, 0};
|
||||||
|
utf16_to_utf8((u8*)character, input, 4, 1);
|
||||||
|
|
||||||
|
u32 char_size = GetCharSize(character);
|
||||||
|
memmove(inputstr + cursor - 4 + char_size, inputstr + cursor, max_size - cursor + 4 - char_size);
|
||||||
|
memcpy(inputstr + cursor - 4, character, char_size);
|
||||||
|
cursor -= 4 - char_size;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else if (key && (key < 0x80)) {
|
||||||
|
if ((cursor < (max_size-1)) && (inputstr_size < max_size)) {
|
||||||
|
// pad string (if cursor beyound string size)
|
||||||
|
while (inputstr_size < cursor) {
|
||||||
|
inputstr[inputstr_size++] = ' ';
|
||||||
|
inputstr[inputstr_size] = '\0';
|
||||||
|
}
|
||||||
|
// make room
|
||||||
|
if (inputstr_size < (max_size-1)) { // only if there is still room
|
||||||
|
memmove(inputstr + cursor + 1, inputstr + cursor, max_size - cursor - 1);
|
||||||
|
inputstr_size++;
|
||||||
|
}
|
||||||
|
// insert char
|
||||||
|
inputstr[cursor++] = key;
|
||||||
|
}
|
||||||
|
if (uppercase == 1) {
|
||||||
|
uppercase = 0;
|
||||||
|
DrawKeyBoard(swkbd, uppercase);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// update text
|
||||||
|
DrawTextBox(textbox, inputstr, cursor, &scroll);
|
||||||
|
}
|
||||||
|
|
||||||
|
ClearScreen(BOT_SCREEN, COLOR_STD_BG);
|
||||||
|
return ret;
|
||||||
|
}
|
89
arm9/source/common/swkbd.h
Normal file
89
arm9/source/common/swkbd.h
Normal file
@ -0,0 +1,89 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include "common.h"
|
||||||
|
#include "ui.h"
|
||||||
|
#include "touchcal.h"
|
||||||
|
|
||||||
|
|
||||||
|
// special key ids
|
||||||
|
enum {
|
||||||
|
KEY_DUMMY = 0x80,
|
||||||
|
KEY_BKSPC = 0x81,
|
||||||
|
KEY_INSERT = 0x82,
|
||||||
|
KEY_ENTER = 0x83,
|
||||||
|
KEY_CAPS = 0x84,
|
||||||
|
KEY_SPECIAL = 0x85,
|
||||||
|
KEY_NUMPAD = 0x86,
|
||||||
|
KEY_ALPHA = 0x87,
|
||||||
|
KEY_LEFT = 0x88,
|
||||||
|
KEY_RIGHT = 0x89,
|
||||||
|
KEY_ESCAPE = 0x8A,
|
||||||
|
KEY_SWITCH = 0x8B,
|
||||||
|
KEY_UNICODE = 0x8C,
|
||||||
|
KEY_TXTBOX = 0xFF
|
||||||
|
};
|
||||||
|
|
||||||
|
// special key strings
|
||||||
|
#define SWKBD_KEYSTR "", "DEL", "INS", "SUBMIT", "CAPS", "#$@", "123", "ABC", "←", "→", "ESC", "SWITCH", "U+"
|
||||||
|
|
||||||
|
#define COLOR_SWKBD_NORMAL COLOR_GREY
|
||||||
|
#define COLOR_SWKBD_PRESSED COLOR_LIGHTGREY
|
||||||
|
#define COLOR_SWKBD_BOX COLOR_DARKGREY
|
||||||
|
#define COLOR_SWKBD_CHARS COLOR_BLACK
|
||||||
|
#define COLOR_SWKBD_ENTER COLOR_TINTEDBLUE
|
||||||
|
#define COLOR_SWKBD_CAPS COLOR_TINTEDYELLOW
|
||||||
|
|
||||||
|
#define SWKBD_TEXTBOX_WIDTH 240
|
||||||
|
#define SWKBD_STDKEY_WIDTH 18
|
||||||
|
#define SWKBD_STDKEY_HEIGHT 20
|
||||||
|
#define SWKDB_KEY_SPACING 1
|
||||||
|
|
||||||
|
#define SWKBD_KEYS_ALPHABET \
|
||||||
|
'1', '2', '3', '4', '5', '6', '7', '8', '9', '0', '+', '-', KEY_BKSPC, \
|
||||||
|
'q', 'w', 'e', 'r', 't', 'y', 'u', 'i', 'o', 'p', '&', KEY_ENTER, \
|
||||||
|
'a', 's', 'd', 'f', 'g', 'h', 'j', 'k', 'l', '(', ')', '[', ']', \
|
||||||
|
'z', 'x', 'c', 'v', 'b', 'n', 'm', ',', '.', '_', '#', '!', \
|
||||||
|
KEY_CAPS, ' ', KEY_NUMPAD, KEY_SPECIAL, KEY_LEFT, KEY_RIGHT
|
||||||
|
|
||||||
|
#define SWKBD_KEYS_SPECIAL \
|
||||||
|
'(', ')', '{', '}', '[', ']', \
|
||||||
|
'.', ',', '?', '!', '`', '\'', \
|
||||||
|
'^', '*', '+', '-', '_', '=', \
|
||||||
|
'@', '#', '$', '%', '&', '~', \
|
||||||
|
KEY_ALPHA, ' ', KEY_BKSPC
|
||||||
|
|
||||||
|
#define SWKBD_KEYS_NUMPAD \
|
||||||
|
'7', '8', '9', 'F', 'E', \
|
||||||
|
'4', '5', '6', 'D', 'C', \
|
||||||
|
'3', '2', '1', 'B', 'A', \
|
||||||
|
'0', '.', '_', KEY_LEFT, KEY_RIGHT, \
|
||||||
|
KEY_ALPHA, KEY_UNICODE, ' ', KEY_BKSPC
|
||||||
|
|
||||||
|
// offset, num of keys in row, width of special keys (...), 0
|
||||||
|
#define SWKBD_LAYOUT_ALPHABET \
|
||||||
|
13, 32, 0, \
|
||||||
|
12, 51, 0, \
|
||||||
|
13, 0, \
|
||||||
|
12, 0, \
|
||||||
|
6, 32, 123, 32, 32, 18, 18, 0, \
|
||||||
|
0
|
||||||
|
|
||||||
|
#define SWKBD_LAYOUT_SPECIAL \
|
||||||
|
6, 0, \
|
||||||
|
6, 0, \
|
||||||
|
6, 0, \
|
||||||
|
6, 0, \
|
||||||
|
3, 32, 46, 32, 0, \
|
||||||
|
0
|
||||||
|
|
||||||
|
#define SWKBD_LAYOUT_NUMPAD \
|
||||||
|
5, 0, \
|
||||||
|
5, 0, \
|
||||||
|
5, 0, \
|
||||||
|
5, 18, 18, 0, \
|
||||||
|
4, 20, 20, 31, 20, 0, \
|
||||||
|
0
|
||||||
|
|
||||||
|
|
||||||
|
#define ShowKeyboardOrPrompt (TouchIsCalibrated() ? ShowKeyboard : ShowStringPrompt)
|
||||||
|
bool PRINTF_ARGS(3) ShowKeyboard(char* inputstr, u32 max_size, const char *format, ...);
|
@ -7,7 +7,7 @@ u64 timer_start( void ) {
|
|||||||
if (!(*TIMER_CNT0 & *TIMER_CNT1 & *TIMER_CNT2 & *TIMER_CNT3 & TIMER_ACTIVE) ||
|
if (!(*TIMER_CNT0 & *TIMER_CNT1 & *TIMER_CNT2 & *TIMER_CNT3 & TIMER_ACTIVE) ||
|
||||||
!(*TIMER_CNT1 & *TIMER_CNT2 & *TIMER_CNT3 & TIMER_COUNT_UP))
|
!(*TIMER_CNT1 & *TIMER_CNT2 & *TIMER_CNT3 & TIMER_COUNT_UP))
|
||||||
timer_init = true;
|
timer_init = true;
|
||||||
|
|
||||||
if (timer_init) {
|
if (timer_init) {
|
||||||
// deactivate, then reset timers
|
// deactivate, then reset timers
|
||||||
*TIMER_CNT0 = 0;
|
*TIMER_CNT0 = 0;
|
||||||
@ -17,7 +17,7 @@ u64 timer_start( void ) {
|
|||||||
// start timers
|
// start timers
|
||||||
*TIMER_CNT0 = TIMER_ACTIVE;
|
*TIMER_CNT0 = TIMER_ACTIVE;
|
||||||
*TIMER_CNT1 = *TIMER_CNT2 = *TIMER_CNT3 = TIMER_ACTIVE | TIMER_COUNT_UP;
|
*TIMER_CNT1 = *TIMER_CNT2 = *TIMER_CNT3 = TIMER_ACTIVE | TIMER_COUNT_UP;
|
||||||
|
|
||||||
// timer initialized
|
// timer initialized
|
||||||
timer_init = false;
|
timer_init = false;
|
||||||
}
|
}
|
||||||
|
141
arm9/source/common/touchcal.c
Normal file
141
arm9/source/common/touchcal.c
Normal file
@ -0,0 +1,141 @@
|
|||||||
|
#include "touchcal.h"
|
||||||
|
#include "ui.h"
|
||||||
|
#include "hid.h"
|
||||||
|
#include "crc16.h"
|
||||||
|
#include "language.h"
|
||||||
|
#include "spiflash.h"
|
||||||
|
#include "support.h"
|
||||||
|
|
||||||
|
|
||||||
|
#define TOUCH_CALIB_FILENAME "gm9calib.bin"
|
||||||
|
|
||||||
|
|
||||||
|
static const HID_CalibrationData default_calib = {
|
||||||
|
.screen_x = 0,
|
||||||
|
.screen_y = 0,
|
||||||
|
.ts_raw = 0
|
||||||
|
// ^ wrong: in my console it's 0x780086
|
||||||
|
// but this is very much console dependent
|
||||||
|
// so it's better to go with a sane default
|
||||||
|
};
|
||||||
|
|
||||||
|
static bool is_calibrated = false;
|
||||||
|
|
||||||
|
|
||||||
|
static bool SetCalibrationDefaults(void)
|
||||||
|
{
|
||||||
|
// Hardcoding this isn't ideal but it's better than
|
||||||
|
// leaving the system without any state to work with
|
||||||
|
is_calibrated = false; // no, this is not proper calibration
|
||||||
|
return HID_SetCalibrationData(&default_calib, 1, SCREEN_WIDTH_BOT, SCREEN_HEIGHT);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool ShowTouchCalibrationDialog(void)
|
||||||
|
{
|
||||||
|
static const u32 dot_positions[][2] = {
|
||||||
|
{16, 16},
|
||||||
|
{SCREEN_WIDTH_BOT - 16, SCREEN_HEIGHT - 16},
|
||||||
|
{16, SCREEN_HEIGHT - 16},
|
||||||
|
{SCREEN_WIDTH_BOT - 16, 16},
|
||||||
|
};
|
||||||
|
|
||||||
|
HID_CalibrationData calibrations[countof(dot_positions)];
|
||||||
|
for (u32 i = 0; i < countof(dot_positions); i++) {
|
||||||
|
calibrations[i].screen_x = dot_positions[i][0];
|
||||||
|
calibrations[i].screen_y = dot_positions[i][1];
|
||||||
|
}
|
||||||
|
|
||||||
|
// clear screen, draw instructions
|
||||||
|
ClearScreen(BOT_SCREEN, COLOR_STD_BG);
|
||||||
|
DrawStringCenter(BOT_SCREEN, COLOR_STD_FONT, COLOR_STD_BG, "%s",
|
||||||
|
STR_TOUCH_CROSSHAIRS_TO_CALIBRATE_TOUCHSCREEN_USE_STYLUS);
|
||||||
|
|
||||||
|
// set calibration defaults
|
||||||
|
SetCalibrationDefaults();
|
||||||
|
|
||||||
|
// actual calibration
|
||||||
|
for (u32 current_dot = 0; current_dot < countof(dot_positions); current_dot++) {
|
||||||
|
// draw four crosshairs
|
||||||
|
for (u32 i = 0; i < countof(dot_positions); i++) {
|
||||||
|
int color_cross = (i < current_dot) ? COLOR_BRIGHTGREEN : (i == current_dot) ? COLOR_RED : COLOR_STD_FONT;
|
||||||
|
for (u32 r = 2; r < 8; r++) {
|
||||||
|
DrawPixel(BOT_SCREEN, dot_positions[i][0] + 0, dot_positions[i][1] + r, color_cross);
|
||||||
|
DrawPixel(BOT_SCREEN, dot_positions[i][0] + r, dot_positions[i][1] + 0, color_cross);
|
||||||
|
DrawPixel(BOT_SCREEN, dot_positions[i][0] + 0, dot_positions[i][1] - r, color_cross);
|
||||||
|
DrawPixel(BOT_SCREEN, dot_positions[i][0] - r, dot_positions[i][1] + 0, color_cross);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// wait for input, store calibration data
|
||||||
|
while (1) {
|
||||||
|
u32 pressed = InputWait(0);
|
||||||
|
if (pressed & BUTTON_B) {
|
||||||
|
return false;
|
||||||
|
} else if (pressed & BUTTON_TOUCH) {
|
||||||
|
calibrations[current_dot].ts_raw = HID_ReadRawTouchState();
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
is_calibrated = HID_SetCalibrationData(calibrations, countof(dot_positions), SCREEN_WIDTH_BOT, SCREEN_HEIGHT);
|
||||||
|
if (is_calibrated) { // store calibration data in a file
|
||||||
|
SaveSupportFile(TOUCH_CALIB_FILENAME, calibrations, sizeof(calibrations));
|
||||||
|
}
|
||||||
|
return is_calibrated;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool CalibrateTouchFromSupportFile(void) {
|
||||||
|
HID_CalibrationData calibrations[10];
|
||||||
|
size_t size = LoadSupportFile(TOUCH_CALIB_FILENAME, calibrations, sizeof(calibrations));
|
||||||
|
u32 n_dots = size / sizeof(HID_CalibrationData);
|
||||||
|
|
||||||
|
is_calibrated = (n_dots == 0) ? false :
|
||||||
|
HID_SetCalibrationData(calibrations, n_dots, SCREEN_WIDTH_BOT, SCREEN_HEIGHT);
|
||||||
|
return is_calibrated;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool CalibrateTouchFromFlash(void) {
|
||||||
|
HID_CalibrationData data[2];
|
||||||
|
|
||||||
|
// set calibration defaults
|
||||||
|
SetCalibrationDefaults();
|
||||||
|
|
||||||
|
// check SPIflash status
|
||||||
|
if (!spiflash_get_status())
|
||||||
|
return false;
|
||||||
|
|
||||||
|
// check NVRAM console ID
|
||||||
|
u32 console_id = 0;
|
||||||
|
if (!spiflash_read(0x001C, 4, (u8*)&console_id))
|
||||||
|
return false;
|
||||||
|
|
||||||
|
if (((console_id >> 8) & 0xFF) != 0x57)
|
||||||
|
return false; // not a 3DS
|
||||||
|
|
||||||
|
// read and check DS fw user settings
|
||||||
|
// see: https://problemkaputt.de/gbatek.htm#dsfirmwareusersettings
|
||||||
|
u32 fw_usercfg_buf[0x100 / 0x4];
|
||||||
|
u8* fw_usercfg = (u8*) fw_usercfg_buf;
|
||||||
|
if (!spiflash_read(0x1FE00, 0x100, fw_usercfg))
|
||||||
|
return false;
|
||||||
|
|
||||||
|
if (getle16(fw_usercfg + 0x72) != crc16_quick(fw_usercfg, 0x70))
|
||||||
|
return false;
|
||||||
|
|
||||||
|
// get touchscreen calibration data from user settings
|
||||||
|
u8 *ts_data = fw_usercfg + 0x58;
|
||||||
|
for (int i = 0; i < 2; i++) {
|
||||||
|
int base = i * 6;
|
||||||
|
data[i].ts_raw = ts_data[base + 1] << 24 | ts_data[base + 0] << 16 | ts_data[base + 3] << 8 | ts_data[base + 2];
|
||||||
|
data[i].screen_x = (((int)ts_data[base + 4]) * SCREEN_WIDTH_BOT) / 256;
|
||||||
|
data[i].screen_y = (((int)ts_data[base + 5]) * SCREEN_HEIGHT) / 192;
|
||||||
|
}
|
||||||
|
|
||||||
|
is_calibrated = HID_SetCalibrationData(data, 2, SCREEN_WIDTH_BOT, SCREEN_HEIGHT);
|
||||||
|
return is_calibrated;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool TouchIsCalibrated(void) {
|
||||||
|
return is_calibrated;
|
||||||
|
}
|
8
arm9/source/common/touchcal.h
Normal file
8
arm9/source/common/touchcal.h
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include "common.h"
|
||||||
|
|
||||||
|
bool ShowTouchCalibrationDialog(void);
|
||||||
|
bool CalibrateTouchFromSupportFile(void);
|
||||||
|
bool CalibrateTouchFromFlash(void);
|
||||||
|
bool TouchIsCalibrated(void);
|
File diff suppressed because it is too large
Load Diff
@ -7,9 +7,10 @@
|
|||||||
#include <vram.h>
|
#include <vram.h>
|
||||||
#include "common.h"
|
#include "common.h"
|
||||||
#include "colors.h"
|
#include "colors.h"
|
||||||
|
#include "fsdir.h" // only required for ShowFileScrollPrompt
|
||||||
|
|
||||||
|
|
||||||
#define BYTES_PER_PIXEL 3
|
#define BYTES_PER_PIXEL 2
|
||||||
#define SCREEN_HEIGHT 240
|
#define SCREEN_HEIGHT 240
|
||||||
#define SCREEN_WIDTH(s) ((s == TOP_SCREEN) ? SCREEN_WIDTH_TOP : SCREEN_WIDTH_BOT)
|
#define SCREEN_WIDTH(s) ((s == TOP_SCREEN) ? SCREEN_WIDTH_TOP : SCREEN_WIDTH_BOT)
|
||||||
#define SCREEN_WIDTH_TOP 400
|
#define SCREEN_WIDTH_TOP 400
|
||||||
@ -20,8 +21,13 @@
|
|||||||
#define FONT_WIDTH_EXT GetFontWidth()
|
#define FONT_WIDTH_EXT GetFontWidth()
|
||||||
#define FONT_HEIGHT_EXT GetFontHeight()
|
#define FONT_HEIGHT_EXT GetFontHeight()
|
||||||
|
|
||||||
#define TOP_SCREEN ((u8*)VRAM_TOP_LA)
|
#define UTF_MAX_BYTES_PER_RUNE 4
|
||||||
#define BOT_SCREEN ((u8*)VRAM_BOT_A)
|
#define UTF_BUFFER_BYTESIZE(rune_count) (((rune_count) + 1) * UTF_MAX_BYTES_PER_RUNE)
|
||||||
|
|
||||||
|
#define PRINTF_ARGS(n) __attribute__ ((format (printf, (n), (n) + 1)))
|
||||||
|
|
||||||
|
#define TOP_SCREEN ((u16*)VRAM_TOP_LA)
|
||||||
|
#define BOT_SCREEN ((u16*)VRAM_BOT_A)
|
||||||
|
|
||||||
#ifdef SWITCH_SCREENS
|
#ifdef SWITCH_SCREENS
|
||||||
#define MAIN_SCREEN TOP_SCREEN
|
#define MAIN_SCREEN TOP_SCREEN
|
||||||
@ -39,44 +45,73 @@
|
|||||||
|
|
||||||
|
|
||||||
#ifndef AUTO_UNLOCK
|
#ifndef AUTO_UNLOCK
|
||||||
bool ShowUnlockSequence(u32 seqlvl, const char *format, ...);
|
bool PRINTF_ARGS(2) ShowUnlockSequence(u32 seqlvl, const char *format, ...);
|
||||||
#else
|
#else
|
||||||
#define ShowUnlockSequence ShowPrompt
|
#define ShowUnlockSequence ShowPrompt
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
u8* GetFontFromPbm(const void* pbm, const u32 pbm_size, u32* w, u32* h);
|
const u8* GetFontFromPbm(const void* pbm, const u32 riff_size, u32* w, u32* h);
|
||||||
bool SetFontFromPbm(const void* pbm, const u32 pbm_size);
|
const u8* GetFontFromRiff(const void* riff, const u32 riff_size, u32* w, u32* h, u16* count);
|
||||||
|
bool SetFont(const void* font, const u32 font_size);
|
||||||
|
|
||||||
void ClearScreen(unsigned char *screen, int color);
|
u16 GetColor(const u16 *screen, int x, int y);
|
||||||
void ClearScreenF(bool clear_main, bool clear_alt, int color);
|
|
||||||
void DrawRectangle(u8* screen, int x, int y, int width, int height, int color);
|
|
||||||
void DrawBitmap(u8* screen, int x, int y, int w, int h, u8* bitmap);
|
|
||||||
void DrawQrCode(u8* screen, u8* qrcode);
|
|
||||||
|
|
||||||
void DrawCharacter(unsigned char *screen, int character, int x, int y, int color, int bgcolor);
|
void ClearScreen(u16 *screen, u32 color);
|
||||||
void DrawString(unsigned char *screen, const char *str, int x, int y, int color, int bgcolor, bool fix_utf8);
|
void ClearScreenF(bool clear_main, bool clear_alt, u32 color);
|
||||||
void DrawStringF(unsigned char *screen, int x, int y, int color, int bgcolor, const char *format, ...);
|
void DrawPixel(u16 *screen, int x, int y, u32 color);
|
||||||
void DrawStringCenter(u8* screen, int color, int bgcolor, const char *format, ...);
|
void DrawRectangle(u16 *screen, int x, int y, u32 width, u32 height, u32 color);
|
||||||
|
void DrawBitmap(u16 *screen, int x, int y, u32 w, u32 h, const u16* bitmap);
|
||||||
|
void DrawQrCode(u16 *screen, const u8* qrcode);
|
||||||
|
|
||||||
|
void DrawCharacter(u16 *screen, u32 character, int x, int y, u32 color, u32 bgcolor);
|
||||||
|
void DrawString(u16 *screen, const char *str, int x, int y, u32 color, u32 bgcolor);
|
||||||
|
void PRINTF_ARGS(6) DrawStringF(u16 *screen, int x, int y, u32 color, u32 bgcolor, const char *format, ...);
|
||||||
|
void PRINTF_ARGS(4) DrawStringCenter(u16 *screen, u32 color, u32 bgcolor, const char *format, ...);
|
||||||
|
|
||||||
|
u32 GetCharSize(const char* str);
|
||||||
|
u32 GetPrevCharSize(const char* str);
|
||||||
|
|
||||||
u32 GetDrawStringHeight(const char* str);
|
u32 GetDrawStringHeight(const char* str);
|
||||||
u32 GetDrawStringWidth(const char* str);
|
u32 GetDrawStringWidth(const char* str);
|
||||||
u32 GetFontWidth(void);
|
u32 GetFontWidth(void);
|
||||||
u32 GetFontHeight(void);
|
u32 GetFontHeight(void);
|
||||||
|
|
||||||
|
void MultiLineString(char* dest, const char* orig, int llen, int maxl);
|
||||||
void WordWrapString(char* str, int llen);
|
void WordWrapString(char* str, int llen);
|
||||||
void ResizeString(char* dest, const char* orig, int nsize, int tpos, bool align_right);
|
void ResizeString(char* dest, const char* orig, int nlength, int tpos, bool align_right);
|
||||||
void TruncateString(char* dest, const char* orig, int nsize, int tpos);
|
void TruncateString(char* dest, const char* orig, int nlength, int tpos);
|
||||||
void FormatNumber(char* str, u64 number);
|
void FormatNumber(char* str, u64 number);
|
||||||
void FormatBytes(char* str, u64 bytes);
|
void FormatBytes(char* str, u64 bytes);
|
||||||
|
|
||||||
void ShowString(const char *format, ...);
|
void PRINTF_ARGS(1) ShowString(const char *format, ...);
|
||||||
void ShowIconString(u8* icon, int w, int h, const char *format, ...);
|
void PRINTF_ARGS(2) ShowStringF(u16* screen, const char *format, ...);
|
||||||
bool ShowPrompt(bool ask, const char *format, ...);
|
void PRINTF_ARGS(4) ShowIconString(u16* icon, int w, int h, const char *format, ...);
|
||||||
u32 ShowSelectPrompt(u32 n, const char** options, const char *format, ...);
|
void PRINTF_ARGS(5) ShowIconStringF(u16* screen, u16* icon, int w, int h, const char *format, ...);
|
||||||
u32 ShowHotkeyPrompt(u32 n, const char** options, const u32* keys, const char *format, ...);
|
bool PRINTF_ARGS(2) ShowPrompt(bool ask, const char *format, ...);
|
||||||
bool ShowStringPrompt(char* inputstr, u32 max_size, const char *format, ...);
|
u32 PRINTF_ARGS(3) ShowSelectPrompt(int n, const char** options, const char *format, ...);
|
||||||
u64 ShowHexPrompt(u64 start_val, u32 n_digits, const char *format, ...);
|
u32 PRINTF_ARGS(4) ShowFileScrollPrompt(int n, const DirEntry** entries, bool hide_ext, const char *format, ...);
|
||||||
u64 ShowNumberPrompt(u64 start_val, const char *format, ...);
|
u32 PRINTF_ARGS(4) ShowHotkeyPrompt(u32 n, const char** options, const u32* keys, const char *format, ...);
|
||||||
bool ShowDataPrompt(u8* data, u32* size, const char *format, ...);
|
bool PRINTF_ARGS(3) ShowStringPrompt(char* inputstr, u32 max_size, const char *format, ...);
|
||||||
bool ShowRtcSetterPrompt(void* time, const char *format, ...);
|
u64 PRINTF_ARGS(3) ShowHexPrompt(u64 start_val, u32 n_digits, const char *format, ...);
|
||||||
|
u64 PRINTF_ARGS(2) ShowNumberPrompt(u64 start_val, const char *format, ...);
|
||||||
|
bool PRINTF_ARGS(3) ShowDataPrompt(u8* data, u32* size, const char *format, ...);
|
||||||
|
bool PRINTF_ARGS(2) ShowRtcSetterPrompt(void* time, const char *format, ...);
|
||||||
bool ShowProgress(u64 current, u64 total, const char* opstr);
|
bool ShowProgress(u64 current, u64 total, const char* opstr);
|
||||||
|
|
||||||
|
int ShowBrightnessConfig(int set_brightness);
|
||||||
|
|
||||||
|
static inline u16 rgb888_to_rgb565(u32 rgb) {
|
||||||
|
u8 r, g, b;
|
||||||
|
r = (rgb >> 16) & 0x1F;
|
||||||
|
g = (rgb >> 8) & 0x3F;
|
||||||
|
b = (rgb >> 0) & 0x1F;
|
||||||
|
return (r << 11) | (g << 5) | b;
|
||||||
|
}
|
||||||
|
|
||||||
|
static inline u16 rgb888_buf_to_rgb565(u8 *rgb) {
|
||||||
|
u8 r, g, b;
|
||||||
|
r = (rgb[0] >> 3);
|
||||||
|
g = (rgb[1] >> 2);
|
||||||
|
b = (rgb[2] >> 3);
|
||||||
|
return (r << 11) | (g << 5) | b;
|
||||||
|
}
|
||||||
|
@ -3,23 +3,16 @@
|
|||||||
#include "common.h"
|
#include "common.h"
|
||||||
|
|
||||||
// see: https://3dbrew.org/wiki/CONFIG11_Registers
|
// see: https://3dbrew.org/wiki/CONFIG11_Registers
|
||||||
#define IS_O3DS ((*(vu32*) 0x10140FFC) != 0x7)
|
#define IS_O3DS (((*(vu16*) 0x10140FFC) & 2) == 0)
|
||||||
|
|
||||||
// see: https://www.3dbrew.org/wiki/Memory_layout#ARM9_ITCM
|
// see: https://www.3dbrew.org/wiki/Memory_layout#ARM9_ITCM
|
||||||
// see: https://www.3dbrew.org/wiki/OTP_Registers#Plaintext_OTP
|
// see: https://www.3dbrew.org/wiki/OTP_Registers#Plaintext_OTP
|
||||||
#define IS_DEVKIT ((*(vu8*) (0x01FFB800+0x19)) != 0x0)
|
#define IS_DEVKIT ((*(vu8*) (0x01FFB800+0x19)) != 0x0)
|
||||||
|
|
||||||
// see: https://3dbrew.org/wiki/CONFIG11_Registers
|
|
||||||
// (also returns true for sighaxed systems, maybe change the name later?)
|
|
||||||
#define IS_A9LH ((*(vu32*) 0x101401C0) == 0)
|
|
||||||
|
|
||||||
// https://www.3dbrew.org/wiki/CONFIG9_Registers
|
// https://www.3dbrew.org/wiki/CONFIG9_Registers
|
||||||
// (actually checks for an unlocked OTP)
|
// (actually checks for an unlocked OTP, meaning sighax)
|
||||||
#define IS_UNLOCKED (!((*(vu8*)0x10000000) & 0x2))
|
#define IS_UNLOCKED (!((*(vu8*)0x10000000) & 0x2))
|
||||||
|
|
||||||
// A9LH + unlocked == SigHax
|
|
||||||
#define IS_SIGHAX (IS_A9LH && IS_UNLOCKED)
|
|
||||||
|
|
||||||
// System models
|
// System models
|
||||||
enum SystemModel {
|
enum SystemModel {
|
||||||
MODEL_OLD_3DS = 0,
|
MODEL_OLD_3DS = 0,
|
||||||
|
@ -189,7 +189,7 @@ int utf16_to_utf8(u8 *out, const u16 *in, int len_out, int len_in)
|
|||||||
units = decode_utf16(&code, in);
|
units = decode_utf16(&code, in);
|
||||||
if(units == -1)
|
if(units == -1)
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
if (len_in >= units)
|
if (len_in >= units)
|
||||||
len_in -= units;
|
len_in -= units;
|
||||||
else return -1;
|
else return -1;
|
||||||
@ -238,7 +238,7 @@ int utf8_to_utf16(u16 *out, const u8 *in, int len_out, int len_in)
|
|||||||
units = decode_utf8(&code, in);
|
units = decode_utf8(&code, in);
|
||||||
if(units == -1)
|
if(units == -1)
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
if (len_in >= units)
|
if (len_in >= units)
|
||||||
len_in -= units;
|
len_in -= units;
|
||||||
else return -1;
|
else return -1;
|
||||||
|
@ -1,11 +1,14 @@
|
|||||||
/* original version by megazig */
|
/* original version by megazig */
|
||||||
#include "aes.h"
|
#include "aes.h"
|
||||||
|
|
||||||
//FIXME some things make assumptions about alignemnts!
|
// FIXME some things make assumptions about alignemnts!
|
||||||
|
// setup_aeskey? and set_ctr do not anymore (c) d0k3
|
||||||
void setup_aeskeyX(uint8_t keyslot, const void* keyx)
|
void setup_aeskeyX(uint8_t keyslot, const void* keyx)
|
||||||
{
|
{
|
||||||
const uint32_t * _keyx = (const uint32_t*)keyx;
|
uint32_t _keyx[4] __attribute__((aligned(32)));
|
||||||
|
for (uint32_t i = 0; i < 16u; i++)
|
||||||
|
((uint8_t*)_keyx)[i] = ((uint8_t*)keyx)[i];
|
||||||
|
|
||||||
*REG_AESCNT = (*REG_AESCNT) | AES_CNT_INPUT_ENDIAN | AES_CNT_INPUT_ORDER;
|
*REG_AESCNT = (*REG_AESCNT) | AES_CNT_INPUT_ENDIAN | AES_CNT_INPUT_ORDER;
|
||||||
*REG_AESKEYCNT = (*REG_AESKEYCNT >> 6 << 6) | keyslot | 0x80;
|
*REG_AESKEYCNT = (*REG_AESKEYCNT >> 6 << 6) | keyslot | 0x80;
|
||||||
if (keyslot > 3) {
|
if (keyslot > 3) {
|
||||||
@ -25,7 +28,10 @@ void setup_aeskeyX(uint8_t keyslot, const void* keyx)
|
|||||||
|
|
||||||
void setup_aeskeyY(uint8_t keyslot, const void* keyy)
|
void setup_aeskeyY(uint8_t keyslot, const void* keyy)
|
||||||
{
|
{
|
||||||
const uint32_t * _keyy = (const uint32_t*)keyy;
|
uint32_t _keyy[4] __attribute__((aligned(32)));
|
||||||
|
for (uint32_t i = 0; i < 16u; i++)
|
||||||
|
((uint8_t*)_keyy)[i] = ((uint8_t*)keyy)[i];
|
||||||
|
|
||||||
*REG_AESCNT = (*REG_AESCNT) | AES_CNT_INPUT_ENDIAN | AES_CNT_INPUT_ORDER;
|
*REG_AESCNT = (*REG_AESCNT) | AES_CNT_INPUT_ENDIAN | AES_CNT_INPUT_ORDER;
|
||||||
*REG_AESKEYCNT = (*REG_AESKEYCNT >> 6 << 6) | keyslot | 0x80;
|
*REG_AESKEYCNT = (*REG_AESKEYCNT >> 6 << 6) | keyslot | 0x80;
|
||||||
if (keyslot > 3) {
|
if (keyslot > 3) {
|
||||||
@ -45,7 +51,10 @@ void setup_aeskeyY(uint8_t keyslot, const void* keyy)
|
|||||||
|
|
||||||
void setup_aeskey(uint8_t keyslot, const void* key)
|
void setup_aeskey(uint8_t keyslot, const void* key)
|
||||||
{
|
{
|
||||||
const uint32_t * _key = (const uint32_t*)key;
|
uint32_t _key[4] __attribute__((aligned(32)));
|
||||||
|
for (uint32_t i = 0; i < 16u; i++)
|
||||||
|
((uint8_t*)_key)[i] = ((uint8_t*)key)[i];
|
||||||
|
|
||||||
*REG_AESCNT = (*REG_AESCNT) | AES_CNT_INPUT_ENDIAN | AES_CNT_INPUT_ORDER;
|
*REG_AESCNT = (*REG_AESCNT) | AES_CNT_INPUT_ENDIAN | AES_CNT_INPUT_ORDER;
|
||||||
*REG_AESKEYCNT = (*REG_AESKEYCNT >> 6 << 6) | keyslot | 0x80;
|
*REG_AESKEYCNT = (*REG_AESKEYCNT >> 6 << 6) | keyslot | 0x80;
|
||||||
if (keyslot > 3) {
|
if (keyslot > 3) {
|
||||||
@ -73,7 +82,10 @@ void use_aeskey(uint32_t keyno)
|
|||||||
|
|
||||||
void set_ctr(void* iv)
|
void set_ctr(void* iv)
|
||||||
{
|
{
|
||||||
uint32_t * _iv = (uint32_t*)iv;
|
uint32_t _iv[4] __attribute__((aligned(32)));
|
||||||
|
for (uint32_t i = 0; i < 16u; i++)
|
||||||
|
((uint8_t*)_iv)[i] = ((uint8_t*)iv)[i];
|
||||||
|
|
||||||
*REG_AESCNT = (*REG_AESCNT) | AES_CNT_INPUT_ENDIAN | AES_CNT_INPUT_ORDER;
|
*REG_AESCNT = (*REG_AESCNT) | AES_CNT_INPUT_ENDIAN | AES_CNT_INPUT_ORDER;
|
||||||
*(REG_AESCTR + 0) = _iv[3];
|
*(REG_AESCTR + 0) = _iv[3];
|
||||||
*(REG_AESCTR + 1) = _iv[2];
|
*(REG_AESCTR + 1) = _iv[2];
|
||||||
@ -89,7 +101,7 @@ void add_ctr(void* ctr, uint32_t carry)
|
|||||||
int32_t i;
|
int32_t i;
|
||||||
|
|
||||||
for(i = 0; i < 4; i++) {
|
for(i = 0; i < 4; i++) {
|
||||||
//FIXME this assumes alignment...
|
//FIXME this assumes alignment...
|
||||||
counter[i] = ((uint32_t)outctr[i*4+0]<<24) | ((uint32_t)outctr[i*4+1]<<16) | ((uint32_t)outctr[i*4+2]<<8) | ((uint32_t)outctr[i*4+3]<<0);
|
counter[i] = ((uint32_t)outctr[i*4+0]<<24) | ((uint32_t)outctr[i*4+1]<<16) | ((uint32_t)outctr[i*4+2]<<8) | ((uint32_t)outctr[i*4+3]<<0);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -201,11 +213,11 @@ void ctr_decrypt_byte(void *inbuf, void *outbuf, size_t size, size_t off, uint32
|
|||||||
uint8_t *in = inbuf;
|
uint8_t *in = inbuf;
|
||||||
uint8_t *out = outbuf;
|
uint8_t *out = outbuf;
|
||||||
uint32_t i;
|
uint32_t i;
|
||||||
|
|
||||||
for (i=0; i<AES_BLOCK_SIZE; i++) // setup local ctr
|
for (i=0; i<AES_BLOCK_SIZE; i++) // setup local ctr
|
||||||
ctr_local[i] = ctr[i];
|
ctr_local[i] = ctr[i];
|
||||||
add_ctr(ctr_local, off / AES_BLOCK_SIZE);
|
add_ctr(ctr_local, off / AES_BLOCK_SIZE);
|
||||||
|
|
||||||
if (off_fix) // handle misaligned offset (at beginning)
|
if (off_fix) // handle misaligned offset (at beginning)
|
||||||
{
|
{
|
||||||
size_t last_byte = ((off_fix + bytes_left) >= AES_BLOCK_SIZE) ?
|
size_t last_byte = ((off_fix + bytes_left) >= AES_BLOCK_SIZE) ?
|
||||||
@ -217,7 +229,7 @@ void ctr_decrypt_byte(void *inbuf, void *outbuf, size_t size, size_t off, uint32
|
|||||||
*(out++) = temp[i];
|
*(out++) = temp[i];
|
||||||
bytes_left -= last_byte - off_fix;
|
bytes_left -= last_byte - off_fix;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (bytes_left >= AES_BLOCK_SIZE)
|
if (bytes_left >= AES_BLOCK_SIZE)
|
||||||
{
|
{
|
||||||
size_t blocks = bytes_left / AES_BLOCK_SIZE;
|
size_t blocks = bytes_left / AES_BLOCK_SIZE;
|
||||||
@ -226,7 +238,7 @@ void ctr_decrypt_byte(void *inbuf, void *outbuf, size_t size, size_t off, uint32
|
|||||||
out += AES_BLOCK_SIZE * blocks;
|
out += AES_BLOCK_SIZE * blocks;
|
||||||
bytes_left -= AES_BLOCK_SIZE * blocks;
|
bytes_left -= AES_BLOCK_SIZE * blocks;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (bytes_left) // handle misaligned offset (at end)
|
if (bytes_left) // handle misaligned offset (at end)
|
||||||
{
|
{
|
||||||
for (i=0; i<bytes_left; i++)
|
for (i=0; i<bytes_left; i++)
|
||||||
@ -288,25 +300,25 @@ void aes_cmac(void* inbuf, void* outbuf, size_t size)
|
|||||||
AES_CNT_INPUT_ENDIAN | AES_CNT_OUTPUT_ENDIAN;
|
AES_CNT_INPUT_ENDIAN | AES_CNT_OUTPUT_ENDIAN;
|
||||||
uint32_t* out = (uint32_t*) outbuf;
|
uint32_t* out = (uint32_t*) outbuf;
|
||||||
uint32_t* in = (uint32_t*) inbuf;
|
uint32_t* in = (uint32_t*) inbuf;
|
||||||
|
|
||||||
// create xorpad for last block
|
// create xorpad for last block
|
||||||
set_ctr(zeroes);
|
set_ctr(zeroes);
|
||||||
aes_decrypt(xorpad, xorpad, 1, mode);
|
aes_decrypt(xorpad, xorpad, 1, mode);
|
||||||
char* xorpadb = (void*) xorpad;
|
char* xorpadb = (void*) xorpad;
|
||||||
char finalxor = (xorpadb[0] & 0x80) ? 0x87 : 0x00;
|
char finalxor = (xorpadb[0] & 0x80) ? 0x87 : 0x00;
|
||||||
for (uint32_t i = 0; i < 15; i++) {
|
for (uint32_t i = 0; i < 15; i++) {
|
||||||
xorpadb[i] <<= 1;
|
xorpadb[i] <<= 1;
|
||||||
xorpadb[i] |= xorpadb[i+1] >> 7;
|
xorpadb[i] |= xorpadb[i+1] >> 7;
|
||||||
}
|
}
|
||||||
xorpadb[15] <<= 1;
|
xorpadb[15] <<= 1;
|
||||||
xorpadb[15] ^= finalxor;
|
xorpadb[15] ^= finalxor;
|
||||||
|
|
||||||
// process blocks
|
// process blocks
|
||||||
for (uint32_t i = 0; i < 4; i++)
|
for (uint32_t i = 0; i < 4; i++)
|
||||||
out[i] = 0;
|
out[i] = 0;
|
||||||
while (size-- > 0) {
|
while (size-- > 0) {
|
||||||
for (uint32_t i = 0; i < 4; i++)
|
for (uint32_t i = 0; i < 4; i++)
|
||||||
out[i] ^= *(in++);
|
out[i] ^= *(in++);
|
||||||
if (!size) { // last block
|
if (!size) { // last block
|
||||||
for (uint32_t i = 0; i < 4; i++)
|
for (uint32_t i = 0; i < 4; i++)
|
||||||
out[i] ^= xorpad[i];
|
out[i] ^= xorpad[i];
|
||||||
|
26
arm9/source/crypto/crc16.c
Normal file
26
arm9/source/crypto/crc16.c
Normal file
@ -0,0 +1,26 @@
|
|||||||
|
#include "crc16.h"
|
||||||
|
|
||||||
|
#define CRC16_TABVAL \
|
||||||
|
0x0000, 0xCC01, 0xD801, 0x1400, 0xF001, 0x3C00, 0x2800, 0xE401, \
|
||||||
|
0xA001, 0x6C00, 0x7800, 0xB401, 0x5000, 0x9C01, 0x8801, 0x4400
|
||||||
|
|
||||||
|
|
||||||
|
// see: https://github.com/TASVideos/desmume/blob/master/desmume/src/bios.cpp#L1070tions
|
||||||
|
u16 crc16_quick(const void* src, u32 len) {
|
||||||
|
static const u16 tabval[] = { CRC16_TABVAL };
|
||||||
|
u16* data = (u16*) src;
|
||||||
|
u16 crc = 0xFFFF;
|
||||||
|
|
||||||
|
for (len >>= 1; len; len--) {
|
||||||
|
u16 curr = *(data++);
|
||||||
|
for (u32 i = 0; i < 4; i++) {
|
||||||
|
u16 tval = tabval[crc&0xF];
|
||||||
|
crc >>= 4;
|
||||||
|
crc ^= tval;
|
||||||
|
tval = tabval[(curr >> (4*i))&0xF];
|
||||||
|
crc ^= tval;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return crc;
|
||||||
|
}
|
5
arm9/source/crypto/crc16.h
Normal file
5
arm9/source/crypto/crc16.h
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include "common.h"
|
||||||
|
|
||||||
|
u16 crc16_quick(const void* src, u32 len);
|
@ -2,8 +2,9 @@
|
|||||||
// https://github.com/eai04191/beat/blob/master/nall/crc32.hpp
|
// https://github.com/eai04191/beat/blob/master/nall/crc32.hpp
|
||||||
// Ported by Hyarion for use with VirtualFatFS
|
// Ported by Hyarion for use with VirtualFatFS
|
||||||
|
|
||||||
#include "crc32.h"
|
|
||||||
#include "common.h"
|
#include "common.h"
|
||||||
|
#include "crc32.h"
|
||||||
|
#include "vff.h"
|
||||||
|
|
||||||
u32 crc32_adjust(u32 crc32, u8 input) {
|
u32 crc32_adjust(u32 crc32, u8 input) {
|
||||||
static const u32 crc32_table[256] = {
|
static const u32 crc32_table[256] = {
|
||||||
@ -67,9 +68,12 @@ u32 crc32_calculate_from_file(const char* fileName, u32 offset, u32 length) {
|
|||||||
u32 bufsiz = min(STD_BUFFER_SIZE, length);
|
u32 bufsiz = min(STD_BUFFER_SIZE, length);
|
||||||
u8* buffer = (u8*) malloc(bufsiz);
|
u8* buffer = (u8*) malloc(bufsiz);
|
||||||
if (!buffer) return false;
|
if (!buffer) return false;
|
||||||
if (fvx_open(&inputFile, fileName, FA_READ) != FR_OK) return crc32;
|
if (fvx_open(&inputFile, fileName, FA_READ) != FR_OK) {
|
||||||
|
free(buffer);
|
||||||
|
return crc32;
|
||||||
|
}
|
||||||
fvx_lseek(&inputFile, offset);
|
fvx_lseek(&inputFile, offset);
|
||||||
|
|
||||||
bool ret = true;
|
bool ret = true;
|
||||||
for (u64 pos = 0; (pos < length) && ret; pos += bufsiz) {
|
for (u64 pos = 0; (pos < length) && ret; pos += bufsiz) {
|
||||||
UINT read_bytes = min(bufsiz, length - pos);
|
UINT read_bytes = min(bufsiz, length - pos);
|
||||||
@ -79,7 +83,7 @@ u32 crc32_calculate_from_file(const char* fileName, u32 offset, u32 length) {
|
|||||||
ret = false;
|
ret = false;
|
||||||
if (ret) crc32 = crc32_calculate(crc32, buffer, read_bytes);
|
if (ret) crc32 = crc32_calculate(crc32, buffer, read_bytes);
|
||||||
}
|
}
|
||||||
|
|
||||||
fvx_close(&inputFile);
|
fvx_close(&inputFile);
|
||||||
free(buffer);
|
free(buffer);
|
||||||
return ~crc32;
|
return ~crc32;
|
||||||
|
@ -3,7 +3,8 @@
|
|||||||
// Ported by Hyarion for use with VirtualFatFS
|
// Ported by Hyarion for use with VirtualFatFS
|
||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
#include "vff.h"
|
|
||||||
|
#include "common.h"
|
||||||
|
|
||||||
u32 crc32_adjust(u32 crc32, u8 input);
|
u32 crc32_adjust(u32 crc32, u8 input);
|
||||||
u32 crc32_calculate(u32 crc32, const u8* data, u32 length);
|
u32 crc32_calculate(u32 crc32, const u8* data, u32 length);
|
||||||
|
@ -8,7 +8,7 @@ typedef struct {
|
|||||||
u8 slot; // keyslot, 0x00...0x39
|
u8 slot; // keyslot, 0x00...0x39
|
||||||
u8 keyUnitType; // 0 for ALL units / 1 for devkit exclusive / 2 for retail exclusive
|
u8 keyUnitType; // 0 for ALL units / 1 for devkit exclusive / 2 for retail exclusive
|
||||||
u8 sample[16]; // sample data, encoded with src = keyY = ctr = { 0 }
|
u8 sample[16]; // sample data, encoded with src = keyY = ctr = { 0 }
|
||||||
} __attribute__((packed)) AesNcchSampleInfo;
|
} PACKED_STRUCT AesNcchSampleInfo;
|
||||||
|
|
||||||
static u64 keyState = 0;
|
static u64 keyState = 0;
|
||||||
static u64 keyXState = 0;
|
static u64 keyXState = 0;
|
||||||
@ -17,7 +17,7 @@ static u64 keyYState = 0;
|
|||||||
u32 GetUnitKeysType(void)
|
u32 GetUnitKeysType(void)
|
||||||
{
|
{
|
||||||
static u32 keys_type = KEYS_UNKNOWN;
|
static u32 keys_type = KEYS_UNKNOWN;
|
||||||
|
|
||||||
if (keys_type == KEYS_UNKNOWN) {
|
if (keys_type == KEYS_UNKNOWN) {
|
||||||
static const u8 slot0x2CSampleRetail[16] = {
|
static const u8 slot0x2CSampleRetail[16] = {
|
||||||
0xBC, 0xC4, 0x16, 0x2C, 0x2A, 0x06, 0x91, 0xEE, 0x47, 0x18, 0x86, 0xB8, 0xEB, 0x2F, 0xB5, 0x48 };
|
0xBC, 0xC4, 0x16, 0x2C, 0x2A, 0x06, 0x91, 0xEE, 0x47, 0x18, 0x86, 0xB8, 0xEB, 0x2F, 0xB5, 0x48 };
|
||||||
@ -35,15 +35,18 @@ u32 GetUnitKeysType(void)
|
|||||||
keys_type = KEYS_DEVKIT;
|
keys_type = KEYS_DEVKIT;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return keys_type;
|
return keys_type;
|
||||||
}
|
}
|
||||||
|
|
||||||
void CryptAesKeyInfo(AesKeyInfo* info) {
|
void CryptAesKeyInfo(AesKeyInfo* info) {
|
||||||
static u8 zeroes[16] = { 0 };
|
static const u8 zeros[16] = { 0 };
|
||||||
|
static const u8 keyY_dev[16] = {
|
||||||
|
0xA2, 0x32, 0x4A, 0x7E, 0x7C, 0xE6, 0x1A, 0x9A, 0x45, 0x4A, 0x52, 0x19, 0xB3, 0x5B, 0xE9, 0x3B };
|
||||||
|
const u8* aeskeyY = GetUnitKeysType() == KEYS_DEVKIT ? &keyY_dev[0] : &zeros[0];
|
||||||
u8 ctr[16] = { 0 };
|
u8 ctr[16] = { 0 };
|
||||||
memcpy(ctr, (void*) info, 12); // CTR -> slot + type + id + zeroes
|
memcpy(ctr, (void*) info, 12); // CTR -> slot + type + id + zeroes
|
||||||
setup_aeskeyY(0x2C, zeroes);
|
setup_aeskeyY(0x2C, aeskeyY);
|
||||||
use_aeskey(0x2C);
|
use_aeskey(0x2C);
|
||||||
set_ctr(ctr);
|
set_ctr(ctr);
|
||||||
aes_decrypt(info->key, info->key, 1, AES_CNT_CTRNAND_MODE);
|
aes_decrypt(info->key, info->key, 1, AES_CNT_CTRNAND_MODE);
|
||||||
@ -67,15 +70,15 @@ u32 CheckKeySlot(u32 keyslot, char type)
|
|||||||
{ 0xBC, 0x83, 0x7C, 0xC9, 0x99, 0xC8, 0x80, 0x9E, 0x8A, 0xDE, 0x4A, 0xFA, 0xAA, 0x72, 0x08, 0x28 } }
|
{ 0xBC, 0x83, 0x7C, 0xC9, 0x99, 0xC8, 0x80, 0x9E, 0x8A, 0xDE, 0x4A, 0xFA, 0xAA, 0x72, 0x08, 0x28 } }
|
||||||
};
|
};
|
||||||
u64* state = (type == 'X') ? &keyXState : (type == 'Y') ? &keyYState : (type == 'N') ? &keyState : NULL;
|
u64* state = (type == 'X') ? &keyXState : (type == 'Y') ? &keyYState : (type == 'N') ? &keyState : NULL;
|
||||||
|
|
||||||
// just to be safe...
|
// just to be safe...
|
||||||
if (keyslot >= 0x40)
|
if (keyslot >= 0x40)
|
||||||
return 1;
|
return 1;
|
||||||
|
|
||||||
// check if key is already loaded
|
// check if key is already loaded
|
||||||
if ((type != 'I') && ((*state >> keyslot) & 1))
|
if ((type != 'I') && ((*state >> keyslot) & 1))
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
// if is not, we may still be able to verify the currently set one (for NCCH keys)
|
// if is not, we may still be able to verify the currently set one (for NCCH keys)
|
||||||
for (u32 p = 0; (type == 'X') && (p < sizeof(keyNcchSamples) / sizeof(AesNcchSampleInfo)); p++) {
|
for (u32 p = 0; (type == 'X') && (p < sizeof(keyNcchSamples) / sizeof(AesNcchSampleInfo)); p++) {
|
||||||
if (keyNcchSamples[p].slot != keyslot) // only for keyslots in the keyNcchSamples table!
|
if (keyNcchSamples[p].slot != keyslot) // only for keyslots in the keyNcchSamples table!
|
||||||
@ -93,7 +96,7 @@ u32 CheckKeySlot(u32 keyslot, char type)
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// not set up if getting here
|
// not set up if getting here
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
@ -102,13 +105,13 @@ u32 CheckKeySlot(u32 keyslot, char type)
|
|||||||
// to get rid of these, you may replace this function with anything that works for you
|
// to get rid of these, you may replace this function with anything that works for you
|
||||||
u32 LoadKeyDb(const char* path_db, AesKeyInfo* keydb, u32 bsize) {
|
u32 LoadKeyDb(const char* path_db, AesKeyInfo* keydb, u32 bsize) {
|
||||||
UINT fsize = 0;
|
UINT fsize = 0;
|
||||||
|
|
||||||
if (path_db) {
|
if (path_db) {
|
||||||
if (fvx_qread (path_db, keydb, 0, bsize, &fsize) != FR_OK) fsize = 0;
|
if (fvx_qread (path_db, keydb, 0, bsize, &fsize) != FR_OK) fsize = 0;
|
||||||
} else if (fvx_qread ("S:/" KEYDB_NAME, keydb, 0, bsize, &fsize) != FR_OK) {
|
} else if (fvx_qread ("S:/" KEYDB_NAME, keydb, 0, bsize, &fsize) != FR_OK) {
|
||||||
fsize = LoadSupportFile(KEYDB_NAME, keydb, bsize); // load key database support file
|
fsize = LoadSupportFile(KEYDB_NAME, keydb, bsize); // load key database support file
|
||||||
}
|
}
|
||||||
|
|
||||||
u32 nkeys = 0;
|
u32 nkeys = 0;
|
||||||
if (fsize && !(fsize % sizeof(AesKeyInfo)))
|
if (fsize && !(fsize % sizeof(AesKeyInfo)))
|
||||||
nkeys = fsize / sizeof(AesKeyInfo);
|
nkeys = fsize / sizeof(AesKeyInfo);
|
||||||
@ -119,24 +122,24 @@ u32 LoadKeyFromFile(void* key, u32 keyslot, char type, char* id)
|
|||||||
{
|
{
|
||||||
u8 keystore[16] __attribute__((aligned(32))) = {0};
|
u8 keystore[16] __attribute__((aligned(32))) = {0};
|
||||||
bool found = false;
|
bool found = false;
|
||||||
|
|
||||||
// checking the obvious
|
// checking the obvious
|
||||||
if ((keyslot >= 0x40) || ((type != 'X') && (type != 'Y') && (type != 'N') && (type != 'I')))
|
if ((keyslot >= 0x40) || ((type != 'X') && (type != 'Y') && (type != 'N') && (type != 'I')))
|
||||||
return 1;
|
return 1;
|
||||||
|
|
||||||
// check if already loaded
|
// check if already loaded
|
||||||
if (!key && !id && (CheckKeySlot(keyslot, type) == 0)) return 0;
|
if (!key && !id && (CheckKeySlot(keyslot, type) == 0)) return 0;
|
||||||
|
|
||||||
// use keystore if key == NULL
|
// use keystore if key == NULL
|
||||||
if (!key) key = keystore;
|
if (!key) key = keystore;
|
||||||
|
|
||||||
// try to get key from 'aeskeydb.bin' file
|
// try to get key from 'aeskeydb.bin' file
|
||||||
AesKeyInfo* keydb = (AesKeyInfo*) malloc(STD_BUFFER_SIZE);
|
AesKeyInfo* keydb = (AesKeyInfo*) malloc(STD_BUFFER_SIZE);
|
||||||
u32 nkeys = (keydb) ? LoadKeyDb(NULL, keydb, STD_BUFFER_SIZE) : 0;
|
u32 nkeys = (keydb) ? LoadKeyDb(NULL, keydb, STD_BUFFER_SIZE) : 0;
|
||||||
|
|
||||||
for (u32 i = 0; i < nkeys; i++) {
|
for (u32 i = 0; i < nkeys; i++) {
|
||||||
AesKeyInfo* info = &(keydb[i]);
|
AesKeyInfo* info = &(keydb[i]);
|
||||||
if (!((info->slot == keyslot) && (info->type == type) &&
|
if (!((info->slot == keyslot) && (info->type == type) &&
|
||||||
((!id && !(info->id[0])) || (id && (strncmp(id, info->id, 10) == 0))) &&
|
((!id && !(info->id[0])) || (id && (strncmp(id, info->id, 10) == 0))) &&
|
||||||
(!info->keyUnitType || (info->keyUnitType == GetUnitKeysType()))))
|
(!info->keyUnitType || (info->keyUnitType == GetUnitKeysType()))))
|
||||||
continue;
|
continue;
|
||||||
@ -146,23 +149,23 @@ u32 LoadKeyFromFile(void* key, u32 keyslot, char type, char* id)
|
|||||||
memcpy(key, info->key, 16);
|
memcpy(key, info->key, 16);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
free(keydb);
|
free(keydb);
|
||||||
|
|
||||||
// load legacy slot0x??Key?.bin file instead
|
// load legacy slot0x??Key?.bin file instead
|
||||||
if (!found && (type != 'I')) {
|
if (!found && (type != 'I')) {
|
||||||
char fname[64];
|
char fname[64];
|
||||||
snprintf(fname, 64, "slot0x%02lXKey%s%s.bin", keyslot,
|
snprintf(fname, sizeof(fname), "slot0x%02lXKey%s%s.bin", keyslot,
|
||||||
(type == 'X') ? "X" : (type == 'Y') ? "Y" : (type == 'I') ? "IV" : "", (id) ? id : "");
|
(type == 'X') ? "X" : (type == 'Y') ? "Y" : (type == 'I') ? "IV" : "", (id) ? id : "");
|
||||||
found = (LoadSupportFile(fname, key, 16) == 16);
|
found = (LoadSupportFile(fname, key, 16) == 16);
|
||||||
}
|
}
|
||||||
|
|
||||||
// key still not found (duh)
|
// key still not found (duh)
|
||||||
if (!found) return 1; // out of options here
|
if (!found) return 1; // out of options here
|
||||||
|
|
||||||
// done if this is an IV
|
// done if this is an IV
|
||||||
if (type == 'I') return 0;
|
if (type == 'I') return 0;
|
||||||
|
|
||||||
// now, setup the key
|
// now, setup the key
|
||||||
if (type == 'X') {
|
if (type == 'X') {
|
||||||
setup_aeskeyX(keyslot, key);
|
setup_aeskeyX(keyslot, key);
|
||||||
@ -177,7 +180,7 @@ u32 LoadKeyFromFile(void* key, u32 keyslot, char type, char* id)
|
|||||||
keyYState |= 1ull << keyslot;
|
keyYState |= 1ull << keyslot;
|
||||||
}
|
}
|
||||||
use_aeskey(keyslot);
|
use_aeskey(keyslot);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -186,11 +189,11 @@ u32 InitKeyDb(const char* path)
|
|||||||
// use this to quickly initialize all applicable keys in aeskeydb.bin
|
// use this to quickly initialize all applicable keys in aeskeydb.bin
|
||||||
static const u64 keyslot_whitelist = (1ull<<0x02)|(1ull<<0x03)|(1ull<<0x05)|(1ull<<0x18)|(1ull<<0x19)|(1ull<<0x1A)|(1ull<<0x1B)|
|
static const u64 keyslot_whitelist = (1ull<<0x02)|(1ull<<0x03)|(1ull<<0x05)|(1ull<<0x18)|(1ull<<0x19)|(1ull<<0x1A)|(1ull<<0x1B)|
|
||||||
(1ull<<0x1C)|(1ull<<0x1D)|(1ull<<0x1E)|(1ull<<0x1F)|(1ull<<0x24)|(1ull<<0x25)|(1ull<<0x2F);
|
(1ull<<0x1C)|(1ull<<0x1D)|(1ull<<0x1E)|(1ull<<0x1F)|(1ull<<0x24)|(1ull<<0x25)|(1ull<<0x2F);
|
||||||
|
|
||||||
// try to load aeskeydb.bin file
|
// try to load aeskeydb.bin file
|
||||||
AesKeyInfo* keydb = (AesKeyInfo*) malloc(STD_BUFFER_SIZE);
|
AesKeyInfo* keydb = (AesKeyInfo*) malloc(STD_BUFFER_SIZE);
|
||||||
u32 nkeys = (keydb) ? LoadKeyDb(path, keydb, STD_BUFFER_SIZE) : 0;
|
u32 nkeys = (keydb) ? LoadKeyDb(path, keydb, STD_BUFFER_SIZE) : 0;
|
||||||
|
|
||||||
// apply all applicable keys
|
// apply all applicable keys
|
||||||
for (u32 i = 0; i < nkeys; i++) {
|
for (u32 i = 0; i < nkeys; i++) {
|
||||||
AesKeyInfo* info = &(keydb[i]);
|
AesKeyInfo* info = &(keydb[i]);
|
||||||
@ -202,7 +205,7 @@ u32 InitKeyDb(const char* path)
|
|||||||
if ((info->type == 'I') || (*(info->id)) || (info->keyUnitType && (info->keyUnitType != GetUnitKeysType())) ||
|
if ((info->type == 'I') || (*(info->id)) || (info->keyUnitType && (info->keyUnitType != GetUnitKeysType())) ||
|
||||||
(CheckKeySlot(info->slot, info->type) == 0)) continue; // most likely valid, but not applicable or already set
|
(CheckKeySlot(info->slot, info->type) == 0)) continue; // most likely valid, but not applicable or already set
|
||||||
if (info->isEncrypted) CryptAesKeyInfo(info); // decrypt key
|
if (info->isEncrypted) CryptAesKeyInfo(info); // decrypt key
|
||||||
|
|
||||||
// apply key
|
// apply key
|
||||||
u8 key[16] __attribute__((aligned(32))) = {0};
|
u8 key[16] __attribute__((aligned(32))) = {0};
|
||||||
char type = info->type;
|
char type = info->type;
|
||||||
@ -222,29 +225,7 @@ u32 InitKeyDb(const char* path)
|
|||||||
}
|
}
|
||||||
use_aeskey(keyslot);
|
use_aeskey(keyslot);
|
||||||
}
|
}
|
||||||
|
|
||||||
free(keydb);
|
free(keydb);
|
||||||
return (nkeys) ? 0 : 1;
|
return (nkeys) ? 0 : 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
// creates dependency to "sha.h", not required for base keydb functions
|
|
||||||
u32 CheckRecommendedKeyDb(const char* path)
|
|
||||||
{
|
|
||||||
// SHA-256 of the recommended aeskeydb.bin file
|
|
||||||
// equals MD5 A5B28945A7C051D7A0CD18AF0E580D1B
|
|
||||||
const u8 recommended_sha[0x20] = {
|
|
||||||
0x40, 0x76, 0x54, 0x3D, 0xA3, 0xFF, 0x91, 0x1C, 0xE1, 0xCC, 0x4E, 0xC7, 0x2F, 0x92, 0xE4, 0xB7,
|
|
||||||
0x2B, 0x24, 0x00, 0x15, 0xBE, 0x9B, 0xFC, 0xDE, 0x7F, 0xED, 0x95, 0x1D, 0xD5, 0xAB, 0x2D, 0xCB
|
|
||||||
};
|
|
||||||
|
|
||||||
// try to load aeskeydb.bin file
|
|
||||||
AesKeyInfo* keydb = (AesKeyInfo*) malloc(STD_BUFFER_SIZE);
|
|
||||||
if (!keydb) return 1;
|
|
||||||
u32 nkeys = LoadKeyDb(path, keydb, STD_BUFFER_SIZE);
|
|
||||||
|
|
||||||
// compare with recommended SHA
|
|
||||||
bool res = (nkeys && (sha_cmp(recommended_sha, keydb, nkeys * sizeof(AesKeyInfo), SHA256_MODE) == 0));
|
|
||||||
|
|
||||||
free(keydb);
|
|
||||||
return res ? 0 : 1;
|
|
||||||
}
|
|
||||||
|
@ -14,20 +14,19 @@
|
|||||||
#define KEYS_UNKNOWN 0
|
#define KEYS_UNKNOWN 0
|
||||||
#define KEYS_DEVKIT 1
|
#define KEYS_DEVKIT 1
|
||||||
#define KEYS_RETAIL 2
|
#define KEYS_RETAIL 2
|
||||||
|
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
u8 slot; // keyslot, 0x00...0x3F
|
u8 slot; // keyslot, 0x00...0x3F
|
||||||
char type; // type 'X' / 'Y' / 'N' for normalKey / 'I' for IV
|
char type; // type 'X' / 'Y' / 'N' for normalKey / 'I' for IV
|
||||||
char id[10]; // key ID for special keys, all zero for standard keys
|
char id[10]; // key ID for special keys, all zero for standard keys
|
||||||
u8 reserved[2]; // reserved space
|
u8 reserved[2]; // reserved space
|
||||||
u8 keyUnitType; // 0 for ALL units / 1 for devkit exclusive / 2 for retail exclusive
|
u8 keyUnitType; // 0 for ALL units / 1 for devkit exclusive / 2 for retail exclusive
|
||||||
u8 isEncrypted; // 0 if not / anything else if it is
|
u8 isEncrypted; // 0 if not / anything else if it is
|
||||||
u8 key[16];
|
u8 key[16];
|
||||||
} __attribute__((packed)) AesKeyInfo;
|
} PACKED_STRUCT __attribute__((aligned(16))) AesKeyInfo;
|
||||||
|
|
||||||
u32 GetUnitKeysType(void);
|
u32 GetUnitKeysType(void);
|
||||||
void CryptAesKeyInfo(AesKeyInfo* info);
|
void CryptAesKeyInfo(AesKeyInfo* info);
|
||||||
u32 LoadKeyFromFile(void* key, u32 keyslot, char type, char* id);
|
u32 LoadKeyFromFile(void* key, u32 keyslot, char type, char* id);
|
||||||
u32 InitKeyDb(const char* path);
|
u32 InitKeyDb(const char* path);
|
||||||
u32 CheckRecommendedKeyDb(const char* path);
|
|
||||||
|
@ -19,6 +19,7 @@
|
|||||||
#include "common.h"
|
#include "common.h"
|
||||||
#include "rsa.h"
|
#include "rsa.h"
|
||||||
#include "sha.h"
|
#include "sha.h"
|
||||||
|
#include "mmio.h"
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@ -34,9 +35,9 @@
|
|||||||
#define REGs_RSA_SLOT2 ((vu32*)(RSA_REGS_BASE + 0x120))
|
#define REGs_RSA_SLOT2 ((vu32*)(RSA_REGS_BASE + 0x120))
|
||||||
#define REGs_RSA_SLOT3 ((vu32*)(RSA_REGS_BASE + 0x130))
|
#define REGs_RSA_SLOT3 ((vu32*)(RSA_REGS_BASE + 0x130))
|
||||||
#define rsaSlots ((RsaSlot*)(RSA_REGS_BASE + 0x100))
|
#define rsaSlots ((RsaSlot*)(RSA_REGS_BASE + 0x100))
|
||||||
#define REG_RSA_EXP ((vu32*)(RSA_REGS_BASE + 0x200))
|
#define REGs_RSA_EXP ((vu32*)(RSA_REGS_BASE + 0x200))
|
||||||
#define REG_RSA_MOD ( (RSA_REGS_BASE + 0x400))
|
#define REGs_RSA_MOD ((vu32*)(RSA_REGS_BASE + 0x400))
|
||||||
#define REG_RSA_TXT ( (RSA_REGS_BASE + 0x800))
|
#define REGs_RSA_TXT ((vu32*)(RSA_REGS_BASE + 0x800))
|
||||||
|
|
||||||
typedef struct
|
typedef struct
|
||||||
{
|
{
|
||||||
@ -63,7 +64,7 @@ void RSA_selectKeyslot(u8 keyslot)
|
|||||||
REG_RSA_CNT = (REG_RSA_CNT & ~RSA_KEYSLOT(0xFu)) | RSA_KEYSLOT(keyslot);
|
REG_RSA_CNT = (REG_RSA_CNT & ~RSA_KEYSLOT(0xFu)) | RSA_KEYSLOT(keyslot);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool RSA_setKey2048(u8 keyslot, const u8 *const mod, u32 exp)
|
bool RSA_setKey2048(u8 keyslot, const u32 *const mod, u32 exp)
|
||||||
{
|
{
|
||||||
RsaSlot *slot = &rsaSlots[keyslot];
|
RsaSlot *slot = &rsaSlots[keyslot];
|
||||||
rsaWaitBusy();
|
rsaWaitBusy();
|
||||||
@ -72,35 +73,35 @@ bool RSA_setKey2048(u8 keyslot, const u8 *const mod, u32 exp)
|
|||||||
if(!(slot->REG_RSA_SLOTCNT & RSA_KEY_UNK_BIT31)) slot->REG_RSA_SLOTCNT &= ~RSA_KEY_STAT_SET;
|
if(!(slot->REG_RSA_SLOTCNT & RSA_KEY_UNK_BIT31)) slot->REG_RSA_SLOTCNT &= ~RSA_KEY_STAT_SET;
|
||||||
|
|
||||||
REG_RSA_CNT = RSA_INPUT_NORMAL | RSA_INPUT_BIG | RSA_KEYSLOT(keyslot);
|
REG_RSA_CNT = RSA_INPUT_NORMAL | RSA_INPUT_BIG | RSA_KEYSLOT(keyslot);
|
||||||
memset((void*)REG_RSA_EXP, 0, 0x100 - 4);
|
iomemset(REGs_RSA_EXP, 0, 0x100 - 4);
|
||||||
REG_RSA_EXP[(0x100>>2) - 1] = exp;
|
REGs_RSA_EXP[(0x100>>2) - 1] = exp;
|
||||||
|
|
||||||
if(slot->REG_RSA_SLOTSIZE != RSA_SLOTSIZE_2048) return false;
|
if(slot->REG_RSA_SLOTSIZE != RSA_SLOTSIZE_2048) return false;
|
||||||
memcpy((void*)REG_RSA_MOD, mod, 0x100);
|
iomemcpy(REGs_RSA_MOD, mod, 0x100);
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool RSA_decrypt2048(void *const decSig, const void *const encSig)
|
bool RSA_decrypt2048(u32 *const decSig, const u32 *const encSig)
|
||||||
{
|
{
|
||||||
const u8 keyslot = RSA_GET_KEYSLOT;
|
const u8 keyslot = RSA_GET_KEYSLOT;
|
||||||
rsaWaitBusy();
|
rsaWaitBusy();
|
||||||
if(!(rsaSlots[keyslot].REG_RSA_SLOTCNT & RSA_KEY_STAT_SET)) return false;
|
if(!(rsaSlots[keyslot].REG_RSA_SLOTCNT & RSA_KEY_STAT_SET)) return false;
|
||||||
|
|
||||||
REG_RSA_CNT |= RSA_INPUT_NORMAL | RSA_INPUT_BIG;
|
REG_RSA_CNT |= RSA_INPUT_NORMAL | RSA_INPUT_BIG;
|
||||||
memcpy((void*)REG_RSA_TXT, encSig, 0x100);
|
iomemcpy(REGs_RSA_TXT, encSig, 0x100);
|
||||||
|
|
||||||
REG_RSA_CNT |= RSA_ENABLE;
|
REG_RSA_CNT |= RSA_ENABLE;
|
||||||
rsaWaitBusy();
|
rsaWaitBusy();
|
||||||
memcpy(decSig, (void*)REG_RSA_TXT, 0x100);
|
iomemcpy(decSig, REGs_RSA_TXT, 0x100);
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool RSA_verify2048(const u32 *const encSig, const u32 *const data, u32 size)
|
bool RSA_verify2048(const u32 *const encSig, const u32 *const data, u32 size)
|
||||||
{
|
{
|
||||||
u8 decSig[0x100];
|
alignas(4) u8 decSig[0x100];
|
||||||
if(!RSA_decrypt2048(decSig, encSig)) return false;
|
if(!RSA_decrypt2048((u32*)(void*)decSig, encSig)) return false;
|
||||||
|
|
||||||
if(decSig[0] != 0x00 || decSig[1] != 0x01) return false;
|
if(decSig[0] != 0x00 || decSig[1] != 0x01) return false;
|
||||||
|
|
||||||
|
@ -66,7 +66,7 @@ void RSA_selectKeyslot(u8 keyslot);
|
|||||||
*
|
*
|
||||||
* @return Returns true on success, false otherwise.
|
* @return Returns true on success, false otherwise.
|
||||||
*/
|
*/
|
||||||
bool RSA_setKey2048(u8 keyslot, const u8 *const mod, u32 exp);
|
bool RSA_setKey2048(u8 keyslot, const u32 *const mod, u32 exp);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Decrypts a RSA 2048 signature.
|
* @brief Decrypts a RSA 2048 signature.
|
||||||
@ -76,7 +76,7 @@ bool RSA_setKey2048(u8 keyslot, const u8 *const mod, u32 exp);
|
|||||||
*
|
*
|
||||||
* @return Returns true on success, false otherwise.
|
* @return Returns true on success, false otherwise.
|
||||||
*/
|
*/
|
||||||
bool RSA_decrypt2048(void *const decSig, const void *const encSig);
|
bool RSA_decrypt2048(u32 *const decSig, const u32 *const encSig);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Verifies a RSA 2048 SHA 256 signature.
|
* @brief Verifies a RSA 2048 SHA 256 signature.
|
||||||
|
@ -1,8 +1,9 @@
|
|||||||
#include "sha.h"
|
#include "sha.h"
|
||||||
|
#include "mmio.h"
|
||||||
|
|
||||||
typedef struct
|
typedef struct
|
||||||
{
|
{
|
||||||
u32 data[16];
|
u32 data[16];
|
||||||
} _sha_block;
|
} _sha_block;
|
||||||
|
|
||||||
void sha_init(u32 mode)
|
void sha_init(u32 mode)
|
||||||
@ -12,17 +13,17 @@ void sha_init(u32 mode)
|
|||||||
}
|
}
|
||||||
|
|
||||||
void sha_update(const void* src, u32 size)
|
void sha_update(const void* src, u32 size)
|
||||||
{
|
{
|
||||||
const u32* src32 = (const u32*)src;
|
const u32* src32 = (const u32*)src;
|
||||||
|
|
||||||
while(size >= 0x40) {
|
while(size >= 0x40) {
|
||||||
while(*REG_SHACNT & 1);
|
while(*REG_SHACNT & 1);
|
||||||
*((_sha_block*)REG_SHAINFIFO) = *((const _sha_block*)src32);
|
*((volatile _sha_block*)REG_SHAINFIFO) = *((const _sha_block*)src32);
|
||||||
src32 += 16;
|
src32 += 16;
|
||||||
size -= 0x40;
|
size -= 0x40;
|
||||||
}
|
}
|
||||||
while(*REG_SHACNT & 1);
|
while(*REG_SHACNT & 1);
|
||||||
if(size) memcpy((void*)REG_SHAINFIFO, src32, size);
|
if(size) iomemcpy((void*)REG_SHAINFIFO, src32, size);
|
||||||
}
|
}
|
||||||
|
|
||||||
void sha_get(void* res) {
|
void sha_get(void* res) {
|
||||||
@ -31,7 +32,7 @@ void sha_get(void* res) {
|
|||||||
*REG_SHACNT = (*REG_SHACNT & ~SHA_NORMAL_ROUND) | SHA_FINAL_ROUND;
|
*REG_SHACNT = (*REG_SHACNT & ~SHA_NORMAL_ROUND) | SHA_FINAL_ROUND;
|
||||||
while(*REG_SHACNT & SHA_FINAL_ROUND);
|
while(*REG_SHACNT & SHA_FINAL_ROUND);
|
||||||
while(*REG_SHACNT & 1);
|
while(*REG_SHACNT & 1);
|
||||||
if (hash_size) memcpy(res, (void*)REG_SHAHASH, hash_size);
|
if (hash_size) iomemcpy(res, (void*)REG_SHAHASH, hash_size);
|
||||||
}
|
}
|
||||||
|
|
||||||
void sha_quick(void* res, const void* src, u32 size, u32 mode) {
|
void sha_quick(void* res, const void* src, u32 size, u32 mode) {
|
||||||
|
@ -322,3 +322,19 @@ R0.13b (April 07, 2018)
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
R0.13c (October 14, 2018)
|
||||||
|
Supported stdint.h for C99 and later. (integer.h was included in ff.h)
|
||||||
|
Fixed reading a directory gets infinite loop when the last directory entry is not empty. (appeared at R0.12)
|
||||||
|
Fixed creating a sub-directory in the fragmented sub-directory on the exFAT volume collapses FAT chain of the parent directory. (appeared at R0.12)
|
||||||
|
Fixed f_getcwd() cause output buffer overrun when the buffer has a valid drive number. (appeared at R0.13b)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
R0.14 (October 14, 2019)
|
||||||
|
Added support for 64-bit LBA and GUID partition table (FF_LBA64 = 1)
|
||||||
|
Changed some API functions, f_mkfs() and f_fdisk().
|
||||||
|
Fixed f_open() function cannot find the file with file name in length of FF_MAX_LFN characters.
|
||||||
|
Fixed f_readdir() function cannot retrieve long file names in length of FF_MAX_LFN - 1 characters.
|
||||||
|
Fixed f_readdir() function returns file names with wrong case conversion. (appeared at R0.12)
|
||||||
|
Fixed f_mkfs() function can fail to create exFAT volume in the second partition. (appeared at R0.12)
|
||||||
|
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
FatFs Module Source Files R0.13b
|
FatFs Module Source Files R0.14
|
||||||
|
|
||||||
|
|
||||||
FILES
|
FILES
|
||||||
@ -10,7 +10,6 @@ FILES
|
|||||||
ff.h Common include file for FatFs and application module.
|
ff.h Common include file for FatFs and application module.
|
||||||
diskio.h Common include file for FatFs and disk I/O module.
|
diskio.h Common include file for FatFs and disk I/O module.
|
||||||
diskio.c An example of glue function to attach existing disk I/O module to FatFs.
|
diskio.c An example of glue function to attach existing disk I/O module to FatFs.
|
||||||
integer.h Integer type definitions for FatFs.
|
|
||||||
ffunicode.c Optional Unicode utility functions.
|
ffunicode.c Optional Unicode utility functions.
|
||||||
ffsystem.c An example of optional O/S related functions.
|
ffsystem.c An example of optional O/S related functions.
|
||||||
|
|
||||||
|
24
arm9/source/fatfs/LICENSE.txt
Normal file
24
arm9/source/fatfs/LICENSE.txt
Normal file
@ -0,0 +1,24 @@
|
|||||||
|
FatFs License
|
||||||
|
|
||||||
|
FatFs has being developped as a personal project of the author, ChaN. It is free from the code anyone else wrote at current release. Following code block shows a copy of the FatFs license document that heading the source files.
|
||||||
|
|
||||||
|
/*----------------------------------------------------------------------------/
|
||||||
|
/ FatFs - Generic FAT Filesystem Module Rx.xx /
|
||||||
|
/-----------------------------------------------------------------------------/
|
||||||
|
/
|
||||||
|
/ Copyright (C) 20xx, ChaN, all right reserved.
|
||||||
|
/
|
||||||
|
/ FatFs module is an open source software. Redistribution and use of FatFs in
|
||||||
|
/ source and binary forms, with or without modification, are permitted provided
|
||||||
|
/ that the following condition is met:
|
||||||
|
/
|
||||||
|
/ 1. Redistributions of source code must retain the above copyright notice,
|
||||||
|
/ this condition and the following disclaimer.
|
||||||
|
/
|
||||||
|
/ This software is provided by the copyright holder and contributors "AS IS"
|
||||||
|
/ and any warranties related to this software are DISCLAIMED.
|
||||||
|
/ The copyright owner or contributors be NOT LIABLE for any damages caused
|
||||||
|
/ by use of this software.
|
||||||
|
/----------------------------------------------------------------------------*/
|
||||||
|
|
||||||
|
Therefore FatFs license is one of the BSD-style licenses but there is a significant feature. FatFs is mainly intended for embedded systems. In order to extend the usability for commercial products, the redistributions of FatFs in binary form, such as embedded code, binary library and any forms without source code, does not need to include about FatFs in the documentations. This is equivalent to the 1-clause BSD license. Of course FatFs is compatible with the most of open source software licenses including GNU GPL. When you redistribute the FatFs source code with any changes or create a fork, the license can also be changed to GNU GPL, BSD-style license or any open source software license that not conflict with FatFs license.
|
@ -1,5 +1,5 @@
|
|||||||
/*-----------------------------------------------------------------------*/
|
/*-----------------------------------------------------------------------*/
|
||||||
/* Low level disk I/O module skeleton for FatFs (C)ChaN, 2014 */
|
/* Low level disk I/O module skeleton for FatFs (C)ChaN, d0k3, 2019 */
|
||||||
/*-----------------------------------------------------------------------*/
|
/*-----------------------------------------------------------------------*/
|
||||||
/* If a working storage control module is available, it should be */
|
/* If a working storage control module is available, it should be */
|
||||||
/* attached to the FatFs via a glue function rather than modifying it. */
|
/* attached to the FatFs via a glue function rather than modifying it. */
|
||||||
@ -7,7 +7,8 @@
|
|||||||
/* storage control modules to the FatFs module with a defined API. */
|
/* storage control modules to the FatFs module with a defined API. */
|
||||||
/*-----------------------------------------------------------------------*/
|
/*-----------------------------------------------------------------------*/
|
||||||
|
|
||||||
#include "diskio.h" /* FatFs lower layer API */
|
#include "ff.h" /* Obtains integer types */
|
||||||
|
#include "diskio.h" /* Declarations of disk functions */
|
||||||
#include "image.h"
|
#include "image.h"
|
||||||
#include "ramdrive.h"
|
#include "ramdrive.h"
|
||||||
#include "nand.h"
|
#include "nand.h"
|
||||||
@ -62,7 +63,7 @@ FATpartition DriveInfo[13] = {
|
|||||||
{ TYPE_RAMDRV, SUBTYPE_NONE, 0, 0, 0xFF } // Z - RAMDRIVE
|
{ TYPE_RAMDRV, SUBTYPE_NONE, 0, 0, 0xFF } // Z - RAMDRIVE
|
||||||
};
|
};
|
||||||
|
|
||||||
static BYTE imgnand_mode = 0x00;
|
static BYTE imgnand_mode = 0x00;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@ -80,7 +81,7 @@ DWORD get_fattime( void ) {
|
|||||||
((DSTIMEGET(&dstime, bcd_D)&0x1F) << 16) |
|
((DSTIMEGET(&dstime, bcd_D)&0x1F) << 16) |
|
||||||
((DSTIMEGET(&dstime, bcd_M)&0x0F) << 21) |
|
((DSTIMEGET(&dstime, bcd_M)&0x0F) << 21) |
|
||||||
(((DSTIMEGET(&dstime, bcd_Y)+(2000-1980))&0x7F) << 25);
|
(((DSTIMEGET(&dstime, bcd_Y)+(2000-1980))&0x7F) << 25);
|
||||||
|
|
||||||
return fattime;
|
return fattime;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -112,10 +113,10 @@ DSTATUS disk_initialize (
|
|||||||
imgnand_mode = (GetMountState() & IMG_NAND) ? 0x01 : 0x00;
|
imgnand_mode = (GetMountState() & IMG_NAND) ? 0x01 : 0x00;
|
||||||
FATpartition* fat_info = PART_INFO(pdrv);
|
FATpartition* fat_info = PART_INFO(pdrv);
|
||||||
BYTE type = PART_TYPE(pdrv);
|
BYTE type = PART_TYPE(pdrv);
|
||||||
|
|
||||||
fat_info->offset = fat_info->size = 0;
|
fat_info->offset = fat_info->size = 0;
|
||||||
fat_info->keyslot = 0xFF;
|
fat_info->keyslot = 0xFF;
|
||||||
|
|
||||||
if (type == TYPE_SDCARD) {
|
if (type == TYPE_SDCARD) {
|
||||||
if (sdmmc_sdcard_init() != 0) return STA_NOINIT|STA_NODISK;
|
if (sdmmc_sdcard_init() != 0) return STA_NOINIT|STA_NODISK;
|
||||||
fat_info->size = getMMCDevice(1)->total_size;
|
fat_info->size = getMMCDevice(1)->total_size;
|
||||||
@ -148,7 +149,7 @@ DSTATUS disk_initialize (
|
|||||||
InitRamDrive();
|
InitRamDrive();
|
||||||
fat_info->size = (GetRamDriveSize() + 0x1FF) / 0x200;
|
fat_info->size = (GetRamDriveSize() + 0x1FF) / 0x200;
|
||||||
}
|
}
|
||||||
|
|
||||||
return RES_OK;
|
return RES_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -165,9 +166,9 @@ DRESULT disk_read (
|
|||||||
DWORD sector, /* Sector address in LBA */
|
DWORD sector, /* Sector address in LBA */
|
||||||
UINT count /* Number of sectors to read */
|
UINT count /* Number of sectors to read */
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
BYTE type = PART_TYPE(pdrv);
|
BYTE type = PART_TYPE(pdrv);
|
||||||
|
|
||||||
if (type == TYPE_NONE) {
|
if (type == TYPE_NONE) {
|
||||||
return RES_PARERR;
|
return RES_PARERR;
|
||||||
} else if (type == TYPE_SDCARD) {
|
} else if (type == TYPE_SDCARD) {
|
||||||
@ -204,7 +205,7 @@ DRESULT disk_write (
|
|||||||
)
|
)
|
||||||
{
|
{
|
||||||
BYTE type = PART_TYPE(pdrv);
|
BYTE type = PART_TYPE(pdrv);
|
||||||
|
|
||||||
if (type == TYPE_NONE) {
|
if (type == TYPE_NONE) {
|
||||||
return RES_PARERR;
|
return RES_PARERR;
|
||||||
} else if (type == TYPE_SDCARD) {
|
} else if (type == TYPE_SDCARD) {
|
||||||
@ -244,7 +245,7 @@ DRESULT disk_ioctl (
|
|||||||
{
|
{
|
||||||
BYTE type = PART_TYPE(pdrv);
|
BYTE type = PART_TYPE(pdrv);
|
||||||
FATpartition* fat_info = PART_INFO(pdrv);
|
FATpartition* fat_info = PART_INFO(pdrv);
|
||||||
|
|
||||||
switch (cmd) {
|
switch (cmd) {
|
||||||
case GET_SECTOR_SIZE:
|
case GET_SECTOR_SIZE:
|
||||||
*((DWORD*) buff) = 0x200;
|
*((DWORD*) buff) = 0x200;
|
||||||
@ -261,7 +262,7 @@ DRESULT disk_ioctl (
|
|||||||
// nothing else to do here - sdmmc.c handles the rest
|
// nothing else to do here - sdmmc.c handles the rest
|
||||||
return RES_OK;
|
return RES_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
return RES_PARERR;
|
return RES_PARERR;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
@ -12,8 +12,6 @@ extern "C" {
|
|||||||
#define _USE_WRITE 1 /* 1: Enable disk_write function */
|
#define _USE_WRITE 1 /* 1: Enable disk_write function */
|
||||||
#define _USE_IOCTL 1 /* 1: Enable disk_ioctl fucntion */
|
#define _USE_IOCTL 1 /* 1: Enable disk_ioctl fucntion */
|
||||||
|
|
||||||
#include "integer.h"
|
|
||||||
|
|
||||||
|
|
||||||
/* Status of Disk Functions */
|
/* Status of Disk Functions */
|
||||||
typedef BYTE DSTATUS;
|
typedef BYTE DSTATUS;
|
||||||
@ -50,11 +48,11 @@ DRESULT disk_ioctl (BYTE pdrv, BYTE cmd, void* buff);
|
|||||||
/* Command code for disk_ioctrl fucntion */
|
/* Command code for disk_ioctrl fucntion */
|
||||||
|
|
||||||
/* Generic command (Used by FatFs) */
|
/* Generic command (Used by FatFs) */
|
||||||
#define CTRL_SYNC 0 /* Complete pending write process (needed at _FS_READONLY == 0) */
|
#define CTRL_SYNC 0 /* Complete pending write process (needed at FF_FS_READONLY == 0) */
|
||||||
#define GET_SECTOR_COUNT 1 /* Get media size (needed at _USE_MKFS == 1) */
|
#define GET_SECTOR_COUNT 1 /* Get media size (needed at FF_USE_MKFS == 1) */
|
||||||
#define GET_SECTOR_SIZE 2 /* Get sector size (needed at FF_MAX_SS != FF_MIN_SS) */
|
#define GET_SECTOR_SIZE 2 /* Get sector size (needed at FF_MAX_SS != FF_MIN_SS) */
|
||||||
#define GET_BLOCK_SIZE 3 /* Get erase block size (needed at _USE_MKFS == 1) */
|
#define GET_BLOCK_SIZE 3 /* Get erase block size (needed at FF_USE_MKFS == 1) */
|
||||||
#define CTRL_TRIM 4 /* Inform device that the data on the block of sectors is no longer used (needed at _USE_TRIM == 1) */
|
#define CTRL_TRIM 4 /* Inform device that the data on the block of sectors is no longer used (needed at FF_USE_TRIM == 1) */
|
||||||
|
|
||||||
/* Generic command (Not used by FatFs) */
|
/* Generic command (Not used by FatFs) */
|
||||||
#define CTRL_POWER 5 /* Get/Set power status */
|
#define CTRL_POWER 5 /* Get/Set power status */
|
||||||
|
File diff suppressed because it is too large
Load Diff
@ -1,8 +1,8 @@
|
|||||||
/*----------------------------------------------------------------------------/
|
/*----------------------------------------------------------------------------/
|
||||||
/ FatFs - Generic FAT Filesystem module R0.13b /
|
/ FatFs - Generic FAT Filesystem module R0.14 /
|
||||||
/-----------------------------------------------------------------------------/
|
/-----------------------------------------------------------------------------/
|
||||||
/
|
/
|
||||||
/ Copyright (C) 2018, ChaN, all right reserved.
|
/ Copyright (C) 2019, ChaN, all right reserved.
|
||||||
/
|
/
|
||||||
/ FatFs module is an open source software. Redistribution and use of FatFs in
|
/ FatFs module is an open source software. Redistribution and use of FatFs in
|
||||||
/ source and binary forms, with or without modification, are permitted provided
|
/ source and binary forms, with or without modification, are permitted provided
|
||||||
@ -20,13 +20,12 @@
|
|||||||
|
|
||||||
|
|
||||||
#ifndef FF_DEFINED
|
#ifndef FF_DEFINED
|
||||||
#define FF_DEFINED 63463 /* Revision ID */
|
#define FF_DEFINED 86606 /* Revision ID */
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
extern "C" {
|
extern "C" {
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#include "integer.h" /* Basic integer types */
|
|
||||||
#include "ffconf.h" /* FatFs configuration options */
|
#include "ffconf.h" /* FatFs configuration options */
|
||||||
|
|
||||||
#if FF_DEFINED != FFCONF_DEF
|
#if FF_DEFINED != FFCONF_DEF
|
||||||
@ -34,6 +33,30 @@ extern "C" {
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
/* Integer types used for FatFs API */
|
||||||
|
|
||||||
|
#if defined(_WIN32) /* Main development platform */
|
||||||
|
#define FF_INTDEF 2
|
||||||
|
#include <windows.h>
|
||||||
|
typedef unsigned __int64 QWORD;
|
||||||
|
#elif (defined(__STDC_VERSION__) && __STDC_VERSION__ >= 199901L) || defined(__cplusplus) /* C99 or later */
|
||||||
|
#define FF_INTDEF 2
|
||||||
|
#include <stdint.h>
|
||||||
|
typedef unsigned int UINT; /* int must be 16-bit or 32-bit */
|
||||||
|
typedef unsigned char BYTE; /* char must be 8-bit */
|
||||||
|
typedef uint16_t WORD; /* 16-bit unsigned integer */
|
||||||
|
typedef uint32_t DWORD; /* 32-bit unsigned integer */
|
||||||
|
typedef uint64_t QWORD; /* 64-bit unsigned integer */
|
||||||
|
typedef WORD WCHAR; /* UTF-16 character type */
|
||||||
|
#else /* Earlier than C99 */
|
||||||
|
#define FF_INTDEF 1
|
||||||
|
typedef unsigned int UINT; /* int must be 16-bit or 32-bit */
|
||||||
|
typedef unsigned char BYTE; /* char must be 8-bit */
|
||||||
|
typedef unsigned short WORD; /* 16-bit unsigned integer */
|
||||||
|
typedef unsigned long DWORD; /* 32-bit unsigned integer */
|
||||||
|
typedef WORD WCHAR; /* UTF-16 character type */
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
/* Definitions of volume management */
|
/* Definitions of volume management */
|
||||||
|
|
||||||
@ -42,7 +65,7 @@ typedef struct {
|
|||||||
BYTE pd; /* Physical drive number */
|
BYTE pd; /* Physical drive number */
|
||||||
BYTE pt; /* Partition: 0:Auto detect, 1-4:Forced partition) */
|
BYTE pt; /* Partition: 0:Auto detect, 1-4:Forced partition) */
|
||||||
} PARTITION;
|
} PARTITION;
|
||||||
extern PARTITION VolToPart[]; /* Volume - Partition resolution table */
|
extern PARTITION VolToPart[]; /* Volume - Partition mapping table */
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if FF_STR_VOLUME_ID
|
#if FF_STR_VOLUME_ID
|
||||||
@ -82,12 +105,24 @@ typedef char TCHAR;
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
/* Type of file size variables */
|
/* Type of file size and LBA variables */
|
||||||
|
|
||||||
#if FF_FS_EXFAT
|
#if FF_FS_EXFAT
|
||||||
|
#if FF_INTDEF != 2
|
||||||
|
#error exFAT feature wants C99 or later
|
||||||
|
#endif
|
||||||
typedef QWORD FSIZE_t;
|
typedef QWORD FSIZE_t;
|
||||||
|
#if FF_LBA64
|
||||||
|
typedef QWORD LBA_t;
|
||||||
#else
|
#else
|
||||||
|
typedef DWORD LBA_t;
|
||||||
|
#endif
|
||||||
|
#else
|
||||||
|
#if FF_LBA64
|
||||||
|
#error exFAT needs to be enabled when enable 64-bit LBA
|
||||||
|
#endif
|
||||||
typedef DWORD FSIZE_t;
|
typedef DWORD FSIZE_t;
|
||||||
|
typedef DWORD LBA_t;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
@ -95,8 +130,8 @@ typedef DWORD FSIZE_t;
|
|||||||
/* Filesystem object structure (FATFS) */
|
/* Filesystem object structure (FATFS) */
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
BYTE fs_type; /* Filesystem type (0:N/A) */
|
BYTE fs_type; /* Filesystem type (0:not mounted) */
|
||||||
BYTE pdrv; /* Physical drive number */
|
BYTE pdrv; /* Associated physical drive */
|
||||||
BYTE n_fats; /* Number of FATs (1 or 2) */
|
BYTE n_fats; /* Number of FATs (1 or 2) */
|
||||||
BYTE wflag; /* win[] flag (b0:dirty) */
|
BYTE wflag; /* win[] flag (b0:dirty) */
|
||||||
BYTE fsi_flag; /* FSINFO flags (b7:disabled, b0:dirty) */
|
BYTE fsi_flag; /* FSINFO flags (b7:disabled, b0:dirty) */
|
||||||
@ -129,11 +164,14 @@ typedef struct {
|
|||||||
#endif
|
#endif
|
||||||
DWORD n_fatent; /* Number of FAT entries (number of clusters + 2) */
|
DWORD n_fatent; /* Number of FAT entries (number of clusters + 2) */
|
||||||
DWORD fsize; /* Size of an FAT [sectors] */
|
DWORD fsize; /* Size of an FAT [sectors] */
|
||||||
DWORD volbase; /* Volume base sector */
|
LBA_t volbase; /* Volume base sector */
|
||||||
DWORD fatbase; /* FAT base sector */
|
LBA_t fatbase; /* FAT base sector */
|
||||||
DWORD dirbase; /* Root directory base sector/cluster */
|
LBA_t dirbase; /* Root directory base sector/cluster */
|
||||||
DWORD database; /* Data base sector */
|
LBA_t database; /* Data base sector */
|
||||||
DWORD winsect; /* Current sector appearing in the win[] */
|
#if FF_FS_EXFAT
|
||||||
|
LBA_t bitbase; /* Allocation bitmap base sector */
|
||||||
|
#endif
|
||||||
|
LBA_t winsect; /* Current sector appearing in the win[] */
|
||||||
BYTE win[FF_MAX_SS]; /* Disk access window for Directory, FAT (and file data at tiny cfg) */
|
BYTE win[FF_MAX_SS]; /* Disk access window for Directory, FAT (and file data at tiny cfg) */
|
||||||
} FATFS;
|
} FATFS;
|
||||||
|
|
||||||
@ -145,7 +183,7 @@ typedef struct {
|
|||||||
FATFS* fs; /* Pointer to the hosting volume of this object */
|
FATFS* fs; /* Pointer to the hosting volume of this object */
|
||||||
WORD id; /* Hosting volume mount ID */
|
WORD id; /* Hosting volume mount ID */
|
||||||
BYTE attr; /* Object attribute */
|
BYTE attr; /* Object attribute */
|
||||||
BYTE stat; /* Object chain status (b1-0: =0:not contiguous, =2:contiguous, =3:flagmented in this session, b2:sub-directory stretched) */
|
BYTE stat; /* Object chain status (b1-0: =0:not contiguous, =2:contiguous, =3:fragmented in this session, b2:sub-directory stretched) */
|
||||||
DWORD sclust; /* Object data start cluster (0:no cluster or root directory) */
|
DWORD sclust; /* Object data start cluster (0:no cluster or root directory) */
|
||||||
FSIZE_t objsize; /* Object size (valid when sclust != 0) */
|
FSIZE_t objsize; /* Object size (valid when sclust != 0) */
|
||||||
#if FF_FS_EXFAT
|
#if FF_FS_EXFAT
|
||||||
@ -170,9 +208,9 @@ typedef struct {
|
|||||||
BYTE err; /* Abort flag (error code) */
|
BYTE err; /* Abort flag (error code) */
|
||||||
FSIZE_t fptr; /* File read/write pointer (Zeroed on file open) */
|
FSIZE_t fptr; /* File read/write pointer (Zeroed on file open) */
|
||||||
DWORD clust; /* Current cluster of fpter (invalid when fptr is 0) */
|
DWORD clust; /* Current cluster of fpter (invalid when fptr is 0) */
|
||||||
DWORD sect; /* Sector number appearing in buf[] (0:invalid) */
|
LBA_t sect; /* Sector number appearing in buf[] (0:invalid) */
|
||||||
#if !FF_FS_READONLY
|
#if !FF_FS_READONLY
|
||||||
DWORD dir_sect; /* Sector number containing the directory entry (not used at exFAT) */
|
LBA_t dir_sect; /* Sector number containing the directory entry (not used at exFAT) */
|
||||||
BYTE* dir_ptr; /* Pointer to the directory entry in the win[] (not used at exFAT) */
|
BYTE* dir_ptr; /* Pointer to the directory entry in the win[] (not used at exFAT) */
|
||||||
#endif
|
#endif
|
||||||
#if FF_USE_FASTSEEK
|
#if FF_USE_FASTSEEK
|
||||||
@ -191,7 +229,7 @@ typedef struct {
|
|||||||
FFOBJID obj; /* Object identifier */
|
FFOBJID obj; /* Object identifier */
|
||||||
DWORD dptr; /* Current read/write offset */
|
DWORD dptr; /* Current read/write offset */
|
||||||
DWORD clust; /* Current cluster */
|
DWORD clust; /* Current cluster */
|
||||||
DWORD sect; /* Current sector (0:Read operation has terminated) */
|
LBA_t sect; /* Current sector (0:Read operation has terminated) */
|
||||||
BYTE* dir; /* Pointer to the directory item in the win[] */
|
BYTE* dir; /* Pointer to the directory item in the win[] */
|
||||||
BYTE fn[12]; /* SFN (in/out) {body[8],ext[3],status[1]} */
|
BYTE fn[12]; /* SFN (in/out) {body[8],ext[3],status[1]} */
|
||||||
#if FF_USE_LFN
|
#if FF_USE_LFN
|
||||||
@ -221,6 +259,18 @@ typedef struct {
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/* Format parameter structure (MKFS_PARM) */
|
||||||
|
|
||||||
|
typedef struct {
|
||||||
|
BYTE fmt; /* Format option (FM_FAT, FM_FAT32, FM_EXFAT and FM_SFD) */
|
||||||
|
BYTE n_fat; /* Number of FATs */
|
||||||
|
UINT align; /* Data area alignment (sector) */
|
||||||
|
UINT n_root; /* Number of root directory entries */
|
||||||
|
DWORD au_size; /* Cluster size (byte) */
|
||||||
|
} MKFS_PARM;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/* File function return code (FRESULT) */
|
/* File function return code (FRESULT) */
|
||||||
|
|
||||||
typedef enum {
|
typedef enum {
|
||||||
@ -276,10 +326,10 @@ FRESULT f_getfree (const TCHAR* path, DWORD* nclst, FATFS** fatfs); /* Get numbe
|
|||||||
FRESULT f_getlabel (const TCHAR* path, TCHAR* label, DWORD* vsn); /* Get volume label */
|
FRESULT f_getlabel (const TCHAR* path, TCHAR* label, DWORD* vsn); /* Get volume label */
|
||||||
FRESULT f_setlabel (const TCHAR* label); /* Set volume label */
|
FRESULT f_setlabel (const TCHAR* label); /* Set volume label */
|
||||||
FRESULT f_forward (FIL* fp, UINT(*func)(const BYTE*,UINT), UINT btf, UINT* bf); /* Forward data to the stream */
|
FRESULT f_forward (FIL* fp, UINT(*func)(const BYTE*,UINT), UINT btf, UINT* bf); /* Forward data to the stream */
|
||||||
FRESULT f_expand (FIL* fp, FSIZE_t szf, BYTE opt); /* Allocate a contiguous block to the file */
|
FRESULT f_expand (FIL* fp, FSIZE_t fsz, BYTE opt); /* Allocate a contiguous block to the file */
|
||||||
FRESULT f_mount (FATFS* fs, const TCHAR* path, BYTE opt); /* Mount/Unmount a logical drive */
|
FRESULT f_mount (FATFS* fs, const TCHAR* path, BYTE opt); /* Mount/Unmount a logical drive */
|
||||||
FRESULT f_mkfs (const TCHAR* path, BYTE opt, DWORD au, void* work, UINT len); /* Create a FAT volume */
|
FRESULT f_mkfs (const TCHAR* path, const MKFS_PARM* opt, void* work, UINT len); /* Create a FAT volume */
|
||||||
FRESULT f_fdisk (BYTE pdrv, const DWORD* szt, void* work); /* Divide a physical drive into some partitions */
|
FRESULT f_fdisk (BYTE pdrv, const LBA_t ptbl[], void* work); /* Divide a physical drive into some partitions */
|
||||||
FRESULT f_setcp (WORD cp); /* Set current code page */
|
FRESULT f_setcp (WORD cp); /* Set current code page */
|
||||||
int f_putc (TCHAR c, FIL* fp); /* Put a character to the file */
|
int f_putc (TCHAR c, FIL* fp); /* Put a character to the file */
|
||||||
int f_puts (const TCHAR* str, FIL* cp); /* Put a string to the file */
|
int f_puts (const TCHAR* str, FIL* cp); /* Put a string to the file */
|
||||||
|
@ -1,8 +1,8 @@
|
|||||||
/*---------------------------------------------------------------------------/
|
/*---------------------------------------------------------------------------/
|
||||||
/ FatFs - Configuration file
|
/ FatFs Functional Configurations
|
||||||
/---------------------------------------------------------------------------*/
|
/---------------------------------------------------------------------------*/
|
||||||
|
|
||||||
#define FFCONF_DEF 63463 /* Revision ID */
|
#define FFCONF_DEF 86606 /* Revision ID */
|
||||||
|
|
||||||
/*---------------------------------------------------------------------------/
|
/*---------------------------------------------------------------------------/
|
||||||
/ Function Configurations
|
/ Function Configurations
|
||||||
@ -110,11 +110,11 @@
|
|||||||
/ requiers certain internal working buffer occupies (FF_MAX_LFN + 1) * 2 bytes and
|
/ requiers certain internal working buffer occupies (FF_MAX_LFN + 1) * 2 bytes and
|
||||||
/ additional (FF_MAX_LFN + 44) / 15 * 32 bytes when exFAT is enabled.
|
/ additional (FF_MAX_LFN + 44) / 15 * 32 bytes when exFAT is enabled.
|
||||||
/ The FF_MAX_LFN defines size of the working buffer in UTF-16 code unit and it can
|
/ The FF_MAX_LFN defines size of the working buffer in UTF-16 code unit and it can
|
||||||
/ be in range of 12 to 255. It is recommended to be set 255 to fully support LFN
|
/ be in range of 12 to 255. It is recommended to be set it 255 to fully support LFN
|
||||||
/ specification.
|
/ specification.
|
||||||
/ When use stack for the working buffer, take care on stack overflow. When use heap
|
/ When use stack for the working buffer, take care on stack overflow. When use heap
|
||||||
/ memory for the working buffer, memory management functions, ff_memalloc() and
|
/ memory for the working buffer, memory management functions, ff_memalloc() and
|
||||||
/ ff_memfree() in ffsystem.c, need to be added to the project. */
|
/ ff_memfree() exemplified in ffsystem.c, need to be added to the project. */
|
||||||
|
|
||||||
|
|
||||||
#define FF_LFN_UNICODE 2
|
#define FF_LFN_UNICODE 2
|
||||||
@ -200,24 +200,22 @@
|
|||||||
/ GET_SECTOR_SIZE command. */
|
/ GET_SECTOR_SIZE command. */
|
||||||
|
|
||||||
|
|
||||||
|
#define FF_LBA64 0
|
||||||
|
/* This option switches support for 64-bit LBA. (0:Disable or 1:Enable)
|
||||||
|
/ To enable the 64-bit LBA, also exFAT needs to be enabled. (FF_FS_EXFAT == 1) */
|
||||||
|
|
||||||
|
|
||||||
|
#define FF_MIN_GPT 0x100000000
|
||||||
|
/* Minimum number of sectors to switch GPT format to create partition in f_mkfs and
|
||||||
|
/ f_fdisk function. 0x100000000 max. This option has no effect when FF_LBA64 == 0. */
|
||||||
|
|
||||||
|
|
||||||
#define FF_USE_TRIM 0
|
#define FF_USE_TRIM 0
|
||||||
/* This option switches support for ATA-TRIM. (0:Disable or 1:Enable)
|
/* This option switches support for ATA-TRIM. (0:Disable or 1:Enable)
|
||||||
/ To enable Trim function, also CTRL_TRIM command should be implemented to the
|
/ To enable Trim function, also CTRL_TRIM command should be implemented to the
|
||||||
/ disk_ioctl() function. */
|
/ disk_ioctl() function. */
|
||||||
|
|
||||||
|
|
||||||
#define FF_FS_NOFSINFO 0
|
|
||||||
/* If you need to know correct free space on the FAT32 volume, set bit 0 of this
|
|
||||||
/ option, and f_getfree() function at first time after volume mount will force
|
|
||||||
/ a full FAT scan. Bit 1 controls the use of last allocated cluster number.
|
|
||||||
/
|
|
||||||
/ bit0=0: Use free cluster count in the FSINFO if available.
|
|
||||||
/ bit0=1: Do not trust free cluster count in the FSINFO.
|
|
||||||
/ bit1=0: Use last allocated cluster number in the FSINFO if available.
|
|
||||||
/ bit1=1: Do not trust last allocated cluster number in the FSINFO.
|
|
||||||
*/
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/*---------------------------------------------------------------------------/
|
/*---------------------------------------------------------------------------/
|
||||||
/ System Configurations
|
/ System Configurations
|
||||||
@ -232,14 +230,14 @@
|
|||||||
|
|
||||||
#define FF_FS_EXFAT 0
|
#define FF_FS_EXFAT 0
|
||||||
/* This option switches support for exFAT filesystem. (0:Disable or 1:Enable)
|
/* This option switches support for exFAT filesystem. (0:Disable or 1:Enable)
|
||||||
/ To enable exFAT, also LFN needs to be enabled.
|
/ To enable exFAT, also LFN needs to be enabled. (FF_USE_LFN >= 1)
|
||||||
/ Note that enabling exFAT discards ANSI C (C89) compatibility. */
|
/ Note that enabling exFAT discards ANSI C (C89) compatibility. */
|
||||||
|
|
||||||
|
|
||||||
#define FF_FS_NORTC 0
|
#define FF_FS_NORTC 0
|
||||||
#define FF_NORTC_MON 1
|
#define FF_NORTC_MON 1
|
||||||
#define FF_NORTC_MDAY 1
|
#define FF_NORTC_MDAY 1
|
||||||
#define FF_NORTC_YEAR 2018
|
#define FF_NORTC_YEAR 2019
|
||||||
/* The option FF_FS_NORTC switches timestamp functiton. If the system does not have
|
/* The option FF_FS_NORTC switches timestamp functiton. If the system does not have
|
||||||
/ any RTC function or valid timestamp is not needed, set FF_FS_NORTC = 1 to disable
|
/ any RTC function or valid timestamp is not needed, set FF_FS_NORTC = 1 to disable
|
||||||
/ the timestamp function. Every object modified by FatFs will have a fixed timestamp
|
/ the timestamp function. Every object modified by FatFs will have a fixed timestamp
|
||||||
@ -247,7 +245,19 @@
|
|||||||
/ To enable timestamp function (FF_FS_NORTC = 0), get_fattime() function need to be
|
/ To enable timestamp function (FF_FS_NORTC = 0), get_fattime() function need to be
|
||||||
/ added to the project to read current time form real-time clock. FF_NORTC_MON,
|
/ added to the project to read current time form real-time clock. FF_NORTC_MON,
|
||||||
/ FF_NORTC_MDAY and FF_NORTC_YEAR have no effect.
|
/ FF_NORTC_MDAY and FF_NORTC_YEAR have no effect.
|
||||||
/ These options have no effect at read-only configuration (FF_FS_READONLY = 1). */
|
/ These options have no effect in read-only configuration (FF_FS_READONLY = 1). */
|
||||||
|
|
||||||
|
|
||||||
|
#define FF_FS_NOFSINFO 0
|
||||||
|
/* If you need to know correct free space on the FAT32 volume, set bit 0 of this
|
||||||
|
/ option, and f_getfree() function at first time after volume mount will force
|
||||||
|
/ a full FAT scan. Bit 1 controls the use of last allocated cluster number.
|
||||||
|
/
|
||||||
|
/ bit0=0: Use free cluster count in the FSINFO if available.
|
||||||
|
/ bit0=1: Do not trust free cluster count in the FSINFO.
|
||||||
|
/ bit1=0: Use last allocated cluster number in the FSINFO if available.
|
||||||
|
/ bit1=1: Do not trust last allocated cluster number in the FSINFO.
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
#define FF_FS_LOCK 32
|
#define FF_FS_LOCK 32
|
||||||
@ -262,6 +272,7 @@
|
|||||||
/ lock control is independent of re-entrancy. */
|
/ lock control is independent of re-entrancy. */
|
||||||
|
|
||||||
|
|
||||||
|
/* #include <somertos.h> // O/S definitions */
|
||||||
#define FF_FS_REENTRANT 0
|
#define FF_FS_REENTRANT 0
|
||||||
#define FF_FS_TIMEOUT 1000
|
#define FF_FS_TIMEOUT 1000
|
||||||
#define FF_SYNC_t HANDLE
|
#define FF_SYNC_t HANDLE
|
||||||
@ -282,8 +293,6 @@
|
|||||||
/ SemaphoreHandle_t and etc. A header file for O/S definitions needs to be
|
/ SemaphoreHandle_t and etc. A header file for O/S definitions needs to be
|
||||||
/ included somewhere in the scope of ff.h. */
|
/ included somewhere in the scope of ff.h. */
|
||||||
|
|
||||||
/* #include <windows.h> // O/S definitions */
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/*--- End of configuration options ---*/
|
/*--- End of configuration options ---*/
|
||||||
|
@ -1,20 +1,19 @@
|
|||||||
/*------------------------------------------------------------------------*/
|
/*------------------------------------------------------------------------*/
|
||||||
/* Sample Code of OS Dependent Functions for FatFs */
|
/* Sample Code of OS Dependent Functions for FatFs */
|
||||||
/* (C)ChaN, 2017 */
|
/* (C)ChaN, 2018 */
|
||||||
/*------------------------------------------------------------------------*/
|
/*------------------------------------------------------------------------*/
|
||||||
|
|
||||||
|
|
||||||
#include "ff.h"
|
#include "ff.h"
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#if FF_USE_LFN == 3 /* Dynamic memory allocation */
|
#if FF_USE_LFN == 3 /* Dynamic memory allocation */
|
||||||
|
|
||||||
/*------------------------------------------------------------------------*/
|
/*------------------------------------------------------------------------*/
|
||||||
/* Allocate a memory block */
|
/* Allocate a memory block */
|
||||||
/*------------------------------------------------------------------------*/
|
/*------------------------------------------------------------------------*/
|
||||||
|
|
||||||
void* ff_memalloc ( /* Returns pointer to the allocated memory block (null on not enough core) */
|
void* ff_memalloc ( /* Returns pointer to the allocated memory block (null if not enough core) */
|
||||||
UINT msize /* Number of bytes to allocate */
|
UINT msize /* Number of bytes to allocate */
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
@ -27,7 +26,7 @@ void* ff_memalloc ( /* Returns pointer to the allocated memory block (null on no
|
|||||||
/*------------------------------------------------------------------------*/
|
/*------------------------------------------------------------------------*/
|
||||||
|
|
||||||
void ff_memfree (
|
void ff_memfree (
|
||||||
void* mblock /* Pointer to the memory block to free (nothing to do for null) */
|
void* mblock /* Pointer to the memory block to free (nothing to do if null) */
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
free(mblock); /* Free the memory block with POSIX API */
|
free(mblock); /* Free the memory block with POSIX API */
|
||||||
@ -47,7 +46,7 @@ void ff_memfree (
|
|||||||
/ When a 0 is returned, the f_mount() function fails with FR_INT_ERR.
|
/ When a 0 is returned, the f_mount() function fails with FR_INT_ERR.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
//const osMutexDef_t Mutex[FF_VOLUMES]; /* CMSIS-RTOS */
|
//const osMutexDef_t Mutex[FF_VOLUMES]; /* Table of CMSIS-RTOS mutex */
|
||||||
|
|
||||||
|
|
||||||
int ff_cre_syncobj ( /* 1:Function succeeded, 0:Could not create the sync object */
|
int ff_cre_syncobj ( /* 1:Function succeeded, 0:Could not create the sync object */
|
||||||
@ -74,7 +73,7 @@ int ff_cre_syncobj ( /* 1:Function succeeded, 0:Could not create the sync object
|
|||||||
// return (int)(*sobj != NULL);
|
// return (int)(*sobj != NULL);
|
||||||
|
|
||||||
/* CMSIS-RTOS */
|
/* CMSIS-RTOS */
|
||||||
// *sobj = osMutexCreate(Mutex + vol);
|
// *sobj = osMutexCreate(&Mutex[vol]);
|
||||||
// return (int)(*sobj != NULL);
|
// return (int)(*sobj != NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
/*------------------------------------------------------------------------*/
|
/*------------------------------------------------------------------------*/
|
||||||
/* Unicode handling functions for FatFs R0.13b */
|
/* Unicode handling functions for FatFs R0.13+ */
|
||||||
/*------------------------------------------------------------------------*/
|
/*------------------------------------------------------------------------*/
|
||||||
/* This module will occupy a huge memory in the .const section when the /
|
/* This module will occupy a huge memory in the .const section when the /
|
||||||
/ FatFs is configured for LFN with DBCS. If the system has any Unicode /
|
/ FatFs is configured for LFN with DBCS. If the system has any Unicode /
|
||||||
@ -7,7 +7,7 @@
|
|||||||
/ that function to avoid silly memory consumption. /
|
/ that function to avoid silly memory consumption. /
|
||||||
/-------------------------------------------------------------------------*/
|
/-------------------------------------------------------------------------*/
|
||||||
/*
|
/*
|
||||||
/ Copyright (C) 2018, ChaN, all right reserved.
|
/ Copyright (C) 2014, ChaN, all right reserved.
|
||||||
/
|
/
|
||||||
/ FatFs module is an open source software. Redistribution and use of FatFs in
|
/ FatFs module is an open source software. Redistribution and use of FatFs in
|
||||||
/ source and binary forms, with or without modification, are permitted provided
|
/ source and binary forms, with or without modification, are permitted provided
|
||||||
@ -25,11 +25,7 @@
|
|||||||
|
|
||||||
#include "ff.h"
|
#include "ff.h"
|
||||||
|
|
||||||
#if FF_USE_LFN /* This module is blanked when non-LFN configuration */
|
#if FF_USE_LFN /* This module will be blanked if non-LFN configuration */
|
||||||
|
|
||||||
#if FF_DEFINED != 63463 /* Revision ID */
|
|
||||||
#error Wrong include file (ff.h).
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#define MERGE2(a, b) a ## b
|
#define MERGE2(a, b) a ## b
|
||||||
#define CVTBL(tbl, cp) MERGE2(tbl, cp)
|
#define CVTBL(tbl, cp) MERGE2(tbl, cp)
|
||||||
@ -15245,7 +15241,7 @@ WCHAR ff_uni2oem ( /* Returns OEM code character, zero on error */
|
|||||||
return c;
|
return c;
|
||||||
}
|
}
|
||||||
|
|
||||||
WCHAR ff_oem2uni ( /* Returns Unicode character, zero on error */
|
WCHAR ff_oem2uni ( /* Returns Unicode character in UTF-16, zero on error */
|
||||||
WCHAR oem, /* OEM code to be converted */
|
WCHAR oem, /* OEM code to be converted */
|
||||||
WORD cp /* Code page for the conversion */
|
WORD cp /* Code page for the conversion */
|
||||||
)
|
)
|
||||||
@ -15312,7 +15308,7 @@ WCHAR ff_uni2oem ( /* Returns OEM code character, zero on error */
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
WCHAR ff_oem2uni ( /* Returns Unicode character, zero on error */
|
WCHAR ff_oem2uni ( /* Returns Unicode character in UTF-16, zero on error */
|
||||||
WCHAR oem, /* OEM code to be converted */
|
WCHAR oem, /* OEM code to be converted */
|
||||||
WORD cp /* Code page for the conversion */
|
WORD cp /* Code page for the conversion */
|
||||||
)
|
)
|
||||||
@ -15411,7 +15407,7 @@ WCHAR ff_uni2oem ( /* Returns OEM code character, zero on error */
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
WCHAR ff_oem2uni ( /* Returns Unicode character, zero on error */
|
WCHAR ff_oem2uni ( /* Returns Unicode character in UTF-16, zero on error */
|
||||||
WCHAR oem, /* OEM code to be converted (DBC if >=0x100) */
|
WCHAR oem, /* OEM code to be converted (DBC if >=0x100) */
|
||||||
WORD cp /* Code page for the conversion */
|
WORD cp /* Code page for the conversion */
|
||||||
)
|
)
|
||||||
|
@ -1,36 +0,0 @@
|
|||||||
/*-------------------------------------------*/
|
|
||||||
/* Integer type definitions for FatFs module */
|
|
||||||
/*-------------------------------------------*/
|
|
||||||
|
|
||||||
#ifndef FF_INTEGER
|
|
||||||
#define FF_INTEGER
|
|
||||||
|
|
||||||
#ifdef _WIN32 /* FatFs development platform */
|
|
||||||
|
|
||||||
#include <windows.h>
|
|
||||||
typedef unsigned __int64 QWORD;
|
|
||||||
|
|
||||||
#else /* Embedded platform */
|
|
||||||
|
|
||||||
/* These types MUST be 16-bit or 32-bit */
|
|
||||||
typedef int INT;
|
|
||||||
typedef unsigned int UINT;
|
|
||||||
|
|
||||||
/* This type MUST be 8-bit */
|
|
||||||
typedef unsigned char BYTE;
|
|
||||||
|
|
||||||
/* These types MUST be 16-bit */
|
|
||||||
typedef short SHORT;
|
|
||||||
typedef unsigned short WORD;
|
|
||||||
typedef unsigned short WCHAR;
|
|
||||||
|
|
||||||
/* These types MUST be 32-bit */
|
|
||||||
typedef long LONG;
|
|
||||||
typedef unsigned long DWORD;
|
|
||||||
|
|
||||||
/* This type MUST be 64-bit (Remove this for ANSI C (C89) compatibility) */
|
|
||||||
typedef unsigned long long QWORD;
|
|
||||||
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#endif
|
|
@ -5,7 +5,7 @@ u32 ValidateMbrHeader(MbrHeader* mbr) {
|
|||||||
u32 sector = 1; // check partitions
|
u32 sector = 1; // check partitions
|
||||||
for (u32 i = 0; i < 4; i++) {
|
for (u32 i = 0; i < 4; i++) {
|
||||||
MbrPartitionInfo* partition = mbr->partitions + i;
|
MbrPartitionInfo* partition = mbr->partitions + i;
|
||||||
if (!partition->count && i) continue;
|
if (!partition->count && i) continue;
|
||||||
else if (!partition->count) return 1; // first partition can't be empty
|
else if (!partition->count) return 1; // first partition can't be empty
|
||||||
if ((partition->type != 0x1) && (partition->type != 0x4) && (partition->type != 0x6) &&
|
if ((partition->type != 0x1) && (partition->type != 0x4) && (partition->type != 0x6) &&
|
||||||
(partition->type != 0xB) && (partition->type != 0xC) && (partition->type != 0xE))
|
(partition->type != 0xB) && (partition->type != 0xC) && (partition->type != 0xE))
|
||||||
@ -22,7 +22,7 @@ u32 ValidateFatHeader(void* fat) {
|
|||||||
if (strncmp(fat32->fs_type, "FAT32 ", 8) == 0)
|
if (strncmp(fat32->fs_type, "FAT32 ", 8) == 0)
|
||||||
return 0; // is FAT32 header
|
return 0; // is FAT32 header
|
||||||
Fat16Header* fat16 = (Fat16Header*) fat;
|
Fat16Header* fat16 = (Fat16Header*) fat;
|
||||||
if ((strncmp(fat16->fs_type, "FAT16 ", 8) == 0) ||
|
if ((strncmp(fat16->fs_type, "FAT16 ", 8) == 0) ||
|
||||||
(strncmp(fat16->fs_type, "FAT12 ", 8) == 0) ||
|
(strncmp(fat16->fs_type, "FAT12 ", 8) == 0) ||
|
||||||
(strncmp(fat16->fs_type, "FAT ", 8) == 0))
|
(strncmp(fat16->fs_type, "FAT ", 8) == 0))
|
||||||
return 0; // is FAT16 / FAT12 header
|
return 0; // is FAT16 / FAT12 header
|
||||||
|
@ -11,13 +11,13 @@ typedef struct {
|
|||||||
u8 chs_end[3]; // 0xFE 0xFF 0xFF
|
u8 chs_end[3]; // 0xFE 0xFF 0xFF
|
||||||
u32 sector; // 0x2000 (4MB offset, 512 byte sectors)
|
u32 sector; // 0x2000 (4MB offset, 512 byte sectors)
|
||||||
u32 count;
|
u32 count;
|
||||||
} __attribute__((packed)) MbrPartitionInfo;
|
} PACKED_ALIGN(2) MbrPartitionInfo;
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
char text[446];
|
char text[446];
|
||||||
MbrPartitionInfo partitions[4];
|
MbrPartitionInfo partitions[4];
|
||||||
u16 magic; // 0xAA55
|
u16 magic; // 0xAA55
|
||||||
} __attribute__((packed)) MbrHeader;
|
} PACKED_ALIGN(2) MbrHeader;
|
||||||
|
|
||||||
typedef struct { // unused
|
typedef struct { // unused
|
||||||
u32 signature0; // 0x41615252
|
u32 signature0; // 0x41615252
|
||||||
@ -27,7 +27,7 @@ typedef struct { // unused
|
|||||||
u32 clr_next; // 0xFFFFFFFF
|
u32 clr_next; // 0xFFFFFFFF
|
||||||
u8 reserved1[14];
|
u8 reserved1[14];
|
||||||
u16 magic; // 0xAA55
|
u16 magic; // 0xAA55
|
||||||
} __attribute__((packed)) FileSystemInfo;
|
} PACKED_STRUCT FileSystemInfo;
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
u8 jmp[3]; // 0x90 0x00 0xEB
|
u8 jmp[3]; // 0x90 0x00 0xEB
|
||||||
@ -50,7 +50,7 @@ typedef struct {
|
|||||||
u32 clr_root; // 0x02
|
u32 clr_root; // 0x02
|
||||||
u16 sct_fsinfo; // 0x01
|
u16 sct_fsinfo; // 0x01
|
||||||
u16 sct_backup; // 0x06
|
u16 sct_backup; // 0x06
|
||||||
u8 reserved3[12];
|
u8 reserved3[12];
|
||||||
u8 ndrive; // 0x80
|
u8 ndrive; // 0x80
|
||||||
u8 head_cur; // 0x00
|
u8 head_cur; // 0x00
|
||||||
u8 boot_sig; // 0x29
|
u8 boot_sig; // 0x29
|
||||||
@ -59,7 +59,7 @@ typedef struct {
|
|||||||
char fs_type[8]; // "FAT32 "
|
char fs_type[8]; // "FAT32 "
|
||||||
u8 reserved4[420];
|
u8 reserved4[420];
|
||||||
u16 magic; // 0xAA55
|
u16 magic; // 0xAA55
|
||||||
} __attribute__((packed)) Fat32Header;
|
} PACKED_STRUCT Fat32Header;
|
||||||
|
|
||||||
typedef struct { // this struct is not tested enough!
|
typedef struct { // this struct is not tested enough!
|
||||||
u8 jmp[3]; // 0x90 0x00 0xEB
|
u8 jmp[3]; // 0x90 0x00 0xEB
|
||||||
@ -84,7 +84,7 @@ typedef struct { // this struct is not tested enough!
|
|||||||
char fs_type[8]; // "FAT16 "
|
char fs_type[8]; // "FAT16 "
|
||||||
u8 reserved4[448];
|
u8 reserved4[448];
|
||||||
u16 magic; // 0xAA55
|
u16 magic; // 0xAA55
|
||||||
} __attribute__((packed)) Fat16Header;
|
} PACKED_STRUCT Fat16Header;
|
||||||
|
|
||||||
u32 ValidateMbrHeader(MbrHeader* mbr);
|
u32 ValidateMbrHeader(MbrHeader* mbr);
|
||||||
u32 ValidateFatHeader(void* fat);
|
u32 ValidateFatHeader(void* fat);
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
#include "filetype.h"
|
#include "filetype.h"
|
||||||
#include "fsutil.h"
|
#include "fsutil.h"
|
||||||
|
#include "image.h"
|
||||||
#include "fatmbr.h"
|
#include "fatmbr.h"
|
||||||
#include "nand.h"
|
#include "nand.h"
|
||||||
#include "game.h"
|
#include "game.h"
|
||||||
@ -7,35 +8,39 @@
|
|||||||
#include "keydb.h"
|
#include "keydb.h"
|
||||||
#include "ctrtransfer.h"
|
#include "ctrtransfer.h"
|
||||||
#include "scripting.h"
|
#include "scripting.h"
|
||||||
|
#include "gm9lua.h"
|
||||||
#include "png.h"
|
#include "png.h"
|
||||||
#include "ui.h" // only for font file detection
|
#include "ui.h" // only for font file detection
|
||||||
|
|
||||||
u64 IdentifyFileType(const char* path) {
|
u64 IdentifyFileType(const char* path) {
|
||||||
const u8 romfs_magic[] = { ROMFS_MAGIC };
|
static const u8 romfs_magic[] = { ROMFS_MAGIC };
|
||||||
const u8 diff_magic[] = { DIFF_MAGIC };
|
static const u8 diff_magic[] = { DIFF_MAGIC };
|
||||||
// const u8 disa_magic[] = { DISA_MAGIC };
|
static const u8 disa_magic[] = { DISA_MAGIC };
|
||||||
const u8 tickdb_magic[] = { TICKDB_MAGIC };
|
static const u8 tickdb_magic[] = { TICKDB_MAGIC };
|
||||||
const u8 smdh_magic[] = { SMDH_MAGIC };
|
static const u8 smdh_magic[] = { SMDH_MAGIC };
|
||||||
const u8 threedsx_magic[] = { THREEDSX_EXT_MAGIC };
|
static const u8 threedsx_magic[] = { THREEDSX_EXT_MAGIC };
|
||||||
const u8 png_magic[] = { PNG_MAGIC };
|
static const u8 png_magic[] = { PNG_MAGIC };
|
||||||
|
|
||||||
if (!path) return 0; // safety
|
if (!path) return 0; // safety
|
||||||
u8 header[0x200] __attribute__((aligned(32))); // minimum required size
|
u8 ALIGN(32) header[0x2C0]; // minimum required size
|
||||||
void* data = (void*) header;
|
void* data = (void*) header;
|
||||||
size_t fsize = FileGetSize(path);
|
size_t fsize = FileGetSize(path);
|
||||||
char* fname = strrchr(path, '/');
|
char* fname = strrchr(path, '/');
|
||||||
char* ext = (fname) ? strrchr(++fname, '.') : NULL;
|
char* ext = (fname) ? strrchr(++fname, '.') : NULL;
|
||||||
u32 id = 0;
|
u32 id = 0;
|
||||||
|
|
||||||
|
|
||||||
// block crappy "._" files from getting recognized as filetype
|
// block crappy "._" files from getting recognized as filetype
|
||||||
if (!fname) return 0;
|
if (!fname) return 0;
|
||||||
if (strncmp(fname, "._", 2) == 0) return 0;
|
if (strncmp(fname, "._", 2) == 0) return 0;
|
||||||
|
|
||||||
if (ext) ext++;
|
if (ext) {
|
||||||
if (FileGetData(path, header, 0x200, 0) < min(0x200, fsize)) return 0;
|
ext++;
|
||||||
|
} else {
|
||||||
|
ext = "";
|
||||||
|
}
|
||||||
|
if (FileGetData(path, header, 0x2C0, 0) < min(0x2C0, fsize)) return 0;
|
||||||
if (!fsize) return 0;
|
if (!fsize) return 0;
|
||||||
|
|
||||||
if (fsize >= 0x200) {
|
if (fsize >= 0x200) {
|
||||||
if (ValidateNandNcsdHeader((NandNcsdHeader*) data) == 0) {
|
if (ValidateNandNcsdHeader((NandNcsdHeader*) data) == 0) {
|
||||||
return (fsize >= GetNandNcsdMinSizeSectors((NandNcsdHeader*) data) * 0x200) ?
|
return (fsize >= GetNandNcsdMinSizeSectors((NandNcsdHeader*) data) * 0x200) ?
|
||||||
@ -53,7 +58,7 @@ u64 IdentifyFileType(const char* path) {
|
|||||||
} else if (ValidateCiaHeader((CiaHeader*) data) == 0) {
|
} else if (ValidateCiaHeader((CiaHeader*) data) == 0) {
|
||||||
// this only works because these functions ignore CIA content index
|
// this only works because these functions ignore CIA content index
|
||||||
CiaInfo info;
|
CiaInfo info;
|
||||||
GetCiaInfo(&info, (CiaHeader*) header);
|
GetCiaInfo(&info, data);
|
||||||
if (fsize >= info.size_cia)
|
if (fsize >= info.size_cia)
|
||||||
return GAME_CIA; // CIA file
|
return GAME_CIA; // CIA file
|
||||||
} else if (ValidateNcsdHeader((NcsdHeader*) data) == 0) {
|
} else if (ValidateNcsdHeader((NcsdHeader*) data) == 0) {
|
||||||
@ -82,11 +87,14 @@ u64 IdentifyFileType(const char* path) {
|
|||||||
return GAME_ROMFS; // RomFS file (check could be better)
|
return GAME_ROMFS; // RomFS file (check could be better)
|
||||||
} else if (ValidateTmd((TitleMetaData*) data) == 0) {
|
} else if (ValidateTmd((TitleMetaData*) data) == 0) {
|
||||||
if (fsize == TMD_SIZE_N(getbe16(header + 0x1DE)) + TMD_CDNCERT_SIZE)
|
if (fsize == TMD_SIZE_N(getbe16(header + 0x1DE)) + TMD_CDNCERT_SIZE)
|
||||||
return GAME_TMD | FLAG_NUSCDN; // TMD file from NUS/CDN
|
return GAME_CDNTMD; // TMD file from NUS/CDN
|
||||||
else if (fsize >= TMD_SIZE_N(getbe16(header + 0x1DE)))
|
else if (fsize >= TMD_SIZE_N(getbe16(header + 0x1DE)))
|
||||||
return GAME_TMD; // TMD file
|
return GAME_TMD; // TMD file
|
||||||
|
} else if (ValidateTwlTmd((TitleMetaData*) data) == 0) {
|
||||||
|
if (fsize == TMD_SIZE_TWL + TMD_CDNCERT_SIZE)
|
||||||
|
return GAME_TWLTMD; // TMD file from NUS/CDN (TWL)
|
||||||
} else if (ValidateTicket((Ticket*) data) == 0) {
|
} else if (ValidateTicket((Ticket*) data) == 0) {
|
||||||
return GAME_TICKET; // Ticket file (not used for anything right now)
|
return GAME_TICKET; // Ticket file
|
||||||
} else if (ValidateFirmHeader((FirmHeader*) data, fsize) == 0) {
|
} else if (ValidateFirmHeader((FirmHeader*) data, fsize) == 0) {
|
||||||
return SYS_FIRM; // FIRM file
|
return SYS_FIRM; // FIRM file
|
||||||
} else if ((ValidateAgbSaveHeader((AgbSaveHeader*) data) == 0) && (fsize >= AGBSAVE_MAX_SIZE)) {
|
} else if ((ValidateAgbSaveHeader((AgbSaveHeader*) data) == 0) && (fsize >= AGBSAVE_MAX_SIZE)) {
|
||||||
@ -95,16 +103,35 @@ u64 IdentifyFileType(const char* path) {
|
|||||||
if (memcmp(header + 0x100, tickdb_magic, sizeof(tickdb_magic)) == 0) // ticket.db file
|
if (memcmp(header + 0x100, tickdb_magic, sizeof(tickdb_magic)) == 0) // ticket.db file
|
||||||
return SYS_DIFF | SYS_TICKDB; // ticket.db
|
return SYS_DIFF | SYS_TICKDB; // ticket.db
|
||||||
return SYS_DIFF;
|
return SYS_DIFF;
|
||||||
|
} else if (memcmp(header + 0x100, disa_magic, sizeof(disa_magic)) == 0) { // DISA file
|
||||||
|
return SYS_DISA;
|
||||||
} else if (memcmp(header, smdh_magic, sizeof(smdh_magic)) == 0) {
|
} else if (memcmp(header, smdh_magic, sizeof(smdh_magic)) == 0) {
|
||||||
return GAME_SMDH; // SMDH file
|
return GAME_SMDH; // SMDH file
|
||||||
} else if (ValidateTwlHeader((TwlHeader*) data) == 0) {
|
} else if (ValidateTwlHeader((TwlHeader*) data) == 0) {
|
||||||
if (((TwlHeader*)data)->ntr_rom_size <= fsize)
|
TwlHeader* twl = (TwlHeader*) data;
|
||||||
|
if (twl->ntr_rom_size <= fsize) { // NDS rom file
|
||||||
|
if ((twl->unit_code == 0x03) && !twl->twl_rom_region_start)
|
||||||
|
return GAME_NDS | FLAG_DSIW; // NDS DSiWare rom file
|
||||||
return GAME_NDS; // NDS rom file
|
return GAME_NDS; // NDS rom file
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (GetFontFromPbm(data, fsize, NULL, NULL)) {
|
if (fsize == sizeof(TitleInfoEntry) && (strncasecmp(path, "T:/", 3) == 0)) {
|
||||||
|
const char* mntpath = GetMountPath();
|
||||||
|
if (mntpath && *mntpath) {
|
||||||
|
if ((strncasecmp(mntpath, "1:/dbs/title.db", 16) == 0) ||
|
||||||
|
(strncasecmp(mntpath, "4:/dbs/title.db", 16) == 0) ||
|
||||||
|
(strncasecmp(mntpath, "A:/dbs/title.db", 16) == 0) ||
|
||||||
|
(strncasecmp(mntpath, "B:/dbs/title.db", 16) == 0))
|
||||||
|
return GAME_TIE;
|
||||||
|
}
|
||||||
|
} else if (GetFontFromPbm(data, fsize, NULL, NULL)) {
|
||||||
return FONT_PBM;
|
return FONT_PBM;
|
||||||
|
} else if (GetFontFromRiff(data, fsize, NULL, NULL, NULL)) {
|
||||||
|
return FONT_RIFF;
|
||||||
|
} else if (GetLanguage(data, fsize, NULL, NULL, NULL)) {
|
||||||
|
return TRANSLATION;
|
||||||
} else if ((fsize > sizeof(AgbHeader)) &&
|
} else if ((fsize > sizeof(AgbHeader)) &&
|
||||||
(ValidateAgbHeader((AgbHeader*) data) == 0)) {
|
(ValidateAgbHeader((AgbHeader*) data) == 0)) {
|
||||||
return GAME_GBA;
|
return GAME_GBA;
|
||||||
@ -114,6 +141,9 @@ u64 IdentifyFileType(const char* path) {
|
|||||||
} else if ((fsize > sizeof(ThreedsxHeader)) &&
|
} else if ((fsize > sizeof(ThreedsxHeader)) &&
|
||||||
(memcmp(data, threedsx_magic, sizeof(threedsx_magic)) == 0)) {
|
(memcmp(data, threedsx_magic, sizeof(threedsx_magic)) == 0)) {
|
||||||
return GAME_3DSX; // 3DSX (executable) file
|
return GAME_3DSX; // 3DSX (executable) file
|
||||||
|
} else if ((fsize > sizeof(CmdHeader)) &&
|
||||||
|
(CMD_SIZE((CmdHeader*) data) == fsize)) {
|
||||||
|
return GAME_CMD; // CMD file
|
||||||
} else if ((fsize > sizeof(NcchInfoHeader)) &&
|
} else if ((fsize > sizeof(NcchInfoHeader)) &&
|
||||||
(GetNcchInfoVersion((NcchInfoHeader*) data)) &&
|
(GetNcchInfoVersion((NcchInfoHeader*) data)) &&
|
||||||
(strncasecmp(fname, NCCHINFO_NAME, 32) == 0)) {
|
(strncasecmp(fname, NCCHINFO_NAME, 32) == 0)) {
|
||||||
@ -121,14 +151,6 @@ u64 IdentifyFileType(const char* path) {
|
|||||||
} else if ((strncasecmp(ext, "png", 4) == 0) &&
|
} else if ((strncasecmp(ext, "png", 4) == 0) &&
|
||||||
(fsize > sizeof(png_magic)) && (memcmp(data, png_magic, sizeof(png_magic)) == 0)) {
|
(fsize > sizeof(png_magic)) && (memcmp(data, png_magic, sizeof(png_magic)) == 0)) {
|
||||||
return GFX_PNG;
|
return GFX_PNG;
|
||||||
} else if (ext && ((strncasecmp(ext, "cdn", 4) == 0) || (strncasecmp(ext, "nus", 4) == 0))) {
|
|
||||||
char path_cetk[256];
|
|
||||||
char* ext_cetk = path_cetk + (ext - path);
|
|
||||||
strncpy(path_cetk, path, 256);
|
|
||||||
path_cetk[255] = '\0';
|
|
||||||
strncpy(ext_cetk, "cetk", 5);
|
|
||||||
if (FileGetSize(path_cetk) > 0)
|
|
||||||
return GAME_NUSCDN; // NUS/CDN type 2
|
|
||||||
} else if (strncasecmp(fname, TIKDB_NAME_ENC, sizeof(TIKDB_NAME_ENC)+1) == 0) {
|
} else if (strncasecmp(fname, TIKDB_NAME_ENC, sizeof(TIKDB_NAME_ENC)+1) == 0) {
|
||||||
return BIN_TIKDB | FLAG_ENC; // titlekey database / encrypted
|
return BIN_TIKDB | FLAG_ENC; // titlekey database / encrypted
|
||||||
} else if (strncasecmp(fname, TIKDB_NAME_DEC, sizeof(TIKDB_NAME_DEC)+1) == 0) {
|
} else if (strncasecmp(fname, TIKDB_NAME_DEC, sizeof(TIKDB_NAME_DEC)+1) == 0) {
|
||||||
@ -137,10 +159,16 @@ u64 IdentifyFileType(const char* path) {
|
|||||||
return BIN_KEYDB; // key database
|
return BIN_KEYDB; // key database
|
||||||
} else if ((sscanf(fname, "slot%02lXKey", &id) == 1) && (strncasecmp(ext, "bin", 4) == 0) && (fsize = 16) && (id < 0x40)) {
|
} else if ((sscanf(fname, "slot%02lXKey", &id) == 1) && (strncasecmp(ext, "bin", 4) == 0) && (fsize = 16) && (id < 0x40)) {
|
||||||
return BIN_LEGKEY; // legacy key file
|
return BIN_LEGKEY; // legacy key file
|
||||||
|
} else if ((strncmp((char*) data, CIFINISH_MAGIC, strlen(CIFINISH_MAGIC)) == 0) &&
|
||||||
|
(fsize == CIFINISH_SIZE((void*) data)) && (fsize > sizeof(CifinishHeader))) {
|
||||||
|
return BIN_CIFNSH;
|
||||||
} else if (ValidateText((char*) data, (fsize > 0x200) ? 0x200 : fsize)) {
|
} else if (ValidateText((char*) data, (fsize > 0x200) ? 0x200 : fsize)) {
|
||||||
u64 type = 0;
|
u64 type = 0;
|
||||||
if ((fsize <= SCRIPT_MAX_SIZE) && ext && (strncasecmp(ext, SCRIPT_EXT, strnlen(SCRIPT_EXT, 16) + 1) == 0))
|
if ((fsize < SCRIPT_MAX_SIZE) && (strcasecmp(ext, SCRIPT_EXT) == 0))
|
||||||
type |= TXT_SCRIPT; // should be a script (which is also generic text)
|
type |= TXT_SCRIPT; // should be a script (which is also generic text)
|
||||||
|
// this should check if it's compiled lua bytecode (done with luac), which is NOT text
|
||||||
|
else if ((fsize < LUASCRIPT_MAX_SIZE) && (strcasecmp(ext, LUASCRIPT_EXT) == 0))
|
||||||
|
type |= TXT_LUA;
|
||||||
if (fsize < STD_BUFFER_SIZE) type |= TXT_GENERIC;
|
if (fsize < STD_BUFFER_SIZE) type |= TXT_GENERIC;
|
||||||
return type;
|
return type;
|
||||||
} else if ((strncmp(path + 2, "/Nintendo DSiWare/", 18) == 0) &&
|
} else if ((strncmp(path + 2, "/Nintendo DSiWare/", 18) == 0) &&
|
||||||
@ -154,13 +182,13 @@ u64 IdentifyFileType(const char* path) {
|
|||||||
char* name_cdn = path_cdn + (fname - path);
|
char* name_cdn = path_cdn + (fname - path);
|
||||||
strncpy(path_cdn, path, 256);
|
strncpy(path_cdn, path, 256);
|
||||||
path_cdn[255] = '\0';
|
path_cdn[255] = '\0';
|
||||||
strncpy(name_cdn, "tmd", 4);
|
strncpy(name_cdn, "tmd", 4); // this will not catch tmd with version
|
||||||
if (FileGetSize(path_cdn) > 0)
|
if (FileGetSize(path_cdn) > 0)
|
||||||
return GAME_NUSCDN; // NUS/CDN type 1
|
return GAME_NUSCDN; // NUS/CDN, recognized by TMD
|
||||||
strncpy(name_cdn, "cetk", 5);
|
strncpy(name_cdn, "cetk", 5);
|
||||||
if (FileGetSize(path_cdn) > 0)
|
if (FileGetSize(path_cdn) > 0)
|
||||||
return GAME_NUSCDN; // NUS/CDN type 1
|
return GAME_NUSCDN; // NUS/CDN, recognized by CETK
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
@ -8,52 +8,65 @@
|
|||||||
#define GAME_NCSD (1ULL<<3)
|
#define GAME_NCSD (1ULL<<3)
|
||||||
#define GAME_NCCH (1ULL<<4)
|
#define GAME_NCCH (1ULL<<4)
|
||||||
#define GAME_TMD (1ULL<<5)
|
#define GAME_TMD (1ULL<<5)
|
||||||
#define GAME_EXEFS (1ULL<<6)
|
#define GAME_CDNTMD (1ULL<<6)
|
||||||
#define GAME_ROMFS (1ULL<<7)
|
#define GAME_TWLTMD (1ULL<<7)
|
||||||
#define GAME_BOSS (1ULL<<8)
|
#define GAME_CMD (1ULL<<8)
|
||||||
#define GAME_NUSCDN (1ULL<<9)
|
#define GAME_EXEFS (1ULL<<9)
|
||||||
#define GAME_TICKET (1ULL<<10)
|
#define GAME_ROMFS (1ULL<<10)
|
||||||
#define GAME_SMDH (1ULL<<11)
|
#define GAME_BOSS (1ULL<<11)
|
||||||
#define GAME_3DSX (1ULL<<12)
|
#define GAME_NUSCDN (1ULL<<12)
|
||||||
#define GAME_NDS (1ULL<<13)
|
#define GAME_TICKET (1ULL<<13)
|
||||||
#define GAME_GBA (1ULL<<14)
|
#define GAME_TIE (1ULL<<14)
|
||||||
#define GAME_TAD (1ULL<<15)
|
#define GAME_SMDH (1ULL<<15)
|
||||||
#define SYS_FIRM (1ULL<<16)
|
#define GAME_3DSX (1ULL<<16)
|
||||||
#define SYS_DIFF (1ULL<<17)
|
#define GAME_NDS (1ULL<<17)
|
||||||
#define SYS_DISA (1ULL<<18) // not yet used
|
#define GAME_GBA (1ULL<<18)
|
||||||
#define SYS_AGBSAVE (1ULL<<19)
|
#define GAME_TAD (1ULL<<19)
|
||||||
#define SYS_TICKDB (1ULL<<20)
|
#define SYS_FIRM (1ULL<<20)
|
||||||
#define BIN_NCCHNFO (1ULL<<21)
|
#define SYS_DIFF (1ULL<<21)
|
||||||
#define BIN_TIKDB (1ULL<<22)
|
#define SYS_DISA (1ULL<<22)
|
||||||
#define BIN_KEYDB (1ULL<<23)
|
#define SYS_AGBSAVE (1ULL<<23)
|
||||||
#define BIN_LEGKEY (1ULL<<24)
|
#define SYS_TICKDB (1ULL<<24)
|
||||||
#define TXT_SCRIPT (1ULL<<25)
|
#define BIN_CIFNSH (1ULL<<25)
|
||||||
#define TXT_GENERIC (1ULL<<26)
|
#define BIN_NCCHNFO (1ULL<<26)
|
||||||
#define GFX_PNG (1ULL<<27)
|
#define BIN_TIKDB (1ULL<<27)
|
||||||
#define FONT_PBM (1ULL<<28)
|
#define BIN_KEYDB (1ULL<<28)
|
||||||
#define NOIMG_NAND (1ULL<<29)
|
#define BIN_LEGKEY (1ULL<<29)
|
||||||
#define HDR_NAND (1ULL<<30)
|
#define TXT_SCRIPT (1ULL<<30)
|
||||||
#define TYPE_BASE 0xFFFFFFFFULL // 32 bit reserved for base types
|
#define TXT_GENERIC (1ULL<<31)
|
||||||
|
#define GFX_PNG (1ULL<<32)
|
||||||
|
#define FONT_PBM (1ULL<<33)
|
||||||
|
#define FONT_RIFF (1ULL<<34)
|
||||||
|
#define NOIMG_NAND (1ULL<<35)
|
||||||
|
#define HDR_NAND (1ULL<<36)
|
||||||
|
#define TRANSLATION (1ULL<<37)
|
||||||
|
#define TXT_LUA (1ULL<<38)
|
||||||
|
#define TYPE_BASE 0xFFFFFFFFFFULL // 40 bit reserved for base types
|
||||||
|
|
||||||
// #define FLAG_FIRM (1ULL<<58) // <--- for CXIs containing FIRMs
|
// #define FLAG_FIRM (1ULL<<58) // <--- for CXIs containing FIRMs
|
||||||
// #define FLAG_GBAVC (1ULL<<59) // <--- for GBAVC CXIs
|
// #define FLAG_GBAVC (1ULL<<59) // <--- for GBAVC CXIs
|
||||||
#define FLAG_ENC (1ULL<<60)
|
#define FLAG_DSIW (1ULL<<60)
|
||||||
#define FLAG_CTR (1ULL<<61)
|
#define FLAG_ENC (1ULL<<61)
|
||||||
#define FLAG_NUSCDN (1ULL<<62)
|
#define FLAG_CTR (1ULL<<62)
|
||||||
#define FLAG_CXI (1ULL<<63)
|
#define FLAG_CXI (1ULL<<63)
|
||||||
|
|
||||||
#define FTYPE_MOUNTABLE(tp) (tp&(IMG_FAT|IMG_NAND|GAME_CIA|GAME_NCSD|GAME_NCCH|GAME_EXEFS|GAME_ROMFS|GAME_NDS|GAME_TAD|SYS_FIRM|SYS_TICKDB|BIN_KEYDB))
|
#define FTYPE_MOUNTABLE(tp) (tp&(IMG_FAT|IMG_NAND|GAME_CIA|GAME_NCSD|GAME_NCCH|GAME_EXEFS|GAME_ROMFS|GAME_NDS|GAME_TAD|SYS_FIRM|SYS_DIFF|SYS_DISA|SYS_TICKDB|BIN_KEYDB))
|
||||||
#define FTYPE_VERIFICABLE(tp) (tp&(IMG_NAND|GAME_CIA|GAME_NCSD|GAME_NCCH|GAME_TMD|GAME_BOSS|SYS_FIRM))
|
#define FTYPE_VERIFICABLE(tp) (tp&(IMG_NAND|GAME_CIA|GAME_NCSD|GAME_NCCH|GAME_TMD|GAME_CDNTMD|GAME_TWLTMD|GAME_TIE|GAME_TAD|GAME_TICKET|GAME_BOSS|SYS_FIRM))
|
||||||
#define FTYPE_DECRYPTABLE(tp) (tp&(GAME_CIA|GAME_NCSD|GAME_NCCH|GAME_BOSS|GAME_NUSCDN|SYS_FIRM|BIN_KEYDB))
|
#define FTYPE_DECRYPTABLE(tp) (tp&(GAME_CIA|GAME_NCSD|GAME_NCCH|GAME_BOSS|GAME_NUSCDN|SYS_FIRM|BIN_KEYDB))
|
||||||
#define FTYPE_ENCRYPTABLE(tp) (tp&(GAME_CIA|GAME_NCSD|GAME_NCCH|GAME_BOSS|BIN_KEYDB))
|
#define FTYPE_ENCRYPTABLE(tp) (tp&(GAME_CIA|GAME_NCSD|GAME_NCCH|GAME_BOSS|BIN_KEYDB))
|
||||||
#define FTYPE_CIABUILD(tp) (tp&(GAME_NCSD|GAME_NCCH|GAME_TMD))
|
#define FTYPE_CIABUILD(tp) ((tp&(GAME_NCSD|GAME_NCCH|GAME_TMD|GAME_CDNTMD|GAME_TWLTMD|GAME_TIE|GAME_TAD)) || ((tp&GAME_NDS)&&(tp&(FLAG_DSIW))))
|
||||||
#define FTYPE_CIABUILD_L(tp) (FTYPE_CIABUILD(tp) && (tp&(GAME_TMD)))
|
#define FTYPE_CIABUILD_L(tp) (tp&(GAME_TMD|GAME_CDNTMD|GAME_TIE|GAME_TAD))
|
||||||
#define FTYPE_CXIDUMP(tp) (tp&(GAME_TMD))
|
#define FTYPE_CIAINSTALL(tp) ((tp&(GAME_NCSD|GAME_NCCH|GAME_CIA|GAME_CDNTMD|GAME_TWLTMD)) || ((tp&GAME_NDS)&&(tp&(FLAG_DSIW))))
|
||||||
|
#define FTYPE_TIKINSTALL(tp) (tp&(GAME_TICKET))
|
||||||
|
#define FTYPE_CIFINSTALL(tp) (tp&(BIN_CIFNSH))
|
||||||
|
#define FTYPE_TIKDUMP(tp) (tp&(GAME_TIE))
|
||||||
|
#define FTYPE_CXIDUMP(tp) (tp&(GAME_TMD|GAME_TIE))
|
||||||
|
#define FTYPE_UNINSTALL(tp) (tp&(GAME_TIE))
|
||||||
#define FTYPE_TIKBUILD(tp) (tp&(GAME_TICKET|SYS_TICKDB|BIN_TIKDB))
|
#define FTYPE_TIKBUILD(tp) (tp&(GAME_TICKET|SYS_TICKDB|BIN_TIKDB))
|
||||||
#define FTYPE_KEYBUILD(tp) (tp&(BIN_KEYDB|BIN_LEGKEY))
|
#define FTYPE_KEYBUILD(tp) (tp&(BIN_KEYDB|BIN_LEGKEY))
|
||||||
#define FTYPE_TITLEINFO(tp) (tp&(GAME_SMDH|GAME_NCCH|GAME_NCSD|GAME_CIA|GAME_TMD|GAME_NDS|GAME_GBA|GAME_TAD|GAME_3DSX))
|
#define FTYPE_TITLEINFO(tp) (tp&(GAME_TIE|GAME_CIA|GAME_TMD|GAME_CDNTMD|GAME_TWLTMD))
|
||||||
#define FTYPE_RENAMABLE(tp) (tp&(GAME_NCCH|GAME_NCSD|GAME_CIA|GAME_NDS|GAME_GBA))
|
#define FTYPE_RENAMABLE(tp) (tp&(GAME_NCCH|GAME_NCSD|GAME_CIA|GAME_NDS|GAME_GBA))
|
||||||
#define FTYPE_TRIMABLE(tp) (tp&(IMG_NAND|GAME_NCCH|GAME_NCSD|GAME_NDS|SYS_FIRM))
|
#define FTYPE_TRIMABLE(tp) (tp&(IMG_NAND|GAME_NCCH|GAME_NCSD|GAME_NDS|GAME_GBA|SYS_FIRM))
|
||||||
#define FTYPE_TRANSFERABLE(tp) ((u64) (tp&(IMG_FAT|FLAG_CTR)) == (u64) (IMG_FAT|FLAG_CTR))
|
#define FTYPE_TRANSFERABLE(tp) ((u64) (tp&(IMG_FAT|FLAG_CTR)) == (u64) (IMG_FAT|FLAG_CTR))
|
||||||
#define FTYPE_NCSDFIXABLE(tp) (tp&(HDR_NAND|NOIMG_NAND))
|
#define FTYPE_NCSDFIXABLE(tp) (tp&(HDR_NAND|NOIMG_NAND))
|
||||||
#define FTYPE_HASCODE(tp) (((u64) (tp&(GAME_NCCH|FLAG_CXI)) == (u64) (GAME_NCCH|FLAG_CXI))|(tp&GAME_NCSD))
|
#define FTYPE_HASCODE(tp) (((u64) (tp&(GAME_NCCH|FLAG_CXI)) == (u64) (GAME_NCCH|FLAG_CXI))|(tp&GAME_NCSD))
|
||||||
@ -65,9 +78,11 @@
|
|||||||
#define FTYPE_KEYINIT(tp) (tp&(BIN_KEYDB))
|
#define FTYPE_KEYINIT(tp) (tp&(BIN_KEYDB))
|
||||||
#define FTYPE_KEYINSTALL(tp) (tp&(BIN_KEYDB))
|
#define FTYPE_KEYINSTALL(tp) (tp&(BIN_KEYDB))
|
||||||
#define FTYPE_SCRIPT(tp) (tp&(TXT_SCRIPT))
|
#define FTYPE_SCRIPT(tp) (tp&(TXT_SCRIPT))
|
||||||
#define FTYPE_FONT(tp) (tp&(FONT_PBM))
|
#define FTYPE_LUA(tp) (tp&(TXT_LUA))
|
||||||
|
#define FTYPE_FONT(tp) (tp&(FONT_PBM|FONT_RIFF))
|
||||||
|
#define FTYPE_TRANSLATION(tp) (tp&(TRANSLATION))
|
||||||
#define FTYPE_GFX(tp) (tp&(GFX_PNG))
|
#define FTYPE_GFX(tp) (tp&(GFX_PNG))
|
||||||
#define FTYPE_SETABLE(tp) (tp&(FONT_PBM))
|
#define FTYPE_SETABLE(tp) (tp&(FONT_PBM|FONT_RIFF|TRANSLATION))
|
||||||
#define FTYPE_BOOTABLE(tp) (tp&(SYS_FIRM))
|
#define FTYPE_BOOTABLE(tp) (tp&(SYS_FIRM))
|
||||||
#define FTYPE_INSTALLABLE(tp) (tp&(SYS_FIRM))
|
#define FTYPE_INSTALLABLE(tp) (tp&(SYS_FIRM))
|
||||||
#define FTYPE_AGBSAVE(tp) (tp&(SYS_AGBSAVE))
|
#define FTYPE_AGBSAVE(tp) (tp&(SYS_AGBSAVE))
|
||||||
|
@ -2,29 +2,24 @@
|
|||||||
|
|
||||||
void DirEntryCpy(DirEntry* dest, const DirEntry* orig) {
|
void DirEntryCpy(DirEntry* dest, const DirEntry* orig) {
|
||||||
memcpy(dest, orig, sizeof(DirEntry));
|
memcpy(dest, orig, sizeof(DirEntry));
|
||||||
dest->name = dest->path + (orig->name - orig->path);
|
dest->name = dest->path + dest->p_name;
|
||||||
|
}
|
||||||
|
|
||||||
|
int compDirEntry(const void* e1, const void* e2) {
|
||||||
|
const DirEntry* entry1 = (const DirEntry*) e1;
|
||||||
|
const DirEntry* entry2 = (const DirEntry*) e2;
|
||||||
|
if (entry1->type == T_DOTDOT) return -1;
|
||||||
|
if (entry2->type == T_DOTDOT) return 1;
|
||||||
|
if (entry1->type != entry2->type)
|
||||||
|
return entry1->type - entry2->type;
|
||||||
|
return strncasecmp(entry1->path, entry2->path, 256);
|
||||||
}
|
}
|
||||||
|
|
||||||
void SortDirStruct(DirStruct* contents) {
|
void SortDirStruct(DirStruct* contents) {
|
||||||
for (u32 s = 0; s < contents->n_entries; s++) {
|
qsort(contents->entry, contents->n_entries, sizeof(DirEntry), compDirEntry);
|
||||||
DirEntry* cmp0 = &(contents->entry[s]);
|
// fix entry->names after qsort
|
||||||
DirEntry* min0 = cmp0;
|
for (int i = 0; i < (int)contents->n_entries; i++) {
|
||||||
if (cmp0->type == T_DOTDOT) continue;
|
DirEntry* entry = &(contents->entry[i]);
|
||||||
for (u32 c = s + 1; c < contents->n_entries; c++) {
|
entry->name = entry->path + entry->p_name;
|
||||||
DirEntry* cmp1 = &(contents->entry[c]);
|
|
||||||
if (min0->type != cmp1->type) {
|
|
||||||
if (min0->type > cmp1->type)
|
|
||||||
min0 = cmp1;
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
if (strncasecmp(min0->name, cmp1->name, 256) > 0)
|
|
||||||
min0 = cmp1;
|
|
||||||
}
|
|
||||||
if (min0 != cmp0) {
|
|
||||||
DirEntry swap; // swap entries and fix names
|
|
||||||
DirEntryCpy(&swap, cmp0);
|
|
||||||
DirEntryCpy(cmp0, min0);
|
|
||||||
DirEntryCpy(min0, &swap);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -17,6 +17,7 @@ typedef struct {
|
|||||||
u64 size;
|
u64 size;
|
||||||
EntryType type;
|
EntryType type;
|
||||||
u8 marked;
|
u8 marked;
|
||||||
|
u8 p_name;
|
||||||
} DirEntry;
|
} DirEntry;
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
|
@ -1,7 +1,9 @@
|
|||||||
#include "fsdrive.h"
|
#include "fsdrive.h"
|
||||||
#include "fsgame.h"
|
#include "fsgame.h"
|
||||||
#include "fsinit.h"
|
#include "fsinit.h"
|
||||||
|
#include "language.h"
|
||||||
#include "virtual.h"
|
#include "virtual.h"
|
||||||
|
#include "vcart.h"
|
||||||
#include "sddata.h"
|
#include "sddata.h"
|
||||||
#include "image.h"
|
#include "image.h"
|
||||||
#include "ui.h"
|
#include "ui.h"
|
||||||
@ -10,16 +12,18 @@
|
|||||||
// last search pattern, path & mode
|
// last search pattern, path & mode
|
||||||
static char search_pattern[256] = { 0 };
|
static char search_pattern[256] = { 0 };
|
||||||
static char search_path[256] = { 0 };
|
static char search_path[256] = { 0 };
|
||||||
static bool search_title_mode = false;
|
static bool title_manager_mode = false;
|
||||||
|
|
||||||
int DriveType(const char* path) {
|
int DriveType(const char* path) {
|
||||||
int type = DRV_UNKNOWN;
|
int type = DRV_UNKNOWN;
|
||||||
int pdrv = GetMountedFSNum(path);
|
int pdrv = GetMountedFSNum(path);
|
||||||
|
|
||||||
if (CheckAliasDrive(path)) {
|
if (CheckAliasDrive(path)) {
|
||||||
type = DRV_FAT | DRV_ALIAS | ((*path == 'A') ? DRV_SYSNAND : DRV_EMUNAND);
|
type = DRV_FAT | DRV_ALIAS | ((*path == 'A') ? DRV_SYSNAND : DRV_EMUNAND);
|
||||||
} else if (*search_pattern && *search_path && (strncmp(path, "Z:", 3) == 0)) {
|
} else if (*search_pattern && *search_path && (strncmp(path, "Z:", 3) == 0)) {
|
||||||
type = DRV_SEARCH;
|
type = DRV_SEARCH;
|
||||||
|
} else if (title_manager_mode && (strncmp(path, "Y:", 3) == 0)) {
|
||||||
|
type = DRV_VIRTUAL | DRV_TITLEMAN;
|
||||||
} else if ((pdrv >= 0) && (pdrv < NORM_FS)) {
|
} else if ((pdrv >= 0) && (pdrv < NORM_FS)) {
|
||||||
if (pdrv == 0) {
|
if (pdrv == 0) {
|
||||||
type = DRV_FAT | DRV_SDCARD | DRV_STDFAT;
|
type = DRV_FAT | DRV_SDCARD | DRV_STDFAT;
|
||||||
@ -38,67 +42,75 @@ int DriveType(const char* path) {
|
|||||||
} else if ((pdrv >= 7) && (pdrv <= 9) &&
|
} else if ((pdrv >= 7) && (pdrv <= 9) &&
|
||||||
(GetMountState() & (IMG_FAT|IMG_NAND))) {
|
(GetMountState() & (IMG_FAT|IMG_NAND))) {
|
||||||
type = DRV_FAT | DRV_IMAGE | DRV_STDFAT;
|
type = DRV_FAT | DRV_IMAGE | DRV_STDFAT;
|
||||||
}
|
}
|
||||||
} else if (CheckVirtualDrive(path)) {
|
} else if (CheckVirtualDrive(path)) {
|
||||||
int vsrc = GetVirtualSource(path);
|
int vsrc = GetVirtualSource(path);
|
||||||
if (vsrc == VRT_SYSNAND) {
|
if (vsrc == VRT_SYSNAND) {
|
||||||
type = DRV_VIRTUAL | DRV_SYSNAND;
|
type = DRV_VIRTUAL | DRV_SYSNAND;
|
||||||
} else if (vsrc == VRT_EMUNAND) {
|
} else if (vsrc == VRT_EMUNAND) {
|
||||||
type = DRV_VIRTUAL | DRV_EMUNAND;
|
type = DRV_VIRTUAL | DRV_EMUNAND;
|
||||||
} else if (vsrc == VRT_IMGNAND) {
|
} else if ((vsrc == VRT_IMGNAND) || (vsrc == VRT_DISADIFF) || (vsrc == VRT_BDRI)) {
|
||||||
type = DRV_VIRTUAL | DRV_IMAGE;
|
type = DRV_VIRTUAL | DRV_IMAGE;
|
||||||
} else if (vsrc == VRT_XORPAD) {
|
} else if (vsrc == VRT_XORPAD) {
|
||||||
type = DRV_VIRTUAL | DRV_XORPAD;
|
type = DRV_VIRTUAL | DRV_XORPAD;
|
||||||
} else if (vsrc == VRT_MEMORY) {
|
} else if (vsrc == VRT_MEMORY) {
|
||||||
type = DRV_VIRTUAL | DRV_MEMORY;
|
type = DRV_VIRTUAL | DRV_MEMORY;
|
||||||
} else if ((vsrc == VRT_GAME) || (vsrc == VRT_KEYDB) || (vsrc == VRT_TICKDB)) {
|
} else if ((vsrc == VRT_GAME) || (vsrc == VRT_KEYDB)) {
|
||||||
type = DRV_VIRTUAL | DRV_GAME | DRV_IMAGE;
|
type = DRV_VIRTUAL | DRV_GAME | DRV_IMAGE;
|
||||||
} else if (vsrc == VRT_CART) {
|
} else if (vsrc == VRT_CART) {
|
||||||
type = DRV_VIRTUAL | DRV_CART;
|
type = DRV_VIRTUAL | DRV_CART;
|
||||||
} else if (vsrc == VRT_VRAM) {
|
} else if (vsrc == VRT_VRAM) {
|
||||||
type = DRV_VIRTUAL | DRV_VRAM;
|
type = DRV_VIRTUAL | DRV_VRAM;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return type;
|
return type;
|
||||||
}
|
}
|
||||||
|
|
||||||
void SetFSSearch(const char* pattern, const char* path, bool mode) {
|
void SetFSSearch(const char* pattern, const char* path) {
|
||||||
if (pattern && path) {
|
if (pattern && path) {
|
||||||
strncpy(search_pattern, pattern, 256);
|
strncpy(search_pattern, pattern, 256);
|
||||||
search_pattern[255] = '\0';
|
search_pattern[255] = '\0';
|
||||||
strncpy(search_path, path, 256);
|
strncpy(search_path, path, 256);
|
||||||
search_path[255] = '\0';
|
search_path[255] = '\0';
|
||||||
search_title_mode = mode;
|
|
||||||
} else *search_pattern = *search_path = '\0';
|
} else *search_pattern = *search_path = '\0';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void SetTitleManagerMode(bool mode) {
|
||||||
|
title_manager_mode = mode;
|
||||||
|
}
|
||||||
|
|
||||||
bool GetFATVolumeLabel(const char* drv, char* label) {
|
bool GetFATVolumeLabel(const char* drv, char* label) {
|
||||||
return (f_getlabel(drv, label, NULL) == FR_OK);
|
return (f_getlabel(drv, label, NULL) == FR_OK);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool GetRootDirContentsWorker(DirStruct* contents) {
|
bool GetRootDirContentsWorker(DirStruct* contents) {
|
||||||
static const char* drvname[] = { FS_DRVNAME };
|
const char* drvname[] = { FS_DRVNAME };
|
||||||
static const char* drvnum[] = { FS_DRVNUM };
|
static const char* drvnum[] = { FS_DRVNUM };
|
||||||
u32 n_entries = 0;
|
u32 n_entries = 0;
|
||||||
|
|
||||||
char sdlabel[16];
|
char sdlabel[DRV_LABEL_LEN];
|
||||||
if (!GetFATVolumeLabel("0:", sdlabel))
|
if (!GetFATVolumeLabel("0:", sdlabel) || !(*sdlabel))
|
||||||
snprintf(sdlabel, 16, "NOLABEL");
|
strcpy(sdlabel, STR_LAB_NOLABEL);
|
||||||
|
|
||||||
|
char carttype[16];
|
||||||
|
GetVCartTypeString(carttype);
|
||||||
|
|
||||||
// virtual root objects hacked in
|
// virtual root objects hacked in
|
||||||
for (u32 i = 0; (i < NORM_FS+VIRT_FS) && (n_entries < MAX_DIR_ENTRIES); i++) {
|
for (u32 i = 0; (i < countof(drvnum)) && (n_entries < MAX_DIR_ENTRIES); i++) {
|
||||||
DirEntry* entry = &(contents->entry[n_entries]);
|
DirEntry* entry = &(contents->entry[n_entries]);
|
||||||
if (!DriveType(drvnum[i])) continue; // drive not available
|
if (!DriveType(drvnum[i])) continue; // drive not available
|
||||||
memset(entry->path, 0x00, 64);
|
entry->p_name = 4;
|
||||||
snprintf(entry->path + 0, 4, "%s", drvnum[i]);
|
entry->name = entry->path + entry->p_name;
|
||||||
|
memset(entry->path, 0x00, 256);
|
||||||
|
snprintf(entry->path, 4, "%s", drvnum[i]);
|
||||||
if ((*(drvnum[i]) >= '7') && (*(drvnum[i]) <= '9') && !(GetMountState() & IMG_NAND)) // Drive 7...9 handling
|
if ((*(drvnum[i]) >= '7') && (*(drvnum[i]) <= '9') && !(GetMountState() & IMG_NAND)) // Drive 7...9 handling
|
||||||
snprintf(entry->path + 4, 32, "[%s] %s", drvnum[i],
|
snprintf(entry->name, 252, "[%s] %s", drvnum[i],
|
||||||
(*(drvnum[i]) == '7') ? "FAT IMAGE" :
|
(*(drvnum[i]) == '7') ? STR_LAB_FAT_IMAGE :
|
||||||
(*(drvnum[i]) == '8') ? "BONUS DRIVE" :
|
(*(drvnum[i]) == '8') ? STR_LAB_BONUS_DRIVE :
|
||||||
(*(drvnum[i]) == '9') ? "RAMDRIVE" : "UNK");
|
(*(drvnum[i]) == '9') ? STR_LAB_RAMDRIVE : "UNK");
|
||||||
else if (*(drvnum[i]) == 'G') // Game drive special handling
|
else if (*(drvnum[i]) == 'G') // Game drive special handling
|
||||||
snprintf(entry->path + 4, 32, "[%s] %s %s", drvnum[i],
|
snprintf(entry->name, 252, "[%s] %s %s", drvnum[i],
|
||||||
(GetMountState() & GAME_CIA ) ? "CIA" :
|
(GetMountState() & GAME_CIA ) ? "CIA" :
|
||||||
(GetMountState() & GAME_NCSD ) ? "NCSD" :
|
(GetMountState() & GAME_NCSD ) ? "NCSD" :
|
||||||
(GetMountState() & GAME_NCCH ) ? "NCCH" :
|
(GetMountState() & GAME_NCCH ) ? "NCCH" :
|
||||||
@ -107,17 +119,18 @@ bool GetRootDirContentsWorker(DirStruct* contents) {
|
|||||||
(GetMountState() & GAME_NDS ) ? "NDS" :
|
(GetMountState() & GAME_NDS ) ? "NDS" :
|
||||||
(GetMountState() & SYS_FIRM ) ? "FIRM" :
|
(GetMountState() & SYS_FIRM ) ? "FIRM" :
|
||||||
(GetMountState() & GAME_TAD ) ? "DSIWARE" : "UNK", drvname[i]);
|
(GetMountState() & GAME_TAD ) ? "DSIWARE" : "UNK", drvname[i]);
|
||||||
|
else if (*(drvnum[i]) == 'C') // Game cart handling
|
||||||
|
snprintf(entry->name, 252, "[%s] %s (%s)", drvnum[i], drvname[i], carttype);
|
||||||
else if (*(drvnum[i]) == '0') // SD card handling
|
else if (*(drvnum[i]) == '0') // SD card handling
|
||||||
snprintf(entry->path + 4, 32, "[%s] %s (%s)", drvnum[i], drvname[i], sdlabel);
|
snprintf(entry->name, 252, "[%s] %s (%s)", drvnum[i], drvname[i], sdlabel);
|
||||||
else snprintf(entry->path + 4, 32, "[%s] %s", drvnum[i], drvname[i]);
|
else snprintf(entry->name, 252, "[%s] %s", drvnum[i], drvname[i]);
|
||||||
entry->name = entry->path + 4;
|
|
||||||
entry->size = GetTotalSpace(entry->path);
|
entry->size = GetTotalSpace(entry->path);
|
||||||
entry->type = T_ROOT;
|
entry->type = T_ROOT;
|
||||||
entry->marked = 0;
|
entry->marked = 0;
|
||||||
n_entries++;
|
n_entries++;
|
||||||
}
|
}
|
||||||
contents->n_entries = n_entries;
|
contents->n_entries = n_entries;
|
||||||
|
|
||||||
return contents->n_entries;
|
return contents->n_entries;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -126,11 +139,11 @@ bool GetDirContentsWorker(DirStruct* contents, char* fpath, int fnsize, const ch
|
|||||||
FILINFO fno;
|
FILINFO fno;
|
||||||
char* fname = fpath + strnlen(fpath, fnsize - 1);
|
char* fname = fpath + strnlen(fpath, fnsize - 1);
|
||||||
bool ret = false;
|
bool ret = false;
|
||||||
|
|
||||||
if (fvx_opendir(&pdir, fpath) != FR_OK)
|
if (fvx_opendir(&pdir, fpath) != FR_OK)
|
||||||
return false;
|
return false;
|
||||||
if (*(fname-1) != '/') *(fname++) = '/';
|
if (*(fname-1) != '/') *(fname++) = '/';
|
||||||
|
|
||||||
while (fvx_readdir(&pdir, &fno) == FR_OK) {
|
while (fvx_readdir(&pdir, &fno) == FR_OK) {
|
||||||
if ((strncmp(fno.fname, ".", 2) == 0) || (strncmp(fno.fname, "..", 3) == 0))
|
if ((strncmp(fno.fname, ".", 2) == 0) || (strncmp(fno.fname, "..", 3) == 0))
|
||||||
continue; // filter out virtual entries
|
continue; // filter out virtual entries
|
||||||
@ -144,9 +157,14 @@ bool GetDirContentsWorker(DirStruct* contents, char* fpath, int fnsize, const ch
|
|||||||
break;
|
break;
|
||||||
} else if (!pattern || (fvx_match_name(fname, pattern) == FR_OK)) {
|
} else if (!pattern || (fvx_match_name(fname, pattern) == FR_OK)) {
|
||||||
DirEntry* entry = &(contents->entry[contents->n_entries]);
|
DirEntry* entry = &(contents->entry[contents->n_entries]);
|
||||||
|
if (contents->n_entries >= MAX_DIR_ENTRIES) {
|
||||||
|
ret = true; // Too many entries, still okay if we stop here
|
||||||
|
break;
|
||||||
|
}
|
||||||
strncpy(entry->path, fpath, 256);
|
strncpy(entry->path, fpath, 256);
|
||||||
entry->path[255] = '\0';
|
entry->path[255] = '\0';
|
||||||
entry->name = entry->path + (fname - fpath);
|
entry->p_name = fname - fpath;
|
||||||
|
entry->name = entry->path + entry->p_name;
|
||||||
if (fno.fattrib & AM_DIR) {
|
if (fno.fattrib & AM_DIR) {
|
||||||
entry->type = T_DIR;
|
entry->type = T_DIR;
|
||||||
entry->size = 0;
|
entry->size = 0;
|
||||||
@ -155,12 +173,8 @@ bool GetDirContentsWorker(DirStruct* contents, char* fpath, int fnsize, const ch
|
|||||||
entry->size = fno.fsize;
|
entry->size = fno.fsize;
|
||||||
}
|
}
|
||||||
entry->marked = 0;
|
entry->marked = 0;
|
||||||
if (!recursive || (entry->type != T_DIR)) {
|
if (!recursive || (entry->type != T_DIR))
|
||||||
if (++(contents->n_entries) >= MAX_DIR_ENTRIES) {
|
++(contents->n_entries);
|
||||||
ret = true; // Too many entries, still okay if we stop here
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
if (recursive && (fno.fattrib & AM_DIR)) {
|
if (recursive && (fno.fattrib & AM_DIR)) {
|
||||||
if (!GetDirContentsWorker(contents, fpath, fnsize, pattern, recursive))
|
if (!GetDirContentsWorker(contents, fpath, fnsize, pattern, recursive))
|
||||||
@ -168,7 +182,7 @@ bool GetDirContentsWorker(DirStruct* contents, char* fpath, int fnsize, const ch
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
fvx_closedir(&pdir);
|
fvx_closedir(&pdir);
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -179,11 +193,13 @@ void SearchDirContents(DirStruct* contents, const char* path, const char* patter
|
|||||||
contents->n_entries = 0; // not required, but so what?
|
contents->n_entries = 0; // not required, but so what?
|
||||||
} else {
|
} else {
|
||||||
// create virtual '..' entry
|
// create virtual '..' entry
|
||||||
contents->entry->name = contents->entry->path + 8;
|
DirEntry* entry = (DirEntry*) &(contents->entry);
|
||||||
strncpy(contents->entry->path, "*?*?*", 8);
|
entry->p_name = 4;
|
||||||
strncpy(contents->entry->name, "..", 4);
|
entry->name = entry->path + entry->p_name;
|
||||||
contents->entry->type = T_DOTDOT;
|
strncpy(entry->path, "*?*", 4);
|
||||||
contents->entry->size = 0;
|
strncpy(entry->name, "..", 4);
|
||||||
|
entry->type = T_DOTDOT;
|
||||||
|
entry->size = 0;
|
||||||
contents->n_entries = 1;
|
contents->n_entries = 1;
|
||||||
// search the path
|
// search the path
|
||||||
char fpath[256]; // 256 is the maximum length of a full path
|
char fpath[256]; // 256 is the maximum length of a full path
|
||||||
@ -196,9 +212,12 @@ void SearchDirContents(DirStruct* contents, const char* path, const char* patter
|
|||||||
|
|
||||||
void GetDirContents(DirStruct* contents, const char* path) {
|
void GetDirContents(DirStruct* contents, const char* path) {
|
||||||
if (*search_path && (DriveType(path) & DRV_SEARCH)) {
|
if (*search_path && (DriveType(path) & DRV_SEARCH)) {
|
||||||
ShowString("Searching, please wait...");
|
ShowString("%s", STR_SEARCHING_PLEASE_WAIT);
|
||||||
SearchDirContents(contents, search_path, search_pattern, true);
|
SearchDirContents(contents, search_path, search_pattern, true);
|
||||||
if (search_title_mode) SetDirGoodNames(contents);
|
ClearScreenF(true, false, COLOR_STD_BG);
|
||||||
|
} else if (title_manager_mode && (DriveType(path) & DRV_TITLEMAN)) {
|
||||||
|
SearchDirContents(contents, "T:", "*", false);
|
||||||
|
SetupTitleManager(contents);
|
||||||
ClearScreenF(true, false, COLOR_STD_BG);
|
ClearScreenF(true, false, COLOR_STD_BG);
|
||||||
} else SearchDirContents(contents, path, NULL, false);
|
} else SearchDirContents(contents, path, NULL, false);
|
||||||
if (*path) SortDirStruct(contents);
|
if (*path) SortDirStruct(contents);
|
||||||
@ -212,8 +231,8 @@ uint64_t GetFreeSpace(const char* path)
|
|||||||
int pdrv = GetMountedFSNum(path);
|
int pdrv = GetMountedFSNum(path);
|
||||||
FATFS* fsobj = GetMountedFSObject(path);
|
FATFS* fsobj = GetMountedFSObject(path);
|
||||||
if ((pdrv < 0) || !fsobj) return 0;
|
if ((pdrv < 0) || !fsobj) return 0;
|
||||||
|
|
||||||
snprintf(fsname, 3, "%i:", pdrv);
|
snprintf(fsname, sizeof(fsname), "%i:", pdrv);
|
||||||
if (f_getfree(fsname, &free_clusters, &fsptr) != FR_OK)
|
if (f_getfree(fsname, &free_clusters, &fsptr) != FR_OK)
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
|
@ -4,8 +4,7 @@
|
|||||||
#include "fsdir.h"
|
#include "fsdir.h"
|
||||||
|
|
||||||
#define NORM_FS 10
|
#define NORM_FS 10
|
||||||
#define IMGN_FS 3 // image normal filesystems
|
#define IMGN_FS 3 // image normal filesystems
|
||||||
#define VIRT_FS 12
|
|
||||||
|
|
||||||
// primary drive types
|
// primary drive types
|
||||||
#define DRV_UNKNOWN (0<<0)
|
#define DRV_UNKNOWN (0<<0)
|
||||||
@ -26,28 +25,36 @@
|
|||||||
#define DRV_VRAM (1UL<<13)
|
#define DRV_VRAM (1UL<<13)
|
||||||
#define DRV_ALIAS (1UL<<14)
|
#define DRV_ALIAS (1UL<<14)
|
||||||
#define DRV_BONUS (1UL<<15)
|
#define DRV_BONUS (1UL<<15)
|
||||||
#define DRV_SEARCH (1UL<<16)
|
#define DRV_TITLEMAN (1UL<<16)
|
||||||
#define DRV_STDFAT (1UL<<17) // standard FAT drive without limitations
|
#define DRV_SEARCH (1UL<<17)
|
||||||
|
#define DRV_STDFAT (1UL<<18) // standard FAT drive without limitations
|
||||||
|
|
||||||
|
#define DRV_LABEL_LEN (36)
|
||||||
|
|
||||||
#define FS_DRVNAME \
|
#define FS_DRVNAME \
|
||||||
"SDCARD", \
|
STR_LAB_SDCARD, \
|
||||||
"SYSNAND CTRNAND", "SYSNAND TWLN", "SYSNAND TWLP", "SYSNAND SD", "SYSNAND VIRTUAL", \
|
STR_LAB_SYSNAND_CTRNAND, STR_LAB_SYSNAND_TWLN, STR_LAB_SYSNAND_TWLP, STR_LAB_SYSNAND_SD, STR_LAB_SYSNAND_VIRTUAL, \
|
||||||
"EMUNAND CTRNAND", "EMUNAND TWLN", "EMUNAND TWLP", "EMUNAND SD", "EMUNAND VIRTUAL", \
|
STR_LAB_EMUNAND_CTRNAND, STR_LAB_EMUNAND_TWLN, STR_LAB_EMUNAND_TWLP, STR_LAB_EMUNAND_SD, STR_LAB_EMUNAND_VIRTUAL, \
|
||||||
"IMGNAND CTRNAND", "IMGNAND TWLN", "IMGNAND TWLP", "IMGNAND VIRTUAL", \
|
STR_LAB_IMGNAND_CTRNAND, STR_LAB_IMGNAND_TWLN, STR_LAB_IMGNAND_TWLP, STR_LAB_IMGNAND_VIRTUAL, \
|
||||||
"GAMECART", \
|
STR_LAB_GAMECART, \
|
||||||
"GAME IMAGE", "AESKEYDB IMAGE", "TICKET.DB IMAGE", \
|
STR_LAB_GAME_IMAGE, STR_LAB_AESKEYDB_IMAGE, STR_LAB_BDRI_IMAGE, STR_LAB_DISA_DIFF_IMAGE, \
|
||||||
"MEMORY VIRTUAL", \
|
STR_LAB_MEMORY_VIRTUAL, \
|
||||||
"VRAM VIRTUAL", \
|
STR_LAB_VRAM_VIRTUAL, \
|
||||||
"LAST SEARCH" \
|
STR_LAB_TITLE_MANAGER, \
|
||||||
|
STR_LAB_LAST_SEARCH
|
||||||
|
|
||||||
#define FS_DRVNUM \
|
#define FS_DRVNUM \
|
||||||
"0:", "1:", "2:", "3:", "A:", "S:", "4:", "5:", "6:", "B:", "E:", "7:", "8:", "9:", "I:", "C:", "G:", "K:", "T:", "M:", "V:", "Z:"
|
"0:", "1:", "2:", "3:", "A:", "S:", "4:", "5:", "6:", "B:", "E:", "7:", "8:", "9:", \
|
||||||
|
"I:", "C:", "G:", "K:", "T:", "D:", "M:", "V:", "Y:", "Z:"
|
||||||
|
|
||||||
/** Function to identify the type of a drive **/
|
/** Function to identify the type of a drive **/
|
||||||
int DriveType(const char* path);
|
int DriveType(const char* path);
|
||||||
|
|
||||||
/** Set search pattern / path / mode for special Z: drive **/
|
/** Set search pattern / path / mode for special Z: drive **/
|
||||||
void SetFSSearch(const char* pattern, const char* path, bool mode);
|
void SetFSSearch(const char* pattern, const char* path);
|
||||||
|
|
||||||
|
/** Enable title manager for special processing of mounted title.db **/
|
||||||
|
void SetTitleManagerMode(bool mode);
|
||||||
|
|
||||||
/** Read the FAT volume label of a partition **/
|
/** Read the FAT volume label of a partition **/
|
||||||
bool GetFATVolumeLabel(const char* drv, char* label);
|
bool GetFATVolumeLabel(const char* drv, char* label);
|
||||||
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
x
Reference in New Issue
Block a user