libsidplayfp  0.3.5
c64xsid.h
1 /***************************************************************************
2  c64sid.h - ReSid Wrapper
3  -------------------
4  begin : Fri Apr 4 2001
5  copyright : (C) 2001 by Simon White
6  email : s_a_white@email.com
7  ***************************************************************************/
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 /* This file could be a specialisation of a sid implementation.
19  * However since the sid emulation is not part of this project
20  * we are actually creating a wrapper instead.
21  */
22 
23 #include "sidplayfp/c64env.h"
24 #include "sidplayfp/sidbuilder.h"
25 #include "../xsid/xsid.h"
26 
27 class c64xsid: public XSID
28 {
29 private:
30  c64env &m_env;
31  sidemu *m_sid;
32 
33 private:
34  uint8_t readMemByte (uint_least16_t addr)
35  {
36  const uint8_t data = m_env.readMemRamByte (addr);
37  m_env.sid2crc (data);
38  return data;
39  }
40  void writeMemByte (uint8_t data)
41  { m_sid->write (0x18, data);}
42 
43 public:
44  c64xsid (c64env *env, sidemu *sid)
45  :XSID(&env->context ()),
46  m_env(*env), m_sid(sid)
47  {;}
48 
49  // Standard component interface
50  const char *error (void) {return "";}
51  void reset () { sidemu::reset (); }
52  void reset (uint8_t volume)
53  {
54  XSID::reset (volume);
55  m_sid->reset (volume);
56  }
57 
58  uint8_t read (uint_least8_t addr)
59  { return m_sid->read (addr); }
60 
61  void write (uint_least8_t addr, uint8_t data)
62  {
63  if (addr == 0x18)
64  XSID::storeSidData0x18 (data);
65  else
66  m_sid->write (addr, data);
67  }
68 
69  void write16 (uint_least16_t addr, uint8_t data)
70  {
71  XSID::write (addr, data);
72  }
73 
74  // Standard SID interface
75  void clock() { m_sid->clock(); }
76 
77  void voice (uint_least8_t num, bool mute)
78  {
79  if (num == 3)
80  XSID::mute (mute);
81  else
82  m_sid->voice (num, mute);
83  }
84 
85  short *buffer() {
86  return m_sid->buffer();
87  }
88  int bufferpos() {
89  return m_sid->bufferpos();
90  }
91  void bufferpos(int val) {
92  m_sid->bufferpos(val);
93  }
94  void sampling(float systemclock, float freq,
95  const sampling_method_t method, const bool fast) {
96  m_sid->sampling(systemclock, freq, method, fast);
97  }
98 
99  // Xsid specific
100  void emulation (sidemu *sid) {
101  m_sid = sid;
102  }
103  sidemu *emulation (void) { return m_sid; }
104 };