diff --git a/.gitmodules b/.gitmodules index e69de29..e80bdc2 100644 --- a/.gitmodules +++ b/.gitmodules @@ -0,0 +1,3 @@ +[submodule "extern/QuickNES_Core"] + path = extern/QuickNES_Core + url = https://github.com/libretro/QuickNES_Core.git diff --git a/extern/QuickNES_Core b/extern/QuickNES_Core new file mode 160000 index 0000000..058d665 --- /dev/null +++ b/extern/QuickNES_Core @@ -0,0 +1 @@ +Subproject commit 058d66516ed3f1260b69e5b71cd454eb7e9234a3 diff --git a/extern/meson.build b/extern/meson.build new file mode 100644 index 0000000..c0a256c --- /dev/null +++ b/extern/meson.build @@ -0,0 +1,76 @@ +# quickNES Core sources + +quickNESCoreSrc = [ + 'QuickNES_Core/nes_emu/abstract_file.cpp', + 'QuickNES_Core/nes_emu/apu_state.cpp', + 'QuickNES_Core/nes_emu/Blip_Buffer.cpp', + 'QuickNES_Core/nes_emu/Effects_Buffer.cpp', + 'QuickNES_Core/nes_emu/Mapper_Fme7.cpp', + 'QuickNES_Core/nes_emu/Mapper_Mmc5.cpp', + 'QuickNES_Core/nes_emu/Mapper_Namco106.cpp', + 'QuickNES_Core/nes_emu/Mapper_Vrc6.cpp', + 'QuickNES_Core/nes_emu/misc_mappers.cpp', + 'QuickNES_Core/nes_emu/Mapper_15.cpp', + 'QuickNES_Core/nes_emu/Mapper_60.cpp', + 'QuickNES_Core/nes_emu/Multi_Buffer.cpp', + 'QuickNES_Core/nes_emu/Nes_Apu.cpp', + 'QuickNES_Core/nes_emu/Nes_Buffer.cpp', + 'QuickNES_Core/nes_emu/Nes_Cart.cpp', + 'QuickNES_Core/nes_emu/Nes_Core.cpp', + 'QuickNES_Core/nes_emu/Nes_Cpu.cpp', + 'QuickNES_Core/nes_emu/nes_data.cpp', + 'QuickNES_Core/nes_emu/Nes_Effects_Buffer.cpp', + 'QuickNES_Core/nes_emu/Nes_Emu.cpp', + 'QuickNES_Core/nes_emu/Nes_File.cpp', + 'QuickNES_Core/nes_emu/Nes_Fme7_Apu.cpp', + 'QuickNES_Core/nes_emu/Nes_Mapper.cpp', + 'QuickNES_Core/nes_emu/nes_mappers.cpp', + 'QuickNES_Core/nes_emu/Nes_Mmc1.cpp', + 'QuickNES_Core/nes_emu/Nes_Mmc3.cpp', + 'QuickNES_Core/nes_emu/Mapper_Misc.cpp', + 'QuickNES_Core/nes_emu/Mapper_Unrom512.cpp', + 'QuickNES_Core/nes_emu/Mapper_Vrc1.cpp', + 'QuickNES_Core/nes_emu/Mapper_Vrc3.cpp', + 'QuickNES_Core/nes_emu/Mapper_Vrc2_4.cpp', + 'QuickNES_Core/nes_emu/Mapper_Vrc7.cpp', + 'QuickNES_Core/nes_emu/Nes_Vrc7.cpp', + 'QuickNES_Core/nes_emu/emu2413.cpp', + 'QuickNES_Core/nes_emu/emu2413_state.cpp', + 'QuickNES_Core/nes_emu/Nes_Namco_Apu.cpp', + 'QuickNES_Core/nes_emu/Mmc24.cpp', + 'QuickNES_Core/nes_emu/Nes_Oscs.cpp', + 'QuickNES_Core/nes_emu/Nes_Ppu.cpp', + 'QuickNES_Core/nes_emu/Nes_Ppu_Impl.cpp', + 'QuickNES_Core/nes_emu/Nes_Ppu_Rendering.cpp', + 'QuickNES_Core/nes_emu/Nes_State.cpp', + 'QuickNES_Core/nes_emu/nes_util.cpp', + 'QuickNES_Core/nes_emu/Nes_Vrc6_Apu.cpp', + 'QuickNES_Core/nes_emu/Data_Reader.cpp', + 'QuickNES_Core/nes_emu/Mappers.cpp', + 'QuickNES_Core/nes_emu/Mapper_74x161x162x32.cpp', + 'QuickNES_Core/nes_emu/Mapper_180.cpp', + 'QuickNES_Core/nes_emu/Mapper_193.cpp', + 'QuickNES_Core/nes_emu/Mapper_240.cpp', + 'QuickNES_Core/nes_emu/Mapper_241.cpp', + 'QuickNES_Core/nes_emu/Mapper_244.cpp', + 'QuickNES_Core/nes_emu/Mapper_246.cpp', + 'QuickNES_Core/nes_emu/Mapper_AveNina.cpp', + 'QuickNES_Core/nes_emu/Mapper_IremG101.cpp', + 'QuickNES_Core/nes_emu/Mapper_IremTamS1.cpp', + 'QuickNES_Core/nes_emu/Mapper_JalecoJF11.cpp', + 'QuickNES_Core/nes_emu/Mapper_Namco54xx.cpp', + 'QuickNES_Core/nes_emu/Mapper_Sunsoft1.cpp', + 'QuickNES_Core/nes_emu/Mapper_Sunsoft2.cpp', + 'QuickNES_Core/nes_emu/Mapper_TaitoX1005.cpp', + 'QuickNES_Core/nes_emu/Mapper_TaitoTC0190.cpp', + 'QuickNES_Core/nes_emu/Mapper_Un1rom.cpp', + 'QuickNES_Core/nes_emu/nes_ntsc.cpp' +] + +# quickNES Core Configuration + + quickNESCoreDependency = declare_dependency( + compile_args : [ '-DUSE_ORIGINAL_QUICKNES'], + include_directories : include_directories(['QuickNES_Core/nes_emu']), + sources : [ quickNESCoreSrc ] + ) \ No newline at end of file diff --git a/meson.build b/meson.build index cddf39c..d8143f8 100644 --- a/meson.build +++ b/meson.build @@ -7,11 +7,12 @@ project('quickerNES','c','cpp', # Getting page alignment option pageSize = get_option('CPUFunctionAlignment') -# Loading source dependencies +# Loading dependencies subdir('source') +subdir('extern') # Common application flags -commonCompileArgs = [ '-Wfatal-errors', '-Wall', '-Werror', '-Wno-multichar' ] +commonCompileArgs = [ '-Wfatal-errors', '-Wall', '-Wno-multichar' ] # Building playback tool @@ -26,18 +27,27 @@ quickerNESPlayerSrc = [ executable('player', 'source/player.cpp', cpp_args : [ commonCompileArgs, '-DNCURSES' ], - dependencies : [ quickerNESApplicationDependency, dependency('sdl2'), dependency('SDL2_image') ], + dependencies : [ quickerNESCoreDependency, quickerNESApplicationDependency, dependency('sdl2'), dependency('SDL2_image') ], include_directories : include_directories(['source']), link_args : [ '-lncurses' ], sources : quickerNESPlayerSrc ) -# Building tester tool +# Building tester tool for QuickerNES -tester = executable('tester', +tester = executable('quickerNESTester', + 'source/tester.cpp', + cpp_args : [ commonCompileArgs, '-Werror' ], + dependencies : [ quickerNESCoreDependency, quickerNESApplicationDependency ], + include_directories : include_directories(['../extern/json']) +) + +# Building tester tool for the original QuickNES + +tester = executable('quickNESTester', 'source/tester.cpp', cpp_args : [ commonCompileArgs ], - dependencies : [ quickerNESApplicationDependency ], + dependencies : [ quickNESCoreDependency, quickerNESApplicationDependency ], include_directories : include_directories(['../extern/json']) ) diff --git a/source/emuInstance.hpp b/source/emuInstance.hpp index 80e5d5b..b2f5191 100644 --- a/source/emuInstance.hpp +++ b/source/emuInstance.hpp @@ -1,11 +1,16 @@ #pragma once -#include -#include +#include +#include #include #include #include "sha1/sha1.hpp" +#ifdef USE_ORIGINAL_QUICKNES + extern void register_misc_mappers(); + extern void register_extra_mappers(); +#endif + #define _LOW_MEM_SIZE 0x800 #define _HIGH_MEM_SIZE 0x2000 #define _NAMETABLES_MEM_SIZE 0x1000 @@ -26,6 +31,12 @@ class EmuInstance // Creating new emulator _nes = new Nes_Emu; + // If running the original QuickNES, register extra mappers now + #ifdef USE_ORIGINAL_QUICKNES + register_misc_mappers(); + register_extra_mappers(); + #endif + // Loading ROM std::string romData; bool status = loadStringFromFile(romData, romFilePath.c_str()); @@ -42,7 +53,7 @@ class EmuInstance // Getting state size to use _stateSize = getStateSizeImpl(); - + // Loading state file, if specified if (stateFilePath != "") loadStateFile(stateFilePath); } @@ -52,8 +63,8 @@ class EmuInstance uint8_t* getHighMem() { return _nes->high_mem();}; const uint8_t* getChrMem() { return _nes->chr_mem();}; size_t getChrMemSize() { return _nes->chr_size();}; - uint8_t* getSpriteRAM() { return _nes->spr_mem(); } - uint16_t getSpriteRAMSize() { return _nes->spr_mem_size(); } +// uint8_t* getSpriteRAM() { return _nes->spr_mem(); } +// uint16_t getSpriteRAMSize() { return _nes->spr_mem_size(); } const std::string getRomSHA1() const { return _romSHA1String; }; @@ -62,6 +73,7 @@ class EmuInstance // Loading state data std::string stateData; bool status = loadStringFromFile(stateData, stateFilePath.c_str()); + if (status == false) EXIT_WITH_ERROR("Could not find/read state file: %s\n", stateFilePath.c_str()); Mem_File_Reader stateReader(stateData.data(), (int)stateData.size()); Auto_File_Reader stateFile(stateReader); @@ -198,11 +210,20 @@ class EmuInstance inline size_t getStateSizeImpl() const { - // Using dry writer to just obtain the state size - Dry_Writer w; - Auto_File_Writer a(w); - _nes->save_state(a); - return w.size(); + #ifdef USE_ORIGINAL_QUICKNES + #define _DUMMY_SIZE 65536 + uint8_t data[_DUMMY_SIZE]; + Mem_Writer w(data, _DUMMY_SIZE); + Auto_File_Writer a(w); + _nes->save_state(a); + return w.size(); + #else + // Using dry writer to just obtain the state size + Dry_Writer w; + Auto_File_Writer a(w); + _nes->save_state(a); + return w.size(); + #endif } // Emulator instance diff --git a/source/meson.build b/source/meson.build index e80ca13..a28ef42 100644 --- a/source/meson.build +++ b/source/meson.build @@ -5,6 +5,5 @@ subdir('core') quickerNESApplicationDependency = declare_dependency( include_directories : include_directories(['.', '../extern']), - sources : [ '../extern/metrohash128/metrohash128.cpp' ], - dependencies : [ quickerNESCoreDependency ] + sources : [ '../extern/metrohash128/metrohash128.cpp' ] ) \ No newline at end of file