1
0
mirror of https://github.com/TomHarte/CLK.git synced 2024-07-02 20:30:00 +00:00

Switches full-screen command and adds user-specifiable ROM paths.

This commit is contained in:
Thomas Harte 2018-06-13 21:21:52 -04:00
parent 8d8f244bf5
commit dfd37e7dec

View File

@ -156,11 +156,11 @@ ParsedArguments parse_arguments(int argc, char *argv[]) {
std::size_t split_index = argument.find("=");
if(split_index == std::string::npos) {
arguments.selections[argument] = std::unique_ptr<Configurable::Selection>(new Configurable::BooleanSelection(true));
arguments.selections[argument] = std::make_unique<Configurable::BooleanSelection>(true);
} else {
std::string name = argument.substr(0, split_index);
std::string value = argument.substr(split_index+1, std::string::npos);
arguments.selections[name] = std::unique_ptr<Configurable::Selection>(new Configurable::ListSelection(value));
arguments.selections[name] = std::make_unique<Configurable::ListSelection>(value);
}
} else {
arguments.file_name = arg;
@ -203,7 +203,7 @@ int main(int argc, char *argv[]) {
// Print a help message if requested.
if(arguments.selections.find("help") != arguments.selections.end() || arguments.selections.find("h") != arguments.selections.end()) {
std::cout << "Usage: " << final_path_component(argv[0]) << " [file] [OPTIONS]" << std::endl;
std::cout << "Usage: " << final_path_component(argv[0]) << " [file] [OPTIONS] [--rompath={path to ROMs}]" << std::endl;
std::cout << "Use alt+enter to toggle full screen display. Use control+shift+V to paste text." << std::endl;
std::cout << "Required machine type and configuration is determined from the file. Machines with further options:" << std::endl << std::endl;
@ -251,22 +251,36 @@ int main(int argc, char *argv[]) {
// For vanilla SDL purposes, assume system ROMs can be found in one of:
//
// /usr/local/share/CLK/[system]; or
// /usr/share/CLK/[system]
// /usr/local/share/CLK/[system];
// /usr/share/CLK/[system]; or
// [user-supplied path]/[system]
std::vector<std::string> rom_names;
std::string machine_name;
ROMMachine::ROMFetcher rom_fetcher = [&rom_names, &machine_name]
ROMMachine::ROMFetcher rom_fetcher = [&rom_names, &machine_name, &arguments]
(const std::string &machine, const std::vector<std::string> &names) -> std::vector<std::unique_ptr<std::vector<uint8_t>>> {
rom_names.insert(rom_names.end(), names.begin(), names.end());
machine_name = machine;
std::vector<std::string> paths = {
"/usr/local/share/CLK/",
"/usr/share/CLK/"
};
if(arguments.selections.find("rompath") != arguments.selections.end()) {
std::string user_path = arguments.selections["rompath"]->list_selection()->value;
if(user_path.back() != '/') {
paths.push_back(user_path + "/");
} else {
paths.push_back(user_path);
}
}
std::vector<std::unique_ptr<std::vector<uint8_t>>> results;
for(const auto &name: names) {
std::string local_path = "/usr/local/share/CLK/" + machine + "/" + name;
FILE *file = std::fopen(local_path.c_str(), "rb");
if(!file) {
std::string path = "/usr/share/CLK/" + machine + "/" + name;
file = std::fopen(path.c_str(), "rb");
FILE *file = nullptr;
for(const auto &path: paths) {
std::string local_path = path + machine + "/" + name;
file = std::fopen(local_path.c_str(), "rb");
if(file) break;
}
if(!file) {
@ -434,16 +448,19 @@ int main(int argc, char *argv[]) {
}
}
// Also syphon off alt+enter (toggle full-screen).
if(event.key.keysym.sym == SDLK_RETURN && (SDL_GetModState()&KMOD_ALT)) {
// deliberate fallthrough...
case SDL_KEYUP: {
// Syphon off alt+enter (toggle full-screen) upon key up only; this was previously a key down action,
// but the SDL_KEYDOWN announcement was found to be reposted after changing graphics mode on some
// systems so key up is safer.
if(event.type == SDL_KEYUP && event.key.keysym.sym == SDLK_RETURN && (SDL_GetModState()&KMOD_ALT)) {
fullscreen_mode ^= SDL_WINDOW_FULLSCREEN_DESKTOP;
SDL_SetWindowFullscreen(window, fullscreen_mode);
SDL_ShowCursor((fullscreen_mode&SDL_WINDOW_FULLSCREEN_DESKTOP) ? SDL_DISABLE : SDL_ENABLE);
break;
}
// deliberate fallthrough...
case SDL_KEYUP: {
const bool is_pressed = event.type == SDL_KEYDOWN;
KeyboardMachine::Machine *const keyboard_machine = machine->keyboard_machine();