Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
alexbevi
GitHub Repository: alexbevi/BizHawk
Path: blob/master/libgambatte/src/sound/channel4.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_CHANNEL4_H
20
#define SOUND_CHANNEL4_H
21
22
#include "gbint.h"
23
#include "master_disabler.h"
24
#include "length_counter.h"
25
#include "envelope_unit.h"
26
#include "static_output_tester.h"
27
#include "newstate.h"
28
29
namespace gambatte {
30
31
struct SaveState;
32
33
class Channel4 {
34
class Lfsr : public SoundUnit {
35
unsigned long backupCounter;
36
unsigned short reg;
37
unsigned char nr3;
38
bool master;
39
40
void updateBackupCounter(unsigned long cc);
41
42
public:
43
Lfsr();
44
void event();
45
bool isHighState() const { return ~reg & 1; }
46
void nr3Change(unsigned newNr3, unsigned long cc);
47
void nr4Init(unsigned long cc);
48
void reset(unsigned long cc);
49
void loadState(const SaveState &state);
50
void resetCounters(unsigned long oldCc);
51
void disableMaster() { killCounter(); master = false; reg = 0x7FFF; }
52
void killCounter() { counter = COUNTER_DISABLED; }
53
void reviveCounter(unsigned long cc);
54
55
template<bool isReader>void SyncState(NewState *ns);
56
};
57
58
class Ch4MasterDisabler : public MasterDisabler {
59
Lfsr &lfsr;
60
public:
61
Ch4MasterDisabler(bool &m, Lfsr &lfsr) : MasterDisabler(m), lfsr(lfsr) {}
62
void operator()() { MasterDisabler::operator()(); lfsr.disableMaster(); }
63
};
64
65
friend class StaticOutputTester<Channel4,Lfsr>;
66
67
StaticOutputTester<Channel4,Lfsr> staticOutputTest;
68
Ch4MasterDisabler disableMaster;
69
LengthCounter lengthCounter;
70
EnvelopeUnit envelopeUnit;
71
Lfsr lfsr;
72
73
SoundUnit *nextEventUnit;
74
75
unsigned long cycleCounter;
76
unsigned long soMask;
77
unsigned long prevOut;
78
79
unsigned char nr4;
80
bool master;
81
82
void setEvent();
83
84
public:
85
Channel4();
86
void setNr1(unsigned data);
87
void setNr2(unsigned data);
88
void setNr3(unsigned data) { lfsr.nr3Change(data, cycleCounter); /*setEvent();*/ }
89
void setNr4(unsigned data);
90
91
void setSo(unsigned long soMask);
92
bool isActive() const { return master; }
93
94
void update(uint_least32_t *buf, unsigned long soBaseVol, unsigned long cycles);
95
96
void reset();
97
void init(bool cgb);
98
void loadState(const SaveState &state);
99
100
template<bool isReader>void SyncState(NewState *ns);
101
};
102
103
}
104
105
#endif
106
107