[64DD] Swap support

This commit is contained in:
luigiblood 2016-05-25 04:06:10 +02:00
parent a29fb1f92a
commit 810bccc755
7 changed files with 64 additions and 7 deletions

View File

@ -81,6 +81,7 @@ enum LanguageStringID
MENU_RESUME = 132,
MENU_RESET_SOFT = 133, //added in build 1.7.50
MENU_RESET_HARD = 134, //added in build 1.7.50
MENU_SWAPDISK = 135, //added in build 2.2.????
//Options Menu
MENU_OPTIONS = 140,

View File

@ -88,6 +88,7 @@ void CLanguage::LoadDefaultStrings(void)
DEF_STR(MENU_RESUME, "R&esume");
DEF_STR(MENU_RESET_SOFT, "&Soft Reset");
DEF_STR(MENU_RESET_HARD, "&Hard Reset");
DEF_STR(MENU_SWAPDISK, "Swap Disk");
//Options Menu
DEF_STR(MENU_OPTIONS, "&Options");

View File

@ -22,6 +22,8 @@
#include <sys/time.h>
#endif
uint8_t dd_swapdelay;
bool dd_write;
bool dd_reset_hold;
uint32_t dd_track_offset, dd_zone;
@ -29,11 +31,9 @@ uint32_t dd_start_block, dd_current;
void DiskCommand()
{
if (g_Disk != NULL)
g_Reg->ASIC_STATUS |= DD_STATUS_DISK_PRES;
//ASIC_CMD_STATUS - Commands
uint32_t cmd = g_Reg->ASIC_CMD;
WriteTrace(TraceN64System, TraceDebug, "DD CMD %08X", cmd);
#ifdef _WIN32
SYSTEMTIME sysTime;
@ -81,7 +81,9 @@ void DiskCommand()
g_Reg->ASIC_STATUS &= ~DD_STATUS_DISK_CHNG; break;
case 0x00090000:
//Unset Reset Bit
g_Reg->ASIC_STATUS &= ~DD_STATUS_RST_STATE; break;
g_Reg->ASIC_STATUS &= ~DD_STATUS_RST_STATE;
g_Reg->ASIC_STATUS &= ~DD_STATUS_DISK_CHNG;
break;
case 0x00120000:
//RTC Get Year & Month
g_Reg->ASIC_DATA = (year << 24) | (month << 16); break;
@ -100,7 +102,11 @@ void DiskCommand()
void DiskReset(void)
{
//ASIC_HARD_RESET 0xAAAA0000
WriteTrace(TraceN64System, TraceDebug, "DD RESET");
g_Reg->ASIC_STATUS |= DD_STATUS_RST_STATE;
dd_swapdelay = 0;
if (g_Disk != NULL)
g_Reg->ASIC_STATUS |= DD_STATUS_DISK_PRES;
}
void DiskBMControl(void)
@ -159,6 +165,17 @@ void DiskGapSectorCheck()
DiskBMUpdate();
}
}
if (!(g_Reg->ASIC_STATUS & DD_STATUS_DISK_PRES) && g_Disk != NULL)
{
dd_swapdelay++;
if (dd_swapdelay >= 40)
{
g_Reg->ASIC_STATUS |= (DD_STATUS_DISK_PRES | DD_STATUS_DISK_CHNG);
dd_swapdelay = 0;
WriteTrace(TraceN64System, TraceDebug, "DD SWAP DONE");
}
}
}
void DiskBMUpdate()
@ -245,7 +262,7 @@ void DiskBMRead()
sector += dd_track_offset;
sector += dd_start_block * SECTORS_PER_BLOCK * ddZoneSecSize[dd_zone];
sector += (dd_current) * (((g_Reg->ASIC_HOST_SECBYTE & 0x00FF0000) >> 16) + 1);
WriteTrace(TraceN64System, TraceDebug, "READ Block %d Sector %02X - %08X", ((g_Reg->ASIC_CUR_TK & 0x0FFF0000) >> 15) | dd_start_block, dd_current, sector);
//WriteTrace(TraceN64System, TraceDebug, "READ Block %d Sector %02X - %08X", ((g_Reg->ASIC_CUR_TK & 0x0FFF0000) >> 15) | dd_start_block, dd_current, sector);
g_Disk->SetDiskAddressBuffer(sector);
return;
}
@ -256,7 +273,7 @@ void DiskBMWrite()
sector += dd_track_offset;
sector += dd_start_block * SECTORS_PER_BLOCK * ddZoneSecSize[dd_zone];
sector += (dd_current) * (((g_Reg->ASIC_HOST_SECBYTE & 0x00FF0000) >> 16) + 1);
WriteTrace(TraceN64System, TraceDebug, "WRITE Block %d Sector %02X - %08X", ((g_Reg->ASIC_CUR_TK & 0x0FFF0000) >> 15) | dd_start_block, dd_current, sector);
//WriteTrace(TraceN64System, TraceDebug, "WRITE Block %d Sector %02X - %08X", ((g_Reg->ASIC_CUR_TK & 0x0FFF0000) >> 15) | dd_start_block, dd_current, sector);
g_Disk->SetDiskAddressBuffer(sector);
return;
}

View File

@ -13,6 +13,7 @@
#include "SystemGlobals.h"
#include <Common/Platform.h>
#include <Common/MemoryManagement.h>
#include <Project64-core/N64System/Mips/RegisterClass.h>
#include <memory>
CN64Disk::CN64Disk() :
@ -80,6 +81,11 @@ bool CN64Disk::SaveDiskImage()
return true;
}
void CN64Disk::SwapDiskImage()
{
g_Reg->ASIC_STATUS &= ~DD_STATUS_DISK_PRES;
}
bool CN64Disk::IsValidDiskImage(uint8_t Test[4])
{
if (*((uint32_t *)&Test[0]) == 0x16D348E8) { return true; }

View File

@ -19,6 +19,7 @@ public:
bool LoadDiskImage(const char * FileLoc);
bool SaveDiskImage();
void SwapDiskImage();
static bool IsValidDiskImage(uint8_t Test[4]);
uint8_t * GetDiskAddress() { return m_DiskImage; }
uint8_t * GetDiskAddressBuffer() { return m_DiskImage + m_DiskBufAddress; }

View File

@ -1,5 +1,6 @@
#include "stdafx.h"
#include "RomInformationClass.h"
#include <Project64-core/N64System/N64DiskClass.h>
#include <windows.h>
#include <commdlg.h>
@ -229,6 +230,32 @@ bool CMainMenu::ProcessMessage(HWND hWnd, DWORD /*FromAccelerator*/, DWORD MenuI
g_Settings->SaveBool(GameRunning_LimitFPS, !g_Settings->LoadBool(GameRunning_LimitFPS));
WriteTrace(TraceUserInterface, TraceDebug, "ID_SYSTEM_LIMITFPS 1");
break;
case ID_SYSTEM_SWAPDISK:
WriteTrace(TraceUserInterface, TraceDebug, "ID_SYSTEM_SWAPDISK");
// Open Disk
OPENFILENAME openfilename;
char FileName[_MAX_PATH], Directory[_MAX_PATH];
memset(&FileName, 0, sizeof(FileName));
memset(&openfilename, 0, sizeof(openfilename));
strcpy(Directory, g_Settings->LoadStringVal(RomList_GameDir).c_str());
openfilename.lStructSize = sizeof(openfilename);
openfilename.hwndOwner = (HWND)hWnd;
openfilename.lpstrFilter = "N64DD Disk Image (*.ndd)\0*.ndd\0All files (*.*)\0*.*\0";
openfilename.lpstrFile = FileName;
openfilename.lpstrInitialDir = Directory;
openfilename.nMaxFile = MAX_PATH;
openfilename.Flags = OFN_FILEMUSTEXIST | OFN_HIDEREADONLY;
if (GetOpenFileName(&openfilename))
{
g_Disk->SaveDiskImage();
g_Disk->SwapDiskImage();
g_Disk->LoadDiskImage(FileName);
}
break;
case ID_SYSTEM_SAVE:
WriteTrace(TraceUserInterface, TraceDebug, "ID_SYSTEM_SAVE");
g_BaseSystem->ExternalEvent(SysEvent_SaveMachineState);
@ -868,6 +895,10 @@ void CMainMenu::FillOutMenu(HMENU hMenu)
SystemMenu.push_back(Item);
SystemMenu.push_back(MENU_ITEM(SPLITER));
}
Item.Reset(ID_SYSTEM_SWAPDISK, MENU_SWAPDISK);
if (g_Disk == NULL) { Item.SetItemEnabled(false); }
SystemMenu.push_back(Item);
SystemMenu.push_back(MENU_ITEM(SPLITER));
SystemMenu.push_back(MENU_ITEM(ID_SYSTEM_SAVE, MENU_SAVE, m_ShortCuts.ShortCutString(ID_SYSTEM_SAVE, AccessLevel)));
if (!inBasicMode)
{

View File

@ -18,7 +18,7 @@ enum MainMenuID
//System Menu
ID_SYSTEM_RESET_SOFT, ID_SYSTEM_RESET_HARD, ID_SYSTEM_PAUSE, ID_SYSTEM_BITMAP,
ID_SYSTEM_LIMITFPS, ID_SYSTEM_RESTORE, ID_SYSTEM_LOAD, ID_SYSTEM_SAVE,
ID_SYSTEM_LIMITFPS, ID_SYSTEM_SWAPDISK, ID_SYSTEM_RESTORE, ID_SYSTEM_LOAD, ID_SYSTEM_SAVE,
ID_SYSTEM_SAVEAS, ID_SYSTEM_CHEAT, ID_SYSTEM_GSBUTTON,
//Current Save Slot