mmu.h
/*
* This file is part of libsidplayfp, a SID player engine.
*
* Copyright 2011-2021 Leandro Nini <drfiemost@users.sourceforge.net>
* Copyright 2007-2010 Antti Lankila
* Copyright 2000 Simon White
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
#ifndef MMU_H
#define MMU_H
#include <stdint.h>
#include "sidendian.h"
#include "sidmemory.h"
#include "EventScheduler.h"
#include "Banks/pla.h"
#include "Banks/SystemRAMBank.h"
#include "Banks/SystemROMBanks.h"
#include "Banks/ZeroRAMBank.h"
#include "sidcxx11.h"
#include <string.h>
namespace libsidplayfp
{
class Bank;
class IOBank;
class MMU final : public PLA, public sidmemory
{
private:
EventScheduler &eventScheduler;
bool loram, hiram, charen;
Bank* cpuReadMap[16];
Bank* cpuWriteMap[16];
IOBank* ioBank;
KernalRomBank kernalRomBank;
BasicRomBank basicRomBank;
CharacterRomBank characterRomBank;
SystemRAMBank ramBank;
ZeroRAMBank zeroRAMBank;
mutable unsigned int seed;
private:
void setCpuPort(uint8_t state) override;
uint8_t getLastReadByte() const override;
event_clock_t getPhi2Time() const override { return eventScheduler.getTime(EVENT_CLOCK_PHI2); }
void updateMappingPHI2();
public:
MMU(EventScheduler &eventScheduler, IOBank* ioBank);
void reset();
// ROM banks methods
void setKernal(const uint8_t* rom) override { kernalRomBank.set(rom); }
void setBasic(const uint8_t* rom) override { basicRomBank.set(rom); }
void setChargen(const uint8_t* rom) override { characterRomBank.set(rom); }
// RAM access methods
uint8_t readMemByte(uint_least16_t addr) override { return ramBank.peek(addr); }
uint_least16_t readMemWord(uint_least16_t addr) override { return endian_little16(ramBank.ram+addr); }
void writeMemByte(uint_least16_t addr, uint8_t value) override { ramBank.poke(addr, value); }
void writeMemWord(uint_least16_t addr, uint_least16_t value) override { endian_little16(ramBank.ram+addr, value); }
void fillRam(uint_least16_t start, uint8_t value, unsigned int size) override
{
memset(ramBank.ram+start, value, size);
}
void fillRam(uint_least16_t start, const uint8_t* source, unsigned int size) override
{
memcpy(ramBank.ram+start, source, size);
}
// SID specific hacks
void installResetHook(uint_least16_t addr) override { kernalRomBank.installResetHook(addr); }
void installBasicTrap(uint_least16_t addr) override { basicRomBank.installTrap(addr); }
void setBasicSubtune(uint8_t tune) override { basicRomBank.setSubtune(tune); }
uint8_t cpuRead(uint_least16_t addr) const { return cpuReadMap[addr >> 12]->peek(addr); }
void cpuWrite(uint_least16_t addr, uint8_t data) { cpuWriteMap[addr >> 12]->poke(addr, data); }
};
}
#endif
libsidplayfp::Bank
Definition: Bank.h:36
libsidplayfp::Bank::peek
virtual uint8_t peek(uint_least16_t address)=0
libsidplayfp::Bank::poke
virtual void poke(uint_least16_t address, uint8_t value)=0
libsidplayfp::BasicRomBank
Definition: SystemROMBanks.h:150
libsidplayfp::BasicRomBank::installTrap
void installTrap(uint_least16_t addr)
Definition: SystemROMBanks.h:179
libsidplayfp::CharacterRomBank
Definition: SystemROMBanks.h:207
libsidplayfp::EventScheduler
Definition: EventScheduler.h:62
libsidplayfp::EventScheduler::getTime
event_clock_t getTime(event_phase_t phase) const
Definition: EventScheduler.h:162
libsidplayfp::IOBank
Definition: IOBank.h:42
libsidplayfp::KernalRomBank
Definition: SystemROMBanks.h:86
libsidplayfp::KernalRomBank::installResetHook
void installResetHook(uint_least16_t addr)
Definition: SystemROMBanks.h:137
libsidplayfp::MMU
Definition: mmu.h:51
libsidplayfp::MMU::installBasicTrap
void installBasicTrap(uint_least16_t addr) override
Definition: mmu.h:121
libsidplayfp::MMU::cpuWrite
void cpuWrite(uint_least16_t addr, uint8_t data)
Definition: mmu.h:139
libsidplayfp::MMU::installResetHook
void installResetHook(uint_least16_t addr) override
Definition: mmu.h:119
libsidplayfp::MMU::readMemByte
uint8_t readMemByte(uint_least16_t addr) override
Definition: mmu.h:103
libsidplayfp::MMU::writeMemWord
void writeMemWord(uint_least16_t addr, uint_least16_t value) override
Definition: mmu.h:107
libsidplayfp::MMU::setBasicSubtune
void setBasicSubtune(uint8_t tune) override
Definition: mmu.h:123
libsidplayfp::MMU::writeMemByte
void writeMemByte(uint_least16_t addr, uint8_t value) override
Definition: mmu.h:106
libsidplayfp::MMU::setKernal
void setKernal(const uint8_t *rom) override
Definition: mmu.h:98
libsidplayfp::MMU::fillRam
void fillRam(uint_least16_t start, uint8_t value, unsigned int size) override
Definition: mmu.h:109
libsidplayfp::MMU::fillRam
void fillRam(uint_least16_t start, const uint8_t *source, unsigned int size) override
Definition: mmu.h:113
libsidplayfp::MMU::readMemWord
uint_least16_t readMemWord(uint_least16_t addr) override
Definition: mmu.h:104
libsidplayfp::MMU::cpuRead
uint8_t cpuRead(uint_least16_t addr) const
Definition: mmu.h:131
libsidplayfp::PLA
Definition: pla.h:35
libsidplayfp::SystemRAMBank
Definition: SystemRAMBank.h:39
libsidplayfp::SystemRAMBank::peek
uint8_t peek(uint_least16_t address) override
Definition: SystemRAMBank.h:72
libsidplayfp::SystemRAMBank::poke
void poke(uint_least16_t address, uint8_t value) override
Definition: SystemRAMBank.h:77
libsidplayfp::ZeroRAMBank
Definition: ZeroRAMBank.h:132
libsidplayfp::romBank::set
void set(const uint8_t *source)
Definition: SystemROMBanks.h:67
libsidplayfp::sidmemory
Definition: sidmemory.h:34