libsidplayfp  2.0.2
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 
38 class 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
50 typedef void (CALLBACK* HsidDLL2_Delay_t) (BYTE deviceID, WORD cycles);
51 typedef BYTE (CALLBACK* HsidDLL2_Devices_t) ();
52 typedef void (CALLBACK* HsidDLL2_Filter_t) (BYTE deviceID, BOOL filter);
53 typedef void (CALLBACK* HsidDLL2_Flush_t) (BYTE deviceID);
54 typedef void (CALLBACK* HsidDLL2_Mute_t) (BYTE deviceID, BYTE channel, BOOL mute);
55 typedef void (CALLBACK* HsidDLL2_MuteAll_t) (BYTE deviceID, BOOL mute);
56 typedef void (CALLBACK* HsidDLL2_Reset_t) (BYTE deviceID);
57 typedef BYTE (CALLBACK* HsidDLL2_Read_t) (BYTE deviceID, WORD cycles, BYTE SID_reg);
58 typedef void (CALLBACK* HsidDLL2_Sync_t) (BYTE deviceID);
59 typedef void (CALLBACK* HsidDLL2_Write_t) (BYTE deviceID, WORD cycles, BYTE SID_reg, BYTE data);
60 typedef WORD (CALLBACK* HsidDLL2_Version_t) ();
61 
62 // Version 2.04 Extensions
63 typedef BOOL (CALLBACK* HsidDLL2_Lock_t) (BYTE deviceID);
64 typedef void (CALLBACK* HsidDLL2_Unlock_t) (BYTE deviceID);
65 typedef void (CALLBACK* HsidDLL2_Reset2_t) (BYTE deviceID, BYTE volume);
66 
67 // Version 2.07 Extensions
68 typedef void (CALLBACK* HsidDLL2_Mute2_t) (BYTE deviceID, BYTE channel, BOOL mute, BOOL manual);
69 
70 namespace libsidplayfp
71 {
72 
73 struct 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 
97 namespace libsidplayfp
98 {
99 
100 #define HARDSID_VOICES 3
101 // Approx 60ms
102 #define HARDSID_DELAY_CYCLES 60000
103 
104 /***************************************************************************
105  * HardSID SID Specialisation
106  ***************************************************************************/
107 class HardSID final : public sidemu, private Event
108 {
109 private:
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  // Must stay in this order
122  bool muted[HARDSID_VOICES];
123  unsigned int m_instance;
124 
125 private:
126  event_clock_t delay();
127 
128 public:
129  static const char* getCredits();
130 
131 public:
132  HardSID(sidbuilder *builder);
133  ~HardSID();
134 
135  bool getStatus() const { return m_status; }
136 
137  uint8_t read(uint_least8_t addr) override;
138  void write(uint_least8_t addr, uint8_t data) override;
139 
140  // c64sid functions
141  void reset(uint8_t volume) override;
142 
143  // Standard SID functions
144  void clock() override;
145 
146  void model(SidConfig::sid_model_t, bool digiboost) override {}
147 
148  void voice(unsigned int num, bool mute) override;
149 
150  // HardSID specific
151  void flush();
152  void filter(bool enable);
153 
154  // Must lock the SID before using the standard functions.
155  bool lock(EventScheduler *env) override;
156  void unlock() override;
157 
158 private:
159  // Fixed interval timer delay to prevent sidplay2
160  // shoot to 100% CPU usage when song no longer
161  // writes to SID.
162  void event() override;
163 };
164 
165 }
166 
167 #endif // HARDSID_EMU_H
libsidplayfp::sidemu
Definition: sidemu.h:47
libsidplayfp::HardSID::unlock
void unlock() override
Definition: hardsid-emu-unix.cpp:238
HardSIDBuilder::filter
void filter(bool enable)
Definition: hardsid-builder.cpp:138
libsidplayfp::EventScheduler
Definition: EventScheduler.h:62
libsidplayfp::HardSID::voice
void voice(unsigned int num, bool mute) override
Definition: hardsid-emu-unix.cpp:191
sidbuilder::getStatus
bool getStatus() const
Definition: sidbuilder.h:143
sidbuilder
Definition: sidbuilder.h:41
libsidplayfp::HardSID
Definition: hardsid-emu.h:108
HardSIDBuilder
Definition: hardsid.h:33
libsidplayfp::HardSID::model
void model(SidConfig::sid_model_t, bool digiboost) override
Definition: hardsid-emu.h:148
sidbuilder::filter
virtual void filter(bool enable)=0
libsidplayfp::HardSID::lock
bool lock(EventScheduler *env) override
Definition: hardsid-emu-unix.cpp:230
libsidplayfp::Event
Definition: Event.h:39
libsidplayfp::HardSID::clock
void clock() override
Definition: hardsid-emu-unix.cpp:154
SidConfig::sid_model_t
sid_model_t
SID chip model.
Definition: SidConfig.h:51