libElysianVMU 1.6.0
Full-featured, accurate, cross-platform library emulating the Dreamcast's Visual Memory Unit
Loading...
Searching...
No Matches
evmu_imemory.h
Go to the documentation of this file.
1/*! \file
2 * \brief EvmuIMemory interface for generic memory access
3 *
4 * This file contains the interface definition and public
5 * API for EvmuIMemory, which is a polymorphic base class
6 * used to provide a common mechanism for interacting
7 * with the different memory peripherals of the VMU.
8 *
9 * \author 2023 Falco Girgis
10 * \copyright MIT License
11 */
12#ifndef EVMU_IMEMORY_H
13#define EVMU_IMEMORY_H
14
15#include "evmu_typedefs.h"
16#include <gimbal/meta/instances/gimbal_object.h>
17#include <gimbal/meta/signals/gimbal_signal.h>
18
19/*! \name Type System
20 * \brief Type UUID and cast operators
21 * @{
22 */
23#define EVMU_IMEMORY_TYPE (GBL_TYPEID(EvmuIMemory)) //!< Type UUID for EvmuIMemory
24#define EVMU_IMEMORY(self) (GBL_CAST(EvmuIMemory, self)) //!< Cast a GblInstance to EvmuIMemory
25#define EVMU_IMEMORY_CLASS(klass) (GBL_CLASS_CAST(EvmuIMemory, klass)) //!< Cast a GblClass to EvmuIMemoryClass
26#define EVMU_IMEMORY_GET_CLASS(self) (GBL_CLASSOF(EvmuIMemory, self)) //!< Get an EvmuIMemoryClass from a GblInstance
27//! @}
28
29#define GBL_SELF_TYPE EvmuIMemory
30
31GBL_DECLS_BEGIN
32
33/*! \struct EvmuIMemoryClass
34 * \extends GblInterface
35 * \brief GblClass structure for EvmuIMemory
36 *
37 * Provides virtual methods for reading and writing to
38 * some underlying memory space. The write method should
39 * also update the "dataChanged" property (required) as
40 * well as fire the "dataChaneg" signal.
41 *
42 * \sa EvmuIMemory
43 */
44GBL_INTERFACE_DERIVE(EvmuIMemory)
45 //! Virtual method for performing a flash read, storing to buffer, reporting number of bytes read
46 EVMU_RESULT (*pFnRead) (GBL_CSELF,
47 EvmuAddress address,
48 void* pBuffer,
49 size_t* pBytes);
50 //! Virtual method for performing a flash write from a buffer, reporting byes written, and emitting the change signal
51 EVMU_RESULT (*pFnWrite)(GBL_SELF,
52 EvmuAddress address,
53 const void* pBuffer,
54 size_t* pBytes);
55 //! Byte size of memory space
56 size_t capacity;
57GBL_INTERFACE_END
58
59/*! \struct EvmuIMemory
60 * \brief Interfaced type for generic read/write memory
61 *
62 * EvmuIMemory provides a generic polymorphic
63 * interface for reading and writing from and to some
64 * external memory space.
65 *
66 * \sa EvmuIMemoryClass
67 */
68
69GBL_PROPERTIES(EvmuIMemory,
70 (dataChanged, GBL_GENERIC, (ABSTRACT, READ, WRITE), GBL_BOOL_TYPE)
71)
72
73GBL_SIGNALS(EvmuIMemory,
74 (dataChange, (GBL_UINT32_TYPE, address), (GBL_UINT32_TYPE, bytes), (GBL_POINTER_TYPE, pData))
75)
76
77//! Returns the GblType UUID associated with EvmuIMemory
78EVMU_EXPORT GblType EvmuIMemory_type(void) GBL_NOEXCEPT;
79
80/*! \name Read Accessors
81 * \brief Methods for reading data and properties
82 * \relatesalso EvmuIMemory
83 * @{
84 */
85//! Retrives the capacity of the given interface, by grabbing it from its class
86EVMU_EXPORT size_t EvmuIMemory_capacity (GBL_CSELF) GBL_NOEXCEPT;
87//! Reads a value from flash at the given address and returns its value
89 EvmuAddress address) GBL_NOEXCEPT;
90//! Reads the given number of bytes from flash into the buffer, returning the number successfully read
91EVMU_EXPORT EVMU_RESULT EvmuIMemory_readBytes (GBL_CSELF,
92 EvmuAddress base,
93 void* pData,
94 size_t* pBytes) GBL_NOEXCEPT;
95//! @}
96
97/*! \name Write Accessors
98 * \brief Methods for writing data
99 * \relatesalso EvmuIMemory
100 * @{
101 */
102//! Writes a value to flash at the given address (bypassing unlock sequence)
103EVMU_EXPORT EVMU_RESULT EvmuIMemory_writeByte (GBL_SELF,
104 EvmuAddress address,
105 EvmuWord value) GBL_NOEXCEPT;
106//! Writes the given buffer to flash, returning nubmer of bytes written (bypassing unlock sequence)
108 EvmuAddress base,
109 const void* pData,
110 size_t* pBytes) GBL_NOEXCEPT;
111//! Fills the given region with the specified bit pattern data, performing a series of batch writes
112EVMU_EXPORT EVMU_RESULT EvmuIMemory_fillBytes (GBL_SELF,
113 EvmuAddress base,
114 size_t regionSize,
115 const void* pData,
116 size_t dataBytes);
117//! @}
118
119GBL_DECLS_END
120
121#undef GBL_SELF_TYPE
122
123#endif // EVMU_IMEMORY_H
#define EVMU_EXPORT
Define used for adding attributes to export public symbols.
Definition evmu_api.h:18
uint8_t EvmuWord
Represents a single 8-bit CPU word.
uint32_t EvmuAddress
Represents a generic absolute address.
#define GBL_BOOL_TYPE
#define GBL_PROPERTIES(object,...)
uintptr_t GblType
size_t capacity
Byte size of memory space.
EVMU_RESULT EvmuIMemory_writeBytes(EvmuIMemory *pSelf, EvmuAddress base, const void *pData, size_t *pBytes)
Writes the given buffer to flash, returning nubmer of bytes written (bypassing unlock sequence)
EVMU_RESULT EvmuIMemory_fillBytes(EvmuIMemory *pSelf, EvmuAddress base, size_t regionSize, const void *pData, size_t dataBytes)
Fills the given region with the specified bit pattern data, performing a series of batch writes.
size_t EvmuIMemory_capacity(const EvmuIMemory *pSelf)
Retrives the capacity of the given interface, by grabbing it from its class.
EVMU_RESULT EvmuIMemory_writeByte(EvmuIMemory *pSelf, EvmuAddress address, EvmuWord value)
Writes a value to flash at the given address (bypassing unlock sequence)
EvmuWord EvmuIMemory_readByte(const EvmuIMemory *pSelf, EvmuAddress address)
Reads a value from flash at the given address and returns its value.
EVMU_RESULT EvmuIMemory_readBytes(const EvmuIMemory *pSelf, EvmuAddress base, void *pData, size_t *pBytes)
Reads the given number of bytes from flash into the buffer, returning the number successfully read.
#define GBL_CLASS_CAST(cType, klass)
#define GBL_CLASSOF(cType, self)
#define GBL_CAST(cType, self)