Skip to content

Commit

Permalink
Slot2: Add Sega Card Reader(HCV-1000)
Browse files Browse the repository at this point in the history
  • Loading branch information
windwakr committed Oct 4, 2023
1 parent 7a3b748 commit 0a34ef8
Show file tree
Hide file tree
Showing 18 changed files with 229 additions and 12 deletions.
1 change: 1 addition & 0 deletions desmume/src/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ libdesmume_a_SOURCES = \
addons/slot2_none.cpp \
addons/slot2_rumblepak.cpp \
addons/slot2_guitarGrip.cpp \
addons/slot2_hcv1000.cpp \
addons/slot2_expMemory.cpp \
addons/slot2_piano.cpp \
addons/slot2_passme.cpp \
Expand Down
81 changes: 81 additions & 0 deletions desmume/src/addons/slot2_hcv1000.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
//HCV-1000 emulation code adapted from GBE+: https://github.com/shonumi/gbe-plus

/*
Modifications Copyright (C) 2023 DeSmuME team
This file is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 2 of the License, or
(at your option) any later version.
This file is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with the this software. If not, see <http://www.gnu.org/licenses/>.
*/

#include <string.h>

#include "../slot2.h"

u8 hcv1000_cnt;
char hcv1000_data[16];

class Slot2_HCV1000 : public ISlot2Interface
{
public:

virtual Slot2Info const* info()
{
static Slot2InfoSimple info("Sega Card Reader", "Sega Card Reader(HCV-1000) add-on", 0x09);
return &info;
}

virtual bool init()
{
hcv1000_cnt = 0;
memset(hcv1000_data, 0x5F, 16);

return TRUE;
}

virtual void writeByte(u8 PROCNUM, u32 addr, u8 val)
{
if (addr == 0xA000000) { hcv1000_cnt = (val & 0x83); }
}

virtual u8 readByte(u8 PROCNUM, u32 addr)
{
u8 slot_byte = 0xFF;
//Reading these cart addresses is for detection
if (addr < 0x8020000)
{
u8 data = 0xF0 | ((addr & 0x1F) >> 1);
slot_byte = (addr & 0x1) ? 0xFD : data;
}

//HCV_CNT
else if (addr == 0xA000000) { slot_byte = hcv1000_cnt; }

//HCV_DATA
else if ((addr >= 0xA000010) && (addr <= 0xA00001F))
{
slot_byte = (u8)hcv1000_data[addr & 0xF];
}

return slot_byte;
}

virtual u16 readWord(u8 PROCNUM, u32 addr) { return 0xFDFD; };
virtual u32 readLong(u8 PROCNUM, u32 addr) { return 0xFDFDFDFD; };
};

ISlot2Interface* construct_Slot2_HCV1000() { return new Slot2_HCV1000(); }

void HCV1000_setReady()
{
hcv1000_cnt &= ~0x80;
}
2 changes: 1 addition & 1 deletion desmume/src/frontend/interface/meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ libdesmume_src += [
'../../utils/tinyxml/tinyxmlerror.cpp',
'../../utils/tinyxml/tinyxmlparser.cpp',
'../../utils/colorspacehandler/colorspacehandler.cpp',
'../../addons/slot2_auto.cpp', '../../addons/slot2_mpcf.cpp', '../../addons/slot2_paddle.cpp', '../../addons/slot2_gbagame.cpp', '../../addons/slot2_none.cpp', '../../addons/slot2_rumblepak.cpp', '../../addons/slot2_guitarGrip.cpp', '../../addons/slot2_expMemory.cpp', '../../addons/slot2_piano.cpp', '../../addons/slot2_passme.cpp', '../../addons/slot1_none.cpp', '../../addons/slot1_r4.cpp', '../../addons/slot1_retail_nand.cpp', '../../addons/slot1_retail_auto.cpp', '../../addons/slot1_retail_mcrom.cpp', '../../addons/slot1_retail_mcrom_debug.cpp', '../../addons/slot1comp_mc.cpp', '../../addons/slot1comp_rom.cpp', '../../addons/slot1comp_protocol.cpp',
'../../addons/slot2_auto.cpp', '../../addons/slot2_mpcf.cpp', '../../addons/slot2_paddle.cpp', '../../addons/slot2_gbagame.cpp', '../../addons/slot2_none.cpp', '../../addons/slot2_rumblepak.cpp', '../../addons/slot2_guitarGrip.cpp', '../../addons/slot2_hcv1000.cpp', '../../addons/slot2_expMemory.cpp', '../../addons/slot2_piano.cpp', '../../addons/slot2_passme.cpp', '../../addons/slot1_none.cpp', '../../addons/slot1_r4.cpp', '../../addons/slot1_retail_nand.cpp', '../../addons/slot1_retail_auto.cpp', '../../addons/slot1_retail_mcrom.cpp', '../../addons/slot1_retail_mcrom_debug.cpp', '../../addons/slot1comp_mc.cpp', '../../addons/slot1comp_rom.cpp', '../../addons/slot1comp_protocol.cpp',
'../../cheatSystem.cpp',
'../../texcache.cpp', '../../rasterize.cpp',
'../../metaspu/metaspu.cpp',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -268,6 +268,7 @@
<ClCompile Include="..\..\..\addons\slot2_expMemory.cpp" />
<ClCompile Include="..\..\..\addons\slot2_gbagame.cpp" />
<ClCompile Include="..\..\..\addons\slot2_guitarGrip.cpp" />
<ClCompile Include="..\..\..\addons\slot2_hcv1000.cpp" />
<ClCompile Include="..\..\..\addons\slot2_none.cpp" />
<ClCompile Include="..\..\..\addons\slot2_rumblepak.cpp" />
<ClCompile Include="..\..\..\utils\guid.cpp" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,9 @@
<ClCompile Include="..\..\..\addons\slot2_guitarGrip.cpp">
<Filter>addons</Filter>
</ClCompile>
<ClCompile Include="..\..\..\addons\slot2_hcv1000.cpp">
<Filter>addons</Filter>
</ClCompile>
<ClCompile Include="..\..\..\addons\slot2_none.cpp">
<Filter>addons</Filter>
</ClCompile>
Expand Down
2 changes: 1 addition & 1 deletion desmume/src/frontend/posix/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ libdesmume_a_SOURCES = \
../../utils/tinyxml/tinyxmlparser.cpp \
../../utils/glcorearb.h \
../../utils/colorspacehandler/colorspacehandler.cpp ../../utils/colorspacehandler/colorspacehandler.h \
../../addons/slot2_auto.cpp ../../addons/slot2_mpcf.cpp ../../addons/slot2_paddle.cpp ../../addons/slot2_gbagame.cpp ../../addons/slot2_none.cpp ../../addons/slot2_rumblepak.cpp ../../addons/slot2_guitarGrip.cpp ../../addons/slot2_expMemory.cpp ../../addons/slot2_piano.cpp ../../addons/slot2_passme.cpp ../../addons/slot1_none.cpp ../../addons/slot1_r4.cpp ../../addons/slot1_retail_nand.cpp ../../addons/slot1_retail_auto.cpp ../../addons/slot1_retail_mcrom.cpp ../../addons/slot1_retail_mcrom_debug.cpp ../../addons/slot1comp_mc.cpp ../../addons/slot1comp_mc.h ../../addons/slot1comp_rom.h ../../addons/slot1comp_rom.cpp ../../addons/slot1comp_protocol.h ../../addons/slot1comp_protocol.cpp \
../../addons/slot2_auto.cpp ../../addons/slot2_mpcf.cpp ../../addons/slot2_paddle.cpp ../../addons/slot2_gbagame.cpp ../../addons/slot2_none.cpp ../../addons/slot2_rumblepak.cpp ../../addons/slot2_guitarGrip.cpp ../../addons/slot2_hcv1000.cpp ../../addons/slot2_expMemory.cpp ../../addons/slot2_piano.cpp ../../addons/slot2_passme.cpp ../../addons/slot1_none.cpp ../../addons/slot1_r4.cpp ../../addons/slot1_retail_nand.cpp ../../addons/slot1_retail_auto.cpp ../../addons/slot1_retail_mcrom.cpp ../../addons/slot1_retail_mcrom_debug.cpp ../../addons/slot1comp_mc.cpp ../../addons/slot1comp_mc.h ../../addons/slot1comp_rom.h ../../addons/slot1comp_rom.cpp ../../addons/slot1comp_protocol.h ../../addons/slot1comp_protocol.cpp \
../../cheatSystem.cpp ../../cheatSystem.h \
../../texcache.cpp ../../texcache.h ../../rasterize.cpp ../../rasterize.h \
../../metaspu/metaspu.cpp ../../metaspu/metaspu.h \
Expand Down
2 changes: 1 addition & 1 deletion desmume/src/frontend/posix/meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ libdesmume_src = [
'../../utils/tinyxml/tinyxmlerror.cpp',
'../../utils/tinyxml/tinyxmlparser.cpp',
'../../utils/colorspacehandler/colorspacehandler.cpp',
'../../addons/slot2_auto.cpp', '../../addons/slot2_mpcf.cpp', '../../addons/slot2_paddle.cpp', '../../addons/slot2_gbagame.cpp', '../../addons/slot2_none.cpp', '../../addons/slot2_rumblepak.cpp', '../../addons/slot2_guitarGrip.cpp', '../../addons/slot2_expMemory.cpp', '../../addons/slot2_piano.cpp', '../../addons/slot2_passme.cpp', '../../addons/slot1_none.cpp', '../../addons/slot1_r4.cpp', '../../addons/slot1_retail_nand.cpp', '../../addons/slot1_retail_auto.cpp', '../../addons/slot1_retail_mcrom.cpp', '../../addons/slot1_retail_mcrom_debug.cpp', '../../addons/slot1comp_mc.cpp', '../../addons/slot1comp_rom.cpp', '../../addons/slot1comp_protocol.cpp',
'../../addons/slot2_auto.cpp', '../../addons/slot2_mpcf.cpp', '../../addons/slot2_paddle.cpp', '../../addons/slot2_gbagame.cpp', '../../addons/slot2_none.cpp', '../../addons/slot2_rumblepak.cpp', '../../addons/slot2_guitarGrip.cpp', '../../addons/slot2_hcv1000.cpp', '../../addons/slot2_expMemory.cpp', '../../addons/slot2_piano.cpp', '../../addons/slot2_passme.cpp', '../../addons/slot1_none.cpp', '../../addons/slot1_r4.cpp', '../../addons/slot1_retail_nand.cpp', '../../addons/slot1_retail_auto.cpp', '../../addons/slot1_retail_mcrom.cpp', '../../addons/slot1_retail_mcrom_debug.cpp', '../../addons/slot1comp_mc.cpp', '../../addons/slot1comp_rom.cpp', '../../addons/slot1comp_protocol.cpp',
'../../cheatSystem.cpp',
'../../texcache.cpp', '../../rasterize.cpp',
'../../metaspu/metaspu.cpp',
Expand Down
1 change: 1 addition & 0 deletions desmume/src/frontend/windows/DeSmuME.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@
<ClCompile Include="..\..\addons\slot1_retail_mcrom.cpp" />
<ClCompile Include="..\..\addons\slot1_retail_mcrom_debug.cpp" />
<ClCompile Include="..\..\addons\slot2_auto.cpp" />
<ClCompile Include="..\..\addons\slot2_hcv1000.cpp" />
<ClCompile Include="..\..\addons\slot2_passme.cpp" />
<ClCompile Include="..\..\addons\slot2_piano.cpp" />
<ClCompile Include="..\..\addons\slot1_none.cpp" />
Expand Down
3 changes: 3 additions & 0 deletions desmume/src/frontend/windows/DeSmuME.vcxproj.filters
Original file line number Diff line number Diff line change
Expand Up @@ -930,6 +930,9 @@
<ClCompile Include="display.cpp">
<Filter>frontend\Windows</Filter>
</ClCompile>
<ClCompile Include="..\..\addons\slot2_hcv1000.cpp">
<Filter>addons</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<ClInclude Include="..\..\utils\guid.h">
Expand Down
68 changes: 66 additions & 2 deletions desmume/src/frontend/windows/gbaslot_config.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
Copyright (C) 2009-2016 DeSmuME team
Copyright (C) 2009-2023 DeSmuME team
This file is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
Expand Down Expand Up @@ -36,18 +36,21 @@ 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 };
ADDON_CFLASH_MODE tmp_CFlashMode = ADDON_CFLASH_MODE_RomPath;
HWND OKbutton = NULL;
bool _OKbutton = false;
SGuitar tmp_Guitar;
SPiano tmp_Piano;
SPaddle tmp_Paddle;
SHCV1000 tmp_HCV1000;

//these are the remembered preset values for directory and filename
//they are named very verbosely to distinguish them from the currently-configured values in addons.cpp
std::string win32_CFlash_cfgDirectory, win32_CFlash_cfgFileName;
UINT win32_CFlash_cfgMode;
std::string win32_GBA_cfgRomPath;
std::string win32_HCV1000_barcode;

INT_PTR CALLBACK GbaSlotNone(HWND dialog, UINT msg,WPARAM wparam,LPARAM lparam)
{
Expand Down Expand Up @@ -263,6 +266,54 @@ INT_PTR CALLBACK GbaSlotPaddle(HWND dialog, UINT msg,WPARAM wparam,LPARAM lparam
return FALSE;
}

INT_PTR CALLBACK GbaSlotHCV1000(HWND dialog, UINT msg, WPARAM wparam, LPARAM lparam)
{
int which = 0;

switch (msg)
{
case WM_INITDIALOG:
_OKbutton = TRUE;
SendDlgItemMessage(dialog, IDC_HCVSCAN, WM_USER + 44, tmp_HCV1000.SCANKEY, 0);
SendDlgItemMessage(dialog, IDC_HCVBARCODE, EM_SETLIMITTEXT, 16, 0);
SendDlgItemMessage(dialog, IDC_HCVBARCODE, EM_SETSEL, 0, 16);
SetWindowText(GetDlgItem(dialog, IDC_HCVBARCODE), tmp_hcv1000_barcode);

return TRUE;

case WM_USER + 46:
SendDlgItemMessage(dialog, IDC_HCVSCAN, WM_USER + 44, tmp_HCV1000.SCANKEY, 0);
return TRUE;

case WM_USER + 43:
//MessageBox(hDlg,"USER+43 CAUGHT","moo",MB_OK);
which = GetDlgCtrlID((HWND)lparam);
switch (which)
{
case IDC_HCVSCAN:
tmp_HCV1000.SCANKEY = wparam;

break;
}

SendDlgItemMessage(dialog, IDC_HCVSCAN, WM_USER + 44, tmp_HCV1000.SCANKEY, 0);
PostMessage(dialog, WM_NEXTDLGCTL, 0, 0);
return true;

case WM_COMMAND:
case EN_UPDATE:
switch (LOWORD(wparam))
{
case IDC_HCVBARCODE:
GetWindowText(GetDlgItem(dialog, IDC_HCVBARCODE), tmp_hcv1000_barcode, 16);

return FALSE;
}
break;
}
return FALSE;
}

INT_PTR CALLBACK GbaSlotRumblePak(HWND dialog, UINT msg,WPARAM wparam,LPARAM lparam)
{
switch(msg)
Expand Down Expand Up @@ -478,6 +529,7 @@ u32 GBAslot_IDDs[NDS_SLOT2_COUNT] = {
IDD_GBASLOT_PIANO,
IDD_GBASLOT_PADDLE, //paddle
IDD_GBASLOT_NONE, //PassME
IDD_GBASLOT_HCV1000, //HCV-1000
};

DLGPROC GBAslot_Procs[NDS_SLOT2_COUNT] = {
Expand All @@ -490,7 +542,8 @@ DLGPROC GBAslot_Procs[NDS_SLOT2_COUNT] = {
GbaSlotNone, //expmem
GbaSlotPiano,
GbaSlotPaddle,
GbaSlotNone // PassME
GbaSlotNone, // PassME
GbaSlotHCV1000, //HCV-1000
};


Expand Down Expand Up @@ -566,9 +619,11 @@ 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());
memcpy(&tmp_Guitar, &Guitar, sizeof(Guitar));
memcpy(&tmp_Piano, &Piano, sizeof(Piano));
memcpy(&tmp_Paddle, &Paddle, sizeof(Paddle));
memcpy(&tmp_HCV1000, &HCV1000, sizeof(HCV1000));
tmp_CFlashMode = CFlash_Mode;
_OKbutton = false;

Expand Down Expand Up @@ -633,6 +688,14 @@ void GBAslotDialog(HWND hwnd)
break;
case NDS_SLOT2_PASSME:
break;
case NDS_SLOT2_HCV1000:
win32_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);
WritePrivateProfileString("Slot2.HCV1000", "barcode", tmp_hcv1000_barcode, IniName);
WritePrivateProfileInt("Slot2.HCV1000", "scankey", HCV1000.SCANKEY, IniName);
break;
default:
return;
}
Expand All @@ -644,6 +707,7 @@ void GBAslotDialog(HWND hwnd)
Guitar.Enabled = (slot2_GetCurrentType() == NDS_SLOT2_GUITARGRIP)?true:false;
Piano.Enabled = (slot2_GetCurrentType() == NDS_SLOT2_EASYPIANO)?true:false;
Paddle.Enabled = (slot2_GetCurrentType() == NDS_SLOT2_PADDLE)?true:false;
HCV1000.Enabled = (slot2_GetCurrentType() == NDS_SLOT2_HCV1000)?true:false;
}
}

3 changes: 2 additions & 1 deletion desmume/src/frontend/windows/gbaslot_config.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
Copyright (C) 2009-2015 DeSmuME team
Copyright (C) 2009-2023 DeSmuME team
This file is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
Expand All @@ -24,6 +24,7 @@
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 void GBAslotDialog(HWND hwnd);

Expand Down
30 changes: 29 additions & 1 deletion desmume/src/frontend/windows/inputdx.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
licensed under the terms supplied at the end of this file (for the terms are very long!)
Differences from that baseline version are:
Copyright (C) 2009-2019 DeSmuME team
Copyright (C) 2009-2023 DeSmuME team
This file is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
Expand Down Expand Up @@ -258,6 +258,9 @@ SPiano DefaultPiano = { false, 'Z', 'S', 'X', 'D', 'C', 'V', 'G', 'B', 'H', 'N',
SPaddle Paddle;
SPaddle DefaultPaddle = { false, 'K', 'L' };

SHCV1000 HCV1000;
SHCV1000 DefaultHCV1000 = { false, 'L'};

bool killStylusTopScreen = false;
bool killStylusOffScreen = false;
bool allowUpAndDown = false;
Expand Down Expand Up @@ -390,6 +393,15 @@ static void ReadPaddleControl(const char* name, WORD& output)
}
}

static void ReadHCV1000Control(const char* name, WORD& output)
{
UINT temp;
temp = GetPrivateProfileInt("Slot2.HCV1000", name, -1, IniName);
if (temp != -1) {
output = temp;
}
}

void LoadHotkeyConfig()
{
SCustomKey *key = &CustomKeys.key(0);
Expand Down Expand Up @@ -452,6 +464,15 @@ static void LoadPaddleConfig()
ReadPaddleControl("INC", Paddle.INC);
}

static void LoadHCV1000Config()
{
memcpy(&HCV1000, &DefaultHCV1000, sizeof(HCV1000));

#define DO(X) ReadHCV1000Control(#X,HCV1000.X);
DO(SCANKEY);
#undef DO
}


static void LoadInputConfig()
{
Expand Down Expand Up @@ -2690,6 +2711,7 @@ void input_init()
LoadGuitarConfig();
LoadPianoConfig();
LoadPaddleConfig();
LoadHCV1000Config();

di_init();
FeedbackON = input_feedback;
Expand Down Expand Up @@ -2816,6 +2838,12 @@ void input_acquire()
if (inc) nds.paddle += 5;
if (dec) nds.paddle -= 5;
}

if (HCV1000.Enabled)
{
bool scan = !S9xGetState(HCV1000.SCANKEY);
if (scan) HCV1000_setReady();
}
}
else
{
Expand Down
Loading

0 comments on commit 0a34ef8

Please sign in to comment.