11#include " CDI.hpp"
22#include " boards/Mono3/Mono3.hpp"
3+ #include " boards/Mono3SoftCDI/Mono3SoftCDI.hpp"
34#include " boards/SoftCDI/SoftCDI.hpp"
45
56/* * \brief Creates a new CD-i instance.
67 * \param board The type of board to use.
8+ * \param useSoftCDI false to use the regular LLE emulator, true to use some SoftCDI modules.
79 * \param systemBios System BIOS data.
810 * \param nvram The initial state of the NVRAM, or an empty span to use a clean NVRAM.
911 * \param config The player configuration.
1820 *
1921 * User needs to ensure the NVRAM data size corresponds to the NVRAM size in the config (or auto-detected).
2022 */
21- std::unique_ptr<CDI> CDI::NewCDI (Boards board, std::span<const uint8_t > systemBios, std::span<const uint8_t > nvram, CDIConfig config, Callbacks callbacks, CDIDisc disc)
23+ std::unique_ptr<CDI> CDI::NewCDI (Boards board, bool useSoftCDI, std::span<const uint8_t > systemBios, std::span<const uint8_t > nvram, CDIConfig config, Callbacks callbacks, CDIDisc disc)
2224{
2325 const OS9::BIOS bios (systemBios);
2426
@@ -31,13 +33,22 @@ std::unique_ptr<CDI> CDI::NewCDI(Boards board, std::span<const uint8_t> systemBi
3133 switch (board)
3234 {
3335 case Boards::Mono3:
34- return NewMono3 (std::move (bios), nvram, std::move (config), std::move (callbacks), std::move (disc));
36+ if (useSoftCDI)
37+ return NewMono3SoftCDI (std::move (bios), nvram, std::move (config), std::move (callbacks), std::move (disc));
38+ else
39+ return NewMono3 (std::move (bios), nvram, std::move (config), std::move (callbacks), std::move (disc));
3540
3641 case Boards::Mono4:
37- return NewMono4 (std::move (bios), nvram, std::move (config), std::move (callbacks), std::move (disc));
42+ if (useSoftCDI)
43+ return NewMono4SoftCDI (std::move (bios), nvram, std::move (config), std::move (callbacks), std::move (disc));
44+ else
45+ return NewMono4 (std::move (bios), nvram, std::move (config), std::move (callbacks), std::move (disc));
3846
3947 case Boards::Roboco:
40- return NewRoboco (std::move (bios), nvram, std::move (config), std::move (callbacks), std::move (disc));
48+ if (useSoftCDI)
49+ return NewRobocoSoftCDI (std::move (bios), nvram, std::move (config), std::move (callbacks), std::move (disc));
50+ else
51+ return NewRoboco (std::move (bios), nvram, std::move (config), std::move (callbacks), std::move (disc));
4152
4253 case Boards::SoftCDI:
4354 return NewSoftCDI (std::move (bios), nvram, std::move (config), std::move (callbacks), std::move (disc));
@@ -55,6 +66,14 @@ std::unique_ptr<CDI> CDI::NewMono3(OS9::BIOS bios, std::span<const uint8_t> nvra
5566 return std::make_unique<Mono3>(std::move (bios), nvram, std::move (config), std::move (callbacks), std::move (disc));
5667}
5768
69+ /* * \brief Creates a new Mono3 player with SoftCDI modules.
70+ * See CDI::NewCDI for a description of the parameters.
71+ */
72+ std::unique_ptr<CDI> CDI::NewMono3SoftCDI (OS9::BIOS bios, std::span<const uint8_t > nvram, CDIConfig config, Callbacks callbacks, CDIDisc disc)
73+ {
74+ return std::make_unique<Mono3SoftCDI>(std::move (bios), nvram, std::move (config), std::move (callbacks), std::move (disc));
75+ }
76+
5877/* * \brief Creates a new Mono4 player.
5978 * See CDI::NewCDI for a description of the parameters.
6079 */
@@ -63,6 +82,14 @@ std::unique_ptr<CDI> CDI::NewMono4(OS9::BIOS bios, std::span<const uint8_t> nvra
6382 return std::make_unique<Mono3>(std::move (bios), nvram, std::move (config), std::move (callbacks), std::move (disc), " Mono-IV" );
6483}
6584
85+ /* * \brief Creates a new Mono4 player with SoftCDI modules.
86+ * See CDI::NewCDI for a description of the parameters.
87+ */
88+ std::unique_ptr<CDI> CDI::NewMono4SoftCDI (OS9::BIOS bios, std::span<const uint8_t > nvram, CDIConfig config, Callbacks callbacks, CDIDisc disc)
89+ {
90+ return std::make_unique<Mono3SoftCDI>(std::move (bios), nvram, std::move (config), std::move (callbacks), std::move (disc), " Mono-IV" );
91+ }
92+
6693/* * \brief Creates a new Roboco player.
6794 * See CDI::NewCDI for a description of the parameters.
6895 */
@@ -71,6 +98,14 @@ std::unique_ptr<CDI> CDI::NewRoboco(OS9::BIOS bios, std::span<const uint8_t> nvr
7198 return std::make_unique<Mono3>(std::move (bios), nvram, std::move (config), std::move (callbacks), std::move (disc), " Roboco" );
7299}
73100
101+ /* * \brief Creates a new Roboco player with SoftCDI modules.
102+ * See CDI::NewCDI for a description of the parameters.
103+ */
104+ std::unique_ptr<CDI> CDI::NewRobocoSoftCDI (OS9::BIOS bios, std::span<const uint8_t > nvram, CDIConfig config, Callbacks callbacks, CDIDisc disc)
105+ {
106+ return std::make_unique<Mono3SoftCDI>(std::move (bios), nvram, std::move (config), std::move (callbacks), std::move (disc), " Roboco" );
107+ }
108+
74109/* * \brief Creates a new SoftCDI player.
75110 * See CDI::NewCDI for a description of the parameters.
76111 */
@@ -173,8 +208,31 @@ CDIDisc& CDI::GetDisc() noexcept
173208 return m_disc;
174209}
175210
211+ void CDI::Scheduler (const std::stop_token stopToken)
212+ {
213+ m_isRunning = true ;
214+
215+ do
216+ {
217+ const SCC68070::InterpreterResult res = m_cpu.SingleStep (25 );
218+ const size_t cycles = res.first ;
219+
220+ const double ns = cycles * m_cpu.cycleDelay ;
221+ IncrementTime (ns);
222+ } while (!stopToken.stop_requested ());
223+
224+ m_isRunning = false ;
225+ }
226+
176227void CDI::IncrementTime (const double ns)
177228{
178229 m_slave->IncrementTime (ns);
179230 m_timekeeper->IncrementClock (ns);
180231}
232+
233+ void CDI::Reset (bool resetCPU)
234+ {
235+ if (resetCPU)
236+ m_cpu.Reset ();
237+ // TODO: reset slave and IRTC too?
238+ }
0 commit comments