libsidplayfp  1.4.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/c64/c64sid.h"
26 
27 #include "NullSid.h"
28 
32 class ExtraSidBank : public Bank
33 {
34 private:
39  static const int MAPPER_SIZE = 8;
40 
41 private:
47  Bank *mapper[MAPPER_SIZE];
48 
49  c64sid *sid;
50 
51 private:
52  static unsigned int mapperIndex(int address) { return address >> 5 & (MAPPER_SIZE - 1); }
53 
54 public:
55  ExtraSidBank() :
57  {}
58 
59  void reset()
60  {
61  sid->reset(0xf);
62  }
63 
64  void resetSIDMapper(Bank *bank)
65  {
66  for (int i = 0; i < MAPPER_SIZE; i++)
67  mapper[i] = bank;
68  }
69 
75  void setSIDMapping(int address)
76  {
77  mapper[mapperIndex(address)] = sid;
78  }
79 
80  uint8_t peek(uint_least16_t addr)
81  {
82  return mapper[mapperIndex(addr)]->peek(addr);
83  }
84 
85  void poke(uint_least16_t addr, uint8_t data)
86  {
87  mapper[mapperIndex(addr)]->poke(addr, data);
88  }
89 
95  void setSID(c64sid *s) { sid = (s != 0) ? s : NullSid::getInstance(); }
96 };
97 
98 #endif
static NullSid * getInstance()
Returns singleton instance.
Definition: NullSid.h:38
Definition: c64sid.h:31
virtual uint8_t peek(uint_least16_t address)=0
uint8_t peek(uint_least16_t addr)
Definition: ExtraSidBank.h:80
void setSIDMapping(int address)
Definition: ExtraSidBank.h:75
Definition: Bank.h:32
void poke(uint_least16_t addr, uint8_t data)
Definition: ExtraSidBank.h:85
void setSID(c64sid *s)
Definition: ExtraSidBank.h:95
Definition: ExtraSidBank.h:32
virtual void poke(uint_least16_t address, uint8_t value)=0