libsidplayfp 1.8.8
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 "c64/c64sid.h"
26
27#include <vector>
28#include <algorithm>
29
33class ExtraSidBank : public Bank
34{
35private:
36 typedef std::vector<c64sid*> sids_t;
37
38 class resetSID
39 {
40 public:
41 void operator() (sids_t::value_type &e) { e->reset(0xf); }
42 };
43
44private:
49 static const int MAPPER_SIZE = 8;
50
51private:
57 Bank *mapper[MAPPER_SIZE];
58
59 sids_t sids;
60
61private:
62 static unsigned int mapperIndex(int address) { return address >> 5 & (MAPPER_SIZE - 1); }
63
64public:
65 virtual ~ExtraSidBank() {}
66
67 void reset()
68 {
69 std::for_each(sids.begin(), sids.end(), resetSID());
70 }
71
72 void resetSIDMapper(Bank *bank)
73 {
74 for (int i = 0; i < MAPPER_SIZE; i++)
75 mapper[i] = bank;
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
94 void addSID(c64sid *s, int address)
95 {
96 sids.push_back(s);
97 mapper[mapperIndex(address)] = s;
98 }
99};
100
101#endif
Definition: Bank.h:33
virtual void poke(uint_least16_t address, uint8_t value)=0
virtual uint8_t peek(uint_least16_t address)=0
Definition: ExtraSidBank.h:34
uint8_t peek(uint_least16_t addr)
Definition: ExtraSidBank.h:78
void addSID(c64sid *s, int address)
Definition: ExtraSidBank.h:94
void poke(uint_least16_t addr, uint8_t data)
Definition: ExtraSidBank.h:83
Definition: c64sid.h:33