|
16 | 16 | // VCC (Virtual Color Computer). If not, see <http://www.gnu.org/licenses/>. |
17 | 17 | //////////////////////////////////////////////////////////////////////////////// |
18 | 18 | #include "becker_cartridge.h" |
| 19 | +#include "configuration_dialog.h" |
19 | 20 | #include "resource.h" |
| 21 | +#include <vcc/devices/serial/beckerport.h> |
| 22 | +#include <vcc/bus/cartridge_capi.h> |
20 | 23 | #include <vcc/utils/winapi.h> |
21 | 24 | #include <vcc/utils/persistent_value_store.h> |
22 | 25 | #include "../CartridgeMenu.h" |
| 26 | +#include <Windows.h> |
23 | 27 |
|
24 | 28 | // Contains Becker cart exports |
| 29 | +HINSTANCE gModuleInstance; |
25 | 30 |
|
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; |
32 | 34 |
|
| 35 | + struct menu_identifiers |
| 36 | + { |
| 37 | + static const UINT open_configuration = 16; |
| 38 | + }; |
33 | 39 |
|
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; |
37 | 47 | } |
38 | 48 |
|
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) |
40 | 54 | { |
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; |
42 | 61 | } |
43 | 62 |
|
44 | | -becker_cartridge::description_type becker_cartridge::description() const |
| 63 | +extern "C" |
45 | 64 | { |
46 | | - return ::vcc::utils::load_string(module_instance_, IDS_DESCRIPTION); |
47 | | -} |
48 | 65 |
|
| 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 | + } |
49 | 71 |
|
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 | + } |
52 | 77 |
|
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 | + } |
55 | 83 |
|
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); |
60 | 84 |
|
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; |
64 | 93 |
|
| 94 | + ::vcc::utils::persistent_value_store settings(configuration_path_); |
65 | 95 |
|
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); |
71 | 100 |
|
| 101 | + build_menu(); |
| 102 | + } |
72 | 103 |
|
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() |
76 | 106 | { |
77 | | - gBecker.write(value,port_id); |
| 107 | + gBecker.enable(false); |
| 108 | + configuration_dialog_.close(); |
78 | 109 | } |
79 | | -} |
80 | 110 |
|
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; |
87 | 111 |
|
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 | + } |
90 | 118 | } |
91 | 119 |
|
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; |
94 | 126 |
|
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 | + } |
99 | 130 |
|
| 131 | + return 0; |
| 132 | + } |
100 | 133 |
|
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) |
104 | 135 | { |
105 | | - configuration_dialog_.open(); |
| 136 | + gBecker.status(text_buffer); // text buffer size?? |
106 | 137 | } |
| 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 | + |
107 | 148 | } |
108 | 149 |
|
109 | 150 |
|
110 | | -void becker_cartridge::build_menu() const |
| 151 | +static void build_menu() |
111 | 152 | { |
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); |
116 | 157 | } |
117 | 158 |
|
118 | 159 |
|
119 | | -becker_cartridge::string_type becker_cartridge::server_address() const |
| 160 | +std::string becker_server_address() |
120 | 161 | { |
121 | 162 | return gBecker.server_address(); |
122 | 163 | } |
123 | 164 |
|
124 | | -becker_cartridge::string_type becker_cartridge::server_port() const |
| 165 | +std::string becker_server_port() |
125 | 166 | { |
126 | 167 | return gBecker.server_port(); |
127 | 168 | } |
128 | 169 |
|
129 | 170 | // 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) |
131 | 172 | { |
132 | 173 | gBecker.sethost(server_address.c_str(), server_port.c_str()); |
133 | 174 |
|
134 | | - ::vcc::utils::persistent_value_store settings(context_->configuration_path()); |
| 175 | + ::vcc::utils::persistent_value_store settings(configuration_path_); |
135 | 176 |
|
136 | 177 | settings.write(configuration_section_id_, "DWServerAddr", server_address); |
137 | 178 | settings.write(configuration_section_id_, "DWServerPort", server_port); |
|
0 commit comments