diff --git a/extern/hqn/hqn.cpp b/extern/hqn/hqn.cpp index fc75347..962119d 100644 --- a/extern/hqn/hqn.cpp +++ b/extern/hqn/hqn.cpp @@ -1,7 +1,6 @@ #include #include #include "hqn.h" -#include "hqn_util.h" namespace hqn { diff --git a/extern/hqn/hqn.h b/extern/hqn/hqn.h index d97cad3..32dce68 100644 --- a/extern/hqn/hqn.h +++ b/extern/hqn/hqn.h @@ -3,19 +3,11 @@ #include #include +#include #define BLIT_SIZE 65536 // Creating emulator instance -#ifdef _USE_QUICKNES - #include - typedef Nes_Emu emulator_t; -#endif - -#ifdef _USE_QUICKERNES - #include - typedef quickerNES::Emu emulator_t; -#endif namespace hqn { diff --git a/extern/hqn/hqn_gui_controller.cpp b/extern/hqn/hqn_gui_controller.cpp index 9424ebf..3a73ce3 100644 --- a/extern/hqn/hqn_gui_controller.cpp +++ b/extern/hqn/hqn_gui_controller.cpp @@ -1,5 +1,4 @@ #include "hqn_gui_controller.h" -#include "hqn_util.h" #include #include #include diff --git a/extern/hqn/hqn_util.cpp b/extern/hqn/hqn_util.cpp deleted file mode 100644 index e434122..0000000 --- a/extern/hqn/hqn_util.cpp +++ /dev/null @@ -1,95 +0,0 @@ - -#include "hqn_util.h" -#include -#include -#include - -namespace hqn -{ - - -bool fileSize(const char *filename, size_t *size) -{ - struct stat s; - if (stat(filename, &s) == 0) - { - *size = s.st_size; - return true; - } - else - { - *size = 0; - return false; - } -} - -bool load_file(const char *filename, char **data, size_t *size) -{ - char *dataRef = nullptr; - char *dataInsert; - size_t dataSize; - size_t readAmount; - FILE *fd; - - if (!fileSize(filename, &dataSize)) - { goto read_failed; } - - dataRef = new char[dataSize]; - dataInsert = dataRef; - readAmount = 0; // how many bytes we read - - fd = fopen(filename, "rb"); - if (!fd) - { goto read_failed; } - - do - { - readAmount = fread(dataInsert, 1, dataSize - (dataInsert - dataRef), fd); - dataInsert += readAmount; - } while (readAmount != 0); - fclose(fd); - - *data = dataRef; - *size = dataSize; - return true; - -// Jump here if we failed to open the file. -read_failed: - if (dataRef) - { delete[] dataRef; } - *data = nullptr; - *size = 0; - return false; -} - -bool save_file(const char *filename, const char *data, size_t size) -{ - FILE *fd = fopen(filename, "wb"); - if (!fd) - { return false; } - if (fwrite(data, 1, size, fd) != size) - { - fclose(fd); - return false; - } - fclose(fd); - return true; -} - -bool file_exists(const char *filename) -{ - struct stat s; - return stat(filename, &s) == 0; -} - - -int stricmp(char const *a, char const *b) -{ - for (;; a++, b++) { - int d = tolower(*a) - tolower(*b); - if (d != 0 || !*a) - return d; - } -} - -} diff --git a/extern/hqn/hqn_util.h b/extern/hqn/hqn_util.h deleted file mode 100644 index 2602214..0000000 --- a/extern/hqn/hqn_util.h +++ /dev/null @@ -1,38 +0,0 @@ -#ifndef __HQN_UTIL_H__ -#define __HQN_UTIL_H__ - -#include -#include - -namespace hqn -{ - -/* -Get the size of the given file in bytes and store it in size. -Returns false if the file could not be read. -*/ -bool fileSize(const char *filename, size_t *size); - -/* -Load the named file into ram. Allocates a buffer using new[]. -The caller is responsible for calling delete[] on the buffer. -*/ -bool load_file(const char *filename, char **data, size_t *size); - -/* -Save the data into the named file. -*/ -bool save_file(const char *filename, const char *data, size_t size); - -/* -Return true if the file exists and false otherwise. -*/ -bool file_exists(const char *filename); - - -/* Compare ascii strings in a case-insensitive manner. */ -int stricmp(char const *a, char const *b); - -} - -#endif /* __HQN_UTIL_H__ */ diff --git a/extern/hqn/meson.build b/extern/hqn/meson.build deleted file mode 100644 index a54331f..0000000 --- a/extern/hqn/meson.build +++ /dev/null @@ -1,17 +0,0 @@ -# Source files and include dirs for HQN - -srcDir = meson.current_source_dir() - -hqnSrc = [ - srcDir + '/src/hqn.cpp', - srcDir + '/src/hqn_gui_controller.cpp', - srcDir + '/src/hqn_surface.cpp', - srcDir + '/src/hqn_util.cpp', - srcDir + '/src/options.cpp' -] - -hqnIncludes = include_directories([ - 'src' -]) - -hqnCFlags = [ ] diff --git a/extern/hqn/options.cpp b/extern/hqn/options.cpp deleted file mode 100644 index 7fbebaa..0000000 --- a/extern/hqn/options.cpp +++ /dev/null @@ -1,158 +0,0 @@ - -#include "options.h" -#include -#include - -#define MAX_LINE 2048 - -// Remove whitespace around a string -std::string trim(const std::string &in) -{ - size_t first = in.find_first_not_of(" "); - size_t last = in.find_last_not_of(" "); - if (first == std::string::npos || last == std::string::npos) - { - return in; - } - else - { - return in.substr(first, last - first + 1); - } -} - -Options::Options() -{} - -Options::~Options() -{} - -int Options::load(const std::string &filename) -{ - FILE *fd; - char line[MAX_LINE]; - int lineno = 1; - - fd = fopen(filename.c_str(), "r"); - if (!fd) - { - return -1; - } - while (fgets(line, MAX_LINE, fd) != nullptr) - { - // split line at the = sign - std::string ln = trim(line); - size_t eqPos = ln.find("="); - if (eqPos == std::string::npos) - { - // clean up and exit - fclose(fd); - return lineno; - } - else - { - std::string key = trim(ln.substr(0, eqPos - 1)); - std::string value = trim(ln.substr(eqPos + 1)); - m_data[key] = value; - } - lineno++; - } - fclose(fd); - return 0; -} - -int Options::save(const std::string &filename) -{ - FILE *fd; - fd = fopen(filename.c_str(), "w"); - if (!fd) - { - return -1; - } - for (auto it : m_data) - { - fprintf(fd, "%s = %s\n", it.first.c_str(), it.second.c_str()); - } - fclose(fd); - return 0; -} - -int Options::getInt(const std::string &name, int def) -{ - int result; - if (!has(name)) - return def; - if (sscanf(m_data[name].c_str(), "%d", &result) != 1) - result = def; - return result; -} - -double Options::getNum(const std::string &name, double def) -{ - double result; - if (!has(name)) - return def; - if (sscanf(m_data[name].c_str(), "%lf", &result) != 1) - result = def; - return result; -} - -bool Options::getBool(const std::string &name, bool def) -{ - if (!has(name)) - return def; - // test for true/false strings - const std::string &value = m_data[name]; - if (string_icompare(value, "true") == 0) - return true; - if (string_icompare(value, "false") == 0) - return false; - // try to convert to an int and use that as a bool - size_t pos; - int asInt = std::stoi(value, &pos); - if (pos) - return (bool)asInt; - // fall back to default - return def; -} - -const std::string &Options::getString(const std::string &name, const std::string &def) -{ - if (!has(name)) - return def; - return m_data[name]; -} - -void Options::set(const std::string &name, const std::string &value) -{ - m_data[name] = value; -} - -void Options::set(const std::string &name, double value) -{ - m_data[name] = std::to_string(value); -} - -void Options::set(const std::string &name, bool value) -{ - m_data[name] = value ? "true" : "false"; -} - -bool Options::has(const std::string &name) -{ - return m_data.find(name) != m_data.end(); -} - -int string_icompare(const std::string &a, const std::string &b) -{ - auto itA = a.begin(); - auto itB = b.begin(); - while (itA != a.end() && itB != b.end()) - { - int diff = toupper(*itA) - toupper(*itB); - if (diff) - return diff; - itA++; - itB++; - } - return 0; -} diff --git a/extern/hqn/options.h b/extern/hqn/options.h deleted file mode 100644 index 93acc57..0000000 --- a/extern/hqn/options.h +++ /dev/null @@ -1,77 +0,0 @@ -#ifndef __OPTIONS_H__ -#define __OPTIONS_H__ - -#include -#include - -/** - * Compare two strings case-insensitively. - */ -int string_icompare(const std::string& a, const std::string &b); - -/** - * Holds options provides an interface to load them - * and save them. - */ -class Options -{ -public: - Options(); - ~Options(); - - /** - * Tries to load options from the filename. - * If the file cannot be opened returns -1, - * if there is an error returns the line the error was on (starting at 1). - * Otherwise returns 0. - */ - int load(const std::string &filename); - - /** - * Save the options to the named file. - * If all goes well returns 0 otherwise returns an error code. - * - * Errors: - * -1 = failed to open file - */ - int save(const std::string &filename); - - /** - * Get a named integer or return the default value. - */ - int getInt(const std::string &name, int def=0); - - /** - * Get the option as a double. - */ - double getNum(const std::string &name, double def=0.0); - - /** - * Get the named option as a boolean or use the default value. - */ - bool getBool(const std::string &name, bool def=false); - - /** - * Get the given option as a string, or return the default value. - * @param name the name of the option to get - * @param def default value if name is not found - */ - const std::string &getString(const std::string &name, const std::string &def=""); - - /** - * Check if the option set has the given option. - */ - bool has(const std::string &name); - - /** - * Set a value in the options. - */ - void set(const std::string &name, const std::string &value); - void set(const std::string &name, double value); - void set(const std::string &name, bool value); - -private: - std::map m_data; -}; - -#endif // __OPTIONS_H__ \ No newline at end of file diff --git a/meson.build b/meson.build index 3005132..f6c4a4e 100644 --- a/meson.build +++ b/meson.build @@ -19,8 +19,6 @@ quickerNESPlayerSrc = [ 'extern/hqn/hqn.cpp', 'extern/hqn/hqn_gui_controller.cpp', 'extern/hqn/hqn_surface.cpp', - 'extern/hqn/hqn_util.cpp', - 'extern/hqn/options.cpp', ] if get_option('buildPlayer') == true diff --git a/source/quickNES/meson.build b/source/quickNES/meson.build index 039c536..6c18eda 100644 --- a/source/quickNES/meson.build +++ b/source/quickNES/meson.build @@ -71,7 +71,7 @@ quickNESSrc = [ # quickNES Core Configuration quickNESDependency = declare_dependency( - compile_args : [ '-D_USE_QUICKNES' ], + compile_args : [ ], include_directories : include_directories(['.', 'core/nes_emu']), sources : [ quickNESSrc ] ) diff --git a/source/quickerNES/meson.build b/source/quickerNES/meson.build index f939322..8e411f7 100644 --- a/source/quickerNES/meson.build +++ b/source/quickerNES/meson.build @@ -31,7 +31,7 @@ quickerNESSrc = quickerNESAPUSrc + quickerNESPPUSrc + [ # quickerNES Core Configuration quickerNESDependency = declare_dependency( - compile_args : [ '-D_USE_QUICKERNES', '-D_PAGE_SIZE="' + pageSize.to_string() + '"'], + compile_args : [ '-D_PAGE_SIZE="' + pageSize.to_string() + '"'], include_directories : include_directories(['.', 'core']), sources : [ quickerNESSrc ] ) \ No newline at end of file diff --git a/source/utils.hpp b/source/utils.hpp index c2b75e5..fea1793 100644 --- a/source/utils.hpp +++ b/source/utils.hpp @@ -57,7 +57,7 @@ inline int getKeyPress() return getch(); } -void initializeTerminal() +inline void initializeTerminal() { // Initializing ncurses screen initscr(); @@ -67,17 +67,17 @@ void initializeTerminal() scrollok(stdscr, TRUE); } -void clearTerminal() +inline void clearTerminal() { clear(); } -void finalizeTerminal() +inline void finalizeTerminal() { endwin(); } -void refreshTerminal() +inline void refreshTerminal() { refresh(); }