libsidplayfp  2.0.2
ExtraSidBank.h
1 /*
2  * This file is part of libsidplayfp, a SID player engine.
3  *
4  * Copyright 2012-2014 Leandro Nini <drfiemost@users.sourceforge.net>
5  *
6  * This program is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; either version 2 of the License, or
9  * (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program; if not, write to the Free Software
18  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
19  */
20 
21 #ifndef EXTRASIDBANK_H
22 #define EXTRASIDBANK_H
23 
24 #include "Bank.h"
25 #include <vector>
26 #include <algorithm>
27 
28 #include "c64/c64sid.h"
29 
30 #include "sidcxx11.h"
31 
32 namespace libsidplayfp
33 {
34 
38 class ExtraSidBank final : public Bank
39 {
40 private:
41  typedef std::vector<c64sid*> sids_t;
42 
43 private:
48  static const int MAPPER_SIZE = 8;
49 
50 private:
56  Bank *mapper[MAPPER_SIZE];
57 
58  sids_t sids;
59 
60 private:
61  static void resetSID(sids_t::value_type &e) { e->reset(0xf); }
62 
63  static unsigned int mapperIndex(int address) { return address >> 5 & (MAPPER_SIZE - 1); }
64 
65 public:
66  virtual ~ExtraSidBank() {}
67 
68  void reset()
69  {
70  std::for_each(sids.begin(), sids.end(), resetSID);
71  }
72 
73  void resetSIDMapper(Bank *bank)
74  {
75  for (int i = 0; i < MAPPER_SIZE; i++)
76  mapper[i] = bank;
77  }
78 
79  uint8_t peek(uint_least16_t addr) override
80  {
81  return mapper[mapperIndex(addr)]->peek(addr);
82  }
83 
84  void poke(uint_least16_t addr, uint8_t data) override
85  {
86  mapper[mapperIndex(addr)]->poke(addr, data);
87  }
88 
95  void addSID(c64sid *s, int address)
96  {
97  sids.push_back(s);
98  mapper[mapperIndex(address)] = s;
99  }
100 };
101 
102 }
103 
104 #endif
libsidplayfp::ExtraSidBank::poke
void poke(uint_least16_t addr, uint8_t data) override
Definition: ExtraSidBank.h:84
libsidplayfp::ExtraSidBank
Definition: ExtraSidBank.h:39
libsidplayfp::Bank
Definition: Bank.h:36
libsidplayfp::Bank::peek
virtual uint8_t peek(uint_least16_t address)=0
libsidplayfp::ExtraSidBank::peek
uint8_t peek(uint_least16_t addr) override
Definition: ExtraSidBank.h:79
libsidplayfp::ExtraSidBank::addSID
void addSID(c64sid *s, int address)
Definition: ExtraSidBank.h:95
libsidplayfp::c64sid
Definition: c64sid.h:37
libsidplayfp::Bank::poke
virtual void poke(uint_least16_t address, uint8_t value)=0