From 4f59407cd03a1dc0d4db8e84ea2cca6663f93174 Mon Sep 17 00:00:00 2001 From: dingusdev Date: Sun, 30 Aug 2020 16:14:58 -0700 Subject: [PATCH] Repair code for powermacg3 presets --- machines/machineconfig.cpp | 24 +++++++++++++++++++++++- machines/machinefactory.cpp | 2 +- machines/machinefactory.h | 3 +++ machines/machineproperties.h | 2 +- main.cpp | 12 +++--------- 5 files changed, 31 insertions(+), 12 deletions(-) diff --git a/machines/machineconfig.cpp b/machines/machineconfig.cpp index 8df5201..7832dcc 100644 --- a/machines/machineconfig.cpp +++ b/machines/machineconfig.cpp @@ -1,6 +1,9 @@ #include "machineproperties.h" #include "machinepresets.h" +#include "machinefactory.h" +#include "devices/memctrlbase.h" #include +#include #include void init_ppc_cpu_map() { @@ -139,7 +142,10 @@ void search_properties(std::string machine_str) { std::cout << "GMEM SIZE: " << std::dec << gfx_size << std::endl; } -bool establish_machine_settings(std::string machine_str, uint32_t* ram_sizes) { +bool establish_machine_presets(const char* rom_filepath, std::string machine_str, uint32_t* ram_sizes) { + ifstream rom_file; + uint32_t file_size; + init_ppc_cpu_map(); init_gpu_map(); init_machine_properties(); @@ -147,6 +153,22 @@ bool establish_machine_settings(std::string machine_str, uint32_t* ram_sizes) { //search_properties(machine_str); + rom_file.open(rom_filepath, ios::in | ios::binary); + if (rom_file.fail()) { + LOG_F(ERROR, "Cound not open the specified ROM file."); + rom_file.close(); + return false; + } + + if (file_size != 0x400000UL) { + LOG_F(ERROR, "Unxpected ROM File size. Expected size is 4 megabytes."); + rom_file.close(); + return false; + } + + load_rom(rom_file, file_size); + rom_file.close(); + if (loop_ram_check (machine_str, ram_sizes)) { return true; } diff --git a/machines/machinefactory.cpp b/machines/machinefactory.cpp index 32128c0..61934af 100644 --- a/machines/machinefactory.cpp +++ b/machines/machinefactory.cpp @@ -75,7 +75,7 @@ int create_machine_for_id(uint32_t id, uint32_t* grab_ram_size, uint32_t gfx_siz /* Read ROM file content and transfer it to the dedicated ROM region */ -void load_rom(ifstream& rom_file, uint32_t file_size) { +void load_rom(std::ifstream& rom_file, uint32_t file_size) { unsigned char* sysrom_mem = new unsigned char[file_size]; rom_file.seekg(0, ios::beg); diff --git a/machines/machinefactory.h b/machines/machinefactory.h index 9d17334..de131fe 100644 --- a/machines/machinefactory.h +++ b/machines/machinefactory.h @@ -28,6 +28,9 @@ along with this program. If not, see . #define MACHINE_FACTORY_H #include "machinebase.h" +#include + +void load_rom(std::ifstream& rom_file, uint32_t file_size); int create_machine_for_rom(const char* rom_filepath, uint32_t* grab_ram_size, uint32_t gfx_size); diff --git a/machines/machineproperties.h b/machines/machineproperties.h index 588f1c8..d703647 100644 --- a/machines/machineproperties.h +++ b/machines/machineproperties.h @@ -41,6 +41,6 @@ void init_gpu_map(); //JANKY FUNCTION TO FIX VS 2019 BUG! uint32_t get_gfx_card(std::string gfx_str); uint32_t get_cpu_type(std::string cpu_str); void search_properties(uint32_t chosen_gestalt); -bool establish_machine_settings(std::string machine_str, uint32_t* ram_sizes); +bool establish_machine_presets(const char* rom_filepath, std::string machine_str, uint32_t* ram_sizes); #endif /* MACHINE_PROPERTIES_H */ \ No newline at end of file diff --git a/main.cpp b/main.cpp index 1ee7a76..18ebae0 100644 --- a/main.cpp +++ b/main.cpp @@ -181,10 +181,10 @@ int main(int argc, char** argv) { if (machine_specified) { if (machine_name.compare("PowerMacG3") == 0) { - if (establish_machine_settings(machine_name, sys_ram_size)) { + if (establish_machine_presets(rom_file.c_str(), machine_name, sys_ram_size)) { if (create_gossamer(sys_ram_size, gfx_mem)) { goto bail; - } + } } else { LOG_F(ERROR, "Invalid Settings Specified"); return -1; @@ -199,15 +199,9 @@ int main(int argc, char** argv) { return -1; } } - else{ + else { if (create_machine_for_rom(rom_file.c_str(), sys_ram_size, gfx_mem)) { goto bail; - } else { - LOG_F( - WARNING, - "Could not create ROM, because the file %s was not found!", rom_file.c_str()); - display_help(); - return -1; } }