Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
alexbevi
GitHub Repository: alexbevi/BizHawk
Path: blob/master/libgambatte/src/sound/duty_unit.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 DUTY_UNIT_H
20
#define DUTY_UNIT_H
21
22
#include "sound_unit.h"
23
#include "master_disabler.h"
24
#include "../savestate.h"
25
#include "newstate.h"
26
27
namespace gambatte {
28
29
class DutyUnit : public SoundUnit {
30
unsigned long nextPosUpdate;
31
unsigned short period;
32
unsigned char pos;
33
unsigned char duty;
34
bool high;
35
bool enableEvents;
36
37
void setCounter();
38
void setDuty(unsigned nr1);
39
void updatePos(unsigned long cc);
40
41
public:
42
DutyUnit();
43
void event();
44
bool isHighState() const { return high; }
45
void nr1Change(unsigned newNr1, unsigned long cc);
46
void nr3Change(unsigned newNr3, unsigned long cc);
47
void nr4Change(unsigned newNr4, unsigned long cc);
48
void reset();
49
void loadState(const SaveState::SPU::Duty &dstate, unsigned nr1, unsigned nr4, unsigned long cc);
50
void resetCounters(unsigned long oldCc);
51
void killCounter();
52
void reviveCounter(unsigned long cc);
53
54
//intended for use by SweepUnit only.
55
unsigned getFreq() const { return 2048 - (period >> 1); }
56
void setFreq(unsigned newFreq, unsigned long cc);
57
58
template<bool isReader>void SyncState(NewState *ns);
59
};
60
61
class DutyMasterDisabler : public MasterDisabler {
62
DutyUnit &dutyUnit;
63
public:
64
DutyMasterDisabler(bool &m, DutyUnit &dutyUnit) : MasterDisabler(m), dutyUnit(dutyUnit) {}
65
void operator()() { MasterDisabler::operator()(); dutyUnit.killCounter(); }
66
};
67
68
}
69
70
#endif
71
72