Skip to content

Commit 05f2e17

Browse files
committed
convert becker port to use procedural api
1 parent 8555604 commit 05f2e17

File tree

7 files changed

+113
-228
lines changed

7 files changed

+113
-228
lines changed

becker/becker.vcxproj

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -98,23 +98,6 @@
9898
</Link>
9999
</ItemDefinitionGroup>
100100
<ItemGroup>
101-
<ClCompile Include="main.cpp">
102-
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Legacy|Win32'">NotUsing</PrecompiledHeader>
103-
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">NotUsing</PrecompiledHeader>
104-
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">NotUsing</PrecompiledHeader>
105-
<PrecompiledHeaderFile Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
106-
</PrecompiledHeaderFile>
107-
<PrecompiledHeaderOutputFile Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
108-
</PrecompiledHeaderOutputFile>
109-
<PrecompiledHeaderFile Condition="'$(Configuration)|$(Platform)'=='Legacy|Win32'">
110-
</PrecompiledHeaderFile>
111-
<PrecompiledHeaderFile Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
112-
</PrecompiledHeaderFile>
113-
<PrecompiledHeaderOutputFile Condition="'$(Configuration)|$(Platform)'=='Legacy|Win32'">
114-
</PrecompiledHeaderOutputFile>
115-
<PrecompiledHeaderOutputFile Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
116-
</PrecompiledHeaderOutputFile>
117-
</ClCompile>
118101
<ClCompile Include="becker_cartridge.cpp" />
119102
<ClCompile Include="configuration_dialog.cpp" />
120103
</ItemGroup>

becker/becker.vcxproj.filters

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,6 @@
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="becker_cartridge.cpp">
85
<Filter>Source Files</Filter>
96
</ClCompile>

becker/becker_cartridge.cpp

Lines changed: 103 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -16,122 +16,163 @@
1616
// VCC (Virtual Color Computer). If not, see <http://www.gnu.org/licenses/>.
1717
////////////////////////////////////////////////////////////////////////////////
1818
#include "becker_cartridge.h"
19+
#include "configuration_dialog.h"
1920
#include "resource.h"
21+
#include <vcc/devices/serial/beckerport.h>
22+
#include <vcc/bus/cartridge_capi.h>
2023
#include <vcc/utils/winapi.h>
2124
#include <vcc/utils/persistent_value_store.h>
2225
#include "../CartridgeMenu.h"
26+
#include <Windows.h>
2327

2428
// Contains Becker cart exports
29+
HINSTANCE gModuleInstance;
2530

26-
becker_cartridge::becker_cartridge(std::unique_ptr<context_type> context, HINSTANCE module_instance)
27-
:
28-
context_(move(context)),
29-
module_instance_(module_instance),
30-
configuration_dialog_(module_instance, *this)
31-
{}
31+
namespace
32+
{
33+
using becker_device_type = ::vcc::devices::serial::Becker;
3234

35+
struct menu_identifiers
36+
{
37+
static const UINT open_configuration = 16;
38+
};
3339

34-
becker_cartridge::name_type becker_cartridge::name() const
35-
{
36-
return ::vcc::utils::load_string(module_instance_, IDS_MODULE_NAME);
40+
const std::string configuration_section_id_ = "DW Becker";
41+
42+
void* gHostKey = nullptr;
43+
const cartridge_capi_context* context_ = nullptr;
44+
std::string configuration_path_;
45+
configuration_dialog configuration_dialog_;
46+
becker_device_type gBecker;
3747
}
3848

39-
becker_cartridge::catalog_id_type becker_cartridge::catalog_id() const
49+
static void build_menu();
50+
51+
52+
// Becker dll main
53+
BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpReserved)
4054
{
41-
return ::vcc::utils::load_string(module_instance_, IDS_CATNUMBER);
55+
if (fdwReason == DLL_PROCESS_ATTACH)
56+
{
57+
gModuleInstance = hinstDLL;
58+
}
59+
60+
return true;
4261
}
4362

44-
becker_cartridge::description_type becker_cartridge::description() const
63+
extern "C"
4564
{
46-
return ::vcc::utils::load_string(module_instance_, IDS_DESCRIPTION);
47-
}
4865

66+
__declspec(dllexport) const char* PakGetName()
67+
{
68+
static const auto name(::vcc::utils::load_string(gModuleInstance, IDS_MODULE_NAME));
69+
return name.c_str();
70+
}
4971

50-
void becker_cartridge::start()
51-
{
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+
}
5277

53-
// Load becker config
54-
::vcc::utils::persistent_value_store settings(context_->configuration_path());
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+
}
5583

56-
gBecker.sethost(
57-
settings.read(configuration_section_id_, "DWServerAddr", "127.0.0.1").c_str(),
58-
settings.read(configuration_section_id_, "DWServerPort", "65504").c_str());
59-
gBecker.enable(true);
6084

61-
// Create dynamic menu
62-
build_menu();
63-
}
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+
gHostKey = host_key;
91+
configuration_path_ = configuration_path;
92+
context_ = context;
6493

94+
::vcc::utils::persistent_value_store settings(configuration_path_);
6595

66-
void becker_cartridge::stop()
67-
{
68-
gBecker.enable(false);
69-
configuration_dialog_.close();
70-
}
96+
gBecker.sethost(
97+
settings.read(configuration_section_id_, "DWServerAddr", "127.0.0.1").c_str(),
98+
settings.read(configuration_section_id_, "DWServerPort", "65504").c_str());
99+
gBecker.enable(true);
71100

101+
build_menu();
102+
}
72103

73-
void becker_cartridge::write_port(unsigned char port_id, unsigned char value)
74-
{
75-
if (port_id == 0x42)
104+
105+
__declspec(dllexport) void PakTerminate()
76106
{
77-
gBecker.write(value,port_id);
107+
gBecker.enable(false);
108+
configuration_dialog_.close();
78109
}
79-
}
80110

81-
unsigned char becker_cartridge::read_port(unsigned char port_id)
82-
{
83-
switch (port_id)
84-
{
85-
case 0x41: // read status
86-
return gBecker.read(port_id) != 0 ? 2 : 0;
87111

88-
case 0x42: // read data
89-
return gBecker.read(port_id);
112+
__declspec(dllexport) void PakWritePort(unsigned char port_id, unsigned char value)
113+
{
114+
if (port_id == 0x42)
115+
{
116+
gBecker.write(value, port_id);
117+
}
90118
}
91119

92-
return 0;
93-
}
120+
__declspec(dllexport) unsigned char PakReadPort(unsigned char port_id)
121+
{
122+
switch (port_id)
123+
{
124+
case 0x41: // read status
125+
return gBecker.read(port_id) != 0 ? 2 : 0;
94126

95-
void becker_cartridge::status(char* text_buffer, size_t buffer_size)
96-
{
97-
gBecker.status(text_buffer); // text buffer size??
98-
}
127+
case 0x42: // read data
128+
return gBecker.read(port_id);
129+
}
99130

131+
return 0;
132+
}
100133

101-
void becker_cartridge::menu_item_clicked(unsigned char menu_item_id)
102-
{
103-
if (menu_item_id == menu_identifiers::open_configuration)
134+
__declspec(dllexport) void PakGetStatus(char* text_buffer, [[maybe_unused]] size_t buffer_size)
104135
{
105-
configuration_dialog_.open();
136+
gBecker.status(text_buffer); // text buffer size??
106137
}
138+
139+
140+
__declspec(dllexport) void PakMenuItemClicked(unsigned char menu_item_id)
141+
{
142+
if (menu_item_id == menu_identifiers::open_configuration)
143+
{
144+
configuration_dialog_.open();
145+
}
146+
}
147+
107148
}
108149

109150

110-
void becker_cartridge::build_menu() const
151+
static void build_menu()
111152
{
112-
context_->add_menu_item("", MID_BEGIN, MIT_Head);
113-
context_->add_menu_item("", MID_ENTRY, MIT_Seperator);
114-
context_->add_menu_item("DriveWire Server..", ControlId(menu_identifiers::open_configuration), MIT_StandAlone);
115-
context_->add_menu_item("", MID_FINISH, MIT_Head);
153+
context_->add_menu_item(gHostKey, "", MID_BEGIN, MIT_Head);
154+
context_->add_menu_item(gHostKey, "", MID_ENTRY, MIT_Seperator);
155+
context_->add_menu_item(gHostKey, "DriveWire Server..", ControlId(menu_identifiers::open_configuration), MIT_StandAlone);
156+
context_->add_menu_item(gHostKey, "", MID_FINISH, MIT_Head);
116157
}
117158

118159

119-
becker_cartridge::string_type becker_cartridge::server_address() const
160+
std::string becker_server_address()
120161
{
121162
return gBecker.server_address();
122163
}
123164

124-
becker_cartridge::string_type becker_cartridge::server_port() const
165+
std::string becker_server_port()
125166
{
126167
return gBecker.server_port();
127168
}
128169

129170
// Save becker config
130-
void becker_cartridge::configure_server(string_type server_address, string_type server_port)
171+
void becker_configure_server(std::string server_address, std::string server_port)
131172
{
132173
gBecker.sethost(server_address.c_str(), server_port.c_str());
133174

134-
::vcc::utils::persistent_value_store settings(context_->configuration_path());
175+
::vcc::utils::persistent_value_store settings(configuration_path_);
135176

136177
settings.write(configuration_section_id_, "DWServerAddr", server_address);
137178
settings.write(configuration_section_id_, "DWServerPort", server_port);

becker/becker_cartridge.h

Lines changed: 5 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -16,63 +16,11 @@
1616
// VCC (Virtual Color Computer). If not, see <http://www.gnu.org/licenses/>.
1717
////////////////////////////////////////////////////////////////////////////////
1818
#pragma once
19-
#include "configuration_dialog.h"
20-
#include <vcc/devices/serial/beckerport.h>
21-
#include <vcc/bus/cartridge.h>
22-
#include <vcc/bus/cartridge_context.h>
23-
#include <memory>
2419
#include <Windows.h>
20+
#include <string>
2521

22+
extern HINSTANCE gModuleInstance;
2623

27-
class becker_cartridge
28-
:
29-
public ::vcc::bus::cartridge,
30-
private ::cartridge_controller
31-
{
32-
public:
33-
34-
using context_type = ::vcc::bus::cartridge_context;
35-
using becker_device_type = ::vcc::devices::serial::Becker;
36-
37-
38-
public:
39-
40-
becker_cartridge(std::unique_ptr<context_type> context, HINSTANCE module_instance);
41-
42-
name_type name() const override;
43-
catalog_id_type catalog_id() const override;
44-
description_type description() const override;
45-
46-
void start() override;
47-
void stop() override;
48-
49-
void write_port(unsigned char port_id, unsigned char value) override;
50-
unsigned char read_port(unsigned char port_id) override;
51-
52-
void status(char* text_buffer, size_t buffer_size) override;
53-
void menu_item_clicked(unsigned char menu_item_id) override;
54-
55-
56-
protected:
57-
58-
string_type server_address() const override;
59-
string_type server_port() const override;
60-
void configure_server(string_type server_address, string_type server_port) override;
61-
62-
void build_menu() const;
63-
64-
65-
private:
66-
67-
struct menu_identifiers
68-
{
69-
static const UINT open_configuration = 16;
70-
};
71-
72-
static const inline std::string configuration_section_id_ = "DW Becker";
73-
74-
const std::unique_ptr<context_type> context_;
75-
const HINSTANCE module_instance_;
76-
configuration_dialog configuration_dialog_;
77-
becker_device_type gBecker;
78-
};
24+
std::string becker_server_address();
25+
std::string becker_server_port();
26+
void becker_configure_server(std::string server_address, std::string server_port);

becker/configuration_dialog.cpp

Lines changed: 5 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -16,26 +16,18 @@
1616
// VCC (Virtual Color Computer). If not, see <http://www.gnu.org/licenses/>.
1717
////////////////////////////////////////////////////////////////////////////////
1818
#include "configuration_dialog.h"
19+
#include "becker_cartridge.h"
1920
#include "resource.h"
2021
#include <vcc/common/DialogOps.h>
2122
#include <vcc/utils/winapi.h>
2223

2324

24-
configuration_dialog::configuration_dialog(
25-
HINSTANCE module_handle,
26-
controller_type& controller)
27-
:
28-
module_handle_(module_handle),
29-
controller_(controller)
30-
{}
31-
32-
3325
void configuration_dialog::open()
3426
{
3527
if (!dialog_handle_)
3628
{
3729
dialog_handle_ = CreateDialogParam(
38-
module_handle_,
30+
gModuleInstance,
3931
MAKEINTRESOURCE(IDD_PROPPAGE),
4032
GetActiveWindow(),
4133
callback_procedure,
@@ -110,21 +102,21 @@ INT_PTR configuration_dialog::process_message(
110102
IDC_TCPHOST,
111103
WM_SETTEXT,
112104
0,
113-
reinterpret_cast<LPARAM>(controller_.server_address().c_str()));
105+
reinterpret_cast<LPARAM>(becker_server_address().c_str()));
114106
SendDlgItemMessage(
115107
hDlg,
116108
IDC_TCPPORT,
117109
WM_SETTEXT,
118110
0,
119-
reinterpret_cast<LPARAM>(controller_.server_port().c_str()));
111+
reinterpret_cast<LPARAM>(becker_server_port().c_str()));
120112
return TRUE;
121113

122114
case WM_COMMAND:
123115
switch (LOWORD(wParam))
124116
{
125117
case IDOK:
126118
// Save config dialog data
127-
controller_.configure_server(
119+
becker_configure_server(
128120
::vcc::utils::get_dialog_item_text(hDlg, IDC_TCPHOST),
129121
::vcc::utils::get_dialog_item_text(hDlg, IDC_TCPPORT));
130122
EndDialog(hDlg, LOWORD(wParam));

0 commit comments

Comments
 (0)