-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathSIDSoundLib.cpp
More file actions
135 lines (121 loc) · 3.5 KB
/
Copy pathSIDSoundLib.cpp
File metadata and controls
135 lines (121 loc) · 3.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
#include "SIDSoundLib.h"
#ifdef _WIN32
#ifndef WIN32_LEAN_AND_MEAN
#define WIN32_LEAN_AND_MEAN
#include <windows.h>
#endif
#define LIBNAME "sidlib.dll"
#define LOAD_LIBRARY(X) LoadLibrary(X)
#define LOAD_FUNCTION GetProcAddress
#define CLOSE_LIBRARY FreeLibrary
static HMODULE m_hDll = NULL;
#else
#include <dlfcn.h>
#include <stdio.h>
#define LIBNAME "sidlib"
#define LOAD_LIBRARY(X) dlopen(X, RTLD_LOCAL)
#define LOAD_FUNCTION dlsym
#define CLOSE_LIBRARY dlclose
static void *m_hDll = NULL;
#endif
#define LIBNAME_DEBUG LIBNAME
typedef void (*_sidCreate)(unsigned int clock_type, unsigned int model, unsigned int replayFreq);
typedef void (*_sidDestroy)();
typedef void (*_sidSetSampleRate)(unsigned int sampleRate_);
typedef void (*_sidReset)();
typedef void (*_sidPause)();
typedef void (*_sidWriteReg)(unsigned int reg, unsigned char value);
typedef unsigned char (*_sidReadReg)(unsigned int reg);
typedef void (*_sidCalcSamples)(short* buf, long count);
typedef const char *(*_sidGetLibVersion)();
static _sidCreate sidCreate = NULL;
static _sidDestroy sidDestroy = NULL;
static _sidSetSampleRate sidSetSampleRate = NULL;
static _sidSetSampleRate sidSetModel = NULL;
static _sidReset sidReset = NULL;
static _sidPause sidPause = NULL;
static _sidWriteReg sidWriteReg = NULL;
static _sidReadReg sidReadReg = NULL;
static _sidCalcSamples sidCalcSamples = NULL;
static _sidGetLibVersion sidGetLibVersion = NULL;
bool SIDSoundLib::detected = false;
bool SIDSoundLib::connect()
{
if (!detected) {
#ifdef _DEBUG
m_hDll = LOAD_LIBRARY(LIBNAME_DEBUG);
#else
m_hDll = LOAD_LIBRARY(LIBNAME);
#endif
//HRESULT r = GetLastError();
if (m_hDll) {
sidCreate = (_sidCreate)LOAD_FUNCTION(m_hDll, "sidCreate");
sidDestroy = (_sidDestroy)LOAD_FUNCTION(m_hDll, "sidDestroy");
sidSetSampleRate = (_sidSetSampleRate)LOAD_FUNCTION(m_hDll, "sidSetSampleRate");
sidSetModel = (_sidSetSampleRate)LOAD_FUNCTION(m_hDll, "sidSetModel");
sidReset = (_sidReset)LOAD_FUNCTION(m_hDll, "sidReset");
sidPause = (_sidPause)LOAD_FUNCTION(m_hDll, "sidPause");
sidWriteReg = (_sidWriteReg)LOAD_FUNCTION(m_hDll, "sidWriteReg");
sidReadReg = (_sidReadReg)LOAD_FUNCTION(m_hDll, "sidReadReg");
sidCalcSamples = (_sidCalcSamples)LOAD_FUNCTION(m_hDll, "sidCalcSamples");
sidGetLibVersion = (_sidGetLibVersion)LOAD_FUNCTION(m_hDll, "sidGetLibVersion");
if (!(sidCreate && sidDestroy && sidSetSampleRate && sidSetModel && sidReset && sidPause
&& sidWriteReg && sidReadReg && sidCalcSamples && sidGetLibVersion))
return false;
} else
return false;
}
detected = true;
return detected;
}
SIDSoundLib::SIDSoundLib(unsigned int model) : SIDsound(model, 0)
{
if (!detected)
connect();
if (detected) {
sidCreate(sidBaseFreq, model, sidBaseFreq);
}
}
SIDSoundLib::~SIDSoundLib()
{
sidDestroy();
CLOSE_LIBRARY(m_hDll);
m_hDll = NULL;
detected = false;
}
void SIDSoundLib::reset()
{
sidReset();
}
void SIDSoundLib::setSampleRate(unsigned int sampleRate)
{
sidSetSampleRate(sampleRate);
}
void SIDSoundLib::setModel(unsigned int model)
{
if (model_ != model) {
sidSetModel(model);
sidReset();
model_ = model;
}
}
void SIDSoundLib::setFrequency(unsigned int frq)
{
SIDsound::setFrequency(frq);
}
void SIDSoundLib::calcSamples(short* buf, long count)
{
sidCalcSamples(buf, count);
}
void SIDSoundLib::write(unsigned int adr, unsigned char byte)
{
sidWriteReg(adr & 0x1F, byte);
}
unsigned char SIDSoundLib::read(unsigned int adr)
{
return sidReadReg(adr & 0x1F);
}
const char* SIDSoundLib::getSidEngineName()
{
return sidGetLibVersion();
}