libsidplayfp 1.8.8
hardsid-emu.h
1/*
2 * This file is part of libsidplayfp, a SID player engine.
3 *
4 * Copyright 2011-2014 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 "sidplayfp/event.h"
28#include "sidemu.h"
29#include "EventScheduler.h"
30#include "sidplayfp/siddefs.h"
31
32#ifdef HAVE_CONFIG_H
33# include "config.h"
34#endif
35
36class sidbuilder;
37
38#ifdef _WIN32
39
40#include <windows.h>
41
42#define HSID_VERSION_MIN (WORD) 0x0200
43#define HSID_VERSION_204 (WORD) 0x0204
44#define HSID_VERSION_207 (WORD) 0x0207
45
46//**************************************************************************
47// Version 2 Interface
48typedef void (CALLBACK* HsidDLL2_Delay_t) (BYTE deviceID, WORD cycles);
49typedef BYTE (CALLBACK* HsidDLL2_Devices_t) ();
50typedef void (CALLBACK* HsidDLL2_Filter_t) (BYTE deviceID, BOOL filter);
51typedef void (CALLBACK* HsidDLL2_Flush_t) (BYTE deviceID);
52typedef void (CALLBACK* HsidDLL2_Mute_t) (BYTE deviceID, BYTE channel, BOOL mute);
53typedef void (CALLBACK* HsidDLL2_MuteAll_t) (BYTE deviceID, BOOL mute);
54typedef void (CALLBACK* HsidDLL2_Reset_t) (BYTE deviceID);
55typedef BYTE (CALLBACK* HsidDLL2_Read_t) (BYTE deviceID, WORD cycles, BYTE SID_reg);
56typedef void (CALLBACK* HsidDLL2_Sync_t) (BYTE deviceID);
57typedef void (CALLBACK* HsidDLL2_Write_t) (BYTE deviceID, WORD cycles, BYTE SID_reg, BYTE data);
58typedef WORD (CALLBACK* HsidDLL2_Version_t) ();
59
60// Version 2.04 Extensions
61typedef BOOL (CALLBACK* HsidDLL2_Lock_t) (BYTE deviceID);
62typedef void (CALLBACK* HsidDLL2_Unlock_t) (BYTE deviceID);
63typedef void (CALLBACK* HsidDLL2_Reset2_t) (BYTE deviceID, BYTE volume);
64
65// Version 2.07 Extensions
66typedef void (CALLBACK* HsidDLL2_Mute2_t) (BYTE deviceID, BYTE channel, BOOL mute, BOOL manual);
67
68struct HsidDLL2
69{
70 HINSTANCE Instance;
71 HsidDLL2_Delay_t Delay;
72 HsidDLL2_Devices_t Devices;
73 HsidDLL2_Filter_t Filter;
74 HsidDLL2_Flush_t Flush;
75 HsidDLL2_Lock_t Lock;
76 HsidDLL2_Unlock_t Unlock;
77 HsidDLL2_Mute_t Mute;
78 HsidDLL2_Mute2_t Mute2;
79 HsidDLL2_MuteAll_t MuteAll;
80 HsidDLL2_Reset_t Reset;
81 HsidDLL2_Reset2_t Reset2;
82 HsidDLL2_Read_t Read;
83 HsidDLL2_Sync_t Sync;
84 HsidDLL2_Write_t Write;
85 WORD Version;
86};
87
88#endif // _WIN32
89
90#define HARDSID_VOICES 3
91// Approx 60ms
92#define HARDSID_DELAY_CYCLES 60000
93
94/***************************************************************************
95 * HardSID SID Specialisation
96 ***************************************************************************/
97class HardSID : public sidemu, private Event
98{
99private:
100 friend class HardSIDBuilder;
101
102 // HardSID specific data
103#ifndef _WIN32
104 static bool m_sidFree[16];
105 int m_handle;
106#endif
107
108 static const unsigned int voices;
109 static unsigned int sid;
110
111 // Must stay in this order
112 bool muted[HARDSID_VOICES];
113 unsigned int m_instance;
114
115public:
116 static const char* getCredits();
117
118public:
119 HardSID(sidbuilder *builder);
120 ~HardSID();
121
122 // Standard component functions
123 void reset() { sidemu::reset (); }
124 void reset(uint8_t volume);
125
126 uint8_t read(uint_least8_t addr);
127 void write(uint_least8_t addr, uint8_t data);
128
129 void clock();
130 bool getStatus() const { return m_status; }
131
132 // Standard SID functions
133 void filter(bool enable);
134 void model(SidConfig::sid_model_t model SID_UNUSED) {;}
135 void voice(unsigned int num, bool mute);
136 // HardSID specific
137 void flush();
138
139 // Must lock the SID before using the standard functions.
140 bool lock(EventContext *env);
141 void unlock();
142
143private:
144 // Fixed interval timer delay to prevent sidplay2
145 // shoot to 100% CPU usage when song nolonger
146 // writes to SID.
147 void event();
148};
149
150#endif // HARDSID_EMU_H
Definition: event.h:108
Definition: event.h:51
Definition: hardsid.h:33
Definition: hardsid-emu.h:98
void clock()
Definition: hardsid-emu-unix.cpp:135
bool lock(EventContext *env)
Definition: hardsid-emu-unix.cpp:233
void unlock()
Definition: hardsid-emu-unix.cpp:241
void voice(unsigned int num, bool mute)
Definition: hardsid-emu-unix.cpp:194
void model(SidConfig::sid_model_t model SID_UNUSED)
Definition: hardsid-emu.h:134
Definition: sidbuilder.h:38
virtual void filter(bool enable)=0
Definition: sidemu.h:40