Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
alexbevi
GitHub Repository: alexbevi/BizHawk
Path: blob/master/libmeteor/source/sound.cpp
2 views
1
// Meteor - A Nintendo Gameboy Advance emulator
2
// Copyright (C) 2009-2011 Philippe Daouadi
3
//
4
// This program is free software: you can redistribute it and/or modify
5
// it under the terms of the GNU General Public License as published by
6
// the Free Software Foundation, either version 3 of the License, or
7
// (at your option) any later version.
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 for more details.
13
//
14
// You should have received a copy of the GNU General Public License
15
// along with this program. If not, see <http://www.gnu.org/licenses/>.
16
17
#include "ameteor/sound.hpp"
18
#include "globals.hpp"
19
#include "ameteor.hpp"
20
21
#include "debug.hpp"
22
23
namespace AMeteor
24
{
25
Sound::Sound () :
26
m_speaker(IO.GetRef16(Io::SOUND1CNT_L), IO.GetRef16(Io::SOUND1CNT_H),
27
IO.GetRef16(Io::SOUND1CNT_X),
28
IO.GetRef16(Io::SOUND2CNT_L), IO.GetRef16(Io::SOUND2CNT_H),
29
IO.GetRef16(Io::SOUND4CNT_L), IO.GetRef16(Io::SOUND4CNT_H),
30
IO.GetRef16(Io::SOUNDCNT_L), IO.GetRef16(Io::SOUNDCNT_H),
31
IO.GetRef16(Io::SOUNDCNT_X), IO.GetRef16(Io::SOUNDBIAS)),
32
m_fATimer(0),
33
m_fBTimer(0)
34
{
35
}
36
37
void Sound::Reset ()
38
{
39
m_fATimer = m_fBTimer = 0;
40
m_speaker.Reset();
41
}
42
43
void Sound::UpdateCntH1 (uint8_t val)
44
{
45
m_fATimer = (val & (0x1 << 10)) ? 1 : 0;
46
m_fBTimer = (val & (0x1 << 14)) ? 1 : 0;
47
if (val & (0x1 << 3))
48
m_speaker.ResetFifoA();
49
if (val & (0x1 << 7))
50
m_speaker.ResetFifoB();
51
}
52
53
void Sound::TimerOverflow (uint8_t timernum)
54
{
55
// both fifo may be triggered by the same timer
56
if (m_fATimer == timernum)
57
TimerOverflowA();
58
if (m_fBTimer == timernum)
59
TimerOverflowB();
60
}
61
62
inline void Sound::TimerOverflowA ()
63
{
64
if (m_speaker.GetSizeA() <= 16)
65
{
66
DMA.Check(1, Dma::Special);
67
if (m_speaker.GetSizeA() <= 16)
68
{
69
int8_t buf[16] = {0};
70
m_speaker.FillFifoA(buf);
71
}
72
}
73
m_speaker.NextSampleA ();
74
}
75
76
inline void Sound::TimerOverflowB ()
77
{
78
if (m_speaker.GetSizeB() <= 16)
79
{
80
DMA.Check(2, Dma::Special);
81
if (m_speaker.GetSizeB() <= 16)
82
{
83
int8_t buf[16] = {0};
84
m_speaker.FillFifoB(buf);
85
}
86
}
87
m_speaker.NextSampleB ();
88
}
89
90
bool Sound::SaveState (std::ostream& stream)
91
{
92
SS_WRITE_VAR(m_fATimer);
93
SS_WRITE_VAR(m_fBTimer);
94
95
if (!m_speaker.SaveState(stream))
96
return false;
97
98
return true;
99
}
100
101
bool Sound::LoadState (std::istream& stream)
102
{
103
SS_READ_VAR(m_fATimer);
104
SS_READ_VAR(m_fBTimer);
105
106
if (!m_speaker.LoadState(stream))
107
return false;
108
109
return true;
110
}
111
}
112
113