Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
alexbevi
GitHub Repository: alexbevi/BizHawk
Path: blob/master/quicknes/nes_emu/Nes_Core.h
2 views
1
2
// Internal NES emulator
3
4
// Nes_Emu 0.7.0
5
6
#ifndef NES_CORE_H
7
#define NES_CORE_H
8
9
#include "blargg_common.h"
10
#include "Nes_Apu.h"
11
#include "Nes_Cpu.h"
12
#include "Nes_Ppu.h"
13
class Nes_Mapper;
14
class Nes_Cart;
15
class Nes_State;
16
17
class Nes_Core : private Nes_Cpu {
18
typedef Nes_Cpu cpu;
19
public:
20
Nes_Core();
21
~Nes_Core();
22
23
blargg_err_t init();
24
blargg_err_t open( Nes_Cart const* );
25
void reset( bool full_reset = true, bool erase_battery_ram = false );
26
blip_time_t emulate_frame();
27
void close();
28
29
void save_state( Nes_State* ) const;
30
void save_state( Nes_State_* ) const;
31
void load_state( Nes_State_ const& );
32
33
void irq_changed();
34
void event_changed();
35
36
public: private: friend class Nes_Emu;
37
38
struct impl_t
39
{
40
enum { sram_size = 0x2000 };
41
BOOST::uint8_t sram [sram_size];
42
Nes_Apu apu;
43
44
// extra byte allows CPU to always read operand of instruction, which
45
// might go past end of data
46
BOOST::uint8_t unmapped_page [::Nes_Cpu::page_size + 1];
47
};
48
impl_t* impl; // keep large arrays separate
49
unsigned long error_count;
50
bool sram_present;
51
52
public:
53
uint32_t current_joypad [2];
54
int joypad_read_count;
55
Nes_Cart const* cart;
56
Nes_Mapper* mapper;
57
nes_state_t nes;
58
Nes_Ppu ppu;
59
60
private:
61
// noncopyable
62
Nes_Core( const Nes_Core& );
63
Nes_Core& operator = ( const Nes_Core& );
64
65
// Timing
66
nes_time_t ppu_2002_time;
67
void disable_rendering() { clock_ = 0; }
68
nes_time_t earliest_irq( nes_time_t present );
69
nes_time_t ppu_frame_length( nes_time_t present );
70
nes_time_t earliest_event( nes_time_t present );
71
72
// APU and Joypad
73
joypad_state_t joypad;
74
int read_io( nes_addr_t );
75
void write_io( nes_addr_t, int data );
76
static int read_dmc( void* emu, nes_addr_t );
77
static void apu_irq_changed( void* emu );
78
79
// CPU
80
unsigned sram_readable;
81
unsigned sram_writable;
82
unsigned lrom_readable;
83
nes_time_t clock_;
84
nes_time_t cpu_time_offset;
85
nes_time_t emulate_frame_();
86
nes_addr_t read_vector( nes_addr_t );
87
void vector_interrupt( nes_addr_t );
88
static void log_unmapped( nes_addr_t addr, int data = -1 );
89
void cpu_set_irq_time( nes_time_t t ) { cpu::set_irq_time_( t - 1 - cpu_time_offset ); }
90
void cpu_set_end_time( nes_time_t t ) { cpu::set_end_time_( t - 1 - cpu_time_offset ); }
91
nes_time_t cpu_time() const { return clock_ + 1; }
92
void cpu_adjust_time( int offset );
93
94
public: private: friend class Nes_Ppu;
95
void set_ppu_2002_time( nes_time_t t ) { ppu_2002_time = t - 1 - cpu_time_offset; }
96
97
public: private: friend class Nes_Mapper;
98
void enable_prg_6000();
99
void enable_sram( bool enabled, bool read_only = false );
100
nes_time_t clock() const { return clock_; }
101
void add_mapper_intercept( nes_addr_t start, unsigned size, bool read, bool write );
102
103
public: private: friend class Nes_Cpu;
104
int cpu_read_ppu( nes_addr_t, nes_time_t );
105
int cpu_read( nes_addr_t, nes_time_t );
106
void cpu_write( nes_addr_t, int data, nes_time_t );
107
void cpu_write_2007( int data );
108
109
private:
110
unsigned char data_reader_mapped [page_count + 1]; // extra entry for overflow
111
unsigned char data_writer_mapped [page_count + 1];
112
};
113
114
int mem_differs( void const* p, int cmp, unsigned long s );
115
116
#endif
117
118
119