Merge pull request #20 from SergioMartin86/refactoring

Refactoring
This commit is contained in:
Sergio Martin 2024-01-29 19:49:03 +01:00 committed by GitHub
commit fd69e3c742
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
7 changed files with 22 additions and 16 deletions

View File

@ -5,14 +5,19 @@
#include <stdio.h> #include <stdio.h>
// If we use NCurses, we need to use the appropriate printing function // If we use NCurses, we need to use the appropriate printing function
#ifdef NCURSES #ifndef LOG
#include <ncurses.h> #ifdef NCURSES
#define LOG printw #include <ncurses.h>
#else #define LOG printw
#define LOG printf #else
#define LOG printf
#endif
#endif
#ifndef EXIT_WITH_ERROR
#define EXIT_WITH_ERROR(...) exitWithError(__FILE__, __LINE__, __VA_ARGS__)
#endif #endif
#define EXIT_WITH_ERROR(...) exitWithError(__FILE__, __LINE__, __VA_ARGS__)
inline void exitWithError [[noreturn]] (const char *fileName, const int lineNumber, const char *format, ...) inline void exitWithError [[noreturn]] (const char *fileName, const int lineNumber, const char *format, ...)
{ {
char *outstr = 0; char *outstr = 0;

View File

@ -3,10 +3,6 @@
#include "logger.hpp" #include "logger.hpp"
#include "controller.hpp" #include "controller.hpp"
#define _LOW_MEM_SIZE 0x800
#define _HIGH_MEM_SIZE 0x2000
#define _NAMETABLES_MEM_SIZE 0x1000
// Size of image generated in graphics buffer // Size of image generated in graphics buffer
static const uint16_t image_width = 256; static const uint16_t image_width = 256;
static const uint16_t image_height = 240; static const uint16_t image_height = 240;
@ -95,7 +91,8 @@ class NESInstanceBase
// Virtual functions // Virtual functions
virtual uint8_t *getLowMem() = 0; virtual uint8_t *getLowMem() const = 0;
virtual size_t getLowMemSize() const = 0;
virtual void serializeState(uint8_t *state) const = 0; virtual void serializeState(uint8_t *state) const = 0;
virtual void deserializeState(const uint8_t *state) = 0; virtual void deserializeState(const uint8_t *state) = 0;

@ -1 +1 @@
Subproject commit c41d8eff29132553e374abc15108c552b6d4a942 Subproject commit e35054dc19c94fcac9b8cfd2fbf5b33f8e1dfbde

View File

@ -23,7 +23,8 @@ class NESInstance final : public NESInstanceBase
register_mapper_70(); register_mapper_70();
} }
uint8_t *getLowMem() override { return _nes.low_mem(); }; uint8_t *getLowMem() const override { return _nes.low_mem(); };
size_t getLowMemSize() const override { return 0x800; };
void serializeState(uint8_t *state) const override void serializeState(uint8_t *state) const override
{ {

View File

@ -204,7 +204,9 @@ class Emu
{ {
low_mem_size = 0x800 low_mem_size = 0x800
}; };
uint8_t *low_mem() { return emu.low_mem; }
uint8_t *get_low_mem() const { return (uint8_t*)emu.low_mem; }
size_t get_low_mem_size() const { return low_mem_size; }
// Optional 8K memory // Optional 8K memory
enum enum

View File

@ -9,7 +9,8 @@ class NESInstance final : public NESInstanceBase
{ {
public: public:
uint8_t *getLowMem() override { return _nes.low_mem(); }; uint8_t *getLowMem() const override { return _nes.get_low_mem(); };
size_t getLowMemSize() const override { return _nes.get_low_mem_size(); };
void serializeState(uint8_t *state) const override { _nes.serializeState(state); } void serializeState(uint8_t *state) const override { _nes.serializeState(state); }
void deserializeState(const uint8_t *state) override { _nes.deserializeState(state); } void deserializeState(const uint8_t *state) override { _nes.deserializeState(state); }

View File

@ -169,5 +169,5 @@ inline hash_t calculateMetroHash(uint8_t *data, size_t size)
inline hash_t calculateStateHash(NESInstance* nes) inline hash_t calculateStateHash(NESInstance* nes)
{ {
return calculateMetroHash(nes->getLowMem(), _LOW_MEM_SIZE); return calculateMetroHash(nes->getLowMem(), nes->getLowMemSize());
} }