Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
alexbevi
GitHub Repository: alexbevi/BizHawk
Path: blob/master/libgambatte/src/sound/channel3.h
2 views
1
/***************************************************************************
2
* Copyright (C) 2007 by Sindre Aamås *
3
* [email protected] *
4
* *
5
* This program is free software; you can redistribute it and/or modify *
6
* it under the terms of the GNU General Public License version 2 as *
7
* published by the Free Software Foundation. *
8
* *
9
* This program is distributed in the hope that it will be useful, *
10
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
11
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
12
* GNU General Public License version 2 for more details. *
13
* *
14
* You should have received a copy of the GNU General Public License *
15
* version 2 along with this program; if not, write to the *
16
* Free Software Foundation, Inc., *
17
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
18
***************************************************************************/
19
#ifndef SOUND_CHANNEL3_H
20
#define SOUND_CHANNEL3_H
21
22
#include "gbint.h"
23
#include "master_disabler.h"
24
#include "length_counter.h"
25
#include "newstate.h"
26
27
namespace gambatte {
28
29
struct SaveState;
30
31
class Channel3 {
32
class Ch3MasterDisabler : public MasterDisabler {
33
unsigned long &waveCounter;
34
35
public:
36
Ch3MasterDisabler(bool &m, unsigned long &wC) : MasterDisabler(m), waveCounter(wC) {}
37
void operator()() { MasterDisabler::operator()(); waveCounter = SoundUnit::COUNTER_DISABLED; }
38
};
39
40
unsigned char waveRam[0x10];
41
42
Ch3MasterDisabler disableMaster;
43
LengthCounter lengthCounter;
44
45
unsigned long cycleCounter;
46
unsigned long soMask;
47
unsigned long prevOut;
48
unsigned long waveCounter;
49
unsigned long lastReadTime;
50
51
unsigned char nr0;
52
unsigned char nr3;
53
unsigned char nr4;
54
unsigned char wavePos;
55
unsigned char rShift;
56
unsigned char sampleBuf;
57
58
bool master;
59
bool cgb;
60
61
void updateWaveCounter(unsigned long cc);
62
63
public:
64
Channel3();
65
bool isActive() const { return master; }
66
void reset();
67
void init(bool cgb);
68
void setStatePtrs(SaveState &state);
69
void loadState(const SaveState &state);
70
void setNr0(unsigned data);
71
void setNr1(unsigned data) { lengthCounter.nr1Change(data, nr4, cycleCounter); }
72
void setNr2(unsigned data);
73
void setNr3(unsigned data) { nr3 = data; }
74
void setNr4(unsigned data);
75
void setSo(unsigned long soMask);
76
void update(uint_least32_t *buf, unsigned long soBaseVol, unsigned long cycles);
77
78
unsigned waveRamRead(unsigned index) const {
79
if (master) {
80
if (!cgb && cycleCounter != lastReadTime)
81
return 0xFF;
82
83
index = wavePos >> 1;
84
}
85
86
return waveRam[index];
87
}
88
89
void waveRamWrite(unsigned index, unsigned data) {
90
if (master) {
91
if (!cgb && cycleCounter != lastReadTime)
92
return;
93
94
index = wavePos >> 1;
95
}
96
97
waveRam[index] = data;
98
}
99
100
template<bool isReader>void SyncState(NewState *ns);
101
};
102
103
}
104
105
#endif
106
107