Skip to content

Commit 9b276f8

Browse files
Merge pull request #3 from SergioMartin86/lightStates2
Added light states: ones that do not copy certain blocks of the NES state for faster/smaller serialization
2 parents 0883f5f + a5c8d4f commit 9b276f8

File tree

123 files changed

+2463
-569
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

123 files changed

+2463
-569
lines changed

.github/workflows/make.yml

+2-1
Original file line numberDiff line numberDiff line change
@@ -26,4 +26,5 @@ jobs:
2626
- uses: actions/upload-artifact@v4
2727
with:
2828
name: meson-logs
29-
path: build/meson-logs/
29+
path: build/meson-logs/
30+

meson.build

+1-1
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ quickerNESTester = executable('quickerNESTester',
4747

4848
quickNESTester = executable('quickNESTester',
4949
'source/tester.cpp',
50-
cpp_args : [ commonCompileArgs, '-Wno-multichar', '-DDISABLE_AUTO_FILE', '-D__LIBRETRO__', '-DNDEBUG', '-DBLARGG_NONPORTABLE' ],
50+
cpp_args : [ commonCompileArgs, '-w', '-DDISABLE_AUTO_FILE', '-D__LIBRETRO__', '-DNDEBUG', '-DBLARGG_NONPORTABLE' ],
5151
dependencies : [ quickNESDependency, toolDependency ],
5252
include_directories : include_directories(['../extern/json'])
5353
)

source/emuInstance.hpp

+26-47
Original file line numberDiff line numberDiff line change
@@ -64,38 +64,14 @@ class EmuInstance
6464
std::string moveString = "|..|........|";
6565
#endif
6666

67-
if (move & 0b00010000)
68-
moveString += 'U';
69-
else
70-
moveString += '.';
71-
if (move & 0b00100000)
72-
moveString += 'D';
73-
else
74-
moveString += '.';
75-
if (move & 0b01000000)
76-
moveString += 'L';
77-
else
78-
moveString += '.';
79-
if (move & 0b10000000)
80-
moveString += 'R';
81-
else
82-
moveString += '.';
83-
if (move & 0b00001000)
84-
moveString += 'S';
85-
else
86-
moveString += '.';
87-
if (move & 0b00000100)
88-
moveString += 's';
89-
else
90-
moveString += '.';
91-
if (move & 0b00000010)
92-
moveString += 'B';
93-
else
94-
moveString += '.';
95-
if (move & 0b00000001)
96-
moveString += 'A';
97-
else
98-
moveString += '.';
67+
if (move & 0b00010000) moveString += 'U'; else moveString += '.';
68+
if (move & 0b00100000) moveString += 'D'; else moveString += '.';
69+
if (move & 0b01000000) moveString += 'L'; else moveString += '.';
70+
if (move & 0b10000000) moveString += 'R'; else moveString += '.';
71+
if (move & 0b00001000) moveString += 'S'; else moveString += '.';
72+
if (move & 0b00000100) moveString += 's'; else moveString += '.';
73+
if (move & 0b00000010) moveString += 'B'; else moveString += '.';
74+
if (move & 0b00000001) moveString += 'A'; else moveString += '.';
9975

10076
moveString += "|";
10177
return moveString;
@@ -108,18 +84,16 @@ class EmuInstance
10884
advanceStateImpl(moveStringToCode(move), 0);
10985
}
11086

111-
inline size_t getStateSize() const { return _stateSize; }
112-
inline size_t getLiteStateSize() const { return _liteStateSize; }
11387
inline std::string getRomSHA1() const { return _romSHA1String; }
11488

11589
inline hash_t getStateHash() const
11690
{
11791
MetroHash128 hash;
11892

11993
hash.Update(getLowMem(), _LOW_MEM_SIZE);
120-
hash.Update(getHighMem(), _HIGH_MEM_SIZE);
121-
hash.Update(getNametableMem(), _NAMETABLES_MEM_SIZE);
122-
hash.Update(getChrMem(), getChrMemSize());
94+
// hash.Update(getHighMem(), _HIGH_MEM_SIZE);
95+
// hash.Update(getNametableMem(), _NAMETABLES_MEM_SIZE);
96+
// hash.Update(getChrMem(), getChrMemSize());
12397

12498
hash_t result;
12599
hash.Finalize(reinterpret_cast<uint8_t *>(&result));
@@ -134,14 +108,14 @@ class EmuInstance
134108
std::string stateData;
135109
bool status = loadStringFromFile(stateData, stateFilePath);
136110
if (status == false) EXIT_WITH_ERROR("Could not find/read state file: %s\n", stateFilePath.c_str());
137-
deserializeState((uint8_t *)stateData.data());
111+
deserializeFullState((uint8_t *)stateData.data());
138112
}
139113

140114
inline void saveStateFile(const std::string &stateFilePath) const
141115
{
142116
std::string stateData;
143-
stateData.resize(_stateSize);
144-
serializeState((uint8_t *)stateData.data());
117+
stateData.resize(_fullStateSize);
118+
serializeFullState((uint8_t *)stateData.data());
145119
saveStringToFile(stateData, stateFilePath.c_str());
146120
}
147121

@@ -159,10 +133,10 @@ class EmuInstance
159133
if (status == false) EXIT_WITH_ERROR("Could not process ROM file: %s\n", romFilePath.c_str());
160134

161135
// Detecting full state size
162-
_stateSize = getStateSizeImpl();
136+
_fullStateSize = getFullStateSize();
163137

164138
// Detecting lite state size
165-
_liteStateSize = getLiteStateSizeImpl();
139+
_liteStateSize = getLiteStateSize();
166140
}
167141

168142
// Virtual functions
@@ -174,10 +148,15 @@ class EmuInstance
174148
virtual uint8_t *getHighMem() const = 0;
175149
virtual const uint8_t *getChrMem() const = 0;
176150
virtual size_t getChrMemSize() const = 0;
177-
virtual void serializeState(uint8_t *state) const = 0;
178-
virtual void deserializeState(const uint8_t *state) = 0;
179-
virtual size_t getStateSizeImpl() const = 0;
180-
virtual size_t getLiteStateSizeImpl() const { return getStateSizeImpl(); };
151+
virtual void serializeFullState(uint8_t *state) const = 0;
152+
virtual void deserializeFullState(const uint8_t *state) = 0;
153+
virtual void serializeLiteState(uint8_t *state) const = 0;
154+
virtual void deserializeLiteState(const uint8_t *state) = 0;
155+
virtual size_t getFullStateSize() const = 0;
156+
virtual size_t getLiteStateSize() const = 0;
157+
virtual void enableLiteStateBlock(const std::string& block) = 0;
158+
virtual void disableLiteStateBlock(const std::string& block) = 0;
159+
181160
virtual void doSoftReset() = 0;
182161
virtual void doHardReset() = 0;
183162
virtual std::string getCoreName() const = 0;
@@ -190,7 +169,7 @@ class EmuInstance
190169
size_t _liteStateSize;
191170

192171
// Storage for the full state size
193-
size_t _stateSize;
172+
size_t _fullStateSize;
194173

195174
// Flag to determine whether to enable/disable rendering
196175
bool _doRendering = true;

source/playbackInstance.hpp

+8-5
Original file line numberDiff line numberDiff line change
@@ -29,13 +29,16 @@ struct stepData_t
2929

3030
class PlaybackInstance
3131
{
32+
static const uint16_t image_width = 256;
33+
static const uint16_t image_height = 240;
34+
3235
public:
3336
void addStep(const std::string &input)
3437
{
3538
stepData_t step;
3639
step.input = input;
37-
step.stateData = (uint8_t *)malloc(_emu->getStateSize());
38-
_emu->serializeState(step.stateData);
40+
step.stateData = (uint8_t *)malloc(_emu->getFullStateSize());
41+
_emu->serializeFullState(step.stateData);
3942
step.hash = _emu->getStateHash();
4043

4144
// Adding the step into the sequence
@@ -50,8 +53,8 @@ class PlaybackInstance
5053

5154
// Loading Emulator instance HQN
5255
_hqnState.setEmulatorPointer(_emu->getInternalEmulatorPointer());
53-
static uint8_t video_buffer[emulator_t::image_width * emulator_t::image_height];
54-
_hqnState.m_emu->set_pixels(video_buffer, emulator_t::image_width + 8);
56+
static uint8_t video_buffer[image_width * image_height];
57+
_hqnState.m_emu->set_pixels(video_buffer, image_width + 8);
5558

5659
// Building sequence information
5760
for (const auto &input : sequence)
@@ -166,7 +169,7 @@ class PlaybackInstance
166169
if (stepId > 0)
167170
{
168171
const auto stateData = getStateData(stepId - 1);
169-
_emu->deserializeState(stateData);
172+
_emu->deserializeFullState(stateData);
170173
_emu->advanceState(getStateInput(stepId - 1));
171174
}
172175

source/player.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ int main(int argc, char *argv[])
103103
auto p = PlaybackInstance(&e, sequence);
104104

105105
// Getting state size
106-
auto stateSize = e.getStateSize();
106+
auto stateSize = e.getFullStateSize();
107107

108108
// Flag to continue running playback
109109
bool continueRunning = true;

source/quickNES/quickNESInstance.hpp

+21-13
Original file line numberDiff line numberDiff line change
@@ -45,20 +45,37 @@ class QuickNESInstance : public EmuInstance
4545
const uint8_t *getChrMem() const override { return _nes->chr_mem(); };
4646
size_t getChrMemSize() const override { return _nes->chr_size(); };
4747

48-
void serializeState(uint8_t *state) const override
48+
void serializeLiteState(uint8_t *state) const override { serializeFullState(state); }
49+
void deserializeLiteState(const uint8_t *state) override { deserializeFullState(state); }
50+
inline size_t getLiteStateSize() const override { return getFullStateSize(); }
51+
52+
void enableLiteStateBlock(const std::string& block) override {};
53+
void disableLiteStateBlock(const std::string& block) override {};
54+
55+
void serializeFullState(uint8_t *state) const override
4956
{
50-
Mem_Writer w(state, _stateSize, 0);
57+
Mem_Writer w(state, _fullStateSize, 0);
5158
Auto_File_Writer a(w);
5259
_nes->save_state(a);
5360
}
5461

55-
void deserializeState(const uint8_t *state) override
62+
void deserializeFullState(const uint8_t *state) override
5663
{
57-
Mem_File_Reader r(state, _stateSize);
64+
Mem_File_Reader r(state, _fullStateSize);
5865
Auto_File_Reader a(r);
5966
_nes->load_state(a);
6067
}
6168

69+
inline size_t getFullStateSize() const override
70+
{
71+
uint8_t *data = (uint8_t *)malloc(_DUMMY_SIZE);
72+
Mem_Writer w(data, _DUMMY_SIZE);
73+
Auto_File_Writer a(w);
74+
_nes->save_state(a);
75+
free(data);
76+
return w.size();
77+
}
78+
6279
void advanceStateImpl(const inputType controller1, const inputType controller2) override
6380
{
6481
if (_doRendering == true) _nes->emulate_frame(controller1, controller2);
@@ -72,15 +89,6 @@ class QuickNESInstance : public EmuInstance
7289
void *getInternalEmulatorPointer() const override { return _nes; }
7390

7491
private:
75-
inline size_t getStateSizeImpl() const override
76-
{
77-
uint8_t *data = (uint8_t *)malloc(_DUMMY_SIZE);
78-
Mem_Writer w(data, _DUMMY_SIZE);
79-
Auto_File_Writer a(w);
80-
_nes->save_state(a);
81-
free(data);
82-
return w.size();
83-
}
8492

8593
// Video buffer
8694
uint8_t *video_buffer;

source/quickerNES/apu/Blip_Buffer.cpp source/quickerNES/apu/blipBuffer.cpp

+5-5
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11

22
// Blip_Buffer 0.4.0. http://www.slack.net/~ant/
33

4-
#include "Blip_Buffer.hpp"
5-
#include <limits.h>
6-
#include <math.h>
7-
#include <stdlib.h>
8-
#include <string.h>
4+
#include <climits>
5+
#include <cmath>
6+
#include <cstdlib>
7+
#include <cstring>
8+
#include "blipBuffer.hpp"
99

1010
/* Copyright (C) 2003-2006 Shay Green. This module is free software; you
1111
can redistribute it and/or modify it under the terms of the GNU Lesser
File renamed without changes.

source/quickerNES/apu/buffer.hpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33
// NES non-linear audio buffer
44
// Emu 0.7.0
55

6-
#include "Multi_Buffer.hpp"
76
#include <cstdint>
7+
#include "multiBuffer.hpp"
88

99
namespace quickerNES
1010
{

source/quickerNES/apu/effectsBuffer.hpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33
// Multi-channel effects buffer with panning, echo and reverb
44
// Game_Music_Emu 0.3.0
55

6-
#include "Multi_Buffer.hpp"
76
#include <stdint.h>
7+
#include "multiBuffer.hpp"
88

99
namespace quickerNES
1010
{

source/quickerNES/apu/fme7/apu.hpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
// Emu 0.7.0
55

66
#include <cstdint>
7-
#include "apu/Blip_Buffer.hpp"
7+
#include "apu/blipBuffer.hpp"
88

99
namespace quickerNES
1010
{

source/quickerNES/apu/Multi_Buffer.cpp source/quickerNES/apu/multiBuffer.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11

22
// Blip_Buffer 0.4.0. http://www.slack.net/~ant/
33

4-
#include "Multi_Buffer.hpp"
54
#include <cstdint>
5+
#include "multiBuffer.hpp"
66

77
/* Copyright (C) 2003-2006 Shay Green. This module is free software; you
88
can redistribute it and/or modify it under the terms of the GNU Lesser

source/quickerNES/apu/Multi_Buffer.hpp source/quickerNES/apu/multiBuffer.hpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
// Multi-channel sound buffer interface, and basic mono and stereo buffers
55
// Blip_Buffer 0.4.0
66

7-
#include "Blip_Buffer.hpp"
7+
#include "blipBuffer.hpp"
88

99
namespace quickerNES
1010
{

source/quickerNES/apu/namco/apu.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
// Snd_Emu 0.1.7. http://www.slack.net/~ant/
33

44
#include "apu/namco/apu.hpp"
5-
#include "apu/Blip_Buffer.hpp"
5+
#include "apu/blipBuffer.hpp"
66

77
/* Copyright (C) 2003-2006 Shay Green. This module is free software; you
88
can redistribute it and/or modify it under the terms of the GNU Lesser

source/quickerNES/apu/oscs.hpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
// Private oscillators used by Apu
55
// Snd_Emu 0.1.7
66

7-
#include "Blip_Buffer.hpp"
7+
#include "blipBuffer.hpp"
88

99
namespace quickerNES
1010
{

source/quickerNES/apu/vrc6/apu.hpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
// Snd_Emu 0.1.7
66

77
#include <cstdint>
8-
#include "apu/Blip_Buffer.hpp"
8+
#include "apu/blipBuffer.hpp"
99
#include "apu/apu.hpp"
1010

1111
namespace quickerNES

source/quickerNES/apu/vrc7/apu.hpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
// Snd_Emu 0.1.7. Copyright (C) 2003-2005 Shay Green. GNU LGPL license.
66

77
#include <cstdint>
8-
#include "apu/Blip_Buffer.hpp"
8+
#include "apu/blipBuffer.hpp"
99
#include "apu/vrc7/emu2413_state.hpp"
1010

1111
namespace quickerNES

0 commit comments

Comments
 (0)