60using std::make_unique;
62using std::string_view;
75 [[nodiscard]]
string help(std::span<const TclObject> tokens)
const override;
85 [[nodiscard]]
string help(std::span<const TclObject> tokens)
const override;
96 [[nodiscard]]
string help(std::span<const TclObject> tokens)
const override;
106 void execute(std::span<const TclObject> tokens,
TclObject& result)
override;
107 [[nodiscard]]
string help(std::span<const TclObject> tokens)
const override;
116 void execute(std::span<const TclObject> tokens,
TclObject& result)
override;
117 [[nodiscard]]
string help(std::span<const TclObject> tokens)
const override;
127 void execute(std::span<const TclObject> tokens,
TclObject& result)
override;
128 [[nodiscard]]
string help(std::span<const TclObject> tokens)
const override;
137 void execute(std::span<const TclObject> tokens,
TclObject& result)
override;
138 [[nodiscard]]
string help(std::span<const TclObject> tokens)
const override;
148 void execute(std::span<const TclObject> tokens,
TclObject& result)
override;
149 [[nodiscard]]
string help(std::span<const TclObject> tokens)
const override;
159 void execute(std::span<const TclObject> tokens,
TclObject& result)
override;
160 [[nodiscard]]
string help(std::span<const TclObject> tokens)
const override;
170 void execute(std::span<const TclObject> tokens,
TclObject& result)
override;
171 [[nodiscard]]
string help(std::span<const TclObject> tokens)
const override;
180 void execute(std::span<const TclObject> tokens,
TclObject& result)
override;
181 [[nodiscard]]
string help(std::span<const TclObject> tokens)
const override;
190 void execute(std::span<const TclObject> tokens,
192 [[nodiscard]]
string help(std::span<const TclObject> tokens)
const override;
195 const string configName;
202 void execute(std::span<const TclObject> tokens,
204 [[nodiscard]]
string help(std::span<const TclObject> tokens)
const override;
206 const uint64_t reference;
213 void execute(std::span<const TclObject> tokens,
215 [[nodiscard]] std::string
help(std::span<const TclObject> tokens)
const override;
225 rtScheduler = make_unique<RTScheduler>();
226 eventDistributor = make_unique<EventDistributor>(*
this);
227 globalCliComm = make_unique<GlobalCliComm>();
228 globalCommandController = make_unique<GlobalCommandController>(
229 *eventDistributor, *globalCliComm, *
this);
230 globalSettings = make_unique<GlobalSettings>(
231 *globalCommandController);
232 inputEventGenerator = make_unique<InputEventGenerator>(
233 *globalCommandController, *eventDistributor, *globalSettings);
234 symbolManager = make_unique<SymbolManager>(
235 *globalCommandController);
236 imGuiManager = make_unique<ImGuiManager>(*
this);
237 diskFactory = make_unique<DiskFactory>(
239 diskManipulator = make_unique<DiskManipulator>(
240 *globalCommandController, *
this);
241 virtualDrive = make_unique<DiskChanger>(
242 *
this,
"virtual_drive");
243 filePool = make_unique<FilePool>(*globalCommandController, *
this);
244 userSettings = make_unique<UserSettings>(
245 *globalCommandController);
246 afterCommand = make_unique<AfterCommand>(
247 *
this, *eventDistributor, *globalCommandController);
248 exitCommand = make_unique<ExitCommand>(
249 *globalCommandController, *eventDistributor);
250 messageCommand = make_unique<MessageCommand>(
251 *globalCommandController);
252 machineCommand = make_unique<MachineCommand>(
253 *globalCommandController, *
this);
254 testMachineCommand = make_unique<TestMachineCommand>(
255 *globalCommandController, *
this);
256 createMachineCommand = make_unique<CreateMachineCommand>(
257 *globalCommandController, *
this);
258 deleteMachineCommand = make_unique<DeleteMachineCommand>(
259 *globalCommandController, *
this);
260 listMachinesCommand = make_unique<ListMachinesCommand>(
261 *globalCommandController, *
this);
262 activateMachineCommand = make_unique<ActivateMachineCommand>(
263 *globalCommandController, *
this);
264 storeMachineCommand = make_unique<StoreMachineCommand>(
265 *globalCommandController, *
this);
266 restoreMachineCommand = make_unique<RestoreMachineCommand>(
267 *globalCommandController, *
this);
268 getClipboardCommand = make_unique<GetClipboardCommand>(
269 *globalCommandController, *
this);
270 setClipboardCommand = make_unique<SetClipboardCommand>(
271 *globalCommandController, *
this);
272 aviRecordCommand = make_unique<AviRecorder>(*
this);
273 extensionInfo = make_unique<ConfigInfo>(
275 machineInfo = make_unique<ConfigInfo>(
277 realTimeInfo = make_unique<RealTimeInfo>(
279 softwareInfoTopic = make_unique<SoftwareInfoTopic>(
281 tclCallbackMessages = make_unique<TclCallbackMessages>(
282 *globalCliComm, *globalCommandController);
284 createMachineSetting();
298 deleteBoard(activeBoard);
311 mixer = make_unique<Mixer>(*
this, *globalCommandController);
318 if (!softwareDatabase) {
319 softwareDatabase = make_unique<RomDatabase>(*globalCliComm);
321 return *softwareDatabase;
326 return *globalCliComm;
336 return *globalCommandController;
341 return globalCommandController->getOpenMSXInfoCommand();
346 return globalCommandController->getHotKey();
351 vector<string> result;
353 auto fileAction = [&](
const std::string& , std::string_view name) {
354 if (name.ends_with(
".xml")) {
355 name.remove_suffix(4);
356 result.emplace_back(name);
359 auto dirAction = [&](std::string& path, std::string_view name) {
360 auto size = path.size();
361 path +=
"/hardwareconfig.xml";
363 result.emplace_back(name);
382 if (
MSXPPI* ppi =
dynamic_cast<MSXPPI*
>(board->findDevice(
"ppi"))) {
383 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::lock_guard<std::mutex> 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::lock_guard<std::mutex> 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")
930 string_view machineID;
931 switch (tokens.size()) {
937 machineID = tokens[1].getString();
941 machineID = tokens[1].getString();
942 filename = tokens[2].getString();
957 "store_machine Save state of current machine to file \"openmsxNNNN.xml.gz\"\n"
958 "store_machine machineID Save state of machine \"machineID\" to file \"openmsxNNNN.xml.gz\"\n"
959 "store_machine machineID <filename> Save state of machine \"machineID\" to indicated file\n"
961 "This is a low-level command, the 'savestate' script is easier to use.";
974 :
Command(commandController_,
"restore_machine")
986 switch (tokens.size()) {
994 time_t modTime = st.st_mtime;
995 if (modTime > lastTime) {
1000 if (filename.empty()) {
1024 newBoard->getStateChangeDistributor().stopReplay(newBoard->getCurrentTime());
1026 result = newBoard->getMachineID();
1027 reactor.boards.push_back(std::move(newBoard));
1032 return "restore_machine Load state from last saved state in default directory\n"
1033 "restore_machine <filename> Load state from indicated file\n"
1035 "This is a low-level command, the 'loadstate' script is easier to use.";
1049 :
Command(commandController_,
"get_clipboard_text")
1064 return "Returns the (text) content of the clipboard as a string.";
1072 :
Command(commandController_,
"set_clipboard_text")
1085 return "Send the given string to the clipboard.";
1092 const string& configName_)
1093 :
InfoTopic(openMSXInfoCommand, configName_)
1094 , configName(configName_)
1101 switch (tokens.size()) {
1108 std::array<char, 8192> allocBuffer;
1109 XMLDocument doc{allocBuffer.data(),
sizeof(allocBuffer)};
1111 doc, configName, tokens[2].getString());
1112 if (
const auto* info = doc.getRoot()->findChild(
"info")) {
1113 for (
const auto& c : info->getChildren()) {
1119 "Couldn't get config info: ", e.getMessage());
1130 return strCat(
"Shows a list of available ", configName,
", "
1131 "or get meta information about the selected item.\n");
1143 :
InfoTopic(openMSXInfoCommand,
"realtime")
1144 , reference(Timer::getTime())
1152 result = narrow_cast<double>(delta) * (1.0 / 1000000.0);
1157 return "Returns the time in seconds since openMSX was started.";
1164 :
InfoTopic(openMSXInfoCommand,
"software")
1170 std::span<const TclObject> tokens,
TclObject& result)
const
1172 if (tokens.size() != 3) {
1176 Sha1Sum sha1sum(tokens[2].getString());
1178 const RomInfo* romInfo = romDatabase.fetchRomInfo(sha1sum);
1182 "Software with sha1sum ", sha1sum.
toString(),
" not found");
1185 const char* bufStart = romDatabase.getBufferStart();
1187 "year", romInfo->
getYear(bufStart),
1199 return "Returns information about the software "
1200 "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(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.
string getNextNumberedFileName(string_view directory, string_view prefix, string_view extension, bool addSeparator)
Gets the next numbered file name with the specified prefix in the specified directory,...
bool isRegularFile(const Stat &st)
const string & getUserOpenMSXDir()
Get the openMSX dir in the user's home directory.
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
bool foreach_file(std::string path, FileAction fileAction)
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)