59using std::make_unique;
61using std::string_view;
74 [[nodiscard]]
string help(std::span<const TclObject> tokens)
const override;
84 [[nodiscard]]
string help(std::span<const TclObject> tokens)
const override;
95 [[nodiscard]]
string help(std::span<const TclObject> tokens)
const override;
105 void execute(std::span<const TclObject> tokens,
TclObject& result)
override;
106 [[nodiscard]]
string help(std::span<const TclObject> tokens)
const override;
115 void execute(std::span<const TclObject> tokens,
TclObject& result)
override;
116 [[nodiscard]]
string help(std::span<const TclObject> tokens)
const override;
126 void execute(std::span<const TclObject> tokens,
TclObject& result)
override;
127 [[nodiscard]]
string help(std::span<const TclObject> tokens)
const override;
136 void execute(std::span<const TclObject> tokens,
TclObject& result)
override;
137 [[nodiscard]]
string help(std::span<const TclObject> tokens)
const override;
147 void execute(std::span<const TclObject> tokens,
TclObject& result)
override;
148 [[nodiscard]]
string help(std::span<const TclObject> tokens)
const override;
158 void execute(std::span<const TclObject> tokens,
TclObject& result)
override;
159 [[nodiscard]]
string help(std::span<const TclObject> tokens)
const override;
169 void execute(std::span<const TclObject> tokens,
TclObject& result)
override;
170 [[nodiscard]]
string help(std::span<const TclObject> tokens)
const override;
179 void execute(std::span<const TclObject> tokens,
TclObject& result)
override;
180 [[nodiscard]]
string help(std::span<const TclObject> tokens)
const override;
189 void execute(std::span<const TclObject> tokens,
191 [[nodiscard]]
string help(std::span<const TclObject> tokens)
const override;
194 const string configName;
201 void execute(std::span<const TclObject> tokens,
203 [[nodiscard]]
string help(std::span<const TclObject> tokens)
const override;
205 const uint64_t reference;
212 void execute(std::span<const TclObject> tokens,
214 [[nodiscard]] std::string
help(std::span<const TclObject> tokens)
const override;
224 rtScheduler = make_unique<RTScheduler>();
225 eventDistributor = make_unique<EventDistributor>(*
this);
226 globalCliComm = make_unique<GlobalCliComm>();
227 globalCommandController = make_unique<GlobalCommandController>(
228 *eventDistributor, *globalCliComm, *
this);
229 globalSettings = make_unique<GlobalSettings>(
230 *globalCommandController);
231 inputEventGenerator = make_unique<InputEventGenerator>(
232 *globalCommandController, *eventDistributor, *globalSettings);
233 symbolManager = make_unique<SymbolManager>(
234 *globalCommandController);
235 imGuiManager = make_unique<ImGuiManager>(*
this, globalCommandController->getSettingsConfig());
236 diskFactory = make_unique<DiskFactory>(
238 diskManipulator = make_unique<DiskManipulator>(
239 *globalCommandController, *
this);
240 virtualDrive = make_unique<DiskChanger>(
241 *
this,
"virtual_drive");
242 filePool = make_unique<FilePool>(*globalCommandController, *
this);
243 userSettings = make_unique<UserSettings>(
244 *globalCommandController);
245 afterCommand = make_unique<AfterCommand>(
246 *
this, *eventDistributor, *globalCommandController);
247 exitCommand = make_unique<ExitCommand>(
248 *globalCommandController, *eventDistributor);
249 messageCommand = make_unique<MessageCommand>(
250 *globalCommandController);
251 machineCommand = make_unique<MachineCommand>(
252 *globalCommandController, *
this);
253 testMachineCommand = make_unique<TestMachineCommand>(
254 *globalCommandController, *
this);
255 createMachineCommand = make_unique<CreateMachineCommand>(
256 *globalCommandController, *
this);
257 deleteMachineCommand = make_unique<DeleteMachineCommand>(
258 *globalCommandController, *
this);
259 listMachinesCommand = make_unique<ListMachinesCommand>(
260 *globalCommandController, *
this);
261 activateMachineCommand = make_unique<ActivateMachineCommand>(
262 *globalCommandController, *
this);
263 storeMachineCommand = make_unique<StoreMachineCommand>(
264 *globalCommandController, *
this);
265 restoreMachineCommand = make_unique<RestoreMachineCommand>(
266 *globalCommandController, *
this);
267 getClipboardCommand = make_unique<GetClipboardCommand>(
268 *globalCommandController, *
this);
269 setClipboardCommand = make_unique<SetClipboardCommand>(
270 *globalCommandController, *
this);
271 aviRecordCommand = make_unique<AviRecorder>(*
this);
272 extensionInfo = make_unique<ConfigInfo>(
274 machineInfo = make_unique<ConfigInfo>(
276 realTimeInfo = make_unique<RealTimeInfo>(
278 softwareInfoTopic = make_unique<SoftwareInfoTopic>(
280 tclCallbackMessages = make_unique<TclCallbackMessages>(
281 *globalCliComm, *globalCommandController);
283 createMachineSetting();
297 deleteBoard(activeBoard);
310 mixer = make_unique<Mixer>(*
this, *globalCommandController);
317 if (!softwareDatabase) {
318 softwareDatabase = make_unique<RomDatabase>(*globalCliComm);
320 return *softwareDatabase;
325 return *globalCliComm;
335 return *globalCommandController;
340 return globalCommandController->getOpenMSXInfoCommand();
345 return globalCommandController->getHotKey();
350 vector<string> result;
352 auto fileAction = [&](
const std::string& , std::string_view name) {
353 if (name.ends_with(
".xml")) {
354 name.remove_suffix(4);
355 result.emplace_back(name);
358 auto dirAction = [&](std::string& path, std::string_view name) {
359 auto size = path.size();
360 path +=
"/hardwareconfig.xml";
362 result.emplace_back(name);
381 if (
auto* ppi =
dynamic_cast<MSXPPI*
>(board->findDevice(
"ppi"))) {
382 return ppi->getKeyboard().getMsxChar2Unicode();
389 return defaultMsxChars;
393void Reactor::createMachineSetting()
397 machines.reserve(names.size() + 1);
401 machines.emplace_back(
"C-BIOS_MSX2+", 0);
403 machineSetting = make_unique<EnumSetting<int>>(
404 *globalCommandController,
"default_machine",
405 "default machine (takes effect next time openMSX is started)",
406 0, std::move(machines));
412 return activeBoard.get();
417 return activeBoard ? activeBoard->getMachineID() : string_view{};
423 it != boards.end()) {
431 return std::make_shared<MSXMotherBoard>(*
this);
439 boards.push_back(newBoard);
443 [](
auto& b) {
return b.get(); });
446 if (*it == activeBoard) {
447 switchBoard(newBoard);
457 display = make_unique<Display>(*
this);
461 display->createVideoSystem();
472 newBoard->loadMachine(machine);
473 boards.push_back(newBoard);
475 auto oldBoard = activeBoard;
476 switchBoard(newBoard);
477 deleteBoard(oldBoard);
480void Reactor::switchBoard(Board newBoard)
483 assert(!newBoard ||
contains(boards, newBoard));
484 assert(!activeBoard ||
contains(boards, activeBoard));
486 activeBoard->activate(
false);
492 std::scoped_lock lock(mbMutex);
493 activeBoard = newBoard;
495 eventDistributor->distributeEvent(MachineLoadedEvent());
498 activeBoard->activate(
true);
502void Reactor::deleteBoard(Board board)
512 if (board == activeBoard) {
514 switchBoard(
nullptr);
526 activeBoard->exitCPULoopSync();
529 std::scoped_lock lock(mbMutex);
531 activeBoard->exitCPULoopAsync();
538 auto& commandController = *globalCommandController;
542 commandController.source(
559 commandController.executeCommand(cmd);
561 throw FatalError(
"Couldn't execute command: ", cmd,
562 '\n', e.getMessage());
574 tclCallbackMessages->redoPostponedCallbacks();
585 activeBoard->powerUp();
589 while (doOneIteration()) {
594bool Reactor::doOneIteration()
596 eventDistributor->deliverEvents();
597 bool blocked = (blockedCounter > 0) || !activeBoard;
601 auto copy = activeBoard;
602 blocked = !copy->execute();
611 eventDistributor->sleep(20 * 1000);
616void Reactor::unpause()
644 assert(blockedCounter >= 0);
652 auto& pauseSetting = getGlobalSettings().getPauseSetting();
653 if (&
setting == &pauseSetting) {
654 if (pauseSetting.getBoolean()) {
663int Reactor::signalEvent(
const Event& event)
666 [&](
const QuitEvent& ) {
670 [&](
const WindowEvent&
e) {
673 if (
e.isMainWindow()) {
683 if (
e.getSdlWindowEvent().type == SDL_WINDOWEVENT_FOCUS_GAINED) {
685 }
else if (
e.getSdlWindowEvent().type == SDL_WINDOWEVENT_FOCUS_LOST) {
691 [](
const EventBase ) {
703 :
Command(commandController_,
"exit")
704 , distributor(distributor_)
711 switch (tokens.size()) {
724 return "Use this command to stop the emulator.\n"
725 "Optionally you can pass an exit-code.\n";
733 :
Command(commandController_,
"machine")
741 switch (tokens.size()) {
760 return "Switch to a different MSX machine.";
773 :
Command(commandController_,
"test_machine")
786 result = e.getMessage();
792 return "Test the configuration for the given machine. "
793 "Returns an error message explaining why the configuration is "
794 "invalid or an empty string in case of success.";
807 :
Command(commandController_,
"create_machine")
816 result = newBoard->getMachineID();
817 reactor.boards.push_back(std::move(newBoard));
822 return "Creates a new (empty) MSX machine. Returns the ID for the new "
824 "Use 'load_machine' to actually load a machine configuration "
825 "into this new machine.\n"
826 "The main reason create_machine and load_machine are two "
827 "separate commands is that sometimes you already want to know "
828 "the ID of the machine before load_machine starts emitting "
829 "events for this machine.";
837 :
Command(commandController_,
"delete_machine")
846 reactor.deleteBoard(reactor.
getMachine(tokens[1].getString()));
851 return "Deletes the given MSX machine.";
864 :
Command(commandController_,
"list_machines")
877 return "Returns a list of all machine IDs.";
885 :
Command(commandController_,
"activate_machine")
894 switch (tokens.size()) {
898 reactor.switchBoard(reactor.
getMachine(tokens[1].getString()));
906 return "Make another machine the active msx machine.\n"
907 "Or when invoked without arguments, query the ID of the "
908 "active msx machine.";
921 :
Command(commandController_,
"store_machine")
929 const auto& machineID = tokens[1].getString();
930 const auto& filename = tokens[2].getString();
943 "store_machine machineID <filename> Save state of machine \"machineID\" to indicated file\n"
945 "This is a low-level command, the 'savestate' script is easier to use.";
958 :
Command(commandController_,
"restore_machine")
984 newBoard->getStateChangeDistributor().stopReplay(newBoard->getCurrentTime());
986 result = newBoard->getMachineID();
987 reactor.boards.push_back(std::move(newBoard));
992 return "restore_machine Load state from last saved state in default directory\n"
993 "restore_machine <filename> Load state from indicated file\n"
995 "This is a low-level command, the 'loadstate' script is easier to use.";
1008 :
Command(commandController_,
"get_clipboard_text")
1023 return "Returns the (text) content of the clipboard as a string.";
1031 :
Command(commandController_,
"set_clipboard_text")
1044 return "Send the given string to the clipboard.";
1051 const string& configName_)
1052 :
InfoTopic(openMSXInfoCommand, configName_)
1053 , configName(configName_)
1060 switch (tokens.size()) {
1067 std::array<char, 8192> allocBuffer;
1068 XMLDocument doc{allocBuffer.data(),
sizeof(allocBuffer)};
1070 doc, configName, tokens[2].getString());
1071 if (
const auto* info = doc.getRoot()->findChild(
"info")) {
1072 for (
const auto& c : info->getChildren()) {
1078 "Couldn't get config info: ", e.getMessage());
1089 return strCat(
"Shows a list of available ", configName,
", "
1090 "or get meta information about the selected item.\n");
1102 :
InfoTopic(openMSXInfoCommand,
"realtime")
1103 , reference(Timer::getTime())
1111 result = narrow_cast<double>(delta) * (1.0 / 1000000.0);
1116 return "Returns the time in seconds since openMSX was started.";
1123 :
InfoTopic(openMSXInfoCommand,
"software")
1129 std::span<const TclObject> tokens,
TclObject& result)
const
1131 if (tokens.size() != 3) {
1135 Sha1Sum sha1sum(tokens[2].getString());
1137 const RomInfo* romInfo = romDatabase.fetchRomInfo(sha1sum);
1141 "Software with sha1sum ", sha1sum.
toString(),
" not found");
1144 const char* bufStart = romDatabase.getBufferStart();
1146 "year", romInfo->
getYear(bufStart),
1158 return "Returns information about the software "
1159 "given its sha1sum, in a paired list.";
void execute(std::span< const TclObject > tokens, TclObject &result) override
Execute this command.
string help(std::span< const TclObject > tokens) const override
Print help for this command.
ActivateMachineCommand(CommandController &commandController, Reactor &reactor)
void tabCompletion(vector< string > &tokens) const override
Attempt tab completion for this command.
Interpreter & getInterpreter() const final
const auto & getStartupScripts() const
ParseStatus getParseStatus() const
const auto & getStartupCommands() const
static void completeFileName(std::vector< std::string > &tokens, const FileContext &context, const RANGE &extra)
static void completeString(std::vector< std::string > &tokens, ITER begin, ITER end, bool caseSensitive=true)
void checkNumArgs(std::span< const TclObject > tokens, unsigned exactly, const char *errMessage) const
void tabCompletion(vector< string > &tokens) const override
Attempt tab completion for this command.
string help(std::span< const TclObject > tokens) const override
Print help for this topic.
ConfigInfo(InfoCommand &openMSXInfoCommand, const string &configName)
void execute(std::span< const TclObject > tokens, TclObject &result) const override
Show info on this topic.
string help(std::span< const TclObject > tokens) const override
Print help for this command.
void execute(std::span< const TclObject > tokens, TclObject &result) override
Execute this command.
CreateMachineCommand(CommandController &commandController, Reactor &reactor)
void execute(std::span< const TclObject > tokens, TclObject &result) override
Execute this command.
void tabCompletion(vector< string > &tokens) const override
Attempt tab completion for this command.
DeleteMachineCommand(CommandController &commandController, Reactor &reactor)
string help(std::span< const TclObject > tokens) const override
Print help for this command.
VideoSystem & getVideoSystem()
void distributeEvent(Event &&event)
Schedule the given event for delivery.
string help(std::span< const TclObject > tokens) const override
Print help for this command.
ExitCommand(CommandController &commandController, EventDistributor &distributor)
void execute(std::span< const TclObject > tokens, TclObject &result) override
Execute this command.
std::span< const std::string > getPaths() const
std::string resolve(std::string_view filename) const
void execute(std::span< const TclObject > tokens, TclObject &result) override
Execute this command.
string help(std::span< const TclObject > tokens) const override
Print help for this command.
GetClipboardCommand(CommandController &commandController, Reactor &reactor)
void setAllowExternalCommands()
Interpreter & getInterpreter() override
BooleanSetting & getPauseSetting()
static void loadConfig(XMLDocument &doc, std::string_view type, std::string_view name)
void execute(std::span< const TclObject > tokens, TclObject &result) override
Execute this command.
ListMachinesCommand(CommandController &commandController, Reactor &reactor)
string help(std::span< const TclObject > tokens) const override
Print help for this command.
std::string loadMachine(const std::string &machine)
std::string_view getMachineID() const
MachineCommand(CommandController &commandController, Reactor &reactor)
void execute(std::span< const TclObject > tokens, TclObject &result) override
Execute this command.
void tabCompletion(vector< string > &tokens) const override
Attempt tab completion for this command.
string help(std::span< const TclObject > tokens) const override
Print help for this command.
void mute()
This methods (un)mute the sound.
Contains the main loop of openMSX.
GlobalSettings & getGlobalSettings()
MSXMotherBoard * getMotherBoard() const
std::shared_ptr< MSXMotherBoard > Board
CommandController & getCommandController()
GlobalCommandController & getGlobalCommandController()
InfoCommand & getOpenMSXInfoCommand()
void switchMachine(const std::string &machine)
void run(const CommandLineParser &parser)
Main loop.
GlobalCliComm & getGlobalCliComm()
Board createEmptyMotherBoard()
Interpreter & getInterpreter()
const HotKey & getHotKey() const
void replaceBoard(MSXMotherBoard &oldBoard, Board newBoard)
std::string_view getMachineID() const
const MsxChar2Unicode & getMsxChar2Unicode() const
static std::vector< std::string > getHwConfigs(std::string_view type)
RomDatabase & getSoftwareDatabase()
Board getMachine(std::string_view machineID) const
auto getMachineIDs() const
RealTimeInfo(InfoCommand &openMSXInfoCommand)
string help(std::span< const TclObject > tokens) const override
Print help for this topic.
void execute(std::span< const TclObject > tokens, TclObject &result) const override
Show info on this topic.
string help(std::span< const TclObject > tokens) const override
Print help for this command.
void tabCompletion(vector< string > &tokens) const override
Attempt tab completion for this command.
RestoreMachineCommand(CommandController &commandController, Reactor &reactor)
void execute(std::span< const TclObject > tokens, TclObject &result) override
Execute this command.
std::string_view getYear(const char *buf) const
unsigned getGenMSXid() const
std::string_view getTitle(const char *buf) const
std::string_view getCompany(const char *buf) const
std::string_view getRemark(const char *buf) const
static std::string_view romTypeToName(RomType type)
std::string_view getCountry(const char *buf) const
RomType getRomType() const
std::string_view getOrigType(const char *buf) const
void execute(std::span< const TclObject > tokens, TclObject &result) override
Execute this command.
SetClipboardCommand(CommandController &commandController, Reactor &reactor)
string help(std::span< const TclObject > tokens) const override
Print help for this command.
This class represents the result of a sha1 calculation (a 160-bit value).
std::string toString() const
std::string help(std::span< const TclObject > tokens) const override
Print help for this topic.
void execute(std::span< const TclObject > tokens, TclObject &result) const override
Show info on this topic.
SoftwareInfoTopic(InfoCommand &openMSXInfoCommand, Reactor &reactor)
void tabCompletion(vector< string > &tokens) const override
Attempt tab completion for this command.
StoreMachineCommand(CommandController &commandController, Reactor &reactor)
string help(std::span< const TclObject > tokens) const override
Print help for this command.
void execute(std::span< const TclObject > tokens, TclObject &result) override
Execute this command.
void detach(Observer< T > &observer)
void attach(Observer< T > &observer)
void addListElements(ITER first, ITER last)
void addDictKeyValue(const Key &key, const Value &value)
void addDictKeyValues(Args &&... args)
void tabCompletion(vector< string > &tokens) const override
Attempt tab completion for this command.
TestMachineCommand(CommandController &commandController, Reactor &reactor)
void execute(std::span< const TclObject > tokens, TclObject &result) override
Execute this command.
string help(std::span< const TclObject > tokens) const override
Print help for this command.
virtual void setClipboardText(zstring_view text)=0
virtual std::string getClipboardText()=0
ALWAYS_INLINE void serialize(const char *tag, const T &t, Args &&...args)
string expandTilde(string path)
Expand the '~' character to the users home directory.
bool isRegularFile(const Stat &st)
string join(string_view part1, string_view part2)
Join two paths.
bool isMainThread()
Returns true when called from the main thread.
uint64_t getTime()
Get current (real) time in us.
This file implemented 3 utility functions:
const FileContext & systemFileContext()
const FileContext & userFileContext()
std::variant< KeyUpEvent, KeyDownEvent, MouseMotionEvent, MouseButtonUpEvent, MouseButtonDownEvent, MouseWheelEvent, JoystickAxisMotionEvent, JoystickHatEvent, JoystickButtonUpEvent, JoystickButtonDownEvent, OsdControlReleaseEvent, OsdControlPressEvent, WindowEvent, TextEvent, FileDropEvent, QuitEvent, FinishFrameEvent, CliCommandEvent, GroupEvent, BootEvent, FrameDrawnEvent, BreakEvent, SwitchRendererEvent, TakeReverseSnapshotEvent, AfterTimedEvent, MachineLoadedEvent, MachineActivatedEvent, MachineDeactivatedEvent, MidiInReaderEvent, MidiInWindowsEvent, MidiInCoreMidiEvent, MidiInCoreMidiVirtualEvent, MidiInALSAEvent, Rs232TesterEvent, Rs232NetEvent, ImGuiDelayedActionEvent, ImGuiActiveEvent > Event
const FileContext & preferSystemFileContext()
bool foreach_file_and_directory(std::string path, FileAction fileAction, DirAction dirAction)
auto unique(ForwardRange &&range)
auto find(InputRange &&range, const T &value)
constexpr void sort(RandomAccessRange &&range)
constexpr auto transform(Range &&range, UnaryOp op)
ITER find_unguarded(ITER first, ITER last, const VAL &val, Proj proj={})
Faster alternative to 'find' when it's guaranteed that the value will be found (if not the behavior i...
void move_pop_back(VECTOR &v, typename VECTOR::iterator it)
Erase the pointed to element from the given vector.
auto rfind_unguarded(RANGE &range, const VAL &val, Proj proj={})
Similar to the find(_if)_unguarded functions above, but searches from the back to front.
constexpr bool contains(ITER first, ITER last, const VAL &val)
Check if a range contains a given value, using linear search.
constexpr auto end(const zstring_view &x)