libsidplayfp 2.10.1
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#include <algorithm>
27
28#include "c64/c64sid.h"
29
30#include "sidcxx11.h"
31
32namespace libsidplayfp
33{
34
38class ExtraSidBank final : public Bank
39{
40private:
41 typedef std::vector<c64sid*> sids_t;
42
43private:
48 static constexpr int MAPPER_SIZE = 8;
49
50private:
56 Bank *mapper[MAPPER_SIZE];
57
58 sids_t sids;
59
60private:
61 static unsigned int mapperIndex(int address) { return address >> 5 & (MAPPER_SIZE - 1); }
62
63public:
64 virtual ~ExtraSidBank() = default;
65
66 void reset()
67 {
68 std::for_each(sids.begin(), sids.end(), [](sids_t::value_type &e) { e->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:39
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