Refactor: Removed unused vars from Memory.cpp. Also change Disk][ I/O regs to return floating bus.

This commit is contained in:
tomcw 2014-09-28 22:04:12 +01:00
parent 1566aa50d5
commit 8fac75322a
3 changed files with 55 additions and 199 deletions

View File

@ -415,16 +415,16 @@ void DiskBoot(void)
//===========================================================================
static BYTE __stdcall DiskControlMotor(WORD, WORD address, BYTE, BYTE, ULONG)
static BYTE __stdcall DiskControlMotor(WORD, WORD address, BYTE, BYTE, ULONG uExecutedCycles)
{
floppymotoron = address & 1;
CheckSpinning();
return MemReturnRandomData(1);
return MemReadFloatingBus(1, uExecutedCycles); // TC-TODO: Check b7 always set
}
//===========================================================================
static BYTE __stdcall DiskControlStepper(WORD, WORD address, BYTE, BYTE, ULONG)
static BYTE __stdcall DiskControlStepper(WORD, WORD address, BYTE, BYTE, ULONG uExecutedCycles)
{
Disk_t * fptr = &g_aFloppyDisk[currdrive];
#if 1
@ -501,7 +501,8 @@ static BYTE __stdcall DiskControlStepper(WORD, WORD address, BYTE, BYTE, ULONG)
}
}
#endif
return (address == 0xE0) ? 0xFF : MemReturnRandomData(1);
return ((address & 0xF) == 0) ? 0xFF // TC-TODO: Check why $C0E0 only returns 0xFF
: MemReadFloatingBus(1, uExecutedCycles); // TC-TODO: Check b7 always set
}
//===========================================================================
@ -519,13 +520,13 @@ void DiskDestroy(void)
//===========================================================================
static BYTE __stdcall DiskEnable(WORD, WORD address, BYTE, BYTE, ULONG)
static BYTE __stdcall DiskEnable(WORD, WORD address, BYTE, BYTE, ULONG uExecutedCycles)
{
currdrive = address & 1;
g_aFloppyDisk[!currdrive].spinning = 0;
g_aFloppyDisk[!currdrive].writelight = 0;
CheckSpinning();
return 0;
return MemReadFloatingBus(uExecutedCycles);
}
//===========================================================================
@ -902,7 +903,8 @@ void DiskSelect(const int iDrive)
//===========================================================================
static BYTE __stdcall DiskSetLatchValue(WORD, WORD, BYTE write, BYTE value, ULONG) {
static BYTE __stdcall DiskSetLatchValue(WORD, WORD, BYTE write, BYTE value, ULONG)
{
if (write)
floppylatch = value;
return floppylatch;
@ -910,15 +912,15 @@ static BYTE __stdcall DiskSetLatchValue(WORD, WORD, BYTE write, BYTE value, ULON
//===========================================================================
static BYTE __stdcall DiskSetReadMode(WORD, WORD, BYTE, BYTE, ULONG)
static BYTE __stdcall DiskSetReadMode(WORD, WORD, BYTE, BYTE, ULONG uExecutedCycles)
{
floppywritemode = 0;
return MemReturnRandomData(g_aFloppyDisk[currdrive].bWriteProtected);
return MemReadFloatingBus(g_aFloppyDisk[currdrive].bWriteProtected, uExecutedCycles);
}
//===========================================================================
static BYTE __stdcall DiskSetWriteMode(WORD, WORD, BYTE, BYTE, ULONG)
static BYTE __stdcall DiskSetWriteMode(WORD, WORD, BYTE, BYTE, ULONG uExecutedCycles)
{
floppywritemode = 1;
BOOL modechange = !g_aFloppyDisk[currdrive].writelight;
@ -928,7 +930,8 @@ static BYTE __stdcall DiskSetWriteMode(WORD, WORD, BYTE, BYTE, ULONG)
//FrameRefreshStatus(DRAW_LEDS);
FrameDrawDiskLEDS( (HDC)0 );
}
return MemReturnRandomData(1);
return MemReadFloatingBus(1, uExecutedCycles); // TC-TODO: Check b7 always set
}
//===========================================================================

View File

@ -162,7 +162,6 @@ SOFT SWITCH STATUS FLAGS
// . memshadow[1] = &memaux[0x0100]
//
//static DWORD imagemode;
static LPBYTE memshadow[0x100];
LPBYTE memwrite[0x100];
@ -170,9 +169,6 @@ iofunction IORead[256];
iofunction IOWrite[256];
static LPVOID SlotParameters[NUM_SLOTS];
//static BOOL fastpaging = 0; // Redundant: only ever set to 0, by MemSetFastPaging(0)
//static DWORD image = 0;
//static DWORD lastimage = 0;
static BOOL lastwriteram = 0;
LPBYTE mem = NULL;
@ -202,7 +198,7 @@ static LPBYTE RWpages[128]; // pointers to RW memory banks
#endif
BYTE __stdcall IO_Annunciator(WORD programcounter, WORD address, BYTE write, BYTE value, ULONG nCycles);
void UpdatePaging(BOOL initialize, BOOL updatewriteonly);
void UpdatePaging(BOOL initialize);
//=============================================================================
@ -818,66 +814,25 @@ static void SetMemMode(const DWORD uNewMemMode)
//===========================================================================
void ResetPaging (BOOL initialize)
static void ResetPaging(BOOL initialize)
{
//if (!initialize)
// MemSetFastPaging(0);
lastwriteram = 0;
SetMemMode(MF_BANK2 | MF_SLOTCXROM | MF_WRITERAM);
UpdatePaging(initialize, 0);
UpdatePaging(initialize);
}
//===========================================================================
//void UpdateFastPaging () {
// BOOL found = 0;
// DWORD imagenum = 0;
// do
// if ((imagemode[imagenum] == memmode) ||
// ((lastimage >= 3) &&
// ((imagemode[imagenum] & MF_IMAGEMASK) == (memmode & MF_IMAGEMASK))))
// found = 1;
// else
// ++imagenum;
// while ((imagenum <= lastimage) && !found);
// if (found) {
// image = imagenum;
// mem = memimage+(image << 16);
// if (imagemode[image] != memmode) {
// imagemode[image] = memmode;
// UpdatePaging(0,1);
// }
// }
// else {
// if (lastimage < MAXIMAGES-1) {
// imagenum = ++lastimage;
// if (lastimage >= 3)
// VirtualAlloc(memimage+lastimage*0x10000,0x10000,MEM_COMMIT,PAGE_READWRITE);
// }
// else {
// static DWORD nextimage = 0;
// if (nextimage > lastimage)
// nextimage = 0;
// imagenum = nextimage++;
// }
// imagemode[image = imagenum] = memmode;
// mem = memimage+(image << 16);
// UpdatePaging(1,0);
// }
//}
//===========================================================================
void MemUpdatePaging(BOOL initialize)
{
UpdatePaging(initialize, 0);
UpdatePaging(initialize);
}
static void UpdatePaging (BOOL initialize, BOOL updatewriteonly /*Always zero*/)
static void UpdatePaging(BOOL initialize)
{
// SAVE THE CURRENT PAGING SHADOW TABLE
LPBYTE oldshadow[256];
if (!(initialize /*|| updatewriteonly*/ /*|| fastpaging*/ ))
if (!initialize)
CopyMemory(oldshadow,memshadow,256*sizeof(LPBYTE));
// UPDATE THE PAGING TABLES BASED ON THE NEW PAGING SWITCH VALUES
@ -891,11 +846,8 @@ static void UpdatePaging (BOOL initialize, BOOL updatewriteonly /*Always zero*/)
memwrite[loop] = NULL;
}
//if (!updatewriteonly)
{
for (loop = 0x00; loop < 0x02; loop++)
memshadow[loop] = SW_ALTZP ? memaux+(loop << 8) : memmain+(loop << 8);
}
for (loop = 0x00; loop < 0x02; loop++)
memshadow[loop] = SW_ALTZP ? memaux+(loop << 8) : memmain+(loop << 8);
for (loop = 0x02; loop < 0xC0; loop++)
{
@ -908,24 +860,21 @@ static void UpdatePaging (BOOL initialize, BOOL updatewriteonly /*Always zero*/)
: memmain+(loop << 8);
}
//if (!updatewriteonly)
for (loop = 0xC0; loop < 0xC8; loop++)
{
for (loop = 0xC0; loop < 0xC8; loop++)
{
const UINT uSlotOffset = (loop & 0x0f) * 0x100;
if (loop == 0xC3)
memshadow[loop] = (SW_SLOTC3ROM && SW_SLOTCXROM) ? pCxRomPeripheral+uSlotOffset // C300..C3FF - Slot 3 ROM (all 0x00's)
: pCxRomInternal+uSlotOffset; // C300..C3FF - Internal ROM
else
memshadow[loop] = SW_SLOTCXROM ? pCxRomPeripheral+uSlotOffset // C000..C7FF - SSC/Disk][/etc
: pCxRomInternal+uSlotOffset; // C000..C7FF - Internal ROM
}
const UINT uSlotOffset = (loop & 0x0f) * 0x100;
if (loop == 0xC3)
memshadow[loop] = (SW_SLOTC3ROM && SW_SLOTCXROM) ? pCxRomPeripheral+uSlotOffset // C300..C3FF - Slot 3 ROM (all 0x00's)
: pCxRomInternal+uSlotOffset; // C300..C3FF - Internal ROM
else
memshadow[loop] = SW_SLOTCXROM ? pCxRomPeripheral+uSlotOffset // C000..C7FF - SSC/Disk][/etc
: pCxRomInternal+uSlotOffset; // C000..C7FF - Internal ROM
}
for (loop = 0xC8; loop < 0xD0; loop++)
{
const UINT uRomOffset = (loop & 0x0f) * 0x100;
memshadow[loop] = pCxRomInternal+uRomOffset; // C800..CFFF - Internal ROM
}
for (loop = 0xC8; loop < 0xD0; loop++)
{
const UINT uRomOffset = (loop & 0x0f) * 0x100;
memshadow[loop] = pCxRomInternal+uRomOffset; // C800..CFFF - Internal ROM
}
for (loop = 0xD0; loop < 0xE0; loop++)
@ -981,24 +930,20 @@ static void UpdatePaging (BOOL initialize, BOOL updatewriteonly /*Always zero*/)
// . Page0 (ZP) : memdirty[0] is set when the 6502 CPU does a ZP-write, but perhaps older versions didn't set this flag (eg. the asm version?).
// . Page1 (stack) : memdirty[1] is NOT set when the 6502 CPU writes to this page with JSR, etc.
//if (!updatewriteonly)
for (loop = 0x00; loop < 0x100; loop++)
{
for (loop = 0x00; loop < 0x100; loop++)
if (initialize || (oldshadow[loop] != memshadow[loop]))
{
if (initialize || (oldshadow[loop] != memshadow[loop]))
if (!initialize &&
((*(memdirty+loop) & 1) || (loop <= 1)))
{
if ((!(initialize/* || fastpaging*/)) &&
((*(memdirty+loop) & 1) || (loop <= 1)))
{
*(memdirty+loop) &= ~1;
CopyMemory(oldshadow[loop],mem+(loop << 8),256);
}
CopyMemory(mem+(loop << 8),memshadow[loop],256);
*(memdirty+loop) &= ~1;
CopyMemory(oldshadow[loop],mem+(loop << 8),256);
}
CopyMemory(mem+(loop << 8),memshadow[loop],256);
}
}
}
//
@ -1008,7 +953,7 @@ static void UpdatePaging (BOOL initialize, BOOL updatewriteonly /*Always zero*/)
//===========================================================================
// TODO: >= Apple2e only?
BYTE __stdcall MemCheckPaging (WORD, WORD address, BYTE, BYTE, ULONG)
BYTE __stdcall MemCheckPaging(WORD, WORD address, BYTE, BYTE, ULONG)
{
address &= 0xFF;
BOOL result = 0;
@ -1030,12 +975,8 @@ BYTE __stdcall MemCheckPaging (WORD, WORD address, BYTE, BYTE, ULONG)
//===========================================================================
void MemDestroy ()
void MemDestroy()
{
//if (fastpaging)
// MemSetFastPaging(0);
// VirtualFree(memimage,MAX(0x30000,0x10000*1),MEM_DECOMMIT);
VirtualFree(memaux ,0,MEM_RELEASE);
VirtualFree(memmain ,0,MEM_RELEASE);
VirtualFree(memdirty,0,MEM_RELEASE);
@ -1178,10 +1119,6 @@ void MemInitialize()
memmain = (LPBYTE)VirtualAlloc(NULL,_6502_MEM_END+1,MEM_COMMIT,PAGE_READWRITE);
memdirty = (LPBYTE)VirtualAlloc(NULL,0x100 ,MEM_COMMIT,PAGE_READWRITE);
memrom = (LPBYTE)VirtualAlloc(NULL,0x5000 ,MEM_COMMIT,PAGE_READWRITE);
// // THE MEMIMAGE BUFFER CAN CONTAIN EITHER MULTIPLE MEMORY IMAGES OR ONE MEMORY IMAGE WITH COMPILER DATA
// memimage = (LPBYTE)VirtualAlloc(NULL,
// MAX(0x30000,MAXIMAGES*0x10000),
// MEM_RESERVE,PAGE_NOACCESS);
memimage = (LPBYTE)VirtualAlloc(NULL,_6502_MEM_END+1,MEM_RESERVE,PAGE_NOACCESS);
pCxRomInternal = (LPBYTE) VirtualAlloc(NULL, CxRomSize, MEM_COMMIT, PAGE_READWRITE);
@ -1198,7 +1135,6 @@ void MemInitialize()
ExitProcess(1);
}
// LPVOID newloc = VirtualAlloc(memimage,0x30000,MEM_COMMIT,PAGE_READWRITE);
LPVOID newloc = VirtualAlloc(memimage,_6502_MEM_END+1,MEM_COMMIT,PAGE_READWRITE);
if (newloc != memimage)
MessageBox(
@ -1376,11 +1312,8 @@ inline DWORD getRandomTime()
// . MemInitialize()
// . ResetMachineState() eg. Power-cycle ('Apple-Go' button)
// . Snapshot_LoadState()
void MemReset ()
void MemReset()
{
//// TURN OFF FAST PAGING IF IT IS CURRENTLY ACTIVE
//MemSetFastPaging(0);
// INITIALIZE THE PAGING TABLES
ZeroMemory(memshadow,256*sizeof(LPBYTE));
ZeroMemory(memwrite ,256*sizeof(LPBYTE));
@ -1511,11 +1444,10 @@ void MemReset ()
memmain[ 0xBFFF ] = 0;
// SET UP THE MEMORY IMAGE
mem = memimage;
//image = 0;
mem = memimage;
// INITIALIZE PAGING, FILLING IN THE 64K MEMORY IMAGE
ResetPaging(1);
ResetPaging(1); // Initialize=1
// INITIALIZE & RESET THE CPU
// . Do this after ROM has been copied back to mem[], so that PC is correctly init'ed from 6502's reset vector
@ -1530,9 +1462,9 @@ void MemReset ()
// Call by:
// . Soft-reset (Ctrl+Reset)
// . Snapshot_LoadState()
void MemResetPaging ()
void MemResetPaging()
{
ResetPaging(0);
ResetPaging(0); // Initialize=0
if (g_Apple2Type == A2TYPE_PRAVETS8A)
{
P8CAPS_ON = false;
@ -1543,21 +1475,6 @@ void MemResetPaging ()
//===========================================================================
// Called by Disk][ I/O only
BYTE MemReturnRandomData(BYTE highbit)
{
static const BYTE retval[16] = {
0x00,0x2D,0x2D,0x30,0x30,0x32,0x32,0x34,
0x35,0x39,0x43,0x43,0x43,0x60,0x7F,0x7F };
BYTE r = (BYTE)(rand() & 0xFF);
if (r <= 170)
return 0x20 | (highbit ? 0x80 : 0);
else
return retval[r & 15] | (highbit ? 0x80 : 0);
}
//===========================================================================
BYTE MemReadFloatingBus(const ULONG uExecutedCycles)
{
return*(LPBYTE)(mem + VideoGetScannerAddress(NULL, uExecutedCycles));
@ -1571,26 +1488,6 @@ BYTE MemReadFloatingBus(const BYTE highbit, const ULONG uExecutedCycles)
return (r & ~0x80) | ((highbit) ? 0x80 : 0);
}
//===========================================================================
//void MemSetFastPaging (BOOL on) {
// if (fastpaging && modechanging) {
// modechanging = 0;
// UpdateFastPaging();
// }
// else if (!fastpaging) {
// BackMainImage();
// if (lastimage >= 3)
// VirtualFree(memimage+0x30000,(lastimage-2) << 16,MEM_DECOMMIT);
// }
// fastpaging = on;
// image = 0;
// mem = memimage;
// lastimage = 0;
// imagemode[0] = memmode;
// if (!fastpaging)
// UpdatePaging(1,0);
//}
//===========================================================================
//#define DEBUG_FLIP_TIMINGS
@ -1625,7 +1522,7 @@ static void DebugFlip(WORD address, ULONG nCyclesLeft)
}
#endif
BYTE __stdcall MemSetPaging (WORD programcounter, WORD address, BYTE write, BYTE value, ULONG nCyclesLeft)
BYTE __stdcall MemSetPaging(WORD programcounter, WORD address, BYTE write, BYTE value, ULONG nCyclesLeft)
{
address &= 0xFF;
DWORD lastmemmode = memmode;
@ -1673,12 +1570,7 @@ BYTE __stdcall MemSetPaging (WORD programcounter, WORD address, BYTE write, BYTE
if ((value < g_uMaxExPages) && RWpages[value])
{
memaux = RWpages[value];
//memmode &= ~MF_RWPMASK;
//memmode |= value;
//if (fastpaging)
// UpdateFastPaging();
//else
UpdatePaging(0,0);
UpdatePaging(0); // Initialize=0
}
break;
#endif
@ -1732,17 +1624,7 @@ BYTE __stdcall MemSetPaging (WORD programcounter, WORD address, BYTE write, BYTE
}
}
//// IF FAST PAGING IS ACTIVE, WE KEEP MULTIPLE COMPLETE MEMORY IMAGES
//// AND WRITE TABLES, AND SWITCH BETWEEN THEM. THE FAST PAGING VERSION
//// OF THE CPU EMULATOR KEEPS ALL OF THE IMAGES COHERENT.
//if (fastpaging)
// UpdateFastPaging();
// IF FAST PAGING IS NOT ACTIVE THEN WE KEEP ONLY ONE MEMORY IMAGE AND
// WRITE TABLE, AND UPDATE THEM EVERY TIME PAGING IS CHANGED.
//else
UpdatePaging(0,0);
UpdatePaging(0); // Initialize=0
}
if ((address <= 1) || ((address >= 0x54) && (address <= 0x57)))
@ -1752,36 +1634,8 @@ BYTE __stdcall MemSetPaging (WORD programcounter, WORD address, BYTE write, BYTE
}
//===========================================================================
//void MemTrimImages () {
// if (fastpaging && (lastimage > 2))
// {
// if (modechanging) {
// modechanging = 0;
// UpdateFastPaging();
// }
// static DWORD trimnumber = 0;
// if ((image != trimnumber) &&
// (image != lastimage) &&
// (trimnumber < lastimage)) {
// imagemode[trimnumber] = imagemode[lastimage];
// VirtualFree(memimage+(lastimage-- << 16),0x10000,MEM_DECOMMIT);
// DWORD realimage = image;
// image = trimnumber;
// mem = memimage+(image << 16);
// memmode = imagemode[image];
// UpdatePaging(1,0);
// image = realimage;
// mem = memimage+(image << 16);
// memmode = imagemode[image];
// }
// if (++trimnumber >= lastimage)
// trimnumber = 0;
// }
//}
//===========================================================================
LPVOID MemGetSlotParameters (UINT uSlot)
LPVOID MemGetSlotParameters(UINT uSlot)
{
_ASSERT(uSlot < NUM_SLOTS);
return SlotParameters[uSlot];
@ -1820,7 +1674,7 @@ DWORD MemSetSnapshot(SS_BaseMemory* pSS)
modechanging = 0;
UpdatePaging(1,0); // Initialize=1, UpdateWriteOnly=0
UpdatePaging(1); // Initialize=1
return 0;
}

View File

@ -49,7 +49,6 @@ BYTE MemReadFloatingBus(const BYTE highbit, const ULONG uExecutedCycles);
void MemReset ();
void MemResetPaging ();
void MemUpdatePaging(BOOL initialize);
BYTE MemReturnRandomData (BYTE highbit);
LPVOID MemGetSlotParameters (UINT uSlot);
DWORD MemGetSnapshot(SS_BaseMemory* pSS);
DWORD MemSetSnapshot(SS_BaseMemory* pSS);