Skip to content

Commit 43f365b

Browse files
committed
convert ramdisk back to procedural api
1 parent 8555604 commit 43f365b

File tree

5 files changed

+86
-162
lines changed

5 files changed

+86
-162
lines changed

Ramdisk/Ramdisk.vcxproj

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -94,11 +94,9 @@
9494
</Link>
9595
</ItemDefinitionGroup>
9696
<ItemGroup>
97-
<ClCompile Include="main.cpp" />
9897
<ClCompile Include="ramdisk_cartridge.cpp" />
9998
</ItemGroup>
10099
<ItemGroup>
101-
<ClInclude Include="ramdisk_cartridge.h" />
102100
<ClInclude Include="resource.h" />
103101
</ItemGroup>
104102
<ItemGroup>

Ramdisk/Ramdisk.vcxproj.filters

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,11 @@
11
<?xml version="1.0" encoding="utf-8"?>
22
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
33
<ItemGroup>
4-
<ClCompile Include="main.cpp">
5-
<Filter>Source Files</Filter>
6-
</ClCompile>
74
<ClCompile Include="ramdisk_cartridge.cpp">
85
<Filter>Source Files</Filter>
96
</ClCompile>
107
</ItemGroup>
118
<ItemGroup>
12-
<ClInclude Include="ramdisk_cartridge.h">
13-
<Filter>Header Files</Filter>
14-
</ClInclude>
159
<ClInclude Include="resource.h">
1610
<Filter>Resource Files</Filter>
1711
</ClInclude>

Ramdisk/main.cpp

Lines changed: 0 additions & 46 deletions
This file was deleted.

Ramdisk/ramdisk_cartridge.cpp

Lines changed: 86 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -15,86 +15,121 @@
1515
// You should have received a copy of the GNU General Public License along with
1616
// VCC (Virtual Color Computer). If not, see <http://www.gnu.org/licenses/>.
1717
////////////////////////////////////////////////////////////////////////////////
18-
#include "ramdisk_cartridge.h"
1918
#include "resource.h"
2019
#include <vcc/utils/winapi.h>
20+
#include <vcc/bus/cartridge_capi.h>
21+
#include <array>
2122

2223

2324
extern HINSTANCE gModuleInstance;
2425

25-
26-
ramdisk_cartridge::name_type ramdisk_cartridge::name() const
26+
namespace
2727
{
28-
return ::vcc::utils::load_string(gModuleInstance, IDS_MODULE_NAME);
29-
}
28+
using address_type = ::std::size_t;
3029

31-
ramdisk_cartridge::catalog_id_type ramdisk_cartridge::catalog_id() const
32-
{
33-
return ::vcc::utils::load_string(gModuleInstance, IDS_CATNUMBER);
34-
}
30+
address_type current_address_ = 0;
31+
address_type address_byte0 = 0;
32+
address_type address_byte1 = 0;
33+
address_type address_byte2 = 0;
34+
std::array<unsigned char, 1024u * 512u> ram_;
3535

36-
ramdisk_cartridge::description_type ramdisk_cartridge::description() const
37-
{
38-
return ::vcc::utils::load_string(gModuleInstance, IDS_DESCRIPTION);
36+
void initialize_state(bool initialize_memory)
37+
{
38+
current_address_ = 0;
39+
address_byte0 = 0;
40+
address_byte1 = 0;
41+
address_byte2 = 0;
42+
if (initialize_memory)
43+
{
44+
std::fill(ram_.begin(), ram_.end(), 0xff);
45+
}
46+
}
3947
}
4048

49+
HINSTANCE gModuleInstance;
4150

42-
void ramdisk_cartridge::start()
43-
{
44-
initialize_state(true);
45-
}
4651

47-
void ramdisk_cartridge::reset()
52+
BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpReserved)
4853
{
49-
initialize_state(false);
54+
if (fdwReason == DLL_PROCESS_ATTACH)
55+
{
56+
gModuleInstance = hinstDLL;
57+
}
58+
59+
return true;
5060
}
5161

52-
void ramdisk_cartridge::write_port(unsigned char port_id, unsigned char value)
62+
63+
extern "C"
5364
{
54-
switch (port_id)
65+
66+
__declspec(dllexport) const char* PakGetName()
5567
{
56-
case 0x40:
57-
address_byte0 = value;
58-
break;
68+
static const auto name(::vcc::utils::load_string(gModuleInstance, IDS_MODULE_NAME));
69+
return name.c_str();
70+
}
5971

60-
case 0x41:
61-
address_byte1 = value;
62-
break;
72+
__declspec(dllexport) const char* PakGetCatalogId()
73+
{
74+
static const auto catalog_id(::vcc::utils::load_string(gModuleInstance, IDS_CATNUMBER));
75+
return catalog_id.c_str();
76+
}
6377

64-
case 0x42:
65-
address_byte2 = (value & 0x7);
66-
break;
78+
__declspec(dllexport) const char* PakGetDescription()
79+
{
80+
static const auto description(::vcc::utils::load_string(gModuleInstance, IDS_DESCRIPTION));
81+
return description.c_str();
82+
}
6783

68-
case 0x43:
69-
ram_[current_address_] = value;
70-
return;
7184

72-
default:
73-
return;
85+
__declspec(dllexport) void PakInitialize(
86+
void* const host_key,
87+
const char* const configuration_path,
88+
const cartridge_capi_context* const context)
89+
{
90+
initialize_state(true);
7491
}
7592

76-
current_address_ = (address_byte2 << 16) | (address_byte1 << 8) | address_byte0;
77-
}
78-
79-
unsigned char ramdisk_cartridge::read_port(unsigned char port_id)
80-
{
81-
if (port_id == 0x43)
93+
__declspec(dllexport) void PakReset()
8294
{
83-
return ram_[current_address_];
95+
initialize_state(false);
8496
}
8597

86-
return 0;
87-
}
98+
__declspec(dllexport) void PakWritePort(unsigned char port_id, unsigned char value)
99+
{
100+
switch (port_id)
101+
{
102+
case 0x40:
103+
address_byte0 = value;
104+
break;
88105

106+
case 0x41:
107+
address_byte1 = value;
108+
break;
89109

90-
void ramdisk_cartridge::initialize_state(bool initialize_memory)
91-
{
92-
current_address_ = 0;
93-
address_byte0 = 0;
94-
address_byte1 = 0;
95-
address_byte2 = 0;
96-
if (initialize_memory)
110+
case 0x42:
111+
address_byte2 = (value & 0x7);
112+
break;
113+
114+
case 0x43:
115+
ram_[current_address_] = value;
116+
return;
117+
118+
default:
119+
return;
120+
}
121+
122+
current_address_ = (address_byte2 << 16) | (address_byte1 << 8) | address_byte0;
123+
}
124+
125+
__declspec(dllexport) unsigned char PakReadPort(unsigned char port_id)
97126
{
98-
std::fill(ram_.begin(), ram_.end(), 0xff);
127+
if (port_id == 0x43)
128+
{
129+
return ram_[current_address_];
130+
}
131+
132+
return 0;
99133
}
134+
100135
}

Ramdisk/ramdisk_cartridge.h

Lines changed: 0 additions & 57 deletions
This file was deleted.

0 commit comments

Comments
 (0)