@@ -15,7 +15,7 @@ uint8* memory_getPointerFromPhysicalOffset(uint32 physicalOffset);
15
15
uint32 memory_virtualToPhysical (uint32 virtualOffset);
16
16
uint32 memory_physicalToVirtual (uint32 physicalOffset);
17
17
18
- extern uint8* memory_base; // points to 0x00000000
18
+ extern uint8* memory_base; // points to base of PowerPC address space
19
19
20
20
enum class MMU_MEM_AREA_ID
21
21
{
@@ -171,33 +171,26 @@ bool memory_isAddressRangeAccessible(MPTR virtualAddress, uint32 size);
171
171
#define MEMORY_SHAREDDATA_AREA_ADDR (0xF8000000 )
172
172
#define MEMORY_SHAREDDATA_AREA_SIZE (0x02000000 ) // 32MB
173
173
174
- static uint16 CPU_swapEndianU16 (uint16 v)
175
- {
176
- return (v>>8 )|(v<<8 );
177
- }
178
-
179
174
#if BOOST_OS_WINDOWS
180
175
#define CPU_swapEndianU64 (_v ) _byteswap_uint64((uint64)(_v))
181
176
#define CPU_swapEndianU32 (_v ) _byteswap_ulong((uint32)(_v))
177
+ #define CPU_swapEndianU16 (_v ) _byteswap_ushort((uint16)(_v))
182
178
#elif BOOST_OS_LINUX
183
179
#define CPU_swapEndianU64 (_v ) bswap_64((uint64)(_v))
184
180
#define CPU_swapEndianU32 (_v ) bswap_32((uint32)(_v))
181
+ #define CPU_swapEndianU16 (_v ) bswap_16((uint16)(_v))
185
182
#elif BOOST_OS_MACOS
186
183
#define CPU_swapEndianU64 (_v ) OSSwapInt64((uint64)(_v))
187
184
#define CPU_swapEndianU32 (_v ) OSSwapInt32((uint32)(_v))
185
+ #define CPU_swapEndianU16 (_v ) OSSwapInt16((uint16)(_v))
188
186
#endif
189
187
190
- // direct memory access (no hardware interface access)
191
- void memory_writeU32Direct (uint32 address, uint32 v);
192
- uint32 memory_readU32Direct (uint32 address);
193
-
194
- // memory access (includes hardware interface, slower)
188
+ // C-style memory access, deprecated. Use memory_read<> and memory_write<> templates instead
195
189
void memory_writeDouble (uint32 address, double vf);
196
190
void memory_writeFloat (uint32 address, float vf);
197
191
void memory_writeU32 (uint32 address, uint32 v);
198
192
void memory_writeU16 (uint32 address, uint16 v);
199
193
void memory_writeU8 (uint32 address, uint8 v);
200
- void memory_writeU64Slow (uint32 address, uint64 v);
201
194
void memory_writeU64 (uint32 address, uint64 v);
202
195
203
196
double memory_readDouble (uint32 address);
@@ -210,43 +203,24 @@ uint8 memory_readU8(uint32 address);
210
203
void memory_createDump ();
211
204
212
205
template <size_t count>
213
- void memory_readBytes (uint32 address, std::array<uint8, count>& buffer)
206
+ void memory_readBytes (VAddr address, std::array<uint8, count>& buffer)
214
207
{
215
208
memcpy (buffer.data (), memory_getPointerFromVirtualOffset (address), count);
216
209
}
217
210
218
- template <typename T> T memory_read (uint32 address)
211
+ template <typename T> inline T memory_read (VAddr address)
219
212
{
220
- if constexpr (std::is_floating_point<T>::value)
221
- {
222
- if constexpr (sizeof (T) == sizeof (float ))
223
- return memory_readFloat (address);
224
- else
225
- return memory_readDouble (address);
226
- }
227
- else if (std::is_integral<T>::value)
228
- {
229
- if constexpr (sizeof (T) == sizeof (uint8))
230
- return (T)memory_readU8 (address);
231
- else if constexpr (sizeof (T) == sizeof (uint16))
232
- return (T)memory_readU16 (address);
233
- else if constexpr (sizeof (T) == sizeof (uint32))
234
- return (T)memory_readU32 (address);
235
- else if constexpr (sizeof (T) == sizeof (uint64))
236
- return (T)memory_readU64 (address);
237
- }
213
+ return *(betype<T>*)(memory_base + address);
214
+ }
238
215
239
- debugBreakpoint ();
240
- return {};
216
+ template <typename T> inline void memory_write (VAddr address, T value)
217
+ {
218
+ *(betype<T>*)(memory_base + address) = value;
241
219
}
242
220
243
221
// LLE implementation
244
222
void memory_initPhysicalLayout ();
245
223
246
- // updated code
247
- using EAddr = uint32; // effective address
248
- using PAddr = uint32; // physical address
249
-
250
224
namespace MMU
251
225
{
252
226
using MMIOFuncWrite32 = void (*)(PAddr addr, uint32 value);
0 commit comments