libsidplayfp 2.15.0
hardsid-emu.h
1/*
2 * This file is part of libsidplayfp, a SID player engine.
3 *
4 * Copyright 2011-2015 Leandro Nini <drfiemost@users.sourceforge.net>
5 * Copyright 2007-2010 Antti Lankila
6 * Copyright 2001-2002 by Jarno Paananen
7 * Copyright 2000-2002 Simon White
8 *
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
13 *
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
18 *
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
22 */
23
24#ifndef HARDSID_EMU_H
25#define HARDSID_EMU_H
26
27#include "sidemu.h"
28#include "Event.h"
29#include "EventScheduler.h"
30#include "sidplayfp/siddefs.h"
31
32#include "sidcxx11.h"
33
34#ifdef HAVE_CONFIG_H
35# include "config.h"
36#endif
37
38class sidbuilder;
39
40#ifdef _WIN32
41
42#include <windows.h>
43
44#define HSID_VERSION_MIN (WORD) 0x0200
45#define HSID_VERSION_204 (WORD) 0x0204
46#define HSID_VERSION_207 (WORD) 0x0207
47
48//**************************************************************************
49// Version 2 Interface
50typedef void (CALLBACK* HsidDLL2_Delay_t) (BYTE deviceID, WORD cycles);
51typedef BYTE (CALLBACK* HsidDLL2_Devices_t) ();
52typedef void (CALLBACK* HsidDLL2_Filter_t) (BYTE deviceID, BOOL filter);
53typedef void (CALLBACK* HsidDLL2_Flush_t) (BYTE deviceID);
54typedef void (CALLBACK* HsidDLL2_Mute_t) (BYTE deviceID, BYTE channel, BOOL mute);
55typedef void (CALLBACK* HsidDLL2_MuteAll_t) (BYTE deviceID, BOOL mute);
56typedef void (CALLBACK* HsidDLL2_Reset_t) (BYTE deviceID);
57typedef BYTE (CALLBACK* HsidDLL2_Read_t) (BYTE deviceID, WORD cycles, BYTE SID_reg);
58typedef void (CALLBACK* HsidDLL2_Sync_t) (BYTE deviceID);
59typedef void (CALLBACK* HsidDLL2_Write_t) (BYTE deviceID, WORD cycles, BYTE SID_reg, BYTE data);
60typedef WORD (CALLBACK* HsidDLL2_Version_t) ();
61
62// Version 2.04 Extensions
63typedef BOOL (CALLBACK* HsidDLL2_Lock_t) (BYTE deviceID);
64typedef void (CALLBACK* HsidDLL2_Unlock_t) (BYTE deviceID);
65typedef void (CALLBACK* HsidDLL2_Reset2_t) (BYTE deviceID, BYTE volume);
66
67// Version 2.07 Extensions
68typedef void (CALLBACK* HsidDLL2_Mute2_t) (BYTE deviceID, BYTE channel, BOOL mute, BOOL manual);
69
70namespace libsidplayfp
71{
72
73struct HsidDLL2
74{
75 HINSTANCE Instance;
76 HsidDLL2_Delay_t Delay;
77 HsidDLL2_Devices_t Devices;
78 HsidDLL2_Filter_t Filter;
79 HsidDLL2_Flush_t Flush;
80 HsidDLL2_Lock_t Lock;
81 HsidDLL2_Unlock_t Unlock;
82 HsidDLL2_Mute_t Mute;
83 HsidDLL2_Mute2_t Mute2;
84 HsidDLL2_MuteAll_t MuteAll;
85 HsidDLL2_Reset_t Reset;
86 HsidDLL2_Reset2_t Reset2;
87 HsidDLL2_Read_t Read;
88 HsidDLL2_Sync_t Sync;
89 HsidDLL2_Write_t Write;
90 WORD Version;
91};
92
93}
94
95#endif // _WIN32
96
97namespace libsidplayfp
98{
99
100#define HARDSID_VOICES 3
101// Approx 60ms
102#define HARDSID_DELAY_CYCLES 60000
103
104/***************************************************************************
105 * HardSID SID Specialisation
106 ***************************************************************************/
107class HardSID final : public sidemu, private Event
108{
109private:
110 friend class HardSIDBuilder;
111
112 // HardSID specific data
113#ifndef _WIN32
114 static bool m_sidFree[16];
115 int m_handle;
116#endif
117
118 static const unsigned int voices;
119 static unsigned int sid;
120
121 unsigned int m_instance;
122
123private:
124 event_clock_t delay();
125
126public:
127 static const char* getCredits();
128
129public:
130 HardSID(sidbuilder *builder);
131 ~HardSID();
132
133 bool getStatus() const { return m_status; }
134
135 uint8_t read(uint_least8_t addr) override;
136 void write(uint_least8_t addr, uint8_t data) override;
137
138 // c64sid functions
139 void reset(uint8_t volume) override;
140
141 // Standard SID functions
142 void clock() override;
143
144 void model(SidConfig::sid_model_t, bool digiboost) override {}
145
146 // HardSID specific
147 void flush();
148 void filter(bool enable);
149
150 // Must lock the SID before using the standard functions.
151 bool lock(EventScheduler *env) override;
152 void unlock() override;
153
154private:
155 // Fixed interval timer delay to prevent sidplay2
156 // shoot to 100% CPU usage when song no longer
157 // writes to SID.
158 void event() override;
159};
160
161}
162
163#endif // HARDSID_EMU_H
Definition hardsid.h:33
sid_model_t
SID chip model.
Definition SidConfig.h:51
Definition EventScheduler.h:62
Definition Event.h:39
Definition hardsid-emu.h:108
void clock() override
Definition hardsid-emu-unix.cpp:143
bool lock(EventScheduler *env) override
Definition hardsid-emu-unix.cpp:206
void model(SidConfig::sid_model_t, bool digiboost) override
Definition hardsid-emu.h:144
void unlock() override
Definition hardsid-emu-unix.cpp:214
Definition sidemu.h:47
Definition sidbuilder.h:41
virtual SID_DEPRECATED void filter(bool enable)=0