mirror of
https://github.com/TomHarte/CLK.git
synced 2025-10-25 09:27:01 +00:00
Compare commits
1629 Commits
2020-11-13
...
2021-12-19
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
bdf0a1941c | ||
|
|
d0e3024bec | ||
|
|
d2ad149e56 | ||
|
|
ad602a4722 | ||
|
|
348840a2aa | ||
|
|
3a719633eb | ||
|
|
bd69948d37 | ||
|
|
54aa211f56 | ||
|
|
f118891970 | ||
|
|
c4055fde97 | ||
|
|
dbae3fc9a5 | ||
|
|
7c73ed7ed5 | ||
|
|
c834960bfb | ||
|
|
600abc55b5 | ||
|
|
f3ec7d54bb | ||
|
|
090760e526 | ||
|
|
cccde7dc89 | ||
|
|
849e48f519 | ||
|
|
1c3935eb40 | ||
|
|
466bed3163 | ||
|
|
641a9c72e9 | ||
|
|
5138216ba1 | ||
|
|
de1f5686a8 | ||
|
|
c983678fcd | ||
|
|
2b0415d552 | ||
|
|
066e4421e8 | ||
|
|
f02a241249 | ||
|
|
a5fe1e4259 | ||
|
|
9b80563443 | ||
|
|
91b5da06e3 | ||
|
|
7320f96ae7 | ||
|
|
fdf2b9cd7b | ||
|
|
bfc70a1b60 | ||
|
|
aff7a93106 | ||
|
|
3b027c4593 | ||
|
|
42d3bdd373 | ||
|
|
57789092c1 | ||
|
|
6bc5268cbd | ||
|
|
887ab705d1 | ||
|
|
ff6ddaed2e | ||
|
|
e6fe36f45c | ||
|
|
3a26f6b8bf | ||
|
|
06b6f85d55 | ||
|
|
d6f1ea50a6 | ||
|
|
9554869886 | ||
|
|
364059551c | ||
|
|
06340b1ad7 | ||
|
|
d23511860d | ||
|
|
a8dd4660b2 | ||
|
|
eb3a0eb3c7 | ||
|
|
cd0148e0bc | ||
|
|
8584ee609f | ||
|
|
373847e2b7 | ||
|
|
84f7d8dfc2 | ||
|
|
e057a7d0dd | ||
|
|
7bab15bf99 | ||
|
|
dac40630fd | ||
|
|
33bfa1b81c | ||
|
|
8fc27dc292 | ||
|
|
f8e8f18be5 | ||
|
|
8b38c567d2 | ||
|
|
cd53e42d79 | ||
|
|
bea6cf2038 | ||
|
|
eca80f1425 | ||
|
|
1c0962e53c | ||
|
|
4b21549ff4 | ||
|
|
30d7b0129b | ||
|
|
ce6877d6e4 | ||
|
|
0ab5177637 | ||
|
|
276cbfa505 | ||
|
|
610c85a354 | ||
|
|
012084b37b | ||
|
|
55af6681af | ||
|
|
2a7a42ff8f | ||
|
|
7af5737ec5 | ||
|
|
0ad1529f3f | ||
|
|
0df8173536 | ||
|
|
b517811e2f | ||
|
|
83d3a9c6dd | ||
|
|
d0402261e6 | ||
|
|
6f6e09d200 | ||
|
|
24e2fd4184 | ||
|
|
1aada996dc | ||
|
|
f5d3d6bcea | ||
|
|
a8a99f647f | ||
|
|
ff68b26c44 | ||
|
|
a94b4f62fd | ||
|
|
bcc959d938 | ||
|
|
cf25d8a378 | ||
|
|
c750bdafd5 | ||
|
|
693d46f8ea | ||
|
|
3496ebd1d7 | ||
|
|
be763cf7fe | ||
|
|
c3b4bee210 | ||
|
|
6df0227ab1 | ||
|
|
2a3a7fa8a0 | ||
|
|
50a6496399 | ||
|
|
c99dee86dd | ||
|
|
0c5bb9626b | ||
|
|
a9971917f5 | ||
|
|
4c62611da3 | ||
|
|
47f36f08fb | ||
|
|
f906bab1a5 | ||
|
|
fffc03c4e4 | ||
|
|
0f6934a131 | ||
|
|
0a94184d6b | ||
|
|
7be3578497 | ||
|
|
eeaccb8ac0 | ||
|
|
8ef9a932aa | ||
|
|
31e22e4cfb | ||
|
|
4fc25fb798 | ||
|
|
941d9a46a2 | ||
|
|
ecfe68d70f | ||
|
|
c0c2b5e3a9 | ||
|
|
f102d8a4b4 | ||
|
|
471e13efbc | ||
|
|
6d34432988 | ||
|
|
d3f0d15732 | ||
|
|
b827b9e33e | ||
|
|
29e5ecc282 | ||
|
|
c9bf2dda16 | ||
|
|
3ceb378b9b | ||
|
|
1cf1c90511 | ||
|
|
491b9f83f2 | ||
|
|
d989825216 | ||
|
|
3976420b88 | ||
|
|
2f1ce5fe43 | ||
|
|
42145a5b8a | ||
|
|
04f4536cb2 | ||
|
|
4e66017205 | ||
|
|
2c1f2edcf2 | ||
|
|
299d517449 | ||
|
|
561e73dbd7 | ||
|
|
9e6ffaad7d | ||
|
|
9cded1e92c | ||
|
|
4c1ab6ff25 | ||
|
|
16f31cab6a | ||
|
|
02c88e6826 | ||
|
|
9ecd43238f | ||
|
|
5ffe71346c | ||
|
|
d25804f4a2 | ||
|
|
edb75e69cb | ||
|
|
f3e895f17c | ||
|
|
b952d73e83 | ||
|
|
07facc0636 | ||
|
|
da1a69be27 | ||
|
|
7e31658932 | ||
|
|
5ebc59dd1f | ||
|
|
b10f5ab110 | ||
|
|
b4286bb42b | ||
|
|
4d7ce3792f | ||
|
|
76767da300 | ||
|
|
dc8701a929 | ||
|
|
139d35c6f9 | ||
|
|
cb24457b4a | ||
|
|
9f3efb7f05 | ||
|
|
e6001e0f22 | ||
|
|
c6535bf035 | ||
|
|
7118a515e0 | ||
|
|
952451c9b8 | ||
|
|
610327a04e | ||
|
|
2121e32409 | ||
|
|
7ec21edc2f | ||
|
|
003162f710 | ||
|
|
040ac93042 | ||
|
|
b489ba3d0d | ||
|
|
c5e8b547af | ||
|
|
e67de90ad0 | ||
|
|
c3c84c88a1 | ||
|
|
0dc9c4cee1 | ||
|
|
544c137cb0 | ||
|
|
b312a61a81 | ||
|
|
4917556a99 | ||
|
|
15ed4a0d09 | ||
|
|
aa6b0f07b7 | ||
|
|
d9d20d9d30 | ||
|
|
689bfbbdb3 | ||
|
|
e27a10bde4 | ||
|
|
253a199f27 | ||
|
|
61e5702520 | ||
|
|
b12c640807 | ||
|
|
9be23ecc34 | ||
|
|
8960f471a0 | ||
|
|
955cb6411c | ||
|
|
fc4ca4f8e3 | ||
|
|
eec068914e | ||
|
|
a1f02d0cd8 | ||
|
|
39b8285ba5 | ||
|
|
7733fef3bd | ||
|
|
6acddfdb98 | ||
|
|
ec3d5c0b32 | ||
|
|
99492c2ec2 | ||
|
|
addf9f9af4 | ||
|
|
846b505d27 | ||
|
|
c4cfcfab8e | ||
|
|
5e083426c5 | ||
|
|
8d43b4a98d | ||
|
|
aeaea073c6 | ||
|
|
6b0dd19442 | ||
|
|
9336ffe216 | ||
|
|
eb157f15f3 | ||
|
|
d6e2a3f425 | ||
|
|
b47ca13ed3 | ||
|
|
67546c4d6e | ||
|
|
f72deb0a5c | ||
|
|
616ccbb878 | ||
|
|
5899af0038 | ||
|
|
ed303310bb | ||
|
|
33ff4f3b5c | ||
|
|
20bad38d42 | ||
|
|
92a07398cd | ||
|
|
ce8f782577 | ||
|
|
e961d0b4a3 | ||
|
|
2253ff656a | ||
|
|
18631399ad | ||
|
|
ad4afcdcd5 | ||
|
|
2cf5bcc5db | ||
|
|
1180ad7662 | ||
|
|
5463cd1ae3 | ||
|
|
647ec770ce | ||
|
|
e47bec2e65 | ||
|
|
6566936be9 | ||
|
|
674941abdf | ||
|
|
b3f0ca39ed | ||
|
|
5ccb512883 | ||
|
|
da286d5ae8 | ||
|
|
73e45511dc | ||
|
|
a282a51673 | ||
|
|
b7b13e20d1 | ||
|
|
ad90c6b6ce | ||
|
|
402fa41bc0 | ||
|
|
0b9ebafc0f | ||
|
|
140e24ef15 | ||
|
|
0c998d60cb | ||
|
|
ffcd2ea10c | ||
|
|
cb460de94d | ||
|
|
f6624bf776 | ||
|
|
b4b6c4d86f | ||
|
|
759689ff31 | ||
|
|
1dfc36f311 | ||
|
|
1c03ff1d37 | ||
|
|
19dd2f92bd | ||
|
|
acfaa016a0 | ||
|
|
732761433a | ||
|
|
9012a7f5e1 | ||
|
|
e957b471b2 | ||
|
|
e5a5faa417 | ||
|
|
313dbe05e0 | ||
|
|
adf7124e2c | ||
|
|
c4ab2bbeed | ||
|
|
42ef459e20 | ||
|
|
cad1a9e0f1 | ||
|
|
f1d514470d | ||
|
|
9a7a54f22f | ||
|
|
137d1c61bd | ||
|
|
adc071ed7a | ||
|
|
e06f470044 | ||
|
|
ab69fe56c9 | ||
|
|
60bad22a91 | ||
|
|
7092429f7c | ||
|
|
fa800bb809 | ||
|
|
e15f1103a0 | ||
|
|
a4263b5a8c | ||
|
|
3d85f820f4 | ||
|
|
245b7baa61 | ||
|
|
0eeaaa150a | ||
|
|
692d87f446 | ||
|
|
6572efe2a7 | ||
|
|
8aac2bd029 | ||
|
|
add11db369 | ||
|
|
e47eab1d40 | ||
|
|
2f86dfdf2b | ||
|
|
fa71ae3174 | ||
|
|
dfcd1508c9 | ||
|
|
0ca4631279 | ||
|
|
7e5fc4444a | ||
|
|
a6221ca322 | ||
|
|
d8e42c4379 | ||
|
|
3bf109ae0b | ||
|
|
dd37fa49a0 | ||
|
|
3227ec72a2 | ||
|
|
ee324c3d89 | ||
|
|
863971f944 | ||
|
|
fd70f7ad43 | ||
|
|
6e034c9b7f | ||
|
|
52e375a985 | ||
|
|
635c1eacd5 | ||
|
|
f49ba18627 | ||
|
|
6dbce96781 | ||
|
|
9ec42f0f8f | ||
|
|
10a5e7313f | ||
|
|
ec9cb21fae | ||
|
|
fdd02ad6a6 | ||
|
|
76e9fcc94a | ||
|
|
e412927415 | ||
|
|
dda154c7c6 | ||
|
|
9215535bee | ||
|
|
27726fd2d1 | ||
|
|
77befb7f8e | ||
|
|
86c6248b48 | ||
|
|
f2af8ff25d | ||
|
|
7d8894415c | ||
|
|
f8380d2d4c | ||
|
|
5cc25d0846 | ||
|
|
1502c4530e | ||
|
|
c1df4d1c0b | ||
|
|
1f9e41e9cb | ||
|
|
e402e690b0 | ||
|
|
6a15bb15ca | ||
|
|
3255fc91fa | ||
|
|
7f2610c4fc | ||
|
|
79bd3eb6ae | ||
|
|
b11dd6950c | ||
|
|
98bd6fc240 | ||
|
|
8be053fd35 | ||
|
|
99fee22a9f | ||
|
|
084d002353 | ||
|
|
dcbc9847a3 | ||
|
|
db3c158215 | ||
|
|
25e2bd307a | ||
|
|
b9f78f5d33 | ||
|
|
b4ec9d70da | ||
|
|
738999a8b7 | ||
|
|
dd91d793d9 | ||
|
|
1f0bf1b32d | ||
|
|
8e51e8eb77 | ||
|
|
6210605bc7 | ||
|
|
0245b040b0 | ||
|
|
34c1cc5693 | ||
|
|
8795719c18 | ||
|
|
6bbbf43341 | ||
|
|
f0ef45f0ca | ||
|
|
ee6039bfa5 | ||
|
|
ef58ce6277 | ||
|
|
15de5e98c4 | ||
|
|
38848ca2db | ||
|
|
77c627e822 | ||
|
|
c640132699 | ||
|
|
60b09d9bb0 | ||
|
|
57dd38aef2 | ||
|
|
460a6cb6fe | ||
|
|
fdb676da4e | ||
|
|
26aaddaa33 | ||
|
|
e51151e558 | ||
|
|
f576baf214 | ||
|
|
5c1ac05170 | ||
|
|
1bae4973bc | ||
|
|
3d9f86c584 | ||
|
|
3514e537ca | ||
|
|
3d160ce85f | ||
|
|
b78090ec76 | ||
|
|
759007ffc1 | ||
|
|
37a55c3a77 | ||
|
|
69ae9d72c8 | ||
|
|
604232acd9 | ||
|
|
82205d71cc | ||
|
|
402eab10f8 | ||
|
|
b6bf4d73ad | ||
|
|
5425b5c423 | ||
|
|
29cd8504ca | ||
|
|
3544746934 | ||
|
|
d8f814f1c4 | ||
|
|
a43175125a | ||
|
|
1d03bc560a | ||
|
|
3832acf6e3 | ||
|
|
7894b50321 | ||
|
|
ffded619e6 | ||
|
|
bcb7bb5cce | ||
|
|
87dcd82f69 | ||
|
|
e671cc6056 | ||
|
|
5da89b88a6 | ||
|
|
5d60c1f20b | ||
|
|
7fd00165c9 | ||
|
|
34d4420e8c | ||
|
|
20da194fab | ||
|
|
8d2d4c850f | ||
|
|
b7bed027d7 | ||
|
|
fcd6b7b0ea | ||
|
|
ceca32ceb3 | ||
|
|
e3bb9fc1d7 | ||
|
|
77a8ddb95c | ||
|
|
c733a4dbf8 | ||
|
|
d898a43dff | ||
|
|
6216d53b1a | ||
|
|
86c30769d9 | ||
|
|
956a6dbd64 | ||
|
|
68fe19818e | ||
|
|
de208ead4e | ||
|
|
69d62560b4 | ||
|
|
87d2fc1491 | ||
|
|
2bc9af09e1 | ||
|
|
26f4758523 | ||
|
|
6123349b79 | ||
|
|
d1ac54fe92 | ||
|
|
9468adf737 | ||
|
|
e85db40b0f | ||
|
|
b3d55cc16d | ||
|
|
56b62a5e49 | ||
|
|
3ee1fc544f | ||
|
|
5401744dc0 | ||
|
|
fe10a10ac2 | ||
|
|
ba2e5a97a9 | ||
|
|
4515d1220c | ||
|
|
486959bce8 | ||
|
|
e1a410bf3d | ||
|
|
3767cc7c0b | ||
|
|
96b0ce9ef2 | ||
|
|
038ed0551e | ||
|
|
cfaf4a8a65 | ||
|
|
22dd8a8847 | ||
|
|
b2ae8e7a4a | ||
|
|
3e2bac8129 | ||
|
|
50b9d0e86d | ||
|
|
a030d9935e | ||
|
|
c425dec4d5 | ||
|
|
67d53601d5 | ||
|
|
622cca0acf | ||
|
|
48999c03a5 | ||
|
|
377cc7bdcd | ||
|
|
a5d0976c2d | ||
|
|
ae05010255 | ||
|
|
66cacbd0e0 | ||
|
|
b1616be4b8 | ||
|
|
a0a9a72d8f | ||
|
|
0cfc7f732c | ||
|
|
f7de6f790c | ||
|
|
d1f3b5ed80 | ||
|
|
7925dcc5a2 | ||
|
|
6ade36bf09 | ||
|
|
c52945aab5 | ||
|
|
2b0a4055f7 | ||
|
|
7cb16a3fc5 | ||
|
|
0b80c1988b | ||
|
|
eab9bc1503 | ||
|
|
5bfedff8d1 | ||
|
|
c8638c0ffb | ||
|
|
8a95b91e2a | ||
|
|
c226be612f | ||
|
|
c8699d9770 | ||
|
|
a0799e14cc | ||
|
|
dea6048849 | ||
|
|
813e252539 | ||
|
|
b41e29a83b | ||
|
|
d35c7ad127 | ||
|
|
ea63415d0e | ||
|
|
52ea3b741c | ||
|
|
2731ca8c92 | ||
|
|
af1ade9433 | ||
|
|
fc248951cc | ||
|
|
84547ee1c1 | ||
|
|
a42848c62f | ||
|
|
c7b5d69431 | ||
|
|
81374b70b5 | ||
|
|
47a530fd5c | ||
|
|
58451d7c0c | ||
|
|
5c8f8c76fe | ||
|
|
ae1d1bdb5b | ||
|
|
33cc1154a2 | ||
|
|
4bc0b75c30 | ||
|
|
eb8ec1efb1 | ||
|
|
616f8efc47 | ||
|
|
29e4369420 | ||
|
|
bd7f7bc8d7 | ||
|
|
e689ca92c4 | ||
|
|
4ef3005072 | ||
|
|
174c837767 | ||
|
|
486bb911a9 | ||
|
|
754221d697 | ||
|
|
3c36c90729 | ||
|
|
3d1d15a25b | ||
|
|
000d99f26c | ||
|
|
524e2abc8c | ||
|
|
00bab98e09 | ||
|
|
6d98349be1 | ||
|
|
d24d153c08 | ||
|
|
b01561712c | ||
|
|
324edcb391 | ||
|
|
6e62e4e296 | ||
|
|
f81ecbf4a0 | ||
|
|
4370456323 | ||
|
|
a424ed7c00 | ||
|
|
a2065f59a1 | ||
|
|
c1bd7f5c67 | ||
|
|
5810a1a98e | ||
|
|
a4c011e3c0 | ||
|
|
337fd15dc0 | ||
|
|
9bc94f4536 | ||
|
|
3f4cf35384 | ||
|
|
4dd7f2cc09 | ||
|
|
1b29cc34c4 | ||
|
|
53c3c1f5ab | ||
|
|
6225abd751 | ||
|
|
c6fcd9a1eb | ||
|
|
30fbb6ea53 | ||
|
|
0e49258546 | ||
|
|
264b8dfb28 | ||
|
|
6a15b8f695 | ||
|
|
5167d256cc | ||
|
|
16bd826491 | ||
|
|
55af8fa5d9 | ||
|
|
1ec8ff20af | ||
|
|
99a65d3297 | ||
|
|
94907b51aa | ||
|
|
0085265d13 | ||
|
|
8e0893bd42 | ||
|
|
704dc9bdcb | ||
|
|
7a673a2448 | ||
|
|
33e2a4b21c | ||
|
|
3e6b804896 | ||
|
|
e98165a657 | ||
|
|
2a7727d12b | ||
|
|
c20e8f4062 | ||
|
|
4ca9db7d49 | ||
|
|
4add48cffb | ||
|
|
adbfb009f8 | ||
|
|
43ceca8711 | ||
|
|
3ef28a4f03 | ||
|
|
adcd580d5b | ||
|
|
5715c9183f | ||
|
|
ceb62ac7f9 | ||
|
|
bda0756620 | ||
|
|
6b47fb38c6 | ||
|
|
38bf8a06a7 | ||
|
|
196651d9aa | ||
|
|
6b46212a4e | ||
|
|
2a6fff2008 | ||
|
|
c5944efe50 | ||
|
|
f384370b18 | ||
|
|
0c09275a9f | ||
|
|
278671cdb9 | ||
|
|
964d2d4fa4 | ||
|
|
f371221dba | ||
|
|
27b0579ec6 | ||
|
|
283092cfbc | ||
|
|
614953a222 | ||
|
|
4fffb3cf19 | ||
|
|
850aa2b23a | ||
|
|
d715e5fd1d | ||
|
|
7826a26c7b | ||
|
|
dc0a82cf9a | ||
|
|
2e60c81bd6 | ||
|
|
763b9ba0ec | ||
|
|
bae8bb0c00 | ||
|
|
bcf483fb7e | ||
|
|
a5b7d819a7 | ||
|
|
fe07a0b1d8 | ||
|
|
d9231e5d4a | ||
|
|
b7aa1a1c84 | ||
|
|
32e144115d | ||
|
|
177cc96f49 | ||
|
|
51d98ef9ab | ||
|
|
2327c48cc4 | ||
|
|
742d44a532 | ||
|
|
52b96db2b9 | ||
|
|
0b9de78c38 | ||
|
|
2c28cb8c57 | ||
|
|
483fe82e9d | ||
|
|
29492d6138 | ||
|
|
19310e32c4 | ||
|
|
c04a395499 | ||
|
|
1c424833a9 | ||
|
|
a46ff5590d | ||
|
|
ab059b63fd | ||
|
|
3d8fc9952d | ||
|
|
8ce8fbd977 | ||
|
|
7f08218b28 | ||
|
|
2c139ad931 | ||
|
|
1119779c8b | ||
|
|
5351ac560f | ||
|
|
49f0ab0f15 | ||
|
|
a5c57e777e | ||
|
|
3c59042388 | ||
|
|
919e211bc4 | ||
|
|
daa0737ce4 | ||
|
|
36805cb120 | ||
|
|
7de69e9874 | ||
|
|
b93575bbcc | ||
|
|
116e0f0105 | ||
|
|
e4a650aaff | ||
|
|
b5312b9ba0 | ||
|
|
6afee7bb9b | ||
|
|
5729e6e13a | ||
|
|
2f53b105bb | ||
|
|
b698056f78 | ||
|
|
95c906f03d | ||
|
|
be19fa9dde | ||
|
|
81e9ba5608 | ||
|
|
f2d7b9f6a9 | ||
|
|
1ea034310a | ||
|
|
bdcab447f9 | ||
|
|
10bf6744aa | ||
|
|
895d98e266 | ||
|
|
903e343895 | ||
|
|
f8b7c59616 | ||
|
|
fcd267a3f9 | ||
|
|
f8bb66d2a0 | ||
|
|
90782d3c27 | ||
|
|
f2336d2efc | ||
|
|
c2d093fa3c | ||
|
|
1a97cc8a91 | ||
|
|
c34a548fa0 | ||
|
|
d1b89392a2 | ||
|
|
ed734754e5 | ||
|
|
520c3c9218 | ||
|
|
9230cf1726 | ||
|
|
6e616972a5 | ||
|
|
f98888824d | ||
|
|
6c8b23e708 | ||
|
|
2c2bb3765f | ||
|
|
0d165740ea | ||
|
|
88f0f2b623 | ||
|
|
0afa143375 | ||
|
|
8319aca351 | ||
|
|
a66734883a | ||
|
|
d2ab0dd839 | ||
|
|
2574407afb | ||
|
|
83a54fd6d2 | ||
|
|
e062780968 | ||
|
|
3acd0be1f7 | ||
|
|
69c0734975 | ||
|
|
c1678d7be7 | ||
|
|
117f9a9794 | ||
|
|
b49cc407c6 | ||
|
|
954386f1cc | ||
|
|
d7ff6bd04d | ||
|
|
6025516f9f | ||
|
|
d8b9cdf7a2 | ||
|
|
09dbff39f2 | ||
|
|
2fe15a6168 | ||
|
|
07dc26f8fa | ||
|
|
a08d65b1ff | ||
|
|
199621db08 | ||
|
|
0e1e8c7faa | ||
|
|
42a98e1676 | ||
|
|
23e26e0333 | ||
|
|
fadb04f3f3 | ||
|
|
4968ccf46d | ||
|
|
1dcac304d3 | ||
|
|
1651efe4fc | ||
|
|
8f24aed43e | ||
|
|
a381374e31 | ||
|
|
9411c37d23 | ||
|
|
6af6f21868 | ||
|
|
9a0022cfcb | ||
|
|
266310d9c2 | ||
|
|
fbf1adef05 | ||
|
|
311ddfb05a | ||
|
|
2fd8a8aa66 | ||
|
|
0c3e9dca28 | ||
|
|
c331d15429 | ||
|
|
4414e96710 | ||
|
|
7161783a4f | ||
|
|
cbac48da86 | ||
|
|
d9142d5427 | ||
|
|
e5e988b28f | ||
|
|
e94e051c87 | ||
|
|
5fc91effb5 | ||
|
|
6c9dacbe89 | ||
|
|
6a7eb832cc | ||
|
|
60cf8486bb | ||
|
|
90b8163d54 | ||
|
|
a1e4389f63 | ||
|
|
440b11708b | ||
|
|
f90dce5c54 | ||
|
|
606c7709cf | ||
|
|
1d1e6d1820 | ||
|
|
3eb4dd74a2 | ||
|
|
853914480c | ||
|
|
fe04410681 | ||
|
|
1f686c4e6b | ||
|
|
2a2ac1227b | ||
|
|
b5340c8f74 | ||
|
|
196c4dcdd9 | ||
|
|
c5a86f0ef7 | ||
|
|
88f2a2940b | ||
|
|
26b019a4d4 | ||
|
|
5f7b3ae313 | ||
|
|
61c127ed2e | ||
|
|
333981e2a7 | ||
|
|
423fbc9ac7 | ||
|
|
1c1719e561 | ||
|
|
56c30e1651 | ||
|
|
1ea4130035 | ||
|
|
57713d63fa | ||
|
|
d18a537509 | ||
|
|
8e0a6df03b | ||
|
|
95a52a9f62 | ||
|
|
ae2993625c | ||
|
|
0982141442 | ||
|
|
85fab2abc4 | ||
|
|
de3b37799c | ||
|
|
70851f3b2d | ||
|
|
462bbf2e40 | ||
|
|
778b9ef683 | ||
|
|
96e7eb1bed | ||
|
|
05671f3553 | ||
|
|
6e4832f999 | ||
|
|
54e3332673 | ||
|
|
6c559d7556 | ||
|
|
9165a85484 | ||
|
|
98ada2588a | ||
|
|
43f686c22d | ||
|
|
4a2673d757 | ||
|
|
f27e331462 | ||
|
|
dd64aef910 | ||
|
|
95971f39f1 | ||
|
|
83beb3c0e6 | ||
|
|
76335e5cf2 | ||
|
|
4494320238 | ||
|
|
5acd97c860 | ||
|
|
b0f551c307 | ||
|
|
b6b3d845a3 | ||
|
|
505d84f336 | ||
|
|
1d5144b912 | ||
|
|
deff91e460 | ||
|
|
afd8dc0915 | ||
|
|
fbee74e1fe | ||
|
|
ccd82591aa | ||
|
|
64931e476d | ||
|
|
604a715a49 | ||
|
|
24757ef20c | ||
|
|
e36cc9e777 | ||
|
|
2e999889bd | ||
|
|
f4db4c3a73 | ||
|
|
d923fe72c0 | ||
|
|
f05cdd5e34 | ||
|
|
f9954619d4 | ||
|
|
0aa8c3c40d | ||
|
|
a30eeaab6a | ||
|
|
3858e79579 | ||
|
|
b4a5fa33b0 | ||
|
|
2a6e9c5e8a | ||
|
|
488c2aed51 | ||
|
|
5483f979dc | ||
|
|
ea11f3826a | ||
|
|
ceae81a332 | ||
|
|
50ea56e908 | ||
|
|
bfb2f79cff | ||
|
|
8268e8ee4c | ||
|
|
cb31e22f59 | ||
|
|
6752f4fd73 | ||
|
|
22c31e4f55 | ||
|
|
c2ff64c1e0 | ||
|
|
4db792591a | ||
|
|
1290a8e32b | ||
|
|
8ae38991b0 | ||
|
|
6d40549c0c | ||
|
|
93d5c9a3c7 | ||
|
|
9af6c0b37a | ||
|
|
7e3528c692 | ||
|
|
41f2fc51be | ||
|
|
11228dc265 | ||
|
|
ef50967793 | ||
|
|
5f6c08b7e0 | ||
|
|
6cb23ec5be | ||
|
|
1bae70bcf8 | ||
|
|
9820591ba4 | ||
|
|
77071b3c69 | ||
|
|
335e839b31 | ||
|
|
6fe947b8b9 | ||
|
|
22b29e77a7 | ||
|
|
4858cfce6b | ||
|
|
8da3e91f5e | ||
|
|
012235bfeb | ||
|
|
052e284c33 | ||
|
|
32e3dd71b1 | ||
|
|
95f4272919 | ||
|
|
00679b6135 | ||
|
|
2c18bb4508 | ||
|
|
0cf1c9040a | ||
|
|
9196341482 | ||
|
|
685140a4c2 | ||
|
|
1465b0ee4d | ||
|
|
0bf6b765d3 | ||
|
|
4774676e2a | ||
|
|
9c29655da2 | ||
|
|
c8ab18f2b6 | ||
|
|
8ebce466db | ||
|
|
1b39b17125 | ||
|
|
5a46853075 | ||
|
|
48ad4d4c4c | ||
|
|
056a036712 | ||
|
|
70eaa79108 | ||
|
|
20c814a4dd | ||
|
|
6a052e1900 | ||
|
|
cecdf8584a | ||
|
|
4758bc8615 | ||
|
|
c906dc3c0a | ||
|
|
d1dcb41b6f | ||
|
|
96ac86a757 | ||
|
|
4919786825 | ||
|
|
24b4185714 | ||
|
|
ad10d0037a | ||
|
|
b6554c8255 | ||
|
|
01dc83d0d6 | ||
|
|
2fd08789ab | ||
|
|
bc9e529995 | ||
|
|
708c24cc57 | ||
|
|
7fb3048257 | ||
|
|
9319f0525a | ||
|
|
b7a62e0121 | ||
|
|
bd5dd9b9a3 | ||
|
|
3348167c46 | ||
|
|
700c505974 | ||
|
|
d403036d86 | ||
|
|
5e08d7db39 | ||
|
|
c34cb310a8 | ||
|
|
8d86aa69bc | ||
|
|
cc41ccc5f1 | ||
|
|
e6252fe0ed | ||
|
|
03577de675 | ||
|
|
205518ba75 | ||
|
|
2510064218 | ||
|
|
0ef2806970 | ||
|
|
d80f03e369 | ||
|
|
fd271d920b | ||
|
|
2bbf8bc9fa | ||
|
|
9b65d56ed0 | ||
|
|
a5098a60ec | ||
|
|
0ebd900e40 | ||
|
|
7aeb17ac92 | ||
|
|
cc78bfb229 | ||
|
|
485c2a866c | ||
|
|
5b419ca5bf | ||
|
|
14ae579fca | ||
|
|
1c2ea0d7fe | ||
|
|
e7a9ae18a1 | ||
|
|
d61f478a39 | ||
|
|
9cc747b3e2 | ||
|
|
2f223f7db2 | ||
|
|
17f11a3be3 | ||
|
|
37dcf61130 | ||
|
|
856ebfacca | ||
|
|
9731fdd33b | ||
|
|
5ea605ccf7 | ||
|
|
d0c789ff9a | ||
|
|
9baa861742 | ||
|
|
30a1a53c97 | ||
|
|
bdb1b7e77c | ||
|
|
9293bcbc88 | ||
|
|
c481f475e7 | ||
|
|
ef01471e17 | ||
|
|
73c8157197 | ||
|
|
af1dc2d3b2 | ||
|
|
8f6b3feee1 | ||
|
|
a20f5528b7 | ||
|
|
f48876d80e | ||
|
|
db52f13c32 | ||
|
|
2590769d3f | ||
|
|
5667dcac36 | ||
|
|
bec71ead39 | ||
|
|
e4d9022d37 | ||
|
|
572be48f38 | ||
|
|
6f4ccebfa1 | ||
|
|
77fcf52d27 | ||
|
|
79c2bc1fd7 | ||
|
|
76370d9418 | ||
|
|
7bac18bd65 | ||
|
|
704737144a | ||
|
|
2a9c73a1d3 | ||
|
|
e87e851401 | ||
|
|
80d4846a27 | ||
|
|
9fd53c9c91 | ||
|
|
53eae873d8 | ||
|
|
93422f4b1c | ||
|
|
06cedb2e50 | ||
|
|
7fdb1d848b | ||
|
|
246fd9442f | ||
|
|
eb99a64b29 | ||
|
|
d7954a4cb1 | ||
|
|
ef636da866 | ||
|
|
fa18b06dbf | ||
|
|
349b9ce502 | ||
|
|
b2cf121410 | ||
|
|
71cf63bd35 | ||
|
|
d1bb3aada4 | ||
|
|
b4214c6e08 | ||
|
|
f5c7746493 | ||
|
|
f10ec80153 | ||
|
|
0af405aa46 | ||
|
|
cf481effa6 | ||
|
|
a1511f9600 | ||
|
|
325e2b3941 | ||
|
|
7017324d60 | ||
|
|
deb5d69ac7 | ||
|
|
68a04f4e6a | ||
|
|
0d61902b10 | ||
|
|
3eec210b30 | ||
|
|
5998f3b35b | ||
|
|
869567fdd9 | ||
|
|
2e70b5eb9f | ||
|
|
8a3bfb8672 | ||
|
|
06f1e64177 | ||
|
|
b42780173a | ||
|
|
36c8821c4c | ||
|
|
947de2d54a | ||
|
|
9347fe5f44 | ||
|
|
e82367def3 | ||
|
|
9cde7c12ba | ||
|
|
015556cc91 | ||
|
|
47c5a243aa | ||
|
|
070e359d82 | ||
|
|
b397059d5e | ||
|
|
400f54e508 | ||
|
|
e0736435f8 | ||
|
|
b09c5538c6 | ||
|
|
ce3d2913bf | ||
|
|
87202a2a27 | ||
|
|
818a4dff25 | ||
|
|
eacffa49f5 | ||
|
|
9e506c3206 | ||
|
|
29cf80339a | ||
|
|
50f53f7d97 | ||
|
|
73fbd89c85 | ||
|
|
f74fa06f2d | ||
|
|
ee989ab762 | ||
|
|
818655a9b6 | ||
|
|
57a7e0834f | ||
|
|
cd787486d2 | ||
|
|
67fd6787a6 | ||
|
|
627b96f73c | ||
|
|
8a6985c2e8 | ||
|
|
60e8273de2 | ||
|
|
aa8ce5c1ac | ||
|
|
dd28246f9f | ||
|
|
dc25a60b9b | ||
|
|
094d623485 | ||
|
|
1266bbb224 | ||
|
|
bd1ea5740a | ||
|
|
3e04b51122 | ||
|
|
76f2aba51a | ||
|
|
fd88071c0a | ||
|
|
16bfe1a55c | ||
|
|
90c3d6a1e8 | ||
|
|
18d6197d6c | ||
|
|
27eddf6dff | ||
|
|
57b32d9537 | ||
|
|
837b9499d5 | ||
|
|
c2fde2b147 | ||
|
|
f26bf4b9e4 | ||
|
|
1da51bee6c | ||
|
|
5a66956221 | ||
|
|
91d973c4a9 | ||
|
|
fa79589db8 | ||
|
|
e52649f74d | ||
|
|
d77ddaf4fa | ||
|
|
9ff392279a | ||
|
|
448d9dc3e1 | ||
|
|
afb4e6d37d | ||
|
|
158122fbf4 | ||
|
|
417ece2386 | ||
|
|
77b241af4f | ||
|
|
25b8c4c062 | ||
|
|
1be88a5308 | ||
|
|
294280a94e | ||
|
|
32aebfebe0 | ||
|
|
14663bd06b | ||
|
|
68abd197aa | ||
|
|
18fd21eae7 | ||
|
|
3296347370 | ||
|
|
28c9463e0d | ||
|
|
044ac949ba | ||
|
|
87317f5673 | ||
|
|
5e21a49841 | ||
|
|
687c05365e | ||
|
|
4f80523828 | ||
|
|
76299a2add | ||
|
|
48f794dc2d | ||
|
|
51b8dcd011 | ||
|
|
acdbd88b9e | ||
|
|
00a3a3c724 | ||
|
|
729edeac6c | ||
|
|
faaa4961ed | ||
|
|
7937cc2d0f | ||
|
|
8a11a5832c | ||
|
|
53ba0e67d1 | ||
|
|
e8825aeada | ||
|
|
e90e30e766 | ||
|
|
9f6bb325e6 | ||
|
|
6e2c65435a | ||
|
|
052ab44f1c | ||
|
|
daa5679241 | ||
|
|
e055668554 | ||
|
|
c96829c29e | ||
|
|
c88abed2dc | ||
|
|
e42b6cb3c8 | ||
|
|
465ecc4a78 | ||
|
|
ae4ccdf5e6 | ||
|
|
6bdaa54aaf | ||
|
|
3543a25168 | ||
|
|
03ef81b07c | ||
|
|
0ac11fc39e | ||
|
|
3d0503a35e | ||
|
|
ad8cb52f11 | ||
|
|
496a294c71 | ||
|
|
465c74ab86 | ||
|
|
4e8f82a39c | ||
|
|
584a5ad7fb | ||
|
|
0ab85cce20 | ||
|
|
44e5caf803 | ||
|
|
04291e9a86 | ||
|
|
d0776b58cf | ||
|
|
6da099d7e1 | ||
|
|
60e77785e8 | ||
|
|
19cd6a55d3 | ||
|
|
08432dd94b | ||
|
|
cc3c3663f6 | ||
|
|
b76c923ff4 | ||
|
|
3c1131a84b | ||
|
|
a3cd953415 | ||
|
|
c0abdf1b86 | ||
|
|
3ef2715eee | ||
|
|
4a12d7086d | ||
|
|
a6b75b8637 | ||
|
|
bdb3bce8d6 | ||
|
|
a26716919c | ||
|
|
8dbc7649aa | ||
|
|
42a9dc7c2b | ||
|
|
7965772745 | ||
|
|
f37f89a7d3 | ||
|
|
d987e5a9d7 | ||
|
|
fcba0cc3d6 | ||
|
|
c097ed348a | ||
|
|
0f9ab53ea0 | ||
|
|
21b1dab4a5 | ||
|
|
dd7419282d | ||
|
|
7562917740 | ||
|
|
3925eee575 | ||
|
|
6482303063 | ||
|
|
388b136980 | ||
|
|
9ce1dbaebb | ||
|
|
064667c0c3 | ||
|
|
58be770eaa | ||
|
|
1b0f45649e | ||
|
|
42bfabbe8c | ||
|
|
986c4006a6 | ||
|
|
07a63d62dd | ||
|
|
26911a16e8 | ||
|
|
cf9a5d595b | ||
|
|
09a6a1905b | ||
|
|
2ad2b4384b | ||
|
|
7729f1f3d0 | ||
|
|
7d59ff6d8f | ||
|
|
2ee478b4c4 | ||
|
|
bb0d35e3d0 | ||
|
|
84774a7910 | ||
|
|
a482ce1546 | ||
|
|
a35e1f4fbe | ||
|
|
2371048ad1 | ||
|
|
93b9ea67e6 | ||
|
|
60a0f8e824 | ||
|
|
b3fc64d4f2 | ||
|
|
650b9a139b | ||
|
|
5758693b7d | ||
|
|
f8c9ef2950 | ||
|
|
69ca2e8803 | ||
|
|
87fac15cc4 | ||
|
|
2d51924a3c | ||
|
|
c3d96b30d7 | ||
|
|
44240773ef | ||
|
|
ed587a4db5 | ||
|
|
020a04006e | ||
|
|
622a8abf7f | ||
|
|
871bac6c8a | ||
|
|
fe3e8f87e7 | ||
|
|
87fc7c02e8 | ||
|
|
f2620e6afb | ||
|
|
ab2ad70885 | ||
|
|
135134acfd | ||
|
|
5664e81d48 | ||
|
|
c353923557 | ||
|
|
b830d62850 | ||
|
|
17f551e89d | ||
|
|
4a4da90d56 | ||
|
|
404c1f06e6 | ||
|
|
730bfcd1fd | ||
|
|
97249b0edd | ||
|
|
5a1bda1d82 | ||
|
|
b7d6b8efcf | ||
|
|
9bec91c2b9 | ||
|
|
3d1775d853 | ||
|
|
814c057570 | ||
|
|
b63ca16ce2 | ||
|
|
0ddf09ac0f | ||
|
|
e53586df1d | ||
|
|
54491b35ef | ||
|
|
b447f5f174 | ||
|
|
39a105b48a | ||
|
|
cdc19c6990 | ||
|
|
397704a1e6 | ||
|
|
1a5dafae00 | ||
|
|
d368dae94a | ||
|
|
54e2eb0948 | ||
|
|
7d778bc328 | ||
|
|
7a8317ad81 | ||
|
|
a32a2f36be | ||
|
|
064fe7658c | ||
|
|
cd215ef521 | ||
|
|
14c5e038e2 | ||
|
|
82717b39bb | ||
|
|
f190a1395a | ||
|
|
4eaf3440bd | ||
|
|
f985248902 | ||
|
|
5c90744f0c | ||
|
|
e9177bbb2a | ||
|
|
ab5e4ca9c7 | ||
|
|
40516c9cec | ||
|
|
d93d380c88 | ||
|
|
8a1c6978de | ||
|
|
6839e9e3b3 | ||
|
|
83cbbe09c6 | ||
|
|
166ddab5e0 | ||
|
|
67408521cd | ||
|
|
f05260b839 | ||
|
|
62949d2f8b | ||
|
|
2f18f40697 | ||
|
|
eea4c1f148 | ||
|
|
63a792f434 | ||
|
|
7b164de6fd | ||
|
|
26ad760904 | ||
|
|
24e68166c6 | ||
|
|
b72474f418 | ||
|
|
38046d49aa | ||
|
|
4601421aa6 | ||
|
|
86fd47545d | ||
|
|
c8471eb993 | ||
|
|
83d0cfc24e | ||
|
|
cbf5a79ee8 | ||
|
|
2f45e07d82 | ||
|
|
496b6b5cfc | ||
|
|
8604b1786e | ||
|
|
267e28e012 | ||
|
|
631a8a7421 | ||
|
|
7dcb0553e4 | ||
|
|
2a7ea9f57c | ||
|
|
e2b20568c6 | ||
|
|
4f5eb4d71b | ||
|
|
a1df8452ce | ||
|
|
9781460c41 | ||
|
|
55c9d152e9 | ||
|
|
71a107fe75 | ||
|
|
6cf9099ce1 | ||
|
|
e6dc39f6f0 | ||
|
|
f6466fd657 | ||
|
|
28ce675c96 | ||
|
|
3d91b0a31b | ||
|
|
5d1970d201 | ||
|
|
72d7901c88 | ||
|
|
60cfec6a65 | ||
|
|
2e9065b34c | ||
|
|
992ee6d631 | ||
|
|
772093c311 | ||
|
|
e42843cca0 | ||
|
|
3336a123f8 | ||
|
|
bd54e30748 | ||
|
|
35be402354 | ||
|
|
28bd620e7f | ||
|
|
96f2d802d9 | ||
|
|
b117df3367 | ||
|
|
fa8236741d | ||
|
|
e16d5f33d1 | ||
|
|
2a45e7a8d4 | ||
|
|
f8f0ff0fae | ||
|
|
f5dcff2f29 | ||
|
|
e773b331cd | ||
|
|
99c21925f4 | ||
|
|
eccf5ca043 | ||
|
|
24af62a3e5 | ||
|
|
52cf15c3e6 | ||
|
|
a791680e6f | ||
|
|
a3e98907ca | ||
|
|
6e53b4c507 | ||
|
|
52c38e72f6 | ||
|
|
a51d143c35 | ||
|
|
17e9305282 | ||
|
|
c284b34003 | ||
|
|
2ab3bba695 | ||
|
|
2c4dcf8843 | ||
|
|
ea40b2c982 | ||
|
|
adfdfa205f | ||
|
|
e83b2120ce | ||
|
|
33abdc95aa | ||
|
|
6ca8aa99fc | ||
|
|
17bac4c8cf | ||
|
|
46bd20b5e0 | ||
|
|
3c7f9a43ad | ||
|
|
82312d3b59 | ||
|
|
93a80a30d3 | ||
|
|
77b1efd176 | ||
|
|
acfab1dfb3 | ||
|
|
819e9039ab | ||
|
|
6526c645a5 | ||
|
|
3d2490b774 | ||
|
|
1e041f1adf | ||
|
|
4fdf01a1a8 | ||
|
|
beb514b231 | ||
|
|
f57e897085 | ||
|
|
2a8e8a4982 | ||
|
|
9f202d4238 | ||
|
|
1a40cc048e | ||
|
|
53514c7fdc | ||
|
|
274b3c7d24 | ||
|
|
07df7572b3 | ||
|
|
906b6ccdb7 | ||
|
|
f1ba040dd8 | ||
|
|
8db289e229 | ||
|
|
8142487d57 | ||
|
|
2860be7068 | ||
|
|
b5ecd5f7ef | ||
|
|
7e720e754b | ||
|
|
41a618c957 | ||
|
|
3d85e6bb97 | ||
|
|
d54085c7fd | ||
|
|
0bb8bdf938 | ||
|
|
865058b8d6 | ||
|
|
b6bc0a21fb | ||
|
|
8311ac4a7c | ||
|
|
4636d8dfb7 | ||
|
|
ac95e4d758 | ||
|
|
b8c6d4b153 | ||
|
|
5eddc92846 | ||
|
|
f50e8b5106 | ||
|
|
dcc2fe0990 | ||
|
|
56111c75ae | ||
|
|
cc90935abd | ||
|
|
413e42e1b6 | ||
|
|
fc4bda0047 | ||
|
|
c8beb59172 | ||
|
|
8789ffda15 | ||
|
|
e8e604dc3c | ||
|
|
57e0fdfadc | ||
|
|
7f62732476 | ||
|
|
36aebe0ff9 | ||
|
|
051d2b83f4 | ||
|
|
17b12120eb | ||
|
|
6e9ce50569 | ||
|
|
adef2e9b4e | ||
|
|
0fafbf5092 | ||
|
|
3c887aff95 | ||
|
|
e5076b295b | ||
|
|
c10c161d39 | ||
|
|
04024ca159 | ||
|
|
64d556f60f | ||
|
|
8564e7406b | ||
|
|
ebdb58d790 | ||
|
|
cf8afc70b2 | ||
|
|
4f02e8fbaf | ||
|
|
6e618a6bb7 | ||
|
|
df1bc18fb3 | ||
|
|
9f12ce2fb8 | ||
|
|
b9672c0669 | ||
|
|
e58608b25a | ||
|
|
e502d76371 | ||
|
|
b0c790f3c6 | ||
|
|
aa478cd222 | ||
|
|
c78c121159 | ||
|
|
e71e506883 | ||
|
|
a601ac0cab | ||
|
|
9b92753e0a | ||
|
|
ec0018df79 | ||
|
|
8b19c523cf | ||
|
|
5ace61f9b9 | ||
|
|
8a74f5911c | ||
|
|
4982430a29 | ||
|
|
dea79c6dea | ||
|
|
ad03858c6e | ||
|
|
54b26c7991 | ||
|
|
17c3a3eb4b | ||
|
|
5f413a38df | ||
|
|
8860d0ff51 | ||
|
|
8bd471fa3c | ||
|
|
cd6ac51aa6 | ||
|
|
10caa1a1fb | ||
|
|
722e0068ca | ||
|
|
8f2eea8819 | ||
|
|
3b2d65fa16 | ||
|
|
3dc36b704a | ||
|
|
37a20e125c | ||
|
|
2910faf963 | ||
|
|
321e10fffb | ||
|
|
1acb8c3c42 | ||
|
|
f667dd223f | ||
|
|
e0d90f69ec | ||
|
|
d82187bee2 | ||
|
|
3c20e1f037 | ||
|
|
15bedc74d4 | ||
|
|
4bd6ffa9e4 | ||
|
|
9c2c918760 | ||
|
|
47d20699d8 | ||
|
|
e8ce70dccb | ||
|
|
fa4938f29c | ||
|
|
ddb4bb1421 | ||
|
|
ca94e9038e | ||
|
|
2c72a77a25 | ||
|
|
8c0e06e645 | ||
|
|
a24ae727a7 | ||
|
|
5058a8b96a | ||
|
|
762ecab3aa | ||
|
|
9ba5b7c1d4 | ||
|
|
5f807b6e47 | ||
|
|
718f950071 | ||
|
|
68fe16a092 | ||
|
|
97a64db5e0 | ||
|
|
86577b772b | ||
|
|
306df7554e | ||
|
|
30c2c0f050 | ||
|
|
205649cac2 | ||
|
|
fd49b72e31 | ||
|
|
995904993d | ||
|
|
17cbba85fc | ||
|
|
9d7d45338f | ||
|
|
3b55d3f158 | ||
|
|
fda2293d6b | ||
|
|
da814c62bc | ||
|
|
d4095b1b3b | ||
|
|
ed41154338 | ||
|
|
38bca5f0f0 | ||
|
|
a8738b533a | ||
|
|
29cf96c703 | ||
|
|
782dc3d046 | ||
|
|
0ae217f51d | ||
|
|
adcb2e03e8 | ||
|
|
11b6c1d4b5 | ||
|
|
367cb1789d | ||
|
|
adf1484ecc | ||
|
|
5401ff6c78 | ||
|
|
eb8d0eefd5 | ||
|
|
c934e22cee | ||
|
|
1a3effc692 | ||
|
|
32c942d154 | ||
|
|
9c5dc0ed29 | ||
|
|
290972cedf | ||
|
|
dc9d370952 | ||
|
|
a41be61f99 | ||
|
|
3d1783ddae | ||
|
|
8151c8e409 | ||
|
|
0ef42f93ff | ||
|
|
d318ab4e70 | ||
|
|
ebfa35c2c7 | ||
|
|
db50b0fe23 | ||
|
|
233a69a1d8 | ||
|
|
3749b7b776 | ||
|
|
ed63e7ea75 | ||
|
|
31d68622c8 | ||
|
|
ee5f45c979 | ||
|
|
3d79b11f92 | ||
|
|
dfe4e49110 | ||
|
|
12784a71e2 | ||
|
|
e0b36c9c3d | ||
|
|
c5c56f9d05 | ||
|
|
9f0129cab8 | ||
|
|
5a48e50355 | ||
|
|
86283b1815 | ||
|
|
a38d964f62 | ||
|
|
114d48b076 | ||
|
|
6e9d517c26 | ||
|
|
3b2e97e77c | ||
|
|
159924dcc0 | ||
|
|
5d8f284757 | ||
|
|
c978a95463 | ||
|
|
fe4caf7a41 | ||
|
|
4bf85abf30 | ||
|
|
49cee90b4d | ||
|
|
394f6b58d8 | ||
|
|
dbdea95241 | ||
|
|
1928c955d9 | ||
|
|
a91a13b46b | ||
|
|
2f86d5ebaf | ||
|
|
b589d6e3ef | ||
|
|
db8b265e80 | ||
|
|
8560b38ffa | ||
|
|
049a78c667 | ||
|
|
574a37814c | ||
|
|
94eb17db0c | ||
|
|
9577c8e27f | ||
|
|
c72bdd776e | ||
|
|
d35def4bbc | ||
|
|
d5f209366a | ||
|
|
9062e80e9d | ||
|
|
fd3760cedc | ||
|
|
9b73331ee9 | ||
|
|
65ca931e83 | ||
|
|
6cb71eb11b | ||
|
|
43251193ee | ||
|
|
55de98fb46 | ||
|
|
1422d43c35 | ||
|
|
6273ef8ba2 | ||
|
|
3c6f09a898 | ||
|
|
24fcb0c24b | ||
|
|
3162873a9c | ||
|
|
03e2b6a265 | ||
|
|
ee22cf7ca1 | ||
|
|
187f507532 | ||
|
|
6000bd3a5e | ||
|
|
87069da3dd | ||
|
|
5cb4077576 | ||
|
|
e9c7e0b9dd | ||
|
|
35aa7612bb | ||
|
|
acaa841822 | ||
|
|
46c1c9b5ee | ||
|
|
4bdbca64b2 | ||
|
|
3da6b4709c | ||
|
|
11fe8ab6db | ||
|
|
a9ce43d244 | ||
|
|
091bce9350 | ||
|
|
32ccce3040 | ||
|
|
ab3fcb3ea0 | ||
|
|
9610672615 | ||
|
|
5ee9630624 | ||
|
|
1b3836eb1c | ||
|
|
1302a046e9 | ||
|
|
33dec3c220 | ||
|
|
7c29c3a944 | ||
|
|
c9ca1fc7a0 | ||
|
|
a965c8de9f | ||
|
|
0b4b271e3d | ||
|
|
5fc6dd1a4d | ||
|
|
79ef026b93 | ||
|
|
a4ab5b0b49 | ||
|
|
310282b7c9 | ||
|
|
af667c718e | ||
|
|
950f5b1691 | ||
|
|
f54a3f8619 | ||
|
|
cbc0d848ad | ||
|
|
f4d13d1f6f | ||
|
|
6808ad6f5d | ||
|
|
7a8920ee38 | ||
|
|
4870506f6e | ||
|
|
6f47f9d67c | ||
|
|
8093f67173 | ||
|
|
72884f37c3 | ||
|
|
8edb3fcd5f | ||
|
|
b0efc647f1 | ||
|
|
fdd102df52 | ||
|
|
73d28838c0 | ||
|
|
03a893dc74 | ||
|
|
56de2512ae | ||
|
|
cdc2311045 | ||
|
|
c6c12209e8 | ||
|
|
eec27c3406 | ||
|
|
2ac6f96806 | ||
|
|
0bd3103949 | ||
|
|
098a22aa95 | ||
|
|
9a819d6ca0 | ||
|
|
b4bf541eec | ||
|
|
7ede3d2b9e | ||
|
|
e7160fe3c3 | ||
|
|
9d61665014 | ||
|
|
d2938ad7c8 | ||
|
|
9e0e063f8a | ||
|
|
46f7ff07f7 | ||
|
|
8ace258fbc | ||
|
|
4359fb1746 | ||
|
|
a34f294ba8 | ||
|
|
cd7d080b7a | ||
|
|
b0936b6ef4 | ||
|
|
8fae74f93e | ||
|
|
fca48e4b66 | ||
|
|
dd816c5a0a | ||
|
|
3b2ea37428 | ||
|
|
8a805b6ba1 | ||
|
|
3cc89cb4d2 | ||
|
|
9b45c5a1cd | ||
|
|
3cba3a5ac0 | ||
|
|
4b024c5787 | ||
|
|
4a42de4f18 | ||
|
|
d00e5d23ef | ||
|
|
2c9ce116a2 | ||
|
|
3512352c32 | ||
|
|
4d9372c52f | ||
|
|
1d288b08b6 | ||
|
|
f3c7c11772 | ||
|
|
4b9fe805e9 | ||
|
|
a7051e4e42 | ||
|
|
34794223b4 | ||
|
|
96cf617ee6 | ||
|
|
69dddf34b9 | ||
|
|
8f4597f742 | ||
|
|
98347cb1c3 | ||
|
|
c7ab3d4075 | ||
|
|
cddd72876f | ||
|
|
62f936128d | ||
|
|
bb80e53021 | ||
|
|
952891d1b6 | ||
|
|
6dfad6a44b | ||
|
|
e4c5bfdd5c | ||
|
|
da8563733b | ||
|
|
e41faeb557 | ||
|
|
9a55eb56ea | ||
|
|
9206ab5dc3 | ||
|
|
7e39550fc0 | ||
|
|
96e79301f3 | ||
|
|
c3f5fbd300 | ||
|
|
1db713fec1 | ||
|
|
68ba73bee0 | ||
|
|
cdacf280e1 | ||
|
|
1538a02e18 | ||
|
|
f9cec9a102 | ||
|
|
adda3d8f42 | ||
|
|
ec3ff0da12 | ||
|
|
73c38b3b0d | ||
|
|
edc8050b36 | ||
|
|
37815a982a | ||
|
|
bd8af25294 | ||
|
|
3207183f05 | ||
|
|
e803f993b7 | ||
|
|
5dbc87caf0 | ||
|
|
4862ccc947 | ||
|
|
e1ecf66485 | ||
|
|
2c71ba0744 | ||
|
|
a7aeb779e9 | ||
|
|
e72cfbf447 | ||
|
|
0c04a376c4 | ||
|
|
3c6dc4c448 | ||
|
|
b0fc2f6ecf | ||
|
|
715a1b9cd6 | ||
|
|
81969bbea9 | ||
|
|
86310849eb | ||
|
|
a2a928e262 | ||
|
|
ffc9e229b6 | ||
|
|
3813e00ca3 | ||
|
|
5698aa6499 | ||
|
|
1f5908dc51 | ||
|
|
72884c3ead | ||
|
|
80358cf5bd | ||
|
|
a15af1df5e | ||
|
|
6d511f01a4 | ||
|
|
da9e378ab1 | ||
|
|
6d3d7c6006 | ||
|
|
8024bbd721 | ||
|
|
ece9382a4e | ||
|
|
6ba517a4c1 | ||
|
|
20fd5adb24 | ||
|
|
abb350ff5b | ||
|
|
dc8d4d49f5 | ||
|
|
54352cb1cb | ||
|
|
7e106c6add | ||
|
|
0ae49b356a | ||
|
|
32374444ba | ||
|
|
287bfeb924 | ||
|
|
81c38c7200 | ||
|
|
3bb3d8c5c1 | ||
|
|
b57a2bfec9 | ||
|
|
93968d267d | ||
|
|
d27fb5f199 | ||
|
|
a51f4122f0 | ||
|
|
35ba5fc894 | ||
|
|
228d901253 | ||
|
|
d37ba62343 | ||
|
|
699fb0aa4b | ||
|
|
613d4b7c8b | ||
|
|
4f9d06d8c7 | ||
|
|
5149e4364a | ||
|
|
6b29e1f598 | ||
|
|
6c9edbb7a2 | ||
|
|
282d0f1ebb | ||
|
|
f466cbadec | ||
|
|
189a468ad4 | ||
|
|
a3414c2673 | ||
|
|
5126163c5d | ||
|
|
46ee98639e | ||
|
|
cc6c0d535c | ||
|
|
78b57e73d5 | ||
|
|
9e2a6526d1 | ||
|
|
d3c7253981 | ||
|
|
e3147b6b45 | ||
|
|
d50b059a17 | ||
|
|
cc5ec78156 | ||
|
|
ddc44ce0d1 | ||
|
|
5cbb91f352 | ||
|
|
91ea2eff4c | ||
|
|
bf85d71674 | ||
|
|
426e90eebf | ||
|
|
3889646d6b | ||
|
|
0178aaee2b | ||
|
|
53f60f7c87 | ||
|
|
2da71acefd | ||
|
|
45f5896b76 | ||
|
|
531a3bb7e6 | ||
|
|
1b28d929e4 | ||
|
|
e8943618dc | ||
|
|
1ae2f6f449 | ||
|
|
88e26b42f5 | ||
|
|
03d1aff6c0 | ||
|
|
e4459b6256 | ||
|
|
2be817a6a1 | ||
|
|
a833bb892b | ||
|
|
7f3f6c339f | ||
|
|
0d562699a2 | ||
|
|
034056d0cd | ||
|
|
1249fb598b | ||
|
|
5a8b8478d2 | ||
|
|
6c54699c44 | ||
|
|
266022b193 | ||
|
|
94a6da6b7d | ||
|
|
885fae1534 | ||
|
|
1df2ce513a | ||
|
|
1e4679ae14 | ||
|
|
267dd59a59 | ||
|
|
0a91ac5af5 | ||
|
|
ad93ad6018 | ||
|
|
0c700094ea | ||
|
|
20631a157b | ||
|
|
bdda84dfde | ||
|
|
e44f95a882 | ||
|
|
31cd45f8b5 | ||
|
|
74f9f6ad3b | ||
|
|
1dfdb51e61 | ||
|
|
18832dc19d | ||
|
|
3dee0666cb | ||
|
|
f830f6a57a | ||
|
|
82c733c68c | ||
|
|
ed510409c4 | ||
|
|
7614eba4bf | ||
|
|
13c8032465 | ||
|
|
44fc08cd5b | ||
|
|
7631b11c55 | ||
|
|
726b5f62bb | ||
|
|
ddd84db510 | ||
|
|
966241b4cc | ||
|
|
9371a8993f | ||
|
|
410c99de54 | ||
|
|
817f93a490 | ||
|
|
43611792ac | ||
|
|
62231708d7 | ||
|
|
a5dcab4092 | ||
|
|
8bde2e5f4c | ||
|
|
5287c57ee0 | ||
|
|
fbe479c43f |
13
.github/FUNDING.yml
vendored
Normal file
13
.github/FUNDING.yml
vendored
Normal file
@@ -0,0 +1,13 @@
|
||||
# These are supported funding model platforms
|
||||
|
||||
github: # Replace with up to 4 GitHub Sponsors-enabled usernames e.g., [user1, user2]
|
||||
patreon: # Replace with a single Patreon username
|
||||
open_collective: # Replace with a single Open Collective username
|
||||
ko_fi: # Replace with a single Ko-fi username
|
||||
tidelift: # Replace with a single Tidelift platform-name/package-name e.g., npm/babel
|
||||
community_bridge: # Replace with a single Community Bridge project-name e.g., cloud-foundry
|
||||
liberapay: # Replace with a single Liberapay username
|
||||
issuehunt: # Replace with a single IssueHunt username
|
||||
otechie: # Replace with a single Otechie username
|
||||
custom: ['https://www.amazon.com/hz/wishlist/ls/8WPVFLQQDPTA']
|
||||
# Replace with up to 4 custom sponsorship URLs e.g., ['link1', 'link2']
|
||||
@@ -23,10 +23,19 @@ namespace Activity {
|
||||
*/
|
||||
class Observer {
|
||||
public:
|
||||
/// Provides hints as to the sort of information presented on an LED.
|
||||
enum LEDPresentation: uint8_t {
|
||||
/// This LED informs the user of some sort of persistent state, e.g. scroll lock.
|
||||
/// If this flag is absent then the LED describes an ephemeral state, such as media access.
|
||||
Persistent = (1 << 0),
|
||||
};
|
||||
|
||||
/// Announces to the receiver that there is an LED of name @c name.
|
||||
virtual void register_led([[maybe_unused]] const std::string &name) {}
|
||||
virtual void register_led([[maybe_unused]] const std::string &name, [[maybe_unused]] uint8_t presentation = 0) {}
|
||||
|
||||
/// Announces to the receiver that there is a drive of name @c name.
|
||||
///
|
||||
/// If a drive has the same name as an LED, that LED goes with this drive.
|
||||
virtual void register_drive([[maybe_unused]] const std::string &name) {}
|
||||
|
||||
/// Informs the receiver of the new state of the LED with name @c name.
|
||||
|
||||
@@ -14,16 +14,20 @@ namespace Analyser {
|
||||
enum class Machine {
|
||||
AmstradCPC,
|
||||
AppleII,
|
||||
AppleIIgs,
|
||||
Atari2600,
|
||||
AtariST,
|
||||
Amiga,
|
||||
ColecoVision,
|
||||
Electron,
|
||||
Enterprise,
|
||||
Macintosh,
|
||||
MasterSystem,
|
||||
MSX,
|
||||
Oric,
|
||||
Vic20,
|
||||
ZX8081
|
||||
ZX8081,
|
||||
ZXSpectrum,
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
@@ -50,7 +50,10 @@ std::unique_ptr<Catalogue> Analyser::Static::Acorn::GetDFSCatalogue(const std::s
|
||||
new_file.name = name;
|
||||
new_file.load_address = uint32_t(details->samples[0][file_offset] | (details->samples[0][file_offset+1] << 8) | ((details->samples[0][file_offset+6]&0x0c) << 14));
|
||||
new_file.execution_address = uint32_t(details->samples[0][file_offset+2] | (details->samples[0][file_offset+3] << 8) | ((details->samples[0][file_offset+6]&0xc0) << 10));
|
||||
new_file.is_protected = names->samples[0][file_offset + 7] & 0x80;
|
||||
if(names->samples[0][file_offset + 7] & 0x80) {
|
||||
// File is locked; it may not be altered or deleted.
|
||||
new_file.flags |= File::Flags::Locked;
|
||||
}
|
||||
|
||||
long data_length = long(details->samples[0][file_offset+4] | (details->samples[0][file_offset+5] << 8) | ((details->samples[0][file_offset+6]&0x30) << 12));
|
||||
int start_sector = details->samples[0][file_offset+7] | ((details->samples[0][file_offset+6]&0x03) << 8);
|
||||
@@ -69,11 +72,16 @@ std::unique_ptr<Catalogue> Analyser::Static::Acorn::GetDFSCatalogue(const std::s
|
||||
new_file.data.insert(new_file.data.end(), next_sector->samples[0].begin(), next_sector->samples[0].begin() + length_from_sector);
|
||||
data_length -= length_from_sector;
|
||||
}
|
||||
if(!data_length) catalogue->files.push_back(new_file);
|
||||
if(!data_length) catalogue->files.push_back(std::move(new_file));
|
||||
}
|
||||
|
||||
return catalogue;
|
||||
}
|
||||
|
||||
/*
|
||||
Primary resource used: "Acorn 8-Bit ADFS Filesystem Structure";
|
||||
http://mdfs.net/Docs/Comp/Disk/Format/ADFS
|
||||
*/
|
||||
std::unique_ptr<Catalogue> Analyser::Static::Acorn::GetADFSCatalogue(const std::shared_ptr<Storage::Disk::Disk> &disk) {
|
||||
auto catalogue = std::make_unique<Catalogue>();
|
||||
Storage::Encodings::MFM::Parser parser(true, disk);
|
||||
@@ -101,5 +109,73 @@ std::unique_ptr<Catalogue> Analyser::Static::Acorn::GetADFSCatalogue(const std::
|
||||
case 3: catalogue->bootOption = Catalogue::BootOption::ExecBOOT; break;
|
||||
}
|
||||
|
||||
// Parse the root directory, at least.
|
||||
for(std::size_t file_offset = 0x005; file_offset < 0x4cb; file_offset += 0x1a) {
|
||||
// Obtain the name, which will be at most ten characters long, and will
|
||||
// be terminated by either a NULL character or a \r.
|
||||
char name[11];
|
||||
std::size_t c = 0;
|
||||
for(; c < 10; c++) {
|
||||
const char next = root_directory[file_offset + c] & 0x7f;
|
||||
name[c] = next;
|
||||
if(next == '\0' || next == '\r') break;
|
||||
}
|
||||
name[c] = '\0';
|
||||
|
||||
// Skip if the name is empty.
|
||||
if(name[0] == '\0') continue;
|
||||
|
||||
// Populate a file then.
|
||||
File new_file;
|
||||
new_file.name = name;
|
||||
new_file.flags =
|
||||
(root_directory[file_offset + 0] & 0x80 ? File::Flags::Readable : 0) |
|
||||
(root_directory[file_offset + 1] & 0x80 ? File::Flags::Writable : 0) |
|
||||
(root_directory[file_offset + 2] & 0x80 ? File::Flags::Locked : 0) |
|
||||
(root_directory[file_offset + 3] & 0x80 ? File::Flags::IsDirectory : 0) |
|
||||
(root_directory[file_offset + 4] & 0x80 ? File::Flags::ExecuteOnly : 0) |
|
||||
(root_directory[file_offset + 5] & 0x80 ? File::Flags::PubliclyReadable : 0) |
|
||||
(root_directory[file_offset + 6] & 0x80 ? File::Flags::PubliclyWritable : 0) |
|
||||
(root_directory[file_offset + 7] & 0x80 ? File::Flags::PubliclyExecuteOnly : 0) |
|
||||
(root_directory[file_offset + 8] & 0x80 ? File::Flags::IsPrivate : 0);
|
||||
|
||||
new_file.load_address =
|
||||
(uint32_t(root_directory[file_offset + 0x0a]) << 0) |
|
||||
(uint32_t(root_directory[file_offset + 0x0b]) << 8) |
|
||||
(uint32_t(root_directory[file_offset + 0x0c]) << 16) |
|
||||
(uint32_t(root_directory[file_offset + 0x0d]) << 24);
|
||||
|
||||
new_file.execution_address =
|
||||
(uint32_t(root_directory[file_offset + 0x0e]) << 0) |
|
||||
(uint32_t(root_directory[file_offset + 0x0f]) << 8) |
|
||||
(uint32_t(root_directory[file_offset + 0x10]) << 16) |
|
||||
(uint32_t(root_directory[file_offset + 0x11]) << 24);
|
||||
|
||||
new_file.sequence_number = root_directory[file_offset + 0x19];
|
||||
|
||||
const uint32_t size =
|
||||
(uint32_t(root_directory[file_offset + 0x12]) << 0) |
|
||||
(uint32_t(root_directory[file_offset + 0x13]) << 8) |
|
||||
(uint32_t(root_directory[file_offset + 0x14]) << 16) |
|
||||
(uint32_t(root_directory[file_offset + 0x15]) << 24);
|
||||
|
||||
uint32_t start_sector =
|
||||
(uint32_t(root_directory[file_offset + 0x16]) << 0) |
|
||||
(uint32_t(root_directory[file_offset + 0x17]) << 8) |
|
||||
(uint32_t(root_directory[file_offset + 0x18]) << 16);
|
||||
|
||||
new_file.data.reserve(size);
|
||||
while(new_file.data.size() < size) {
|
||||
const Storage::Encodings::MFM::Sector *const sector = parser.get_sector(start_sector / (80 * 16), (start_sector / 16) % 80, start_sector % 16);
|
||||
if(!sector) break;
|
||||
|
||||
const auto length_from_sector = std::min(size - new_file.data.size(), sector->samples[0].size());
|
||||
new_file.data.insert(new_file.data.end(), sector->samples[0].begin(), sector->samples[0].begin() + ssize_t(length_from_sector));
|
||||
++start_sector;
|
||||
}
|
||||
|
||||
catalogue->files.push_back(std::move(new_file));
|
||||
}
|
||||
|
||||
return catalogue;
|
||||
}
|
||||
|
||||
@@ -19,19 +19,38 @@ namespace Acorn {
|
||||
|
||||
struct File {
|
||||
std::string name;
|
||||
uint32_t load_address;
|
||||
uint32_t execution_address;
|
||||
bool is_protected;
|
||||
uint32_t load_address = 0;
|
||||
uint32_t execution_address = 0;
|
||||
|
||||
enum Flags: uint16_t {
|
||||
Readable = 1 << 0,
|
||||
Writable = 1 << 1,
|
||||
Locked = 1 << 2,
|
||||
IsDirectory = 1 << 3,
|
||||
ExecuteOnly = 1 << 4,
|
||||
PubliclyReadable = 1 << 5,
|
||||
PubliclyWritable = 1 << 6,
|
||||
PubliclyExecuteOnly = 1 << 7,
|
||||
IsPrivate = 1 << 8,
|
||||
};
|
||||
uint16_t flags = Flags::Readable | Flags::Readable | Flags::PubliclyReadable | Flags::PubliclyWritable;
|
||||
uint8_t sequence_number = 0;
|
||||
|
||||
std::vector<uint8_t> data;
|
||||
|
||||
/// Describes a single chunk of file data; these relate to the tape and ROM filing system.
|
||||
/// The File-level fields contain a 'definitive' version of the load and execution addresses,
|
||||
/// but both of those filing systems also store them per chunk.
|
||||
///
|
||||
/// Similarly, the file-level data will contain the aggregate data of all chunks.
|
||||
struct Chunk {
|
||||
std::string name;
|
||||
uint32_t load_address;
|
||||
uint32_t execution_address;
|
||||
uint16_t block_number;
|
||||
uint16_t block_length;
|
||||
uint8_t block_flag;
|
||||
uint32_t next_address;
|
||||
uint32_t load_address = 0;
|
||||
uint32_t execution_address = 0;
|
||||
uint16_t block_number = 0;
|
||||
uint16_t block_length = 0;
|
||||
uint32_t next_address = 0;
|
||||
uint8_t block_flag = 0;
|
||||
|
||||
bool header_crc_matched;
|
||||
bool data_crc_matched;
|
||||
|
||||
@@ -12,6 +12,8 @@
|
||||
#include "Tape.hpp"
|
||||
#include "Target.hpp"
|
||||
|
||||
#include <algorithm>
|
||||
|
||||
using namespace Analyser::Static::Acorn;
|
||||
|
||||
static std::vector<std::shared_ptr<Storage::Cartridge::Cartridge>>
|
||||
@@ -59,10 +61,6 @@ static std::vector<std::shared_ptr<Storage::Cartridge::Cartridge>>
|
||||
|
||||
Analyser::Static::TargetList Analyser::Static::Acorn::GetTargets(const Media &media, const std::string &, TargetPlatform::IntType) {
|
||||
auto target = std::make_unique<Target>();
|
||||
target->confidence = 0.5; // TODO: a proper estimation
|
||||
target->has_dfs = false;
|
||||
target->has_adfs = false;
|
||||
target->should_shift_restart = false;
|
||||
|
||||
// strip out inappropriate cartridges
|
||||
target->media.cartridges = AcornCartridgesFrom(media.cartridges);
|
||||
@@ -77,8 +75,8 @@ Analyser::Static::TargetList Analyser::Static::Acorn::GetTargets(const Media &me
|
||||
if(!files.empty()) {
|
||||
bool is_basic = true;
|
||||
|
||||
// protected files are always for *RUNning only
|
||||
if(files.front().is_protected) is_basic = false;
|
||||
// If a file is execute-only, that means *RUN.
|
||||
if(files.front().flags & File::Flags::ExecuteOnly) is_basic = false;
|
||||
|
||||
// check also for a continuous threading of BASIC lines; if none then this probably isn't BASIC code,
|
||||
// so that's also justification to *RUN
|
||||
@@ -108,15 +106,60 @@ Analyser::Static::TargetList Analyser::Static::Acorn::GetTargets(const Media &me
|
||||
dfs_catalogue = GetDFSCatalogue(disk);
|
||||
if(dfs_catalogue == nullptr) adfs_catalogue = GetADFSCatalogue(disk);
|
||||
if(dfs_catalogue || adfs_catalogue) {
|
||||
// Accept the disk and determine whether DFS or ADFS ROMs are implied.
|
||||
// Use the Pres ADFS if using an ADFS, as it leaves Page at &EOO.
|
||||
target->media.disks = media.disks;
|
||||
target->has_dfs = !!dfs_catalogue;
|
||||
target->has_adfs = !!adfs_catalogue;
|
||||
target->has_dfs = bool(dfs_catalogue);
|
||||
target->has_pres_adfs = bool(adfs_catalogue);
|
||||
|
||||
// Check whether a simple shift+break will do for loading this disk.
|
||||
Catalogue::BootOption bootOption = (dfs_catalogue ?: adfs_catalogue)->bootOption;
|
||||
if(bootOption != Catalogue::BootOption::None)
|
||||
if(bootOption != Catalogue::BootOption::None) {
|
||||
target->should_shift_restart = true;
|
||||
else
|
||||
} else {
|
||||
target->loading_command = "*CAT\n";
|
||||
}
|
||||
|
||||
// Check whether adding the AP6 ROM is justified.
|
||||
// For now this is an incredibly dense text search;
|
||||
// if any of the commands that aren't usually present
|
||||
// on a stock Electron are here, add the AP6 ROM and
|
||||
// some sideways RAM such that the SR commands are useful.
|
||||
for(const auto &file: dfs_catalogue ? dfs_catalogue->files : adfs_catalogue->files) {
|
||||
for(const auto &command: {
|
||||
"AQRPAGE", "BUILD", "DUMP", "FORMAT", "INSERT", "LANG", "LIST", "LOADROM",
|
||||
"LOCK", "LROMS", "RLOAD", "ROMS", "RSAVE", "SAVEROM", "SRLOAD", "SRPAGE",
|
||||
"SRUNLOCK", "SRWIPE", "TUBE", "TYPE", "UNLOCK", "UNPLUG", "UROMS",
|
||||
"VERIFY", "ZERO"
|
||||
}) {
|
||||
if(std::search(file.data.begin(), file.data.end(), command, command+strlen(command)) != file.data.end()) {
|
||||
target->has_ap6_rom = true;
|
||||
target->has_sideways_ram = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Enable the Acorn ADFS if a mass-storage device is attached;
|
||||
// unlike the Pres ADFS it retains SCSI logic.
|
||||
if(!media.mass_storage_devices.empty()) {
|
||||
target->has_pres_adfs = false; // To override a floppy selection, if one was made.
|
||||
target->has_acorn_adfs = true;
|
||||
|
||||
// Assume some sort of later-era Acorn work is likely to happen;
|
||||
// so ensure *TYPE, etc are present.
|
||||
target->has_ap6_rom = true;
|
||||
target->has_sideways_ram = true;
|
||||
|
||||
target->media.mass_storage_devices = media.mass_storage_devices;
|
||||
|
||||
// Check for a boot option.
|
||||
const auto sector = target->media.mass_storage_devices.front()->get_block(1);
|
||||
if(sector[0xfd]) {
|
||||
target->should_shift_restart = true;
|
||||
} else {
|
||||
target->loading_command = "*CAT\n";
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -109,7 +109,12 @@ static std::unique_ptr<File> GetNextFile(std::deque<File::Chunk> &chunks) {
|
||||
file->name = file->chunks.front().name;
|
||||
file->load_address = file->chunks.front().load_address;
|
||||
file->execution_address = file->chunks.front().execution_address;
|
||||
file->is_protected = !!(file->chunks.back().block_flag & 0x01); // I think the last flags are the ones that count; TODO: check.
|
||||
// I think the final chunk's flags are the ones that count; TODO: check.
|
||||
if(file->chunks.back().block_flag & 0x01) {
|
||||
// File is locked, which in more generalised terms means it is
|
||||
// for execution only.
|
||||
file->flags |= File::Flags::ExecuteOnly;
|
||||
}
|
||||
|
||||
// copy all data into a single big block
|
||||
for(File::Chunk chunk : file->chunks) {
|
||||
|
||||
@@ -18,15 +18,21 @@ namespace Static {
|
||||
namespace Acorn {
|
||||
|
||||
struct Target: public ::Analyser::Static::Target, public Reflection::StructImpl<Target> {
|
||||
bool has_adfs = false;
|
||||
bool has_acorn_adfs = false;
|
||||
bool has_pres_adfs = false;
|
||||
bool has_dfs = false;
|
||||
bool has_ap6_rom = false;
|
||||
bool has_sideways_ram = false;
|
||||
bool should_shift_restart = false;
|
||||
std::string loading_command;
|
||||
|
||||
Target() : Analyser::Static::Target(Machine::Electron) {
|
||||
if(needs_declare()) {
|
||||
DeclareField(has_adfs);
|
||||
DeclareField(has_pres_adfs);
|
||||
DeclareField(has_acorn_adfs);
|
||||
DeclareField(has_dfs);
|
||||
DeclareField(has_ap6_rom);
|
||||
DeclareField(has_sideways_ram);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
25
Analyser/Static/Amiga/StaticAnalyser.cpp
Normal file
25
Analyser/Static/Amiga/StaticAnalyser.cpp
Normal file
@@ -0,0 +1,25 @@
|
||||
//
|
||||
// StaticAnalyser.cpp
|
||||
// Clock Signal
|
||||
//
|
||||
// Created by Thomas Harte on 16/07/2021.
|
||||
// Copyright © 2021 Thomas Harte. All rights reserved.
|
||||
//
|
||||
|
||||
#include "StaticAnalyser.hpp"
|
||||
#include "Target.hpp"
|
||||
|
||||
Analyser::Static::TargetList Analyser::Static::Amiga::GetTargets(const Media &media, const std::string &, TargetPlatform::IntType) {
|
||||
// This analyser can comprehend disks and mass-storage devices only.
|
||||
if(media.disks.empty()) return {};
|
||||
|
||||
// As there is at least one usable media image, wave it through.
|
||||
Analyser::Static::TargetList targets;
|
||||
|
||||
using Target = Analyser::Static::Amiga::Target;
|
||||
auto *const target = new Target();
|
||||
target->media = media;
|
||||
targets.push_back(std::unique_ptr<Analyser::Static::Target>(target));
|
||||
|
||||
return targets;
|
||||
}
|
||||
27
Analyser/Static/Amiga/StaticAnalyser.hpp
Normal file
27
Analyser/Static/Amiga/StaticAnalyser.hpp
Normal file
@@ -0,0 +1,27 @@
|
||||
//
|
||||
// StaticAnalyser.hpp
|
||||
// Clock Signal
|
||||
//
|
||||
// Created by Thomas Harte on 16/07/2021.
|
||||
// Copyright © 2021 Thomas Harte. All rights reserved.
|
||||
//
|
||||
|
||||
#ifndef Analyser_Static_Amiga_StaticAnalyser_hpp
|
||||
#define Analyser_Static_Amiga_StaticAnalyser_hpp
|
||||
|
||||
#include "../StaticAnalyser.hpp"
|
||||
#include "../../../Storage/TargetPlatforms.hpp"
|
||||
#include <string>
|
||||
|
||||
namespace Analyser {
|
||||
namespace Static {
|
||||
namespace Amiga {
|
||||
|
||||
TargetList GetTargets(const Media &media, const std::string &file_name, TargetPlatform::IntType potential_platforms);
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
#endif /* Analyser_Static_Amiga_StaticAnalyser_hpp */
|
||||
27
Analyser/Static/Amiga/Target.hpp
Normal file
27
Analyser/Static/Amiga/Target.hpp
Normal file
@@ -0,0 +1,27 @@
|
||||
//
|
||||
// Target.hpp
|
||||
// Clock Signal
|
||||
//
|
||||
// Created by Thomas Harte on 16/07/2021.
|
||||
// Copyright © 2021 Thomas Harte. All rights reserved.
|
||||
//
|
||||
|
||||
#ifndef Analyser_Static_Amiga_Target_h
|
||||
#define Analyser_Static_Amiga_Target_h
|
||||
|
||||
#include "../../../Reflection/Struct.hpp"
|
||||
#include "../StaticAnalyser.hpp"
|
||||
|
||||
namespace Analyser {
|
||||
namespace Static {
|
||||
namespace Amiga {
|
||||
|
||||
struct Target: public Analyser::Static::Target, public Reflection::StructImpl<Target> {
|
||||
Target() : Analyser::Static::Target(Machine::Amiga) {}
|
||||
};
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endif /* Analyser_Static_Amiga_Target_h */
|
||||
@@ -11,12 +11,15 @@
|
||||
#include <algorithm>
|
||||
#include <cstring>
|
||||
|
||||
#include "Target.hpp"
|
||||
|
||||
#include "../../../Storage/Disk/Parsers/CPM.hpp"
|
||||
#include "../../../Storage/Disk/Encodings/MFM/Parser.hpp"
|
||||
#include "../../../Storage/Tape/Parsers/Spectrum.hpp"
|
||||
|
||||
static bool strcmp_insensitive(const char *a, const char *b) {
|
||||
#include "Target.hpp"
|
||||
|
||||
namespace {
|
||||
|
||||
bool strcmp_insensitive(const char *a, const char *b) {
|
||||
if(std::strlen(a) != std::strlen(b)) return false;
|
||||
while(*a) {
|
||||
if(std::tolower(*a) != std::tolower(*b)) return false;
|
||||
@@ -26,20 +29,20 @@ static bool strcmp_insensitive(const char *a, const char *b) {
|
||||
return true;
|
||||
}
|
||||
|
||||
static bool is_implied_extension(const std::string &extension) {
|
||||
bool is_implied_extension(const std::string &extension) {
|
||||
return
|
||||
extension == " " ||
|
||||
strcmp_insensitive(extension.c_str(), "BAS") ||
|
||||
strcmp_insensitive(extension.c_str(), "BIN");
|
||||
}
|
||||
|
||||
static void right_trim(std::string &string) {
|
||||
void right_trim(std::string &string) {
|
||||
string.erase(std::find_if(string.rbegin(), string.rend(), [](int ch) {
|
||||
return !std::isspace(ch);
|
||||
}).base(), string.end());
|
||||
}
|
||||
|
||||
static std::string RunCommandFor(const Storage::Disk::CPM::File &file) {
|
||||
std::string RunCommandFor(const Storage::Disk::CPM::File &file) {
|
||||
// Trim spaces from the name.
|
||||
std::string name = file.name;
|
||||
right_trim(name);
|
||||
@@ -58,7 +61,7 @@ static std::string RunCommandFor(const Storage::Disk::CPM::File &file) {
|
||||
return command + "\n";
|
||||
}
|
||||
|
||||
static void InspectCatalogue(
|
||||
void InspectCatalogue(
|
||||
const Storage::Disk::CPM::Catalogue &catalogue,
|
||||
const std::unique_ptr<Analyser::Static::AmstradCPC::Target> &target) {
|
||||
|
||||
@@ -155,7 +158,7 @@ static void InspectCatalogue(
|
||||
target->loading_command = "cat\n";
|
||||
}
|
||||
|
||||
static bool CheckBootSector(const std::shared_ptr<Storage::Disk::Disk> &disk, const std::unique_ptr<Analyser::Static::AmstradCPC::Target> &target) {
|
||||
bool CheckBootSector(const std::shared_ptr<Storage::Disk::Disk> &disk, const std::unique_ptr<Analyser::Static::AmstradCPC::Target> &target) {
|
||||
Storage::Encodings::MFM::Parser parser(true, disk);
|
||||
Storage::Encodings::MFM::Sector *boot_sector = parser.get_sector(0, 0, 0x41);
|
||||
if(boot_sector != nullptr && !boot_sector->samples.empty() && boot_sector->samples[0].size() == 512) {
|
||||
@@ -179,6 +182,28 @@ static bool CheckBootSector(const std::shared_ptr<Storage::Disk::Disk> &disk, co
|
||||
return false;
|
||||
}
|
||||
|
||||
bool IsAmstradTape(const std::shared_ptr<Storage::Tape::Tape> &tape) {
|
||||
// Limited sophistication here; look for a CPC-style file header, that is
|
||||
// any Spectrum-esque block with a synchronisation character of 0x2c.
|
||||
//
|
||||
// More could be done here: parse the header, look for 0x16 data records.
|
||||
using Parser = Storage::Tape::ZXSpectrum::Parser;
|
||||
Parser parser(Parser::MachineType::AmstradCPC);
|
||||
|
||||
while(true) {
|
||||
const auto block = parser.find_block(tape);
|
||||
if(!block) break;
|
||||
|
||||
if(block->type == 0x2c) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
Analyser::Static::TargetList Analyser::Static::AmstradCPC::GetTargets(const Media &media, const std::string &, TargetPlatform::IntType) {
|
||||
TargetList destination;
|
||||
auto target = std::make_unique<Target>();
|
||||
@@ -187,13 +212,19 @@ Analyser::Static::TargetList Analyser::Static::AmstradCPC::GetTargets(const Medi
|
||||
target->model = Target::Model::CPC6128;
|
||||
|
||||
if(!media.tapes.empty()) {
|
||||
// TODO: which of these are actually potentially CPC tapes?
|
||||
target->media.tapes = media.tapes;
|
||||
bool has_cpc_tape = false;
|
||||
for(auto &tape: media.tapes) {
|
||||
has_cpc_tape |= IsAmstradTape(tape);
|
||||
}
|
||||
|
||||
// Ugliness flows here: assume the CPC isn't smart enough to pause between pressing
|
||||
// enter and responding to the follow-on prompt to press a key, so just type for
|
||||
// a while. Yuck!
|
||||
target->loading_command = "|tape\nrun\"\n1234567890";
|
||||
if(has_cpc_tape) {
|
||||
target->media.tapes = media.tapes;
|
||||
|
||||
// Ugliness flows here: assume the CPC isn't smart enough to pause between pressing
|
||||
// enter and responding to the follow-on prompt to press a key, so just type for
|
||||
// a while. Yuck!
|
||||
target->loading_command = "|tape\nrun\"\n123";
|
||||
}
|
||||
}
|
||||
|
||||
if(!media.disks.empty()) {
|
||||
|
||||
@@ -6,8 +6,8 @@
|
||||
// Copyright 2018 Thomas Harte. All rights reserved.
|
||||
//
|
||||
|
||||
#ifndef Target_h
|
||||
#define Target_h
|
||||
#ifndef Analyser_Static_AppleII_Target_h
|
||||
#define Analyser_Static_AppleII_Target_h
|
||||
|
||||
#include "../../../Reflection/Enum.hpp"
|
||||
#include "../../../Reflection/Struct.hpp"
|
||||
@@ -47,4 +47,4 @@ struct Target: public Analyser::Static::Target, public Reflection::StructImpl<Ta
|
||||
}
|
||||
}
|
||||
|
||||
#endif /* Target_h */
|
||||
#endif /* Analyser_Static_AppleII_Target_h */
|
||||
|
||||
19
Analyser/Static/AppleIIgs/StaticAnalyser.cpp
Normal file
19
Analyser/Static/AppleIIgs/StaticAnalyser.cpp
Normal file
@@ -0,0 +1,19 @@
|
||||
//
|
||||
// StaticAnalyser.cpp
|
||||
// Clock Signal
|
||||
//
|
||||
// Created by Thomas Harte on 20/10/2020.
|
||||
// Copyright 2018 Thomas Harte. All rights reserved.
|
||||
//
|
||||
|
||||
#include "StaticAnalyser.hpp"
|
||||
#include "Target.hpp"
|
||||
|
||||
Analyser::Static::TargetList Analyser::Static::AppleIIgs::GetTargets(const Media &media, const std::string &, TargetPlatform::IntType) {
|
||||
auto target = std::make_unique<Target>();
|
||||
target->media = media;
|
||||
|
||||
TargetList targets;
|
||||
targets.push_back(std::move(target));
|
||||
return targets;
|
||||
}
|
||||
26
Analyser/Static/AppleIIgs/StaticAnalyser.hpp
Normal file
26
Analyser/Static/AppleIIgs/StaticAnalyser.hpp
Normal file
@@ -0,0 +1,26 @@
|
||||
//
|
||||
// StaticAnalyser.hpp
|
||||
// Clock Signal
|
||||
//
|
||||
// Created by Thomas Harte on 20/10/2020.
|
||||
// Copyright 2018 Thomas Harte. All rights reserved.
|
||||
//
|
||||
|
||||
#ifndef Analyser_Static_AppleIIgs_StaticAnalyser_hpp
|
||||
#define Analyser_Static_AppleIIgs_StaticAnalyser_hpp
|
||||
|
||||
#include "../StaticAnalyser.hpp"
|
||||
#include "../../../Storage/TargetPlatforms.hpp"
|
||||
#include <string>
|
||||
|
||||
namespace Analyser {
|
||||
namespace Static {
|
||||
namespace AppleIIgs {
|
||||
|
||||
TargetList GetTargets(const Media &media, const std::string &file_name, TargetPlatform::IntType potential_platforms);
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endif /* Analyser_Static_AppleIIgs_StaticAnalyser_hpp */
|
||||
49
Analyser/Static/AppleIIgs/Target.hpp
Normal file
49
Analyser/Static/AppleIIgs/Target.hpp
Normal file
@@ -0,0 +1,49 @@
|
||||
//
|
||||
// Target.hpp
|
||||
// Clock Signal
|
||||
//
|
||||
// Created by Thomas Harte on 20/10/2020.
|
||||
// Copyright 2018 Thomas Harte. All rights reserved.
|
||||
//
|
||||
|
||||
#ifndef Analyser_Static_AppleIIgs_Target_h
|
||||
#define Analyser_Static_AppleIIgs_Target_h
|
||||
|
||||
#include "../../../Reflection/Enum.hpp"
|
||||
#include "../../../Reflection/Struct.hpp"
|
||||
#include "../StaticAnalyser.hpp"
|
||||
|
||||
namespace Analyser {
|
||||
namespace Static {
|
||||
namespace AppleIIgs {
|
||||
|
||||
struct Target: public Analyser::Static::Target, public Reflection::StructImpl<Target> {
|
||||
ReflectableEnum(Model,
|
||||
ROM00,
|
||||
ROM01,
|
||||
ROM03
|
||||
);
|
||||
ReflectableEnum(MemoryModel,
|
||||
TwoHundredAndFiftySixKB,
|
||||
OneMB,
|
||||
EightMB
|
||||
);
|
||||
|
||||
Model model = Model::ROM01;
|
||||
MemoryModel memory_model = MemoryModel::EightMB;
|
||||
|
||||
Target() : Analyser::Static::Target(Machine::AppleIIgs) {
|
||||
if(needs_declare()) {
|
||||
DeclareField(model);
|
||||
DeclareField(memory_model);
|
||||
AnnounceEnum(Model);
|
||||
AnnounceEnum(MemoryModel);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endif /* Analyser_Static_AppleIIgs_Target_h */
|
||||
@@ -9,6 +9,7 @@
|
||||
#include "StaticAnalyser.hpp"
|
||||
|
||||
#include "../AppleII/Target.hpp"
|
||||
#include "../AppleIIgs/Target.hpp"
|
||||
#include "../Oric/Target.hpp"
|
||||
#include "../Disassembler/6502.hpp"
|
||||
#include "../Disassembler/AddressMapper.hpp"
|
||||
@@ -18,7 +19,7 @@
|
||||
|
||||
namespace {
|
||||
|
||||
Analyser::Static::Target *AppleTarget(const Storage::Encodings::AppleGCR::Sector *sector_zero) {
|
||||
Analyser::Static::Target *AppleIITarget(const Storage::Encodings::AppleGCR::Sector *sector_zero) {
|
||||
using Target = Analyser::Static::AppleII::Target;
|
||||
auto *const target = new Target;
|
||||
|
||||
@@ -31,6 +32,10 @@ Analyser::Static::Target *AppleTarget(const Storage::Encodings::AppleGCR::Sector
|
||||
return target;
|
||||
}
|
||||
|
||||
Analyser::Static::Target *AppleIIgsTarget() {
|
||||
return new Analyser::Static::AppleIIgs::Target();
|
||||
}
|
||||
|
||||
Analyser::Static::Target *OricTarget(const Storage::Encodings::AppleGCR::Sector *) {
|
||||
using Target = Analyser::Static::Oric::Target;
|
||||
auto *const target = new Target;
|
||||
@@ -46,8 +51,18 @@ Analyser::Static::TargetList Analyser::Static::DiskII::GetTargets(const Media &m
|
||||
// This analyser can comprehend disks only.
|
||||
if(media.disks.empty()) return {};
|
||||
|
||||
auto &disk = media.disks.front();
|
||||
TargetList targets;
|
||||
|
||||
// If the disk image is too large for a 5.25" disk, map this to the IIgs.
|
||||
if(disk->get_maximum_head_position() > Storage::Disk::HeadPosition(40)) {
|
||||
targets.push_back(std::unique_ptr<Analyser::Static::Target>(AppleIIgsTarget()));
|
||||
targets.back()->media = media;
|
||||
return targets;
|
||||
}
|
||||
|
||||
// Grab track 0, sector 0: the boot sector.
|
||||
const auto track_zero = media.disks.front()->get_track_at_position(Storage::Disk::Track::Address(0, Storage::Disk::HeadPosition(0)));
|
||||
const auto track_zero = disk->get_track_at_position(Storage::Disk::Track::Address(0, Storage::Disk::HeadPosition(0)));
|
||||
const auto sector_map = Storage::Encodings::AppleGCR::sectors_from_segment(
|
||||
Storage::Disk::track_serialisation(*track_zero, Storage::Time(1, 50000)));
|
||||
|
||||
@@ -61,12 +76,11 @@ Analyser::Static::TargetList Analyser::Static::DiskII::GetTargets(const Media &m
|
||||
|
||||
// If there's no boot sector then if there are also no sectors at all,
|
||||
// decline to nominate a machine. Otherwise go with an Apple as the default.
|
||||
TargetList targets;
|
||||
if(!sector_zero) {
|
||||
if(sector_map.empty()) {
|
||||
return targets;
|
||||
} else {
|
||||
targets.push_back(std::unique_ptr<Analyser::Static::Target>(AppleTarget(nullptr)));
|
||||
targets.push_back(std::unique_ptr<Analyser::Static::Target>(AppleIITarget(nullptr)));
|
||||
targets.back()->media = media;
|
||||
return targets;
|
||||
}
|
||||
@@ -116,7 +130,7 @@ Analyser::Static::TargetList Analyser::Static::DiskII::GetTargets(const Media &m
|
||||
if(is_oric) {
|
||||
targets.push_back(std::unique_ptr<Analyser::Static::Target>(OricTarget(sector_zero)));
|
||||
} else {
|
||||
targets.push_back(std::unique_ptr<Analyser::Static::Target>(AppleTarget(sector_zero)));
|
||||
targets.push_back(std::unique_ptr<Analyser::Static::Target>(AppleIITarget(sector_zero)));
|
||||
}
|
||||
targets.back()->media = media;
|
||||
return targets;
|
||||
|
||||
84
Analyser/Static/Enterprise/StaticAnalyser.cpp
Normal file
84
Analyser/Static/Enterprise/StaticAnalyser.cpp
Normal file
@@ -0,0 +1,84 @@
|
||||
//
|
||||
// StaticAnalyser.cpp
|
||||
// Clock Signal
|
||||
//
|
||||
// Created by Thomas Harte on 24/06/2021.
|
||||
// Copyright 2021 Thomas Harte. All rights reserved.
|
||||
//
|
||||
|
||||
#include "StaticAnalyser.hpp"
|
||||
#include "Target.hpp"
|
||||
|
||||
#include "../../../Storage/Disk/Parsers/FAT.hpp"
|
||||
|
||||
#include <algorithm>
|
||||
|
||||
namespace {
|
||||
|
||||
bool insensitive_equal(const std::string &lhs, const std::string &rhs) {
|
||||
return std::equal(
|
||||
lhs.begin(), lhs.end(),
|
||||
rhs.begin(), rhs.end(),
|
||||
[] (char l, char r) {
|
||||
return tolower(l) == tolower(r);
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Analyser::Static::TargetList Analyser::Static::Enterprise::GetTargets(const Media &media, const std::string &, TargetPlatform::IntType) {
|
||||
// This analyser can comprehend disks only.
|
||||
if(media.disks.empty()) return {};
|
||||
|
||||
// Otherwise, assume a return will happen.
|
||||
Analyser::Static::TargetList targets;
|
||||
using Target = Analyser::Static::Enterprise::Target;
|
||||
auto *const target = new Target;
|
||||
target->media = media;
|
||||
|
||||
// Always require a BASIC.
|
||||
target->basic_version = Target::BASICVersion::Any;
|
||||
|
||||
// Inspect any supplied disks.
|
||||
if(!media.disks.empty()) {
|
||||
// DOS will be needed.
|
||||
target->dos = Target::DOS::EXDOS;
|
||||
|
||||
// Grab the volume information, which includes the root directory.
|
||||
auto volume = Storage::Disk::FAT::GetVolume(media.disks.front());
|
||||
if(volume) {
|
||||
// If there's an EXDOS.INI then this disk should be able to boot itself.
|
||||
// If not but if there's only one visible .COM or .BAS, automatically load
|
||||
// that. Otherwise, issue a :DIR.
|
||||
using File = Storage::Disk::FAT::File;
|
||||
const File *selected_file = nullptr;
|
||||
bool has_exdos_ini = false;
|
||||
bool did_pick_file = false;
|
||||
for(const auto &file: (*volume).root_directory) {
|
||||
if(insensitive_equal(file.name, "exdos") && insensitive_equal(file.extension, "ini")) {
|
||||
has_exdos_ini = true;
|
||||
break;
|
||||
}
|
||||
|
||||
if(!(file.attributes & File::Attribute::Hidden) &&
|
||||
(insensitive_equal(file.extension, "com") || insensitive_equal(file.extension, "bas"))
|
||||
) {
|
||||
did_pick_file = !selected_file;
|
||||
selected_file = &file;
|
||||
}
|
||||
}
|
||||
|
||||
if(!has_exdos_ini) {
|
||||
if(did_pick_file) {
|
||||
target->loading_command = std::string("run \"") + selected_file->name + "." + selected_file->extension + "\"\n";
|
||||
} else {
|
||||
target->loading_command = ":dir\n";
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
targets.push_back(std::unique_ptr<Analyser::Static::Target>(target));
|
||||
|
||||
return targets;
|
||||
}
|
||||
27
Analyser/Static/Enterprise/StaticAnalyser.hpp
Normal file
27
Analyser/Static/Enterprise/StaticAnalyser.hpp
Normal file
@@ -0,0 +1,27 @@
|
||||
//
|
||||
// StaticAnalyser.hpp
|
||||
// Clock Signal
|
||||
//
|
||||
// Created by Thomas Harte on 24/06/2021.
|
||||
// Copyright 2018 Thomas Harte. All rights reserved.
|
||||
//
|
||||
|
||||
#ifndef Analyser_Static_Enterprise_StaticAnalyser_hpp
|
||||
#define Analyser_Static_Enterprise_StaticAnalyser_hpp
|
||||
|
||||
#include "../StaticAnalyser.hpp"
|
||||
#include "../../../Storage/TargetPlatforms.hpp"
|
||||
#include <string>
|
||||
|
||||
namespace Analyser {
|
||||
namespace Static {
|
||||
namespace Enterprise {
|
||||
|
||||
TargetList GetTargets(const Media &media, const std::string &file_name, TargetPlatform::IntType potential_platforms);
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
#endif /* Analyser_Static_Enterprise_StaticAnalyser_hpp */
|
||||
57
Analyser/Static/Enterprise/Target.hpp
Normal file
57
Analyser/Static/Enterprise/Target.hpp
Normal file
@@ -0,0 +1,57 @@
|
||||
//
|
||||
// Target.hpp
|
||||
// Clock Signal
|
||||
//
|
||||
// Created by Thomas Harte on 14/06/2021.
|
||||
// Copyright © 2021 Thomas Harte. All rights reserved.
|
||||
//
|
||||
|
||||
#ifndef Analyser_Static_Enterprise_Target_h
|
||||
#define Analyser_Static_Enterprise_Target_h
|
||||
|
||||
#include "../../../Reflection/Enum.hpp"
|
||||
#include "../../../Reflection/Struct.hpp"
|
||||
#include "../StaticAnalyser.hpp"
|
||||
|
||||
#include <string>
|
||||
|
||||
namespace Analyser {
|
||||
namespace Static {
|
||||
namespace Enterprise {
|
||||
|
||||
struct Target: public Analyser::Static::Target, public Reflection::StructImpl<Target> {
|
||||
ReflectableEnum(Model, Enterprise64, Enterprise128, Enterprise256);
|
||||
ReflectableEnum(EXOSVersion, v10, v20, v21, v23, Any);
|
||||
ReflectableEnum(BASICVersion, v10, v11, v21, Any, None);
|
||||
ReflectableEnum(DOS, EXDOS, None);
|
||||
ReflectableEnum(Speed, FourMHz, SixMHz);
|
||||
|
||||
Model model = Model::Enterprise128;
|
||||
EXOSVersion exos_version = EXOSVersion::Any;
|
||||
BASICVersion basic_version = BASICVersion::None;
|
||||
DOS dos = DOS::None;
|
||||
Speed speed = Speed::FourMHz;
|
||||
std::string loading_command;
|
||||
|
||||
Target() : Analyser::Static::Target(Machine::Enterprise) {
|
||||
if(needs_declare()) {
|
||||
AnnounceEnum(Model);
|
||||
AnnounceEnum(EXOSVersion);
|
||||
AnnounceEnum(BASICVersion);
|
||||
AnnounceEnum(DOS);
|
||||
AnnounceEnum(Speed);
|
||||
|
||||
DeclareField(model);
|
||||
DeclareField(exos_version);
|
||||
DeclareField(basic_version);
|
||||
DeclareField(dos);
|
||||
DeclareField(speed);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endif /* Analyser_Static_Enterprise_Target_h */
|
||||
@@ -19,6 +19,19 @@ Analyser::Static::TargetList Analyser::Static::Macintosh::GetTargets(const Media
|
||||
using Target = Analyser::Static::Macintosh::Target;
|
||||
auto *const target = new Target;
|
||||
target->media = media;
|
||||
|
||||
// If this is a single-sided floppy disk, guess the Macintosh 512kb.
|
||||
if(media.mass_storage_devices.empty()) {
|
||||
bool has_800kb_disks = false;
|
||||
for(const auto &disk: media.disks) {
|
||||
has_800kb_disks |= disk->get_head_count() > 1;
|
||||
}
|
||||
|
||||
if(!has_800kb_disks) {
|
||||
target->model = Target::Model::Mac512k;
|
||||
}
|
||||
}
|
||||
|
||||
targets.push_back(std::unique_ptr<Analyser::Static::Target>(target));
|
||||
|
||||
return targets;
|
||||
|
||||
@@ -15,34 +15,40 @@
|
||||
|
||||
// Analysers
|
||||
#include "Acorn/StaticAnalyser.hpp"
|
||||
#include "Amiga/StaticAnalyser.hpp"
|
||||
#include "AmstradCPC/StaticAnalyser.hpp"
|
||||
#include "AppleII/StaticAnalyser.hpp"
|
||||
#include "AppleIIgs/StaticAnalyser.hpp"
|
||||
#include "Atari2600/StaticAnalyser.hpp"
|
||||
#include "AtariST/StaticAnalyser.hpp"
|
||||
#include "Coleco/StaticAnalyser.hpp"
|
||||
#include "Commodore/StaticAnalyser.hpp"
|
||||
#include "DiskII/StaticAnalyser.hpp"
|
||||
#include "Enterprise/StaticAnalyser.hpp"
|
||||
#include "Macintosh/StaticAnalyser.hpp"
|
||||
#include "MSX/StaticAnalyser.hpp"
|
||||
#include "Oric/StaticAnalyser.hpp"
|
||||
#include "Sega/StaticAnalyser.hpp"
|
||||
#include "ZX8081/StaticAnalyser.hpp"
|
||||
#include "ZXSpectrum/StaticAnalyser.hpp"
|
||||
|
||||
// Cartridges
|
||||
#include "../../Storage/Cartridge/Formats/BinaryDump.hpp"
|
||||
#include "../../Storage/Cartridge/Formats/PRG.hpp"
|
||||
|
||||
// Disks
|
||||
#include "../../Storage/Disk/DiskImage/Formats/2MG.hpp"
|
||||
#include "../../Storage/Disk/DiskImage/Formats/AcornADF.hpp"
|
||||
#include "../../Storage/Disk/DiskImage/Formats/AmigaADF.hpp"
|
||||
#include "../../Storage/Disk/DiskImage/Formats/AppleDSK.hpp"
|
||||
#include "../../Storage/Disk/DiskImage/Formats/CPCDSK.hpp"
|
||||
#include "../../Storage/Disk/DiskImage/Formats/D64.hpp"
|
||||
#include "../../Storage/Disk/DiskImage/Formats/MacintoshIMG.hpp"
|
||||
#include "../../Storage/Disk/DiskImage/Formats/G64.hpp"
|
||||
#include "../../Storage/Disk/DiskImage/Formats/DMK.hpp"
|
||||
#include "../../Storage/Disk/DiskImage/Formats/FAT12.hpp"
|
||||
#include "../../Storage/Disk/DiskImage/Formats/HFE.hpp"
|
||||
#include "../../Storage/Disk/DiskImage/Formats/MSA.hpp"
|
||||
#include "../../Storage/Disk/DiskImage/Formats/MSXDSK.hpp"
|
||||
#include "../../Storage/Disk/DiskImage/Formats/NIB.hpp"
|
||||
#include "../../Storage/Disk/DiskImage/Formats/OricMFMDSK.hpp"
|
||||
#include "../../Storage/Disk/DiskImage/Formats/SSD.hpp"
|
||||
@@ -51,8 +57,15 @@
|
||||
#include "../../Storage/Disk/DiskImage/Formats/WOZ.hpp"
|
||||
|
||||
// Mass Storage Devices (i.e. usually, hard disks)
|
||||
#include "../../Storage/MassStorage/Formats/DAT.hpp"
|
||||
#include "../../Storage/MassStorage/Formats/DSK.hpp"
|
||||
#include "../../Storage/MassStorage/Formats/HFV.hpp"
|
||||
|
||||
// State Snapshots
|
||||
#include "../../Storage/State/SNA.hpp"
|
||||
#include "../../Storage/State/SZX.hpp"
|
||||
#include "../../Storage/State/Z80.hpp"
|
||||
|
||||
// Tapes
|
||||
#include "../../Storage/Tape/Formats/CAS.hpp"
|
||||
#include "../../Storage/Tape/Formats/CommodoreTAP.hpp"
|
||||
@@ -62,83 +75,114 @@
|
||||
#include "../../Storage/Tape/Formats/TapeUEF.hpp"
|
||||
#include "../../Storage/Tape/Formats/TZX.hpp"
|
||||
#include "../../Storage/Tape/Formats/ZX80O81P.hpp"
|
||||
#include "../../Storage/Tape/Formats/ZXSpectrumTAP.hpp"
|
||||
|
||||
// Target Platform Types
|
||||
#include "../../Storage/TargetPlatforms.hpp"
|
||||
|
||||
using namespace Analyser::Static;
|
||||
|
||||
static Media GetMediaAndPlatforms(const std::string &file_name, TargetPlatform::IntType &potential_platforms) {
|
||||
Media result;
|
||||
namespace {
|
||||
|
||||
std::string get_extension(const std::string &name) {
|
||||
// Get the extension, if any; it will be assumed that extensions are reliable, so an extension is a broad-phase
|
||||
// test as to file format.
|
||||
std::string::size_type final_dot = file_name.find_last_of(".");
|
||||
if(final_dot == std::string::npos) return result;
|
||||
std::string extension = file_name.substr(final_dot + 1);
|
||||
std::string::size_type final_dot = name.find_last_of(".");
|
||||
if(final_dot == std::string::npos) return name;
|
||||
std::string extension = name.substr(final_dot + 1);
|
||||
std::transform(extension.begin(), extension.end(), extension.begin(), ::tolower);
|
||||
return extension;
|
||||
}
|
||||
|
||||
#define Insert(list, class, platforms) \
|
||||
list.emplace_back(new Storage::class(file_name));\
|
||||
}
|
||||
|
||||
static Media GetMediaAndPlatforms(const std::string &file_name, TargetPlatform::IntType &potential_platforms) {
|
||||
Media result;
|
||||
const std::string extension = get_extension(file_name);
|
||||
|
||||
#define InsertInstance(list, instance, platforms) \
|
||||
list.emplace_back(instance);\
|
||||
potential_platforms |= platforms;\
|
||||
TargetPlatform::TypeDistinguisher *distinguisher = dynamic_cast<TargetPlatform::TypeDistinguisher *>(list.back().get());\
|
||||
if(distinguisher) potential_platforms &= distinguisher->target_platform_type();
|
||||
if(distinguisher) potential_platforms &= distinguisher->target_platform_type(); \
|
||||
|
||||
#define TryInsert(list, class, platforms) \
|
||||
#define Insert(list, class, platforms, ...) \
|
||||
InsertInstance(list, new Storage::class(__VA_ARGS__), platforms);
|
||||
|
||||
#define TryInsert(list, class, platforms, ...) \
|
||||
try {\
|
||||
Insert(list, class, platforms) \
|
||||
Insert(list, class, platforms, __VA_ARGS__) \
|
||||
} catch(...) {}
|
||||
|
||||
#define Format(ext, list, class, platforms) \
|
||||
if(extension == ext) { \
|
||||
TryInsert(list, class, platforms) \
|
||||
TryInsert(list, class, platforms, file_name) \
|
||||
}
|
||||
|
||||
// 2MG
|
||||
if(extension == "2mg") {
|
||||
// 2MG uses a factory method; defer to it.
|
||||
try {
|
||||
InsertInstance(result.disks, Storage::Disk::Disk2MG::open(file_name), TargetPlatform::DiskII)
|
||||
} catch(...) {}
|
||||
}
|
||||
|
||||
Format("80", result.tapes, Tape::ZX80O81P, TargetPlatform::ZX8081) // 80
|
||||
Format("81", result.tapes, Tape::ZX80O81P, TargetPlatform::ZX8081) // 81
|
||||
Format("a26", result.cartridges, Cartridge::BinaryDump, TargetPlatform::Atari2600) // A26
|
||||
Format("adf", result.disks, Disk::DiskImageHolder<Storage::Disk::AcornADF>, TargetPlatform::Acorn) // ADF
|
||||
Format("adf", result.disks, Disk::DiskImageHolder<Storage::Disk::AcornADF>, TargetPlatform::Acorn) // ADF (Acorn)
|
||||
Format("adf", result.disks, Disk::DiskImageHolder<Storage::Disk::AmigaADF>, TargetPlatform::Amiga) // ADF (Amiga)
|
||||
Format("adl", result.disks, Disk::DiskImageHolder<Storage::Disk::AcornADF>, TargetPlatform::Acorn) // ADL
|
||||
Format("bin", result.cartridges, Cartridge::BinaryDump, TargetPlatform::AllCartridge) // BIN (cartridge dump)
|
||||
Format("cas", result.tapes, Tape::CAS, TargetPlatform::MSX) // CAS
|
||||
Format("cdt", result.tapes, Tape::TZX, TargetPlatform::AmstradCPC) // CDT
|
||||
Format("col", result.cartridges, Cartridge::BinaryDump, TargetPlatform::ColecoVision) // COL
|
||||
Format("col", result.cartridges, Cartridge::BinaryDump, TargetPlatform::Coleco) // COL
|
||||
Format("csw", result.tapes, Tape::CSW, TargetPlatform::AllTape) // CSW
|
||||
Format("d64", result.disks, Disk::DiskImageHolder<Storage::Disk::D64>, TargetPlatform::Commodore) // D64
|
||||
Format("dat", result.mass_storage_devices, MassStorage::DAT, TargetPlatform::Acorn) // DAT
|
||||
Format("dmk", result.disks, Disk::DiskImageHolder<Storage::Disk::DMK>, TargetPlatform::MSX) // DMK
|
||||
Format("do", result.disks, Disk::DiskImageHolder<Storage::Disk::AppleDSK>, TargetPlatform::DiskII) // DO
|
||||
Format("dsd", result.disks, Disk::DiskImageHolder<Storage::Disk::SSD>, TargetPlatform::Acorn) // DSD
|
||||
Format( "dsk",
|
||||
result.disks,
|
||||
Disk::DiskImageHolder<Storage::Disk::CPCDSK>,
|
||||
TargetPlatform::AmstradCPC | TargetPlatform::Oric) // DSK (Amstrad CPC)
|
||||
TargetPlatform::AmstradCPC | TargetPlatform::Oric | TargetPlatform::ZXSpectrum) // DSK (Amstrad CPC, etc)
|
||||
Format("dsk", result.disks, Disk::DiskImageHolder<Storage::Disk::AppleDSK>, TargetPlatform::DiskII) // DSK (Apple II)
|
||||
Format("dsk", result.disks, Disk::DiskImageHolder<Storage::Disk::MacintoshIMG>, TargetPlatform::Macintosh) // DSK (Macintosh, floppy disk)
|
||||
Format("dsk", result.mass_storage_devices, MassStorage::HFV, TargetPlatform::Macintosh) // DSK (Macintosh, hard disk)
|
||||
Format("dsk", result.disks, Disk::DiskImageHolder<Storage::Disk::MSXDSK>, TargetPlatform::MSX) // DSK (MSX)
|
||||
Format("dsk", result.mass_storage_devices, MassStorage::HFV, TargetPlatform::Macintosh) // DSK (Macintosh, hard disk, single volume image)
|
||||
Format("dsk", result.mass_storage_devices, MassStorage::DSK, TargetPlatform::Macintosh) // DSK (Macintosh, hard disk, full device image)
|
||||
Format("dsk", result.disks, Disk::DiskImageHolder<Storage::Disk::FAT12>, TargetPlatform::MSX) // DSK (MSX)
|
||||
Format("dsk", result.disks, Disk::DiskImageHolder<Storage::Disk::OricMFMDSK>, TargetPlatform::Oric) // DSK (Oric)
|
||||
Format("g64", result.disks, Disk::DiskImageHolder<Storage::Disk::G64>, TargetPlatform::Commodore) // G64
|
||||
Format( "hfe",
|
||||
result.disks,
|
||||
Disk::DiskImageHolder<Storage::Disk::HFE>,
|
||||
TargetPlatform::Acorn | TargetPlatform::AmstradCPC | TargetPlatform::Commodore | TargetPlatform::Oric)
|
||||
TargetPlatform::Acorn | TargetPlatform::AmstradCPC | TargetPlatform::Commodore | TargetPlatform::Oric | TargetPlatform::ZXSpectrum)
|
||||
// HFE (TODO: switch to AllDisk once the MSX stops being so greedy)
|
||||
Format("img", result.disks, Disk::DiskImageHolder<Storage::Disk::MacintoshIMG>, TargetPlatform::Macintosh) // IMG (DiskCopy 4.2)
|
||||
Format("image", result.disks, Disk::DiskImageHolder<Storage::Disk::MacintoshIMG>, TargetPlatform::Macintosh) // IMG (DiskCopy 4.2)
|
||||
Format("img", result.disks, Disk::DiskImageHolder<Storage::Disk::FAT12>, TargetPlatform::Enterprise) // IMG (Enterprise/MS-DOS style)
|
||||
Format("msa", result.disks, Disk::DiskImageHolder<Storage::Disk::MSA>, TargetPlatform::AtariST) // MSA
|
||||
Format("nib", result.disks, Disk::DiskImageHolder<Storage::Disk::NIB>, TargetPlatform::DiskII) // NIB
|
||||
Format("o", result.tapes, Tape::ZX80O81P, TargetPlatform::ZX8081) // O
|
||||
Format("p", result.tapes, Tape::ZX80O81P, TargetPlatform::ZX8081) // P
|
||||
Format("po", result.disks, Disk::DiskImageHolder<Storage::Disk::AppleDSK>, TargetPlatform::DiskII) // PO
|
||||
Format("po", result.disks, Disk::DiskImageHolder<Storage::Disk::AppleDSK>, TargetPlatform::DiskII) // PO (original Apple II kind)
|
||||
|
||||
// PO (Apple IIgs kind)
|
||||
if(extension == "po") {
|
||||
TryInsert(result.disks, Disk::DiskImageHolder<Storage::Disk::MacintoshIMG>, TargetPlatform::AppleIIgs, file_name, Storage::Disk::MacintoshIMG::FixedType::GCR)
|
||||
}
|
||||
|
||||
Format("p81", result.tapes, Tape::ZX80O81P, TargetPlatform::ZX8081) // P81
|
||||
|
||||
// PRG
|
||||
if(extension == "prg") {
|
||||
// try instantiating as a ROM; failing that accept as a tape
|
||||
try {
|
||||
Insert(result.cartridges, Cartridge::PRG, TargetPlatform::Commodore)
|
||||
Insert(result.cartridges, Cartridge::PRG, TargetPlatform::Commodore, file_name)
|
||||
} catch(...) {
|
||||
try {
|
||||
Insert(result.tapes, Tape::PRG, TargetPlatform::Commodore)
|
||||
Insert(result.tapes, Tape::PRG, TargetPlatform::Commodore, file_name)
|
||||
} catch(...) {}
|
||||
}
|
||||
}
|
||||
@@ -146,7 +190,7 @@ static Media GetMediaAndPlatforms(const std::string &file_name, TargetPlatform::
|
||||
Format( "rom",
|
||||
result.cartridges,
|
||||
Cartridge::BinaryDump,
|
||||
TargetPlatform::AcornElectron | TargetPlatform::ColecoVision | TargetPlatform::MSX) // ROM
|
||||
TargetPlatform::AcornElectron | TargetPlatform::Coleco | TargetPlatform::MSX) // ROM
|
||||
Format("sg", result.cartridges, Cartridge::BinaryDump, TargetPlatform::Sega) // SG
|
||||
Format("sms", result.cartridges, Cartridge::BinaryDump, TargetPlatform::Sega) // SMS
|
||||
Format("ssd", result.disks, Disk::DiskImageHolder<Storage::Disk::SSD>, TargetPlatform::Acorn) // SSD
|
||||
@@ -154,14 +198,16 @@ static Media GetMediaAndPlatforms(const std::string &file_name, TargetPlatform::
|
||||
Format("stx", result.disks, Disk::DiskImageHolder<Storage::Disk::STX>, TargetPlatform::AtariST) // STX
|
||||
Format("tap", result.tapes, Tape::CommodoreTAP, TargetPlatform::Commodore) // TAP (Commodore)
|
||||
Format("tap", result.tapes, Tape::OricTAP, TargetPlatform::Oric) // TAP (Oric)
|
||||
Format("tap", result.tapes, Tape::ZXSpectrumTAP, TargetPlatform::ZXSpectrum) // TAP (ZX Spectrum)
|
||||
Format("tsx", result.tapes, Tape::TZX, TargetPlatform::MSX) // TSX
|
||||
Format("tzx", result.tapes, Tape::TZX, TargetPlatform::ZX8081) // TZX
|
||||
Format("tzx", result.tapes, Tape::TZX, TargetPlatform::ZX8081 | TargetPlatform::ZXSpectrum) // TZX
|
||||
Format("uef", result.tapes, Tape::UEF, TargetPlatform::Acorn) // UEF (tape)
|
||||
Format("woz", result.disks, Disk::DiskImageHolder<Storage::Disk::WOZ>, TargetPlatform::DiskII) // WOZ
|
||||
|
||||
#undef Format
|
||||
#undef Insert
|
||||
#undef TryInsert
|
||||
#undef InsertInstance
|
||||
|
||||
return result;
|
||||
}
|
||||
@@ -173,34 +219,59 @@ Media Analyser::Static::GetMedia(const std::string &file_name) {
|
||||
|
||||
TargetList Analyser::Static::GetTargets(const std::string &file_name) {
|
||||
TargetList targets;
|
||||
const std::string extension = get_extension(file_name);
|
||||
|
||||
// Check whether the file directly identifies a target; if so then just return that.
|
||||
#define Format(ext, class) \
|
||||
if(extension == ext) { \
|
||||
try { \
|
||||
auto target = Storage::State::class::load(file_name); \
|
||||
if(target) { \
|
||||
targets.push_back(std::move(target)); \
|
||||
return targets; \
|
||||
} \
|
||||
} catch(...) {} \
|
||||
}
|
||||
|
||||
Format("sna", SNA);
|
||||
Format("szx", SZX);
|
||||
Format("z80", Z80);
|
||||
|
||||
#undef TryInsert
|
||||
|
||||
// Otherwise:
|
||||
//
|
||||
// Collect all disks, tapes ROMs, etc as can be extrapolated from this file, forming the
|
||||
// union of all platforms this file might be a target for.
|
||||
TargetPlatform::IntType potential_platforms = 0;
|
||||
Media media = GetMediaAndPlatforms(file_name, potential_platforms);
|
||||
|
||||
// Hand off to platform-specific determination of whether these things are actually compatible and,
|
||||
// if so, how to load them.
|
||||
#define Append(x) {\
|
||||
auto new_targets = x::GetTargets(media, file_name, potential_platforms);\
|
||||
std::move(new_targets.begin(), new_targets.end(), std::back_inserter(targets));\
|
||||
}
|
||||
if(potential_platforms & TargetPlatform::Acorn) Append(Acorn);
|
||||
if(potential_platforms & TargetPlatform::AmstradCPC) Append(AmstradCPC);
|
||||
if(potential_platforms & TargetPlatform::AppleII) Append(AppleII);
|
||||
if(potential_platforms & TargetPlatform::Atari2600) Append(Atari2600);
|
||||
if(potential_platforms & TargetPlatform::AtariST) Append(AtariST);
|
||||
if(potential_platforms & TargetPlatform::ColecoVision) Append(Coleco);
|
||||
if(potential_platforms & TargetPlatform::Commodore) Append(Commodore);
|
||||
if(potential_platforms & TargetPlatform::DiskII) Append(DiskII);
|
||||
if(potential_platforms & TargetPlatform::Macintosh) Append(Macintosh);
|
||||
if(potential_platforms & TargetPlatform::MSX) Append(MSX);
|
||||
if(potential_platforms & TargetPlatform::Oric) Append(Oric);
|
||||
if(potential_platforms & TargetPlatform::Sega) Append(Sega);
|
||||
if(potential_platforms & TargetPlatform::ZX8081) Append(ZX8081);
|
||||
#undef Append
|
||||
// Hand off to platform-specific determination of whether these
|
||||
// things are actually compatible and, if so, how to load them.
|
||||
#define Append(x) if(potential_platforms & TargetPlatform::x) {\
|
||||
auto new_targets = x::GetTargets(media, file_name, potential_platforms);\
|
||||
std::move(new_targets.begin(), new_targets.end(), std::back_inserter(targets));\
|
||||
}
|
||||
Append(Acorn);
|
||||
Append(AmstradCPC);
|
||||
Append(AppleII);
|
||||
Append(AppleIIgs);
|
||||
Append(Amiga);
|
||||
Append(Atari2600);
|
||||
Append(AtariST);
|
||||
Append(Coleco);
|
||||
Append(Commodore);
|
||||
Append(DiskII);
|
||||
Append(Enterprise);
|
||||
Append(Macintosh);
|
||||
Append(MSX);
|
||||
Append(Oric);
|
||||
Append(Sega);
|
||||
Append(ZX8081);
|
||||
Append(ZXSpectrum);
|
||||
#undef Append
|
||||
|
||||
// Reset any tapes to their initial position
|
||||
// Reset any tapes to their initial position.
|
||||
for(const auto &target : targets) {
|
||||
for(auto &tape : target->media.tapes) {
|
||||
tape->reset();
|
||||
|
||||
@@ -15,6 +15,7 @@
|
||||
#include "../../Storage/Disk/Disk.hpp"
|
||||
#include "../../Storage/MassStorage/MassStorageDevice.hpp"
|
||||
#include "../../Storage/Tape/Tape.hpp"
|
||||
#include "../../Reflection/Struct.hpp"
|
||||
|
||||
#include <memory>
|
||||
#include <string>
|
||||
@@ -23,8 +24,10 @@
|
||||
namespace Analyser {
|
||||
namespace Static {
|
||||
|
||||
struct State;
|
||||
|
||||
/*!
|
||||
A list of disks, tapes and cartridges.
|
||||
A list of disks, tapes and cartridges, and possibly a state snapshot.
|
||||
*/
|
||||
struct Media {
|
||||
std::vector<std::shared_ptr<Storage::Disk::Disk>> disks;
|
||||
@@ -48,13 +51,16 @@ struct Media {
|
||||
};
|
||||
|
||||
/*!
|
||||
A list of disks, tapes and cartridges plus information about the machine to which to attach them and its configuration,
|
||||
and instructions on how to launch the software attached, plus a measure of confidence in this target's correctness.
|
||||
Describes a machine and possibly its state; conventionally subclassed to add other machine-specific configuration fields and any
|
||||
necessary instructions on how to launch any software provided, plus a measure of confidence in this target's correctness.
|
||||
*/
|
||||
struct Target {
|
||||
Target(Machine machine) : machine(machine) {}
|
||||
virtual ~Target() {}
|
||||
|
||||
// This field is entirely optional.
|
||||
std::unique_ptr<Reflection::Struct> state;
|
||||
|
||||
Machine machine;
|
||||
Media media;
|
||||
float confidence = 0.0f;
|
||||
|
||||
95
Analyser/Static/ZXSpectrum/StaticAnalyser.cpp
Normal file
95
Analyser/Static/ZXSpectrum/StaticAnalyser.cpp
Normal file
@@ -0,0 +1,95 @@
|
||||
//
|
||||
// StaticAnalyser.cpp
|
||||
// Clock Signal
|
||||
//
|
||||
// Created by Thomas Harte on 17/03/2021.
|
||||
// Copyright © 2021 Thomas Harte. All rights reserved.
|
||||
//
|
||||
|
||||
#include "StaticAnalyser.hpp"
|
||||
|
||||
#include "../../../Storage/Disk/Encodings/MFM/Parser.hpp"
|
||||
#include "../../../Storage/Tape/Parsers/Spectrum.hpp"
|
||||
|
||||
#include "Target.hpp"
|
||||
|
||||
namespace {
|
||||
|
||||
bool IsSpectrumTape(const std::shared_ptr<Storage::Tape::Tape> &tape) {
|
||||
using Parser = Storage::Tape::ZXSpectrum::Parser;
|
||||
Parser parser(Parser::MachineType::ZXSpectrum);
|
||||
|
||||
while(true) {
|
||||
const auto block = parser.find_block(tape);
|
||||
if(!block) break;
|
||||
|
||||
// Check for a Spectrum header block.
|
||||
if(block->type == 0x00) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
bool IsSpectrumDisk(const std::shared_ptr<Storage::Disk::Disk> &disk) {
|
||||
Storage::Encodings::MFM::Parser parser(true, disk);
|
||||
|
||||
// Get logical sector 1; the Spectrum appears to support various physical
|
||||
// sectors as sector 1.
|
||||
Storage::Encodings::MFM::Sector *boot_sector = nullptr;
|
||||
uint8_t sector_mask = 0;
|
||||
while(!boot_sector) {
|
||||
boot_sector = parser.get_sector(0, 0, sector_mask + 1);
|
||||
sector_mask += 0x40;
|
||||
if(!sector_mask) break;
|
||||
}
|
||||
if(!boot_sector) return false;
|
||||
|
||||
// Test that the contents of the boot sector sum to 3, modulo 256.
|
||||
uint8_t byte_sum = 0;
|
||||
for(auto byte: boot_sector->samples[0]) {
|
||||
byte_sum += byte;
|
||||
}
|
||||
return byte_sum == 3;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Analyser::Static::TargetList Analyser::Static::ZXSpectrum::GetTargets(const Media &media, const std::string &, TargetPlatform::IntType) {
|
||||
TargetList destination;
|
||||
auto target = std::make_unique<Target>();
|
||||
target->confidence = 0.5;
|
||||
|
||||
if(!media.tapes.empty()) {
|
||||
bool has_spectrum_tape = false;
|
||||
for(auto &tape: media.tapes) {
|
||||
has_spectrum_tape |= IsSpectrumTape(tape);
|
||||
}
|
||||
|
||||
if(has_spectrum_tape) {
|
||||
target->media.tapes = media.tapes;
|
||||
}
|
||||
}
|
||||
|
||||
if(!media.disks.empty()) {
|
||||
bool has_spectrum_disk = false;
|
||||
|
||||
for(auto &disk: media.disks) {
|
||||
has_spectrum_disk |= IsSpectrumDisk(disk);
|
||||
}
|
||||
|
||||
if(has_spectrum_disk) {
|
||||
target->media.disks = media.disks;
|
||||
target->model = Target::Model::Plus3;
|
||||
}
|
||||
}
|
||||
|
||||
// If any media survived, add the target.
|
||||
if(!target->media.empty()) {
|
||||
target->should_hold_enter = true; // To force entry into the 'loader' and thereby load the media.
|
||||
destination.push_back(std::move(target));
|
||||
}
|
||||
|
||||
return destination;
|
||||
}
|
||||
26
Analyser/Static/ZXSpectrum/StaticAnalyser.hpp
Normal file
26
Analyser/Static/ZXSpectrum/StaticAnalyser.hpp
Normal file
@@ -0,0 +1,26 @@
|
||||
//
|
||||
// StaticAnalyser.hpp
|
||||
// Clock Signal
|
||||
//
|
||||
// Created by Thomas Harte on 17/03/2021.
|
||||
// Copyright © 2021 Thomas Harte. All rights reserved.
|
||||
//
|
||||
|
||||
#ifndef Analyser_Static_ZXSpectrum_StaticAnalyser_hpp
|
||||
#define Analyser_Static_ZXSpectrum_StaticAnalyser_hpp
|
||||
|
||||
#include "../StaticAnalyser.hpp"
|
||||
#include "../../../Storage/TargetPlatforms.hpp"
|
||||
#include <string>
|
||||
|
||||
namespace Analyser {
|
||||
namespace Static {
|
||||
namespace ZXSpectrum {
|
||||
|
||||
TargetList GetTargets(const Media &media, const std::string &file_name, TargetPlatform::IntType potential_platforms);
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endif /* StaticAnalyser_hpp */
|
||||
45
Analyser/Static/ZXSpectrum/Target.hpp
Normal file
45
Analyser/Static/ZXSpectrum/Target.hpp
Normal file
@@ -0,0 +1,45 @@
|
||||
//
|
||||
// Target.hpp
|
||||
// Clock Signal
|
||||
//
|
||||
// Created by Thomas Harte on 18/03/2021.
|
||||
// Copyright © 2021 Thomas Harte. All rights reserved.
|
||||
//
|
||||
|
||||
#ifndef Analyser_Static_ZXSpectrum_Target_h
|
||||
#define Analyser_Static_ZXSpectrum_Target_h
|
||||
|
||||
#include "../../../Reflection/Enum.hpp"
|
||||
#include "../../../Reflection/Struct.hpp"
|
||||
#include "../StaticAnalyser.hpp"
|
||||
|
||||
namespace Analyser {
|
||||
namespace Static {
|
||||
namespace ZXSpectrum {
|
||||
|
||||
struct Target: public ::Analyser::Static::Target, public Reflection::StructImpl<Target> {
|
||||
ReflectableEnum(Model,
|
||||
SixteenK,
|
||||
FortyEightK,
|
||||
OneTwoEightK,
|
||||
Plus2,
|
||||
Plus2a,
|
||||
Plus3,
|
||||
);
|
||||
|
||||
Model model = Model::Plus2;
|
||||
bool should_hold_enter = false;
|
||||
|
||||
Target(): Analyser::Static::Target(Machine::ZXSpectrum) {
|
||||
if(needs_declare()) {
|
||||
DeclareField(model);
|
||||
AnnounceEnum(Model);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endif /* Target_h */
|
||||
@@ -10,7 +10,10 @@
|
||||
#define ClockReceiver_hpp
|
||||
|
||||
#include "ForceInline.hpp"
|
||||
|
||||
#include <algorithm>
|
||||
#include <cstdint>
|
||||
#include <limits>
|
||||
|
||||
/*
|
||||
Informal pattern for all classes that run from a clock cycle:
|
||||
@@ -136,8 +139,11 @@ template <class T> class WrappedInt {
|
||||
forceinline constexpr bool operator !() const { return !length_; }
|
||||
// bool operator () is not supported because it offers an implicit cast to int, which is prone silently to permit misuse
|
||||
|
||||
/// @returns The underlying int, cast to an integral type of your choosing.
|
||||
template<typename Type = IntType> forceinline constexpr Type as() const { return Type(length_); }
|
||||
/// @returns The underlying int, converted to an integral type of your choosing, clamped to that int's range.
|
||||
template<typename Type = IntType> forceinline constexpr Type as() const {
|
||||
const auto clamped = std::clamp(length_, IntType(std::numeric_limits<Type>::min()), IntType(std::numeric_limits<Type>::max()));
|
||||
return Type(clamped);
|
||||
}
|
||||
|
||||
/// @returns The underlying int, in its native form.
|
||||
forceinline constexpr IntType as_integral() const { return length_; }
|
||||
@@ -176,6 +182,9 @@ class Cycles: public WrappedInt<Cycles> {
|
||||
public:
|
||||
forceinline constexpr Cycles(IntType l) noexcept : WrappedInt<Cycles>(l) {}
|
||||
forceinline constexpr Cycles() noexcept : WrappedInt<Cycles>() {}
|
||||
forceinline static constexpr Cycles max() {
|
||||
return Cycles(std::numeric_limits<IntType>::max());
|
||||
}
|
||||
|
||||
private:
|
||||
friend WrappedInt;
|
||||
@@ -195,6 +204,9 @@ class HalfCycles: public WrappedInt<HalfCycles> {
|
||||
public:
|
||||
forceinline constexpr HalfCycles(IntType l) noexcept : WrappedInt<HalfCycles>(l) {}
|
||||
forceinline constexpr HalfCycles() noexcept : WrappedInt<HalfCycles>() {}
|
||||
forceinline static constexpr HalfCycles max() {
|
||||
return HalfCycles(std::numeric_limits<IntType>::max());
|
||||
}
|
||||
|
||||
forceinline constexpr HalfCycles(const Cycles &cycles) noexcept : WrappedInt<HalfCycles>(cycles.as_integral() * 2) {}
|
||||
|
||||
@@ -205,7 +217,7 @@ class HalfCycles: public WrappedInt<HalfCycles> {
|
||||
|
||||
/*!
|
||||
Severs from @c this the effect of dividing by @c divisor; @c this will end up with
|
||||
the value of @c this modulo @c divisor and @c divided by @c divisor is returned.
|
||||
the value of @c this modulo @c divisor . @c this divided by @c divisor is returned.
|
||||
*/
|
||||
forceinline Cycles divide_cycles(const Cycles &divisor) {
|
||||
const HalfCycles half_divisor = HalfCycles(divisor);
|
||||
@@ -214,6 +226,15 @@ class HalfCycles: public WrappedInt<HalfCycles> {
|
||||
return result;
|
||||
}
|
||||
|
||||
/*!
|
||||
Equivalent to @c divide_cycles(Cycles(1)) but faster.
|
||||
*/
|
||||
forceinline Cycles divide_cycles() {
|
||||
const Cycles result(length_ >> 1);
|
||||
length_ &= 1;
|
||||
return result;
|
||||
}
|
||||
|
||||
private:
|
||||
friend WrappedInt;
|
||||
void fill(Cycles &result) {
|
||||
|
||||
48
ClockReceiver/DeferredValue.hpp
Normal file
48
ClockReceiver/DeferredValue.hpp
Normal file
@@ -0,0 +1,48 @@
|
||||
//
|
||||
// DeferredValue.hpp
|
||||
// Clock Signal
|
||||
//
|
||||
// Created by Thomas Harte on 07/08/2021.
|
||||
// Copyright © 2021 Thomas Harte. All rights reserved.
|
||||
//
|
||||
|
||||
#ifndef DeferredValue_h
|
||||
#define DeferredValue_h
|
||||
|
||||
/*!
|
||||
Provides storage for a single deferred value: one with a current value and a certain number
|
||||
of future values.
|
||||
*/
|
||||
template <int DeferredDepth, typename ValueT> class DeferredValue {
|
||||
private:
|
||||
static_assert(sizeof(ValueT) <= 4);
|
||||
|
||||
constexpr int elements_per_uint32 = sizeof(uint32_t) / sizeof(ValueT);
|
||||
constexpr int unit_shift = sizeof(ValueT) * 8;
|
||||
constexpr int insert_shift = (DeferredDepth & (elements_per_uint32 - 1)) * unit_shift;
|
||||
constexpr uint32_t insert_mask = ~(0xffff'ffff << insert_shift);
|
||||
|
||||
std::array<uint32_t, (DeferredDepth + elements_per_uint32 - 1) / elements_per_uint32> backlog;
|
||||
|
||||
public:
|
||||
/// @returns the current value.
|
||||
ValueT value() const {
|
||||
return uint8_t(backlog[0]);
|
||||
}
|
||||
|
||||
/// Advances to the next enqueued value.
|
||||
void advance() {
|
||||
for(size_t c = 0; c < backlog.size() - 1; c--) {
|
||||
backlog[c] = (backlog[c] >> unit_shift) | (backlog[c+1] << (32 - unit_shift));
|
||||
}
|
||||
backlog[backlog.size() - 1] >>= unit_shift;
|
||||
}
|
||||
|
||||
/// Inserts a new value, replacing whatever is currently at the end of the queue.
|
||||
void insert(ValueT value) {
|
||||
backlog[DeferredDepth / elements_per_uint32] =
|
||||
(backlog[DeferredDepth / elements_per_uint32] & insert_mask) | (value << insert_shift);
|
||||
}
|
||||
};
|
||||
|
||||
#endif /* DeferredValue_h */
|
||||
@@ -9,7 +9,9 @@
|
||||
#ifndef JustInTime_h
|
||||
#define JustInTime_h
|
||||
|
||||
#include "ClockReceiver.hpp"
|
||||
#include "../Concurrency/AsyncTaskQueue.hpp"
|
||||
#include "ClockingHintSource.hpp"
|
||||
#include "ForceInline.hpp"
|
||||
|
||||
/*!
|
||||
@@ -21,44 +23,150 @@
|
||||
|
||||
Machines that accumulate HalfCycle time but supply to a Cycle-counted device may supply a
|
||||
separate @c TargetTimeScale at template declaration.
|
||||
|
||||
If the held object implements get_next_sequence_point() then it'll be used to flush implicitly
|
||||
as and when sequence points are hit. Callers can use will_flush() to predict these.
|
||||
|
||||
If the held object is a subclass of ClockingHint::Source, this template will register as an
|
||||
observer and potentially stop clocking or stop delaying clocking until just-in-time references
|
||||
as directed.
|
||||
|
||||
TODO: incorporate and codify AsyncJustInTimeActor.
|
||||
*/
|
||||
template <class T, int multiplier = 1, int divider = 1, class LocalTimeScale = HalfCycles, class TargetTimeScale = LocalTimeScale> class JustInTimeActor {
|
||||
template <class T, class LocalTimeScale = HalfCycles, int multiplier = 1, int divider = 1> class JustInTimeActor:
|
||||
public ClockingHint::Observer {
|
||||
private:
|
||||
/*!
|
||||
A std::unique_ptr deleter which causes an update_sequence_point to occur on the actor supplied
|
||||
to it at construction if it implements get_next_sequence_point(). Otherwise destruction is a no-op.
|
||||
|
||||
**Does not delete the object.**
|
||||
|
||||
This is used by the -> operators below, which provide a unique pointer to the enclosed object and
|
||||
update their sequence points upon its destruction — i.e. after the caller has made whatever call
|
||||
or calls as were relevant to the enclosed object.
|
||||
*/
|
||||
class SequencePointAwareDeleter {
|
||||
public:
|
||||
explicit SequencePointAwareDeleter(JustInTimeActor<T, LocalTimeScale, multiplier, divider> *actor) noexcept
|
||||
: actor_(actor) {}
|
||||
|
||||
forceinline void operator ()(const T *const) const {
|
||||
if constexpr (has_sequence_points<T>::value) {
|
||||
actor_->update_sequence_point();
|
||||
}
|
||||
}
|
||||
|
||||
private:
|
||||
JustInTimeActor<T, LocalTimeScale, multiplier, divider> *const actor_;
|
||||
};
|
||||
|
||||
// This block of SFINAE determines whether objects of type T accepts Cycles or HalfCycles.
|
||||
using HalfRunFor = void (T::*const)(HalfCycles);
|
||||
static uint8_t half_sig(...);
|
||||
static uint16_t half_sig(HalfRunFor);
|
||||
using TargetTimeScale =
|
||||
std::conditional_t<
|
||||
sizeof(half_sig(&T::run_for)) == sizeof(uint16_t),
|
||||
HalfCycles,
|
||||
Cycles>;
|
||||
|
||||
public:
|
||||
/// Constructs a new JustInTimeActor using the same construction arguments as the included object.
|
||||
template<typename... Args> JustInTimeActor(Args&&... args) : object_(std::forward<Args>(args)...) {}
|
||||
template<typename... Args> JustInTimeActor(Args&&... args) : object_(std::forward<Args>(args)...) {
|
||||
if constexpr (std::is_base_of<ClockingHint::Source, T>::value) {
|
||||
object_.set_clocking_hint_observer(this);
|
||||
}
|
||||
}
|
||||
|
||||
/// Adds time to the actor.
|
||||
forceinline void operator += (const LocalTimeScale &rhs) {
|
||||
///
|
||||
/// @returns @c true if adding time caused a flush; @c false otherwise.
|
||||
forceinline bool operator += (LocalTimeScale rhs) {
|
||||
if constexpr (std::is_base_of<ClockingHint::Source, T>::value) {
|
||||
if(clocking_preference_ == ClockingHint::Preference::None) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
if constexpr (multiplier != 1) {
|
||||
time_since_update_ += rhs * multiplier;
|
||||
} else {
|
||||
time_since_update_ += rhs;
|
||||
}
|
||||
is_flushed_ = false;
|
||||
|
||||
if constexpr (std::is_base_of<ClockingHint::Source, T>::value) {
|
||||
if (clocking_preference_ == ClockingHint::Preference::RealTime) {
|
||||
flush();
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
if constexpr (has_sequence_points<T>::value) {
|
||||
time_until_event_ -= rhs * multiplier;
|
||||
if(time_until_event_ <= LocalTimeScale(0)) {
|
||||
time_overrun_ = time_until_event_ / divider;
|
||||
flush();
|
||||
update_sequence_point();
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/// Flushes all accumulated time and returns a pointer to the included object.
|
||||
forceinline T *operator->() {
|
||||
///
|
||||
/// If this object provides sequence points, checks for changes to the next
|
||||
/// sequence point upon deletion of the pointer.
|
||||
[[nodiscard]] forceinline auto operator->() {
|
||||
flush();
|
||||
return &object_;
|
||||
return std::unique_ptr<T, SequencePointAwareDeleter>(&object_, SequencePointAwareDeleter(this));
|
||||
}
|
||||
|
||||
/// Acts exactly as per the standard ->, but preserves constness.
|
||||
forceinline const T *operator->() const {
|
||||
auto non_const_this = const_cast<JustInTimeActor<T, multiplier, divider, LocalTimeScale, TargetTimeScale> *>(this);
|
||||
///
|
||||
/// Despite being const, this will flush the object and, if relevant, update the next sequence point.
|
||||
[[nodiscard]] forceinline auto operator -> () const {
|
||||
auto non_const_this = const_cast<JustInTimeActor<T, LocalTimeScale, multiplier, divider> *>(this);
|
||||
non_const_this->flush();
|
||||
return std::unique_ptr<const T, SequencePointAwareDeleter>(&object_, SequencePointAwareDeleter(non_const_this));
|
||||
}
|
||||
|
||||
/// @returns a pointer to the included object, without flushing time.
|
||||
[[nodiscard]] forceinline T *last_valid() {
|
||||
return &object_;
|
||||
}
|
||||
|
||||
/// Returns a pointer to the included object without flushing time.
|
||||
forceinline T *last_valid() {
|
||||
/// @returns a const pointer to the included object, without flushing time.
|
||||
[[nodiscard]] forceinline const T *last_valid() const {
|
||||
return &object_;
|
||||
}
|
||||
|
||||
/// @returns the amount of time since the object was last flushed, in the target time scale.
|
||||
[[nodiscard]] forceinline TargetTimeScale time_since_flush() const {
|
||||
if constexpr (divider == 1) {
|
||||
return time_since_update_;
|
||||
}
|
||||
return TargetTimeScale(time_since_update_.as_integral() / divider);
|
||||
}
|
||||
|
||||
/// @returns the amount of time since the object was last flushed, plus the local time scale @c offset,
|
||||
/// converted to the target time scale.
|
||||
[[nodiscard]] forceinline TargetTimeScale time_since_flush(LocalTimeScale offset) const {
|
||||
if constexpr (divider == 1) {
|
||||
return time_since_update_ + offset;
|
||||
}
|
||||
return TargetTimeScale((time_since_update_ + offset).as_integral() / divider);
|
||||
}
|
||||
|
||||
/// Flushes all accumulated time.
|
||||
///
|
||||
/// This does not affect this actor's record of when the next sequence point will occur.
|
||||
forceinline void flush() {
|
||||
if(!is_flushed_) {
|
||||
is_flushed_ = true;
|
||||
did_flush_ = is_flushed_ = true;
|
||||
if constexpr (divider == 1) {
|
||||
const auto duration = time_since_update_.template flush<TargetTimeScale>();
|
||||
object_.run_for(duration);
|
||||
@@ -70,56 +178,96 @@ template <class T, int multiplier = 1, int divider = 1, class LocalTimeScale = H
|
||||
}
|
||||
}
|
||||
|
||||
private:
|
||||
T object_;
|
||||
LocalTimeScale time_since_update_;
|
||||
bool is_flushed_ = true;
|
||||
};
|
||||
/// Indicates whether a flush has occurred since the last call to did_flush().
|
||||
[[nodiscard]] forceinline bool did_flush() {
|
||||
const bool did_flush = did_flush_;
|
||||
did_flush_ = false;
|
||||
return did_flush;
|
||||
}
|
||||
|
||||
/*!
|
||||
A RealTimeActor presents the same interface as a JustInTimeActor but doesn't defer work.
|
||||
Time added will be performed immediately.
|
||||
/// @returns a number in the range [-max, 0] indicating the offset of the most recent sequence
|
||||
/// point from the final time at the end of the += that triggered the sequence point.
|
||||
[[nodiscard]] forceinline LocalTimeScale last_sequence_point_overrun() {
|
||||
return time_overrun_;
|
||||
}
|
||||
|
||||
Its primary purpose is to allow consumers to remain flexible in their scheduling.
|
||||
*/
|
||||
template <class T, int multiplier = 1, int divider = 1, class LocalTimeScale = HalfCycles, class TargetTimeScale = LocalTimeScale> class RealTimeActor {
|
||||
public:
|
||||
template<typename... Args> RealTimeActor(Args&&... args) : object_(std::forward<Args>(args)...) {}
|
||||
/// @returns the number of cycles until the next sequence-point-based flush, if the embedded object
|
||||
/// supports sequence points; @c LocalTimeScale() otherwise.
|
||||
[[nodiscard]] LocalTimeScale cycles_until_implicit_flush() const {
|
||||
return time_until_event_ / divider;
|
||||
}
|
||||
|
||||
forceinline void operator += (const LocalTimeScale &rhs) {
|
||||
/// Indicates whether a sequence-point-caused flush will occur if the specified period is added.
|
||||
[[nodiscard]] forceinline bool will_flush(LocalTimeScale rhs) const {
|
||||
if constexpr (!has_sequence_points<T>::value) {
|
||||
return false;
|
||||
}
|
||||
return rhs >= time_until_event_;
|
||||
}
|
||||
|
||||
/// Indicates the amount of time, in the local time scale, until the first local slot that falls wholly
|
||||
/// after @c duration, if that delay were to occur in @c offset units of time from now.
|
||||
[[nodiscard]] forceinline LocalTimeScale back_map(TargetTimeScale duration, TargetTimeScale offset) const {
|
||||
// A 1:1 mapping is easy.
|
||||
if constexpr (multiplier == 1 && divider == 1) {
|
||||
object_.run_for(TargetTimeScale(rhs));
|
||||
return;
|
||||
return duration;
|
||||
}
|
||||
|
||||
if constexpr (multiplier == 1) {
|
||||
accumulated_time_ += rhs;
|
||||
} else {
|
||||
accumulated_time_ += rhs * multiplier;
|
||||
}
|
||||
// Work out when this query is placed, and the time to which it relates
|
||||
const auto base = time_since_update_ + offset * divider;
|
||||
const auto target = base + duration * divider;
|
||||
|
||||
if constexpr (divider == 1) {
|
||||
const auto duration = accumulated_time_.template flush<TargetTimeScale>();
|
||||
object_.run_for(duration);
|
||||
} else {
|
||||
const auto duration = accumulated_time_.template divide<TargetTimeScale>(LocalTimeScale(divider));
|
||||
if(duration > TargetTimeScale(0))
|
||||
object_.run_for(duration);
|
||||
// Figure out the number of whole input steps that is required to get
|
||||
// past target, and subtract the number of whole input steps necessary
|
||||
// to get to base.
|
||||
const auto steps_to_base = base.as_integral() / multiplier;
|
||||
const auto steps_to_target = (target.as_integral() + divider - 1) / multiplier;
|
||||
|
||||
return LocalTimeScale(steps_to_target - steps_to_base);
|
||||
}
|
||||
|
||||
/// Updates this template's record of the next sequence point.
|
||||
void update_sequence_point() {
|
||||
if constexpr (has_sequence_points<T>::value) {
|
||||
// Keep a fast path where no conversions will be applied; if conversions are
|
||||
// going to be applied then do a direct max -> max translation rather than
|
||||
// allowing the arithmetic to overflow.
|
||||
if constexpr (divider == 1 && std::is_same_v<LocalTimeScale, TargetTimeScale>) {
|
||||
time_until_event_ = object_.get_next_sequence_point();
|
||||
} else {
|
||||
const auto time = object_.get_next_sequence_point();
|
||||
if(time == TargetTimeScale::max()) {
|
||||
time_until_event_ = LocalTimeScale::max();
|
||||
} else {
|
||||
time_until_event_ = time * divider;
|
||||
}
|
||||
}
|
||||
assert(time_until_event_ > LocalTimeScale(0));
|
||||
}
|
||||
}
|
||||
|
||||
forceinline T *operator->() { return &object_; }
|
||||
forceinline const T *operator->() const { return &object_; }
|
||||
forceinline T *last_valid() { return &object_; }
|
||||
forceinline void flush() {}
|
||||
/// @returns A cached copy of the object's clocking preference.
|
||||
ClockingHint::Preference clocking_preference() const {
|
||||
return clocking_preference_;
|
||||
}
|
||||
|
||||
private:
|
||||
T object_;
|
||||
LocalTimeScale accumulated_time_;
|
||||
LocalTimeScale time_since_update_, time_until_event_, time_overrun_;
|
||||
bool is_flushed_ = true;
|
||||
bool did_flush_ = false;
|
||||
|
||||
template <typename S, typename = void> struct has_sequence_points : std::false_type {};
|
||||
template <typename S> struct has_sequence_points<S, decltype(void(std::declval<S &>().get_next_sequence_point()))> : std::true_type {};
|
||||
|
||||
ClockingHint::Preference clocking_preference_ = ClockingHint::Preference::JustInTime;
|
||||
void set_component_prefers_clocking(ClockingHint::Source *, ClockingHint::Preference clocking) {
|
||||
clocking_preference_ = clocking;
|
||||
}
|
||||
};
|
||||
|
||||
/*!
|
||||
A AsyncJustInTimeActor acts like a JustInTimeActor but additionally contains an AsyncTaskQueue.
|
||||
An AsyncJustInTimeActor acts like a JustInTimeActor but additionally contains an AsyncTaskQueue.
|
||||
Any time the amount of accumulated time crosses a threshold provided at construction time,
|
||||
the object will be updated on the AsyncTaskQueue.
|
||||
*/
|
||||
|
||||
@@ -276,7 +276,10 @@ void WD1770::posit_event(int new_event_type) {
|
||||
goto test_type1_type;
|
||||
|
||||
begin_type1_spin_up:
|
||||
if((command_&0x08) || get_drive().get_motor_on()) goto test_type1_type;
|
||||
if((command_&0x08) || get_drive().get_motor_on()) {
|
||||
set_motor_on(true);
|
||||
goto test_type1_type;
|
||||
}
|
||||
SPIN_UP();
|
||||
|
||||
test_type1_type:
|
||||
@@ -387,7 +390,10 @@ void WD1770::posit_event(int new_event_type) {
|
||||
distance_into_section_ = 0;
|
||||
|
||||
if((command_&0x08) && has_motor_on_line()) goto test_type2_delay;
|
||||
if(!has_motor_on_line() && !has_head_load_line()) goto test_type2_delay;
|
||||
if(!has_motor_on_line() && !has_head_load_line()) {
|
||||
if(has_motor_on_line()) set_motor_on(true);
|
||||
goto test_type2_delay;
|
||||
}
|
||||
|
||||
if(has_motor_on_line()) goto begin_type2_spin_up;
|
||||
goto begin_type2_load_head;
|
||||
|
||||
@@ -10,8 +10,6 @@
|
||||
#define _522_hpp
|
||||
|
||||
#include <cstdint>
|
||||
#include <typeinfo>
|
||||
#include <cstdio>
|
||||
|
||||
#include "Implementation/6522Storage.hpp"
|
||||
|
||||
@@ -37,22 +35,24 @@ enum Line {
|
||||
class PortHandler {
|
||||
public:
|
||||
/// Requests the current input value of @c port from the port handler.
|
||||
uint8_t get_port_input([[maybe_unused]] Port port) { return 0xff; }
|
||||
uint8_t get_port_input([[maybe_unused]] Port port) {
|
||||
return 0xff;
|
||||
}
|
||||
|
||||
/// Sets the current output value of @c port and provides @c direction_mask, indicating which pins are marked as output.
|
||||
void set_port_output([[maybe_unused]] Port port, [[maybe_unused]] uint8_t value, [[maybe_unused]] uint8_t direction_mask) {}
|
||||
void set_port_output([[maybe_unused]] Port port, [[maybe_unused]] uint8_t value, [[maybe_unused]] uint8_t direction_mask) {}
|
||||
|
||||
/// Sets the current logical output level for line @c line on port @c port.
|
||||
void set_control_line_output([[maybe_unused]] Port port, [[maybe_unused]] Line line, [[maybe_unused]] bool value) {}
|
||||
void set_control_line_output([[maybe_unused]] Port port, [[maybe_unused]] Line line, [[maybe_unused]] bool value) {}
|
||||
|
||||
/// Sets the current logical value of the interrupt line.
|
||||
void set_interrupt_status([[maybe_unused]] bool status) {}
|
||||
void set_interrupt_status([[maybe_unused]] bool status) {}
|
||||
|
||||
/// Provides a measure of time elapsed between other calls.
|
||||
void run_for([[maybe_unused]] HalfCycles duration) {}
|
||||
void run_for([[maybe_unused]] HalfCycles duration) {}
|
||||
|
||||
/// Receives passed-on flush() calls from the 6522.
|
||||
void flush() {}
|
||||
void flush() {}
|
||||
};
|
||||
|
||||
/*!
|
||||
@@ -88,9 +88,9 @@ class IRQDelegatePortHandler: public PortHandler {
|
||||
Consumers should derive their own curiously-recurring-template-pattern subclass,
|
||||
implementing bus communications as required.
|
||||
*/
|
||||
template <class T> class MOS6522: public MOS6522Storage {
|
||||
template <class BusHandlerT> class MOS6522: public MOS6522Storage {
|
||||
public:
|
||||
MOS6522(T &bus_handler) noexcept : bus_handler_(bus_handler) {}
|
||||
MOS6522(BusHandlerT &bus_handler) noexcept : bus_handler_(bus_handler) {}
|
||||
MOS6522(const MOS6522 &) = delete;
|
||||
|
||||
/*! Sets a register value. */
|
||||
@@ -100,7 +100,7 @@ template <class T> class MOS6522: public MOS6522Storage {
|
||||
uint8_t read(int address);
|
||||
|
||||
/*! @returns the bus handler. */
|
||||
T &bus_handler();
|
||||
BusHandlerT &bus_handler();
|
||||
|
||||
/// Sets the input value of line @c line on port @c port.
|
||||
void set_control_line_input(Port port, Line line, bool value);
|
||||
@@ -123,7 +123,7 @@ template <class T> class MOS6522: public MOS6522Storage {
|
||||
void shift_in();
|
||||
void shift_out();
|
||||
|
||||
T &bus_handler_;
|
||||
BusHandlerT &bus_handler_;
|
||||
HalfCycles time_since_bus_handler_call_;
|
||||
|
||||
void access(int address);
|
||||
|
||||
94
Components/6526/6526.hpp
Normal file
94
Components/6526/6526.hpp
Normal file
@@ -0,0 +1,94 @@
|
||||
//
|
||||
// 6526.h
|
||||
// Clock Signal
|
||||
//
|
||||
// Created by Thomas Harte on 18/07/2021.
|
||||
// Copyright © 2021 Thomas Harte. All rights reserved.
|
||||
//
|
||||
|
||||
#ifndef _526_h
|
||||
#define _526_h
|
||||
|
||||
#include <cstdint>
|
||||
|
||||
#include "Implementation/6526Storage.hpp"
|
||||
#include "../Serial/Line.hpp"
|
||||
|
||||
namespace MOS {
|
||||
namespace MOS6526 {
|
||||
|
||||
enum Port {
|
||||
A = 0,
|
||||
B = 1
|
||||
};
|
||||
|
||||
struct PortHandler {
|
||||
/// Requests the current input value of @c port from the port handler.
|
||||
uint8_t get_port_input([[maybe_unused]] Port port) {
|
||||
return 0xff;
|
||||
}
|
||||
|
||||
/// Sets the current output value of @c port; any bits marked as input will be supplied as 1s.
|
||||
void set_port_output([[maybe_unused]] Port port, [[maybe_unused]] uint8_t value) {}
|
||||
};
|
||||
|
||||
enum class Personality {
|
||||
// The 6526, used in machines such as the C64, has a BCD time-of-day clock.
|
||||
P6526,
|
||||
// The 8250, used in the Amiga, provides a binary time-of-day clock.
|
||||
P8250,
|
||||
};
|
||||
|
||||
template <typename PortHandlerT, Personality personality> class MOS6526:
|
||||
private MOS6526Storage,
|
||||
private Serial::Line<true>::ReadDelegate
|
||||
{
|
||||
public:
|
||||
MOS6526(PortHandlerT &port_handler) noexcept : port_handler_(port_handler) {
|
||||
serial_input.set_read_delegate(this);
|
||||
}
|
||||
MOS6526(const MOS6526 &) = delete;
|
||||
|
||||
/// Writes @c value to the register at @c address. Only the low two bits of the address are decoded.
|
||||
void write(int address, uint8_t value);
|
||||
|
||||
/// Fetches the value of the register @c address. Only the low two bits of the address are decoded.
|
||||
uint8_t read(int address);
|
||||
|
||||
/// Pulses Phi2 to advance by the specified number of half cycles.
|
||||
void run_for(const HalfCycles half_cycles);
|
||||
|
||||
/// Pulses the TOD input the specified number of times.
|
||||
void advance_tod(int count);
|
||||
|
||||
/// @returns @c true if the interrupt output is active, @c false otherwise.
|
||||
bool get_interrupt_line();
|
||||
|
||||
/// Sets the current state of the CNT input.
|
||||
void set_cnt_input(bool active);
|
||||
|
||||
/// Provides both the serial input bit and an additional source of CNT.
|
||||
Serial::Line<true> serial_input;
|
||||
|
||||
/// Sets the current state of the FLG input.
|
||||
void set_flag_input(bool low);
|
||||
|
||||
private:
|
||||
PortHandlerT &port_handler_;
|
||||
TODStorage<personality == Personality::P8250> tod_;
|
||||
|
||||
template <int port> void set_port_output();
|
||||
template <int port> uint8_t get_port_input();
|
||||
void update_interrupts();
|
||||
void posit_interrupt(uint8_t mask);
|
||||
void advance_counters(int);
|
||||
|
||||
bool serial_line_did_produce_bit(Serial::Line<true> *line, int bit) final;
|
||||
};
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
#include "Implementation/6526Implementation.hpp"
|
||||
|
||||
#endif /* _526_h */
|
||||
244
Components/6526/Implementation/6526Implementation.hpp
Normal file
244
Components/6526/Implementation/6526Implementation.hpp
Normal file
@@ -0,0 +1,244 @@
|
||||
//
|
||||
// 6526Implementation.hpp
|
||||
// Clock Signal
|
||||
//
|
||||
// Created by Thomas Harte on 18/07/2021.
|
||||
// Copyright © 2021 Thomas Harte. All rights reserved.
|
||||
//
|
||||
|
||||
#ifndef _526Implementation_h
|
||||
#define _526Implementation_h
|
||||
|
||||
#include <cassert>
|
||||
#include <cstdio>
|
||||
|
||||
namespace MOS {
|
||||
namespace MOS6526 {
|
||||
|
||||
enum Interrupts: uint8_t {
|
||||
TimerA = 1 << 0,
|
||||
TimerB = 1 << 1,
|
||||
Alarm = 1 << 2,
|
||||
SerialPort = 1 << 3,
|
||||
Flag = 1 << 4,
|
||||
};
|
||||
|
||||
template <typename BusHandlerT, Personality personality>
|
||||
template <int port> void MOS6526<BusHandlerT, personality>::set_port_output() {
|
||||
const uint8_t output = output_[port] | (~data_direction_[port]);
|
||||
port_handler_.set_port_output(Port(port), output);
|
||||
}
|
||||
|
||||
template <typename BusHandlerT, Personality personality>
|
||||
template <int port> uint8_t MOS6526<BusHandlerT, personality>::get_port_input() {
|
||||
// Avoid bothering the port handler if there's no input active.
|
||||
const uint8_t input_mask = ~data_direction_[port];
|
||||
const uint8_t input = input_mask ? port_handler_.get_port_input(Port(port)) : 0x00;
|
||||
return (input & input_mask) | (output_[port] & data_direction_[port]);
|
||||
}
|
||||
|
||||
template <typename BusHandlerT, Personality personality>
|
||||
void MOS6526<BusHandlerT, personality>::posit_interrupt(uint8_t mask) {
|
||||
if(!mask) {
|
||||
return;
|
||||
}
|
||||
interrupt_state_ |= mask;
|
||||
update_interrupts();
|
||||
}
|
||||
|
||||
template <typename BusHandlerT, Personality personality>
|
||||
void MOS6526<BusHandlerT, personality>::update_interrupts() {
|
||||
if(interrupt_state_ & interrupt_control_) {
|
||||
pending_ |= InterruptInOne;
|
||||
}
|
||||
}
|
||||
|
||||
template <typename BusHandlerT, Personality personality>
|
||||
bool MOS6526<BusHandlerT, personality>::get_interrupt_line() {
|
||||
return interrupt_state_ & 0x80;
|
||||
}
|
||||
|
||||
template <typename BusHandlerT, Personality personality>
|
||||
void MOS6526<BusHandlerT, personality>::set_cnt_input(bool active) {
|
||||
cnt_edge_ = active && !cnt_state_;
|
||||
cnt_state_ = active;
|
||||
}
|
||||
|
||||
template <typename BusHandlerT, Personality personality>
|
||||
void MOS6526<BusHandlerT, personality>::set_flag_input(bool low) {
|
||||
if(low && !flag_state_) {
|
||||
posit_interrupt(Interrupts::Flag);
|
||||
}
|
||||
flag_state_ = low;
|
||||
}
|
||||
|
||||
template <typename BusHandlerT, Personality personality>
|
||||
void MOS6526<BusHandlerT, personality>::write(int address, uint8_t value) {
|
||||
address &= 0xf;
|
||||
switch(address) {
|
||||
// Port output.
|
||||
case 0:
|
||||
output_[0] = value;
|
||||
set_port_output<0>();
|
||||
break;
|
||||
case 1:
|
||||
output_[1] = value;
|
||||
set_port_output<1>();
|
||||
break;
|
||||
|
||||
// Port direction.
|
||||
case 2:
|
||||
data_direction_[0] = value;
|
||||
set_port_output<0>();
|
||||
break;
|
||||
case 3:
|
||||
data_direction_[1] = value;
|
||||
set_port_output<1>();
|
||||
break;
|
||||
|
||||
// Counters; writes set the reload values.
|
||||
case 4: counter_[0].template set_reload<0, personality == Personality::P8250>(value); break;
|
||||
case 5: counter_[0].template set_reload<8, personality == Personality::P8250>(value); break;
|
||||
case 6: counter_[1].template set_reload<0, personality == Personality::P8250>(value); break;
|
||||
case 7: counter_[1].template set_reload<8, personality == Personality::P8250>(value); break;
|
||||
|
||||
// Time-of-day clock.
|
||||
case 8: tod_.template write<0>(value); break;
|
||||
case 9: tod_.template write<1>(value); break;
|
||||
case 10: tod_.template write<2>(value); break;
|
||||
case 11: tod_.template write<3>(value); break;
|
||||
|
||||
// Interrupt control.
|
||||
case 13: {
|
||||
if(value & 0x80) {
|
||||
interrupt_control_ |= value & 0x7f;
|
||||
} else {
|
||||
interrupt_control_ &= ~(value & 0x7f);
|
||||
}
|
||||
update_interrupts();
|
||||
} break;
|
||||
|
||||
// Control. Posted to both the counters and the clock as it affects both.
|
||||
case 14:
|
||||
counter_[0].template set_control<false>(value);
|
||||
tod_.template set_control<false>(value);
|
||||
if(shifter_is_output_ != bool(value & 0x40)) {
|
||||
shifter_is_output_ = value & 0x40;
|
||||
shift_bits_ = 0;
|
||||
}
|
||||
break;
|
||||
case 15:
|
||||
counter_[1].template set_control<true>(value);
|
||||
tod_.template set_control<true>(value);
|
||||
break;
|
||||
|
||||
// Shift control.
|
||||
case 12:
|
||||
printf("TODO: write to shift register\n");
|
||||
break;
|
||||
|
||||
default:
|
||||
printf("Unhandled 6526 write: %02x to %d\n", value, address);
|
||||
assert(false);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
template <typename BusHandlerT, Personality personality>
|
||||
uint8_t MOS6526<BusHandlerT, personality>::read(int address) {
|
||||
address &= 0xf;
|
||||
switch(address) {
|
||||
case 0: return get_port_input<0>();
|
||||
case 1: return get_port_input<1>();
|
||||
|
||||
case 2: case 3:
|
||||
return data_direction_[address - 2];
|
||||
|
||||
// Counters; reads obtain the current values.
|
||||
case 4: return uint8_t(counter_[0].value >> 0);
|
||||
case 5: return uint8_t(counter_[0].value >> 8);
|
||||
case 6: return uint8_t(counter_[1].value >> 0);
|
||||
case 7: return uint8_t(counter_[1].value >> 8);
|
||||
|
||||
// Interrupt state.
|
||||
case 13: {
|
||||
const uint8_t result = interrupt_state_;
|
||||
interrupt_state_ = 0;
|
||||
pending_ &= ~(InterruptNow | InterruptInOne);
|
||||
update_interrupts();
|
||||
return result;
|
||||
} break;
|
||||
|
||||
case 14: case 15:
|
||||
return counter_[address - 14].control;
|
||||
|
||||
// Time-of-day clock.
|
||||
case 8: return tod_.template read<0>();
|
||||
case 9: return tod_.template read<1>();
|
||||
case 10: return tod_.template read<2>();
|
||||
case 11: return tod_.template read<3>();
|
||||
|
||||
// Shift register.
|
||||
case 12: return shift_data_;
|
||||
|
||||
default:
|
||||
printf("Unhandled 6526 read from %d\n", address);
|
||||
assert(false);
|
||||
break;
|
||||
}
|
||||
return 0xff;
|
||||
}
|
||||
|
||||
template <typename BusHandlerT, Personality personality>
|
||||
void MOS6526<BusHandlerT, personality>::run_for(const HalfCycles half_cycles) {
|
||||
half_divider_ += half_cycles;
|
||||
int sub = half_divider_.divide_cycles().template as<int>();
|
||||
|
||||
while(sub--) {
|
||||
pending_ <<= 1;
|
||||
if(pending_ & InterruptNow) {
|
||||
interrupt_state_ |= 0x80;
|
||||
}
|
||||
pending_ &= PendingClearMask;
|
||||
|
||||
// TODO: use CNT potentially to clock timer A, elimiante conditional above.
|
||||
const bool timer1_did_reload = counter_[0].template advance<false>(false, cnt_state_, cnt_edge_);
|
||||
|
||||
const bool timer1_carry = timer1_did_reload && (counter_[1].control & 0x60) == 0x40;
|
||||
const bool timer2_did_reload = counter_[1].template advance<true>(timer1_carry, cnt_state_, cnt_edge_);
|
||||
posit_interrupt((timer1_did_reload ? Interrupts::TimerA : 0x00) | (timer2_did_reload ? Interrupts::TimerB : 0x00));
|
||||
|
||||
cnt_edge_ = false;
|
||||
}
|
||||
}
|
||||
|
||||
template <typename BusHandlerT, Personality personality>
|
||||
void MOS6526<BusHandlerT, personality>::advance_tod(int count) {
|
||||
if(!count) return;
|
||||
if(tod_.advance(count)) {
|
||||
posit_interrupt(Interrupts::Alarm);
|
||||
}
|
||||
}
|
||||
|
||||
template <typename BusHandlerT, Personality personality>
|
||||
bool MOS6526<BusHandlerT, personality>::serial_line_did_produce_bit(Serial::Line<true> *, int bit) {
|
||||
// TODO: post CNT change; might affect timer.
|
||||
|
||||
if(!shifter_is_output_) {
|
||||
shift_register_ = uint8_t((shift_register_ << 1) | bit);
|
||||
++shift_bits_;
|
||||
|
||||
if(shift_bits_ == 8) {
|
||||
shift_bits_ = 0;
|
||||
shift_data_ = shift_register_;
|
||||
posit_interrupt(Interrupts::SerialPort);
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
#endif /* _526Implementation_h */
|
||||
339
Components/6526/Implementation/6526Storage.hpp
Normal file
339
Components/6526/Implementation/6526Storage.hpp
Normal file
@@ -0,0 +1,339 @@
|
||||
//
|
||||
// 6526Storage.hpp
|
||||
// Clock Signal
|
||||
//
|
||||
// Created by Thomas Harte on 18/07/2021.
|
||||
// Copyright © 2021 Thomas Harte. All rights reserved.
|
||||
//
|
||||
|
||||
#ifndef _526Storage_h
|
||||
#define _526Storage_h
|
||||
|
||||
#include <array>
|
||||
|
||||
#include "../../../ClockReceiver/ClockReceiver.hpp"
|
||||
|
||||
namespace MOS {
|
||||
namespace MOS6526 {
|
||||
|
||||
class TODBase {
|
||||
public:
|
||||
template <bool is_timer2> void set_control(uint8_t value) {
|
||||
if constexpr (is_timer2) {
|
||||
write_alarm = value & 0x80;
|
||||
} else {
|
||||
is_50Hz = value & 0x80;
|
||||
}
|
||||
}
|
||||
|
||||
protected:
|
||||
bool write_alarm = false, is_50Hz = false;
|
||||
};
|
||||
|
||||
template <bool is_8250> class TODStorage {};
|
||||
|
||||
template <> class TODStorage<false>: public TODBase {
|
||||
private:
|
||||
bool increment_ = true, latched_ = false;
|
||||
int divider_ = 0;
|
||||
std::array<uint8_t, 4> value_;
|
||||
std::array<uint8_t, 4> latch_;
|
||||
std::array<uint8_t, 4> alarm_;
|
||||
|
||||
static constexpr uint8_t masks[4] = {0xf, 0x3f, 0x3f, 0x1f};
|
||||
|
||||
void bcd_increment(uint8_t &value) {
|
||||
++value;
|
||||
if((value&0x0f) > 0x09) value += 0x06;
|
||||
}
|
||||
|
||||
public:
|
||||
template <int byte> void write(uint8_t v) {
|
||||
if(write_alarm) {
|
||||
alarm_[byte] = v & masks[byte];
|
||||
} else {
|
||||
value_[byte] = v & masks[byte];
|
||||
|
||||
if constexpr (byte == 0) {
|
||||
increment_ = true;
|
||||
}
|
||||
if constexpr (byte == 3) {
|
||||
increment_ = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
template <int byte> uint8_t read() {
|
||||
if(latched_) {
|
||||
const uint8_t result = latch_[byte];
|
||||
if constexpr (byte == 0) {
|
||||
latched_ = false;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
if constexpr (byte == 3) {
|
||||
latched_ = true;
|
||||
latch_ = value_;
|
||||
}
|
||||
return value_[byte];
|
||||
}
|
||||
|
||||
bool advance(int count) {
|
||||
if(!increment_) {
|
||||
return false;
|
||||
}
|
||||
|
||||
while(count--) {
|
||||
// Increment the pre-10ths divider.
|
||||
++divider_;
|
||||
if(divider_ < 5) continue;
|
||||
if(divider_ < 6 && !is_50Hz) continue;
|
||||
divider_ = 0;
|
||||
|
||||
// Increments 10ths of a second. One BCD digit.
|
||||
++value_[0];
|
||||
if(value_[0] < 10) {
|
||||
continue;
|
||||
}
|
||||
|
||||
// Increment seconds. Actual BCD needed from here onwards.
|
||||
bcd_increment(value_[1]);
|
||||
if(value_[1] != 60) {
|
||||
continue;
|
||||
}
|
||||
value_[1] = 0;
|
||||
|
||||
// Increment minutes.
|
||||
bcd_increment(value_[2]);
|
||||
if(value_[2] != 60) {
|
||||
continue;
|
||||
}
|
||||
value_[2] = 0;
|
||||
|
||||
// TODO: increment hours, keeping AM/PM separate?
|
||||
}
|
||||
|
||||
return false; // TODO: test against alarm.
|
||||
}
|
||||
};
|
||||
|
||||
template <> class TODStorage<true>: public TODBase {
|
||||
private:
|
||||
uint32_t increment_mask_ = uint32_t(~0);
|
||||
uint32_t latch_ = 0;
|
||||
uint32_t value_ = 0;
|
||||
uint32_t alarm_ = 0xff'ffff;
|
||||
|
||||
public:
|
||||
template <int byte> void write(uint8_t v) {
|
||||
if constexpr (byte == 3) {
|
||||
return;
|
||||
}
|
||||
constexpr int shift = byte << 3;
|
||||
|
||||
// Write to either the alarm or the current value as directed;
|
||||
// writing to any part of the current value other than the LSB
|
||||
// pauses incrementing until the LSB is written.
|
||||
const uint32_t mask = uint32_t(~(0xff << shift));
|
||||
if(write_alarm) {
|
||||
alarm_ = (alarm_ & mask) | uint32_t(v << shift);
|
||||
} else {
|
||||
value_ = (value_ & mask) | uint32_t(v << shift);
|
||||
increment_mask_ = (byte == 0) ? uint32_t(~0) : 0;
|
||||
}
|
||||
}
|
||||
|
||||
template <int byte> uint8_t read() {
|
||||
if constexpr (byte == 3) {
|
||||
return 0xff; // Assumed. Just a guess.
|
||||
}
|
||||
constexpr int shift = byte << 3;
|
||||
|
||||
if constexpr (byte == 2) {
|
||||
latch_ = value_ | 0xff00'0000;
|
||||
}
|
||||
|
||||
const uint32_t source = latch_ ? latch_ : value_;
|
||||
const uint8_t result = uint8_t((source >> shift) & 0xff);
|
||||
|
||||
if constexpr (byte == 0) {
|
||||
latch_ = 0;
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
bool advance(int count) {
|
||||
// The 8250 uses a simple binary counter to replace the
|
||||
// 6526's time-of-day clock. So this is easy.
|
||||
const uint32_t distance_to_alarm = (alarm_ - value_) & 0xff'ffff;
|
||||
const auto increment = uint32_t(count) & increment_mask_;
|
||||
value_ = (value_ + increment) & 0xff'ffff;
|
||||
return distance_to_alarm <= increment;
|
||||
}
|
||||
};
|
||||
|
||||
struct MOS6526Storage {
|
||||
bool cnt_state_ = false; // Inactive by default.
|
||||
bool cnt_edge_ = false;
|
||||
bool flag_state_ = false;
|
||||
HalfCycles half_divider_;
|
||||
|
||||
uint8_t output_[2] = {0, 0};
|
||||
uint8_t data_direction_[2] = {0, 0};
|
||||
|
||||
uint8_t interrupt_control_ = 0;
|
||||
uint8_t interrupt_state_ = 0;
|
||||
|
||||
uint8_t shift_data_ = 0;
|
||||
uint8_t shift_register_ = 0;
|
||||
int shift_bits_ = 0;
|
||||
bool shifter_is_output_ = false;
|
||||
|
||||
struct Counter {
|
||||
uint16_t reload = 0;
|
||||
uint16_t value = 0;
|
||||
uint8_t control = 0;
|
||||
|
||||
template <int shift, bool is_8250> void set_reload(uint8_t v) {
|
||||
reload = (reload & (0xff00 >> shift)) | uint16_t(v << shift);
|
||||
|
||||
if constexpr (shift == 8) {
|
||||
// This seems to be a special 8250 feature per the Amiga
|
||||
// Hardware Reference Manual; cf. Appendix F.
|
||||
if(is_8250) {
|
||||
control |= 1;
|
||||
pending |= ReloadInOne;
|
||||
} else {
|
||||
if(!(control&1)) {
|
||||
pending |= ReloadInOne;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// If this write has hit during a reload cycle, reload.
|
||||
if(pending & ReloadNow) {
|
||||
value = reload;
|
||||
}
|
||||
}
|
||||
|
||||
template <bool is_counter_2> void set_control(uint8_t v) {
|
||||
control = v;
|
||||
|
||||
if(v&2) {
|
||||
printf("UNIMPLEMENTED: PB strobe\n");
|
||||
}
|
||||
}
|
||||
|
||||
template <bool is_counter_2> bool advance(bool chained_input, bool cnt_state, bool cnt_edge) {
|
||||
// TODO: remove most of the conditionals here in favour of bit shuffling.
|
||||
|
||||
pending = (pending & PendingClearMask) << 1;
|
||||
|
||||
//
|
||||
// Apply feeder states inputs: anything that
|
||||
// will take effect in the future.
|
||||
//
|
||||
|
||||
// Schedule a force reload if requested.
|
||||
if(control & 0x10) {
|
||||
pending |= ReloadInOne;
|
||||
control &= ~0x10;
|
||||
}
|
||||
|
||||
// Keep a history of the one-shot bit.
|
||||
if(control & 0x08) {
|
||||
pending |= OneShotInOne;
|
||||
}
|
||||
|
||||
// Determine whether an input clock is applicable.
|
||||
if constexpr(is_counter_2) {
|
||||
switch(control&0x60) {
|
||||
case 0x00: // Count Phi2 pulses.
|
||||
pending |= TestInputNow;
|
||||
break;
|
||||
case 0x20: // Count negative CNTs, with an extra cycle of delay.
|
||||
pending |= cnt_edge ? TestInputInOne : 0;
|
||||
break;
|
||||
case 0x40: // Count timer A reloads.
|
||||
pending |= chained_input ? TestInputNow : 0;
|
||||
break;
|
||||
case 0x60: // Count timer A transitions when CNT is low.
|
||||
pending |= chained_input && cnt_state ? TestInputNow : 0;
|
||||
break;
|
||||
}
|
||||
} else {
|
||||
if(!(control&0x20)) {
|
||||
pending |= TestInputNow;
|
||||
} else if (cnt_edge) {
|
||||
pending |= TestInputInOne;
|
||||
}
|
||||
}
|
||||
if(pending&TestInputNow && control&1) {
|
||||
pending |= ApplyClockInTwo;
|
||||
}
|
||||
|
||||
|
||||
//
|
||||
// Perform a timer tick and decide whether a reload is prompted.
|
||||
//
|
||||
if(pending & ApplyClockNow) {
|
||||
--value;
|
||||
}
|
||||
|
||||
const bool should_reload = !value && (pending & ApplyClockInOne);
|
||||
|
||||
// Schedule a reload if so ordered.
|
||||
if(should_reload) {
|
||||
pending |= ReloadNow; // Combine this decision with a deferred
|
||||
// input from the force-reoad test above.
|
||||
|
||||
// If this was one-shot, stop.
|
||||
if(pending&(OneShotInOne | OneShotNow)) {
|
||||
control &= ~1;
|
||||
pending &= ~(ApplyClockInOne|ApplyClockInTwo); // Cancel scheduled ticks.
|
||||
}
|
||||
}
|
||||
|
||||
// Reload if scheduled.
|
||||
if(pending & ReloadNow) {
|
||||
value = reload;
|
||||
pending &= ~ApplyClockInOne; // Skip next decrement.
|
||||
}
|
||||
|
||||
|
||||
return should_reload;
|
||||
}
|
||||
|
||||
private:
|
||||
int pending = 0;
|
||||
|
||||
static constexpr int ReloadInOne = 1 << 0;
|
||||
static constexpr int ReloadNow = 1 << 1;
|
||||
|
||||
static constexpr int OneShotInOne = 1 << 2;
|
||||
static constexpr int OneShotNow = 1 << 3;
|
||||
|
||||
static constexpr int ApplyClockInTwo = 1 << 4;
|
||||
static constexpr int ApplyClockInOne = 1 << 5;
|
||||
static constexpr int ApplyClockNow = 1 << 6;
|
||||
|
||||
static constexpr int TestInputInOne = 1 << 7;
|
||||
static constexpr int TestInputNow = 1 << 8;
|
||||
|
||||
static constexpr int PendingClearMask = ~(ReloadNow | OneShotNow | ApplyClockNow);
|
||||
|
||||
bool active_ = false;
|
||||
} counter_[2];
|
||||
|
||||
static constexpr int InterruptInOne = 1 << 0;
|
||||
static constexpr int InterruptNow = 1 << 1;
|
||||
static constexpr int PendingClearMask = ~(InterruptNow);
|
||||
int pending_ = 0;
|
||||
};
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
#endif /* _526Storage_h */
|
||||
@@ -435,7 +435,7 @@ template <class BusHandler> class MOS6560 {
|
||||
|
||||
Concurrency::DeferringAsyncTaskQueue audio_queue_;
|
||||
AudioGenerator audio_generator_;
|
||||
Outputs::Speaker::LowpassSpeaker<AudioGenerator> speaker_;
|
||||
Outputs::Speaker::PullLowpass<AudioGenerator> speaker_;
|
||||
|
||||
Cycles cycles_since_speaker_update_;
|
||||
void update_audio() {
|
||||
|
||||
@@ -129,8 +129,8 @@ ClockingHint::Preference ACIA::preferred_clocking() const {
|
||||
// because it's unclear when the interrupt might come.
|
||||
if(bits_incoming_ && receive_interrupt_enabled_) return ClockingHint::Preference::RealTime;
|
||||
|
||||
// No clocking required then.
|
||||
return ClockingHint::Preference::None;
|
||||
// Real-time clocking not required then.
|
||||
return ClockingHint::Preference::JustInTime;
|
||||
}
|
||||
|
||||
bool ACIA::get_interrupt_line() const {
|
||||
@@ -148,7 +148,7 @@ uint8_t ACIA::parity(uint8_t value) {
|
||||
return value ^ (parity_ == Parity::Even);
|
||||
}
|
||||
|
||||
bool ACIA::serial_line_did_produce_bit(Serial::Line *, int bit) {
|
||||
bool ACIA::serial_line_did_produce_bit(Serial::Line<false> *, int bit) {
|
||||
// Shift this bit into the 11-bit input register; this is big enough to hold
|
||||
// the largest transmission symbol.
|
||||
++bits_received_;
|
||||
|
||||
@@ -18,7 +18,7 @@
|
||||
namespace Motorola {
|
||||
namespace ACIA {
|
||||
|
||||
class ACIA: public ClockingHint::Source, private Serial::Line::ReadDelegate {
|
||||
class ACIA: public ClockingHint::Source, private Serial::Line<false>::ReadDelegate {
|
||||
public:
|
||||
static constexpr const HalfCycles SameAsTransmit = HalfCycles(0);
|
||||
|
||||
@@ -77,13 +77,13 @@ class ACIA: public ClockingHint::Source, private Serial::Line::ReadDelegate {
|
||||
void reset();
|
||||
|
||||
// Input lines.
|
||||
Serial::Line receive;
|
||||
Serial::Line clear_to_send;
|
||||
Serial::Line data_carrier_detect;
|
||||
Serial::Line<false> receive;
|
||||
Serial::Line<false> clear_to_send;
|
||||
Serial::Line<false> data_carrier_detect;
|
||||
|
||||
// Output lines.
|
||||
Serial::Line transmit;
|
||||
Serial::Line request_to_send;
|
||||
Serial::Line<false> transmit;
|
||||
Serial::Line<false> request_to_send;
|
||||
|
||||
// ClockingHint::Source.
|
||||
ClockingHint::Preference preferred_clocking() const final;
|
||||
@@ -118,7 +118,7 @@ class ACIA: public ClockingHint::Source, private Serial::Line::ReadDelegate {
|
||||
HalfCycles transmit_clock_rate_;
|
||||
HalfCycles receive_clock_rate_;
|
||||
|
||||
bool serial_line_did_produce_bit(Serial::Line *line, int bit) final;
|
||||
bool serial_line_did_produce_bit(Serial::Line<false> *line, int bit) final;
|
||||
|
||||
bool interrupt_line_ = false;
|
||||
void update_interrupt_line();
|
||||
|
||||
@@ -208,7 +208,7 @@ void MFP68901::run_for(HalfCycles time) {
|
||||
}
|
||||
|
||||
HalfCycles MFP68901::get_next_sequence_point() {
|
||||
return HalfCycles(-1);
|
||||
return HalfCycles::max();
|
||||
}
|
||||
|
||||
// MARK: - Timers
|
||||
|
||||
@@ -8,6 +8,10 @@
|
||||
|
||||
#include "z8530.hpp"
|
||||
|
||||
#ifndef NDEBUG
|
||||
#define NDEBUG
|
||||
#endif
|
||||
|
||||
#define LOG_PREFIX "[SCC] "
|
||||
#include "../../Outputs/Log.hpp"
|
||||
|
||||
|
||||
@@ -708,9 +708,9 @@ HalfCycles Base::half_cycles_before_internal_cycles(int internal_cycles) {
|
||||
return HalfCycles(((internal_cycles << 2) + (2 - cycles_error_)) / 3);
|
||||
}
|
||||
|
||||
HalfCycles TMS9918::get_time_until_interrupt() {
|
||||
if(!generate_interrupts_ && !enable_line_interrupts_) return HalfCycles(-1);
|
||||
if(get_interrupt_line()) return HalfCycles(0);
|
||||
HalfCycles TMS9918::get_next_sequence_point() {
|
||||
if(!generate_interrupts_ && !enable_line_interrupts_) return HalfCycles::max();
|
||||
if(get_interrupt_line()) return HalfCycles::max();
|
||||
|
||||
// Calculate the amount of time until the next end-of-frame interrupt.
|
||||
const int frame_length = 342 * mode_timing_.total_lines;
|
||||
@@ -750,7 +750,7 @@ HalfCycles TMS9918::get_time_until_interrupt() {
|
||||
if(next_line_interrupt_row == -1) {
|
||||
return generate_interrupts_ ?
|
||||
half_cycles_before_internal_cycles(time_until_frame_interrupt) :
|
||||
HalfCycles(-1);
|
||||
HalfCycles::max();
|
||||
}
|
||||
|
||||
// Figure out the number of internal cycles until the next line interrupt, which is the amount
|
||||
|
||||
@@ -75,13 +75,13 @@ class TMS9918: public Base {
|
||||
void latch_horizontal_counter();
|
||||
|
||||
/*!
|
||||
Returns the amount of time until @c get_interrupt_line would next return true if
|
||||
Returns the amount of time until @c get_interrupt_line would next change if
|
||||
there are no interceding calls to @c write or to @c read.
|
||||
|
||||
If get_interrupt_line is true now, returns zero. If get_interrupt_line would
|
||||
never return true, returns -1.
|
||||
If get_interrupt_line is true now of if get_interrupt_line would
|
||||
never return true, returns HalfCycles::max().
|
||||
*/
|
||||
HalfCycles get_time_until_interrupt();
|
||||
HalfCycles get_next_sequence_point();
|
||||
|
||||
/*!
|
||||
Returns the amount of time until the nominated line interrupt position is
|
||||
|
||||
@@ -350,11 +350,14 @@ class Base {
|
||||
|
||||
case MemoryAccess::Write:
|
||||
if(master_system_.cram_is_selected) {
|
||||
// Adjust the palette.
|
||||
// Adjust the palette. In a Master System blue has a slightly different
|
||||
// scale; cf. https://www.retrorgb.com/sega-master-system-non-linear-blue-channel-findings.html
|
||||
constexpr uint8_t rg_scale[] = {0, 85, 170, 255};
|
||||
constexpr uint8_t b_scale[] = {0, 104, 170, 255};
|
||||
master_system_.colour_ram[ram_pointer_ & 0x1f] = palette_pack(
|
||||
uint8_t(((read_ahead_buffer_ >> 0) & 3) * 255 / 3),
|
||||
uint8_t(((read_ahead_buffer_ >> 2) & 3) * 255 / 3),
|
||||
uint8_t(((read_ahead_buffer_ >> 4) & 3) * 255 / 3)
|
||||
rg_scale[(read_ahead_buffer_ >> 0) & 3],
|
||||
rg_scale[(read_ahead_buffer_ >> 2) & 3],
|
||||
b_scale[(read_ahead_buffer_ >> 4) & 3]
|
||||
);
|
||||
|
||||
// Schedule a CRAM dot; this is scheduled for wherever it should appear
|
||||
|
||||
@@ -12,6 +12,8 @@
|
||||
#include "../../Outputs/Speaker/Implementation/SampleSource.hpp"
|
||||
#include "../../Concurrency/AsyncTaskQueue.hpp"
|
||||
|
||||
#include "../../Reflection/Struct.hpp"
|
||||
|
||||
namespace GI {
|
||||
namespace AY38910 {
|
||||
|
||||
@@ -162,8 +164,60 @@ template <bool is_stereo> class AY38910: public ::Outputs::Speaker::SampleSource
|
||||
uint8_t a_left_ = 255, a_right_ = 255;
|
||||
uint8_t b_left_ = 255, b_right_ = 255;
|
||||
uint8_t c_left_ = 255, c_right_ = 255;
|
||||
|
||||
friend struct State;
|
||||
};
|
||||
|
||||
/*!
|
||||
Provides helper code, to provide something closer to the interface exposed by many
|
||||
AY-deploying machines of the era.
|
||||
*/
|
||||
struct Utility {
|
||||
template <typename AY> static void write(AY &ay, bool is_data_write, uint8_t data) {
|
||||
ay.set_control_lines(GI::AY38910::ControlLines(GI::AY38910::BDIR | GI::AY38910::BC2 | (is_data_write ? 0 : GI::AY38910::BC1)));
|
||||
ay.set_data_input(data);
|
||||
ay.set_control_lines(GI::AY38910::ControlLines(0));
|
||||
}
|
||||
|
||||
template <typename AY> static void select_register(AY &ay, uint8_t reg) {
|
||||
write(ay, false, reg);
|
||||
}
|
||||
|
||||
template <typename AY> static void write_data(AY &ay, uint8_t reg) {
|
||||
write(ay, true, reg);
|
||||
}
|
||||
|
||||
template <typename AY> static uint8_t read(AY &ay) {
|
||||
ay.set_control_lines(GI::AY38910::ControlLines(GI::AY38910::BC2 | GI::AY38910::BC1));
|
||||
const uint8_t result = ay.get_data_output();
|
||||
ay.set_control_lines(GI::AY38910::ControlLines(0));
|
||||
return result;
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
struct State: public Reflection::StructImpl<State> {
|
||||
uint8_t registers[16]{};
|
||||
uint8_t selected_register = 0;
|
||||
|
||||
// TODO: all audio-production thread state.
|
||||
|
||||
State() {
|
||||
if(needs_declare()) {
|
||||
DeclareField(registers);
|
||||
DeclareField(selected_register);
|
||||
}
|
||||
}
|
||||
|
||||
template <typename AY> void apply(AY &target) {
|
||||
// Establish emulator-thread state
|
||||
for(uint8_t c = 0; c < 16; c++) {
|
||||
target.select_register(c);
|
||||
target.set_register_value(registers[c]);
|
||||
}
|
||||
target.select_register(selected_register);
|
||||
}
|
||||
};
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
299
Components/AppleClock/AppleClock.hpp
Normal file
299
Components/AppleClock/AppleClock.hpp
Normal file
@@ -0,0 +1,299 @@
|
||||
//
|
||||
// RealTimeClock.hpp
|
||||
// Clock Signal
|
||||
//
|
||||
// Created by Thomas Harte on 07/05/2019.
|
||||
// Copyright © 2019 Thomas Harte. All rights reserved.
|
||||
//
|
||||
|
||||
#ifndef Apple_RealTimeClock_hpp
|
||||
#define Apple_RealTimeClock_hpp
|
||||
|
||||
#include <array>
|
||||
|
||||
namespace Apple {
|
||||
namespace Clock {
|
||||
|
||||
/*!
|
||||
Models Apple's real-time clocks, as contained in the Macintosh and IIgs.
|
||||
|
||||
Since tracking of time is pushed to this class, it is assumed
|
||||
that whomever is translating real time into emulated time
|
||||
will also signal interrupts — this is just the storage and time counting.
|
||||
*/
|
||||
class ClockStorage {
|
||||
public:
|
||||
ClockStorage() {}
|
||||
|
||||
/*!
|
||||
Advances the clock by 1 second.
|
||||
|
||||
The caller should also signal an interrupt if applicable.
|
||||
*/
|
||||
void update() {
|
||||
for(size_t c = 0; c < 4; ++c) {
|
||||
++seconds_[c];
|
||||
if(seconds_[c]) break;
|
||||
}
|
||||
}
|
||||
|
||||
/*!
|
||||
Sets the current [P/B]RAM contents.
|
||||
*/
|
||||
template <typename CollectionT> void set_data(const CollectionT &collection) {
|
||||
set_data(collection.begin(), collection.end());
|
||||
}
|
||||
|
||||
template <typename IteratorT> void set_data(IteratorT begin, const IteratorT end) {
|
||||
size_t c = 0;
|
||||
while(begin != end && c < 256) {
|
||||
data_[c] = *begin;
|
||||
++begin;
|
||||
++c;
|
||||
}
|
||||
}
|
||||
|
||||
protected:
|
||||
static constexpr uint16_t NoResult = 0x100;
|
||||
static constexpr uint16_t DidComplete = 0x101;
|
||||
uint16_t perform(uint8_t command) {
|
||||
/*
|
||||
Documented commands:
|
||||
|
||||
z0000001 Seconds register 0 (lowest order byte)
|
||||
z0000101 Seconds register 1
|
||||
z0001001 Seconds register 2
|
||||
z0001101 Seconds register 3
|
||||
00110001 Test register (write only)
|
||||
00110101 Write-protect register (write only)
|
||||
z010aa01 RAM addresses 0x10 - 0x13
|
||||
z1aaaa01 RAM addresses 0x00 – 0x0f
|
||||
|
||||
z0111abc, followed by 0defgh00
|
||||
RAM address abcdefgh
|
||||
|
||||
z = 1 => a read; z = 0 => a write.
|
||||
|
||||
The top bit of the write-protect register enables (0) or disables (1)
|
||||
writes to other locations.
|
||||
|
||||
All the documentation says about the test register is to set the top
|
||||
two bits to 0 for normal operation. Abnormal operation is undefined.
|
||||
*/
|
||||
switch(phase_) {
|
||||
case Phase::Command:
|
||||
// Decode an address.
|
||||
switch(command & 0x70) {
|
||||
default:
|
||||
if(command & 0x40) {
|
||||
// RAM addresses 0x00 – 0x0f.
|
||||
address_ = (command >> 2) & 0xf;
|
||||
} else return DidComplete; // Unrecognised.
|
||||
break;
|
||||
|
||||
case 0x00:
|
||||
// A time access.
|
||||
address_ = SecondsBuffer + ((command >> 2)&3);
|
||||
break;
|
||||
case 0x30:
|
||||
// Either a register access or an extended instruction.
|
||||
if(command & 0x08) {
|
||||
address_ = unsigned((command & 0x7) << 5);
|
||||
phase_ = (command & 0x80) ? Phase::SecondAddressByteRead : Phase::SecondAddressByteWrite;
|
||||
return NoResult;
|
||||
} else {
|
||||
address_ = (command & 4) ? RegisterWriteProtect : RegisterTest;
|
||||
}
|
||||
break;
|
||||
case 0x20:
|
||||
// RAM addresses 0x10 – 0x13.
|
||||
address_ = 0x10 + ((command >> 2) & 0x3);
|
||||
break;
|
||||
}
|
||||
|
||||
// If this is a read, return a result; otherwise prepare to write.
|
||||
if(command & 0x80) {
|
||||
// The two registers are write-only.
|
||||
if(address_ == RegisterTest || address_ == RegisterWriteProtect) {
|
||||
return DidComplete;
|
||||
}
|
||||
return (address_ >= SecondsBuffer) ? seconds_[address_ & 0xff] : data_[address_];
|
||||
}
|
||||
phase_ = Phase::WriteData;
|
||||
return NoResult;
|
||||
|
||||
case Phase::SecondAddressByteRead:
|
||||
case Phase::SecondAddressByteWrite:
|
||||
if(command & 0x83) {
|
||||
return DidComplete;
|
||||
}
|
||||
address_ |= command >> 2;
|
||||
|
||||
if(phase_ == Phase::SecondAddressByteRead) {
|
||||
phase_ = Phase::Command;
|
||||
return data_[address_]; // Only RAM accesses can get this far.
|
||||
} else {
|
||||
phase_ = Phase::WriteData;
|
||||
}
|
||||
return NoResult;
|
||||
|
||||
case Phase::WriteData:
|
||||
// First test: is this to the write-protect register?
|
||||
if(address_ == RegisterWriteProtect) {
|
||||
write_protect_ = command;
|
||||
return DidComplete;
|
||||
}
|
||||
|
||||
if(address_ == RegisterTest) {
|
||||
// No documentation here.
|
||||
return DidComplete;
|
||||
}
|
||||
|
||||
// No other writing is permitted if the write protect
|
||||
// register won't allow it.
|
||||
if(!(write_protect_ & 0x80)) {
|
||||
if(address_ >= SecondsBuffer) {
|
||||
seconds_[address_ & 0xff] = command;
|
||||
} else {
|
||||
data_[address_] = command;
|
||||
}
|
||||
}
|
||||
|
||||
phase_ = Phase::Command;
|
||||
return DidComplete;
|
||||
}
|
||||
|
||||
return NoResult;
|
||||
}
|
||||
|
||||
|
||||
private:
|
||||
std::array<uint8_t, 256> data_{0xff};
|
||||
std::array<uint8_t, 4> seconds_{};
|
||||
uint8_t write_protect_ = 0;
|
||||
unsigned int address_ = 0;
|
||||
|
||||
static constexpr int SecondsBuffer = 0x100;
|
||||
static constexpr int RegisterTest = 0x200;
|
||||
static constexpr int RegisterWriteProtect = 0x201;
|
||||
|
||||
enum class Phase {
|
||||
Command,
|
||||
SecondAddressByteRead,
|
||||
SecondAddressByteWrite,
|
||||
WriteData
|
||||
};
|
||||
Phase phase_ = Phase::Command;
|
||||
|
||||
};
|
||||
|
||||
/*!
|
||||
Provides the serial interface implemented by the Macintosh.
|
||||
*/
|
||||
class SerialClock: public ClockStorage {
|
||||
public:
|
||||
/*!
|
||||
Sets the current clock and data inputs to the clock.
|
||||
*/
|
||||
void set_input(bool clock, bool data) {
|
||||
// The data line is valid when the clock transitions to level 0.
|
||||
if(clock && !previous_clock_) {
|
||||
// Shift into the command_ register, no matter what.
|
||||
command_ = uint16_t((command_ << 1) | (data ? 1 : 0));
|
||||
result_ <<= 1;
|
||||
|
||||
// Increment phase.
|
||||
++phase_;
|
||||
|
||||
// If a whole byte has been collected, push it onwards.
|
||||
if(!(phase_&7)) {
|
||||
// Begin pessimistically.
|
||||
const auto effect = perform(uint8_t(command_));
|
||||
|
||||
switch(effect) {
|
||||
case ClockStorage::NoResult:
|
||||
break;
|
||||
default:
|
||||
result_ = uint8_t(effect);
|
||||
break;
|
||||
case ClockStorage::DidComplete:
|
||||
abort();
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
previous_clock_ = clock;
|
||||
}
|
||||
|
||||
/*!
|
||||
Reads the current data output level from the clock.
|
||||
*/
|
||||
bool get_data() {
|
||||
return !!(result_ & 0x80);
|
||||
}
|
||||
|
||||
/*!
|
||||
Announces that a serial command has been aborted.
|
||||
*/
|
||||
void abort() {
|
||||
result_ = 0;
|
||||
phase_ = 0;
|
||||
command_ = 0;
|
||||
}
|
||||
|
||||
private:
|
||||
int phase_ = 0;
|
||||
uint16_t command_;
|
||||
uint8_t result_ = 0;
|
||||
|
||||
bool previous_clock_ = false;
|
||||
};
|
||||
|
||||
/*!
|
||||
Provides the parallel interface implemented by the IIgs.
|
||||
*/
|
||||
class ParallelClock: public ClockStorage {
|
||||
public:
|
||||
void set_control(uint8_t control) {
|
||||
if(!(control&0x80)) return;
|
||||
|
||||
if(control & 0x40) {
|
||||
// Read from the RTC.
|
||||
// A no-op for now.
|
||||
} else {
|
||||
// Write to the RTC. Which in this implementation also sets up a future read.
|
||||
const auto result = perform(data_);
|
||||
if(result < 0x100) {
|
||||
data_ = uint8_t(result);
|
||||
}
|
||||
}
|
||||
|
||||
// MAGIC! The transaction took 0 seconds.
|
||||
// TODO: no magic.
|
||||
control_ = control & 0x7f;
|
||||
|
||||
// Bit 5 is also meant to be 1 or 0 to indicate the final byte.
|
||||
}
|
||||
|
||||
uint8_t get_control() {
|
||||
return control_;
|
||||
}
|
||||
|
||||
void set_data(uint8_t data) {
|
||||
data_ = data;
|
||||
}
|
||||
|
||||
uint8_t get_data() {
|
||||
return data_;
|
||||
}
|
||||
|
||||
private:
|
||||
uint8_t data_;
|
||||
uint8_t control_;
|
||||
};
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
#endif /* Apple_RealTimeClock_hpp */
|
||||
@@ -22,7 +22,10 @@ namespace {
|
||||
DiskII::DiskII(int clock_rate) :
|
||||
clock_rate_(clock_rate),
|
||||
inputs_(input_command),
|
||||
drives_{{clock_rate, 300, 1}, {clock_rate, 300, 1}}
|
||||
drives_{
|
||||
Storage::Disk::Drive{clock_rate, 300, 1},
|
||||
Storage::Disk::Drive{clock_rate, 300, 1}
|
||||
}
|
||||
{
|
||||
drives_[0].set_clocking_hint_observer(this);
|
||||
drives_[1].set_clocking_hint_observer(this);
|
||||
@@ -137,10 +140,15 @@ void DiskII::decide_clocking_preference() {
|
||||
|
||||
// If in read mode, clocking is either:
|
||||
//
|
||||
// just-in-time, if drives are running or the shift register has any 1s in it or a flux event hasn't yet passed; or
|
||||
// none, given that drives are not running, the shift register has already emptied and there's no flux about to be received.
|
||||
// just-in-time, if drives are running or the shift register has any 1s in it and shifting may occur, or a flux event hasn't yet passed; or
|
||||
// none, given that drives are not running, the shift register has already emptied or stopped and there's no flux about to be received.
|
||||
if(!(inputs_ & ~input_flux)) {
|
||||
clocking_preference_ = (!motor_is_enabled_ && !shift_register_ && (inputs_&input_flux)) ? ClockingHint::Preference::None : ClockingHint::Preference::JustInTime;
|
||||
const bool is_stuck_at_nop =
|
||||
!flux_duration_ && state_machine_[(state_ & 0xf0) | inputs_ | ((shift_register_&0x80) >> 6)] == state_ && (state_ &0xf) == 0x8;
|
||||
|
||||
clocking_preference_ =
|
||||
(drive_is_sleeping_[0] && drive_is_sleeping_[1] && (!shift_register_ || is_stuck_at_nop) && (inputs_&input_flux))
|
||||
? ClockingHint::Preference::None : ClockingHint::Preference::JustInTime;
|
||||
}
|
||||
|
||||
// If in writing mode, clocking is real time.
|
||||
@@ -180,29 +188,40 @@ void DiskII::set_state_machine(const std::vector<uint8_t> &state_machine) {
|
||||
if(state_machine[0] != 0x18) {
|
||||
for(size_t source_address = 0; source_address < 256; ++source_address) {
|
||||
// Remap into Beneath Apple Pro-DOS address form.
|
||||
size_t destination_address =
|
||||
((source_address&0x80) ? 0x10 : 0x00) |
|
||||
((source_address&0x01) ? 0x20 : 0x00) |
|
||||
((source_address&0x40) ? 0x40 : 0x00) |
|
||||
const size_t destination_address =
|
||||
((source_address&0x20) ? 0x80 : 0x00) |
|
||||
((source_address&0x10) ? 0x01 : 0x00) |
|
||||
((source_address&0x40) ? 0x40 : 0x00) |
|
||||
((source_address&0x01) ? 0x20 : 0x00) |
|
||||
((source_address&0x80) ? 0x10 : 0x00) |
|
||||
((source_address&0x08) ? 0x08 : 0x00) |
|
||||
((source_address&0x04) ? 0x04 : 0x00) |
|
||||
((source_address&0x02) ? 0x02 : 0x00);
|
||||
uint8_t source_value = state_machine[source_address];
|
||||
((source_address&0x02) ? 0x02 : 0x00) |
|
||||
((source_address&0x10) ? 0x01 : 0x00);
|
||||
|
||||
source_value =
|
||||
// Store.
|
||||
const uint8_t source_value = state_machine[source_address];
|
||||
state_machine_[destination_address] =
|
||||
((source_value & 0x80) ? 0x10 : 0x0) |
|
||||
((source_value & 0x40) ? 0x20 : 0x0) |
|
||||
((source_value & 0x20) ? 0x40 : 0x0) |
|
||||
((source_value & 0x10) ? 0x80 : 0x0) |
|
||||
(source_value & 0x0f);
|
||||
|
||||
// Store.
|
||||
state_machine_[destination_address] = source_value;
|
||||
}
|
||||
} else {
|
||||
memcpy(&state_machine_[0], &state_machine[0], 128);
|
||||
for(size_t source_address = 0; source_address < 256; ++source_address) {
|
||||
// Reshuffle ordering of bytes only, to retain indexing by the high nibble.
|
||||
const size_t destination_address =
|
||||
((source_address&0x80) ? 0x80 : 0x00) |
|
||||
((source_address&0x40) ? 0x40 : 0x00) |
|
||||
((source_address&0x01) ? 0x20 : 0x00) |
|
||||
((source_address&0x20) ? 0x10 : 0x00) |
|
||||
((source_address&0x08) ? 0x08 : 0x00) |
|
||||
((source_address&0x04) ? 0x04 : 0x00) |
|
||||
((source_address&0x02) ? 0x02 : 0x00) |
|
||||
((source_address&0x10) ? 0x01 : 0x00);
|
||||
|
||||
state_machine_[destination_address] = state_machine[source_address];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
45
Components/DiskII/DiskIIDrive.cpp
Normal file
45
Components/DiskII/DiskIIDrive.cpp
Normal file
@@ -0,0 +1,45 @@
|
||||
//
|
||||
// DiskIIDrive.cpp
|
||||
// Clock Signal
|
||||
//
|
||||
// Created by Thomas Harte on 20/11/2020.
|
||||
// Copyright © 2020 Thomas Harte. All rights reserved.
|
||||
//
|
||||
|
||||
#include "DiskIIDrive.hpp"
|
||||
|
||||
using namespace Apple::Disk;
|
||||
|
||||
DiskIIDrive::DiskIIDrive(int input_clock_rate) :
|
||||
IWMDrive(input_clock_rate, 1) {
|
||||
Drive::set_rotation_speed(300.0f);
|
||||
}
|
||||
|
||||
void DiskIIDrive::set_enabled(bool enabled) {
|
||||
set_motor_on(enabled);
|
||||
}
|
||||
|
||||
void DiskIIDrive::set_control_lines(int lines) {
|
||||
// If the stepper magnet selections have changed, and any is on, see how
|
||||
// that moves the head.
|
||||
if(lines ^ stepper_mask_ && lines) {
|
||||
// Convert from a representation of bits set to the centre of pull.
|
||||
int direction = 0;
|
||||
if(lines&1) direction += (((stepper_position_ - 0) + 4)&7) - 4;
|
||||
if(lines&2) direction += (((stepper_position_ - 2) + 4)&7) - 4;
|
||||
if(lines&4) direction += (((stepper_position_ - 4) + 4)&7) - 4;
|
||||
if(lines&8) direction += (((stepper_position_ - 6) + 4)&7) - 4;
|
||||
const int bits_set = (lines&1) + ((lines >> 1)&1) + ((lines >> 2)&1) + ((lines >> 3)&1);
|
||||
direction /= bits_set;
|
||||
|
||||
// Compare to the stepper position to decide whether that pulls in the
|
||||
// current cog notch, or grabs a later one.
|
||||
step(Storage::Disk::HeadPosition(-direction, 4));
|
||||
stepper_position_ = (stepper_position_ - direction + 8) & 7;
|
||||
}
|
||||
stepper_mask_ = lines;
|
||||
}
|
||||
|
||||
bool DiskIIDrive::read() {
|
||||
return !!(stepper_mask_ & 2) || get_is_read_only();
|
||||
}
|
||||
33
Components/DiskII/DiskIIDrive.hpp
Normal file
33
Components/DiskII/DiskIIDrive.hpp
Normal file
@@ -0,0 +1,33 @@
|
||||
//
|
||||
// DiskIIDrive.hpp
|
||||
// Clock Signal
|
||||
//
|
||||
// Created by Thomas Harte on 20/11/2020.
|
||||
// Copyright © 2020 Thomas Harte. All rights reserved.
|
||||
//
|
||||
|
||||
#ifndef DiskIIDrive_hpp
|
||||
#define DiskIIDrive_hpp
|
||||
|
||||
#include "IWM.hpp"
|
||||
|
||||
namespace Apple {
|
||||
namespace Disk {
|
||||
|
||||
class DiskIIDrive: public IWMDrive {
|
||||
public:
|
||||
DiskIIDrive(int input_clock_rate);
|
||||
|
||||
private:
|
||||
void set_enabled(bool) final;
|
||||
void set_control_lines(int) final;
|
||||
bool read() final;
|
||||
|
||||
int stepper_mask_ = 0;
|
||||
int stepper_position_ = 0;
|
||||
};
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
#endif /* DiskIIDrive_hpp */
|
||||
@@ -8,6 +8,11 @@
|
||||
|
||||
#include "IWM.hpp"
|
||||
|
||||
#ifndef NDEBUG
|
||||
#define NDEBUG
|
||||
#endif
|
||||
|
||||
#define LOG_PREFIX "[IWM] "
|
||||
#include "../../Outputs/Log.hpp"
|
||||
|
||||
using namespace Apple;
|
||||
@@ -50,7 +55,7 @@ uint8_t IWM::read(int address) {
|
||||
|
||||
switch(state_ & (Q6 | Q7 | ENABLE)) {
|
||||
default:
|
||||
LOG("[IWM] Invalid read\n");
|
||||
LOG("Invalid read\n");
|
||||
return 0xff;
|
||||
|
||||
// "Read all 1s".
|
||||
@@ -62,9 +67,8 @@ uint8_t IWM::read(int address) {
|
||||
const auto result = data_register_;
|
||||
|
||||
if(data_register_ & 0x80) {
|
||||
// printf("\n\nIWM:%02x\n\n", data_register_);
|
||||
// printf(".");
|
||||
data_register_ = 0;
|
||||
// LOG("Reading data: " << PADHEX(2) << int(result));
|
||||
}
|
||||
// LOG("Reading data register: " << PADHEX(2) << int(result));
|
||||
|
||||
@@ -99,7 +103,7 @@ uint8_t IWM::read(int address) {
|
||||
bit 6: 1 = write state (0 = underrun has occurred; 1 = no underrun so far).
|
||||
bit 7: 1 = write data buffer ready for data (1 = ready; 0 = busy).
|
||||
*/
|
||||
// LOG("Reading write handshake: " << PADHEX(2) << (0x3f | write_handshake_));
|
||||
// LOG("Reading write handshake: " << PADHEX(2) << int(0x3f | write_handshake_));
|
||||
return 0x3f | write_handshake_;
|
||||
}
|
||||
|
||||
@@ -128,13 +132,21 @@ void IWM::write(int address, uint8_t input) {
|
||||
|
||||
mode_ = input;
|
||||
|
||||
// TEMPORARY. To test for the unimplemented mode.
|
||||
if(input&0x2) {
|
||||
LOG("Switched to asynchronous mode");
|
||||
} else {
|
||||
LOG("Switched to synchronous mode");
|
||||
}
|
||||
|
||||
switch(mode_ & 0x18) {
|
||||
case 0x00: bit_length_ = Cycles(24); break; // slow mode, 7Mhz
|
||||
case 0x08: bit_length_ = Cycles(12); break; // fast mode, 7Mhz
|
||||
case 0x00: bit_length_ = Cycles(28); break; // slow mode, 7Mhz
|
||||
case 0x08: bit_length_ = Cycles(14); break; // fast mode, 7Mhz
|
||||
case 0x10: bit_length_ = Cycles(32); break; // slow mode, 8Mhz
|
||||
case 0x18: bit_length_ = Cycles(16); break; // fast mode, 8Mhz
|
||||
}
|
||||
LOG("IWM mode is now " << PADHEX(2) << int(mode_));
|
||||
LOG("Mode is now " << PADHEX(2) << int(mode_));
|
||||
LOG("New bit length is " << std::dec << bit_length_.as_integral());
|
||||
break;
|
||||
|
||||
case Q7|Q6|ENABLE: // Write data register.
|
||||
@@ -248,6 +260,7 @@ void IWM::run_for(const Cycles cycles) {
|
||||
drives_[active_drive_]->run_for(Cycles(1));
|
||||
++cycles_since_shift_;
|
||||
if(cycles_since_shift_ == bit_length_ + error_margin) {
|
||||
// LOG("Shifting 0 at " << std::dec << cycles_since_shift_.as_integral());
|
||||
propose_shift(0);
|
||||
}
|
||||
}
|
||||
@@ -263,41 +276,45 @@ void IWM::run_for(const Cycles cycles) {
|
||||
} break;
|
||||
|
||||
case ShiftMode::Writing:
|
||||
if(drives_[active_drive_]->is_writing()) {
|
||||
while(cycles_since_shift_ + integer_cycles >= bit_length_) {
|
||||
const auto cycles_until_write = bit_length_ - cycles_since_shift_;
|
||||
while(cycles_since_shift_ + integer_cycles >= bit_length_) {
|
||||
const auto cycles_until_write = bit_length_ - cycles_since_shift_;
|
||||
if(drives_[active_drive_]) {
|
||||
drives_[active_drive_]->run_for(cycles_until_write);
|
||||
|
||||
// Output a flux transition if the top bit is set.
|
||||
drives_[active_drive_]->write_bit(shift_register_ & 0x80);
|
||||
shift_register_ <<= 1;
|
||||
}
|
||||
shift_register_ <<= 1;
|
||||
|
||||
integer_cycles -= cycles_until_write.as_integral();
|
||||
cycles_since_shift_ = Cycles(0);
|
||||
integer_cycles -= cycles_until_write.as_integral();
|
||||
cycles_since_shift_ = Cycles(0);
|
||||
|
||||
--output_bits_remaining_;
|
||||
if(!output_bits_remaining_) {
|
||||
if(!(write_handshake_ & 0x80)) {
|
||||
write_handshake_ |= 0x80;
|
||||
shift_register_ = next_output_;
|
||||
output_bits_remaining_ = 8;
|
||||
// LOG("Next byte: " << PADHEX(2) << int(shift_register_));
|
||||
} else {
|
||||
write_handshake_ &= ~0x40;
|
||||
drives_[active_drive_]->end_writing();
|
||||
// printf("\n");
|
||||
LOG("Overrun; done.");
|
||||
select_shift_mode();
|
||||
}
|
||||
--output_bits_remaining_;
|
||||
if(!output_bits_remaining_) {
|
||||
if(!(write_handshake_ & 0x80)) {
|
||||
shift_register_ = next_output_;
|
||||
output_bits_remaining_ = 8;
|
||||
// LOG("Next byte: " << PADHEX(2) << int(shift_register_));
|
||||
} else {
|
||||
write_handshake_ &= ~0x40;
|
||||
if(drives_[active_drive_]) drives_[active_drive_]->end_writing();
|
||||
LOG("Overrun; done.");
|
||||
output_bits_remaining_ = 1;
|
||||
}
|
||||
}
|
||||
|
||||
cycles_since_shift_ = integer_cycles;
|
||||
if(integer_cycles) {
|
||||
drives_[active_drive_]->run_for(cycles_since_shift_);
|
||||
// Either way, the IWM is ready for more data.
|
||||
write_handshake_ |= 0x80;
|
||||
}
|
||||
} else {
|
||||
drives_[active_drive_]->run_for(cycles);
|
||||
}
|
||||
|
||||
// Either some bits were output, in which case cycles_since_shift_ is no 0 and
|
||||
// integer_cycles is some number less than bit_length_, or none were and
|
||||
// cycles_since_shift_ + integer_cycles is less than bit_length, and the new
|
||||
// part should be accumulated.
|
||||
cycles_since_shift_ += integer_cycles;
|
||||
|
||||
if(drives_[active_drive_] && integer_cycles) {
|
||||
drives_[active_drive_]->run_for(cycles_since_shift_);
|
||||
}
|
||||
break;
|
||||
|
||||
@@ -332,12 +349,12 @@ void IWM::select_shift_mode() {
|
||||
}
|
||||
|
||||
// If writing mode just began, set the drive into write mode and cue up the first output byte.
|
||||
if(drives_[active_drive_] && old_shift_mode != ShiftMode::Writing && shift_mode_ == ShiftMode::Writing) {
|
||||
drives_[active_drive_]->begin_writing(Storage::Time(1, clock_rate_ / bit_length_.as_integral()), false);
|
||||
if(old_shift_mode != ShiftMode::Writing && shift_mode_ == ShiftMode::Writing) {
|
||||
if(drives_[active_drive_]) drives_[active_drive_]->begin_writing(Storage::Time(1, clock_rate_ / bit_length_.as_integral()), false);
|
||||
shift_register_ = next_output_;
|
||||
write_handshake_ |= 0x80 | 0x40;
|
||||
output_bits_remaining_ = 8;
|
||||
LOG("Seeding output with " << PADHEX(2) << shift_register_);
|
||||
LOG("Seeding output with " << PADHEX(2) << int(shift_register_));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -351,6 +368,7 @@ void IWM::process_event(const Storage::Disk::Drive::Event &event) {
|
||||
switch(event.type) {
|
||||
case Storage::Disk::Track::Event::IndexHole: return;
|
||||
case Storage::Disk::Track::Event::FluxTransition:
|
||||
// LOG("Shifting 1 at " << std::dec << cycles_since_shift_.as_integral());
|
||||
propose_shift(1);
|
||||
break;
|
||||
}
|
||||
@@ -359,12 +377,13 @@ void IWM::process_event(const Storage::Disk::Drive::Event &event) {
|
||||
void IWM::propose_shift(uint8_t bit) {
|
||||
// TODO: synchronous mode.
|
||||
|
||||
// LOG("Shifting at " << std::dec << cycles_since_shift_.as_integral());
|
||||
// LOG("Shifting input");
|
||||
|
||||
// See above for text from the IWM patent, column 7, around line 35 onwards.
|
||||
// The error_margin here implements the 'before' part of that contract.
|
||||
//
|
||||
// Basic effective logic: if at least 1 is fozund in the bit_length_ cycles centred
|
||||
// Basic effective logic: if at least 1 is found in the bit_length_ cycles centred
|
||||
// on the current expected bit delivery time as implied by cycles_since_shift_,
|
||||
// shift in a 1 and start a new window wherever the first found 1 was.
|
||||
//
|
||||
@@ -374,6 +393,7 @@ void IWM::propose_shift(uint8_t bit) {
|
||||
|
||||
shift_register_ = uint8_t((shift_register_ << 1) | bit);
|
||||
if(shift_register_ & 0x80) {
|
||||
// if(data_register_ & 0x80) LOG("Byte missed");
|
||||
data_register_ = shift_register_;
|
||||
shift_register_ = 0;
|
||||
}
|
||||
@@ -386,16 +406,20 @@ void IWM::propose_shift(uint8_t bit) {
|
||||
|
||||
void IWM::set_drive(int slot, IWMDrive *drive) {
|
||||
drives_[slot] = drive;
|
||||
drive->set_event_delegate(this);
|
||||
drive->set_clocking_hint_observer(this);
|
||||
if(drive) {
|
||||
drive->set_event_delegate(this);
|
||||
drive->set_clocking_hint_observer(this);
|
||||
} else {
|
||||
drive_is_rotating_[slot] = false;
|
||||
}
|
||||
}
|
||||
|
||||
void IWM::set_component_prefers_clocking(ClockingHint::Source *component, ClockingHint::Preference clocking) {
|
||||
const bool is_rotating = clocking != ClockingHint::Preference::None;
|
||||
|
||||
if(component == static_cast<ClockingHint::Source *>(drives_[0])) {
|
||||
if(drives_[0] && component == static_cast<ClockingHint::Source *>(drives_[0])) {
|
||||
drive_is_rotating_[0] = is_rotating;
|
||||
} else {
|
||||
} else if(drives_[1] && component == static_cast<ClockingHint::Source *>(drives_[1])) {
|
||||
drive_is_rotating_[1] = is_rotating;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -142,8 +142,11 @@ bool DoubleDensityDrive::read() {
|
||||
return !get_is_track_zero();
|
||||
|
||||
case CA1|CA0: // Disk has been ejected.
|
||||
// (0 = user has ejected disk)
|
||||
return !has_new_disk_;
|
||||
// (1 = user has ejected disk)
|
||||
//
|
||||
// TODO: does this really mean _user_ has ejected disk? If so then I should avoid
|
||||
// changing the flag upon a programmatic eject.
|
||||
return has_new_disk_;
|
||||
|
||||
case CA1|CA0|SEL: // Tachometer.
|
||||
// (arbitrary)
|
||||
@@ -170,12 +173,10 @@ bool DoubleDensityDrive::read() {
|
||||
|
||||
case CA2|CA1|CA0|SEL: // Drive installed.
|
||||
// (0 = present, 1 = missing)
|
||||
//
|
||||
// TODO: why do I need to return this the wrong way around for the Mac Plus?
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
void DoubleDensityDrive::did_set_disk() {
|
||||
has_new_disk_ = true;
|
||||
void DoubleDensityDrive::did_set_disk(bool did_replace) {
|
||||
has_new_disk_ = did_replace;
|
||||
}
|
||||
|
||||
@@ -21,7 +21,7 @@ class DoubleDensityDrive: public IWMDrive {
|
||||
/*!
|
||||
@returns @c true if this is an 800kb drive; @c false otherwise.
|
||||
*/
|
||||
bool is_800k() {
|
||||
bool is_800k() const {
|
||||
return is_800k_;
|
||||
}
|
||||
|
||||
@@ -39,7 +39,7 @@ class DoubleDensityDrive: public IWMDrive {
|
||||
|
||||
// To receive the proper notifications from Storage::Disk::Drive.
|
||||
void did_step(Storage::Disk::HeadPosition to_position) final;
|
||||
void did_set_disk() final;
|
||||
void did_set_disk(bool) final;
|
||||
|
||||
const bool is_800k_;
|
||||
bool has_new_disk_ = false;
|
||||
|
||||
@@ -8,13 +8,18 @@
|
||||
|
||||
#include "Line.hpp"
|
||||
|
||||
#include <cassert>
|
||||
#include <limits>
|
||||
|
||||
using namespace Serial;
|
||||
|
||||
void Line::set_writer_clock_rate(HalfCycles clock_rate) {
|
||||
template <bool include_clock>
|
||||
void Line<include_clock>::set_writer_clock_rate(HalfCycles clock_rate) {
|
||||
clock_rate_ = clock_rate;
|
||||
}
|
||||
|
||||
void Line::advance_writer(HalfCycles cycles) {
|
||||
template <bool include_clock>
|
||||
void Line<include_clock>::advance_writer(HalfCycles cycles) {
|
||||
if(cycles == HalfCycles(0)) return;
|
||||
|
||||
const auto integral_cycles = cycles.as_integral();
|
||||
@@ -25,7 +30,9 @@ void Line::advance_writer(HalfCycles cycles) {
|
||||
transmission_extra_ -= integral_cycles;
|
||||
if(transmission_extra_ <= 0) {
|
||||
transmission_extra_ = 0;
|
||||
update_delegate(level_);
|
||||
if constexpr (!include_clock) {
|
||||
update_delegate(level_);
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
@@ -38,12 +45,17 @@ void Line::advance_writer(HalfCycles cycles) {
|
||||
auto iterator = events_.begin() + 1;
|
||||
while(iterator != events_.end() && iterator->type != Event::Delay) {
|
||||
level_ = iterator->type == Event::SetHigh;
|
||||
if constexpr(include_clock) {
|
||||
update_delegate(level_);
|
||||
}
|
||||
++iterator;
|
||||
}
|
||||
events_.erase(events_.begin(), iterator);
|
||||
|
||||
if(old_level != level_) {
|
||||
update_delegate(old_level);
|
||||
if constexpr (!include_clock) {
|
||||
if(old_level != level_) {
|
||||
update_delegate(old_level);
|
||||
}
|
||||
}
|
||||
|
||||
// Book enough extra time for the read delegate to be posted
|
||||
@@ -60,7 +72,8 @@ void Line::advance_writer(HalfCycles cycles) {
|
||||
}
|
||||
}
|
||||
|
||||
void Line::write(bool level) {
|
||||
template <bool include_clock>
|
||||
void Line<include_clock>::write(bool level) {
|
||||
if(!events_.empty()) {
|
||||
events_.emplace_back();
|
||||
events_.back().type = level ? Event::SetHigh : Event::SetLow;
|
||||
@@ -70,7 +83,8 @@ void Line::write(bool level) {
|
||||
}
|
||||
}
|
||||
|
||||
void Line::write(HalfCycles cycles, int count, int levels) {
|
||||
template <bool include_clock>
|
||||
template <bool lsb_first, typename IntT> void Line<include_clock>::write_internal(HalfCycles cycles, int count, IntT levels) {
|
||||
remaining_delays_ += count * cycles.as_integral();
|
||||
|
||||
auto event = events_.size();
|
||||
@@ -78,63 +92,122 @@ void Line::write(HalfCycles cycles, int count, int levels) {
|
||||
while(count--) {
|
||||
events_[event].type = Event::Delay;
|
||||
events_[event].delay = int(cycles.as_integral());
|
||||
events_[event+1].type = (levels&1) ? Event::SetHigh : Event::SetLow;
|
||||
levels >>= 1;
|
||||
IntT bit;
|
||||
if constexpr (lsb_first) {
|
||||
bit = levels & 1;
|
||||
levels >>= 1;
|
||||
} else {
|
||||
constexpr auto top_bit = IntT(0x80) << ((sizeof(IntT) - 1) * 8);
|
||||
bit = levels & top_bit;
|
||||
levels <<= 1;
|
||||
}
|
||||
|
||||
events_[event+1].type = bit ? Event::SetHigh : Event::SetLow;
|
||||
event += 2;
|
||||
}
|
||||
}
|
||||
|
||||
void Line::reset_writing() {
|
||||
template <bool include_clock>
|
||||
void Line<include_clock>::write(HalfCycles cycles, int count, int levels) {
|
||||
write_internal<true, int>(cycles, count, levels);
|
||||
}
|
||||
|
||||
template <bool include_clock>
|
||||
template <bool lsb_first, typename IntT> void Line<include_clock>::write(HalfCycles cycles, IntT value) {
|
||||
write_internal<lsb_first, IntT>(cycles, 8 * sizeof(IntT), value);
|
||||
}
|
||||
|
||||
template <bool include_clock>
|
||||
void Line<include_clock>::reset_writing() {
|
||||
remaining_delays_ = 0;
|
||||
events_.clear();
|
||||
}
|
||||
|
||||
bool Line::read() const {
|
||||
template <bool include_clock>
|
||||
bool Line<include_clock>::read() const {
|
||||
return level_;
|
||||
}
|
||||
|
||||
void Line::set_read_delegate(ReadDelegate *delegate, Storage::Time bit_length) {
|
||||
template <bool include_clock>
|
||||
void Line<include_clock>::set_read_delegate(ReadDelegate *delegate, Storage::Time bit_length) {
|
||||
read_delegate_ = delegate;
|
||||
read_delegate_bit_length_ = bit_length;
|
||||
read_delegate_bit_length_.simplify();
|
||||
write_cycles_since_delegate_call_ = 0;
|
||||
if constexpr (!include_clock) {
|
||||
assert(bit_length > Storage::Time(0));
|
||||
read_delegate_bit_length_ = bit_length;
|
||||
read_delegate_bit_length_.simplify();
|
||||
write_cycles_since_delegate_call_ = 0;
|
||||
}
|
||||
}
|
||||
|
||||
void Line::update_delegate(bool level) {
|
||||
template <bool include_clock>
|
||||
void Line<include_clock>::update_delegate(bool level) {
|
||||
// Exit early if there's no delegate, or if the delegate is waiting for
|
||||
// zero and this isn't zero.
|
||||
if(!read_delegate_) return;
|
||||
|
||||
const int cycles_to_forward = write_cycles_since_delegate_call_;
|
||||
write_cycles_since_delegate_call_ = 0;
|
||||
if(level && read_delegate_phase_ == ReadDelegatePhase::WaitingForZero) return;
|
||||
if constexpr (!include_clock) {
|
||||
const int cycles_to_forward = write_cycles_since_delegate_call_;
|
||||
write_cycles_since_delegate_call_ = 0;
|
||||
if(level && read_delegate_phase_ == ReadDelegatePhase::WaitingForZero) return;
|
||||
|
||||
// Deal with a transition out of waiting-for-zero mode by seeding time left
|
||||
// in bit at half a bit.
|
||||
if(read_delegate_phase_ == ReadDelegatePhase::WaitingForZero) {
|
||||
time_left_in_bit_ = read_delegate_bit_length_;
|
||||
time_left_in_bit_.clock_rate <<= 1;
|
||||
read_delegate_phase_ = ReadDelegatePhase::Serialising;
|
||||
}
|
||||
|
||||
// Forward as many bits as occur.
|
||||
Storage::Time time_left(cycles_to_forward, int(clock_rate_.as_integral()));
|
||||
const int bit = level ? 1 : 0;
|
||||
int bits = 0;
|
||||
while(time_left >= time_left_in_bit_) {
|
||||
++bits;
|
||||
if(!read_delegate_->serial_line_did_produce_bit(this, bit)) {
|
||||
read_delegate_phase_ = ReadDelegatePhase::WaitingForZero;
|
||||
if(bit) return;
|
||||
// Deal with a transition out of waiting-for-zero mode by seeding time left
|
||||
// in bit at half a bit.
|
||||
if(read_delegate_phase_ == ReadDelegatePhase::WaitingForZero) {
|
||||
time_left_in_bit_ = read_delegate_bit_length_;
|
||||
time_left_in_bit_.clock_rate <<= 1;
|
||||
read_delegate_phase_ = ReadDelegatePhase::Serialising;
|
||||
}
|
||||
|
||||
time_left -= time_left_in_bit_;
|
||||
time_left_in_bit_ = read_delegate_bit_length_;
|
||||
// Forward as many bits as occur.
|
||||
Storage::Time time_left(cycles_to_forward, int(clock_rate_.as_integral()));
|
||||
const int bit = level ? 1 : 0;
|
||||
int bits = 0;
|
||||
while(time_left >= time_left_in_bit_) {
|
||||
++bits;
|
||||
if(!read_delegate_->serial_line_did_produce_bit(this, bit)) {
|
||||
read_delegate_phase_ = ReadDelegatePhase::WaitingForZero;
|
||||
if(bit) return;
|
||||
}
|
||||
|
||||
time_left -= time_left_in_bit_;
|
||||
time_left_in_bit_ = read_delegate_bit_length_;
|
||||
}
|
||||
time_left_in_bit_ -= time_left;
|
||||
} else {
|
||||
read_delegate_->serial_line_did_produce_bit(this, level);
|
||||
}
|
||||
time_left_in_bit_ -= time_left;
|
||||
}
|
||||
|
||||
Cycles::IntType Line::minimum_write_cycles_for_read_delegate_bit() {
|
||||
template <bool include_clock>
|
||||
Cycles::IntType Line<include_clock>::minimum_write_cycles_for_read_delegate_bit() {
|
||||
if(!read_delegate_) return 0;
|
||||
return 1 + (read_delegate_bit_length_ * unsigned(clock_rate_.as_integral())).get<int>();
|
||||
return 1 + (read_delegate_bit_length_ * unsigned(clock_rate_.as_integral())).template get<int>();
|
||||
}
|
||||
|
||||
//
|
||||
// Explicitly instantiate the meaningful instances of templates above;
|
||||
// this class uses templates primarily to keep the interface compact and
|
||||
// to take advantage of constexpr functionality selection, not so as
|
||||
// to be generic.
|
||||
//
|
||||
|
||||
template class Serial::Line<true>;
|
||||
template class Serial::Line<false>;
|
||||
|
||||
template void Line<true>::write<true, uint8_t>(HalfCycles, uint8_t);
|
||||
template void Line<true>::write<false, uint8_t>(HalfCycles, uint8_t);
|
||||
template void Line<true>::write<true, uint16_t>(HalfCycles, uint16_t);
|
||||
template void Line<true>::write<false, uint16_t>(HalfCycles, uint16_t);
|
||||
template void Line<true>::write<true, uint32_t>(HalfCycles, uint32_t);
|
||||
template void Line<true>::write<false, uint32_t>(HalfCycles, uint32_t);
|
||||
template void Line<true>::write<true, uint64_t>(HalfCycles, uint64_t);
|
||||
template void Line<true>::write<false, uint64_t>(HalfCycles, uint64_t);
|
||||
|
||||
template void Line<false>::write<true, uint8_t>(HalfCycles, uint8_t);
|
||||
template void Line<false>::write<false, uint8_t>(HalfCycles, uint8_t);
|
||||
template void Line<false>::write<true, uint16_t>(HalfCycles, uint16_t);
|
||||
template void Line<false>::write<false, uint16_t>(HalfCycles, uint16_t);
|
||||
template void Line<false>::write<true, uint32_t>(HalfCycles, uint32_t);
|
||||
template void Line<false>::write<false, uint32_t>(HalfCycles, uint32_t);
|
||||
template void Line<false>::write<true, uint64_t>(HalfCycles, uint64_t);
|
||||
template void Line<false>::write<false, uint64_t>(HalfCycles, uint64_t);
|
||||
|
||||
@@ -17,25 +17,42 @@
|
||||
namespace Serial {
|
||||
|
||||
/*!
|
||||
@c Line connects a single reader and a single writer, allowing timestamped events to be
|
||||
published and consumed, potentially with a clock conversion in between. It allows line
|
||||
levels to be written and read in larger collections.
|
||||
Models one of two connections, either:
|
||||
|
||||
It is assumed that the owner of the reader and writer will ensure that the reader will never
|
||||
get ahead of the writer. If the writer posts events behind the reader they will simply be
|
||||
given instanteous effect.
|
||||
(i) a plain single-line serial; or
|
||||
(ii) a two-line data + clock.
|
||||
|
||||
In both cases connects a single reader to a single writer.
|
||||
|
||||
When operating as a single-line serial connection:
|
||||
|
||||
Provides a mechanism for the writer to enqueue levels arbitrarily far
|
||||
ahead of the current time, which are played back only as the
|
||||
write queue advances. Permits the reader and writer to work at
|
||||
different clock rates, and provides a virtual delegate protocol with
|
||||
start bit detection.
|
||||
|
||||
Can alternatively be used by reader and/or writer only in immediate
|
||||
mode, getting or setting the current level now, without the actor on
|
||||
the other end having to have made the same decision.
|
||||
|
||||
When operating as a two-line connection:
|
||||
|
||||
Implies a clock over enqueued data and provides the reader with
|
||||
all enqueued bits at appropriate times.
|
||||
*/
|
||||
class Line {
|
||||
template <bool include_clock> class Line {
|
||||
public:
|
||||
void set_writer_clock_rate(HalfCycles clock_rate);
|
||||
|
||||
/// Advances the read position by @c cycles relative to the writer's
|
||||
/// clock rate.
|
||||
void advance_writer(HalfCycles cycles);
|
||||
|
||||
/// Sets the line to @c level.
|
||||
/// Sets the line to @c level instantaneously.
|
||||
void write(bool level);
|
||||
|
||||
/// @returns The instantaneous level of this line.
|
||||
bool read() const;
|
||||
|
||||
/// Sets the denominator for the between levels for any data enqueued
|
||||
/// via an @c write.
|
||||
void set_writer_clock_rate(HalfCycles clock_rate);
|
||||
|
||||
/// Enqueues @c count level changes, the first occurring immediately
|
||||
/// after the final event currently posted and each subsequent event
|
||||
/// occurring @c cycles after the previous. An additional gap of @c cycles
|
||||
@@ -44,6 +61,10 @@ class Line {
|
||||
/// relative to the writer's clock rate.
|
||||
void write(HalfCycles cycles, int count, int levels);
|
||||
|
||||
/// Enqueus every bit from @c value as per the rules of write(HalfCycles, int, int),
|
||||
/// either in LSB or MSB order as per the @c lsb_first template flag.
|
||||
template <bool lsb_first, typename IntT> void write(HalfCycles cycles, IntT value);
|
||||
|
||||
/// @returns the number of cycles until currently enqueued write data is exhausted.
|
||||
forceinline HalfCycles write_data_time_remaining() const {
|
||||
return HalfCycles(remaining_delays_);
|
||||
@@ -55,25 +76,36 @@ class Line {
|
||||
return HalfCycles(remaining_delays_ + transmission_extra_);
|
||||
}
|
||||
|
||||
/// Advances the read position by @c cycles relative to the writer's
|
||||
/// clock rate.
|
||||
void advance_writer(HalfCycles cycles);
|
||||
|
||||
/// Eliminates all future write states, leaving the output at whatever it is now.
|
||||
void reset_writing();
|
||||
|
||||
/// @returns The instantaneous level of this line.
|
||||
bool read() const;
|
||||
|
||||
struct ReadDelegate {
|
||||
virtual bool serial_line_did_produce_bit(Line *line, int bit) = 0;
|
||||
};
|
||||
/*!
|
||||
Sets a read delegate, which will receive samples of the output level every
|
||||
@c bit_lengths of a second apart subject to a state machine:
|
||||
Sets a read delegate.
|
||||
|
||||
* initially no bits will be delivered;
|
||||
* when a zero level is first detected, the line will wait half a bit's length, then start
|
||||
sampling at single-bit intervals, passing each bit to the delegate while it returns @c true;
|
||||
* as soon as the delegate returns @c false, the line will return to the initial state.
|
||||
Single line serial connection:
|
||||
|
||||
The delegate will receive samples of the output level every
|
||||
@c bit_lengths of a second apart subject to a state machine:
|
||||
|
||||
* initially no bits will be delivered;
|
||||
* when a zero level is first detected, the line will wait half a bit's length, then start
|
||||
sampling at single-bit intervals, passing each bit to the delegate while it returns @c true;
|
||||
* as soon as the delegate returns @c false, the line will return to the initial state.
|
||||
|
||||
Two-line clock + data connection:
|
||||
|
||||
The delegate will receive every bit that has been enqueued, spaced as nominated
|
||||
by the writer. @c bit_length is ignored, as is the return result of
|
||||
@c ReadDelegate::serial_line_did_produce_bit.
|
||||
*/
|
||||
void set_read_delegate(ReadDelegate *delegate, Storage::Time bit_length);
|
||||
void set_read_delegate(ReadDelegate *delegate, Storage::Time bit_length = Storage::Time());
|
||||
|
||||
private:
|
||||
struct Event {
|
||||
@@ -98,6 +130,9 @@ class Line {
|
||||
|
||||
void update_delegate(bool level);
|
||||
HalfCycles::IntType minimum_write_cycles_for_read_delegate_bit();
|
||||
|
||||
template <bool lsb_first, typename IntT> void
|
||||
write_internal(HalfCycles, int, IntT);
|
||||
};
|
||||
|
||||
/*!
|
||||
|
||||
@@ -11,11 +11,11 @@
|
||||
using namespace Concurrency;
|
||||
|
||||
AsyncTaskQueue::AsyncTaskQueue()
|
||||
#ifndef __APPLE__
|
||||
#ifndef USE_GCD
|
||||
: should_destruct_(false)
|
||||
#endif
|
||||
{
|
||||
#ifdef __APPLE__
|
||||
#ifdef USE_GCD
|
||||
serial_dispatch_queue_ = dispatch_queue_create("com.thomasharte.clocksignal.asyntaskqueue", DISPATCH_QUEUE_SERIAL);
|
||||
#else
|
||||
thread_ = std::make_unique<std::thread>([this]() {
|
||||
@@ -44,7 +44,7 @@ AsyncTaskQueue::AsyncTaskQueue()
|
||||
}
|
||||
|
||||
AsyncTaskQueue::~AsyncTaskQueue() {
|
||||
#ifdef __APPLE__
|
||||
#ifdef USE_GCD
|
||||
flush();
|
||||
dispatch_release(serial_dispatch_queue_);
|
||||
serial_dispatch_queue_ = nullptr;
|
||||
@@ -57,7 +57,7 @@ AsyncTaskQueue::~AsyncTaskQueue() {
|
||||
}
|
||||
|
||||
void AsyncTaskQueue::enqueue(std::function<void(void)> function) {
|
||||
#ifdef __APPLE__
|
||||
#ifdef USE_GCD
|
||||
dispatch_async(serial_dispatch_queue_, ^{function();});
|
||||
#else
|
||||
std::lock_guard lock(queue_mutex_);
|
||||
@@ -67,7 +67,7 @@ void AsyncTaskQueue::enqueue(std::function<void(void)> function) {
|
||||
}
|
||||
|
||||
void AsyncTaskQueue::flush() {
|
||||
#ifdef __APPLE__
|
||||
#ifdef USE_GCD
|
||||
dispatch_sync(serial_dispatch_queue_, ^{});
|
||||
#else
|
||||
auto flush_mutex = std::make_shared<std::mutex>();
|
||||
|
||||
@@ -16,8 +16,9 @@
|
||||
#include <memory>
|
||||
#include <thread>
|
||||
|
||||
#ifdef __APPLE__
|
||||
#if defined(__APPLE__) && !defined(IGNORE_APPLE)
|
||||
#include <dispatch/dispatch.h>
|
||||
#define USE_GCD
|
||||
#endif
|
||||
|
||||
namespace Concurrency {
|
||||
@@ -47,7 +48,7 @@ class AsyncTaskQueue {
|
||||
void flush();
|
||||
|
||||
private:
|
||||
#ifdef __APPLE__
|
||||
#ifdef USE_GCD
|
||||
dispatch_queue_t serial_dispatch_queue_;
|
||||
#else
|
||||
std::unique_ptr<std::thread> thread_;
|
||||
|
||||
@@ -9,6 +9,7 @@
|
||||
#ifndef Joystick_hpp
|
||||
#define Joystick_hpp
|
||||
|
||||
#include <cstddef>
|
||||
#include <vector>
|
||||
|
||||
namespace Inputs {
|
||||
@@ -35,7 +36,10 @@ class Joystick {
|
||||
// Fire buttons.
|
||||
Fire,
|
||||
// Other labelled keys.
|
||||
Key
|
||||
Key,
|
||||
|
||||
// The maximum value this enum can contain.
|
||||
Max = Key
|
||||
};
|
||||
const Type type;
|
||||
|
||||
|
||||
@@ -8,6 +8,8 @@
|
||||
|
||||
#include "Keyboard.hpp"
|
||||
|
||||
#include <cstddef>
|
||||
|
||||
using namespace Inputs;
|
||||
|
||||
Keyboard::Keyboard(const std::set<Key> &essential_modifiers) : essential_modifiers_(essential_modifiers) {
|
||||
|
||||
24
InstructionSets/AccessType.hpp
Normal file
24
InstructionSets/AccessType.hpp
Normal file
@@ -0,0 +1,24 @@
|
||||
//
|
||||
// AccessType.h
|
||||
// Clock Signal
|
||||
//
|
||||
// Created by Thomas Harte on 16/01/21.
|
||||
// Copyright © 2021 Thomas Harte. All rights reserved.
|
||||
//
|
||||
|
||||
#ifndef AccessType_h
|
||||
#define AccessType_h
|
||||
|
||||
namespace InstructionSet {
|
||||
|
||||
enum class AccessType {
|
||||
None,
|
||||
Read,
|
||||
Write,
|
||||
ReadModifyWrite
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
|
||||
#endif /* AccessType_h */
|
||||
200
InstructionSets/CachingExecutor.hpp
Normal file
200
InstructionSets/CachingExecutor.hpp
Normal file
@@ -0,0 +1,200 @@
|
||||
//
|
||||
// CachingExecutor.hpp
|
||||
// Clock Signal
|
||||
//
|
||||
// Created by Thomas Harte on 16/01/2021.
|
||||
// Copyright © 2021 Thomas Harte. All rights reserved.
|
||||
//
|
||||
|
||||
#ifndef CachingExecutor_hpp
|
||||
#define CachingExecutor_hpp
|
||||
|
||||
#include "../Numeric/Sizes.hpp"
|
||||
|
||||
#include <array>
|
||||
#include <cstdint>
|
||||
#include <limits>
|
||||
#include <list>
|
||||
#include <map>
|
||||
#include <queue>
|
||||
#include <unordered_map>
|
||||
|
||||
namespace InstructionSet {
|
||||
|
||||
/*!
|
||||
A caching executor makes use of an instruction set-specific executor to cache 'performers' (i.e. function pointers)
|
||||
that result from decoding.
|
||||
|
||||
In other words, it's almost a JIT compiler, but producing threaded code (in the Forth sense) and then incurring whatever
|
||||
costs sit behind using the C ABI for calling. Since there'll always be exactly one parameter, being the specific executor,
|
||||
hopefully the calling costs are acceptable.
|
||||
|
||||
Intended usage is for specific executors to subclass from this and declare it a friend.
|
||||
|
||||
TODO: determine promises re: interruption, amongst other things.
|
||||
*/
|
||||
template <
|
||||
/// Indicates the Executor for this platform.
|
||||
typename Executor,
|
||||
/// Indicates the greatest value the program counter might take.
|
||||
uint64_t max_address,
|
||||
/// Indicates the maximum number of potential performers that will be provided.
|
||||
uint64_t max_performer_count,
|
||||
/// Provides the type of Instruction to expect.
|
||||
typename InstructionType,
|
||||
/// Indicates whether instructions should be treated as ephemeral or included in the cache.
|
||||
bool retain_instructions
|
||||
> class CachingExecutor {
|
||||
public:
|
||||
using Performer = void (Executor::*)();
|
||||
using PerformerIndex = typename MinIntTypeValue<max_performer_count>::type;
|
||||
using ProgramCounterType = typename MinIntTypeValue<max_address>::type;
|
||||
|
||||
// MARK: - Parser call-ins.
|
||||
|
||||
void announce_overflow(ProgramCounterType) {
|
||||
/*
|
||||
Should be impossible for now; this is intended to provide information
|
||||
when page caching.
|
||||
*/
|
||||
}
|
||||
void announce_instruction(ProgramCounterType, InstructionType instruction) {
|
||||
// Dutifully map the instruction to a performer and keep it.
|
||||
program_.push_back(static_cast<Executor *>(this)->action_for(instruction));
|
||||
|
||||
if constexpr (retain_instructions) {
|
||||
// TODO.
|
||||
}
|
||||
}
|
||||
|
||||
protected:
|
||||
|
||||
// Storage for the statically-allocated list of performers. It's a bit more
|
||||
// work for executors to fill this array, but subsequently performers can be
|
||||
// indexed by array position, which is a lot more compact than a generic pointer.
|
||||
std::array<Performer, max_performer_count+1> performers_;
|
||||
ProgramCounterType program_counter_;
|
||||
|
||||
/*!
|
||||
Moves the current point of execution to @c address, updating necessary performer caches
|
||||
and doing any translation as is necessary.
|
||||
*/
|
||||
void set_program_counter(ProgramCounterType address) {
|
||||
// Set flag to terminate any inner loop currently running through
|
||||
// previously-parsed content.
|
||||
has_branched_ = true;
|
||||
program_counter_ = address;
|
||||
|
||||
// Temporary implementation: just interpret.
|
||||
program_.clear();
|
||||
program_index_ = 0;
|
||||
static_cast<Executor *>(this)->parse(address, ProgramCounterType(max_address));
|
||||
|
||||
// const auto page = find_page(address);
|
||||
// const auto entry = page->entry_points.find(address);
|
||||
// if(entry == page->entry_points.end()) {
|
||||
// // Requested segment wasn't found; check whether it was
|
||||
// // within the recently translated list and otherwise
|
||||
// // translate it.
|
||||
// }
|
||||
}
|
||||
|
||||
/*!
|
||||
Indicates whether the processor is currently 'stopped', i.e. whether all attempts to run
|
||||
should produce no activity. Some processors have such a state when waiting for
|
||||
interrupts or for a reset.
|
||||
*/
|
||||
void set_is_stopped(bool) {}
|
||||
|
||||
/*!
|
||||
Executes up to the next branch.
|
||||
*/
|
||||
void run_to_branch() {
|
||||
has_branched_ = false;
|
||||
for(auto index: program_) {
|
||||
const auto performer = performers_[index];
|
||||
(static_cast<Executor *>(this)->*performer)();
|
||||
if(has_branched_) break;
|
||||
}
|
||||
}
|
||||
|
||||
/*!
|
||||
Runs for @c duration; the intention is that subclasses provide a method
|
||||
that is clear about units, and call this to count down in whatever units they
|
||||
count down in.
|
||||
*/
|
||||
void run_for(int duration) {
|
||||
remaining_duration_ += duration;
|
||||
|
||||
while(remaining_duration_ > 0) {
|
||||
has_branched_ = false;
|
||||
Executor *const executor = static_cast<Executor *>(this);
|
||||
while(remaining_duration_ > 0 && !has_branched_) {
|
||||
const auto performer = performers_[program_[program_index_]];
|
||||
++program_index_;
|
||||
|
||||
(executor->*performer)();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/*!
|
||||
Should be called by a specific executor to subtract from the remaining
|
||||
running duration.
|
||||
*/
|
||||
inline void subtract_duration(int duration) {
|
||||
remaining_duration_ -= duration;
|
||||
}
|
||||
|
||||
private:
|
||||
bool has_branched_ = false;
|
||||
int remaining_duration_ = 0;
|
||||
std::vector<PerformerIndex> program_;
|
||||
size_t program_index_ = 0;
|
||||
|
||||
/* TODO: almost below here can be shoved off into an LRUCache object, or similar. */
|
||||
|
||||
// static constexpr size_t max_cached_pages = 64;
|
||||
|
||||
// struct Page {
|
||||
// std::map<ProgramCounterType, PerformerIndex> entry_points;
|
||||
|
||||
// TODO: can I statically these two? Should I?
|
||||
// std::vector<PerformerIndex> actions_;
|
||||
// std::vector<typename std::enable_if<!std::is_same<InstructionType, void>::value, InstructionType>::type> instructions_;
|
||||
// };
|
||||
// std::array<Page, max_cached_pages> pages_;
|
||||
|
||||
// Maps from page numbers to pages.
|
||||
// std::unordered_map<ProgramCounterType, Page *> cached_pages_;
|
||||
|
||||
// Maintains an LRU of recently-used pages in case of a need for reuse.
|
||||
// std::list<ProgramCounterType> touched_pages_;
|
||||
|
||||
/*!
|
||||
Finds or creates the page that contains @c address.
|
||||
*/
|
||||
/* Page *find_page(ProgramCounterType address) {
|
||||
// TODO: are 1kb pages always appropriate? Is 64 the correct amount to keep?
|
||||
const auto page_address = ProgramCounterType(address >> 10);
|
||||
|
||||
auto page = cached_pages_.find(page_address);
|
||||
if(page == cached_pages_.end()) {
|
||||
// Page wasn't found; either allocate a new one or
|
||||
// reuse one that already exists.
|
||||
if(cached_pages_.size() == max_cached_pages) {
|
||||
|
||||
} else {
|
||||
|
||||
}
|
||||
} else {
|
||||
// Page was found; LRU shuffle it.
|
||||
}
|
||||
|
||||
return nullptr;
|
||||
}*/
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif /* CachingExecutor_hpp */
|
||||
89
InstructionSets/Disassembler.hpp
Normal file
89
InstructionSets/Disassembler.hpp
Normal file
@@ -0,0 +1,89 @@
|
||||
//
|
||||
// Disassembler.hpp
|
||||
// Clock Signal
|
||||
//
|
||||
// Created by Thomas Harte on 26/01/2021.
|
||||
// Copyright © 2021 Thomas Harte. All rights reserved.
|
||||
//
|
||||
|
||||
#ifndef Disassembler_hpp
|
||||
#define Disassembler_hpp
|
||||
|
||||
#include "../Numeric/Sizes.hpp"
|
||||
|
||||
#include <list>
|
||||
#include <map>
|
||||
#include <set>
|
||||
|
||||
namespace InstructionSet {
|
||||
|
||||
template <
|
||||
/// Indicates the Parser for this platform.
|
||||
template<typename, bool> class ParserType,
|
||||
/// Indicates the greatest value the program counter might take.
|
||||
uint64_t max_address,
|
||||
/// Provides the type of Instruction to expect.
|
||||
typename InstructionType,
|
||||
/// Provides the storage size used for memory.
|
||||
typename MemoryWord,
|
||||
/// Provides the addressing range of memory.
|
||||
typename AddressType
|
||||
> class Disassembler {
|
||||
public:
|
||||
using ProgramCounterType = typename MinIntTypeValue<max_address>::type;
|
||||
|
||||
/*!
|
||||
Adds the result of disassembling @c memory which is @c length @c MemoryWords long from @c start_address
|
||||
to the current net total of instructions and recorded memory accesses.
|
||||
*/
|
||||
void disassemble(const MemoryWord *memory, ProgramCounterType location, ProgramCounterType length, ProgramCounterType start_address) {
|
||||
// TODO: possibly, move some of this stuff to instruction-set specific disassemblers, analogous to
|
||||
// the Executor's ownership of the Parser. That would allow handling of stateful parsing.
|
||||
ParserType<decltype(*this), true> parser;
|
||||
pending_entry_points_.push_back(start_address);
|
||||
entry_points_.insert(start_address);
|
||||
|
||||
while(!pending_entry_points_.empty()) {
|
||||
const auto next_entry_point = pending_entry_points_.front();
|
||||
pending_entry_points_.pop_front();
|
||||
|
||||
if(next_entry_point >= location) {
|
||||
parser.parse(*this, memory - location, next_entry_point & max_address, length + location);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
const std::map<ProgramCounterType, InstructionType> &instructions() const {
|
||||
return instructions_;
|
||||
}
|
||||
|
||||
const std::set<ProgramCounterType> &entry_points() const {
|
||||
return entry_points_;
|
||||
}
|
||||
|
||||
void announce_overflow(ProgramCounterType) {}
|
||||
void announce_instruction(ProgramCounterType address, InstructionType instruction) {
|
||||
instructions_[address] = instruction;
|
||||
}
|
||||
void add_entry(ProgramCounterType address) {
|
||||
if(entry_points_.find(address) == entry_points_.end()) {
|
||||
pending_entry_points_.push_back(address);
|
||||
entry_points_.insert(address);
|
||||
}
|
||||
}
|
||||
void add_access(AddressType address, AccessType access_type) {
|
||||
// TODO.
|
||||
(void)address;
|
||||
(void)access_type;
|
||||
}
|
||||
|
||||
private:
|
||||
std::map<ProgramCounterType, InstructionType> instructions_;
|
||||
std::set<ProgramCounterType> entry_points_;
|
||||
|
||||
std::list<ProgramCounterType> pending_entry_points_;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif /* Disassembler_h */
|
||||
282
InstructionSets/M50740/Decoder.cpp
Normal file
282
InstructionSets/M50740/Decoder.cpp
Normal file
@@ -0,0 +1,282 @@
|
||||
//
|
||||
// Decoder.cpp
|
||||
// Clock Signal
|
||||
//
|
||||
// Created by Thomas Harte on 15/01/21.
|
||||
// Copyright © 2021 Thomas Harte. All rights reserved.
|
||||
//
|
||||
|
||||
#include "Decoder.hpp"
|
||||
|
||||
#include <algorithm>
|
||||
|
||||
namespace InstructionSet {
|
||||
namespace M50740 {
|
||||
|
||||
Instruction Decoder::instrucion_for_opcode(uint8_t opcode) {
|
||||
switch(opcode) {
|
||||
default: return Instruction(opcode);
|
||||
|
||||
#define Map(opcode, operation, addressing_mode) case opcode: return Instruction(Operation::operation, AddressingMode::addressing_mode, opcode);
|
||||
|
||||
/* 0x00 – 0x0f */
|
||||
Map(0x00, BRK, Implied); Map(0x01, ORA, XIndirect);
|
||||
Map(0x02, JSR, ZeroPageIndirect); Map(0x03, BBS0, AccumulatorRelative);
|
||||
|
||||
Map(0x05, ORA, ZeroPage);
|
||||
Map(0x06, ASL, ZeroPage); Map(0x07, BBS0, ZeroPageRelative);
|
||||
|
||||
Map(0x08, PHP, Implied); Map(0x09, ORA, Immediate);
|
||||
Map(0x0a, ASL, Accumulator); Map(0x0b, SEB0, Accumulator);
|
||||
|
||||
Map(0x0d, ORA, Absolute);
|
||||
Map(0x0e, ASL, Absolute); Map(0x0f, SEB0, ZeroPage);
|
||||
|
||||
/* 0x10 – 0x1f */
|
||||
Map(0x10, BPL, Relative); Map(0x11, ORA, IndirectY);
|
||||
Map(0x12, CLT, Implied); Map(0x13, BBC0, AccumulatorRelative);
|
||||
|
||||
Map(0x15, ORA, ZeroPageX);
|
||||
Map(0x16, ASL, ZeroPageX); Map(0x17, BBC0, ZeroPageRelative);
|
||||
|
||||
Map(0x18, CLC, Implied); Map(0x19, ORA, AbsoluteY);
|
||||
Map(0x1a, DEC, Accumulator); Map(0x1b, CLB0, Accumulator);
|
||||
|
||||
Map(0x1d, ORA, AbsoluteX);
|
||||
Map(0x1e, ASL, AbsoluteX); Map(0x1f, CLB0, ZeroPage);
|
||||
|
||||
/* 0x20 – 0x2f */
|
||||
Map(0x20, JSR, Absolute); Map(0x21, AND, XIndirect);
|
||||
Map(0x22, JSR, SpecialPage); Map(0x23, BBS1, AccumulatorRelative);
|
||||
|
||||
Map(0x24, BIT, ZeroPage); Map(0x25, AND, ZeroPage);
|
||||
Map(0x26, ROL, ZeroPage); Map(0x27, BBS1, ZeroPageRelative);
|
||||
|
||||
Map(0x28, PLP, Implied); Map(0x29, AND, Immediate);
|
||||
Map(0x2a, ROL, Accumulator); Map(0x2b, SEB1, Accumulator);
|
||||
|
||||
Map(0x2c, BIT, Absolute); Map(0x2d, AND, Absolute);
|
||||
Map(0x2e, ROL, Absolute); Map(0x2f, SEB1, ZeroPage);
|
||||
|
||||
/* 0x30 – 0x3f */
|
||||
Map(0x30, BMI, Relative); Map(0x31, AND, IndirectY);
|
||||
Map(0x32, SET, Implied); Map(0x33, BBC1, AccumulatorRelative);
|
||||
|
||||
Map(0x35, AND, ZeroPageX);
|
||||
Map(0x36, ROL, ZeroPageX); Map(0x37, BBC1, ZeroPageRelative);
|
||||
|
||||
Map(0x38, SEC, Implied); Map(0x39, AND, AbsoluteY);
|
||||
Map(0x3a, INC, Accumulator); Map(0x3b, CLB1, Accumulator);
|
||||
|
||||
Map(0x3c, LDM, ImmediateZeroPage); Map(0x3d, AND, AbsoluteX);
|
||||
Map(0x3e, ROL, AbsoluteX); Map(0x3f, CLB1, ZeroPage);
|
||||
|
||||
/* 0x40 – 0x4f */
|
||||
Map(0x40, RTI, Implied); Map(0x41, EOR, XIndirect);
|
||||
Map(0x42, STP, Implied); Map(0x43, BBS2, AccumulatorRelative);
|
||||
|
||||
Map(0x44, COM, ZeroPage); Map(0x45, EOR, ZeroPage);
|
||||
Map(0x46, LSR, ZeroPage); Map(0x47, BBS2, ZeroPageRelative);
|
||||
|
||||
Map(0x48, PHA, Implied); Map(0x49, EOR, Immediate);
|
||||
Map(0x4a, LSR, Accumulator); Map(0x4b, SEB2, Accumulator);
|
||||
|
||||
Map(0x4c, JMP, Absolute); Map(0x4d, EOR, Absolute);
|
||||
Map(0x4e, LSR, Absolute); Map(0x4f, SEB2, ZeroPage);
|
||||
|
||||
/* 0x50 – 0x5f */
|
||||
Map(0x50, BVC, Relative); Map(0x51, EOR, IndirectY);
|
||||
Map(0x53, BBC2, AccumulatorRelative);
|
||||
|
||||
Map(0x55, EOR, ZeroPageX);
|
||||
Map(0x56, LSR, ZeroPageX); Map(0x57, BBC2, ZeroPageRelative);
|
||||
|
||||
Map(0x58, CLI, Implied); Map(0x59, EOR, AbsoluteY);
|
||||
Map(0x5b, CLB2, Accumulator);
|
||||
|
||||
Map(0x5d, EOR, AbsoluteX);
|
||||
Map(0x5e, LSR, AbsoluteX); Map(0x5f, CLB2, ZeroPage);
|
||||
|
||||
/* 0x60 – 0x6f */
|
||||
Map(0x60, RTS, Implied); Map(0x61, ADC, XIndirect);
|
||||
Map(0x63, BBS3, AccumulatorRelative);
|
||||
|
||||
Map(0x64, TST, ZeroPage); Map(0x65, ADC, ZeroPage);
|
||||
Map(0x66, ROR, ZeroPage); Map(0x67, BBS3, ZeroPageRelative);
|
||||
|
||||
Map(0x68, PLA, Implied); Map(0x69, ADC, Immediate);
|
||||
Map(0x6a, ROR, Accumulator); Map(0x6b, SEB3, Accumulator);
|
||||
|
||||
Map(0x6c, JMP, AbsoluteIndirect); Map(0x6d, ADC, Absolute);
|
||||
Map(0x6e, ROR, Absolute); Map(0x6f, SEB3, ZeroPage);
|
||||
|
||||
/* 0x70 – 0x7f */
|
||||
Map(0x70, BVS, Relative); Map(0x71, ADC, IndirectY);
|
||||
Map(0x73, BBC3, AccumulatorRelative);
|
||||
|
||||
Map(0x75, ADC, ZeroPageX);
|
||||
Map(0x76, ROR, ZeroPageX); Map(0x77, BBC3, ZeroPageRelative);
|
||||
|
||||
Map(0x78, SEI, Implied); Map(0x79, ADC, AbsoluteY);
|
||||
Map(0x7b, CLB3, Accumulator);
|
||||
|
||||
Map(0x7d, ADC, AbsoluteX);
|
||||
Map(0x7e, ROR, AbsoluteX); Map(0x7f, CLB3, ZeroPage);
|
||||
|
||||
/* 0x80 – 0x8f */
|
||||
Map(0x80, BRA, Relative); Map(0x81, STA, XIndirect);
|
||||
Map(0x82, RRF, ZeroPage); Map(0x83, BBS4, AccumulatorRelative);
|
||||
|
||||
Map(0x84, STY, ZeroPage); Map(0x85, STA, ZeroPage);
|
||||
Map(0x86, STX, ZeroPage); Map(0x87, BBS4, ZeroPageRelative);
|
||||
|
||||
Map(0x88, DEY, Implied);
|
||||
Map(0x8a, TXA, Implied); Map(0x8b, SEB4, Accumulator);
|
||||
|
||||
Map(0x8c, STY, Absolute); Map(0x8d, STA, Absolute);
|
||||
Map(0x8e, STX, Absolute); Map(0x8f, SEB4, ZeroPage);
|
||||
|
||||
/* 0x90 – 0x9f */
|
||||
Map(0x90, BCC, Relative); Map(0x91, STA, IndirectY);
|
||||
Map(0x93, BBC4, AccumulatorRelative);
|
||||
|
||||
Map(0x94, STY, ZeroPageX); Map(0x95, STA, ZeroPageX);
|
||||
Map(0x96, STX, ZeroPageX); Map(0x97, BBC4, ZeroPageRelative);
|
||||
|
||||
Map(0x98, TYA, Implied); Map(0x99, STA, AbsoluteY);
|
||||
Map(0x9a, TXS, Implied); Map(0x9b, CLB4, Accumulator);
|
||||
|
||||
Map(0x9d, ADC, AbsoluteX);
|
||||
Map(0x9f, CLB4, ZeroPage);
|
||||
|
||||
/* 0xa0 – 0xaf */
|
||||
Map(0xa0, LDY, Immediate); Map(0xa1, LDA, XIndirect);
|
||||
Map(0xa2, LDX, Immediate); Map(0xa3, BBS5, AccumulatorRelative);
|
||||
|
||||
Map(0xa4, LDY, ZeroPage); Map(0xa5, LDA, ZeroPage);
|
||||
Map(0xa6, LDX, ZeroPage); Map(0xa7, BBS5, ZeroPageRelative);
|
||||
|
||||
Map(0xa8, TAY, Implied); Map(0xa9, LDA, Immediate);
|
||||
Map(0xaa, TAX, Implied); Map(0xab, SEB5, Accumulator);
|
||||
|
||||
Map(0xac, LDY, Absolute); Map(0xad, LDA, Absolute);
|
||||
Map(0xae, LDX, Absolute); Map(0xaf, SEB5, ZeroPage);
|
||||
|
||||
/* 0xb0 – 0xbf */
|
||||
Map(0xb0, BCS, Relative); Map(0xb1, STA, IndirectY);
|
||||
Map(0xb2, JMP, ZeroPageIndirect); Map(0xb3, BBC5, AccumulatorRelative);
|
||||
|
||||
Map(0xb4, LDY, ZeroPageX); Map(0xb5, LDA, ZeroPageX);
|
||||
Map(0xb6, LDX, ZeroPageY); Map(0xb7, BBC5, ZeroPageRelative);
|
||||
|
||||
Map(0xb8, CLV, Implied); Map(0xb9, LDA, AbsoluteY);
|
||||
Map(0xba, TSX, Implied); Map(0xbb, CLB5, Accumulator);
|
||||
|
||||
Map(0xbc, LDY, AbsoluteX); Map(0xbd, LDA, AbsoluteX);
|
||||
Map(0xbe, LDX, AbsoluteY); Map(0xbf, CLB5, ZeroPage);
|
||||
|
||||
/* 0xc0 – 0xcf */
|
||||
Map(0xc0, CPY, Immediate); Map(0xc1, CMP, XIndirect);
|
||||
Map(0xc2, SLW, Implied); Map(0xc3, BBS6, AccumulatorRelative);
|
||||
|
||||
Map(0xc4, CPY, ZeroPage); Map(0xc5, CMP, ZeroPage);
|
||||
Map(0xc6, DEC, ZeroPage); Map(0xc7, BBS6, ZeroPageRelative);
|
||||
|
||||
Map(0xc8, INY, Implied); Map(0xc9, CMP, Immediate);
|
||||
Map(0xca, DEX, Implied); Map(0xcb, SEB6, Accumulator);
|
||||
|
||||
Map(0xcc, CPY, Absolute); Map(0xcd, CMP, Absolute);
|
||||
Map(0xce, DEC, Absolute); Map(0xcf, SEB6, ZeroPage);
|
||||
|
||||
/* 0xd0 – 0xdf */
|
||||
Map(0xd0, BNE, Relative); Map(0xd1, CMP, IndirectY);
|
||||
Map(0xd3, BBC6, AccumulatorRelative);
|
||||
|
||||
Map(0xd5, CMP, ZeroPageX);
|
||||
Map(0xd6, DEC, ZeroPageX); Map(0xd7, BBC6, ZeroPageRelative);
|
||||
|
||||
Map(0xd8, CLD, Implied); Map(0xd9, CMP, AbsoluteY);
|
||||
Map(0xdb, CLB6, Accumulator);
|
||||
|
||||
Map(0xdd, CMP, AbsoluteX);
|
||||
Map(0xde, DEC, AbsoluteX); Map(0xdf, CLB6, ZeroPage);
|
||||
|
||||
/* 0xe0 – 0xef */
|
||||
Map(0xe0, CPX, Immediate); Map(0xe1, SBC, XIndirect);
|
||||
Map(0xe2, FST, Implied); Map(0xe3, BBS7, AccumulatorRelative);
|
||||
|
||||
Map(0xe4, CPX, ZeroPage); Map(0xe5, SBC, ZeroPage);
|
||||
Map(0xe6, INC, ZeroPage); Map(0xe7, BBS7, ZeroPageRelative);
|
||||
|
||||
Map(0xe8, INX, Implied); Map(0xe9, SBC, Immediate);
|
||||
Map(0xea, NOP, Implied); Map(0xeb, SEB7, Accumulator);
|
||||
|
||||
Map(0xec, CPX, Absolute); Map(0xed, SBC, Absolute);
|
||||
Map(0xee, INC, Absolute); Map(0xef, SEB7, ZeroPage);
|
||||
|
||||
/* 0xf0 – 0xff */
|
||||
Map(0xf0, BEQ, Relative); Map(0xf1, SBC, IndirectY);
|
||||
Map(0xf3, BBC7, AccumulatorRelative);
|
||||
|
||||
Map(0xf5, SBC, ZeroPageX);
|
||||
Map(0xf6, INC, ZeroPageX); Map(0xf7, BBC7, ZeroPageRelative);
|
||||
|
||||
Map(0xf8, SED, Implied); Map(0xf9, SBC, AbsoluteY);
|
||||
Map(0xfb, CLB7, Accumulator);
|
||||
|
||||
Map(0xfd, SBC, AbsoluteX);
|
||||
Map(0xfe, INC, AbsoluteX); Map(0xff, CLB7, ZeroPage);
|
||||
|
||||
#undef Map
|
||||
}
|
||||
}
|
||||
|
||||
std::pair<int, InstructionSet::M50740::Instruction> Decoder::decode(const uint8_t *source, size_t length) {
|
||||
const uint8_t *const end = source + length;
|
||||
|
||||
if(phase_ == Phase::Instruction && source != end) {
|
||||
const uint8_t instruction = *source;
|
||||
++source;
|
||||
++consumed_;
|
||||
|
||||
// Determine the instruction in hand, and finish now if its undefined.
|
||||
instr_ = instrucion_for_opcode(instruction);
|
||||
if(instr_.operation == Operation::Invalid) {
|
||||
consumed_ = 0;
|
||||
return std::make_pair(1, instr_);
|
||||
}
|
||||
|
||||
// Obtain an operand size and roll onto the correct phase.
|
||||
operand_size_ = size(instr_.addressing_mode);
|
||||
phase_ = operand_size_ ? Phase::AwaitingOperand : Phase::ReadyToPost;
|
||||
operand_bytes_ = 0;
|
||||
}
|
||||
|
||||
if(phase_ == Phase::AwaitingOperand && source != end) {
|
||||
const int outstanding_bytes = operand_size_ - operand_bytes_;
|
||||
const int bytes_to_consume = std::min(int(end - source), outstanding_bytes);
|
||||
|
||||
consumed_ += bytes_to_consume;
|
||||
source += bytes_to_consume;
|
||||
operand_bytes_ += bytes_to_consume;
|
||||
|
||||
if(operand_size_ == operand_bytes_) {
|
||||
phase_ = Phase::ReadyToPost;
|
||||
} else {
|
||||
return std::make_pair(-(operand_size_ - operand_bytes_), Instruction());
|
||||
}
|
||||
}
|
||||
|
||||
if(phase_ == Phase::ReadyToPost) {
|
||||
const auto result = std::make_pair(consumed_, instr_);
|
||||
consumed_ = 0;
|
||||
phase_ = Phase::Instruction;
|
||||
return result;
|
||||
}
|
||||
|
||||
// Decoding didn't complete, without it being clear how many more bytes are required.
|
||||
return std::make_pair(0, Instruction());
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
39
InstructionSets/M50740/Decoder.hpp
Normal file
39
InstructionSets/M50740/Decoder.hpp
Normal file
@@ -0,0 +1,39 @@
|
||||
//
|
||||
// Decoder.hpp
|
||||
// Clock Signal
|
||||
//
|
||||
// Created by Thomas Harte on 15/01/21.
|
||||
// Copyright © 2021 Thomas Harte. All rights reserved.
|
||||
//
|
||||
|
||||
#ifndef InstructionSets_M50740_Decoder_hpp
|
||||
#define InstructionSets_M50740_Decoder_hpp
|
||||
|
||||
#include "Instruction.hpp"
|
||||
|
||||
#include <cstddef>
|
||||
#include <utility>
|
||||
|
||||
namespace InstructionSet {
|
||||
namespace M50740 {
|
||||
|
||||
class Decoder {
|
||||
public:
|
||||
std::pair<int, Instruction> decode(const uint8_t *source, size_t length);
|
||||
Instruction instrucion_for_opcode(uint8_t opcode);
|
||||
|
||||
private:
|
||||
enum class Phase {
|
||||
Instruction,
|
||||
AwaitingOperand,
|
||||
ReadyToPost
|
||||
} phase_ = Phase::Instruction;
|
||||
int operand_size_ = 0, operand_bytes_ = 0;
|
||||
int consumed_ = 0;
|
||||
Instruction instr_;
|
||||
};
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
#endif /* InstructionSets_M50740_Decoder_hpp */
|
||||
838
InstructionSets/M50740/Executor.cpp
Normal file
838
InstructionSets/M50740/Executor.cpp
Normal file
@@ -0,0 +1,838 @@
|
||||
//
|
||||
// Executor.hpp
|
||||
// Clock Signal
|
||||
//
|
||||
// Created by Thomas Harte on 16/1/21.
|
||||
// Copyright © 2021 Thomas Harte. All rights reserved.
|
||||
//
|
||||
|
||||
#include "Executor.hpp"
|
||||
|
||||
#include <algorithm>
|
||||
#include <cassert>
|
||||
#include <cstring>
|
||||
|
||||
#include "../../Machines/Utility/MemoryFuzzer.hpp"
|
||||
|
||||
#define LOG_PREFIX "[M50740] "
|
||||
#include "../../Outputs/Log.hpp"
|
||||
|
||||
using namespace InstructionSet::M50740;
|
||||
|
||||
namespace {
|
||||
constexpr int port_remap[] = {0, 1, 2, 0, 3};
|
||||
}
|
||||
|
||||
Executor::Executor(PortHandler &port_handler) : port_handler_(port_handler) {
|
||||
// Cut down the list of all generated performers to those the processor actually uses, and install that
|
||||
// for future referencing by action_for.
|
||||
Decoder decoder;
|
||||
for(size_t c = 0; c < 256; c++) {
|
||||
const auto instruction = decoder.instrucion_for_opcode(uint8_t(c));
|
||||
|
||||
// Treat invalid as NOP, because I've got to do _something_.
|
||||
if(instruction.operation == Operation::Invalid) {
|
||||
performers_[c] = performer_lookup_.performer(Operation::NOP, instruction.addressing_mode);
|
||||
} else {
|
||||
performers_[c] = performer_lookup_.performer(instruction.operation, instruction.addressing_mode);
|
||||
}
|
||||
}
|
||||
|
||||
// Fuzz RAM; then set anything that may be replaced by ROM to FF.
|
||||
Memory::Fuzz(memory_);
|
||||
memset(&memory_[0x100], 0xff, memory_.size() - 0x100);
|
||||
}
|
||||
|
||||
void Executor::set_rom(const std::vector<uint8_t> &rom) {
|
||||
// Copy into place, and reset.
|
||||
const auto length = std::min(size_t(0x1000), rom.size());
|
||||
memcpy(&memory_[0x2000 - length], rom.data(), length);
|
||||
reset();
|
||||
}
|
||||
|
||||
void Executor::run_for(Cycles cycles) {
|
||||
// The incoming clock is divided by four; the local cycles_ count
|
||||
// ensures that fractional parts are kept track of.
|
||||
cycles_ += cycles;
|
||||
CachingExecutor::run_for(cycles_.divide(Cycles(4)).as<int>());
|
||||
}
|
||||
|
||||
void Executor::reset() {
|
||||
// Just jump to the reset vector.
|
||||
set_program_counter(uint16_t(memory_[0x1ffe] | (memory_[0x1fff] << 8)));
|
||||
}
|
||||
|
||||
void Executor::set_interrupt_line(bool line) {
|
||||
// Super hack: interrupt now, if permitted. Otherwise do nothing.
|
||||
// So this will fail to catch enabling of interrupts while the line
|
||||
// is active, amongst other things.
|
||||
if(interrupt_line_ != line) {
|
||||
interrupt_line_ = line;
|
||||
|
||||
// TODO: verify interrupt connection. Externally, but stubbed off here.
|
||||
// if(!interrupt_disable_ && line) {
|
||||
// perform_interrupt<false>(0x1ff4);
|
||||
// }
|
||||
}
|
||||
}
|
||||
|
||||
uint8_t Executor::read(uint16_t address) {
|
||||
address &= 0x1fff;
|
||||
|
||||
// Deal with RAM and ROM accesses quickly.
|
||||
if(address < 0x60 || address >= 0x100) return memory_[address];
|
||||
|
||||
port_handler_.run_ports_for(cycles_since_port_handler_.flush<Cycles>());
|
||||
switch(address) {
|
||||
default:
|
||||
LOG("Unrecognised read from " << PADHEX(4) << address);
|
||||
return 0xff;
|
||||
|
||||
// "Port R"; sixteen four-bit ports
|
||||
case 0xd0: case 0xd1: case 0xd2: case 0xd3: case 0xd4: case 0xd5: case 0xd6: case 0xd7:
|
||||
case 0xd8: case 0xd9: case 0xda: case 0xdb: case 0xdc: case 0xdd: case 0xde: case 0xdf:
|
||||
LOG("Unimplemented Port R read from " << PADHEX(4) << address);
|
||||
return 0x00;
|
||||
|
||||
// Ports P0–P3.
|
||||
case 0xe0: case 0xe2:
|
||||
case 0xe4: case 0xe8: {
|
||||
const int port = port_remap[(address - 0xe0) >> 1];
|
||||
const uint8_t input = port_handler_.get_port_input(port);
|
||||
|
||||
// In the direction registers, a 0 indicates input, a 1 indicates output.
|
||||
return (input &~ port_directions_[port]) | (port_outputs_[port] & port_directions_[port]);
|
||||
}
|
||||
|
||||
case 0xe1: case 0xe3:
|
||||
case 0xe5: case 0xe9:
|
||||
return port_directions_[port_remap[(address - 0xe0) >> 1]];
|
||||
|
||||
// Timers.
|
||||
case 0xf9: return prescalers_[0].value;
|
||||
case 0xfa: return timers_[0].value;
|
||||
case 0xfb: return timers_[1].value;
|
||||
case 0xfc: return prescalers_[1].value;
|
||||
case 0xfd: return timers_[2].value;
|
||||
|
||||
case 0xfe: return interrupt_control_;
|
||||
case 0xff: return timer_control_;
|
||||
}
|
||||
}
|
||||
|
||||
void Executor::set_port_output(int port) {
|
||||
// Force 'output' to a 1 anywhere that a bit is set as input.
|
||||
port_handler_.set_port_output(port, port_outputs_[port] | ~port_directions_[port]);
|
||||
}
|
||||
|
||||
void Executor::write(uint16_t address, uint8_t value) {
|
||||
address &= 0x1fff;
|
||||
|
||||
// RAM writes are easy.
|
||||
if(address < 0x60) {
|
||||
memory_[address] = value;
|
||||
return;
|
||||
}
|
||||
|
||||
// ROM 'writes' are almost as easy (albeit unexpected).
|
||||
if(address >= 0x100) {
|
||||
LOG("Attempted ROM write of " << PADHEX(2) << value << " to " << PADHEX(4) << address);
|
||||
return;
|
||||
}
|
||||
|
||||
// Push time to the port handler.
|
||||
port_handler_.run_ports_for(cycles_since_port_handler_.flush<Cycles>());
|
||||
|
||||
switch(address) {
|
||||
default:
|
||||
LOG("Unrecognised write of " << PADHEX(2) << value << " to " << PADHEX(4) << address);
|
||||
break;
|
||||
|
||||
// "Port R"; sixteen four-bit ports
|
||||
case 0xd0: case 0xd1: case 0xd2: case 0xd3: case 0xd4: case 0xd5: case 0xd6: case 0xd7:
|
||||
case 0xd8: case 0xd9: case 0xda: case 0xdb: case 0xdc: case 0xdd: case 0xde: case 0xdf:
|
||||
LOG("Unimplemented Port R write of " << PADHEX(2) << value << " from " << PADHEX(4) << address);
|
||||
break;
|
||||
|
||||
// Ports P0–P3.
|
||||
case 0xe0: case 0xe2:
|
||||
case 0xe4: case 0xe8: {
|
||||
const int port = port_remap[(address - 0xe0) >> 1];
|
||||
port_outputs_[port] = value;
|
||||
set_port_output(port);
|
||||
}
|
||||
break;
|
||||
|
||||
case 0xe1: case 0xe3:
|
||||
case 0xe5: case 0xe9: {
|
||||
const int port = port_remap[(address - 0xe0) >> 1];
|
||||
port_directions_[port] = value;
|
||||
set_port_output(port);
|
||||
} break;
|
||||
|
||||
// Timers.
|
||||
//
|
||||
// Reloading of value with the reload value is a guess, based upon what I take
|
||||
// to be the intended usage of timer 2 in handling key repeat on the Apple IIgs.
|
||||
case 0xf9: prescalers_[0].value = prescalers_[0].reload_value = value; break;
|
||||
case 0xfa: timers_[0].value = timers_[0].reload_value = value; break;
|
||||
case 0xfb: timers_[1].value = timers_[1].reload_value = value; break;
|
||||
case 0xfc: prescalers_[1].value = prescalers_[1].reload_value = value; break;
|
||||
case 0xfd: timers_[2].value = timers_[2].reload_value = value; break;
|
||||
|
||||
case 0xfe: interrupt_control_ = value; break;
|
||||
case 0xff: timer_control_ = value; break;
|
||||
}
|
||||
}
|
||||
|
||||
void Executor::push(uint8_t value) {
|
||||
write(s_, value);
|
||||
--s_;
|
||||
}
|
||||
|
||||
uint8_t Executor::pull() {
|
||||
++s_;
|
||||
return read(s_);
|
||||
}
|
||||
|
||||
void Executor::set_flags(uint8_t flags) {
|
||||
negative_result_ = flags;
|
||||
overflow_result_ = uint8_t(flags << 1);
|
||||
index_mode_ = flags & 0x20;
|
||||
decimal_mode_ = flags & 0x08;
|
||||
interrupt_disable_ = flags & 0x04;
|
||||
zero_result_ = !(flags & 0x02);
|
||||
carry_flag_ = flags & 0x01;
|
||||
}
|
||||
|
||||
uint8_t Executor::flags() {
|
||||
return
|
||||
(negative_result_ & 0x80) |
|
||||
((overflow_result_ & 0x80) >> 1) |
|
||||
(index_mode_ ? 0x20 : 0x00) |
|
||||
(decimal_mode_ ? 0x08 : 0x00) |
|
||||
interrupt_disable_ |
|
||||
(zero_result_ ? 0x00 : 0x02) |
|
||||
carry_flag_;
|
||||
}
|
||||
|
||||
template<bool is_brk> inline void Executor::perform_interrupt(uint16_t vector) {
|
||||
// BRK has an unused operand.
|
||||
++program_counter_;
|
||||
push(uint8_t(program_counter_ >> 8));
|
||||
push(uint8_t(program_counter_ & 0xff));
|
||||
push(flags() | (is_brk ? 0x10 : 0x00));
|
||||
set_program_counter(uint16_t(memory_[vector] | (memory_[vector+1] << 8)));
|
||||
}
|
||||
|
||||
template <Operation operation, AddressingMode addressing_mode> void Executor::perform() {
|
||||
// Post cycle cost; this emulation _does not provide accurate timing_.
|
||||
#define TLength(mode, base) case AddressingMode::mode: subtract_duration(base + t_lengths[index_mode_]); break;
|
||||
#define Length(mode, base) case AddressingMode::mode: subtract_duration(base); break;
|
||||
|
||||
switch(operation) {
|
||||
case Operation::ADC: case Operation::AND: case Operation::CMP: case Operation::EOR:
|
||||
case Operation::LDA: case Operation::ORA: case Operation::SBC:
|
||||
{
|
||||
constexpr int t_lengths[] = {
|
||||
0,
|
||||
operation == Operation::LDA ? 2 : (operation == Operation::CMP ? 1 : 3)
|
||||
};
|
||||
switch(addressing_mode) {
|
||||
TLength(XIndirect, 6);
|
||||
TLength(ZeroPage, 3);
|
||||
TLength(Immediate, 2);
|
||||
TLength(Absolute, 4);
|
||||
TLength(IndirectY, 6);
|
||||
TLength(ZeroPageX, 4);
|
||||
TLength(AbsoluteY, 5);
|
||||
TLength(AbsoluteX, 5);
|
||||
default: assert(false);
|
||||
}
|
||||
} break;
|
||||
|
||||
case Operation::ASL: case Operation::DEC: case Operation::INC: case Operation::LSR:
|
||||
case Operation::ROL: case Operation::ROR:
|
||||
switch(addressing_mode) {
|
||||
Length(ZeroPage, 5);
|
||||
Length(Accumulator, 2);
|
||||
Length(Absolute, 6);
|
||||
Length(ZeroPageX, 6);
|
||||
Length(AbsoluteX, 7);
|
||||
default: assert(false);
|
||||
}
|
||||
break;
|
||||
|
||||
case Operation::BBC0: case Operation::BBC1: case Operation::BBC2: case Operation::BBC3:
|
||||
case Operation::BBC4: case Operation::BBC5: case Operation::BBC6: case Operation::BBC7:
|
||||
case Operation::BBS0: case Operation::BBS1: case Operation::BBS2: case Operation::BBS3:
|
||||
case Operation::BBS4: case Operation::BBS5: case Operation::BBS6: case Operation::BBS7:
|
||||
switch(addressing_mode) {
|
||||
Length(AccumulatorRelative, 4);
|
||||
Length(ZeroPageRelative, 5);
|
||||
default: assert(false);
|
||||
}
|
||||
break;
|
||||
case Operation::BPL: case Operation::BMI: case Operation::BEQ: case Operation::BNE:
|
||||
case Operation::BCS: case Operation::BCC: case Operation::BVS: case Operation::BVC:
|
||||
case Operation::INX: case Operation::INY:
|
||||
subtract_duration(2);
|
||||
break;
|
||||
|
||||
case Operation::CPX: case Operation::CPY: case Operation::BIT: case Operation::LDX:
|
||||
case Operation::LDY:
|
||||
switch(addressing_mode) {
|
||||
Length(Immediate, 2);
|
||||
Length(ZeroPage, 3);
|
||||
Length(Absolute, 4);
|
||||
Length(ZeroPageX, 4);
|
||||
Length(ZeroPageY, 4);
|
||||
Length(AbsoluteX, 5);
|
||||
Length(AbsoluteY, 5);
|
||||
default: assert(false);
|
||||
}
|
||||
break;
|
||||
|
||||
case Operation::BRA: subtract_duration(4); break;
|
||||
case Operation::BRK: subtract_duration(7); break;
|
||||
|
||||
case Operation::CLB0: case Operation::CLB1: case Operation::CLB2: case Operation::CLB3:
|
||||
case Operation::CLB4: case Operation::CLB5: case Operation::CLB6: case Operation::CLB7:
|
||||
case Operation::SEB0: case Operation::SEB1: case Operation::SEB2: case Operation::SEB3:
|
||||
case Operation::SEB4: case Operation::SEB5: case Operation::SEB6: case Operation::SEB7:
|
||||
switch(addressing_mode) {
|
||||
Length(Accumulator, 2);
|
||||
Length(ZeroPage, 5);
|
||||
default: assert(false);
|
||||
}
|
||||
break;
|
||||
|
||||
case Operation::CLC: case Operation::CLD: case Operation::CLT: case Operation::CLV:
|
||||
case Operation::CLI:
|
||||
case Operation::DEX: case Operation::DEY: case Operation::FST: case Operation::NOP:
|
||||
case Operation::SEC: case Operation::SED: case Operation::SEI: case Operation::SET:
|
||||
case Operation::SLW: case Operation::STP: case Operation::TAX: case Operation::TAY:
|
||||
case Operation::TSX: case Operation::TXA: case Operation::TXS: case Operation::TYA:
|
||||
subtract_duration(2);
|
||||
break;
|
||||
|
||||
case Operation::COM: subtract_duration(5); break;
|
||||
|
||||
case Operation::JMP:
|
||||
switch(addressing_mode) {
|
||||
Length(Absolute, 3);
|
||||
Length(AbsoluteIndirect, 5);
|
||||
Length(ZeroPageIndirect, 4);
|
||||
default: assert(false);
|
||||
}
|
||||
break;
|
||||
|
||||
case Operation::JSR:
|
||||
switch(addressing_mode) {
|
||||
Length(ZeroPageIndirect, 7);
|
||||
Length(Absolute, 6);
|
||||
Length(SpecialPage, 5);
|
||||
default: assert(false);
|
||||
}
|
||||
break;
|
||||
|
||||
case Operation::LDM: subtract_duration(4); break;
|
||||
|
||||
case Operation::PHA: case Operation::PHP: case Operation::TST:
|
||||
subtract_duration(3);
|
||||
break;
|
||||
|
||||
case Operation::PLA: case Operation::PLP:
|
||||
subtract_duration(4);
|
||||
break;
|
||||
|
||||
case Operation::RRF: subtract_duration(8); break;
|
||||
case Operation::RTI: subtract_duration(6); break;
|
||||
case Operation::RTS: subtract_duration(6); break;
|
||||
|
||||
case Operation::STA: case Operation::STX: case Operation::STY:
|
||||
switch(addressing_mode) {
|
||||
Length(XIndirect, 7);
|
||||
Length(ZeroPage, 4);
|
||||
Length(Absolute, 5);
|
||||
Length(IndirectY, 7);
|
||||
Length(ZeroPageX, 5);
|
||||
Length(ZeroPageY, 5);
|
||||
Length(AbsoluteY, 6);
|
||||
Length(AbsoluteX, 6);
|
||||
default: assert(false);
|
||||
}
|
||||
break;
|
||||
|
||||
default: assert(false);
|
||||
}
|
||||
|
||||
// Deal with all modes that don't access memory up here;
|
||||
// those that access memory will go through a slightly longer
|
||||
// sequence below that wraps the address and checks whether
|
||||
// a write is valid [if required].
|
||||
|
||||
unsigned int address;
|
||||
#define next8() memory_[(program_counter_ + 1) & 0x1fff]
|
||||
#define next16() uint16_t(memory_[(program_counter_ + 1) & 0x1fff] | (memory_[(program_counter_ + 2) & 0x1fff] << 8))
|
||||
|
||||
// Underlying assumption below: the instruction stream will never
|
||||
// overlap with IO ports.
|
||||
switch(addressing_mode) {
|
||||
|
||||
// Addressing modes with no further memory access.
|
||||
|
||||
case AddressingMode::Implied:
|
||||
perform<operation>(nullptr);
|
||||
++program_counter_;
|
||||
return;
|
||||
|
||||
case AddressingMode::Accumulator:
|
||||
perform<operation>(&a_);
|
||||
++program_counter_;
|
||||
return;
|
||||
|
||||
case AddressingMode::Immediate:
|
||||
perform<operation>(&next8());
|
||||
program_counter_ += 2;
|
||||
return;
|
||||
|
||||
// Special-purpose addressing modes.
|
||||
|
||||
case AddressingMode::Relative:
|
||||
address = unsigned(program_counter_ + 1 + size(addressing_mode) + int8_t(next8()));
|
||||
break;
|
||||
|
||||
case AddressingMode::SpecialPage: address = 0x1f00 | next8(); break;
|
||||
|
||||
case AddressingMode::ImmediateZeroPage:
|
||||
// LDM only...
|
||||
write(memory_[(program_counter_+2)&0x1fff], memory_[(program_counter_+1)&0x1fff]);
|
||||
program_counter_ += 1 + size(addressing_mode);
|
||||
return;
|
||||
|
||||
case AddressingMode::AccumulatorRelative:
|
||||
case AddressingMode::ZeroPageRelative: {
|
||||
// Order of bytes is: (i) zero page address; (ii) relative jump.
|
||||
uint8_t value;
|
||||
if constexpr (addressing_mode == AddressingMode::AccumulatorRelative) {
|
||||
value = a_;
|
||||
address = unsigned(program_counter_ + 1 + size(addressing_mode) + int8_t(next8()));
|
||||
} else {
|
||||
value = read(next8());
|
||||
address = unsigned(program_counter_ + 1 + size(addressing_mode) + int8_t(memory_[(program_counter_+2)&0x1fff]));
|
||||
}
|
||||
program_counter_ += 1 + size(addressing_mode);
|
||||
switch(operation) {
|
||||
case Operation::BBS0: case Operation::BBS1: case Operation::BBS2: case Operation::BBS3:
|
||||
case Operation::BBS4: case Operation::BBS5: case Operation::BBS6: case Operation::BBS7: {
|
||||
if constexpr (operation >= Operation::BBS0 && operation <= Operation::BBS7) {
|
||||
constexpr uint8_t mask = 1 << (int(operation) - int(Operation::BBS0));
|
||||
if(value & mask) {
|
||||
set_program_counter(uint16_t(address));
|
||||
subtract_duration(2);
|
||||
}
|
||||
}
|
||||
} return;
|
||||
case Operation::BBC0: case Operation::BBC1: case Operation::BBC2: case Operation::BBC3:
|
||||
case Operation::BBC4: case Operation::BBC5: case Operation::BBC6: case Operation::BBC7: {
|
||||
if constexpr (operation >= Operation::BBC0 && operation <= Operation::BBC7) {
|
||||
constexpr uint8_t mask = 1 << (int(operation) - int(Operation::BBC0));
|
||||
if(!(value & mask)) {
|
||||
set_program_counter(uint16_t(address));
|
||||
subtract_duration(2);
|
||||
}
|
||||
}
|
||||
} return;
|
||||
default: assert(false);
|
||||
}
|
||||
} break;
|
||||
|
||||
// Addressing modes with a memory access.
|
||||
|
||||
case AddressingMode::Absolute: address = next16(); break;
|
||||
case AddressingMode::AbsoluteX: address = next16() + x_; break;
|
||||
case AddressingMode::AbsoluteY: address = next16() + y_; break;
|
||||
case AddressingMode::ZeroPage: address = next8(); break;
|
||||
case AddressingMode::ZeroPageX: address = (next8() + x_) & 0xff; break;
|
||||
case AddressingMode::ZeroPageY: address = (next8() + y_) & 0xff; break;
|
||||
|
||||
case AddressingMode::ZeroPageIndirect:
|
||||
address = next8();
|
||||
address = unsigned(memory_[address] | (memory_[(address + 1) & 0xff] << 8));
|
||||
break;
|
||||
|
||||
case AddressingMode::XIndirect:
|
||||
address = (next8() + x_) & 0xff;
|
||||
address = unsigned(memory_[address] | (memory_[(address + 1)&0xff] << 8));
|
||||
break;
|
||||
|
||||
case AddressingMode::IndirectY:
|
||||
address = unsigned((memory_[next8()] | (memory_[(next8()+1)&0xff] << 8)) + y_);
|
||||
break;
|
||||
|
||||
case AddressingMode::AbsoluteIndirect:
|
||||
address = next16();
|
||||
address = unsigned(memory_[address & 0x1fff] | (memory_[(address + 1) & 0x1fff] << 8));
|
||||
break;
|
||||
|
||||
default:
|
||||
assert(false);
|
||||
}
|
||||
|
||||
#undef next16
|
||||
#undef next8
|
||||
program_counter_ += 1 + size(addressing_mode);
|
||||
|
||||
// Check for a branch; those don't go through the memory accesses below.
|
||||
switch(operation) {
|
||||
case Operation::BRA: case Operation::JMP:
|
||||
set_program_counter(uint16_t(address));
|
||||
return;
|
||||
|
||||
case Operation::JSR: {
|
||||
// Push one less than the actual return address.
|
||||
const auto return_address = program_counter_ - 1;
|
||||
push(uint8_t(return_address >> 8));
|
||||
push(uint8_t(return_address & 0xff));
|
||||
set_program_counter(uint16_t(address));
|
||||
} return;
|
||||
|
||||
#define Bcc(c) if(c) { set_program_counter(uint16_t(address)); subtract_duration(2); } return
|
||||
case Operation::BPL: Bcc(!(negative_result_&0x80));
|
||||
case Operation::BMI: Bcc(negative_result_&0x80);
|
||||
case Operation::BEQ: Bcc(!zero_result_);
|
||||
case Operation::BNE: Bcc(zero_result_);
|
||||
case Operation::BCS: Bcc(carry_flag_);
|
||||
case Operation::BCC: Bcc(!carry_flag_);
|
||||
case Operation::BVS: Bcc(overflow_result_ & 0x80);
|
||||
case Operation::BVC: Bcc(!(overflow_result_ & 0x80));
|
||||
#undef Bcc
|
||||
|
||||
default: break;
|
||||
}
|
||||
|
||||
assert(access_type(operation) != AccessType::None);
|
||||
|
||||
if constexpr(access_type(operation) == AccessType::Read) {
|
||||
uint8_t source = read(uint16_t(address));
|
||||
perform<operation>(&source);
|
||||
return;
|
||||
}
|
||||
|
||||
uint8_t value;
|
||||
if constexpr(access_type(operation) == AccessType::ReadModifyWrite) {
|
||||
value = read(uint16_t(address));
|
||||
} else {
|
||||
value = 0xff;
|
||||
}
|
||||
perform<operation>(&value);
|
||||
write(uint16_t(address), value);
|
||||
}
|
||||
|
||||
template <Operation operation> void Executor::perform(uint8_t *operand [[maybe_unused]]) {
|
||||
|
||||
#define set_nz(a) negative_result_ = zero_result_ = (a)
|
||||
switch(operation) {
|
||||
case Operation::LDA:
|
||||
if(index_mode_) {
|
||||
write(x_, *operand);
|
||||
set_nz(*operand);
|
||||
} else {
|
||||
set_nz(a_ = *operand);
|
||||
}
|
||||
break;
|
||||
case Operation::LDX: set_nz(x_ = *operand); break;
|
||||
case Operation::LDY: set_nz(y_ = *operand); break;
|
||||
|
||||
case Operation::STA: *operand = a_; break;
|
||||
case Operation::STX: *operand = x_; break;
|
||||
case Operation::STY: *operand = y_; break;
|
||||
|
||||
case Operation::TXA: set_nz(a_ = x_); break;
|
||||
case Operation::TYA: set_nz(a_ = y_); break;
|
||||
case Operation::TXS: s_ = x_; break;
|
||||
case Operation::TAX: set_nz(x_ = a_); break;
|
||||
case Operation::TAY: set_nz(y_ = a_); break;
|
||||
case Operation::TSX: set_nz(x_ = s_); break;
|
||||
|
||||
case Operation::SEB0: case Operation::SEB1: case Operation::SEB2: case Operation::SEB3:
|
||||
case Operation::SEB4: case Operation::SEB5: case Operation::SEB6: case Operation::SEB7:
|
||||
if constexpr(operation >= Operation::SEB0 && operation <= Operation::SEB7) {
|
||||
*operand |= 1 << (int(operation) - int(Operation::SEB0));
|
||||
}
|
||||
break;
|
||||
case Operation::CLB0: case Operation::CLB1: case Operation::CLB2: case Operation::CLB3:
|
||||
case Operation::CLB4: case Operation::CLB5: case Operation::CLB6: case Operation::CLB7:
|
||||
if constexpr(operation >= Operation::CLB0 && operation <= Operation::CLB7) {
|
||||
*operand &= ~(1 << (int(operation) - int(Operation::CLB0)));
|
||||
}
|
||||
break;
|
||||
|
||||
case Operation::CLI: interrupt_disable_ = 0x00; break;
|
||||
case Operation::SEI: interrupt_disable_ = 0x04; break;
|
||||
case Operation::CLT: index_mode_ = false; break;
|
||||
case Operation::SET: index_mode_ = true; break;
|
||||
case Operation::CLD: decimal_mode_ = false; break;
|
||||
case Operation::SED: decimal_mode_ = true; break;
|
||||
case Operation::CLC: carry_flag_ = 0; break;
|
||||
case Operation::SEC: carry_flag_ = 1; break;
|
||||
case Operation::CLV: overflow_result_ = 0; break;
|
||||
|
||||
case Operation::DEX: --x_; set_nz(x_); break;
|
||||
case Operation::INX: ++x_; set_nz(x_); break;
|
||||
case Operation::DEY: --y_; set_nz(y_); break;
|
||||
case Operation::INY: ++y_; set_nz(y_); break;
|
||||
case Operation::DEC: --*operand; set_nz(*operand); break;
|
||||
case Operation::INC: ++*operand; set_nz(*operand); break;
|
||||
|
||||
case Operation::RTS: {
|
||||
uint16_t target = pull();
|
||||
target |= pull() << 8;
|
||||
set_program_counter(target+1);
|
||||
--program_counter_; // To undo the unavoidable increment
|
||||
// after exiting from here.
|
||||
} break;
|
||||
|
||||
case Operation::RTI: {
|
||||
set_flags(pull());
|
||||
uint16_t target = pull();
|
||||
target |= pull() << 8;
|
||||
set_program_counter(target);
|
||||
--program_counter_; // To undo the unavoidable increment
|
||||
// after exiting from here.
|
||||
} break;
|
||||
|
||||
case Operation::BRK:
|
||||
perform_interrupt<true>(0x1ff4);
|
||||
--program_counter_; // To undo the unavoidable increment
|
||||
// after exiting from here.
|
||||
break;
|
||||
|
||||
case Operation::STP: set_is_stopped(true); break;
|
||||
|
||||
case Operation::COM: set_nz(*operand ^= 0xff); break;
|
||||
|
||||
case Operation::FST: case Operation::SLW: case Operation::NOP:
|
||||
// TODO: communicate FST and SLW onwards, I imagine. Find out what they interface with.
|
||||
break;
|
||||
|
||||
case Operation::PHA: push(a_); break;
|
||||
case Operation::PHP: push(flags()); break;
|
||||
case Operation::PLA: set_nz(a_ = pull()); break;
|
||||
case Operation::PLP: set_flags(pull()); break;
|
||||
|
||||
case Operation::ASL:
|
||||
carry_flag_ = *operand >> 7;
|
||||
*operand <<= 1;
|
||||
set_nz(*operand);
|
||||
break;
|
||||
|
||||
case Operation::LSR:
|
||||
carry_flag_ = *operand & 1;
|
||||
*operand >>= 1;
|
||||
set_nz(*operand);
|
||||
break;
|
||||
|
||||
case Operation::ROL: {
|
||||
const uint8_t temp8 = uint8_t((*operand << 1) | carry_flag_);
|
||||
carry_flag_ = *operand >> 7;
|
||||
set_nz(*operand = temp8);
|
||||
} break;
|
||||
|
||||
case Operation::ROR: {
|
||||
const uint8_t temp8 = uint8_t((*operand >> 1) | (carry_flag_ << 7));
|
||||
carry_flag_ = *operand & 1;
|
||||
set_nz(*operand = temp8);
|
||||
} break;
|
||||
|
||||
case Operation::RRF:
|
||||
*operand = uint8_t((*operand >> 4) | (*operand << 4));
|
||||
break;
|
||||
|
||||
case Operation::BIT:
|
||||
zero_result_ = *operand & a_;
|
||||
negative_result_ = *operand;
|
||||
overflow_result_ = uint8_t(*operand << 1);
|
||||
break;
|
||||
|
||||
case Operation::TST:
|
||||
set_nz(*operand);
|
||||
break;
|
||||
|
||||
/*
|
||||
Operations affected by the index mode flag: ADC, AND, CMP, EOR, LDA, ORA, and SBC.
|
||||
*/
|
||||
|
||||
#define index(op) \
|
||||
if(index_mode_) { \
|
||||
uint8_t t = read(x_); \
|
||||
op(t); \
|
||||
write(x_, t); \
|
||||
} else { \
|
||||
op(a_); \
|
||||
}
|
||||
|
||||
#define op_ora(x) set_nz(x |= *operand)
|
||||
#define op_and(x) set_nz(x &= *operand)
|
||||
#define op_eor(x) set_nz(x ^= *operand)
|
||||
case Operation::ORA: index(op_ora); break;
|
||||
case Operation::AND: index(op_and); break;
|
||||
case Operation::EOR: index(op_eor); break;
|
||||
#undef op_eor
|
||||
#undef op_and
|
||||
#undef op_ora
|
||||
#undef index
|
||||
|
||||
#define op_cmp(x) { \
|
||||
const uint16_t temp16 = x - *operand; \
|
||||
set_nz(uint8_t(temp16)); \
|
||||
carry_flag_ = (~temp16 >> 8)&1; \
|
||||
}
|
||||
case Operation::CMP:
|
||||
if(index_mode_) {
|
||||
op_cmp(read(x_));
|
||||
} else {
|
||||
op_cmp(a_);
|
||||
}
|
||||
break;
|
||||
case Operation::CPX: op_cmp(x_); break;
|
||||
case Operation::CPY: op_cmp(y_); break;
|
||||
#undef op_cmp
|
||||
|
||||
case Operation::SBC:
|
||||
case Operation::ADC: {
|
||||
const uint8_t a = index_mode_ ? read(x_) : a_;
|
||||
|
||||
if(decimal_mode_) {
|
||||
if(operation == Operation::ADC) {
|
||||
uint16_t partials = 0;
|
||||
int result = carry_flag_;
|
||||
|
||||
#define nibble(mask, limit, adjustment, carry) \
|
||||
result += (a & mask) + (*operand & mask); \
|
||||
partials += result & mask; \
|
||||
if(result >= limit) result = ((result + (adjustment)) & (carry - 1)) + carry;
|
||||
|
||||
nibble(0x000f, 0x000a, 0x0006, 0x00010);
|
||||
nibble(0x00f0, 0x00a0, 0x0060, 0x00100);
|
||||
|
||||
#undef nibble
|
||||
|
||||
overflow_result_ = uint8_t((partials ^ a) & (partials ^ *operand));
|
||||
set_nz(uint8_t(result));
|
||||
carry_flag_ = (result >> 8) & 1;
|
||||
} else {
|
||||
unsigned int result = 0;
|
||||
unsigned int borrow = carry_flag_ ^ 1;
|
||||
const uint16_t decimal_result = uint16_t(a - *operand - borrow);
|
||||
|
||||
#define nibble(mask, adjustment, carry) \
|
||||
result += (a & mask) - (*operand & mask) - borrow; \
|
||||
if(result > mask) result -= adjustment; \
|
||||
borrow = (result > mask) ? carry : 0; \
|
||||
result &= (carry - 1);
|
||||
|
||||
nibble(0x000f, 0x0006, 0x00010);
|
||||
nibble(0x00f0, 0x0060, 0x00100);
|
||||
|
||||
#undef nibble
|
||||
|
||||
overflow_result_ = uint8_t((decimal_result ^ a) & (~decimal_result ^ *operand));
|
||||
set_nz(uint8_t(result));
|
||||
carry_flag_ = ((borrow >> 8)&1)^1;
|
||||
}
|
||||
} else {
|
||||
int result;
|
||||
if(operation == Operation::ADC) {
|
||||
result = int(a + *operand + carry_flag_);
|
||||
overflow_result_ = uint8_t((result ^ a) & (result ^ *operand));
|
||||
} else {
|
||||
result = int(a + ~*operand + carry_flag_);
|
||||
overflow_result_ = uint8_t((result ^ a) & (result ^ ~*operand));
|
||||
}
|
||||
set_nz(uint8_t(result));
|
||||
carry_flag_ = (result >> 8) & 1;
|
||||
}
|
||||
|
||||
if(index_mode_) {
|
||||
write(x_, a);
|
||||
} else {
|
||||
a_ = a;
|
||||
}
|
||||
} break;
|
||||
|
||||
|
||||
/*
|
||||
Already removed from the instruction stream:
|
||||
|
||||
* all branches and jumps;
|
||||
* LDM.
|
||||
*/
|
||||
|
||||
default:
|
||||
LOG("Unimplemented operation: " << operation);
|
||||
assert(false);
|
||||
}
|
||||
#undef set_nz
|
||||
}
|
||||
|
||||
inline void Executor::subtract_duration(int duration) {
|
||||
// Pass along.
|
||||
CachingExecutor::subtract_duration(duration);
|
||||
|
||||
// Update count for potential port accesses.
|
||||
cycles_since_port_handler_ += Cycles(duration);
|
||||
|
||||
// Update timer 1 and 2 prescaler.
|
||||
constexpr int t12_divider = 4; // A divide by 4 has already been applied before counting instruction lengths; therefore
|
||||
// this additional divide by 4 produces the correct net divide by 16.
|
||||
|
||||
timer_divider_ += duration;
|
||||
const int t12_ticks = update_timer(prescalers_[0], timer_divider_ / t12_divider);
|
||||
timer_divider_ &= (t12_divider-1);
|
||||
|
||||
// Update timers 1 and 2. TODO: interrupts (elsewhere?).
|
||||
if(update_timer(timers_[0], t12_ticks)) interrupt_control_ |= 0x20;
|
||||
if(update_timer(timers_[1], t12_ticks)) interrupt_control_ |= 0x08;
|
||||
|
||||
// If timer X is disabled, stop.
|
||||
if(timer_control_&0x20) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Update timer X prescaler.
|
||||
switch(timer_control_ & 0x0c) {
|
||||
default: {
|
||||
const int tx_ticks = update_timer(prescalers_[1], t12_ticks); // TODO: don't hard code this. And is this even right?
|
||||
if(update_timer(timers_[2], tx_ticks))
|
||||
timer_control_ |= 0x80; // TODO: interrupt result of this.
|
||||
} break;
|
||||
case 0x04:
|
||||
LOG("TODO: Timer X; Pulse output mode");
|
||||
break;
|
||||
case 0x08:
|
||||
LOG("TODO: Timer X; Event counter mode");
|
||||
break;
|
||||
case 0x0c:
|
||||
LOG("TODO: Timer X; Pulse width measurement mode");
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
inline int Executor::update_timer(Timer &timer, int count) {
|
||||
const int next_value = timer.value - count;
|
||||
if(next_value < 0) {
|
||||
// Determine how many reloads were required to get above zero.
|
||||
const int reload_value = timer.reload_value ? timer.reload_value : 256;
|
||||
const int underflow_count = 1 - next_value / reload_value;
|
||||
timer.value = uint8_t((next_value % reload_value) + timer.reload_value);
|
||||
return underflow_count;
|
||||
}
|
||||
timer.value = uint8_t(next_value);
|
||||
return 0;
|
||||
}
|
||||
|
||||
uint8_t Executor::get_output_mask(int port) {
|
||||
return port_directions_[port];
|
||||
}
|
||||
180
InstructionSets/M50740/Executor.hpp
Normal file
180
InstructionSets/M50740/Executor.hpp
Normal file
@@ -0,0 +1,180 @@
|
||||
//
|
||||
// Executor.h
|
||||
// Clock Signal
|
||||
//
|
||||
// Created by Thomas Harte on 16/01/21.
|
||||
// Copyright © 2021 Thomas Harte. All rights reserved.
|
||||
//
|
||||
|
||||
#ifndef Executor_h
|
||||
#define Executor_h
|
||||
|
||||
#include "Instruction.hpp"
|
||||
#include "Parser.hpp"
|
||||
#include "../CachingExecutor.hpp"
|
||||
#include "../../ClockReceiver/ClockReceiver.hpp"
|
||||
|
||||
#include <array>
|
||||
#include <cstdint>
|
||||
#include <vector>
|
||||
|
||||
namespace InstructionSet {
|
||||
namespace M50740 {
|
||||
|
||||
class Executor;
|
||||
using CachingExecutor = CachingExecutor<Executor, 0x1fff, 255, Instruction, false>;
|
||||
|
||||
struct PortHandler {
|
||||
virtual void run_ports_for(Cycles) = 0;
|
||||
virtual void set_port_output(int port, uint8_t value) = 0;
|
||||
virtual uint8_t get_port_input(int port) = 0;
|
||||
};
|
||||
|
||||
/*!
|
||||
Executes M50740 code subject to heavy limitations:
|
||||
|
||||
* the instruction stream cannot run across any of the specialised IO addresses; and
|
||||
* timing is correct to whole-opcode boundaries only.
|
||||
*/
|
||||
class Executor: public CachingExecutor {
|
||||
public:
|
||||
Executor(PortHandler &);
|
||||
void set_rom(const std::vector<uint8_t> &rom);
|
||||
|
||||
void reset();
|
||||
void set_interrupt_line(bool);
|
||||
|
||||
uint8_t get_output_mask(int port);
|
||||
|
||||
/*!
|
||||
Runs, in discrete steps, the minimum number of instructions as it takes to complete at least @c cycles.
|
||||
*/
|
||||
void run_for(Cycles cycles);
|
||||
|
||||
private:
|
||||
// MARK: - CachingExecutor-facing interface.
|
||||
|
||||
friend CachingExecutor;
|
||||
|
||||
/*!
|
||||
Maps instructions to performers; called by the CachingExecutor and for this instruction set, extremely trivial.
|
||||
*/
|
||||
inline PerformerIndex action_for(Instruction instruction) {
|
||||
// This is a super-simple processor, so the opcode can be used directly to index the performers.
|
||||
return instruction.opcode;
|
||||
}
|
||||
|
||||
/*!
|
||||
Parses from @c start and no later than @c max_address, using the CachingExecutor as a target.
|
||||
*/
|
||||
inline void parse(uint16_t start, uint16_t closing_bound) {
|
||||
Parser<Executor, false> parser;
|
||||
parser.parse(*this, &memory_[0], start & 0x1fff, closing_bound);
|
||||
}
|
||||
|
||||
private:
|
||||
// MARK: - Internal framework for generator performers.
|
||||
|
||||
/*!
|
||||
Provides dynamic lookup of @c perform(Executor*).
|
||||
*/
|
||||
class PerformerLookup {
|
||||
public:
|
||||
PerformerLookup() {
|
||||
fill<int(MinOperation)>(performers_);
|
||||
}
|
||||
|
||||
Performer performer(Operation operation, AddressingMode addressing_mode) {
|
||||
const auto index =
|
||||
(int(operation) - MinOperation) * (1 + MaxAddressingMode - MinAddressingMode) +
|
||||
(int(addressing_mode) - MinAddressingMode);
|
||||
return performers_[index];
|
||||
}
|
||||
|
||||
private:
|
||||
Performer performers_[(1 + MaxAddressingMode - MinAddressingMode) * (1 + MaxOperation - MinOperation)];
|
||||
|
||||
template<int operation, int addressing_mode> void fill_operation(Performer *target) {
|
||||
*target = &Executor::perform<Operation(operation), AddressingMode(addressing_mode)>;
|
||||
|
||||
if constexpr (addressing_mode+1 <= MaxAddressingMode) {
|
||||
fill_operation<operation, addressing_mode+1>(target + 1);
|
||||
}
|
||||
}
|
||||
|
||||
template<int operation> void fill(Performer *target) {
|
||||
fill_operation<operation, int(MinAddressingMode)>(target);
|
||||
target += 1 + MaxAddressingMode - MinAddressingMode;
|
||||
|
||||
if constexpr (operation+1 <= MaxOperation) {
|
||||
fill<operation+1>(target);
|
||||
}
|
||||
}
|
||||
};
|
||||
inline static PerformerLookup performer_lookup_;
|
||||
|
||||
/*!
|
||||
Performs @c operation using @c operand as the value fetched from memory, if any.
|
||||
*/
|
||||
template <Operation operation> void perform(uint8_t *operand);
|
||||
|
||||
/*!
|
||||
Performs @c operation in @c addressing_mode.
|
||||
*/
|
||||
template <Operation operation, AddressingMode addressing_mode> void perform();
|
||||
|
||||
private:
|
||||
// MARK: - Instruction set state.
|
||||
|
||||
// Memory.
|
||||
std::array<uint8_t, 0x2000> memory_;
|
||||
|
||||
// Registers.
|
||||
uint8_t a_ = 0, x_ = 0, y_ = 0, s_ = 0;
|
||||
|
||||
uint8_t negative_result_ = 0;
|
||||
uint8_t zero_result_ = 0;
|
||||
uint8_t interrupt_disable_ = 0x04;
|
||||
uint8_t carry_flag_ = 0;
|
||||
uint8_t overflow_result_ = 0;
|
||||
bool index_mode_ = false;
|
||||
bool decimal_mode_ = false;
|
||||
|
||||
// IO ports.
|
||||
uint8_t port_directions_[4] = {0x00, 0x00, 0x00, 0x00};
|
||||
uint8_t port_outputs_[4] = {0xff, 0xff, 0xff, 0xff};
|
||||
|
||||
// Timers.
|
||||
struct Timer {
|
||||
uint8_t value = 0xff, reload_value = 0xff;
|
||||
};
|
||||
int timer_divider_ = 0;
|
||||
Timer timers_[3], prescalers_[2];
|
||||
inline int update_timer(Timer &timer, int count);
|
||||
|
||||
// Interrupt and timer control.
|
||||
uint8_t interrupt_control_ = 0, timer_control_ = 0;
|
||||
bool interrupt_line_ = false;
|
||||
|
||||
// Access helpers.
|
||||
inline uint8_t read(uint16_t address);
|
||||
inline void write(uint16_t address, uint8_t value);
|
||||
inline void push(uint8_t value);
|
||||
inline uint8_t pull();
|
||||
inline void set_flags(uint8_t);
|
||||
inline uint8_t flags();
|
||||
template<bool is_brk> inline void perform_interrupt(uint16_t vector);
|
||||
inline void set_port_output(int port);
|
||||
|
||||
// MARK: - Execution time
|
||||
|
||||
Cycles cycles_;
|
||||
Cycles cycles_since_port_handler_;
|
||||
PortHandler &port_handler_;
|
||||
inline void subtract_duration(int duration);
|
||||
};
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
#endif /* Executor_h */
|
||||
242
InstructionSets/M50740/Instruction.hpp
Normal file
242
InstructionSets/M50740/Instruction.hpp
Normal file
@@ -0,0 +1,242 @@
|
||||
//
|
||||
// Instruction.hpp
|
||||
// Clock Signal
|
||||
//
|
||||
// Created by Thomas Harte on 15/01/21.
|
||||
// Copyright © 2021 Thomas Harte. All rights reserved.
|
||||
//
|
||||
|
||||
#ifndef InstructionSets_M50740_Instruction_h
|
||||
#define InstructionSets_M50740_Instruction_h
|
||||
|
||||
#include <cstdint>
|
||||
#include <iomanip>
|
||||
#include <string>
|
||||
#include <sstream>
|
||||
#include "../AccessType.hpp"
|
||||
|
||||
namespace InstructionSet {
|
||||
namespace M50740 {
|
||||
|
||||
enum class AddressingMode {
|
||||
Implied, Accumulator, Immediate,
|
||||
Absolute, AbsoluteX, AbsoluteY,
|
||||
ZeroPage, ZeroPageX, ZeroPageY,
|
||||
XIndirect, IndirectY,
|
||||
Relative,
|
||||
AbsoluteIndirect, ZeroPageIndirect,
|
||||
SpecialPage,
|
||||
ImmediateZeroPage,
|
||||
AccumulatorRelative, ZeroPageRelative
|
||||
};
|
||||
|
||||
static constexpr auto MaxAddressingMode = int(AddressingMode::ZeroPageRelative);
|
||||
static constexpr auto MinAddressingMode = int(AddressingMode::Implied);
|
||||
|
||||
constexpr int size(AddressingMode mode) {
|
||||
// This is coupled to the AddressingMode list above; be careful!
|
||||
constexpr int sizes[] = {
|
||||
0, 0, 1,
|
||||
2, 2, 2,
|
||||
1, 1, 1,
|
||||
1, 1,
|
||||
1,
|
||||
2, 1,
|
||||
1,
|
||||
2,
|
||||
1, 2
|
||||
};
|
||||
static_assert(sizeof(sizes)/sizeof(*sizes) == int(MaxAddressingMode) + 1);
|
||||
return sizes[int(mode)];
|
||||
}
|
||||
|
||||
enum class Operation: uint8_t {
|
||||
Invalid,
|
||||
|
||||
// Operations that don't access memory.
|
||||
BBC0, BBC1, BBC2, BBC3, BBC4, BBC5, BBC6, BBC7,
|
||||
BBS0, BBS1, BBS2, BBS3, BBS4, BBS5, BBS6, BBS7,
|
||||
BCC, BCS,
|
||||
BEQ, BMI, BNE, BPL,
|
||||
BVC, BVS, BRA, BRK,
|
||||
JMP, JSR,
|
||||
RTI, RTS,
|
||||
CLC, CLD, CLI, CLT, CLV,
|
||||
SEC, SED, SEI, SET,
|
||||
INX, INY, DEX, DEY,
|
||||
FST, SLW,
|
||||
NOP,
|
||||
PHA, PHP, PLA, PLP,
|
||||
STP,
|
||||
TAX, TAY, TSX, TXA,
|
||||
TXS, TYA,
|
||||
|
||||
// Read operations.
|
||||
ADC, SBC,
|
||||
AND, ORA, EOR, BIT,
|
||||
CMP, CPX, CPY,
|
||||
LDA, LDX, LDY,
|
||||
TST,
|
||||
|
||||
// Read-modify-write operations.
|
||||
ASL, LSR,
|
||||
CLB0, CLB1, CLB2, CLB3, CLB4, CLB5, CLB6, CLB7,
|
||||
SEB0, SEB1, SEB2, SEB3, SEB4, SEB5, SEB6, SEB7,
|
||||
COM,
|
||||
DEC, INC,
|
||||
ROL, ROR, RRF,
|
||||
|
||||
// Write operations.
|
||||
LDM,
|
||||
STA, STX, STY,
|
||||
};
|
||||
|
||||
static constexpr auto MaxOperation = int(Operation::STY);
|
||||
static constexpr auto MinOperation = int(Operation::BBC0);
|
||||
|
||||
constexpr AccessType access_type(Operation operation) {
|
||||
if(operation < Operation::ADC) return AccessType::None;
|
||||
if(operation < Operation::ASL) return AccessType::Read;
|
||||
if(operation < Operation::LDM) return AccessType::ReadModifyWrite;
|
||||
return AccessType::Write;
|
||||
}
|
||||
|
||||
constexpr bool uses_index_mode(Operation operation) {
|
||||
return
|
||||
operation == Operation::ADC || operation == Operation::AND ||
|
||||
operation == Operation::CMP || operation == Operation::EOR ||
|
||||
operation == Operation::LDA || operation == Operation::ORA ||
|
||||
operation == Operation::SBC;
|
||||
}
|
||||
|
||||
/*!
|
||||
@returns The name of @c operation.
|
||||
*/
|
||||
inline constexpr const char *operation_name(Operation operation) {
|
||||
#define MAP(x) case Operation::x: return #x;
|
||||
switch(operation) {
|
||||
default: break;
|
||||
MAP(BBC0); MAP(BBC1); MAP(BBC2); MAP(BBC3); MAP(BBC4); MAP(BBC5); MAP(BBC6); MAP(BBC7);
|
||||
MAP(BBS0); MAP(BBS1); MAP(BBS2); MAP(BBS3); MAP(BBS4); MAP(BBS5); MAP(BBS6); MAP(BBS7);
|
||||
MAP(BCC); MAP(BCS); MAP(BEQ); MAP(BMI); MAP(BNE); MAP(BPL); MAP(BVC); MAP(BVS);
|
||||
MAP(BRA); MAP(BRK); MAP(JMP); MAP(JSR); MAP(RTI); MAP(RTS); MAP(CLC); MAP(CLD);
|
||||
MAP(CLI); MAP(CLT); MAP(CLV); MAP(SEC); MAP(SED); MAP(SEI); MAP(SET); MAP(INX);
|
||||
MAP(INY); MAP(DEX); MAP(DEY); MAP(FST); MAP(SLW); MAP(NOP); MAP(PHA); MAP(PHP);
|
||||
MAP(PLA); MAP(PLP); MAP(STP); MAP(TAX); MAP(TAY); MAP(TSX); MAP(TXA); MAP(TXS);
|
||||
MAP(TYA); MAP(ADC); MAP(SBC); MAP(AND); MAP(ORA); MAP(EOR); MAP(BIT); MAP(CMP);
|
||||
MAP(CPX); MAP(CPY); MAP(LDA); MAP(LDX); MAP(LDY); MAP(TST); MAP(ASL); MAP(LSR);
|
||||
MAP(CLB0); MAP(CLB1); MAP(CLB2); MAP(CLB3); MAP(CLB4); MAP(CLB5); MAP(CLB6); MAP(CLB7);
|
||||
MAP(SEB0); MAP(SEB1); MAP(SEB2); MAP(SEB3); MAP(SEB4); MAP(SEB5); MAP(SEB6); MAP(SEB7);
|
||||
MAP(COM); MAP(DEC); MAP(INC); MAP(ROL); MAP(ROR); MAP(RRF); MAP(LDM); MAP(STA);
|
||||
MAP(STX); MAP(STY);
|
||||
}
|
||||
#undef MAP
|
||||
|
||||
return "???";
|
||||
}
|
||||
|
||||
inline std::ostream &operator <<(std::ostream &stream, Operation operation) {
|
||||
stream << operation_name(operation);
|
||||
return stream;
|
||||
}
|
||||
|
||||
/*!
|
||||
@returns The name of @c addressing_mode.
|
||||
*/
|
||||
inline constexpr const char *addressing_mode_name(AddressingMode addressing_mode) {
|
||||
switch(addressing_mode) {
|
||||
default: break;
|
||||
case AddressingMode::Implied: return "";
|
||||
case AddressingMode::Accumulator: return "A";
|
||||
case AddressingMode::Immediate: return "#";
|
||||
case AddressingMode::Absolute: return "abs";
|
||||
case AddressingMode::AbsoluteX: return "abs, x";
|
||||
case AddressingMode::AbsoluteY: return "abs, y";
|
||||
case AddressingMode::ZeroPage: return "zp";
|
||||
case AddressingMode::ZeroPageX: return "zp, x";
|
||||
case AddressingMode::ZeroPageY: return "zp, y";
|
||||
case AddressingMode::XIndirect: return "((zp, x))";
|
||||
case AddressingMode::IndirectY: return "((zp), y)";
|
||||
case AddressingMode::Relative: return "rel";
|
||||
case AddressingMode::AbsoluteIndirect: return "(abs)";
|
||||
case AddressingMode::ZeroPageIndirect: return "(zp)";
|
||||
case AddressingMode::SpecialPage: return "\\sp";
|
||||
case AddressingMode::ImmediateZeroPage: return "#, zp";
|
||||
case AddressingMode::AccumulatorRelative: return "A, rel";
|
||||
case AddressingMode::ZeroPageRelative: return "zp, rel";
|
||||
}
|
||||
|
||||
return "???";
|
||||
}
|
||||
|
||||
inline std::ostream &operator <<(std::ostream &stream, AddressingMode mode) {
|
||||
stream << addressing_mode_name(mode);
|
||||
return stream;
|
||||
}
|
||||
|
||||
/*!
|
||||
@returns The way that the address for an operation with @c addressing_mode and encoded starting from @c operation
|
||||
would appear in an assembler. E.g. '$5a' for that zero page address, or '$5a, x' for zero-page indexed from $5a. This function
|
||||
may access up to three bytes from @c operation onwards.
|
||||
*/
|
||||
inline std::string address(AddressingMode addressing_mode, const uint8_t *operation, uint16_t program_counter) {
|
||||
std::stringstream output;
|
||||
output << std::hex;
|
||||
|
||||
#define NUM(x) std::setfill('0') << std::setw(2) << int(x)
|
||||
#define NUM4(x) std::setfill('0') << std::setw(4) << int(x)
|
||||
switch(addressing_mode) {
|
||||
default: return "???";
|
||||
case AddressingMode::Implied: return "";
|
||||
case AddressingMode::Accumulator: return "A ";
|
||||
case AddressingMode::Immediate: output << "#$" << NUM(operation[1]); break;
|
||||
case AddressingMode::Absolute: output << "$" << NUM(operation[2]) << NUM(operation[1]); break;
|
||||
case AddressingMode::AbsoluteX: output << "$" << NUM(operation[2]) << NUM(operation[1]) << ", x"; break;
|
||||
case AddressingMode::AbsoluteY: output << "$" << NUM(operation[2]) << NUM(operation[1]) << ", y"; break;
|
||||
case AddressingMode::ZeroPage: output << "$" << NUM(operation[1]); break;
|
||||
case AddressingMode::ZeroPageX: output << "$" << NUM(operation[1]) << ", x"; break;
|
||||
case AddressingMode::ZeroPageY: output << "$" << NUM(operation[1]) << ", y"; break;
|
||||
case AddressingMode::XIndirect: output << "(($" << NUM(operation[1]) << ", x))"; break;
|
||||
case AddressingMode::IndirectY: output << "(($" << NUM(operation[1]) << "), y)"; break;
|
||||
case AddressingMode::Relative: output << "#$" << NUM4(2 + program_counter + int8_t(operation[1])); break;
|
||||
case AddressingMode::AbsoluteIndirect: output << "($" << NUM(operation[2]) << NUM(operation[1]) << ") "; break;
|
||||
case AddressingMode::ZeroPageIndirect: output << "($" << NUM(operation[1]) << ")"; break;
|
||||
case AddressingMode::SpecialPage: output << "$1f" << NUM(operation[1]); break;
|
||||
case AddressingMode::ImmediateZeroPage: output << "#$" << NUM(operation[1]) << ", $" << NUM(operation[2]); break;
|
||||
case AddressingMode::AccumulatorRelative: output << "A, $" << NUM4(2 + program_counter + int8_t(operation[1])); break;
|
||||
case AddressingMode::ZeroPageRelative:
|
||||
output << "$" << NUM(operation[1]) << ", $" << NUM4(3 + program_counter + int8_t(operation[2]));
|
||||
break;
|
||||
}
|
||||
#undef NUM4
|
||||
#undef NUM
|
||||
|
||||
return output.str();
|
||||
}
|
||||
|
||||
/*!
|
||||
Models a complete M50740-style instruction, including its operation, addressing mode and opcode.
|
||||
*/
|
||||
struct Instruction {
|
||||
Operation operation = Operation::Invalid;
|
||||
AddressingMode addressing_mode = AddressingMode::Implied;
|
||||
uint8_t opcode = 0;
|
||||
|
||||
Instruction(Operation operation, AddressingMode addressing_mode, uint8_t opcode) : operation(operation), addressing_mode(addressing_mode), opcode(opcode) {}
|
||||
Instruction(uint8_t opcode) : opcode(opcode) {}
|
||||
Instruction() {}
|
||||
};
|
||||
|
||||
/*!
|
||||
Outputs a description of @c instruction to @c stream.
|
||||
*/
|
||||
inline std::ostream &operator <<(std::ostream &stream, const Instruction &instruction) {
|
||||
stream << operation_name(instruction.operation) << " " << addressing_mode_name(instruction.addressing_mode);
|
||||
return stream;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
#endif /* InstructionSets_M50740_Instruction_h */
|
||||
125
InstructionSets/M50740/Parser.hpp
Normal file
125
InstructionSets/M50740/Parser.hpp
Normal file
@@ -0,0 +1,125 @@
|
||||
//
|
||||
// Parser.hpp
|
||||
// Clock Signal
|
||||
//
|
||||
// Created by Thomas Harte on 16/01/21.
|
||||
// Copyright © 2021 Thomas Harte. All rights reserved.
|
||||
//
|
||||
|
||||
#ifndef InstructionSets_M50740_Parser_hpp
|
||||
#define InstructionSets_M50740_Parser_hpp
|
||||
|
||||
#include <cstdint>
|
||||
#include "Decoder.hpp"
|
||||
#include "../AccessType.hpp"
|
||||
|
||||
namespace InstructionSet {
|
||||
namespace M50740 {
|
||||
|
||||
template<typename Target, bool include_entries_and_accesses> struct Parser {
|
||||
void parse(Target &target, const uint8_t *storage, uint16_t start, uint16_t closing_bound) {
|
||||
Decoder decoder;
|
||||
|
||||
while(start <= closing_bound) {
|
||||
const auto next = decoder.decode(&storage[start], 1 + closing_bound - start);
|
||||
if(next.first <= 0) {
|
||||
// If there weren't enough bytes left before the closing bound to complete
|
||||
// an instruction, but implicitly there were some bytes left, announce overflow
|
||||
// and terminate.
|
||||
target.announce_overflow(start);
|
||||
return;
|
||||
} else {
|
||||
// Pass on the instruction.
|
||||
target.announce_instruction(start, next.second);
|
||||
|
||||
if constexpr(!include_entries_and_accesses) {
|
||||
// Do a simplified test: is this a terminating operation?
|
||||
switch(next.second.operation) {
|
||||
case Operation::RTS: case Operation::RTI: case Operation::BRK:
|
||||
case Operation::JMP: case Operation::BRA:
|
||||
return;
|
||||
|
||||
default: break;
|
||||
}
|
||||
} else {
|
||||
// Check for end of stream and potential new entry points.
|
||||
switch(next.second.operation) {
|
||||
// Terminating instructions.
|
||||
case Operation::RTS: case Operation::RTI: case Operation::BRK:
|
||||
return;
|
||||
|
||||
// Terminating operations, possibly with implied additional entry point.
|
||||
case Operation::JMP:
|
||||
if(next.second.addressing_mode == AddressingMode::Absolute) {
|
||||
target.add_entry(uint16_t(storage[start + 1] | (storage[start + 2] << 8)));
|
||||
}
|
||||
return;
|
||||
case Operation::BRA:
|
||||
target.add_entry(uint16_t(start + 2 + int8_t(storage[start + 1])));
|
||||
return;
|
||||
|
||||
// Instructions that suggest another entry point but don't terminate parsing.
|
||||
case Operation::BCC: case Operation::BCS:
|
||||
case Operation::BVC: case Operation::BVS:
|
||||
case Operation::BMI: case Operation::BPL:
|
||||
case Operation::BNE: case Operation::BEQ:
|
||||
target.add_entry(uint16_t(start + 2 + int8_t(storage[start + 1])));
|
||||
break;
|
||||
case Operation::JSR:
|
||||
switch(next.second.addressing_mode) {
|
||||
default: break;
|
||||
case AddressingMode::Absolute:
|
||||
target.add_entry(uint16_t(storage[start + 1] | (storage[start + 2] << 8)));
|
||||
break;
|
||||
case AddressingMode::SpecialPage:
|
||||
target.add_entry(uint16_t(storage[start + 1] | 0x1f00));
|
||||
break;
|
||||
}
|
||||
break;
|
||||
|
||||
case Operation::BBS0: case Operation::BBS1: case Operation::BBS2: case Operation::BBS3:
|
||||
case Operation::BBS4: case Operation::BBS5: case Operation::BBS6: case Operation::BBS7:
|
||||
case Operation::BBC0: case Operation::BBC1: case Operation::BBC2: case Operation::BBC3:
|
||||
case Operation::BBC4: case Operation::BBC5: case Operation::BBC6: case Operation::BBC7:
|
||||
switch(next.second.addressing_mode) {
|
||||
default: break;
|
||||
case AddressingMode::AccumulatorRelative:
|
||||
target.add_entry(uint16_t(start + 2 + int8_t(storage[start + 1])));
|
||||
break;
|
||||
case AddressingMode::ZeroPageRelative:
|
||||
target.add_entry(uint16_t(start + 3 + int8_t(storage[start + 2])));
|
||||
break;
|
||||
}
|
||||
break;
|
||||
|
||||
|
||||
default: break;
|
||||
}
|
||||
|
||||
// Provide any fixed address accesses.
|
||||
switch(next.second.addressing_mode) {
|
||||
case AddressingMode::Absolute:
|
||||
target.add_access(uint16_t(storage[start + 1] | (storage[start + 2] << 8)), access_type(next.second.operation));
|
||||
break;
|
||||
case AddressingMode::ZeroPage: case AddressingMode::ZeroPageRelative:
|
||||
target.add_access(storage[start + 1], access_type(next.second.operation));
|
||||
break;
|
||||
case AddressingMode::ImmediateZeroPage:
|
||||
target.add_access(storage[start + 2], access_type(next.second.operation));
|
||||
break;
|
||||
|
||||
default: break;
|
||||
}
|
||||
}
|
||||
|
||||
// Advance.
|
||||
start += next.first;
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
#endif /* InstructionSets_M50740_Parser_hpp */
|
||||
347
InstructionSets/PowerPC/Decoder.cpp
Normal file
347
InstructionSets/PowerPC/Decoder.cpp
Normal file
@@ -0,0 +1,347 @@
|
||||
//
|
||||
// Decoder.cpp
|
||||
// Clock Signal
|
||||
//
|
||||
// Created by Thomas Harte on 30/12/20.
|
||||
// Copyright © 2020 Thomas Harte. All rights reserved.
|
||||
//
|
||||
|
||||
#include "Decoder.hpp"
|
||||
|
||||
using namespace InstructionSet::PowerPC;
|
||||
|
||||
Decoder::Decoder(Model model) : model_(model) {}
|
||||
|
||||
Instruction Decoder::decode(uint32_t opcode) {
|
||||
// Quick bluffer's guide to PowerPC instruction encoding:
|
||||
//
|
||||
// There is a six-bit field at the very top of the instruction.
|
||||
// Sometimes that fully identifies an instruction, but usually
|
||||
// it doesn't.
|
||||
//
|
||||
// There is an addition 9- or 10-bit field starting one bit above
|
||||
// least significant that disambiguates the rest. Strictly speaking
|
||||
// it's a 10-bit field, but the mnemonics for many instructions treat
|
||||
// it as a 9-bit field with a flag at the top.
|
||||
//
|
||||
// I've decided to hew directly to the mnemonics.
|
||||
//
|
||||
// Various opcodes in the 1995 documentation define reserved bits,
|
||||
// which are given the nominal value of 0. It does not give a formal
|
||||
// definition of a reserved bit. As a result this code does not
|
||||
// currently check the value of reserved bits. That may need to change
|
||||
// if/when I add support for extended instruction sets.
|
||||
|
||||
#define Bind(mask, operation) case mask: return Instruction(Operation::operation, opcode);
|
||||
#define BindSupervisor(mask, operation) case mask: return Instruction(Operation::operation, opcode, true);
|
||||
#define BindConditional(condition, mask, operation) \
|
||||
case mask: \
|
||||
if(condition()) return Instruction(Operation::operation, opcode); \
|
||||
return Instruction(opcode);
|
||||
#define BindSupervisorConditional(condition, mask, operation) \
|
||||
case mask: \
|
||||
if(condition()) return Instruction(Operation::operation, opcode, true); \
|
||||
return Instruction(opcode);
|
||||
|
||||
#define Six(x) (unsigned(x) << 26)
|
||||
#define SixTen(x, y) (Six(x) | ((y) << 1))
|
||||
|
||||
// First pass: weed out all those instructions identified entirely by the
|
||||
// top six bits.
|
||||
switch(opcode & Six(0b111111)) {
|
||||
default: break;
|
||||
|
||||
BindConditional(is64bit, Six(0b000010), tdi);
|
||||
|
||||
Bind(Six(0b000011), twi);
|
||||
Bind(Six(0b000111), mulli);
|
||||
Bind(Six(0b001000), subfic);
|
||||
Bind(Six(0b001100), addic); Bind(Six(0b001101), addic_);
|
||||
Bind(Six(0b001110), addi); Bind(Six(0b001111), addis);
|
||||
case Six(0b010000): {
|
||||
// This might be a bcx, but check for a valid bo field.
|
||||
switch((opcode >> 21) & 0x1f) {
|
||||
case 0: case 1: case 2: case 3: case 4: case 5:
|
||||
case 8: case 9: case 10: case 11: case 12: case 13:
|
||||
case 16: case 17: case 18: case 19: case 20:
|
||||
return Instruction(Operation::bcx, opcode);
|
||||
|
||||
default: return Instruction(opcode);
|
||||
}
|
||||
} break;
|
||||
Bind(Six(0b010010), bx);
|
||||
Bind(Six(0b010100), rlwimix);
|
||||
Bind(Six(0b010101), rlwinmx);
|
||||
Bind(Six(0b010111), rlwnmx);
|
||||
|
||||
Bind(Six(0b011000), ori); Bind(Six(0b011001), oris);
|
||||
Bind(Six(0b011010), xori); Bind(Six(0b011011), xoris);
|
||||
Bind(Six(0b011100), andi_); Bind(Six(0b011101), andis_);
|
||||
Bind(Six(0b100000), lwz); Bind(Six(0b100001), lwzu);
|
||||
Bind(Six(0b100010), lbz); Bind(Six(0b100011), lbzu);
|
||||
Bind(Six(0b100100), stw); Bind(Six(0b100101), stwu);
|
||||
Bind(Six(0b100110), stb); Bind(Six(0b100111), stbu);
|
||||
Bind(Six(0b101000), lhz); Bind(Six(0b101001), lhzu);
|
||||
Bind(Six(0b101010), lha); Bind(Six(0b101011), lhau);
|
||||
Bind(Six(0b101100), sth); Bind(Six(0b101101), sthu);
|
||||
Bind(Six(0b101110), lmw); Bind(Six(0b101111), stmw);
|
||||
Bind(Six(0b110000), lfs); Bind(Six(0b110001), lfsu);
|
||||
Bind(Six(0b110010), lfd); Bind(Six(0b110011), lfdu);
|
||||
Bind(Six(0b110100), stfs); Bind(Six(0b110101), stfsu);
|
||||
Bind(Six(0b110110), stfd); Bind(Six(0b110111), stfdu);
|
||||
|
||||
BindConditional(is601, Six(9), dozi);
|
||||
BindConditional(is601, Six(22), rlmix);
|
||||
|
||||
Bind(Six(0b001010), cmpli); Bind(Six(0b001011), cmpi);
|
||||
}
|
||||
|
||||
// Second pass: all those with a top six bits and a bottom nine or ten.
|
||||
switch(opcode & SixTen(0b111111, 0b1111111111)) {
|
||||
default: break;
|
||||
|
||||
// 64-bit instructions.
|
||||
BindConditional(is64bit, SixTen(0b011111, 0b0000001001), mulhdux); BindConditional(is64bit, SixTen(0b011111, 0b1000001001), mulhdux);
|
||||
BindConditional(is64bit, SixTen(0b011111, 0b0000010101), ldx);
|
||||
BindConditional(is64bit, SixTen(0b011111, 0b0000011011), sldx);
|
||||
BindConditional(is64bit, SixTen(0b011111, 0b0000110101), ldux);
|
||||
BindConditional(is64bit, SixTen(0b011111, 0b0000111010), cntlzdx);
|
||||
BindConditional(is64bit, SixTen(0b011111, 0b0001000100), td);
|
||||
BindConditional(is64bit, SixTen(0b011111, 0b0001001001), mulhdx); BindConditional(is64bit, SixTen(0b011111, 0b1001001001), mulhdx);
|
||||
BindConditional(is64bit, SixTen(0b011111, 0b0001010100), ldarx);
|
||||
BindConditional(is64bit, SixTen(0b011111, 0b0010010101), stdx);
|
||||
BindConditional(is64bit, SixTen(0b011111, 0b0010110101), stdux);
|
||||
BindConditional(is64bit, SixTen(0b011111, 0b0011101001), mulld); BindConditional(is64bit, SixTen(0b011111, 0b1011101001), mulld);
|
||||
BindConditional(is64bit, SixTen(0b011111, 0b0101010101), lwax);
|
||||
BindConditional(is64bit, SixTen(0b011111, 0b0101110101), lwaux);
|
||||
BindConditional(is64bit, SixTen(0b011111, 0b1100111011), sradix); BindConditional(is64bit, SixTen(0b011111, 0b1100111010), sradix);
|
||||
BindConditional(is64bit, SixTen(0b011111, 0b0110110010), slbie);
|
||||
BindConditional(is64bit, SixTen(0b011111, 0b0111001001), divdux); BindConditional(is64bit, SixTen(0b011111, 0b1111001001), divdux);
|
||||
BindConditional(is64bit, SixTen(0b011111, 0b0111101001), divdx); BindConditional(is64bit, SixTen(0b011111, 0b1111101001), divdx);
|
||||
BindConditional(is64bit, SixTen(0b011111, 0b1000011011), srdx);
|
||||
BindConditional(is64bit, SixTen(0b011111, 0b1100011010), sradx);
|
||||
BindConditional(is64bit, SixTen(0b111111, 0b1111011010), extsw);
|
||||
|
||||
// Power instructions; these are all taken from the MPC601 manual rather than
|
||||
// the PowerPC Programmer's Reference Guide, hence the decimal encoding of the
|
||||
// ten-bit field.
|
||||
BindConditional(is601, SixTen(0b011111, 360), absx); BindConditional(is601, SixTen(0b011111, 512 + 360), absx);
|
||||
BindConditional(is601, SixTen(0b011111, 531), clcs);
|
||||
BindConditional(is601, SixTen(0b011111, 331), divx); BindConditional(is601, SixTen(0b011111, 512 + 331), divx);
|
||||
BindConditional(is601, SixTen(0b011111, 363), divsx); BindConditional(is601, SixTen(0b011111, 512 + 363), divsx);
|
||||
BindConditional(is601, SixTen(0b011111, 264), dozx); BindConditional(is601, SixTen(0b011111, 512 + 264), dozx);
|
||||
BindConditional(is601, SixTen(0b011111, 277), lscbxx);
|
||||
BindConditional(is601, SixTen(0b011111, 29), maskgx);
|
||||
BindConditional(is601, SixTen(0b011111, 541), maskirx);
|
||||
BindConditional(is601, SixTen(0b011111, 107), mulx); BindConditional(is601, SixTen(0b011111, 512 + 107), mulx);
|
||||
BindConditional(is601, SixTen(0b011111, 488), nabsx); BindConditional(is601, SixTen(0b011111, 512 + 488), nabsx);
|
||||
BindConditional(is601, SixTen(0b011111, 537), rribx);
|
||||
BindConditional(is601, SixTen(0b011111, 153), slex);
|
||||
BindConditional(is601, SixTen(0b011111, 217), sleqx);
|
||||
BindConditional(is601, SixTen(0b011111, 184), sliqx);
|
||||
BindConditional(is601, SixTen(0b011111, 248), slliqx);
|
||||
BindConditional(is601, SixTen(0b011111, 216), sllqx);
|
||||
BindConditional(is601, SixTen(0b011111, 152), slqx);
|
||||
BindConditional(is601, SixTen(0b011111, 952), sraiqx);
|
||||
BindConditional(is601, SixTen(0b011111, 920), sraqx);
|
||||
BindConditional(is601, SixTen(0b011111, 665), srex);
|
||||
BindConditional(is601, SixTen(0b011111, 921), sreax);
|
||||
BindConditional(is601, SixTen(0b011111, 729), sreqx);
|
||||
BindConditional(is601, SixTen(0b011111, 696), sriqx);
|
||||
BindConditional(is601, SixTen(0b011111, 760), srliqx);
|
||||
BindConditional(is601, SixTen(0b011111, 728), srlqx);
|
||||
BindConditional(is601, SixTen(0b011111, 664), srqx);
|
||||
|
||||
// 32-bit instructions.
|
||||
Bind(SixTen(0b010011, 0b0000000000), mcrf);
|
||||
Bind(SixTen(0b010011, 0b0000010000), bclrx);
|
||||
Bind(SixTen(0b010011, 0b0000100001), crnor);
|
||||
Bind(SixTen(0b010011, 0b0000110010), rfi);
|
||||
Bind(SixTen(0b010011, 0b0010000001), crandc);
|
||||
Bind(SixTen(0b010011, 0b0010010110), isync);
|
||||
Bind(SixTen(0b010011, 0b0011000001), crxor);
|
||||
Bind(SixTen(0b010011, 0b0011100001), crnand);
|
||||
Bind(SixTen(0b010011, 0b0100000001), crand);
|
||||
Bind(SixTen(0b010011, 0b0100100001), creqv);
|
||||
Bind(SixTen(0b010011, 0b0110100001), crorc);
|
||||
Bind(SixTen(0b010011, 0b0111000001), cror);
|
||||
Bind(SixTen(0b010011, 0b1000010000), bcctrx);
|
||||
Bind(SixTen(0b011111, 0b0000000000), cmp);
|
||||
Bind(SixTen(0b011111, 0b0000000100), tw);
|
||||
Bind(SixTen(0b011111, 0b0000001000), subfcx); Bind(SixTen(0b011111, 0b1000001000), subfcx);
|
||||
Bind(SixTen(0b011111, 0b0000001010), addcx); Bind(SixTen(0b011111, 0b1000001010), addcx);
|
||||
Bind(SixTen(0b011111, 0b0000001011), mulhwux); Bind(SixTen(0b011111, 0b1000001011), mulhwux);
|
||||
Bind(SixTen(0b011111, 0b0000010011), mfcr);
|
||||
Bind(SixTen(0b011111, 0b0000010100), lwarx);
|
||||
Bind(SixTen(0b011111, 0b0000010111), lwzx);
|
||||
Bind(SixTen(0b011111, 0b0000011000), slwx);
|
||||
Bind(SixTen(0b011111, 0b0000011010), cntlzwx);
|
||||
Bind(SixTen(0b011111, 0b0000011100), andx);
|
||||
Bind(SixTen(0b011111, 0b0000100000), cmpl);
|
||||
Bind(SixTen(0b011111, 0b0000101000), subfx); Bind(SixTen(0b011111, 0b1000101000), subfx);
|
||||
Bind(SixTen(0b011111, 0b0000110110), dcbst);
|
||||
Bind(SixTen(0b011111, 0b0000110111), lwzux);
|
||||
Bind(SixTen(0b011111, 0b0000111100), andcx);
|
||||
Bind(SixTen(0b011111, 0b0001001011), mulhwx); Bind(SixTen(0b011111, 0b1001001011), mulhwx);
|
||||
Bind(SixTen(0b011111, 0b0001010011), mfmsr);
|
||||
Bind(SixTen(0b011111, 0b0001010110), dcbf);
|
||||
Bind(SixTen(0b011111, 0b0001010111), lbzx);
|
||||
Bind(SixTen(0b011111, 0b0001101000), negx); Bind(SixTen(0b011111, 0b1001101000), negx);
|
||||
Bind(SixTen(0b011111, 0b0001110111), lbzux);
|
||||
Bind(SixTen(0b011111, 0b0001111100), norx);
|
||||
Bind(SixTen(0b011111, 0b0010001000), subfex); Bind(SixTen(0b011111, 0b1010001000), subfex);
|
||||
Bind(SixTen(0b011111, 0b0010001010), addex); Bind(SixTen(0b011111, 0b1010001010), addex);
|
||||
Bind(SixTen(0b011111, 0b0010010000), mtcrf);
|
||||
Bind(SixTen(0b011111, 0b0010010010), mtmsr);
|
||||
Bind(SixTen(0b011111, 0b0010010111), stwx);
|
||||
Bind(SixTen(0b011111, 0b0010110111), stwux);
|
||||
Bind(SixTen(0b011111, 0b0011001000), subfzex); Bind(SixTen(0b011111, 0b1011001000), subfzex);
|
||||
Bind(SixTen(0b011111, 0b0011001010), addzex); Bind(SixTen(0b011111, 0b1011001010), addzex);
|
||||
Bind(SixTen(0b011111, 0b0011010111), stbx);
|
||||
Bind(SixTen(0b011111, 0b0011101000), subfmex); Bind(SixTen(0b011111, 0b1011101000), subfmex);
|
||||
Bind(SixTen(0b011111, 0b0011101010), addmex); Bind(SixTen(0b011111, 0b1011101010), addmex);
|
||||
Bind(SixTen(0b011111, 0b0011101011), mullwx); Bind(SixTen(0b011111, 0b1011101011), mullwx);
|
||||
Bind(SixTen(0b011111, 0b0011110110), dcbtst);
|
||||
Bind(SixTen(0b011111, 0b0011110111), stbux);
|
||||
Bind(SixTen(0b011111, 0b0100001010), addx); Bind(SixTen(0b011111, 0b1100001010), addx);
|
||||
Bind(SixTen(0b011111, 0b0100010110), dcbt);
|
||||
Bind(SixTen(0b011111, 0b0100010111), lhzx);
|
||||
Bind(SixTen(0b011111, 0b0100011100), eqvx);
|
||||
Bind(SixTen(0b011111, 0b0100110110), eciwx);
|
||||
Bind(SixTen(0b011111, 0b0100110111), lhzux);
|
||||
Bind(SixTen(0b011111, 0b0100111100), xorx);
|
||||
Bind(SixTen(0b011111, 0b0101010111), lhax);
|
||||
Bind(SixTen(0b011111, 0b0101110011), mftb);
|
||||
Bind(SixTen(0b011111, 0b0101110111), lhaux);
|
||||
Bind(SixTen(0b011111, 0b0110010111), sthx);
|
||||
Bind(SixTen(0b011111, 0b0110011100), orcx);
|
||||
Bind(SixTen(0b011111, 0b0110110110), ecowx);
|
||||
Bind(SixTen(0b011111, 0b0110110111), sthux);
|
||||
Bind(SixTen(0b011111, 0b0110111100), orx);
|
||||
Bind(SixTen(0b011111, 0b0111001011), divwux); Bind(SixTen(0b011111, 0b1111001011), divwux);
|
||||
Bind(SixTen(0b011111, 0b0111010110), dcbi);
|
||||
Bind(SixTen(0b011111, 0b0111011100), nandx);
|
||||
Bind(SixTen(0b011111, 0b0111101011), divwx); Bind(SixTen(0b011111, 0b1111101011), divwx);
|
||||
Bind(SixTen(0b011111, 0b1000000000), mcrxr);
|
||||
Bind(SixTen(0b011111, 0b1000010101), lswx);
|
||||
Bind(SixTen(0b011111, 0b1000010110), lwbrx);
|
||||
Bind(SixTen(0b011111, 0b1000010111), lfsx);
|
||||
Bind(SixTen(0b011111, 0b1000011000), srwx);
|
||||
Bind(SixTen(0b011111, 0b1000110111), lfsux);
|
||||
Bind(SixTen(0b011111, 0b1001010101), lswi);
|
||||
Bind(SixTen(0b011111, 0b1001010110), sync);
|
||||
Bind(SixTen(0b011111, 0b1001010111), lfdx);
|
||||
Bind(SixTen(0b011111, 0b1001110111), lfdux);
|
||||
Bind(SixTen(0b011111, 0b1010010101), stswx);
|
||||
Bind(SixTen(0b011111, 0b1010010110), stwbrx);
|
||||
Bind(SixTen(0b011111, 0b1010010111), stfsx);
|
||||
Bind(SixTen(0b011111, 0b1010110111), stfsux);
|
||||
Bind(SixTen(0b011111, 0b1011010101), stswi);
|
||||
Bind(SixTen(0b011111, 0b1011010111), stfdx);
|
||||
Bind(SixTen(0b011111, 0b1011110111), stfdux);
|
||||
Bind(SixTen(0b011111, 0b1100010110), lhbrx);
|
||||
Bind(SixTen(0b011111, 0b1100011000), srawx);
|
||||
Bind(SixTen(0b011111, 0b1100111000), srawix);
|
||||
Bind(SixTen(0b011111, 0b1101010110), eieio);
|
||||
Bind(SixTen(0b011111, 0b1110010110), sthbrx);
|
||||
Bind(SixTen(0b011111, 0b1110011010), extshx);
|
||||
Bind(SixTen(0b011111, 0b1110111010), extsbx);
|
||||
Bind(SixTen(0b011111, 0b1111010110), icbi);
|
||||
Bind(SixTen(0b011111, 0b1111010111), stfiwx);
|
||||
Bind(SixTen(0b011111, 0b1111110110), dcbz);
|
||||
Bind(SixTen(0b111111, 0b0000000000), fcmpu);
|
||||
Bind(SixTen(0b111111, 0b0000001100), frspx);
|
||||
Bind(SixTen(0b111111, 0b0000001110), fctiwx);
|
||||
Bind(SixTen(0b111111, 0b0000001111), fctiwzx);
|
||||
Bind(SixTen(0b111111, 0b0000100000), fcmpo);
|
||||
Bind(SixTen(0b111111, 0b0000100110), mtfsb1x);
|
||||
Bind(SixTen(0b111111, 0b0000101000), fnegx);
|
||||
Bind(SixTen(0b111111, 0b0001000000), mcrfs);
|
||||
Bind(SixTen(0b111111, 0b0001000110), mtfsb0x);
|
||||
Bind(SixTen(0b111111, 0b0001001000), fmrx);
|
||||
Bind(SixTen(0b111111, 0b0010000110), mtfsfix);
|
||||
Bind(SixTen(0b111111, 0b0010001000), fnabsx);
|
||||
Bind(SixTen(0b111111, 0b0100001000), fabsx);
|
||||
Bind(SixTen(0b111111, 0b1001000111), mffsx);
|
||||
Bind(SixTen(0b111111, 0b1011000111), mtfsfx);
|
||||
Bind(SixTen(0b111111, 0b1100101110), fctidx);
|
||||
Bind(SixTen(0b111111, 0b1100101111), fctidzx);
|
||||
Bind(SixTen(0b111111, 0b1101001110), fcfidx);
|
||||
|
||||
Bind(SixTen(0b011111, 0b0101010011), mfspr); // Flagged as "supervisor and user"?
|
||||
Bind(SixTen(0b011111, 0b0111010011), mtspr); // Flagged as "supervisor and user"?
|
||||
|
||||
BindSupervisorConditional(is32bit, SixTen(0b011111, 0b0011010010), mtsr);
|
||||
BindSupervisorConditional(is32bit, SixTen(0b011111, 0b0011110010), mtsrin);
|
||||
BindSupervisorConditional(is32bit, SixTen(0b011111, 0b1001010011), mfsr);
|
||||
BindSupervisorConditional(is32bit, SixTen(0b011111, 0b1010010011), mfsrin);
|
||||
|
||||
BindSupervisorConditional(is64bit, SixTen(0b011111, 0b0111110010), slbia); // optional
|
||||
|
||||
// The following are all optional; should I record that?
|
||||
BindSupervisor(SixTen(0b011111, 0b0100110010), tlbie);
|
||||
BindSupervisor(SixTen(0b011111, 0b0101110010), tlbia);
|
||||
BindSupervisor(SixTen(0b011111, 0b1000110110), tlbsync);
|
||||
}
|
||||
|
||||
// Third pass: like six-ten except that the top five of the final ten
|
||||
// are reserved (i.e. ignored here).
|
||||
switch(opcode & SixTen(0b111111, 0b11111)) {
|
||||
default: break;
|
||||
|
||||
Bind(SixTen(0b111011, 0b10010), fdivsx);
|
||||
Bind(SixTen(0b111011, 0b10100), fsubsx);
|
||||
Bind(SixTen(0b111011, 0b10101), faddsx);
|
||||
Bind(SixTen(0b111011, 0b11001), fmulsx);
|
||||
Bind(SixTen(0b111011, 0b11100), fmsubsx);
|
||||
Bind(SixTen(0b111011, 0b11101), fmaddsx);
|
||||
Bind(SixTen(0b111011, 0b11110), fnmsubsx);
|
||||
Bind(SixTen(0b111011, 0b11111), fnmaddsx);
|
||||
|
||||
Bind(SixTen(0b111111, 0b10010), fdivx);
|
||||
Bind(SixTen(0b111111, 0b10100), fsubx);
|
||||
Bind(SixTen(0b111111, 0b10101), faddx);
|
||||
Bind(SixTen(0b111111, 0b11001), fmulx);
|
||||
Bind(SixTen(0b111111, 0b11100), fmsubx);
|
||||
Bind(SixTen(0b111111, 0b11101), fmaddx);
|
||||
Bind(SixTen(0b111111, 0b11110), fnmsubx);
|
||||
Bind(SixTen(0b111111, 0b11111), fnmaddx);
|
||||
|
||||
BindConditional(is64bit, SixTen(0b111011, 0b10110), fsqrtsx);
|
||||
BindConditional(is64bit, SixTen(0b111011, 0b11000), fresx);
|
||||
|
||||
// Optional...
|
||||
Bind(SixTen(0b111111, 0b10110), fsqrtx);
|
||||
Bind(SixTen(0b111111, 0b10111), fselx);
|
||||
Bind(SixTen(0b111111, 0b11010), frsqrtex);
|
||||
}
|
||||
|
||||
// stwcx. and stdcx.
|
||||
switch(opcode & 0b111111'00'00000000'000'111111111'1){
|
||||
case 0b011111'00'00000000'00000'0010010110'1: return Instruction(Operation::stwcx_, opcode);
|
||||
case 0b011111'00'00000000'00000'0011010110'1:
|
||||
if(is64bit()) return Instruction(Operation::stdcx_, opcode);
|
||||
return Instruction(opcode);
|
||||
}
|
||||
|
||||
// std and stdu
|
||||
switch(opcode & 0b111111'00'00000000'00000000'000000'11){
|
||||
case 0b111110'00'00000000'00000000'000000'00: return Instruction(Operation::std, opcode);
|
||||
case 0b111110'00'00000000'00000000'000000'01:
|
||||
if(is64bit()) return Instruction(Operation::stdu, opcode);
|
||||
return Instruction(opcode);
|
||||
}
|
||||
|
||||
// sc
|
||||
if((opcode & 0b111111'00'00000000'00000000'000000'1'0) == 0b010001'00'00000000'00000000'000000'1'0) {
|
||||
return Instruction(Operation::sc, opcode);
|
||||
}
|
||||
|
||||
#undef Six
|
||||
#undef SixTen
|
||||
|
||||
#undef Bind
|
||||
#undef BindConditional
|
||||
|
||||
return Instruction(opcode);
|
||||
}
|
||||
56
InstructionSets/PowerPC/Decoder.hpp
Normal file
56
InstructionSets/PowerPC/Decoder.hpp
Normal file
@@ -0,0 +1,56 @@
|
||||
//
|
||||
// Decoder.hpp
|
||||
// Clock Signal
|
||||
//
|
||||
// Created by Thomas Harte on 30/12/20.
|
||||
// Copyright © 2020 Thomas Harte. All rights reserved.
|
||||
//
|
||||
|
||||
#ifndef InstructionSets_PowerPC_Decoder_hpp
|
||||
#define InstructionSets_PowerPC_Decoder_hpp
|
||||
|
||||
#include "Instruction.hpp"
|
||||
|
||||
namespace InstructionSet {
|
||||
namespace PowerPC {
|
||||
|
||||
enum class Model {
|
||||
/// i.e. 32-bit, with POWER carry-over instructions.
|
||||
MPC601,
|
||||
/// i.e. 32-bit, no POWER instructions.
|
||||
MPC603,
|
||||
/// i.e. 64-bit.
|
||||
MPC620,
|
||||
};
|
||||
|
||||
/*!
|
||||
Implements PowerPC instruction decoding.
|
||||
|
||||
This is an experimental implementation; it has not yet undergone significant testing.
|
||||
*/
|
||||
struct Decoder {
|
||||
public:
|
||||
Decoder(Model model);
|
||||
|
||||
Instruction decode(uint32_t opcode);
|
||||
|
||||
private:
|
||||
Model model_;
|
||||
|
||||
bool is64bit() const {
|
||||
return model_ == Model::MPC620;
|
||||
}
|
||||
|
||||
bool is32bit() const {
|
||||
return !is64bit();
|
||||
}
|
||||
|
||||
bool is601() const {
|
||||
return model_ == Model::MPC601;
|
||||
}
|
||||
};
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
#endif /* InstructionSets_PowerPC_Decoder_hpp */
|
||||
190
InstructionSets/PowerPC/Instruction.hpp
Normal file
190
InstructionSets/PowerPC/Instruction.hpp
Normal file
@@ -0,0 +1,190 @@
|
||||
//
|
||||
// Instruction.hpp
|
||||
// Clock Signal
|
||||
//
|
||||
// Created by Thomas Harte on 15/01/21.
|
||||
// Copyright © 2021 Thomas Harte. All rights reserved.
|
||||
//
|
||||
|
||||
#ifndef InstructionSets_PowerPC_Instruction_h
|
||||
#define InstructionSets_PowerPC_Instruction_h
|
||||
|
||||
#include <cstdint>
|
||||
|
||||
namespace InstructionSet {
|
||||
namespace PowerPC {
|
||||
|
||||
enum class Operation: uint8_t {
|
||||
Undefined,
|
||||
|
||||
// These 601-exclusive instructions; a lot of them are carry-overs
|
||||
// from POWER.
|
||||
absx, clcs, divx, divsx, dozx, dozi, lscbxx, maskgx, maskirx, mulx,
|
||||
nabsx, rlmix, rribx, slex, sleqx, sliqx, slliqx, sllqx, slqx,
|
||||
sraiqx, sraqx, srex, sreax, sreqx, sriqx, srliqx, srlqx, srqx,
|
||||
|
||||
// 32- and 64-bit PowerPC instructions.
|
||||
addx, addcx, addex, addi, addic, addic_, addis, addmex, addzex, andx,
|
||||
andcx, andi_, andis_, bx, bcx, bcctrx, bclrx, cmp, cmpi, cmpl, cmpli,
|
||||
cntlzwx, crand, crandc, creqv, crnand, crnor, cror, crorc, crxor, dcbf,
|
||||
dcbst, dcbt, dcbtst, dcbz, divwx, divwux, eciwx, ecowx, eieio, eqvx,
|
||||
extsbx, extshx, fabsx, faddx, faddsx, fcmpo, fcmpu, fctiwx, fctiwzx,
|
||||
fdivx, fdivsx, fmaddx, fmaddsx, fmrx, fmsubx, fmsubsx, fmulx, fmulsx,
|
||||
fnabsx, fnegx, fnmaddx, fnmaddsx, fnmsubx, fnmsubsx, frspx, fsubx, fsubsx,
|
||||
icbi, isync, lbz, lbzu, lbzux, lbzx, lfd, lfdu, lfdux, lfdx, lfs, lfsu,
|
||||
lfsux, lfsx, lha, lhau, lhaux, lhax, lhbrx, lhz, lhzu, lhzux, lhzx, lmw,
|
||||
lswi, lswx, lwarx, lwbrx, lwz, lwzu, lwzux, lwzx, mcrf, mcrfs, mcrxr,
|
||||
mfcr, mffsx, mfmsr, mfspr, mfsr, mfsrin, mtcrf, mtfsb0x, mtfsb1x, mtfsfx,
|
||||
mtfsfix, mtmsr, mtspr, mtsr, mtsrin, mulhwx, mulhwux, mulli, mullwx,
|
||||
nandx, negx, norx, orx, orcx, ori, oris, rfi, rlwimix, rlwinmx, rlwnmx,
|
||||
sc, slwx, srawx, srawix, srwx, stb, stbu, stbux, stbx, stfd, stfdu,
|
||||
stfdux, stfdx, stfs, stfsu, stfsux, stfsx, sth, sthbrx, sthu, sthux, sthx,
|
||||
stmw, stswi, stswx, stw, stwbrx, stwcx_, stwu, stwux, stwx, subfx, subfcx,
|
||||
subfex, subfic, subfmex, subfzex, sync, tw, twi, xorx, xori, xoris, mftb,
|
||||
|
||||
// 32-bit, supervisor level.
|
||||
dcbi,
|
||||
|
||||
// Supervisor, optional.
|
||||
tlbia, tlbie, tlbsync,
|
||||
|
||||
// Optional.
|
||||
fresx, frsqrtex, fselx, fsqrtx, slbia, slbie, stfiwx,
|
||||
|
||||
// 64-bit only PowerPC instructions.
|
||||
cntlzdx, divdx, divdux, extswx, fcfidx, fctidx, fctidzx, tdi, mulhdux,
|
||||
ldx, sldx, ldux, td, mulhdx, ldarx, stdx, stdux, mulld, lwax, lwaux,
|
||||
sradix, srdx, sradx, extsw, fsqrtsx, std, stdu, stdcx_,
|
||||
};
|
||||
|
||||
/*!
|
||||
Holds a decoded PowerPC instruction.
|
||||
|
||||
Implementation note: because the PowerPC encoding is particularly straightforward,
|
||||
only the operation has been decoded ahead of time; all other fields are decoded on-demand.
|
||||
|
||||
It would be possible to partition the ordering of Operations into user followed by supervisor,
|
||||
eliminating the storage necessary for a flag, but it wouldn't save anything due to alignment.
|
||||
*/
|
||||
struct Instruction {
|
||||
Operation operation = Operation::Undefined;
|
||||
bool is_supervisor = false;
|
||||
uint32_t opcode = 0;
|
||||
|
||||
Instruction() noexcept {}
|
||||
Instruction(uint32_t opcode) noexcept : opcode(opcode) {}
|
||||
Instruction(Operation operation, uint32_t opcode, bool is_supervisor = false) noexcept : operation(operation), is_supervisor(is_supervisor), opcode(opcode) {}
|
||||
|
||||
// Instruction fields are decoded below; naming is a compromise between
|
||||
// Motorola's documentation and IBM's.
|
||||
//
|
||||
// I've dutifully implemented various synonyms with unique entry points,
|
||||
// in order to capture that information here rather than thrusting it upon
|
||||
// the reader of whatever implementation may follow.
|
||||
|
||||
// Currently omitted: OPCD and XO, which I think are unnecessary given that
|
||||
// full decoding has already occurred.
|
||||
|
||||
/// Immediate field used to specify an unsigned 16-bit integer.
|
||||
uint16_t uimm() const { return uint16_t(opcode & 0xffff); }
|
||||
/// Immediate field used to specify a signed 16-bit integer.
|
||||
int16_t simm() const { return int16_t(opcode & 0xffff); }
|
||||
/// Immediate field used to specify a signed 16-bit integer.
|
||||
int16_t d() const { return int16_t(opcode & 0xffff); }
|
||||
/// Immediate field used to specify a signed 14-bit integer [64-bit only].
|
||||
int16_t ds() const { return int16_t(opcode & 0xfffc); }
|
||||
/// Immediate field used as data to be placed into a field in the floating point status and condition register.
|
||||
int32_t imm() const { return (opcode >> 12) & 0xf; }
|
||||
|
||||
/// Specifies the conditions on which to trap.
|
||||
int32_t to() const { return (opcode >> 21) & 0x1f; }
|
||||
|
||||
/// Register source A or destination.
|
||||
uint32_t rA() const { return (opcode >> 16) & 0x1f; }
|
||||
/// Register source B.
|
||||
uint32_t rB() const { return (opcode >> 11) & 0x1f; }
|
||||
/// Register destination.
|
||||
uint32_t rD() const { return (opcode >> 21) & 0x1f; }
|
||||
/// Register source.
|
||||
uint32_t rS() const { return (opcode >> 21) & 0x1f; }
|
||||
|
||||
/// Floating point register source A.
|
||||
uint32_t frA() const { return (opcode >> 16) & 0x1f; }
|
||||
/// Floating point register source B.
|
||||
uint32_t frB() const { return (opcode >> 11) & 0x1f; }
|
||||
/// Floating point register source C.
|
||||
uint32_t frC() const { return (opcode >> 6) & 0x1f; }
|
||||
/// Floating point register source.
|
||||
uint32_t frS() const { return (opcode >> 21) & 0x1f; }
|
||||
/// Floating point register destination.
|
||||
uint32_t frD() const { return (opcode >> 21) & 0x1f; }
|
||||
|
||||
/// Branch conditional options.
|
||||
uint32_t bo() const { return (opcode >> 21) & 0x1f; }
|
||||
/// Source condition register bit for branch conditionals.
|
||||
uint32_t bi() const { return (opcode >> 16) & 0x1f; }
|
||||
/// Branch displacement; provided as already sign extended.
|
||||
int16_t bd() const { return int16_t(opcode & 0xfffc); }
|
||||
|
||||
/// Specifies the first 1 bit of a 32/64-bit mask for rotate operations.
|
||||
uint32_t mb() const { return (opcode >> 6) & 0x1f; }
|
||||
/// Specifies the first 1 bit of a 32/64-bit mask for rotate operations.
|
||||
uint32_t me() const { return (opcode >> 1) & 0x1f; }
|
||||
|
||||
/// Condition register source bit A.
|
||||
uint32_t crbA() const { return (opcode >> 16) & 0x1f; }
|
||||
/// Condition register source bit B.
|
||||
uint32_t crbB() const { return (opcode >> 11) & 0x1f; }
|
||||
/// Condition register (or floating point status & condition register) destination bit.
|
||||
uint32_t crbD() const { return (opcode >> 21) & 0x1f; }
|
||||
|
||||
/// Condition register (or floating point status & condition register) destination field.
|
||||
uint32_t crfD() const { return (opcode >> 23) & 0x07; }
|
||||
/// Condition register (or floating point status & condition register) source field.
|
||||
uint32_t crfS() const { return (opcode >> 18) & 0x07; }
|
||||
|
||||
/// Mask identifying fields to be updated by mtcrf.
|
||||
uint32_t crm() const { return (opcode >> 12) & 0xff; }
|
||||
|
||||
/// Mask identifying fields to be updated by mtfsf.
|
||||
uint32_t fm() const { return (opcode >> 17) & 0xff; }
|
||||
|
||||
/// Specifies the number of bytes to move in an immediate string load or store.
|
||||
uint32_t nb() const { return (opcode >> 11) & 0x1f; }
|
||||
|
||||
/// Specifies a shift amount.
|
||||
/// TODO: possibly bit 30 is also used in 64-bit mode, find out.
|
||||
uint32_t sh() const { return (opcode >> 11) & 0x1f; }
|
||||
|
||||
/// Specifies one of the 16 segment registers [32-bit only].
|
||||
uint32_t sr() const { return (opcode >> 16) & 0xf; }
|
||||
|
||||
/// A 24-bit signed number; provided as already sign extended.
|
||||
int32_t li() const {
|
||||
constexpr uint32_t extensions[2] = {
|
||||
0x0000'0000,
|
||||
0xfc00'0000
|
||||
};
|
||||
const uint32_t value = (opcode & 0x03ff'fffc) | extensions[(opcode >> 25) & 1];
|
||||
return int32_t(value);
|
||||
}
|
||||
|
||||
/// Absolute address bit; @c 0 or @c non-0.
|
||||
uint32_t aa() const { return opcode & 0x02; }
|
||||
/// Link bit; @c 0 or @c non-0.
|
||||
uint32_t lk() const { return opcode & 0x01; }
|
||||
/// Record bit; @c 0 or @c non-0.
|
||||
uint32_t rc() const { return opcode & 0x01; }
|
||||
/// Whether to compare 32-bit or 64-bit numbers [for 64-bit implementations only]; @c 0 or @c non-0.
|
||||
uint32_t l() const { return opcode & 0x200000; }
|
||||
/// Enables setting of OV and SO in the XER; @c 0 or @c non-0.
|
||||
uint32_t oe() const { return opcode & 0x800; }
|
||||
};
|
||||
|
||||
// Sanity check on Instruction size.
|
||||
static_assert(sizeof(Instruction) <= 8);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
#endif /* InstructionSets_PowerPC_Instruction_h */
|
||||
86
InstructionSets/README.md
Normal file
86
InstructionSets/README.md
Normal file
@@ -0,0 +1,86 @@
|
||||
# Instruction Sets
|
||||
|
||||
Code in here provides the means to disassemble, and to execute code for certain instruction sets.
|
||||
|
||||
It **does not seek to emulate specific processors** other than in terms of implementing their instruction sets. So:
|
||||
* it doesn't involve itself in the actual bus signalling of real processors; and
|
||||
* instruction-level timing (e.g. total cycle counts) may be unimplemented, and is likely to be incomplete.
|
||||
|
||||
This part of CLK is intended primarily to provide disassembly services for static analysis, and processing for machines where timing is not part of the specification — i.e. anything that's an instruction set and a HAL.
|
||||
|
||||
## Decoders
|
||||
|
||||
A decoder extracts fully-decoded instructions from a data stream for its associated architecture.
|
||||
|
||||
The meaning of 'fully-decoded' is flexible but it means that a caller can easily discern at least:
|
||||
* the operation in use;
|
||||
* its addressing mode; and
|
||||
* relevant registers.
|
||||
|
||||
It may be assumed that callers will have access to the original data stream for immediate values, if it is sensible to do so.
|
||||
|
||||
In deciding what to expose, what to store ahead of time and what to obtain just-in-time a decoder should have an eye on two principal consumers:
|
||||
1. disassemblers; and
|
||||
2. instruction executors.
|
||||
|
||||
It may also be reasonable to make allowances for bus-centric CPU emulators, but those will be tightly coupled to specific decoders so no general rules need apply.
|
||||
|
||||
Disassemblers are likely to decode an instruction, output it, and then immediately forget about it.
|
||||
|
||||
Instruction executors may opt to cache decoded instructions to reduce recurrent costs, but will always be dealing with an actual instruction stream. The chance of caching means that decoded instructions should seek to be small. If helpful then a decoder might prefer to return a `std::pair` or similar of ephemeral information and stuff that it is meaningful to store.
|
||||
|
||||
### Likely Interfaces
|
||||
|
||||
These examples assume that the processor itself doesn't hold any state that affects instruction parsing. Whether processors with such state offer more than one decoder or take state as an argument will be a question of measure and effect.
|
||||
|
||||
#### Fixed-size instruction words
|
||||
|
||||
If the instructions are a fixed size, the decoder can provide what is functionally a simple lookup, whether implemented as such or not:
|
||||
|
||||
Instruction decode(word_type instruction) { ... }
|
||||
|
||||
For now I have preferred not to make this a simple constructor on `Instruction` because I'm reserving the option of switching to an ephemeral/permanent split in what's returned. More consideration needs to be applied here.
|
||||
|
||||
#### Variable-size instruction words
|
||||
|
||||
If instructions are a variable size, the decoder should maintain internal state such that it can be provided with fragments of instructions until a full decoding has occurred — this avoids an assumption that all source bytes will always be laid out linearly in memory.
|
||||
|
||||
A sample interface:
|
||||
|
||||
std::pair<int, Instruction> decode(word_type *stream, size_t length) { ... }
|
||||
|
||||
In this sample the returned pair provides an `int` size that is one of:
|
||||
* a positive number, indicating a completed decoding that consumed that many `word_type`s; or
|
||||
* a negative number, indicating the [negatived] minimum number of `word_type`s that the caller should try to get hold of before calling `decode` again.
|
||||
|
||||
A caller is permitted to react in any way it prefers to negative numbers; they're a hint potentially to reduce calling overhead only. A size of `0` would be taken to have the same meaning as a size of `-1`.
|
||||
|
||||
## Parsers
|
||||
|
||||
A parser sits one level above a decoder; it is handed:
|
||||
* a start address;
|
||||
* a closing bound; and
|
||||
* a target.
|
||||
|
||||
It is responsible for parsing the instruction stream from the start address up to and not beyond the closing bound, and no further than any unconditional branches.
|
||||
|
||||
It should post to the target:
|
||||
* any instructions fully decoded;
|
||||
* any conditional branch destinations encountered;
|
||||
* any immediately-knowable accessed addresses; and
|
||||
* if a final instruction exists but runs beyond the closing bound, notification of that fact.
|
||||
|
||||
So a parser has the same two primary potential recipients as a decoder: diassemblers, and executors.
|
||||
|
||||
## Executors
|
||||
|
||||
An executor is responsible for only one thing:
|
||||
* mapping from decoded instructions to objects that can perform those instructions.
|
||||
|
||||
An executor is assumed to bundle all the things that go into instruction set execution: processor state and memory, alongside a parser.
|
||||
|
||||
## Caching Executor
|
||||
|
||||
The caching executor is a generic class templated on a specific executor. It will use an executor to cache the results of parsing.
|
||||
|
||||
Idiomatically, the objects that perform instructions will expect to receive an appropriate executor as an argument. If they require other information, such as a copy of the decoded instruction, it should be built into the classes.
|
||||
625
InstructionSets/x86/Decoder.cpp
Normal file
625
InstructionSets/x86/Decoder.cpp
Normal file
@@ -0,0 +1,625 @@
|
||||
//
|
||||
// x86.cpp
|
||||
// Clock Signal
|
||||
//
|
||||
// Created by Thomas Harte on 01/01/21.
|
||||
// Copyright © 2021 Thomas Harte. All rights reserved.
|
||||
//
|
||||
|
||||
#include "Decoder.hpp"
|
||||
|
||||
#include <algorithm>
|
||||
#include <cassert>
|
||||
#include <utility>
|
||||
|
||||
using namespace InstructionSet::x86;
|
||||
|
||||
// Only 8086 is suppoted for now.
|
||||
Decoder::Decoder(Model) {}
|
||||
|
||||
std::pair<int, InstructionSet::x86::Instruction> Decoder::decode(const uint8_t *source, size_t length) {
|
||||
const uint8_t *const end = source + length;
|
||||
|
||||
// MARK: - Prefixes (if present) and the opcode.
|
||||
|
||||
/// Helper macro for those that follow.
|
||||
#define SetOpSrcDestSize(op, src, dest, size) \
|
||||
operation_ = Operation::op; \
|
||||
source_ = Source::src; \
|
||||
destination_ = Source::dest; \
|
||||
operation_size_ = size
|
||||
|
||||
/// Covers anything which is complete as soon as the opcode is encountered.
|
||||
#define Complete(op, src, dest, size) \
|
||||
SetOpSrcDestSize(op, src, dest, size); \
|
||||
phase_ = Phase::ReadyToPost
|
||||
|
||||
/// Handles instructions of the form rr, kk and rr, jjkk, i.e. a destination register plus an operand.
|
||||
#define RegData(op, dest, size) \
|
||||
SetOpSrcDestSize(op, DirectAddress, dest, size); \
|
||||
source_ = Source::Immediate; \
|
||||
operand_size_ = size; \
|
||||
phase_ = Phase::AwaitingDisplacementOrOperand
|
||||
|
||||
/// Handles instructions of the form Ax, jjkk where the latter is implicitly an address.
|
||||
#define RegAddr(op, dest, op_size, addr_size) \
|
||||
SetOpSrcDestSize(op, DirectAddress, dest, op_size); \
|
||||
operand_size_ = addr_size; \
|
||||
phase_ = Phase::AwaitingDisplacementOrOperand
|
||||
|
||||
/// Handles instructions of the form jjkk, Ax where the former is implicitly an address.
|
||||
#define AddrReg(op, source, op_size, addr_size) \
|
||||
SetOpSrcDestSize(op, source, DirectAddress, op_size); \
|
||||
operand_size_ = addr_size; \
|
||||
destination_ = Source::DirectAddress; \
|
||||
phase_ = Phase::AwaitingDisplacementOrOperand
|
||||
|
||||
/// Covers both `mem/reg, reg` and `reg, mem/reg`.
|
||||
#define MemRegReg(op, format, size) \
|
||||
operation_ = Operation::op; \
|
||||
phase_ = Phase::ModRegRM; \
|
||||
modregrm_format_ = ModRegRMFormat::format; \
|
||||
operand_size_ = 0; \
|
||||
operation_size_ = size
|
||||
|
||||
/// Handles JO, JNO, JB, etc — jumps with a single byte displacement.
|
||||
#define Jump(op) \
|
||||
operation_ = Operation::op; \
|
||||
phase_ = Phase::AwaitingDisplacementOrOperand; \
|
||||
displacement_size_ = 1
|
||||
|
||||
/// Handles far CALL and far JMP — fixed four byte operand operations.
|
||||
#define Far(op) \
|
||||
operation_ = Operation::op; \
|
||||
phase_ = Phase::AwaitingDisplacementOrOperand; \
|
||||
operand_size_ = 4; \
|
||||
|
||||
while(phase_ == Phase::Instruction && source != end) {
|
||||
// Retain the instruction byte, in case additional decoding is deferred
|
||||
// to the ModRegRM byte.
|
||||
instr_ = *source;
|
||||
++source;
|
||||
++consumed_;
|
||||
|
||||
switch(instr_) {
|
||||
default: {
|
||||
const auto result = std::make_pair(consumed_, Instruction());
|
||||
reset_parsing();
|
||||
return result;
|
||||
}
|
||||
|
||||
#define PartialBlock(start, operation) \
|
||||
case start + 0x00: MemRegReg(operation, MemReg_Reg, 1); break; \
|
||||
case start + 0x01: MemRegReg(operation, MemReg_Reg, 2); break; \
|
||||
case start + 0x02: MemRegReg(operation, Reg_MemReg, 1); break; \
|
||||
case start + 0x03: MemRegReg(operation, Reg_MemReg, 2); break; \
|
||||
case start + 0x04: RegData(operation, AL, 1); break; \
|
||||
case start + 0x05: RegData(operation, AX, 2)
|
||||
|
||||
PartialBlock(0x00, ADD); break;
|
||||
case 0x06: Complete(PUSH, ES, None, 2); break;
|
||||
case 0x07: Complete(POP, None, ES, 2); break;
|
||||
|
||||
PartialBlock(0x08, OR); break;
|
||||
case 0x0e: Complete(PUSH, CS, None, 2); break;
|
||||
|
||||
PartialBlock(0x10, ADC); break;
|
||||
case 0x16: Complete(PUSH, SS, None, 2); break;
|
||||
case 0x17: Complete(POP, None, SS, 2); break;
|
||||
|
||||
PartialBlock(0x18, SBB); break;
|
||||
case 0x1e: Complete(PUSH, DS, None, 2); break;
|
||||
case 0x1f: Complete(POP, None, DS, 2); break;
|
||||
|
||||
PartialBlock(0x20, AND); break;
|
||||
case 0x26: segment_override_ = Source::ES; break;
|
||||
case 0x27: Complete(DAA, AL, AL, 1); break;
|
||||
|
||||
PartialBlock(0x28, SUB); break;
|
||||
case 0x2e: segment_override_ = Source::CS; break;
|
||||
case 0x2f: Complete(DAS, AL, AL, 1); break;
|
||||
|
||||
PartialBlock(0x30, XOR); break;
|
||||
case 0x36: segment_override_ = Source::SS; break;
|
||||
case 0x37: Complete(AAA, AL, AX, 1); break;
|
||||
|
||||
PartialBlock(0x38, CMP); break;
|
||||
case 0x3e: segment_override_ = Source::DS; break;
|
||||
case 0x3f: Complete(AAS, AL, AX, 1); break;
|
||||
|
||||
#undef PartialBlock
|
||||
|
||||
#define RegisterBlock(start, operation) \
|
||||
case start + 0x00: Complete(operation, AX, AX, 2); break; \
|
||||
case start + 0x01: Complete(operation, CX, CX, 2); break; \
|
||||
case start + 0x02: Complete(operation, DX, DX, 2); break; \
|
||||
case start + 0x03: Complete(operation, BX, BX, 2); break; \
|
||||
case start + 0x04: Complete(operation, SP, SP, 2); break; \
|
||||
case start + 0x05: Complete(operation, BP, BP, 2); break; \
|
||||
case start + 0x06: Complete(operation, SI, SI, 2); break; \
|
||||
case start + 0x07: Complete(operation, DI, DI, 2)
|
||||
|
||||
RegisterBlock(0x40, INC); break;
|
||||
RegisterBlock(0x48, DEC); break;
|
||||
RegisterBlock(0x50, PUSH); break;
|
||||
RegisterBlock(0x58, POP); break;
|
||||
|
||||
#undef RegisterBlock
|
||||
|
||||
// 0x60–0x6f: not used.
|
||||
|
||||
case 0x70: Jump(JO); break;
|
||||
case 0x71: Jump(JNO); break;
|
||||
case 0x72: Jump(JB); break;
|
||||
case 0x73: Jump(JNB); break;
|
||||
case 0x74: Jump(JE); break;
|
||||
case 0x75: Jump(JNE); break;
|
||||
case 0x76: Jump(JBE); break;
|
||||
case 0x77: Jump(JNBE); break;
|
||||
case 0x78: Jump(JS); break;
|
||||
case 0x79: Jump(JNS); break;
|
||||
case 0x7a: Jump(JP); break;
|
||||
case 0x7b: Jump(JNP); break;
|
||||
case 0x7c: Jump(JL); break;
|
||||
case 0x7d: Jump(JNL); break;
|
||||
case 0x7e: Jump(JLE); break;
|
||||
case 0x7f: Jump(JNLE); break;
|
||||
|
||||
case 0x80: MemRegReg(Invalid, MemRegADD_to_CMP, 1); break;
|
||||
case 0x81: MemRegReg(Invalid, MemRegADD_to_CMP, 2); break;
|
||||
case 0x82: MemRegReg(Invalid, MemRegADC_to_CMP, 1); break;
|
||||
case 0x83: MemRegReg(Invalid, MemRegADC_to_CMP, 2); break;
|
||||
|
||||
case 0x84: MemRegReg(TEST, MemReg_Reg, 1); break;
|
||||
case 0x85: MemRegReg(TEST, MemReg_Reg, 2); break;
|
||||
case 0x86: MemRegReg(XCHG, Reg_MemReg, 1); break;
|
||||
case 0x87: MemRegReg(XCHG, Reg_MemReg, 2); break;
|
||||
case 0x88: MemRegReg(MOV, MemReg_Reg, 1); break;
|
||||
case 0x89: MemRegReg(MOV, MemReg_Reg, 2); break;
|
||||
case 0x8a: MemRegReg(MOV, Reg_MemReg, 1); break;
|
||||
case 0x8b: MemRegReg(MOV, Reg_MemReg, 2); break;
|
||||
// 0x8c: not used.
|
||||
case 0x8d: MemRegReg(LEA, Reg_MemReg, 2); break;
|
||||
case 0x8e: MemRegReg(MOV, SegReg, 2); break;
|
||||
case 0x8f: MemRegReg(POP, MemRegPOP, 2); break;
|
||||
|
||||
case 0x90: Complete(NOP, None, None, 0); break; // Or XCHG AX, AX?
|
||||
case 0x91: Complete(XCHG, AX, CX, 2); break;
|
||||
case 0x92: Complete(XCHG, AX, DX, 2); break;
|
||||
case 0x93: Complete(XCHG, AX, BX, 2); break;
|
||||
case 0x94: Complete(XCHG, AX, SP, 2); break;
|
||||
case 0x95: Complete(XCHG, AX, BP, 2); break;
|
||||
case 0x96: Complete(XCHG, AX, SI, 2); break;
|
||||
case 0x97: Complete(XCHG, AX, DI, 2); break;
|
||||
|
||||
case 0x98: Complete(CBW, AL, AH, 1); break;
|
||||
case 0x99: Complete(CWD, AX, DX, 2); break;
|
||||
case 0x9a: Far(CALLF); break;
|
||||
case 0x9b: Complete(WAIT, None, None, 0); break;
|
||||
case 0x9c: Complete(PUSHF, None, None, 2); break;
|
||||
case 0x9d: Complete(POPF, None, None, 2); break;
|
||||
case 0x9e: Complete(SAHF, None, None, 1); break;
|
||||
case 0x9f: Complete(LAHF, None, None, 1); break;
|
||||
|
||||
case 0xa0: RegAddr(MOV, AL, 1, 1); break;
|
||||
case 0xa1: RegAddr(MOV, AX, 2, 2); break;
|
||||
case 0xa2: AddrReg(MOV, AL, 1, 1); break;
|
||||
case 0xa3: AddrReg(MOV, AX, 2, 2); break;
|
||||
|
||||
case 0xa4: Complete(MOVS, None, None, 1); break;
|
||||
case 0xa5: Complete(MOVS, None, None, 2); break;
|
||||
case 0xa6: Complete(CMPS, None, None, 1); break;
|
||||
case 0xa7: Complete(CMPS, None, None, 2); break;
|
||||
case 0xa8: RegData(TEST, AL, 1); break;
|
||||
case 0xa9: RegData(TEST, AX, 2); break;
|
||||
case 0xaa: Complete(STOS, None, None, 1); break;
|
||||
case 0xab: Complete(STOS, None, None, 2); break;
|
||||
case 0xac: Complete(LODS, None, None, 1); break;
|
||||
case 0xad: Complete(LODS, None, None, 2); break;
|
||||
case 0xae: Complete(SCAS, None, None, 1); break;
|
||||
case 0xaf: Complete(SCAS, None, None, 2); break;
|
||||
|
||||
case 0xb0: RegData(MOV, AL, 1); break;
|
||||
case 0xb1: RegData(MOV, CL, 1); break;
|
||||
case 0xb2: RegData(MOV, DL, 1); break;
|
||||
case 0xb3: RegData(MOV, BL, 1); break;
|
||||
case 0xb4: RegData(MOV, AH, 1); break;
|
||||
case 0xb5: RegData(MOV, CH, 1); break;
|
||||
case 0xb6: RegData(MOV, DH, 1); break;
|
||||
case 0xb7: RegData(MOV, BH, 1); break;
|
||||
case 0xb8: RegData(MOV, AX, 2); break;
|
||||
case 0xb9: RegData(MOV, CX, 2); break;
|
||||
case 0xba: RegData(MOV, DX, 2); break;
|
||||
case 0xbb: RegData(MOV, BX, 2); break;
|
||||
case 0xbc: RegData(MOV, SP, 2); break;
|
||||
case 0xbd: RegData(MOV, BP, 2); break;
|
||||
case 0xbe: RegData(MOV, SI, 2); break;
|
||||
case 0xbf: RegData(MOV, DI, 2); break;
|
||||
|
||||
case 0xc2: RegData(RETN, None, 2); break;
|
||||
case 0xc3: Complete(RETN, None, None, 2); break;
|
||||
case 0xc4: MemRegReg(LES, Reg_MemReg, 2); break;
|
||||
case 0xc5: MemRegReg(LDS, Reg_MemReg, 2); break;
|
||||
case 0xc6: MemRegReg(MOV, MemRegMOV, 1); break;
|
||||
case 0xc7: MemRegReg(MOV, MemRegMOV, 2); break;
|
||||
|
||||
case 0xca: RegData(RETF, None, 2); break;
|
||||
case 0xcb: Complete(RETF, None, None, 4); break;
|
||||
|
||||
case 0xcc: Complete(INT3, None, None, 0); break;
|
||||
case 0xcd: RegData(INT, None, 1); break;
|
||||
case 0xce: Complete(INTO, None, None, 0); break;
|
||||
case 0xcf: Complete(IRET, None, None, 0); break;
|
||||
|
||||
case 0xd0: case 0xd1:
|
||||
phase_ = Phase::ModRegRM;
|
||||
modregrm_format_ = ModRegRMFormat::MemRegROL_to_SAR;
|
||||
operation_size_ = 1 + (instr_ & 1);
|
||||
source_ = Source::Immediate;
|
||||
operand_ = 1;
|
||||
break;
|
||||
case 0xd2: case 0xd3:
|
||||
phase_ = Phase::ModRegRM;
|
||||
modregrm_format_ = ModRegRMFormat::MemRegROL_to_SAR;
|
||||
operation_size_ = 1 + (instr_ & 1);
|
||||
source_ = Source::CL;
|
||||
break;
|
||||
case 0xd4: RegData(AAM, AX, 1); break;
|
||||
case 0xd5: RegData(AAD, AX, 1); break;
|
||||
|
||||
case 0xd7: Complete(XLAT, None, None, 1); break;
|
||||
|
||||
case 0xd8: MemRegReg(ESC, MemReg_Reg, 0); break;
|
||||
case 0xd9: MemRegReg(ESC, MemReg_Reg, 0); break;
|
||||
case 0xda: MemRegReg(ESC, MemReg_Reg, 0); break;
|
||||
case 0xdb: MemRegReg(ESC, MemReg_Reg, 0); break;
|
||||
case 0xdc: MemRegReg(ESC, MemReg_Reg, 0); break;
|
||||
case 0xdd: MemRegReg(ESC, MemReg_Reg, 0); break;
|
||||
case 0xde: MemRegReg(ESC, MemReg_Reg, 0); break;
|
||||
case 0xdf: MemRegReg(ESC, MemReg_Reg, 0); break;
|
||||
|
||||
case 0xe0: Jump(LOOPNE); break;
|
||||
case 0xe1: Jump(LOOPE); break;
|
||||
case 0xe2: Jump(LOOP); break;
|
||||
case 0xe3: Jump(JPCX); break;
|
||||
|
||||
case 0xe4: RegAddr(IN, AL, 1, 1); break;
|
||||
case 0xe5: RegAddr(IN, AX, 2, 1); break;
|
||||
case 0xe6: AddrReg(OUT, AL, 1, 1); break;
|
||||
case 0xe7: AddrReg(OUT, AX, 2, 1); break;
|
||||
|
||||
case 0xe8: RegData(CALLD, None, 2); break;
|
||||
case 0xe9: RegData(JMPN, None, 2); break;
|
||||
case 0xea: Far(JMPF); break;
|
||||
case 0xeb: Jump(JMPN); break;
|
||||
|
||||
case 0xec: Complete(IN, DX, AL, 1); break;
|
||||
case 0xed: Complete(IN, DX, AX, 1); break;
|
||||
case 0xee: Complete(OUT, AL, DX, 1); break;
|
||||
case 0xef: Complete(OUT, AX, DX, 2); break;
|
||||
|
||||
case 0xf4: Complete(HLT, None, None, 1); break;
|
||||
case 0xf5: Complete(CMC, None, None, 1); break;
|
||||
case 0xf6: MemRegReg(Invalid, MemRegTEST_to_IDIV, 1); break;
|
||||
case 0xf7: MemRegReg(Invalid, MemRegTEST_to_IDIV, 2); break;
|
||||
|
||||
case 0xf8: Complete(CLC, None, None, 1); break;
|
||||
case 0xf9: Complete(STC, None, None, 1); break;
|
||||
case 0xfa: Complete(CLI, None, None, 1); break;
|
||||
case 0xfb: Complete(STI, None, None, 1); break;
|
||||
case 0xfc: Complete(CLD, None, None, 1); break;
|
||||
case 0xfd: Complete(STD, None, None, 1); break;
|
||||
|
||||
case 0xfe: MemRegReg(Invalid, MemRegINC_DEC, 1); break;
|
||||
case 0xff: MemRegReg(Invalid, MemRegINC_to_PUSH, 1); break;
|
||||
|
||||
// Other prefix bytes.
|
||||
case 0xf0: lock_ = true; break;
|
||||
case 0xf2: repetition_ = Repetition::RepNE; break;
|
||||
case 0xf3: repetition_ = Repetition::RepE; break;
|
||||
}
|
||||
}
|
||||
|
||||
#undef Far
|
||||
#undef Jump
|
||||
#undef MemRegReg
|
||||
#undef AddrReg
|
||||
#undef RegAddr
|
||||
#undef RegData
|
||||
#undef Complete
|
||||
#undef SetOpSrcDestSize
|
||||
|
||||
// MARK: - ModRegRM byte, if any.
|
||||
|
||||
if(phase_ == Phase::ModRegRM && source != end) {
|
||||
const uint8_t mod = *source >> 6; // i.e. mode.
|
||||
const uint8_t reg = (*source >> 3) & 7; // i.e. register.
|
||||
const uint8_t rm = *source & 7; // i.e. register/memory.
|
||||
++source;
|
||||
++consumed_;
|
||||
|
||||
Source memreg;
|
||||
constexpr Source reg_table[3][8] = {
|
||||
{},
|
||||
{
|
||||
Source::AL, Source::CL, Source::DL, Source::BL,
|
||||
Source::AH, Source::CH, Source::DH, Source::BH,
|
||||
}, {
|
||||
Source::AX, Source::CX, Source::DX, Source::BX,
|
||||
Source::SP, Source::BP, Source::SI, Source::DI,
|
||||
}
|
||||
};
|
||||
switch(mod) {
|
||||
case 0: {
|
||||
constexpr Source rm_table[8] = {
|
||||
Source::IndBXPlusSI, Source::IndBXPlusDI,
|
||||
Source::IndBPPlusSI, Source::IndBPPlusDI,
|
||||
Source::IndSI, Source::IndDI,
|
||||
Source::DirectAddress, Source::IndBX,
|
||||
};
|
||||
memreg = rm_table[rm];
|
||||
} break;
|
||||
|
||||
default: {
|
||||
constexpr Source rm_table[8] = {
|
||||
Source::IndBXPlusSI, Source::IndBXPlusDI,
|
||||
Source::IndBPPlusSI, Source::IndBPPlusDI,
|
||||
Source::IndSI, Source::IndDI,
|
||||
Source::IndBP, Source::IndBX,
|
||||
};
|
||||
memreg = rm_table[rm];
|
||||
|
||||
displacement_size_ = 1 + (mod == 2);
|
||||
} break;
|
||||
|
||||
// Other operand is just a register.
|
||||
case 3:
|
||||
memreg = reg_table[operation_size_][rm];
|
||||
|
||||
// LES and LDS accept a memory argument only, not a register.
|
||||
if(operation_ == Operation::LES || operation_ == Operation::LDS) {
|
||||
const auto result = std::make_pair(consumed_, Instruction());
|
||||
reset_parsing();
|
||||
return result;
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
switch(modregrm_format_) {
|
||||
case ModRegRMFormat::Reg_MemReg:
|
||||
case ModRegRMFormat::MemReg_Reg: {
|
||||
if(modregrm_format_ == ModRegRMFormat::Reg_MemReg) {
|
||||
source_ = memreg;
|
||||
destination_ = reg_table[operation_size_][reg];
|
||||
} else {
|
||||
source_ = reg_table[operation_size_][reg];
|
||||
destination_ = memreg;
|
||||
}
|
||||
} break;
|
||||
|
||||
case ModRegRMFormat::MemRegTEST_to_IDIV:
|
||||
source_ = destination_ = memreg;
|
||||
|
||||
switch(reg) {
|
||||
default: {
|
||||
const auto result = std::make_pair(consumed_, Instruction());
|
||||
reset_parsing();
|
||||
return result;
|
||||
}
|
||||
|
||||
case 0: operation_ = Operation::TEST; break;
|
||||
case 2: operation_ = Operation::NOT; break;
|
||||
case 3: operation_ = Operation::NEG; break;
|
||||
case 4: operation_ = Operation::MUL; break;
|
||||
case 5: operation_ = Operation::IMUL; break;
|
||||
case 6: operation_ = Operation::DIV; break;
|
||||
case 7: operation_ = Operation::IDIV; break;
|
||||
}
|
||||
break;
|
||||
|
||||
case ModRegRMFormat::SegReg: {
|
||||
source_ = memreg;
|
||||
|
||||
constexpr Source seg_table[4] = {
|
||||
Source::ES, Source::CS,
|
||||
Source::SS, Source::DS,
|
||||
};
|
||||
|
||||
if(reg & 4) {
|
||||
const auto result = std::make_pair(consumed_, Instruction());
|
||||
reset_parsing();
|
||||
return result;
|
||||
}
|
||||
|
||||
destination_ = seg_table[reg];
|
||||
} break;
|
||||
|
||||
case ModRegRMFormat::MemRegROL_to_SAR:
|
||||
destination_ = memreg;
|
||||
|
||||
switch(reg) {
|
||||
default: {
|
||||
const auto result = std::make_pair(consumed_, Instruction());
|
||||
reset_parsing();
|
||||
return result;
|
||||
}
|
||||
|
||||
case 0: operation_ = Operation::ROL; break;
|
||||
case 2: operation_ = Operation::ROR; break;
|
||||
case 3: operation_ = Operation::RCL; break;
|
||||
case 4: operation_ = Operation::RCR; break;
|
||||
case 5: operation_ = Operation::SAL; break;
|
||||
case 6: operation_ = Operation::SHR; break;
|
||||
case 7: operation_ = Operation::SAR; break;
|
||||
}
|
||||
break;
|
||||
|
||||
case ModRegRMFormat::MemRegINC_DEC:
|
||||
source_ = destination_ = memreg;
|
||||
|
||||
switch(reg) {
|
||||
default: {
|
||||
const auto result = std::make_pair(consumed_, Instruction());
|
||||
reset_parsing();
|
||||
return result;
|
||||
}
|
||||
|
||||
case 0: operation_ = Operation::INC; break;
|
||||
case 1: operation_ = Operation::DEC; break;
|
||||
}
|
||||
break;
|
||||
|
||||
case ModRegRMFormat::MemRegINC_to_PUSH:
|
||||
source_ = destination_ = memreg;
|
||||
|
||||
switch(reg) {
|
||||
default: {
|
||||
const auto result = std::make_pair(consumed_, Instruction());
|
||||
reset_parsing();
|
||||
return result;
|
||||
}
|
||||
|
||||
case 0: operation_ = Operation::INC; break;
|
||||
case 1: operation_ = Operation::DEC; break;
|
||||
case 2: operation_ = Operation::CALLN; break;
|
||||
case 3:
|
||||
operation_ = Operation::CALLF;
|
||||
operand_size_ = 4;
|
||||
source_ = Source::Immediate;
|
||||
break;
|
||||
case 4: operation_ = Operation::JMPN; break;
|
||||
case 5:
|
||||
operation_ = Operation::JMPF;
|
||||
operand_size_ = 4;
|
||||
source_ = Source::Immediate;
|
||||
break;
|
||||
case 6: operation_ = Operation::PUSH; break;
|
||||
}
|
||||
break;
|
||||
|
||||
case ModRegRMFormat::MemRegPOP:
|
||||
source_ = destination_ = memreg;
|
||||
|
||||
if(reg != 0) {
|
||||
reset_parsing();
|
||||
return std::make_pair(consumed_, Instruction());
|
||||
}
|
||||
break;
|
||||
|
||||
case ModRegRMFormat::MemRegMOV:
|
||||
source_ = Source::Immediate;
|
||||
destination_ = memreg;
|
||||
operand_size_ = operation_size_;
|
||||
break;
|
||||
|
||||
case ModRegRMFormat::MemRegADD_to_CMP:
|
||||
destination_ = memreg;
|
||||
operand_size_ = operation_size_;
|
||||
|
||||
switch(reg) {
|
||||
default: operation_ = Operation::ADD; break;
|
||||
case 1: operation_ = Operation::OR; break;
|
||||
case 2: operation_ = Operation::ADC; break;
|
||||
case 3: operation_ = Operation::SBB; break;
|
||||
case 4: operation_ = Operation::AND; break;
|
||||
case 5: operation_ = Operation::SUB; break;
|
||||
case 6: operation_ = Operation::XOR; break;
|
||||
case 7: operation_ = Operation::CMP; break;
|
||||
}
|
||||
break;
|
||||
|
||||
case ModRegRMFormat::MemRegADC_to_CMP:
|
||||
destination_ = memreg;
|
||||
source_ = Source::Immediate;
|
||||
operand_size_ = 1; // ... and always 1; it'll be sign extended if
|
||||
// the operation requires it.
|
||||
|
||||
switch(reg) {
|
||||
default: {
|
||||
const auto result = std::make_pair(consumed_, Instruction());
|
||||
reset_parsing();
|
||||
return result;
|
||||
}
|
||||
|
||||
case 0: operation_ = Operation::ADD; break;
|
||||
case 2: operation_ = Operation::ADC; break;
|
||||
case 3: operation_ = Operation::SBB; break;
|
||||
case 5: operation_ = Operation::SUB; break;
|
||||
case 7: operation_ = Operation::CMP; break;
|
||||
}
|
||||
break;
|
||||
|
||||
default: assert(false);
|
||||
}
|
||||
|
||||
phase_ = (displacement_size_ + operand_size_) ? Phase::AwaitingDisplacementOrOperand : Phase::ReadyToPost;
|
||||
}
|
||||
|
||||
// MARK: - Displacement and operand.
|
||||
|
||||
if(phase_ == Phase::AwaitingDisplacementOrOperand && source != end) {
|
||||
const int required_bytes = displacement_size_ + operand_size_;
|
||||
|
||||
const int outstanding_bytes = required_bytes - operand_bytes_;
|
||||
const int bytes_to_consume = std::min(int(end - source), outstanding_bytes);
|
||||
|
||||
// TODO: I can surely do better than this?
|
||||
for(int c = 0; c < bytes_to_consume; c++) {
|
||||
inward_data_ = (inward_data_ >> 8) | (uint64_t(source[0]) << 56);
|
||||
++source;
|
||||
}
|
||||
|
||||
consumed_ += bytes_to_consume;
|
||||
operand_bytes_ += bytes_to_consume;
|
||||
|
||||
if(bytes_to_consume == outstanding_bytes) {
|
||||
phase_ = Phase::ReadyToPost;
|
||||
|
||||
switch(operand_size_) {
|
||||
default: operand_ = 0; break;
|
||||
case 1:
|
||||
operand_ = inward_data_ >> 56; inward_data_ <<= 8;
|
||||
|
||||
// Sign extend if a single byte operand is feeding a two-byte instruction.
|
||||
if(operation_size_ == 2 && operation_ != Operation::IN && operation_ != Operation::OUT) {
|
||||
operand_ |= (operand_ & 0x80) ? 0xff00 : 0x0000;
|
||||
}
|
||||
break;
|
||||
case 4: displacement_size_ = 2; [[fallthrough]];
|
||||
case 2: operand_ = inward_data_ >> 48; inward_data_ <<= 16; break;
|
||||
break;
|
||||
}
|
||||
switch(displacement_size_) {
|
||||
default: displacement_ = 0; break;
|
||||
case 1: displacement_ = int8_t(inward_data_ >> 56); break;
|
||||
case 2: displacement_ = int16_t(inward_data_ >> 48); break;
|
||||
}
|
||||
} else {
|
||||
// Provide a genuine measure of further bytes required.
|
||||
return std::make_pair(-(outstanding_bytes - bytes_to_consume), Instruction());
|
||||
}
|
||||
}
|
||||
|
||||
// MARK: - Check for completion.
|
||||
|
||||
if(phase_ == Phase::ReadyToPost) {
|
||||
const auto result = std::make_pair(
|
||||
consumed_,
|
||||
Instruction(
|
||||
operation_,
|
||||
source_,
|
||||
destination_,
|
||||
lock_,
|
||||
segment_override_,
|
||||
repetition_,
|
||||
Size(operation_size_),
|
||||
displacement_,
|
||||
operand_)
|
||||
);
|
||||
reset_parsing();
|
||||
return result;
|
||||
}
|
||||
|
||||
// i.e. not done yet.
|
||||
return std::make_pair(0, Instruction());
|
||||
}
|
||||
155
InstructionSets/x86/Decoder.hpp
Normal file
155
InstructionSets/x86/Decoder.hpp
Normal file
@@ -0,0 +1,155 @@
|
||||
//
|
||||
// Decoder.hpp
|
||||
// Clock Signal
|
||||
//
|
||||
// Created by Thomas Harte on 01/01/21.
|
||||
// Copyright © 2021 Thomas Harte. All rights reserved.
|
||||
//
|
||||
|
||||
#ifndef InstructionSets_x86_Decoder_hpp
|
||||
#define InstructionSets_x86_Decoder_hpp
|
||||
|
||||
#include "Instruction.hpp"
|
||||
|
||||
#include <cstddef>
|
||||
#include <utility>
|
||||
|
||||
namespace InstructionSet {
|
||||
namespace x86 {
|
||||
|
||||
enum class Model {
|
||||
i8086,
|
||||
};
|
||||
|
||||
/*!
|
||||
Implements Intel x86 instruction decoding.
|
||||
|
||||
This is an experimental implementation; it has not yet undergone significant testing.
|
||||
*/
|
||||
class Decoder {
|
||||
public:
|
||||
Decoder(Model model);
|
||||
|
||||
/*!
|
||||
@returns an @c Instruction plus a size; a positive size to indicate successful decoding; a
|
||||
negative size specifies the [negatived] number of further bytes the caller should ideally
|
||||
collect before calling again. The caller is free to call with fewer, but may not get a decoded
|
||||
instruction in response, and the decoder may still not be able to complete decoding
|
||||
even if given that number of bytes.
|
||||
*/
|
||||
std::pair<int, Instruction> decode(const uint8_t *source, size_t length);
|
||||
|
||||
private:
|
||||
enum class Phase {
|
||||
/// Captures all prefixes and continues until an instruction byte is encountered.
|
||||
Instruction,
|
||||
/// Receives a ModRegRM byte and either populates the source_ and dest_ fields appropriately
|
||||
/// or completes decoding of the instruction, as per the instruction format.
|
||||
ModRegRM,
|
||||
/// Waits for sufficiently many bytes to pass for the required displacement and operand to be captured.
|
||||
/// Cf. displacement_size_ and operand_size_.
|
||||
AwaitingDisplacementOrOperand,
|
||||
/// Forms and returns an Instruction, and resets parsing state.
|
||||
ReadyToPost
|
||||
} phase_ = Phase::Instruction;
|
||||
|
||||
/// During the ModRegRM phase, format dictates interpretation of the ModRegRM byte.
|
||||
///
|
||||
/// During the ReadyToPost phase, format determines how transiently-recorded fields
|
||||
/// are packaged into an Instruction.
|
||||
enum class ModRegRMFormat: uint8_t {
|
||||
// Parse the ModRegRM for mode, register and register/memory fields
|
||||
// and populate the source_ and destination_ fields appropriate.
|
||||
MemReg_Reg,
|
||||
Reg_MemReg,
|
||||
|
||||
// Parse for mode and register/memory fields, populating both
|
||||
// source_ and destination_ fields with the result. Use the 'register'
|
||||
// field to pick an operation from the TEST/NOT/NEG/MUL/IMUL/DIV/IDIV group.
|
||||
MemRegTEST_to_IDIV,
|
||||
|
||||
// Parse for mode and register/memory fields, populating both
|
||||
// source_ and destination_ fields with the result. Use the 'register'
|
||||
// field to check for the POP operation.
|
||||
MemRegPOP,
|
||||
|
||||
// Parse for mode and register/memory fields, populating both
|
||||
// the destination_ field with the result and setting source_ to Immediate.
|
||||
// Use the 'register' field to check for the MOV operation.
|
||||
MemRegMOV,
|
||||
|
||||
// Parse for mode and register/memory fields, populating the
|
||||
// destination_ field with the result. Use the 'register' field
|
||||
// to pick an operation from the ROL/ROR/RCL/RCR/SAL/SHR/SAR group.
|
||||
MemRegROL_to_SAR,
|
||||
|
||||
// Parse for mode and register/memory fields, populating the
|
||||
// destination_ field with the result. Use the 'register' field
|
||||
// to pick an operation from the ADD/OR/ADC/SBB/AND/SUB/XOR/CMP group and
|
||||
// waits for an operand equal to the operation size.
|
||||
MemRegADD_to_CMP,
|
||||
|
||||
// Parse for mode and register/memory fields, populating the
|
||||
// source_ field with the result. Fills destination_ with a segment
|
||||
// register based on the reg field.
|
||||
SegReg,
|
||||
|
||||
// Parse for mode and register/memory fields, populating the
|
||||
// source_ and destination_ fields with the result. Uses the
|
||||
// 'register' field to pick INC or DEC.
|
||||
MemRegINC_DEC,
|
||||
|
||||
// Parse for mode and register/memory fields, populating the
|
||||
// source_ and destination_ fields with the result. Uses the
|
||||
// 'register' field to pick from INC/DEC/CALL/JMP/PUSH, altering
|
||||
// the source to ::Immediate and setting an operand size if necessary.
|
||||
MemRegINC_to_PUSH,
|
||||
|
||||
// Parse for mode and register/memory fields, populating the
|
||||
// source_ and destination_ fields with the result. Uses the
|
||||
// 'register' field to pick from ADD/ADC/SBB/SUB/CMP, altering
|
||||
// the source to ::Immediate and setting an appropriate operand size.
|
||||
MemRegADC_to_CMP,
|
||||
} modregrm_format_ = ModRegRMFormat::MemReg_Reg;
|
||||
|
||||
// Ephemeral decoding state.
|
||||
Operation operation_ = Operation::Invalid;
|
||||
uint8_t instr_ = 0x00; // TODO: is this desired, versus loading more context into ModRegRMFormat?
|
||||
int consumed_ = 0, operand_bytes_ = 0;
|
||||
|
||||
// Source and destination locations.
|
||||
Source source_ = Source::None;
|
||||
Source destination_ = Source::None;
|
||||
|
||||
// Immediate fields.
|
||||
int16_t displacement_ = 0;
|
||||
uint16_t operand_ = 0;
|
||||
uint64_t inward_data_ = 0;
|
||||
|
||||
// Facts about the instruction.
|
||||
int displacement_size_ = 0; // i.e. size of in-stream displacement, if any.
|
||||
int operand_size_ = 0; // i.e. size of in-stream operand, if any.
|
||||
int operation_size_ = 0; // i.e. size of data manipulated by the operation.
|
||||
|
||||
// Prefix capture fields.
|
||||
Repetition repetition_ = Repetition::None;
|
||||
bool lock_ = false;
|
||||
Source segment_override_ = Source::None;
|
||||
|
||||
/// Resets size capture and all fields with default values.
|
||||
void reset_parsing() {
|
||||
consumed_ = operand_bytes_ = 0;
|
||||
displacement_size_ = operand_size_ = 0;
|
||||
displacement_ = operand_ = 0;
|
||||
lock_ = false;
|
||||
segment_override_ = Source::None;
|
||||
repetition_ = Repetition::None;
|
||||
phase_ = Phase::Instruction;
|
||||
source_ = destination_ = Source::None;
|
||||
}
|
||||
};
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
#endif /* InstructionSets_x86_Decoder_hpp */
|
||||
303
InstructionSets/x86/Instruction.hpp
Normal file
303
InstructionSets/x86/Instruction.hpp
Normal file
@@ -0,0 +1,303 @@
|
||||
//
|
||||
// Instruction.hpp
|
||||
// Clock Signal
|
||||
//
|
||||
// Created by Thomas Harte on 15/01/21.
|
||||
// Copyright © 2021 Thomas Harte. All rights reserved.
|
||||
//
|
||||
|
||||
#ifndef InstructionSets_x86_Instruction_h
|
||||
#define InstructionSets_x86_Instruction_h
|
||||
|
||||
#include <cstdint>
|
||||
|
||||
namespace InstructionSet {
|
||||
namespace x86 {
|
||||
|
||||
/*
|
||||
Operations are documented below to establish expectations as to which
|
||||
instruction fields will be meaningful for each; this is a work-in-progress
|
||||
and may currently contain errors in the opcode descriptions — especially
|
||||
where implicit register dependencies are afoot.
|
||||
*/
|
||||
enum class Operation: uint8_t {
|
||||
Invalid,
|
||||
|
||||
/// ASCII adjust after addition; source will be AL and destination will be AX.
|
||||
AAA,
|
||||
/// ASCII adjust before division; destination will be AX and source will be a multiplier.
|
||||
AAD,
|
||||
/// ASCII adjust after multiplication; destination will be AX and source will be a divider.
|
||||
AAM,
|
||||
/// ASCII adjust after subtraction; source will be AL and destination will be AX.
|
||||
AAS,
|
||||
/// Decimal adjust after addition; source and destination will be AL.
|
||||
DAA,
|
||||
/// Decimal adjust after subtraction; source and destination will be AL.
|
||||
DAS,
|
||||
|
||||
/// Convert byte into word; source will be AL, destination will be AH.
|
||||
CBW,
|
||||
/// Convert word to double word; source will be AX and destination will be DX.
|
||||
CWD,
|
||||
|
||||
/// Escape, for a coprocessor; perform the bus cycles necessary to read the source and destination and perform a NOP.
|
||||
ESC,
|
||||
|
||||
/// Stops the processor until the next interrupt is fired.
|
||||
HLT,
|
||||
/// Waits until the WAIT input is asserted; if an interrupt occurs then it is serviced but returns to the WAIT.
|
||||
WAIT,
|
||||
|
||||
/// Add with carry; source, destination, operand and displacement will be populated appropriately.
|
||||
ADC,
|
||||
/// Add; source, destination, operand and displacement will be populated appropriately.
|
||||
ADD,
|
||||
/// Subtract with borrow; source, destination, operand and displacement will be populated appropriately.
|
||||
SBB,
|
||||
/// Subtract; source, destination, operand and displacement will be populated appropriately.
|
||||
SUB,
|
||||
/// Unsigned multiply; multiplies the source value by AX or AL, storing the result in DX:AX or AX.
|
||||
MUL,
|
||||
/// Signed multiply; multiplies the source value by AX or AL, storing the result in DX:AX or AX.
|
||||
IMUL,
|
||||
/// Unsigned divide; divide the source value by AX or AL, storing the quotient in AL and the remainder in AH.
|
||||
DIV,
|
||||
/// Signed divide; divide the source value by AX or AL, storing the quotient in AL and the remainder in AH.
|
||||
IDIV,
|
||||
|
||||
/// Increment; source, destination, operand and displacement will be populated appropriately.
|
||||
INC,
|
||||
/// Decrement; source, destination, operand and displacement will be populated appropriately.
|
||||
DEC,
|
||||
|
||||
/// Reads from the port specified by source to the destination.
|
||||
IN,
|
||||
/// Writes from the port specified by destination from the source.
|
||||
OUT,
|
||||
|
||||
// Various jumps; see the displacement to calculate targets.
|
||||
JO, JNO, JB, JNB, JE, JNE, JBE, JNBE,
|
||||
JS, JNS, JP, JNP, JL, JNL, JLE, JNLE,
|
||||
|
||||
/// Far call; see the segment() and offset() fields.
|
||||
CALLF,
|
||||
/// Displacement call; followed by a 16-bit operand providing a call offset.
|
||||
CALLD,
|
||||
/// Near call.
|
||||
CALLN,
|
||||
/// Return from interrupt.
|
||||
IRET,
|
||||
/// Near return; if source is not ::None then it will be an ::Immediate indicating how many additional bytes to remove from the stack.
|
||||
RETF,
|
||||
/// Far return; if source is not ::None then it will be an ::Immediate indicating how many additional bytes to remove from the stack.
|
||||
RETN,
|
||||
/// Near jump; if an operand is not ::None then it gives an absolute destination; otherwise see the displacement.
|
||||
JMPN,
|
||||
/// Far jump to the indicated segment and offset.
|
||||
JMPF,
|
||||
/// Relative jump performed only if CX = 0; see the displacement.
|
||||
JPCX,
|
||||
/// Generates a software interrupt of the level stated in the operand.
|
||||
INT,
|
||||
/// Generates a software interrupt of level 3.
|
||||
INT3,
|
||||
/// Generates a software interrupt of level 4 if overflow is set.
|
||||
INTO,
|
||||
|
||||
/// Load status flags to AH.
|
||||
LAHF,
|
||||
/// Load status flags from AH.
|
||||
SAHF,
|
||||
/// Load a segment and offset from the source into DS and the destination.
|
||||
LDS,
|
||||
/// Load a segment and offset from the source into ES and the destination.
|
||||
LES,
|
||||
/// Computes the effective address of the source and loads it into the destination.
|
||||
LEA,
|
||||
|
||||
/// Compare [bytes or words, per operation size]; source and destination implied to be DS:[SI] and ES:[DI].
|
||||
CMPS,
|
||||
/// Load string; reads from DS:SI into AL or AX, subject to segment override.
|
||||
LODS,
|
||||
/// Move string; moves a byte or word from DS:SI to ES:DI. If a segment override is provided, it overrides the the source.
|
||||
MOVS,
|
||||
/// Scan string; reads a byte or word from DS:SI and compares it to AL or AX.
|
||||
SCAS,
|
||||
/// Store string; store AL or AX to ES:DI.
|
||||
STOS,
|
||||
|
||||
// Perform a possibly-conditional loop, decrementing CX. See the displacement.
|
||||
LOOP, LOOPE, LOOPNE,
|
||||
|
||||
/// Loads the destination with the source.
|
||||
MOV,
|
||||
/// Negatives; source and destination point to the same thing, to negative.
|
||||
NEG,
|
||||
/// Logical NOT; source and destination point to the same thing, to negative.
|
||||
NOT,
|
||||
/// Logical AND; source, destination, operand and displacement will be populated appropriately.
|
||||
AND,
|
||||
/// Logical OR of source onto destination.
|
||||
OR,
|
||||
/// Logical XOR of source onto destination.
|
||||
XOR,
|
||||
/// NOP; no further fields.
|
||||
NOP,
|
||||
/// POP from the stack to destination.
|
||||
POP,
|
||||
/// POP from the stack to the flags register.
|
||||
POPF,
|
||||
/// PUSH the source to the stack.
|
||||
PUSH,
|
||||
/// PUSH the flags register to the stack.
|
||||
PUSHF,
|
||||
/// Rotate the destination left through carry the number of bits indicated by source.
|
||||
RCL,
|
||||
/// Rotate the destination right through carry the number of bits indicated by source.
|
||||
RCR,
|
||||
/// Rotate the destination left the number of bits indicated by source.
|
||||
ROL,
|
||||
/// Rotate the destination right the number of bits indicated by source.
|
||||
ROR,
|
||||
/// Arithmetic shift left the destination by the number of bits indicated by source.
|
||||
SAL,
|
||||
/// Arithmetic shift right the destination by the number of bits indicated by source.
|
||||
SAR,
|
||||
/// Logical shift right the destination by the number of bits indicated by source.
|
||||
SHR,
|
||||
|
||||
/// Clear carry flag; no source or destination provided.
|
||||
CLC,
|
||||
/// Clear direction flag; no source or destination provided.
|
||||
CLD,
|
||||
/// Clear interrupt flag; no source or destination provided.
|
||||
CLI,
|
||||
/// Set carry flag.
|
||||
STC,
|
||||
/// Set decimal flag.
|
||||
STD,
|
||||
/// Set interrupt flag.
|
||||
STI,
|
||||
/// Complement carry flag; no source or destination provided.
|
||||
CMC,
|
||||
|
||||
/// Compare; source, destination, operand and displacement will be populated appropriately.
|
||||
CMP,
|
||||
/// Sets flags based on the result of a logical AND of source and destination.
|
||||
TEST,
|
||||
|
||||
/// Exchanges the contents of the source and destination.
|
||||
XCHG,
|
||||
|
||||
/// Load AL with DS:[AL+BX].
|
||||
XLAT,
|
||||
};
|
||||
|
||||
enum class Size: uint8_t {
|
||||
Implied = 0,
|
||||
Byte = 1,
|
||||
Word = 2,
|
||||
DWord = 4,
|
||||
};
|
||||
|
||||
enum class Source: uint8_t {
|
||||
None,
|
||||
CS, DS, ES, SS,
|
||||
|
||||
AL, AH, AX,
|
||||
BL, BH, BX,
|
||||
CL, CH, CX,
|
||||
DL, DH, DX,
|
||||
|
||||
SI, DI,
|
||||
BP, SP,
|
||||
|
||||
IndBXPlusSI,
|
||||
IndBXPlusDI,
|
||||
IndBPPlusSI,
|
||||
IndBPPlusDI,
|
||||
IndSI,
|
||||
IndDI,
|
||||
DirectAddress,
|
||||
IndBP,
|
||||
IndBX,
|
||||
|
||||
Immediate
|
||||
};
|
||||
|
||||
enum class Repetition: uint8_t {
|
||||
None, RepE, RepNE
|
||||
};
|
||||
|
||||
class Instruction {
|
||||
public:
|
||||
Operation operation = Operation::Invalid;
|
||||
|
||||
bool operator ==(const Instruction &rhs) const {
|
||||
return
|
||||
repetition_size_ == rhs.repetition_size_ &&
|
||||
sources_ == rhs.sources_ &&
|
||||
displacement_ == rhs.displacement_ &&
|
||||
operand_ == rhs.operand_;
|
||||
}
|
||||
|
||||
private:
|
||||
// b0, b1: a Repetition;
|
||||
// b2+: operation size.
|
||||
uint8_t repetition_size_ = 0;
|
||||
|
||||
// b0–b5: source;
|
||||
// b6–b11: destination;
|
||||
// b12–b14: segment override;
|
||||
// b15: lock.
|
||||
uint16_t sources_ = 0;
|
||||
|
||||
// Unpackable fields.
|
||||
int16_t displacement_ = 0;
|
||||
uint16_t operand_ = 0; // ... or used to store a segment for far operations.
|
||||
|
||||
public:
|
||||
Source source() const { return Source(sources_ & 0x3f); }
|
||||
Source destination() const { return Source((sources_ >> 6) & 0x3f); }
|
||||
bool lock() const { return sources_ & 0x8000; }
|
||||
Source segment_override() const { return Source((sources_ >> 12) & 7); }
|
||||
|
||||
Repetition repetition() const { return Repetition(repetition_size_ & 3); }
|
||||
Size operation_size() const { return Size(repetition_size_ >> 2); }
|
||||
|
||||
uint16_t segment() const { return uint16_t(operand_); }
|
||||
uint16_t offset() const { return uint16_t(displacement_); }
|
||||
|
||||
int16_t displacement() const { return displacement_; }
|
||||
uint16_t operand() const { return operand_; }
|
||||
|
||||
Instruction() noexcept {}
|
||||
Instruction(
|
||||
Operation operation,
|
||||
Source source,
|
||||
Source destination,
|
||||
bool lock,
|
||||
Source segment_override,
|
||||
Repetition repetition,
|
||||
Size operation_size,
|
||||
int16_t displacement,
|
||||
uint16_t operand) noexcept :
|
||||
operation(operation),
|
||||
repetition_size_(uint8_t((int(operation_size) << 2) | int(repetition))),
|
||||
sources_(uint16_t(
|
||||
int(source) |
|
||||
(int(destination) << 6) |
|
||||
(int(segment_override) << 12) |
|
||||
(int(lock) << 15)
|
||||
)),
|
||||
displacement_(displacement),
|
||||
operand_(operand) {}
|
||||
};
|
||||
|
||||
static_assert(sizeof(Instruction) <= 8);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
#endif /* InstructionSets_x86_Instruction_h */
|
||||
254
Machines/Amiga/Amiga.cpp
Normal file
254
Machines/Amiga/Amiga.cpp
Normal file
@@ -0,0 +1,254 @@
|
||||
//
|
||||
// Amiga.cpp
|
||||
// Clock Signal
|
||||
//
|
||||
// Created by Thomas Harte on 16/07/2021.
|
||||
// Copyright © 2021 Thomas Harte. All rights reserved.
|
||||
//
|
||||
|
||||
#include "Amiga.hpp"
|
||||
|
||||
#include "../../Activity/Source.hpp"
|
||||
#include "../MachineTypes.hpp"
|
||||
|
||||
#include "../../Processors/68000/68000.hpp"
|
||||
|
||||
#include "../../Analyser/Static/Amiga/Target.hpp"
|
||||
|
||||
#include "../Utility/MemoryPacker.hpp"
|
||||
#include "../Utility/MemoryFuzzer.hpp"
|
||||
|
||||
//#define NDEBUG
|
||||
#define LOG_PREFIX "[Amiga] "
|
||||
#include "../../Outputs/Log.hpp"
|
||||
|
||||
#include "Chipset.hpp"
|
||||
#include "Keyboard.hpp"
|
||||
#include "MemoryMap.hpp"
|
||||
|
||||
#include <cassert>
|
||||
|
||||
namespace {
|
||||
|
||||
// NTSC clock rate: 2*3.579545 = 7.15909Mhz.
|
||||
// PAL clock rate: 7.09379Mhz; 227 cycles/line.
|
||||
constexpr int PALClockRate = 7'093'790;
|
||||
//constexpr int NTSCClockRate = 7'159'090;
|
||||
|
||||
}
|
||||
|
||||
namespace Amiga {
|
||||
|
||||
class ConcreteMachine:
|
||||
public Activity::Source,
|
||||
public CPU::MC68000::BusHandler,
|
||||
public MachineTypes::AudioProducer,
|
||||
public MachineTypes::JoystickMachine,
|
||||
public MachineTypes::MappedKeyboardMachine,
|
||||
public MachineTypes::MediaTarget,
|
||||
public MachineTypes::MouseMachine,
|
||||
public MachineTypes::ScanProducer,
|
||||
public MachineTypes::TimedMachine,
|
||||
public Machine {
|
||||
public:
|
||||
ConcreteMachine(const Analyser::Static::Amiga::Target &target, const ROMMachine::ROMFetcher &rom_fetcher) :
|
||||
mc68000_(*this),
|
||||
chipset_(memory_, PALClockRate)
|
||||
{
|
||||
// Temporary: use a hard-coded Kickstart selection.
|
||||
constexpr ROM::Name rom_name = ROM::Name::AmigaA500Kickstart13;
|
||||
ROM::Request request(rom_name);
|
||||
auto roms = rom_fetcher(request);
|
||||
if(!request.validate(roms)) {
|
||||
throw ROMMachine::Error::MissingROMs;
|
||||
}
|
||||
Memory::PackBigEndian16(roms.find(rom_name)->second, memory_.kickstart.data());
|
||||
|
||||
// For now, also hard-code assumption of PAL.
|
||||
// (Assumption is both here and in the video timing of the Chipset).
|
||||
set_clock_rate(PALClockRate);
|
||||
|
||||
// Insert supplied media.
|
||||
insert_media(target.media);
|
||||
}
|
||||
|
||||
// MARK: - MediaTarget.
|
||||
|
||||
bool insert_media(const Analyser::Static::Media &media) final {
|
||||
return chipset_.insert(media.disks);
|
||||
}
|
||||
|
||||
// MARK: - MC68000::BusHandler.
|
||||
using Microcycle = CPU::MC68000::Microcycle;
|
||||
HalfCycles perform_bus_operation(const CPU::MC68000::Microcycle &cycle, int) {
|
||||
|
||||
// Do a quick advance check for Chip RAM access; add a suitable delay if required.
|
||||
HalfCycles total_length;
|
||||
if(cycle.operation & Microcycle::NewAddress && *cycle.address < 0x20'0000) {
|
||||
total_length = chipset_.run_until_after_cpu_slot().duration;
|
||||
assert(total_length >= cycle.length);
|
||||
} else {
|
||||
total_length = cycle.length;
|
||||
chipset_.run_for(total_length);
|
||||
}
|
||||
mc68000_.set_interrupt_level(chipset_.get_interrupt_level());
|
||||
|
||||
// Check for assertion of reset.
|
||||
if(cycle.operation & Microcycle::Reset) {
|
||||
memory_.reset();
|
||||
LOG("Reset; PC is around " << PADHEX(8) << mc68000_.get_state().program_counter);
|
||||
}
|
||||
|
||||
// Autovector interrupts.
|
||||
if(cycle.operation & Microcycle::InterruptAcknowledge) {
|
||||
mc68000_.set_is_peripheral_address(true);
|
||||
return total_length - cycle.length;
|
||||
}
|
||||
|
||||
// Do nothing if no address is exposed.
|
||||
if(!(cycle.operation & (Microcycle::NewAddress | Microcycle::SameAddress))) return total_length - cycle.length;
|
||||
|
||||
// Grab the target address to pick a memory source.
|
||||
const uint32_t address = cycle.host_endian_byte_address();
|
||||
|
||||
// Set VPA if this is [going to be] a CIA access.
|
||||
mc68000_.set_is_peripheral_address((address & 0xe0'0000) == 0xa0'0000);
|
||||
|
||||
if(!memory_.regions[address >> 18].read_write_mask) {
|
||||
if((cycle.operation & (Microcycle::SelectByte | Microcycle::SelectWord))) {
|
||||
// Check for various potential chip accesses.
|
||||
|
||||
// Per the manual:
|
||||
//
|
||||
// CIA A is: 101x xxxx xx01 rrrr xxxx xxx0 (i.e. loaded into high byte)
|
||||
// CIA B is: 101x xxxx xx10 rrrr xxxx xxx1 (i.e. loaded into low byte)
|
||||
//
|
||||
// but in order to map 0xbfexxx to CIA A and 0xbfdxxx to CIA B, I think
|
||||
// these might be listed the wrong way around.
|
||||
//
|
||||
// Additional assumption: the relevant CIA select lines are connected
|
||||
// directly to the chip enables.
|
||||
if((address & 0xe0'0000) == 0xa0'0000) {
|
||||
const int reg = address >> 8;
|
||||
const bool select_a = !(address & 0x1000);
|
||||
const bool select_b = !(address & 0x2000);
|
||||
|
||||
if(cycle.operation & Microcycle::Read) {
|
||||
uint16_t result = 0xffff;
|
||||
if(select_a) result &= 0xff00 | (chipset_.cia_a.read(reg) << 0);
|
||||
if(select_b) result &= 0x00ff | (chipset_.cia_b.read(reg) << 8);
|
||||
cycle.set_value16(result);
|
||||
} else {
|
||||
if(select_a) chipset_.cia_a.write(reg, cycle.value8_low());
|
||||
if(select_b) chipset_.cia_b.write(reg, cycle.value8_high());
|
||||
}
|
||||
|
||||
// LOG("CIA " << (((address >> 12) & 3)^3) << " " << (cycle.operation & Microcycle::Read ? "read " : "write ") << std::dec << (reg & 0xf) << " of " << PADHEX(4) << +cycle.value16());
|
||||
} else if(address >= 0xdf'f000 && address <= 0xdf'f1be) {
|
||||
chipset_.perform(cycle);
|
||||
} else {
|
||||
// This'll do for open bus, for now.
|
||||
if(cycle.operation & Microcycle::Read) {
|
||||
cycle.set_value16(0xffff);
|
||||
}
|
||||
|
||||
// Don't log for the region that is definitely just ROM this machine doesn't have.
|
||||
if(address < 0xf0'0000) {
|
||||
LOG("Unmapped " << (cycle.operation & Microcycle::Read ? "read from " : "write to ") << PADHEX(6) << ((*cycle.address)&0xffffff) << " of " << cycle.value16());
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
// A regular memory access.
|
||||
cycle.apply(
|
||||
&memory_.regions[address >> 18].contents[address],
|
||||
memory_.regions[address >> 18].read_write_mask
|
||||
);
|
||||
}
|
||||
|
||||
return total_length - cycle.length;
|
||||
}
|
||||
|
||||
void flush() {
|
||||
chipset_.flush();
|
||||
}
|
||||
|
||||
private:
|
||||
CPU::MC68000::Processor<ConcreteMachine, true> mc68000_;
|
||||
|
||||
// MARK: - Memory map.
|
||||
|
||||
MemoryMap memory_;
|
||||
|
||||
// MARK: - Chipset.
|
||||
|
||||
Chipset chipset_;
|
||||
|
||||
// MARK: - Activity Source
|
||||
|
||||
void set_activity_observer(Activity::Observer *observer) final {
|
||||
chipset_.set_activity_observer(observer);
|
||||
}
|
||||
|
||||
// MARK: - MachineTypes::AudioProducer.
|
||||
|
||||
Outputs::Speaker::Speaker *get_speaker() final {
|
||||
return chipset_.get_speaker();
|
||||
}
|
||||
|
||||
// MARK: - MachineTypes::ScanProducer.
|
||||
|
||||
void set_scan_target(Outputs::Display::ScanTarget *scan_target) final {
|
||||
chipset_.set_scan_target(scan_target);
|
||||
}
|
||||
|
||||
Outputs::Display::ScanStatus get_scaled_scan_status() const {
|
||||
return chipset_.get_scaled_scan_status();
|
||||
}
|
||||
|
||||
// MARK: - MachineTypes::TimedMachine.
|
||||
|
||||
void run_for(const Cycles cycles) {
|
||||
mc68000_.run_for(cycles);
|
||||
}
|
||||
|
||||
// MARK: - MachineTypes::MouseMachine.
|
||||
|
||||
Inputs::Mouse &get_mouse() final {
|
||||
return chipset_.get_mouse();;
|
||||
}
|
||||
|
||||
// MARK: - MachineTypes::JoystickMachine.
|
||||
|
||||
const std::vector<std::unique_ptr<Inputs::Joystick>> &get_joysticks() {
|
||||
return chipset_.get_joysticks();
|
||||
}
|
||||
|
||||
// MARK: - Keyboard.
|
||||
|
||||
Amiga::KeyboardMapper keyboard_mapper_;
|
||||
KeyboardMapper *get_keyboard_mapper() {
|
||||
return &keyboard_mapper_;
|
||||
}
|
||||
|
||||
void set_key_state(uint16_t key, bool is_pressed) {
|
||||
chipset_.get_keyboard().set_key_state(key, is_pressed);
|
||||
}
|
||||
|
||||
void clear_all_keys() {
|
||||
chipset_.get_keyboard().clear_all_keys();
|
||||
}
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
|
||||
using namespace Amiga;
|
||||
|
||||
Machine *Machine::Amiga(const Analyser::Static::Target *target, const ROMMachine::ROMFetcher &rom_fetcher) {
|
||||
using Target = Analyser::Static::Amiga::Target;
|
||||
const Target *const amiga_target = dynamic_cast<const Target *>(target);
|
||||
return new Amiga::ConcreteMachine(*amiga_target, rom_fetcher);
|
||||
}
|
||||
|
||||
Machine::~Machine() {}
|
||||
27
Machines/Amiga/Amiga.hpp
Normal file
27
Machines/Amiga/Amiga.hpp
Normal file
@@ -0,0 +1,27 @@
|
||||
//
|
||||
// Amiga.hpp
|
||||
// Clock Signal
|
||||
//
|
||||
// Created by Thomas Harte on 16/07/2021.
|
||||
// Copyright © 2021 Thomas Harte. All rights reserved.
|
||||
//
|
||||
|
||||
#ifndef Amiga_hpp
|
||||
#define Amiga_hpp
|
||||
|
||||
#include "../../Analyser/Static/StaticAnalyser.hpp"
|
||||
#include "../ROMMachine.hpp"
|
||||
|
||||
namespace Amiga {
|
||||
|
||||
class Machine {
|
||||
public:
|
||||
virtual ~Machine();
|
||||
|
||||
/// Creates and returns an Amiga.
|
||||
static Machine *Amiga(const Analyser::Static::Target *target, const ROMMachine::ROMFetcher &rom_fetcher);
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif /* Amiga_hpp */
|
||||
678
Machines/Amiga/Audio.cpp
Normal file
678
Machines/Amiga/Audio.cpp
Normal file
@@ -0,0 +1,678 @@
|
||||
//
|
||||
// Audio.cpp
|
||||
// Clock Signal
|
||||
//
|
||||
// Created by Thomas Harte on 09/11/2021.
|
||||
// Copyright © 2021 Thomas Harte. All rights reserved.
|
||||
//
|
||||
|
||||
#include "Audio.hpp"
|
||||
|
||||
#include "Flags.hpp"
|
||||
|
||||
#define LOG_PREFIX "[Audio] "
|
||||
#include "../../Outputs/Log.hpp"
|
||||
|
||||
#include <cassert>
|
||||
#include <tuple>
|
||||
|
||||
using namespace Amiga;
|
||||
|
||||
Audio::Audio(Chipset &chipset, uint16_t *ram, size_t word_size, float output_rate) :
|
||||
DMADevice<4>(chipset, ram, word_size) {
|
||||
|
||||
// Mark all buffers as available.
|
||||
for(auto &flag: buffer_available_) {
|
||||
flag.store(true, std::memory_order::memory_order_relaxed);
|
||||
}
|
||||
|
||||
speaker_.set_input_rate(output_rate);
|
||||
speaker_.set_high_frequency_cutoff(7000.0f);
|
||||
}
|
||||
|
||||
// MARK: - Exposed setters.
|
||||
|
||||
void Audio::set_length(int channel, uint16_t length) {
|
||||
assert(channel >= 0 && channel < 4);
|
||||
channels_[channel].length = length;
|
||||
}
|
||||
|
||||
void Audio::set_period(int channel, uint16_t period) {
|
||||
assert(channel >= 0 && channel < 4);
|
||||
channels_[channel].period = period;
|
||||
}
|
||||
|
||||
void Audio::set_volume(int channel, uint16_t volume) {
|
||||
assert(channel >= 0 && channel < 4);
|
||||
channels_[channel].volume = (volume & 0x40) ? 64 : (volume & 0x3f);
|
||||
}
|
||||
|
||||
template <bool is_external> void Audio::set_data(int channel, uint16_t data) {
|
||||
assert(channel >= 0 && channel < 4);
|
||||
channels_[channel].wants_data = false;
|
||||
channels_[channel].data = data;
|
||||
|
||||
// TODO: "the [PWM] counter is reset when ... AUDxDAT is written", but
|
||||
// does that just mean written by the CPU, or does it include DMA?
|
||||
// My guess is the former. But TODO.
|
||||
if constexpr (is_external) {
|
||||
channels_[channel].reset_output_phase();
|
||||
}
|
||||
}
|
||||
|
||||
template void Audio::set_data<false>(int, uint16_t);
|
||||
template void Audio::set_data<true>(int, uint16_t);
|
||||
|
||||
void Audio::set_channel_enables(uint16_t enables) {
|
||||
channels_[0].dma_enabled = enables & 1;
|
||||
channels_[1].dma_enabled = enables & 2;
|
||||
channels_[2].dma_enabled = enables & 4;
|
||||
channels_[3].dma_enabled = enables & 8;
|
||||
}
|
||||
|
||||
void Audio::set_modulation_flags(uint16_t flags) {
|
||||
channels_[3].attach_period = flags & 0x80;
|
||||
channels_[2].attach_period = flags & 0x40;
|
||||
channels_[1].attach_period = flags & 0x20;
|
||||
channels_[0].attach_period = flags & 0x10;
|
||||
|
||||
channels_[3].attach_volume = flags & 0x08;
|
||||
channels_[2].attach_volume = flags & 0x04;
|
||||
channels_[1].attach_volume = flags & 0x02;
|
||||
channels_[0].attach_volume = flags & 0x01;
|
||||
}
|
||||
|
||||
void Audio::set_interrupt_requests(uint16_t requests) {
|
||||
channels_[0].interrupt_pending = requests & uint16_t(InterruptFlag::AudioChannel0);
|
||||
channels_[1].interrupt_pending = requests & uint16_t(InterruptFlag::AudioChannel1);
|
||||
channels_[2].interrupt_pending = requests & uint16_t(InterruptFlag::AudioChannel2);
|
||||
channels_[3].interrupt_pending = requests & uint16_t(InterruptFlag::AudioChannel3);
|
||||
}
|
||||
|
||||
// MARK: - DMA and mixing.
|
||||
|
||||
bool Audio::advance_dma(int channel) {
|
||||
if(!channels_[channel].wants_data) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if(channels_[channel].should_reload_address) {
|
||||
channels_[channel].data_address = pointer_[size_t(channel)];
|
||||
channels_[channel].should_reload_address = false;
|
||||
}
|
||||
|
||||
set_data<false>(channel, ram_[channels_[channel].data_address & ram_mask_]);
|
||||
|
||||
if(channels_[channel].state != Channel::State::WaitingForDummyDMA) {
|
||||
++channels_[channel].data_address;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void Audio::output() {
|
||||
constexpr InterruptFlag interrupts[] = {
|
||||
InterruptFlag::AudioChannel0,
|
||||
InterruptFlag::AudioChannel1,
|
||||
InterruptFlag::AudioChannel2,
|
||||
InterruptFlag::AudioChannel3,
|
||||
};
|
||||
Channel *const modulands[] = {
|
||||
&channels_[1],
|
||||
&channels_[2],
|
||||
&channels_[3],
|
||||
nullptr,
|
||||
};
|
||||
|
||||
for(int c = 0; c < 4; c++) {
|
||||
if(channels_[c].output(modulands[c])) {
|
||||
posit_interrupt(interrupts[c]);
|
||||
}
|
||||
}
|
||||
|
||||
// Spin until the next buffer is available if just entering it for the first time.
|
||||
// Contention here should be essentially non-existent.
|
||||
if(!sample_pointer_) {
|
||||
while(!buffer_available_[buffer_pointer_].load(std::memory_order::memory_order_relaxed));
|
||||
}
|
||||
|
||||
// Left.
|
||||
static_assert(std::tuple_size<AudioBuffer>::value % 2 == 0);
|
||||
buffer_[buffer_pointer_][sample_pointer_] = int16_t(
|
||||
(
|
||||
channels_[1].output_level * channels_[1].output_enabled +
|
||||
channels_[2].output_level * channels_[2].output_enabled
|
||||
) << 7
|
||||
);
|
||||
|
||||
// Right.
|
||||
buffer_[buffer_pointer_][sample_pointer_ + 1] = int16_t(
|
||||
(
|
||||
channels_[0].output_level * channels_[0].output_enabled +
|
||||
channels_[3].output_level * channels_[3].output_enabled
|
||||
) << 7
|
||||
);
|
||||
sample_pointer_ += 2;
|
||||
|
||||
if(sample_pointer_ == buffer_[buffer_pointer_].size()) {
|
||||
const auto &buffer = buffer_[buffer_pointer_];
|
||||
auto &flag = buffer_available_[buffer_pointer_];
|
||||
|
||||
flag.store(false, std::memory_order::memory_order_release);
|
||||
queue_.enqueue([this, &buffer, &flag] {
|
||||
speaker_.push(buffer.data(), buffer.size() >> 1);
|
||||
flag.store(true, std::memory_order::memory_order_relaxed);
|
||||
});
|
||||
|
||||
buffer_pointer_ = (buffer_pointer_ + 1) % BufferCount;
|
||||
sample_pointer_ = 0;
|
||||
}
|
||||
}
|
||||
|
||||
// MARK: - Per-channel logic.
|
||||
|
||||
/*
|
||||
Big spiel on the state machine:
|
||||
|
||||
Commodore's Hardware Rerefence Manual provides the audio subsystem's state
|
||||
machine, so I've just tried to reimplement it verbatim. It's depicted
|
||||
diagrammatically in the original source as a finite state automata, the
|
||||
below is my attempt to translate that into text.
|
||||
|
||||
|
||||
000 State::Disabled:
|
||||
|
||||
-> State::Disabled (000)
|
||||
if: N/A
|
||||
action: percntrld
|
||||
|
||||
-> State::PlayingHigh (010)
|
||||
if: AUDDAT, and not AUDxON, and not AUDxIP
|
||||
action: percntrld, AUDxIR, volcntrld, pbudld1
|
||||
|
||||
-> State::WaitingForDummyDMA (001)
|
||||
if: AUDxON
|
||||
action: percntrld, AUDxDR, lencntrld, dmasen*
|
||||
|
||||
|
||||
* NOTE: except for this case, dmasen is true only when
|
||||
LENFIN = 1. Also, AUDxDSR = (AUDxDR and dmasen).
|
||||
|
||||
|
||||
|
||||
001 State::WaitingForDummyDMA:
|
||||
|
||||
-> State::WaitingForDummyDMA (001)
|
||||
if: N/A
|
||||
action: None
|
||||
|
||||
-> State::Disabled (000)
|
||||
if: not AUDxON
|
||||
action: None
|
||||
|
||||
-> State::WaitingForDMA (101)
|
||||
if: AUDxON, and AUDxDAT
|
||||
action:
|
||||
1. AUDxIR
|
||||
2. if not lenfin, then lencount
|
||||
|
||||
|
||||
|
||||
101 State::WaitingForDMA:
|
||||
|
||||
-> State::WaitingForDMA (101)
|
||||
if: N/A
|
||||
action: None
|
||||
|
||||
-> State:Disabled (000)
|
||||
if: not AUDxON
|
||||
action: None
|
||||
|
||||
-> State::PlayingHigh (010)
|
||||
if: AUDxON, and AUDxDAT
|
||||
action:
|
||||
1. volcntrld, percntrld, pbufld1
|
||||
2. if napnav, then AUDxDR
|
||||
|
||||
|
||||
|
||||
010 State::PlayingHigh
|
||||
|
||||
-> State::PlayingHigh (010)
|
||||
if: N/A
|
||||
action: percount, and penhi
|
||||
|
||||
-> State::PlayingLow (011)
|
||||
if: perfin
|
||||
action:
|
||||
1. if AUDxAP, then pbufld2
|
||||
2. if AUDxAP and AUDxON, then AUDxDR
|
||||
3. percntrld
|
||||
4. if intreq2 and AUDxON and AUDxAP, then AUDxIR
|
||||
5. if AUDxAP and AUDxON, then AUDxIR
|
||||
6. if lenfin and AUDxON and AUDxDAT, then lencntrld
|
||||
7. if (not lenfin) and AUDxON and AUDxDAT, then lencount
|
||||
8. if lenfin and AUDxON and AUDxDAT, then intreq2
|
||||
|
||||
[note that 6–8 are shared with the Low -> High transition]
|
||||
|
||||
|
||||
|
||||
011 State::PlayingLow
|
||||
|
||||
-> State::PlayingLow (011)
|
||||
if: N/A
|
||||
action: percount, and not penhi
|
||||
|
||||
-> State::Disabled (000)
|
||||
if: perfin and not (AUDxON or not AUDxIP)
|
||||
action: None
|
||||
|
||||
-> State::PlayingHigh (010)
|
||||
if: perfin and (AUDxON or not AUDxIP)
|
||||
action:
|
||||
1. pbufld1
|
||||
2. percntrld
|
||||
3. if napnav and AUDxON, then AUDxDR
|
||||
4. if napnav and AUDxON and intreq2, AUDxIR
|
||||
5. if napnav and not AUDxON, AUDxIR
|
||||
6. if lenfin and AUDxON and AUDxDAT, then lencntrld
|
||||
7. if (not lenfin) and AUDxON and AUDxDAT, then lencount
|
||||
8. if lenfin and AUDxON and AUDxDAT, then intreq2
|
||||
|
||||
[note that 6-8 are shared with the High -> Low transition]
|
||||
|
||||
|
||||
|
||||
Definitions:
|
||||
|
||||
AUDxON DMA on "x" indicates channel number (signal from DMACON).
|
||||
|
||||
AUDxIP Audio interrupt pending (input to channel from interrupt circuitry).
|
||||
|
||||
AUDxIR Audio interrupt request (output from channel to interrupt circuitry).
|
||||
|
||||
intreq1 Interrupt request that combines with intreq2 to form AUDxIR.
|
||||
|
||||
intreq2 Prepare for interrupt request. Request comes out after the
|
||||
next 011->010 transition in normal operation.
|
||||
|
||||
AUDxDAT Audio data load signal. Loads 16 bits of data to audio channel.
|
||||
|
||||
AUDxDR Audio DMA request to Agnus for one word of data.
|
||||
|
||||
AUDxDSR Audio DMA request to Agnus to reset pointer to start of block.
|
||||
|
||||
dmasen Restart request enable.
|
||||
|
||||
percntrld Reload period counter from back-up latch typically written
|
||||
by processor with AUDxPER (can also be written by attach mode).
|
||||
|
||||
percount Count period counter down one latch.
|
||||
|
||||
perfin Period counter finished (value = 1).
|
||||
|
||||
lencntrld Reload length counter from back-up latch.
|
||||
|
||||
lencount Count length counter down one notch.
|
||||
|
||||
lenfin Length counter finished (value = 1).
|
||||
|
||||
volcntrld Reload volume counter from back-up latch.
|
||||
|
||||
pbufld1 Load output buffer from holding latch written to by AUDxDAT.
|
||||
|
||||
pbufld2 Like pbufld1, but only during 010->011 with attach period.
|
||||
|
||||
AUDxAV Attach volume. Send data to volume latch of next channel
|
||||
instead of to D->A converter.
|
||||
|
||||
AUDxAP Attach period. Send data to period latch of next channel
|
||||
instead of to the D->A converter.
|
||||
|
||||
penhi Enable the high 8 bits of data to go to the D->A converter.
|
||||
|
||||
napnav /AUDxAV * /AUDxAP + AUDxAV -- no attach stuff or else attach
|
||||
volume. Condition for normal DMA and interrupt requests.
|
||||
*/
|
||||
|
||||
//
|
||||
// Non-action fallback transition and setter, plus specialised begin_state declarations.
|
||||
//
|
||||
|
||||
template <Audio::Channel::State end> void Audio::Channel::begin_state(Channel *) {
|
||||
state = end;
|
||||
}
|
||||
template <> void Audio::Channel::begin_state<Audio::Channel::State::PlayingHigh>(Channel *);
|
||||
template <> void Audio::Channel::begin_state<Audio::Channel::State::PlayingLow>(Channel *);
|
||||
|
||||
template <
|
||||
Audio::Channel::State begin,
|
||||
Audio::Channel::State end> bool Audio::Channel::transit(Channel *moduland) {
|
||||
begin_state<end>(moduland);
|
||||
return false;
|
||||
}
|
||||
|
||||
//
|
||||
// Audio::Channel::State::Disabled
|
||||
//
|
||||
|
||||
template <> bool Audio::Channel::transit<
|
||||
Audio::Channel::State::Disabled,
|
||||
Audio::Channel::State::PlayingHigh>(Channel *moduland) {
|
||||
begin_state<State::PlayingHigh>(moduland);
|
||||
|
||||
// percntrld
|
||||
period_counter = period;
|
||||
|
||||
// [AUDxIR]: see return result.
|
||||
|
||||
// volcntrld
|
||||
volume_latch = volume;
|
||||
reset_output_phase();
|
||||
|
||||
// pbufld1
|
||||
data_latch = data;
|
||||
wants_data = true;
|
||||
if(moduland && attach_volume) moduland->volume = uint8_t(data_latch);
|
||||
|
||||
// AUDxIR.
|
||||
return true;
|
||||
}
|
||||
|
||||
template <> bool Audio::Channel::transit<
|
||||
Audio::Channel::State::Disabled,
|
||||
Audio::Channel::State::WaitingForDummyDMA>(Channel *moduland) {
|
||||
begin_state<State::WaitingForDummyDMA>(moduland);
|
||||
|
||||
// percntrld
|
||||
period_counter = period;
|
||||
|
||||
// AUDxDR
|
||||
wants_data = true;
|
||||
|
||||
// lencntrld
|
||||
length_counter = length;
|
||||
|
||||
// dmasen / AUDxDSR
|
||||
should_reload_address = true;
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
template <> bool Audio::Channel::output<Audio::Channel::State::Disabled>(Channel *moduland) {
|
||||
// if AUDDAT, and not AUDxON, and not AUDxIP.
|
||||
if(!wants_data && !dma_enabled && !interrupt_pending) {
|
||||
return transit<State::Disabled, State::PlayingHigh>(moduland);
|
||||
}
|
||||
|
||||
// if AUDxON.
|
||||
if(dma_enabled) {
|
||||
return transit<State::Disabled, State::WaitingForDummyDMA>(moduland);
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
//
|
||||
// Audio::Channel::State::WaitingForDummyDMA
|
||||
//
|
||||
|
||||
template <> bool Audio::Channel::transit<
|
||||
Audio::Channel::State::WaitingForDummyDMA,
|
||||
Audio::Channel::State::WaitingForDMA>(Channel *moduland) {
|
||||
begin_state<State::WaitingForDMA>(moduland);
|
||||
|
||||
// AUDxDR
|
||||
wants_data = true;
|
||||
|
||||
// if not lenfin, then lencount
|
||||
if(length != 1) {
|
||||
-- length_counter;
|
||||
}
|
||||
|
||||
// AUDxIR
|
||||
return true;
|
||||
}
|
||||
|
||||
template <> bool Audio::Channel::output<Audio::Channel::State::WaitingForDummyDMA>(Channel *moduland) {
|
||||
// if not AUDxON
|
||||
if(!dma_enabled) {
|
||||
return transit<State::WaitingForDummyDMA, State::Disabled>(moduland);
|
||||
}
|
||||
|
||||
// if AUDxON and AUDxDAT
|
||||
if(dma_enabled && !wants_data) {
|
||||
return transit<State::WaitingForDummyDMA, State::WaitingForDMA>(moduland);
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
//
|
||||
// Audio::Channel::State::WaitingForDMA
|
||||
//
|
||||
|
||||
template <> bool Audio::Channel::transit<
|
||||
Audio::Channel::State::WaitingForDMA,
|
||||
Audio::Channel::State::PlayingHigh>(Channel *moduland) {
|
||||
begin_state<State::PlayingHigh>(moduland);
|
||||
|
||||
// volcntrld
|
||||
volume_latch = volume;
|
||||
reset_output_phase();
|
||||
|
||||
// percntrld
|
||||
period_counter = period;
|
||||
|
||||
// pbufld1
|
||||
data_latch = data;
|
||||
if(moduland && attach_volume) moduland->volume = uint8_t(data_latch);
|
||||
|
||||
// if napnav
|
||||
if(attach_volume || !(attach_volume || attach_period)) {
|
||||
// AUDxDR
|
||||
wants_data = true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
template <> bool Audio::Channel::output<Audio::Channel::State::WaitingForDMA>(Channel *moduland) {
|
||||
// if: not AUDxON
|
||||
if(!dma_enabled) {
|
||||
return transit<State::WaitingForDummyDMA, State::Disabled>(moduland);
|
||||
}
|
||||
|
||||
// if: AUDxON, and AUDxDAT
|
||||
if(dma_enabled && !wants_data) {
|
||||
return transit<State::WaitingForDummyDMA, State::PlayingHigh>(moduland);
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
//
|
||||
// Audio::Channel::State::PlayingHigh
|
||||
//
|
||||
|
||||
void Audio::Channel::decrement_length() {
|
||||
// if lenfin and AUDxON and AUDxDAT, then lencntrld
|
||||
// if (not lenfin) and AUDxON and AUDxDAT, then lencount
|
||||
// if lenfin and AUDxON and AUDxDAT, then intreq2
|
||||
if(dma_enabled && !wants_data) {
|
||||
-- length_counter;
|
||||
|
||||
if(!length_counter) {
|
||||
length_counter = length;
|
||||
will_request_interrupt = true;
|
||||
should_reload_address = true; // This feels logical to me; it's a bit
|
||||
// of a stab in the dark though.
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
template <> bool Audio::Channel::transit<
|
||||
Audio::Channel::State::PlayingHigh,
|
||||
Audio::Channel::State::PlayingLow>(Channel *moduland) {
|
||||
begin_state<State::PlayingLow>(moduland);
|
||||
|
||||
bool wants_interrupt = false;
|
||||
|
||||
// if AUDxAP
|
||||
if(attach_period) {
|
||||
// pbufld2
|
||||
data_latch = data;
|
||||
if(moduland) moduland->period = data_latch;
|
||||
|
||||
// [if AUDxAP] and AUDxON
|
||||
if(dma_enabled) {
|
||||
// AUDxDR
|
||||
wants_data = true;
|
||||
|
||||
// [if AUDxAP and AUDxON] and intreq2
|
||||
if(will_request_interrupt) {
|
||||
will_request_interrupt = false;
|
||||
|
||||
// AUDxIR
|
||||
wants_interrupt = true;
|
||||
}
|
||||
} else {
|
||||
// i.e. if AUDxAP and AUDxON, then AUDxIR
|
||||
wants_interrupt = true;
|
||||
}
|
||||
}
|
||||
|
||||
// percntrld
|
||||
period_counter = period;
|
||||
|
||||
decrement_length();
|
||||
|
||||
return wants_interrupt;
|
||||
}
|
||||
|
||||
template <> void Audio::Channel::begin_state<Audio::Channel::State::PlayingHigh>(Channel *) {
|
||||
state = Audio::Channel::State::PlayingHigh;
|
||||
|
||||
// penhi.
|
||||
output_level = int8_t(data_latch >> 8);
|
||||
}
|
||||
|
||||
template <> bool Audio::Channel::output<Audio::Channel::State::PlayingHigh>(Channel *moduland) {
|
||||
// This is a reasonable guess as to the exit condition for this node;
|
||||
// Commodore doesn't document.
|
||||
if(period_counter == 1) {
|
||||
return transit<State::PlayingHigh, State::PlayingLow>(moduland);
|
||||
}
|
||||
|
||||
// percount.
|
||||
-- period_counter;
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
//
|
||||
// Audio::Channel::State::PlayingLow
|
||||
//
|
||||
|
||||
template <> bool Audio::Channel::transit<
|
||||
Audio::Channel::State::PlayingLow,
|
||||
Audio::Channel::State::Disabled>(Channel *moduland) {
|
||||
begin_state<State::Disabled>(moduland);
|
||||
|
||||
// Clear the slightly nebulous 'if intreq2 occurred' state.
|
||||
will_request_interrupt = false;
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
template <> bool Audio::Channel::transit<
|
||||
Audio::Channel::State::PlayingLow,
|
||||
Audio::Channel::State::PlayingHigh>(Channel *moduland) {
|
||||
begin_state<State::PlayingHigh>(moduland);
|
||||
|
||||
bool wants_interrupt = false;
|
||||
|
||||
// volcntrld
|
||||
volume_latch = volume;
|
||||
reset_output_phase(); // Is this correct?
|
||||
|
||||
// percntrld
|
||||
period_counter = period;
|
||||
|
||||
// pbufld1
|
||||
data_latch = data;
|
||||
if(moduland && attach_volume) moduland->volume = uint8_t(data_latch);
|
||||
|
||||
// if napnav
|
||||
if(attach_volume || !(attach_volume || attach_period)) {
|
||||
// [if napnav] and AUDxON
|
||||
if(dma_enabled) {
|
||||
// AUDxDR
|
||||
wants_data = true;
|
||||
|
||||
// [if napnav and AUDxON] and intreq2
|
||||
if(will_request_interrupt) {
|
||||
will_request_interrupt = false;
|
||||
wants_interrupt = true;
|
||||
}
|
||||
} else {
|
||||
// AUDxIR
|
||||
wants_interrupt = true;
|
||||
}
|
||||
}
|
||||
|
||||
decrement_length();
|
||||
|
||||
return wants_interrupt;
|
||||
}
|
||||
|
||||
template <> void Audio::Channel::begin_state<Audio::Channel::State::PlayingLow>(Channel *) {
|
||||
state = Audio::Channel::State::PlayingLow;
|
||||
|
||||
// Output low byte.
|
||||
output_level = int8_t(data_latch & 0xff);
|
||||
}
|
||||
|
||||
template <> bool Audio::Channel::output<Audio::Channel::State::PlayingLow>(Channel *moduland) {
|
||||
-- period_counter;
|
||||
|
||||
if(!period_counter) {
|
||||
const bool dma_or_no_interrupt = dma_enabled || !interrupt_pending;
|
||||
if(dma_or_no_interrupt) {
|
||||
return transit<State::PlayingLow, State::PlayingHigh>(moduland);
|
||||
} else {
|
||||
return transit<State::PlayingLow, State::Disabled>(moduland);
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
//
|
||||
// Dispatcher
|
||||
//
|
||||
|
||||
bool Audio::Channel::output(Channel *moduland) {
|
||||
// Update pulse-width modulation.
|
||||
output_phase = output_phase + 1;
|
||||
if(output_phase == 64) {
|
||||
reset_output_phase();
|
||||
} else {
|
||||
output_enabled &= output_phase != volume_latch;
|
||||
}
|
||||
|
||||
switch(state) {
|
||||
case State::Disabled: return output<State::Disabled>(moduland);
|
||||
case State::WaitingForDummyDMA: return output<State::WaitingForDummyDMA>(moduland);
|
||||
case State::WaitingForDMA: return output<State::WaitingForDMA>(moduland);
|
||||
case State::PlayingHigh: return output<State::PlayingHigh>(moduland);
|
||||
case State::PlayingLow: return output<State::PlayingLow>(moduland);
|
||||
|
||||
default:
|
||||
assert(false);
|
||||
break;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
163
Machines/Amiga/Audio.hpp
Normal file
163
Machines/Amiga/Audio.hpp
Normal file
@@ -0,0 +1,163 @@
|
||||
//
|
||||
// Audio.hpp
|
||||
// Clock Signal
|
||||
//
|
||||
// Created by Thomas Harte on 09/11/2021.
|
||||
// Copyright © 2021 Thomas Harte. All rights reserved.
|
||||
//
|
||||
|
||||
#ifndef Audio_hpp
|
||||
#define Audio_hpp
|
||||
|
||||
#include <atomic>
|
||||
#include <cstdint>
|
||||
|
||||
#include "DMADevice.hpp"
|
||||
#include "../../ClockReceiver/ClockReceiver.hpp"
|
||||
#include "../../Concurrency/AsyncTaskQueue.hpp"
|
||||
#include "../../Outputs/Speaker/Implementation/LowpassSpeaker.hpp"
|
||||
|
||||
namespace Amiga {
|
||||
|
||||
class Audio: public DMADevice<4> {
|
||||
public:
|
||||
Audio(Chipset &chipset, uint16_t *ram, size_t word_size, float output_rate);
|
||||
|
||||
/// Idiomatic call-in for DMA scheduling; indicates that this class may
|
||||
/// perform a DMA access for the stated channel now.
|
||||
bool advance_dma(int channel);
|
||||
|
||||
/// Advances output by one DMA window, which is implicitly two cycles
|
||||
/// at the output rate that was specified to the constructor.
|
||||
void output();
|
||||
|
||||
/// Sets the total number of words to fetch for the given channel.
|
||||
void set_length(int channel, uint16_t);
|
||||
|
||||
/// Sets the number of DMA windows between each 8-bit output,
|
||||
/// in the same time base as @c ticks_per_line.
|
||||
void set_period(int channel, uint16_t);
|
||||
|
||||
/// Sets the output volume for the given channel; if bit 6 is set
|
||||
/// then output is maximal; otherwise bits 0–5 select
|
||||
/// a volume of [0–63]/64, on a logarithmic scale.
|
||||
void set_volume(int channel, uint16_t);
|
||||
|
||||
/// Sets the next two samples of audio to output.
|
||||
template <bool is_external = true> void set_data(int channel, uint16_t);
|
||||
|
||||
/// Provides a copy of the DMA enable flags, for the purpose of
|
||||
/// determining which channels are enabled for DMA.
|
||||
void set_channel_enables(uint16_t);
|
||||
|
||||
/// Sets which channels, if any, modulate period or volume of
|
||||
/// their neighbours.
|
||||
void set_modulation_flags(uint16_t);
|
||||
|
||||
/// Sets which interrupt requests are currently active.
|
||||
void set_interrupt_requests(uint16_t);
|
||||
|
||||
/// Obtains the output source.
|
||||
Outputs::Speaker::Speaker *get_speaker() {
|
||||
return &speaker_;
|
||||
}
|
||||
|
||||
private:
|
||||
struct Channel {
|
||||
// The data latch plus a count of unused samples
|
||||
// in the latch, which will always be 0, 1 or 2.
|
||||
uint16_t data = 0x0000;
|
||||
bool wants_data = false;
|
||||
uint16_t data_latch = 0x0000;
|
||||
|
||||
// The DMA address; unlike most of the Amiga Chipset,
|
||||
// the user posts a value to feed a pointer, rather
|
||||
// than having access to the pointer itself.
|
||||
bool should_reload_address = false;
|
||||
uint32_t data_address = 0x0000'0000;
|
||||
|
||||
// Number of words remaining in DMA data.
|
||||
uint16_t length = 0;
|
||||
uint16_t length_counter = 0;
|
||||
|
||||
// Number of ticks between each sample, plus the
|
||||
// current counter, which counts downward.
|
||||
uint16_t period = 0;
|
||||
uint16_t period_counter = 0;
|
||||
|
||||
// Modulation / attach flags.
|
||||
bool attach_period = false;
|
||||
bool attach_volume = false;
|
||||
|
||||
// Output volume, [0, 64].
|
||||
uint8_t volume = 0;
|
||||
uint8_t volume_latch = 0;
|
||||
|
||||
// Indicates whether DMA is enabled for this channel.
|
||||
bool dma_enabled = false;
|
||||
|
||||
// Records whether this audio interrupt is pending.
|
||||
bool interrupt_pending = false;
|
||||
bool will_request_interrupt = false;
|
||||
|
||||
// Replicates the Hardware Reference Manual state machine;
|
||||
// comments indicate which of the documented states each
|
||||
// label refers to.
|
||||
enum class State {
|
||||
Disabled, // 000
|
||||
WaitingForDummyDMA, // 001
|
||||
WaitingForDMA, // 101
|
||||
PlayingHigh, // 010
|
||||
PlayingLow, // 011
|
||||
} state = State::Disabled;
|
||||
|
||||
/// Dispatches to the appropriate templatised output for the current state.
|
||||
/// @param moduland The channel to modulate, if modulation is enabled.
|
||||
/// @returns @c true if an interrupt should be posted; @c false otherwise.
|
||||
bool output(Channel *moduland);
|
||||
|
||||
/// Applies dynamic logic for @c state, mostly testing for potential state transitions.
|
||||
/// @param moduland The channel to modulate, if modulation is enabled.
|
||||
/// @returns @c true if an interrupt should be posted; @c false otherwise.
|
||||
template <State state> bool output(Channel *moduland);
|
||||
|
||||
/// Transitions from @c begin to @c end, calling the appropriate @c begin_state
|
||||
/// and taking any steps specific to that particular transition.
|
||||
/// @param moduland The channel to modulate, if modulation is enabled.
|
||||
/// @returns @c true if an interrupt should be posted; @c false otherwise.
|
||||
template <State begin, State end> bool transit(Channel *moduland);
|
||||
|
||||
/// Begins @c state, performing all fixed logic that would otherwise have to be
|
||||
/// repeated endlessly in the relevant @c output.
|
||||
/// @param moduland The channel to modulate, if modulation is enabled.
|
||||
template <State state> void begin_state(Channel *moduland);
|
||||
|
||||
/// Provides the common length-decrementing logic used when transitioning
|
||||
/// between PlayingHigh and PlayingLow in either direction.
|
||||
void decrement_length();
|
||||
|
||||
// Output state.
|
||||
int8_t output_level = 0;
|
||||
uint8_t output_phase = 0;
|
||||
bool output_enabled = false;
|
||||
|
||||
void reset_output_phase() {
|
||||
output_phase = 0;
|
||||
output_enabled = (volume_latch > 0) && !attach_period && !attach_volume;
|
||||
}
|
||||
} channels_[4];
|
||||
|
||||
// Transient output state, and its destination.
|
||||
Outputs::Speaker::PushLowpass<true> speaker_;
|
||||
Concurrency::AsyncTaskQueue queue_;
|
||||
|
||||
using AudioBuffer = std::array<int16_t, 4096>;
|
||||
static constexpr int BufferCount = 3;
|
||||
AudioBuffer buffer_[BufferCount];
|
||||
std::atomic<bool> buffer_available_[BufferCount];
|
||||
size_t buffer_pointer_ = 0, sample_pointer_ = 0;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif /* Audio_hpp */
|
||||
132
Machines/Amiga/Bitplanes.cpp
Normal file
132
Machines/Amiga/Bitplanes.cpp
Normal file
@@ -0,0 +1,132 @@
|
||||
//
|
||||
// Bitplanes.cpp
|
||||
// Clock Signal
|
||||
//
|
||||
// Created by Thomas Harte on 26/11/2021.
|
||||
// Copyright © 2021 Thomas Harte. All rights reserved.
|
||||
//
|
||||
|
||||
#include "Bitplanes.hpp"
|
||||
#include "Chipset.hpp"
|
||||
|
||||
using namespace Amiga;
|
||||
|
||||
namespace {
|
||||
|
||||
/// Expands @c source so that b7 is the least-significant bit of the most-significant byte of the result,
|
||||
/// b6 is the least-significant bit of the next most significant byte, etc. b0 stays in place.
|
||||
constexpr uint64_t expand_bitplane_byte(uint8_t source) {
|
||||
uint64_t result = source; // 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 abcd efgh
|
||||
result = (result | (result << 28)) & 0x0000'000f'0000'000f; // 0000 0000 0000 0000 0000 0000 0000 abcd 0000 0000 0000 0000 0000 0000 0000 efgh
|
||||
result = (result | (result << 14)) & 0x0003'0003'0003'0003; // 0000 0000 0000 00ab 0000 0000 0000 00cd 0000 0000 0000 00ef 0000 0000 0000 00gh
|
||||
result = (result | (result << 7)) & 0x0101'0101'0101'0101; // 0000 000a 0000 000b 0000 000c 0000 000d 0000 000e 0000 000f 0000 000g 0000 000h
|
||||
return result;
|
||||
}
|
||||
|
||||
// A very small selection of test cases.
|
||||
static_assert(expand_bitplane_byte(0xff) == 0x01'01'01'01'01'01'01'01);
|
||||
static_assert(expand_bitplane_byte(0x55) == 0x00'01'00'01'00'01'00'01);
|
||||
static_assert(expand_bitplane_byte(0xaa) == 0x01'00'01'00'01'00'01'00);
|
||||
static_assert(expand_bitplane_byte(0x00) == 0x00'00'00'00'00'00'00'00);
|
||||
|
||||
}
|
||||
|
||||
// MARK: - BitplaneShifter.
|
||||
|
||||
void BitplaneShifter::set(const BitplaneData &previous, const BitplaneData &next, int odd_delay, int even_delay) {
|
||||
const uint16_t planes[6] = {
|
||||
uint16_t(((previous[0] << 16) | next[0]) >> even_delay),
|
||||
uint16_t(((previous[1] << 16) | next[1]) >> odd_delay),
|
||||
uint16_t(((previous[2] << 16) | next[2]) >> even_delay),
|
||||
uint16_t(((previous[3] << 16) | next[3]) >> odd_delay),
|
||||
uint16_t(((previous[4] << 16) | next[4]) >> even_delay),
|
||||
uint16_t(((previous[5] << 16) | next[5]) >> odd_delay),
|
||||
};
|
||||
|
||||
// Swizzle bits into the form:
|
||||
//
|
||||
// [b5 b3 b1 b4 b2 b0]
|
||||
//
|
||||
// ... and assume a suitably adjusted palette is in use elsewhere.
|
||||
// This makes dual playfields very easy to separate.
|
||||
data_[0] =
|
||||
(expand_bitplane_byte(uint8_t(planes[0])) << 0) |
|
||||
(expand_bitplane_byte(uint8_t(planes[2])) << 1) |
|
||||
(expand_bitplane_byte(uint8_t(planes[4])) << 2) |
|
||||
(expand_bitplane_byte(uint8_t(planes[1])) << 3) |
|
||||
(expand_bitplane_byte(uint8_t(planes[3])) << 4) |
|
||||
(expand_bitplane_byte(uint8_t(planes[5])) << 5);
|
||||
|
||||
data_[1] =
|
||||
(expand_bitplane_byte(uint8_t(planes[0] >> 8)) << 0) |
|
||||
(expand_bitplane_byte(uint8_t(planes[2] >> 8)) << 1) |
|
||||
(expand_bitplane_byte(uint8_t(planes[4] >> 8)) << 2) |
|
||||
(expand_bitplane_byte(uint8_t(planes[1] >> 8)) << 3) |
|
||||
(expand_bitplane_byte(uint8_t(planes[3] >> 8)) << 4) |
|
||||
(expand_bitplane_byte(uint8_t(planes[5] >> 8)) << 5);
|
||||
}
|
||||
|
||||
// MARK: - Bitplanes.
|
||||
|
||||
bool Bitplanes::advance_dma(int cycle) {
|
||||
#define BIND_CYCLE(offset, plane) \
|
||||
case offset: \
|
||||
if(plane_count_ > plane) { \
|
||||
next[plane] = ram_[pointer_[plane] & ram_mask_]; \
|
||||
++pointer_[plane]; \
|
||||
if constexpr (!plane) { \
|
||||
chipset_.post_bitplanes(next); \
|
||||
} \
|
||||
return true; \
|
||||
} \
|
||||
return false;
|
||||
|
||||
if(is_high_res_) {
|
||||
switch(cycle&3) {
|
||||
default: return false;
|
||||
BIND_CYCLE(0, 3);
|
||||
BIND_CYCLE(1, 1);
|
||||
BIND_CYCLE(2, 2);
|
||||
BIND_CYCLE(3, 0);
|
||||
}
|
||||
} else {
|
||||
switch(cycle&7) {
|
||||
default: return false;
|
||||
/* Omitted: 0. */
|
||||
BIND_CYCLE(1, 3);
|
||||
BIND_CYCLE(2, 5);
|
||||
BIND_CYCLE(3, 1);
|
||||
/* Omitted: 4. */
|
||||
BIND_CYCLE(5, 2);
|
||||
BIND_CYCLE(6, 4);
|
||||
BIND_CYCLE(7, 0);
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
|
||||
#undef BIND_CYCLE
|
||||
}
|
||||
|
||||
void Bitplanes::do_end_of_line() {
|
||||
// Apply modulos here. Posssibly correct?
|
||||
pointer_[0] += modulos_[1];
|
||||
pointer_[2] += modulos_[1];
|
||||
pointer_[4] += modulos_[1];
|
||||
|
||||
pointer_[1] += modulos_[0];
|
||||
pointer_[3] += modulos_[0];
|
||||
pointer_[5] += modulos_[0];
|
||||
}
|
||||
|
||||
void Bitplanes::set_control(uint16_t control) {
|
||||
is_high_res_ = control & 0x8000;
|
||||
plane_count_ = (control >> 12) & 7;
|
||||
|
||||
// TODO: who really has responsibility for clearing the other
|
||||
// bit plane fields?
|
||||
std::fill(next.begin() + plane_count_, next.end(), 0);
|
||||
if(plane_count_ == 7) {
|
||||
plane_count_ = 4;
|
||||
}
|
||||
}
|
||||
96
Machines/Amiga/Bitplanes.hpp
Normal file
96
Machines/Amiga/Bitplanes.hpp
Normal file
@@ -0,0 +1,96 @@
|
||||
//
|
||||
// Bitplanes.hpp
|
||||
// Clock Signal
|
||||
//
|
||||
// Created by Thomas Harte on 26/11/2021.
|
||||
// Copyright © 2021 Thomas Harte. All rights reserved.
|
||||
//
|
||||
|
||||
#ifndef Bitplanes_hpp
|
||||
#define Bitplanes_hpp
|
||||
|
||||
#include <cstdint>
|
||||
|
||||
#include "DMADevice.hpp"
|
||||
|
||||
namespace Amiga {
|
||||
|
||||
struct BitplaneData: public std::array<uint16_t, 6> {
|
||||
BitplaneData &operator <<= (int c) {
|
||||
(*this)[0] <<= c;
|
||||
(*this)[1] <<= c;
|
||||
(*this)[2] <<= c;
|
||||
(*this)[3] <<= c;
|
||||
(*this)[4] <<= c;
|
||||
(*this)[5] <<= c;
|
||||
return *this;
|
||||
}
|
||||
|
||||
void clear() {
|
||||
std::fill(begin(), end(), 0);
|
||||
}
|
||||
};
|
||||
|
||||
class Bitplanes: public DMADevice<6, 2> {
|
||||
public:
|
||||
using DMADevice::DMADevice;
|
||||
|
||||
bool advance_dma(int cycle);
|
||||
void do_end_of_line();
|
||||
void set_control(uint16_t);
|
||||
|
||||
private:
|
||||
bool is_high_res_ = false;
|
||||
int plane_count_ = 0;
|
||||
|
||||
BitplaneData next;
|
||||
};
|
||||
|
||||
template <typename SourceT> constexpr SourceT bitplane_swizzle(SourceT value) {
|
||||
return
|
||||
(value&0x21) |
|
||||
((value&0x02) << 2) |
|
||||
((value&0x04) >> 1) |
|
||||
((value&0x08) << 1) |
|
||||
((value&0x10) >> 2);
|
||||
}
|
||||
|
||||
class BitplaneShifter {
|
||||
public:
|
||||
/// Installs a new set of output pixels.
|
||||
void set(
|
||||
const BitplaneData &previous,
|
||||
const BitplaneData &next,
|
||||
int odd_delay,
|
||||
int even_delay);
|
||||
|
||||
/// Shifts either two pixels (in low-res mode) and four pixels (in high-res).
|
||||
void shift(bool high_res) {
|
||||
constexpr int shifts[] = {16, 32};
|
||||
|
||||
data_[1] = (data_[1] << shifts[high_res]) | (data_[0] >> (64 - shifts[high_res]));
|
||||
data_[0] <<= shifts[high_res];
|
||||
}
|
||||
|
||||
/// @returns The next four pixels to output; in low-resolution mode only two
|
||||
/// of them will be unique. The value is arranges so that MSB = first pixel to output,
|
||||
/// LSB = last. Each byte is formed as 00[bitplane 5][bitplane 4]...[bitplane 0].
|
||||
uint32_t get(bool high_res) {
|
||||
if(high_res) {
|
||||
return uint32_t(data_[1] >> 32);
|
||||
} else {
|
||||
uint32_t result = uint16_t(data_[1] >> 48);
|
||||
result = ((result & 0xff00) << 8) | (result & 0x00ff);
|
||||
result |= result << 8;
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
private:
|
||||
std::array<uint64_t, 2> data_{};
|
||||
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif /* Bitplanes_hpp */
|
||||
400
Machines/Amiga/Blitter.cpp
Normal file
400
Machines/Amiga/Blitter.cpp
Normal file
@@ -0,0 +1,400 @@
|
||||
//
|
||||
// Blitter.cpp
|
||||
// Clock Signal
|
||||
//
|
||||
// Created by Thomas Harte on 22/07/2021.
|
||||
// Copyright © 2021 Thomas Harte. All rights reserved.
|
||||
//
|
||||
|
||||
#include "Blitter.hpp"
|
||||
|
||||
#include "Minterms.hpp"
|
||||
|
||||
#include <cassert>
|
||||
|
||||
#ifndef NDEBUG
|
||||
#define NDEBUG
|
||||
#endif
|
||||
|
||||
#define LOG_PREFIX "[Blitter] "
|
||||
#include "../../Outputs/Log.hpp"
|
||||
|
||||
using namespace Amiga;
|
||||
|
||||
namespace {
|
||||
|
||||
/// @returns Either the final carry flag or the output nibble when using fill mode given that it either @c is_exclusive fill mode, or isn't;
|
||||
/// and the specified initial @c carry and input @c nibble.
|
||||
template <bool wants_carry> constexpr uint32_t fill_nibble(bool is_exclusive, uint8_t carry, uint8_t nibble) {
|
||||
uint8_t fill_output = 0;
|
||||
uint8_t bit = 0x01;
|
||||
while(bit < 0x10) {
|
||||
auto pre_toggle = nibble & bit, post_toggle = pre_toggle;
|
||||
if(!is_exclusive) {
|
||||
pre_toggle &= ~carry; // Accept bits that would transition to set immediately.
|
||||
post_toggle &= carry; // Accept bits that would transition to clear after the fact.
|
||||
} else {
|
||||
post_toggle = 0; // Just do the pre-toggle.
|
||||
}
|
||||
|
||||
carry ^= pre_toggle;
|
||||
fill_output |= carry;
|
||||
carry ^= post_toggle;
|
||||
|
||||
bit <<= 1;
|
||||
carry <<= 1;
|
||||
}
|
||||
|
||||
if constexpr (wants_carry) {
|
||||
return carry >> 4;
|
||||
} else {
|
||||
return fill_output;
|
||||
}
|
||||
}
|
||||
|
||||
// Lookup key for these tables is:
|
||||
//
|
||||
// b0–b3: input nibble
|
||||
// b4: carry
|
||||
// b5: is_exclusive
|
||||
//
|
||||
// i.e. it's in the range [0, 63].
|
||||
//
|
||||
// Tables below are indexed such that the higher-order bits select a table entry, lower-order bits select
|
||||
// a bit or nibble from within the indexed item.
|
||||
|
||||
constexpr uint32_t fill_carries[] = {
|
||||
(fill_nibble<true>(false, 0, 0x0) << 0x0) | (fill_nibble<true>(false, 0, 0x1) << 0x1) | (fill_nibble<true>(false, 0, 0x2) << 0x2) | (fill_nibble<true>(false, 0, 0x3) << 0x3) |
|
||||
(fill_nibble<true>(false, 0, 0x4) << 0x4) | (fill_nibble<true>(false, 0, 0x5) << 0x5) | (fill_nibble<true>(false, 0, 0x6) << 0x6) | (fill_nibble<true>(false, 0, 0x7) << 0x7) |
|
||||
(fill_nibble<true>(false, 0, 0x8) << 0x8) | (fill_nibble<true>(false, 0, 0x9) << 0x9) | (fill_nibble<true>(false, 0, 0xa) << 0xa) | (fill_nibble<true>(false, 0, 0xb) << 0xb) |
|
||||
(fill_nibble<true>(false, 0, 0xc) << 0xc) | (fill_nibble<true>(false, 0, 0xd) << 0xd) | (fill_nibble<true>(false, 0, 0xe) << 0xe) | (fill_nibble<true>(false, 0, 0xf) << 0xf) |
|
||||
|
||||
(fill_nibble<true>(false, 1, 0x0) << 0x10) | (fill_nibble<true>(false, 1, 0x1) << 0x11) | (fill_nibble<true>(false, 1, 0x2) << 0x12) | (fill_nibble<true>(false, 1, 0x3) << 0x13) |
|
||||
(fill_nibble<true>(false, 1, 0x4) << 0x14) | (fill_nibble<true>(false, 1, 0x5) << 0x15) | (fill_nibble<true>(false, 1, 0x6) << 0x16) | (fill_nibble<true>(false, 1, 0x7) << 0x17) |
|
||||
(fill_nibble<true>(false, 1, 0x8) << 0x18) | (fill_nibble<true>(false, 1, 0x9) << 0x19) | (fill_nibble<true>(false, 1, 0xa) << 0x1a) | (fill_nibble<true>(false, 1, 0xb) << 0x1b) |
|
||||
(fill_nibble<true>(false, 1, 0xc) << 0x1c) | (fill_nibble<true>(false, 1, 0xd) << 0x1d) | (fill_nibble<true>(false, 1, 0xe) << 0x1e) | (fill_nibble<true>(false, 1, 0xf) << 0x1f),
|
||||
|
||||
(fill_nibble<true>(true, 0, 0x0) << 0x0) | (fill_nibble<true>(true, 0, 0x1) << 0x1) | (fill_nibble<true>(true, 0, 0x2) << 0x2) | (fill_nibble<true>(true, 0, 0x3) << 0x3) |
|
||||
(fill_nibble<true>(true, 0, 0x4) << 0x4) | (fill_nibble<true>(true, 0, 0x5) << 0x5) | (fill_nibble<true>(true, 0, 0x6) << 0x6) | (fill_nibble<true>(true, 0, 0x7) << 0x7) |
|
||||
(fill_nibble<true>(true, 0, 0x8) << 0x8) | (fill_nibble<true>(true, 0, 0x9) << 0x9) | (fill_nibble<true>(true, 0, 0xa) << 0xa) | (fill_nibble<true>(true, 0, 0xb) << 0xb) |
|
||||
(fill_nibble<true>(true, 0, 0xc) << 0xc) | (fill_nibble<true>(true, 0, 0xd) << 0xd) | (fill_nibble<true>(true, 0, 0xe) << 0xe) | (fill_nibble<true>(true, 0, 0xf) << 0xf) |
|
||||
|
||||
(fill_nibble<true>(true, 1, 0x0) << 0x10) | (fill_nibble<true>(true, 1, 0x1) << 0x11) | (fill_nibble<true>(true, 1, 0x2) << 0x12) | (fill_nibble<true>(true, 1, 0x3) << 0x13) |
|
||||
(fill_nibble<true>(true, 1, 0x4) << 0x14) | (fill_nibble<true>(true, 1, 0x5) << 0x15) | (fill_nibble<true>(true, 1, 0x6) << 0x16) | (fill_nibble<true>(true, 1, 0x7) << 0x17) |
|
||||
(fill_nibble<true>(true, 1, 0x8) << 0x18) | (fill_nibble<true>(true, 1, 0x9) << 0x19) | (fill_nibble<true>(true, 1, 0xa) << 0x1a) | (fill_nibble<true>(true, 1, 0xb) << 0x1b) |
|
||||
(fill_nibble<true>(true, 1, 0xc) << 0x1c) | (fill_nibble<true>(true, 1, 0xd) << 0x1d) | (fill_nibble<true>(true, 1, 0xe) << 0x1e) | (fill_nibble<true>(true, 1, 0xf) << 0x1f),
|
||||
};
|
||||
|
||||
constexpr uint32_t fill_values[] = {
|
||||
(fill_nibble<false>(false, 0, 0x0) << 0) | (fill_nibble<false>(false, 0, 0x1) << 4) | (fill_nibble<false>(false, 0, 0x2) << 8) | (fill_nibble<false>(false, 0, 0x3) << 12) |
|
||||
(fill_nibble<false>(false, 0, 0x4) << 16) | (fill_nibble<false>(false, 0, 0x5) << 20) | (fill_nibble<false>(false, 0, 0x6) << 24) | (fill_nibble<false>(false, 0, 0x7) << 28),
|
||||
|
||||
(fill_nibble<false>(false, 0, 0x8) << 0) | (fill_nibble<false>(false, 0, 0x9) << 4) | (fill_nibble<false>(false, 0, 0xa) << 8) | (fill_nibble<false>(false, 0, 0xb) << 12) |
|
||||
(fill_nibble<false>(false, 0, 0xc) << 16) | (fill_nibble<false>(false, 0, 0xd) << 20) | (fill_nibble<false>(false, 0, 0xe) << 24) | (fill_nibble<false>(false, 0, 0xf) << 28),
|
||||
|
||||
(fill_nibble<false>(false, 1, 0x0) << 0) | (fill_nibble<false>(false, 1, 0x1) << 4) | (fill_nibble<false>(false, 1, 0x2) << 8) | (fill_nibble<false>(false, 1, 0x3) << 12) |
|
||||
(fill_nibble<false>(false, 1, 0x4) << 16) | (fill_nibble<false>(false, 1, 0x5) << 20) | (fill_nibble<false>(false, 1, 0x6) << 24) | (fill_nibble<false>(false, 1, 0x7) << 28),
|
||||
|
||||
(fill_nibble<false>(false, 1, 0x8) << 0) | (fill_nibble<false>(false, 1, 0x9) << 4) | (fill_nibble<false>(false, 1, 0xa) << 8) | (fill_nibble<false>(false, 1, 0xb) << 12) |
|
||||
(fill_nibble<false>(false, 1, 0xc) << 16) | (fill_nibble<false>(false, 1, 0xd) << 20) | (fill_nibble<false>(false, 1, 0xe) << 24) | (fill_nibble<false>(false, 1, 0xf) << 28),
|
||||
|
||||
(fill_nibble<false>(true, 0, 0x0) << 0) | (fill_nibble<false>(true, 0, 0x1) << 4) | (fill_nibble<false>(true, 0, 0x2) << 8) | (fill_nibble<false>(true, 0, 0x3) << 12) |
|
||||
(fill_nibble<false>(true, 0, 0x4) << 16) | (fill_nibble<false>(true, 0, 0x5) << 20) | (fill_nibble<false>(true, 0, 0x6) << 24) | (fill_nibble<false>(true, 0, 0x7) << 28),
|
||||
|
||||
(fill_nibble<false>(true, 0, 0x8) << 0) | (fill_nibble<false>(true, 0, 0x9) << 4) | (fill_nibble<false>(true, 0, 0xa) << 8) | (fill_nibble<false>(true, 0, 0xb) << 12) |
|
||||
(fill_nibble<false>(true, 0, 0xc) << 16) | (fill_nibble<false>(true, 0, 0xd) << 20) | (fill_nibble<false>(true, 0, 0xe) << 24) | (fill_nibble<false>(true, 0, 0xf) << 28),
|
||||
|
||||
(fill_nibble<false>(true, 1, 0x0) << 0) | (fill_nibble<false>(true, 1, 0x1) << 4) | (fill_nibble<false>(true, 1, 0x2) << 8) | (fill_nibble<false>(true, 1, 0x3) << 12) |
|
||||
(fill_nibble<false>(true, 1, 0x4) << 16) | (fill_nibble<false>(true, 1, 0x5) << 20) | (fill_nibble<false>(true, 1, 0x6) << 24) | (fill_nibble<false>(true, 1, 0x7) << 28),
|
||||
|
||||
(fill_nibble<false>(true, 1, 0x8) << 0) | (fill_nibble<false>(true, 1, 0x9) << 4) | (fill_nibble<false>(true, 1, 0xa) << 8) | (fill_nibble<false>(true, 1, 0xb) << 12) |
|
||||
(fill_nibble<false>(true, 1, 0xc) << 16) | (fill_nibble<false>(true, 1, 0xd) << 20) | (fill_nibble<false>(true, 1, 0xe) << 24) | (fill_nibble<false>(true, 1, 0xf) << 28),
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
void Blitter::set_control(int index, uint16_t value) {
|
||||
if(index) {
|
||||
line_mode_ = (value & 0x0001);
|
||||
one_dot_ = value & 0x0002;
|
||||
line_direction_ = (value >> 2) & 7;
|
||||
line_sign_ = (value & 0x0040) ? -1 : 1;
|
||||
|
||||
direction_ = one_dot_ ? uint32_t(-1) : uint32_t(1);
|
||||
exclusive_fill_ = (value & 0x0010);
|
||||
inclusive_fill_ = !exclusive_fill_ && (value & 0x0008); // Exclusive fill takes precedence. Probably? TODO: verify.
|
||||
fill_carry_ = (value & 0x0004);
|
||||
} else {
|
||||
minterms_ = value & 0xff;
|
||||
channel_enables_[3] = value & 0x100;
|
||||
channel_enables_[2] = value & 0x200;
|
||||
channel_enables_[1] = value & 0x400;
|
||||
channel_enables_[0] = value & 0x800;
|
||||
}
|
||||
shifts_[index] = value >> 12;
|
||||
LOG("Set control " << index << " to " << PADHEX(4) << value);
|
||||
}
|
||||
|
||||
void Blitter::set_first_word_mask(uint16_t value) {
|
||||
LOG("Set first word mask: " << PADHEX(4) << value);
|
||||
a_mask_[0] = value;
|
||||
}
|
||||
|
||||
void Blitter::set_last_word_mask(uint16_t value) {
|
||||
LOG("Set last word mask: " << PADHEX(4) << value);
|
||||
a_mask_[1] = value;
|
||||
}
|
||||
|
||||
void Blitter::set_size(uint16_t value) {
|
||||
// width_ = (width_ & ~0x3f) | (value & 0x3f);
|
||||
// height_ = (height_ & ~0x3ff) | (value >> 6);
|
||||
width_ = value & 0x3f;
|
||||
if(!width_) width_ = 0x40;
|
||||
height_ = value >> 6;
|
||||
if(!height_) height_ = 1024;
|
||||
LOG("Set size to " << std::dec << width_ << ", " << height_);
|
||||
|
||||
// Current assumption: writing this register informs the
|
||||
// blitter that it should treat itself as about to start a new line.
|
||||
}
|
||||
|
||||
void Blitter::set_minterms(uint16_t value) {
|
||||
LOG("Set minterms " << PADHEX(4) << value);
|
||||
minterms_ = value & 0xff;
|
||||
}
|
||||
|
||||
//void Blitter::set_vertical_size([[maybe_unused]] uint16_t value) {
|
||||
// LOG("Set vertical size " << PADHEX(4) << value);
|
||||
// // TODO. This is ECS only, I think. Ditto set_horizontal_size.
|
||||
//}
|
||||
//
|
||||
//void Blitter::set_horizontal_size([[maybe_unused]] uint16_t value) {
|
||||
// LOG("Set horizontal size " << PADHEX(4) << value);
|
||||
//}
|
||||
|
||||
void Blitter::set_data(int channel, uint16_t value) {
|
||||
LOG("Set data " << channel << " to " << PADHEX(4) << value);
|
||||
|
||||
// Ugh, backed myself into a corner. TODO: clean.
|
||||
switch(channel) {
|
||||
case 0: a_data_ = value; break;
|
||||
case 1: b_data_ = value; break;
|
||||
case 2: c_data_ = value; break;
|
||||
default: break;
|
||||
}
|
||||
}
|
||||
|
||||
uint16_t Blitter::get_status() {
|
||||
const uint16_t result =
|
||||
(not_zero_flag_ ? 0x0000 : 0x2000) | (height_ ? 0x4000 : 0x0000);
|
||||
LOG("Returned status of " << result);
|
||||
return result;
|
||||
}
|
||||
|
||||
bool Blitter::advance_dma() {
|
||||
if(!height_) return false;
|
||||
|
||||
not_zero_flag_ = false;
|
||||
if(line_mode_) {
|
||||
// As-yet unimplemented:
|
||||
assert(b_data_ == 0xffff);
|
||||
|
||||
//
|
||||
// Line mode.
|
||||
//
|
||||
|
||||
// Bluffer's guide to line mode:
|
||||
//
|
||||
// In Bresenham terms, the following registers have been set up:
|
||||
//
|
||||
// [A modulo] = 4 * (dy - dx)
|
||||
// [B modulo] = 4 * dy
|
||||
// [A pointer] = 4 * dy - 2 * dx, with the sign flag in BLTCON1 indicating sign.
|
||||
//
|
||||
// [A data] = 0x8000
|
||||
// [Both masks] = 0xffff
|
||||
// [A shift] = x1 & 15
|
||||
//
|
||||
// [B data] = texture
|
||||
// [B shift] = bit at which to start the line texture (0 = LSB)
|
||||
//
|
||||
// [C and D pointers] = word containing the first pixel of the line
|
||||
// [C and D modulo] = width of the bitplane in bytes
|
||||
//
|
||||
// height = number of pixels
|
||||
//
|
||||
// If ONEDOT of BLTCON1 is set, plot only a single bit per horizontal row.
|
||||
//
|
||||
// BLTCON1 quadrants are (bits 2–4):
|
||||
//
|
||||
// 110 -> step in x, x positive, y negative
|
||||
// 111 -> step in x, x negative, y negative
|
||||
// 101 -> step in x, x negative, y positive
|
||||
// 100 -> step in x, x positive, y positive
|
||||
//
|
||||
// 001 -> step in y, x positive, y negative
|
||||
// 011 -> step in y, x negative, y negative
|
||||
// 010 -> step in y, x negative, y positive
|
||||
// 000 -> step in y, x positive, y positive
|
||||
//
|
||||
// So that's:
|
||||
//
|
||||
// * bit 4 = x [=1] or y [=0] major;
|
||||
// * bit 3 = 1 => major variable negative; otherwise positive;
|
||||
// * bit 2 = 1 => minor variable negative; otherwise positive.
|
||||
|
||||
//
|
||||
// Implementation below is heavily based on the documentation found
|
||||
// at https://github.com/niklasekstrom/blitter-subpixel-line/blob/master/Drawing%20lines%20using%20the%20Amiga%20blitter.pdf
|
||||
//
|
||||
|
||||
int error = int16_t(pointer_[0] << 1) >> 1; // TODO: what happens if line_sign_ doesn't agree with this?
|
||||
bool draw_ = true;
|
||||
while(height_--) {
|
||||
|
||||
if(draw_) {
|
||||
// TODO: patterned lines. Unclear what to do with the bit that comes out of b.
|
||||
// Probably extend it to a full word?
|
||||
c_data_ = ram_[pointer_[3] & ram_mask_];
|
||||
const uint16_t output =
|
||||
apply_minterm<uint16_t>(a_data_ >> shifts_[0], b_data_, c_data_, minterms_);
|
||||
ram_[pointer_[3] & ram_mask_] = output;
|
||||
not_zero_flag_ |= output;
|
||||
draw_ &= !one_dot_;
|
||||
}
|
||||
|
||||
constexpr int LEFT = 1 << 0;
|
||||
constexpr int RIGHT = 1 << 1;
|
||||
constexpr int UP = 1 << 2;
|
||||
constexpr int DOWN = 1 << 3;
|
||||
int step = (line_direction_ & 4) ?
|
||||
((line_direction_ & 1) ? LEFT : RIGHT) :
|
||||
((line_direction_ & 1) ? UP : DOWN);
|
||||
|
||||
if(error < 0) {
|
||||
error += modulos_[1];
|
||||
} else {
|
||||
step |=
|
||||
(line_direction_ & 4) ?
|
||||
((line_direction_ & 2) ? UP : DOWN) :
|
||||
((line_direction_ & 2) ? LEFT : RIGHT);
|
||||
|
||||
error += modulos_[0];
|
||||
}
|
||||
|
||||
if(step & LEFT) {
|
||||
--shifts_[0];
|
||||
if(shifts_[0] == -1) {
|
||||
--pointer_[3];
|
||||
}
|
||||
} else if(step & RIGHT) {
|
||||
++shifts_[0];
|
||||
if(shifts_[0] == 16) {
|
||||
++pointer_[3];
|
||||
}
|
||||
}
|
||||
shifts_[0] &= 15;
|
||||
|
||||
if(step & UP) {
|
||||
pointer_[3] -= modulos_[2];
|
||||
draw_ = true;
|
||||
} else if(step & DOWN) {
|
||||
pointer_[3] += modulos_[2];
|
||||
draw_ = true;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
// Copy mode.
|
||||
|
||||
// Quick hack: do the entire action atomically.
|
||||
a32_ = 0;
|
||||
b32_ = 0;
|
||||
|
||||
for(int y = 0; y < height_; y++) {
|
||||
bool fill_carry = fill_carry_;
|
||||
|
||||
for(int x = 0; x < width_; x++) {
|
||||
uint16_t a_mask = 0xffff;
|
||||
if(x == 0) a_mask &= a_mask_[0];
|
||||
if(x == width_ - 1) a_mask &= a_mask_[1];
|
||||
|
||||
if(channel_enables_[0]) {
|
||||
a_data_ = ram_[pointer_[0] & ram_mask_];
|
||||
pointer_[0] += direction_;
|
||||
}
|
||||
a32_ = (a32_ << 16) | (a_data_ & a_mask);
|
||||
|
||||
if(channel_enables_[1]) {
|
||||
b_data_ = ram_[pointer_[1] & ram_mask_];
|
||||
pointer_[1] += direction_;
|
||||
}
|
||||
b32_ = (b32_ << 16) | b_data_;
|
||||
|
||||
if(channel_enables_[2]) {
|
||||
c_data_ = ram_[pointer_[2] & ram_mask_];
|
||||
pointer_[2] += direction_;
|
||||
}
|
||||
|
||||
uint16_t a, b;
|
||||
|
||||
// The barrel shifter shifts to the right in ascending address mode,
|
||||
// but to the left otherwise
|
||||
if(!one_dot_) {
|
||||
a = uint16_t(a32_ >> shifts_[0]);
|
||||
b = uint16_t(b32_ >> shifts_[1]);
|
||||
} else {
|
||||
// TODO: there must be a neater solution than this.
|
||||
a = uint16_t(
|
||||
(a32_ << shifts_[0]) |
|
||||
(a32_ >> (32 - shifts_[0]))
|
||||
);
|
||||
|
||||
b = uint16_t(
|
||||
(b32_ << shifts_[1]) |
|
||||
(b32_ >> (32 - shifts_[1]))
|
||||
);
|
||||
}
|
||||
|
||||
uint16_t output =
|
||||
apply_minterm<uint16_t>(
|
||||
a,
|
||||
b,
|
||||
c_data_,
|
||||
minterms_);
|
||||
|
||||
if(exclusive_fill_ || inclusive_fill_) {
|
||||
// Use the fill tables nibble-by-nibble to figure out the filled word.
|
||||
uint16_t fill_output = 0;
|
||||
int ongoing_carry = fill_carry;
|
||||
const int type_mask = exclusive_fill_ ? (1 << 5) : 0;
|
||||
for(int c = 0; c < 16; c += 4) {
|
||||
const int total_index = (output & 0xf) | (ongoing_carry << 4) | type_mask;
|
||||
fill_output |= ((fill_values[total_index >> 3] >> ((total_index & 7) * 4)) & 0xf) << c;
|
||||
ongoing_carry = (fill_carries[total_index >> 5] >> (total_index & 31)) & 1;
|
||||
output >>= 4;
|
||||
}
|
||||
|
||||
output = fill_output;
|
||||
fill_carry = ongoing_carry;
|
||||
}
|
||||
|
||||
not_zero_flag_ |= output;
|
||||
|
||||
if(channel_enables_[3]) {
|
||||
ram_[pointer_[3] & ram_mask_] = output;
|
||||
pointer_[3] += direction_;
|
||||
}
|
||||
}
|
||||
|
||||
pointer_[0] += modulos_[0] * channel_enables_[0] * direction_;
|
||||
pointer_[1] += modulos_[1] * channel_enables_[1] * direction_;
|
||||
pointer_[2] += modulos_[2] * channel_enables_[2] * direction_;
|
||||
pointer_[3] += modulos_[3] * channel_enables_[3] * direction_;
|
||||
}
|
||||
}
|
||||
|
||||
posit_interrupt(InterruptFlag::Blitter);
|
||||
height_ = 0;
|
||||
|
||||
return true;
|
||||
}
|
||||
69
Machines/Amiga/Blitter.hpp
Normal file
69
Machines/Amiga/Blitter.hpp
Normal file
@@ -0,0 +1,69 @@
|
||||
//
|
||||
// Blitter.hpp
|
||||
// Clock Signal
|
||||
//
|
||||
// Created by Thomas Harte on 22/07/2021.
|
||||
// Copyright © 2021 Thomas Harte. All rights reserved.
|
||||
//
|
||||
|
||||
#ifndef Blitter_hpp
|
||||
#define Blitter_hpp
|
||||
|
||||
#include <cstddef>
|
||||
#include <cstdint>
|
||||
|
||||
#include "../../ClockReceiver/ClockReceiver.hpp"
|
||||
#include "DMADevice.hpp"
|
||||
|
||||
namespace Amiga {
|
||||
|
||||
class Blitter: public DMADevice<4, 4> {
|
||||
public:
|
||||
using DMADevice::DMADevice;
|
||||
|
||||
// Various setters; it's assumed that address decoding is handled externally.
|
||||
//
|
||||
// In all cases where a channel is identified numerically, it's taken that
|
||||
// 0 = A, 1 = B, 2 = C, 3 = D.
|
||||
void set_control(int index, uint16_t value);
|
||||
void set_first_word_mask(uint16_t value);
|
||||
void set_last_word_mask(uint16_t value);
|
||||
|
||||
void set_size(uint16_t value);
|
||||
void set_minterms(uint16_t value);
|
||||
// void set_vertical_size(uint16_t value);
|
||||
// void set_horizontal_size(uint16_t value);
|
||||
void set_data(int channel, uint16_t value);
|
||||
|
||||
uint16_t get_status();
|
||||
|
||||
bool advance_dma();
|
||||
|
||||
private:
|
||||
int width_ = 0, height_ = 0;
|
||||
int shifts_[2]{};
|
||||
uint16_t a_mask_[2] = {0xffff, 0xffff};
|
||||
|
||||
bool line_mode_ = false;
|
||||
bool one_dot_ = false;
|
||||
int line_direction_ = 0;
|
||||
int line_sign_ = 1;
|
||||
|
||||
uint32_t direction_ = 1;
|
||||
bool inclusive_fill_ = false;
|
||||
bool exclusive_fill_ = false;
|
||||
bool fill_carry_ = false;
|
||||
|
||||
bool channel_enables_[4]{};
|
||||
|
||||
uint8_t minterms_ = 0;
|
||||
uint32_t a32_ = 0, b32_ = 0;
|
||||
uint16_t a_data_ = 0, b_data_ = 0, c_data_ = 0;
|
||||
|
||||
bool not_zero_flag_ = false;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
|
||||
#endif /* Blitter_hpp */
|
||||
1255
Machines/Amiga/Chipset.cpp
Normal file
1255
Machines/Amiga/Chipset.cpp
Normal file
File diff suppressed because it is too large
Load Diff
366
Machines/Amiga/Chipset.hpp
Normal file
366
Machines/Amiga/Chipset.hpp
Normal file
@@ -0,0 +1,366 @@
|
||||
//
|
||||
// Chipset.hpp
|
||||
// Clock Signal
|
||||
//
|
||||
// Created by Thomas Harte on 22/07/2021.
|
||||
// Copyright © 2021 Thomas Harte. All rights reserved.
|
||||
//
|
||||
|
||||
#ifndef Chipset_hpp
|
||||
#define Chipset_hpp
|
||||
|
||||
#include <algorithm>
|
||||
#include <array>
|
||||
#include <cassert>
|
||||
#include <cstddef>
|
||||
#include <cstdint>
|
||||
|
||||
#include "../../Activity/Source.hpp"
|
||||
#include "../../ClockReceiver/ClockingHintSource.hpp"
|
||||
#include "../../ClockReceiver/JustInTime.hpp"
|
||||
#include "../../Components/6526/6526.hpp"
|
||||
#include "../../Outputs/CRT/CRT.hpp"
|
||||
#include "../../Processors/68000/68000.hpp"
|
||||
#include "../../Storage/Disk/Controller/DiskController.hpp"
|
||||
#include "../../Storage/Disk/Drive.hpp"
|
||||
|
||||
#include "Audio.hpp"
|
||||
#include "Bitplanes.hpp"
|
||||
#include "Blitter.hpp"
|
||||
#include "Copper.hpp"
|
||||
#include "DMADevice.hpp"
|
||||
#include "Flags.hpp"
|
||||
#include "Keyboard.hpp"
|
||||
#include "MouseJoystick.hpp"
|
||||
#include "MemoryMap.hpp"
|
||||
#include "Sprites.hpp"
|
||||
|
||||
namespace Amiga {
|
||||
|
||||
class Chipset: private ClockingHint::Observer {
|
||||
public:
|
||||
Chipset(MemoryMap &memory_map, int input_clock_rate);
|
||||
|
||||
struct Changes {
|
||||
int interrupt_level = 0;
|
||||
HalfCycles duration;
|
||||
|
||||
Changes &operator += (const Changes &rhs) {
|
||||
duration += rhs.duration;
|
||||
return *this;
|
||||
}
|
||||
};
|
||||
|
||||
/// Advances the stated amount of time.
|
||||
Changes run_for(HalfCycles);
|
||||
|
||||
/// Advances to the end of the next available CPU slot.
|
||||
Changes run_until_after_cpu_slot();
|
||||
|
||||
/// Performs the provided microcycle, which the caller guarantees to be a memory access.
|
||||
void perform(const CPU::MC68000::Microcycle &);
|
||||
|
||||
/// Sets the current state of the CIA interrupt lines.
|
||||
void set_cia_interrupts(bool cia_a, bool cia_b);
|
||||
|
||||
/// Provides the chipset's current interrupt level.
|
||||
int get_interrupt_level() {
|
||||
return interrupt_level_;
|
||||
}
|
||||
|
||||
/// Inserts the disks provided.
|
||||
/// @returns @c true if anything was inserted; @c false otherwise.
|
||||
bool insert(const std::vector<std::shared_ptr<Storage::Disk::Disk>> &disks);
|
||||
|
||||
// The standard CRT set.
|
||||
void set_scan_target(Outputs::Display::ScanTarget *scan_target);
|
||||
Outputs::Display::ScanStatus get_scaled_scan_status() const;
|
||||
void set_display_type(Outputs::Display::DisplayType);
|
||||
Outputs::Display::DisplayType get_display_type() const;
|
||||
|
||||
// Activity observation.
|
||||
void set_activity_observer(Activity::Observer *observer) {
|
||||
cia_a_handler_.set_activity_observer(observer);
|
||||
disk_controller_.set_activity_observer(observer);
|
||||
}
|
||||
|
||||
// Keyboard and mouse exposure.
|
||||
Keyboard &get_keyboard() {
|
||||
return keyboard_;
|
||||
}
|
||||
|
||||
const std::vector<std::unique_ptr<Inputs::Joystick>> &get_joysticks() {
|
||||
return joysticks_;
|
||||
}
|
||||
|
||||
// Synchronisation.
|
||||
void flush();
|
||||
|
||||
// Input for receiving collected bitplanes.
|
||||
void post_bitplanes(const BitplaneData &data);
|
||||
|
||||
// Obtains the source of audio output.
|
||||
Outputs::Speaker::Speaker *get_speaker() {
|
||||
return audio_.get_speaker();
|
||||
}
|
||||
|
||||
private:
|
||||
friend class DMADeviceBase;
|
||||
|
||||
// MARK: - Register read/write functions.
|
||||
uint16_t read(uint32_t address, bool allow_conversion = true);
|
||||
void write(uint32_t address, uint16_t value, bool allow_conversion = true);
|
||||
static constexpr uint32_t ChipsetAddressMask = 0x1fe;
|
||||
friend class Copper;
|
||||
|
||||
// MARK: - E Clock and keyboard dividers.
|
||||
|
||||
HalfCycles cia_divider_;
|
||||
HalfCycles keyboard_divider_;
|
||||
|
||||
// MARK: - Interrupts.
|
||||
|
||||
uint16_t interrupt_enable_ = 0;
|
||||
uint16_t interrupt_requests_ = 0;
|
||||
int interrupt_level_ = 0;
|
||||
|
||||
void update_interrupts();
|
||||
void posit_interrupt(InterruptFlag);
|
||||
|
||||
// MARK: - Scheduler.
|
||||
|
||||
template <bool stop_on_cpu> Changes run(HalfCycles duration = HalfCycles::max());
|
||||
template <bool stop_on_cpu> int advance_slots(int, int);
|
||||
template <int cycle, bool stop_if_cpu> bool perform_cycle();
|
||||
template <int cycle> void output();
|
||||
void output_pixels(int cycles_until_sync);
|
||||
void apply_ham(uint8_t);
|
||||
|
||||
// MARK: - DMA Control, Scheduler and Blitter.
|
||||
|
||||
uint16_t dma_control_ = 0;
|
||||
Blitter blitter_;
|
||||
|
||||
// MARK: - Sprites and collision flags.
|
||||
|
||||
std::array<Sprite, 8> sprites_;
|
||||
std::array<TwoSpriteShifter, 4> sprite_shifters_;
|
||||
uint16_t collisions_ = 0, collisions_flags_= 0;
|
||||
|
||||
uint32_t playfield_collision_mask_ = 0, playfield_collision_complement_ = 0;
|
||||
|
||||
// MARK: - Raster position and state.
|
||||
|
||||
// Definitions related to PAL/NTSC.
|
||||
// (Default values are PAL).
|
||||
int line_length_ = 227;
|
||||
int short_field_height_ = 312;
|
||||
int vertical_blank_height_ = 25; // PAL = 25, NTSC = 20
|
||||
|
||||
// Current raster position.
|
||||
int line_cycle_ = 0, y_ = 0;
|
||||
|
||||
// Parameters affecting bitplane collection and output.
|
||||
uint16_t display_window_start_[2] = {0, 0};
|
||||
uint16_t display_window_stop_[2] = {0, 0};
|
||||
uint16_t fetch_window_[2] = {0, 0};
|
||||
|
||||
// Ephemeral bitplane collection state.
|
||||
bool fetch_vertical_ = false, fetch_horizontal_ = false;
|
||||
bool display_horizontal_ = false;
|
||||
bool did_fetch_ = false;
|
||||
uint16_t fetch_stop_ = 0xffff;
|
||||
|
||||
// Output state.
|
||||
uint16_t border_colour_ = 0;
|
||||
bool is_border_ = true;
|
||||
int zone_duration_ = 0;
|
||||
uint16_t *pixels_ = nullptr;
|
||||
uint16_t last_colour_ = 0; // Retained for HAM mode.
|
||||
void flush_output();
|
||||
|
||||
Bitplanes bitplanes_;
|
||||
|
||||
BitplaneData next_bitplanes_, previous_bitplanes_;
|
||||
bool has_next_bitplanes_ = false;
|
||||
|
||||
int odd_priority_ = 0, even_priority_ = 0;
|
||||
bool even_over_odd_ = false;
|
||||
bool hold_and_modify_ = false;
|
||||
bool dual_playfields_ = false;
|
||||
bool interlace_ = false;
|
||||
bool is_long_field_ = false;
|
||||
|
||||
BitplaneShifter bitplane_pixels_;
|
||||
|
||||
int odd_delay_ = 0, even_delay_ = 0;
|
||||
bool is_high_res_ = false;
|
||||
|
||||
// MARK: - Copper.
|
||||
|
||||
Copper copper_;
|
||||
|
||||
// MARK: - Audio.
|
||||
|
||||
Audio audio_;
|
||||
|
||||
// MARK: - Serial port.
|
||||
|
||||
class SerialPort {
|
||||
public:
|
||||
void set_control(uint16_t) {}
|
||||
|
||||
private:
|
||||
uint16_t value = 0, reload = 0;
|
||||
uint16_t shift = 0, receive_shift = 0;
|
||||
uint16_t status;
|
||||
} serial_;
|
||||
|
||||
// MARK: - Pixel output.
|
||||
|
||||
Outputs::CRT::CRT crt_;
|
||||
uint16_t palette_[32]{};
|
||||
uint16_t swizzled_palette_[64]{};
|
||||
|
||||
// MARK: - Mouse.
|
||||
private:
|
||||
Mouse mouse_;
|
||||
|
||||
public:
|
||||
Inputs::Mouse &get_mouse() {
|
||||
return mouse_;
|
||||
}
|
||||
|
||||
// MARK: - Joystick.
|
||||
private:
|
||||
std::vector<std::unique_ptr<Inputs::Joystick>> joysticks_;
|
||||
Joystick &joystick(size_t index) const {
|
||||
return *static_cast<Joystick *>(joysticks_[index].get());
|
||||
}
|
||||
|
||||
// MARK: - CIAs.
|
||||
private:
|
||||
class DiskController;
|
||||
|
||||
class CIAAHandler: public MOS::MOS6526::PortHandler {
|
||||
public:
|
||||
CIAAHandler(MemoryMap &map, DiskController &controller, Mouse &mouse);
|
||||
void set_port_output(MOS::MOS6526::Port port, uint8_t value);
|
||||
uint8_t get_port_input(MOS::MOS6526::Port port);
|
||||
void set_activity_observer(Activity::Observer *observer);
|
||||
|
||||
// TEMPORARY.
|
||||
// TODO: generalise mice and joysticks.
|
||||
// This is a hack. A TEMPORARY HACK.
|
||||
void set_joystick(Joystick *joystick) {
|
||||
joystick_ = joystick;
|
||||
}
|
||||
|
||||
private:
|
||||
MemoryMap &map_;
|
||||
DiskController &controller_;
|
||||
Mouse &mouse_;
|
||||
Joystick *joystick_ = nullptr;
|
||||
Activity::Observer *observer_ = nullptr;
|
||||
inline static const std::string led_name = "Power";
|
||||
} cia_a_handler_;
|
||||
|
||||
class CIABHandler: public MOS::MOS6526::PortHandler {
|
||||
public:
|
||||
CIABHandler(DiskController &controller);
|
||||
void set_port_output(MOS::MOS6526::Port port, uint8_t value);
|
||||
uint8_t get_port_input(MOS::MOS6526::Port);
|
||||
|
||||
private:
|
||||
DiskController &controller_;
|
||||
} cia_b_handler_;
|
||||
|
||||
public:
|
||||
using CIAA = MOS::MOS6526::MOS6526<CIAAHandler, MOS::MOS6526::Personality::P8250>;
|
||||
using CIAB = MOS::MOS6526::MOS6526<CIABHandler, MOS::MOS6526::Personality::P8250>;
|
||||
|
||||
// CIAs are provided for direct access; it's up to the caller properly
|
||||
// to distinguish relevant accesses.
|
||||
CIAA cia_a;
|
||||
CIAB cia_b;
|
||||
|
||||
private:
|
||||
// MARK: - Disk drives.
|
||||
|
||||
class DiskDMA: public DMADevice<1> {
|
||||
public:
|
||||
using DMADevice::DMADevice;
|
||||
|
||||
void set_length(uint16_t);
|
||||
void set_control(uint16_t);
|
||||
bool advance_dma();
|
||||
|
||||
void enqueue(uint16_t value, bool matches_sync);
|
||||
|
||||
private:
|
||||
uint16_t length_;
|
||||
bool dma_enable_ = false;
|
||||
bool write_ = false;
|
||||
uint16_t last_set_length_ = 0;
|
||||
bool sync_with_word_ = false;
|
||||
|
||||
std::array<uint16_t, 4> buffer_;
|
||||
size_t buffer_read_ = 0, buffer_write_ = 0;
|
||||
|
||||
enum class State {
|
||||
Inactive,
|
||||
WaitingForSync,
|
||||
Reading,
|
||||
} state_ = State::Inactive;
|
||||
} disk_;
|
||||
|
||||
class DiskController: public Storage::Disk::Controller {
|
||||
public:
|
||||
DiskController(Cycles clock_rate, Chipset &chipset, DiskDMA &disk_dma, CIAB &cia);
|
||||
|
||||
void set_mtr_sel_side_dir_step(uint8_t);
|
||||
uint8_t get_rdy_trk0_wpro_chng();
|
||||
|
||||
void run_for(Cycles duration) {
|
||||
Storage::Disk::Controller::run_for(duration);
|
||||
}
|
||||
|
||||
bool insert(const std::shared_ptr<Storage::Disk::Disk> &disk, size_t drive);
|
||||
void set_activity_observer(Activity::Observer *);
|
||||
|
||||
void set_sync_word(uint16_t);
|
||||
void set_control(uint16_t);
|
||||
|
||||
private:
|
||||
void process_input_bit(int value) final;
|
||||
void process_index_hole() final;
|
||||
|
||||
// Implement the Amiga's drive ID shift registers
|
||||
// directly in the controller for now.
|
||||
uint32_t drive_ids_[4]{};
|
||||
uint32_t previous_select_ = 0;
|
||||
|
||||
uint16_t data_ = 0;
|
||||
int bit_count_ = 0;
|
||||
uint16_t sync_word_ = 0x4489; // TODO: confirm or deny guess.
|
||||
bool sync_with_word_ = false;
|
||||
|
||||
Chipset &chipset_;
|
||||
DiskDMA &disk_dma_;
|
||||
CIAB &cia_;
|
||||
|
||||
} disk_controller_;
|
||||
friend DiskController;
|
||||
|
||||
void set_component_prefers_clocking(ClockingHint::Source *, ClockingHint::Preference) final;
|
||||
bool disk_controller_is_sleeping_ = false;
|
||||
uint16_t paula_disk_control_ = 0;
|
||||
|
||||
// MARK: - Keyboard.
|
||||
|
||||
Keyboard keyboard_;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif /* Chipset_hpp */
|
||||
145
Machines/Amiga/Copper.cpp
Normal file
145
Machines/Amiga/Copper.cpp
Normal file
@@ -0,0 +1,145 @@
|
||||
//
|
||||
// Copper.cpp
|
||||
// Clock Signal
|
||||
//
|
||||
// Created by Thomas Harte on 16/09/2021.
|
||||
// Copyright © 2021 Thomas Harte. All rights reserved.
|
||||
//
|
||||
|
||||
#ifndef NDEBUG
|
||||
#define NDEBUG
|
||||
#endif
|
||||
|
||||
#define LOG_PREFIX "[Copper] "
|
||||
#include "../../Outputs/Log.hpp"
|
||||
|
||||
#include "Chipset.hpp"
|
||||
#include "Copper.hpp"
|
||||
|
||||
using namespace Amiga;
|
||||
|
||||
namespace {
|
||||
|
||||
bool satisfies_raster(uint16_t position, uint16_t blitter_status, uint16_t *instruction) {
|
||||
const uint16_t mask = 0x8000 | (instruction[1] & 0x7ffe);
|
||||
return
|
||||
(position & mask) >= (instruction[0] & mask) &&
|
||||
(!(blitter_status & 0x4000) || (instruction[1] & 0x8000));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
//
|
||||
// Quick notes on the Copper:
|
||||
//
|
||||
// There are three instructions: move, wait and skip. All are two words in length.
|
||||
//
|
||||
// Move writes a value to one of the Chipset registers; it is encoded as:
|
||||
//
|
||||
// First word:
|
||||
// b0: 0
|
||||
// b1–b8: register address
|
||||
// b9+: unused ("should be set to 0")
|
||||
//
|
||||
// Second word:
|
||||
// b0–b15: value to move.
|
||||
//
|
||||
//
|
||||
// Wait waits until the raster gets to at least a certain position, and
|
||||
// optionally until the Blitter has finished. It is encoded as:
|
||||
//
|
||||
// First word:
|
||||
// b0: 1
|
||||
// b1–b7: horizontal beam position
|
||||
// b8+: vertical beam position
|
||||
//
|
||||
// Second word:
|
||||
// b0: 0
|
||||
// b1–b7: horizontal beam comparison mask
|
||||
// b8–b14: vertical beam comparison mask
|
||||
// b15: 1 => don't also wait for the Blitter to be finished; 0 => wait.
|
||||
//
|
||||
//
|
||||
// Skip skips the next instruction if the raster has already reached a certain
|
||||
// position, and optionally only if the Blitter has finished, and only if the
|
||||
// next instruction is a move.
|
||||
//
|
||||
// First word:
|
||||
// b0: 1
|
||||
// b1–b7: horizontal beam position
|
||||
// b8+: vertical beam position
|
||||
//
|
||||
// Second word:
|
||||
// b0: 1
|
||||
// b1–b7: horizontal beam comparison mask
|
||||
// b8–b14: vertical beam comparison mask
|
||||
// b15: 1 => don't also test whether the Blitter is finished; 0 => test.
|
||||
//
|
||||
bool Copper::advance_dma(uint16_t position, uint16_t blitter_status) {
|
||||
switch(state_) {
|
||||
default: return false;
|
||||
|
||||
case State::Waiting:
|
||||
if(satisfies_raster(position, blitter_status, instruction_)) {
|
||||
LOG("Unblocked waiting for " << PADHEX(4) << instruction_[0] << " at " << PADHEX(4) << position << " with mask " << PADHEX(4) << (instruction_[1] & 0x7ffe));
|
||||
state_ = State::FetchFirstWord;
|
||||
}
|
||||
return false;
|
||||
|
||||
case State::FetchFirstWord:
|
||||
instruction_[0] = ram_[address_ & ram_mask_];
|
||||
++address_;
|
||||
state_ = State::FetchSecondWord;
|
||||
LOG("First word fetch at " << PADHEX(4) << position);
|
||||
break;
|
||||
|
||||
case State::FetchSecondWord: {
|
||||
// Get and reset the should-skip-next flag.
|
||||
const bool should_skip_move = skip_next_;
|
||||
skip_next_ = false;
|
||||
|
||||
// Read in the second instruction word.
|
||||
instruction_[1] = ram_[address_ & ram_mask_];
|
||||
++address_;
|
||||
LOG("Second word fetch at " << PADHEX(4) << position);
|
||||
|
||||
// Check for a MOVE.
|
||||
if(!(instruction_[0] & 1)) {
|
||||
if(!should_skip_move) {
|
||||
// Stop if this move would be a privilege violation.
|
||||
instruction_[0] &= 0x1fe;
|
||||
if((instruction_[0] < 0x10) || (instruction_[0] < 0x20 && !(control_&1))) {
|
||||
LOG("Invalid MOVE to " << PADHEX(4) << instruction_[0] << "; stopping");
|
||||
state_ = State::Stopped;
|
||||
break;
|
||||
}
|
||||
|
||||
chipset_.write(instruction_[0], instruction_[1]);
|
||||
}
|
||||
|
||||
// Roll onto the next command.
|
||||
state_ = State::FetchFirstWord;
|
||||
break;
|
||||
}
|
||||
|
||||
// Got to here => this is a WAIT or a SKIP.
|
||||
|
||||
const bool raster_is_satisfied = satisfies_raster(position, blitter_status, instruction_);
|
||||
|
||||
if(!(instruction_[1] & 1)) {
|
||||
// A WAIT. Empirically, I don't think this waits at all if the test is
|
||||
// already satisfied.
|
||||
state_ = raster_is_satisfied ? State::FetchFirstWord : State::Waiting;
|
||||
if(raster_is_satisfied) LOG("Will wait from " << PADHEX(4) << position);
|
||||
break;
|
||||
}
|
||||
|
||||
// Neither a WAIT nor a MOVE => a SKIP.
|
||||
|
||||
skip_next_ = satisfies_raster(position, blitter_status, instruction_);
|
||||
state_ = State::FetchFirstWord;
|
||||
} break;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
54
Machines/Amiga/Copper.hpp
Normal file
54
Machines/Amiga/Copper.hpp
Normal file
@@ -0,0 +1,54 @@
|
||||
//
|
||||
// Copper.hpp
|
||||
// Clock Signal
|
||||
//
|
||||
// Created by Thomas Harte on 16/09/2021.
|
||||
// Copyright © 2021 Thomas Harte. All rights reserved.
|
||||
//
|
||||
|
||||
#ifndef Copper_h
|
||||
#define Copper_h
|
||||
|
||||
#include "DMADevice.hpp"
|
||||
|
||||
namespace Amiga {
|
||||
|
||||
class Copper: public DMADevice<2> {
|
||||
public:
|
||||
using DMADevice<2>::DMADevice;
|
||||
|
||||
/// Offers a DMA slot to the Copper, specifying the current beam position and Blitter status.
|
||||
///
|
||||
/// @returns @c true if the slot was used; @c false otherwise.
|
||||
bool advance_dma(uint16_t position, uint16_t blitter_status);
|
||||
|
||||
/// Forces a reload of address @c id (i.e. 0 or 1) and restarts the Copper.
|
||||
template <int id> void reload() {
|
||||
address_ = pointer_[id];
|
||||
state_ = State::FetchFirstWord;
|
||||
}
|
||||
|
||||
/// Sets the Copper control word.
|
||||
void set_control(uint16_t c) {
|
||||
control_ = c;
|
||||
}
|
||||
|
||||
/// Forces the Copper into the stopped state.
|
||||
void stop() {
|
||||
state_ = State::Stopped;
|
||||
}
|
||||
|
||||
private:
|
||||
uint32_t address_ = 0;
|
||||
uint16_t control_ = 0;
|
||||
|
||||
enum class State {
|
||||
FetchFirstWord, FetchSecondWord, Waiting, Stopped,
|
||||
} state_ = State::Stopped;
|
||||
bool skip_next_ = false;
|
||||
uint16_t instruction_[2]{};
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif /* Copper_h */
|
||||
74
Machines/Amiga/DMADevice.hpp
Normal file
74
Machines/Amiga/DMADevice.hpp
Normal file
@@ -0,0 +1,74 @@
|
||||
//
|
||||
// DMADevice.hpp
|
||||
// Clock Signal
|
||||
//
|
||||
// Created by Thomas Harte on 14/09/2021.
|
||||
// Copyright © 2021 Thomas Harte. All rights reserved.
|
||||
//
|
||||
|
||||
#ifndef DMADevice_hpp
|
||||
#define DMADevice_hpp
|
||||
|
||||
#include <array>
|
||||
#include <cstddef>
|
||||
#include <cstdint>
|
||||
|
||||
#include "Flags.hpp"
|
||||
|
||||
namespace Amiga {
|
||||
|
||||
class Chipset;
|
||||
|
||||
class DMADeviceBase {
|
||||
public:
|
||||
DMADeviceBase(Chipset &chipset, uint16_t *ram, size_t word_size) :
|
||||
chipset_(chipset), ram_(ram), ram_mask_(uint32_t(word_size - 1)) {}
|
||||
|
||||
void posit_interrupt(Amiga::InterruptFlag);
|
||||
|
||||
protected:
|
||||
Chipset &chipset_;
|
||||
uint16_t *const ram_ = nullptr;
|
||||
const uint32_t ram_mask_ = 0;
|
||||
};
|
||||
|
||||
template <size_t num_addresses, size_t num_modulos = 0> class DMADevice: public DMADeviceBase {
|
||||
public:
|
||||
using DMADeviceBase::DMADeviceBase;
|
||||
|
||||
/// Writes the word @c value to the address register @c id, shifting it by @c shift (0 or 16) first.
|
||||
template <int id, int shift> void set_pointer(uint16_t value) {
|
||||
static_assert(id < num_addresses);
|
||||
static_assert(shift == 0 || shift == 16);
|
||||
|
||||
byte_pointer_[id] = (byte_pointer_[id] & (0xffff'0000 >> shift)) | uint32_t(value << shift);
|
||||
pointer_[id] = byte_pointer_[id] >> 1;
|
||||
}
|
||||
|
||||
/// Writes the word @c value to the modulo register @c id, shifting it by @c shift (0 or 16) first.
|
||||
template <int id> void set_modulo(uint16_t value) {
|
||||
static_assert(id < num_modulos);
|
||||
|
||||
// Convert by sign extension.
|
||||
modulos_[id] = uint32_t(int16_t(value) >> 1);
|
||||
}
|
||||
|
||||
template <int id, int shift> uint16_t get_pointer() {
|
||||
// Restore the original least-significant bit.
|
||||
const uint32_t source = (pointer_[id] << 1) | (byte_pointer_[id] & 1);
|
||||
return uint16_t(source >> shift);
|
||||
}
|
||||
|
||||
protected:
|
||||
// These are shifted right one to provide word-indexing pointers;
|
||||
// subclasses should use e.g. ram_[pointer_[0] & ram_mask_] directly.
|
||||
std::array<uint32_t, num_addresses> pointer_{};
|
||||
std::array<uint32_t, num_modulos> modulos_{};
|
||||
|
||||
private:
|
||||
std::array<uint32_t, num_addresses> byte_pointer_{};
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif /* DMADevice_hpp */
|
||||
259
Machines/Amiga/Disk.cpp
Normal file
259
Machines/Amiga/Disk.cpp
Normal file
@@ -0,0 +1,259 @@
|
||||
//
|
||||
// Disk.cpp
|
||||
// Clock Signal
|
||||
//
|
||||
// Created by Thomas Harte on 02/11/2021.
|
||||
// Copyright © 2021 Thomas Harte. All rights reserved.
|
||||
//
|
||||
|
||||
#include "Chipset.hpp"
|
||||
|
||||
#define LOG_PREFIX "[Disk] "
|
||||
#include "../../Outputs/Log.hpp"
|
||||
|
||||
using namespace Amiga;
|
||||
|
||||
// MARK: - Disk DMA.
|
||||
|
||||
void Chipset::DiskDMA::enqueue(uint16_t value, bool matches_sync) {
|
||||
if(matches_sync && state_ == State::WaitingForSync) {
|
||||
state_ = State::Reading;
|
||||
return;
|
||||
}
|
||||
|
||||
if(state_ == State::Reading) {
|
||||
buffer_[buffer_write_ & 3] = value;
|
||||
if(buffer_write_ == buffer_read_ + 4) {
|
||||
++buffer_read_;
|
||||
}
|
||||
++buffer_write_;
|
||||
}
|
||||
}
|
||||
|
||||
void Chipset::DiskDMA::set_control(uint16_t control) {
|
||||
sync_with_word_ = control & 0x400;
|
||||
}
|
||||
|
||||
void Chipset::DiskDMA::set_length(uint16_t value) {
|
||||
if(value == last_set_length_) {
|
||||
dma_enable_ = value & 0x8000;
|
||||
write_ = value & 0x4000;
|
||||
length_ = value & 0x3fff;
|
||||
buffer_read_ = buffer_write_ = 0;
|
||||
|
||||
if(dma_enable_) {
|
||||
LOG("Disk DMA " << (write_ ? "write" : "read") << " of " << length_ << " to " << PADHEX(8) << pointer_[0]);
|
||||
}
|
||||
|
||||
state_ = sync_with_word_ ? State::WaitingForSync : State::Reading;
|
||||
}
|
||||
|
||||
last_set_length_ = value;
|
||||
}
|
||||
|
||||
bool Chipset::DiskDMA::advance_dma() {
|
||||
if(!dma_enable_) return false;
|
||||
|
||||
if(!write_) {
|
||||
if(length_ && buffer_read_ != buffer_write_) {
|
||||
ram_[pointer_[0] & ram_mask_] = buffer_[buffer_read_ & 3];
|
||||
++pointer_[0];
|
||||
++buffer_read_;
|
||||
--length_;
|
||||
|
||||
if(!length_) {
|
||||
chipset_.posit_interrupt(InterruptFlag::DiskBlock);
|
||||
state_ = State::Inactive;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
// MARK: - Disk Controller.
|
||||
|
||||
Chipset::DiskController::DiskController(Cycles clock_rate, Chipset &chipset, DiskDMA &disk_dma, CIAB &cia) :
|
||||
Storage::Disk::Controller(clock_rate),
|
||||
chipset_(chipset),
|
||||
disk_dma_(disk_dma),
|
||||
cia_(cia) {
|
||||
|
||||
// Add four drives.
|
||||
for(int c = 0; c < 4; c++) {
|
||||
emplace_drive(clock_rate.as<int>(), 300, 2, Storage::Disk::Drive::ReadyType::IBMRDY);
|
||||
}
|
||||
}
|
||||
|
||||
void Chipset::DiskController::process_input_bit(int value) {
|
||||
data_ = uint16_t((data_ << 1) | value);
|
||||
++bit_count_;
|
||||
|
||||
const bool sync_matches = data_ == sync_word_;
|
||||
if(sync_matches) {
|
||||
chipset_.posit_interrupt(InterruptFlag::DiskSyncMatch);
|
||||
|
||||
if(sync_with_word_) {
|
||||
bit_count_ = 0;
|
||||
}
|
||||
}
|
||||
|
||||
if(!(bit_count_ & 15)) {
|
||||
disk_dma_.enqueue(data_, sync_matches);
|
||||
}
|
||||
}
|
||||
|
||||
void Chipset::DiskController::set_sync_word(uint16_t value) {
|
||||
LOG("Set disk sync word to " << PADHEX(4) << value);
|
||||
sync_word_ = value;
|
||||
}
|
||||
|
||||
void Chipset::DiskController::set_control(uint16_t control) {
|
||||
// b13 and b14: precompensation length specifier
|
||||
// b12: 0 => GCR precompensation; 1 => MFM.
|
||||
// b10: 1 => enable use of word sync; 0 => disable.
|
||||
// b9: 1 => sync on MSB (Disk II style, presumably?); 0 => don't.
|
||||
// b8: 1 => 2µs per bit; 0 => 4µs.
|
||||
|
||||
sync_with_word_ = control & 0x400;
|
||||
|
||||
Storage::Time bit_length;
|
||||
bit_length.length = 1;
|
||||
bit_length.clock_rate = (control & 0x100) ? 500000 : 250000;
|
||||
set_expected_bit_length(bit_length);
|
||||
|
||||
LOG((sync_with_word_ ? "Will" : "Won't") << " sync with word; bit length is " << ((control & 0x100) ? "short" : "long"));
|
||||
}
|
||||
|
||||
void Chipset::DiskController::process_index_hole() {
|
||||
// Pulse the CIA flag input.
|
||||
//
|
||||
// TODO: rectify once drives do an actual index pulse, with length.
|
||||
cia_.set_flag_input(true);
|
||||
cia_.set_flag_input(false);
|
||||
|
||||
// Resync word output. Experimental!!
|
||||
bit_count_ = 0;
|
||||
}
|
||||
|
||||
void Chipset::DiskController::set_mtr_sel_side_dir_step(uint8_t value) {
|
||||
// b7: /MTR
|
||||
// b6: /SEL3
|
||||
// b5: /SEL2
|
||||
// b4: /SEL1
|
||||
// b3: /SEL0
|
||||
// b2: /SIDE
|
||||
// b1: DIR
|
||||
// b0: /STEP
|
||||
|
||||
// Select active drive.
|
||||
set_drive(((value >> 3) & 0x0f) ^ 0x0f);
|
||||
|
||||
// "[The MTR] signal is nonstandard on the Amiga system.
|
||||
// Each drive will latch the motor signal at the time its
|
||||
// select signal turns on." — The Hardware Reference Manual.
|
||||
const auto difference = int(previous_select_ ^ value);
|
||||
previous_select_ = value;
|
||||
|
||||
// Check for changes in the SEL line per drive.
|
||||
const bool motor_on = !(value & 0x80);
|
||||
const int side = (value & 0x04) ? 0 : 1;
|
||||
const bool did_step = difference & value & 0x01;
|
||||
const auto direction = Storage::Disk::HeadPosition(
|
||||
(value & 0x02) ? -1 : 1
|
||||
);
|
||||
|
||||
for(int c = 0; c < 4; c++) {
|
||||
auto &drive = get_drive(size_t(c));
|
||||
const int select_mask = 0x08 << c;
|
||||
const bool is_selected = !(value & select_mask);
|
||||
|
||||
// Both the motor state and the ID shifter are affected upon
|
||||
// changes in drive selection only.
|
||||
if(difference & select_mask) {
|
||||
// If transitioning to inactive, shift the drive ID value;
|
||||
// if transitioning to active, possibly reset the drive
|
||||
// ID and definitely latch the new motor state.
|
||||
if(!is_selected) {
|
||||
drive_ids_[c] <<= 1;
|
||||
LOG("Shifted drive ID shift register for drive " << +c << " to " << PADHEX(4) << std::bitset<16>{drive_ids_[c]});
|
||||
} else {
|
||||
// Motor transition on -> off => reload register.
|
||||
if(!motor_on && drive.get_motor_on()) {
|
||||
// NB:
|
||||
// 0xffff'ffff = 3.5" drive;
|
||||
// 0x5555'5555 = 5.25" drive;
|
||||
// 0x0000'0000 = no drive.
|
||||
drive_ids_[c] = 0xffff'ffff;
|
||||
LOG("Reloaded drive ID shift register for drive " << +c);
|
||||
}
|
||||
|
||||
// Also latch the new motor state.
|
||||
drive.set_motor_on(motor_on);
|
||||
}
|
||||
}
|
||||
|
||||
// Set the new side.
|
||||
drive.set_head(side);
|
||||
|
||||
// Possibly step.
|
||||
if(did_step && is_selected) {
|
||||
LOG("Stepped drive " << +c << " by " << std::dec << +direction.as_int());
|
||||
drive.step(direction);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
uint8_t Chipset::DiskController::get_rdy_trk0_wpro_chng() {
|
||||
// b5: /RDY
|
||||
// b4: /TRK0
|
||||
// b3: /WPRO
|
||||
// b2: /CHNG
|
||||
|
||||
// My interpretation:
|
||||
//
|
||||
// RDY isn't RDY, it's a shift value as described above, combined with the motor state.
|
||||
// CHNG is what is normally RDY.
|
||||
|
||||
const uint32_t combined_id =
|
||||
((previous_select_ & 0x40) ? 0 : drive_ids_[3]) |
|
||||
((previous_select_ & 0x20) ? 0 : drive_ids_[2]) |
|
||||
((previous_select_ & 0x10) ? 0 : drive_ids_[1]) |
|
||||
((previous_select_ & 0x08) ? 0 : drive_ids_[0]);
|
||||
|
||||
auto &drive = get_drive();
|
||||
const uint8_t active_high =
|
||||
((combined_id & 0x8000) >> 10) |
|
||||
(drive.get_motor_on() ? 0x20 : 0x00) |
|
||||
(drive.get_is_ready() ? 0x00 : 0x04) |
|
||||
(drive.get_is_track_zero() ? 0x10 : 0x00) |
|
||||
(drive.get_is_read_only() ? 0x08 : 0x00);
|
||||
|
||||
return ~active_high;
|
||||
}
|
||||
|
||||
void Chipset::DiskController::set_activity_observer(Activity::Observer *observer) {
|
||||
for_all_drives([observer] (Storage::Disk::Drive &drive, size_t index) {
|
||||
drive.set_activity_observer(observer, "Drive " + std::to_string(index+1), true);
|
||||
});
|
||||
}
|
||||
|
||||
bool Chipset::DiskController::insert(const std::shared_ptr<Storage::Disk::Disk> &disk, size_t drive) {
|
||||
if(drive >= 4) return false;
|
||||
get_drive(drive).set_disk(disk);
|
||||
return true;
|
||||
}
|
||||
|
||||
bool Chipset::insert(const std::vector<std::shared_ptr<Storage::Disk::Disk>> &disks) {
|
||||
bool inserted = false;
|
||||
|
||||
size_t target = 0;
|
||||
for(const auto &disk: disks) {
|
||||
inserted |= disk_controller_.insert(disk, target);
|
||||
++target;
|
||||
}
|
||||
|
||||
return inserted;
|
||||
}
|
||||
49
Machines/Amiga/Flags.hpp
Normal file
49
Machines/Amiga/Flags.hpp
Normal file
@@ -0,0 +1,49 @@
|
||||
//
|
||||
// Flags.hpp
|
||||
// Clock Signal
|
||||
//
|
||||
// Created by Thomas Harte on 13/10/2021.
|
||||
// Copyright © 2021 Thomas Harte. All rights reserved.
|
||||
//
|
||||
|
||||
#ifndef Flags_hpp
|
||||
#define Flags_hpp
|
||||
|
||||
namespace Amiga {
|
||||
|
||||
enum class InterruptFlag: uint16_t {
|
||||
SerialPortTransmit = 1 << 0,
|
||||
DiskBlock = 1 << 1,
|
||||
Software = 1 << 2,
|
||||
IOPortsAndTimers = 1 << 3, // i.e. CIA A.
|
||||
Copper = 1 << 4,
|
||||
VerticalBlank = 1 << 5,
|
||||
Blitter = 1 << 6,
|
||||
AudioChannel0 = 1 << 7,
|
||||
AudioChannel1 = 1 << 8,
|
||||
AudioChannel2 = 1 << 9,
|
||||
AudioChannel3 = 1 << 10,
|
||||
SerialPortReceive = 1 << 11,
|
||||
DiskSyncMatch = 1 << 12,
|
||||
External = 1 << 13, // i.e. CIA B.
|
||||
};
|
||||
|
||||
enum class DMAFlag: uint16_t {
|
||||
AudioChannel0 = 1 << 0,
|
||||
AudioChannel1 = 1 << 1,
|
||||
AudioChannel2 = 1 << 2,
|
||||
AudioChannel3 = 1 << 3,
|
||||
Disk = 1 << 4,
|
||||
Sprites = 1 << 5,
|
||||
Blitter = 1 << 6,
|
||||
Copper = 1 << 7,
|
||||
Bitplane = 1 << 8,
|
||||
AllBelow = 1 << 9,
|
||||
BlitterPriority = 1 << 10,
|
||||
BlitterZero = 1 << 13,
|
||||
BlitterBusy = 1 << 14,
|
||||
};
|
||||
|
||||
};
|
||||
|
||||
#endif /* Flags_hpp */
|
||||
188
Machines/Amiga/Keyboard.cpp
Normal file
188
Machines/Amiga/Keyboard.cpp
Normal file
@@ -0,0 +1,188 @@
|
||||
//
|
||||
// Keyboard.cpp
|
||||
// Clock Signal
|
||||
//
|
||||
// Created by Thomas Harte on 29/07/2021.
|
||||
// Copyright © 2021 Thomas Harte. All rights reserved.
|
||||
//
|
||||
|
||||
#include "Keyboard.hpp"
|
||||
|
||||
// Notes to self:
|
||||
//
|
||||
//
|
||||
// Before
|
||||
// the transmission starts, both KCLK and KDAT are high. The keyboard starts
|
||||
// the transmission by putting out the first data bit (on KDAT), followed by
|
||||
// a pulse on KCLK (low then high); then it puts out the second data bit and
|
||||
// pulses KCLK until all eight data bits have been sent.
|
||||
//
|
||||
// When the computer has received the eighth bit, it must pulse KDAT low for
|
||||
// at least 1 (one) microsecond, as a handshake signal to the keyboard. The
|
||||
// keyboard must be able to detect pulses greater than or equal
|
||||
// to 1 microsecond. Software MUST pulse the line low for 85 microseconds to
|
||||
// ensure compatibility with all keyboard models.
|
||||
//
|
||||
//
|
||||
// If the handshake pulse does not arrive within
|
||||
// 143 ms of the last clock of the transmission, the keyboard will assume
|
||||
// that the computer is still waiting for the rest of the transmission and is
|
||||
// therefore out of sync. The keyboard will then attempt to restore sync by
|
||||
// going into "resync mode." In this mode, the keyboard clocks out a 1 and
|
||||
// waits for a handshake pulse. If none arrives within 143 ms, it clocks out
|
||||
// another 1 and waits again.
|
||||
//
|
||||
// The keyboard Hard Resets the Amiga by pulling KCLK low and starting a 500
|
||||
// millisecond timer. When one or more of the keys is released and 500
|
||||
// milliseconds have passed, the keyboard will release KCLK.
|
||||
//
|
||||
// The usual sequence of events will therefore be: power-up; synchronize;
|
||||
// transmit "initiate power-up key stream" ($FD); transmit "terminate key
|
||||
// stream" ($FE).
|
||||
|
||||
using namespace Amiga;
|
||||
|
||||
Keyboard::Keyboard(Serial::Line<true> &output) : output_(output) {
|
||||
output_.set_writer_clock_rate(HalfCycles(1'000'000)); // Use µs.
|
||||
}
|
||||
|
||||
/*uint8_t Keyboard::update(uint8_t input) {
|
||||
// If a bit transmission is ongoing, continue that, up to and including
|
||||
// the handshake. If no handshake comes, set a macro state of synchronising.
|
||||
switch(shift_state_) {
|
||||
case ShiftState::Shifting:
|
||||
// The keyboard processor sets the KDAT line about 20 microseconds before it
|
||||
// pulls KCLK low. KCLK stays low for about 20 microseconds, then goes high
|
||||
// again. The processor waits another 20 microseconds before changing KDAT.
|
||||
switch(bit_phase_) {
|
||||
default: break;
|
||||
case 0: lines_ = Lines::Clock | (shift_sequence_ & 1); break;
|
||||
case 20: lines_ = (shift_sequence_ & 1); break;
|
||||
case 40: lines_ = Lines::Clock | (shift_sequence_ & 1); break;
|
||||
}
|
||||
bit_phase_ = (bit_phase_ + 1) % 60;
|
||||
|
||||
if(!bit_phase_) {
|
||||
--bits_remaining_;
|
||||
shift_sequence_ >>= 1;
|
||||
if(!bits_remaining_) {
|
||||
shift_state_ = ShiftState::AwaitingHandshake;
|
||||
}
|
||||
}
|
||||
return lines_;
|
||||
|
||||
case ShiftState::AwaitingHandshake:
|
||||
if(!(input & Lines::Data)) {
|
||||
shift_state_ = ShiftState::Idle;
|
||||
}
|
||||
++bit_phase_;
|
||||
if(bit_phase_ == 143) {
|
||||
// shift_state_ = ShiftState::Synchronising;
|
||||
}
|
||||
return lines_;
|
||||
|
||||
default: break;
|
||||
}
|
||||
|
||||
switch(state_) {
|
||||
case State::Startup:
|
||||
bit_phase_ = 0;
|
||||
shift_sequence_ = 0xff;
|
||||
shift_state_ = ShiftState::Shifting;
|
||||
break;
|
||||
}
|
||||
|
||||
return lines_;
|
||||
}*/
|
||||
|
||||
void Keyboard::set_key_state(uint16_t key, bool is_pressed) {
|
||||
if(pressed_[key] == is_pressed) {
|
||||
return;
|
||||
}
|
||||
pressed_[key] = is_pressed;
|
||||
output_.write<false>(
|
||||
HalfCycles(60),
|
||||
uint8_t(((key << 1) | (is_pressed ? 0 : 1)) ^ 0xff)
|
||||
);
|
||||
}
|
||||
|
||||
void Keyboard::clear_all_keys() {
|
||||
for(uint16_t c = 0; c < uint16_t(pressed_.size()); c++) {
|
||||
if(pressed_[c]) set_key_state(c, false);
|
||||
}
|
||||
}
|
||||
|
||||
// MARK: - KeyboardMapper.
|
||||
|
||||
uint16_t KeyboardMapper::mapped_key_for_key(Inputs::Keyboard::Key key) const {
|
||||
#define BIND(source, dest) case Inputs::Keyboard::Key::source: return uint16_t(Key::dest)
|
||||
#define DIRECTBIND(source) BIND(source, source)
|
||||
switch(key) {
|
||||
default: break;
|
||||
|
||||
DIRECTBIND(Escape);
|
||||
DIRECTBIND(Delete);
|
||||
|
||||
DIRECTBIND(F1); DIRECTBIND(F2); DIRECTBIND(F3); DIRECTBIND(F4); DIRECTBIND(F5);
|
||||
DIRECTBIND(F6); DIRECTBIND(F7); DIRECTBIND(F8); DIRECTBIND(F9); DIRECTBIND(F10);
|
||||
|
||||
BIND(BackTick, Tilde);
|
||||
DIRECTBIND(k1); DIRECTBIND(k2); DIRECTBIND(k3); DIRECTBIND(k4); DIRECTBIND(k5);
|
||||
DIRECTBIND(k6); DIRECTBIND(k7); DIRECTBIND(k8); DIRECTBIND(k9); DIRECTBIND(k0);
|
||||
|
||||
DIRECTBIND(Hyphen);
|
||||
DIRECTBIND(Equals);
|
||||
DIRECTBIND(Backslash);
|
||||
DIRECTBIND(Backspace);
|
||||
DIRECTBIND(Tab);
|
||||
DIRECTBIND(CapsLock);
|
||||
|
||||
BIND(LeftControl, Control);
|
||||
BIND(RightControl, Control);
|
||||
DIRECTBIND(LeftShift);
|
||||
DIRECTBIND(RightShift);
|
||||
BIND(LeftOption, Alt);
|
||||
BIND(RightOption, Alt);
|
||||
BIND(LeftMeta, LeftAmiga);
|
||||
BIND(RightMeta, RightAmiga);
|
||||
|
||||
DIRECTBIND(Q); DIRECTBIND(W); DIRECTBIND(E); DIRECTBIND(R); DIRECTBIND(T);
|
||||
DIRECTBIND(Y); DIRECTBIND(U); DIRECTBIND(I); DIRECTBIND(O); DIRECTBIND(P);
|
||||
DIRECTBIND(A); DIRECTBIND(S); DIRECTBIND(D); DIRECTBIND(F); DIRECTBIND(G);
|
||||
DIRECTBIND(H); DIRECTBIND(J); DIRECTBIND(K); DIRECTBIND(L); DIRECTBIND(Z);
|
||||
DIRECTBIND(X); DIRECTBIND(C); DIRECTBIND(V); DIRECTBIND(B); DIRECTBIND(N);
|
||||
DIRECTBIND(M);
|
||||
|
||||
DIRECTBIND(OpenSquareBracket);
|
||||
DIRECTBIND(CloseSquareBracket);
|
||||
|
||||
DIRECTBIND(Help);
|
||||
BIND(Insert, Help);
|
||||
BIND(Home, Help);
|
||||
BIND(End, Help);
|
||||
BIND(Enter, Return);
|
||||
DIRECTBIND(Semicolon);
|
||||
DIRECTBIND(Quote);
|
||||
DIRECTBIND(Comma);
|
||||
DIRECTBIND(FullStop);
|
||||
DIRECTBIND(ForwardSlash);
|
||||
|
||||
DIRECTBIND(Space);
|
||||
DIRECTBIND(Up);
|
||||
DIRECTBIND(Down);
|
||||
DIRECTBIND(Left);
|
||||
DIRECTBIND(Right);
|
||||
|
||||
DIRECTBIND(Keypad0); DIRECTBIND(Keypad1); DIRECTBIND(Keypad2);
|
||||
DIRECTBIND(Keypad3); DIRECTBIND(Keypad4); DIRECTBIND(Keypad5);
|
||||
DIRECTBIND(Keypad6); DIRECTBIND(Keypad7); DIRECTBIND(Keypad8);
|
||||
DIRECTBIND(Keypad9);
|
||||
|
||||
DIRECTBIND(KeypadDecimalPoint);
|
||||
DIRECTBIND(KeypadMinus);
|
||||
DIRECTBIND(KeypadEnter);
|
||||
}
|
||||
#undef DIRECTBIND
|
||||
#undef BIND
|
||||
return MachineTypes::MappedKeyboardMachine::KeyNotMapped;
|
||||
}
|
||||
121
Machines/Amiga/Keyboard.hpp
Normal file
121
Machines/Amiga/Keyboard.hpp
Normal file
@@ -0,0 +1,121 @@
|
||||
//
|
||||
// Keyboard.hpp
|
||||
// Clock Signal
|
||||
//
|
||||
// Created by Thomas Harte on 29/07/2021.
|
||||
// Copyright © 2021 Thomas Harte. All rights reserved.
|
||||
//
|
||||
|
||||
#ifndef Machines_Amiga_Keyboard_hpp
|
||||
#define Machines_Amiga_Keyboard_hpp
|
||||
|
||||
#include <array>
|
||||
#include <cstdint>
|
||||
#include "../KeyboardMachine.hpp"
|
||||
#include "../../Components/Serial/Line.hpp"
|
||||
#include "../../ClockReceiver/ClockReceiver.hpp"
|
||||
|
||||
namespace Amiga {
|
||||
|
||||
enum class Key: uint16_t {
|
||||
Escape = 0x45,
|
||||
Delete = 0x46,
|
||||
|
||||
F1 = 0x50, F2 = 0x51, F3 = 0x52, F4 = 0x53, F5 = 0x54,
|
||||
F6 = 0x55, F7 = 0x56, F8 = 0x57, F9 = 0x58, F10 = 0x59,
|
||||
|
||||
Tilde = 0x00,
|
||||
k1 = 0x01, k2 = 0x02, k3 = 0x03, k4 = 0x04, k5 = 0x05,
|
||||
k6 = 0x06, k7 = 0x07, k8 = 0x08, k9 = 0x09, k0 = 0x0a,
|
||||
|
||||
Hyphen = 0x0b,
|
||||
Equals = 0x0c,
|
||||
Backslash = 0x0d,
|
||||
Backspace = 0x41,
|
||||
Tab = 0x42,
|
||||
Control = 0x63,
|
||||
CapsLock = 0x62,
|
||||
LeftShift = 0x60,
|
||||
RightShift = 0x61,
|
||||
|
||||
Q = 0x10, W = 0x11, E = 0x12, R = 0x13, T = 0x14,
|
||||
Y = 0x15, U = 0x16, I = 0x17, O = 0x18, P = 0x19,
|
||||
A = 0x20, S = 0x21, D = 0x22, F = 0x23, G = 0x24,
|
||||
H = 0x25, J = 0x26, K = 0x27, L = 0x28, Z = 0x31,
|
||||
X = 0x32, C = 0x33, V = 0x34, B = 0x35, N = 0x36,
|
||||
M = 0x37,
|
||||
|
||||
OpenSquareBracket = 0x1a,
|
||||
CloseSquareBracket = 0x1b,
|
||||
Help = 0x5f,
|
||||
Return = 0x44,
|
||||
Semicolon = 0x29,
|
||||
Quote = 0x2a,
|
||||
Comma = 0x38,
|
||||
FullStop = 0x39,
|
||||
ForwardSlash = 0x3a,
|
||||
Alt = 0x64,
|
||||
LeftAmiga = 0x66,
|
||||
RightAmiga = 0x67,
|
||||
Space = 0x40,
|
||||
|
||||
Up = 0x4c, Left = 0x4f, Right = 0x4e, Down = 0x4d,
|
||||
|
||||
Keypad7 = 0x3d, Keypad8 = 0x3e, Keypad9 = 0x3f,
|
||||
Keypad4 = 0x2d, Keypad5 = 0x2e, Keypad6 = 0x2f,
|
||||
Keypad1 = 0x1d, Keypad2 = 0x1e, Keypad3 = 0x1f,
|
||||
Keypad0 = 0x0f, KeypadDecimalPoint = 0x3c,
|
||||
KeypadMinus = 0x4a, KeypadEnter = 0x43,
|
||||
KeypadOpenBracket = 0x5a,
|
||||
KeypadCloseBracket = 0x5b,
|
||||
KeypadDivide = 0x5c,
|
||||
KeypadMultiply = 0x5d,
|
||||
KeypadPlus = 0x5e,
|
||||
};
|
||||
|
||||
struct KeyboardMapper: public MachineTypes::MappedKeyboardMachine::KeyboardMapper {
|
||||
uint16_t mapped_key_for_key(Inputs::Keyboard::Key key) const final;
|
||||
};
|
||||
|
||||
class Keyboard {
|
||||
public:
|
||||
Keyboard(Serial::Line<true> &output);
|
||||
|
||||
// enum Lines: uint8_t {
|
||||
// Data = (1 << 0),
|
||||
// Clock = (1 << 1),
|
||||
// };
|
||||
//
|
||||
// uint8_t update(uint8_t);
|
||||
|
||||
void set_key_state(uint16_t, bool);
|
||||
void clear_all_keys();
|
||||
|
||||
void run_for(HalfCycles duration) {
|
||||
output_.advance_writer(duration);
|
||||
}
|
||||
|
||||
private:
|
||||
enum class ShiftState {
|
||||
Shifting,
|
||||
AwaitingHandshake,
|
||||
Idle,
|
||||
} shift_state_ = ShiftState::Idle;
|
||||
|
||||
enum class State {
|
||||
Startup,
|
||||
} state_ = State::Startup;
|
||||
|
||||
int bit_phase_ = 0;
|
||||
uint32_t shift_sequence_ = 0;
|
||||
int bits_remaining_ = 0;
|
||||
|
||||
uint8_t lines_ = 0;
|
||||
|
||||
Serial::Line<true> &output_;
|
||||
std::array<bool, 128> pressed_{};
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif /* Machines_Amiga_Keyboard_hpp */
|
||||
85
Machines/Amiga/MemoryMap.hpp
Normal file
85
Machines/Amiga/MemoryMap.hpp
Normal file
@@ -0,0 +1,85 @@
|
||||
//
|
||||
// MemoryMap.hpp
|
||||
// Clock Signal
|
||||
//
|
||||
// Created by Thomas Harte on 04/10/2021.
|
||||
// Copyright © 2021 Thomas Harte. All rights reserved.
|
||||
//
|
||||
|
||||
#ifndef MemoryMap_hpp
|
||||
#define MemoryMap_hpp
|
||||
|
||||
namespace Amiga {
|
||||
|
||||
class MemoryMap {
|
||||
private:
|
||||
static constexpr auto PermitRead = CPU::MC68000::Microcycle::PermitRead;
|
||||
static constexpr auto PermitWrite = CPU::MC68000::Microcycle::PermitWrite;
|
||||
static constexpr auto PermitReadWrite = PermitRead | PermitWrite;
|
||||
|
||||
public:
|
||||
// TODO: decide what of the below I want to be dynamic.
|
||||
std::array<uint8_t, 1024*1024> chip_ram{};
|
||||
std::array<uint8_t, 512*1024> kickstart{0xff};
|
||||
|
||||
struct MemoryRegion {
|
||||
uint8_t *contents = nullptr;
|
||||
unsigned int read_write_mask = 0;
|
||||
} regions[64]; // i.e. top six bits are used as an index.
|
||||
|
||||
MemoryMap() {
|
||||
// Address spaces that matter:
|
||||
//
|
||||
// 00'0000 – 08'0000: chip RAM. [or overlayed KickStart]
|
||||
// – 10'0000: extended chip ram for ECS.
|
||||
// – 20'0000: slow RAM and further chip RAM.
|
||||
// – a0'0000: auto-config space (/fast RAM).
|
||||
// ...
|
||||
// bf'd000 – c0'0000: 8250s.
|
||||
// c0'0000 – d8'0000: pseudo-fast RAM.
|
||||
// ...
|
||||
// dc'0000 – dd'0000: optional real-time clock.
|
||||
// df'f000 - e0'0000: custom chip registers.
|
||||
// ...
|
||||
// f0'0000 — : 512kb Kickstart (or possibly just an extra 512kb reserved for hypothetical 1mb Kickstart?).
|
||||
// f8'0000 — : 256kb Kickstart if 2.04 or higher.
|
||||
// fc'0000 – : 256kb Kickstart otherwise.
|
||||
set_region(0xfc'0000, 0x1'00'0000, kickstart.data(), PermitRead);
|
||||
reset();
|
||||
}
|
||||
|
||||
void reset() {
|
||||
set_overlay(true);
|
||||
}
|
||||
|
||||
void set_overlay(bool enabled) {
|
||||
if(overlay_ == enabled) {
|
||||
return;
|
||||
}
|
||||
overlay_ = enabled;
|
||||
|
||||
set_region(0x00'0000, uint32_t(chip_ram.size()), chip_ram.data(), PermitReadWrite);
|
||||
if(enabled) {
|
||||
set_region(0x00'0000, 0x08'0000, kickstart.data(), PermitRead);
|
||||
}
|
||||
}
|
||||
|
||||
private:
|
||||
bool overlay_ = false;
|
||||
|
||||
void set_region(uint32_t start, uint32_t end, uint8_t *base, unsigned int read_write_mask) {
|
||||
[[maybe_unused]] constexpr uint32_t precision_loss_mask = uint32_t(~0xfc'0000);
|
||||
assert(!(start & precision_loss_mask));
|
||||
assert(!((end - (1 << 18)) & precision_loss_mask));
|
||||
assert(end > start);
|
||||
|
||||
if(base) base -= start;
|
||||
for(decltype(start) c = start >> 18; c < end >> 18; c++) {
|
||||
regions[c].contents = base;
|
||||
regions[c].read_write_mask = read_write_mask;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
}
|
||||
#endif /* MemoryMap_hpp */
|
||||
387
Machines/Amiga/Minterms.hpp
Normal file
387
Machines/Amiga/Minterms.hpp
Normal file
@@ -0,0 +1,387 @@
|
||||
//
|
||||
// Minterms.hpp
|
||||
// Clock Signal
|
||||
//
|
||||
// Created by Thomas Harte on 20/09/2021.
|
||||
// Copyright © 2021 Thomas Harte. All rights reserved.
|
||||
//
|
||||
|
||||
#ifndef Minterms_hpp
|
||||
#define Minterms_hpp
|
||||
|
||||
namespace Amiga {
|
||||
|
||||
/// @returns the result of applying the Amiga-format @c minterm to inputs @c a, @c b and @c c.
|
||||
template <typename IntT> IntT apply_minterm(IntT a, IntT b, IntT c, int minterm) {
|
||||
|
||||
// Quick implementation notes:
|
||||
//
|
||||
// This was created very lazily. I tried to enter as many logical combinations of
|
||||
// a, b and c as I could think of and had a test program match them up to the
|
||||
// Amiga minterm IDs, prioritising by simplicity.
|
||||
//
|
||||
// That got me most of the way; starting from the point indicated below I had run
|
||||
// out of good ideas and automatically generated the rest.
|
||||
//
|
||||
switch(minterm) {
|
||||
default:
|
||||
case 0x00: return IntT(0);
|
||||
case 0xff: return IntT(~0);
|
||||
|
||||
|
||||
case 0xf0: return a;
|
||||
case 0xcc: return b;
|
||||
case 0xaa: return c;
|
||||
|
||||
case 0x0f: return ~a;
|
||||
case 0x33: return ~b;
|
||||
case 0x55: return ~c;
|
||||
|
||||
case 0xfc: return a | b;
|
||||
case 0xfa: return a | c;
|
||||
case 0xee: return b | c;
|
||||
case 0xfe: return a | b | c;
|
||||
|
||||
case 0xf3: return a | ~b;
|
||||
case 0xf5: return a | ~c;
|
||||
case 0xdd: return b | ~c;
|
||||
|
||||
case 0xfd: return a | b | ~c;
|
||||
case 0xfb: return a | ~b | c;
|
||||
case 0xf7: return a | ~b | ~c;
|
||||
|
||||
case 0xcf: return ~a | b;
|
||||
case 0xaf: return ~a | c;
|
||||
case 0xbb: return ~b | c;
|
||||
|
||||
case 0xef: return ~a | b | c;
|
||||
case 0xdf: return ~a | b | ~c;
|
||||
case 0x7f: return ~a | ~b | ~c;
|
||||
|
||||
|
||||
case 0x3c: return a ^ b;
|
||||
case 0x5a: return a ^ c;
|
||||
case 0x66: return b ^ c;
|
||||
case 0x96: return a ^ b ^ c;
|
||||
|
||||
case 0xc3: return ~a ^ b;
|
||||
case 0xa5: return ~a ^ c;
|
||||
case 0x99: return ~b ^ c;
|
||||
case 0x69: return ~a ^ b ^ c;
|
||||
|
||||
|
||||
case 0xc0: return a & b;
|
||||
case 0xa0: return a & c;
|
||||
case 0x88: return b & c;
|
||||
case 0x80: return a & b & c;
|
||||
|
||||
case 0x30: return a & ~b;
|
||||
case 0x50: return a & ~c;
|
||||
case 0x44: return b & ~c;
|
||||
|
||||
case 0x0c: return ~a & b;
|
||||
case 0x0a: return ~a & c;
|
||||
case 0x22: return ~b & c;
|
||||
|
||||
case 0x40: return a & b & ~c;
|
||||
case 0x20: return a & ~b & c;
|
||||
case 0x08: return ~a & b & c;
|
||||
|
||||
case 0x10: return a & ~b & ~c;
|
||||
case 0x04: return ~a & b & ~c;
|
||||
case 0x02: return ~a & ~b & c;
|
||||
|
||||
case 0x03: return ~a & ~b;
|
||||
case 0x05: return ~a & ~c;
|
||||
case 0x11: return ~b & ~c;
|
||||
case 0x01: return ~a & ~b & ~c;
|
||||
|
||||
case 0x70: return a & ~(b & c);
|
||||
case 0x4c: return b & ~(a & c);
|
||||
case 0x2a: return c & ~(a & b);
|
||||
|
||||
case 0x07: return ~a & ~(b & c);
|
||||
case 0x13: return ~b & ~(a & c);
|
||||
case 0x15: return ~c & ~(a & b);
|
||||
|
||||
|
||||
case 0xe0: return a & (b | c);
|
||||
case 0xc8: return b & (a | c);
|
||||
case 0xa8: return c & (a | b);
|
||||
|
||||
case 0x0e: return ~a & (b | c);
|
||||
case 0x32: return ~b & (a | c);
|
||||
case 0x54: return ~c & (a | b);
|
||||
|
||||
case 0x60: return a & (b ^ c);
|
||||
case 0x48: return b & (a ^ c);
|
||||
case 0x28: return c & (a ^ b);
|
||||
|
||||
case 0x06: return ~a & (b ^ c);
|
||||
case 0x12: return ~b & (a ^ c);
|
||||
case 0x14: return ~c & (a ^ b);
|
||||
|
||||
case 0x90: return a & ~(b ^ c);
|
||||
case 0x84: return b & ~(a ^ c);
|
||||
case 0x82: return c & ~(a ^ b);
|
||||
|
||||
case 0x09: return ~a & ~(b ^ c);
|
||||
case 0x21: return ~b & ~(a ^ c);
|
||||
case 0x41: return ~c & ~(a ^ b);
|
||||
|
||||
case 0xb0: return a & (~b | c);
|
||||
case 0xd0: return a & (b | ~c);
|
||||
case 0x0b: return ~a & (~b | c);
|
||||
case 0x0d: return ~a & (b | ~c);
|
||||
|
||||
|
||||
case 0xf6: return a | (b ^ c);
|
||||
case 0xde: return b | (a ^ c);
|
||||
case 0xbe: return c | (a ^ b);
|
||||
|
||||
case 0x6f: return ~a | (b ^ c);
|
||||
case 0x7b: return ~b | (a ^ c);
|
||||
case 0x7d: return ~c | (a ^ b);
|
||||
|
||||
case 0x9f: return ~a | ~(b ^ c);
|
||||
case 0xb7: return ~b | ~(a ^ c);
|
||||
case 0xd7: return ~c | ~(a ^ b);
|
||||
|
||||
case 0xf8: return a | (b & c);
|
||||
case 0xec: return b | (a & c);
|
||||
case 0xea: return c | (a & b);
|
||||
|
||||
case 0x8f: return ~a | (b & c);
|
||||
case 0xb3: return ~b | (a & c);
|
||||
case 0xd5: return ~c | (a & b);
|
||||
|
||||
case 0xf1: return a | ~(b | c);
|
||||
case 0xcd: return b | ~(a | c);
|
||||
case 0xab: return c | ~(a | b);
|
||||
|
||||
case 0x1f: return ~a | ~(b | c);
|
||||
case 0x37: return ~b | ~(a | c);
|
||||
case 0x57: return ~c | ~(a | b);
|
||||
|
||||
case 0x8c: return b & (~a | c);
|
||||
case 0x8a: return c & (~a | b);
|
||||
|
||||
case 0xc4: return b & (a | ~c);
|
||||
case 0xa2: return c & (a | ~b);
|
||||
|
||||
|
||||
case 0x78: return a ^ (b & c);
|
||||
case 0x6c: return b ^ (a & c);
|
||||
case 0x6a: return c ^ (a & b);
|
||||
|
||||
case 0x87: return ~a ^ (b & c);
|
||||
case 0x93: return ~b ^ (a & c);
|
||||
case 0x95: return ~c ^ (a & b);
|
||||
|
||||
|
||||
case 0x1e: return a ^ (b | c);
|
||||
case 0x36: return b ^ (a | c);
|
||||
case 0x56: return c ^ (a | b);
|
||||
|
||||
case 0x2d: return a ^ (b | ~c);
|
||||
case 0x4b: return a ^ (~b | c);
|
||||
case 0xe1: return a ^ ~(b | c);
|
||||
|
||||
case 0x39: return b ^ (a | ~c);
|
||||
case 0x63: return b ^ (~a | c);
|
||||
case 0xc9: return b ^ ~(a | c);
|
||||
|
||||
case 0x59: return c ^ (a | ~b);
|
||||
case 0x65: return c ^ (~a | b);
|
||||
case 0xa9: return c ^ ~(a | b);
|
||||
|
||||
|
||||
case 0x24: return (a ^ b) & (b ^ c);
|
||||
case 0x18: return (a ^ b) & (a ^ c);
|
||||
case 0x42: return (a ^ c) & (b ^ c);
|
||||
|
||||
case 0xa6: return (a & b) ^ (b ^ c);
|
||||
case 0xc6: return (a & c) ^ (b ^ c);
|
||||
|
||||
case 0x5c: return (a | b) ^ (a & c);
|
||||
case 0x74: return (a | b) ^ (b & c);
|
||||
case 0x72: return (a | c) ^ (b & c);
|
||||
case 0x4e: return (b | c) ^ (a & c);
|
||||
|
||||
case 0x58: return (a | b) & (a ^ c);
|
||||
case 0x62: return (a | c) & (b ^ c);
|
||||
|
||||
case 0x7e: return (a ^ b) | (a ^ c);
|
||||
|
||||
case 0xca: return (a & b) | (~a & c);
|
||||
case 0xac: return (~a & b) | (a & c);
|
||||
case 0xa3: return (~a & ~b) | (a & c);
|
||||
|
||||
|
||||
case 0xf4: return a | ((a ^ b) & (b ^ c));
|
||||
case 0xf2: return a | ((a ^ c) & (b ^ c));
|
||||
case 0xdc: return b | ((a ^ b) & (a ^ c));
|
||||
case 0xce: return b | ((a ^ c) & (b ^ c));
|
||||
case 0xae: return c | ((a ^ b) & (b ^ c));
|
||||
case 0xba: return c | ((a ^ b) & (a ^ c));
|
||||
|
||||
case 0x2f: return ~a | ((a ^ b) & (b ^ c));
|
||||
case 0x4f: return ~a | ((a ^ c) & (b ^ c));
|
||||
case 0x3b: return ~b | ((a ^ b) & (a ^ c));
|
||||
case 0x73: return ~b | ((a ^ c) & (b ^ c));
|
||||
case 0x75: return ~c | ((a ^ b) & (b ^ c));
|
||||
case 0x5d: return ~c | ((a ^ b) & (a ^ c));
|
||||
|
||||
case 0x3f: return ~a | ~b | ((a ^ b) & (b ^ c));
|
||||
case 0x77: return ~b | ~c | ((a ^ b) & (b ^ c));
|
||||
|
||||
case 0x27: return ~(a | b) | ((a ^ b) & (b ^ c));
|
||||
case 0x47: return ~(a | c) | ((a ^ c) & (b ^ c));
|
||||
case 0x53: return ~(b | c) | ((a ^ c) & (b ^ c));
|
||||
case 0x43: return ~(a | b | c) | ((a ^ c) & (b ^ c));
|
||||
|
||||
|
||||
case 0x7a: return (a & ~b) | (a ^ c);
|
||||
case 0x76: return (a & ~b) | (b ^ c);
|
||||
case 0x7c: return (a & ~c) | (a ^ b);
|
||||
|
||||
case 0x5e: return (~a & b) | (a ^ c);
|
||||
case 0x6e: return (~a & b) | (b ^ c);
|
||||
case 0x3e: return (~a & c) | (a ^ b);
|
||||
|
||||
case 0xad: return (~a & b) | ~(a ^ c);
|
||||
case 0xb5: return (a & ~b) | ~(a ^ c);
|
||||
case 0xcb: return (~a & c) | ~(a ^ b);
|
||||
case 0xd3: return (a & ~c) | ~(a ^ b);
|
||||
|
||||
case 0x9b: return (~a & c) | ~(b ^ c);
|
||||
case 0xd9: return (a & ~c) | ~(b ^ c);
|
||||
case 0x9d: return (~a & b) | ~(b ^ c);
|
||||
case 0xb9: return (a & ~b) | ~(b ^ c);
|
||||
|
||||
case 0x9e: return (~a & b) | (a ^ b ^ c);
|
||||
case 0xb6: return (a & ~b) | (a ^ b ^ c);
|
||||
case 0xd6: return (a & ~c) | (a ^ b ^ c);
|
||||
case 0xbf: return ~(a & b) | (a ^ b ^ c);
|
||||
|
||||
case 0x6d: return (~a & b) | ~(a ^ b ^ c);
|
||||
case 0x79: return (a & ~b) | ~(a ^ b ^ c);
|
||||
case 0x6b: return (~a & c) | ~(a ^ b ^ c);
|
||||
case 0xe9: return (b & c) | ~(a ^ b ^ c);
|
||||
|
||||
case 0xb8: return (a & ~b) | (c & b);
|
||||
case 0xd8: return (a & ~c) | (b & c);
|
||||
case 0xe4: return (b & ~c) | (a & c);
|
||||
case 0xe2: return (c & ~b) | (a & b);
|
||||
|
||||
|
||||
case 0x2c: return (~a & b) | ((a ^ b) & (b ^ c));
|
||||
case 0x34: return (a & ~b) | ((a ^ b) & (b ^ c));
|
||||
case 0x4a: return (~a & c) | ((a ^ c) & (b ^ c));
|
||||
case 0x52: return (a & ~c) | ((a ^ c) & (b ^ c));
|
||||
case 0x5f: return ~(a & c) | ((a ^ c) & (b ^ c));
|
||||
|
||||
|
||||
case 0x16: return (a & ~(c | b)) | (c & ~(b | a)) | (b & ~(a | c));
|
||||
case 0x81: return (a ^ ~(c | b)) & (c ^ ~(b | a)) & (b ^ ~(a | c));
|
||||
|
||||
|
||||
case 0x2e: return (~a & (b | c)) | (~b & c);
|
||||
case 0x3a: return (~b & (a | c)) | (~a & c);
|
||||
|
||||
case 0x8b: return (~a & ~b) | (c & b);
|
||||
case 0x8d: return (~a & ~c) | (b & c);
|
||||
case 0xb1: return (~b & ~c) | (a & c);
|
||||
case 0xd1: return (~c & ~b) | (a & b);
|
||||
|
||||
|
||||
case 0x98: return (a & ~(c | b)) | (b & c);
|
||||
case 0x8e: return (~a & (c | b)) | (b & c);
|
||||
|
||||
case 0x46: return (~a | b) & (b ^ c);
|
||||
|
||||
case 0xe6: return ((~a | b) & (b ^ c)) ^ (a & c);
|
||||
case 0xc2: return ((a | ~b) & (b ^ c)) ^ (a & c);
|
||||
|
||||
case 0x85: return (~a | b) & ~(a ^ c);
|
||||
case 0x83: return (~a | c) & ~(a ^ b);
|
||||
case 0x89: return (~a | c) & ~(b ^ c);
|
||||
|
||||
case 0xa1: return (a | ~b) & ~(a ^ c);
|
||||
case 0x91: return (a | ~b) & ~(b ^ c);
|
||||
case 0xc1: return (a | ~c) & ~(a ^ b);
|
||||
|
||||
case 0x94: return (a | b) & (a ^ b ^ c);
|
||||
case 0x86: return (b | c) & (a ^ b ^ c);
|
||||
case 0x92: return (a | c) & (a ^ b ^ c);
|
||||
|
||||
case 0x68: return (a | b) & ~(a ^ b ^ c);
|
||||
case 0x61: return (a | ~b) & ~(a ^ b ^ c);
|
||||
case 0x49: return (~a | b) & ~(a ^ b ^ c);
|
||||
case 0x29: return (~a | c) & ~(a ^ b ^ c);
|
||||
|
||||
case 0x64: return (a & ~b & c) | (b & ~c);
|
||||
|
||||
//
|
||||
// From here downwards functions were found automatically.
|
||||
// Neater versions likely exist of many of the functions below.
|
||||
//
|
||||
|
||||
case 0xe8: return (a & b) | ((b | a) & c);
|
||||
case 0xd4: return (a & b) | ((b | a) & ~c);
|
||||
case 0xb2: return (a & ~b) | ((~b | a) & c);
|
||||
case 0x17: return (~a & ~b) | ((~b | ~a) & ~c);
|
||||
case 0x1b: return (~a & ~b) | (~b & ~c) | (~a & c);
|
||||
case 0x1d: return (~a & b) | ((~b | ~a) & ~c);
|
||||
case 0x2b: return (~a & ~b) | ((~b | ~a) & c);
|
||||
case 0x35: return (a & ~b) | ((~b | ~a) & ~c);
|
||||
case 0x4d: return (~a & b) | ((b | ~a) & ~c);
|
||||
case 0x71: return (a & ~b) | ((~b | a) & ~c);
|
||||
case 0xbd: return (~a & b) | (~b & ~c) | (a & c);
|
||||
case 0xc5: return (a & b) | ((b | ~a) & ~c);
|
||||
case 0xdb: return (a & b) | (~b & ~c) | (~a & c);
|
||||
case 0xe7: return (~a & ~b) | (b & ~c) | (a & c);
|
||||
|
||||
|
||||
case 0x1c: return (~a & b) | (a & ~b & ~c);
|
||||
case 0x23: return (~a & ~b) | (a & ~b & c);
|
||||
case 0x31: return (a & ~b) | (~a & ~b & ~c);
|
||||
case 0x38: return (a & ~b) | (~a & b & c);
|
||||
case 0x1a: return (~a & c) | (a & ~b & ~c);
|
||||
case 0x25: return (~a & ~c) | (a & ~b & c);
|
||||
case 0x45: return (~a & ~c) | (a & b & ~c);
|
||||
case 0x51: return (a & ~c) | (~a & ~b & ~c);
|
||||
case 0xa4: return (a & c) | (~a & b & ~c);
|
||||
case 0x19: return (~b & ~c) | (~a & b & c);
|
||||
case 0x26: return (~b & c) | (~a & b & ~c);
|
||||
|
||||
case 0xc7: return (a & b) | (~a & (~b | ~c));
|
||||
case 0x3d: return (a & ~b) | (~a & (b | ~c));
|
||||
case 0xbc: return (~a & b) | (a & (~b | c));
|
||||
case 0xe3: return (~a & ~b) | (a & (b | c));
|
||||
case 0xa7: return (a & c) | (~a & (~b | ~c));
|
||||
case 0x5b: return (a & ~c) | (~a & (~b | c));
|
||||
case 0xda: return (~a & c) | (a & (b | ~c));
|
||||
case 0xe5: return (~a & ~c) | (a & (b | c));
|
||||
|
||||
case 0x67: return (~a & ~b) | ((~a | b) & ~c) | (~b & c);
|
||||
case 0x97: return (~a & ~b) | ((~a | ~b) & ~c) | (a & b & c);
|
||||
|
||||
case 0xb4: return (a & ~b) | (a & c) | (~a & b & ~c);
|
||||
case 0x9c: return (~a & b) | (b & c) | (a & ~b & ~c);
|
||||
|
||||
case 0xd2: return ((~c | b) & a) | (~a & ~b & c);
|
||||
case 0x9a: return ((~a | b) & c) | (a & ~b & ~c);
|
||||
|
||||
case 0xf9: return a | (~b & ~c) | (b & c);
|
||||
case 0xed: return b | (~a & ~c) | (a & c);
|
||||
case 0xeb: return c | (~a & ~b) | (a & b);
|
||||
}
|
||||
|
||||
// Should be unreachable.
|
||||
return 0;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
#endif /* Minterms_hpp */
|
||||
124
Machines/Amiga/MouseJoystick.cpp
Normal file
124
Machines/Amiga/MouseJoystick.cpp
Normal file
@@ -0,0 +1,124 @@
|
||||
//
|
||||
// MouseJoystick.cpp
|
||||
// Clock Signal
|
||||
//
|
||||
// Created by Thomas Harte on 26/11/2021.
|
||||
// Copyright © 2021 Thomas Harte. All rights reserved.
|
||||
//
|
||||
|
||||
#include "MouseJoystick.hpp"
|
||||
|
||||
#include <algorithm>
|
||||
|
||||
using namespace Amiga;
|
||||
|
||||
// MARK: - Mouse.
|
||||
|
||||
int Mouse::get_number_of_buttons() {
|
||||
return 2;
|
||||
}
|
||||
|
||||
void Mouse::set_button_pressed(int button, bool is_set) {
|
||||
switch(button) {
|
||||
case 0:
|
||||
cia_state_ = (cia_state_ &~ 0x40) | (is_set ? 0 : 0x40);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
uint8_t Mouse::get_cia_button() const {
|
||||
return cia_state_;
|
||||
}
|
||||
|
||||
void Mouse::reset_all_buttons() {
|
||||
cia_state_ = 0xff;
|
||||
}
|
||||
|
||||
void Mouse::move(int x, int y) {
|
||||
position_[0] += x;
|
||||
position_[1] += y;
|
||||
}
|
||||
|
||||
uint16_t Mouse::get_position() {
|
||||
// The Amiga hardware retains only eight bits of position
|
||||
// for the mouse; its software polls frequently and maps
|
||||
// changes into a larger space.
|
||||
//
|
||||
// On modern computers with 5k+ displays and trackpads, it
|
||||
// proved empirically possible to overflow the hardware
|
||||
// counters more quickly than software would poll.
|
||||
//
|
||||
// Therefore the approach taken for mapping mouse motion
|
||||
// into the Amiga is to do it in steps of no greater than
|
||||
// [-128, +127], as per the below.
|
||||
const int pending[] = {
|
||||
position_[0], position_[1]
|
||||
};
|
||||
|
||||
const int8_t change[] = {
|
||||
int8_t(std::clamp(pending[0], -128, 127)),
|
||||
int8_t(std::clamp(pending[1], -128, 127))
|
||||
};
|
||||
|
||||
position_[0] -= change[0];
|
||||
position_[1] -= change[1];
|
||||
declared_position_[0] += change[0];
|
||||
declared_position_[1] += change[1];
|
||||
|
||||
return uint16_t(
|
||||
(declared_position_[1] << 8) |
|
||||
declared_position_[0]
|
||||
);
|
||||
}
|
||||
|
||||
// MARK: - Joystick.
|
||||
|
||||
// TODO: add second fire button.
|
||||
|
||||
Joystick::Joystick() :
|
||||
ConcreteJoystick({
|
||||
Input(Input::Up),
|
||||
Input(Input::Down),
|
||||
Input(Input::Left),
|
||||
Input(Input::Right),
|
||||
Input(Input::Fire, 0),
|
||||
}) {}
|
||||
|
||||
void Joystick::did_set_input(const Input &input, bool is_active) {
|
||||
// Accumulate state.
|
||||
inputs_[input.type] = is_active;
|
||||
|
||||
// Determine what that does to the two position bits.
|
||||
const auto low =
|
||||
(inputs_[Input::Type::Down] ^ inputs_[Input::Type::Right]) |
|
||||
(inputs_[Input::Type::Right] << 1);
|
||||
const auto high =
|
||||
(inputs_[Input::Type::Up] ^ inputs_[Input::Type::Left]) |
|
||||
(inputs_[Input::Type::Left] << 1);
|
||||
|
||||
// Ripple upwards if that affects the mouse position counters.
|
||||
const uint8_t previous_low = position_ & 3;
|
||||
uint8_t low_upper = (position_ >> 2) & 0x3f;
|
||||
const uint8_t previous_high = (position_ >> 8) & 3;
|
||||
uint8_t high_upper = (position_ >> 10) & 0x3f;
|
||||
|
||||
if(!low && previous_low == 3) ++low_upper;
|
||||
if(!previous_low && low == 3) --low_upper;
|
||||
if(!high && previous_high == 3) ++high_upper;
|
||||
if(!previous_high && high == 3) --high_upper;
|
||||
|
||||
position_ = uint16_t(
|
||||
low | ((low_upper & 0x3f) << 2) |
|
||||
(high << 8) | ((high_upper & 0x3f) << 10)
|
||||
);
|
||||
}
|
||||
|
||||
uint16_t Joystick::get_position() {
|
||||
return position_;
|
||||
}
|
||||
|
||||
uint8_t Joystick::get_cia_button() const {
|
||||
return inputs_[Input::Type::Fire] ? 0xbf : 0xff;
|
||||
}
|
||||
57
Machines/Amiga/MouseJoystick.hpp
Normal file
57
Machines/Amiga/MouseJoystick.hpp
Normal file
@@ -0,0 +1,57 @@
|
||||
//
|
||||
// MouseJoystick.hpp
|
||||
// Clock Signal
|
||||
//
|
||||
// Created by Thomas Harte on 26/11/2021.
|
||||
// Copyright © 2021 Thomas Harte. All rights reserved.
|
||||
//
|
||||
|
||||
#ifndef MouseJoystick_hpp
|
||||
#define MouseJoystick_hpp
|
||||
|
||||
#include <array>
|
||||
#include <atomic>
|
||||
|
||||
#include "../../Inputs/Joystick.hpp"
|
||||
#include "../../Inputs/Mouse.hpp"
|
||||
|
||||
namespace Amiga {
|
||||
|
||||
struct MouseJoystickInput {
|
||||
virtual uint16_t get_position() = 0;
|
||||
virtual uint8_t get_cia_button() const = 0;
|
||||
};
|
||||
|
||||
class Mouse: public Inputs::Mouse, public MouseJoystickInput {
|
||||
public:
|
||||
uint16_t get_position() final;
|
||||
uint8_t get_cia_button() const final;
|
||||
|
||||
private:
|
||||
int get_number_of_buttons() final;
|
||||
void set_button_pressed(int, bool) final;
|
||||
void reset_all_buttons() final;
|
||||
void move(int, int) final;
|
||||
|
||||
uint8_t declared_position_[2]{};
|
||||
uint8_t cia_state_ = 0xff;
|
||||
std::array<std::atomic<int>, 2> position_{};
|
||||
};
|
||||
|
||||
class Joystick: public Inputs::ConcreteJoystick, public MouseJoystickInput {
|
||||
public:
|
||||
Joystick();
|
||||
|
||||
uint16_t get_position() final;
|
||||
uint8_t get_cia_button() const final;
|
||||
|
||||
private:
|
||||
void did_set_input(const Input &input, bool is_active) final;
|
||||
|
||||
bool inputs_[Joystick::Input::Type::Max]{};
|
||||
uint16_t position_ = 0;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif /* MouseJoystick_hpp */
|
||||
115
Machines/Amiga/Sprites.cpp
Normal file
115
Machines/Amiga/Sprites.cpp
Normal file
@@ -0,0 +1,115 @@
|
||||
//
|
||||
// Sprites.cpp
|
||||
// Clock Signal
|
||||
//
|
||||
// Created by Thomas Harte on 26/11/2021.
|
||||
// Copyright © 2021 Thomas Harte. All rights reserved.
|
||||
//
|
||||
|
||||
#include "Sprites.hpp"
|
||||
|
||||
using namespace Amiga;
|
||||
|
||||
namespace {
|
||||
|
||||
/// Expands @c source from b15 ... b0 to 000b15 ... 000b0.
|
||||
constexpr uint64_t expand_sprite_word(uint16_t source) {
|
||||
uint64_t result = source;
|
||||
result = (result | (result << 24)) & 0x0000'00ff'0000'00ff;
|
||||
result = (result | (result << 12)) & 0x000f'000f'000f'000f;
|
||||
result = (result | (result << 6)) & 0x0303'0303'0303'0303;
|
||||
result = (result | (result << 3)) & 0x1111'1111'1111'1111;
|
||||
return result;
|
||||
}
|
||||
|
||||
// A very small selection of test cases.
|
||||
static_assert(expand_sprite_word(0xffff) == 0x11'11'11'11'11'11'11'11);
|
||||
static_assert(expand_sprite_word(0x5555) == 0x01'01'01'01'01'01'01'01);
|
||||
static_assert(expand_sprite_word(0xaaaa) == 0x10'10'10'10'10'10'10'10);
|
||||
static_assert(expand_sprite_word(0x0000) == 0x00'00'00'00'00'00'00'00);
|
||||
|
||||
}
|
||||
|
||||
// MARK: - Sprites.
|
||||
|
||||
void Sprite::set_start_position(uint16_t value) {
|
||||
v_start_ = (v_start_ & 0xff00) | (value >> 8);
|
||||
h_start = uint16_t((h_start & 0x0001) | ((value & 0xff) << 1));
|
||||
}
|
||||
|
||||
void Sprite::set_stop_and_control(uint16_t value) {
|
||||
h_start = uint16_t((h_start & 0x01fe) | (value & 0x01));
|
||||
v_stop_ = uint16_t((value >> 8) | ((value & 0x02) << 7));
|
||||
v_start_ = uint16_t((v_start_ & 0x00ff) | ((value & 0x04) << 6));
|
||||
attached = value & 0x80;
|
||||
|
||||
// Disarm the sprite, but expect graphics next from DMA.
|
||||
visible = false;
|
||||
dma_state_ = DMAState::FetchImage;
|
||||
}
|
||||
|
||||
void Sprite::set_image_data(int slot, uint16_t value) {
|
||||
data[slot] = value;
|
||||
visible |= slot == 0;
|
||||
}
|
||||
|
||||
void Sprite::advance_line(int y, bool is_end_of_blank) {
|
||||
if(dma_state_ == DMAState::FetchImage && y == v_start_) {
|
||||
visible = true;
|
||||
}
|
||||
if(is_end_of_blank || y == v_stop_) {
|
||||
dma_state_ = DMAState::FetchControl;
|
||||
visible = true;
|
||||
}
|
||||
}
|
||||
|
||||
bool Sprite::advance_dma(int offset) {
|
||||
if(!visible) return false;
|
||||
|
||||
// Fetch another word.
|
||||
const uint16_t next_word = ram_[pointer_[0] & ram_mask_];
|
||||
++pointer_[0];
|
||||
|
||||
// Put the fetched word somewhere appropriate and update the DMA state.
|
||||
switch(dma_state_) {
|
||||
// i.e. stopped.
|
||||
default: return false;
|
||||
|
||||
case DMAState::FetchControl:
|
||||
if(offset) {
|
||||
set_stop_and_control(next_word);
|
||||
} else {
|
||||
set_start_position(next_word);
|
||||
}
|
||||
return true;
|
||||
|
||||
case DMAState::FetchImage:
|
||||
set_image_data(1 - bool(offset), next_word);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
template <int sprite> void TwoSpriteShifter::load(
|
||||
uint16_t lsb,
|
||||
uint16_t msb,
|
||||
int delay) {
|
||||
constexpr int sprite_shift = sprite << 1;
|
||||
const int delay_shift = delay << 2;
|
||||
|
||||
// Clear out any current sprite pixels; this is a reload.
|
||||
data_ &= 0xcccc'cccc'cccc'ccccull >> (sprite_shift + delay_shift);
|
||||
|
||||
// Map LSB and MSB up to 64-bits and load into the shifter.
|
||||
const uint64_t new_data =
|
||||
(
|
||||
expand_sprite_word(lsb) |
|
||||
(expand_sprite_word(msb) << 1)
|
||||
) << sprite_shift;
|
||||
|
||||
data_ |= new_data >> delay_shift;
|
||||
overflow_ |= uint8_t((new_data << 8) >> delay_shift);
|
||||
}
|
||||
|
||||
template void TwoSpriteShifter::load<0>(uint16_t, uint16_t, int);
|
||||
template void TwoSpriteShifter::load<1>(uint16_t, uint16_t, int);
|
||||
76
Machines/Amiga/Sprites.hpp
Normal file
76
Machines/Amiga/Sprites.hpp
Normal file
@@ -0,0 +1,76 @@
|
||||
//
|
||||
// Sprites.hpp
|
||||
// Clock Signal
|
||||
//
|
||||
// Created by Thomas Harte on 26/11/2021.
|
||||
// Copyright © 2021 Thomas Harte. All rights reserved.
|
||||
//
|
||||
|
||||
#ifndef Sprites_hpp
|
||||
#define Sprites_hpp
|
||||
|
||||
#include <cstdint>
|
||||
|
||||
#include "DMADevice.hpp"
|
||||
|
||||
namespace Amiga {
|
||||
|
||||
class Sprite: public DMADevice<1> {
|
||||
public:
|
||||
using DMADevice::DMADevice;
|
||||
|
||||
void set_start_position(uint16_t value);
|
||||
void set_stop_and_control(uint16_t value);
|
||||
void set_image_data(int slot, uint16_t value);
|
||||
|
||||
void advance_line(int y, bool is_end_of_blank);
|
||||
bool advance_dma(int offset);
|
||||
|
||||
uint16_t data[2]{};
|
||||
bool attached = false;
|
||||
bool visible = false;
|
||||
uint16_t h_start = 0;
|
||||
|
||||
private:
|
||||
uint16_t v_start_ = 0, v_stop_ = 0;
|
||||
|
||||
enum class DMAState {
|
||||
FetchControl,
|
||||
FetchImage
|
||||
} dma_state_ = DMAState::FetchControl;
|
||||
};
|
||||
|
||||
class TwoSpriteShifter {
|
||||
public:
|
||||
/// Installs new pixel data for @c sprite (either 0 or 1),
|
||||
/// with @c delay being either 0 or 1 to indicate whether
|
||||
/// output should begin now or in one pixel's time.
|
||||
template <int sprite> void load(
|
||||
uint16_t lsb,
|
||||
uint16_t msb,
|
||||
int delay);
|
||||
|
||||
/// Shifts two pixels.
|
||||
void shift() {
|
||||
data_ <<= 8;
|
||||
data_ |= overflow_;
|
||||
overflow_ = 0;
|
||||
}
|
||||
|
||||
/// @returns The next two pixels to output, formulated as
|
||||
/// abcd efgh where ab and ef are two pixels of the first sprite
|
||||
/// and cd and gh are two pixels of the second. In each case the
|
||||
/// more significant two are output first.
|
||||
uint8_t get() {
|
||||
return uint8_t(data_ >> 56);
|
||||
}
|
||||
|
||||
private:
|
||||
uint64_t data_;
|
||||
uint8_t overflow_;
|
||||
};
|
||||
|
||||
|
||||
}
|
||||
|
||||
#endif /* Sprites_hpp */
|
||||
@@ -9,12 +9,12 @@
|
||||
#include "AmstradCPC.hpp"
|
||||
|
||||
#include "Keyboard.hpp"
|
||||
#include "FDC.hpp"
|
||||
|
||||
#include "../../Processors/Z80/Z80.hpp"
|
||||
|
||||
#include "../../Components/6845/CRTC6845.hpp"
|
||||
#include "../../Components/8255/i8255.hpp"
|
||||
#include "../../Components/8272/i8272.hpp"
|
||||
#include "../../Components/AY38910/AY38910.hpp"
|
||||
|
||||
#include "../Utility/MemoryFuzzer.hpp"
|
||||
@@ -24,6 +24,7 @@
|
||||
#include "../MachineTypes.hpp"
|
||||
|
||||
#include "../../Storage/Tape/Tape.hpp"
|
||||
#include "../../Storage/Tape/Parsers/Spectrum.hpp"
|
||||
|
||||
#include "../../ClockReceiver/ForceInline.hpp"
|
||||
#include "../../Outputs/Speaker/Implementation/LowpassSpeaker.hpp"
|
||||
@@ -31,6 +32,8 @@
|
||||
|
||||
#include "../../Analyser/Static/AmstradCPC/Target.hpp"
|
||||
|
||||
#include "../../Numeric/CRC.hpp"
|
||||
|
||||
#include <array>
|
||||
#include <cstdint>
|
||||
#include <vector>
|
||||
@@ -155,7 +158,7 @@ class AYDeferrer {
|
||||
private:
|
||||
Concurrency::DeferringAsyncTaskQueue audio_queue_;
|
||||
GI::AY38910::AY38910<true> ay_;
|
||||
Outputs::Speaker::LowpassSpeaker<GI::AY38910::AY38910<true>> speaker_;
|
||||
Outputs::Speaker::PullLowpass<GI::AY38910::AY38910<true>> speaker_;
|
||||
HalfCycles cycles_since_update_;
|
||||
};
|
||||
|
||||
@@ -673,37 +676,6 @@ class KeyboardState: public GI::AY38910::PortHandler {
|
||||
};
|
||||
};
|
||||
|
||||
/*!
|
||||
Wraps the 8272 so as to provide proper clocking and RPM counts, and just directly
|
||||
exposes motor control, applying the same value to all drives.
|
||||
*/
|
||||
class FDC: public Intel::i8272::i8272 {
|
||||
private:
|
||||
Intel::i8272::BusHandler bus_handler_;
|
||||
|
||||
public:
|
||||
FDC() : i8272(bus_handler_, Cycles(8000000)) {
|
||||
emplace_drive(8000000, 300, 1);
|
||||
set_drive(1);
|
||||
}
|
||||
|
||||
void set_motor_on(bool on) {
|
||||
get_drive().set_motor_on(on);
|
||||
}
|
||||
|
||||
void select_drive(int) {
|
||||
// TODO: support more than one drive. (and in set_disk)
|
||||
}
|
||||
|
||||
void set_disk(std::shared_ptr<Storage::Disk::Disk> disk, int) {
|
||||
get_drive().set_disk(disk);
|
||||
}
|
||||
|
||||
void set_activity_observer(Activity::Observer *observer) {
|
||||
get_drive().set_activity_observer(observer, "Drive 1", true);
|
||||
}
|
||||
};
|
||||
|
||||
/*!
|
||||
Provides the mechanism of receipt for input and output of the 8255's various ports.
|
||||
*/
|
||||
@@ -815,45 +787,43 @@ template <bool has_fdc> class ConcreteMachine:
|
||||
ay_.ay().set_port_handler(&key_state_);
|
||||
|
||||
// construct the list of necessary ROMs
|
||||
const std::string machine_name = "AmstradCPC";
|
||||
std::vector<ROMMachine::ROM> required_roms = {
|
||||
ROMMachine::ROM(machine_name, "the Amstrad Disk Operating System", "amsdos.rom", 16*1024, 0x1fe22ecd)
|
||||
};
|
||||
std::string model_number;
|
||||
uint32_t crcs[2];
|
||||
bool has_amsdos = false;
|
||||
ROM::Name firmware, basic;
|
||||
|
||||
switch(target.model) {
|
||||
default:
|
||||
model_number = "6128";
|
||||
has_128k_ = true;
|
||||
crcs[0] = 0x0219bb74;
|
||||
crcs[1] = 0xca6af63d;
|
||||
break;
|
||||
case Analyser::Static::AmstradCPC::Target::Model::CPC464:
|
||||
model_number = "464";
|
||||
has_128k_ = false;
|
||||
crcs[0] = 0x815752df;
|
||||
crcs[1] = 0x7d9a3bac;
|
||||
firmware = ROM::Name::CPC464Firmware;
|
||||
basic = ROM::Name::CPC464BASIC;
|
||||
break;
|
||||
case Analyser::Static::AmstradCPC::Target::Model::CPC664:
|
||||
model_number = "664";
|
||||
has_128k_ = false;
|
||||
crcs[0] = 0x3f5a6dc4;
|
||||
crcs[1] = 0x32fee492;
|
||||
firmware = ROM::Name::CPC664Firmware;
|
||||
basic = ROM::Name::CPC664BASIC;
|
||||
has_amsdos = true;
|
||||
break;
|
||||
default:
|
||||
firmware = ROM::Name::CPC6128Firmware;
|
||||
basic = ROM::Name::CPC6128BASIC;
|
||||
has_amsdos = true;
|
||||
break;
|
||||
}
|
||||
required_roms.emplace_back(machine_name, "the CPC " + model_number + " firmware", "os" + model_number + ".rom", 16*1024, crcs[0]);
|
||||
required_roms.emplace_back(machine_name, "the CPC " + model_number + " BASIC ROM", "basic" + model_number + ".rom", 16*1024, crcs[1]);
|
||||
|
||||
// fetch and verify the ROMs
|
||||
const auto roms = rom_fetcher(required_roms);
|
||||
|
||||
for(std::size_t index = 0; index < roms.size(); ++index) {
|
||||
auto &data = roms[index];
|
||||
if(!data) throw ROMMachine::Error::MissingROMs;
|
||||
roms_[index] = std::move(*data);
|
||||
roms_[index].resize(16384);
|
||||
ROM::Request request = ROM::Request(firmware) && ROM::Request(basic);
|
||||
if(has_amsdos) {
|
||||
request = request && ROM::Request(ROM::Name::AMSDOS);
|
||||
}
|
||||
|
||||
// Fetch and verify the ROMs.
|
||||
auto roms = rom_fetcher(request);
|
||||
if(!request.validate(roms)) {
|
||||
throw ROMMachine::Error::MissingROMs;
|
||||
}
|
||||
|
||||
if(has_amsdos) {
|
||||
roms_[ROMType::AMSDOS] = roms.find(ROM::Name::AMSDOS)->second;
|
||||
}
|
||||
roms_[ROMType::OS] = roms.find(firmware)->second;
|
||||
roms_[ROMType::BASIC] = roms.find(basic)->second;
|
||||
|
||||
// Establish default memory map
|
||||
upper_rom_is_paged_ = true;
|
||||
upper_rom_ = ROMType::BASIC;
|
||||
@@ -915,6 +885,59 @@ template <bool has_fdc> class ConcreteMachine:
|
||||
uint16_t address = cycle.address ? *cycle.address : 0x0000;
|
||||
switch(cycle.operation) {
|
||||
case CPU::Z80::PartialMachineCycle::ReadOpcode:
|
||||
|
||||
// TODO: just capturing byte reads as below doesn't seem to do that much in terms of acceleration;
|
||||
// I'm not immediately clear whether that's just because the machine still has to sit through
|
||||
// pilot tone in real time, or just that almost no software uses the ROM loader.
|
||||
if(use_fast_tape_hack_ && address == tape_read_byte_address && read_pointers_[0] == roms_[ROMType::OS].data()) {
|
||||
using Parser = Storage::Tape::ZXSpectrum::Parser;
|
||||
Parser parser(Parser::MachineType::AmstradCPC);
|
||||
|
||||
const auto speed = read_pointers_[tape_speed_value_address >> 14][tape_speed_value_address & 16383];
|
||||
parser.set_cpc_read_speed(speed);
|
||||
|
||||
// Seed with the current pulse; the CPC will have finished the
|
||||
// preceding symbol and be a short way into the pulse that should determine the
|
||||
// first bit of this byte.
|
||||
parser.process_pulse(tape_player_.get_current_pulse());
|
||||
const auto byte = parser.get_byte(tape_player_.get_tape());
|
||||
auto flags = z80_.get_value_of_register(CPU::Z80::Register::Flags);
|
||||
|
||||
if(byte) {
|
||||
// In A ROM-esque fashion, begin the first pulse after the final one
|
||||
// that was just consumed.
|
||||
tape_player_.complete_pulse();
|
||||
|
||||
// Update in-memory CRC.
|
||||
auto crc_value =
|
||||
uint16_t(
|
||||
read_pointers_[tape_crc_address >> 14][tape_crc_address & 16383] |
|
||||
(read_pointers_[(tape_crc_address+1) >> 14][(tape_crc_address+1) & 16383] << 8)
|
||||
);
|
||||
|
||||
tape_crc_.set_value(crc_value);
|
||||
tape_crc_.add(*byte);
|
||||
crc_value = tape_crc_.get_value();
|
||||
|
||||
write_pointers_[tape_crc_address >> 14][tape_crc_address & 16383] = uint8_t(crc_value);
|
||||
write_pointers_[(tape_crc_address+1) >> 14][(tape_crc_address+1) & 16383] = uint8_t(crc_value >> 8);
|
||||
|
||||
// Indicate successful byte read.
|
||||
z80_.set_value_of_register(CPU::Z80::Register::A, *byte);
|
||||
flags |= CPU::Z80::Flag::Carry;
|
||||
} else {
|
||||
// TODO: return tape player to previous state and decline to serve.
|
||||
z80_.set_value_of_register(CPU::Z80::Register::A, 0);
|
||||
flags &= ~CPU::Z80::Flag::Carry;
|
||||
}
|
||||
z80_.set_value_of_register(CPU::Z80::Register::Flags, flags);
|
||||
|
||||
// RET.
|
||||
*cycle.value = 0xc9;
|
||||
break;
|
||||
}
|
||||
[[fallthrough]];
|
||||
|
||||
case CPU::Z80::PartialMachineCycle::Read:
|
||||
*cycle.value = read_pointers_[address >> 14][address & 16383];
|
||||
break;
|
||||
@@ -965,6 +988,7 @@ template <bool has_fdc> class ConcreteMachine:
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
case CPU::Z80::PartialMachineCycle::Input:
|
||||
// Default to nothing answering
|
||||
*cycle.value = 0xff;
|
||||
@@ -1062,6 +1086,7 @@ template <bool has_fdc> class ConcreteMachine:
|
||||
// If there are any tapes supplied, use the first of them.
|
||||
if(!media.tapes.empty()) {
|
||||
tape_player_.set_tape(media.tapes.front());
|
||||
set_use_fast_tape_hack();
|
||||
}
|
||||
|
||||
// Insert up to four disks.
|
||||
@@ -1089,12 +1114,12 @@ template <bool has_fdc> class ConcreteMachine:
|
||||
return Utility::TypeRecipient<CharacterMapper>::can_type(c);
|
||||
}
|
||||
|
||||
HalfCycles get_typer_delay() const final {
|
||||
HalfCycles get_typer_delay(const std::string &) const final {
|
||||
return z80_.get_is_resetting() ? Cycles(3'400'000) : Cycles(0);
|
||||
}
|
||||
|
||||
HalfCycles get_typer_frequency() const final {
|
||||
return Cycles(80'000); // Perform one key transition per frame.
|
||||
return Cycles(160'000); // Perform one key transition per frame and a half.
|
||||
}
|
||||
|
||||
// See header; sets a key as either pressed or released.
|
||||
@@ -1114,18 +1139,22 @@ template <bool has_fdc> class ConcreteMachine:
|
||||
// MARK: - Activity Source
|
||||
void set_activity_observer([[maybe_unused]] Activity::Observer *observer) final {
|
||||
if constexpr (has_fdc) fdc_.set_activity_observer(observer);
|
||||
tape_player_.set_activity_observer(observer);
|
||||
}
|
||||
|
||||
// MARK: - Configuration options.
|
||||
std::unique_ptr<Reflection::Struct> get_options() final {
|
||||
auto options = std::make_unique<Options>(Configurable::OptionsType::UserFriendly);
|
||||
options->output = get_video_signal_configurable();
|
||||
options->quickload = allow_fast_tape_hack_;
|
||||
return options;
|
||||
}
|
||||
|
||||
void set_options(const std::unique_ptr<Reflection::Struct> &str) {
|
||||
const auto options = dynamic_cast<Options *>(str.get());
|
||||
set_video_signal_configurable(options->output);
|
||||
allow_fast_tape_hack_ = options->quickload;
|
||||
set_use_fast_tape_hack();
|
||||
}
|
||||
|
||||
// MARK: - Joysticks
|
||||
@@ -1188,7 +1217,7 @@ template <bool has_fdc> class ConcreteMachine:
|
||||
i8255PortHandler i8255_port_handler_;
|
||||
Intel::i8255::i8255<i8255PortHandler> i8255_;
|
||||
|
||||
FDC fdc_;
|
||||
Amstrad::FDC fdc_;
|
||||
HalfCycles time_since_fdc_update_;
|
||||
void flush_fdc() {
|
||||
if constexpr (has_fdc) {
|
||||
@@ -1203,6 +1232,18 @@ template <bool has_fdc> class ConcreteMachine:
|
||||
InterruptTimer interrupt_timer_;
|
||||
Storage::Tape::BinaryTapePlayer tape_player_;
|
||||
|
||||
// By luck these values are the same between the 664 and the 6128;
|
||||
// therefore the has_fdc template flag is sufficient to locate them.
|
||||
static constexpr uint16_t tape_read_byte_address = has_fdc ? 0x2b20 : 0x29b0;
|
||||
static constexpr uint16_t tape_speed_value_address = has_fdc ? 0xb1e7 : 0xbc8f;
|
||||
static constexpr uint16_t tape_crc_address = has_fdc ? 0xb1eb : 0xb8d3;
|
||||
CRC::CCITT tape_crc_;
|
||||
bool use_fast_tape_hack_ = false;
|
||||
bool allow_fast_tape_hack_ = false;
|
||||
void set_use_fast_tape_hack() {
|
||||
use_fast_tape_hack_ = allow_fast_tape_hack_ && tape_player_.has_tape();
|
||||
}
|
||||
|
||||
HalfCycles clock_offset_;
|
||||
HalfCycles crtc_counter_;
|
||||
HalfCycles half_cycles_since_ay_update_;
|
||||
@@ -1219,7 +1260,7 @@ template <bool has_fdc> class ConcreteMachine:
|
||||
ROMType upper_rom_;
|
||||
|
||||
uint8_t *ram_pages_[4];
|
||||
uint8_t *read_pointers_[4];
|
||||
const uint8_t *read_pointers_[4];
|
||||
uint8_t *write_pointers_[4];
|
||||
|
||||
KeyboardState key_state_;
|
||||
|
||||
@@ -29,12 +29,21 @@ class Machine {
|
||||
static Machine *AmstradCPC(const Analyser::Static::Target *target, const ROMMachine::ROMFetcher &rom_fetcher);
|
||||
|
||||
/// Defines the runtime options available for an Amstrad CPC.
|
||||
class Options: public Reflection::StructImpl<Options>, public Configurable::DisplayOption<Options> {
|
||||
class Options:
|
||||
public Reflection::StructImpl<Options>,
|
||||
public Configurable::DisplayOption<Options>,
|
||||
public Configurable::QuickloadOption<Options>
|
||||
{
|
||||
friend Configurable::DisplayOption<Options>;
|
||||
friend Configurable::QuickloadOption<Options>;
|
||||
public:
|
||||
Options(Configurable::OptionsType) : Configurable::DisplayOption<Options>(Configurable::Display::RGB) {
|
||||
Options(Configurable::OptionsType type) :
|
||||
Configurable::DisplayOption<Options>(Configurable::Display::RGB),
|
||||
Configurable::QuickloadOption<Options>(type == Configurable::OptionsType::UserFriendly)
|
||||
{
|
||||
if(needs_declare()) {
|
||||
declare_display_option();
|
||||
declare_quickload_option();
|
||||
limit_enum(&output, Configurable::Display::RGB, Configurable::Display::CompositeColour, -1);
|
||||
}
|
||||
}
|
||||
|
||||
51
Machines/AmstradCPC/FDC.hpp
Normal file
51
Machines/AmstradCPC/FDC.hpp
Normal file
@@ -0,0 +1,51 @@
|
||||
//
|
||||
// FDC.hpp
|
||||
// Clock Signal
|
||||
//
|
||||
// Created by Thomas Harte on 22/03/2021.
|
||||
// Copyright © 2021 Thomas Harte. All rights reserved.
|
||||
//
|
||||
|
||||
#ifndef FDC_h
|
||||
#define FDC_h
|
||||
|
||||
#include "../../Components/8272/i8272.hpp"
|
||||
|
||||
namespace Amstrad {
|
||||
|
||||
/*!
|
||||
Wraps the 8272 so as to provide proper clocking and RPM counts, and just directly
|
||||
exposes motor control, applying the same value to all drives.
|
||||
*/
|
||||
class FDC: public Intel::i8272::i8272 {
|
||||
private:
|
||||
Intel::i8272::BusHandler bus_handler_;
|
||||
|
||||
public:
|
||||
FDC(Cycles clock_rate = Cycles(8000000)) :
|
||||
i8272(bus_handler_, clock_rate)
|
||||
{
|
||||
emplace_drive(clock_rate.as<int>(), 300, 1);
|
||||
set_drive(1);
|
||||
}
|
||||
|
||||
void set_motor_on(bool on) {
|
||||
get_drive().set_motor_on(on);
|
||||
}
|
||||
|
||||
void select_drive(int) {
|
||||
// TODO: support more than one drive. (and in set_disk)
|
||||
}
|
||||
|
||||
void set_disk(std::shared_ptr<Storage::Disk::Disk> disk, int) {
|
||||
get_drive().set_disk(disk);
|
||||
}
|
||||
|
||||
void set_activity_observer(Activity::Observer *observer) {
|
||||
get_drive().set_activity_observer(observer, "Drive 1", true);
|
||||
}
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif /* FDC_h */
|
||||
@@ -151,7 +151,7 @@ const uint16_t *CharacterMapper::sequence_for_character(char character) const {
|
||||
#undef SHIFT
|
||||
#undef X
|
||||
|
||||
return table_lookup_sequence_for_character(key_sequences, sizeof(key_sequences), character);
|
||||
return table_lookup_sequence_for_character(key_sequences, character);
|
||||
}
|
||||
|
||||
bool CharacterMapper::needs_pause_after_key(uint16_t key) const {
|
||||
|
||||
@@ -40,7 +40,7 @@ struct KeyboardMapper: public MachineTypes::MappedKeyboardMachine::KeyboardMappe
|
||||
struct CharacterMapper: public ::Utility::CharacterMapper {
|
||||
const uint16_t *sequence_for_character(char character) const override;
|
||||
|
||||
bool needs_pause_after_reset_all_keys() const override { return false; }
|
||||
bool needs_pause_after_reset_all_keys() const override { return true; }
|
||||
bool needs_pause_after_key(uint16_t key) const override;
|
||||
};
|
||||
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user