libsidplayfp  1.2.2
hardsid-emu.h
1 /*
2  * This file is part of libsidplayfp, a SID player engine.
3  *
4  * Copyright 2011-2013 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 <string>
28 
29 #include "sidplayfp/event.h"
30 #include "sidplayfp/sidemu.h"
31 #include "sidplayfp/EventScheduler.h"
32 #include "sidplayfp/siddefs.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 struct HsidDLL2
71 {
72  HINSTANCE Instance;
73  HsidDLL2_Delay_t Delay;
74  HsidDLL2_Devices_t Devices;
75  HsidDLL2_Filter_t Filter;
76  HsidDLL2_Flush_t Flush;
77  HsidDLL2_Lock_t Lock;
78  HsidDLL2_Unlock_t Unlock;
79  HsidDLL2_Mute_t Mute;
80  HsidDLL2_Mute2_t Mute2;
81  HsidDLL2_MuteAll_t MuteAll;
82  HsidDLL2_Reset_t Reset;
83  HsidDLL2_Reset2_t Reset2;
84  HsidDLL2_Read_t Read;
85  HsidDLL2_Sync_t Sync;
86  HsidDLL2_Write_t Write;
87  WORD Version;
88 };
89 
90 #endif // _WIN32
91 
92 #define HARDSID_VOICES 3
93 // Approx 60ms
94 #define HARDSID_DELAY_CYCLES 60000
95 
96 /***************************************************************************
97  * HardSID SID Specialisation
98  ***************************************************************************/
99 class HardSID : public sidemu, private Event
100 {
101 private:
102  friend class HardSIDBuilder;
103 
104  // HardSID specific data
105 #ifndef _WIN32
106  static bool m_sidFree[16];
107  int m_handle;
108 #endif
109 
110  static const unsigned int voices;
111  static unsigned int sid;
112 
113  static std::string m_credit;
114 
115 
116  // Generic variables
117  EventContext *m_eventContext;
118  event_clock_t m_accessClk;
119  std::string m_errorBuffer;
120 
121  // Must stay in this order
122  bool muted[HARDSID_VOICES];
123  unsigned int m_instance;
124  bool m_status;
125  bool m_locked;
126 
127 public:
128  static const char* getCredits();
129 
130 public:
131  HardSID(sidbuilder *builder);
132  ~HardSID();
133 
134  // Standard component functions
135  const char *credits () const { return getCredits(); }
136 
137  void reset() { sidemu::reset (); }
138  void reset(uint8_t volume);
139 
140  uint8_t read(uint_least8_t addr);
141  void write(uint_least8_t addr, uint8_t data);
142 
143  void clock();
144  const char *error() const { return m_errorBuffer.c_str(); }
145  bool getStatus() const { return m_status; }
146 
147  // Standard SID functions
148  void filter(bool enable);
149  void model(SidConfig::sid_model_t model SID_UNUSED) {;}
150  void voice(unsigned int num, bool mute);
151  // HardSID specific
152  void flush();
153 
154  // Must lock the SID before using the standard functions.
155  bool lock(EventContext *env);
156  void unlock();
157 
158 private:
159  // Fixed interval timer delay to prevent sidplay2
160  // shoot to 100% CPU usage when song nolonger
161  // writes to SID.
162  void event();
163 };
164 
165 #endif // HARDSID_EMU_H
const char * credits() const
Definition: hardsid-builder.cpp:125
sidemu * lock(EventContext *env, SidConfig::sid_model_t model)
Definition: sidbuilder.cpp:27
Definition: hardsid.h:32
Definition: sidemu.h:45
void filter(bool enable)
enable/disable filter.
Definition: hardsid-builder.cpp:136
Definition: hardsid-emu.h:99
Definition: event.h:101
bool getStatus() const
Definition: sidbuilder.h:138
const char * error() const
Definition: sidbuilder.h:131
Definition: event.h:50
Definition: sidbuilder.h:37
void unlock(sidemu *device)
Definition: sidbuilder.cpp:47
virtual void filter(bool enable)=0