libsidplayfp  2.11.0
ExtraSidBank.h
1 /*
2  * This file is part of libsidplayfp, a SID player engine.
3  *
4  * Copyright 2012-2024 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 
27 #include "c64/c64sid.h"
28 
29 #include "sidcxx11.h"
30 
31 namespace libsidplayfp
32 {
33 
37 class ExtraSidBank final : public Bank
38 {
39 private:
40  typedef std::vector<c64sid*> sids_t;
41 
42 private:
47  static constexpr int MAPPER_SIZE = 8;
48 
49 private:
55  Bank *mapper[MAPPER_SIZE];
56 
57  sids_t sids;
58 
59 private:
60  static unsigned int mapperIndex(int address) { return address >> 5 & (MAPPER_SIZE - 1); }
61 
62 public:
63  virtual ~ExtraSidBank() = default;
64 
65  void reset()
66  {
67  for (c64sid* sid: sids)
68  sid->reset(0xf);
69  }
70 
71  void resetSIDMapper(Bank *bank)
72  {
73  for (int i = 0; i < MAPPER_SIZE; i++)
74  mapper[i] = bank;
75  }
76 
77  uint8_t peek(uint_least16_t addr) override
78  {
79  return mapper[mapperIndex(addr)]->peek(addr);
80  }
81 
82  void poke(uint_least16_t addr, uint8_t data) override
83  {
84  mapper[mapperIndex(addr)]->poke(addr, data);
85  }
86 
93  void addSID(c64sid *s, int address)
94  {
95  sids.push_back(s);
96  mapper[mapperIndex(address)] = s;
97  }
98 };
99 
100 }
101 
102 #endif
Definition: Bank.h:36
virtual uint8_t peek(uint_least16_t address)=0
virtual void poke(uint_least16_t address, uint8_t value)=0
Definition: ExtraSidBank.h:38
void addSID(c64sid *s, int address)
Definition: ExtraSidBank.h:93
void poke(uint_least16_t addr, uint8_t data) override
Definition: ExtraSidBank.h:82
uint8_t peek(uint_least16_t addr) override
Definition: ExtraSidBank.h:77
Definition: c64sid.h:40