libElysianVMU 1.6.0
Full-featured, accurate, cross-platform library emulating the Dreamcast's Visual Memory Unit
Loading...
Searching...
No Matches
evmu_rom.h
Go to the documentation of this file.
1/*! \file
2 * \brief EvmuRom: External ROM chip, BIOS, Firmware routines
3 * \ingroup peripherals
4 *
5 * \todo
6 * - CLEAN UP IMPLEMENTATION IN GENERAL
7 * - EvmuRom_setBiosMode() (set mode button then jump to Colton's address?)
8 * - EvmuRom["biosMode"]: R/W
9 * - EvmuRom["dateTime"]: R/W (pending on ISO8601 in Gimbal)
10 * - Maybe signal when entering/exiting BIOS
11 * - overridable virtuals for whole custom BIOS
12 * - return elapsed ticks/cycles for subroutine call
13 * - return BIOS version information and shit
14 * - EvmuRom_biosMode()
15 *
16 * \author 2023 Falco Girgis
17 * \author 2023 Colton Pawielski
18 * \copyright MIT License
19 */
20#ifndef EVMU_ROM_H
21#define EVMU_ROM_H
22
23#include "../types/evmu_peripheral.h"
24#include "../types/evmu_imemory.h"
25#include <gimbal/utils/gimbal_date_time.h>
26
27/*! \name Type System
28 * \brief Type UUID and cast operators
29 * @{
30 */
31#define EVMU_ROM_TYPE (GBL_TYPEID(EvmuRom)) //!< Type UUID for EvmuRom
32#define EVMU_ROM(self) (GBL_CAST(EvmuRom, self)) //!< Cast GblInstance to EvmuRom
33#define EVMU_ROM_CLASS(klass) (GBL_CLASS_CAST(EvmuRom, klass)) //!< Cast GblClass to EvmuRomClass
34#define EVMU_ROM_GET_CLASS(self) (GBL_CLASSOF(EvmuRom, self)) //!< Get EvmuRomClass from GblInstance
35//! @}
36
37#define EVMU_ROM_NAME "rom" //!< GblObject name of EvmuRom peripoheral
38
39/*! \name Address Space
40 * \brief Definitions for region locations and sizes
41 * @{
42 */
43#define EVMU_ROM_SIZE 65536 //!< Total size of external ROM chip
44#define EVMU_BIOS_SYS_PROG_ADDRESS_BASE 0x0000 //!< Start of Firmware/Subroutines in bytes
45#define EVMU_BIOS_SYS_PROG_SIZE 16384 //!< Size of Firmware/Subroutines in bytes
46#define EVMU_BIOS_OS_PROG_ADDRESS_BASE 0xed00 //!< Start address of OS/BIOS program
47#define EVMU_BIOS_OS_PROG_SIZE 4096 //!< Size of OS/BIOS program in bytes
48//! @}
49
50#define EVMU_BIOS_SKIP_DATE_TIME_PC 0x2e1 //!< BIOS PC address just after setting date/time
51
52#define GBL_SELF_TYPE EvmuRom
53
54GBL_DECLS_BEGIN
55
56GBL_FORWARD_DECLARE_STRUCT(EvmuRom);
57
58GBL_DECLARE_ENUM(EVMU_BIOS_SUBROUTINE) {
59 EVMU_BIOS_SUBROUTINE_RESET = 0x000, //!< Regular starting point
60 // Firmware calls: utility functions that return execution back to app
61 EVMU_BIOS_SUBROUTINE_FM_WRT_EX = 0x100, //!< Flash memory write, return address variant 1
62 EVMU_BIOS_SUBROUTINE_FM_WRTA_EX = 0x108, //!< Flash memory write, return address variant 2
63 EVMU_BIOS_SUBROUTINE_FM_VRF_EX = 0x110, //!< Flash memory page data verify
64 EVMU_BIOS_SUBROUTINE_FM_PRD_EX = 0x120, //!< Flash memory paged read data
65 // BIOS routines: control yields to BIOS?
66 EVMU_BIOS_SUBROUTINE_TIMER_EX = 0x130, //!< System time update, used as Base Timer ISR
67 EVMU_BIOS_SUBROUTINE_SLEEP_EX = 0x140, //!< Enable sleep mode
68 EVMU_BIOS_SUBROUTINE_EXIT_EX = 0x1f0 //!< MODE button logic
69};
70
71GBL_DECLARE_ENUM(EVMU_BIOS_TYPE) {
72 EVMU_BIOS_TYPE_EMULATED, //!< Default, no BIOS, software emulation
73 EVMU_BIOS_TYPE_AMERICAN_IMAGE_V1_05 = 0xC825003A, //!< CRC for American BIOS
74 EVMU_BIOS_TYPE_JAPANESE_IMAGE_V1_04 = 0x8E0F867A, //!< CRC for Japanese BIOS
75 EVMU_BIOS_TYPE_UNKNOWN_IMAGE //!< Any other unknown image
76};
77
78GBL_DECLARE_ENUM(EVMU_BIOS_MODE) {
79 EVMU_BIOS_MODE_FILE, //!< File Manager mode
80 EVMU_BIOS_MODE_GAME, //!< Game/Application mode
81 EVMU_BIOS_MODE_TIME, //!< Clock/time mode
82 EVMU_BIOS_MODE_MAPLE, //!< Connected to DC, Maple slave mode
83 EVMU_BIOS_MODE_UNKNOWN, //!< Unknown mode (unknown BIOS)
84 EVMU_BIOS_MODE_COUNT //!< Number of BIOS modes
85};
86
87/*! \struct EvmuRomClass
88 * \extends EvmuPeripheralClass
89 * \implements EvmuIMemoryClass
90 * \brief GblClass for EvmuRom
91 *
92 * EvmuRomClass provides a vtable implementing a BIOS within the VMU's ROM.
93 * The default implementation either emulates firmware calls in software or
94 * defers them to a loaded BIOS image. You may override this to implement
95 * a custom BIOS or firmware.
96 *
97 * \sa EvmuRom
98 */
99GBL_CLASS_DERIVE(EvmuRom, EvmuPeripheral, EvmuIMemory)
100 //! Virtual function for loading a BIOS image into ROM
101 EVMU_RESULT (*pFnLoadBios)(GBL_SELF, const char* pPath);
102 //! Virtual function for invoking a firmware call at a given entry-point
103 EVMU_RESULT (*pFnCallBios)(GBL_SELF, EvmuAddress entryPc, EvmuAddress* pRetPc);
104GBL_CLASS_END
105
106/*! \struct EvmuRom
107 * \extends EvmuPeripheral
108 * \implements EvmuIMemory
109 * \ingroup peripherals
110 * \brief Peripheral managing ROM, firmware calls, and BIOS images
111 *
112 * There are no public members.
113 *
114 * \sa EvmuRomClass
115 */
116GBL_INSTANCE_DERIVE_EMPTY(EvmuRom, EvmuPeripheral)
117
118//! \cond
119GBL_PROPERTIES(EvmuRom,
120 (dataChanged, GBL_GENERIC, (READ, WRITE, OVERRIDE), GBL_BOOL_TYPE),
121 (biosActive, GBL_GENERIC, (READ ), GBL_BOOL_TYPE),
122 (biosType, GBL_GENERIC, (READ ), GBL_ENUM_TYPE),
123 (biosMode, GBL_GENERIC, (READ ), GBL_ENUM_TYPE),
124 (dateTime, GBL_GENERIC, (READ ), GBL_STRING_TYPE)
125)
126//! \endcond
127
128//! Returns the GblType UUID associated with EvmuRom.
129EVMU_EXPORT GblType EvmuRom_type (void) GBL_NOEXCEPT;
130
131/*! \name BIOS State
132 * \relatesalso EvmuRom
133 * \brief Methods for querying BIOS configuration and state
134 * @{
135 */
136//! Returns GBL_TRUE if the CPU is currently executing code from the BIOS
137EVMU_EXPORT GblBool EvmuRom_biosActive (GBL_CSELF) GBL_NOEXCEPT;
138//! Returns the type of BIOS currently loaded into ROM
140//! Returns the mode the BIOS is in (file manager, game, clock, etc)
142//! @}
143
144/*! \name BIOS Management
145 * \relatesalso EvmuRom
146 * \brief Methods for loading, unloading, and calling BIOS routines
147 * @{
148 */
149//! Loads a BIOS image from the path given by \p pPath
150EVMU_EXPORT EVMU_RESULT EvmuRom_loadBios (GBL_SELF, const char* pPath) GBL_NOEXCEPT;
151//! Unloads any currently-loaded BIOS image, returning to software emulation
152EVMU_EXPORT EVMU_RESULT EvmuRom_unloadBios (GBL_SELF) GBL_NOEXCEPT;
153//! Makes a firmware or BIOS subroutine call at the entry point given by \p entry
155//! Enables or disables skipping the BIOS date/time setup based on the value of \p enableSkip
156EVMU_EXPORT EVMU_RESULT EvmuRom_skipBiosSetup (GBL_SELF, GblBool enableSkip) GBL_NOEXCEPT;
157//! @}
158
159/*! \name Date/Time Management
160 * \relatesalso EvmuRom
161 * \brief Methods for querying and setting date/time
162 * @{
163 */
164//! Returns the current date and time as seen by the BIOS
165EVMU_EXPORT GblDateTime* EvmuRom_dateTime (GBL_CSELF,
166 GblDateTime* pDateTime) GBL_NOEXCEPT;
167//! Sets the current date and time as seen by the BIOS to the value given by \p pDateTime
168EVMU_EXPORT EVMU_RESULT EvmuRom_setDateTime (GBL_SELF,
169 const GblDateTime* pDateTime) GBL_NOEXCEPT;
170//! @}
171
172/*! \name Read/Write Accessors
173 * \brief Methods for reading and writing ROM data
174 * \relatesalso EvmuRom
175 * @{
176 */
177//! Returns the byte value located at the given ROM \p address
179 EvmuAddress address) GBL_NOEXCEPT;
180//! Reads \p pSize bytes from ROM into \p pData, starting at \p address, writing back the number of bytes read
181EVMU_EXPORT EVMU_RESULT EvmuRom_readBytes (GBL_CSELF,
182 EvmuAddress address,
183 void* pData,
184 size_t* pSize) GBL_NOEXCEPT;
185//! Writes the \p byte value to the ROM \p address
186EVMU_EXPORT EVMU_RESULT EvmuRom_writeByte (GBL_SELF,
187 EvmuAddress address,
188 EvmuWord byte) GBL_NOEXCEPT;
189//! Writes \p pSize bytes to ROM from \p pData, starting at \p address, writing back the number of bytes written
190EVMU_EXPORT EVMU_RESULT EvmuRom_writeBytes (GBL_SELF,
191 EvmuAddress address,
192 const void* pData,
193 size_t* pSize) GBL_NOEXCEPT;
194//! @}
195
196
197GBL_DECLS_END
198
199#undef GBL_SELF_TYPE
200
201#endif // EVMU_ROM_H
#define EVMU_EXPORT
Define used for adding attributes to export public symbols.
Definition evmu_api.h:18
EVMU_BIOS_MODE
Definition evmu_rom.h:78
@ EVMU_BIOS_MODE_FILE
File Manager mode.
Definition evmu_rom.h:79
@ EVMU_BIOS_MODE_MAPLE
Connected to DC, Maple slave mode.
Definition evmu_rom.h:82
@ EVMU_BIOS_MODE_GAME
Game/Application mode.
Definition evmu_rom.h:80
@ EVMU_BIOS_MODE_UNKNOWN
Unknown mode (unknown BIOS)
Definition evmu_rom.h:83
@ EVMU_BIOS_MODE_COUNT
Number of BIOS modes.
Definition evmu_rom.h:84
@ EVMU_BIOS_MODE_TIME
Clock/time mode.
Definition evmu_rom.h:81
EVMU_BIOS_SUBROUTINE
Definition evmu_rom.h:58
@ EVMU_BIOS_SUBROUTINE_FM_PRD_EX
Flash memory paged read data.
Definition evmu_rom.h:64
@ EVMU_BIOS_SUBROUTINE_FM_WRTA_EX
Flash memory write, return address variant 2.
Definition evmu_rom.h:62
@ EVMU_BIOS_SUBROUTINE_FM_VRF_EX
Flash memory page data verify.
Definition evmu_rom.h:63
@ EVMU_BIOS_SUBROUTINE_EXIT_EX
MODE button logic.
Definition evmu_rom.h:68
@ EVMU_BIOS_SUBROUTINE_RESET
Regular starting point.
Definition evmu_rom.h:59
@ EVMU_BIOS_SUBROUTINE_FM_WRT_EX
Flash memory write, return address variant 1.
Definition evmu_rom.h:61
@ EVMU_BIOS_SUBROUTINE_TIMER_EX
System time update, used as Base Timer ISR.
Definition evmu_rom.h:66
@ EVMU_BIOS_SUBROUTINE_SLEEP_EX
Enable sleep mode.
Definition evmu_rom.h:67
GblType EvmuRom_type(void)
Returns the GblType UUID associated with EvmuRom.
EVMU_BIOS_TYPE
Definition evmu_rom.h:71
@ EVMU_BIOS_TYPE_UNKNOWN_IMAGE
Any other unknown image.
Definition evmu_rom.h:75
@ EVMU_BIOS_TYPE_EMULATED
Default, no BIOS, software emulation.
Definition evmu_rom.h:72
@ EVMU_BIOS_TYPE_AMERICAN_IMAGE_V1_05
CRC for American BIOS.
Definition evmu_rom.h:73
@ EVMU_BIOS_TYPE_JAPANESE_IMAGE_V1_04
CRC for Japanese BIOS.
Definition evmu_rom.h:74
uint8_t EvmuWord
Represents a single 8-bit CPU word.
uint32_t EvmuAddress
Represents a generic absolute address.
#define GBL_ENUM_TYPE
#define GBL_STRING_TYPE
#define GBL_BOOL_TYPE
#define GBL_PROPERTIES(object,...)
uint8_t GblBool
uintptr_t GblType
Peripheral managing ROM, firmware calls, and BIOS images.
Definition evmu_rom.h:116
EVMU_RESULT EvmuRom_writeByte(EvmuRom *pSelf, EvmuAddress address, EvmuWord byte)
Writes the byte value to the ROM address.
EVMU_RESULT EvmuRom_writeBytes(EvmuRom *pSelf, EvmuAddress address, const void *pData, size_t *pSize)
Writes pSize bytes to ROM from pData, starting at address, writing back the number of bytes written.
EVMU_RESULT EvmuRom_loadBios(EvmuRom *pSelf, const char *pPath)
Loads a BIOS image from the path given by pPath.
GblBool EvmuRom_biosActive(const EvmuRom *pSelf)
Returns GBL_TRUE if the CPU is currently executing code from the BIOS.
EvmuWord EvmuRom_readByte(const EvmuRom *pSelf, EvmuAddress address)
Returns the byte value located at the given ROM address.
EVMU_RESULT EvmuRom_setDateTime(EvmuRom *pSelf, const GblDateTime *pDateTime)
Sets the current date and time as seen by the BIOS to the value given by pDateTime.
EvmuAddress EvmuRom_callBios(EvmuRom *pSelf, EvmuAddress entry)
Makes a firmware or BIOS subroutine call at the entry point given by entry.
EVMU_RESULT EvmuRom_skipBiosSetup(EvmuRom *pSelf, GblBool enableSkip)
Enables or disables skipping the BIOS date/time setup based on the value of enableSkip.
GblDateTime * EvmuRom_dateTime(const EvmuRom *pSelf, GblDateTime *pDateTime)
Returns the current date and time as seen by the BIOS.
EVMU_BIOS_TYPE EvmuRom_biosType(const EvmuRom *pSelf)
Returns the type of BIOS currently loaded into ROM.
EVMU_BIOS_MODE EvmuRom_biosMode(const EvmuRom *pSelf)
Returns the mode the BIOS is in (file manager, game, clock, etc)
EVMU_RESULT EvmuRom_readBytes(const EvmuRom *pSelf, EvmuAddress address, void *pData, size_t *pSize)
Reads pSize bytes from ROM into pData, starting at address, writing back the number of bytes read.
EVMU_RESULT EvmuRom_unloadBios(EvmuRom *pSelf)
Unloads any currently-loaded BIOS image, returning to software emulation.
#define GBL_CLASS_CAST(cType, klass)
#define GBL_CLASSOF(cType, self)
#define GBL_CAST(cType, self)