libsidplayfp  1.5.3
sidemu.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 2000-2001 Simon White
7  *
8  * This program is free software; you can redistribute it and/or modify
9  * it under the terms of the GNU General Public License as published by
10  * the Free Software Foundation; either version 2 of the License, or
11  * (at your option) any later version.
12  *
13  * This program is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16  * GNU General Public License for more details.
17  *
18  * You should have received a copy of the GNU General Public License
19  * along with this program; if not, write to the Free Software
20  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
21  */
22 
23 #ifndef SIDEMU_H
24 #define SIDEMU_H
25 
26 #include <string>
27 
28 #include "component.h"
29 #include "SidConfig.h"
30 #include "siddefs.h"
31 #include "event.h"
32 #include "c64/c64sid.h"
33 
34 class sidbuilder;
35 class EventContext;
36 
40 enum
41 {
42  OUTPUTBUFFERSIZE = 5000
43 };
44 
48 class sidemu : public c64sid, public component
49 {
50 private:
51  sidbuilder *m_builder;
52 
53 protected:
54  static std::string m_credit;
55 
56 protected:
57  EventContext *m_context;
58 
59  event_clock_t m_accessClk;
60 
61  short *m_buffer;
62  int m_bufferpos;
63 
64  bool m_status;
65  bool m_locked;
66 
67  std::string m_error;
68 
69 public:
70  sidemu(sidbuilder *builder) :
71  m_builder (builder),
72  m_context(0),
73  m_buffer(0),
74  m_bufferpos(0),
75  m_status(true),
76  m_locked(false),
77  m_error("N/A") {}
78  virtual ~sidemu() {}
79 
80  // Standard component functions
81  void reset() { reset(0); }
82 
83  virtual void reset(uint8_t volume) = 0;
84 
85  virtual void clock() = 0;
86 
88  virtual bool lock(EventContext *env);
89 
91  virtual void unlock();
92 
93  const char *error() const { return m_error.c_str(); }
94 
95  // Standard SID functions
96  virtual void voice(unsigned int num, bool mute) = 0;
97  virtual void model(SidConfig::sid_model_t model) = 0;
98 
99  sidbuilder *builder() const { return m_builder; }
100 
101  virtual void sampling(float systemfreq SID_UNUSED, float outputfreq SID_UNUSED,
102  SidConfig::sampling_method_t method SID_UNUSED, bool fast SID_UNUSED) {}
103 
104  int bufferpos() const { return m_bufferpos; }
105  void bufferpos(int pos) { m_bufferpos = pos; }
106  short *buffer() const { return m_buffer; }
107 
108  void poke(uint_least16_t address, uint8_t value) { write(address & 0x1f, value); }
109  uint8_t peek(uint_least16_t address) { return read(address & 0x1f); }
110 };
111 
112 #endif // SIDEMU_H