1
0
mirror of https://github.com/TomHarte/CLK.git synced 2025-10-25 09:27:01 +00:00

Compare commits

...

405 Commits

Author SHA1 Message Date
Thomas Harte
506b4da6c3 Merge pull request #408 from TomHarte/MixerBalance
Enhances the CompoundSource so that constituents can have different volumes.
2018-04-07 14:32:47 -04:00
Thomas Harte
10f637d2cf Enhances the CompoundSource so that constituents can have different volumes. 2018-04-07 14:30:02 -04:00
Thomas Harte
0bab7c88f0 Merge pull request #407 from TomHarte/NameImplications
Allows the Vic-20 analyser to act on 'NTSC' in a filename.
2018-04-06 20:10:56 -04:00
Thomas Harte
78c612ca17 Adds a missing import, removes a redundant conversion. 2018-04-06 20:07:10 -04:00
Thomas Harte
e1c4035812 Switches away from C strings and allows Vic-20 region inference from filenames. 2018-04-06 17:42:24 -04:00
Thomas Harte
eb6d6c8033 Merge pull request #406 from TomHarte/NewFixes
Tweaks the 'new machine' dialogue for ZX memory size
2018-04-05 22:02:10 -04:00
Thomas Harte
7bf88565ce Resizes to fit all options. 2018-04-05 21:59:19 -04:00
Thomas Harte
ee10155296 Adds advice and withdraws the ZX 64kb option. 2018-04-05 21:57:26 -04:00
Thomas Harte
cc49140f6f Merge pull request #405 from TomHarte/VicFraming
Introduces different clipping zones for NTSC and PAL output.
2018-04-05 21:26:07 -04:00
Thomas Harte
3e846f89a1 Introduces different clipping zones for NTSC and PAL output. 2018-04-05 21:25:19 -04:00
Thomas Harte
5782cab2a0 Minor whitespace fix. 2018-04-05 21:15:25 -04:00
Thomas Harte
8c511e2b76 Merge pull request #404 from TomHarte/ProperShaderSetup
Ensures the SVideo shader gets all proper `enable_vertex_attribute_with_pointer`s.
2018-04-05 21:13:26 -04:00
Thomas Harte
ec72fb3baf Ensures the SVideo shader gets all proper enable_vertex_attribute_with_pointers. 2018-04-05 21:12:28 -04:00
Thomas Harte
bab1440f5c Merge pull request #403 from TomHarte/VicRange
Causes the 6560 to obey `set_sample_volume_range`.
2018-04-05 21:06:09 -04:00
Thomas Harte
60c1da6a66 Causes the 6560 to obey set_sample_volume_range.
Thereby resolves a clipping issue.
2018-04-05 21:04:46 -04:00
Thomas Harte
a849b3f2e4 Merge pull request #402 from TomHarte/AudioCutoff
Ensures artificial audio frequency limits are honoured.
2018-04-05 19:05:48 -04:00
Thomas Harte
dbe3c5c3f8 Ensures artificial frequency limits are honoured. 2018-04-05 18:40:07 -04:00
Thomas Harte
60cf6b3cfd Merge pull request #401 from TomHarte/VideoQuirks
Corrects composite output of the ZX80/81 and the Oric
2018-04-04 19:23:45 -04:00
Thomas Harte
5044aac337 Sizes up default window size better to fit machine selector. 2018-04-04 19:18:22 -04:00
Thomas Harte
36e0cb29c0 Ensures proper propagation of video choice through the Oric. 2018-04-04 19:14:42 -04:00
Thomas Harte
c0b4dd65da Mades the expected video signal usage explicit. 2018-04-04 19:01:18 -04:00
Thomas Harte
d061ea232b Ensures no attempt to compile an SVideo shader without appropriate source. 2018-04-04 19:01:01 -04:00
Thomas Harte
49feca4ddf Merge pull request #400 from TomHarte/NewCrash
Introduces a rudimentary 'new' dialogue for the Mac
2018-04-03 23:24:00 -04:00
Thomas Harte
46b1c57bf4 Enables the titlebar, inexplicably allowing the sheet to obtain focus. 2018-04-03 23:22:26 -04:00
Thomas Harte
eaf1482182 Reverts the once-again-unused document controller. 2018-04-03 23:11:19 -04:00
Thomas Harte
d3418550eb Attempts explicitly to disable promise of saving. 2018-04-03 23:06:48 -04:00
Thomas Harte
3ffa9e2751 Ensures complete machine picker state is preserved. 2018-04-03 23:01:12 -04:00
Thomas Harte
c697dd78f0 Ensures a new machine starts as first responder. 2018-04-03 22:22:39 -04:00
Thomas Harte
7dac791290 Causes the machine picker to show as a sheet.
Albeit with some user experience issues lingering.
2018-04-03 18:47:07 -04:00
Thomas Harte
cde2faeda6 Makes an unsuccessful attempt to show the new machine dialogue as a sheet.
Also corrects the 'open' case versus recent changes.
2018-04-02 23:31:36 -04:00
Thomas Harte
69f520428d Makes a first, ugly attempt at a 'new machine' dialogue for the Mac.
Which has implied getting much more specific about MSX disk drive attachment, and has prompted an excuse to offer the ZX80 with the ZX81 ROM.
2018-04-02 22:42:41 -04:00
Thomas Harte
80c84ddd75 Merge pull request #398 from TomHarte/SVideoOption
Exposes S-Video as a user-selectable option
2018-04-01 13:30:41 -04:00
Thomas Harte
fca8a58b36 Exposes S-Video option in the Mac UI. 2018-04-01 13:29:04 -04:00
Thomas Harte
33084899d0 Provides s-video as a command-line option. 2018-03-31 22:14:34 -04:00
Thomas Harte
7b381a8b6b Merge pull request #397 from TomHarte/Vic20FastTape
Improves Vic-20 fast tape ownership and simplifies memory logic.
2018-03-31 21:05:22 -04:00
Thomas Harte
9c75689a8d Increased verbosity. 2018-03-31 20:58:16 -04:00
Thomas Harte
0ee40e8556 Reintroduces 90% crop for VIC output. 2018-03-31 20:57:45 -04:00
Thomas Harte
8b45377b89 Simplifies storage underlying Vic memory.
In the hope of avoiding non-obvious bugs.
2018-03-31 18:54:40 -04:00
Thomas Harte
f6fb368d88 Allows the fast-tape mechanism to take ownership of tape handling.
Any successful fast tape interaction will now permanently pause the tape until a failed interaction occurs. This may or may not be a good idea.
2018-03-30 21:22:52 -04:00
Thomas Harte
183a5379de Merge pull request #396 from TomHarte/SVideo
Adds support for s-video.
2018-03-30 18:25:28 -04:00
Thomas Harte
912791d3d4 Causes the s-video path correctly to function. 2018-03-30 18:24:18 -04:00
Thomas Harte
163a61dd63 Corrects SVideo-as-composite output; the Atari and Vic-20 now both supply svideo. 2018-03-30 13:16:18 -04:00
Thomas Harte
207d462dbf Attempts to provide an implementation of SVideo support. 2018-03-30 12:41:20 -04:00
Thomas Harte
33281b9d89 Introduces S-Video as a video signal type at the interface level. 2018-03-30 10:25:41 -04:00
Thomas Harte
389979923e Performs update to and satisfaction of Xcode 9.3's preferred warnings. 2018-03-30 10:25:01 -04:00
Thomas Harte
067174965e Merge pull request #395 from TomHarte/TEDEsqueColours
Introduces Vic luminances sourced from the TED manual.
2018-03-30 09:39:02 -04:00
Thomas Harte
286259c83b Adds missing 6560 update hooks. 2018-03-29 20:49:36 -04:00
Thomas Harte
e1aa3e5a7f Imports chrominances from the TED documentation. They seem to apply to the VIC-I also. 2018-03-29 20:04:37 -04:00
Thomas Harte
78e1c2851a Merge pull request #393 from TomHarte/Vic20Faster
Introduces some minor Vic-20 optimisations.
2018-03-27 22:04:40 -04:00
Thomas Harte
0869213c55 Cuts detritus. 2018-03-27 22:00:13 -04:00
Thomas Harte
f3fe16215a Reintroduces options for the Vic-20, now tape loading speed only. 2018-03-27 21:55:43 -04:00
Thomas Harte
ec353ce663 Makes minor Vic-20 optimisations.
Specifically: the 6560 is updated only upon writes (more nuance can arrive), and tape sleeps are observed.
2018-03-27 21:52:52 -04:00
Thomas Harte
b7ff5ef9dd Merge pull request #392 from TomHarte/VicPalette
Tweaks VIC palette, especially PAL.
2018-03-26 21:25:12 -04:00
Thomas Harte
3b26e0a7c5 Tweaks NTSC colour generation. 2018-03-26 21:22:06 -04:00
Thomas Harte
6d464557a0 Reintroduces a warm-up run for the C1540.
That simulates the normal real-life scenario of switching the drive on slightly before the computer, and causes it to function correctly from immediate fast typing on an American Vic.

Also switches a couple of casts within the C1540 to functional style.
2018-03-26 21:06:07 -04:00
Thomas Harte
a776bec46a Tweaks PAL colours for the 6560 to be closer to screenshots found online. 2018-03-26 19:02:16 -04:00
Thomas Harte
a2da51c30b Commutes Vic-20 machine configuration options to its Target. 2018-03-26 19:01:57 -04:00
Thomas Harte
8067bf548a Merge pull request #390 from TomHarte/VicOptions
Ensures the Vic-20 doesn't show the ZX80/81 options panel on macOS.
2018-03-25 16:07:13 -04:00
Thomas Harte
62b0645ed0 Ensures the Vic-20 doesn't show the ZX80/81 options panel on macOS. 2018-03-25 16:04:44 -04:00
Thomas Harte
39a94874ae Merge pull request #389 from TomHarte/VicAnalysis
Strips back Vic-20 static analysis to the bare minimum.
2018-03-25 13:42:59 -04:00
Thomas Harte
e15d6717a1 Strips back Vic-20 static analysis to the bare minimum.
Also corrects an unsafe assumption in fast loading.
2018-03-25 13:37:33 -04:00
Thomas Harte
37ef46e7bb Merge branch 'SDLTravis' of github.com:TomHarte/CLK into SDLTravis 2018-03-23 21:52:27 -04:00
Thomas Harte
70c09b3031 Attempted to draft a travis.yml for SDL. 2018-03-23 21:51:15 -04:00
Thomas Harte
9378fbb0df Attempted to draft a travis.yml for SDL. 2018-03-23 21:40:46 -04:00
Thomas Harte
2118b9c0cd Merge pull request #385 from TomHarte/OricHFE
Corrects nullptr references in the CPC static analyser.
2018-03-23 18:40:13 -04:00
Thomas Harte
d0c53de250 Corrects nullptr references in the CPC static analyser. 2018-03-23 18:39:37 -04:00
Thomas Harte
d98507eab0 Merge pull request #384 from TomHarte/PlentifulIcons
Fills out the application icon set.
2018-03-23 18:33:02 -04:00
Thomas Harte
760c75103e Fills out the application icon set. 2018-03-23 18:29:18 -04:00
Thomas Harte
4407fd2f1f Merge pull request #383 from TomHarte/D64Crash
Ensures the rom fetcher is properly provided to the C1540.
2018-03-23 18:22:37 -04:00
Thomas Harte
7fcd243be0 Ensures the rom fetcher is properly recorded for potential provision to the C1540. 2018-03-23 18:20:17 -04:00
Thomas Harte
3165e9d82e Merge pull request #382 from TomHarte/Headers
Introduces missing #includes.
2018-03-23 18:08:55 -04:00
Thomas Harte
6656a08c60 Introduces missing #includes. 2018-03-23 18:05:51 -04:00
Thomas Harte
76661c0b51 Merge pull request #375 from TomHarte/UndefinedBehaviour
Resolves various pieces of undefined behaviour.
2018-03-22 22:01:19 -04:00
Thomas Harte
3bb496f9ae Enforces a maximum sector size to avoid impossible sizes.
Such as 128 * 2^255.
2018-03-22 22:00:26 -04:00
Thomas Harte
45be1c19df Resolves undefined behaviour of a signed shift left. 2018-03-22 21:59:39 -04:00
Thomas Harte
a301964bd0 Ensures all audio queues are fully merged before machine destruction.
Thereby avoids a race condition.
2018-03-22 21:59:19 -04:00
Thomas Harte
eea6858121 Resolves undefined behaviour from uninitialised limited-range values. 2018-03-22 21:58:42 -04:00
Thomas Harte
2a320fdf56 Merge pull request #374 from TomHarte/HFEFixup
Corrects two errors in all-machine HFE offering.
2018-03-22 20:24:24 -04:00
Thomas Harte
4695296ef2 Corrects bit mask for offering HFE around. 2018-03-22 20:23:39 -04:00
Thomas Harte
0fdbbeca1d Ensures the Commodore parser properly rejects non-GCR disks. 2018-03-22 20:23:21 -04:00
Thomas Harte
34cc39ad65 Merge pull request #373 from TomHarte/SpeakerCritical
Moves all LowpassSpeaker delegate calls outside of critical sections.
2018-03-22 20:07:20 -04:00
Thomas Harte
3d0c832a21 Moves all LowpassSpeaker delegate calls outside of critical sections. 2018-03-22 19:01:20 -04:00
Thomas Harte
1acdab9448 Expanded potential HFE targets to everything other than the MSX.
The MSX does not yet perform any sanity checks on disks. That's TODO.
2018-03-22 18:55:52 -04:00
Thomas Harte
93e85c5c4a The CPC now accepts disks only if it can make sense of them. 2018-03-22 18:52:43 -04:00
Thomas Harte
ab98189d25 Merge pull request #372 from TomHarte/MultiJoystick
Implements multimachine joystick support.
2018-03-22 11:09:38 -04:00
Thomas Harte
cd0fb7624b Pulls delegate messages out of the critical sections. 2018-03-22 11:08:07 -04:00
Thomas Harte
bae38497bb Implements multitarget joysticks. 2018-03-22 11:07:52 -04:00
Thomas Harte
29921bfa8d Merge pull request #371 from TomHarte/NanosecondMachines
Devolves time -> clock rate mapping to machines.
2018-03-22 10:08:58 -04:00
Thomas Harte
2712702461 Makes get_clock_rate protected. It's now an implementation detail. 2018-03-22 10:01:18 -04:00
Thomas Harte
a3fa9440d1 Renames method better to communicate purpose. 2018-03-22 09:49:36 -04:00
Thomas Harte
6419b0e619 Reintroduces CSMachineDelegate, allowing the Mac port to switch output audio rate dynamically. 2018-03-22 09:48:19 -04:00
Thomas Harte
58e5b6e3f1 Updates SDL kiosk mode to the death of CRTMachineDelegate. 2018-03-22 09:23:27 -04:00
Thomas Harte
682c3d8079 Adds new hook for watching audio output rate changes. 2018-03-22 09:23:01 -04:00
Thomas Harte
da3d65c18f Devolves time to cycle conversion to machines.
Thereby avoids a whole bunch of complicated machinations that would otherwise have been required of the multimachine.
2018-03-21 22:18:13 -04:00
Thomas Harte
ece3a05504 Merge pull request #370 from TomHarte/OricDiskDetection
Causes the Oric properly to evaluate disks offered to it.
2018-03-21 20:51:12 -04:00
Thomas Harte
927697b0f0 Causes the Oric properly to evaluate disks offered to it. 2018-03-21 20:48:21 -04:00
Thomas Harte
74dfc80b0f Merge pull request #369 from TomHarte/AnalyserUnion
Encapsulates per-platform analyser result fields.
2018-03-09 16:13:17 -05:00
Thomas Harte
a7f229bc4b Adds missing files. 2018-03-09 16:10:17 -05:00
Thomas Harte
89bec2919f Encapsulates machine configuration properties for all remaining platforms. 2018-03-09 16:07:29 -05:00
Thomas Harte
78eaecb29e Provides the proper framework for encapsulation of analyser target specifics.
... while making them a safe container for objects too. Uses the ZX80/81 as the pilot platform.
2018-03-09 15:36:11 -05:00
Thomas Harte
d410aea856 Merge pull request #368 from TomHarte/DiamondInheritance
Eliminates diamond inheritance of KeyboardMachine::Machine by typers.
2018-03-09 15:19:54 -05:00
Thomas Harte
6b1eef572b Eliminates diamond inheritance of KeyboardMachine::Machine by typers.
Specifically by pulling the key action stuff into a purely abstract class [/interface]. Takes the opportunity to unpublish a bunch of machine details.
2018-03-09 15:19:02 -05:00
Thomas Harte
719f5d79c2 Merge pull request #367 from TomHarte/DynamicVolume
Introduces formal setting of the output volume to `SampleSource`.
2018-03-09 14:10:55 -05:00
Thomas Harte
48737a32a7 Introduces formal setting of the output volume to SampleSource.
Previously every output device was making its own decision. Which is increasingly less sustainable due to the CompoundSource.
2018-03-09 13:23:18 -05:00
Thomas Harte
53f05efb2d Merge pull request #366 from TomHarte/MoreMemptr
Improves Z80 memptr behaviour.
2018-03-09 10:05:57 -05:00
Thomas Harte
0e73ba4b3e Introduces proper 5/3 SCF/CCF behaviour for the Z80.
While also `const`ing a bunch of things.
2018-03-09 09:47:00 -05:00
Thomas Harte
f0f9d5a6af Corrects memptr leakage via BIT, and ld (de/bc/nn), A behaviour. 2018-03-08 20:30:22 -05:00
Thomas Harte
03501df9e5 Merge pull request #365 from TomHarte/CartridgeDetermination
Works towards eliminating the special cases for Atari 2600 ROM handling.
2018-03-08 18:40:58 -05:00
Thomas Harte
dd6f85d4db Merge pull request #364 from TomHarte/TimingUpfront
Ensures the Coleco & MSX account for instruction lengths prior to outward accesses.
2018-03-07 17:29:32 -05:00
Thomas Harte
1804ea6849 Ensures the ColecoVision and MSX account for instruction lengths in advance when timing secondary components. 2018-03-07 17:00:18 -05:00
Thomas Harte
c8657e08f4 Merge remote-tracking branch 'origin/master' into CartridgeDetermination 2018-03-07 16:42:16 -05:00
Thomas Harte
a942e1319b Merge pull request #363 from TomHarte/ZonX
Introduces ZonX emulation and corrects a minor ColecoVision AY timing issue.
2018-03-07 16:23:51 -05:00
Thomas Harte
9e0a56b4f0 Withdraws the 2600 from .rom consideration.
Will return when it is performing more sanity checks; for the time being I don't want it constantly forcing multimachines.
2018-03-07 16:21:17 -05:00
Thomas Harte
9abc020818 Corrects potential ColecoVision SGM AY timing issues. 2018-03-07 16:16:58 -05:00
Thomas Harte
2dade8d353 Introduces ZonX emulation for the ZX81. 2018-03-07 16:16:29 -05:00
Thomas Harte
1100dc6993 Opens up .bin and .rom to all cartridge platforms, and adds a confidence estimate to the Atari 2600. 2018-03-07 14:26:07 -05:00
Thomas Harte
f212b18511 Declares a confidence for the ColecoVision equal to the probability that the special bytes are wrong. 2018-03-07 14:25:25 -05:00
Thomas Harte
a6ca69550f Standardises machines that aren't making a real guess on reporting a confidence of 0.5. 2018-03-07 14:24:52 -05:00
Thomas Harte
2452641844 Introduces a fast workaround to avert a MultiMachine where it would instantly end. 2018-03-06 19:08:02 -05:00
Thomas Harte
c82af4b814 Introduces get_confidence for the ColecoVision.
Based almost entirely on joypad accesses for now.
2018-03-06 19:06:35 -05:00
Thomas Harte
fdef914137 Corrects test target regression. 2018-03-06 18:32:21 -05:00
Thomas Harte
dfcc502a88 Merge pull request #360 from TomHarte/SDLJoystick
Introduces keyboard-as-joystick fallback for the SDL target.
2018-03-04 17:28:05 -05:00
Thomas Harte
1c6faaae88 Introduces keyboard-as-joystick fallback for the SDL target. 2018-03-04 17:26:32 -05:00
Thomas Harte
35c8a0dd8c Merge pull request #359 from TomHarte/MentionColecoVision
Adds the ColecoVision to the declared list of machines.
2018-03-03 19:05:05 -05:00
Thomas Harte
38feedaf6a Adds the ColecoVision. 2018-03-03 19:03:54 -05:00
Thomas Harte
0a2f908af4 Merge pull request #358 from TomHarte/TMSPhase
Picks a phase for the TMS empirically.
2018-03-03 13:56:10 -05:00
Thomas Harte
705d53cc21 Picks a phase for the TMS empirically. 2018-03-03 13:53:00 -05:00
Thomas Harte
35b18d58af Merge pull request #357 from TomHarte/SuperGameModule
Adds Super Game Module support for the ColecoVision.
2018-03-03 13:14:48 -05:00
Thomas Harte
3c5a8d9ff3 Adds Super Game Module support for the ColecoVision. 2018-03-03 13:08:33 -05:00
Thomas Harte
7ca02be578 Merge pull request #356 from TomHarte/Multicolour
Implements multicolour mode on the TMS.
2018-03-02 23:10:31 -05:00
Thomas Harte
ea13c7dd32 Implements multicolour mode on the TMS. 2018-03-02 23:08:01 -05:00
Thomas Harte
fdfd72a42c Merge pull request #355 from TomHarte/MegaCart
Adds MegaCart support for the ColecoVision.
2018-03-02 19:21:26 -05:00
Thomas Harte
da97bf95c0 Loosens ColecoVision cartridge size test to allow for slightly broken images. 2018-03-02 19:20:37 -05:00
Thomas Harte
bdfc36427c Implements MegaCart support. 2018-03-02 18:40:01 -05:00
Thomas Harte
74dfe56d2b Expands documentation of NMI setting.
Given that it was previously incorrect, explains logic behind request_status_ and last_request_status_ setting. Also takes the opportunity to ensure that NMI is 'sampled' at the same time as IRQ; whether the next thing should be the NMI routine now occurs one cycle before the end of any instruction. That's an assumption for now. Testing to come.
2018-03-02 11:10:02 -05:00
Thomas Harte
6cce9aa54e Merge pull request #353 from TomHarte/ColecoVision
Adds provisional emulation of the ColecoVision
2018-03-01 22:33:34 -05:00
Thomas Harte
ba68b7247b Adds latest files to SConstruct. 2018-03-01 22:19:50 -05:00
Thomas Harte
b02e4fbbf6 Corrects NMI receipt to be genuinely edge triggered.
Previously a caller that signalled NMI set multiple times would trigger multiple NMIs.
2018-03-01 22:04:56 -05:00
Thomas Harte
59b4c7314d Merge branch 'master' into ColecoVision 2018-03-01 22:01:26 -05:00
Thomas Harte
d328589bd0 Merge pull request #354 from TomHarte/MSXTiming
Corrects a counting error in the MSX.
2018-03-01 22:00:53 -05:00
Thomas Harte
b05d2b26bf Corrects a counting error in the MSX. 2018-03-01 21:59:51 -05:00
Thomas Harte
86239469e7 Allows SN76489 consumers to apply an additional divider that reduces computation. 2018-03-01 18:51:05 -05:00
Thomas Harte
7890506b16 Gives the SN76489 its proper dividers and personalities. 2018-02-28 22:36:03 -05:00
Thomas Harte
83f73c3f02 Installs additional safeguards against unsafe deconstruction. 2018-02-28 22:15:22 -05:00
Thomas Harte
87760297fc Fixes underpumping of SN76489.
Audio works now. Though I still need properly to confirm who owns dividers in practice. I think probably all division should be within the SN.
2018-02-27 22:59:29 -05:00
Thomas Harte
5b854d51e7 Corrects out-of-bounds access. 2018-02-27 22:45:45 -05:00
Thomas Harte
d4df101ab6 Makes a first attempt at implementing the SN76489. 2018-02-27 22:25:12 -05:00
Thomas Harte
0ad2676640 Adds a class for the SN76489 and wires it into the ColecoVision. 2018-02-26 22:04:34 -05:00
Thomas Harte
a074ee2071 Possibly fixes ColecoVision input mapping.
Also provides symbolic input from the Mac.
2018-02-25 22:47:47 -05:00
Thomas Harte
204d5cc964 Extends JoystickMachine protocol to cover ColecoVision use case.
Also thereby implements input on the ColecoVision, in theory at least. No input is being fed though, so...
2018-02-25 19:08:50 -05:00
Thomas Harte
23d15a4d6c The ColecoVision now accepts and loads cartridges. 2018-02-24 18:26:44 -05:00
Thomas Harte
23c47e21de Proceeds the ColecoVision to booting. 2018-02-24 18:14:38 -05:00
Thomas Harte
5530b96446 Wired up a class and analyser for a ColecoVision. 2018-02-23 22:47:15 -05:00
Thomas Harte
99d28a172b Merge pull request #352 from TomHarte/TZXCompletion
Makes an attempt at implementing all missing TZX 1.20 blocks.
2018-02-22 21:37:46 -05:00
Thomas Harte
d83178f29d Makes an attempt at implementing all missing TZX 1.20 blocks.
Towards that aim, simplifies CSW handling so that even regular RLE compression uses a static grab of file contents.
2018-02-22 21:28:12 -05:00
Thomas Harte
d9d5ffdaa2 Merge pull request #351 from TomHarte/TMSFlip
Optimises the inner TMS loops slightly.
2018-02-21 21:33:04 -05:00
Thomas Harte
cabad6fc05 Optimises the inner TMS loops slightly. 2018-02-21 21:29:17 -05:00
Thomas Harte
a4dc9c0403 Merge pull request #350 from TomHarte/MinorMSXOptimisations
Introduces modest MSX optimisations
2018-02-19 20:53:20 -05:00
Thomas Harte
270723ae72 Forces the MSX's perform_machine_cycle into the Z80. 2018-02-19 19:54:42 -05:00
Thomas Harte
b215cf83d5 Eliminates implicit update queue flush, as unnecessary. 2018-02-19 19:54:18 -05:00
Thomas Harte
f237dcf904 Avoids deadlock when one bestEffortUpdate action implies another. 2018-02-19 18:44:12 -05:00
Thomas Harte
fc81bfa59b Eliminates tape player call when tape is not playing. 2018-02-19 18:36:31 -05:00
Thomas Harte
832ac173ae Merge pull request #349 from TomHarte/CheaperTapeChecks
Reduces cost of checking for fast-tape usage
2018-02-19 16:58:03 -05:00
Thomas Harte
3673cfe9be Pulls method call for tape fast loading checks out of inner loop for the Vic, Electron and ZX80/81. 2018-02-19 16:57:24 -05:00
Thomas Harte
6aaef97158 Breaks Mac machine shutdown deadlock. 2018-02-19 16:48:03 -05:00
Thomas Harte
b0ab617393 Simplifies inner loop test for MSX fast loading. 2018-02-19 16:24:47 -05:00
Thomas Harte
6780b0bf11 Corrects error preventing fast loading preference from making it to machines on the Mac. 2018-02-19 16:24:28 -05:00
Thomas Harte
9c0a440c38 Merge pull request #347 from TomHarte/DynamicAnalysis
Introduces dynamic selection of MSX MegaROM type
2018-02-19 16:10:46 -05:00
Thomas Harte
2439f5aee5 Corrects some whitespace errors. 2018-02-19 16:06:46 -05:00
Thomas Harte
8265f289bd Improves documentation within the new parts. 2018-02-19 16:03:17 -05:00
Thomas Harte
9728bea0a7 Updates scons file and corrects missing headers; backports to C++11. 2018-02-19 05:13:41 -08:00
Thomas Harte
fc9e84c72e Eliminates unsafe optimisation.
Also likely to be unhelpful as and when multiple machines are in play.
2018-02-18 22:09:27 -05:00
Thomas Harte
7d75e864b1 Ensures thread safety of usages of bestEffortLock. 2018-02-18 22:09:03 -05:00
Thomas Harte
a005dabbe3 Corrects some minor outstanding data races. 2018-02-18 16:37:07 -05:00
Thomas Harte
c8a4432c63 Makes an attempt to transfer audio outputs during dynamic analysis. 2018-02-18 15:23:15 -05:00
Thomas Harte
7b420d56e3 Removed state mirroring in the machine-specific Mac UI classes. 2018-02-14 21:46:50 -05:00
Thomas Harte
ddf1bf3cbf Reintroduces options selection for the Mac.
For everything except the Vic-20, anyway. That has a somewhat outdated notion of what an options panel should be, corresponding to the work yet to do on its analyser.
2018-02-12 21:46:21 -05:00
Thomas Harte
7ea4ca00dc Ensures perform_parallel doesn't lock up if all machines complete prior to reaching condition.wait. 2018-02-11 21:06:51 -05:00
Thomas Harte
6b8c223804 Adds an extra termination condition for the multimachine. 2018-02-11 21:05:59 -05:00
Thomas Harte
23105956d6 Fixes spurious unrecognised miss detection for the ASCII mappers. 2018-02-11 20:51:39 -05:00
Thomas Harte
d751b7e2cb Marginally reformats for current style. 2018-02-11 20:32:59 -05:00
Thomas Harte
f02989649c Corrects effect of pc_is_outside_bios. 2018-02-11 20:32:45 -05:00
Thomas Harte
dcf313a833 Changes equivocal semantics. 2018-02-11 20:32:21 -05:00
Thomas Harte
9960121b08 Introduces an exit condition for the multi machine. 2018-02-11 20:24:08 -05:00
Thomas Harte
8eea55b51c Simplifies perform_parallel slightly. 2018-02-10 23:39:30 -05:00
Thomas Harte
e1cab52c84 Ensures thread safety of access to machines array. 2018-02-10 19:38:26 -05:00
Thomas Harte
eb39617ad0 Allows cartridges to filter based on the actor talking to them; corrects outstanding_machines access error. 2018-02-10 17:11:16 -05:00
Thomas Harte
43b682a5af Adds multiple target versions of all the DynamicMachine-vended types. 2018-02-09 16:31:05 -05:00
Thomas Harte
043fd5d404 Merge branch 'DynamicAnalysis' of github.com:TomHarte/CLK into DynamicAnalysis 2018-02-09 09:12:05 -05:00
Thomas Harte
d63a95983d Adds a couple of hard-stop conditions to the MSX, and respect for hard stops. 2018-02-09 09:10:56 -05:00
Thomas Harte
4cf258f952 Parallelises MultiMachine running, and ensures errors propagate. 2018-02-08 20:33:57 -05:00
Thomas Harte
4e720d57b2 With debugging hooks still on display, makes first attempt at dynamic analysis. 2018-02-01 07:53:52 -05:00
Thomas Harte
c12aaea747 Attempts to get as far as running the MultiMachine.
In doing so, fixes the long-standing bug that machines that output audio but don't have a listener produce a divide by zero.
2018-01-30 22:23:06 -05:00
Thomas Harte
ca48497e87 Pulls DynamicMachine out of MachineForTarget and adds MultiConfigurationTarget as a first multiplexer. 2018-01-29 21:49:49 -05:00
Thomas Harte
d493ea4bca Introduces a multimachine to handle multi-target static analyser outputs.
Non-functional as of yet.
2018-01-28 22:22:21 -05:00
Thomas Harte
e025674eb2 The MSX analyser is now smart enough not to be definitive when it's uncertain.
The cartridge type has also migrated to being a property of the cartridge, prefiguring my intention to discard the static analyser union.
2018-01-25 22:16:46 -05:00
Thomas Harte
f2519f4fd7 Decided to focus on 'confidence' over 'probability'.
Besides anything else, it individualises the measure. E.g. two targets can each have a confidence of 0.8 without each giving the wrong answer about probability.
2018-01-25 19:02:16 -05:00
Thomas Harte
db914d8c56 Removes redundant second configuration. 2018-01-25 18:50:23 -05:00
Thomas Harte
66faed4008 Gives MachineForTargets complete responsibility for initial machine state. 2018-01-25 18:28:19 -05:00
Thomas Harte
11abc99ef8 Introduces the extra level of indirection necessary to make Analyser::Static::Target polymorphic. 2018-01-24 22:35:54 -05:00
Thomas Harte
21efb32b6f Integrates the static and nascent dynamic analyser namespaces. 2018-01-24 21:48:44 -05:00
Thomas Harte
622a04aec8 Starts stripping the Mac port of its special machine knowledge.
Partly to force myself into moving that stuff into the cross-platform area, but mainly so that dynamic analysis can work equally from day one.
2018-01-24 20:14:15 -05:00
Thomas Harte
d360b2c62d Standardises the static analyser on std::vector and slightly widens passageway to a machine.
The SDL target would now be fooled by a hypothetical multi-target, the Mac not yet.
2018-01-23 22:18:16 -05:00
Thomas Harte
6a112edc18 Corrects 16kb ASCII mapper.
Also increases hit position acceptance for the 8kb ASCII.
2018-01-22 22:13:16 -05:00
Thomas Harte
8fb4409ebb Adds hasty attempt at dynamic analysis to the MSX ROM handlers.
Logging for now, for further experimentation.
2018-01-22 21:50:56 -05:00
Thomas Harte
d213341d9c Introduces the counters upon which I expect dynamic analysis to rest. 2018-01-22 21:39:23 -05:00
Thomas Harte
c2f1306d85 Updates copyright year. 2018-01-18 21:11:30 -05:00
Thomas Harte
2143ea6f12 Merge pull request #344 from TomHarte/MacICON
Introduces an icon for the Mac.
2018-01-18 18:08:44 -08:00
Thomas Harte
edb30b3c6c Introduces an icon for the Mac.
About which I have yet to decide my full feelings.
2018-01-18 21:01:30 -05:00
Thomas Harte
234e4f6f66 Merge pull request #343 from TomHarte/MSXROMs
Allows 8kb and not-quite-multiple-of-8kb MSX ROMs
2018-01-18 16:57:05 -08:00
Thomas Harte
ce2d3c6e82 Resolves implicit conversion warning. 2018-01-17 22:02:16 -05:00
Thomas Harte
46c76b9c07 Switches to using the boilerplate public.item for all macOS UTIs. 2018-01-17 22:01:38 -05:00
Thomas Harte
583c3cfe7d Allows the MSX to load ROMs that aren't quite multiples of 8kb. 2018-01-16 22:27:41 -05:00
Thomas Harte
e13312dcc5 Removed stray new line. 2018-01-16 21:46:31 -05:00
Thomas Harte
d9e49c0d5f Merge pull request #340 from TomHarte/MSXDocs
Adds the MSX to README.md.
2018-01-16 16:47:57 -08:00
Thomas Harte
8a370cc1ac Adds the MSX to README.md. 2018-01-16 19:46:29 -05:00
Thomas Harte
cdae0fa593 Merge pull request #339 from TomHarte/AcornROMs
Allows the Electron to load 8kb ROMs.
2018-01-15 18:28:19 -08:00
Thomas Harte
765c0d4ff8 Allows the Electron to load 8kb ROMs. 2018-01-15 21:27:45 -05:00
Thomas Harte
4cf2e16b5c Merge pull request #338 from TomHarte/MSXComposite
onsolidates Mac presentation of composite video selection.
2018-01-15 15:38:45 -08:00
Thomas Harte
9cbd61e709 Replaces CRT quantity assert with test.
Primarily to handle television/composite target switches that can unsync the buffers.
2018-01-15 18:37:09 -05:00
Thomas Harte
0202c7afb2 Consolidates Mac presentation of composite video selection.
Moves handling of an RGB/composite into `MachinePanel`, eliminating the need for `ElectronOptionsPanel` and `OricOptionsPanel`; similarly merges the MSX and Electron options panels so as to provide television/monitor selection for the MSX.
2018-01-15 18:36:22 -05:00
Thomas Harte
c187c5a637 Merge pull request #337 from TomHarte/DoublePhase
Corrects calculation of intermediate buffer width multiplier.
2018-01-15 13:57:26 -08:00
Thomas Harte
23c34a8c14 Corrects calculation of intermediate buffer width multiplier.
Specifically: I had failed to factor in that the multiplied-up input frequency might be less than than the full width of the bitmap.

The Atari and MSX in particular now look much better.
2018-01-15 16:52:40 -05:00
Thomas Harte
93ece2aec7 "Doubles" the bandwidth given to composite signals.
Because I suspect it may inadvertently have been halved previously. I'm investigating.
2018-01-14 20:44:53 -05:00
Thomas Harte
e12ab8fe2e Merge pull request #336 from TomHarte/TMSGamma
Sets TMS input gamma.
2018-01-13 19:20:32 -08:00
Thomas Harte
2fe0ceb52a Sets TMS input gamma. 2018-01-13 22:19:41 -05:00
Thomas Harte
f354c12c81 Merge pull request #335 from TomHarte/BetterTape
Makes MSX tape parsing more tolerant to phase.
2018-01-10 18:56:44 -08:00
Thomas Harte
def82cba49 Makes MSX tape parsing more tolerant to phase.
Also reintroduces proper file type association for TSX on the Mac.
2018-01-10 21:54:15 -05:00
Thomas Harte
e7bc7b94c9 Merge pull request #334 from TomHarte/DMK
Adds support for the DMK file format
2018-01-09 19:22:00 -08:00
Thomas Harte
aafdff49be Implements the ugly stuff of converting a DMK back to flux. 2018-01-09 22:13:04 -05:00
Thomas Harte
4ef583813a Minor tidying of PCMSegment and Oric MFM DSK. 2018-01-09 22:12:34 -05:00
Thomas Harte
9f97fb738e Merge branch 'master' into DMK 2018-01-09 19:42:27 -05:00
Thomas Harte
4e124047c6 Introduces enough DMK support to progress to failure to parse a track. 2018-01-08 21:57:11 -05:00
Thomas Harte
6eb56a1564 Corrects various comment typos. 2018-01-08 20:55:40 -05:00
Thomas Harte
35fc0a5c16 Corrects assumption of double sidedness. 2018-01-08 09:35:29 -05:00
Thomas Harte
b36c917810 Merge pull request #331 from TomHarte/MSXFloppy
Adds floppy emulation for the MSX
2018-01-07 19:25:11 -08:00
Thomas Harte
a5ac8c824e Removes logging and unnecessary get_drive_is_ready. 2018-01-07 21:59:59 -05:00
Thomas Harte
0ccc104027 Corrects start sector and track interleaving for MSX DSK.
MSX DSKs start with sector 1; Acorn disks still begin with sector 0. Also it turns out that MSX DSKs are indeed interleaved.
2018-01-07 21:59:18 -05:00
Thomas Harte
8be6cb827b Implements MSX interrupt/data request reading register.
The disk ROM now appears to accept on-disk bytes, but still announces an IO failure.
2018-01-07 20:28:34 -05:00
Thomas Harte
2f59226300 Fixes: DiskROM drive motor control, track_for_sectors' sides. 2018-01-07 20:02:40 -05:00
Thomas Harte
793ef68206 Implements unconditional force interrupt for the WD. 2018-01-07 19:42:38 -05:00
Thomas Harte
513c067f94 Makes an attempt to rope in the WD1770 for MSX disk ROM emulation. 2018-01-07 19:12:52 -05:00
Thomas Harte
999a0c22d4 Adds superficial support for MSX .DSK.
In the sense that the file format itself is properly parsed, but the MSX doesn't actually yet have disk hardware.
2018-01-07 16:35:57 -05:00
Thomas Harte
5d0832613f Merge pull request #330 from TomHarte/SCC
Adds emulation of the Konami SCC
2018-01-07 07:14:05 -08:00
Thomas Harte
2ffde4c3c2 Corrects SCC volume errors.
Which were leading to substantial overflow.
2018-01-07 09:59:00 -05:00
Thomas Harte
57ddfcd645 Corrects AY counter type. 2018-01-06 23:16:01 -05:00
Thomas Harte
fc16e8eb8c Makes first attempt at actually implementing the SCC. 2018-01-06 23:15:42 -05:00
Thomas Harte
655b971976 Establishes that there is such as a thing as a Konami SCC.
Creates one, ensures it appears in memory when intended to, lets it handle reads and writes. It currently does nothing.
2018-01-06 20:15:55 -05:00
Thomas Harte
3e1d8ea082 Adds is_silent to SampleSource plus shortcut processing to CompoundSource. 2018-01-06 18:50:26 -05:00
Thomas Harte
772c320d5a Merge pull request #329 from TomHarte/TMSTopLine
Corrects bad TMS sprite selections on the top row of the screen.
2018-01-06 13:26:33 -08:00
Thomas Harte
bcc7ad0c30 Corrects bad TMS sprite selections on the top row of the screen. 2018-01-06 16:26:11 -05:00
Thomas Harte
73b4e1722b Merge pull request #328 from TomHarte/MSXROMs
Introduces a basic attempt at MSX MegaROM support
2018-01-06 12:55:00 -08:00
Thomas Harte
185cd3c123 Expands and documents MSX::MemoryMap and MSX::ROMSlotHandler.
Hopefully to cover all intended use cases.
2018-01-06 15:51:29 -05:00
Thomas Harte
ed564cb810 Implements the main four cartridge banking schemes.
Slightly proof of concept for now.
2018-01-04 22:18:18 -05:00
Thomas Harte
b78ece1f1e Adds an attempt to catch LD (xx), A / [CALL/JP] pairs.
Also corrects use of std::stable_sort. Results are still largely incorrect though.
2018-01-02 22:18:10 -05:00
Thomas Harte
c8367a017f Cleans up test and makes attempt to factor in cartridge type popularity. 2018-01-01 21:21:05 -05:00
Thomas Harte
344a12566b Tweaks a couple of expected cartridge types. 2018-01-01 20:14:56 -05:00
Thomas Harte
c07113ea95 Ensures no illegal accesses while testing MSX ROM type detection.
Specifically: the static analyser doesn't even correctly identify everything that is an MSX ROM yet, let alone then properly determine type.
2018-01-01 17:38:26 -05:00
Thomas Harte
bc2879c412 Corrects the MSX ROM unit test.
I.e. the test is correct now, for those SHAs I could find. The static analyser is still wrong just slightly less than half the time.
2018-01-01 17:35:13 -05:00
Thomas Harte
1d47b55729 Ensures the selected cartridge start address is recorded in the cartridge. 2018-01-01 16:38:49 -05:00
Thomas Harte
db25b4554b Introduces failing tests of the MSX static analyser. 2018-01-01 16:38:26 -05:00
Thomas Harte
05b95ea2e0 Corrects Xcode tests. 2018-01-01 16:04:13 -05:00
Thomas Harte
250f7bf6b0 Makes attempt to support 48kb ROMs. 2018-01-01 11:25:27 -05:00
Thomas Harte
34db35b500 Merge pull request #327 from TomHarte/Z80Disassembler
Introduces a Z80 disassembler.
2017-12-31 18:39:01 -08:00
Thomas Harte
f75590253d Introduces necessary header for std::sort. 2017-12-31 21:36:24 -05:00
Thomas Harte
4f6abc9059 Introduces missing header. 2017-12-31 21:34:35 -05:00
Thomas Harte
c70dbc6a49 Introduces the most basic attempt to guess MSX cartridge type. 2017-12-31 21:23:30 -05:00
Thomas Harte
1c255b9e7d Generalises some of the disassembler, and provides Z80 logic to create a [first attempt at a] Z80 disassembler. 2017-12-31 18:49:35 -05:00
Thomas Harte
188bfa9c18 Merge pull request #326 from TomHarte/TyperTermination
Ensures typers terminate.
2017-12-30 10:49:53 -08:00
Thomas Harte
c7f8f37822 Ensures typers terminate. 2017-12-30 13:46:30 -05:00
Thomas Harte
4a19dbb8cb Merge pull request #325 from TomHarte/ContentTypes
Adds document type UTIs.
2017-12-30 10:41:14 -08:00
Thomas Harte
bf0601123b Adds some document type UTIs.
Will need to survey all the other Mac emulators to get a complete list, I guess.
2017-12-30 13:36:29 -05:00
Thomas Harte
9339f3413f Liberalises the end-of-file test for MSX ASCII.
From: must be back padded with 0x1a to merely must contain 0x1a.
2017-12-29 20:54:10 -05:00
Thomas Harte
c18517be4b Ensures that the fast loading option successfully flows from the Mac interface. 2017-12-29 19:07:22 -05:00
Thomas Harte
eef34adcbd Merge pull request #324 from TomHarte/MSXAnalysis
Introduces basic tape analysis for the MSX
2017-12-29 15:45:21 -08:00
Thomas Harte
769d9dfbb9 Adds missing header. 2017-12-29 18:41:26 -05:00
Thomas Harte
6a0bb83716 Corrects typos in the SDL main. 2017-12-29 18:40:32 -05:00
Thomas Harte
6da8a3e24b Causes the MSX to respond to the appropriate standard configuration options. 2017-12-29 18:36:42 -05:00
Thomas Harte
e349161a53 Rejigs the typing relationship so that use of a typer is not strongly implied by the interface.
Simultaneously implements typing on the MSX by direct insertion into the key buffer.
2017-12-29 18:30:46 -05:00
Thomas Harte
d5b1a9d918 Moves the typer functionality behind a functionality-based naming scheme, eliminates its C-style memory management. 2017-12-29 15:26:03 -05:00
Thomas Harte
76af0228dd Corrects longstanding survival of camel case in the analyser's loadingCommand. 2017-12-29 15:15:29 -05:00
Thomas Harte
2cc1a2684a Introduces [over-]analysis of cassette contents prior to starting the MSX, and simplifies ROM checking.
So a proper loading command is now known.
2017-12-29 15:11:10 -05:00
Thomas Harte
98a9d57c0b Imputes the alignment requirement for CAS headers.
Also stops adding a spurious 0xff as the final byte on the tape.
2017-12-29 10:42:18 -05:00
Thomas Harte
c481293aca Liberalises CAS interpretation.
It seems to be an even weirder file format than I thought; it can contain only ROM-formatted data but seemingly often contains blobs that the ROM cannot write.
2017-12-29 09:56:58 -05:00
Thomas Harte
5fd0a2b9ea Attempts to pull reimplementations of TAPION and TAPIN better into line with originals.
Also improves whole flow of the fast tape hack that uses them.
2017-12-28 22:48:04 -05:00
Thomas Harte
11b73a9c0b Adds preliminary, non-error-checking wiring in of MSX parser alternatives to TAPION and TAPIN.
As both a prototype of the pending fast tape loading, and to provide for exact behaviour comparison.
2017-12-26 22:31:34 -05:00
Thomas Harte
c4950574ea Introduces an attempted reimplementation of the MSX BIOS's two main tape reading entry points. 2017-12-26 22:19:37 -05:00
Thomas Harte
0b297f2972 Adds some appropriate costs to the tape players. 2017-12-26 22:13:28 -05:00
Thomas Harte
f9f870ad2d Merge pull request #323 from TomHarte/MSXCAS
Adds support for the MSX .CAS file format.
2017-12-23 17:00:02 -08:00
Thomas Harte
cbba6a5595 Ensures final few bytes of a CAS file aren't dropped. 2017-12-23 19:54:42 -05:00
Thomas Harte
0a079b0f94 Attempts to fix failure to distinguish end-of-file. 2017-12-23 19:32:24 -05:00
Thomas Harte
9a7e974579 Corrects skipping of every other file, and transition from bytes back into header. 2017-12-23 19:20:04 -05:00
Thomas Harte
f4d414d6e4 Removes stray line break. 2017-12-23 18:42:04 -05:00
Thomas Harte
b4bfcd4279 Switches to an attempt to break the .CAS into files ahead of time.
Hopefully the better to insert appropriate lengths of header and gap.
2017-12-23 18:41:50 -05:00
Thomas Harte
e8ddff0ee0 Makes a first, messy, attempt at serialising CAS files into audio. 2017-12-21 22:34:03 -05:00
Thomas Harte
b61fab9df7 Merge pull request #322 from TomHarte/MSXTapes
Introduces TSX support for the MSX.
2017-12-20 18:43:54 -08:00
Thomas Harte
28fb1ce2ae Removes unnecessary logging. 2017-12-20 21:39:17 -05:00
Thomas Harte
b9b107ee85 Switches KeyGrave and KeyQuote, correcting a disarrangement. 2017-12-20 21:16:54 -05:00
Thomas Harte
f17758e7f9 Attempts better to deal with large numbers. 2017-12-20 21:03:24 -05:00
Thomas Harte
0bb24075b6 Immediate fixes: TSX is seemingly TZX 1.21; the tape motor control works the other way around.
Input is not yet being recognised.
2017-12-19 22:17:42 -05:00
Thomas Harte
db6d9b59d0 Attempts to implement TSX support for the MSX. 2017-12-19 21:53:04 -05:00
Thomas Harte
51e82c10c5 Merge pull request #321 from TomHarte/MSXKeyTaps
Introduces the MSX keyboard toggle sample source.
2017-12-19 18:19:42 -08:00
Thomas Harte
2d892da225 Introduces the MSX keyboard toggle sample source.
In support of which, it also introduces a means of sample source composition.
2017-12-19 21:08:10 -05:00
Thomas Harte
b99ba2bc02 Merge pull request #320 from TomHarte/AudioRejig
Separates the audio pipeline into its component parts
2017-12-18 18:50:36 -08:00
Thomas Harte
d36e9d0b0d Reintroduces cstring.h to a few files that previously got it implicitly. 2017-12-18 21:47:30 -05:00
Thomas Harte
2dc1d4443e Separates LowpassFilter and SampleSource. 2017-12-18 21:39:23 -05:00
Thomas Harte
f8a2459c91 Corrects two lingering adaptation errors in the Vic-20. 2017-12-17 21:43:08 -05:00
Thomas Harte
ac80d10cd8 Separates the component parts of running an audio stream: task deferral, filtering and generation.
Walking towards improving opportunities for composition.
2017-12-17 21:26:06 -05:00
Thomas Harte
eb6b612052 Adds DeferringAsyncTaskQueue as a base concurrency primitive. 2017-12-15 22:14:09 -05:00
Thomas Harte
d66a33f249 Merge pull request #319 from TomHarte/TMSTests
Corrects a couple of lingering TMS issues and tidies it up
2017-12-14 18:20:13 -08:00
Thomas Harte
ec4c259695 Removes unused file. 2017-12-14 21:19:09 -05:00
Thomas Harte
ad50b6b1fb Corrects TMS' get_time_until_interrupt when the next interrupt is exactly a frame away. 2017-12-14 21:12:51 -05:00
Thomas Harte
3da323c657 Corrects lingering free TMS read. 2017-12-14 20:30:56 -05:00
Thomas Harte
aca7842ca4 Better documents and tidies the TMS9918. 2017-12-14 20:27:26 -05:00
Thomas Harte
38c912b968 Merge pull request #318 from TomHarte/TMSVRAMTiming
Attempts real VRAM access timings for the TMS9918a
2017-12-13 19:56:56 -08:00
Thomas Harte
7a52e7d6d2 Provides an empty value for the interrupt cycle. 2017-12-13 22:44:03 -05:00
Thomas Harte
c36de4f640 Attempts real VRAM access timings, correcting a frame timing error as I go. 2017-12-13 22:37:27 -05:00
Thomas Harte
504772bcda Merge pull request #317 from TomHarte/SpriteGlitching
Corrects occasional TMS sprite glitching.
2017-12-12 19:20:27 -08:00
Thomas Harte
5d0c33d545 Corrects occasional TMS sprite glitching. 2017-12-12 22:19:33 -05:00
Thomas Harte
7bc1bcd493 Merge pull request #316 from TomHarte/SpriteTopLine
Adds one-before-the-graphics as a line for TMS video collection.
2017-12-12 18:36:03 -08:00
Thomas Harte
b0616ee10c Adds one-before-the-graphics as a line for video collection.
Thereby corrects sprites on line 0.
2017-12-12 21:35:33 -05:00
Thomas Harte
da57df55e8 Merge pull request #315 from TomHarte/MSX
Introduces very provisional MSX 1 emulation
2017-12-12 18:30:09 -08:00
Thomas Harte
4daea1121b Gives up on C-BIOS for a while, to get to an acceptable merge point. 2017-12-12 21:19:33 -05:00
Thomas Harte
afcdd64d5e Switches to a less easy-to-confuse storage arrangement for MSX memory slots. 2017-12-11 21:09:53 -05:00
Thomas Harte
798cdba979 8255: update_outputs now affects only those ports designated as outputs. 2017-12-10 17:55:37 -05:00
Thomas Harte
f957344ac4 Corrects TMS failure to show background through tile layer. 2017-12-09 23:15:04 -05:00
Thomas Harte
b3fbd0f352 Tidies up some of the TMS' magic constants. 2017-12-09 23:08:07 -05:00
Thomas Harte
042edc72f7 Adjusts TMS declared timing so as to be in-phase with an NTSC clock, and adopts an alternative palette. 2017-12-09 22:28:34 -05:00
Thomas Harte
943418c434 Reformulates TMS sprite plotting to set the collision flag and to support magnified sprites. 2017-12-09 20:30:12 -05:00
Thomas Harte
7d7e2538bd Introduces a computationally simplified inner loop for TMS graphics modes, modelled on that for text. 2017-12-09 16:02:33 -05:00
Thomas Harte
7a544731e2 Makes minor tidiness improvements to the TMS. 2017-12-08 22:20:21 -05:00
Thomas Harte
e1914b4f16 Attempts to add a proper intermediate buffer for sprites to allow the split of collection and output. 2017-12-08 22:12:39 -05:00
Thomas Harte
202958303e Merge branch 'MSX' of github.com:TomHarte/CLK into MSX 2017-12-06 21:58:29 -05:00
Thomas Harte
57b060ac3c Updates SConstruct for the incoming MSX changes. 2017-12-06 18:56:26 -08:00
Thomas Harte
8653eb8b55 Corrects various latent errors in optimised TMS video collection. 2017-12-06 20:24:29 -05:00
Thomas Harte
a4f0a260fd Reformulates the TMS graphics mode fetch loop to try to eliminate heavy conditionality. Temporarily introduces some sprite selection issues. 2017-12-05 22:39:03 -05:00
Thomas Harte
d4a53e82bb Replaces manual retread of memcpy with standard memcpy. 2017-12-05 18:21:34 -05:00
Thomas Harte
6eedc99286 Makes substantial optimisations to text mode.
Character optimisations to come.
2017-12-04 22:18:51 -05:00
Thomas Harte
ec266d6c8e Ensures the AY stops listening to the bus after each read or write. 2017-12-04 19:18:54 -05:00
Thomas Harte
e3a5218e78 Fixes AY and random port input for the MSX. 2017-12-03 22:25:18 -05:00
Thomas Harte
a473338abe Makes minor type conversion fixes. 2017-12-03 22:24:48 -05:00
Thomas Harte
ae21782adc Corrects two Cartridge type mismatches. 2017-12-03 15:43:59 -05:00
Thomas Harte
ee44d671e7 Steps towards exposing the MSX in Cocoa builds. 2017-12-03 15:42:54 -05:00
Thomas Harte
3766bef962 Eliminates some redundant white space. 2017-12-03 14:52:42 -05:00
Thomas Harte
ad3df36c20 Corrects sprite information collection to cover all four. 2017-12-03 14:51:55 -05:00
Thomas Harte
38b11893e8 Takes first steps towards sprite display on the TMS. 2017-12-02 22:13:43 -05:00
Thomas Harte
e4534775b0 Cleans up and zooms in on the TMS slightly. 2017-12-02 17:48:31 -05:00
Thomas Harte
fe7fc6b22e Enables AY output from the MSX. 2017-12-02 16:30:43 -05:00
Thomas Harte
fe0cdc8d69 Corrects colour fetching in TMS Graphics II to be a function of row. 2017-12-02 16:10:29 -05:00
Thomas Harte
7f8a13a409 Adds bare minimum to get accepted 16- and 32kb cartridges to start on the MSX. 2017-12-02 16:06:04 -05:00
Thomas Harte
ca26ce8400 Slightly corrects style errors in the Cartridge hierarchy, and introduces mapping of .ROM to the MSX when appropriate. 2017-12-02 16:01:30 -05:00
Thomas Harte
d3dd8f3f2a Implements screen 2 addressing. 2017-12-02 14:05:52 -05:00
Thomas Harte
3c8d2d579d Resolves remaining sources of text mode instability. 2017-11-30 22:48:07 -05:00
Thomas Harte
edcbb3dfed Tidies code a little and thereby uncovers and corrects one cause of output instability. 2017-11-30 22:19:53 -05:00
Thomas Harte
9c8158753e Makes a first attempt at displaying text mode. 2017-11-30 21:35:26 -05:00
Thomas Harte
5da9cb2957 Introduces most of a keyboard mapping for the MSX. 2017-11-30 19:27:53 -05:00
Thomas Harte
54c845b6e2 Adds just enough logic to make every host key look like '0' to the MSX. 2017-11-29 22:07:30 -05:00
Thomas Harte
ee84f33ab5 Ensures that the 9918 admits that it is the source of interrupts. 2017-11-29 21:33:43 -05:00
Thomas Harte
f0f149c018 Simplified paging logic. 2017-11-29 20:49:02 -05:00
Thomas Harte
7dfbe4bb93 Ensures proper Boolean startup values for IFF1 and IFF2. 2017-11-29 20:32:55 -05:00
Thomas Harte
aa4eef41d8 Seeks to introduce MSX interrupts. 2017-11-29 20:31:55 -05:00
Thomas Harte
69ec8a362e Makes an attempt to perform MSX memory paging. 2017-11-28 21:56:15 -05:00
Thomas Harte
ecd7d4731b Advances emulation to showing what looks like appropriate text on screen. 2017-11-28 21:27:15 -05:00
Thomas Harte
563aa051e4 Simplifies code a little and gives something on screen. 2017-11-28 21:19:28 -05:00
Thomas Harte
642bb8333f Introduces something of a first attempt at graphics collection and display. An unsuccessful attempt. 2017-11-28 21:10:30 -05:00
Thomas Harte
c558e86e03 Adds border colour output. 2017-11-27 22:05:40 -05:00
Thomas Harte
dbb14ea2e2 Corrects counting deficiencies that could produce an unstable display. 2017-11-27 21:36:12 -05:00
Thomas Harte
173e16b107 Corrects the 9918 so that it terminates. 2017-11-27 19:48:04 -05:00
Thomas Harte
7d2adad67e Adds the absolute most basic version of in-frame time keeping, to display a white square. 2017-11-27 19:43:33 -05:00
Thomas Harte
d33612def5 Ensures the MSX provides a clock to the VDP. 2017-11-26 20:07:30 -05:00
Thomas Harte
9cb6ca3440 Adds elementary decoding of VDP accesses. 2017-11-26 20:01:11 -05:00
Thomas Harte
e957e40b14 Shifts 8255 logging up into its own port handler. That's probably fine for now. 2017-11-26 18:59:29 -05:00
Thomas Harte
7a8a43a96a Adds just enough of the MSX memory map for the Z80 to appear to try to do useful things. 2017-11-26 18:34:40 -05:00
Thomas Harte
0eb5dd9688 Introduces the fundamentals of bus routing for the MSX. 2017-11-26 16:47:59 -05:00
Thomas Harte
a14b53a9ab Adds a TMS9918 skeleton plus enough in the MSX to get to a blank screen in SDL/kiosk mode. 2017-11-26 13:28:26 -05:00
Thomas Harte
576d554a2c Expands upon the MSX skeleton. 2017-11-25 13:33:51 -05:00
Thomas Harte
68a2895753 Adds enough static analyser to get to the MSX itself as the point of failure in SDL/kiosk mode. 2017-11-25 13:18:24 -05:00
Thomas Harte
f90b3f06aa Merge branch 'master' into MSX 2017-11-25 08:19:24 -05:00
Thomas Harte
f067fa9923 Merge pull request #310 from TomHarte/ROMSafety
Simplifies CPC ROM input mechanism.
2017-11-25 05:19:00 -08:00
Thomas Harte
ee9f89ccb5 Simplifies CPC ROM input mechanism. 2017-11-25 08:18:01 -05:00
Thomas Harte
573a9c6fb2 Merge pull request #309 from TomHarte/ROMSafety
Ensures all vectors loaded from disk are the expected size.
2017-11-25 05:17:23 -08:00
Thomas Harte
a46a37fba9 Ensures all vectors loaded from disk are the expected size. 2017-11-24 22:22:32 -05:00
Thomas Harte
324b57c054 Adds inclusion of the 3/4 of the MSX's support chips that are currently implemented. 2017-11-24 22:05:50 -05:00
Thomas Harte
ae50ca9ab2 Moves the MSX class to the appropriate place and gives it a Z80. 2017-11-24 21:59:54 -05:00
Thomas Harte
6e4bde00d3 Merge branch 'master' into MSX 2017-11-24 21:50:38 -05:00
Thomas Harte
d4d0dd87c9 Merge pull request #307 from TomHarte/MacDynamic
Adapts the Mac port to use a Machine::DynamicMachine.
2017-11-24 18:43:27 -08:00
Thomas Harte
221c05ca76 Adapts the Mac port to use a Machine::DynamicMachine, thereby eliminating plenty of duplication. 2017-11-24 21:36:22 -05:00
Thomas Harte
ff21ff90eb Introduces MSX ROMs and an MSX class. 2017-11-24 20:43:26 -05:00
Thomas Harte
fcf295fd68 Merge pull request #306 from TomHarte/ShaderUniforms
Formalises naming of shader inputs and related guarantees.
2017-11-24 16:28:30 -08:00
Thomas Harte
2008dec1ed Adds exceptions for bad enumeration values. 2017-11-24 19:27:49 -05:00
Thomas Harte
b4f3c41aae Formalises naming of shader inputs and related guarantees. 2017-11-24 18:45:24 -05:00
Thomas Harte
90c4e3726f Merge pull request #305 from TomHarte/MacCleanup
Withdraws genericised selection and ROM provision interfaces.
2017-11-24 14:58:49 -08:00
Thomas Harte
c83b3cefbc Eliminates the generalised special case selectors and ROM suppliers from the CPC, Vic-20, Electron and ZX80/81. 2017-11-24 17:55:28 -05:00
Thomas Harte
a8ac51da73 Eliminates the Oric's non-reflective inputs for selections, and the Oric-specific ROM setter. 2017-11-24 16:59:00 -05:00
Thomas Harte
bc65ba3f9b Merge pull request #303 from mattgodbolt/fixes-for-uninitialized-errors
Initialize all `const` members.
2017-11-24 12:19:55 -08:00
Thomas Harte
79674fdbd3 Merge pull request #304 from mattgodbolt/gitignore
Add a .gitignore file to ignore the built `clksignal` binary
2017-11-24 12:19:25 -08:00
Matt Godbolt
adea4711f1 Add a .gitignore file to ignore the built clksignal binary 2017-11-24 12:12:48 -06:00
Matt Godbolt
bded406caa Initialize all const members.
Without this change, GCC versions >4.8 will error with things like:

```
./CLK/Outputs/CRT/Internals/CRTOpenGL.cpp:154:2:error: uninitialized const member
'Outputs::CRT::OpenGLOutputBuilder::draw_frame(unsigned int, unsigned int, bool)::RenderStage::target'
```
2017-11-24 12:09:10 -06:00
Thomas Harte
85085a6375 Merge pull request #302 from TomHarte/OricStartup
Ensures Oric video output starts up and changes validly.
2017-11-23 13:23:31 -08:00
Thomas Harte
d122d598d3 Merge branch 'OricStartup' of github.com:TomHarte/CLK into OricStartup 2017-11-23 16:20:19 -05:00
Thomas Harte
d6192b8c58 Ensures Oric video output starts up and changes validly. 2017-11-23 16:19:41 -05:00
Thomas Harte
f02d4dbb59 Ensures Oric video output starts up and changes validly. 2017-11-23 16:17:52 -05:00
Thomas Harte
f3818991f6 Merge pull request #301 from TomHarte/ElectronMode3
Corrects Electron Mode 3 timing.
2017-11-23 13:07:15 -08:00
Thomas Harte
c7dd6247f0 Corrects Electron Mode 3 timing. 2017-11-23 16:06:05 -05:00
Thomas Harte
99e17600d7 Updated as per slow appropriate of the full 'Clock Signal'. 2017-11-22 20:44:06 -05:00
299 changed files with 12780 additions and 3600 deletions

5
.gitignore vendored
View File

@@ -18,9 +18,10 @@ DerivedData
*.xcuserstate
.DS_Store
# Exclude system ROMs
# Exclude system ROMs and unit test ROMs
ROMImages/*
OSBindings/Mac/Clock SignalTests/Atari\ ROMs
OSBindings/Mac/Clock SignalTests/Atari ROMs
OSBindings/Mac/Clock SignalTests/MSX ROMs
# Exclude intermediate build products
*.o

View File

@@ -1,5 +1,13 @@
language: objective-c
osx_image: xcode8.2
xcode_project: OSBindings/Mac/Clock Signal.xcodeproj
xcode_scheme: Clock Signal
xcode_sdk: macosx10.12
# language: objective-c
# osx_image: xcode8.2
# xcode_project: OSBindings/Mac/Clock Signal.xcodeproj
# xcode_scheme: Clock Signal
# xcode_sdk: macosx10.12
language: cpp
before_install:
- sudo apt-get install libsdl2-dev
script: cd OSBindings/SDL && scons
compiler:
- clang
- gcc

View File

@@ -0,0 +1,30 @@
//
// ConfidenceCounter.cpp
// Clock Signal
//
// Created by Thomas Harte on 21/01/2018.
// Copyright © 2018 Thomas Harte. All rights reserved.
//
#include "ConfidenceCounter.hpp"
using namespace Analyser::Dynamic;
float ConfidenceCounter::get_confidence() {
return static_cast<float>(hits_) / static_cast<float>(hits_ + misses_);
}
void ConfidenceCounter::add_hit() {
hits_++;
}
void ConfidenceCounter::add_miss() {
misses_++;
}
void ConfidenceCounter::add_equivocal() {
if(hits_ > misses_) {
hits_++;
misses_++;
}
}

View File

@@ -0,0 +1,47 @@
//
// ConfidenceCounter.hpp
// Clock Signal
//
// Created by Thomas Harte on 21/01/2018.
// Copyright © 2018 Thomas Harte. All rights reserved.
//
#ifndef ConfidenceCounter_hpp
#define ConfidenceCounter_hpp
#include "ConfidenceSource.hpp"
namespace Analyser {
namespace Dynamic {
/*!
Provides a confidence source that calculates its probability by virtual of a history of events.
The initial value of the confidence counter is 0.5.
*/
class ConfidenceCounter: public ConfidenceSource {
public:
/*! @returns The computed probability, based on the history of events. */
float get_confidence() override;
/*! Records an event that implies this is the appropriate class — pushes probability up towards 1.0. */
void add_hit();
/*! Records an event that implies this is not the appropriate class — pushes probability down towards 0.0. */
void add_miss();
/*!
Records an event that could be correct but isn't necessarily so; which can push probability
down towards 0.5, but will never push it upwards.
*/
void add_equivocal();
private:
int hits_ = 1;
int misses_ = 1;
};
}
}
#endif /* ConfidenceCounter_hpp */

View File

@@ -0,0 +1,28 @@
//
// ConfidenceSource.hpp
// Clock Signal
//
// Created by Thomas Harte on 21/01/2018.
// Copyright © 2018 Thomas Harte. All rights reserved.
//
#ifndef ConfidenceSource_hpp
#define ConfidenceSource_hpp
namespace Analyser {
namespace Dynamic {
/*!
Provides an abstract interface through which objects can declare the probability
that they are the proper target for their input; e.g. if an Acorn Electron is asked
to run an Atari 2600 program then its confidence should shrink towards 0.0; if the
program is handed to an Atari 2600 then its confidence should grow towards 1.0.
*/
struct ConfidenceSource {
virtual float get_confidence() = 0;
};
}
}
#endif /* ConfidenceSource_hpp */

View File

@@ -0,0 +1,28 @@
//
// ConfidenceSummary.cpp
// Clock Signal
//
// Created by Thomas Harte on 21/01/2018.
// Copyright © 2018 Thomas Harte. All rights reserved.
//
#include "ConfidenceSummary.hpp"
#include <cassert>
#include <numeric>
using namespace Analyser::Dynamic;
ConfidenceSummary::ConfidenceSummary(const std::vector<ConfidenceSource *> &sources, const std::vector<float> &weights) :
sources_(sources), weights_(weights) {
assert(weights.size() == sources.size());
weight_sum_ = std::accumulate(weights.begin(), weights.end(), 0.0f);
}
float ConfidenceSummary::get_confidence() {
float result = 0.0f;
for(std::size_t index = 0; index < sources_.size(); ++index) {
result += sources_[index]->get_confidence() * weights_[index];
}
return result / weight_sum_;
}

View File

@@ -0,0 +1,46 @@
//
// ConfidenceSummary.hpp
// Clock Signal
//
// Created by Thomas Harte on 21/01/2018.
// Copyright © 2018 Thomas Harte. All rights reserved.
//
#ifndef ConfidenceSummary_hpp
#define ConfidenceSummary_hpp
#include "ConfidenceSource.hpp"
#include <vector>
namespace Analyser {
namespace Dynamic {
/*!
Summaries a collection of confidence sources by calculating their weighted sum.
*/
class ConfidenceSummary: public ConfidenceSource {
public:
/*!
Instantiates a summary that will produce the weighted sum of
@c sources, each using the corresponding entry of @c weights.
Requires that @c sources and @c weights are of the same length.
*/
ConfidenceSummary(
const std::vector<ConfidenceSource *> &sources,
const std::vector<float> &weights);
/*! @returns The weighted sum of all sources. */
float get_confidence() override;
private:
std::vector<ConfidenceSource *> sources_;
std::vector<float> weights_;
float weight_sum_;
};
}
}
#endif /* ConfidenceSummary_hpp */

View File

@@ -0,0 +1,90 @@
//
// MultiCRTMachine.cpp
// Clock Signal
//
// Created by Thomas Harte on 29/01/2018.
// Copyright © 2018 Thomas Harte. All rights reserved.
//
#include "MultiCRTMachine.hpp"
#include <condition_variable>
#include <mutex>
using namespace Analyser::Dynamic;
MultiCRTMachine::MultiCRTMachine(const std::vector<std::unique_ptr<::Machine::DynamicMachine>> &machines, std::mutex &machines_mutex) :
machines_(machines), machines_mutex_(machines_mutex), queues_(machines.size()) {
speaker_ = MultiSpeaker::create(machines);
}
void MultiCRTMachine::perform_parallel(const std::function<void(::CRTMachine::Machine *)> &function) {
// Apply a blunt force parallelisation of the machines; each run_for is dispatched
// to a separate queue and this queue will block until all are done.
volatile std::size_t outstanding_machines;
std::condition_variable condition;
std::mutex mutex;
{
std::lock_guard<std::mutex> machines_lock(machines_mutex_);
std::lock_guard<std::mutex> lock(mutex);
outstanding_machines = machines_.size();
for(std::size_t index = 0; index < machines_.size(); ++index) {
CRTMachine::Machine *crt_machine = machines_[index]->crt_machine();
queues_[index].enqueue([&mutex, &condition, crt_machine, function, &outstanding_machines]() {
if(crt_machine) function(crt_machine);
std::lock_guard<std::mutex> lock(mutex);
outstanding_machines--;
condition.notify_all();
});
}
}
std::unique_lock<std::mutex> lock(mutex);
condition.wait(lock, [&outstanding_machines] { return !outstanding_machines; });
}
void MultiCRTMachine::perform_serial(const std::function<void (::CRTMachine::Machine *)> &function) {
std::lock_guard<std::mutex> machines_lock(machines_mutex_);
for(const auto &machine: machines_) {
CRTMachine::Machine *crt_machine = machine->crt_machine();
if(crt_machine) function(crt_machine);
}
}
void MultiCRTMachine::setup_output(float aspect_ratio) {
perform_serial([=](::CRTMachine::Machine *machine) {
machine->setup_output(aspect_ratio);
});
}
void MultiCRTMachine::close_output() {
perform_serial([=](::CRTMachine::Machine *machine) {
machine->close_output();
});
}
Outputs::CRT::CRT *MultiCRTMachine::get_crt() {
std::lock_guard<std::mutex> machines_lock(machines_mutex_);
CRTMachine::Machine *crt_machine = machines_.front()->crt_machine();
return crt_machine ? crt_machine->get_crt() : nullptr;
}
Outputs::Speaker::Speaker *MultiCRTMachine::get_speaker() {
return speaker_;
}
void MultiCRTMachine::run_for(Time::Seconds duration) {
perform_parallel([=](::CRTMachine::Machine *machine) {
if(machine->get_confidence() >= 0.01f) machine->run_for(duration);
});
if(delegate_) delegate_->multi_crt_did_run_machines();
}
void MultiCRTMachine::did_change_machine_order() {
if(speaker_) {
speaker_->set_new_front_machine(machines_.front().get());
}
}

View File

@@ -0,0 +1,89 @@
//
// MultiCRTMachine.hpp
// Clock Signal
//
// Created by Thomas Harte on 29/01/2018.
// Copyright © 2018 Thomas Harte. All rights reserved.
//
#ifndef MultiCRTMachine_hpp
#define MultiCRTMachine_hpp
#include "../../../../Concurrency/AsyncTaskQueue.hpp"
#include "../../../../Machines/CRTMachine.hpp"
#include "../../../../Machines/DynamicMachine.hpp"
#include "MultiSpeaker.hpp"
#include <memory>
#include <mutex>
#include <vector>
namespace Analyser {
namespace Dynamic {
/*!
Provides a class that multiplexes the CRT machine interface to multiple machines.
Keeps a reference to the original vector of machines; will access it only after
acquiring a supplied mutex. The owner should also call did_change_machine_order()
if the order of machines changes.
*/
class MultiCRTMachine: public CRTMachine::Machine {
public:
MultiCRTMachine(const std::vector<std::unique_ptr<::Machine::DynamicMachine>> &machines, std::mutex &machines_mutex);
/*!
Informs the MultiCRTMachine that the order of machines has changed; the MultiCRTMachine
uses this as an opportunity to synthesis any CRTMachine::Machine::Delegate messages that
are necessary to bridge the gap between one machine and the next.
*/
void did_change_machine_order();
/*!
Provides a mechanism by which a delegate can be informed each time a call to run_for has
been received.
*/
struct Delegate {
virtual void multi_crt_did_run_machines() = 0;
};
/// Sets @c delegate as the receiver of delegate messages.
void set_delegate(Delegate *delegate) {
delegate_ = delegate;
}
// Below is the standard CRTMachine::Machine interface; see there for documentation.
void setup_output(float aspect_ratio) override;
void close_output() override;
Outputs::CRT::CRT *get_crt() override;
Outputs::Speaker::Speaker *get_speaker() override;
void run_for(Time::Seconds duration) override;
private:
void run_for(const Cycles cycles) override {}
const std::vector<std::unique_ptr<::Machine::DynamicMachine>> &machines_;
std::mutex &machines_mutex_;
std::vector<Concurrency::AsyncTaskQueue> queues_;
MultiSpeaker *speaker_ = nullptr;
Delegate *delegate_ = nullptr;
/*!
Performs a parallel for operation across all machines, performing the supplied
function on each and returning only once all applications have completed.
No guarantees are extended as to which thread operations will occur on.
*/
void perform_parallel(const std::function<void(::CRTMachine::Machine *)> &);
/*!
Performs a serial for operation across all machines, performing the supplied
function on each on the calling thread.
*/
void perform_serial(const std::function<void(::CRTMachine::Machine *)> &);
};
}
}
#endif /* MultiCRTMachine_hpp */

View File

@@ -0,0 +1,64 @@
//
// MultiConfigurable.cpp
// Clock Signal
//
// Created by Thomas Harte on 09/02/2018.
// Copyright © 2018 Thomas Harte. All rights reserved.
//
#include "MultiConfigurable.hpp"
#include <algorithm>
using namespace Analyser::Dynamic;
MultiConfigurable::MultiConfigurable(const std::vector<std::unique_ptr<::Machine::DynamicMachine>> &machines) {
for(const auto &machine: machines) {
Configurable::Device *device = machine->configurable_device();
if(device) devices_.push_back(device);
}
}
std::vector<std::unique_ptr<Configurable::Option>> MultiConfigurable::get_options() {
std::vector<std::unique_ptr<Configurable::Option>> options;
// Produce the list of unique options.
for(const auto &device : devices_) {
std::vector<std::unique_ptr<Configurable::Option>> device_options = device->get_options();
for(auto &option : device_options) {
if(std::find(options.begin(), options.end(), option) == options.end()) {
options.push_back(std::move(option));
}
}
}
return options;
}
void MultiConfigurable::set_selections(const Configurable::SelectionSet &selection_by_option) {
for(const auto &device : devices_) {
device->set_selections(selection_by_option);
}
}
Configurable::SelectionSet MultiConfigurable::get_accurate_selections() {
Configurable::SelectionSet set;
for(const auto &device : devices_) {
Configurable::SelectionSet device_set = device->get_accurate_selections();
for(auto &selection : device_set) {
set.insert(std::move(selection));
}
}
return set;
}
Configurable::SelectionSet MultiConfigurable::get_user_friendly_selections() {
Configurable::SelectionSet set;
for(const auto &device : devices_) {
Configurable::SelectionSet device_set = device->get_user_friendly_selections();
for(auto &selection : device_set) {
set.insert(std::move(selection));
}
}
return set;
}

View File

@@ -0,0 +1,43 @@
//
// MultiConfigurable.hpp
// Clock Signal
//
// Created by Thomas Harte on 09/02/2018.
// Copyright © 2018 Thomas Harte. All rights reserved.
//
#ifndef MultiConfigurable_hpp
#define MultiConfigurable_hpp
#include "../../../../Machines/DynamicMachine.hpp"
#include <memory>
#include <vector>
namespace Analyser {
namespace Dynamic {
/*!
Provides a class that multiplexes the configurable interface to multiple machines.
Makes a static internal copy of the list of machines; makes no guarantees about the
order of delivered messages.
*/
class MultiConfigurable: public Configurable::Device {
public:
MultiConfigurable(const std::vector<std::unique_ptr<::Machine::DynamicMachine>> &machines);
// Below is the standard Configurable::Device interface; see there for documentation.
std::vector<std::unique_ptr<Configurable::Option>> get_options() override;
void set_selections(const Configurable::SelectionSet &selection_by_option) override;
Configurable::SelectionSet get_accurate_selections() override;
Configurable::SelectionSet get_user_friendly_selections() override;
private:
std::vector<Configurable::Device *> devices_;
};
}
}
#endif /* MultiConfigurable_hpp */

View File

@@ -0,0 +1,29 @@
//
// MultiConfigurationTarget.cpp
// Clock Signal
//
// Created by Thomas Harte on 29/01/2018.
// Copyright © 2018 Thomas Harte. All rights reserved.
//
#include "MultiConfigurationTarget.hpp"
using namespace Analyser::Dynamic;
MultiConfigurationTarget::MultiConfigurationTarget(const std::vector<std::unique_ptr<::Machine::DynamicMachine>> &machines) {
for(const auto &machine: machines) {
ConfigurationTarget::Machine *configuration_target = machine->configuration_target();
if(configuration_target) targets_.push_back(configuration_target);
}
}
void MultiConfigurationTarget::configure_as_target(const Analyser::Static::Target *target) {
}
bool MultiConfigurationTarget::insert_media(const Analyser::Static::Media &media) {
bool inserted = false;
for(const auto &target : targets_) {
inserted |= target->insert_media(media);
}
return inserted;
}

View File

@@ -0,0 +1,42 @@
//
// MultiConfigurationTarget.hpp
// Clock Signal
//
// Created by Thomas Harte on 29/01/2018.
// Copyright © 2018 Thomas Harte. All rights reserved.
//
#ifndef MultiConfigurationTarget_hpp
#define MultiConfigurationTarget_hpp
#include "../../../../Machines/ConfigurationTarget.hpp"
#include "../../../../Machines/DynamicMachine.hpp"
#include <memory>
#include <vector>
namespace Analyser {
namespace Dynamic {
/*!
Provides a class that multiplexes the configuration target interface to multiple machines.
Makes a static internal copy of the list of machines; makes no guarantees about the
order of delivered messages.
*/
struct MultiConfigurationTarget: public ConfigurationTarget::Machine {
public:
MultiConfigurationTarget(const std::vector<std::unique_ptr<::Machine::DynamicMachine>> &machines);
// Below is the standard ConfigurationTarget::Machine interface; see there for documentation.
void configure_as_target(const Analyser::Static::Target *target) override;
bool insert_media(const Analyser::Static::Media &media) override;
private:
std::vector<ConfigurationTarget::Machine *> targets_;
};
}
}
#endif /* MultiConfigurationTarget_hpp */

View File

@@ -0,0 +1,78 @@
//
// MultiJoystickMachine.cpp
// Clock Signal
//
// Created by Thomas Harte on 09/02/2018.
// Copyright © 2018 Thomas Harte. All rights reserved.
//
#include "MultiJoystickMachine.hpp"
#include <algorithm>
using namespace Analyser::Dynamic;
namespace {
class MultiJoystick: public Inputs::Joystick {
public:
MultiJoystick(std::vector<JoystickMachine::Machine *> &machines, std::size_t index) {
for(const auto &machine: machines) {
const auto &joysticks = machine->get_joysticks();
if(joysticks.size() >= index) {
joysticks_.push_back(joysticks[index].get());
}
}
}
std::vector<DigitalInput> get_inputs() override {
std::vector<DigitalInput> inputs;
for(const auto &joystick: joysticks_) {
std::vector<DigitalInput> joystick_inputs = joystick->get_inputs();
for(const auto &input: joystick_inputs) {
if(std::find(inputs.begin(), inputs.end(), input) != inputs.end()) {
inputs.push_back(input);
}
}
}
return inputs;
}
void set_digital_input(const DigitalInput &digital_input, bool is_active) override {
for(const auto &joystick: joysticks_) {
joystick->set_digital_input(digital_input, is_active);
}
}
void reset_all_inputs() override {
for(const auto &joystick: joysticks_) {
joystick->reset_all_inputs();
}
}
private:
std::vector<Inputs::Joystick *> joysticks_;
};
}
MultiJoystickMachine::MultiJoystickMachine(const std::vector<std::unique_ptr<::Machine::DynamicMachine>> &machines) {
std::size_t total_joysticks = 0;
std::vector<JoystickMachine::Machine *> joystick_machines;
for(const auto &machine: machines) {
JoystickMachine::Machine *joystick_machine = machine->joystick_machine();
if(joystick_machine) {
joystick_machines.push_back(joystick_machine);
total_joysticks = std::max(total_joysticks, joystick_machine->get_joysticks().size());
}
}
for(std::size_t index = 0; index < total_joysticks; ++index) {
joysticks_.emplace_back(new MultiJoystick(joystick_machines, index));
}
}
std::vector<std::unique_ptr<Inputs::Joystick>> &MultiJoystickMachine::get_joysticks() {
return joysticks_;
}

View File

@@ -0,0 +1,40 @@
//
// MultiJoystickMachine.hpp
// Clock Signal
//
// Created by Thomas Harte on 09/02/2018.
// Copyright © 2018 Thomas Harte. All rights reserved.
//
#ifndef MultiJoystickMachine_hpp
#define MultiJoystickMachine_hpp
#include "../../../../Machines/DynamicMachine.hpp"
#include <memory>
#include <vector>
namespace Analyser {
namespace Dynamic {
/*!
Provides a class that multiplexes the joystick machine interface to multiple machines.
Makes a static internal copy of the list of machines; makes no guarantees about the
order of delivered messages.
*/
class MultiJoystickMachine: public JoystickMachine::Machine {
public:
MultiJoystickMachine(const std::vector<std::unique_ptr<::Machine::DynamicMachine>> &machines);
// Below is the standard JoystickMachine::Machine interface; see there for documentation.
std::vector<std::unique_ptr<Inputs::Joystick>> &get_joysticks() override;
private:
std::vector<std::unique_ptr<Inputs::Joystick>> joysticks_;
};
}
}
#endif /* MultiJoystickMachine_hpp */

View File

@@ -0,0 +1,43 @@
//
// MultiKeyboardMachine.cpp
// Clock Signal
//
// Created by Thomas Harte on 09/02/2018.
// Copyright © 2018 Thomas Harte. All rights reserved.
//
#include "MultiKeyboardMachine.hpp"
using namespace Analyser::Dynamic;
MultiKeyboardMachine::MultiKeyboardMachine(const std::vector<std::unique_ptr<::Machine::DynamicMachine>> &machines) {
for(const auto &machine: machines) {
KeyboardMachine::Machine *keyboard_machine = machine->keyboard_machine();
if(keyboard_machine) machines_.push_back(keyboard_machine);
}
}
void MultiKeyboardMachine::clear_all_keys() {
for(const auto &machine: machines_) {
machine->clear_all_keys();
}
}
void MultiKeyboardMachine::set_key_state(uint16_t key, bool is_pressed) {
for(const auto &machine: machines_) {
machine->set_key_state(key, is_pressed);
}
}
void MultiKeyboardMachine::type_string(const std::string &string) {
for(const auto &machine: machines_) {
machine->type_string(string);
}
}
void MultiKeyboardMachine::keyboard_did_change_key(Inputs::Keyboard *keyboard, Inputs::Keyboard::Key key, bool is_pressed) {
for(const auto &machine: machines_) {
uint16_t mapped_key = machine->get_keyboard_mapper()->mapped_key_for_key(key);
if(mapped_key != KeyNotMapped) machine->set_key_state(mapped_key, is_pressed);
}
}

View File

@@ -0,0 +1,44 @@
//
// MultiKeyboardMachine.hpp
// Clock Signal
//
// Created by Thomas Harte on 09/02/2018.
// Copyright © 2018 Thomas Harte. All rights reserved.
//
#ifndef MultiKeyboardMachine_hpp
#define MultiKeyboardMachine_hpp
#include "../../../../Machines/DynamicMachine.hpp"
#include "../../../../Machines/KeyboardMachine.hpp"
#include <memory>
#include <vector>
namespace Analyser {
namespace Dynamic {
/*!
Provides a class that multiplexes the keyboard machine interface to multiple machines.
Makes a static internal copy of the list of machines; makes no guarantees about the
order of delivered messages.
*/
class MultiKeyboardMachine: public KeyboardMachine::Machine {
public:
MultiKeyboardMachine(const std::vector<std::unique_ptr<::Machine::DynamicMachine>> &machines);
// Below is the standard KeyboardMachine::Machine interface; see there for documentation.
void clear_all_keys() override;
void set_key_state(uint16_t key, bool is_pressed) override;
void type_string(const std::string &) override;
void keyboard_did_change_key(Inputs::Keyboard *keyboard, Inputs::Keyboard::Key key, bool is_pressed) override;
private:
std::vector<::KeyboardMachine::Machine *> machines_;
};
}
}
#endif /* MultiKeyboardMachine_hpp */

View File

@@ -0,0 +1,76 @@
//
// MultiSpeaker.cpp
// Clock Signal
//
// Created by Thomas Harte on 18/02/2018.
// Copyright © 2018 Thomas Harte. All rights reserved.
//
#include "MultiSpeaker.hpp"
using namespace Analyser::Dynamic;
MultiSpeaker *MultiSpeaker::create(const std::vector<std::unique_ptr<::Machine::DynamicMachine>> &machines) {
std::vector<Outputs::Speaker::Speaker *> speakers;
for(const auto &machine: machines) {
Outputs::Speaker::Speaker *speaker = machine->crt_machine()->get_speaker();
if(speaker) speakers.push_back(speaker);
}
if(speakers.empty()) return nullptr;
return new MultiSpeaker(speakers);
}
MultiSpeaker::MultiSpeaker(const std::vector<Outputs::Speaker::Speaker *> &speakers) :
speakers_(speakers), front_speaker_(speakers.front()) {
for(const auto &speaker: speakers_) {
speaker->set_delegate(this);
}
}
float MultiSpeaker::get_ideal_clock_rate_in_range(float minimum, float maximum) {
float ideal = 0.0f;
for(const auto &speaker: speakers_) {
ideal += speaker->get_ideal_clock_rate_in_range(minimum, maximum);
}
return ideal / static_cast<float>(speakers_.size());
}
void MultiSpeaker::set_output_rate(float cycles_per_second, int buffer_size) {
for(const auto &speaker: speakers_) {
speaker->set_output_rate(cycles_per_second, buffer_size);
}
}
void MultiSpeaker::set_delegate(Outputs::Speaker::Speaker::Delegate *delegate) {
delegate_ = delegate;
}
void MultiSpeaker::speaker_did_complete_samples(Speaker *speaker, const std::vector<int16_t> &buffer) {
if(!delegate_) return;
{
std::lock_guard<std::mutex> lock_guard(front_speaker_mutex_);
if(speaker != front_speaker_) return;
}
delegate_->speaker_did_complete_samples(this, buffer);
}
void MultiSpeaker::speaker_did_change_input_clock(Speaker *speaker) {
if(!delegate_) return;
{
std::lock_guard<std::mutex> lock_guard(front_speaker_mutex_);
if(speaker != front_speaker_) return;
}
delegate_->speaker_did_change_input_clock(this);
}
void MultiSpeaker::set_new_front_machine(::Machine::DynamicMachine *machine) {
{
std::lock_guard<std::mutex> lock_guard(front_speaker_mutex_);
front_speaker_ = machine->crt_machine()->get_speaker();
}
if(delegate_) {
delegate_->speaker_did_change_input_clock(this);
}
}

View File

@@ -0,0 +1,59 @@
//
// MultiSpeaker.hpp
// Clock Signal
//
// Created by Thomas Harte on 18/02/2018.
// Copyright © 2018 Thomas Harte. All rights reserved.
//
#ifndef MultiSpeaker_hpp
#define MultiSpeaker_hpp
#include "../../../../Machines/DynamicMachine.hpp"
#include "../../../../Outputs/Speaker/Speaker.hpp"
#include <memory>
#include <mutex>
#include <vector>
namespace Analyser {
namespace Dynamic {
/*!
Provides a class that multiplexes calls to and from Outputs::Speaker::Speaker in order
transparently to connect a single caller to multiple destinations.
Makes a static internal copy of the list of machines; expects the owner to keep it
abreast of the current frontmost machine.
*/
class MultiSpeaker: public Outputs::Speaker::Speaker, Outputs::Speaker::Speaker::Delegate {
public:
/*!
Provides a construction mechanism that may return nullptr, in the case that all included
machines return nullptr as their speaker.
*/
static MultiSpeaker *create(const std::vector<std::unique_ptr<::Machine::DynamicMachine>> &machines);
/// This class requires the caller to nominate changes in the frontmost machine.
void set_new_front_machine(::Machine::DynamicMachine *machine);
// Below is the standard Outputs::Speaker::Speaker interface; see there for documentation.
float get_ideal_clock_rate_in_range(float minimum, float maximum) override;
void set_output_rate(float cycles_per_second, int buffer_size) override;
void set_delegate(Outputs::Speaker::Speaker::Delegate *delegate) override;
private:
void speaker_did_complete_samples(Speaker *speaker, const std::vector<int16_t> &buffer) override;
void speaker_did_change_input_clock(Speaker *speaker) override;
MultiSpeaker(const std::vector<Outputs::Speaker::Speaker *> &speakers);
std::vector<Outputs::Speaker::Speaker *> speakers_;
Outputs::Speaker::Speaker *front_speaker_ = nullptr;
Outputs::Speaker::Speaker::Delegate *delegate_ = nullptr;
std::mutex front_speaker_mutex_;
};
}
}
#endif /* MultiSpeaker_hpp */

View File

@@ -0,0 +1,109 @@
//
// MultiMachine.cpp
// Clock Signal
//
// Created by Thomas Harte on 28/01/2018.
// Copyright © 2018 Thomas Harte. All rights reserved.
//
#include "MultiMachine.hpp"
#include <algorithm>
using namespace Analyser::Dynamic;
MultiMachine::MultiMachine(std::vector<std::unique_ptr<DynamicMachine>> &&machines) :
machines_(std::move(machines)),
configurable_(machines_),
configuration_target_(machines_),
crt_machine_(machines_, machines_mutex_),
joystick_machine_(machines),
keyboard_machine_(machines_) {
crt_machine_.set_delegate(this);
}
ConfigurationTarget::Machine *MultiMachine::configuration_target() {
if(has_picked_) {
return machines_.front()->configuration_target();
} else {
return &configuration_target_;
}
}
CRTMachine::Machine *MultiMachine::crt_machine() {
if(has_picked_) {
return machines_.front()->crt_machine();
} else {
return &crt_machine_;
}
}
JoystickMachine::Machine *MultiMachine::joystick_machine() {
if(has_picked_) {
return machines_.front()->joystick_machine();
} else {
return &joystick_machine_;
}
}
KeyboardMachine::Machine *MultiMachine::keyboard_machine() {
if(has_picked_) {
return machines_.front()->keyboard_machine();
} else {
return &keyboard_machine_;
}
}
Configurable::Device *MultiMachine::configurable_device() {
if(has_picked_) {
return machines_.front()->configurable_device();
} else {
return &configurable_;
}
}
bool MultiMachine::would_collapse(const std::vector<std::unique_ptr<DynamicMachine>> &machines) {
return
(machines.front()->crt_machine()->get_confidence() > 0.9f) ||
(machines.front()->crt_machine()->get_confidence() >= 2.0f * machines[1]->crt_machine()->get_confidence());
}
void MultiMachine::multi_crt_did_run_machines() {
std::lock_guard<std::mutex> machines_lock(machines_mutex_);
#ifdef DEBUG
for(const auto &machine: machines_) {
CRTMachine::Machine *crt = machine->crt_machine();
printf("%0.2f ", crt->get_confidence());
crt->print_type();
printf("; ");
}
printf("\n");
#endif
DynamicMachine *front = machines_.front().get();
std::stable_sort(machines_.begin(), machines_.end(),
[] (const std::unique_ptr<DynamicMachine> &lhs, const std::unique_ptr<DynamicMachine> &rhs){
CRTMachine::Machine *lhs_crt = lhs->crt_machine();
CRTMachine::Machine *rhs_crt = rhs->crt_machine();
return lhs_crt->get_confidence() > rhs_crt->get_confidence();
});
if(machines_.front().get() != front) {
crt_machine_.did_change_machine_order();
}
if(would_collapse(machines_)) {
pick_first();
}
}
void MultiMachine::pick_first() {
has_picked_ = true;
// machines_.erase(machines_.begin() + 1, machines_.end());
// TODO: this isn't quite correct, because it may leak OpenGL/etc resources through failure to
// request a close_output while the context is active.
}
void *MultiMachine::raw_pointer() {
return nullptr;
}

View File

@@ -0,0 +1,79 @@
//
// MultiMachine.hpp
// Clock Signal
//
// Created by Thomas Harte on 28/01/2018.
// Copyright © 2018 Thomas Harte. All rights reserved.
//
#ifndef MultiMachine_hpp
#define MultiMachine_hpp
#include "../../../Machines/DynamicMachine.hpp"
#include "Implementation/MultiConfigurable.hpp"
#include "Implementation/MultiConfigurationTarget.hpp"
#include "Implementation/MultiCRTMachine.hpp"
#include "Implementation/MultiJoystickMachine.hpp"
#include "Implementation/MultiKeyboardMachine.hpp"
#include <memory>
#include <mutex>
#include <vector>
namespace Analyser {
namespace Dynamic {
/*!
Provides the same interface as to a single machine, while multiplexing all
underlying calls to an array of real dynamic machines.
Calls to crt_machine->get_crt will return that for the frontmost machine;
anything installed as the speaker's delegate will similarly receive
feedback only from that machine.
Following each crt_machine->run_for, reorders the supplied machines by
confidence.
If confidence for any machine becomes disproportionately low compared to
the others in the set, that machine stops running.
*/
class MultiMachine: public ::Machine::DynamicMachine, public MultiCRTMachine::Delegate {
public:
/*!
Allows a potential MultiMachine creator to enquire as to whether there's any benefit in
requesting this class as a proxy.
@returns @c true if the multimachine would discard all but the first machine in this list;
@c false otherwise.
*/
static bool would_collapse(const std::vector<std::unique_ptr<DynamicMachine>> &machines);
MultiMachine(std::vector<std::unique_ptr<DynamicMachine>> &&machines);
ConfigurationTarget::Machine *configuration_target() override;
CRTMachine::Machine *crt_machine() override;
JoystickMachine::Machine *joystick_machine() override;
KeyboardMachine::Machine *keyboard_machine() override;
Configurable::Device *configurable_device() override;
void *raw_pointer() override;
private:
void multi_crt_did_run_machines() override;
std::vector<std::unique_ptr<DynamicMachine>> machines_;
std::mutex machines_mutex_;
MultiConfigurable configurable_;
MultiConfigurationTarget configuration_target_;
MultiCRTMachine crt_machine_;
MultiJoystickMachine joystick_machine_;
MultiKeyboardMachine keyboard_machine_;
void pick_first();
bool has_picked_ = false;
};
}
}
#endif /* MultiMachine_hpp */

27
Analyser/Machines.hpp Normal file
View File

@@ -0,0 +1,27 @@
//
// Machines.h
// Clock Signal
//
// Created by Thomas Harte on 24/01/2018.
// Copyright © 2018 Thomas Harte. All rights reserved.
//
#ifndef Machines_h
#define Machines_h
namespace Analyser {
enum class Machine {
AmstradCPC,
Atari2600,
ColecoVision,
Electron,
MSX,
Oric,
Vic20,
ZX8081
};
}
#endif /* Machines_h */

View File

@@ -7,14 +7,16 @@
//
#include "Disk.hpp"
#include "../../Storage/Disk/Controller/DiskController.hpp"
#include "../../Storage/Disk/Encodings/MFM/Parser.hpp"
#include "../../NumberTheory/CRC.hpp"
#include "../../../Storage/Disk/Controller/DiskController.hpp"
#include "../../../Storage/Disk/Encodings/MFM/Parser.hpp"
#include "../../../NumberTheory/CRC.hpp"
#include <algorithm>
using namespace StaticAnalyser::Acorn;
using namespace Analyser::Static::Acorn;
std::unique_ptr<Catalogue> StaticAnalyser::Acorn::GetDFSCatalogue(const std::shared_ptr<Storage::Disk::Disk> &disk) {
std::unique_ptr<Catalogue> Analyser::Static::Acorn::GetDFSCatalogue(const std::shared_ptr<Storage::Disk::Disk> &disk) {
// c.f. http://beebwiki.mdfs.net/Acorn_DFS_disc_format
std::unique_ptr<Catalogue> catalogue(new Catalogue);
Storage::Encodings::MFM::Parser parser(false, disk);
@@ -41,9 +43,7 @@ std::unique_ptr<Catalogue> StaticAnalyser::Acorn::GetDFSCatalogue(const std::sha
case 3: catalogue->bootOption = Catalogue::BootOption::ExecBOOT; break;
}
// DFS files are stored contiguously, and listed in descending order of distance from track 0.
// So iterating backwards implies the least amount of seeking.
for(std::size_t file_offset = final_file_offset - 8; file_offset > 0; file_offset -= 8) {
for(std::size_t file_offset = 8; file_offset < final_file_offset; file_offset += 8) {
File new_file;
char name[10];
snprintf(name, 10, "%c.%.7s", names->samples[0][file_offset + 7] & 0x7f, &names->samples[0][file_offset]);
@@ -69,12 +69,12 @@ std::unique_ptr<Catalogue> StaticAnalyser::Acorn::GetDFSCatalogue(const std::sha
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_front(new_file);
if(!data_length) catalogue->files.push_back(new_file);
}
return catalogue;
}
std::unique_ptr<Catalogue> StaticAnalyser::Acorn::GetADFSCatalogue(const std::shared_ptr<Storage::Disk::Disk> &disk) {
std::unique_ptr<Catalogue> Analyser::Static::Acorn::GetADFSCatalogue(const std::shared_ptr<Storage::Disk::Disk> &disk) {
std::unique_ptr<Catalogue> catalogue(new Catalogue);
Storage::Encodings::MFM::Parser parser(true, disk);

View File

@@ -10,15 +10,16 @@
#define StaticAnalyser_Acorn_Disk_hpp
#include "File.hpp"
#include "../../Storage/Disk/Disk.hpp"
#include "../../../Storage/Disk/Disk.hpp"
namespace StaticAnalyser {
namespace Analyser {
namespace Static {
namespace Acorn {
/// Describes a DFS- or ADFS-format catalogue(/directory) — the list of files available and the catalogue's boot option.
struct Catalogue {
std::string name;
std::list<File> files;
std::vector<File> files;
enum class BootOption {
None,
LoadBOOT,
@@ -30,6 +31,7 @@ struct Catalogue {
std::unique_ptr<Catalogue> GetDFSCatalogue(const std::shared_ptr<Storage::Disk::Disk> &disk);
std::unique_ptr<Catalogue> GetADFSCatalogue(const std::shared_ptr<Storage::Disk::Disk> &disk);
}
}
}

View File

@@ -9,12 +9,12 @@
#ifndef StaticAnalyser_Acorn_File_hpp
#define StaticAnalyser_Acorn_File_hpp
#include <list>
#include <memory>
#include <string>
#include <vector>
namespace StaticAnalyser {
namespace Analyser {
namespace Static {
namespace Acorn {
struct File {
@@ -38,9 +38,10 @@ struct File {
std::vector<uint8_t> data;
};
std::list<Chunk> chunks;
std::vector<Chunk> chunks;
};
}
}
}

View File

@@ -10,22 +10,23 @@
#include "Disk.hpp"
#include "Tape.hpp"
#include "Target.hpp"
using namespace StaticAnalyser::Acorn;
using namespace Analyser::Static::Acorn;
static std::list<std::shared_ptr<Storage::Cartridge::Cartridge>>
AcornCartridgesFrom(const std::list<std::shared_ptr<Storage::Cartridge::Cartridge>> &cartridges) {
std::list<std::shared_ptr<Storage::Cartridge::Cartridge>> acorn_cartridges;
static std::vector<std::shared_ptr<Storage::Cartridge::Cartridge>>
AcornCartridgesFrom(const std::vector<std::shared_ptr<Storage::Cartridge::Cartridge>> &cartridges) {
std::vector<std::shared_ptr<Storage::Cartridge::Cartridge>> acorn_cartridges;
for(std::shared_ptr<Storage::Cartridge::Cartridge> cartridge : cartridges) {
const std::list<Storage::Cartridge::Cartridge::Segment> &segments = cartridge->get_segments();
for(const auto &cartridge : cartridges) {
const auto &segments = cartridge->get_segments();
// only one mapped item is allowed
if(segments.size() != 1) continue;
// which must be 16 kb in size
Storage::Cartridge::Cartridge::Segment segment = segments.front();
if(segment.data.size() != 0x4000) continue;
// which must be 8 or 16 kb in size
const Storage::Cartridge::Cartridge::Segment &segment = segments.front();
if(segment.data.size() != 0x4000 && segment.data.size() != 0x2000) continue;
// is a copyright string present?
uint8_t copyright_offset = segment.data[7];
@@ -56,21 +57,21 @@ static std::list<std::shared_ptr<Storage::Cartridge::Cartridge>>
return acorn_cartridges;
}
void StaticAnalyser::Acorn::AddTargets(const Media &media, std::list<Target> &destination) {
Target target;
target.machine = Target::Electron;
target.probability = 1.0; // TODO: a proper estimation
target.acorn.has_dfs = false;
target.acorn.has_adfs = false;
target.acorn.should_shift_restart = false;
void Analyser::Static::Acorn::AddTargets(const Media &media, std::vector<std::unique_ptr<::Analyser::Static::Target>> &destination) {
std::unique_ptr<Target> target(new Target);
target->machine = Machine::Electron;
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);
target->media.cartridges = AcornCartridgesFrom(media.cartridges);
// if there are any tapes, attempt to get data from the first
if(media.tapes.size() > 0) {
std::shared_ptr<Storage::Tape::Tape> tape = media.tapes.front();
std::list<File> files = GetFiles(tape);
std::vector<File> files = GetFiles(tape);
tape->reset();
// continue if there are any files
@@ -96,9 +97,9 @@ void StaticAnalyser::Acorn::AddTargets(const Media &media, std::list<Target> &de
// Inspect first file. If it's protected or doesn't look like BASIC
// then the loading command is *RUN. Otherwise it's CHAIN"".
target.loadingCommand = is_basic ? "CHAIN\"\"\n" : "*RUN\n";
target->loading_command = is_basic ? "CHAIN\"\"\n" : "*RUN\n";
target.media.tapes = media.tapes;
target->media.tapes = media.tapes;
}
}
@@ -108,18 +109,19 @@ void StaticAnalyser::Acorn::AddTargets(const Media &media, std::list<Target> &de
dfs_catalogue = GetDFSCatalogue(disk);
if(dfs_catalogue == nullptr) adfs_catalogue = GetADFSCatalogue(disk);
if(dfs_catalogue || adfs_catalogue) {
target.media.disks = media.disks;
target.acorn.has_dfs = !!dfs_catalogue;
target.acorn.has_adfs = !!adfs_catalogue;
target->media.disks = media.disks;
target->has_dfs = !!dfs_catalogue;
target->has_adfs = !!adfs_catalogue;
Catalogue::BootOption bootOption = (dfs_catalogue ?: adfs_catalogue)->bootOption;
if(bootOption != Catalogue::BootOption::None)
target.acorn.should_shift_restart = true;
target->should_shift_restart = true;
else
target.loadingCommand = "*CAT\n";
target->loading_command = "*CAT\n";
}
}
if(target.media.tapes.size() || target.media.disks.size() || target.media.cartridges.size())
destination.push_back(target);
if(target->media.tapes.size() || target->media.disks.size() || target->media.cartridges.size()) {
destination.push_back(std::move(target));
}
}

View File

@@ -11,11 +11,13 @@
#include "../StaticAnalyser.hpp"
namespace StaticAnalyser {
namespace Analyser {
namespace Static {
namespace Acorn {
void AddTargets(const Media &media, std::list<Target> &destination);
void AddTargets(const Media &media, std::vector<std::unique_ptr<Target>> &destination);
}
}
}

View File

@@ -9,10 +9,11 @@
#include "Tape.hpp"
#include <deque>
#include "../../NumberTheory/CRC.hpp"
#include "../../Storage/Tape/Parsers/Acorn.hpp"
using namespace StaticAnalyser::Acorn;
#include "../../../NumberTheory/CRC.hpp"
#include "../../../Storage/Tape/Parsers/Acorn.hpp"
using namespace Analyser::Static::Acorn;
static std::unique_ptr<File::Chunk> GetNextChunk(const std::shared_ptr<Storage::Tape::Tape> &tape, Storage::Tape::Acorn::Parser &parser) {
std::unique_ptr<File::Chunk> new_chunk(new File::Chunk);
@@ -118,7 +119,7 @@ static std::unique_ptr<File> GetNextFile(std::deque<File::Chunk> &chunks) {
return file;
}
std::list<File> StaticAnalyser::Acorn::GetFiles(const std::shared_ptr<Storage::Tape::Tape> &tape) {
std::vector<File> Analyser::Static::Acorn::GetFiles(const std::shared_ptr<Storage::Tape::Tape> &tape) {
Storage::Tape::Acorn::Parser parser;
// populate chunk list
@@ -131,7 +132,7 @@ std::list<File> StaticAnalyser::Acorn::GetFiles(const std::shared_ptr<Storage::T
}
// decompose into file list
std::list<File> file_list;
std::vector<File> file_list;
while(chunk_list.size()) {
std::unique_ptr<File> next_file = GetNextFile(chunk_list);

View File

@@ -12,13 +12,15 @@
#include <memory>
#include "File.hpp"
#include "../../Storage/Tape/Tape.hpp"
#include "../../../Storage/Tape/Tape.hpp"
namespace StaticAnalyser {
namespace Analyser {
namespace Static {
namespace Acorn {
std::list<File> GetFiles(const std::shared_ptr<Storage::Tape::Tape> &tape);
std::vector<File> GetFiles(const std::shared_ptr<Storage::Tape::Tape> &tape);
}
}
}

View File

@@ -0,0 +1,28 @@
//
// Target.hpp
// Clock Signal
//
// Created by Thomas Harte on 09/03/2018.
// Copyright © 2018 Thomas Harte. All rights reserved.
//
#ifndef Analyser_Static_Acorn_Target_h
#define Analyser_Static_Acorn_Target_h
#include "../StaticAnalyser.hpp"
namespace Analyser {
namespace Static {
namespace Acorn {
struct Target: public ::Analyser::Static::Target {
bool has_adfs = false;
bool has_dfs = false;
bool should_shift_restart = false;
};
}
}
}
#endif /* Analyser_Static_Acorn_Target_h */

View File

@@ -11,8 +11,10 @@
#include <algorithm>
#include <cstring>
#include "../../Storage/Disk/Parsers/CPM.hpp"
#include "../../Storage/Disk/Encodings/MFM/Parser.hpp"
#include "Target.hpp"
#include "../../../Storage/Disk/Parsers/CPM.hpp"
#include "../../../Storage/Disk/Encodings/MFM/Parser.hpp"
static bool strcmp_insensitive(const char *a, const char *b) {
if(std::strlen(a) != std::strlen(b)) return false;
@@ -58,7 +60,7 @@ static std::string RunCommandFor(const Storage::Disk::CPM::File &file) {
static void InspectCatalogue(
const Storage::Disk::CPM::Catalogue &catalogue,
StaticAnalyser::Target &target) {
const std::unique_ptr<Analyser::Static::AmstradCPC::Target> &target) {
std::vector<const Storage::Disk::CPM::File *> candidate_files;
candidate_files.reserve(catalogue.files.size());
@@ -95,7 +97,7 @@ static void InspectCatalogue(
// If there's just one file, run that.
if(candidate_files.size() == 1) {
target.loadingCommand = RunCommandFor(*candidate_files[0]);
target->loading_command = RunCommandFor(*candidate_files[0]);
return;
}
@@ -126,7 +128,7 @@ static void InspectCatalogue(
}
if(basic_files == 1 || implicit_suffixed_files == 1) {
std::size_t selected_file = (basic_files == 1) ? last_basic_file : last_implicit_suffixed_file;
target.loadingCommand = RunCommandFor(*candidate_files[selected_file]);
target->loading_command = RunCommandFor(*candidate_files[selected_file]);
return;
}
@@ -143,20 +145,20 @@ static void InspectCatalogue(
if(name_counts.size() == 2) {
for(auto &pair : name_counts) {
if(pair.second == 1) {
target.loadingCommand = RunCommandFor(*candidate_files[indices_by_name[pair.first]]);
target->loading_command = RunCommandFor(*candidate_files[indices_by_name[pair.first]]);
return;
}
}
}
// Desperation.
target.loadingCommand = "cat\n";
target->loading_command = "cat\n";
}
static bool CheckBootSector(const std::shared_ptr<Storage::Disk::Disk> &disk, StaticAnalyser::Target &target) {
static 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()) {
if(boot_sector != nullptr && !boot_sector->samples.empty() && boot_sector->samples[0].size() == 512) {
// Check that the first 64 bytes of the sector aren't identical; if they are then probably
// this disk was formatted and the filler byte never replaced.
bool matched = true;
@@ -169,7 +171,7 @@ static bool CheckBootSector(const std::shared_ptr<Storage::Disk::Disk> &disk, St
// This is a system disk, then launch it as though it were CP/M.
if(!matched) {
target.loadingCommand = "|cpm\n";
target->loading_command = "|cpm\n";
return true;
}
}
@@ -177,24 +179,24 @@ static bool CheckBootSector(const std::shared_ptr<Storage::Disk::Disk> &disk, St
return false;
}
void StaticAnalyser::AmstradCPC::AddTargets(const Media &media, std::list<Target> &destination) {
Target target;
target.machine = Target::AmstradCPC;
target.probability = 1.0;
target.media.disks = media.disks;
target.media.tapes = media.tapes;
target.media.cartridges = media.cartridges;
void Analyser::Static::AmstradCPC::AddTargets(const Media &media, std::vector<std::unique_ptr<Analyser::Static::Target>> &destination) {
std::unique_ptr<Target> target(new Target);
target->machine = Machine::AmstradCPC;
target->confidence = 0.5;
target.amstradcpc.model = AmstradCPCModel::CPC6128;
target->model = Target::Model::CPC6128;
if(!media.tapes.empty()) {
// TODO: which of these are actually potentially CPC tapes?
target->media.tapes = media.tapes;
if(!target.media.tapes.empty()) {
// 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.loadingCommand = "|tape\nrun\"\n1234567890";
target->loading_command = "|tape\nrun\"\n1234567890";
}
if(!target.media.disks.empty()) {
if(!media.disks.empty()) {
Storage::Disk::CPM::ParameterBlock data_format;
data_format.sectors_per_track = 9;
data_format.tracks = 40;
@@ -203,26 +205,40 @@ void StaticAnalyser::AmstradCPC::AddTargets(const Media &media, std::list<Target
data_format.catalogue_allocation_bitmap = 0xc000;
data_format.reserved_tracks = 0;
std::unique_ptr<Storage::Disk::CPM::Catalogue> data_catalogue = Storage::Disk::CPM::GetCatalogue(target.media.disks.front(), data_format);
if(data_catalogue) {
InspectCatalogue(*data_catalogue, target);
} else {
if(!CheckBootSector(target.media.disks.front(), target)) {
Storage::Disk::CPM::ParameterBlock system_format;
system_format.sectors_per_track = 9;
system_format.tracks = 40;
system_format.block_size = 1024;
system_format.first_sector = 0x41;
system_format.catalogue_allocation_bitmap = 0xc000;
system_format.reserved_tracks = 2;
Storage::Disk::CPM::ParameterBlock system_format;
system_format.sectors_per_track = 9;
system_format.tracks = 40;
system_format.block_size = 1024;
system_format.first_sector = 0x41;
system_format.catalogue_allocation_bitmap = 0xc000;
system_format.reserved_tracks = 2;
std::unique_ptr<Storage::Disk::CPM::Catalogue> system_catalogue = Storage::Disk::CPM::GetCatalogue(target.media.disks.front(), system_format);
if(system_catalogue) {
InspectCatalogue(*system_catalogue, target);
}
for(const auto &disk: media.disks) {
// Check for an ordinary catalogue.
std::unique_ptr<Storage::Disk::CPM::Catalogue> data_catalogue = Storage::Disk::CPM::GetCatalogue(disk, data_format);
if(data_catalogue) {
InspectCatalogue(*data_catalogue, target);
target->media.disks.push_back(disk);
continue;
}
// Failing that check for a boot sector.
if(CheckBootSector(disk, target)) {
target->media.disks.push_back(disk);
continue;
}
// Failing that check for a system catalogue.
std::unique_ptr<Storage::Disk::CPM::Catalogue> system_catalogue = Storage::Disk::CPM::GetCatalogue(disk, system_format);
if(system_catalogue) {
InspectCatalogue(*system_catalogue, target);
target->media.disks.push_back(disk);
continue;
}
}
}
destination.push_back(target);
// If any media survived, add the target.
if(!target->media.empty())
destination.push_back(std::move(target));
}

View File

@@ -11,11 +11,13 @@
#include "../StaticAnalyser.hpp"
namespace StaticAnalyser {
namespace Analyser {
namespace Static {
namespace AmstradCPC {
void AddTargets(const Media &media, std::list<Target> &destination);
void AddTargets(const Media &media, std::vector<std::unique_ptr<Target>> &destination);
}
}
}

View File

@@ -0,0 +1,33 @@
//
// Target.hpp
// Clock Signal
//
// Created by Thomas Harte on 09/03/2018.
// Copyright © 2018 Thomas Harte. All rights reserved.
//
#ifndef Analyser_Static_AmstradCPC_Target_h
#define Analyser_Static_AmstradCPC_Target_h
#include "../StaticAnalyser.hpp"
namespace Analyser {
namespace Static {
namespace AmstradCPC {
struct Target: public ::Analyser::Static::Target {
enum class Model {
CPC464,
CPC664,
CPC6128
};
Model model = Model::CPC464;
};
}
}
}
#endif /* Analyser_Static_AmstradCPC_Target_h */

View File

@@ -8,11 +8,13 @@
#include "StaticAnalyser.hpp"
#include "../Disassembler/Disassembler6502.hpp"
#include "Target.hpp"
using namespace StaticAnalyser::Atari;
#include "../Disassembler/6502.hpp"
static void DeterminePagingFor2kCartridge(StaticAnalyser::Target &target, const Storage::Cartridge::Cartridge::Segment &segment) {
using namespace Analyser::Static::Atari;
static void DeterminePagingFor2kCartridge(Analyser::Static::Atari::Target &target, const Storage::Cartridge::Cartridge::Segment &segment) {
// if this is a 2kb cartridge then it's definitely either unpaged or a CommaVid
uint16_t entry_address, break_address;
@@ -26,17 +28,17 @@ static void DeterminePagingFor2kCartridge(StaticAnalyser::Target &target, const
address &= 0x1fff;
return static_cast<std::size_t>(address - 0x1800);
};
StaticAnalyser::MOS6502::Disassembly high_location_disassembly =
StaticAnalyser::MOS6502::Disassemble(segment.data, high_location_mapper, {entry_address, break_address});
Analyser::Static::MOS6502::Disassembly high_location_disassembly =
Analyser::Static::MOS6502::Disassemble(segment.data, high_location_mapper, {entry_address, break_address});
// assume that any kind of store that looks likely to be intended for large amounts of memory implies
// large amounts of memory
bool has_wide_area_store = false;
for(std::map<uint16_t, StaticAnalyser::MOS6502::Instruction>::value_type &entry : high_location_disassembly.instructions_by_address) {
if(entry.second.operation == StaticAnalyser::MOS6502::Instruction::STA) {
has_wide_area_store |= entry.second.addressing_mode == StaticAnalyser::MOS6502::Instruction::Indirect;
has_wide_area_store |= entry.second.addressing_mode == StaticAnalyser::MOS6502::Instruction::IndexedIndirectX;
has_wide_area_store |= entry.second.addressing_mode == StaticAnalyser::MOS6502::Instruction::IndirectIndexedY;
for(std::map<uint16_t, Analyser::Static::MOS6502::Instruction>::value_type &entry : high_location_disassembly.instructions_by_address) {
if(entry.second.operation == Analyser::Static::MOS6502::Instruction::STA) {
has_wide_area_store |= entry.second.addressing_mode == Analyser::Static::MOS6502::Instruction::Indirect;
has_wide_area_store |= entry.second.addressing_mode == Analyser::Static::MOS6502::Instruction::IndexedIndirectX;
has_wide_area_store |= entry.second.addressing_mode == Analyser::Static::MOS6502::Instruction::IndirectIndexedY;
if(has_wide_area_store) break;
}
@@ -46,10 +48,10 @@ static void DeterminePagingFor2kCartridge(StaticAnalyser::Target &target, const
// caveat: false positives aren't likely to be problematic; a false positive is a 2KB ROM that always addresses
// itself so as to land in ROM even if mapped as a CommaVid and this code is on the fence as to whether it
// attempts to modify itself but it probably doesn't
if(has_wide_area_store) target.atari.paging_model = StaticAnalyser::Atari2600PagingModel::CommaVid;
if(has_wide_area_store) target.paging_model = Analyser::Static::Atari::Target::PagingModel::CommaVid;
}
static void DeterminePagingFor8kCartridge(StaticAnalyser::Target &target, const Storage::Cartridge::Cartridge::Segment &segment, const StaticAnalyser::MOS6502::Disassembly &disassembly) {
static void DeterminePagingFor8kCartridge(Analyser::Static::Atari::Target &target, const Storage::Cartridge::Cartridge::Segment &segment, const Analyser::Static::MOS6502::Disassembly &disassembly) {
// Activision stack titles have their vectors at the top of the low 4k, not the top, and
// always list 0xf000 as both vectors; they do not repeat them, and, inexplicably, they all
// issue an SEI as their first instruction (maybe some sort of relic of the development environment?)
@@ -58,12 +60,12 @@ static void DeterminePagingFor8kCartridge(StaticAnalyser::Target &target, const
(segment.data[8191] != 0xf0 || segment.data[8189] != 0xf0 || segment.data[8190] != 0x00 || segment.data[8188] != 0x00) &&
segment.data[0] == 0x78
) {
target.atari.paging_model = StaticAnalyser::Atari2600PagingModel::ActivisionStack;
target.paging_model = Analyser::Static::Atari::Target::PagingModel::ActivisionStack;
return;
}
// make an assumption that this is the Atari paging model
target.atari.paging_model = StaticAnalyser::Atari2600PagingModel::Atari8k;
target.paging_model = Analyser::Static::Atari::Target::PagingModel::Atari8k;
std::set<uint16_t> internal_accesses;
internal_accesses.insert(disassembly.internal_stores.begin(), disassembly.internal_stores.end());
@@ -83,13 +85,13 @@ static void DeterminePagingFor8kCartridge(StaticAnalyser::Target &target, const
tigervision_access_count += masked_address == 0x3f;
}
if(parker_access_count > atari_access_count) target.atari.paging_model = StaticAnalyser::Atari2600PagingModel::ParkerBros;
else if(tigervision_access_count > atari_access_count) target.atari.paging_model = StaticAnalyser::Atari2600PagingModel::Tigervision;
if(parker_access_count > atari_access_count) target.paging_model = Analyser::Static::Atari::Target::PagingModel::ParkerBros;
else if(tigervision_access_count > atari_access_count) target.paging_model = Analyser::Static::Atari::Target::PagingModel::Tigervision;
}
static void DeterminePagingFor16kCartridge(StaticAnalyser::Target &target, const Storage::Cartridge::Cartridge::Segment &segment, const StaticAnalyser::MOS6502::Disassembly &disassembly) {
static void DeterminePagingFor16kCartridge(Analyser::Static::Atari::Target &target, const Storage::Cartridge::Cartridge::Segment &segment, const Analyser::Static::MOS6502::Disassembly &disassembly) {
// make an assumption that this is the Atari paging model
target.atari.paging_model = StaticAnalyser::Atari2600PagingModel::Atari16k;
target.paging_model = Analyser::Static::Atari::Target::PagingModel::Atari16k;
std::set<uint16_t> internal_accesses;
internal_accesses.insert(disassembly.internal_stores.begin(), disassembly.internal_stores.end());
@@ -104,17 +106,17 @@ static void DeterminePagingFor16kCartridge(StaticAnalyser::Target &target, const
mnetwork_access_count += masked_address >= 0x1fe0 && masked_address < 0x1ffb;
}
if(mnetwork_access_count > atari_access_count) target.atari.paging_model = StaticAnalyser::Atari2600PagingModel::MNetwork;
if(mnetwork_access_count > atari_access_count) target.paging_model = Analyser::Static::Atari::Target::PagingModel::MNetwork;
}
static void DeterminePagingFor64kCartridge(StaticAnalyser::Target &target, const Storage::Cartridge::Cartridge::Segment &segment, const StaticAnalyser::MOS6502::Disassembly &disassembly) {
static void DeterminePagingFor64kCartridge(Analyser::Static::Atari::Target &target, const Storage::Cartridge::Cartridge::Segment &segment, const Analyser::Static::MOS6502::Disassembly &disassembly) {
// make an assumption that this is a Tigervision if there is a write to 3F
target.atari.paging_model =
target.paging_model =
(disassembly.external_stores.find(0x3f) != disassembly.external_stores.end()) ?
StaticAnalyser::Atari2600PagingModel::Tigervision : StaticAnalyser::Atari2600PagingModel::MegaBoy;
Analyser::Static::Atari::Target::PagingModel::Tigervision : Analyser::Static::Atari::Target::PagingModel::MegaBoy;
}
static void DeterminePagingForCartridge(StaticAnalyser::Target &target, const Storage::Cartridge::Cartridge::Segment &segment) {
static void DeterminePagingForCartridge(Analyser::Static::Atari::Target &target, const Storage::Cartridge::Cartridge::Segment &segment) {
if(segment.data.size() == 2048) {
DeterminePagingFor2kCartridge(target, segment);
return;
@@ -131,23 +133,23 @@ static void DeterminePagingForCartridge(StaticAnalyser::Target &target, const St
};
std::vector<uint8_t> final_4k(segment.data.end() - 4096, segment.data.end());
StaticAnalyser::MOS6502::Disassembly disassembly = StaticAnalyser::MOS6502::Disassemble(final_4k, address_mapper, {entry_address, break_address});
Analyser::Static::MOS6502::Disassembly disassembly = Analyser::Static::MOS6502::Disassemble(final_4k, address_mapper, {entry_address, break_address});
switch(segment.data.size()) {
case 8192:
DeterminePagingFor8kCartridge(target, segment, disassembly);
break;
case 10495:
target.atari.paging_model = StaticAnalyser::Atari2600PagingModel::Pitfall2;
target.paging_model = Analyser::Static::Atari::Target::PagingModel::Pitfall2;
break;
case 12288:
target.atari.paging_model = StaticAnalyser::Atari2600PagingModel::CBSRamPlus;
target.paging_model = Analyser::Static::Atari::Target::PagingModel::CBSRamPlus;
break;
case 16384:
DeterminePagingFor16kCartridge(target, segment, disassembly);
break;
case 32768:
target.atari.paging_model = StaticAnalyser::Atari2600PagingModel::Atari32k;
target.paging_model = Analyser::Static::Atari::Target::PagingModel::Atari32k;
break;
case 65536:
DeterminePagingFor64kCartridge(target, segment, disassembly);
@@ -159,8 +161,8 @@ static void DeterminePagingForCartridge(StaticAnalyser::Target &target, const St
// check for a Super Chip. Atari ROM images [almost] always have the same value stored over RAM
// regions; when they don't they at least seem to have the first 128 bytes be the same as the
// next 128 bytes. So check for that.
if( target.atari.paging_model != StaticAnalyser::Atari2600PagingModel::CBSRamPlus &&
target.atari.paging_model != StaticAnalyser::Atari2600PagingModel::MNetwork) {
if( target.paging_model != Analyser::Static::Atari::Target::PagingModel::CBSRamPlus &&
target.paging_model != Analyser::Static::Atari::Target::PagingModel::MNetwork) {
bool has_superchip = true;
for(std::size_t address = 0; address < 128; address++) {
if(segment.data[address] != segment.data[address+128]) {
@@ -168,34 +170,34 @@ static void DeterminePagingForCartridge(StaticAnalyser::Target &target, const St
break;
}
}
target.atari.uses_superchip = has_superchip;
target.uses_superchip = has_superchip;
}
// check for a Tigervision or Tigervision-esque scheme
if(target.atari.paging_model == StaticAnalyser::Atari2600PagingModel::None && segment.data.size() > 4096) {
if(target.paging_model == Analyser::Static::Atari::Target::PagingModel::None && segment.data.size() > 4096) {
bool looks_like_tigervision = disassembly.external_stores.find(0x3f) != disassembly.external_stores.end();
if(looks_like_tigervision) target.atari.paging_model = StaticAnalyser::Atari2600PagingModel::Tigervision;
if(looks_like_tigervision) target.paging_model = Analyser::Static::Atari::Target::PagingModel::Tigervision;
}
}
void StaticAnalyser::Atari::AddTargets(const Media &media, std::list<Target> &destination) {
// TODO: sanity checking; is this image really for an Atari 2600.
Target target;
target.machine = Target::Atari2600;
target.probability = 1.0;
target.media.cartridges = media.cartridges;
target.atari.paging_model = Atari2600PagingModel::None;
target.atari.uses_superchip = false;
void Analyser::Static::Atari::AddTargets(const Media &media, std::vector<std::unique_ptr<Analyser::Static::Target>> &destination) {
// TODO: sanity checking; is this image really for an Atari 2600?
std::unique_ptr<Analyser::Static::Atari::Target> target(new Analyser::Static::Atari::Target);
target->machine = Machine::Atari2600;
target->confidence = 0.5;
target->media.cartridges = media.cartridges;
target->paging_model = Analyser::Static::Atari::Target::PagingModel::None;
target->uses_superchip = false;
// try to figure out the paging scheme
if(!media.cartridges.empty()) {
const std::list<Storage::Cartridge::Cartridge::Segment> &segments = media.cartridges.front()->get_segments();
const auto &segments = media.cartridges.front()->get_segments();
if(segments.size() == 1) {
const Storage::Cartridge::Cartridge::Segment &segment = segments.front();
DeterminePagingForCartridge(target, segment);
DeterminePagingForCartridge(*target, segment);
}
}
destination.push_back(target);
destination.push_back(std::move(target));
}

View File

@@ -11,11 +11,13 @@
#include "../StaticAnalyser.hpp"
namespace StaticAnalyser {
namespace Analyser {
namespace Static {
namespace Atari {
void AddTargets(const Media &media, std::list<Target> &destination);
void AddTargets(const Media &media, std::vector<std::unique_ptr<Target>> &destination);
}
}
}

View File

@@ -0,0 +1,43 @@
//
// Target.hpp
// Clock Signal
//
// Created by Thomas Harte on 09/03/2018.
// Copyright © 2018 Thomas Harte. All rights reserved.
//
#ifndef Analyser_Static_Atari_Target_h
#define Analyser_Static_Atari_Target_h
#include "../StaticAnalyser.hpp"
namespace Analyser {
namespace Static {
namespace Atari {
struct Target: public ::Analyser::Static::Target {
enum class PagingModel {
None,
CommaVid,
Atari8k,
Atari16k,
Atari32k,
ActivisionStack,
ParkerBros,
Tigervision,
CBSRamPlus,
MNetwork,
MegaBoy,
Pitfall2
};
// TODO: shouldn't these be properties of the cartridge?
PagingModel paging_model = PagingModel::None;
bool uses_superchip = false;
};
}
}
}
#endif /* Analyser_Static_Atari_Target_h */

View File

@@ -0,0 +1,62 @@
//
// StaticAnalyser.cpp
// Clock Signal
//
// Created by Thomas Harte on 23/02/2018.
// Copyright © 2018 Thomas Harte. All rights reserved.
//
#include "StaticAnalyser.hpp"
static std::vector<std::shared_ptr<Storage::Cartridge::Cartridge>>
ColecoCartridgesFrom(const std::vector<std::shared_ptr<Storage::Cartridge::Cartridge>> &cartridges) {
std::vector<std::shared_ptr<Storage::Cartridge::Cartridge>> coleco_cartridges;
for(const auto &cartridge : cartridges) {
const auto &segments = cartridge->get_segments();
// only one mapped item is allowed
if(segments.size() != 1) continue;
// which must be 8, 12, 16, 24 or 32 kb in size
const Storage::Cartridge::Cartridge::Segment &segment = segments.front();
const std::size_t data_size = segment.data.size();
const std::size_t overflow = data_size&8191;
if(overflow > 8 && overflow != 512 && (data_size != 12*1024)) continue;
if(data_size < 8192) continue;
// the two bytes that will be first must be 0xaa and 0x55, either way around
auto *start = &segment.data[0];
if((data_size & static_cast<std::size_t>(~8191)) > 32768) {
start = &segment.data[segment.data.size() - 16384];
}
if(start[0] != 0xaa && start[0] != 0x55 && start[1] != 0xaa && start[1] != 0x55) continue;
if(start[0] == start[1]) continue;
// probability of a random binary blob that isn't a Coleco ROM proceeding to here is 1 - 1/32768.
if(!overflow) {
coleco_cartridges.push_back(cartridge);
} else {
// Size down to a multiple of 8kb and apply the start address.
std::vector<Storage::Cartridge::Cartridge::Segment> output_segments;
std::vector<uint8_t> truncated_data;
std::vector<uint8_t>::difference_type truncated_size = static_cast<std::vector<uint8_t>::difference_type>(segment.data.size()) & ~8191;
truncated_data.insert(truncated_data.begin(), segment.data.begin(), segment.data.begin() + truncated_size);
output_segments.emplace_back(0x8000, truncated_data);
coleco_cartridges.emplace_back(new Storage::Cartridge::Cartridge(output_segments));
}
}
return coleco_cartridges;
}
void Analyser::Static::Coleco::AddTargets(const Media &media, std::vector<std::unique_ptr<Target>> &destination) {
std::unique_ptr<Target> target(new Target);
target->machine = Machine::ColecoVision;
target->confidence = 1.0f - 1.0f / 32768.0f;
target->media.cartridges = ColecoCartridgesFrom(media.cartridges);
if(!target->media.empty())
destination.push_back(std::move(target));
}

View File

@@ -0,0 +1,25 @@
//
// StaticAnalyser.hpp
// Clock Signal
//
// Created by Thomas Harte on 23/02/2018.
// Copyright © 2018 Thomas Harte. All rights reserved.
//
#ifndef StaticAnalyser_Coleco_StaticAnalyser_hpp
#define StaticAnalyser_Coleco_StaticAnalyser_hpp
#include "../StaticAnalyser.hpp"
namespace Analyser {
namespace Static {
namespace Coleco {
void AddTargets(const Media &media, std::vector<std::unique_ptr<Target>> &destination);
}
}
}
#endif /* StaticAnalyser_hpp */

View File

@@ -7,15 +7,15 @@
//
#include "Disk.hpp"
#include "../../Storage/Disk/Controller/DiskController.hpp"
#include "../../Storage/Disk/Encodings/CommodoreGCR.hpp"
#include "../../Storage/Data/Commodore.hpp"
#include "../../../Storage/Disk/Controller/DiskController.hpp"
#include "../../../Storage/Disk/Encodings/CommodoreGCR.hpp"
#include "../../../Storage/Data/Commodore.hpp"
#include <limits>
#include <vector>
#include <array>
using namespace StaticAnalyser::Commodore;
using namespace Analyser::Static::Commodore;
class CommodoreGCRParser: public Storage::Disk::Controller {
public:
@@ -71,19 +71,19 @@ class CommodoreGCRParser: public Storage::Disk::Controller {
bit_count_++;
}
unsigned int proceed_to_next_block() {
unsigned int proceed_to_next_block(int max_index_count) {
// find GCR lead-in
proceed_to_shift_value(0x3ff);
if(shift_register_ != 0x3ff) return 0xff;
// find end of lead-in
while(shift_register_ == 0x3ff && index_count_ < 2) {
while(shift_register_ == 0x3ff && index_count_ < max_index_count) {
run_for(Cycles(1));
}
// continue for a further nine bits
bit_count_ = 0;
while(bit_count_ < 9 && index_count_ < 2) {
while(bit_count_ < 9 && index_count_ < max_index_count) {
run_for(Cycles(1));
}
@@ -97,8 +97,8 @@ class CommodoreGCRParser: public Storage::Disk::Controller {
}
void proceed_to_shift_value(unsigned int shift_value) {
index_count_ = 0;
while(shift_register_ != shift_value && index_count_ < 2) {
const int max_index_count = index_count_ + 2;
while(shift_register_ != shift_value && index_count_ < max_index_count) {
run_for(Cycles(1));
}
}
@@ -124,13 +124,13 @@ class CommodoreGCRParser: public Storage::Disk::Controller {
std::shared_ptr<Sector> get_next_sector() {
std::shared_ptr<Sector> sector(new Sector);
index_count_ = 0;
const int max_index_count = index_count_ + 2;
while(index_count_ < 2) {
while(index_count_ < max_index_count) {
// look for a sector header
while(1) {
if(proceed_to_next_block() == 0x08) break;
if(index_count_ >= 2) return nullptr;
if(proceed_to_next_block(max_index_count) == 0x08) break;
if(index_count_ >= max_index_count) return nullptr;
}
// get sector details, skip if this looks malformed
@@ -144,8 +144,8 @@ class CommodoreGCRParser: public Storage::Disk::Controller {
// look for the following data
while(1) {
if(proceed_to_next_block() == 0x07) break;
if(index_count_ >= 2) return nullptr;
if(proceed_to_next_block(max_index_count) == 0x07) break;
if(index_count_ >= max_index_count) return nullptr;
}
checksum = 0;
@@ -165,8 +165,8 @@ class CommodoreGCRParser: public Storage::Disk::Controller {
}
};
std::list<File> StaticAnalyser::Commodore::GetFiles(const std::shared_ptr<Storage::Disk::Disk> &disk) {
std::list<File> files;
std::vector<File> Analyser::Static::Commodore::GetFiles(const std::shared_ptr<Storage::Disk::Disk> &disk) {
std::vector<File> files;
CommodoreGCRParser parser;
parser.drive->set_disk(disk);

View File

@@ -9,17 +9,19 @@
#ifndef StaticAnalyser_Commodore_Disk_hpp
#define StaticAnalyser_Commodore_Disk_hpp
#include "../../Storage/Disk/Disk.hpp"
#include "../../../Storage/Disk/Disk.hpp"
#include "File.hpp"
#include <list>
namespace StaticAnalyser {
#include <vector>
namespace Analyser {
namespace Static {
namespace Commodore {
std::list<File> GetFiles(const std::shared_ptr<Storage::Disk::Disk> &disk);
std::vector<File> GetFiles(const std::shared_ptr<Storage::Disk::Disk> &disk);
}
}
}
#endif /* Disk_hpp */

View File

@@ -8,7 +8,7 @@
#include "File.hpp"
bool StaticAnalyser::Commodore::File::is_basic() {
bool Analyser::Static::Commodore::File::is_basic() {
// BASIC files are always relocatable (?)
if(type != File::RelocatableProgram) return false;

View File

@@ -12,7 +12,8 @@
#include <string>
#include <vector>
namespace StaticAnalyser {
namespace Analyser {
namespace Static {
namespace Commodore {
struct File {
@@ -34,6 +35,7 @@ struct File {
bool is_basic();
};
}
}
}

View File

@@ -8,21 +8,23 @@
#include "StaticAnalyser.hpp"
#include "Disk.hpp"
#include "File.hpp"
#include "Tape.hpp"
#include "Disk.hpp"
#include "../../Storage/Cartridge/Encodings/CommodoreROM.hpp"
#include "Target.hpp"
#include "../../../Storage/Cartridge/Encodings/CommodoreROM.hpp"
#include <algorithm>
#include <sstream>
using namespace StaticAnalyser::Commodore;
using namespace Analyser::Static::Commodore;
static std::list<std::shared_ptr<Storage::Cartridge::Cartridge>>
Vic20CartridgesFrom(const std::list<std::shared_ptr<Storage::Cartridge::Cartridge>> &cartridges) {
std::list<std::shared_ptr<Storage::Cartridge::Cartridge>> vic20_cartridges;
static std::vector<std::shared_ptr<Storage::Cartridge::Cartridge>>
Vic20CartridgesFrom(const std::vector<std::shared_ptr<Storage::Cartridge::Cartridge>> &cartridges) {
std::vector<std::shared_ptr<Storage::Cartridge::Cartridge>> vic20_cartridges;
for(std::shared_ptr<Storage::Cartridge::Cartridge> cartridge : cartridges) {
const std::list<Storage::Cartridge::Cartridge::Segment> &segments = cartridge->get_segments();
for(const auto &cartridge : cartridges) {
const auto &segments = cartridge->get_segments();
// only one mapped item is allowed
if(segments.size() != 1) continue;
@@ -38,42 +40,42 @@ static std::list<std::shared_ptr<Storage::Cartridge::Cartridge>>
return vic20_cartridges;
}
void StaticAnalyser::Commodore::AddTargets(const Media &media, std::list<Target> &destination) {
Target target;
target.machine = Target::Vic20; // TODO: machine estimation
target.probability = 1.0; // TODO: a proper estimation
void Analyser::Static::Commodore::AddTargets(const Media &media, std::vector<std::unique_ptr<Analyser::Static::Target>> &destination, const std::string &file_name) {
std::unique_ptr<Target> target(new Target);
target->machine = Machine::Vic20; // TODO: machine estimation
target->confidence = 0.5; // TODO: a proper estimation
int device = 0;
std::list<File> files;
std::vector<File> files;
bool is_disk = false;
// strip out inappropriate cartridges
target.media.cartridges = Vic20CartridgesFrom(media.cartridges);
target->media.cartridges = Vic20CartridgesFrom(media.cartridges);
// check disks
for(auto &disk : media.disks) {
std::list<File> disk_files = GetFiles(disk);
std::vector<File> disk_files = GetFiles(disk);
if(!disk_files.empty()) {
is_disk = true;
files.splice(files.end(), disk_files);
target.media.disks.push_back(disk);
files.insert(files.end(), disk_files.begin(), disk_files.end());
target->media.disks.push_back(disk);
if(!device) device = 8;
}
}
// check tapes
for(auto &tape : media.tapes) {
std::list<File> tape_files = GetFiles(tape);
std::vector<File> tape_files = GetFiles(tape);
tape->reset();
if(!tape_files.empty()) {
files.splice(files.end(), tape_files);
target.media.tapes.push_back(tape);
files.insert(files.end(), tape_files.begin(), tape_files.end());
target->media.tapes.push_back(tape);
if(!device) device = 1;
}
}
if(!files.empty()) {
target.vic20.memory_model = Vic20MemoryModel::Unexpanded;
target->memory_model = Target::MemoryModel::Unexpanded;
std::ostringstream string_stream;
string_stream << "LOAD\"" << (is_disk ? "*" : "") << "\"," << device << ",";
if(files.front().is_basic()) {
@@ -82,23 +84,26 @@ void StaticAnalyser::Commodore::AddTargets(const Media &media, std::list<Target>
string_stream << "1";
}
string_stream << "\nRUN\n";
target.loadingCommand = string_stream.str();
target->loading_command = string_stream.str();
// make a first guess based on loading address
switch(files.front().starting_address) {
default:
printf("Starting address %04x?\n", files.front().starting_address);
case 0x1001:
default: break;
target->memory_model = Target::MemoryModel::Unexpanded;
break;
case 0x1201:
target.vic20.memory_model = Vic20MemoryModel::ThirtyTwoKB;
target->memory_model = Target::MemoryModel::ThirtyTwoKB;
break;
case 0x0401:
target.vic20.memory_model = Vic20MemoryModel::EightKB;
target->memory_model = Target::MemoryModel::EightKB;
break;
}
// General approach: increase memory size conservatively such that the largest file found will fit.
for(File &file : files) {
std::size_t file_size = file.data.size();
// for(File &file : files) {
// std::size_t file_size = file.data.size();
// bool is_basic = file.is_basic();
/*if(is_basic)
@@ -108,9 +113,9 @@ void StaticAnalyser::Commodore::AddTargets(const Media &media, std::list<Target>
// An unexpanded machine has 3583 bytes free for BASIC;
// a 3kb expanded machine has 6655 bytes free.
if(file_size > 6655)
target.vic20.memory_model = Vic20MemoryModel::ThirtyTwoKB;
else if(target.vic20.memory_model == Vic20MemoryModel::Unexpanded && file_size > 3583)
target.vic20.memory_model = Vic20MemoryModel::EightKB;
target->vic20.memory_model = Vic20MemoryModel::ThirtyTwoKB;
else if(target->vic20.memory_model == Vic20MemoryModel::Unexpanded && file_size > 3583)
target->vic20.memory_model = Vic20MemoryModel::EightKB;
}
else
{*/
@@ -124,18 +129,26 @@ void StaticAnalyser::Commodore::AddTargets(const Media &media, std::list<Target>
// An unexpanded Vic has memory between 0x0000 and 0x0400; and between 0x1000 and 0x2000.
// A 3kb expanded Vic fills in the gap and has memory between 0x0000 and 0x2000.
// A 32kb expanded Vic has memory in the entire low 32kb.
uint16_t starting_address = file.starting_address;
// uint16_t starting_address = file.starting_address;
// If anything above the 8kb mark is touched, mark as a 32kb machine; otherwise if the
// region 0x0400 to 0x1000 is touched and this is an unexpanded machine, mark as 3kb.
if(starting_address + file_size > 0x2000)
target.vic20.memory_model = Vic20MemoryModel::ThirtyTwoKB;
else if(target.vic20.memory_model == Vic20MemoryModel::Unexpanded && !(starting_address >= 0x1000 || starting_address+file_size < 0x0400))
target.vic20.memory_model = Vic20MemoryModel::ThirtyTwoKB;
// if(starting_address + file_size > 0x2000)
// target->memory_model = Target::MemoryModel::ThirtyTwoKB;
// else if(target->memory_model == Target::MemoryModel::Unexpanded && !(starting_address >= 0x1000 || starting_address+file_size < 0x0400))
// target->memory_model = Target::MemoryModel::ThirtyTwoKB;
// }
}
// }
}
if(!target.media.tapes.empty() || !target.media.cartridges.empty() || !target.media.disks.empty())
destination.push_back(target);
if(!target->media.empty()) {
// Inspect filename for a region hint.
std::string lowercase_name = file_name;
std::transform(lowercase_name.begin(), lowercase_name.end(), lowercase_name.begin(), ::tolower);
if(lowercase_name.find("ntsc") != std::string::npos) {
target->region = Analyser::Static::Commodore::Target::Region::American;
}
destination.push_back(std::move(target));
}
}

View File

@@ -10,12 +10,15 @@
#define StaticAnalyser_Commodore_StaticAnalyser_hpp
#include "../StaticAnalyser.hpp"
#include <string>
namespace StaticAnalyser {
namespace Analyser {
namespace Static {
namespace Commodore {
void AddTargets(const Media &media, std::list<Target> &destination);
void AddTargets(const Media &media, std::vector<std::unique_ptr<Target>> &destination, const std::string &file_name);
}
}
}

View File

@@ -8,13 +8,13 @@
#include "Tape.hpp"
#include "../../Storage/Tape/Parsers/Commodore.hpp"
#include "../../../Storage/Tape/Parsers/Commodore.hpp"
using namespace StaticAnalyser::Commodore;
using namespace Analyser::Static::Commodore;
std::list<File> StaticAnalyser::Commodore::GetFiles(const std::shared_ptr<Storage::Tape::Tape> &tape) {
std::vector<File> Analyser::Static::Commodore::GetFiles(const std::shared_ptr<Storage::Tape::Tape> &tape) {
Storage::Tape::Commodore::Parser parser;
std::list<File> file_list;
std::vector<File> file_list;
std::unique_ptr<Storage::Tape::Commodore::Header> header = parser.get_next_header(tape);

View File

@@ -9,15 +9,16 @@
#ifndef StaticAnalyser_Commodore_Tape_hpp
#define StaticAnalyser_Commodore_Tape_hpp
#include "../../Storage/Tape/Tape.hpp"
#include "../../../Storage/Tape/Tape.hpp"
#include "File.hpp"
#include <list>
namespace StaticAnalyser {
namespace Analyser {
namespace Static {
namespace Commodore {
std::list<File> GetFiles(const std::shared_ptr<Storage::Tape::Tape> &tape);
std::vector<File> GetFiles(const std::shared_ptr<Storage::Tape::Tape> &tape);
}
}
}

View File

@@ -0,0 +1,42 @@
//
// Target.hpp
// Clock Signal
//
// Created by Thomas Harte on 09/03/2018.
// Copyright © 2018 Thomas Harte. All rights reserved.
//
#ifndef Analyser_Static_Commodore_Target_h
#define Analyser_Static_Commodore_Target_h
#include "../StaticAnalyser.hpp"
namespace Analyser {
namespace Static {
namespace Commodore {
struct Target: public ::Analyser::Static::Target {
enum class MemoryModel {
Unexpanded,
EightKB,
ThirtyTwoKB
};
enum class Region {
American,
Danish,
Japanese,
European,
Swedish
};
MemoryModel memory_model = MemoryModel::Unexpanded;
Region region = Region::European;
bool has_c1540 = false;
};
}
}
}
#endif /* Analyser_Static_Commodore_Target_h */

View File

@@ -6,24 +6,25 @@
// Copyright © 2016 Thomas Harte. All rights reserved.
//
#include "Disassembler6502.hpp"
#include <map>
#include "6502.hpp"
using namespace StaticAnalyser::MOS6502;
#include "Kernel.hpp"
struct PartialDisassembly {
Disassembly disassembly;
std::vector<uint16_t> remaining_entry_points;
};
using namespace Analyser::Static::MOS6502;
namespace {
using PartialDisassembly = Analyser::Static::Disassembly::PartialDisassembly<Disassembly, uint16_t>;
struct MOS6502Disassembler {
static void AddToDisassembly(PartialDisassembly &disassembly, const std::vector<uint8_t> &memory, const std::function<std::size_t(uint16_t)> &address_mapper, uint16_t entry_point) {
disassembly.disassembly.internal_calls.insert(entry_point);
uint16_t address = entry_point;
while(1) {
while(true) {
std::size_t local_address = address_mapper(address);
if(local_address >= memory.size()) return;
struct Instruction instruction;
Instruction instruction;
instruction.address = address;
address++;
@@ -307,31 +308,13 @@ static void AddToDisassembly(PartialDisassembly &disassembly, const std::vector<
}
}
Disassembly StaticAnalyser::MOS6502::Disassemble(const std::vector<uint8_t> &memory, const std::function<std::size_t(uint16_t)> &address_mapper, std::vector<uint16_t> entry_points) {
PartialDisassembly partialDisassembly;
partialDisassembly.remaining_entry_points = entry_points;
};
while(!partialDisassembly.remaining_entry_points.empty()) {
// pull the next entry point from the back of the vector
uint16_t next_entry_point = partialDisassembly.remaining_entry_points.back();
partialDisassembly.remaining_entry_points.pop_back();
} // end of anonymous namespace
// if that address has already bene visited, forget about it
if(partialDisassembly.disassembly.instructions_by_address.find(next_entry_point) != partialDisassembly.disassembly.instructions_by_address.end()) continue;
// if it's outgoing, log it as such and forget about it; otherwise disassemble
std::size_t mapped_entry_point = address_mapper(next_entry_point);
if(mapped_entry_point >= memory.size())
partialDisassembly.disassembly.outward_calls.insert(next_entry_point);
else
AddToDisassembly(partialDisassembly, memory, address_mapper, next_entry_point);
}
return std::move(partialDisassembly.disassembly);
}
std::function<std::size_t(uint16_t)> StaticAnalyser::MOS6502::OffsetMapper(uint16_t start_address) {
return [start_address](uint16_t argument) {
return static_cast<std::size_t>(argument - start_address);
};
Disassembly Analyser::Static::MOS6502::Disassemble(
const std::vector<uint8_t> &memory,
const std::function<std::size_t(uint16_t)> &address_mapper,
std::vector<uint16_t> entry_points) {
return Analyser::Static::Disassembly::Disassemble<Disassembly, uint16_t, MOS6502Disassembler>(memory, address_mapper, entry_points);
}

View File

@@ -0,0 +1,101 @@
//
// 6502.hpp
// Clock Signal
//
// Created by Thomas Harte on 10/11/2016.
// Copyright © 2016 Thomas Harte. All rights reserved.
//
#ifndef StaticAnalyser_Disassembler_6502_hpp
#define StaticAnalyser_Disassembler_6502_hpp
#include <cstdint>
#include <functional>
#include <map>
#include <memory>
#include <set>
#include <vector>
namespace Analyser {
namespace Static {
namespace MOS6502 {
/*!
Describes a 6502 instruciton — its address, the operation it performs, its addressing mode
and its operand, if any.
*/
struct Instruction {
/*! The address this instruction starts at. This is a mapped address. */
uint16_t address = 0;
/*! The operation this instruction performs. */
enum {
BRK, JSR, RTI, RTS, JMP,
CLC, SEC, CLD, SED, CLI, SEI, CLV,
NOP,
SLO, RLA, SRE, RRA, ALR, ARR,
SAX, LAX, DCP, ISC,
ANC, XAA, AXS,
AND, EOR, ORA, BIT,
ADC, SBC,
AHX, SHY, SHX, TAS, LAS,
LDA, STA, LDX, STX, LDY, STY,
BPL, BMI, BVC, BVS, BCC, BCS, BNE, BEQ,
CMP, CPX, CPY,
INC, DEC, DEX, DEY, INX, INY,
ASL, ROL, LSR, ROR,
TAX, TXA, TAY, TYA, TSX, TXS,
PLA, PHA, PLP, PHP,
KIL
} operation = NOP;
/*! The addressing mode used by the instruction. */
enum {
Absolute,
AbsoluteX,
AbsoluteY,
Immediate,
Implied,
ZeroPage,
ZeroPageX,
ZeroPageY,
Indirect,
IndexedIndirectX,
IndirectIndexedY,
Relative,
} addressing_mode = Implied;
/*! The instruction's operand, if any. */
uint16_t operand = 0;
};
/*! Represents the disassembled form of a program. */
struct Disassembly {
/*! All instructions found, mapped by address. */
std::map<uint16_t, Instruction> instructions_by_address;
/*! The set of all calls or jumps that land outside of the area covered by the data provided for disassembly. */
std::set<uint16_t> outward_calls;
/*! The set of all calls or jumps that land inside of the area covered by the data provided for disassembly. */
std::set<uint16_t> internal_calls;
/*! The sets of all stores, loads and modifies that occur to data outside of the area covered by the data provided for disassembly. */
std::set<uint16_t> external_stores, external_loads, external_modifies;
/*! The sets of all stores, loads and modifies that occur to data inside of the area covered by the data provided for disassembly. */
std::set<uint16_t> internal_stores, internal_loads, internal_modifies;
};
/*!
Disassembles the data provided as @c memory, mapping it into the 6502's full address range via the @c address_mapper,
starting disassembly from each of the @c entry_points.
*/
Disassembly Disassemble(
const std::vector<uint8_t> &memory,
const std::function<std::size_t(uint16_t)> &address_mapper,
std::vector<uint16_t> entry_points);
}
}
}
#endif /* Disassembler6502_hpp */

View File

@@ -0,0 +1,9 @@
//
// AddressMapper.cpp
// Clock Signal
//
// Created by Thomas Harte on 30/12/2017.
// Copyright © 2017 Thomas Harte. All rights reserved.
//
#include "AddressMapper.hpp"

View File

@@ -0,0 +1,32 @@
//
// AddressMapper.hpp
// Clock Signal
//
// Created by Thomas Harte on 30/12/2017.
// Copyright © 2017 Thomas Harte. All rights reserved.
//
#ifndef AddressMapper_hpp
#define AddressMapper_hpp
#include <functional>
namespace Analyser {
namespace Static {
namespace Disassembler {
/*!
Provides an address mapper that relocates a chunk of memory so that it starts at
address @c start_address.
*/
template <typename T> std::function<std::size_t(T)> OffsetMapper(T start_address) {
return [start_address](T argument) {
return static_cast<std::size_t>(argument - start_address);
};
}
}
}
}
#endif /* AddressMapper_hpp */

View File

@@ -0,0 +1,52 @@
//
// Kernel.hpp
// Clock Signal
//
// Created by Thomas Harte on 31/12/2017.
// Copyright © 2017 Thomas Harte. All rights reserved.
//
#ifndef Kernel_hpp
#define Kernel_hpp
namespace Analyser {
namespace Static {
namespace Disassembly {
template <typename D, typename S> struct PartialDisassembly {
D disassembly;
std::vector<S> remaining_entry_points;
};
template <typename D, typename S, typename Disassembler> D Disassemble(
const std::vector<uint8_t> &memory,
const std::function<std::size_t(S)> &address_mapper,
std::vector<S> entry_points) {
PartialDisassembly<D, S> partial_disassembly;
partial_disassembly.remaining_entry_points = entry_points;
while(!partial_disassembly.remaining_entry_points.empty()) {
// pull the next entry point from the back of the vector
S next_entry_point = partial_disassembly.remaining_entry_points.back();
partial_disassembly.remaining_entry_points.pop_back();
// if that address has already been visited, forget about it
if( partial_disassembly.disassembly.instructions_by_address.find(next_entry_point)
!= partial_disassembly.disassembly.instructions_by_address.end()) continue;
// if it's outgoing, log it as such and forget about it; otherwise disassemble
std::size_t mapped_entry_point = address_mapper(next_entry_point);
if(mapped_entry_point >= memory.size())
partial_disassembly.disassembly.outward_calls.insert(next_entry_point);
else
Disassembler::AddToDisassembly(partial_disassembly, memory, address_mapper, next_entry_point);
}
return partial_disassembly.disassembly;
}
}
}
}
#endif /* Kernel_hpp */

View File

@@ -0,0 +1,619 @@
//
// Z80.cpp
// Clock Signal
//
// Created by Thomas Harte on 30/12/2017.
// Copyright © 2017 Thomas Harte. All rights reserved.
//
#include "Z80.hpp"
#include "Kernel.hpp"
using namespace Analyser::Static::Z80;
namespace {
using PartialDisassembly = Analyser::Static::Disassembly::PartialDisassembly<Disassembly, uint16_t>;
class Accessor {
public:
Accessor(const std::vector<uint8_t> &memory, const std::function<std::size_t(uint16_t)> &address_mapper, uint16_t address) :
memory_(memory), address_mapper_(address_mapper), address_(address) {}
uint8_t byte() {
std::size_t mapped_address = address_mapper_(address_);
address_++;
if(mapped_address >= memory_.size()) {
overrun_ = true;
return 0xff;
}
return memory_[mapped_address];
}
uint16_t word() {
uint8_t low = byte();
uint8_t high = byte();
return static_cast<uint16_t>(low | (high << 8));
}
bool overrun() {
return overrun_;
}
bool at_end() {
std::size_t mapped_address = address_mapper_(address_);
return mapped_address >= memory_.size();
}
uint16_t address() {
return address_;
}
private:
const std::vector<uint8_t> &memory_;
const std::function<std::size_t(uint16_t)> &address_mapper_;
uint16_t address_;
bool overrun_ = false;
};
#define x(v) (v >> 6)
#define y(v) ((v >> 3) & 7)
#define q(v) ((v >> 3) & 1)
#define p(v) ((v >> 4) & 3)
#define z(v) (v & 7)
Instruction::Condition condition_table[] = {
Instruction::Condition::NZ, Instruction::Condition::Z,
Instruction::Condition::NC, Instruction::Condition::C,
Instruction::Condition::PO, Instruction::Condition::PE,
Instruction::Condition::P, Instruction::Condition::M
};
Instruction::Location register_pair_table[] = {
Instruction::Location::BC,
Instruction::Location::DE,
Instruction::Location::HL,
Instruction::Location::SP
};
Instruction::Location register_pair_table2[] = {
Instruction::Location::BC,
Instruction::Location::DE,
Instruction::Location::HL,
Instruction::Location::AF
};
Instruction::Location RegisterTableEntry(int offset, Accessor &accessor, Instruction &instruction, bool needs_indirect_offset) {
Instruction::Location register_table[] = {
Instruction::Location::B, Instruction::Location::C,
Instruction::Location::D, Instruction::Location::E,
Instruction::Location::H, Instruction::Location::L,
Instruction::Location::HL_Indirect,
Instruction::Location::A
};
Instruction::Location location = register_table[offset];
if(location == Instruction::Location::HL_Indirect && needs_indirect_offset) {
instruction.offset = accessor.byte() - 128;
}
return location;
}
Instruction::Operation alu_table[] = {
Instruction::Operation::ADD,
Instruction::Operation::ADC,
Instruction::Operation::SUB,
Instruction::Operation::SBC,
Instruction::Operation::AND,
Instruction::Operation::XOR,
Instruction::Operation::OR,
Instruction::Operation::CP
};
Instruction::Operation rotation_table[] = {
Instruction::Operation::RLC,
Instruction::Operation::RRC,
Instruction::Operation::RL,
Instruction::Operation::RR,
Instruction::Operation::SLA,
Instruction::Operation::SRA,
Instruction::Operation::SLL,
Instruction::Operation::SRL
};
Instruction::Operation block_table[][4] = {
{Instruction::Operation::LDI, Instruction::Operation::CPI, Instruction::Operation::INI, Instruction::Operation::OUTI},
{Instruction::Operation::LDD, Instruction::Operation::CPD, Instruction::Operation::IND, Instruction::Operation::OUTD},
{Instruction::Operation::LDIR, Instruction::Operation::CPIR, Instruction::Operation::INIR, Instruction::Operation::OTIR},
{Instruction::Operation::LDDR, Instruction::Operation::CPDR, Instruction::Operation::INDR, Instruction::Operation::OTDR},
};
void DisassembleCBPage(Accessor &accessor, Instruction &instruction, bool needs_indirect_offset) {
const uint8_t operation = accessor.byte();
if(!x(operation)) {
instruction.operation = rotation_table[y(operation)];
instruction.source = instruction.destination = RegisterTableEntry(z(operation), accessor, instruction, needs_indirect_offset);
} else {
instruction.destination = RegisterTableEntry(z(operation), accessor, instruction, needs_indirect_offset);
instruction.source = Instruction::Location::Operand;
instruction.operand = y(operation);
switch(x(operation)) {
case 1: instruction.operation = Instruction::Operation::BIT; break;
case 2: instruction.operation = Instruction::Operation::RES; break;
case 3: instruction.operation = Instruction::Operation::SET; break;
}
}
}
void DisassembleEDPage(Accessor &accessor, Instruction &instruction, bool needs_indirect_offset) {
const uint8_t operation = accessor.byte();
switch(x(operation)) {
default:
instruction.operation = Instruction::Operation::Invalid;
break;
case 2:
if(z(operation) < 4 && y(operation) >= 4) {
instruction.operation = block_table[y(operation)-4][z(operation)];
} else {
instruction.operation = Instruction::Operation::Invalid;
}
break;
case 3:
switch(z(operation)) {
case 0:
instruction.operation = Instruction::Operation::IN;
instruction.source = Instruction::Location::BC_Indirect;
if(y(operation) == 6) {
instruction.destination = Instruction::Location::None;
} else {
instruction.destination = RegisterTableEntry(y(operation), accessor, instruction, needs_indirect_offset);
}
break;
case 1:
instruction.operation = Instruction::Operation::OUT;
instruction.destination = Instruction::Location::BC_Indirect;
if(y(operation) == 6) {
instruction.source = Instruction::Location::None;
} else {
instruction.source = RegisterTableEntry(y(operation), accessor, instruction, needs_indirect_offset);
}
break;
case 2:
instruction.operation = (y(operation)&1) ? Instruction::Operation::ADC : Instruction::Operation::SBC;
instruction.destination = Instruction::Location::HL;
instruction.source = register_pair_table[y(operation) >> 1];
break;
case 3:
instruction.operation = Instruction::Operation::LD;
if(q(operation)) {
instruction.destination = RegisterTableEntry(p(operation), accessor, instruction, needs_indirect_offset);
instruction.source = Instruction::Location::Operand_Indirect;
} else {
instruction.destination = Instruction::Location::Operand_Indirect;
instruction.source = RegisterTableEntry(p(operation), accessor, instruction, needs_indirect_offset);
}
instruction.operand = accessor.word();
break;
case 4:
instruction.operation = Instruction::Operation::NEG;
break;
case 5:
instruction.operation = (y(operation) == 1) ? Instruction::Operation::RETI : Instruction::Operation::RETN;
break;
case 6:
instruction.operation = Instruction::Operation::IM;
instruction.source = Instruction::Location::Operand;
switch(y(operation)&3) {
case 0: instruction.operand = 0; break;
case 1: instruction.operand = 0; break;
case 2: instruction.operand = 1; break;
case 3: instruction.operand = 2; break;
}
break;
case 7:
switch(y(operation)) {
case 0:
instruction.operation = Instruction::Operation::LD;
instruction.destination = Instruction::Location::I;
instruction.source = Instruction::Location::A;
break;
case 1:
instruction.operation = Instruction::Operation::LD;
instruction.destination = Instruction::Location::R;
instruction.source = Instruction::Location::A;
break;
case 2:
instruction.operation = Instruction::Operation::LD;
instruction.destination = Instruction::Location::A;
instruction.source = Instruction::Location::I;
break;
case 3:
instruction.operation = Instruction::Operation::LD;
instruction.destination = Instruction::Location::A;
instruction.source = Instruction::Location::R;
break;
case 4: instruction.operation = Instruction::Operation::RRD; break;
case 5: instruction.operation = Instruction::Operation::RLD; break;
default: instruction.operation = Instruction::Operation::NOP; break;
}
break;
}
break;
}
}
void DisassembleMainPage(Accessor &accessor, Instruction &instruction) {
bool needs_indirect_offset = false;
enum HLSubstitution {
None, IX, IY
} hl_substitution = None;
while(true) {
uint8_t operation = accessor.byte();
switch(x(operation)) {
case 0:
switch(z(operation)) {
case 0:
switch(y(operation)) {
case 0: instruction.operation = Instruction::Operation::NOP; break;
case 1: instruction.operation = Instruction::Operation::EXAFAFd; break;
case 2:
instruction.operation = Instruction::Operation::DJNZ;
instruction.operand = accessor.byte() - 128;
break;
default:
instruction.operation = Instruction::Operation::JR;
instruction.operand = accessor.byte() - 128;
if(y(operation) >= 4) instruction.condition = condition_table[y(operation) - 4];
break;
}
break;
case 1:
if(y(operation)&1) {
instruction.operation = Instruction::Operation::ADD;
instruction.destination = Instruction::Location::HL;
instruction.source = register_pair_table[y(operation) >> 1];
} else {
instruction.operation = Instruction::Operation::LD;
instruction.destination = register_pair_table[y(operation) >> 1];
instruction.source = Instruction::Location::Operand;
instruction.operand = accessor.word();
}
break;
case 2:
switch(y(operation)) {
case 0:
instruction.operation = Instruction::Operation::LD;
instruction.destination = Instruction::Location::BC_Indirect;
instruction.source = Instruction::Location::A;
break;
case 1:
instruction.operation = Instruction::Operation::LD;
instruction.destination = Instruction::Location::A;
instruction.source = Instruction::Location::BC_Indirect;
break;
case 2:
instruction.operation = Instruction::Operation::LD;
instruction.destination = Instruction::Location::DE_Indirect;
instruction.source = Instruction::Location::A;
break;
case 3:
instruction.operation = Instruction::Operation::LD;
instruction.destination = Instruction::Location::A;
instruction.source = Instruction::Location::DE_Indirect;
break;
case 4:
instruction.operation = Instruction::Operation::LD;
instruction.destination = Instruction::Location::Operand_Indirect;
instruction.source = Instruction::Location::HL;
break;
case 5:
instruction.operation = Instruction::Operation::LD;
instruction.destination = Instruction::Location::HL;
instruction.source = Instruction::Location::Operand_Indirect;
break;
case 6:
instruction.operation = Instruction::Operation::LD;
instruction.destination = Instruction::Location::Operand_Indirect;
instruction.source = Instruction::Location::A;
break;
case 7:
instruction.operation = Instruction::Operation::LD;
instruction.destination = Instruction::Location::A;
instruction.source = Instruction::Location::Operand_Indirect;
break;
}
if(y(operation) > 3) {
instruction.operand = accessor.word();
}
break;
case 3:
if(y(operation)&1) {
instruction.operation = Instruction::Operation::DEC;
} else {
instruction.operation = Instruction::Operation::INC;
}
instruction.source = instruction.destination = register_pair_table[y(operation) >> 1];
break;
case 4:
instruction.operation = Instruction::Operation::INC;
instruction.source = instruction.destination = RegisterTableEntry(y(operation), accessor, instruction, needs_indirect_offset);
break;
case 5:
instruction.operation = Instruction::Operation::DEC;
instruction.source = instruction.destination = RegisterTableEntry(y(operation), accessor, instruction, needs_indirect_offset);
break;
case 6:
instruction.operation = Instruction::Operation::LD;
instruction.destination = RegisterTableEntry(y(operation), accessor, instruction, needs_indirect_offset);
instruction.source = Instruction::Location::Operand;
instruction.operand = accessor.byte();
break;
case 7:
switch(y(operation)) {
case 0: instruction.operation = Instruction::Operation::RLCA; break;
case 1: instruction.operation = Instruction::Operation::RRCA; break;
case 2: instruction.operation = Instruction::Operation::RLA; break;
case 3: instruction.operation = Instruction::Operation::RRA; break;
case 4: instruction.operation = Instruction::Operation::DAA; break;
case 5: instruction.operation = Instruction::Operation::CPL; break;
case 6: instruction.operation = Instruction::Operation::SCF; break;
case 7: instruction.operation = Instruction::Operation::CCF; break;
}
break;
}
break;
case 1:
if(y(operation) == 6 && z(operation) == 6) {
instruction.operation = Instruction::Operation::HALT;
} else {
instruction.operation = Instruction::Operation::LD;
instruction.source = RegisterTableEntry(z(operation), accessor, instruction, needs_indirect_offset);
instruction.destination = RegisterTableEntry(y(operation), accessor, instruction, needs_indirect_offset);
}
break;
case 2:
instruction.operation = alu_table[y(operation)];
instruction.source = RegisterTableEntry(z(operation), accessor, instruction, needs_indirect_offset);
instruction.destination = Instruction::Location::A;
break;
case 3:
switch(z(operation)) {
case 0:
instruction.operation = Instruction::Operation::RET;
instruction.condition = condition_table[y(operation)];
break;
case 1:
switch(y(operation)) {
default:
instruction.operation = Instruction::Operation::POP;
instruction.source = register_pair_table2[y(operation) >> 1];
break;
case 1:
instruction.operation = Instruction::Operation::RET;
break;
case 3:
instruction.operation = Instruction::Operation::EXX;
break;
case 5:
instruction.operation = Instruction::Operation::JP;
instruction.source = Instruction::Location::HL;
break;
case 7:
instruction.operation = Instruction::Operation::LD;
instruction.destination = Instruction::Location::SP;
instruction.source = Instruction::Location::HL;
break;
}
break;
case 2:
instruction.operation = Instruction::Operation::JP;
instruction.condition = condition_table[y(operation)];
instruction.operand = accessor.word();
break;
case 3:
switch(y(operation)) {
case 0:
instruction.operation = Instruction::Operation::JP;
instruction.source = Instruction::Location::Operand;
instruction.operand = accessor.word();
break;
case 1:
DisassembleCBPage(accessor, instruction, needs_indirect_offset);
break;
case 2:
instruction.operation = Instruction::Operation::OUT;
instruction.source = Instruction::Location::A;
instruction.destination = Instruction::Location::Operand_Indirect;
instruction.operand = accessor.byte();
break;
case 3:
instruction.operation = Instruction::Operation::IN;
instruction.destination = Instruction::Location::A;
instruction.source = Instruction::Location::Operand_Indirect;
instruction.operand = accessor.byte();
break;
case 4:
instruction.operation = Instruction::Operation::EX;
instruction.destination = Instruction::Location::SP_Indirect;
instruction.source = Instruction::Location::HL;
break;
case 5:
instruction.operation = Instruction::Operation::EX;
instruction.destination = Instruction::Location::DE;
instruction.source = Instruction::Location::HL;
break;
case 6:
instruction.operation = Instruction::Operation::DI;
break;
case 7:
instruction.operation = Instruction::Operation::EI;
break;
}
break;
case 4:
instruction.operation = Instruction::Operation::CALL;
instruction.source = Instruction::Location::Operand_Indirect;
instruction.operand = accessor.word();
instruction.condition = condition_table[y(operation)];
break;
case 5:
switch(y(operation)) {
default:
instruction.operation = Instruction::Operation::PUSH;
instruction.source = register_pair_table2[y(operation) >> 1];
break;
case 1:
instruction.operation = Instruction::Operation::CALL;
instruction.source = Instruction::Location::Operand;
instruction.operand = accessor.word();
break;
case 3:
needs_indirect_offset = true;
hl_substitution = IX;
continue; // i.e. repeat loop.
case 5:
DisassembleEDPage(accessor, instruction, needs_indirect_offset);
break;
case 7:
needs_indirect_offset = true;
hl_substitution = IY;
continue; // i.e. repeat loop.
}
break;
case 6:
instruction.operation = alu_table[y(operation)];
instruction.source = Instruction::Location::Operand;
instruction.destination = Instruction::Location::A;
instruction.operand = accessor.byte();
break;
case 7:
instruction.operation = Instruction::Operation::RST;
instruction.source = Instruction::Location::Operand;
instruction.operand = y(operation) << 3;
break;
}
break;
}
// This while(true) isn't an infinite loop for everything except those paths that opt in
// via continue.
break;
}
// Perform IX/IY substitution for HL, if applicable.
if(hl_substitution != None) {
// EX DE, HL is not affected.
if(instruction.operation == Instruction::Operation::EX) return;
// If an (HL) is involved, switch it for IX+d or IY+d.
if( instruction.source == Instruction::Location::HL_Indirect ||
instruction.destination == Instruction::Location::HL_Indirect) {
if(instruction.source == Instruction::Location::HL_Indirect) {
instruction.source = (hl_substitution == IX) ? Instruction::Location::IX_Indirect_Offset : Instruction::Location::IY_Indirect_Offset;
}
if(instruction.destination == Instruction::Location::HL_Indirect) {
instruction.destination = (hl_substitution == IX) ? Instruction::Location::IX_Indirect_Offset : Instruction::Location::IY_Indirect_Offset;
}
return;
}
// Otherwise, switch either of H or L for I[X/Y]h and I[X/Y]l.
if(instruction.source == Instruction::Location::H) {
instruction.source = (hl_substitution == IX) ? Instruction::Location::IXh : Instruction::Location::IYh;
}
if(instruction.source == Instruction::Location::L) {
instruction.source = (hl_substitution == IX) ? Instruction::Location::IXl : Instruction::Location::IYl;
}
if(instruction.destination == Instruction::Location::H) {
instruction.destination = (hl_substitution == IX) ? Instruction::Location::IXh : Instruction::Location::IYh;
}
if(instruction.destination == Instruction::Location::L) {
instruction.destination = (hl_substitution == IX) ? Instruction::Location::IXl : Instruction::Location::IYl;
}
}
}
struct Z80Disassembler {
static void AddToDisassembly(PartialDisassembly &disassembly, const std::vector<uint8_t> &memory, const std::function<std::size_t(uint16_t)> &address_mapper, uint16_t entry_point) {
disassembly.disassembly.internal_calls.insert(entry_point);
Accessor accessor(memory, address_mapper, entry_point);
while(!accessor.at_end()) {
Instruction instruction;
instruction.address = accessor.address();
DisassembleMainPage(accessor, instruction);
// If any memory access was invalid, end disassembly.
if(accessor.overrun()) return;
// Store the instruction away.
disassembly.disassembly.instructions_by_address[instruction.address] = instruction;
// Update access tables.
int access_type =
((instruction.source == Instruction::Location::Operand_Indirect) ? 1 : 0) |
((instruction.destination == Instruction::Location::Operand_Indirect) ? 2 : 0);
uint16_t address = static_cast<uint16_t>(instruction.operand);
bool is_internal = address_mapper(address) < memory.size();
switch(access_type) {
default: break;
case 1:
if(is_internal) {
disassembly.disassembly.internal_loads.insert(address);
} else {
disassembly.disassembly.external_loads.insert(address);
}
break;
case 2:
if(is_internal) {
disassembly.disassembly.internal_stores.insert(address);
} else {
disassembly.disassembly.external_stores.insert(address);
}
break;
case 3:
if(is_internal) {
disassembly.disassembly.internal_modifies.insert(address);
} else {
disassembly.disassembly.internal_modifies.insert(address);
}
break;
}
// Add any (potentially) newly discovered entry point.
if( instruction.operation == Instruction::Operation::JP ||
instruction.operation == Instruction::Operation::JR ||
instruction.operation == Instruction::Operation::CALL ||
instruction.operation == Instruction::Operation::RST) {
disassembly.remaining_entry_points.push_back(static_cast<uint16_t>(instruction.operand));
}
// This is it if: an unconditional RET, RETI, RETN, JP or JR is found.
if(instruction.condition != Instruction::Condition::None) continue;
if(instruction.operation == Instruction::Operation::RET) return;
if(instruction.operation == Instruction::Operation::RETI) return;
if(instruction.operation == Instruction::Operation::RETN) return;
if(instruction.operation == Instruction::Operation::JP) return;
if(instruction.operation == Instruction::Operation::JR) return;
}
}
};
} // end of anonymous namespace
Disassembly Analyser::Static::Z80::Disassemble(
const std::vector<uint8_t> &memory,
const std::function<std::size_t(uint16_t)> &address_mapper,
std::vector<uint16_t> entry_points) {
return Analyser::Static::Disassembly::Disassemble<Disassembly, uint16_t, Z80Disassembler>(memory, address_mapper, entry_points);
}

View File

@@ -0,0 +1,90 @@
//
// Z80.hpp
// Clock Signal
//
// Created by Thomas Harte on 30/12/2017.
// Copyright © 2017 Thomas Harte. All rights reserved.
//
#ifndef StaticAnalyser_Disassembler_Z80_hpp
#define StaticAnalyser_Disassembler_Z80_hpp
#include <cstdint>
#include <functional>
#include <map>
#include <set>
#include <vector>
namespace Analyser {
namespace Static {
namespace Z80 {
struct Instruction {
/*! The address this instruction starts at. This is a mapped address. */
uint16_t address = 0;
/*! The operation this instruction performs. */
enum class Operation {
NOP,
EXAFAFd, EXX, EX,
LD, HALT,
ADD, ADC, SUB, SBC, AND, XOR, OR, CP,
INC, DEC,
RLCA, RRCA, RLA, RRA, DAA, CPL, SCF, CCF,
RLD, RRD,
DJNZ, JR, JP, CALL, RST, RET, RETI, RETN,
PUSH, POP,
IN, OUT,
EI, DI,
RLC, RRC, RL, RR, SLA, SRA, SLL, SRL,
BIT, RES, SET,
LDI, CPI, INI, OUTI,
LDD, CPD, IND, OUTD,
LDIR, CPIR, INIR, OTIR,
LDDR, CPDR, INDR, OTDR,
NEG,
IM,
Invalid
} operation = Operation::NOP;
/*! The condition required for this instruction to take effect. */
enum class Condition {
None, NZ, Z, NC, C, PO, PE, P, M
} condition = Condition::None;
enum class Location {
B, C, D, E, H, L, HL_Indirect, A, I, R,
BC, DE, HL, SP, AF, Operand,
IX_Indirect_Offset, IY_Indirect_Offset, IXh, IXl, IYh, IYl,
Operand_Indirect,
BC_Indirect, DE_Indirect, SP_Indirect,
None
};
/*! The locations of source data for this instruction. */
Location source = Location::None;
/*! The locations of destination data from this instruction. */
Location destination = Location::None;
/*! The operand, if any; if this is used then it'll be referenced by either the source or destination location. */
int operand = 0;
/*! The offset to apply, if any; applies to IX_Indirect_Offset and IY_Indirect_Offset locations. */
int offset = 0;
};
struct Disassembly {
std::map<uint16_t, Instruction> instructions_by_address;
std::set<uint16_t> outward_calls;
std::set<uint16_t> internal_calls;
std::set<uint16_t> external_stores, external_loads, external_modifies;
std::set<uint16_t> internal_stores, internal_loads, internal_modifies;
};
Disassembly Disassemble(
const std::vector<uint8_t> &memory,
const std::function<std::size_t(uint16_t)> &address_mapper,
std::vector<uint16_t> entry_points);
}
}
}
#endif /* StaticAnalyser_Disassembler_Z80_hpp */

View File

@@ -0,0 +1,40 @@
//
// Cartridge.hpp
// Clock Signal
//
// Created by Thomas Harte on 25/01/2018.
// Copyright © 2018 Thomas Harte. All rights reserved.
//
#ifndef Cartridge_hpp
#define Cartridge_hpp
#include "../../../Storage/Cartridge/Cartridge.hpp"
namespace Analyser {
namespace Static {
namespace MSX {
/*!
Extends the base cartridge class by adding a (guess at) the banking scheme.
*/
struct Cartridge: public ::Storage::Cartridge::Cartridge {
enum Type {
None,
Konami,
KonamiWithSCC,
ASCII8kb,
ASCII16kb,
FMPac
};
const Type type;
Cartridge(const std::vector<Segment> &segments, Type type) :
Storage::Cartridge::Cartridge(segments), type(type) {}
};
}
}
}
#endif /* Cartridge_hpp */

View File

@@ -0,0 +1,295 @@
//
// StaticAnalyser.cpp
// Clock Signal
//
// Created by Thomas Harte on 25/11/2017.
// Copyright © 2017 Thomas Harte. All rights reserved.
//
#include "StaticAnalyser.hpp"
#include "Cartridge.hpp"
#include "Tape.hpp"
#include "Target.hpp"
#include "../Disassembler/Z80.hpp"
#include "../Disassembler/AddressMapper.hpp"
#include <algorithm>
static std::unique_ptr<Analyser::Static::Target> CartridgeTarget(
const Storage::Cartridge::Cartridge::Segment &segment,
uint16_t start_address,
Analyser::Static::MSX::Cartridge::Type type,
float confidence) {
// Size down to a multiple of 8kb in size and apply the start address.
std::vector<Storage::Cartridge::Cartridge::Segment> output_segments;
if(segment.data.size() & 0x1fff) {
std::vector<uint8_t> truncated_data;
std::vector<uint8_t>::difference_type truncated_size = static_cast<std::vector<uint8_t>::difference_type>(segment.data.size()) & ~0x1fff;
truncated_data.insert(truncated_data.begin(), segment.data.begin(), segment.data.begin() + truncated_size);
output_segments.emplace_back(start_address, truncated_data);
} else {
output_segments.emplace_back(start_address, segment.data);
}
std::unique_ptr<Analyser::Static::MSX::Target> target(new Analyser::Static::MSX::Target);
target->machine = Analyser::Machine::MSX;
target->confidence = confidence;
if(type == Analyser::Static::MSX::Cartridge::Type::None) {
target->media.cartridges.emplace_back(new Storage::Cartridge::Cartridge(output_segments));
} else {
target->media.cartridges.emplace_back(new Analyser::Static::MSX::Cartridge(output_segments, type));
}
return target;
}
/*
Expected standard cartridge format:
DEFB "AB" ; expansion ROM header
DEFW initcode ; start of the init code, 0 if no initcode
DEFW callstat; pointer to CALL statement handler, 0 if no such handler
DEFW device; pointer to expansion device handler, 0 if no such handler
DEFW basic ; pointer to the start of a tokenized basicprogram, 0 if no basicprogram
DEFS 6,0 ; room reserved for future extensions
MSX cartridges often include banking hardware; those games were marketed as MegaROMs. The file
format that the MSX community has decided upon doesn't retain the type of hardware included, so
this analyser has to guess.
(additional audio hardware is also sometimes included, but it's implied by the banking hardware)
*/
static std::vector<std::unique_ptr<Analyser::Static::Target>> CartridgeTargetsFrom(
const std::vector<std::shared_ptr<Storage::Cartridge::Cartridge>> &cartridges) {
// No cartridges implies no targets.
if(cartridges.empty()) {
return {};
}
std::vector<std::unique_ptr<Analyser::Static::Target>> targets;
for(const auto &cartridge : cartridges) {
const auto &segments = cartridge->get_segments();
// Only one mapped item is allowed.
if(segments.size() != 1) continue;
// Which must be no more than 63 bytes larger than a multiple of 8 kb in size.
Storage::Cartridge::Cartridge::Segment segment = segments.front();
const size_t data_size = segment.data.size();
if(data_size < 0x2000 || (data_size & 0x1fff) > 64) continue;
// Check for a ROM header at address 0; if it's not found then try 0x4000
// and adjust the start address;
uint16_t start_address = 0;
bool found_start = false;
if(segment.data[0] == 0x41 && segment.data[1] == 0x42) {
start_address = 0x4000;
found_start = true;
} else if(segment.data.size() >= 0x8000 && segment.data[0x4000] == 0x41 && segment.data[0x4001] == 0x42) {
start_address = 0;
found_start = true;
}
// Reject cartridge if the ROM header wasn't found.
if(!found_start) continue;
uint16_t init_address = static_cast<uint16_t>(segment.data[2] | (segment.data[3] << 8));
// TODO: check for a rational init address?
// If this ROM is less than 48kb in size then it's an ordinary ROM. Just emplace it and move on.
if(data_size <= 0xc000) {
targets.emplace_back(CartridgeTarget(segment, start_address, Analyser::Static::MSX::Cartridge::Type::None, 1.0));
continue;
}
// If this ROM is greater than 48kb in size then some sort of MegaROM scheme must
// be at play; disassemble to try to figure it out.
std::vector<uint8_t> first_8k;
first_8k.insert(first_8k.begin(), segment.data.begin(), segment.data.begin() + 8192);
Analyser::Static::Z80::Disassembly disassembly =
Analyser::Static::Z80::Disassemble(
first_8k,
Analyser::Static::Disassembler::OffsetMapper(start_address),
{ init_address }
);
// // Look for a indirect store followed by an unconditional JP or CALL into another
// // segment, that's a fairly explicit sign where found.
using Instruction = Analyser::Static::Z80::Instruction;
std::map<uint16_t, Instruction> &instructions = disassembly.instructions_by_address;
bool is_ascii = false;
// auto iterator = instructions.begin();
// while(iterator != instructions.end()) {
// auto next_iterator = iterator;
// next_iterator++;
// if(next_iterator == instructions.end()) break;
//
// if( iterator->second.operation == Instruction::Operation::LD &&
// iterator->second.destination == Instruction::Location::Operand_Indirect &&
// (
// iterator->second.operand == 0x5000 ||
// iterator->second.operand == 0x6000 ||
// iterator->second.operand == 0x6800 ||
// iterator->second.operand == 0x7000 ||
// iterator->second.operand == 0x77ff ||
// iterator->second.operand == 0x7800 ||
// iterator->second.operand == 0x8000 ||
// iterator->second.operand == 0x9000 ||
// iterator->second.operand == 0xa000
// ) &&
// (
// next_iterator->second.operation == Instruction::Operation::CALL ||
// next_iterator->second.operation == Instruction::Operation::JP
// ) &&
// ((next_iterator->second.operand >> 13) != (0x4000 >> 13))
// ) {
// const uint16_t address = static_cast<uint16_t>(next_iterator->second.operand);
// switch(iterator->second.operand) {
// case 0x6000:
// if(address >= 0x6000 && address < 0x8000) {
// target.msx.cartridge_type = Analyser::Static::MSXCartridgeType::KonamiWithSCC;
// }
// break;
// case 0x6800:
// if(address >= 0x6000 && address < 0x6800) {
// target.msx.cartridge_type = Analyser::Static::MSXCartridgeType::ASCII8kb;
// }
// break;
// case 0x7000:
// if(address >= 0x6000 && address < 0x8000) {
// target.msx.cartridge_type = Analyser::Static::MSXCartridgeType::KonamiWithSCC;
// }
// if(address >= 0x7000 && address < 0x7800) {
// is_ascii = true;
// }
// break;
// case 0x77ff:
// if(address >= 0x7000 && address < 0x7800) {
// target.msx.cartridge_type = Analyser::Static::MSXCartridgeType::ASCII16kb;
// }
// break;
// case 0x7800:
// if(address >= 0xa000 && address < 0xc000) {
// target.msx.cartridge_type = Analyser::Static::MSXCartridgeType::ASCII8kb;
// }
// break;
// case 0x8000:
// if(address >= 0x8000 && address < 0xa000) {
// target.msx.cartridge_type = Analyser::Static::MSXCartridgeType::KonamiWithSCC;
// }
// break;
// case 0x9000:
// if(address >= 0x8000 && address < 0xa000) {
// target.msx.cartridge_type = Analyser::Static::MSXCartridgeType::KonamiWithSCC;
// }
// break;
// case 0xa000:
// if(address >= 0xa000 && address < 0xc000) {
// target.msx.cartridge_type = Analyser::Static::MSXCartridgeType::Konami;
// }
// break;
// case 0xb000:
// if(address >= 0xa000 && address < 0xc000) {
// target.msx.cartridge_type = Analyser::Static::MSXCartridgeType::KonamiWithSCC;
// }
// break;
// }
// }
//
// iterator = next_iterator;
// Look for LD (nnnn), A instructions, and collate those addresses.
std::map<uint16_t, int> address_counts;
for(const auto &instruction_pair : instructions) {
if( instruction_pair.second.operation == Instruction::Operation::LD &&
instruction_pair.second.destination == Instruction::Location::Operand_Indirect &&
instruction_pair.second.source == Instruction::Location::A) {
address_counts[static_cast<uint16_t>(instruction_pair.second.operand)]++;
}
}
// Weight confidences by number of observed hits.
float total_hits =
static_cast<float>(
address_counts[0x6000] + address_counts[0x6800] +
address_counts[0x7000] + address_counts[0x7800] +
address_counts[0x77ff] + address_counts[0x8000] +
address_counts[0xa000] + address_counts[0x5000] +
address_counts[0x9000] + address_counts[0xb000]
);
targets.push_back(CartridgeTarget(
segment,
start_address,
Analyser::Static::MSX::Cartridge::ASCII8kb,
static_cast<float>( address_counts[0x6000] +
address_counts[0x6800] +
address_counts[0x7000] +
address_counts[0x7800]) / total_hits));
targets.push_back(CartridgeTarget(
segment,
start_address,
Analyser::Static::MSX::Cartridge::ASCII16kb,
static_cast<float>( address_counts[0x6000] +
address_counts[0x7000] +
address_counts[0x77ff]) / total_hits));
if(!is_ascii) {
targets.push_back(CartridgeTarget(
segment,
start_address,
Analyser::Static::MSX::Cartridge::Konami,
static_cast<float>( address_counts[0x6000] +
address_counts[0x8000] +
address_counts[0xa000]) / total_hits));
}
if(!is_ascii) {
targets.push_back(CartridgeTarget(
segment,
start_address,
Analyser::Static::MSX::Cartridge::KonamiWithSCC,
static_cast<float>( address_counts[0x5000] +
address_counts[0x7000] +
address_counts[0x9000] +
address_counts[0xb000]) / total_hits));
}
}
return targets;
}
void Analyser::Static::MSX::AddTargets(const Media &media, std::vector<std::unique_ptr<::Analyser::Static::Target>> &destination) {
// Append targets for any cartridges that look correct.
auto cartridge_targets = CartridgeTargetsFrom(media.cartridges);
std::move(cartridge_targets.begin(), cartridge_targets.end(), std::back_inserter(destination));
// Consider building a target for disks and/or tapes.
std::unique_ptr<Target> target(new Target);
// Check tapes for loadable files.
for(const auto &tape : media.tapes) {
std::vector<File> files_on_tape = GetFiles(tape);
if(!files_on_tape.empty()) {
switch(files_on_tape.front().type) {
case File::Type::ASCII: target->loading_command = "RUN\"CAS:\r"; break;
case File::Type::TokenisedBASIC: target->loading_command = "CLOAD\rRUN\r"; break;
case File::Type::Binary: target->loading_command = "BLOAD\"CAS:\",R\r"; break;
default: break;
}
target->media.tapes.push_back(tape);
}
}
// Blindly accept disks for now.
target->media.disks = media.disks;
target->has_disk_drive = !media.disks.empty();
if(!target->media.empty()) {
target->machine = Machine::MSX;
target->confidence = 0.5;
destination.push_back(std::move(target));
}
}

View File

@@ -0,0 +1,24 @@
//
// StaticAnalyser.hpp
// Clock Signal
//
// Created by Thomas Harte on 25/11/2017.
// Copyright © 2017 Thomas Harte. All rights reserved.
//
#ifndef StaticAnalyser_MSX_StaticAnalyser_hpp
#define StaticAnalyser_MSX_StaticAnalyser_hpp
#include "../StaticAnalyser.hpp"
namespace Analyser {
namespace Static {
namespace MSX {
void AddTargets(const Media &media, std::vector<std::unique_ptr<Target>> &destination);
}
}
}
#endif /* StaticAnalyser_MSX_StaticAnalyser_hpp */

View File

@@ -0,0 +1,165 @@
//
// Tape.cpp
// Clock Signal
//
// Created by Thomas Harte on 25/12/2017.
// Copyright © 2017 Thomas Harte. All rights reserved.
//
#include "Tape.hpp"
#include "../../../Storage/Tape/Parsers/MSX.hpp"
using namespace Analyser::Static::MSX;
File::File(File &&rhs) :
name(std::move(rhs.name)),
type(rhs.type),
data(std::move(rhs.data)),
starting_address(rhs.starting_address),
entry_address(rhs.entry_address) {}
File::File() :
type(Type::Binary),
starting_address(0),
entry_address(0) {} // For the sake of initialising in a defined state.
std::vector<File> Analyser::Static::MSX::GetFiles(const std::shared_ptr<Storage::Tape::Tape> &tape) {
std::vector<File> files;
Storage::Tape::BinaryTapePlayer tape_player(1000000);
tape_player.set_motor_control(true);
tape_player.set_tape(tape);
using Parser = Storage::Tape::MSX::Parser;
// Get all recognisable files from the tape.
while(!tape->is_at_end()) {
// Try to locate and measure a header.
std::unique_ptr<Parser::FileSpeed> file_speed = Parser::find_header(tape_player);
if(!file_speed) continue;
// Check whether what follows is a recognisable file type.
uint8_t header[10] = {0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff};
for(std::size_t c = 0; c < sizeof(header); ++c) {
int next_byte = Parser::get_byte(*file_speed, tape_player);
if(next_byte == -1) break;
header[c] = static_cast<uint8_t>(next_byte);
}
bool bytes_are_same = true;
for(std::size_t c = 1; c < sizeof(header); ++c)
bytes_are_same &= (header[c] == header[0]);
if(!bytes_are_same) continue;
if(header[0] != 0xd0 && header[0] != 0xd3 && header[0] != 0xea) continue;
File file;
// Determine file type from information already collected.
switch(header[0]) {
case 0xd0: file.type = File::Type::Binary; break;
case 0xd3: file.type = File::Type::TokenisedBASIC; break;
case 0xea: file.type = File::Type::ASCII; break;
default: break; // Unreachable.
}
// Read file name.
char name[7];
for(std::size_t c = 1; c < 6; ++c)
name[c] = static_cast<char>(Parser::get_byte(*file_speed, tape_player));
name[6] = '\0';
file.name = name;
// ASCII: Read 256-byte segments until one ends with an end-of-file character.
if(file.type == File::Type::ASCII) {
while(true) {
file_speed = Parser::find_header(tape_player);
if(!file_speed) break;
int c = 256;
bool contains_end_of_file = false;
while(c--) {
int byte = Parser::get_byte(*file_speed, tape_player);
if(byte == -1) break;
contains_end_of_file |= (byte == 0x1a);
file.data.push_back(static_cast<uint8_t>(byte));
}
if(c != -1) break;
if(contains_end_of_file) {
files.push_back(std::move(file));
break;
}
}
continue;
}
// Read a single additional segment, using the information at the begging to determine length.
file_speed = Parser::find_header(tape_player);
if(!file_speed) continue;
// Binary: read start address, end address, entry address, then that many bytes.
if(file.type == File::Type::Binary) {
uint8_t locations[6];
uint16_t end_address;
std::size_t c;
for(c = 0; c < sizeof(locations); ++c) {
int byte = Parser::get_byte(*file_speed, tape_player);
if(byte == -1) break;
locations[c] = static_cast<uint8_t>(byte);
}
if(c != sizeof(locations)) continue;
file.starting_address = static_cast<uint16_t>(locations[0] | (locations[1] << 8));
end_address = static_cast<uint16_t>(locations[2] | (locations[3] << 8));
file.entry_address = static_cast<uint16_t>(locations[4] | (locations[5] << 8));
if(end_address < file.starting_address) continue;
std::size_t length = end_address - file.starting_address;
while(length--) {
int byte = Parser::get_byte(*file_speed, tape_player);
if(byte == -1) continue;
file.data.push_back(static_cast<uint8_t>(byte));
}
files.push_back(std::move(file));
continue;
}
// Tokenised BASIC, then: keep following 'next line' links from a hypothetical start of
// 0x8001, until finding the final line.
uint16_t current_address = 0x8001;
while(current_address) {
int next_address_buffer[2];
next_address_buffer[0] = Parser::get_byte(*file_speed, tape_player);
next_address_buffer[1] = Parser::get_byte(*file_speed, tape_player);
if(next_address_buffer[0] == -1 || next_address_buffer[1] == -1) break;
file.data.push_back(static_cast<uint8_t>(next_address_buffer[0]));
file.data.push_back(static_cast<uint8_t>(next_address_buffer[1]));
uint16_t next_address = static_cast<uint16_t>(next_address_buffer[0] | (next_address_buffer[1] << 8));
if(!next_address) {
files.push_back(std::move(file));
break;
}
if(next_address < current_address+2) break;
// This line makes sense, so push it all in.
std::size_t length = next_address - current_address - 2;
current_address = next_address;
bool found_error = false;
while(length--) {
int byte = Parser::get_byte(*file_speed, tape_player);
if(byte == -1) {
found_error = true;
break;
}
file.data.push_back(static_cast<uint8_t>(byte));
}
if(found_error) break;
}
}
return files;
}

View File

@@ -0,0 +1,44 @@
//
// Tape.hpp
// Clock Signal
//
// Created by Thomas Harte on 25/12/2017.
// Copyright © 2017 Thomas Harte. All rights reserved.
//
#ifndef StaticAnalyser_MSX_Tape_hpp
#define StaticAnalyser_MSX_Tape_hpp
#include "../../../Storage/Tape/Tape.hpp"
#include <string>
#include <vector>
namespace Analyser {
namespace Static {
namespace MSX {
struct File {
std::string name;
enum Type {
Binary,
TokenisedBASIC,
ASCII
} type;
std::vector<uint8_t> data;
uint16_t starting_address; // Provided only for Type::Binary files.
uint16_t entry_address; // Provided only for Type::Binary files.
File(File &&rhs);
File();
};
std::vector<File> GetFiles(const std::shared_ptr<Storage::Tape::Tape> &tape);
}
}
}
#endif /* StaticAnalyser_MSX_Tape_hpp */

View File

@@ -0,0 +1,26 @@
//
// Target.hpp
// Clock Signal
//
// Created by Thomas Harte on 02/04/2018.
// Copyright © 2018 Thomas Harte. All rights reserved.
//
#ifndef Analyser_Static_MSX_Target_h
#define Analyser_Static_MSX_Target_h
#include "../StaticAnalyser.hpp"
namespace Analyser {
namespace Static {
namespace MSX {
struct Target: public ::Analyser::Static::Target {
bool has_disk_drive = false;
};
}
}
}
#endif /* Analyser_Static_MSX_Target_h */

View File

@@ -9,11 +9,18 @@
#include "StaticAnalyser.hpp"
#include "Tape.hpp"
#include "../Disassembler/Disassembler6502.hpp"
#include "Target.hpp"
using namespace StaticAnalyser::Oric;
#include "../Disassembler/6502.hpp"
#include "../Disassembler/AddressMapper.hpp"
static int Score(const StaticAnalyser::MOS6502::Disassembly &disassembly, const std::set<uint16_t> &rom_functions, const std::set<uint16_t> &variable_locations) {
#include "../../../Storage/Disk/Encodings/MFM/Parser.hpp"
#include <cstring>
using namespace Analyser::Static::Oric;
static int Score(const Analyser::Static::MOS6502::Disassembly &disassembly, const std::set<uint16_t> &rom_functions, const std::set<uint16_t> &variable_locations) {
int score = 0;
for(auto address : disassembly.outward_calls) score += (rom_functions.find(address) != rom_functions.end()) ? 1 : -1;
@@ -23,7 +30,7 @@ static int Score(const StaticAnalyser::MOS6502::Disassembly &disassembly, const
return score;
}
static int Basic10Score(const StaticAnalyser::MOS6502::Disassembly &disassembly) {
static int Basic10Score(const Analyser::Static::MOS6502::Disassembly &disassembly) {
std::set<uint16_t> rom_functions = {
0x0228, 0x022b,
0xc3ca, 0xc3f8, 0xc448, 0xc47c, 0xc4b5, 0xc4e3, 0xc4e0, 0xc524, 0xc56f, 0xc5a2, 0xc5f8, 0xc60a, 0xc6a5, 0xc6de, 0xc719, 0xc738,
@@ -47,7 +54,7 @@ static int Basic10Score(const StaticAnalyser::MOS6502::Disassembly &disassembly)
return Score(disassembly, rom_functions, variable_locations);
}
static int Basic11Score(const StaticAnalyser::MOS6502::Disassembly &disassembly) {
static int Basic11Score(const Analyser::Static::MOS6502::Disassembly &disassembly) {
std::set<uint16_t> rom_functions = {
0x0238, 0x023b, 0x023e, 0x0241, 0x0244, 0x0247,
0xc3c6, 0xc3f4, 0xc444, 0xc47c, 0xc4a8, 0xc4d3, 0xc4e0, 0xc524, 0xc55f, 0xc592, 0xc5e8, 0xc5fa, 0xc692, 0xc6b3, 0xc6ee, 0xc70d,
@@ -72,23 +79,44 @@ static int Basic11Score(const StaticAnalyser::MOS6502::Disassembly &disassembly)
return Score(disassembly, rom_functions, variable_locations);
}
void StaticAnalyser::Oric::AddTargets(const Media &media, std::list<Target> &destination) {
Target target;
target.machine = Target::Oric;
target.probability = 1.0;
static bool IsMicrodisc(Storage::Encodings::MFM::Parser &parser) {
/*
The Microdisc boot sector is sector 2 of track 0 and contains a 23-byte signature.
*/
Storage::Encodings::MFM::Sector *sector = parser.get_sector(0, 0, 2);
if(!sector) return false;
if(sector->samples.empty()) return false;
const std::vector<uint8_t> &first_sample = sector->samples[0];
if(first_sample.size() != 256) return false;
const uint8_t signature[] = {
0x00, 0x00, 0xFF, 0x00, 0xD0, 0x9F, 0xD0,
0x9F, 0x02, 0xB9, 0x01, 0x00, 0xFF, 0x00,
0x00, 0xB9, 0xE4, 0xB9, 0x00, 0x00, 0xE6,
0x12, 0x00
};
return !std::memcmp(signature, first_sample.data(), sizeof(signature));
}
void Analyser::Static::Oric::AddTargets(const Media &media, std::vector<std::unique_ptr<Analyser::Static::Target>> &destination) {
std::unique_ptr<Target> target(new Target);
target->machine = Machine::Oric;
target->confidence = 0.5;
int basic10_votes = 0;
int basic11_votes = 0;
for(auto &tape : media.tapes) {
std::list<File> tape_files = GetFiles(tape);
std::vector<File> tape_files = GetFiles(tape);
tape->reset();
if(tape_files.size()) {
for(auto file : tape_files) {
if(file.data_type == File::MachineCode) {
std::vector<uint16_t> entry_points = {file.starting_address};
StaticAnalyser::MOS6502::Disassembly disassembly =
StaticAnalyser::MOS6502::Disassemble(file.data, StaticAnalyser::MOS6502::OffsetMapper(file.starting_address), entry_points);
Analyser::Static::MOS6502::Disassembly disassembly =
Analyser::Static::MOS6502::Disassemble(file.data, Analyser::Static::Disassembler::OffsetMapper(file.starting_address), entry_points);
int basic10_score = Basic10Score(disassembly);
int basic11_score = Basic11Score(disassembly);
@@ -96,23 +124,28 @@ void StaticAnalyser::Oric::AddTargets(const Media &media, std::list<Target> &des
}
}
target.media.tapes.push_back(tape);
target.loadingCommand = "CLOAD\"\"\n";
target->media.tapes.push_back(tape);
target->loading_command = "CLOAD\"\"\n";
}
}
// trust that any disk supplied can be handled by the Microdisc. TODO: check.
if(!media.disks.empty()) {
target.oric.has_microdisc = true;
target.media.disks = media.disks;
// Only the Microdisc is emulated right now, so accept only disks that it can boot from.
for(const auto &disk: media.disks) {
Storage::Encodings::MFM::Parser parser(true, disk);
if(IsMicrodisc(parser)) {
target->has_microdrive = true;
target->media.disks.push_back(disk);
}
}
} else {
target.oric.has_microdisc = false;
target->has_microdrive = false;
}
// TODO: really this should add two targets if not all votes agree
target.oric.use_atmos_rom = basic11_votes >= basic10_votes;
if(target.oric.has_microdisc) target.oric.use_atmos_rom = true;
target->use_atmos_rom = basic11_votes >= basic10_votes;
if(target->has_microdrive) target->use_atmos_rom = true;
if(target.media.tapes.size() || target.media.disks.size() || target.media.cartridges.size())
destination.push_back(target);
if(target->media.tapes.size() || target->media.disks.size() || target->media.cartridges.size())
destination.push_back(std::move(target));
}

View File

@@ -11,13 +11,14 @@
#include "../StaticAnalyser.hpp"
namespace StaticAnalyser {
namespace Analyser {
namespace Static {
namespace Oric {
void AddTargets(const Media &media, std::list<Target> &destination);
void AddTargets(const Media &media, std::vector<std::unique_ptr<Target>> &destination);
}
}
}
#endif /* StaticAnalyser_hpp */

View File

@@ -7,12 +7,12 @@
//
#include "Tape.hpp"
#include "../../Storage/Tape/Parsers/Oric.hpp"
#include "../../../Storage/Tape/Parsers/Oric.hpp"
using namespace StaticAnalyser::Oric;
using namespace Analyser::Static::Oric;
std::list<File> StaticAnalyser::Oric::GetFiles(const std::shared_ptr<Storage::Tape::Tape> &tape) {
std::list<File> files;
std::vector<File> Analyser::Static::Oric::GetFiles(const std::shared_ptr<Storage::Tape::Tape> &tape) {
std::vector<File> files;
Storage::Tape::Oric::Parser parser;
while(!tape->is_at_end()) {

View File

@@ -9,12 +9,13 @@
#ifndef StaticAnalyser_Oric_Tape_hpp
#define StaticAnalyser_Oric_Tape_hpp
#include "../../Storage/Tape/Tape.hpp"
#include <list>
#include "../../../Storage/Tape/Tape.hpp"
#include <string>
#include <vector>
namespace StaticAnalyser {
namespace Analyser {
namespace Static {
namespace Oric {
struct File {
@@ -30,8 +31,9 @@ struct File {
std::vector<uint8_t> data;
};
std::list<File> GetFiles(const std::shared_ptr<Storage::Tape::Tape> &tape);
std::vector<File> GetFiles(const std::shared_ptr<Storage::Tape::Tape> &tape);
}
}
}

View File

@@ -0,0 +1,25 @@
//
// Target.hpp
// Clock Signal
//
// Created by Thomas Harte on 09/03/2018.
// Copyright © 2018 Thomas Harte. All rights reserved.
//
#ifndef Analyser_Static_Oric_Target_h
#define Analyser_Static_Oric_Target_h
namespace Analyser {
namespace Static {
namespace Oric {
struct Target: public ::Analyser::Static::Target {
bool use_atmos_rom = false;
bool has_microdrive = false;
};
}
}
}
#endif /* Analyser_Static_Oric_Target_h */

View File

@@ -0,0 +1,175 @@
//
// StaticAnalyser.cpp
// Clock Signal
//
// Created by Thomas Harte on 23/08/2016.
// Copyright © 2016 Thomas Harte. All rights reserved.
//
#include "StaticAnalyser.hpp"
#include <algorithm>
#include <cstdlib>
#include <cstring>
// Analysers
#include "Acorn/StaticAnalyser.hpp"
#include "AmstradCPC/StaticAnalyser.hpp"
#include "Atari/StaticAnalyser.hpp"
#include "Coleco/StaticAnalyser.hpp"
#include "Commodore/StaticAnalyser.hpp"
#include "MSX/StaticAnalyser.hpp"
#include "Oric/StaticAnalyser.hpp"
#include "ZX8081/StaticAnalyser.hpp"
// Cartridges
#include "../../Storage/Cartridge/Formats/BinaryDump.hpp"
#include "../../Storage/Cartridge/Formats/PRG.hpp"
// Disks
#include "../../Storage/Disk/DiskImage/Formats/AcornADF.hpp"
#include "../../Storage/Disk/DiskImage/Formats/CPCDSK.hpp"
#include "../../Storage/Disk/DiskImage/Formats/D64.hpp"
#include "../../Storage/Disk/DiskImage/Formats/G64.hpp"
#include "../../Storage/Disk/DiskImage/Formats/DMK.hpp"
#include "../../Storage/Disk/DiskImage/Formats/HFE.hpp"
#include "../../Storage/Disk/DiskImage/Formats/MSXDSK.hpp"
#include "../../Storage/Disk/DiskImage/Formats/OricMFMDSK.hpp"
#include "../../Storage/Disk/DiskImage/Formats/SSD.hpp"
// Tapes
#include "../../Storage/Tape/Formats/CAS.hpp"
#include "../../Storage/Tape/Formats/CommodoreTAP.hpp"
#include "../../Storage/Tape/Formats/CSW.hpp"
#include "../../Storage/Tape/Formats/OricTAP.hpp"
#include "../../Storage/Tape/Formats/TapePRG.hpp"
#include "../../Storage/Tape/Formats/TapeUEF.hpp"
#include "../../Storage/Tape/Formats/TZX.hpp"
#include "../../Storage/Tape/Formats/ZX80O81P.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;
// 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::transform(extension.begin(), extension.end(), extension.begin(), ::tolower);
#define Insert(list, class, platforms) \
list.emplace_back(new Storage::class(file_name));\
potential_platforms |= platforms;\
TargetPlatform::TypeDistinguisher *distinguisher = dynamic_cast<TargetPlatform::TypeDistinguisher *>(list.back().get());\
if(distinguisher) potential_platforms &= distinguisher->target_platform_type();
#define TryInsert(list, class, platforms) \
try {\
Insert(list, class, platforms) \
} catch(...) {}
#define Format(ext, list, class, platforms) \
if(extension == ext) { \
TryInsert(list, class, platforms) \
}
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("bin", result.cartridges, Cartridge::BinaryDump, TargetPlatform::AllCartridge) // BIN
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("csw", result.tapes, Tape::CSW, TargetPlatform::AllTape) // CSW
Format("d64", result.disks, Disk::DiskImageHolder<Storage::Disk::D64>, TargetPlatform::Commodore) // D64
Format("dmk", result.disks, Disk::DiskImageHolder<Storage::Disk::DMK>, TargetPlatform::MSX) // DMK
Format("dsd", result.disks, Disk::DiskImageHolder<Storage::Disk::SSD>, TargetPlatform::Acorn) // DSD
Format("dsk", result.disks, Disk::DiskImageHolder<Storage::Disk::CPCDSK>, TargetPlatform::AmstradCPC) // DSK (Amstrad CPC)
Format("dsk", result.disks, Disk::DiskImageHolder<Storage::Disk::MSXDSK>, 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)
// HFE (TODO: switch to AllDisk once the MSX stops being so greedy)
Format("o", result.tapes, Tape::ZX80O81P, TargetPlatform::ZX8081) // O
Format("p", result.tapes, Tape::ZX80O81P, TargetPlatform::ZX8081) // P
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)
} catch(...) {
try {
Insert(result.tapes, Tape::PRG, TargetPlatform::Commodore)
} catch(...) {}
}
}
Format( "rom",
result.cartridges,
Cartridge::BinaryDump,
TargetPlatform::AcornElectron | TargetPlatform::ColecoVision | TargetPlatform::MSX) // ROM
Format("ssd", result.disks, Disk::DiskImageHolder<Storage::Disk::SSD>, TargetPlatform::Acorn) // SSD
Format("tap", result.tapes, Tape::CommodoreTAP, TargetPlatform::Commodore) // TAP (Commodore)
Format("tap", result.tapes, Tape::OricTAP, TargetPlatform::Oric) // TAP (Oric)
Format("tsx", result.tapes, Tape::TZX, TargetPlatform::MSX) // TSX
Format("tzx", result.tapes, Tape::TZX, TargetPlatform::ZX8081) // TZX
Format("uef", result.tapes, Tape::UEF, TargetPlatform::Acorn) // UEF (tape)
#undef Format
#undef Insert
#undef TryInsert
return result;
}
Media Analyser::Static::GetMedia(const std::string &file_name) {
TargetPlatform::IntType throwaway;
return GetMediaAndPlatforms(file_name, throwaway);
}
std::vector<std::unique_ptr<Target>> Analyser::Static::GetTargets(const std::string &file_name) {
std::vector<std::unique_ptr<Target>> targets;
// Collect all disks, tapes and ROMs 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.
if(potential_platforms & TargetPlatform::Acorn) Acorn::AddTargets(media, targets);
if(potential_platforms & TargetPlatform::AmstradCPC) AmstradCPC::AddTargets(media, targets);
if(potential_platforms & TargetPlatform::Atari2600) Atari::AddTargets(media, targets);
if(potential_platforms & TargetPlatform::ColecoVision) Coleco::AddTargets(media, targets);
if(potential_platforms & TargetPlatform::Commodore) Commodore::AddTargets(media, targets, file_name);
if(potential_platforms & TargetPlatform::MSX) MSX::AddTargets(media, targets);
if(potential_platforms & TargetPlatform::Oric) Oric::AddTargets(media, targets);
if(potential_platforms & TargetPlatform::ZX8081) ZX8081::AddTargets(media, targets, potential_platforms);
// Reset any tapes to their initial position
for(auto &target : targets) {
for(auto &tape : target->media.tapes) {
tape->reset();
}
}
// Sort by initial confidence. Use a stable sort in case any of the machine-specific analysers
// picked their insertion order carefully.
std::stable_sort(targets.begin(), targets.end(),
[] (const std::unique_ptr<Target> &a, const std::unique_ptr<Target> &b) {
return a->confidence > b->confidence;
});
return targets;
}

View File

@@ -0,0 +1,66 @@
//
// StaticAnalyser.hpp
// Clock Signal
//
// Created by Thomas Harte on 23/08/2016.
// Copyright © 2016 Thomas Harte. All rights reserved.
//
#ifndef StaticAnalyser_hpp
#define StaticAnalyser_hpp
#include "../Machines.hpp"
#include "../../Storage/Tape/Tape.hpp"
#include "../../Storage/Disk/Disk.hpp"
#include "../../Storage/Cartridge/Cartridge.hpp"
#include <string>
#include <vector>
namespace Analyser {
namespace Static {
/*!
A list of disks, tapes and cartridges.
*/
struct Media {
std::vector<std::shared_ptr<Storage::Disk::Disk>> disks;
std::vector<std::shared_ptr<Storage::Tape::Tape>> tapes;
std::vector<std::shared_ptr<Storage::Cartridge::Cartridge>> cartridges;
bool empty() const {
return disks.empty() && tapes.empty() && cartridges.empty();
}
};
/*!
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.
*/
struct Target {
virtual ~Target() {}
Machine machine;
Media media;
float confidence;
std::string loading_command;
};
/*!
Attempts, through any available means, to return a list of potential targets for the file with the given name.
@returns The list of potential targets, sorted from most to least probable.
*/
std::vector<std::unique_ptr<Target>> GetTargets(const std::string &file_name);
/*!
Inspects the supplied file and determines the media included.
*/
Media GetMedia(const std::string &file_name);
}
}
#endif /* StaticAnalyser_hpp */

View File

@@ -11,7 +11,8 @@
#include <string>
#include <vector>
#include "../../Storage/Tape/Parsers/ZX8081.hpp"
#include "Target.hpp"
#include "../../../Storage/Tape/Parsers/ZX8081.hpp"
static std::vector<Storage::Data::ZX8081::File> GetFiles(const std::shared_ptr<Storage::Tape::Tape> &tape) {
std::vector<Storage::Data::ZX8081::File> files;
@@ -27,41 +28,41 @@ static std::vector<Storage::Data::ZX8081::File> GetFiles(const std::shared_ptr<S
return files;
}
void StaticAnalyser::ZX8081::AddTargets(const Media &media, std::list<Target> &destination, TargetPlatform::IntType potential_platforms) {
void Analyser::Static::ZX8081::AddTargets(const Media &media, std::vector<std::unique_ptr<::Analyser::Static::Target>> &destination, TargetPlatform::IntType potential_platforms) {
if(!media.tapes.empty()) {
std::vector<Storage::Data::ZX8081::File> files = GetFiles(media.tapes.front());
media.tapes.front()->reset();
if(!files.empty()) {
StaticAnalyser::Target target;
target.machine = Target::ZX8081;
Target *target = new Target;
destination.push_back(std::unique_ptr<::Analyser::Static::Target>(target));
target->machine = Machine::ZX8081;
// Guess the machine type from the file only if it isn't already known.
switch(potential_platforms & (TargetPlatform::ZX80 | TargetPlatform::ZX81)) {
default:
target.zx8081.isZX81 = files.front().isZX81;
target->is_ZX81 = files.front().isZX81;
break;
case TargetPlatform::ZX80: target.zx8081.isZX81 = false; break;
case TargetPlatform::ZX81: target.zx8081.isZX81 = true; break;
case TargetPlatform::ZX80: target->is_ZX81 = false; break;
case TargetPlatform::ZX81: target->is_ZX81 = true; break;
}
/*if(files.front().data.size() > 16384) {
target.zx8081.memory_model = ZX8081MemoryModel::SixtyFourKB;
target->zx8081.memory_model = ZX8081MemoryModel::SixtyFourKB;
} else*/ if(files.front().data.size() > 1024) {
target.zx8081.memory_model = ZX8081MemoryModel::SixteenKB;
target->memory_model = Target::MemoryModel::SixteenKB;
} else {
target.zx8081.memory_model = ZX8081MemoryModel::Unexpanded;
target->memory_model = Target::MemoryModel::Unexpanded;
}
target.media.tapes = media.tapes;
target->media.tapes = media.tapes;
// TODO: how to run software once loaded? Might require a BASIC detokeniser.
if(target.zx8081.isZX81) {
target.loadingCommand = "J\"\"\n";
if(target->is_ZX81) {
target->loading_command = "J\"\"\n";
} else {
target.loadingCommand = "W\n";
target->loading_command = "W\n";
}
destination.push_back(target);
}
}
}

View File

@@ -10,13 +10,15 @@
#define StaticAnalyser_ZX8081_StaticAnalyser_hpp
#include "../StaticAnalyser.hpp"
#include "../../Storage/TargetPlatforms.hpp"
#include "../../../Storage/TargetPlatforms.hpp"
namespace StaticAnalyser {
namespace Analyser {
namespace Static {
namespace ZX8081 {
void AddTargets(const Media &media, std::list<Target> &destination, TargetPlatform::IntType potential_platforms);
void AddTargets(const Media &media, std::vector<std::unique_ptr<Target>> &destination, TargetPlatform::IntType potential_platforms);
}
}
}

View File

@@ -0,0 +1,34 @@
//
// Target.hpp
// Clock Signal
//
// Created by Thomas Harte on 09/03/2018.
// Copyright © 2018 Thomas Harte. All rights reserved.
//
#ifndef Analyser_Static_ZX8081_Target_h
#define Analyser_Static_ZX8081_Target_h
#include "../StaticAnalyser.hpp"
namespace Analyser {
namespace Static {
namespace ZX8081 {
struct Target: public ::Analyser::Static::Target {
enum class MemoryModel {
Unexpanded,
SixteenKB,
SixtyFourKB
};
MemoryModel memory_model = MemoryModel::Unexpanded;
bool is_ZX81 = false;
bool ZX80_uses_ZX81_ROM = false;
};
}
}
}
#endif /* Analyser_Static_ZX8081_Target_h */

View File

@@ -169,13 +169,20 @@ class HalfCycles: public WrappedInt<HalfCycles> {
return Cycles(length_ >> 1);
}
///Flushes the whole cycles in @c this, subtracting that many from the total stored here.
/// Flushes the whole cycles in @c this, subtracting that many from the total stored here.
inline Cycles flush_cycles() {
Cycles result(length_ >> 1);
length_ &= 1;
return result;
}
/// Flushes the half cycles in @c this, returning the number stored and setting this total to zero.
inline HalfCycles flush() {
HalfCycles result(length_);
length_ = 0;
return result;
}
/*!
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.

View File

@@ -0,0 +1,18 @@
//
// TimeTypes.hpp
// Clock Signal
//
// Created by Thomas Harte on 21/03/2018.
// Copyright © 2018 Thomas Harte. All rights reserved.
//
#ifndef TimeTypes_h
#define TimeTypes_h
namespace Time {
typedef double Seconds;
}
#endif /* TimeTypes_h */

View File

@@ -23,10 +23,16 @@ void WD1770::set_register(int address, uint8_t value) {
switch(address&3) {
case 0: {
if((value&0xf0) == 0xd0) {
printf("!!!TODO: force interrupt!!!\n");
update_status([] (Status &status) {
status.type = Status::One;
});
if(value == 0xd0) {
// Force interrupt **immediately**.
printf("Force interrupt immediately\n");
posit_event(static_cast<int>(Event1770::ForceInterrupt));
} else {
printf("!!!TODO: force interrupt!!!\n");
update_status([] (Status &status) {
status.type = Status::One;
});
}
} else {
command_ = value;
posit_event(static_cast<int>(Event1770::Command));
@@ -169,13 +175,23 @@ void WD1770::posit_event(int new_event_type) {
}
}
if(!(interesting_event_mask_ & static_cast<int>(new_event_type))) return;
interesting_event_mask_ &= ~new_event_type;
if(new_event_type == static_cast<int>(Event1770::ForceInterrupt)) {
interesting_event_mask_ = 0;
resume_point_ = 0;
update_status([] (Status &status) {
status.type = Status::One;
status.data_request = false;
});
} else {
if(!(interesting_event_mask_ & static_cast<int>(new_event_type))) return;
interesting_event_mask_ &= ~new_event_type;
}
Status new_status;
BEGIN_SECTION()
// Wait for a new command, branch to the appropriate handler.
case 0:
wait_for_command:
printf("Idle...\n");
set_data_mode(DataMode::Scanning);
@@ -460,7 +476,7 @@ void WD1770::posit_event(int new_event_type) {
sector_++;
goto test_type2_write_protection;
}
printf("Read sector %d\n", sector_);
printf("Finished reading sector %d\n", sector_);
goto wait_for_command;
}
goto type2_check_crc;

View File

@@ -116,7 +116,8 @@ class WD1770: public Storage::Disk::MFMController {
Command = (1 << 3), // Indicates receipt of a new command.
HeadLoad = (1 << 4), // Indicates the head has been loaded (1973 only).
Timer = (1 << 5), // Indicates that the delay_time_-powered timer has timed out.
IndexHoleTarget = (1 << 6) // Indicates that index_hole_count_ has reached index_hole_count_target_.
IndexHoleTarget = (1 << 6), // Indicates that index_hole_count_ has reached index_hole_count_target_.
ForceInterrupt = (1 << 7) // Indicates a forced interrupt.
};
void posit_event(int type);
int interesting_event_mask_;

View File

@@ -12,14 +12,18 @@
using namespace MOS;
void Speaker::set_volume(uint8_t volume) {
enqueue([=]() {
volume_ = volume;
AudioGenerator::AudioGenerator(Concurrency::DeferringAsyncTaskQueue &audio_queue) :
audio_queue_(audio_queue) {}
void AudioGenerator::set_volume(uint8_t volume) {
audio_queue_.defer([=]() {
volume_ = static_cast<int16_t>(volume) * range_multiplier_;
});
}
void Speaker::set_control(int channel, uint8_t value) {
enqueue([=]() {
void AudioGenerator::set_control(int channel, uint8_t value) {
audio_queue_.defer([=]() {
control_registers_[channel] = value;
});
}
@@ -101,7 +105,7 @@ static uint8_t noise_pattern[] = {
// testing against 0x80. The effect should be the same: loading with 0x7f means an output update every cycle, loading with 0x7e
// means every second cycle, etc.
void Speaker::get_samples(unsigned int number_of_samples, int16_t *target) {
void AudioGenerator::get_samples(std::size_t number_of_samples, int16_t *target) {
for(unsigned int c = 0; c < number_of_samples; c++) {
update(0, 2, shift);
update(1, 1, shift);
@@ -110,16 +114,16 @@ void Speaker::get_samples(unsigned int number_of_samples, int16_t *target) {
// this sums the output of all three sounds channels plus a DC offset for volume;
// TODO: what's the real ratio of this stuff?
target[c] = (
target[c] = static_cast<int16_t>(
(shift_registers_[0]&1) +
(shift_registers_[1]&1) +
(shift_registers_[2]&1) +
((noise_pattern[shift_registers_[3] >> 3] >> (shift_registers_[3]&7))&(control_registers_[3] >> 7)&1)
) * volume_ * 700 + volume_ * 44;
) * volume_ + (volume_ >> 4);
}
}
void Speaker::skip_samples(unsigned int number_of_samples) {
void AudioGenerator::skip_samples(std::size_t number_of_samples) {
for(unsigned int c = 0; c < number_of_samples; c++) {
update(0, 2, shift);
update(1, 1, shift);
@@ -128,6 +132,10 @@ void Speaker::skip_samples(unsigned int number_of_samples) {
}
}
void AudioGenerator::set_sample_volume_range(std::int16_t range) {
range_multiplier_ = static_cast<int16_t>(range / 64);
}
#undef shift
#undef increment
#undef update

View File

@@ -9,26 +9,35 @@
#ifndef _560_hpp
#define _560_hpp
#include "../../Outputs/CRT/CRT.hpp"
#include "../../Outputs/Speaker.hpp"
#include "../../ClockReceiver/ClockReceiver.hpp"
#include "../../Concurrency/AsyncTaskQueue.hpp"
#include "../../Outputs/CRT/CRT.hpp"
#include "../../Outputs/Speaker/Implementation/LowpassSpeaker.hpp"
#include "../../Outputs/Speaker/Implementation/SampleSource.hpp"
namespace MOS {
// audio state
class Speaker: public ::Outputs::Filter<Speaker> {
class AudioGenerator: public ::Outputs::Speaker::SampleSource {
public:
AudioGenerator(Concurrency::DeferringAsyncTaskQueue &audio_queue);
void set_volume(uint8_t volume);
void set_control(int channel, uint8_t value);
void get_samples(unsigned int number_of_samples, int16_t *target);
void skip_samples(unsigned int number_of_samples);
// For ::SampleSource.
void get_samples(std::size_t number_of_samples, int16_t *target);
void skip_samples(std::size_t number_of_samples);
void set_sample_volume_range(std::int16_t range);
private:
Concurrency::DeferringAsyncTaskQueue &audio_queue_;
unsigned int counters_[4] = {2, 1, 0, 0}; // create a slight phase offset for the three channels
unsigned int shift_registers_[4] = {0, 0, 0, 0};
uint8_t control_registers_[4] = {0, 0, 0, 0};
uint8_t volume_ = 0;
int16_t volume_ = 0;
int16_t range_multiplier_ = 1;
};
/*!
@@ -43,27 +52,41 @@ template <class T> class MOS6560 {
public:
MOS6560() :
crt_(new Outputs::CRT::CRT(65*4, 4, Outputs::CRT::DisplayType::NTSC60, 2)),
speaker_(new Speaker) {
crt_->set_composite_sampling_function(
"float composite_sample(usampler2D texID, vec2 coordinate, vec2 iCoordinate, float phase, float amplitude)"
audio_generator_(audio_queue_),
speaker_(audio_generator_)
{
crt_->set_svideo_sampling_function(
"vec2 svideo_sample(usampler2D texID, vec2 coordinate, vec2 iCoordinate, float phase)"
"{"
"vec2 yc = texture(texID, coordinate).rg / vec2(255.0);"
"float phaseOffset = 6.283185308 * 2.0 * yc.y;"
"float chroma = cos(phase + phaseOffset);"
"return mix(yc.x, step(yc.y, 0.75) * chroma, amplitude);"
"float phaseOffset = 6.283185308 * 2.0 * yc.y;"
"float chroma = step(yc.y, 0.75) * cos(phase + phaseOffset);"
"return vec2(yc.x, chroma);"
"}");
// default to s-video output
crt_->set_video_signal(Outputs::CRT::VideoSignal::SVideo);
// default to NTSC
set_output_mode(OutputMode::NTSC);
}
void set_clock_rate(double clock_rate) {
speaker_->set_input_rate(static_cast<float>(clock_rate / 4.0));
~MOS6560() {
audio_queue_.flush();
}
std::shared_ptr<Outputs::CRT::CRT> get_crt() { return crt_; }
std::shared_ptr<Outputs::Speaker> get_speaker() { return speaker_; }
void set_clock_rate(double clock_rate) {
speaker_.set_input_rate(static_cast<float>(clock_rate / 4.0));
}
Outputs::CRT::CRT *get_crt() { return crt_.get(); }
Outputs::Speaker::Speaker *get_speaker() { return &speaker_; }
void set_high_frequency_cutoff(float cutoff) {
speaker_.set_high_frequency_cutoff(cutoff);
}
enum OutputMode {
PAL, NTSC
@@ -75,28 +98,28 @@ template <class T> class MOS6560 {
void set_output_mode(OutputMode output_mode) {
output_mode_ = output_mode;
// Lumunances are encoded trivially: on a 0255 scale.
// Luminances are encoded trivially: on a 0255 scale.
const uint8_t luminances[16] = {
0, 255, 109, 189,
199, 144, 159, 161,
126, 227, 227, 207,
235, 173, 188, 196
0, 255, 60, 189,
80, 144, 40, 227,
90, 161, 207, 227,
200, 196, 160, 196
};
// Chrominances are encoded such that 0128 is a complete revolution of phase;
// anything above 191 disables the colour subcarrier. Phase is relative to the
// colour burst, so 0 is green.
const uint8_t pal_chrominances[16] = {
255, 255, 40, 112,
8, 88, 120, 56,
40, 48, 40, 112,
8, 88, 120, 56,
255, 255, 37, 101,
19, 86, 123, 59,
46, 53, 37, 101,
19, 86, 123, 59,
};
const uint8_t ntsc_chrominances[16] = {
255, 255, 8, 72,
32, 88, 48, 112,
0, 0, 8, 72,
32, 88, 48, 112,
255, 255, 7, 71,
25, 86, 48, 112,
0, 119, 7, 71,
25, 86, 48, 112,
};
const uint8_t *chrominances;
Outputs::CRT::DisplayType display_type;
@@ -122,16 +145,15 @@ template <class T> class MOS6560 {
}
crt_->set_new_display_type(static_cast<unsigned int>(timing_.cycles_per_line*4), display_type);
crt_->set_visible_area(Outputs::CRT::Rect(0.05f, 0.05f, 0.9f, 0.9f));
// switch(output_mode) {
// case OutputMode::PAL:
// crt_->set_visible_area(crt_->get_rect_for_area(16, 237, 15*4, 55*4, 4.0f / 3.0f));
// break;
// case OutputMode::NTSC:
// crt_->set_visible_area(crt_->get_rect_for_area(16, 237, 11*4, 55*4, 4.0f / 3.0f));
// break;
// }
switch(output_mode) {
case OutputMode::PAL:
crt_->set_visible_area(Outputs::CRT::Rect(0.1f, 0.05f, 0.9f, 0.9f));
break;
case OutputMode::NTSC:
crt_->set_visible_area(Outputs::CRT::Rect(0.05f, 0.05f, 0.9f, 0.9f));
break;
}
for(int c = 0; c < 16; c++) {
uint8_t *colour = reinterpret_cast<uint8_t *>(&colours_[c]);
@@ -318,7 +340,10 @@ template <class T> class MOS6560 {
/*!
Causes the 6560 to flush as much pending CRT and speaker communications as possible.
*/
inline void flush() { update_audio(); speaker_->flush(); }
inline void flush() {
update_audio();
audio_queue_.perform();
}
/*!
Writes to a 6560 register.
@@ -356,13 +381,13 @@ template <class T> class MOS6560 {
case 0xc:
case 0xd:
update_audio();
speaker_->set_control(address - 0xa, value);
audio_generator_.set_control(address - 0xa, value);
break;
case 0xe:
update_audio();
registers_.auxiliary_colour = colours_[value >> 4];
speaker_->set_volume(value & 0xf);
audio_generator_.set_volume(value & 0xf);
break;
case 0xf: {
@@ -398,12 +423,15 @@ template <class T> class MOS6560 {
}
private:
std::shared_ptr<Outputs::CRT::CRT> crt_;
std::unique_ptr<Outputs::CRT::CRT> crt_;
Concurrency::DeferringAsyncTaskQueue audio_queue_;
AudioGenerator audio_generator_;
Outputs::Speaker::LowpassSpeaker<AudioGenerator> speaker_;
std::shared_ptr<Speaker> speaker_;
Cycles cycles_since_speaker_update_;
void update_audio() {
speaker_->run_for(Cycles(cycles_since_speaker_update_.divide(Cycles(4))));
speaker_.run_for(audio_queue_, Cycles(cycles_since_speaker_update_.divide(Cycles(4))));
}
// register state

View File

@@ -76,8 +76,8 @@ template <class T> class i8255 {
private:
void update_outputs() {
port_handler_.set_value(0, outputs_[0]);
port_handler_.set_value(1, outputs_[1]);
if(!(control_ & 0x10)) port_handler_.set_value(0, outputs_[0]);
if(!(control_ & 0x02)) port_handler_.set_value(1, outputs_[1]);
port_handler_.set_value(2, outputs_[2]);
}

712
Components/9918/9918.cpp Normal file
View File

@@ -0,0 +1,712 @@
//
// 9918.cpp
// Clock Signal
//
// Created by Thomas Harte on 25/11/2017.
// Copyright © 2017 Thomas Harte. All rights reserved.
//
#include "9918.hpp"
#include <cassert>
#include <cstring>
using namespace TI;
namespace {
const uint32_t palette_pack(uint8_t r, uint8_t g, uint8_t b) {
uint32_t result = 0;
uint8_t *const result_ptr = reinterpret_cast<uint8_t *>(&result);
result_ptr[0] = r;
result_ptr[1] = g;
result_ptr[2] = b;
result_ptr[3] = 0;
return result;
}
const uint32_t palette[16] = {
palette_pack(0, 0, 0),
palette_pack(0, 0, 0),
palette_pack(33, 200, 66),
palette_pack(94, 220, 120),
palette_pack(84, 85, 237),
palette_pack(125, 118, 252),
palette_pack(212, 82, 77),
palette_pack(66, 235, 245),
palette_pack(252, 85, 84),
palette_pack(255, 121, 120),
palette_pack(212, 193, 84),
palette_pack(230, 206, 128),
palette_pack(33, 176, 59),
palette_pack(201, 91, 186),
palette_pack(204, 204, 204),
palette_pack(255, 255, 255)
};
const uint8_t StatusInterrupt = 0x80;
const uint8_t StatusFifthSprite = 0x40;
const int StatusSpriteCollisionShift = 5;
const uint8_t StatusSpriteCollision = 0x20;
struct ReverseTable {
std::uint8_t map[256];
ReverseTable() {
for(int c = 0; c < 256; ++c) {
map[c] = static_cast<uint8_t>(
((c & 0x80) >> 7) |
((c & 0x40) >> 5) |
((c & 0x20) >> 3) |
((c & 0x10) >> 1) |
((c & 0x08) << 1) |
((c & 0x04) << 3) |
((c & 0x02) << 5) |
((c & 0x01) << 7)
);
}
}
} reverse_table;
// Bits are reversed in the internal mode value; they're stored
// in the order M1 M2 M3. Hence the definitions below.
enum ScreenMode {
Text = 4,
MultiColour = 2,
ColouredText = 0,
Graphics = 1
};
}
TMS9918Base::TMS9918Base() :
// 342 internal cycles are 228/227.5ths of a line, so 341.25 cycles should be a whole
// line. Therefore multiply everything by four, but set line length to 1365 rather than 342*4 = 1368.
crt_(new Outputs::CRT::CRT(1365, 4, Outputs::CRT::DisplayType::NTSC60, 4)) {}
TMS9918::TMS9918(Personality p) {
// Unimaginatively, this class just passes RGB through to the shader. Investigation is needed
// into whether there's a more natural form.
crt_->set_rgb_sampling_function(
"vec3 rgb_sample(usampler2D sampler, vec2 coordinate, vec2 icoordinate)"
"{"
"return texture(sampler, coordinate).rgb / vec3(255.0);"
"}");
crt_->set_video_signal(Outputs::CRT::VideoSignal::RGB);
crt_->set_visible_area(Outputs::CRT::Rect(0.055f, 0.025f, 0.9f, 0.9f));
crt_->set_input_gamma(2.8f);
// The TMS remains in-phase with the NTSC colour clock; this is an empirical measurement
// intended to produce the correct relationship between the hard edges between pixels and
// the colour clock. It was eyeballed rather than derived from any knowledge of the TMS
// colour burst generator because I've yet to find any.
crt_->set_immediate_default_phase(0.85f);
}
Outputs::CRT::CRT *TMS9918::get_crt() {
return crt_.get();
}
void TMS9918Base::test_sprite(int sprite_number, int screen_row) {
if(!(status_ & StatusFifthSprite)) {
status_ = static_cast<uint8_t>((status_ & ~31) | sprite_number);
}
if(sprites_stopped_)
return;
const int sprite_position = ram_[sprite_attribute_table_address_ + (sprite_number << 2)];
// A sprite Y of 208 means "don't scan the list any further".
if(sprite_position == 208) {
sprites_stopped_ = true;
return;
}
const int sprite_row = (screen_row - sprite_position)&255;
if(sprite_row < 0 || sprite_row >= sprite_height_) return;
const int active_sprite_slot = sprite_sets_[active_sprite_set_].active_sprite_slot;
if(active_sprite_slot == 4) {
status_ |= StatusFifthSprite;
return;
}
SpriteSet::ActiveSprite &sprite = sprite_sets_[active_sprite_set_].active_sprites[active_sprite_slot];
sprite.index = sprite_number;
sprite.row = sprite_row >> (sprites_magnified_ ? 1 : 0);
sprite_sets_[active_sprite_set_].active_sprite_slot++;
}
void TMS9918Base::get_sprite_contents(int field, int cycles_left, int screen_row) {
int sprite_id = field / 6;
field %= 6;
while(true) {
const int cycles_in_sprite = std::min(cycles_left, 6 - field);
cycles_left -= cycles_in_sprite;
const int final_field = cycles_in_sprite + field;
assert(sprite_id < 4);
SpriteSet::ActiveSprite &sprite = sprite_sets_[active_sprite_set_].active_sprites[sprite_id];
if(field < 4) {
std::memcpy(
&sprite.info[field],
&ram_[sprite_attribute_table_address_ + (sprite.index << 2) + field],
static_cast<size_t>(std::min(4, final_field) - field));
}
field = std::min(4, final_field);
const int sprite_offset = sprite.info[2] & ~(sprites_16x16_ ? 3 : 0);
const int sprite_address = sprite_generator_table_address_ + (sprite_offset << 3) + sprite.row; // TODO: recalclate sprite.row from screen_row (?)
while(field < final_field) {
sprite.image[field - 4] = ram_[sprite_address + ((field - 4) << 4)];
field++;
}
if(!cycles_left) return;
field = 0;
sprite_id++;
}
}
void TMS9918::run_for(const HalfCycles cycles) {
// As specific as I've been able to get:
// Scanline time is always 228 cycles.
// PAL output is 313 lines total. NTSC output is 262 lines total.
// Interrupt is signalled upon entering the lower border.
// Keep a count of cycles separate from internal counts to avoid
// potential errors mapping back and forth.
half_cycles_into_frame_ = (half_cycles_into_frame_ + cycles) % HalfCycles(frame_lines_ * 228 * 2);
// Convert 456 clocked half cycles per line to 342 internal cycles per line;
// the internal clock is 1.5 times the nominal 3.579545 Mhz that I've advertised
// for this part. So multiply by three quarters.
int int_cycles = (cycles.as_int() * 3) + cycles_error_;
cycles_error_ = int_cycles & 3;
int_cycles >>= 2;
if(!int_cycles) return;
while(int_cycles) {
// Determine how much time has passed in the remainder of this line, and proceed.
int cycles_left = std::min(342 - column_, int_cycles);
// ------------------------------------
// Potentially perform a memory access.
// ------------------------------------
if(queued_access_ != MemoryAccess::None) {
int time_until_access_slot = 0;
switch(line_mode_) {
case LineMode::Refresh:
if(column_ < 53 || column_ >= 307) time_until_access_slot = column_&1;
else time_until_access_slot = 3 - ((column_ - 53)&3);
// i.e. 53 -> 3, 52 -> 2, 51 -> 1, 50 -> 0, etc
break;
case LineMode::Text:
if(column_ < 59 || column_ >= 299) time_until_access_slot = column_&1;
else time_until_access_slot = 5 - ((column_ + 3)%6);
// i.e. 59 -> 3, 60 -> 2, 61 -> 1, etc
break;
case LineMode::Character:
if(column_ < 9) time_until_access_slot = column_&1;
else if(column_ < 30) time_until_access_slot = 30 - column_;
else if(column_ < 37) time_until_access_slot = column_&1;
else if(column_ < 311) time_until_access_slot = 31 - ((column_ + 7)&31);
// i.e. 53 -> 3, 54 -> 2, 55 -> 1, 56 -> 0, 57 -> 31, etc
else if(column_ < 313) time_until_access_slot = column_&1;
else time_until_access_slot = 342 - column_;
break;
}
if(cycles_left >= time_until_access_slot) {
if(queued_access_ == MemoryAccess::Write) {
ram_[ram_pointer_ & 16383] = read_ahead_buffer_;
} else {
read_ahead_buffer_ = ram_[ram_pointer_ & 16383];
}
ram_pointer_++;
queued_access_ = MemoryAccess::None;
}
}
column_ += cycles_left; // column_ is now the column that has been reached in this line.
int_cycles -= cycles_left; // Count down duration to run for.
// ------------------------------
// Perform video memory accesses.
// ------------------------------
if(((row_ < 192) || (row_ == frame_lines_-1)) && !blank_screen_) {
const int sprite_row = (row_ < 192) ? row_ : -1;
const int access_slot = column_ >> 1; // There are only 171 available memory accesses per line.
switch(line_mode_) {
default: break;
case LineMode::Text:
access_pointer_ = std::min(30, access_slot);
if(access_pointer_ >= 30 && access_pointer_ < 150) {
const int row_base = pattern_name_address_ + (row_ >> 3) * 40;
const int end = std::min(150, access_slot);
// Pattern names are collected every third window starting from window 30.
const int pattern_names_start = (access_pointer_ - 30 + 2) / 3;
const int pattern_names_end = (end - 30 + 2) / 3;
std::memcpy(&pattern_names_[pattern_names_start], &ram_[row_base + pattern_names_start], static_cast<size_t>(pattern_names_end - pattern_names_start));
// Patterns are collected every third window starting from window 32.
const int pattern_buffer_start = (access_pointer_ - 32 + 2) / 3;
const int pattern_buffer_end = (end - 32 + 2) / 3;
for(int column = pattern_buffer_start; column < pattern_buffer_end; ++column) {
pattern_buffer_[column] = ram_[pattern_generator_table_address_ + (pattern_names_[column] << 3) + (row_ & 7)];
}
}
break;
case LineMode::Character:
// Four access windows: no collection.
if(access_pointer_ < 5)
access_pointer_ = std::min(5, access_slot);
// Then ten access windows are filled with collection of sprite 3 and 4 details.
if(access_pointer_ >= 5 && access_pointer_ < 15) {
int end = std::min(15, access_slot);
get_sprite_contents(access_pointer_ - 5 + 14, end - access_pointer_, sprite_row - 1);
access_pointer_ = std::min(15, access_slot);
}
// Four more access windows: no collection.
if(access_pointer_ >= 15 && access_pointer_ < 19) {
access_pointer_ = std::min(19, access_slot);
// Start new sprite set if this is location 19.
if(access_pointer_ == 19) {
active_sprite_set_ ^= 1;
sprite_sets_[active_sprite_set_].active_sprite_slot = 0;
sprites_stopped_ = false;
}
}
// Then eight access windows fetch the y position for the first eight sprites.
while(access_pointer_ < 27 && access_pointer_ < access_slot) {
test_sprite(access_pointer_ - 19, sprite_row);
access_pointer_++;
}
// The next 128 access slots are video and sprite collection interleaved.
if(access_pointer_ >= 27 && access_pointer_ < 155) {
int end = std::min(155, access_slot);
int row_base = pattern_name_address_;
int pattern_base = pattern_generator_table_address_;
int colour_base = colour_table_address_;
if(screen_mode_ == ScreenMode::Graphics) {
// If this is high resolution mode, allow the row number to affect the pattern and colour addresses.
pattern_base &= 0x2000 | ((row_ & 0xc0) << 5);
colour_base &= 0x2000 | ((row_ & 0xc0) << 5);
}
row_base += (row_ << 2)&~31;
// Pattern names are collected every fourth window starting from window 27.
const int pattern_names_start = (access_pointer_ - 27 + 3) >> 2;
const int pattern_names_end = (end - 27 + 3) >> 2;
std::memcpy(&pattern_names_[pattern_names_start], &ram_[row_base + pattern_names_start], static_cast<size_t>(pattern_names_end - pattern_names_start));
// Colours are collected every fourth window starting from window 29.
const int colours_start = (access_pointer_ - 29 + 3) >> 2;
const int colours_end = (end - 29 + 3) >> 2;
if(screen_mode_ != 1) {
for(int column = colours_start; column < colours_end; ++column) {
colour_buffer_[column] = ram_[colour_base + (pattern_names_[column] >> 3)];
}
} else {
for(int column = colours_start; column < colours_end; ++column) {
colour_buffer_[column] = ram_[colour_base + (pattern_names_[column] << 3) + (row_ & 7)];
}
}
// Patterns are collected ever fourth window starting from window 30.
const int pattern_buffer_start = (access_pointer_ - 30 + 3) >> 2;
const int pattern_buffer_end = (end - 30 + 3) >> 2;
// Multicolour mode uss a different function of row to pick bytes
const int row = (screen_mode_ != 2) ? (row_ & 7) : ((row_ >> 2) & 7);
for(int column = pattern_buffer_start; column < pattern_buffer_end; ++column) {
pattern_buffer_[column] = ram_[pattern_base + (pattern_names_[column] << 3) + row];
}
// Sprite slots occur in three quarters of ever fourth window starting from window 28.
const int sprite_start = (access_pointer_ - 28 + 3) >> 2;
const int sprite_end = (end - 28 + 3) >> 2;
for(int column = sprite_start; column < sprite_end; ++column) {
if(column&3) {
test_sprite(7 + column - (column >> 2), sprite_row);
}
}
access_pointer_ = std::min(155, access_slot);
}
// Two access windows: no collection.
if(access_pointer_ < 157)
access_pointer_ = std::min(157, access_slot);
// Fourteen access windows: collect initial sprite information.
if(access_pointer_ >= 157 && access_pointer_ < 171) {
int end = std::min(171, access_slot);
get_sprite_contents(access_pointer_ - 157, end - access_pointer_, sprite_row);
access_pointer_ = std::min(171, access_slot);
}
break;
}
}
// --------------------------
// End video memory accesses.
// --------------------------
// --------------------
// Output video stream.
// --------------------
if(row_ < 192 && !blank_screen_) {
// ----------------------
// Output horizontal sync
// ----------------------
if(!output_column_ && column_ >= 26) {
crt_->output_sync(13 * 4);
crt_->output_default_colour_burst(13 * 4);
output_column_ = 26;
}
// -------------------
// Output left border.
// -------------------
if(output_column_ >= 26) {
int pixels_end = std::min(first_pixel_column_, column_);
if(output_column_ < pixels_end) {
output_border(pixels_end - output_column_);
output_column_ = pixels_end;
// Grab a pointer for drawing pixels to, if the moment has arrived.
if(pixels_end == first_pixel_column_) {
pixel_base_ = pixel_target_ = reinterpret_cast<uint32_t *>(crt_->allocate_write_area(static_cast<unsigned int>(first_right_border_column_ - first_pixel_column_)));
}
}
}
// --------------
// Output pixels.
// --------------
if(output_column_ >= first_pixel_column_) {
int pixels_end = std::min(first_right_border_column_, column_);
if(output_column_ < pixels_end) {
switch(line_mode_) {
default: break;
case LineMode::Text: {
const uint32_t colours[2] = { palette[background_colour_], palette[text_colour_] };
const int shift = (output_column_ - first_pixel_column_) % 6;
int byte_column = (output_column_ - first_pixel_column_) / 6;
int pattern = reverse_table.map[pattern_buffer_[byte_column]] >> shift;
int pixels_left = pixels_end - output_column_;
int length = std::min(pixels_left, 6 - shift);
while(true) {
pixels_left -= length;
for(int c = 0; c < length; ++c) {
pixel_target_[c] = colours[pattern&0x01];
pattern >>= 1;
}
pixel_target_ += length;
if(!pixels_left) break;
length = std::min(6, pixels_left);
byte_column++;
pattern = reverse_table.map[pattern_buffer_[byte_column]];
}
output_column_ = pixels_end;
} break;
case LineMode::Character: {
// If this is the start of the visible area, seed sprite shifter positions.
SpriteSet &sprite_set = sprite_sets_[active_sprite_set_ ^ 1];
if(output_column_ == first_pixel_column_) {
int c = sprite_set.active_sprite_slot;
while(c--) {
SpriteSet::ActiveSprite &sprite = sprite_set.active_sprites[c];
sprite.shift_position = -sprite.info[1];
if(sprite.info[3] & 0x80) {
sprite.shift_position += 32;
if(sprite.shift_position > 0 && !sprites_magnified_)
sprite.shift_position *= 2;
}
}
}
// Paint the background tiles.
const int pixels_left = pixels_end - output_column_;
if(screen_mode_ == ScreenMode::MultiColour) {
int pixel_location = output_column_ - first_pixel_column_;
for(int c = 0; c < pixels_left; ++c) {
pixel_target_[c] = palette[
(pattern_buffer_[(pixel_location + c) >> 3] >> (((pixel_location + c) & 4)^4)) & 15
];
}
pixel_target_ += pixels_left;
} else {
const int shift = (output_column_ - first_pixel_column_) & 7;
int byte_column = (output_column_ - first_pixel_column_) >> 3;
int length = std::min(pixels_left, 8 - shift);
int pattern = reverse_table.map[pattern_buffer_[byte_column]] >> shift;
uint8_t colour = colour_buffer_[byte_column];
uint32_t colours[2] = {
palette[(colour & 15) ? (colour & 15) : background_colour_],
palette[(colour >> 4) ? (colour >> 4) : background_colour_]
};
int background_pixels_left = pixels_left;
while(true) {
background_pixels_left -= length;
for(int c = 0; c < length; ++c) {
pixel_target_[c] = colours[pattern&0x01];
pattern >>= 1;
}
pixel_target_ += length;
if(!background_pixels_left) break;
length = std::min(8, background_pixels_left);
byte_column++;
pattern = reverse_table.map[pattern_buffer_[byte_column]];
colour = colour_buffer_[byte_column];
colours[0] = palette[(colour & 15) ? (colour & 15) : background_colour_];
colours[1] = palette[(colour >> 4) ? (colour >> 4) : background_colour_];
}
}
// Paint sprites and check for collisions.
if(sprite_set.active_sprite_slot) {
int sprite_pixels_left = pixels_left;
const int shift_advance = sprites_magnified_ ? 1 : 2;
const uint32_t sprite_colour_selection_masks[2] = {0x00000000, 0xffffffff};
const int colour_masks[16] = {0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1};
while(sprite_pixels_left--) {
uint32_t sprite_colour = pixel_base_[output_column_ - first_pixel_column_];
int sprite_mask = 0;
int c = sprite_set.active_sprite_slot;
while(c--) {
SpriteSet::ActiveSprite &sprite = sprite_set.active_sprites[c];
if(sprite.shift_position < 0) {
sprite.shift_position++;
continue;
} else if(sprite.shift_position < 32) {
int mask = sprite.image[sprite.shift_position >> 4] << ((sprite.shift_position&15) >> 1);
mask = (mask >> 7) & 1;
status_ |= (mask & sprite_mask) << StatusSpriteCollisionShift;
sprite_mask |= mask;
sprite.shift_position += shift_advance;
mask &= colour_masks[sprite.info[3]&15];
sprite_colour = (sprite_colour & sprite_colour_selection_masks[mask^1]) | (palette[sprite.info[3]&15] & sprite_colour_selection_masks[mask]);
}
}
pixel_base_[output_column_ - first_pixel_column_] = sprite_colour;
output_column_++;
}
}
output_column_ = pixels_end;
} break;
}
if(output_column_ == first_right_border_column_) {
crt_->output_data(static_cast<unsigned int>(first_right_border_column_ - first_pixel_column_) * 4, 4);
pixel_target_ = nullptr;
}
}
}
// --------------------
// Output right border.
// --------------------
if(output_column_ >= first_right_border_column_) {
output_border(column_ - output_column_);
output_column_ = column_;
}
} else if(row_ >= first_vsync_line_ && row_ < first_vsync_line_+3) {
// Vertical sync.
if(column_ == 342) {
crt_->output_sync(342 * 4);
}
} else {
// Blank.
if(!output_column_ && column_ >= 26) {
crt_->output_sync(13 * 4);
crt_->output_default_colour_burst(13 * 4);
output_column_ = 26;
}
if(output_column_ >= 26) {
output_border(column_ - output_column_);
output_column_ = column_;
}
}
// -----------------
// End video stream.
// -----------------
// -----------------------------------
// Prepare for next line, potentially.
// -----------------------------------
if(column_ == 342) {
access_pointer_ = column_ = output_column_ = 0;
row_ = (row_ + 1) % frame_lines_;
if(row_ == 192) status_ |= StatusInterrupt;
screen_mode_ = next_screen_mode_;
blank_screen_ = next_blank_screen_;
switch(screen_mode_) {
case ScreenMode::Text:
line_mode_ = LineMode::Text;
first_pixel_column_ = 69;
first_right_border_column_ = 309;
break;
default:
line_mode_ = LineMode::Character;
first_pixel_column_ = 63;
first_right_border_column_ = 319;
break;
}
if(blank_screen_ || (row_ >= 192 && row_ != frame_lines_-1)) line_mode_ = LineMode::Refresh;
}
}
}
void TMS9918Base::output_border(int cycles) {
pixel_target_ = reinterpret_cast<uint32_t *>(crt_->allocate_write_area(1));
if(pixel_target_) *pixel_target_ = palette[background_colour_];
crt_->output_level(static_cast<unsigned int>(cycles) * 4);
}
void TMS9918::set_register(int address, uint8_t value) {
// Writes to address 0 are writes to the video RAM. Store
// the value and return.
if(!(address & 1)) {
write_phase_ = false;
// Enqueue the write to occur at the next available slot.
read_ahead_buffer_ = value;
queued_access_ = MemoryAccess::Write;
return;
}
// Writes to address 1 are performed in pairs; if this is the
// low byte of a value, store it and wait for the high byte.
if(!write_phase_) {
low_write_ = value;
write_phase_ = true;
return;
}
write_phase_ = false;
if(value & 0x80) {
// This is a write to a register.
switch(value & 7) {
case 0:
next_screen_mode_ = (next_screen_mode_ & 6) | ((low_write_ & 2) >> 1);
break;
case 1:
next_blank_screen_ = !(low_write_ & 0x40);
generate_interrupts_ = !!(low_write_ & 0x20);
next_screen_mode_ = (next_screen_mode_ & 1) | ((low_write_ & 0x18) >> 2);
sprites_16x16_ = !!(low_write_ & 0x02);
sprites_magnified_ = !!(low_write_ & 0x01);
sprite_height_ = 8;
if(sprites_16x16_) sprite_height_ <<= 1;
if(sprites_magnified_) sprite_height_ <<= 1;
break;
case 2:
pattern_name_address_ = static_cast<uint16_t>((low_write_ & 0xf) << 10);
break;
case 3:
colour_table_address_ = static_cast<uint16_t>(low_write_ << 6);
break;
case 4:
pattern_generator_table_address_ = static_cast<uint16_t>((low_write_ & 0x07) << 11);
break;
case 5:
sprite_attribute_table_address_ = static_cast<uint16_t>((low_write_ & 0x7f) << 7);
break;
case 6:
sprite_generator_table_address_ = static_cast<uint16_t>((low_write_ & 0x07) << 11);
break;
case 7:
text_colour_ = low_write_ >> 4;
background_colour_ = low_write_ & 0xf;
break;
}
} else {
// This is a write to the RAM pointer.
ram_pointer_ = static_cast<uint16_t>(low_write_ | (value << 8));
if(!(value & 0x40)) {
// Officially a 'read' set, so perform lookahead.
queued_access_ = MemoryAccess::Read;
}
}
}
uint8_t TMS9918::get_register(int address) {
write_phase_ = false;
// Reads from address 0 read video RAM, via the read-ahead buffer.
if(!(address & 1)) {
// Enqueue the write to occur at the next available slot.
uint8_t result = read_ahead_buffer_;
queued_access_ = MemoryAccess::Read;
return result;
}
// Reads from address 1 get the status register.
uint8_t result = status_;
status_ &= ~(StatusInterrupt | StatusFifthSprite | StatusSpriteCollision);
return result;
}
HalfCycles TMS9918::get_time_until_interrupt() {
if(!generate_interrupts_) return HalfCycles(-1);
if(get_interrupt_line()) return HalfCycles(0);
const int half_cycles_per_frame = frame_lines_ * 228 * 2;
int half_cycles_remaining = (192 * 228 * 2 + half_cycles_per_frame - half_cycles_into_frame_.as_int()) % half_cycles_per_frame;
return HalfCycles(half_cycles_remaining ? half_cycles_remaining : half_cycles_per_frame);
}
bool TMS9918::get_interrupt_line() {
return (status_ & StatusInterrupt) && generate_interrupts_;
}

86
Components/9918/9918.hpp Normal file
View File

@@ -0,0 +1,86 @@
//
// 9918.hpp
// Clock Signal
//
// Created by Thomas Harte on 25/11/2017.
// Copyright © 2017 Thomas Harte. All rights reserved.
//
#ifndef TMS9918_hpp
#define TMS9918_hpp
#include "../../Outputs/CRT/CRT.hpp"
#include "../../ClockReceiver/ClockReceiver.hpp"
#include "Implementation/9918Base.hpp"
#include <cstdint>
namespace TI {
/*!
Provides emulation of the TMS9918a, TMS9928 and TMS9929. Likely in the future to be the
vessel for emulation of sufficiently close derivatives, such as the Master System VDP.
The TMS9918 and descendants are video display generators that own their own RAM, making it
accessible through an implicitly-timed register interface, and (depending on model) can generate
PAL and NTSC component and composite video.
These chips have only one non-on-demand interaction with the outside world: an interrupt line.
See get_time_until_interrupt and get_interrupt_line for asynchronous operation options.
*/
class TMS9918: public TMS9918Base {
public:
enum Personality {
TMS9918A, // includes the 9928 and 9929; set TV standard and output device as desired.
};
/*!
Constructs an instance of the drive controller that behaves according to personality @c p.
@param p The type of controller to emulate.
*/
TMS9918(Personality p);
enum TVStandard {
/*! i.e. 50Hz output at around 312.5 lines/field */
PAL,
/*! i.e. 60Hz output at around 262.5 lines/field */
NTSC
};
/*! Sets the TV standard for this TMS, if that is hard-coded in hardware. */
void set_tv_standard(TVStandard standard);
/*! Provides the CRT this TMS is connected to. */
Outputs::CRT::CRT *get_crt();
/*!
Runs the VCP for the number of cycles indicate; it is an implicit assumption of the code
that the input clock rate is 3579545 Hz — the NTSC colour clock rate.
*/
void run_for(const HalfCycles cycles);
/*! Sets a register value. */
void set_register(int address, uint8_t value);
/*! Gets a register value. */
uint8_t get_register(int address);
/*!
Returns the amount of time until get_interrupt_line would next return true if
there are no interceding calls to set_register or get_register.
If get_interrupt_line is true now, returns zero. If get_interrupt_line would
never return true, returns -1.
*/
HalfCycles get_time_until_interrupt();
/*!
@returns @c true if the interrupt line is currently active; @c false otherwise.
*/
bool get_interrupt_line();
};
};
#endif /* TMS9918_hpp */

View File

@@ -0,0 +1,101 @@
//
// 9918Base.hpp
// Clock Signal
//
// Created by Thomas Harte on 14/12/2017.
// Copyright © 2017 Thomas Harte. All rights reserved.
//
#ifndef TMS9918Base_hpp
#define TMS9918Base_hpp
#include "../../../Outputs/CRT/CRT.hpp"
#include "../../../ClockReceiver/ClockReceiver.hpp"
#include <cstdint>
#include <memory>
namespace TI {
class TMS9918Base {
protected:
TMS9918Base();
std::unique_ptr<Outputs::CRT::CRT> crt_;
uint8_t ram_[16384];
uint16_t ram_pointer_ = 0;
uint8_t read_ahead_buffer_ = 0;
enum class MemoryAccess {
Read, Write, None
} queued_access_ = MemoryAccess::None;
uint8_t status_ = 0;
bool write_phase_ = false;
uint8_t low_write_ = 0;
// The various register flags.
int next_screen_mode_ = 0, screen_mode_ = 0;
bool next_blank_screen_ = true, blank_screen_ = true;
bool sprites_16x16_ = false;
bool sprites_magnified_ = false;
bool generate_interrupts_ = false;
int sprite_height_ = 8;
uint16_t pattern_name_address_ = 0;
uint16_t colour_table_address_ = 0;
uint16_t pattern_generator_table_address_ = 0;
uint16_t sprite_attribute_table_address_ = 0;
uint16_t sprite_generator_table_address_ = 0;
uint8_t text_colour_ = 0;
uint8_t background_colour_ = 0;
HalfCycles half_cycles_into_frame_;
int column_ = 0, row_ = 0, output_column_ = 0;
int cycles_error_ = 0;
uint32_t *pixel_target_ = nullptr, *pixel_base_ = nullptr;
void output_border(int cycles);
// Vertical timing details.
int frame_lines_ = 262;
int first_vsync_line_ = 227;
// Horizontal selections.
enum class LineMode {
Text = 0,
Character = 1,
Refresh = 2
} line_mode_ = LineMode::Text;
int first_pixel_column_, first_right_border_column_;
uint8_t pattern_names_[40];
uint8_t pattern_buffer_[40];
uint8_t colour_buffer_[40];
struct SpriteSet {
struct ActiveSprite {
int index = 0;
int row = 0;
uint8_t info[4];
uint8_t image[2];
int shift_position = 0;
} active_sprites[4];
int active_sprite_slot = 0;
} sprite_sets_[2];
int active_sprite_set_ = 0;
bool sprites_stopped_ = false;
int access_pointer_ = 0;
inline void test_sprite(int sprite_number, int screen_row);
inline void get_sprite_contents(int start, int cycles, int screen_row);
};
}
#endif /* TMS9918Base_hpp */

View File

@@ -8,9 +8,11 @@
#include "AY38910.hpp"
#include <cmath>
using namespace GI::AY38910;
AY38910::AY38910() {
AY38910::AY38910(Concurrency::DeferringAsyncTaskQueue &task_queue) : task_queue_(task_queue) {
// set up envelope lookup tables
for(int c = 0; c < 16; c++) {
for(int p = 0; p < 32; p++) {
@@ -54,21 +56,22 @@ AY38910::AY38910() {
}
}
set_sample_volume_range(0);
}
void AY38910::set_sample_volume_range(std::int16_t range) {
// set up volume lookup table
float max_volume = 8192;
float root_two = sqrtf(2.0f);
const float max_volume = static_cast<float>(range) / 3.0f; // As there are three channels.
const float root_two = sqrtf(2.0f);
for(int v = 0; v < 16; v++) {
volumes_[v] = static_cast<int>(max_volume / powf(root_two, static_cast<float>(v ^ 0xf)));
}
volumes_[0] = 0;
evaluate_output_volume();
}
void AY38910::set_clock_rate(double clock_rate) {
set_input_rate(static_cast<float>(clock_rate));
}
void AY38910::get_samples(unsigned int number_of_samples, int16_t *target) {
unsigned int c = 0;
void AY38910::get_samples(std::size_t number_of_samples, int16_t *target) {
std::size_t c = 0;
while((master_divider_&7) && c < number_of_samples) {
target[c] = output_volume_;
master_divider_++;
@@ -158,6 +161,11 @@ void AY38910::evaluate_output_volume() {
);
}
bool AY38910::is_zero_level() {
// Confirm that the AY is trivially at the zero level if all three volume controls are set to fixed zero.
return output_registers_[0x8] == 0 && output_registers_[0x9] == 0 && output_registers_[0xa] == 0;
}
// MARK: - Register manipulation
void AY38910::select_register(uint8_t r) {
@@ -169,7 +177,7 @@ void AY38910::set_register_value(uint8_t value) {
registers_[selected_register_] = value;
if(selected_register_ < 14) {
int selected_register = selected_register_;
enqueue([=] () {
task_queue_.defer([=] () {
uint8_t masked_value = value;
switch(selected_register) {
case 0: case 2: case 4:

View File

@@ -9,7 +9,8 @@
#ifndef AY_3_8910_hpp
#define AY_3_8910_hpp
#include "../../Outputs/Speaker.hpp"
#include "../../Outputs/Speaker/Implementation/SampleSource.hpp"
#include "../../Concurrency/AsyncTaskQueue.hpp"
namespace GI {
namespace AY38910 {
@@ -55,13 +56,10 @@ enum ControlLines {
noise generator and a volume envelope generator, which also provides two bidirectional
interface ports.
*/
class AY38910: public ::Outputs::Filter<AY38910> {
class AY38910: public ::Outputs::Speaker::SampleSource {
public:
/// Creates a new AY38910.
AY38910();
/// Sets the clock rate at which this AY38910 will be run.
void set_clock_rate(double clock_rate);
AY38910(Concurrency::DeferringAsyncTaskQueue &task_queue);
/// Sets the value the AY would read from its data lines if it were not outputting.
void set_data_input(uint8_t r);
@@ -86,9 +84,13 @@ class AY38910: public ::Outputs::Filter<AY38910> {
void set_port_handler(PortHandler *);
// to satisfy ::Outputs::Speaker (included via ::Outputs::Filter; not for public consumption
void get_samples(unsigned int number_of_samples, int16_t *target);
void get_samples(std::size_t number_of_samples, int16_t *target);
bool is_zero_level();
void set_sample_volume_range(std::int16_t range);
private:
Concurrency::DeferringAsyncTaskQueue &task_queue_;
int selected_register_ = 0;
uint8_t registers_[16];
uint8_t output_registers_[16] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};

View File

@@ -0,0 +1,115 @@
//
// KonamiSCC.cpp
// Clock Signal
//
// Created by Thomas Harte on 06/01/2018.
// Copyright © 2018 Thomas Harte. All rights reserved.
//
#include "KonamiSCC.hpp"
#include <cstring>
using namespace Konami;
SCC::SCC(Concurrency::DeferringAsyncTaskQueue &task_queue) :
task_queue_(task_queue) {}
bool SCC::is_zero_level() {
return !(channel_enable_ & 0x1f);
}
void SCC::get_samples(std::size_t number_of_samples, std::int16_t *target) {
if(is_zero_level()) {
std::memset(target, 0, sizeof(std::int16_t) * number_of_samples);
return;
}
std::size_t c = 0;
while((master_divider_&7) && c < number_of_samples) {
target[c] = transient_output_level_;
master_divider_++;
c++;
}
while(c < number_of_samples) {
for(int channel = 0; channel < 5; ++channel) {
if(channels_[channel].tone_counter) channels_[channel].tone_counter--;
else {
channels_[channel].offset = (channels_[channel].offset + 1) & 0x1f;
channels_[channel].tone_counter = channels_[channel].period;
}
}
evaluate_output_volume();
for(int ic = 0; ic < 8 && c < number_of_samples; ++ic) {
target[c] = transient_output_level_;
c++;
master_divider_++;
}
}
}
void SCC::write(uint16_t address, uint8_t value) {
address &= 0xff;
if(address < 0x80) ram_[address] = value;
task_queue_.defer([=] {
// Check for a write into waveform memory.
if(address < 0x80) {
waves_[address >> 5].samples[address & 0x1f] = value;
} else switch(address) {
default: break;
case 0x80: case 0x82: case 0x84: case 0x86: case 0x88: {
int channel = (address - 0x80) >> 1;
channels_[channel].period = (channels_[channel].period & ~0xff) | value;
} break;
case 0x81: case 0x83: case 0x85: case 0x87: case 0x89: {
int channel = (address - 0x80) >> 1;
channels_[channel].period = (channels_[channel].period & 0xff) | ((value & 0xf) << 8);
} break;
case 0x8a: case 0x8b: case 0x8c: case 0x8d: case 0x8e:
channels_[address - 0x8a].amplitude = value & 0xf;
break;
case 0x8f:
channel_enable_ = value;
break;
}
evaluate_output_volume();
});
}
void SCC::evaluate_output_volume() {
transient_output_level_ =
static_cast<int16_t>(
((
(channel_enable_ & 0x01) ? static_cast<int8_t>(waves_[0].samples[channels_[0].offset]) * channels_[0].amplitude : 0 +
(channel_enable_ & 0x02) ? static_cast<int8_t>(waves_[1].samples[channels_[1].offset]) * channels_[1].amplitude : 0 +
(channel_enable_ & 0x04) ? static_cast<int8_t>(waves_[2].samples[channels_[2].offset]) * channels_[2].amplitude : 0 +
(channel_enable_ & 0x08) ? static_cast<int8_t>(waves_[3].samples[channels_[3].offset]) * channels_[3].amplitude : 0 +
(channel_enable_ & 0x10) ? static_cast<int8_t>(waves_[3].samples[channels_[4].offset]) * channels_[4].amplitude : 0
) * master_volume_) / (255*15*5)
// Five channels, each with 8-bit samples and 4-bit volumes implies a natural range of 0 to 255*15*5.
);
}
void SCC::set_sample_volume_range(std::int16_t range) {
master_volume_ = range;
evaluate_output_volume();
}
uint8_t SCC::read(uint16_t address) {
address &= 0xff;
if(address < 0x80) {
return ram_[address];
}
return 0xff;
}

View File

@@ -0,0 +1,74 @@
//
// KonamiSCC.hpp
// Clock Signal
//
// Created by Thomas Harte on 06/01/2018.
// Copyright © 2018 Thomas Harte. All rights reserved.
//
#ifndef KonamiSCC_hpp
#define KonamiSCC_hpp
#include "../../Outputs/Speaker/Implementation/SampleSource.hpp"
#include "../../Concurrency/AsyncTaskQueue.hpp"
namespace Konami {
/*!
Provides an emulation of Konami's Sound Creative Chip ('SCC').
The SCC is a primitive wavetable synthesis chip, offering 32-sample tables,
and five channels of output. The original SCC uses the same wave for channels
four and five, the SCC+ supports different waves for the two channels.
*/
class SCC: public ::Outputs::Speaker::SampleSource {
public:
/// Creates a new SCC.
SCC(Concurrency::DeferringAsyncTaskQueue &task_queue);
/// As per ::SampleSource; provides a broadphase test for silence.
bool is_zero_level();
/// As per ::SampleSource; provides audio output.
void get_samples(std::size_t number_of_samples, std::int16_t *target);
void set_sample_volume_range(std::int16_t range);
/// Writes to the SCC.
void write(uint16_t address, uint8_t value);
/// Reads from the SCC.
uint8_t read(uint16_t address);
private:
Concurrency::DeferringAsyncTaskQueue &task_queue_;
// State from here on down is accessed ony from the audio thread.
int master_divider_ = 0;
std::int16_t master_volume_ = 0;
int16_t transient_output_level_ = 0;
struct Channel {
int period = 0;
int amplitude = 0;
int tone_counter = 0;
int offset = 0;
} channels_[5];
struct Wavetable {
std::uint8_t samples[32];
} waves_[4];
std::uint8_t channel_enable_ = 0;
std::uint8_t test_register_ = 0;
void evaluate_output_volume();
// This keeps a copy of wave memory that is accessed from the
// main emulation thread.
std::uint8_t ram_[128];
};
}
#endif /* KonamiSCC_hpp */

View File

@@ -0,0 +1,161 @@
//
// SN76489.cpp
// Clock Signal
//
// Created by Thomas Harte on 26/02/2018.
// Copyright © 2018 Thomas Harte. All rights reserved.
//
#include "SN76489.hpp"
#include <cassert>
#include <cmath>
using namespace TI;
SN76489::SN76489(Personality personality, Concurrency::DeferringAsyncTaskQueue &task_queue, int additional_divider) : task_queue_(task_queue) {
set_sample_volume_range(0);
switch(personality) {
case Personality::SN76494:
master_divider_period_ = 2;
shifter_is_16bit_ = false;
break;
case Personality::SN76489:
master_divider_period_ = 16;
shifter_is_16bit_ = false;
break;
case Personality::SMS:
master_divider_period_ = 16;
shifter_is_16bit_ = true;
break;
}
assert((master_divider_period_ % additional_divider) == 0);
assert(additional_divider < master_divider_period_);
master_divider_period_ /= additional_divider;
}
void SN76489::set_sample_volume_range(std::int16_t range) {
// Build a volume table.
double multiplier = pow(10.0, -0.1);
double volume = static_cast<float>(range) / 4.0f; // As there are four channels.
for(int c = 0; c < 16; ++c) {
volumes_[c] = (int)round(volume);
volume *= multiplier;
}
volumes_[15] = 0;
evaluate_output_volume();
}
void SN76489::set_register(uint8_t value) {
task_queue_.defer([value, this] () {
if(value & 0x80) {
active_register_ = value;
}
const int channel = (active_register_ >> 5)&3;
if(active_register_ & 0x10) {
// latch for volume
channels_[channel].volume = value & 0xf;
evaluate_output_volume();
} else {
// latch for tone/data
if(channel < 3) {
if(value & 0x80) {
channels_[channel].divider = (channels_[channel].divider & ~0xf) | (value & 0xf);
} else {
channels_[channel].divider = static_cast<uint16_t>((channels_[channel].divider & 0xf) | ((value & 0x3f) << 4));
}
} else {
// writes to the noise register always reset the shifter
noise_shifter_ = shifter_is_16bit_ ? 0x8000 : 0x4000;
if(value & 4) {
noise_mode_ = shifter_is_16bit_ ? Noise16 : Noise15;
} else {
noise_mode_ = shifter_is_16bit_ ? Periodic16 : Periodic15;
}
channels_[3].divider = static_cast<uint16_t>(0x10 << (value & 3));
// Special case: if these bits are both set, the noise channel should track channel 2,
// which is marked with a divider of 0xffff.
if(channels_[3].divider == 0x80) channels_[3].divider = 0xffff;
}
}
});
}
bool SN76489::is_zero_level() {
return channels_[0].volume == 0xf && channels_[1].volume == 0xf && channels_[2].volume == 0xf && channels_[3].volume == 0xf;
}
void SN76489::evaluate_output_volume() {
output_volume_ = static_cast<int16_t>(
channels_[0].level * volumes_[channels_[0].volume] +
channels_[1].level * volumes_[channels_[1].volume] +
channels_[2].level * volumes_[channels_[2].volume] +
channels_[3].level * volumes_[channels_[3].volume]
);
}
void SN76489::get_samples(std::size_t number_of_samples, std::int16_t *target) {
std::size_t c = 0;
while((master_divider_& (master_divider_period_ - 1)) && c < number_of_samples) {
target[c] = output_volume_;
master_divider_++;
c++;
}
while(c < number_of_samples) {
bool did_flip = false;
#define step_channel(x, s) \
if(channels_[x].counter) channels_[x].counter--;\
else {\
channels_[x].level ^= 1;\
channels_[x].counter = channels_[x].divider;\
s;\
}
step_channel(0, /**/);
step_channel(1, /**/);
step_channel(2, did_flip = true);
#undef step_channel
if(channels_[3].divider != 0xffff) {
if(channels_[3].counter) channels_[3].counter--;
else {
did_flip = true;
channels_[3].counter = channels_[3].divider;
}
}
if(did_flip) {
channels_[3].level = noise_shifter_ & 1;
int new_bit = channels_[3].level;
switch(noise_mode_) {
default: break;
case Noise15:
new_bit ^= (noise_shifter_ >> 1);
break;
case Noise16:
new_bit ^= (noise_shifter_ >> 3);
break;
}
noise_shifter_ >>= 1;
noise_shifter_ |= (new_bit & 1) << (shifter_is_16bit_ ? 15 : 14);
}
evaluate_output_volume();
for(int ic = 0; ic < master_divider_period_ && c < number_of_samples; ++ic) {
target[c] = output_volume_;
c++;
master_divider_++;
}
}
master_divider_ &= (master_divider_period_ - 1);
}

View File

@@ -0,0 +1,68 @@
//
// SN76489.hpp
// Clock Signal
//
// Created by Thomas Harte on 26/02/2018.
// Copyright © 2018 Thomas Harte. All rights reserved.
//
#ifndef SN76489_hpp
#define SN76489_hpp
#include "../../Outputs/Speaker/Implementation/SampleSource.hpp"
#include "../../Concurrency/AsyncTaskQueue.hpp"
namespace TI {
class SN76489: public Outputs::Speaker::SampleSource {
public:
enum class Personality {
SN76489,
SN76494,
SMS
};
/// Creates a new SN76489.
SN76489(Personality personality, Concurrency::DeferringAsyncTaskQueue &task_queue, int additional_divider = 1);
/// Writes a new value to the SN76489.
void set_register(uint8_t value);
// As per SampleSource.
void get_samples(std::size_t number_of_samples, std::int16_t *target);
bool is_zero_level();
void set_sample_volume_range(std::int16_t range);
private:
int master_divider_ = 0;
int master_divider_period_ = 16;
int16_t output_volume_ = 0;
void evaluate_output_volume();
int volumes_[16];
Concurrency::DeferringAsyncTaskQueue &task_queue_;
struct ToneChannel {
// Programmatically-set state; updated by the processor.
uint16_t divider = 0;
uint8_t volume = 0xf;
// Active state; self-evolving as a function of time.
uint16_t counter = 0;
int level = 0;
} channels_[4];
enum {
Periodic15,
Periodic16,
Noise15,
Noise16
} noise_mode_ = Periodic15;
uint16_t noise_shifter_ = 0;
int active_register_ = 0;
bool shifter_is_16bit_ = false;
};
}
#endif /* SN76489_hpp */

View File

@@ -45,6 +45,7 @@ AsyncTaskQueue::AsyncTaskQueue()
AsyncTaskQueue::~AsyncTaskQueue() {
#ifdef __APPLE__
flush();
dispatch_release(serial_dispatch_queue_);
serial_dispatch_queue_ = nullptr;
#else
@@ -79,3 +80,26 @@ void AsyncTaskQueue::flush() {
flush_condition->wait(lock);
#endif
}
DeferringAsyncTaskQueue::~DeferringAsyncTaskQueue() {
perform();
flush();
}
void DeferringAsyncTaskQueue::defer(std::function<void(void)> function) {
if(!deferred_tasks_) {
deferred_tasks_.reset(new std::list<std::function<void(void)>>);
}
deferred_tasks_->push_back(function);
}
void DeferringAsyncTaskQueue::perform() {
if(!deferred_tasks_) return;
std::shared_ptr<std::list<std::function<void(void)>>> deferred_tasks = deferred_tasks_;
deferred_tasks_.reset();
enqueue([deferred_tasks] {
for(auto &function : *deferred_tasks) {
function();
}
});
}

View File

@@ -30,7 +30,7 @@ namespace Concurrency {
class AsyncTaskQueue {
public:
AsyncTaskQueue();
~AsyncTaskQueue();
virtual ~AsyncTaskQueue();
/*!
Adds @c function to the queue.
@@ -59,6 +59,39 @@ class AsyncTaskQueue {
#endif
};
/*!
A deferring async task queue is one that accepts a list of functions to be performed but defers
any action until told to perform. It performs them by enquing a single asynchronous task that will
perform the deferred tasks in order.
It therefore offers similar semantics to an asynchronous task queue, but allows for management of
synchronisation costs, since neither defer nor perform make any effort to be thread safe.
*/
class DeferringAsyncTaskQueue: public AsyncTaskQueue {
public:
~DeferringAsyncTaskQueue();
/*!
Adds a function to the deferral list.
This is not thread safe; it should be serialised with other calls to itself and to perform.
*/
void defer(std::function<void(void)> function);
/*!
Enqueues a function that will perform all currently deferred functions, in the
order that they were deferred.
This is not thread safe; it should be serialised with other calls to itself and to defer.
*/
void perform();
private:
// TODO: this is a shared_ptr because of the issues capturing moveables in C++11;
// switch to a unique_ptr if/when adapting to C++14
std::shared_ptr<std::list<std::function<void(void)>>> deferred_tasks_;
};
}
#endif /* Concurrency_hpp */

View File

@@ -17,6 +17,11 @@ BestEffortUpdater::BestEffortUpdater() {
update_is_ongoing_.clear();
}
BestEffortUpdater::~BestEffortUpdater() {
// Don't allow further deconstruction until the task queue is stopped.
flush();
}
void BestEffortUpdater::update() {
// Perform an update only if one is not currently ongoing.
if(!update_is_ongoing_.test_and_set()) {
@@ -31,13 +36,11 @@ void BestEffortUpdater::update() {
// If the duration is valid, convert it to integer cycles, maintaining a rolling error and call the delegate
// if there is one. Proceed only if the number of cycles is positive, and cap it to the per-second maximum —
// it's possible this is an adjustable clock so be ready to swallow unexpected adjustments.
const int64_t duration = std::chrono::duration_cast<std::chrono::nanoseconds>(elapsed).count();
if(duration > 0) {
double cycles = ((static_cast<double>(duration) * clock_rate_) / 1e9) + error_;
error_ = fmod(cycles, 1.0);
const int64_t integer_duration = std::chrono::duration_cast<std::chrono::nanoseconds>(elapsed).count();
if(integer_duration > 0) {
if(delegate_) {
delegate_->update(this, static_cast<int>(std::min(cycles, clock_rate_)), has_skipped_);
const double duration = static_cast<double>(integer_duration) / 1e9;
delegate_->update(this, duration, has_skipped_);
}
has_skipped_ = false;
}
@@ -65,8 +68,3 @@ void BestEffortUpdater::set_delegate(Delegate *const delegate) {
});
}
void BestEffortUpdater::set_clock_rate(const double clock_rate) {
async_task_queue_.enqueue([this, clock_rate]() {
this->clock_rate_ = clock_rate;
});
}

View File

@@ -13,6 +13,7 @@
#include <chrono>
#include "AsyncTaskQueue.hpp"
#include "../ClockReceiver/TimeTypes.hpp"
namespace Concurrency {
@@ -26,18 +27,16 @@ namespace Concurrency {
class BestEffortUpdater {
public:
BestEffortUpdater();
~BestEffortUpdater();
/// A delegate receives timing cues.
struct Delegate {
virtual void update(BestEffortUpdater *updater, int cycles, bool did_skip_previous_update) = 0;
virtual void update(BestEffortUpdater *updater, Time::Seconds duration, bool did_skip_previous_update) = 0;
};
/// Sets the current delegate.
void set_delegate(Delegate *);
/// Sets the clock rate of the delegate.
void set_clock_rate(double clock_rate);
/*!
If the delegate is not currently in the process of an `update` call, calls it now to catch up to the current time.
The call is asynchronous; this method will return immediately.
@@ -53,11 +52,9 @@ class BestEffortUpdater {
std::chrono::time_point<std::chrono::high_resolution_clock> previous_time_point_;
bool has_previous_time_point_ = false;
double error_ = 0.0;
bool has_skipped_ = false;
Delegate *delegate_ = nullptr;
double clock_rate_ = 1.0;
};
}

View File

@@ -26,6 +26,10 @@ struct Option {
virtual ~Option() {}
Option(const std::string &long_name, const std::string &short_name) : long_name(long_name), short_name(short_name) {}
virtual bool operator==(const Option &rhs) {
return long_name == rhs.long_name && short_name == rhs.short_name;
}
};
struct BooleanOption: public Option {
@@ -35,6 +39,12 @@ struct BooleanOption: public Option {
struct ListOption: public Option {
std::vector<std::string> options;
ListOption(const std::string &long_name, const std::string &short_name, const std::vector<std::string> &options) : Option(long_name, short_name), options(options) {}
virtual bool operator==(const Option &rhs) {
const ListOption *list_rhs = dynamic_cast<const ListOption *>(&rhs);
if(!list_rhs) return false;
return long_name == rhs.long_name && short_name == rhs.short_name && options == list_rhs->options;
}
};
struct BooleanSelection;

View File

@@ -33,7 +33,13 @@ bool get_bool(const Configurable::SelectionSet &selections_by_option, const std:
std::vector<std::unique_ptr<Configurable::Option>> Configurable::standard_options(Configurable::StandardOptions mask) {
std::vector<std::unique_ptr<Configurable::Option>> options;
if(mask & QuickLoadTape) options.emplace_back(new Configurable::BooleanOption("Load Tapes Quickly", "quickload"));
if(mask & DisplayRGBComposite) options.emplace_back(new Configurable::ListOption("Display", "display", {"composite", "rgb"}));
if(mask & (DisplayRGB | DisplayComposite | DisplaySVideo)) {
std::vector<std::string> display_options;
if(mask & DisplayComposite) display_options.emplace_back("composite");
if(mask & DisplaySVideo) display_options.emplace_back("svideo");
if(mask & DisplayRGB) display_options.emplace_back("rgb");
options.emplace_back(new Configurable::ListOption("Display", "display", display_options));
}
if(mask & AutomaticTapeMotorControl) options.emplace_back(new Configurable::BooleanOption("Automatic Tape Motor Control", "autotapemotor"));
return options;
}
@@ -48,7 +54,14 @@ void Configurable::append_automatic_tape_motor_control_selection(SelectionSet &s
}
void Configurable::append_display_selection(Configurable::SelectionSet &selection_set, Display selection) {
selection_set["display"] = std::unique_ptr<Configurable::Selection>(new Configurable::ListSelection((selection == Display::RGB) ? "rgb" : "composite"));
std::string string_selection;
switch(selection) {
default:
case Display::RGB: string_selection = "rgb"; break;
case Display::SVideo: string_selection = "svideo"; break;
case Display::Composite: string_selection = "composite"; break;
}
selection_set["display"] = std::unique_ptr<Configurable::Selection>(new Configurable::ListSelection(string_selection));
}
// MARK: - Selection parsers
@@ -67,6 +80,10 @@ bool Configurable::get_display(const Configurable::SelectionSet &selections_by_o
result = Configurable::Display::RGB;
return true;
}
if(display->value == "svideo") {
result = Configurable::Display::SVideo;
return true;
}
if(display->value == "composite") {
result = Configurable::Display::Composite;
return true;

View File

@@ -14,13 +14,16 @@
namespace Configurable {
enum StandardOptions {
DisplayRGBComposite = (1 << 0),
QuickLoadTape = (1 << 1),
AutomaticTapeMotorControl = (1 << 2)
DisplayRGB = (1 << 0),
DisplaySVideo = (1 << 1),
DisplayComposite = (1 << 2),
QuickLoadTape = (1 << 3),
AutomaticTapeMotorControl = (1 << 4)
};
enum class Display {
RGB,
SVideo,
Composite
};

View File

@@ -21,18 +21,45 @@ class Joystick {
public:
virtual ~Joystick() {}
enum class DigitalInput {
Up, Down, Left, Right, Fire
struct DigitalInput {
enum Type {
Up, Down, Left, Right, Fire,
Key
} type;
union {
struct {
int index;
} control;
struct {
wchar_t symbol;
} key;
} info;
DigitalInput(Type type, int index = 0) : type(type) {
info.control.index = index;
}
DigitalInput(wchar_t symbol) : type(Key) {
info.key.symbol = symbol;
}
bool operator == (const DigitalInput &rhs) {
if(rhs.type != type) return false;
if(rhs.type == Key) {
return rhs.info.key.symbol == info.key.symbol;
} else {
return rhs.info.control.index == info.control.index;
}
}
};
virtual std::vector<DigitalInput> get_inputs() = 0;
// Host interface.
virtual void set_digital_input(DigitalInput digital_input, bool is_active) = 0;
virtual void set_digital_input(const DigitalInput &digital_input, bool is_active) = 0;
virtual void reset_all_inputs() {
set_digital_input(DigitalInput::Up, false);
set_digital_input(DigitalInput::Down, false);
set_digital_input(DigitalInput::Left, false);
set_digital_input(DigitalInput::Right, false);
set_digital_input(DigitalInput::Fire, false);
for(const auto &input: get_inputs()) {
set_digital_input(input, false);
}
}
};

View File

@@ -20,12 +20,29 @@
#include "../Utility/MemoryFuzzer.hpp"
#include "../Utility/Typer.hpp"
#include "../ConfigurationTarget.hpp"
#include "../CRTMachine.hpp"
#include "../KeyboardMachine.hpp"
#include "../../Storage/Tape/Tape.hpp"
#include "../../ClockReceiver/ForceInline.hpp"
#include "../../Outputs/Speaker/Implementation/LowpassSpeaker.hpp"
#include "../../Analyser/Static/AmstradCPC/Target.hpp"
#include <cstdint>
#include <vector>
namespace AmstradCPC {
enum ROMType: int {
OS464 = 0, BASIC464,
OS664, BASIC664,
OS6128, BASIC6128,
AMSDOS
};
/*!
Models the CPC's interrupt timer. Inputs are vsync, hsync, interrupt acknowledge and reset, and its output
is simply yes or no on whether an interupt is currently requested. Internally it uses a counter with a period
@@ -105,14 +122,12 @@ class InterruptTimer {
class AYDeferrer {
public:
/// Constructs a new AY instance and sets its clock rate.
inline void setup_output() {
ay_.reset(new GI::AY38910::AY38910);
ay_->set_input_rate(1000000);
AYDeferrer() : ay_(audio_queue_), speaker_(ay_) {
speaker_.set_input_rate(1000000);
}
/// Destructs the AY.
inline void close_output() {
ay_.reset();
~AYDeferrer() {
audio_queue_.flush();
}
/// Adds @c half_cycles half cycles to the amount of time that has passed.
@@ -122,26 +137,28 @@ class AYDeferrer {
/// Enqueues an update-to-now into the AY's deferred queue.
inline void update() {
ay_->run_for(cycles_since_update_.divide_cycles(Cycles(4)));
speaker_.run_for(audio_queue_, cycles_since_update_.divide_cycles(Cycles(4)));
}
/// Issues a request to the AY to perform all processing up to the current time.
inline void flush() {
ay_->flush();
audio_queue_.perform();
}
/// @returns the speaker the AY is using for output.
std::shared_ptr<Outputs::Speaker> get_speaker() {
return ay_;
Outputs::Speaker::Speaker *get_speaker() {
return &speaker_;
}
/// @returns the AY itself.
GI::AY38910::AY38910 *ay() {
return ay_.get();
GI::AY38910::AY38910 &ay() {
return ay_;
}
private:
std::shared_ptr<GI::AY38910::AY38910> ay_;
Concurrency::DeferringAsyncTaskQueue audio_queue_;
GI::AY38910::AY38910 ay_;
Outputs::Speaker::LowpassSpeaker<GI::AY38910::AY38910> speaker_;
HalfCycles cycles_since_update_;
};
@@ -300,7 +317,7 @@ class CRTCBusHandler {
"return vec3(float((sample >> 4) & 3u), float((sample >> 2) & 3u), float(sample & 3u)) / 2.0;"
"}");
crt_->set_visible_area(Outputs::CRT::Rect(0.075f, 0.05f, 0.9f, 0.9f));
crt_->set_output_device(Outputs::CRT::OutputDevice::Monitor);
crt_->set_video_signal(Outputs::CRT::VideoSignal::RGB);
}
/// Destructs the CRT.
@@ -309,8 +326,8 @@ class CRTCBusHandler {
}
/// @returns the CRT.
std::shared_ptr<Outputs::CRT::CRT> get_crt() {
return crt_;
Outputs::CRT::CRT *get_crt() {
return crt_.get();
}
/*!
@@ -493,7 +510,7 @@ class CRTCBusHandler {
bool was_enabled_ = false, was_sync_ = false, was_hsync_ = false, was_vsync_ = false;
int cycles_into_hsync_ = 0;
std::shared_ptr<Outputs::CRT::CRT> crt_;
std::unique_ptr<Outputs::CRT::CRT> crt_;
uint8_t *pixel_data_ = nullptr, *pixel_pointer_ = nullptr;
uint8_t *ram_ = nullptr;
@@ -613,7 +630,7 @@ class i8255PortHandler : public Intel::i8255::PortHandler {
case 0:
// Port A is connected to the AY's data bus.
ay_.update();
ay_.ay()->set_data_input(value);
ay_.ay().set_data_input(value);
break;
case 1:
// Port B is an input only. So output goes nowehere.
@@ -629,7 +646,7 @@ class i8255PortHandler : public Intel::i8255::PortHandler {
tape_player_.set_tape_output((value & 0x20) ? true : false);
// Bits 6 and 7 set BDIR and BC1 for the AY.
ay_.ay()->set_control_lines(
ay_.ay().set_control_lines(
(GI::AY38910::ControlLines)(
((value & 0x80) ? GI::AY38910::BDIR : 0) |
((value & 0x40) ? GI::AY38910::BC1 : 0) |
@@ -642,7 +659,7 @@ class i8255PortHandler : public Intel::i8255::PortHandler {
/// The i8255 will call this to obtain a new input for @c port.
uint8_t get_value(int port) {
switch(port) {
case 0: return ay_.ay()->get_data_output(); // Port A is wired to the AY
case 0: return ay_.ay().get_data_output(); // Port A is wired to the AY
case 1: return
(crtc_.get_bus_state().vsync ? 0x01 : 0x00) | // Bit 0 returns CRTC vsync.
(tape_player_.get_input() ? 0x80 : 0x00) | // Bit 7 returns cassette input.
@@ -667,6 +684,9 @@ class i8255PortHandler : public Intel::i8255::PortHandler {
The actual Amstrad CPC implementation; tying the 8255, 6845 and AY to the Z80.
*/
class ConcreteMachine:
public CRTMachine::Machine,
public ConfigurationTarget::Machine,
public KeyboardMachine::Machine,
public Utility::TypeRecipient,
public CPU::Z80::BusHandler,
public Sleeper::SleepObserver,
@@ -693,6 +713,8 @@ class ConcreteMachine:
tape_player_.set_sleep_observer(this);
tape_player_is_sleeping_ = tape_player_.is_sleeping();
ay_.ay().set_port_handler(&key_state_);
}
/// The entry point for performing a partial Z80 machine cycle.
@@ -835,23 +857,20 @@ class ConcreteMachine:
/// A CRTMachine function; indicates that outputs should be created now.
void setup_output(float aspect_ratio) override final {
crtc_bus_handler_.setup_output(aspect_ratio);
ay_.setup_output();
ay_.ay()->set_port_handler(&key_state_);
}
/// A CRTMachine function; indicates that outputs should be destroyed now.
void close_output() override final {
crtc_bus_handler_.close_output();
ay_.close_output();
}
/// @returns the CRT in use.
std::shared_ptr<Outputs::CRT::CRT> get_crt() override final {
Outputs::CRT::CRT *get_crt() override final {
return crtc_bus_handler_.get_crt();
}
/// @returns the speaker in use.
std::shared_ptr<Outputs::Speaker> get_speaker() override final {
Outputs::Speaker::Speaker *get_speaker() override final {
return ay_.get_speaker();
}
@@ -861,19 +880,21 @@ class ConcreteMachine:
}
/// The ConfigurationTarget entry point; should configure this meachine as described by @c target.
void configure_as_target(const StaticAnalyser::Target &target) override final {
switch(target.amstradcpc.model) {
case StaticAnalyser::AmstradCPCModel::CPC464:
void configure_as_target(const Analyser::Static::Target *target) override final {
auto *const cpc_target = dynamic_cast<const Analyser::Static::AmstradCPC::Target *>(target);
switch(cpc_target->model) {
case Analyser::Static::AmstradCPC::Target::Model::CPC464:
rom_model_ = ROMType::OS464;
has_128k_ = false;
has_fdc_ = false;
break;
case StaticAnalyser::AmstradCPCModel::CPC664:
case Analyser::Static::AmstradCPC::Target::Model::CPC664:
rom_model_ = ROMType::OS664;
has_128k_ = false;
has_fdc_ = true;
break;
case StaticAnalyser::AmstradCPCModel::CPC6128:
case Analyser::Static::AmstradCPC::Target::Model::CPC6128:
rom_model_ = ROMType::OS6128;
has_128k_ = true;
has_fdc_ = true;
@@ -895,14 +916,14 @@ class ConcreteMachine:
read_pointers_[3] = roms_[upper_rom_].data();
// Type whatever is required.
if(target.loadingCommand.length()) {
set_typer_for_string(target.loadingCommand.c_str());
if(target->loading_command.length()) {
type_string(target->loading_command);
}
insert_media(target.media);
insert_media(target->media);
}
bool insert_media(const StaticAnalyser::Media &media) override final {
bool insert_media(const Analyser::Static::Media &media) override final {
// If there are any tapes supplied, use the first of them.
if(!media.tapes.empty()) {
tape_player_.set_tape(media.tapes.front());
@@ -919,11 +940,6 @@ class ConcreteMachine:
return !media.tapes.empty() || (!media.disks.empty() && has_fdc_);
}
// See header; provides the system ROMs.
void set_rom(ROMType type, const std::vector<uint8_t> &data) override final {
roms_[static_cast<int>(type)] = data;
}
// Obtains the system ROMs.
bool set_rom_fetcher(const std::function<std::vector<std::unique_ptr<std::vector<uint8_t>>>(const std::string &machine, const std::vector<std::string> &names)> &roms_with_names) override {
auto roms = roms_with_names(
@@ -938,7 +954,8 @@ class ConcreteMachine:
for(std::size_t index = 0; index < roms.size(); ++index) {
auto &data = roms[index];
if(!data) return false;
set_rom(static_cast<ROMType>(index), *data);
roms_[static_cast<int>(index)] = std::move(*data);
roms_[static_cast<int>(index)].resize(16384);
}
return true;
@@ -951,9 +968,9 @@ class ConcreteMachine:
// MARK: - Keyboard
void set_typer_for_string(const char *string) override final {
void type_string(const std::string &string) override final {
std::unique_ptr<CharacterMapper> mapper(new CharacterMapper());
Utility::TypeRecipient::set_typer_for_string(string, std::move(mapper));
Utility::TypeRecipient::add_typer(string, std::move(mapper));
}
HalfCycles get_typer_delay() override final {
@@ -974,8 +991,8 @@ class ConcreteMachine:
key_state_.clear_all_keys();
}
KeyboardMapper &get_keyboard_mapper() override {
return keyboard_mapper_;
KeyboardMapper *get_keyboard_mapper() override {
return &keyboard_mapper_;
}
private:

View File

@@ -9,37 +9,17 @@
#ifndef AmstradCPC_hpp
#define AmstradCPC_hpp
#include "../ConfigurationTarget.hpp"
#include "../CRTMachine.hpp"
#include "../KeyboardMachine.hpp"
#include <cstdint>
#include <vector>
namespace AmstradCPC {
enum ROMType: int {
OS464 = 0, BASIC464,
OS664, BASIC664,
OS6128, BASIC6128,
AMSDOS
};
/*!
Models an Amstrad CPC.
*/
class Machine:
public CRTMachine::Machine,
public ConfigurationTarget::Machine,
public KeyboardMachine::Machine {
class Machine {
public:
virtual ~Machine();
/// Creates and returns an Amstrad CPC.
static Machine *AmstradCPC();
/// Sets the contents of rom @c type to @c data. Assumed to be a setup step; has no effect once a machine is running.
virtual void set_rom(ROMType type, const std::vector<uint8_t> &data) = 0;
};
}

View File

@@ -11,6 +11,12 @@
#include <algorithm>
#include <cstdio>
#include "../ConfigurationTarget.hpp"
#include "../CRTMachine.hpp"
#include "../JoystickMachine.hpp"
#include "../../Analyser/Static/Atari/Target.hpp"
#include "Cartridges/Atari8k.hpp"
#include "Cartridges/Atari16k.hpp"
#include "Cartridges/Atari32k.hpp"
@@ -36,8 +42,18 @@ class Joystick: public Inputs::Joystick {
Joystick(Bus *bus, std::size_t shift, std::size_t fire_tia_input) :
bus_(bus), shift_(shift), fire_tia_input_(fire_tia_input) {}
void set_digital_input(DigitalInput digital_input, bool is_active) {
switch(digital_input) {
std::vector<DigitalInput> get_inputs() override {
return {
DigitalInput(DigitalInput::Up),
DigitalInput(DigitalInput::Down),
DigitalInput(DigitalInput::Left),
DigitalInput(DigitalInput::Right),
DigitalInput(DigitalInput::Fire)
};
}
void set_digital_input(const DigitalInput &digital_input, bool is_active) override {
switch(digital_input.type) {
case DigitalInput::Up: bus_->mos6532_.update_port_input(0, 0x10 >> shift_, is_active); break;
case DigitalInput::Down: bus_->mos6532_.update_port_input(0, 0x20 >> shift_, is_active); break;
case DigitalInput::Left: bus_->mos6532_.update_port_input(0, 0x40 >> shift_, is_active); break;
@@ -50,6 +66,8 @@ class Joystick: public Inputs::Joystick {
else
bus_->tia_input_value_[fire_tia_input_] |= 0x80;
break;
default: break;
}
}
@@ -60,11 +78,12 @@ class Joystick: public Inputs::Joystick {
class ConcreteMachine:
public Machine,
public CRTMachine::Machine,
public ConfigurationTarget::Machine,
public JoystickMachine::Machine,
public Outputs::CRT::Delegate {
public:
ConcreteMachine() :
frame_record_pointer_(0),
is_ntsc_(true) {
ConcreteMachine() {
set_clock_rate(NTSC_clock_rate);
}
@@ -72,35 +91,38 @@ class ConcreteMachine:
close_output();
}
void configure_as_target(const StaticAnalyser::Target &target) override {
const std::vector<uint8_t> &rom = target.media.cartridges.front()->get_segments().front().data;
switch(target.atari.paging_model) {
case StaticAnalyser::Atari2600PagingModel::ActivisionStack: bus_.reset(new Cartridge::Cartridge<Cartridge::ActivisionStack>(rom)); break;
case StaticAnalyser::Atari2600PagingModel::CBSRamPlus: bus_.reset(new Cartridge::Cartridge<Cartridge::CBSRAMPlus>(rom)); break;
case StaticAnalyser::Atari2600PagingModel::CommaVid: bus_.reset(new Cartridge::Cartridge<Cartridge::CommaVid>(rom)); break;
case StaticAnalyser::Atari2600PagingModel::MegaBoy: bus_.reset(new Cartridge::Cartridge<Cartridge::MegaBoy>(rom)); break;
case StaticAnalyser::Atari2600PagingModel::MNetwork: bus_.reset(new Cartridge::Cartridge<Cartridge::MNetwork>(rom)); break;
case StaticAnalyser::Atari2600PagingModel::None: bus_.reset(new Cartridge::Cartridge<Cartridge::Unpaged>(rom)); break;
case StaticAnalyser::Atari2600PagingModel::ParkerBros: bus_.reset(new Cartridge::Cartridge<Cartridge::ParkerBros>(rom)); break;
case StaticAnalyser::Atari2600PagingModel::Pitfall2: bus_.reset(new Cartridge::Cartridge<Cartridge::Pitfall2>(rom)); break;
case StaticAnalyser::Atari2600PagingModel::Tigervision: bus_.reset(new Cartridge::Cartridge<Cartridge::Tigervision>(rom)); break;
void configure_as_target(const Analyser::Static::Target *target) override {
auto *const atari_target = dynamic_cast<const Analyser::Static::Atari::Target *>(target);
const std::vector<uint8_t> &rom = target->media.cartridges.front()->get_segments().front().data;
case StaticAnalyser::Atari2600PagingModel::Atari8k:
if(target.atari.uses_superchip) {
using PagingModel = Analyser::Static::Atari::Target::PagingModel;
switch(atari_target->paging_model) {
case PagingModel::ActivisionStack: bus_.reset(new Cartridge::Cartridge<Cartridge::ActivisionStack>(rom)); break;
case PagingModel::CBSRamPlus: bus_.reset(new Cartridge::Cartridge<Cartridge::CBSRAMPlus>(rom)); break;
case PagingModel::CommaVid: bus_.reset(new Cartridge::Cartridge<Cartridge::CommaVid>(rom)); break;
case PagingModel::MegaBoy: bus_.reset(new Cartridge::Cartridge<Cartridge::MegaBoy>(rom)); break;
case PagingModel::MNetwork: bus_.reset(new Cartridge::Cartridge<Cartridge::MNetwork>(rom)); break;
case PagingModel::None: bus_.reset(new Cartridge::Cartridge<Cartridge::Unpaged>(rom)); break;
case PagingModel::ParkerBros: bus_.reset(new Cartridge::Cartridge<Cartridge::ParkerBros>(rom)); break;
case PagingModel::Pitfall2: bus_.reset(new Cartridge::Cartridge<Cartridge::Pitfall2>(rom)); break;
case PagingModel::Tigervision: bus_.reset(new Cartridge::Cartridge<Cartridge::Tigervision>(rom)); break;
case PagingModel::Atari8k:
if(atari_target->uses_superchip) {
bus_.reset(new Cartridge::Cartridge<Cartridge::Atari8kSuperChip>(rom));
} else {
bus_.reset(new Cartridge::Cartridge<Cartridge::Atari8k>(rom));
}
break;
case StaticAnalyser::Atari2600PagingModel::Atari16k:
if(target.atari.uses_superchip) {
case PagingModel::Atari16k:
if(atari_target->uses_superchip) {
bus_.reset(new Cartridge::Cartridge<Cartridge::Atari16kSuperChip>(rom));
} else {
bus_.reset(new Cartridge::Cartridge<Cartridge::Atari16k>(rom));
}
break;
case StaticAnalyser::Atari2600PagingModel::Atari32k:
if(target.atari.uses_superchip) {
case PagingModel::Atari32k:
if(atari_target->uses_superchip) {
bus_.reset(new Cartridge::Cartridge<Cartridge::Atari32kSuperChip>(rom));
} else {
bus_.reset(new Cartridge::Cartridge<Cartridge::Atari32k>(rom));
@@ -112,7 +134,7 @@ class ConcreteMachine:
joysticks_.emplace_back(new Joystick(bus_.get(), 4, 1));
}
bool insert_media(const StaticAnalyser::Media &media) override {
bool insert_media(const Analyser::Static::Media &media) override {
return false;
}
@@ -130,6 +152,18 @@ class ConcreteMachine:
}
}
bool get_switch_is_enabled(Atari2600Switch input) override {
uint8_t port_input = bus_->mos6532_.get_port_input(1);
switch(input) {
case Atari2600SwitchReset: return !!(port_input & 0x01);
case Atari2600SwitchSelect: return !!(port_input & 0x02);
case Atari2600SwitchColour: return !!(port_input & 0x08);
case Atari2600SwitchLeftPlayerDifficulty: return !!(port_input & 0x40);
case Atari2600SwitchRightPlayerDifficulty: return !!(port_input & 0x80);
default: return false;
}
}
void set_reset_switch(bool state) override {
bus_->set_reset_line(state);
}
@@ -137,8 +171,7 @@ class ConcreteMachine:
// to satisfy CRTMachine::Machine
void setup_output(float aspect_ratio) override {
bus_->tia_.reset(new TIA);
bus_->speaker_.reset(new Speaker);
bus_->speaker_->set_input_rate(static_cast<float>(get_clock_rate() / static_cast<double>(CPUTicksPerAudioTick)));
bus_->speaker_.set_input_rate(static_cast<float>(get_clock_rate() / static_cast<double>(CPUTicksPerAudioTick)));
bus_->tia_->get_crt()->set_delegate(this);
}
@@ -146,16 +179,17 @@ class ConcreteMachine:
bus_.reset();
}
std::shared_ptr<Outputs::CRT::CRT> get_crt() override {
Outputs::CRT::CRT *get_crt() override {
return bus_->tia_->get_crt();
}
std::shared_ptr<Outputs::Speaker> get_speaker() override {
return bus_->speaker_;
Outputs::Speaker::Speaker *get_speaker() override {
return &bus_->speaker_;
}
void run_for(const Cycles cycles) override {
bus_->run_for(cycles);
bus_->apply_confidence(confidence_counter_);
}
// to satisfy Outputs::CRT::Delegate
@@ -189,13 +223,17 @@ class ConcreteMachine:
bus_->tia_->set_output_mode(TIA::OutputMode::PAL);
}
bus_->speaker_->set_input_rate(static_cast<float>(clock_rate / static_cast<double>(CPUTicksPerAudioTick)));
bus_->speaker_->set_high_frequency_cut_off(static_cast<float>(clock_rate / (static_cast<double>(CPUTicksPerAudioTick) * 2.0)));
bus_->speaker_.set_input_rate(static_cast<float>(clock_rate / static_cast<double>(CPUTicksPerAudioTick)));
bus_->speaker_.set_high_frequency_cutoff(static_cast<float>(clock_rate / (static_cast<double>(CPUTicksPerAudioTick) * 2.0)));
set_clock_rate(clock_rate);
}
}
}
float get_confidence() override {
return confidence_counter_.get_confidence();
}
private:
// the bus
std::unique_ptr<Bus> bus_;
@@ -207,9 +245,12 @@ class ConcreteMachine:
FrameRecord() : number_of_frames(0), number_of_unexpected_vertical_syncs(0) {}
} frame_records_[4];
unsigned int frame_record_pointer_;
bool is_ntsc_;
unsigned int frame_record_pointer_ = 0;
bool is_ntsc_ = true;
std::vector<std::unique_ptr<Inputs::Joystick>> joysticks_;
// a confidence counter
Analyser::Dynamic::ConfidenceCounter confidence_counter_;
};
}

View File

@@ -9,10 +9,6 @@
#ifndef Atari2600_cpp
#define Atari2600_cpp
#include "../ConfigurationTarget.hpp"
#include "../CRTMachine.hpp"
#include "../JoystickMachine.hpp"
#include "Atari2600Inputs.h"
namespace Atari2600 {
@@ -20,10 +16,7 @@ namespace Atari2600 {
/*!
Models an Atari 2600.
*/
class Machine:
public CRTMachine::Machine,
public ConfigurationTarget::Machine,
public JoystickMachine::Machine {
class Machine {
public:
virtual ~Machine();
@@ -33,6 +26,9 @@ class Machine:
/// Sets the switch @c input to @c state.
virtual void set_switch_is_enabled(Atari2600Switch input, bool state) = 0;
/// Gets the state of switch @c input.
virtual bool get_switch_is_enabled(Atari2600Switch input) = 0;
// Presses or releases the reset button.
virtual void set_reset_switch(bool state) = 0;
};

View File

@@ -11,35 +11,45 @@
#include "Atari2600.hpp"
#include "PIA.hpp"
#include "Speaker.hpp"
#include "TIA.hpp"
#include "TIASound.hpp"
#include "../../Analyser/Dynamic/ConfidenceCounter.hpp"
#include "../../ClockReceiver/ClockReceiver.hpp"
#include "../../Outputs/Speaker/Implementation/LowpassSpeaker.hpp"
namespace Atari2600 {
class Bus {
public:
Bus() :
tia_input_value_{0xff, 0xff},
cycles_since_speaker_update_(0) {}
tia_sound_(audio_queue_),
speaker_(tia_sound_) {}
virtual ~Bus() {
audio_queue_.flush();
}
virtual void run_for(const Cycles cycles) = 0;
virtual void apply_confidence(Analyser::Dynamic::ConfidenceCounter &confidence_counter) = 0;
virtual void set_reset_line(bool state) = 0;
// the RIOT, TIA and speaker
PIA mos6532_;
std::shared_ptr<TIA> tia_;
std::shared_ptr<Speaker> speaker_;
Concurrency::DeferringAsyncTaskQueue audio_queue_;
TIASound tia_sound_;
Outputs::Speaker::LowpassSpeaker<TIASound> speaker_;
// joystick state
uint8_t tia_input_value_[2];
uint8_t tia_input_value_[2] = {0xff, 0xff};
protected:
// speaker backlog accumlation counter
Cycles cycles_since_speaker_update_;
inline void update_audio() {
speaker_->run_for(cycles_since_speaker_update_.divide(Cycles(CPUTicksPerAudioTick * 3)));
speaker_.run_for(audio_queue_, cycles_since_speaker_update_.divide(Cycles(CPUTicksPerAudioTick * 3)));
}
// video backlog accumulation counter

View File

@@ -39,7 +39,23 @@ template<class T> class Cartridge:
// consider doing something less fragile.
}
void run_for(const Cycles cycles) { m6502_.run_for(cycles); }
void run_for(const Cycles cycles) {
// Horizontal counter resets are used as a proxy for whether this really is an Atari 2600
// title. Random memory accesses are likely to trigger random counter resets.
horizontal_counter_resets_ = 0;
cycle_count_ = cycles;
m6502_.run_for(cycles);
}
/*!
Adjusts @c confidence_counter according to the results of the most recent run_for.
*/
void apply_confidence(Analyser::Dynamic::ConfidenceCounter &confidence_counter) {
if(cycle_count_.as_int() < 200) return;
if(horizontal_counter_resets_ > 10)
confidence_counter.add_miss();
}
void set_reset_line(bool state) { m6502_.set_reset_line(state); }
// to satisfy CPU::MOS6502::Processor
@@ -108,7 +124,11 @@ template<class T> class Cartridge:
case 0x01: update_video(); tia_->set_blank(*value & 0x02); break;
case 0x02: m6502_.set_ready_line(true); break;
case 0x03: update_video(); tia_->reset_horizontal_counter(); break;
case 0x03:
update_video();
tia_->reset_horizontal_counter();
horizontal_counter_resets_++;
break;
// TODO: audio will now be out of synchronisation — fix
case 0x04:
@@ -148,11 +168,11 @@ template<class T> class Cartridge:
case 0x2c: update_video(); tia_->clear_collision_flags(); break;
case 0x15:
case 0x16: update_audio(); speaker_->set_control(decodedAddress - 0x15, *value); break;
case 0x16: update_audio(); tia_sound_.set_control(decodedAddress - 0x15, *value); break;
case 0x17:
case 0x18: update_audio(); speaker_->set_divider(decodedAddress - 0x17, *value); break;
case 0x18: update_audio(); tia_sound_.set_divider(decodedAddress - 0x17, *value); break;
case 0x19:
case 0x1a: update_audio(); speaker_->set_volume(decodedAddress - 0x19, *value); break;
case 0x1a: update_audio(); tia_sound_.set_volume(decodedAddress - 0x19, *value); break;
}
}
}
@@ -180,7 +200,7 @@ template<class T> class Cartridge:
void flush() {
update_audio();
update_video();
speaker_->flush();
audio_queue_.perform();
}
protected:
@@ -189,6 +209,9 @@ template<class T> class Cartridge:
private:
T bus_extender_;
int horizontal_counter_resets_ = 0;
Cycles cycle_count_;
};
}

Some files were not shown because too many files have changed in this diff Show More