diff --git a/.gitignore b/.gitignore index 38f7eda..7e6bad7 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ build/ Testing/ -.cache/ \ No newline at end of file +.cache/ +doc/doxygen/ diff --git a/EMUAPI b/EMUAPI new file mode 100644 index 0000000..abd8e32 --- /dev/null +++ b/EMUAPI @@ -0,0 +1,39 @@ +mfdemu/plugin/api.{hpp,cpp} + -> General API implementation + - Accessors to System, CPU, Config, etc. + - Plugin load method, returns devices +mfdemu/plugin/config.{hpp,cpp} + -> Config +mfdemu/plugin/device.{hpp,cpp} + -> PluginDevice + public: + ::LoadDevice(API &api) virtual + -> PluginAioDevice : AioDevice, PluginDevice + protected: + ::read(u16 addr) -> u16 + ::write(u16 addr, u16 val) + -> PluginGioDevice : GioDevice + protected: + ::read(u16 addr) -> u16 + ::write(u16 addr, u8 val, bool low) +mfdemu/plugin/internal/ + loaded_mri + -> Contains the MRI given to the emulator, AIO Device + zero_AIO + zero_GIO + -> Initialised with 0, ignores writes if configured appropriately + +/* overriden from mfdemu::plugin::PluginAioDevice */ +ABC16::LoadDevice(API &api) { + ABC16Cfg cfg; + cfg.load(api.getConfig().getDevice("mfd_abc16")); +} + + EMU + | + ABC16 + | + +--------------+------------+ + | | | +internal:zero internal:loaded_mri bmg + diff --git a/asm/doxyfile b/doxyfile similarity index 99% rename from asm/doxyfile rename to doxyfile index 33f15af..4c56b78 100644 --- a/asm/doxyfile +++ b/doxyfile @@ -32,7 +32,7 @@ DOXYFILE_ENCODING = UTF-8 # title of most generated pages and in a few other places. # The default value is: My Project. -PROJECT_NAME = "MCFG/2" +PROJECT_NAME = "MFD0816" # The PROJECT_NUMBER tag can be used to enter a project or revision number. This # could be handy for archiving the generated documentation or if some version @@ -864,7 +864,7 @@ WARN_LOGFILE = # spaces. See also FILE_PATTERNS and EXTENSION_MAPPING # Note: If this tag is empty the current directory is searched. -INPUT = mfdasm +INPUT = asm/ emu/ shared/ # This tag can be used to specify the character encoding of the source files # that doxygen parses. Internally doxygen uses the UTF-8 encoding. Doxygen uses @@ -1061,7 +1061,7 @@ FILTER_SOURCE_PATTERNS = # (index.html). This can be useful if you have a project on for instance GitHub # and want to reuse the introduction page also for the doxygen output. -USE_MDFILE_AS_MAINPAGE = ./README.md +USE_MDFILE_AS_MAINPAGE = #--------------------------------------------------------------------------- # Configuration options related to source browsing diff --git a/emu/api_include/mfdemu_api.h b/emu/api_include/mfdemu_api.h new file mode 100644 index 0000000..c745e68 --- /dev/null +++ b/emu/api_include/mfdemu_api.h @@ -0,0 +1,172 @@ +/* + * Copyright (C) 2024 Marie Eckert + * + * This program is free software: you can redistribute it 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. + * + * This program 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 this program. If not, see . + */ + +/** + * @file mfdemu_api.h + * @brief Type and Function-Prototype definitions for the MFDEMU device plugin + * API. + */ + +#ifndef __MFDEMU_API_H +#define __MFDEMU_API_H + +#ifdef __cplusplus +namespace mfdemu::api { +#endif + +#include + +#define MFDEMU_DEVICE_API_H_VERSION 0 + +extern uint32_t mfdemuApiVersion; + +/** + * @brief Used to represent the current state of CPU pins relevant for Address + * Bus devices. + */ +typedef struct { + /** + * @brief The current state of the AIO pins. This value may be modified, but + * modifications are ignored unless the CPU is currently at the T3 stage of + * an Address Bus read. + */ + u16 busPins; + + /** + * @brief The current value of the AMS pin. + */ + u8 mode; + u8 pad; +} AioState; + +/** + * @brief Used to represent the current state of CPU pins relevant for I/O Bus + * devices. + */ +typedef struct { + /** + * @brief The current state of the GIO pins. This value may be modified, but + * modifications are ignored unless the CPU is currently at the T3 or T4 + * stage of an I/O Bus read. + */ + u8 busPins; + + /** + * @brief The current value of the GMS pin. + */ + u8 mode; + u16 pad; +} GioState; + +/** + * @brief The possible datatypes contained within a MFDEMU configuration. + */ +typedef enum { + String, + + /** + * @brief Corresponds to the C++ default bool type. + */ + Boolean, + + /** + * @brief Corresponds to the systems default character type. + */ + Character, + + /** + * @brief Corresponds to ínt64_t. + */ + Integer, + + /** + * @brief Corresponds to uint64_t. + */ + Unsigned, + + /** + * @brief Corresponds to 32-bit floats. + */ + Float, + + /** + * @brief Corresponds to the native pointer type. If the pointer is valid, + * the underlying value's type corresponds to the type used for JSON objects + * by the used JSON implementation. + */ + Object, +} ConfigDataType; + +/** + * @brief A result from a config inquiry. + */ +typedef struct { + ConfigDataType type; + + /** + * @brief If value is nullptr, the result is invalid. + */ + void *value; +} ConfigValueResult; + +/** + * @defgroup EmuApi-EmuCalls Functions called by the Emulator. + * @{ + */ + +/** + * @brief Used to signal that the CLK pin connected to the address bus device has been + * pulled high. + */ +void AioClk(AioState *state); + +/** + * @brief Used to signal that the CLK pin connected to the i/o bus device has been + * pulled high. + */ +void GioClk(GioState *state); + +/** + * @brief Used to initialise a device plugin. + * @param handle The handle to the API. + */ +void DeviceInit(APIHandle handle); + +/** @} */ +/** + * @defgroup EmuApi-DevCalls Functions called by Devices. + * @{ + */ + +/** + * @brief Used to get a value from the emulators configuration. + * @param handle The API Handle. + * @param nameLength The name of the proceeding name string. + * @param name The name of the value to get. + * @param baseObject Optionally set the object from which the value should be + * acquired. Only pointers returned from this function with the associated + * `ConfigDataType` of `Object` can possibly be valid. + */ +ConfigValueResult +GetConfigValue(APIHandle handle, size_t nameLength, const char *name, void *baseObject = nullptr); + +/** @} */ + +#ifdef __cplusplus +} +#endif +#endif diff --git a/emu/mfdemu/plugin/api.hpp b/emu/mfdemu/plugin/api.hpp new file mode 100644 index 0000000..09de0de --- /dev/null +++ b/emu/mfdemu/plugin/api.hpp @@ -0,0 +1,48 @@ +/* + * Copyright (C) 2025 Marie Eckert + * + * This program is free software: you can redistribute it 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. + * + * This program 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 this program. If not, see . + */ + +#ifndef MFDEMU_PLUGIN_API_HPP +#define MFDEMU_PLUGIN_API_HPP + +#include + +#include +#include + +namespace mfdemu::plugin { + +/* Dummy declarations because the config class doesn't exist yet */ +class Config {}; +class PluginDevice {}; +class PluginAioDevice : public PluginDevice, public impl::AioDevice {}; +class PluginGioDevice : public PluginDevice, public impl::GioDevice {}; + +class PluginAPI { + public: + const Config &getConfig() const; + + std::optional> loadPluginDevice(const std::string &path); + + private: + Config m_cfg; + std::shared_ptr m_attachedAddressDevice; + std::shared_ptr m_attachedGioDevice; +}; + +} // namespace mfdemu::plugin + +#endif \ No newline at end of file diff --git a/mfd-c16..json b/mfd-c16..json new file mode 100644 index 0000000..7016574 --- /dev/null +++ b/mfd-c16..json @@ -0,0 +1,61 @@ +{ + "devices": { + "mfd0816": { + "address_device": "mfd_abc16.so", + "gio_device": "internal:zero" + }, + "internal:loaded_mri": { + "available_sections": [ + { + "start": "0x0000", + "end": "0x4fff" + }, + { + "start": "0xfffd", + "end": "0xffff" + } + ] + }, + "mfd_abc16": { + "devices": [ + { + "name": "program", + "access": "r", + "device": "internal:loaded_mri", + "start": "0x0000", + "end": "0x4fff", + "normalize": false + }, + { + "name": "ram0", + "access": "rw", + "device": "internal:zero", + "start": "0x5000", + "end": "0x7fff" + }, + { + "name": "mfd_bmg", + "access": "rw", + "device": "mfd_bmg.so", + "start": "0x8000", + "end": "0x8fff" + }, + { + "name": "ram1", + "access": "rw", + "device": "internal:zero", + "start": "0x9000", + "end": "0xfffc" + }, + { + "name": "vectors", + "access": "r", + "device": "internal:zero", + "start": "0xfffd", + "end": "0xffff", + "normalize": false + } + ] + } + } +} \ No newline at end of file