libsidplayfp  1.0.1
ExtraSidBank.h
1 /*
2  * This file is part of libsidplayfp, a SID player engine.
3  *
4  * Copyright 2012-2013 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 "sidplayfp/sidemu.h"
26 
30 class ExtraSidBank : public Bank
31 {
32 private:
37  static const int MAPPER_SIZE = 8;
38 
39 private:
45  Bank *mapper[MAPPER_SIZE];
46 
47  sidemu *sid;
48 
49 private:
50  static unsigned int mapperIndex(int address) { return address >> 5 & (MAPPER_SIZE - 1); }
51 
52 public:
53  void reset()
54  {
55  if (sid)
56  sid->reset(0xf);
57  }
58 
59  void resetSIDMapper(Bank *bank)
60  {
61  for (int i = 0; i < MAPPER_SIZE; i++)
62  mapper[i] = bank;
63  }
64 
70  void setSIDMapping(int address)
71  {
72  mapper[mapperIndex(address)] = sid;
73  }
74 
75  uint8_t peek(uint_least16_t addr)
76  {
77  return mapper[mapperIndex(addr)]->peek(addr);
78  }
79 
80  void poke(uint_least16_t addr, uint8_t data)
81  {
82  mapper[mapperIndex(addr)]->poke(addr, data);
83  }
84 
90  void setSID(sidemu *s) { sid = s; }
91 
97  sidemu *getSID() const { return sid; }
98 };
99 
100 #endif