some more refactoring

This commit is contained in:
thrust26 2017-11-28 22:00:42 +01:00
parent 8d42af251e
commit b3e92842e5
6 changed files with 79 additions and 56 deletions

View File

@ -43,5 +43,12 @@ void CartridgeE7::checkSwitchBank(uInt16 address)
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
uInt16 CartridgeE7::bankCount() const
{
return 8;
return BANK_COUNT;
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
uInt32 CartridgeE7::romSize()
{
return bankCount() * BANK_SIZE;
}

View File

@ -71,11 +71,21 @@ class CartridgeE7 : public CartridgeMNetwork
#endif
private:
/**
Query the size of the BS type.
*/
uInt32 romSize();
/**
Check hotspots and switch bank if triggered.
*/
void checkSwitchBank(uInt16 address) override;
// Number of banks
static const uInt32 BANK_COUNT = 8;
// Size of ROM
static const uInt32 ROM_SIZE = BANK_COUNT * BANK_SIZE;
private:
// Following constructors and assignment operators not supported
CartridgeE7() = delete;

View File

@ -43,5 +43,12 @@ void CartridgeE78K::checkSwitchBank(uInt16 address)
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
uInt16 CartridgeE78K::bankCount() const
{
return 4;
return BANK_COUNT;
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
uInt32 CartridgeE78K::romSize()
{
return bankCount() * BANK_SIZE;
}

View File

@ -69,11 +69,20 @@ class CartridgeE78K : public CartridgeMNetwork
#endif
private:
/**
Query the size of the BS type.
*/
uInt32 romSize();
/**
Check hotspots and switch bank if triggered.
*/
void checkSwitchBank(uInt16 address) override;
// Number of banks
static const uInt32 BANK_COUNT = 4;
// Size of ROM
static const uInt32 ROM_SIZE = BANK_COUNT * BANK_SIZE;
private:
// Following constructors and assignment operators not supported
CartridgeE78K() = delete;

View File

@ -28,8 +28,8 @@ CartridgeMNetwork::CartridgeMNetwork(const BytePtr& image, uInt32 size,
void CartridgeMNetwork::initialize(const BytePtr& image, uInt32 size)
{
// Copy the ROM image into my buffer
memcpy(myImage, image.get(), std::min(bankCount() * BANK_SIZE, size));
createCodeAccessBase(bankCount() * BANK_SIZE + RAM_SIZE);
memcpy(myImage, image.get(), std::min(romSize(), size));
createCodeAccessBase(romSize() + RAM_SIZE);
// Remember startup bank
myStartBank = 0;
@ -48,6 +48,25 @@ void CartridgeMNetwork::reset()
myBankChanged = true;
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
void CartridgeMNetwork::setAccess(uInt16 addrFrom, uInt16 size, uInt16 directOffset, uInt8* directData,
uInt16 codeOffset, System::PageAccessType type, uInt16 addrMask)
{
if(addrMask == 0)
addrMask = size - 1;
System::PageAccess access(this, type);
for(uInt16 addr = addrFrom; addr < addrFrom + size; addr += System::PAGE_SIZE)
{
if (type == System::PA_READ)
access.directPeekBase = &directData[directOffset + (addr & addrMask)];
if(type == System::PA_WRITE)
access.directPokeBase = &directData[directOffset + (addr & addrMask)];
access.codeAccessBase = &myCodeAccessBase[codeOffset + (addr & addrMask)];
mySystem->setPageAccess(addr, access);
}
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
void CartridgeMNetwork::install(System& system)
{
@ -64,13 +83,8 @@ void CartridgeMNetwork::install(System& system)
}
// Setup the second segment to always point to the last ROM slice
for(uInt16 addr = 0x1A00; addr < (0x1FE0U & ~System::PAGE_MASK);
addr += System::PAGE_SIZE)
{
access.directPeekBase = &myImage[myRAMSlice * BANK_SIZE + (addr & (BANK_SIZE-1))];
access.codeAccessBase = &myCodeAccessBase[myRAMSlice * BANK_SIZE + (addr & (BANK_SIZE-1))];
mySystem->setPageAccess(addr, access);
}
setAccess(0x1A00, 0x1FE0U & ~System::PAGE_MASK - 0x1A00,
myRAMSlice * BANK_SIZE, myImage, myRAMSlice * BANK_SIZE, System::PA_READ, BANK_SIZE - 1);
myCurrentSlice[1] = myRAMSlice;
// Install some default banks for the RAM and first segment
@ -141,25 +155,11 @@ void CartridgeMNetwork::bankRAM(uInt16 bank)
uInt16 offset = bank << 8; // * RAM_SLICE_SIZE (256)
// Setup the page access methods for the current bank
System::PageAccess access(this, System::PA_WRITE);
// Set the page accessing method for the 256 bytes of RAM writing pages
for(uInt16 addr = 0x1800; addr < 0x1900; addr += System::PAGE_SIZE)
{
access.directPokeBase = &myRAM[1024 + offset + (addr & 0x00FF)];
access.codeAccessBase = &myCodeAccessBase[bankCount() * BANK_SIZE + BANK_SIZE / 2 + offset + (addr & 0x00FF)];
mySystem->setPageAccess(addr, access);
}
// Set the page accessing method for the 256 bytes of RAM reading pages
access.directPokeBase = nullptr;
access.type = System::PA_READ;
for(uInt16 addr = 0x1900; addr < 0x1A00; addr += System::PAGE_SIZE)
{
access.directPeekBase = &myRAM[1024 + offset + (addr & 0x00FF)];
access.codeAccessBase = &myCodeAccessBase[bankCount() * BANK_SIZE + BANK_SIZE / 2 + offset + (addr & 0x00FF)];
mySystem->setPageAccess(addr, access);
}
setAccess(0x1800, 0x100, 1024 + offset, myRAM, romSize() + BANK_SIZE / 2, System::PA_WRITE);
// Set the page accessing method for the 256 bytes of RAM reading pages
setAccess(0x1900, 0x100, 1024 + offset, myRAM, romSize() + BANK_SIZE / 2, System::PA_READ);
myBankChanged = true;
}
@ -170,42 +170,21 @@ bool CartridgeMNetwork::bank(uInt16 slice)
// Remember what bank we're in
myCurrentSlice[0] = slice;
uInt16 offset = slice << 11; // * BANK_SIZE (2048)
// Setup the page access methods for the current bank
if(slice != myRAMSlice)
{
System::PageAccess access(this, System::PA_READ);
uInt16 offset = slice << 11; // * BANK_SIZE (2048)
// Map ROM image into first segment
for(uInt16 addr = 0x1000; addr < 0x1000 + BANK_SIZE; addr += System::PAGE_SIZE)
{
access.directPeekBase = &myImage[offset + (addr & (BANK_SIZE - 1))];
access.codeAccessBase = &myCodeAccessBase[offset + (addr & (BANK_SIZE - 1))];
mySystem->setPageAccess(addr, access);
}
setAccess(0x1000, BANK_SIZE, offset, myImage, offset, System::PA_READ);
}
else
{
System::PageAccess access(this, System::PA_WRITE);
// Set the page accessing method for the 1K slice of RAM writing pages
for(uInt16 addr = 0x1000; addr < 0x1000 + BANK_SIZE / 2; addr += System::PAGE_SIZE)
{
access.directPokeBase = &myRAM[addr & (BANK_SIZE/2-1)];
access.codeAccessBase = &myCodeAccessBase[bankCount() * BANK_SIZE + (addr & (BANK_SIZE / 2 - 1))];
mySystem->setPageAccess(addr, access);
}
setAccess(0x1000, BANK_SIZE / 2, 0, myRAM, romSize(), System::PA_WRITE);
// Set the page accessing method for the 1K slice of RAM reading pages
access.directPokeBase = nullptr;
access.type = System::PA_READ;
for(uInt16 addr = 0x1000 + BANK_SIZE / 2; addr < 0x1000 + BANK_SIZE; addr += System::PAGE_SIZE)
{
access.directPeekBase = &myRAM[addr & (BANK_SIZE / 2 - 1)];
access.codeAccessBase = &myCodeAccessBase[bankCount() * BANK_SIZE + (addr & (BANK_SIZE / 2 - 1))];
mySystem->setPageAccess(addr, access);
}
setAccess(0x1000 + BANK_SIZE / 2, BANK_SIZE / 2, 0, myRAM, romSize(), System::PA_READ);
}
return myBankChanged = true;
}

View File

@ -21,6 +21,8 @@
class System;
#include "System.hxx"
#include "bspf.hxx"
#include "Cart.hxx"
@ -165,19 +167,28 @@ class CartridgeMNetwork : public Cartridge
*/
void bankRAM(uInt16 bank);
private:
// Size of a ROM or RAM bank
static const uInt32 BANK_SIZE = 0x800; // 2K
private:
// Size of RAM in the cart
static const uInt32 RAM_SIZE = 0x800; // 1K + 4 * 256B = 2K
// number of slices with 4K address space
// Number of slices with 4K address space
static const uInt32 NUM_SEGMENTS = 2;
/**
Query the size of the BS type.
*/
virtual uInt32 romSize() = 0;
/**
Check hotspots and switch bank if triggered.
*/
virtual void checkSwitchBank(uInt16 address) = 0;
void setAccess(uInt16 addrFrom, uInt16 size, uInt16 directOffset, uInt8* directData,
uInt16 codeOffset, System::PageAccessType type, uInt16 addrMask = 0);
private:
// The 16K ROM image of the cartridge (works for E78K too)
uInt8 myImage[BANK_SIZE * 8];