| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
#ifndef GIT_MEMORY_H |
| 5 |
#define GIT_MEMORY_H |
| 6 |
|
| 7 |
#include "config.h" |
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
#ifdef USE_BIG_ENDIAN_UNALIGNED |
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
#define read32(ptr) (*((git_uint32*)(ptr))) |
| 19 |
#define read16(ptr) (*((git_uint16*)(ptr))) |
| 20 |
#define write32(ptr,v) (read32(ptr)=(git_uint32)(v)) |
| 21 |
#define write16(ptr,v) (read16(ptr)=(git_uint16)(v)) |
| 22 |
|
| 23 |
#else |
| 24 |
|
| 25 |
|
| 26 |
|
| 27 |
|
| 28 |
|
| 29 |
#define read32(ptr) \ |
| 30 |
( (git_uint32)(((git_uint8 *)(ptr))[0] << 24) \ |
| 31 |
| (git_uint32)(((git_uint8 *)(ptr))[1] << 16) \ |
| 32 |
| (git_uint32)(((git_uint8 *)(ptr))[2] << 8) \ |
| 33 |
| (git_uint32)(((git_uint8 *)(ptr))[3])) |
| 34 |
#define read16(ptr) \ |
| 35 |
( (git_uint16)(((git_uint8 *)(ptr))[0] << 8) \ |
| 36 |
| (git_uint16)(((git_uint8 *)(ptr))[1])) |
| 37 |
|
| 38 |
#define write32(ptr, v) \ |
| 39 |
(((ptr)[0] = (git_uint8)(((git_uint32)(v)) >> 24)), \ |
| 40 |
((ptr)[1] = (git_uint8)(((git_uint32)(v)) >> 16)), \ |
| 41 |
((ptr)[2] = (git_uint8)(((git_uint32)(v)) >> 8)), \ |
| 42 |
((ptr)[3] = (git_uint8)(((git_uint32)(v))))) |
| 43 |
#define write16(ptr, v) \ |
| 44 |
(((ptr)[0] = (git_uint8)(((git_uint32)(v)) >> 8)), \ |
| 45 |
((ptr)[1] = (git_uint8)(((git_uint32)(v))))) |
| 46 |
|
| 47 |
#endif |
| 48 |
|
| 49 |
GIT_INLINE git_uint32 readtag (const char *ptr) { |
| 50 |
return read32((const git_uint8 *)ptr); |
| 51 |
} |
| 52 |
|
| 53 |
|
| 54 |
|
| 55 |
#define read8(ptr) (*((git_uint8*)(ptr))) |
| 56 |
#define write8(ptr, v) (read8(ptr)=(git_uint8)(v)) |
| 57 |
|
| 58 |
|
| 59 |
|
| 60 |
|
| 61 |
extern git_uint32 gRamStart; |
| 62 |
extern git_uint32 gExtStart; |
| 63 |
extern git_uint32 gEndMem; |
| 64 |
extern git_uint32 gOriginalEndMem; |
| 65 |
|
| 66 |
|
| 67 |
|
| 68 |
|
| 69 |
|
| 70 |
extern const git_uint8 * gInitMem; |
| 71 |
|
| 72 |
|
| 73 |
|
| 74 |
extern git_uint8 * gMem; |
| 75 |
|
| 76 |
|
| 77 |
|
| 78 |
|
| 79 |
|
| 80 |
|
| 81 |
|
| 82 |
|
| 83 |
|
| 84 |
extern void initMemory (const git_uint8 * game, git_uint32 gameSize); |
| 85 |
|
| 86 |
|
| 87 |
|
| 88 |
extern int verifyMemory (); |
| 89 |
|
| 90 |
|
| 91 |
|
| 92 |
extern int resizeMemory (git_uint32 newSize, int isInternal); |
| 93 |
|
| 94 |
|
| 95 |
|
| 96 |
extern void resetMemory (git_uint32 protectPos, git_uint32 protectSize); |
| 97 |
|
| 98 |
|
| 99 |
|
| 100 |
extern void shutdownMemory (); |
| 101 |
|
| 102 |
|
| 103 |
|
| 104 |
|
| 105 |
extern git_noreturn void memReadError (git_uint32 address); |
| 106 |
extern git_noreturn void memWriteError (git_uint32 address); |
| 107 |
|
| 108 |
|
| 109 |
|
| 110 |
GIT_INLINE git_uint32 memRead32 (git_uint32 address) |
| 111 |
{ |
| 112 |
if (address <= gEndMem - 4) |
| 113 |
return read32 (gMem + address); |
| 114 |
else |
| 115 |
return memReadError (address), 0; |
| 116 |
} |
| 117 |
|
| 118 |
GIT_INLINE git_uint32 memRead16 (git_uint32 address) |
| 119 |
{ |
| 120 |
if (address <= gEndMem - 2) |
| 121 |
return read16 (gMem + address); |
| 122 |
else |
| 123 |
return memReadError (address), 0; |
| 124 |
} |
| 125 |
|
| 126 |
GIT_INLINE git_uint32 memRead8 (git_uint32 address) |
| 127 |
{ |
| 128 |
if (address < gEndMem) |
| 129 |
return read8 (gMem + address); |
| 130 |
else |
| 131 |
return memReadError (address), 0; |
| 132 |
} |
| 133 |
|
| 134 |
GIT_INLINE void memWrite32 (git_uint32 address, git_uint32 val) |
| 135 |
{ |
| 136 |
if (address >= gRamStart && address <= (gEndMem - 4)) |
| 137 |
write32 (gMem + address, val); |
| 138 |
else |
| 139 |
memWriteError (address); |
| 140 |
} |
| 141 |
|
| 142 |
GIT_INLINE void memWrite16 (git_uint32 address, git_uint32 val) |
| 143 |
{ |
| 144 |
if (address >= gRamStart && address <= (gEndMem - 2)) |
| 145 |
write16 (gMem + address, val); |
| 146 |
else |
| 147 |
memWriteError (address); |
| 148 |
} |
| 149 |
|
| 150 |
GIT_INLINE void memWrite8 (git_uint32 address, git_uint32 val) |
| 151 |
{ |
| 152 |
if (address >= gRamStart && address < gEndMem) |
| 153 |
write8 (gMem + address, val); |
| 154 |
else |
| 155 |
memWriteError (address); |
| 156 |
} |
| 157 |
|
| 158 |
#endif |