libElysianVMU 1.6.0
Full-featured, accurate, cross-platform library emulating the Dreamcast's Visual Memory Unit
Loading...
Searching...
No Matches
evmu_ram.h
Go to the documentation of this file.
1/*! \file
2 * \brief EvmuRam top-level memory BUS entity
3 * \ingroup peripherals
4 *
5 * \todo
6 * - Move ROM and WRAM to respective peripherals
7 *
8 * \author 2023 Falco Girgis
9 * \copyright MIT License
10 */
11#ifndef EVMU_RAM_H
12#define EVMU_RAM_H
13
14#include "../types/evmu_peripheral.h"
15#include "../hw/evmu_sfr.h"
16#include "../types/evmu_imemory.h"
17
18/*! \name Type System
19 * \brief Type UUID and cast operators
20 * @{
21 */
22#define EVMU_RAM_TYPE (GBL_TYPEID(EvmuRam)) //!< Type UUID for EvmuRam
23#define EVMU_RAM(self) (GBL_CAST(EvmuRam, self)) //!< Cast GblInstance to EvmuRam
24#define EVMU_RAM_CLASS(klass) (GBL_CLASS_CAST(EvmuRam, klass)) //!< Cast GblClass to EvmuRamClass
25#define EVMU_RAM_GET_CLASS(self) (GBL_CLASSOF(EvmuRam, self)) //!< Get EvmuRamClass from GblInstances
26//! @}
27
28#define EVMU_RAM_NAME "memory" //!< GblObject peripheral name
29
30#define GBL_SELF_TYPE EvmuRam
31
32GBL_DECLS_BEGIN
33
34GBL_FORWARD_DECLARE_STRUCT(EvmuRam);
35
36//! Source memory space for program execution
37typedef enum EVMU_PROGRAM_SRC {
41} EVMU_PROGRAM_SRC;
42
43/*! \struct EvmuRamClass
44 * \extends EvmuPeripheralclass
45 * \implements EvmuIMemoryClass
46 * \brief GblClass structure for EvmuPeripheral
47 *
48 * Virtual table structure for EvmuPeripheral. Overridable for
49 * providing custom hooks for memory events or for custom
50 * address-space mapping.
51 *
52 * \sa EvmuRam
53 */
54GBL_CLASS_DERIVE_EMPTY(EvmuRam, EvmuPeripheral, EvmuIMemory)
55
56/*! \struct EvmuRam
57 * \extends EvmuPeripheral
58 * \implements EvmuIMemory
59 * \ingroup peripherals
60 * \brief GblInstance structure for EvmuPeripheral
61 *
62 * Actual instantiable object for a "memory" peripheral.
63 * Public members are user r/w toggles which are used
64 * for the back-end to notify the client that a particular
65 * region of memory has changed. The client is then to
66 * reset the toggle of interest, in acknolwedgement, so it
67 * can be set again later.
68 *
69 * \sa EvmuRamClass
70 */
71GBL_INSTANCE_DERIVE(EvmuRam, EvmuPeripheral)
72 GblBool dataChanged;
73GBL_INSTANCE_END
74
75//! \cond
76GBL_PROPERTIES(EvmuRam,
77 (dataChanged, GBL_GENERIC, (READ, WRITE, OVERRIDE), GBL_BOOL_TYPE),
78 (ramBank, GBL_GENERIC, (READ, WRITE ), GBL_ENUM_TYPE),
79 (xramBank, GBL_GENERIC, (READ, WRITE ), GBL_ENUM_TYPE),
80 (programSource, GBL_GENERIC, (READ, WRITE ), GBL_ENUM_TYPE),
81 (stackPointer, GBL_GENERIC, (READ ), GBL_UINT8_TYPE)
82)
83
84GBL_SIGNALS(EvmuRam,
85 (ramValueChange, (GBL_INSTANCE_TYPE, pReceiver), (GBL_UINT32_TYPE, address), (GBL_ENUM_TYPE, bank)),
86 (ramBankChange, (GBL_INSTANCE_TYPE, pReceiver), (GBL_ENUM_TYPE, bank)),
87 (sfrValueChange, (GBL_INSTANCE_TYPE, pReceiver), (GBL_UINT32_TYPE, address)),
88 (xramValueChange, (GBL_INSTANCE_TYPE, pReceiver), (GBL_UINT32_TYPE, address), (GBL_ENUM_TYPE, bank)),
89 (xramBankChange, (GBL_INSTANCE_TYPE, pReceiver), (GBL_ENUM_TYPE, bank)),
90 (programSourceChange, (GBL_INSTANCE_TYPE, pReceiver), (GBL_BOOL_TYPE, flash)),
91 (stackPush, (GBL_INSTANCE_TYPE, pReceiver), (GBL_UINT8_TYPE, value)),
92 (stackPop, (GBL_INSTANCE_TYPE, pReceiver))
93)
94//! \endcond
95
96//! Returns the GblType UUID associated with EvmuRam
97EVMU_EXPORT GblType EvmuRam_type (void) GBL_NOEXCEPT;
98
99/*! \name Address Modes
100 * \brief Method(s) for working with address modes
101 * \relatesalso EvmuRam
102 * @{
103 */
104//! Returns the memory address pointed to by the given register indirect mode
105EVMU_EXPORT EvmuAddress EvmuRam_indirectAddress (GBL_CSELF, size_t mode) GBL_NOEXCEPT;
106//! @}
107
108/*! \name Data Memory
109 * \brief Methods for managing the data address space
110 * \relatesalso EvmuRam
111 * @{
112 */
113//! Returns the register or port value located in data memory at the address given by \p addr
114EVMU_EXPORT EvmuWord EvmuRam_readData (GBL_CSELF, EvmuAddress addr) GBL_NOEXCEPT;
115//! Returns the latch value located in data memory at the address given by \p addr
117//! Returns the register or port value located in data memory at the given address WITHOUT triggering read side-effects
118EVMU_EXPORT EvmuWord EvmuRam_viewData (GBL_CSELF, EvmuAddress addr) GBL_NOEXCEPT;
119//! Writes \p val to the register or port at the \p addr address in data memory
120EVMU_EXPORT EVMU_RESULT EvmuRam_writeData (GBL_SELF, EvmuAddress addr, EvmuWord val) GBL_NOEXCEPT;
121//! Writes \p val to the latch located at the \p addr address in data memory
122EVMU_EXPORT EVMU_RESULT EvmuRam_writeDataLatch (GBL_SELF, EvmuAddress addr, EvmuWord val) GBL_NOEXCEPT;
123//! @}
124
125/*! \name Program Memory
126 * \brief Methods for managing the program address space
127 * \relatesalso EvmuRam
128 * @{
129 */
130//! Returns the current source memory chip for program data (ROM or Flash)
131EVMU_EXPORT EVMU_PROGRAM_SRC EvmuRam_programSrc (GBL_CSELF) GBL_NOEXCEPT;
132//! Sets the current source memory chip for program data to \p src (ROM or Flash)
133EVMU_EXPORT EVMU_RESULT EvmuRam_setProgramSrc (GBL_SELF, EVMU_PROGRAM_SRC src) GBL_NOEXCEPT;
134//! Returns the value located in program memory at the address given by \p addr
136//! Writes the \p val value to the location given by \p addr to program memory
137EVMU_EXPORT EVMU_RESULT EvmuRam_writeProgram (GBL_SELF, EvmuAddress addr, EvmuWord val) GBL_NOEXCEPT;
138//! @}
139
140/*! \name Stack
141 * \brief Methods for managing the program stack
142 * \relatesalso EvmuRam
143 * @{
144 */
145//! Returns the current depth of the program stack
146EVMU_EXPORT int EvmuRam_stackDepth (GBL_CSELF) GBL_NOEXCEPT;
147//! Returns the value at the given stack depth (0 is current stack location)
148EVMU_EXPORT EvmuWord EvmuRam_viewStack (GBL_CSELF, size_t depth) GBL_NOEXCEPT;
149//! Pops the value from the top of the stack, returning it and updating the stack pointer
150EVMU_EXPORT EvmuWord EvmuRam_popStack (GBL_SELF) GBL_NOEXCEPT;
151//! Pushes \p value onto the top of the stack, updating the stack pointer
152EVMU_EXPORT EVMU_RESULT EvmuRam_pushStack (GBL_SELF, EvmuWord value) GBL_NOEXCEPT;
153//! @}
154
155GBL_DECLS_END
156
157#undef GBL_SELF_TYPE
158
159#endif // EVMU_RAM_H
#define EVMU_EXPORT
Define used for adding attributes to export public symbols.
Definition evmu_api.h:18
EVMU_PROGRAM_SRC
Source memory space for program execution.
Definition evmu_ram.h:37
@ EVMU_PROGRAM_SRC_FLASH_BANK_1
Flash (Bank 1)
Definition evmu_ram.h:40
@ EVMU_PROGRAM_SRC_FLASH_BANK_0
Flash (Bank 0)
Definition evmu_ram.h:39
@ EVMU_PROGRAM_SRC_ROM
ROM.
Definition evmu_ram.h:38
GblType EvmuRam_type(void)
Returns the GblType UUID associated with EvmuRam.
#define EVMU_SFR_EXT_ROM
Definition evmu_sfr.h:84
#define EVMU_SFR_EXT_FLASH_BANK_1
Definition evmu_sfr.h:86
#define EVMU_SFR_EXT_FLASH_BANK_0
Definition evmu_sfr.h:85
uint8_t EvmuWord
Represents a single 8-bit CPU word.
uint32_t EvmuAddress
Represents a generic absolute address.
#define GBL_ENUM_TYPE
#define GBL_BOOL_TYPE
#define GBL_UINT8_TYPE
#define GBL_PROPERTIES(object,...)
uint8_t GblBool
uintptr_t GblType
GblInstance structure for EvmuPeripheral.
Definition evmu_ram.h:71
EvmuWord EvmuRam_viewStack(const EvmuRam *pSelf, size_t depth)
Returns the value at the given stack depth (0 is current stack location)
EVMU_PROGRAM_SRC EvmuRam_programSrc(const EvmuRam *pSelf)
Returns the current source memory chip for program data (ROM or Flash)
EVMU_RESULT EvmuRam_writeDataLatch(EvmuRam *pSelf, EvmuAddress addr, EvmuWord val)
Writes val to the latch located at the addr address in data memory.
EvmuWord EvmuRam_readDataLatch(const EvmuRam *pSelf, EvmuAddress addr)
Returns the latch value located in data memory at the address given by addr.
EVMU_RESULT EvmuRam_setProgramSrc(EvmuRam *pSelf, EVMU_PROGRAM_SRC src)
Sets the current source memory chip for program data to src (ROM or Flash)
int EvmuRam_stackDepth(const EvmuRam *pSelf)
Returns the current depth of the program stack.
EVMU_RESULT EvmuRam_pushStack(EvmuRam *pSelf, EvmuWord value)
Pushes value onto the top of the stack, updating the stack pointer.
EvmuWord EvmuRam_popStack(EvmuRam *pSelf)
Pops the value from the top of the stack, returning it and updating the stack pointer.
EVMU_RESULT EvmuRam_writeProgram(EvmuRam *pSelf, EvmuAddress addr, EvmuWord val)
Writes the val value to the location given by addr to program memory.
EvmuWord EvmuRam_viewData(const EvmuRam *pSelf, EvmuAddress addr)
Returns the register or port value located in data memory at the given address WITHOUT triggering rea...
EvmuAddress EvmuRam_indirectAddress(const EvmuRam *pSelf, size_t mode)
Returns the memory address pointed to by the given register indirect mode.
EvmuWord EvmuRam_readProgram(const EvmuRam *pSelf, EvmuAddress addr)
Returns the value located in program memory at the address given by addr.
EVMU_RESULT EvmuRam_writeData(EvmuRam *pSelf, EvmuAddress addr, EvmuWord val)
Writes val to the register or port at the addr address in data memory.
EvmuWord EvmuRam_readData(const EvmuRam *pSelf, EvmuAddress addr)
Returns the register or port value located in data memory at the address given by addr.
#define GBL_CLASS_CAST(cType, klass)
#define GBL_CLASSOF(cType, self)
#define GBL_CAST(cType, self)