Added AY38912 support
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
using System;
|
||||
using Core.Interfaces;
|
||||
using Core.Interfaces;
|
||||
using System;
|
||||
using System.Diagnostics;
|
||||
|
||||
namespace Core.Memory
|
||||
{
|
||||
@@ -46,6 +47,7 @@ namespace Core.Memory
|
||||
// Called by the IO Bus when the CPU writes to a paging port
|
||||
public void HandlePaging(ushort port, byte value)
|
||||
{
|
||||
Debug.WriteLine($"[PAGING] 0x7FFD Triggered! Hex: 0x{value:X2} | Bank: {value & 0x07}");
|
||||
if (_pagingDisabled || _currentRomBank == 4) return; // Ignore if locked or in 48K mode
|
||||
|
||||
if (port == 0x7FFD)
|
||||
@@ -65,33 +67,62 @@ namespace Core.Memory
|
||||
_currentRomBank = (romHigh << 1) | romLow;
|
||||
}
|
||||
|
||||
public byte Read(ushort address)
|
||||
private int GetBankForSlot(int slot)
|
||||
{
|
||||
int slot = address >> 14; // Divide by 16384 to find Slot 0, 1, 2, or 3
|
||||
int offset = address & 0x3FFF; // Find the exact byte inside that 16KB slot
|
||||
// Amstrad +2A / +3 Special Paging Mode
|
||||
bool specialPaging = (_port1FFD & 0x01) != 0;
|
||||
|
||||
if (specialPaging)
|
||||
{
|
||||
// Bits 1 and 2 dictate the specific Special RAM layout
|
||||
int config = (_port1FFD >> 1) & 0x03;
|
||||
switch (config)
|
||||
{
|
||||
case 0: return slot == 0 ? 0 : slot == 1 ? 1 : slot == 2 ? 2 : 3;
|
||||
case 1: return slot == 0 ? 4 : slot == 1 ? 5 : slot == 2 ? 6 : 7;
|
||||
case 2: return slot == 0 ? 4 : slot == 1 ? 5 : slot == 2 ? 6 : 3;
|
||||
case 3: return slot == 0 ? 4 : slot == 1 ? 7 : slot == 2 ? 6 : 3;
|
||||
}
|
||||
}
|
||||
|
||||
// Standard 128K Paging
|
||||
switch (slot)
|
||||
{
|
||||
case 0: return _romBanks[_currentRomBank][offset]; // 0x0000 - 0x3FFF (ROM)
|
||||
case 1: return _ramBanks[5][offset]; // 0x4000 - 0x7FFF (Always RAM 5)
|
||||
case 2: return _ramBanks[2][offset]; // 0x8000 - 0xBFFF (Always RAM 2)
|
||||
case 3: return _ramBanks[_currentRamBankSlot3][offset]; // 0xC000 - 0xFFFF (Switchable RAM)
|
||||
default: return 0xFF;
|
||||
case 1: return 5;
|
||||
case 2: return 2;
|
||||
case 3: return _currentRamBankSlot3;
|
||||
default: return -1; // -1 means it is pointing to a ROM chip!
|
||||
}
|
||||
}
|
||||
public byte Read(ushort address)
|
||||
{
|
||||
int slot = address >> 14; // Find the 16KB Slot (0, 1, 2, or 3)
|
||||
int offset = address & 0x3FFF;
|
||||
|
||||
int bank = GetBankForSlot(slot);
|
||||
|
||||
if (bank == -1)
|
||||
{
|
||||
return _romBanks[_currentRomBank][offset];
|
||||
}
|
||||
else
|
||||
{
|
||||
return _ramBanks[bank][offset];
|
||||
}
|
||||
}
|
||||
|
||||
public void Write(ushort address, byte value)
|
||||
{
|
||||
if (address < 0x4000) return; // Cannot write to ROM
|
||||
|
||||
int slot = address >> 14;
|
||||
int offset = address & 0x3FFF;
|
||||
|
||||
switch (slot)
|
||||
int bank = GetBankForSlot(slot);
|
||||
|
||||
// If the bank is NOT a ROM chip, we are allowed to write to it!
|
||||
// (This allows the BIOS to write to 0x0000 during the self-test)
|
||||
if (bank != -1)
|
||||
{
|
||||
case 1: _ramBanks[5][offset] = value; break;
|
||||
case 2: _ramBanks[2][offset] = value; break;
|
||||
case 3: _ramBanks[_currentRamBankSlot3][offset] = value; break;
|
||||
_ramBanks[bank][offset] = value;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user