| 1 | #cxx . . $ `<file>/mednafen/masmem.h`/ifndef __MDFN_PSX_MASMEM_H |
| 2 | #define __MDFN_PSX_MASMEM_Hcxx . . $ `mednafen/masmem.h:2:9`! |
| 3 | |
| 4 | // TODO, WIP (big-endian stores and loads not fully supported yet) |
| 5 | |
| 6 | #ifdef MSB_FIRST |
| 7 | #define MAS_NATIVE_IS_BIGENDIAN 1 |
| 8 | #else |
| 9 | #define MAS_NATIVE_IS_BIGENDIANcxx . . $ `mednafen/masmem.h:9:10`! 0 |
| 10 | #endif |
| 11 | |
| 12 | static INLINEcxx . . $ `mednafen/mednafen-types.h:21:11`! uint16cxx . . $ uint16# LoadU16_RBOcxx . . $ LoadU16_RBO(7cce449bb1bc4dad).(const uint16cxx . . $ uint16# *a) |
| 13 | { |
| 14 | #ifdef ARCH_POWERPC |
| 15 | uint16 tmp; |
| 16 | |
| 17 | __asm__ ("lhbrx %0, %y1" : "=r"(tmp) : "Z"(*a)); |
| 18 | |
| 19 | return(tmp); |
| 20 | |
| 21 | #else |
| 22 | uint16cxx . . $ uint16# tmp = *a; |
| 23 | return((tmp << 8) | (tmp >> 8)); |
| 24 | #endif |
| 25 | } |
| 26 | |
| 27 | static INLINEcxx . . $ `mednafen/mednafen-types.h:21:11`! uint32cxx . . $ uint32# LoadU32_RBOcxx . . $ LoadU32_RBO(f01f3f8043e2db77).(const uint32cxx . . $ uint32# *a) |
| 28 | { |
| 29 | #ifdef ARCH_POWERPC |
| 30 | uint32 tmp; |
| 31 | |
| 32 | __asm__ ("lwbrx %0, %y1" : "=r"(tmp) : "Z"(*a)); |
| 33 | |
| 34 | return(tmp); |
| 35 | #else |
| 36 | uint32cxx . . $ uint32# tmp = *a; |
| 37 | return((tmp << 24) | ((tmp & 0xFF00) << 8) | ((tmp >> 8) & 0xFF00) | (tmp >> 24)); |
| 38 | #endif |
| 39 | } |
| 40 | |
| 41 | static INLINEcxx . . $ `mednafen/mednafen-types.h:21:11`! void StoreU16_RBOcxx . . $ StoreU16_RBO(9c42bc65687727f9).(uint16cxx . . $ uint16# *a, const uint16cxx . . $ uint16# v) |
| 42 | { |
| 43 | #ifdef ARCH_POWERPC |
| 44 | __asm__ ("sthbrx %0, %y1" : : "r"(v), "Z"(*a)); |
| 45 | #else |
| 46 | uint16cxx . . $ uint16# tmp = (v << 8) | (v >> 8); |
| 47 | *a = tmp; |
| 48 | #endif |
| 49 | } |
| 50 | |
| 51 | static INLINEcxx . . $ `mednafen/mednafen-types.h:21:11`! void StoreU32_RBOcxx . . $ StoreU32_RBO(d89196f67e9c91e5).(uint32cxx . . $ uint32# *a, const uint32cxx . . $ uint32# v) |
| 52 | { |
| 53 | #ifdef ARCH_POWERPC |
| 54 | __asm__ ("stwbrx %0, %y1" : : "r"(v), "Z"(*a)); |
| 55 | #else |
| 56 | uint32cxx . . $ uint32# tmp = (v << 24) | ((v & 0xFF00) << 8) | ((v >> 8) & 0xFF00) | (v >> 24); |
| 57 | *a = tmp; |
| 58 | #endif |
| 59 | } |
| 60 | |
| 61 | static INLINEcxx . . $ `mednafen/mednafen-types.h:21:11`! uint16cxx . . $ uint16# LoadU16_LEcxx . . $ LoadU16_LE(7cce449bb1bc4dad).(const uint16cxx . . $ uint16# *a) |
| 62 | { |
| 63 | #ifdef MSB_FIRST |
| 64 | return LoadU16_RBO(a); |
| 65 | #else |
| 66 | return *a; |
| 67 | #endif |
| 68 | } |
| 69 | |
| 70 | static INLINEcxx . . $ `mednafen/mednafen-types.h:21:11`! uint32cxx . . $ uint32# LoadU32_LEcxx . . $ LoadU32_LE(f01f3f8043e2db77).(const uint32cxx . . $ uint32# *a) |
| 71 | { |
| 72 | #ifdef MSB_FIRST |
| 73 | return LoadU32_RBO(a); |
| 74 | #else |
| 75 | return *a; |
| 76 | #endif |
| 77 | } |
| 78 | |
| 79 | static INLINEcxx . . $ `mednafen/mednafen-types.h:21:11`! void StoreU16_LEcxx . . $ StoreU16_LE(9c42bc65687727f9).(uint16cxx . . $ uint16# *a, const uint16cxx . . $ uint16# v) |
| 80 | { |
| 81 | #ifdef MSB_FIRST |
| 82 | StoreU16_RBO(a, v); |
| 83 | #else |
| 84 | *a = v; |
| 85 | #endif |
| 86 | } |
| 87 | |
| 88 | static INLINEcxx . . $ `mednafen/mednafen-types.h:21:11`! void StoreU32_LEcxx . . $ StoreU32_LE(d89196f67e9c91e5).(uint32cxx . . $ uint32# *a, const uint32cxx . . $ uint32# v) |
| 89 | { |
| 90 | #ifdef MSB_FIRST |
| 91 | StoreU32_RBO(a, v); |
| 92 | #else |
| 93 | *a = v; |
| 94 | #endif |
| 95 | } |
| 96 | |
| 97 | |
| 98 | // address must not be >= size specified by template parameter, and address must be a multiple of the byte-size of the |
| 99 | // unit(1,2,4) being read(except for Read/WriteU24, which only needs to be byte-aligned). |
| 100 | // |
| 101 | // max_unit_type should be uint16 or uint32 |
| 102 | // |
| 103 | // pre_padding and post_padding are specified in units of sizeof(max_unit_type). |
| 104 | // |
| 105 | template<unsigned size, typename max_unit_type, bool big_endian> //, unsigned pre_padding_count, unsigned post_padding_count> |
| 106 | struct MultiAccessSizeMemcxx . . $ MultiAccessSizeMem# |
| 107 | { |
| 108 | //max_unit_type pre_padding[pre_padding_count ? pre_padding_count : 1]; |
| 109 | |
| 110 | unioncxx . . $ MultiAccessSizeMem#$anonymous_type_0# |
| 111 | { |
| 112 | uint8cxx . . $ uint8# data8cxx . . $ MultiAccessSizeMem#$anonymous_type_0#data8.[size]; |
| 113 | uint16cxx . . $ uint16# data16cxx . . $ MultiAccessSizeMem#$anonymous_type_0#data16.[size / sizeof(uint16cxx . . $ uint16#)]; |
| 114 | uint32cxx . . $ uint32# data32cxx . . $ MultiAccessSizeMem#$anonymous_type_0#data32.[size / sizeof(uint32cxx . . $ uint32#)]; |
| 115 | }; |
| 116 | |
| 117 | //max_unit_type post_padding[post_padding_count ? post_padding_count : 1]; |
| 118 | |
| 119 | INLINEcxx . . $ `mednafen/mednafen-types.h:21:11`! uint8cxx . . $ uint8# ReadU8cxx . . $ MultiAccessSizeMem#ReadU8(32407b39b2dfce37).(uint32cxx . . $ uint32# address) |
| 120 | { |
| 121 | return data8cxx . . $ MultiAccessSizeMem#$anonymous_type_0#data8.[address]; |
| 122 | } |
| 123 | |
| 124 | INLINEcxx . . $ `mednafen/mednafen-types.h:21:11`! uint16cxx . . $ uint16# ReadU16cxx . . $ MultiAccessSizeMem#ReadU16(6557041c941ab807).(uint32cxx . . $ uint32# address) |
| 125 | { |
| 126 | if(MAS_NATIVE_IS_BIGENDIANcxx . . $ `mednafen/masmem.h:9:10`! == big_endian) |
| 127 | return *(uint16cxx . . $ uint16#*)(((uint8cxx . . $ uint8#*)data16cxx . . $ MultiAccessSizeMem#$anonymous_type_0#data16.) + address); |
| 128 | else |
| 129 | return LoadU16_RBOcxx . . $ LoadU16_RBO(7cce449bb1bc4dad).((uint16cxx . . $ uint16#*)(((uint8cxx . . $ uint8#*)data16cxx . . $ MultiAccessSizeMem#$anonymous_type_0#data16.) + address)); |
| 130 | } |
| 131 | |
| 132 | INLINEcxx . . $ `mednafen/mednafen-types.h:21:11`! uint32cxx . . $ uint32# ReadU32cxx . . $ MultiAccessSizeMem#ReadU32(2141b656ce2cc063).(uint32cxx . . $ uint32# address) |
| 133 | { |
| 134 | if(MAS_NATIVE_IS_BIGENDIANcxx . . $ `mednafen/masmem.h:9:10`! == big_endian) |
| 135 | return *(uint32cxx . . $ uint32#*)(((uint8cxx . . $ uint8#*)data32cxx . . $ MultiAccessSizeMem#$anonymous_type_0#data32.) + address); |
| 136 | else |
| 137 | return LoadU32_RBOcxx . . $ LoadU32_RBO(f01f3f8043e2db77).((uint32cxx . . $ uint32#*)(((uint8cxx . . $ uint8#*)data32cxx . . $ MultiAccessSizeMem#$anonymous_type_0#data32.) + address)); |
| 138 | } |
| 139 | |
| 140 | INLINEcxx . . $ `mednafen/mednafen-types.h:21:11`! uint32cxx . . $ uint32# ReadU24cxx . . $ MultiAccessSizeMem#ReadU24(2141b656ce2cc063).(uint32cxx . . $ uint32# address) |
| 141 | { |
| 142 | uint32cxx . . $ uint32# ret; |
| 143 | |
| 144 | if(!big_endian) |
| 145 | { |
| 146 | ret = ReadU8cxx . . $ MultiAccessSizeMem#ReadU8(32407b39b2dfce37).(address) | (ReadU8cxx . . $ MultiAccessSizeMem#ReadU8(32407b39b2dfce37).(address + 1) << 8) | (ReadU8cxx . . $ MultiAccessSizeMem#ReadU8(32407b39b2dfce37).(address + 2) << 16); |
| 147 | } |
| 148 | |
| 149 | return(ret); |
| 150 | } |
| 151 | |
| 152 | |
| 153 | INLINEcxx . . $ `mednafen/mednafen-types.h:21:11`! void WriteU8cxx . . $ MultiAccessSizeMem#WriteU8(cc289a6b3dfc48da).(uint32cxx . . $ uint32# address, uint8cxx . . $ uint8# value) |
| 154 | { |
| 155 | data8cxx . . $ MultiAccessSizeMem#$anonymous_type_0#data8.[address] = value; |
| 156 | } |
| 157 | |
| 158 | INLINEcxx . . $ `mednafen/mednafen-types.h:21:11`! void WriteU16cxx . . $ MultiAccessSizeMem#WriteU16(272d193675e92631).(uint32cxx . . $ uint32# address, uint16cxx . . $ uint16# value) |
| 159 | { |
| 160 | if(MAS_NATIVE_IS_BIGENDIANcxx . . $ `mednafen/masmem.h:9:10`! == big_endian) |
| 161 | *(uint16cxx . . $ uint16#*)(((uint8cxx . . $ uint8#*)data16cxx . . $ MultiAccessSizeMem#$anonymous_type_0#data16.) + address) = value; |
| 162 | else |
| 163 | StoreU16_RBOcxx . . $ StoreU16_RBO(9c42bc65687727f9).((uint16cxx . . $ uint16#*)(((uint8cxx . . $ uint8#*)data16cxx . . $ MultiAccessSizeMem#$anonymous_type_0#data16.) + address), value); |
| 164 | } |
| 165 | |
| 166 | INLINEcxx . . $ `mednafen/mednafen-types.h:21:11`! void WriteU32cxx . . $ MultiAccessSizeMem#WriteU32(b4d55b1286ff73e8).(uint32cxx . . $ uint32# address, uint32cxx . . $ uint32# value) |
| 167 | { |
| 168 | if(MAS_NATIVE_IS_BIGENDIANcxx . . $ `mednafen/masmem.h:9:10`! == big_endian) |
| 169 | *(uint32cxx . . $ uint32#*)(((uint8cxx . . $ uint8#*)data32cxx . . $ MultiAccessSizeMem#$anonymous_type_0#data32.) + address) = value; |
| 170 | else |
| 171 | StoreU32_RBOcxx . . $ StoreU32_RBO(d89196f67e9c91e5).((uint32cxx . . $ uint32#*)(((uint8cxx . . $ uint8#*)data32cxx . . $ MultiAccessSizeMem#$anonymous_type_0#data32.) + address), value); |
| 172 | } |
| 173 | |
| 174 | INLINEcxx . . $ `mednafen/mednafen-types.h:21:11`! void WriteU24cxx . . $ MultiAccessSizeMem#WriteU24(b4d55b1286ff73e8).(uint32cxx . . $ uint32# address, uint32cxx . . $ uint32# value) |
| 175 | { |
| 176 | if(!big_endian) |
| 177 | { |
| 178 | WriteU8cxx . . $ MultiAccessSizeMem#WriteU8(cc289a6b3dfc48da).(address + 0, value >> 0); |
| 179 | WriteU8cxx . . $ MultiAccessSizeMem#WriteU8(cc289a6b3dfc48da).(address + 1, value >> 8); |
| 180 | WriteU8cxx . . $ MultiAccessSizeMem#WriteU8(cc289a6b3dfc48da).(address + 2, value >> 16); |
| 181 | } |
| 182 | } |
| 183 | |
| 184 | template<typename T> |
| 185 | INLINEcxx . . $ `mednafen/mednafen-types.h:21:11`! T Readcxx . . $ MultiAccessSizeMem#Read(7708d02b5da0a4a7).(uint32cxx . . $ uint32# address) |
| 186 | { |
| 187 | if(sizeof(T) == 4) |
| 188 | return(ReadU32cxx . . $ MultiAccessSizeMem#ReadU32(2141b656ce2cc063).(address)); |
| 189 | else if(sizeof(T) == 2) |
| 190 | return(ReadU16cxx . . $ MultiAccessSizeMem#ReadU16(6557041c941ab807).(address)); |
| 191 | else |
| 192 | return(ReadU8cxx . . $ MultiAccessSizeMem#ReadU8(32407b39b2dfce37).(address)); |
| 193 | } |
| 194 | |
| 195 | template<typename T> |
| 196 | INLINEcxx . . $ `mednafen/mednafen-types.h:21:11`! void Writecxx . . $ MultiAccessSizeMem#Write(133633b80a795ac6).(uint32cxx . . $ uint32# address, T value) |
| 197 | { |
| 198 | if(sizeof(T) == 4) |
| 199 | WriteU32cxx . . $ MultiAccessSizeMem#WriteU32(b4d55b1286ff73e8).(address, value); |
| 200 | else if(sizeof(T) == 2) |
| 201 | WriteU16cxx . . $ MultiAccessSizeMem#WriteU16(272d193675e92631).(address, value); |
| 202 | else |
| 203 | WriteU8cxx . . $ MultiAccessSizeMem#WriteU8(cc289a6b3dfc48da).(address, value); |
| 204 | } |
| 205 | }; |
| 206 | |
| 207 | #undef MAS_NATIVE_IS_BIGENDIANcxx . . $ `mednafen/masmem.h:9:10`! |
| 208 | |
| 209 | #endif |