libsidplayfp  0.3.5
hardsid-emu.h
1 /***************************************************************************
2  hardsid-emu.h - Hardsid support interface.
3  -------------------
4  begin : Fri Dec 15 2000
5  copyright : (C) 2000-2002 by Simon White
6  : (C) 2001-2002 by Jarno Paananen
7  email : s_a_white@email.com
8  ***************************************************************************/
9 /***************************************************************************
10  * *
11  * This program is free software; you can redistribute it and/or modify *
12  * it under the terms of the GNU General Public License as published by *
13  * the Free Software Foundation; either version 2 of the License, or *
14  * (at your option) any later version. *
15  * *
16  ***************************************************************************/
17 /***************************************************************************
18  * $Log: hardsid-emu.h,v $
19  * Revision 1.8 2004/03/18 20:50:21 s_a_white
20  * Indicate the 2.07 extensions.
21  *
22  * Revision 1.7 2003/10/28 00:15:16 s_a_white
23  * Get time with respect to correct clock phase.
24  *
25  * Revision 1.6 2003/06/27 07:08:17 s_a_white
26  * Use new hardsid.dll muting interface.
27  *
28  * Revision 1.5 2002/08/09 18:11:35 s_a_white
29  * Added backwards compatibility support for older hardsid.dll.
30  *
31  * Revision 1.4 2002/07/20 08:36:24 s_a_white
32  * Remove unnecessary and pointless conts.
33  *
34  * Revision 1.3 2002/02/17 17:24:50 s_a_white
35  * Updated for new reset interface.
36  *
37  * Revision 1.2 2002/01/29 21:47:35 s_a_white
38  * Constant fixed interval delay added to prevent emulation going fast when
39  * there are no writes to the sid.
40  *
41  * Revision 1.1 2002/01/28 22:35:20 s_a_white
42  * Initial Release.
43  *
44  ***************************************************************************/
45 
46 #ifndef _hardsid_emu_h_
47 #define _hardsid_emu_h_
48 
49 #ifdef HAVE_CONFIG_H
50 # include "config.h"
51 #endif
52 
53 #include "sidplayfp/sidbuilder.h"
54 #include "sidplayfp/event.h"
55 
56 #ifdef _WIN32
57 
58 #include <windows.h>
59 
60 #define HSID_VERSION_MIN (WORD) 0x0200
61 #define HSID_VERSION_204 (WORD) 0x0204
62 #define HSID_VERSION_207 (WORD) 0x0207
63 
64 //**************************************************************************
65 // Version 2 Interface
66 typedef void (CALLBACK* HsidDLL2_Delay_t) (BYTE deviceID, WORD cycles);
67 typedef BYTE (CALLBACK* HsidDLL2_Devices_t) (void);
68 typedef void (CALLBACK* HsidDLL2_Filter_t) (BYTE deviceID, BOOL filter);
69 typedef void (CALLBACK* HsidDLL2_Flush_t) (BYTE deviceID);
70 typedef void (CALLBACK* HsidDLL2_Mute_t) (BYTE deviceID, BYTE channel, BOOL mute);
71 typedef void (CALLBACK* HsidDLL2_MuteAll_t) (BYTE deviceID, BOOL mute);
72 typedef void (CALLBACK* HsidDLL2_Reset_t) (BYTE deviceID);
73 typedef BYTE (CALLBACK* HsidDLL2_Read_t) (BYTE deviceID, WORD cycles, BYTE SID_reg);
74 typedef void (CALLBACK* HsidDLL2_Sync_t) (BYTE deviceID);
75 typedef void (CALLBACK* HsidDLL2_Write_t) (BYTE deviceID, WORD cycles, BYTE SID_reg, BYTE data);
76 typedef WORD (CALLBACK* HsidDLL2_Version_t) (void);
77 
78 // Version 2.04 Extensions
79 typedef BOOL (CALLBACK* HsidDLL2_Lock_t) (BYTE deviceID);
80 typedef void (CALLBACK* HsidDLL2_Unlock_t) (BYTE deviceID);
81 typedef void (CALLBACK* HsidDLL2_Reset2_t) (BYTE deviceID, BYTE volume);
82 
83 // Version 2.07 Extensions
84 typedef void (CALLBACK* HsidDLL2_Mute2_t) (BYTE deviceID, BYTE channel, BOOL mute, BOOL manual);
85 
86 struct HsidDLL2
87 {
88  HINSTANCE Instance;
89  HsidDLL2_Delay_t Delay;
90  HsidDLL2_Devices_t Devices;
91  HsidDLL2_Filter_t Filter;
92  HsidDLL2_Flush_t Flush;
93  HsidDLL2_Lock_t Lock;
94  HsidDLL2_Unlock_t Unlock;
95  HsidDLL2_Mute_t Mute;
96  HsidDLL2_Mute2_t Mute2;
97  HsidDLL2_MuteAll_t MuteAll;
98  HsidDLL2_Reset_t Reset;
99  HsidDLL2_Reset2_t Reset2;
100  HsidDLL2_Read_t Read;
101  HsidDLL2_Sync_t Sync;
102  HsidDLL2_Write_t Write;
103  WORD Version;
104 };
105 
106 #endif // _WIN32
107 
108 #define HARDSID_VOICES 3
109 // Approx 60ms
110 #define HARDSID_DELAY_CYCLES 60000
111 
112 /***************************************************************************
113  * HardSID SID Specialisation
114  ***************************************************************************/
115 class HardSID: public sidemu, private Event
116 {
117 private:
118  friend class HardSIDBuilder;
119 
120  // HardSID specific data
121 #ifndef _WIN32
122  static bool m_sidFree[16];
123  int m_handle;
124 #endif
125 
126  static const uint voices;
127  static uint sid;
128  static char credit[100];
129 
130 
131  // Generic variables
132  EventContext *m_eventContext;
133  event_phase_t m_phase;
134  event_clock_t m_accessClk;
135  char m_errorBuffer[100];
136 
137  // Must stay in this order
138  bool muted[HARDSID_VOICES];
139  uint m_instance;
140  bool m_status;
141  bool m_locked;
142 
143 public:
144  HardSID (sidbuilder *builder);
145  ~HardSID ();
146 
147  // Standard component functions
148  const char *credits (void) {return credit;}
149  void reset () { sidemu::reset (); }
150  void reset (uint8_t volume);
151  uint8_t read (uint_least8_t addr);
152  void write (uint_least8_t addr, uint8_t data);
153  void clock ();
154  const char *error (void) {return m_errorBuffer;}
155  operator bool () const { return m_status; }
156 
157  // Standard SID functions
158  void filter (bool enable);
159  void model (sid2_model_t model) {;}
160  void voice (uint_least8_t num, bool mute);
161  // HardSID specific
162  void flush (void);
163 
164  // Must lock the SID before using the standard functions.
165  bool lock (c64env *env);
166 
167 private:
168  // Fixed interval timer delay to prevent sidplay2
169  // shoot to 100% CPU usage when song nolonger
170  // writes to SID.
171  void event (void);
172 };
173 
174 #endif // _hardsid_emu_h_