libsidplayfp  1.0.3
ExtraSidBank.h
00001 /*
00002  * This file is part of libsidplayfp, a SID player engine.
00003  *
00004  * Copyright 2012-2013 Leandro Nini <drfiemost@users.sourceforge.net>
00005  *
00006  * This program is free software; you can redistribute it and/or modify
00007  * it under the terms of the GNU General Public License as published by
00008  * the Free Software Foundation; either version 2 of the License, or
00009  * (at your option) any later version.
00010  *
00011  * This program is distributed in the hope that it will be useful,
00012  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00013  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00014  * GNU General Public License for more details.
00015  *
00016  * You should have received a copy of the GNU General Public License
00017  * along with this program; if not, write to the Free Software
00018  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
00019  */
00020 
00021 #ifndef EXTRASIDBANK_H
00022 #define EXTRASIDBANK_H
00023 
00024 #include "Bank.h"
00025 #include "sidplayfp/sidemu.h"
00026 
00030 class ExtraSidBank : public Bank
00031 {
00032 private:
00037     static const int MAPPER_SIZE = 8;
00038 
00039 private:
00045     Bank *mapper[MAPPER_SIZE];
00046 
00047     sidemu *sid;
00048 
00049 private:
00050     static unsigned int mapperIndex(int address) { return address >> 5 & (MAPPER_SIZE - 1); }
00051 
00052 public:
00053     ExtraSidBank() : sid(0) {}
00054 
00055     void reset()
00056     {
00057         if (sid)
00058             sid->reset(0xf);
00059     }
00060 
00061     void resetSIDMapper(Bank *bank)
00062     {
00063         for (int i = 0; i < MAPPER_SIZE; i++)
00064             mapper[i] = bank;
00065     }
00066 
00072     void setSIDMapping(int address)
00073     {
00074         if (sid)
00075             mapper[mapperIndex(address)] = sid;
00076     }
00077 
00078     uint8_t peek(uint_least16_t addr)
00079     {
00080         return mapper[mapperIndex(addr)]->peek(addr);
00081     }
00082 
00083     void poke(uint_least16_t addr, uint8_t data)
00084     {
00085         mapper[mapperIndex(addr)]->poke(addr, data);
00086     }
00087 
00093     void setSID(sidemu *s) { sid = s; }
00094 
00100     sidemu *getSID() const { return sid; }
00101 };
00102 
00103 #endif