mmu.h
/*
* This file is part of libsidplayfp, a SID player engine.
*
* Copyright 2011-2015 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 "sidplayfp/event.h"
#include "sidendian.h"
#include "sidmemory.h"
#include "Banks/Bank.h"
#include "Banks/IOBank.h"
#include "Banks/SystemRAMBank.h"
#include "Banks/SystemROMBanks.h"
#include "Banks/ZeroRAMBank.h"
#include <string.h>
class MMU : public PLA, public sidmemory
{
private:
EventContext &context;
bool loram, hiram, charen;
Bank* cpuReadMap[16];
Bank* cpuWriteMap[16];
IOBank* ioBank;
KernalRomBank kernalRomBank;
BasicRomBank basicRomBank;
CharacterRomBank characterRomBank;
SystemRAMBank ramBank;
ZeroRAMBank zeroRAMBank;
private:
void setCpuPort(int state);
void updateMappingPHI2();
uint8_t getLastReadByte() const { return 0; }
event_clock_t getPhi2Time() const { return context.getTime(EVENT_CLOCK_PHI2); }
public:
MMU(EventContext *context, IOBank* ioBank);
~MMU () {}
void reset();
void setRoms(const uint8_t* kernal, const uint8_t* basic, const uint8_t* character)
{
kernalRomBank.set(kernal);
basicRomBank.set(basic);
characterRomBank.set(character);
}
// RAM access methods
uint8_t readMemByte(uint_least16_t addr) { return ramBank.peek(addr); }
uint_least16_t readMemWord(uint_least16_t addr) { return endian_little16(ramBank.ram+addr); }
void writeMemByte(uint_least16_t addr, uint8_t value) { ramBank.poke(addr, value); }
void writeMemWord(uint_least16_t addr, uint_least16_t value) { endian_little16(ramBank.ram+addr, value); }
void fillRam(uint_least16_t start, uint8_t value, unsigned int size)
{
memset(ramBank.ram+start, value, size);
}
void fillRam(uint_least16_t start, const uint8_t* source, unsigned int size)
{
memcpy(ramBank.ram+start, source, size);
}
// SID specific hacks
void installResetHook(uint_least16_t addr) { kernalRomBank.installResetHook(addr); }
void installBasicTrap(uint_least16_t addr) { basicRomBank.installTrap(addr); }
void setBasicSubtune(uint8_t tune) { 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
SystemRAMBank
Definition: SystemRAMBank.h:35
MMU::fillRam
void fillRam(uint_least16_t start, uint8_t value, unsigned int size)
Definition: mmu.h:101
Bank
Definition: Bank.h:32
CharacterRomBank
Definition: SystemROMBanks.h:247
MMU::installBasicTrap
void installBasicTrap(uint_least16_t addr)
Definition: mmu.h:113
MMU::readMemByte
uint8_t readMemByte(uint_least16_t addr)
Definition: mmu.h:95
MMU::setBasicSubtune
void setBasicSubtune(uint8_t tune)
Definition: mmu.h:115
romBank::set
void set(const uint8_t *source)
Definition: SystemROMBanks.h:62
BasicRomBank
Definition: SystemROMBanks.h:189
KernalRomBank::installResetHook
void installResetHook(uint_least16_t addr)
Definition: SystemROMBanks.h:177
MMU::cpuWrite
void cpuWrite(uint_least16_t addr, uint8_t data)
Definition: mmu.h:131
Bank::poke
virtual void poke(uint_least16_t address, uint8_t value)=0
SystemRAMBank::poke
void poke(uint_least16_t address, uint8_t value)
Definition: SystemRAMBank.h:61
MMU::readMemWord
uint_least16_t readMemWord(uint_least16_t addr)
Definition: mmu.h:96
MMU::writeMemByte
void writeMemByte(uint_least16_t addr, uint8_t value)
Definition: mmu.h:98
EventContext
Definition: event.h:107
ZeroRAMBank
Definition: ZeroRAMBank.h:60
MMU::fillRam
void fillRam(uint_least16_t start, const uint8_t *source, unsigned int size)
Definition: mmu.h:105
MMU::cpuRead
uint8_t cpuRead(uint_least16_t addr) const
Definition: mmu.h:123
MMU::installResetHook
void installResetHook(uint_least16_t addr)
Definition: mmu.h:111
PLA
Definition: ZeroRAMBank.h:35
EventContext::getTime
virtual event_clock_t getTime(event_phase_t phase) const =0
sidmemory
Definition: sidmemory.h:30
SystemRAMBank::peek
uint8_t peek(uint_least16_t address)
Definition: SystemRAMBank.h:56
MMU::writeMemWord
void writeMemWord(uint_least16_t addr, uint_least16_t value)
Definition: mmu.h:99
MMU
Definition: mmu.h:43
Bank::peek
virtual uint8_t peek(uint_least16_t address)=0
BasicRomBank::installTrap
void installTrap(uint_least16_t addr)
Definition: SystemROMBanks.h:219
KernalRomBank
Definition: SystemROMBanks.h:77
IOBank
Definition: IOBank.h:36