Refactor Z80Card as a class

This commit is contained in:
tomcw 2023-01-28 19:58:12 +00:00
parent 3abf0c1753
commit f73f23c1c7
6 changed files with 66 additions and 49 deletions

View File

@ -34,6 +34,7 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
#include "SerialComms.h"
#include "SNESMAX.h"
#include "VidHD.h"
#include "z80emu.h"
#include <sstream>
@ -70,10 +71,7 @@ void DummyCard::InitializeIO(LPBYTE pCxRomPeripheral)
switch (QueryType())
{
case CT_GenericClock:
break; // nothing to do
case CT_Z80:
Z80_InitializeIO(pCxRomPeripheral, m_slot);
break;
case CT_Echo:
default:
_ASSERT(0);
}
@ -83,8 +81,8 @@ void DummyCard::Update(const ULONG nExecutedCycles)
{
switch (QueryType())
{
case CT_Z80:
break; // nothing to do
case CT_GenericClock:
case CT_Echo:
default:
_ASSERT(0);
break;
@ -95,8 +93,8 @@ void DummyCard::SaveSnapshot(YamlSaveHelper& yamlSaveHelper)
{
switch (QueryType())
{
case CT_Z80:
Z80_SaveSnapshot(yamlSaveHelper, m_slot);
case CT_GenericClock:
case CT_Echo:
default:
_ASSERT(0);
break;
@ -107,8 +105,8 @@ bool DummyCard::LoadSnapshot(YamlLoadHelper& yamlLoadHelper, UINT version)
{
switch (QueryType())
{
case CT_Z80:
return Z80_LoadSnapshot(yamlLoadHelper, m_slot, version);
case CT_GenericClock:
case CT_Echo:
default:
_ASSERT(0);
}
@ -145,7 +143,7 @@ std::string Card::GetCardName(const SS_CARDTYPE cardType)
case CT_MouseInterface:
return CMouseInterface::GetSnapshotCardName();
case CT_Z80:
return Z80_GetSnapshotCardName();
return Z80Card::GetSnapshotCardName();
case CT_Phasor:
return MockingboardCard::GetSnapshotCardNamePhasor();
case CT_Echo:
@ -181,7 +179,7 @@ SS_CARDTYPE Card::GetCardType(const std::string & card)
{
return CT_MouseInterface;
}
else if (card == Z80_GetSnapshotCardName())
else if (card == Z80Card::GetSnapshotCardName())
{
return CT_Z80;
}

View File

@ -47,6 +47,7 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
#include "VidHD.h"
#include "LanguageCard.h"
#include "Memory.h"
#include "z80emu.h"
void CardManager::InsertInternal(UINT slot, SS_CARDTYPE type)
{
@ -85,7 +86,9 @@ void CardManager::InsertInternal(UINT slot, SS_CARDTYPE type)
m_slot[slot] = m_pMouseCard = new CMouseInterface(slot);
break;
case CT_Z80:
m_slot[slot] = new DummyCard(type, slot);
_ASSERT(m_pZ80Card == NULL);
if (m_pZ80Card) break; // Only support one Z80 card
m_slot[slot] = new Z80Card(slot);
break;
case CT_Phasor:
m_slot[slot] = new MockingboardCard(slot, type);

View File

@ -12,7 +12,8 @@ public:
m_pMouseCard(NULL),
m_pSSC(NULL),
m_pLanguageCard(NULL),
m_pParallelPrinterCard(NULL)
m_pParallelPrinterCard(NULL),
m_pZ80Card(NULL)
{
InsertInternal(SLOT0, CT_Empty);
InsertInternal(SLOT1, CT_GenericPrinter);
@ -82,4 +83,5 @@ private:
class CSuperSerialCard* m_pSSC;
class LanguageCardUnit* m_pLanguageCard;
class ParallelPrinterCard* m_pParallelPrinterCard;
class m_pZ80Card* m_pZ80Card;
};

View File

@ -43,5 +43,8 @@ DWORD z80_mainloop(ULONG uTotalCycles, ULONG uExecutedCycles);
BYTE z80_RDMEM(WORD Addr);
void z80_WRMEM(WORD Addr, BYTE Value);
#endif
const std::string& Z80_GetSnapshotCardName(void);
void Z80_SaveSnapshot(class YamlSaveHelper& yamlSaveHelper, const UINT uSlot);
bool Z80_LoadSnapshot(class YamlLoadHelper& yamlLoadHelper, UINT uSlot, UINT version);
#endif

View File

@ -18,30 +18,39 @@
#include "z80emu.h"
#include "CPU.h"
#include "Memory.h"
#include "Z80VICE/z80.h"
// Variaveis
static int g_uCPMZ80Slot = 0;
BYTE __stdcall CPMZ80_IONull(WORD PC, WORD uAddr, BYTE bWrite, BYTE uValue, ULONG nExecutedCycles)
BYTE __stdcall Z80Card::IOWrite(WORD pc, WORD addr, BYTE bWrite, BYTE value, ULONG nExecutedCycles)
{
return IO_Null(PC, uAddr, bWrite, uValue, nExecutedCycles);
}
const UINT slot = (addr >> 8) & 0x7;
BYTE __stdcall CPMZ80_IOWrite(WORD PC, WORD uAddr, BYTE bWrite, BYTE uValue, ULONG nExecutedCycles)
{
if ((uAddr & 0xFF00) == (0xC000 + (g_uCPMZ80Slot << 8)))
if ((addr & 0xFF00) == (0xC000 + (slot << 8)))
SetActiveCpu( GetActiveCpu() == CPU_Z80 ? GetMainCpu() : CPU_Z80 );
return IO_Null(PC, uAddr, bWrite, uValue, nExecutedCycles);
return IO_Null(pc, addr, bWrite, value, nExecutedCycles);
}
void Z80Card::InitializeIO(LPBYTE pCxRomPeripheral)
{
memset(pCxRomPeripheral + (m_slot << 8), 0xFF, APPLE_SLOT_SIZE);
RegisterIoHandler(m_slot, IO_Null, IO_Null, IO_Null, &Z80Card::IOWrite, this, NULL);
}
//===========================================================================
void Z80_InitializeIO(LPBYTE pCxRomPeripheral, UINT uSlot)
{
memset(pCxRomPeripheral + (uSlot << 8), 0xFF, APPLE_SLOT_SIZE);
g_uCPMZ80Slot = uSlot;
RegisterIoHandler(uSlot, CPMZ80_IONull, CPMZ80_IONull, CPMZ80_IONull, CPMZ80_IOWrite, NULL, NULL);
const std::string& Z80Card::GetSnapshotCardName(void)
{
return Z80_GetSnapshotCardName();
}
void Z80Card::SaveSnapshot(YamlSaveHelper& yamlSaveHelper)
{
return Z80_SaveSnapshot(yamlSaveHelper, m_slot);
}
bool Z80Card::LoadSnapshot(YamlLoadHelper& yamlLoadHelper, UINT version)
{
return Z80_LoadSnapshot(yamlLoadHelper, m_slot, version);
}

View File

@ -1,23 +1,25 @@
#pragma once
/* Emulador do computador TK3000 //e (Microdigital)
* por Fábio Belavenuto - Copyright (C) 2004
*
* Adaptado do emulador Applewin por Michael O'Brien
*
* Este arquivo é distribuido pela Licença Pública Geral GNU.
* Veja o arquivo Licenca.txt distribuido com este software.
*
* ESTE SOFTWARE NÃO OFERECE NENHUMA GARANTIA
*
*/
#include "Card.h"
// Emula a CPU Z80
class Z80Card : public Card
{
public:
Z80Card(UINT slot) :
Card(CT_Z80, slot)
{
}
virtual ~Z80Card(void) {}
// Protótipos
void Z80_InitializeIO(LPBYTE pCxRomPeripheral, UINT uSlot);
virtual void Destroy(void) {}
virtual void Reset(const bool powerCycle) {}
virtual void Update(const ULONG nExecutedCycles) {}
// NB. These are in z80.cpp:
const std::string& Z80_GetSnapshotCardName(void);
void Z80_SaveSnapshot(class YamlSaveHelper& yamlSaveHelper, const UINT uSlot);
bool Z80_LoadSnapshot(class YamlLoadHelper& yamlLoadHelper, UINT uSlot, UINT version);
virtual void InitializeIO(LPBYTE pCxRomPeripheral);
static BYTE __stdcall IOWrite(WORD pc, WORD addr, BYTE bWrite, BYTE value, ULONG nExecutedCycles);
static const std::string& GetSnapshotCardName(void);
virtual void SaveSnapshot(YamlSaveHelper& yamlSaveHelper);
virtual bool LoadSnapshot(YamlLoadHelper& yamlLoadHelper, UINT version);
};