From 8be30fe971ae5471554690e79381af8b2eed61c7 Mon Sep 17 00:00:00 2001 From: windwakr <284886+windwakr@users.noreply.github.com> Date: Sat, 7 Oct 2023 00:35:48 -0400 Subject: [PATCH] Slot2: Sega Card Reader fixes --- desmume/src/addons/slot2_hcv1000.cpp | 6 ++++++ desmume/src/frontend/windows/gbaslot_config.cpp | 14 +++++++------- desmume/src/frontend/windows/gbaslot_config.h | 3 ++- desmume/src/frontend/windows/main.cpp | 5 +++-- desmume/src/slot2.h | 2 +- 5 files changed, 19 insertions(+), 11 deletions(-) diff --git a/desmume/src/addons/slot2_hcv1000.cpp b/desmume/src/addons/slot2_hcv1000.cpp index 8135fe003..5c8747bb1 100644 --- a/desmume/src/addons/slot2_hcv1000.cpp +++ b/desmume/src/addons/slot2_hcv1000.cpp @@ -79,3 +79,9 @@ void HCV1000_setReady() { hcv1000_cnt &= ~0x80; } + +void HCV1000_setBarcode(std::string barcode) +{ + barcode.resize(16, '_'); + memcpy(hcv1000_data, barcode.c_str(), barcode.length()); +} diff --git a/desmume/src/frontend/windows/gbaslot_config.cpp b/desmume/src/frontend/windows/gbaslot_config.cpp index 5797b67c9..9109eba18 100644 --- a/desmume/src/frontend/windows/gbaslot_config.cpp +++ b/desmume/src/frontend/windows/gbaslot_config.cpp @@ -36,7 +36,7 @@ u8 last_type = 0; char tmp_cflash_filename[MAX_PATH] = { 0 }; char tmp_cflash_path[MAX_PATH] = { 0 }; char tmp_gbagame_filename[MAX_PATH] = { 0 }; -TCHAR tmp_hcv1000_barcode[17] = { 0 }; +char tmp_hcv1000_barcode[17] = { 0 }; ADDON_CFLASH_MODE tmp_CFlashMode = ADDON_CFLASH_MODE_RomPath; HWND OKbutton = NULL; bool _OKbutton = false; @@ -50,7 +50,8 @@ SHCV1000 tmp_HCV1000; std::string win32_CFlash_cfgDirectory, win32_CFlash_cfgFileName; UINT win32_CFlash_cfgMode; std::string win32_GBA_cfgRomPath; -std::string win32_HCV1000_barcode; + +std::string slot2_HCV1000_barcode; INT_PTR CALLBACK GbaSlotNone(HWND dialog, UINT msg,WPARAM wparam,LPARAM lparam) { @@ -305,7 +306,7 @@ INT_PTR CALLBACK GbaSlotHCV1000(HWND dialog, UINT msg, WPARAM wparam, LPARAM lpa switch (LOWORD(wparam)) { case IDC_HCVBARCODE: - GetWindowText(GetDlgItem(dialog, IDC_HCVBARCODE), tmp_hcv1000_barcode, 16); + GetWindowText(GetDlgItem(dialog, IDC_HCVBARCODE), tmp_hcv1000_barcode, 17); return FALSE; } @@ -619,7 +620,7 @@ void GBAslotDialog(HWND hwnd) strcpy(tmp_cflash_filename, win32_CFlash_cfgFileName.c_str()); strcpy(tmp_cflash_path, win32_CFlash_cfgDirectory.c_str()); strcpy(tmp_gbagame_filename, win32_GBA_cfgRomPath.c_str()); - strcpy(tmp_hcv1000_barcode, win32_HCV1000_barcode.c_str()); + strcpy(tmp_hcv1000_barcode, slot2_HCV1000_barcode.c_str()); memcpy(&tmp_Guitar, &Guitar, sizeof(Guitar)); memcpy(&tmp_Piano, &Piano, sizeof(Piano)); memcpy(&tmp_Paddle, &Paddle, sizeof(Paddle)); @@ -689,10 +690,9 @@ void GBAslotDialog(HWND hwnd) case NDS_SLOT2_PASSME: break; case NDS_SLOT2_HCV1000: - win32_HCV1000_barcode = tmp_hcv1000_barcode; + slot2_HCV1000_barcode = tmp_hcv1000_barcode; memcpy(&HCV1000, &tmp_HCV1000, sizeof(tmp_HCV1000)); - memset(hcv1000_data, 0x5F, 16); - memcpy(hcv1000_data, win32_HCV1000_barcode.c_str(), (win32_HCV1000_barcode.length() <= 16) ? win32_HCV1000_barcode.length() : 16); + HCV1000_setBarcode(slot2_HCV1000_barcode); WritePrivateProfileString("Slot2.HCV1000", "barcode", tmp_hcv1000_barcode, IniName); WritePrivateProfileInt("Slot2.HCV1000", "scankey", HCV1000.SCANKEY, IniName); break; diff --git a/desmume/src/frontend/windows/gbaslot_config.h b/desmume/src/frontend/windows/gbaslot_config.h index f06140d7c..2516a5365 100644 --- a/desmume/src/frontend/windows/gbaslot_config.h +++ b/desmume/src/frontend/windows/gbaslot_config.h @@ -24,7 +24,8 @@ extern std::string win32_CFlash_cfgDirectory, win32_CFlash_cfgFileName; extern UINT win32_CFlash_cfgMode; extern std::string win32_GBA_cfgRomPath; -extern std::string win32_HCV1000_barcode; + +extern std::string slot2_HCV1000_barcode; extern void GBAslotDialog(HWND hwnd); diff --git a/desmume/src/frontend/windows/main.cpp b/desmume/src/frontend/windows/main.cpp index 052c4f5cb..5588ace62 100644 --- a/desmume/src/frontend/windows/main.cpp +++ b/desmume/src/frontend/windows/main.cpp @@ -2198,8 +2198,9 @@ int _main() win32_CFlash_cfgDirectory = GetPrivateProfileStdString("Slot2.CFlash", "path", ""); win32_CFlash_cfgFileName = GetPrivateProfileStdString("Slot2.CFlash", "filename", ""); win32_GBA_cfgRomPath = GetPrivateProfileStdString("Slot2.GBAgame", "filename", ""); - win32_HCV1000_barcode = GetPrivateProfileStdString("Slot2.HCV1000", "barcode", ""); - memcpy(hcv1000_data, win32_HCV1000_barcode.c_str(), (win32_HCV1000_barcode.length() <= 16) ? win32_HCV1000_barcode.length() : 16); + + slot2_HCV1000_barcode = GetPrivateProfileStdString("Slot2.HCV1000", "barcode", "").substr(0, 16); + HCV1000_setBarcode(slot2_HCV1000_barcode); cmdline.process_addonCommands(); WIN_InstallCFlash(); diff --git a/desmume/src/slot2.h b/desmume/src/slot2.h index a50631629..66f84f708 100644 --- a/desmume/src/slot2.h +++ b/desmume/src/slot2.h @@ -143,7 +143,6 @@ bool slot2_read(u32 addr, T &val); extern std::string GBACartridge_RomPath; extern std::string GBACartridge_SRAMPath; extern void (*FeedbackON)(bool enable); // feedback on/off -extern char hcv1000_data[16]; enum ADDON_CFLASH_MODE { @@ -160,4 +159,5 @@ void Paddle_SetValue(u16 theValue); extern void guitarGrip_setKey(bool green, bool red, bool yellow, bool blue); // Guitar grip keys extern void piano_setKey(bool c, bool cs, bool d, bool ds, bool e, bool f, bool fs, bool g, bool gs, bool a, bool as, bool b, bool hic); //piano keys extern void HCV1000_setReady(); +extern void HCV1000_setBarcode(std::string barcode); #endif //__SLOT_H__