summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorGravatar ShizZy2013-09-18 23:52:51 -0400
committerGravatar ShizZy2013-09-18 23:52:51 -0400
commit030c836793c72f3a3c4b6847d04b1a59d5c07be8 (patch)
tree762597280e86e874399273602959c772b55eda65 /src
parentadded swap types to common (diff)
downloadyuzu-030c836793c72f3a3c4b6847d04b1a59d5c07be8.tar.gz
yuzu-030c836793c72f3a3c4b6847d04b1a59d5c07be8.tar.xz
yuzu-030c836793c72f3a3c4b6847d04b1a59d5c07be8.zip
added hw R/W/ memory functions
Diffstat (limited to 'src')
-rw-r--r--src/core/core.vcxproj1
-rw-r--r--src/core/core.vcxproj.filters1
-rw-r--r--src/core/src/mem_map.cpp2
-rw-r--r--src/core/src/mem_map.h3
-rw-r--r--src/core/src/mem_map_funcs.cpp157
5 files changed, 161 insertions, 3 deletions
diff --git a/src/core/core.vcxproj b/src/core/core.vcxproj
index 147cfc66d..081f4a489 100644
--- a/src/core/core.vcxproj
+++ b/src/core/core.vcxproj
@@ -138,6 +138,7 @@
138 <ClCompile Include="src\arm\disassembler\arm_disasm.cpp" /> 138 <ClCompile Include="src\arm\disassembler\arm_disasm.cpp" />
139 <ClCompile Include="src\core.cpp" /> 139 <ClCompile Include="src\core.cpp" />
140 <ClCompile Include="src\mem_map.cpp" /> 140 <ClCompile Include="src\mem_map.cpp" />
141 <ClCompile Include="src\mem_map_funcs.cpp" />
141 </ItemGroup> 142 </ItemGroup>
142 <ItemGroup> 143 <ItemGroup>
143 <ClInclude Include="src\arm\armcpu.h" /> 144 <ClInclude Include="src\arm\armcpu.h" />
diff --git a/src/core/core.vcxproj.filters b/src/core/core.vcxproj.filters
index b262708fc..cf374ee88 100644
--- a/src/core/core.vcxproj.filters
+++ b/src/core/core.vcxproj.filters
@@ -12,6 +12,7 @@
12 <ClCompile Include="src\arm\armemu.cpp"> 12 <ClCompile Include="src\arm\armemu.cpp">
13 <Filter>arm</Filter> 13 <Filter>arm</Filter>
14 </ClCompile> 14 </ClCompile>
15 <ClCompile Include="src\mem_map_funcs.cpp" />
15 </ItemGroup> 16 </ItemGroup>
16 <ItemGroup> 17 <ItemGroup>
17 <Filter Include="arm"> 18 <Filter Include="arm">
diff --git a/src/core/src/mem_map.cpp b/src/core/src/mem_map.cpp
index 0d3c6ca12..7bab1d4bd 100644
--- a/src/core/src/mem_map.cpp
+++ b/src/core/src/mem_map.cpp
@@ -101,7 +101,7 @@ void Init() {
101 101
102 for (size_t i = 0; i < ARRAY_SIZE(g_views); i++) { 102 for (size_t i = 0; i < ARRAY_SIZE(g_views); i++) {
103 if (g_views[i].flags & MV_IS_PRIMARY_RAM) 103 if (g_views[i].flags & MV_IS_PRIMARY_RAM)
104 g_views[i].size = MEMORY_SIZE; 104 g_views[i].size = MEM_FCRAM_SIZE;
105 } 105 }
106 106
107 INFO_LOG(MEMMAP, "Memory system initialized. RAM at %p (mirror at 0 @ %p)", g_fcram, 107 INFO_LOG(MEMMAP, "Memory system initialized. RAM at %p (mirror at 0 @ %p)", g_fcram,
diff --git a/src/core/src/mem_map.h b/src/core/src/mem_map.h
index a6370f766..08380ab3a 100644
--- a/src/core/src/mem_map.h
+++ b/src/core/src/mem_map.h
@@ -39,8 +39,7 @@
39#define MEM_AXI_WRAM_SIZE 0x00080000 ///< AXI WRAM size 39#define MEM_AXI_WRAM_SIZE 0x00080000 ///< AXI WRAM size
40#define MEM_FCRAM_SIZE 0x08000000 ///< FCRAM size 40#define MEM_FCRAM_SIZE 0x08000000 ///< FCRAM size
41 41
42#define MEMORY_SIZE MEM_FCRAM_SIZE 42#define MEM_FCRAM_MASK (MEM_FCRAM_SIZE - 1) ///< FCRAm mask
43#define MEMORY_MASK (MEM_FCRAM_SIZE - 1) ///< Main memory mask
44 43
45//////////////////////////////////////////////////////////////////////////////////////////////////// 44////////////////////////////////////////////////////////////////////////////////////////////////////
46 45
diff --git a/src/core/src/mem_map_funcs.cpp b/src/core/src/mem_map_funcs.cpp
new file mode 100644
index 000000000..ed367e01f
--- /dev/null
+++ b/src/core/src/mem_map_funcs.cpp
@@ -0,0 +1,157 @@
1/**
2 * Copyright (C) 2013 Citrus Emulator
3 *
4 * @file mem_map_funcs.cpp
5 * @author ShizZy <shizzy247@gmail.com>
6 * @date 2013-09-18
7 * @brief Memory map R/W functions
8 *
9 * @section LICENSE
10 * This program is free software; you can redistribute it and/or
11 * modify it under the terms of the GNU General Public License as
12 * published by the Free Software Foundation; either version 2 of
13 * the License, or (at your option) any later version.
14 *
15 * This program is distributed in the hope that it will be useful, but
16 * WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 * General Public License for more details at
19 * http://www.gnu.org/copyleft/gpl.html
20 *
21 * Official project repository can be found at:
22 * http://code.google.com/p/gekko-gc-emu/
23 */
24
25#include "common.h"
26
27#include "mem_map.h"
28
29namespace Memory {
30
31/*
32u8 *GetPointer(const u32 address)
33{
34 if ((address & 0x3E000000) == 0x08000000) {
35 return g_fcram + (address & MEM_FCRAM_MASK);
36 }
37 else if ((address & 0x3F800000) == 0x04000000) {
38 return m_pVRAM + (address & VRAM_MASK);
39 }
40 else if ((address & 0x3F000000) >= 0x08000000 && (address & 0x3F000000) < 0x08000000 + g_MemorySize) {
41 return m_pRAM + (address & g_MemoryMask);
42 }
43 else {
44 ERROR_LOG(MEMMAP, "Unknown GetPointer %08x PC %08x LR %08x", address, currentMIPS->pc, currentMIPS->r[MIPS_REG_RA]);
45 static bool reported = false;
46 if (!reported) {
47 Reporting::ReportMessage("Unknown GetPointer %08x PC %08x LR %08x", address, currentMIPS->pc, currentMIPS->r[MIPS_REG_RA]);
48 reported = true;
49 }
50 if (!g_Config.bIgnoreBadMemAccess) {
51 Core_EnableStepping(true);
52 host->SetDebugMode(true);
53 }
54 return 0;
55 }
56}*/
57
58template <typename T>
59inline void ReadFromHardware(T &var, const u32 address)
60{
61 // TODO: Figure out the fastest order of tests for both read and write (they are probably different).
62 // TODO: Make sure this represents the mirrors in a correct way.
63
64 // Could just do a base-relative read, too.... TODO
65
66 if ((address & 0x3E000000) == 0x08000000) {
67 var = *((const T*)&g_fcram[address & MEM_FCRAM_MASK]);
68 }
69 /*else if ((address & 0x3F800000) == 0x04000000) {
70 var = *((const T*)&m_pVRAM[address & VRAM_MASK]);
71 }*/
72 else {
73 _assert_msg_(MEMMAP, false, "unknown hardware read");
74 // WARN_LOG(MEMMAP, "ReadFromHardware: Invalid address %08x PC %08x LR %08x", address, currentMIPS->pc, currentMIPS->r[MIPS_REG_RA]);
75 }
76}
77
78template <typename T>
79inline void WriteToHardware(u32 address, const T data)
80{
81 // Could just do a base-relative write, too.... TODO
82
83 if ((address & 0x3E000000) == 0x08000000) {
84 *(T*)&g_fcram[address & MEM_FCRAM_MASK] = data;
85 }
86 /*else if ((address & 0x3F800000) == 0x04000000) {
87 *(T*)&m_pVRAM[address & VRAM_MASK] = data;
88 }*/
89 else {
90 _assert_msg_(MEMMAP, false, "unknown hardware write");
91 // WARN_LOG(MEMMAP, "WriteToHardware: Invalid address %08x PC %08x LR %08x", address, currentMIPS->pc, currentMIPS->r[MIPS_REG_RA]);
92 }
93}
94
95bool IsValidAddress(const u32 address) {
96 if ((address & 0x3E000000) == 0x08000000) {
97 return true;
98 } else if ((address & 0x3F800000) == 0x04000000) {
99 return true;
100 } else if ((address & 0xBFFF0000) == 0x00010000) {
101 return true;
102 } else if ((address & 0x3F000000) >= 0x08000000 && (address & 0x3F000000) < 0x08000000 + MEM_FCRAM_MASK) {
103 return true;
104 } else {
105 return false;
106 }
107}
108
109u8 Read_U8(const u32 _Address) {
110 u8 _var = 0;
111 ReadFromHardware<u8>(_var, _Address);
112 return (u8)_var;
113}
114
115u16 Read_U16(const u32 _Address) {
116 u16_le _var = 0;
117 ReadFromHardware<u16_le>(_var, _Address);
118 return (u16)_var;
119}
120
121u32 Read_U32(const u32 _Address) {
122 u32_le _var = 0;
123 ReadFromHardware<u32_le>(_var, _Address);
124 return _var;
125}
126
127u64 Read_U64(const u32 _Address) {
128 u64_le _var = 0;
129 ReadFromHardware<u64_le>(_var, _Address);
130 return _var;
131}
132
133u32 Read_U8_ZX(const u32 _Address) {
134 return (u32)Read_U8(_Address);
135}
136
137u32 Read_U16_ZX(const u32 _Address) {
138 return (u32)Read_U16(_Address);
139}
140
141void Write_U8(const u8 _Data, const u32 _Address) {
142 WriteToHardware<u8>(_Address, _Data);
143}
144
145void Write_U16(const u16 _Data, const u32 _Address) {
146 WriteToHardware<u16_le>(_Address, _Data);
147}
148
149void Write_U32(const u32 _Data, const u32 _Address) {
150 WriteToHardware<u32_le>(_Address, _Data);
151}
152
153void Write_U64(const u64 _Data, const u32 _Address) {
154 WriteToHardware<u64_le>(_Address, _Data);
155}
156
157} // namespace