Publish VCC Plus OSS source distribution for 3.6.2 build 60
This commit is contained in:
commit
c652a5276d
1192 files changed
+272368
No files matched your search
@@ -0,0 +1,211 @@
|
||||
|
||||
This describes the cartridge interface design for VCC
|
||||
|
||||
---
|
||||
|
||||
# VCC Cartridge Types
|
||||
|
||||
VCC emulates the physical cartridges that could be plugged into the side expansion slot
|
||||
of a CoCo 3 or into a MultiPak Interface. VCC supports three main categories of cartridges:
|
||||
|
||||
---
|
||||
|
||||
## 1. ROM Cartridges
|
||||
|
||||
ROM cartridges contain only read-only memory and the minimal hardware needed to expose that
|
||||
memory to the CoCo 3.
|
||||
|
||||
**Characteristics:**
|
||||
|
||||
- Typically contain 6809 or 6309 executable code.
|
||||
- The CoCo reads data directly from mapped ROM addresses.
|
||||
- Some cartridges support bank switching by writing to I/O ports.
|
||||
- In VCC, all ROM banking logic is implemented inside the emulator itself.
|
||||
- ROM cartridges require no host-side code.
|
||||
- They are stored as simple binary files.
|
||||
- Some ROM files include headers or signatures to indicate special mapping or banking behavior.
|
||||
- Most common ROM cartridges were 16 KB or smaller and mapped at `0xC000` in ROM mode.
|
||||
|
||||
---
|
||||
|
||||
## 2. Hardware Cartridges
|
||||
|
||||
Hardware cartridges contain actual devices, such as:
|
||||
|
||||
- Disk controllers
|
||||
- Sound synthesizers
|
||||
- RS-232 interfaces
|
||||
- Additional microprocessors
|
||||
- Often, onboard ROM
|
||||
|
||||
These cartridges require host-side x86 code to emulate their hardware behavior.
|
||||
|
||||
**In VCC:**
|
||||
|
||||
- Hardware cartridges are implemented as **Windows DLLs**.
|
||||
- VCC identifies them by checking for the `MZ` signature at the start of the file.
|
||||
- Hardware DLL's must export the PakInitialize call to be valid
|
||||
- ROM data for these cartridges is usually stored separately, though this is not required.
|
||||
- Some hardware cartridges can load multiple ROMs and switch between them under program control.
|
||||
- The DLL is responsible for loading and managing these ROMs.
|
||||
- The CoCo communicates with the emulated hardware by reading and writing specific I/O ports.
|
||||
- Hardware cartridges may generate interrupts or output audio through a dedicated sound channel.
|
||||
- Hardware cartridges cannot load other hardware cartridges.
|
||||
|
||||
---
|
||||
|
||||
## 3. MultiPak Cartridge (MPI)
|
||||
|
||||
MultiPak is a special type of hardware cartridge, not really a true cartridge, it is a
|
||||
bus expansion that acts as hosts for other hardware cartridges.
|
||||
|
||||
**Capabilities:**
|
||||
|
||||
- MultiPak Cartridge DLL must export the init MPI call to be valid
|
||||
- Provide multiple cartridge slots.
|
||||
- Contains no ROM of it's own
|
||||
- Allow slot selection through UI controls or programmatically.
|
||||
|
||||
**VCC support:**
|
||||
|
||||
- VCC currently emulates the original Radio Shack MultiPak Interface.
|
||||
- Multipak can only be inserted Coco slide slot, not into another multipak.
|
||||
- Third-party MultiPak-style devices also exist, including:
|
||||
- Two-slot versions
|
||||
- Hobbyist designs supporting up to eight slots
|
||||
|
||||
---
|
||||
|
||||
# Cartridge Loader: Cartridge Type Identification Logic
|
||||
|
||||
The cartridge loader determines the cartridge type using the following sequence:
|
||||
|
||||
1. **Check if the file can be read**
|
||||
- If it cannot be read, the cartridge is **not loadable**.
|
||||
|
||||
2. **Check if the file is a DLL**
|
||||
- If it is *not* a DLL, the cartridge is a **ROM Cartridge**.
|
||||
|
||||
3. **Check if the DLL exports `InitCart`**
|
||||
- If it does *not*, the cartridge is **not loadable**.
|
||||
|
||||
4. **Check if the DLL exports PakGetCapabilities**
|
||||
- If it does not, the cartridge is CART_TYPE_GENERIC
|
||||
|
||||
5. Continue with loading and initialization
|
||||
|
||||
---
|
||||
|
||||
#Cartridge Exports
|
||||
|
||||
DLL's can export any of the following calls
|
||||
|
||||
Initiate pack (REQUIRED)
|
||||
PakInitialize (SLotId, settings_path, hVccWnd, &callbacks);
|
||||
|
||||
Retrieve cart menu item
|
||||
PakGetMenuItem(item, index);
|
||||
|
||||
Get cart capabilities (PROPOSED)
|
||||
PakGetCapabilities (void);
|
||||
|
||||
Terminate pack, prepare for DLL unload
|
||||
PakTerminate ()
|
||||
|
||||
Get pack name
|
||||
PakGetName (name, buf_size)
|
||||
|
||||
Get pack ID
|
||||
PakGetCatalogId (catalogId, buf_size)
|
||||
|
||||
Get pack description
|
||||
PakGetDescription (Description, buf_size)
|
||||
|
||||
Reset the pack
|
||||
PakReset ()
|
||||
|
||||
Horizontal sync occurred
|
||||
PakProcessHorizontalSync ()
|
||||
|
||||
Get pack status line text
|
||||
PakGetStatus (Status, buf_size)
|
||||
|
||||
Write I/O port
|
||||
PakWritePort (Port, data)
|
||||
|
||||
Read I/O port
|
||||
unsigned char PakReadPort (Port)
|
||||
|
||||
Read ROM byte
|
||||
unsigned char PakReadMemoryByte (Address)
|
||||
|
||||
Sample audio line
|
||||
unsigned short PakSampleAudio ()
|
||||
|
||||
A hardware pack menu item was clicked
|
||||
PakMenuItemClicked (menu_item_id)
|
||||
|
||||
---
|
||||
|
||||
#Callbacks
|
||||
|
||||
There are two ways a cartridge can initiate host actions:
|
||||
|
||||
1) Notifications initiated by cartridge UI events like adding menu items or inserting
|
||||
cartridges in slots. These are asyncronous and can rely on DLL exports for details.
|
||||
The mechanism for these is Vcc's main window message loop. The window handle (hVccWnd)
|
||||
has been added to PakInitialize() for this purpose. Two notification messages are
|
||||
defined, one to initiate a VCC reset and another to initiate cartridge menu rebuilds.
|
||||
|
||||
2) Callbacks initiated by 6x09 code running inside the CPU loop such as asserting
|
||||
interrupts, cart lines, or reading and writing memory to handle DMA requests. These
|
||||
are syncronous and must return quickly to not affect emulator timing. Callbacks are
|
||||
determined by Coco3's physical bus and are not likely to change. There are four
|
||||
callbacks:
|
||||
|
||||
void assert_cartridge_line (SlotId, line_state)
|
||||
void assert_interrupt (SlotId, interrupt, interrupt_source)
|
||||
void write_memory_byte (SlotId, value, address)
|
||||
unsigned char read_memory_byte (SlotId, unsigned short address)
|
||||
|
||||
SlotId is used by the MPI to filter assert_cartridge_line. DLL's are passed their slot
|
||||
location in PakInitialize().
|
||||
|
||||
---
|
||||
|
||||
#Proposed New Design Philosophy For The MPI (under consideration)
|
||||
|
||||
VCC and forks of VCC use run-time loading and unloading of dynamic libraries to simulate
|
||||
the inserting and removing of Cartridges.
|
||||
|
||||
A special "cartridge" is the Multipak MPI. On a physical Coco the MPI it is not actually
|
||||
a cartridge. It is more accurately an extension of the bus.
|
||||
|
||||
The pakinterface loads and unloads cartridges. So does the MPI. If both MPI and pakinterface
|
||||
call cartridge DLLs directly there are now two modules, VCC and MPI, that need to know about
|
||||
cartridge lifetimes, handles, exports, and inports. All loading and unloading of carts belongs
|
||||
in one place and that place is the PakInterface part of VCC main.
|
||||
|
||||
If slot management is moved to the Pakinterface the logic that controls the CTS and SCS and
|
||||
the management of saved slot content settings must move too. The pakinterface must share this
|
||||
information with the MPI DLL which becomes purely a user interface.
|
||||
|
||||
The pakinterface slot management concept:
|
||||
|
||||
- The pakinterface maintains a list indexed by slot number of loaded cartridges.
|
||||
|
||||
- Slots are numbered 0-4. Slot 0 is the Boot slot. Slots 1-4 loaded if MPI is in the Boot slot.
|
||||
|
||||
- The pakInterface routes I/O to slots per CTS/SCS using existing capability / callcacks
|
||||
|
||||
- The pakinterface saves slot content to settings.
|
||||
|
||||
- Any change to current CTS triggers a reset. This is detected and effected by the pakinterface
|
||||
Reset stops the CPU, unloads all cartridges, reloads the basic rom, reloads cartridges
|
||||
per settings, and then restarts the CPU.
|
||||
|
||||
- MPI sends changes to startup CTS/SCS via a notification message. Startup CTS/SCS does not
|
||||
affect the running CPU, a reset is required for them to take effect.
|
||||
|
||||
- The MPI requests cartridge loads / unloads by sending messages to WinMain.
|
||||
|
||||
@@ -0,0 +1,73 @@
|
||||
|
||||
# VCC Export Based Cartridge Menu System
|
||||
|
||||
This replaces per‑item callbacks with a export‑based model for exchanging menu
|
||||
items between cartridge DLLs, Multipak (MPI), and the PakInterface host.
|
||||
|
||||
Concept:
|
||||
|
||||
- Each cartridge DLL creates an internal list of it's menu items as needed.
|
||||
- DLL's expose an export that returns menu items from the list on demand.
|
||||
- MPI aggregates child cartridge menus, applies slot‑based ID biasing, and returns a
|
||||
unified list to the host.
|
||||
- The host pakinterface rebuilds the UI menu from the aggregated list.
|
||||
- DLLs notify the host of menu changes using a single Windows message.
|
||||
- Clear separation of responsibilities:
|
||||
- DLLs own their menu state.
|
||||
- MPI aggregates and biases.
|
||||
- Host renders.
|
||||
- The export signature remains stable even if internal implementations change.
|
||||
|
||||
---
|
||||
|
||||
## Cartridge DLL
|
||||
|
||||
- Sends WM_VCC_UPD_MENU to the host on internal state changes that affect its menu.
|
||||
- Keeps a static list of menu items that represents it's internal state.
|
||||
- Implements a GetMenuItemList(item,index) export that:
|
||||
- Updates the list as required (see note)
|
||||
- Accepts a index that indicate which entry is desired.
|
||||
- Returns the entry at that index in the item buffer.
|
||||
- Returns false if the entry does not exist.
|
||||
|
||||
Notes:
|
||||
|
||||
If the item buffer is a nullptr the DLL returns false.
|
||||
If the index is above MAX_MENU_ITEMS DLL returns false.
|
||||
An index of zero indicates the DLL's internal list should be refreshed.
|
||||
- DLL updates / recreates it's internal list as required.
|
||||
- DLL returns the first item if it exists, otherwise false.
|
||||
For indexes above zero the DLL simply returns the item or false.
|
||||
Cartridge plumbing guarantees that DLL's who don't expose the actual
|
||||
export will return false when call is attempted.
|
||||
|
||||
---
|
||||
|
||||
## Multipak (MPI)
|
||||
|
||||
MPI acts as an aggregator and applies deterministic slot‑based menu ID biasing.
|
||||
The MPI is only permitted to be installed in the boot slot. (Coco side slot)
|
||||
|
||||
MPI:
|
||||
|
||||
- Maintains references to each child cartridge’s menu export.
|
||||
- When its export is called:
|
||||
- If index is zero it refreshes it's own menu items.
|
||||
- Calls each child cartridge’s export to retrieve their items.
|
||||
- Applies slot‑based menu ID biasing:
|
||||
- Merges all items into a single unified list.
|
||||
- Returns item from the list indicated by the index.
|
||||
|
||||
---
|
||||
|
||||
## VCC
|
||||
|
||||
The host:
|
||||
|
||||
- Creates the master menu item list from which the cartridge menu is drawn
|
||||
- Listens for WM_VCC_UPD_MENU from any DLL including the MPI.
|
||||
- On receiving the message, updates it's list using calls to the boot slot's
|
||||
(slot 0) export and rebuilds the menu.
|
||||
|
||||
The host only sees a flat, final list of menu items.
|
||||
|
||||
@@ -0,0 +1,95 @@
|
||||
//#define USE_LOGGING
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
// Copyright 2015 by Joseph Forgione
|
||||
// This file is part of VCC (Virtual Color Computer).
|
||||
//
|
||||
// VCC (Virtual Color Computer) is free software: you can redistribute itand/or
|
||||
// modify it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or (at your
|
||||
// option) any later version.
|
||||
//
|
||||
// VCC (Virtual Color Computer) 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
|
||||
// VCC (Virtual Color Computer). If not, see <http://www.gnu.org/licenses/>.
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
#include <vcc/bus/basic_cartridge.h>
|
||||
#include <vcc/util/logger.h>
|
||||
#include <typeinfo>
|
||||
|
||||
namespace VCC::Core
|
||||
{
|
||||
|
||||
basic_cartridge::name_type basic_cartridge::name() const
|
||||
{
|
||||
return {};
|
||||
}
|
||||
|
||||
basic_cartridge::catalog_id_type basic_cartridge::catalog_id() const
|
||||
{
|
||||
return {};
|
||||
}
|
||||
|
||||
basic_cartridge::description_type basic_cartridge:: description() const
|
||||
{
|
||||
return {};
|
||||
}
|
||||
|
||||
|
||||
void basic_cartridge::start()
|
||||
{
|
||||
DLOG_C("basic_cartridge::start type: %s cart ptr: %p\n",
|
||||
typeid(*this).name(), this);
|
||||
initialize_pak();
|
||||
initialize_bus();
|
||||
}
|
||||
|
||||
void basic_cartridge::stop()
|
||||
{}
|
||||
|
||||
void basic_cartridge::reset()
|
||||
{}
|
||||
|
||||
void basic_cartridge::process_horizontal_sync()
|
||||
{}
|
||||
|
||||
void basic_cartridge::write_port(unsigned char port_id, unsigned char value)
|
||||
{}
|
||||
|
||||
unsigned char basic_cartridge::read_port(unsigned char port_id)
|
||||
{
|
||||
return {};
|
||||
}
|
||||
|
||||
unsigned char basic_cartridge::read_memory_byte(unsigned short memory_address)
|
||||
{
|
||||
return {};
|
||||
}
|
||||
|
||||
void basic_cartridge::status(char* text_buffer, size_t buffer_size)
|
||||
{
|
||||
*text_buffer = 0;
|
||||
}
|
||||
|
||||
unsigned short basic_cartridge::sample_audio()
|
||||
{
|
||||
return {};
|
||||
}
|
||||
|
||||
void basic_cartridge::menu_item_clicked(unsigned char menu_item_id)
|
||||
{}
|
||||
|
||||
void basic_cartridge::initialize_pak()
|
||||
{}
|
||||
|
||||
void basic_cartridge::initialize_bus()
|
||||
{}
|
||||
|
||||
bool basic_cartridge::get_menu_item( menu_item_entry* item, size_t index)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,57 @@
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
// Copyright 2015 by Joseph Forgione
|
||||
// This file is part of VCC (Virtual Color Computer).
|
||||
//
|
||||
// VCC (Virtual Color Computer) is free software: you can redistribute itand/or
|
||||
// modify it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or (at your
|
||||
// option) any later version.
|
||||
//
|
||||
// VCC (Virtual Color Computer) 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
|
||||
// VCC (Virtual Color Computer). If not, see <http://www.gnu.org/licenses/>.
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
#pragma once
|
||||
#include <vcc/bus/cartridge.h>
|
||||
|
||||
namespace VCC::Core
|
||||
{
|
||||
|
||||
struct basic_cartridge : public ::VCC::Core::cartridge
|
||||
{
|
||||
public:
|
||||
|
||||
using name_type = std::string;
|
||||
using catalog_id_type = std::string;
|
||||
|
||||
public:
|
||||
|
||||
using cartridge::cartridge;
|
||||
|
||||
name_type name() const override;
|
||||
catalog_id_type catalog_id() const override;
|
||||
description_type description() const override;
|
||||
|
||||
void start() override;
|
||||
void stop() override;
|
||||
|
||||
void reset() override;
|
||||
void process_horizontal_sync() override;
|
||||
void write_port(unsigned char port_id, unsigned char value) override;
|
||||
unsigned char read_port(unsigned char port_id) override;
|
||||
unsigned char read_memory_byte(unsigned short memory_address) override;
|
||||
void status(char* text_buffer, size_t buffer_size) override;
|
||||
unsigned short sample_audio() override;
|
||||
void menu_item_clicked(unsigned char menu_item_id) override;
|
||||
bool get_menu_item(menu_item_entry* item, size_t index) override;
|
||||
|
||||
protected:
|
||||
|
||||
virtual void initialize_pak();
|
||||
virtual void initialize_bus();
|
||||
};
|
||||
}
|
||||
@@ -0,0 +1,59 @@
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
// Copyright 2015 by Joseph Forgione
|
||||
// This file is part of VCC (Virtual Color Computer).
|
||||
//
|
||||
// VCC (Virtual Color Computer) is free software: you can redistribute itand/or
|
||||
// modify it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or (at your
|
||||
// option) any later version.
|
||||
//
|
||||
// VCC (Virtual Color Computer) 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
|
||||
// VCC (Virtual Color Computer). If not, see <http://www.gnu.org/licenses/>.
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
#pragma once
|
||||
#include <vcc/bus/cartridge_menuitem.h>
|
||||
#include <string>
|
||||
|
||||
namespace VCC::Core
|
||||
{
|
||||
struct cartridge
|
||||
{
|
||||
public:
|
||||
using name_type = std::string;
|
||||
using catalog_id_type = std::string;
|
||||
using description_type = std::string;
|
||||
|
||||
public:
|
||||
// Protect cartridge objects by deleting move constructers
|
||||
cartridge() = default;
|
||||
cartridge(const cartridge&) = delete;
|
||||
cartridge(cartridge&&) = delete;
|
||||
|
||||
// Default destructor ensures deleting a cartridge* calls
|
||||
// the destructor of cpak_cartridge or rom_cartridge
|
||||
virtual ~cartridge() = default;
|
||||
|
||||
virtual name_type name() const = 0;
|
||||
virtual catalog_id_type catalog_id() const = 0;
|
||||
virtual description_type description() const = 0;
|
||||
|
||||
virtual void start() = 0;
|
||||
virtual void stop() = 0;
|
||||
virtual void reset() = 0;
|
||||
virtual void process_horizontal_sync() = 0;
|
||||
virtual void write_port(unsigned char port_id, unsigned char value) = 0;
|
||||
virtual unsigned char read_port(unsigned char port_id) = 0;
|
||||
virtual unsigned char read_memory_byte(unsigned short memory_address) = 0;
|
||||
virtual void status(char* text_buffer, size_t buffer_size) = 0;
|
||||
virtual unsigned short sample_audio() = 0;
|
||||
virtual void menu_item_clicked(unsigned char menu_item_id) = 0;
|
||||
|
||||
// TODO following is no longer used. Should be cleaned up
|
||||
virtual bool get_menu_item(menu_item_entry* item, size_t index) = 0;
|
||||
};
|
||||
}
|
||||
@@ -0,0 +1,39 @@
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
// Copyright 2015 by Joseph Forgione
|
||||
// This file is part of VCC (Virtual Color Computer).
|
||||
//
|
||||
// VCC (Virtual Color Computer) is free software: you can redistribute itand/or
|
||||
// modify it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or (at your
|
||||
// option) any later version.
|
||||
//
|
||||
// VCC (Virtual Color Computer) 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
|
||||
// VCC (Virtual Color Computer). If not, see <http://www.gnu.org/licenses/>.
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
#pragma once
|
||||
#include "../../../../../src/core/Interrupts.h"
|
||||
#include <string>
|
||||
|
||||
enum MenuItemType;
|
||||
|
||||
namespace VCC::Core
|
||||
{
|
||||
struct cartridge_callbacks
|
||||
{
|
||||
using path_type = std::string;
|
||||
|
||||
virtual ~cartridge_callbacks() = default;
|
||||
virtual path_type configuration_path() const = 0;
|
||||
|
||||
virtual void assert_cartridge_line(bool line_state) = 0;
|
||||
virtual void assert_interrupt(Interrupt interrupt, InterruptSource interrupt_source) = 0;
|
||||
virtual void write_memory_byte(unsigned char value, unsigned short address) = 0;
|
||||
virtual unsigned char read_memory_byte(unsigned short address) = 0;
|
||||
};
|
||||
}
|
||||
|
||||
@@ -0,0 +1,247 @@
|
||||
//#define USE_LOGGING
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
// Copyright 2015 by Joseph Forgione
|
||||
// This file is part of VCC (Virtual Color Computer).
|
||||
//
|
||||
// VCC (Virtual Color Computer) is free software: you can redistribute itand/or
|
||||
// modify it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or (at your
|
||||
// option) any later version.
|
||||
//
|
||||
// VCC (Virtual Color Computer) 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
|
||||
// VCC (Virtual Color Computer). If not, see <http://www.gnu.org/licenses/>.
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
#include <vcc/bus/cartridge_loader.h>
|
||||
#include <vcc/bus/rom_cartridge.h>
|
||||
#include <vcc/bus/cpak_cartridge.h>
|
||||
#include <vcc/util/logger.h>
|
||||
#include <vector>
|
||||
#include <fstream>
|
||||
#include <iterator>
|
||||
|
||||
//----------------------------------------------------------------------------
|
||||
// The cartridge loader loads the cart's file and creates the cartridge object
|
||||
//----------------------------------------------------------------------------
|
||||
|
||||
namespace VCC::Core
|
||||
{
|
||||
namespace
|
||||
{
|
||||
//TODO use existing utility function for this
|
||||
std::string extract_filename(std::string name)
|
||||
{
|
||||
name = name.substr(name.find_last_of("/\\") + 1);
|
||||
const auto endIndex = name.find_last_of('.');
|
||||
if (endIndex > 0)
|
||||
{
|
||||
name = name.substr(0, endIndex);
|
||||
}
|
||||
return name;
|
||||
}
|
||||
}
|
||||
|
||||
cartridge_file_type determine_cartridge_type(const std::string& filename)
|
||||
{
|
||||
std::ifstream input(filename, std::ios::binary);
|
||||
|
||||
if (!input.is_open()) {
|
||||
return cartridge_file_type::not_opened;
|
||||
}
|
||||
|
||||
// Read two bytes from the start of the file
|
||||
unsigned char header[2] = {};
|
||||
input.clear();
|
||||
input.seekg(0, std::ios::beg);
|
||||
input.read(reinterpret_cast<char*>(header), 2);
|
||||
if (!input) {
|
||||
DLOG_C("cartridge_loader.determine_cartridge_type cart too small\n");
|
||||
return cartridge_file_type::rom_image;
|
||||
}
|
||||
|
||||
// Check for magic 'MZ' DLL indicator
|
||||
if (header[0] == 'M' && header[1] == 'Z') {
|
||||
DLOG_C("cartridge_loader.determine_cartridge_type Cpak\n");
|
||||
return cartridge_file_type::library;
|
||||
}
|
||||
|
||||
DLOG_C("cartridge_loader.determine_cartridge_type ROM\n");
|
||||
return cartridge_file_type::rom_image;
|
||||
}
|
||||
|
||||
// Load a ROM cartridge
|
||||
cartridge_loader_result load_rom_cartridge(
|
||||
const std::string& filename,
|
||||
slot_id_type SlotId,
|
||||
const std::string& iniPath,
|
||||
HWND hVccWnd,
|
||||
const cpak_callbacks& cpak_callbacks)
|
||||
{
|
||||
DLOG_C("cartridge_loader.load_rom_cartridge\n");
|
||||
constexpr size_t PAK_MAX_MEM = 0x40000;
|
||||
|
||||
std::vector<uint8_t> romImage;
|
||||
|
||||
romImage.reserve(PAK_MAX_MEM);
|
||||
|
||||
// Open the ROM file, fail if unable to
|
||||
std::ifstream input(filename, std::ios::binary);
|
||||
if (!input.is_open()) {
|
||||
DLOG_C("cartridge_loader.load_rom_cartridge open fail\n");
|
||||
return { nullptr, nullptr, cartridge_loader_status::cannot_open };
|
||||
}
|
||||
|
||||
// Load the file
|
||||
input.unsetf(std::ios::skipws);
|
||||
std::copy(
|
||||
std::istream_iterator<uint8_t>(input),
|
||||
std::istream_iterator<uint8_t>(),
|
||||
back_inserter(romImage));
|
||||
|
||||
if (romImage.empty()) {
|
||||
DLOG_C("cartridge_loader.load_rom_cartridge empty\n");
|
||||
return { nullptr, nullptr, cartridge_loader_status::not_rom };
|
||||
}
|
||||
|
||||
// Force enable bank switching since we don't have a way to detect if
|
||||
// it should be enabled.
|
||||
constexpr bool enable_bank_switching = true;
|
||||
|
||||
// Create rom cartridge object to contain the rom
|
||||
auto rom = std::make_unique<VCC::Core::rom_cartridge>
|
||||
(
|
||||
cpak_callbacks,
|
||||
extract_filename(filename),
|
||||
"",
|
||||
std::move(romImage),
|
||||
enable_bank_switching,
|
||||
SlotId
|
||||
);
|
||||
|
||||
auto result = cartridge_loader_result {
|
||||
nullptr,
|
||||
std::move(rom),
|
||||
cartridge_loader_status::success };
|
||||
|
||||
DLOG_C("cartridge_loader.load_rom_cartridge success %s\n",filename.c_str());
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
// Load a dll cartridge
|
||||
cartridge_loader_result load_cpak_cartridge(
|
||||
const std::string& filename,
|
||||
slot_id_type SlotId,
|
||||
const std::string& iniPath,
|
||||
HWND hVccWnd,
|
||||
const cpak_callbacks& cpak_callbacks)
|
||||
{
|
||||
|
||||
DLOG_C("cartridge_loader.load_cpak_cartridge %s\n",filename.c_str());
|
||||
|
||||
auto h = GetModuleHandle(filename.c_str());
|
||||
if (h != nullptr) {
|
||||
DLOG_C("cartridge_loader.load_cpak_cartridge duplicate load\n");
|
||||
return { nullptr, nullptr, cartridge_loader_status::already_loaded };
|
||||
}
|
||||
|
||||
// Load the cart DLL
|
||||
cartridge_loader_result details;
|
||||
HMODULE hCart = LoadLibrary(filename.c_str());
|
||||
details.dll_module.reset(hCart);
|
||||
|
||||
if (details.dll_module == nullptr)
|
||||
{
|
||||
DLOG_C("cartridge_loader.load_cpak_cartridge dll load failed\n");
|
||||
return { nullptr, nullptr, cartridge_loader_status::cannot_open };
|
||||
}
|
||||
|
||||
// Create cartridge object if DLL has a PakInitialize export
|
||||
if (GetProcAddress(details.dll_module.get(), "PakInitialize") != nullptr)
|
||||
{
|
||||
details.cartridge = std::make_unique<VCC::Core::cpak_cartridge>(
|
||||
details.dll_module.get(),
|
||||
SlotId,
|
||||
iniPath,
|
||||
hVccWnd,
|
||||
cpak_callbacks);
|
||||
details.load_result = cartridge_loader_status::success;
|
||||
DLOG_C("cartridge_loader.load_cpak_cartridge success %p\n",details.cartridge.get());
|
||||
return details;
|
||||
}
|
||||
|
||||
// Else not a valid cartridge plugin DLL
|
||||
DLOG_C("cartridge_loader.load_cpak_cartridge dll initialize missing\n");
|
||||
return { nullptr, nullptr, cartridge_loader_status::not_expansion };
|
||||
}
|
||||
|
||||
// Load a cartridge; either a ROM image or a pak dll. Load cartridge is called
|
||||
// by both mpi/multipak_cartridge.cpp and pakinterface.cpp.
|
||||
// cartridge_loader_result is defined in libcommon/include/vcc/bus/cartridge_loader.h
|
||||
// cartridge_callbacks is defined in libcommon/include/vcc/bus/cartridge_callbacks.h
|
||||
// SlotId is size_t 0-4, 0 = boot slot (side slot), 1-4 = MPI slots. SlotId is
|
||||
// passed to cpak cart DLLs and is returned as first argment of callbacks
|
||||
// cpak_callbacks is used by all hardware paks and is defined in
|
||||
// libcommon/include/vcc/bus/cpak_cartridge_definitions.h.
|
||||
cartridge_loader_result load_cartridge(
|
||||
const std::string& filename,
|
||||
slot_id_type SlotId,
|
||||
const std::string& iniPath,
|
||||
HWND hVccWnd,
|
||||
const cpak_callbacks& cpak_callbacks)
|
||||
{
|
||||
DLOG_C("cartridge_loader.load_cartridge %d %s\n", SlotId,filename.c_str());
|
||||
|
||||
switch (VCC::Core::determine_cartridge_type(filename))
|
||||
{
|
||||
default:
|
||||
case cartridge_file_type::not_opened: // File doesn't exist or can't be opened
|
||||
return { nullptr, nullptr, cartridge_loader_status::cannot_open };
|
||||
|
||||
case cartridge_file_type::rom_image: // File is a ROM image
|
||||
return VCC::Core::load_rom_cartridge(
|
||||
filename,
|
||||
SlotId,
|
||||
iniPath,
|
||||
hVccWnd,
|
||||
cpak_callbacks);
|
||||
|
||||
case cartridge_file_type::library: // File is a DLL
|
||||
return VCC::Core::load_cpak_cartridge(
|
||||
filename,
|
||||
SlotId, // Where cart is inserted
|
||||
iniPath, // Path to vcc ini file
|
||||
hVccWnd, // Vcc message proxy window
|
||||
cpak_callbacks); // DLL callbacks in here
|
||||
}
|
||||
}
|
||||
|
||||
// Return error string per cartridge load status.
|
||||
// TODO: Move and make this generic so it also can be used elsewhere in the project
|
||||
std::string cartridge_load_error_string(const cartridge_loader_status error_status)
|
||||
{
|
||||
switch (error_status)
|
||||
{
|
||||
case cartridge_loader_status::success:
|
||||
return "Success";
|
||||
case cartridge_loader_status::already_loaded:
|
||||
return "Module is already loaded.";
|
||||
case cartridge_loader_status::cannot_open:
|
||||
return "Cannot open module.";
|
||||
case cartridge_loader_status::not_found:
|
||||
return "Module not found.";
|
||||
case cartridge_loader_status::not_loaded:
|
||||
return "Unable to load module.";
|
||||
case cartridge_loader_status::not_rom:
|
||||
return "Module is not a valid ROM image.";
|
||||
case cartridge_loader_status::not_expansion:
|
||||
return "Module is not a valid expansion plugin.";
|
||||
default:
|
||||
return "Unknown error.";
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,91 @@
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
// Copyright 2015 by Joseph Forgione
|
||||
// This file is part of VCC (Virtual Color Computer).
|
||||
//
|
||||
// VCC (Virtual Color Computer) is free software: you can redistribute itand/or
|
||||
// modify it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or (at your
|
||||
// option) any later version.
|
||||
//
|
||||
// VCC (Virtual Color Computer) 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
|
||||
// VCC (Virtual Color Computer). If not, see <http://www.gnu.org/licenses/>.
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
#pragma once
|
||||
#include <vcc/bus/cartridge.h>
|
||||
#include <vcc/bus/cartridge_callbacks.h>
|
||||
#include <vcc/bus/cpak_cartridge_definitions.h>
|
||||
#include <string>
|
||||
#include <memory>
|
||||
#include <Windows.h>
|
||||
|
||||
namespace VCC::Core
|
||||
{
|
||||
enum class cartridge_file_type
|
||||
{
|
||||
not_opened,
|
||||
rom_image,
|
||||
library
|
||||
};
|
||||
|
||||
enum class cartridge_loader_status
|
||||
{
|
||||
success,
|
||||
already_loaded,
|
||||
cannot_open,
|
||||
not_found,
|
||||
not_loaded,
|
||||
not_rom,
|
||||
not_expansion
|
||||
};
|
||||
|
||||
struct dll_deleter {
|
||||
void operator()(HMODULE h) const {
|
||||
if (h) FreeLibrary(h);
|
||||
}
|
||||
};
|
||||
|
||||
struct cartridge_loader_result
|
||||
{
|
||||
using dll_module_type =
|
||||
std::unique_ptr<std::remove_pointer_t<HMODULE>,VCC::Core::dll_deleter>;
|
||||
using cartridge_ptr_type = std::unique_ptr<VCC::Core::cartridge>;
|
||||
|
||||
dll_module_type dll_module;
|
||||
cartridge_ptr_type cartridge;
|
||||
cartridge_loader_status load_result = cartridge_loader_status::not_loaded;
|
||||
};
|
||||
|
||||
cartridge_file_type determine_cartridge_type(const std::string& filename);
|
||||
|
||||
//-------------------------------------------------------------------------------
|
||||
// Cartridge Loaders. Determine type and call appropriate loader, rom or cpak
|
||||
// SlotID is the 0-4 slot id; 0 is the boot slot, 1-4 are multipak slots.
|
||||
// iniPath is the name of the ini file (typically vcc.ini)
|
||||
// hVccWnd is the VCC main window handle, used for messaging
|
||||
// cpak_callbacks defines the cartridge callbacks
|
||||
//-------------------------------------------------------------------------------
|
||||
|
||||
cartridge_loader_result load_cartridge(
|
||||
const std::string& filename,
|
||||
slot_id_type SlotId,
|
||||
const std::string& iniPath,
|
||||
HWND hVccWnd,
|
||||
const cpak_callbacks& cpak_callbacks);
|
||||
|
||||
cartridge_loader_result load_cpak_cartridge(
|
||||
const std::string& filename,
|
||||
slot_id_type SlotId,
|
||||
const std::string& iniPath,
|
||||
HWND hVccWnd,
|
||||
const cpak_callbacks& cpak_callbacks);
|
||||
|
||||
// Return load error string per cartridge load status
|
||||
std::string cartridge_load_error_string(
|
||||
const cartridge_loader_status error_status);
|
||||
|
||||
}
|
||||
@@ -0,0 +1,137 @@
|
||||
//#define USE_LOGGING
|
||||
//======================================================================
|
||||
// This file is part of VCC (Virtual Color Computer).
|
||||
// Vcc is Copyright 2015 by Joseph Forgione
|
||||
//
|
||||
// VCC (Virtual Color Computer) is free software, you can redistribute
|
||||
// and/or modify it under the terms of the GNU General Public License
|
||||
// as published by the Free Software Foundation, either version 3 of
|
||||
// the License, or (at your option) any later version.
|
||||
//
|
||||
// VCC (Virtual Color Computer) 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 VCC (Virtual Color Computer). If not, see
|
||||
// <http://www.gnu.org/licenses/>.
|
||||
//======================================================================
|
||||
|
||||
#include <vcc/bus/cartridge_menu.h>
|
||||
#include <vcc/bus/cartridge_menuitem.h>
|
||||
#include <vcc/util/logger.h>
|
||||
#include <vcc/util/coreutil.h>
|
||||
|
||||
namespace VCC::Bus {
|
||||
|
||||
// Global cart menu for vcc.exe
|
||||
// DLL's should never use this
|
||||
cartridge_menu gVccCartMenu;
|
||||
|
||||
// Cart menu for DLL use
|
||||
// Vcc or pakinterface should not use this
|
||||
cartridge_menu gDllCartMenu;
|
||||
|
||||
// ------------------------------------------------------------
|
||||
// Copy a menu item to the API safe structure
|
||||
// ------------------------------------------------------------
|
||||
bool cartridge_menu::copy_item(menu_item_entry& out, size_t index) const
|
||||
{
|
||||
if (index >= menu_.size() || index >= MAX_MENU_ITEMS)
|
||||
return false;
|
||||
|
||||
const auto& src = menu_[index];
|
||||
|
||||
// std::min won't work for legacy builds so ...
|
||||
// size_t n = sizeof(out.name) -1;
|
||||
// n = src.name.size() < n ? src.name.size() : n;
|
||||
size_t n = VCC::Util::min_compat(src.name.size(), sizeof(out.name) - 1);
|
||||
|
||||
memcpy(out.name, src.name.data(), n);
|
||||
out.name[n] = '\0';
|
||||
|
||||
out.menu_id = src.menu_id;
|
||||
out.type = src.type;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------
|
||||
// Draw the menu. DLL's should not call this
|
||||
// ------------------------------------------------------------
|
||||
HMENU cartridge_menu::draw(HWND hWnd, int position, const std::string& title)
|
||||
{
|
||||
auto hMenuBar = GetMenu(hWnd);
|
||||
|
||||
// Erase the Existing Cartridge Menu. Vcc.rc defines
|
||||
// a dummy Cartridge menu to preserve it's place.
|
||||
DeleteMenu(hMenuBar,position,MF_BYPOSITION);
|
||||
|
||||
// Create first sub menu item
|
||||
HMENU hMenu = CreatePopupMenu();
|
||||
HMENU hMenu0 = hMenu;
|
||||
|
||||
MENUITEMINFO Mii{};
|
||||
memset(&Mii,0,sizeof(MENUITEMINFO));
|
||||
Mii.cbSize= sizeof(MENUITEMINFO);
|
||||
|
||||
// Create title bar item
|
||||
Mii.fMask = MIIM_TYPE | MIIM_SUBMENU | MIIM_ID; // setting the submenu id
|
||||
Mii.fType = MFT_STRING; // Type is a string
|
||||
Mii.hSubMenu = hMenu;
|
||||
Mii.dwTypeData = const_cast<LPSTR>(title.c_str());
|
||||
Mii.cch = title.size();
|
||||
InsertMenuItem(hMenuBar,position,TRUE,&Mii);
|
||||
|
||||
// Create sub menus in order
|
||||
unsigned int pos = 0u;
|
||||
for (CartMenuItem item : menu_) {
|
||||
DLOG_C("%4d %d '%s'\n",item.menu_id,item.type,item.name.c_str());
|
||||
switch (item.type) {
|
||||
case MIT_Head:
|
||||
hMenu = CreatePopupMenu();
|
||||
Mii.fMask = MIIM_TYPE | MIIM_SUBMENU | MIIM_ID;
|
||||
Mii.fType = MFT_STRING;
|
||||
Mii.hSubMenu = hMenu;
|
||||
Mii.dwTypeData = const_cast<LPSTR>(item.name.c_str());
|
||||
Mii.cch = item.name.size();
|
||||
InsertMenuItem(hMenu0,pos,TRUE,&Mii);
|
||||
pos++;
|
||||
break;
|
||||
case MIT_Slave:
|
||||
Mii.fMask = MIIM_TYPE | MIIM_ID;
|
||||
Mii.fType = MFT_STRING;
|
||||
Mii.wID = item.menu_id;
|
||||
Mii.hSubMenu = hMenu;
|
||||
Mii.dwTypeData = const_cast<LPSTR>(item.name.c_str());
|
||||
Mii.cch=item.name.size();
|
||||
InsertMenuItem(hMenu,0,FALSE,&Mii);
|
||||
break;
|
||||
case MIT_Seperator:
|
||||
Mii.fMask = MIIM_TYPE;
|
||||
Mii.hSubMenu = hMenuBar;
|
||||
Mii.dwTypeData = "";
|
||||
Mii.cch=0;
|
||||
Mii.fType = MF_SEPARATOR;
|
||||
InsertMenuItem(hMenu0,pos,TRUE,&Mii);
|
||||
pos++;
|
||||
break;
|
||||
case MIT_StandAlone:
|
||||
Mii.fMask = MIIM_TYPE | MIIM_ID;
|
||||
Mii.wID = item.menu_id;
|
||||
Mii.hSubMenu = hMenuBar;
|
||||
Mii.dwTypeData = const_cast<LPSTR>(item.name.c_str());
|
||||
Mii.cch=item.name.size();
|
||||
Mii.fType = MFT_STRING;
|
||||
InsertMenuItem(hMenu0,pos,TRUE,&Mii);
|
||||
pos++;
|
||||
break;
|
||||
}
|
||||
}
|
||||
DrawMenuBar(hWnd);
|
||||
return hMenu0;
|
||||
}
|
||||
|
||||
} // namespace VCC::Bus
|
||||
|
||||
@@ -0,0 +1,109 @@
|
||||
//#define USE_LOGGING
|
||||
//======================================================================
|
||||
// This file is part of VCC (Virtual Color Computer).
|
||||
// Vcc is Copyright 2015 by Joseph Forgione
|
||||
//
|
||||
// VCC (Virtual Color Computer) is free software, you can redistribute
|
||||
// and/or modify it under the terms of the GNU General Public License
|
||||
// as published by the Free Software Foundation, either version 3 of
|
||||
// the License, or (at your option) any later version.
|
||||
//
|
||||
// VCC (Virtual Color Computer) 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 VCC (Virtual Color Computer). If not, see
|
||||
// <http://www.gnu.org/licenses/>.
|
||||
//======================================================================
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <Windows.h>
|
||||
#include <vector>
|
||||
#include <string>
|
||||
#include <vcc/util/logger.h>
|
||||
#include <vcc/bus/cartridge_menuitem.h>
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
// cartridge_menu objects hold cartridge menu lists.
|
||||
//
|
||||
// Every cartridge DLL that uses menu items holds a cartridge_menu
|
||||
// list for it's items. When it modifies what is in it's list it posts
|
||||
// a menu changed message to Vcc main.
|
||||
//
|
||||
// Menu building and drawing is controlled by the PakInterface and
|
||||
// is initiated by VCC startup or by a menu changed message from
|
||||
// one of the catridge DLL's.
|
||||
//
|
||||
// PakInterface builds the master cartridge_menu starting with it's
|
||||
// own items. It then calls PakGetMenuItems to get and append items
|
||||
// from the DLL in slot 0 (AKA the boot or side slot).
|
||||
//
|
||||
// If the MPI is in slot 0 it responds with it's own list plus the
|
||||
// lists from each cartridge it has loaded, each via PakGetMenuItems
|
||||
// calls to them.
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
namespace VCC::Bus {
|
||||
|
||||
// A single menu entry
|
||||
struct CartMenuItem {
|
||||
std::string name;
|
||||
size_t menu_id;
|
||||
MenuItemType type;
|
||||
};
|
||||
|
||||
class cartridge_menu {
|
||||
|
||||
private:
|
||||
std::vector<CartMenuItem> menu_;
|
||||
|
||||
public:
|
||||
|
||||
// Constructor
|
||||
cartridge_menu() {}
|
||||
|
||||
// Clear all items
|
||||
void clear() { menu_.clear(); }
|
||||
|
||||
// Add a single item
|
||||
void add(const std::string& name, unsigned int menu_id, MenuItemType type)
|
||||
{
|
||||
menu_.push_back({ name, menu_id, type });
|
||||
}
|
||||
|
||||
// fetch an item
|
||||
CartMenuItem& operator[](size_t i)
|
||||
{
|
||||
return menu_[i];
|
||||
}
|
||||
|
||||
// Number of items in list
|
||||
size_t size() const { return menu_.size(); }
|
||||
|
||||
// copy an item to API structure
|
||||
bool copy_item(menu_item_entry& out, size_t index) const;
|
||||
|
||||
// debug logging
|
||||
void log()
|
||||
{
|
||||
for (size_t i = 0; i < menu_.size(); ++i) {
|
||||
DLOG_C("%s %d %d\n", menu_[i].name.c_str(),menu_[i].menu_id,menu_[i].type);
|
||||
}
|
||||
}
|
||||
|
||||
// Draw the menu (implemented in catridge_menu.cpp)
|
||||
HMENU draw(HWND hWnd,
|
||||
int position=3,
|
||||
const std::string& title="Cartridge");
|
||||
};
|
||||
|
||||
// instance for Vcc.cpp and pakinterface to use. Host only!
|
||||
extern cartridge_menu gVccCartMenu;
|
||||
|
||||
// instance for dll's to use. DLL's only!
|
||||
extern cartridge_menu gDllCartMenu;
|
||||
|
||||
} // namespace VCC::Bus
|
||||
@@ -0,0 +1,45 @@
|
||||
//======================================================================
|
||||
// This file is part of VCC (Virtual Color Computer).
|
||||
// Vcc is Copyright 2015 by Joseph Forgione
|
||||
//
|
||||
// VCC (Virtual Color Computer) is free software, you can redistribute
|
||||
// and/or modify it under the terms of the GNU General Public License
|
||||
// as published by the Free Software Foundation, either version 3 of
|
||||
// the License, or (at your option) any later version.
|
||||
//
|
||||
// VCC (Virtual Color Computer) 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 VCC (Virtual Color Computer). If not, see
|
||||
// <http://www.gnu.org/licenses/>.
|
||||
//======================================================================
|
||||
|
||||
#pragma once
|
||||
|
||||
enum MenuItemType
|
||||
{
|
||||
MIT_Head, // Menu header, should have slave items
|
||||
MIT_Slave, // Slave items with associated control in header submenu.
|
||||
MIT_StandAlone, // Menu item with an associated control
|
||||
MIT_Seperator, // Draws a horizontal line to seperate groups of menu items
|
||||
};
|
||||
|
||||
// Define a C API safe struct for DLL ItemList export
|
||||
// PakGetMenuItem(menu_item_entry* items, size_t* count)
|
||||
struct menu_item_entry
|
||||
{
|
||||
char name[256];
|
||||
size_t menu_id;
|
||||
MenuItemType type;
|
||||
};
|
||||
|
||||
// Sanity check maximum menu items
|
||||
constexpr auto MAX_MENU_ITEMS = 200u;
|
||||
|
||||
// MenuItem ID <-> Command ID mapping
|
||||
constexpr auto MID_CONTROL = 5000;
|
||||
constexpr int ControlId(int id) { return MID_CONTROL + id; }
|
||||
|
||||
@@ -0,0 +1,129 @@
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
// Copyright 2015 by Joseph Forgione
|
||||
// This file is part of VCC (Virtual Color Computer).
|
||||
//
|
||||
// VCC (Virtual Color Computer) is free software: you can redistribute itand/or
|
||||
// modify it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or (at your
|
||||
// option) any later version.
|
||||
//
|
||||
// VCC (Virtual Color Computer) 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
|
||||
// VCC (Virtual Color Computer). If not, see <http://www.gnu.org/licenses/>.
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
//----------------------------------------------------
|
||||
// Defines messages sent to VCC WndProc from cart DLL's
|
||||
//----------------------------------------------------
|
||||
|
||||
#pragma once
|
||||
#include <windows.h>
|
||||
#include <cstdint>
|
||||
|
||||
//----------------------------------------------------
|
||||
// Structures for moving data across DLL boundaries
|
||||
// These require a fixed size buffer to contain the data
|
||||
// buffer must be an array of atomic C types
|
||||
// size is the size of the data buffer.
|
||||
//----------------------------------------------------
|
||||
|
||||
struct CartLoadRequest {
|
||||
const uint32_t size;
|
||||
char pluginPath[MAX_PATH];
|
||||
CartLoadRequest() noexcept
|
||||
: size(MAX_PATH), pluginPath{} {}
|
||||
};
|
||||
|
||||
struct CartNameReply {
|
||||
static constexpr uint32_t BUFSIZE = 128;
|
||||
const uint32_t size;
|
||||
char name[BUFSIZE];
|
||||
CartNameReply() noexcept
|
||||
: size(BUFSIZE), name{} {}
|
||||
};
|
||||
|
||||
struct CartDescReply {
|
||||
static constexpr uint32_t BUFSIZE = 512;
|
||||
const uint32_t size;
|
||||
char description[BUFSIZE];
|
||||
CartDescReply() noexcept
|
||||
: size(BUFSIZE), description{} {}
|
||||
};
|
||||
|
||||
//----------------------------------------------------
|
||||
// DLL <-> VCC Messages and helpers
|
||||
//----------------------------------------------------
|
||||
|
||||
// Fatal (any plugin)
|
||||
inline constexpr uint32_t WM_VCC_FATAL = WM_APP + 100;
|
||||
inline LRESULT SendFatalError(HWND hwnd, uint32_t err) {
|
||||
return SendMessage(hwnd,WM_VCC_FATAL, err, 0);
|
||||
}
|
||||
|
||||
// Hard Reset (any plugin)
|
||||
inline constexpr uint32_t WM_VCC_CPU_RESET = WM_APP + 101;
|
||||
inline LRESULT SendHardReset(HWND hwnd) {
|
||||
return SendMessage(hwnd,WM_VCC_CPU_RESET, 0, 0);
|
||||
}
|
||||
|
||||
// Update menu request (any plugin)
|
||||
inline constexpr uint32_t WM_VCC_UPD_MENU = WM_APP + 102;
|
||||
inline LRESULT SendMenuUpdate(HWND hwnd) {
|
||||
return SendMessage(hwnd,WM_VCC_UPD_MENU, 0, 0);
|
||||
}
|
||||
|
||||
// Soft RESET (any plugin)
|
||||
inline constexpr uint32_t WM_VCC_SOFT_RESET = WM_APP + 103;
|
||||
inline LRESULT SendSoftReset(HWND hwnd) {
|
||||
return SendMessage(hwnd,WM_VCC_SOFT_RESET, 0, 0);
|
||||
}
|
||||
|
||||
// Set active slot (MPI)
|
||||
inline constexpr uint32_t WM_VCC_SET_ACTIVE_SLOT = WM_APP + 104;
|
||||
inline LRESULT SendActiveSlot(HWND hwnd, uint32_t slotnum) {
|
||||
return SendMessage(hwnd,WM_VCC_SET_ACTIVE_SLOT, slotnum, 0);
|
||||
}
|
||||
|
||||
// Unload slot request (MPI)
|
||||
inline constexpr uint32_t WM_VCC_UNLOAD_SLOT = WM_APP + 105;
|
||||
inline LRESULT SendUnloadSlot(HWND hwnd, uint32_t slotnum) {
|
||||
return SendMessage(hwnd,WM_VCC_UNLOAD_SLOT, slotnum, 0);
|
||||
}
|
||||
|
||||
// Load slot request (MPI)
|
||||
inline constexpr uint32_t WM_VCC_LOAD_SLOT = WM_APP + 106;
|
||||
inline LRESULT SendLoadSlot(HWND hwnd, uint32_t slot, CartLoadRequest& req) {
|
||||
return SendMessage(
|
||||
hwnd,
|
||||
WM_VCC_LOAD_SLOT,
|
||||
static_cast<WPARAM>(slot),
|
||||
reinterpret_cast<LPARAM>(&req)
|
||||
);
|
||||
}
|
||||
|
||||
// Request name of cartridge in slot (MPI)
|
||||
inline constexpr uint32_t WM_VCC_GET_CART_NAME = WM_APP + 107;
|
||||
inline LRESULT GetCartName(HWND hwnd, uint32_t slot, CartNameReply& rpy) {
|
||||
return SendMessage(
|
||||
hwnd,
|
||||
WM_VCC_GET_CART_NAME,
|
||||
static_cast<WPARAM>(slot),
|
||||
reinterpret_cast<LPARAM>(&rpy)
|
||||
);
|
||||
}
|
||||
|
||||
// Request desription of cartridge in slot (MPI)
|
||||
inline constexpr uint32_t WM_VCC_GET_CART_DESCRIPT = WM_APP + 108;
|
||||
inline LRESULT GetCartDesc(HWND hwnd, uint32_t slot, CartDescReply& rpy) {
|
||||
return SendMessage(
|
||||
hwnd,
|
||||
WM_VCC_GET_CART_DESCRIPT,
|
||||
static_cast<WPARAM>(slot),
|
||||
reinterpret_cast<LPARAM>(&rpy)
|
||||
);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,203 @@
|
||||
//#define USE_LOGGING
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
// Copyright 2015 by Joseph Forgione
|
||||
// This file is part of VCC (Virtual Color Computer).
|
||||
//
|
||||
// VCC (Virtual Color Computer) is free software: you can redistribute itand/or
|
||||
// modify it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or (at your
|
||||
// option) any later version.
|
||||
//
|
||||
// VCC (Virtual Color Computer) 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
|
||||
// VCC (Virtual Color Computer). If not, see <http://www.gnu.org/licenses/>.
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#include <vcc/bus/cpak_cartridge.h>
|
||||
#include <vcc/bus/cartridge_menuitem.h>
|
||||
#include <stdexcept>
|
||||
#include <vcc/util/logger.h>
|
||||
|
||||
namespace VCC::Core
|
||||
{
|
||||
namespace
|
||||
{
|
||||
template<class Type_>
|
||||
Type_ GetImportedProcAddress(HMODULE module, LPCSTR procName, Type_ defaultFunction)
|
||||
{
|
||||
const auto importedFunction(reinterpret_cast<Type_>(
|
||||
GetProcAddress(module, procName))
|
||||
);
|
||||
return importedFunction ? importedFunction : defaultFunction;
|
||||
}
|
||||
|
||||
void default_stop()
|
||||
{}
|
||||
|
||||
void default_menu_item_clicked(unsigned char)
|
||||
{}
|
||||
|
||||
void default_heartbeat()
|
||||
{}
|
||||
|
||||
void default_write_port(unsigned char, unsigned char)
|
||||
{}
|
||||
|
||||
unsigned char default_read_port(unsigned char)
|
||||
{
|
||||
return {};
|
||||
}
|
||||
|
||||
unsigned char default_read_memory_byte(unsigned short)
|
||||
{
|
||||
return {};
|
||||
}
|
||||
|
||||
void default_status(char* text_buffer, size_t buffer_size)
|
||||
{
|
||||
*text_buffer = 0;
|
||||
}
|
||||
|
||||
unsigned short default_sample_audio()
|
||||
{
|
||||
return {};
|
||||
}
|
||||
|
||||
void default_reset()
|
||||
{}
|
||||
|
||||
const char* default_get_empty_string()
|
||||
{
|
||||
return "";
|
||||
}
|
||||
|
||||
bool default_get_menu_item(menu_item_entry*, size_t)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
cpak_cartridge::cpak_cartridge(
|
||||
HMODULE module_handle,
|
||||
slot_id_type SlotId,
|
||||
path_type configuration_path,
|
||||
const HWND hVccWnd,
|
||||
const cpak_callbacks& cpak_callbacks)
|
||||
:
|
||||
handle_(module_handle),
|
||||
SlotId_(SlotId),
|
||||
configuration_path_(move(configuration_path)),
|
||||
hVccWnd_(hVccWnd),
|
||||
cpak_callbacks_(cpak_callbacks),
|
||||
initialize_(GetImportedProcAddress<PakInitializeModuleFunction>(
|
||||
module_handle, "PakInitialize", nullptr)),
|
||||
terminate_(GetImportedProcAddress(
|
||||
module_handle, "PakTerminate", default_stop)),
|
||||
get_name_(GetImportedProcAddress(
|
||||
module_handle, "PakGetName", default_get_empty_string)),
|
||||
get_catalog_id_(GetImportedProcAddress(
|
||||
module_handle, "PakGetCatalogId", default_get_empty_string)),
|
||||
get_description_(GetImportedProcAddress(
|
||||
module_handle, "PakGetDescription", default_get_empty_string)),
|
||||
reset_(GetImportedProcAddress(
|
||||
module_handle, "PakReset", default_reset)),
|
||||
heartbeat_(GetImportedProcAddress(
|
||||
module_handle, "PakProcessHorizontalSync", default_heartbeat)),
|
||||
status_(GetImportedProcAddress(
|
||||
module_handle, "PakGetStatus", default_status)),
|
||||
write_port_(GetImportedProcAddress(
|
||||
module_handle, "PakWritePort", default_write_port)),
|
||||
read_port_(GetImportedProcAddress(
|
||||
module_handle, "PakReadPort", default_read_port)),
|
||||
read_memory_byte_(GetImportedProcAddress(
|
||||
module_handle, "PakReadMemoryByte", default_read_memory_byte)),
|
||||
sample_audio_(GetImportedProcAddress(
|
||||
module_handle, "PakSampleAudio", default_sample_audio)),
|
||||
menu_item_clicked_(GetImportedProcAddress(
|
||||
module_handle, "PakMenuItemClicked", default_menu_item_clicked)),
|
||||
get_menu_item_(GetImportedProcAddress(
|
||||
module_handle, "PakGetMenuItem", default_get_menu_item))
|
||||
{
|
||||
if (initialize_ == nullptr)
|
||||
{
|
||||
throw std::invalid_argument("Cannot initialize pak interface. Module does not export PakInitialize.");
|
||||
}
|
||||
}
|
||||
|
||||
cpak_cartridge::name_type cpak_cartridge::name() const
|
||||
{
|
||||
return get_name_();
|
||||
}
|
||||
|
||||
cpak_cartridge::catalog_id_type cpak_cartridge::catalog_id() const
|
||||
{
|
||||
return get_catalog_id_();
|
||||
}
|
||||
|
||||
cpak_cartridge::description_type cpak_cartridge:: description() const
|
||||
{
|
||||
return get_description_();
|
||||
}
|
||||
|
||||
void cpak_cartridge::start()
|
||||
{
|
||||
DLOG_C("+++ cpak_cartridge::start %d +++\n",SlotId_);
|
||||
initialize_(SlotId_, configuration_path_.c_str(), hVccWnd_, &cpak_callbacks_);
|
||||
}
|
||||
|
||||
void cpak_cartridge::stop()
|
||||
{
|
||||
terminate_();
|
||||
}
|
||||
|
||||
void cpak_cartridge::reset()
|
||||
{
|
||||
reset_();
|
||||
}
|
||||
|
||||
void cpak_cartridge::process_horizontal_sync()
|
||||
{
|
||||
heartbeat_();
|
||||
}
|
||||
|
||||
void cpak_cartridge::status(char* text_buffer, size_t buffer_size)
|
||||
{
|
||||
status_(text_buffer, buffer_size);
|
||||
}
|
||||
|
||||
void cpak_cartridge::write_port(unsigned char port_id, unsigned char value)
|
||||
{
|
||||
write_port_(port_id, value);
|
||||
}
|
||||
|
||||
unsigned char cpak_cartridge::read_port(unsigned char port_id)
|
||||
{
|
||||
return read_port_(port_id);
|
||||
}
|
||||
|
||||
unsigned char cpak_cartridge::read_memory_byte(unsigned short memory_address)
|
||||
{
|
||||
return read_memory_byte_(memory_address);
|
||||
}
|
||||
|
||||
unsigned short cpak_cartridge::sample_audio()
|
||||
{
|
||||
return sample_audio_();
|
||||
}
|
||||
|
||||
void cpak_cartridge::menu_item_clicked(unsigned char menu_item_id)
|
||||
{
|
||||
menu_item_clicked_(menu_item_id);
|
||||
}
|
||||
|
||||
bool cpak_cartridge::get_menu_item(menu_item_entry* item, size_t index)
|
||||
{
|
||||
return get_menu_item_(item, index);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,82 @@
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
// Copyright 2015 by Joseph Forgione
|
||||
// This file is part of VCC (Virtual Color Computer).
|
||||
//
|
||||
// VCC (Virtual Color Computer) is free software: you can redistribute itand/or
|
||||
// modify it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or (at your
|
||||
// option) any later version.
|
||||
//
|
||||
// VCC (Virtual Color Computer) 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
|
||||
// VCC (Virtual Color Computer). If not, see <http://www.gnu.org/licenses/>.
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
#pragma once
|
||||
#include <vcc/bus/cartridge.h>
|
||||
#include <vcc/bus/cpak_cartridge_definitions.h>
|
||||
#include <vcc/bus/cartridge_menuitem.h>
|
||||
#include <Windows.h>
|
||||
#include <string>
|
||||
|
||||
namespace VCC::Core
|
||||
{
|
||||
|
||||
class cpak_cartridge: public cartridge
|
||||
{
|
||||
public:
|
||||
using path_type = std::string;
|
||||
|
||||
public:
|
||||
cpak_cartridge(
|
||||
HMODULE module_handle, // Cartridge filename
|
||||
slot_id_type const SlotId, // Slot id
|
||||
path_type configuration_path, // Path of ini file
|
||||
HWND hVccWnd, // Handle to main VCC window proc
|
||||
const cpak_callbacks& cpak_callbacks); // Callbacks
|
||||
|
||||
name_type name() const override;
|
||||
catalog_id_type catalog_id() const override;
|
||||
description_type description() const override;
|
||||
|
||||
void start() override;
|
||||
void stop() override;
|
||||
|
||||
void reset() override;
|
||||
void process_horizontal_sync() override;
|
||||
void status(char* text_buffer, size_t buffer_size) override;
|
||||
void write_port(unsigned char port_id, unsigned char value) override;
|
||||
unsigned char read_port(unsigned char port_id) override;
|
||||
unsigned char read_memory_byte(unsigned short memory_address) override;
|
||||
unsigned short sample_audio() override;
|
||||
void menu_item_clicked(unsigned char menu_item_id) override;
|
||||
bool get_menu_item(menu_item_entry* item, size_t index) override;
|
||||
|
||||
private:
|
||||
|
||||
const HMODULE handle_;
|
||||
slot_id_type SlotId_;
|
||||
const HWND hVccWnd_;
|
||||
const path_type configuration_path_;
|
||||
const cpak_callbacks cpak_callbacks_;
|
||||
|
||||
// imported module functions
|
||||
const PakInitializeModuleFunction initialize_;
|
||||
const PakTerminateModuleFunction terminate_;
|
||||
const PakGetNameModuleFunction get_name_;
|
||||
const PakGetCatalogIdModuleFunction get_catalog_id_;
|
||||
const PakGetDescriptionModuleFunction get_description_;
|
||||
const PakResetModuleFunction reset_;
|
||||
const PakHeartBeatModuleFunction heartbeat_;
|
||||
const PakGetStatusModuleFunction status_;
|
||||
const PakWritePortModuleFunction write_port_;
|
||||
const PakReadPortModuleFunction read_port_;
|
||||
const PakReadMemoryByteModuleFunction read_memory_byte_;
|
||||
const PakSampleAudioModuleFunction sample_audio_;
|
||||
const PakMenuItemClickedModuleFunction menu_item_clicked_;
|
||||
const PakGetMenuItemFunction get_menu_item_;
|
||||
};
|
||||
}
|
||||
@@ -0,0 +1,53 @@
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
// Copyright 2015 by Joseph Forgione
|
||||
// This file is part of VCC (Virtual Color Computer).
|
||||
//
|
||||
// VCC (Virtual Color Computer) is free software: you can redistribute itand/or
|
||||
// modify it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or (at your
|
||||
// option) any later version.
|
||||
//
|
||||
// VCC (Virtual Color Computer) 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
|
||||
// VCC (Virtual Color Computer). If not, see <http://www.gnu.org/licenses/>.
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
//===============================================================//
|
||||
// This defines the exports that can be used by plugins //
|
||||
//===============================================================//
|
||||
|
||||
#pragma once
|
||||
#include "../../../../../src/core/Interrupts.h"
|
||||
#include <vcc/bus/plugin_callbacks.h>
|
||||
#include <vcc/bus/cartridge_menuitem.h>
|
||||
#include <windows.h>
|
||||
|
||||
//----------------------------------------------------------------
|
||||
// ABI identity is based on SlotId; 0 = Boot Slot, 1-4 = MPI slots
|
||||
//----------------------------------------------------------------
|
||||
extern "C"
|
||||
{
|
||||
// Cartridge exports. At least PakInitilizeModuleFunction must be implimented
|
||||
using PakInitializeModuleFunction = void (*)(
|
||||
slot_id_type SlotId, // SlotId
|
||||
const char* const configuration_path, // Path of ini file
|
||||
HWND hVccWnd, // VCC proxy handle
|
||||
const cpak_callbacks* const context); // Callbacks
|
||||
using PakTerminateModuleFunction = void (*)();
|
||||
using PakGetNameModuleFunction = const char* (*)();
|
||||
using PakGetCatalogIdModuleFunction = const char* (*)();
|
||||
using PakGetDescriptionModuleFunction = const char* (*)();
|
||||
using PakResetModuleFunction = void (*)();
|
||||
using PakHeartBeatModuleFunction = void (*)();
|
||||
using PakGetStatusModuleFunction = void (*)(char* text_buffer, size_t buffer_size);
|
||||
using PakWritePortModuleFunction = void (*)(unsigned char port, unsigned char value);
|
||||
using PakReadMemoryByteModuleFunction = unsigned char (*)(unsigned short address);
|
||||
using PakReadPortModuleFunction = unsigned char (*)(unsigned char port);
|
||||
using PakSampleAudioModuleFunction = unsigned short (*)();
|
||||
using PakMenuItemClickedModuleFunction = void (*)(unsigned char itemId);
|
||||
using PakGetMenuItemFunction = bool (*)(menu_item_entry* item, size_t index);
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
// Copyright 2015 by Joseph Forgione
|
||||
// This file is part of VCC (Virtual Color Computer).
|
||||
//
|
||||
// VCC (Virtual Color Computer) is free software: you can redistribute itand/or
|
||||
// modify it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or (at your
|
||||
// option) any later version.
|
||||
//
|
||||
// VCC (Virtual Color Computer) 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
|
||||
// VCC (Virtual Color Computer). If not, see <http://www.gnu.org/licenses/>.
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
#pragma once
|
||||
#include <vcc/bus/basic_cartridge.h>
|
||||
|
||||
// Basically not a cartridge but by another name
|
||||
namespace VCC::Core
|
||||
{
|
||||
class null_cartridge : public basic_cartridge
|
||||
{};
|
||||
}
|
||||
@@ -0,0 +1,52 @@
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
// Copyright 2015 by Joseph Forgione
|
||||
// This file is part of VCC (Virtual Color Computer).
|
||||
//
|
||||
// VCC (Virtual Color Computer) is free software: you can redistribute itand/or
|
||||
// modify it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or (at your
|
||||
// option) any later version.
|
||||
//
|
||||
// VCC (Virtual Color Computer) 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
|
||||
// VCC (Virtual Color Computer). If not, see <http://www.gnu.org/licenses/>.
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
//=============================================================//
|
||||
// This defines the callbacks used by all cartridges (plugins) //
|
||||
//=============================================================//
|
||||
|
||||
#pragma once
|
||||
#include "../../../../../src/core/Interrupts.h"
|
||||
#include <cstddef> // for std::size_t
|
||||
|
||||
//----------------------------------------------------------------
|
||||
// ABI identity is based on SlotId; 0 = Boot Slot, 1-4 = MPI slots
|
||||
//----------------------------------------------------------------
|
||||
using slot_id_type = std::size_t;
|
||||
|
||||
extern "C"
|
||||
{
|
||||
using PakWriteMemoryByteHostCallback = void (*)
|
||||
(slot_id_type SlotId, unsigned char value, unsigned short address);
|
||||
using PakReadMemoryByteHostCallback = unsigned char (*)
|
||||
(slot_id_type SlotId, unsigned short address);
|
||||
using PakAssertCartridgeLineHostCallback = void (*)
|
||||
(slot_id_type SlotId, bool lineState);
|
||||
using PakAssertInteruptHostCallback = void (*)
|
||||
(slot_id_type SlotId, Interrupt interrupt, InterruptSource interrupt_source);
|
||||
|
||||
// Plugin (cartridge) callbacks
|
||||
struct cpak_callbacks
|
||||
{
|
||||
const PakAssertInteruptHostCallback assert_interrupt;
|
||||
const PakAssertCartridgeLineHostCallback assert_cartridge_line;
|
||||
const PakWriteMemoryByteHostCallback write_memory_byte;
|
||||
const PakReadMemoryByteHostCallback read_memory_byte;
|
||||
};
|
||||
}
|
||||
|
||||
@@ -0,0 +1,92 @@
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
// Copyright 2015 by Joseph Forgione
|
||||
// This file is part of VCC (Virtual Color Computer).
|
||||
//
|
||||
// VCC (Virtual Color Computer) is free software: you can redistribute itand/or
|
||||
// modify it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or (at your
|
||||
// option) any later version.
|
||||
//
|
||||
// VCC (Virtual Color Computer) 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
|
||||
// VCC (Virtual Color Computer). If not, see <http://www.gnu.org/licenses/>.
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#include <vcc/bus/proxy_msgwin.h>
|
||||
#include <vcc/bus/cartridge_messages.h>
|
||||
#include <vcc/util/logger.h>
|
||||
|
||||
namespace VCC::Core
|
||||
{
|
||||
HWND ProxyMsgWin::h_proxy_ = nullptr;
|
||||
HWND ProxyMsgWin::h_target_ = nullptr;
|
||||
const char PROXY_CLASS[] = "ProxyMessageWindow";
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// Private message handler forwards messages defined in cartridge_messages.h
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
LRESULT CALLBACK ProxyMsgWin::ProxyProc(
|
||||
HWND hwnd,
|
||||
UINT uMsg,
|
||||
WPARAM wParam,
|
||||
LPARAM lParam)
|
||||
{
|
||||
if (uMsg >= WM_APP + 100 && uMsg <= WM_APP + 200) {
|
||||
DLOG_C("DLL msg %d\n", uMsg);
|
||||
return SendMessageA(h_target_, uMsg, wParam, lParam);
|
||||
}
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// Set up message only proxy for DLL messages. This gets called each time
|
||||
// DirectDrawInterface creates or recreates the VCC WndProc. This happens
|
||||
// at VCC startup and when full screen mode is toggled.
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
HWND ProxyMsgWin::SetProxy(HWND h_VccWndProc)
|
||||
{
|
||||
// Save target handle (VCC WndProc)
|
||||
h_target_ = h_VccWndProc;
|
||||
|
||||
// One time create proxy msg window
|
||||
if (h_proxy_ == nullptr) {
|
||||
|
||||
HINSTANCE h_inst = GetModuleHandle(nullptr);
|
||||
|
||||
WNDCLASSA wc = { };
|
||||
wc.lpfnWndProc = ProxyProc;
|
||||
wc.hInstance = h_inst;
|
||||
wc.lpszClassName = PROXY_CLASS;
|
||||
|
||||
if (!RegisterClassA(&wc)) {
|
||||
const DWORD err = GetLastError();
|
||||
if (err != ERROR_CLASS_ALREADY_EXISTS) {
|
||||
DLOG_C("RegisterClass failed, error = %lu\n", err);
|
||||
return h_VccWndProc; // fallback
|
||||
}
|
||||
}
|
||||
|
||||
h_proxy_ = CreateWindowExA(
|
||||
0, PROXY_CLASS, "ProxyWindow",
|
||||
0, 0, 0, 0, 0, HWND_MESSAGE,
|
||||
nullptr, h_inst, nullptr
|
||||
);
|
||||
|
||||
if (h_proxy_ == nullptr) {
|
||||
const DWORD err = GetLastError();
|
||||
DLOG_C("CreateWindowExA failed, error = %lu\n", err);
|
||||
return h_VccWndProc;
|
||||
}
|
||||
}
|
||||
|
||||
// Return proxy handle
|
||||
return h_proxy_;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,52 @@
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
// Copyright 2015 by Joseph Forgione
|
||||
// This file is part of VCC (Virtual Color Computer).
|
||||
//
|
||||
// VCC (Virtual Color Computer) is free software: you can redistribute itand/or
|
||||
// modify it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or (at your
|
||||
// option) any later version.
|
||||
//
|
||||
// VCC (Virtual Color Computer) 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
|
||||
// VCC (Virtual Color Computer). If not, see <http://www.gnu.org/licenses/>.
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// VCC’s main window handle is not stable. When entering or leaving fullscreen
|
||||
// mode, the system may destroy and recreate the main window, causing its HWND
|
||||
// to change. This breaks messaging from other program units or dynamically
|
||||
// loaded DLLs that rely on a fixed window handle.
|
||||
//
|
||||
// To provide a stable messaging endpoint, VCC creates an invisible proxy
|
||||
// message window. This proxy window has a permanent HWND and receives
|
||||
// DLL messages. It forwards these messages to VCC’s main WndProc.
|
||||
//
|
||||
// Whenever the main window is recreated, the proxy updates its forwarding
|
||||
// target to the new HWND.
|
||||
//
|
||||
// The proxy window ensures reliable message delivery to VCC’s WndProc even
|
||||
// when the main window handle changes.
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
#pragma once
|
||||
#include <windows.h>
|
||||
|
||||
namespace VCC::Core
|
||||
{
|
||||
class ProxyMsgWin
|
||||
{
|
||||
public:
|
||||
static HWND SetProxy(HWND hwnd);
|
||||
private:
|
||||
static LRESULT CALLBACK ProxyProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam);
|
||||
static HWND h_proxy_;
|
||||
static HWND h_target_;
|
||||
};
|
||||
}
|
||||
|
||||
@@ -0,0 +1,83 @@
|
||||
//#define USE_LOGGING
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
// Copyright 2015 by Joseph Forgione
|
||||
// This file is part of VCC (Virtual Color Computer).
|
||||
//
|
||||
// VCC (Virtual Color Computer) is free software: you can redistribute itand/or
|
||||
// modify it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or (at your
|
||||
// option) any later version.
|
||||
//
|
||||
// VCC (Virtual Color Computer) 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
|
||||
// VCC (Virtual Color Computer). If not, see <http://www.gnu.org/licenses/>.
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
#include <vcc/bus/rom_cartridge.h>
|
||||
#include <vcc/util/logger.h>
|
||||
|
||||
namespace VCC::Core
|
||||
{
|
||||
rom_cartridge::rom_cartridge(
|
||||
const cpak_callbacks& callbacks,
|
||||
name_type name,
|
||||
catalog_id_type catalog_id,
|
||||
buffer_type buffer,
|
||||
bool enable_bank_switching,
|
||||
slot_id_type slotId
|
||||
)
|
||||
: callbacks_(callbacks),
|
||||
name_(move(name)),
|
||||
catalog_id_(move(catalog_id)),
|
||||
buffer_(move(buffer)),
|
||||
enable_bank_switching_(enable_bank_switching),
|
||||
bank_offset_(0),
|
||||
slotId_(slotId)
|
||||
{
|
||||
DLOG_C("rom_cartridge ctor slot %d %s\n",slotId_, name_.c_str());
|
||||
}
|
||||
|
||||
rom_cartridge::name_type rom_cartridge::name() const
|
||||
{
|
||||
return name_;
|
||||
}
|
||||
|
||||
rom_cartridge::catalog_id_type rom_cartridge::catalog_id() const
|
||||
{
|
||||
return catalog_id_;
|
||||
}
|
||||
|
||||
rom_cartridge::description_type rom_cartridge::description() const
|
||||
{
|
||||
return {};
|
||||
}
|
||||
|
||||
void rom_cartridge::reset()
|
||||
{
|
||||
DLOG_C("rom_cartridge reset\n");
|
||||
bank_offset_ = 0;
|
||||
}
|
||||
|
||||
void rom_cartridge::write_port(unsigned char port_id, unsigned char value)
|
||||
{
|
||||
if (enable_bank_switching_ && port_id == 0x40)
|
||||
{
|
||||
bank_offset_ = (value & 0x0f) << 14;
|
||||
}
|
||||
}
|
||||
|
||||
unsigned char rom_cartridge::read_memory_byte(unsigned short memory_address)
|
||||
{
|
||||
return buffer_[((memory_address & 32767) + bank_offset_) % buffer_.size()];
|
||||
}
|
||||
|
||||
void rom_cartridge::initialize_bus()
|
||||
{
|
||||
DLOG_C("rom_cartridge.initialize_bus assert line slot %d\n",slotId_);
|
||||
callbacks_.assert_cartridge_line(slotId_,true);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,67 @@
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
// Copyright 2015 by Joseph Forgione
|
||||
// This file is part of VCC (Virtual Color Computer).
|
||||
//
|
||||
// VCC (Virtual Color Computer) is free software: you can redistribute itand/or
|
||||
// modify it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or (at your
|
||||
// option) any later version.
|
||||
//
|
||||
// VCC (Virtual Color Computer) 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
|
||||
// VCC (Virtual Color Computer). If not, see <http://www.gnu.org/licenses/>.
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
#pragma once
|
||||
#include <vcc/bus/basic_cartridge.h>
|
||||
#include <vcc/bus/cartridge_callbacks.h> //depreciated
|
||||
#include <vcc/bus/plugin_callbacks.h>
|
||||
#include <vector>
|
||||
#include <memory>
|
||||
|
||||
namespace VCC::Core
|
||||
{
|
||||
class rom_cartridge : public basic_cartridge
|
||||
{
|
||||
public:
|
||||
using callbacks_type = ::VCC::Core::cartridge_callbacks;
|
||||
using buffer_type = std::vector<uint8_t>;
|
||||
using size_type = std::size_t;
|
||||
|
||||
public:
|
||||
using basic_cartridge::basic_cartridge;
|
||||
|
||||
rom_cartridge(
|
||||
const cpak_callbacks& callbacks,
|
||||
name_type name,
|
||||
catalog_id_type catalog_id,
|
||||
buffer_type buffer,
|
||||
bool enable_bank_switching,
|
||||
slot_id_type slotId
|
||||
);
|
||||
|
||||
name_type name() const override;
|
||||
catalog_id_type catalog_id() const override;
|
||||
description_type description() const override;
|
||||
|
||||
void reset() override;
|
||||
void write_port(unsigned char port_id, unsigned char value) override;
|
||||
unsigned char read_memory_byte(unsigned short memory_address) override;
|
||||
|
||||
protected:
|
||||
void initialize_bus() override;
|
||||
|
||||
private:
|
||||
const cpak_callbacks& callbacks_;
|
||||
const name_type name_;
|
||||
const catalog_id_type catalog_id_;
|
||||
const buffer_type buffer_;
|
||||
const bool enable_bank_switching_;
|
||||
size_type bank_offset_;
|
||||
const std::string filename_;
|
||||
slot_id_type slotId_;
|
||||
};
|
||||
}
|
||||
Reference in new issue
Block a user