Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
folium-app
GitHub Repository: folium-app/Folium
Path: blob/a-new-beginning/Cherry/Core/include/AY8910.h
2 views
1
/*
2
* Gearcoleco - ColecoVision Emulator
3
* Copyright (C) 2021 Ignacio Sanchez
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 as published by
7
* the Free Software Foundation, either version 3 of the License, or
8
* any later version.
9
10
* This program is distributed in the hope that it will be useful,
11
* but WITHOUT ANY WARRANTY; without even the implied warranty of
12
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
* GNU General Public License for more details.
14
15
* You should have received a copy of the GNU General Public License
16
* along with this program. If not, see http://www.gnu.org/licenses/
17
*
18
*/
19
20
#ifndef AY8910_H
21
#define AY8910_H
22
23
#include "definitions.h"
24
#include "log.h"
25
26
class AY8910
27
{
28
public:
29
AY8910();
30
~AY8910();
31
void Init(int clockRate);
32
void Reset(int clockRate);
33
void WriteRegister(u8 value);
34
u8 ReadRegister();
35
void SelectRegister(u8 reg);
36
void Tick(unsigned int clockCycles);
37
int EndFrame(s16* pSampleBuffer);
38
void SaveState(std::ostream& stream);
39
void LoadState(std::istream& stream);
40
41
private:
42
void EnvelopeReset();
43
void Sync();
44
45
private:
46
u8 m_Registers[16];
47
u8 m_SelectedRegister;
48
u16 m_TonePeriod[3];
49
u16 m_ToneCounter[3];
50
u8 m_Amplitude[3];
51
u8 m_NoisePeriod;
52
u16 m_NoiseCounter;
53
u32 m_NoiseShift;
54
u16 m_EnvelopePeriod;
55
u16 m_EnvelopeCounter;
56
bool m_EnvelopeSegment;
57
u8 m_EnvelopeStep;
58
u8 m_EnvelopeVolume;
59
bool m_ToneDisable[3];
60
bool m_NoiseDisable[3];
61
bool m_EnvelopeMode[3];
62
bool m_Sign[3];
63
int m_iCycleCounter;
64
int m_iSampleCounter;
65
int m_iCyclesPerSample;
66
s16* m_pBuffer;
67
int m_iBufferIndex;
68
int m_ElapsedCycles;
69
int m_iClockRate;
70
s16 m_CurrentSample;
71
};
72
73
const u8 kAY8910RegisterMask[16] = {0xFF, 0x0F, 0xFF, 0x0F, 0xFF, 0x0F, 0x1F, 0xFF, 0x1F, 0x1F, 0x1F, 0xFF, 0xFF, 0x0F, 0xFF, 0xFF};
74
const s16 kAY8910VolumeTable[16] = {0, 40, 60, 86, 124, 186, 264, 440, 518, 840, 1196, 1526, 2016, 2602, 3300, 4096};
75
76
#endif /* AY8910_H */
77