Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
alexbevi
GitHub Repository: alexbevi/BizHawk
Path: blob/master/libsnes/bsnes/snes/chip/hitachidsp/hitachidsp.cpp
2 views
1
#include <snes/snes.hpp>
2
3
#define HITACHIDSP_CPP
4
namespace SNES {
5
6
#include "memory.cpp"
7
#include "opcodes.cpp"
8
#include "registers.cpp"
9
#include "serialization.cpp"
10
HitachiDSP hitachidsp;
11
12
//zero 01-sep-2014 - dont clobber these when reconstructing!
13
unsigned HitachiDSP::frequency;
14
uint24 HitachiDSP::dataROM[1024];
15
16
void HitachiDSP::Enter() { hitachidsp.enter(); }
17
18
void HitachiDSP::enter() {
19
while(true) {
20
// exit requested due to savestate
21
if(scheduler.sync == Scheduler::SynchronizeMode::All) {
22
scheduler.exit(Scheduler::ExitReason::SynchronizeEvent);
23
}
24
25
// if we bail out due to savestating, the first thing we'll try afterwards is synchronize_cpu() again
26
synchronize_cpu();
27
28
switch(state) {
29
case State::Idle:
30
step(1);
31
break;
32
case State::DMA:
33
for(unsigned n = 0; n < regs.dma_length; n++) {
34
bus.write(regs.dma_target + n, bus.read(regs.dma_source + n));
35
step(2);
36
}
37
state = State::Idle;
38
break;
39
case State::Execute:
40
unsigned offset = regs.program_offset + regs.pc * 2;
41
opcode = bus_read(offset + 0) << 0;
42
opcode |= bus_read(offset + 1) << 8;
43
regs.pc = (regs.pc & 0xffff00) | ((regs.pc + 1) & 0x0000ff);
44
exec();
45
step(1);
46
break;
47
}
48
49
// this call is gone, but it's the first thing we try at the top of the loop AFTER we bail out
50
//synchronize_cpu();
51
}
52
}
53
54
void HitachiDSP::init() {
55
}
56
57
void HitachiDSP::load() {
58
}
59
60
void HitachiDSP::unload() {
61
}
62
63
void HitachiDSP::power() {
64
}
65
66
void HitachiDSP::reset() {
67
create(HitachiDSP::Enter, frequency);
68
state = State::Idle;
69
70
regs.n = 0;
71
regs.z = 0;
72
regs.c = 0;
73
74
regs.dma_source = 0x000000;
75
regs.dma_length = 0x0000;
76
regs.dma_target = 0x000000;
77
regs.r1f48 = 0x00;
78
regs.program_offset = 0x000000;
79
regs.r1f4c = 0x00;
80
regs.page_number = 0x0000;
81
regs.program_counter = 0x00;
82
regs.r1f50 = 0x33;
83
regs.r1f51 = 0x00;
84
regs.r1f52 = 0x01;
85
}
86
87
}
88
89