libsidplayfp  1.0.3
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  ExtraSidBank() : sid(0) {}
54 
55  void reset()
56  {
57  if (sid)
58  sid->reset(0xf);
59  }
60 
61  void resetSIDMapper(Bank *bank)
62  {
63  for (int i = 0; i < MAPPER_SIZE; i++)
64  mapper[i] = bank;
65  }
66 
72  void setSIDMapping(int address)
73  {
74  if (sid)
75  mapper[mapperIndex(address)] = sid;
76  }
77 
78  uint8_t peek(uint_least16_t addr)
79  {
80  return mapper[mapperIndex(addr)]->peek(addr);
81  }
82 
83  void poke(uint_least16_t addr, uint8_t data)
84  {
85  mapper[mapperIndex(addr)]->poke(addr, data);
86  }
87 
93  void setSID(sidemu *s) { sid = s; }
94 
100  sidemu *getSID() const { return sid; }
101 };
102 
103 #endif