Skip to content

Commit

Permalink
Memcards fix
Browse files Browse the repository at this point in the history
  • Loading branch information
ogamespec committed Aug 27, 2020
1 parent 194546a commit 96a9fb3
Show file tree
Hide file tree
Showing 3 changed files with 86 additions and 13 deletions.
42 changes: 34 additions & 8 deletions SRC/Backends/DolwinVideo/Fifo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ GX_FromFuture::FifoProcessor GxFifo;

bool frame_done = true;

bool logDrawCommands = false;

// ---------------------------------------------------------------------------

// stage callbacks
Expand Down Expand Up @@ -975,7 +977,10 @@ static void GxCommand(GX_FromFuture::FifoProcessor * fifo)
uint8_t* fifoPtr = &RAM[physAddress];
size_t size = fifo->Read32() & ~0x1f;

Report(Channel::GP, "OP_CMD_CALL_DL: addr: 0x%08X, size: %i\n", physAddress, size);
if (logDrawCommands)
{
Report(Channel::GP, "OP_CMD_CALL_DL: addr: 0x%08X, size: %i\n", physAddress, size);
}

GX_FromFuture::FifoProcessor* callDlFifo = new GX_FromFuture::FifoProcessor(fifoPtr, size);

Expand Down Expand Up @@ -1134,7 +1139,10 @@ static void GxCommand(GX_FromFuture::FifoProcessor * fifo)
unsigned vatnum = cmd & 7;
unsigned vtxnum = fifo->Read16();
usevat = vatnum;
Report(Channel::GP, "OP_CMD_DRAW_QUAD: vtxnum: %i, vat: %i\n", vtxnum, vatnum);
if (logDrawCommands)
{
Report(Channel::GP, "OP_CMD_DRAW_QUAD: vtxnum: %i, vat: %i\n", vtxnum, vatnum);
}
/*/
1---2 tri1: 0-1-2
| /| tri2: 0-2-3
Expand Down Expand Up @@ -1171,7 +1179,10 @@ static void GxCommand(GX_FromFuture::FifoProcessor * fifo)
unsigned vatnum = cmd & 7;
unsigned vtxnum = fifo->Read16();
usevat = vatnum;
Report(Channel::GP, "OP_CMD_DRAW_TRIANGLE: vtxnum: %i, vat: %i\n", vtxnum, vatnum);
if (logDrawCommands)
{
Report(Channel::GP, "OP_CMD_DRAW_TRIANGLE: vtxnum: %i, vat: %i\n", vtxnum, vatnum);
}
/*/
1---2 tri: 0-1-2
| /
Expand Down Expand Up @@ -1208,7 +1219,10 @@ static void GxCommand(GX_FromFuture::FifoProcessor * fifo)
unsigned vatnum = cmd & 7;
unsigned vtxnum = fifo->Read16();
usevat = vatnum;
Report(Channel::GP, "OP_CMD_DRAW_STRIP: vtxnum: %i, vat: %i\n", vtxnum, vatnum);
if (logDrawCommands)
{
Report(Channel::GP, "OP_CMD_DRAW_STRIP: vtxnum: %i, vat: %i\n", vtxnum, vatnum);
}
/*/
1---3---5 tri1: 0-1-2
/| /| / tri2: 1-2-3
Expand Down Expand Up @@ -1260,7 +1274,10 @@ static void GxCommand(GX_FromFuture::FifoProcessor * fifo)
unsigned vatnum = cmd & 7;
unsigned vtxnum = fifo->Read16();
usevat = vatnum;
Report(Channel::GP, "OP_CMD_DRAW_FAN: vtxnum: %i, vat: %i\n", vtxnum, vatnum);
if (logDrawCommands)
{
Report(Channel::GP, "OP_CMD_DRAW_FAN: vtxnum: %i, vat: %i\n", vtxnum, vatnum);
}
/*/
1---2---3 tri1: 0-1-2
| / _/ tri2: 0-2-3
Expand Down Expand Up @@ -1311,7 +1328,10 @@ static void GxCommand(GX_FromFuture::FifoProcessor * fifo)
unsigned vatnum = cmd & 7;
unsigned vtxnum = fifo->Read16();
usevat = vatnum;
Report(Channel::GP, "OP_CMD_DRAW_LINE: vtxnum: %i, vat: %i\n", vtxnum, vatnum);
if (logDrawCommands)
{
Report(Channel::GP, "OP_CMD_DRAW_LINE: vtxnum: %i, vat: %i\n", vtxnum, vatnum);
}
/*/
1 3 5
/ / /
Expand Down Expand Up @@ -1348,7 +1368,10 @@ static void GxCommand(GX_FromFuture::FifoProcessor * fifo)
unsigned vatnum = cmd & 7;
unsigned vtxnum = fifo->Read16();
usevat = vatnum;
Report(Channel::GP, "OP_CMD_DRAW_LINESTRIP: vtxnum: %i, vat: %i\n", vtxnum, vatnum);
if (logDrawCommands)
{
Report(Channel::GP, "OP_CMD_DRAW_LINESTRIP: vtxnum: %i, vat: %i\n", vtxnum, vatnum);
}
/*/
1 3 5
/| /| /
Expand Down Expand Up @@ -1395,7 +1418,10 @@ static void GxCommand(GX_FromFuture::FifoProcessor * fifo)
unsigned vatnum = cmd & 7;
unsigned vtxnum = fifo->Read16();
usevat = vatnum;
Report(Channel::GP, "OP_CMD_DRAW_POINT: vtxnum: %i, vat: %i\n", vtxnum, vatnum);
if (logDrawCommands)
{
Report(Channel::GP, "OP_CMD_DRAW_POINT: vtxnum: %i, vat: %i\n", vtxnum, vatnum);
}
/*/
0---0 tri: 0-0-0 (1x1x1 tri)
| /
Expand Down
12 changes: 11 additions & 1 deletion SRC/Hardware/MC.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,7 @@ static void MCReadArrayProc (Memcard * memcard){
offset = MCCalculateOffset(auxdata);

if (offset >= memcard->size + size) {
Halt("MC :: ReadArray offset is out of range\n");
Report(Channel::MC, "ReadArray offset is out of range\n");
return;
}

Expand Down Expand Up @@ -530,6 +530,16 @@ void MCOpen (HWConfig * config)
wcscpy(memcard[MEMCARD_SLOTB].filename, config->MemcardB_Filename);
SyncSave = config->Memcard_SyncSave;

if (!Util::FileExists(memcard[MEMCARD_SLOTA].filename))
{
Memcard_Connected[MEMCARD_SLOTA] = false;
}

if (!Util::FileExists(memcard[MEMCARD_SLOTB].filename))
{
Memcard_Connected[MEMCARD_SLOTB] = false;
}

MCConnect();
}

Expand Down
45 changes: 41 additions & 4 deletions SRC/UI/Legacy/DolwinLegacy/UserMemcards.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -252,6 +252,7 @@ static INT_PTR CALLBACK MemcardSettingsProc(HWND hwndDlg, UINT uMsg, WPARAM wPar
{
wchar_t buf[MAX_PATH] = { 0 }, buf2[MAX_PATH] = { 0 }, * filename;
size_t newsize;
size_t fileSize;

switch(uMsg)
{
Expand All @@ -264,6 +265,19 @@ static INT_PTR CALLBACK MemcardSettingsProc(HWND hwndDlg, UINT uMsg, WPARAM wPar
else if (um_num == 1)
SendMessage(hwndDlg, WM_SETTEXT, (WPARAM)0, lParam = (LPARAM)L"Memcard B Settings");

SyncSave = UI::Jdi.GetConfigBool(Memcard_SyncSave_Key, USER_MEMCARDS);

if (um_num == 0)
{
Memcard_Connected[um_num] = UI::Jdi.GetConfigBool(MemcardA_Connected_Key, USER_MEMCARDS);
wcscpy_s(Memcard_filename[um_num], _countof(Memcard_filename[um_num]), Util::StringToWstring(UI::Jdi.GetConfigString(MemcardA_Filename_Key, USER_MEMCARDS)).c_str());
}
else if (um_num == 1)
{
Memcard_Connected[um_num] = UI::Jdi.GetConfigBool(MemcardB_Connected_Key, USER_MEMCARDS);
wcscpy_s(Memcard_filename[um_num], _countof(Memcard_filename[um_num]), Util::StringToWstring(UI::Jdi.GetConfigString(MemcardB_Filename_Key, USER_MEMCARDS)).c_str());
}

if (SyncSave)
CheckRadioButton(hwndDlg, IDC_MEMCARD_SYNCSAVE_FALSE,
IDC_MEMCARD_SYNCSAVE_TRUE, IDC_MEMCARD_SYNCSAVE_TRUE );
Expand All @@ -286,11 +300,20 @@ static INT_PTR CALLBACK MemcardSettingsProc(HWND hwndDlg, UINT uMsg, WPARAM wPar
SendDlgItemMessage(hwndDlg, IDC_MEMCARD_PATH, WM_SETTEXT, (WPARAM)0, (LPARAM)(LPCTSTR)buf);
}

if (Util::FileExists(buf))
{
fileSize = Util::FileSize(buf);
}
else
{
Memcard_Connected[um_num] = false;
fileSize = 0;
}

if (Memcard_Connected[um_num]) {
// TODO: Refactoring
//_stprintf_s (buf, _countof(buf) - 1, _T("Size: %d usable blocks (%d Kb)"),
// (int)(memcard[um_num].size / Memcard_BlockSize - 5), (int)(memcard[um_num].size / 1024));
//SendDlgItemMessage(hwndDlg, IDC_MEMCARD_SIZEDESC, WM_SETTEXT, (WPARAM)0, (LPARAM)(LPCTSTR)buf);
swprintf_s (buf, _countof(buf) - 1, L"Size: %d usable blocks (%d Kb)",
(int)(fileSize / Memcard_BlockSize - 5), (int)(fileSize / 1024));
SendDlgItemMessage(hwndDlg, IDC_MEMCARD_SIZEDESC, WM_SETTEXT, (WPARAM)0, (LPARAM)(LPCTSTR)buf);
}
else {
SendDlgItemMessage(hwndDlg, IDC_MEMCARD_SIZEDESC, WM_SETTEXT, (WPARAM)0, (LPARAM)L"Not connected");
Expand Down Expand Up @@ -377,6 +400,18 @@ static INT_PTR CALLBACK MemcardSettingsProc(HWND hwndDlg, UINT uMsg, WPARAM wPar
wcscat_s(buf, _countof(buf) - 1, L"\\");
wcscat_s(buf, _countof(buf) - 1, buf2);
}
else
{
size_t Fnsize, Pathsize;
Fnsize = SendDlgItemMessage(hwndDlg, IDC_MEMCARD_FILE, WM_GETTEXTLENGTH, (WPARAM)0, (LPARAM)0);
Pathsize = SendDlgItemMessage(hwndDlg, IDC_MEMCARD_PATH, WM_GETTEXTLENGTH, (WPARAM)0, (LPARAM)0);

SendDlgItemMessage(hwndDlg, IDC_MEMCARD_PATH, WM_GETTEXT, (WPARAM)(Pathsize + 1), (LPARAM)(LPCTSTR)buf);
SendDlgItemMessage(hwndDlg, IDC_MEMCARD_FILE, WM_GETTEXT, (WPARAM)(Fnsize + 1), (LPARAM)(LPCTSTR)buf2);

wcscat_s(buf, _countof(buf) - 1, L"\\");
wcscat_s(buf, _countof(buf) - 1, buf2);
}

if (IsDlgButtonChecked(hwndDlg, IDC_MEMCARD_SYNCSAVE_FALSE) == BST_CHECKED )
SyncSave = false;
Expand All @@ -398,11 +433,13 @@ static INT_PTR CALLBACK MemcardSettingsProc(HWND hwndDlg, UINT uMsg, WPARAM wPar

if (um_num == 0)
{
wcscpy_s(Memcard_filename[0], _countof(Memcard_filename[0]), buf);
UI::Jdi.SetConfigBool(MemcardA_Connected_Key, Memcard_Connected[0], USER_MEMCARDS);
UI::Jdi.SetConfigString(MemcardA_Filename_Key, Util::WstringToString(Memcard_filename[0]), USER_MEMCARDS);
}
else
{
wcscpy_s(Memcard_filename[1], _countof(Memcard_filename[1]), buf);
UI::Jdi.SetConfigBool(MemcardB_Connected_Key, Memcard_Connected[1], USER_MEMCARDS);
UI::Jdi.SetConfigString(MemcardB_Filename_Key, Util::WstringToString(Memcard_filename[1]), USER_MEMCARDS);
}
Expand Down

0 comments on commit 96a9fb3

Please sign in to comment.