|
15 | 15 | // You should have received a copy of the GNU General Public License along with |
16 | 16 | // VCC (Virtual Color Computer). If not, see <http://www.gnu.org/licenses/>. |
17 | 17 | //////////////////////////////////////////////////////////////////////////////// |
18 | | -#include "ramdisk_cartridge.h" |
19 | 18 | #include "resource.h" |
20 | 19 | #include <vcc/utils/winapi.h> |
| 20 | +#include <vcc/bus/cartridge_capi.h> |
| 21 | +#include <array> |
21 | 22 |
|
22 | 23 |
|
23 | 24 | extern HINSTANCE gModuleInstance; |
24 | 25 |
|
25 | | - |
26 | | -ramdisk_cartridge::name_type ramdisk_cartridge::name() const |
| 26 | +namespace |
27 | 27 | { |
28 | | - return ::vcc::utils::load_string(gModuleInstance, IDS_MODULE_NAME); |
29 | | -} |
| 28 | + using address_type = ::std::size_t; |
30 | 29 |
|
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_; |
35 | 35 |
|
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 | + } |
39 | 47 | } |
40 | 48 |
|
| 49 | +HINSTANCE gModuleInstance; |
41 | 50 |
|
42 | | -void ramdisk_cartridge::start() |
43 | | -{ |
44 | | - initialize_state(true); |
45 | | -} |
46 | 51 |
|
47 | | -void ramdisk_cartridge::reset() |
| 52 | +BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpReserved) |
48 | 53 | { |
49 | | - initialize_state(false); |
| 54 | + if (fdwReason == DLL_PROCESS_ATTACH) |
| 55 | + { |
| 56 | + gModuleInstance = hinstDLL; |
| 57 | + } |
| 58 | + |
| 59 | + return true; |
50 | 60 | } |
51 | 61 |
|
52 | | -void ramdisk_cartridge::write_port(unsigned char port_id, unsigned char value) |
| 62 | + |
| 63 | +extern "C" |
53 | 64 | { |
54 | | - switch (port_id) |
| 65 | + |
| 66 | + __declspec(dllexport) const char* PakGetName() |
55 | 67 | { |
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 | + } |
59 | 71 |
|
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 | + } |
63 | 77 |
|
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 | + } |
67 | 83 |
|
68 | | - case 0x43: |
69 | | - ram_[current_address_] = value; |
70 | | - return; |
71 | 84 |
|
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); |
74 | 91 | } |
75 | 92 |
|
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() |
82 | 94 | { |
83 | | - return ram_[current_address_]; |
| 95 | + initialize_state(false); |
84 | 96 | } |
85 | 97 |
|
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; |
88 | 105 |
|
| 106 | + case 0x41: |
| 107 | + address_byte1 = value; |
| 108 | + break; |
89 | 109 |
|
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) |
97 | 126 | { |
98 | | - std::fill(ram_.begin(), ram_.end(), 0xff); |
| 127 | + if (port_id == 0x43) |
| 128 | + { |
| 129 | + return ram_[current_address_]; |
| 130 | + } |
| 131 | + |
| 132 | + return 0; |
99 | 133 | } |
| 134 | + |
100 | 135 | } |
0 commit comments