diff options
Diffstat (limited to 'src/core/hw')
| -rw-r--r-- | src/core/hw/gpu.cpp | 253 | ||||
| -rw-r--r-- | src/core/hw/gpu.h | 219 | ||||
| -rw-r--r-- | src/core/hw/hw.h | 4 |
3 files changed, 356 insertions, 120 deletions
diff --git a/src/core/hw/gpu.cpp b/src/core/hw/gpu.cpp index f0ca4eada..c00be2a83 100644 --- a/src/core/hw/gpu.cpp +++ b/src/core/hw/gpu.cpp | |||
| @@ -15,48 +15,58 @@ | |||
| 15 | 15 | ||
| 16 | namespace GPU { | 16 | namespace GPU { |
| 17 | 17 | ||
| 18 | Registers g_regs; | 18 | RegisterSet<u32, Regs> g_regs; |
| 19 | 19 | ||
| 20 | u64 g_last_ticks = 0; ///< Last CPU ticks | 20 | u64 g_last_ticks = 0; ///< Last CPU ticks |
| 21 | 21 | ||
| 22 | /** | 22 | /** |
| 23 | * Sets whether the framebuffers are in the GSP heap (FCRAM) or VRAM | 23 | * Sets whether the framebuffers are in the GSP heap (FCRAM) or VRAM |
| 24 | * @param | 24 | * @param |
| 25 | */ | 25 | */ |
| 26 | void SetFramebufferLocation(const FramebufferLocation mode) { | 26 | void SetFramebufferLocation(const FramebufferLocation mode) { |
| 27 | switch (mode) { | 27 | switch (mode) { |
| 28 | case FRAMEBUFFER_LOCATION_FCRAM: | 28 | case FRAMEBUFFER_LOCATION_FCRAM: |
| 29 | g_regs.framebuffer_top_left_1 = PADDR_TOP_LEFT_FRAME1; | 29 | { |
| 30 | g_regs.framebuffer_top_left_2 = PADDR_TOP_LEFT_FRAME2; | 30 | auto& framebuffer_top = g_regs.Get<Regs::FramebufferTop>(); |
| 31 | g_regs.framebuffer_top_right_1 = PADDR_TOP_RIGHT_FRAME1; | 31 | auto& framebuffer_sub = g_regs.Get<Regs::FramebufferBottom>(); |
| 32 | g_regs.framebuffer_top_right_2 = PADDR_TOP_RIGHT_FRAME2; | 32 | |
| 33 | g_regs.framebuffer_sub_left_1 = PADDR_SUB_FRAME1; | 33 | framebuffer_top.address_left1 = PADDR_TOP_LEFT_FRAME1; |
| 34 | //g_regs.framebuffer_sub_left_2 = unknown; | 34 | framebuffer_top.address_left2 = PADDR_TOP_LEFT_FRAME2; |
| 35 | g_regs.framebuffer_sub_right_1 = PADDR_SUB_FRAME2; | 35 | framebuffer_top.address_right1 = PADDR_TOP_RIGHT_FRAME1; |
| 36 | //g_regs.framebufferr_sub_right_2 = unknown; | 36 | framebuffer_top.address_right2 = PADDR_TOP_RIGHT_FRAME2; |
| 37 | framebuffer_sub.address_left1 = PADDR_SUB_FRAME1; | ||
| 38 | //framebuffer_sub.address_left2 = unknown; | ||
| 39 | framebuffer_sub.address_right1 = PADDR_SUB_FRAME2; | ||
| 40 | //framebuffer_sub.address_right2 = unknown; | ||
| 37 | break; | 41 | break; |
| 42 | } | ||
| 38 | 43 | ||
| 39 | case FRAMEBUFFER_LOCATION_VRAM: | 44 | case FRAMEBUFFER_LOCATION_VRAM: |
| 40 | g_regs.framebuffer_top_left_1 = PADDR_VRAM_TOP_LEFT_FRAME1; | 45 | { |
| 41 | g_regs.framebuffer_top_left_2 = PADDR_VRAM_TOP_LEFT_FRAME2; | 46 | auto& framebuffer_top = g_regs.Get<Regs::FramebufferTop>(); |
| 42 | g_regs.framebuffer_top_right_1 = PADDR_VRAM_TOP_RIGHT_FRAME1; | 47 | auto& framebuffer_sub = g_regs.Get<Regs::FramebufferBottom>(); |
| 43 | g_regs.framebuffer_top_right_2 = PADDR_VRAM_TOP_RIGHT_FRAME2; | 48 | |
| 44 | g_regs.framebuffer_sub_left_1 = PADDR_VRAM_SUB_FRAME1; | 49 | framebuffer_top.address_left1 = PADDR_VRAM_TOP_LEFT_FRAME1; |
| 45 | //g_regs.framebuffer_sub_left_2 = unknown; | 50 | framebuffer_top.address_left2 = PADDR_VRAM_TOP_LEFT_FRAME2; |
| 46 | g_regs.framebuffer_sub_right_1 = PADDR_VRAM_SUB_FRAME2; | 51 | framebuffer_top.address_right1 = PADDR_VRAM_TOP_RIGHT_FRAME1; |
| 47 | //g_regs.framebufferr_sub_right_2 = unknown; | 52 | framebuffer_top.address_right2 = PADDR_VRAM_TOP_RIGHT_FRAME2; |
| 53 | framebuffer_sub.address_left1 = PADDR_VRAM_SUB_FRAME1; | ||
| 54 | //framebuffer_sub.address_left2 = unknown; | ||
| 55 | framebuffer_sub.address_right1 = PADDR_VRAM_SUB_FRAME2; | ||
| 56 | //framebuffer_sub.address_right2 = unknown; | ||
| 48 | break; | 57 | break; |
| 49 | } | 58 | } |
| 59 | } | ||
| 50 | } | 60 | } |
| 51 | 61 | ||
| 52 | /** | 62 | /** |
| 53 | * Gets the location of the framebuffers | 63 | * Gets the location of the framebuffers |
| 54 | * @return Location of framebuffers as FramebufferLocation enum | 64 | * @return Location of framebuffers as FramebufferLocation enum |
| 55 | */ | 65 | */ |
| 56 | const FramebufferLocation GetFramebufferLocation() { | 66 | FramebufferLocation GetFramebufferLocation(u32 address) { |
| 57 | if ((g_regs.framebuffer_top_right_1 & ~Memory::VRAM_MASK) == Memory::VRAM_PADDR) { | 67 | if ((address & ~Memory::VRAM_MASK) == Memory::VRAM_PADDR) { |
| 58 | return FRAMEBUFFER_LOCATION_VRAM; | 68 | return FRAMEBUFFER_LOCATION_VRAM; |
| 59 | } else if ((g_regs.framebuffer_top_right_1 & ~Memory::FCRAM_MASK) == Memory::FCRAM_PADDR) { | 69 | } else if ((address & ~Memory::FCRAM_MASK) == Memory::FCRAM_PADDR) { |
| 60 | return FRAMEBUFFER_LOCATION_FCRAM; | 70 | return FRAMEBUFFER_LOCATION_FCRAM; |
| 61 | } else { | 71 | } else { |
| 62 | ERROR_LOG(GPU, "unknown framebuffer location!"); | 72 | ERROR_LOG(GPU, "unknown framebuffer location!"); |
| @@ -64,91 +74,161 @@ const FramebufferLocation GetFramebufferLocation() { | |||
| 64 | return FRAMEBUFFER_LOCATION_UNKNOWN; | 74 | return FRAMEBUFFER_LOCATION_UNKNOWN; |
| 65 | } | 75 | } |
| 66 | 76 | ||
| 77 | u32 GetFramebufferAddr(const u32 address) { | ||
| 78 | switch (GetFramebufferLocation(address)) { | ||
| 79 | case FRAMEBUFFER_LOCATION_FCRAM: | ||
| 80 | return Memory::VirtualAddressFromPhysical_FCRAM(address); | ||
| 81 | case FRAMEBUFFER_LOCATION_VRAM: | ||
| 82 | return Memory::VirtualAddressFromPhysical_VRAM(address); | ||
| 83 | default: | ||
| 84 | ERROR_LOG(GPU, "unknown framebuffer location"); | ||
| 85 | } | ||
| 86 | return 0; | ||
| 87 | } | ||
| 88 | |||
| 67 | /** | 89 | /** |
| 68 | * Gets a read-only pointer to a framebuffer in memory | 90 | * Gets a read-only pointer to a framebuffer in memory |
| 69 | * @param address Physical address of framebuffer | 91 | * @param address Physical address of framebuffer |
| 70 | * @return Returns const pointer to raw framebuffer | 92 | * @return Returns const pointer to raw framebuffer |
| 71 | */ | 93 | */ |
| 72 | const u8* GetFramebufferPointer(const u32 address) { | 94 | const u8* GetFramebufferPointer(const u32 address) { |
| 73 | switch (GetFramebufferLocation()) { | 95 | u32 addr = GetFramebufferAddr(address); |
| 74 | case FRAMEBUFFER_LOCATION_FCRAM: | 96 | return (addr != 0) ? Memory::GetPointer(addr) : nullptr; |
| 75 | return (const u8*)Memory::GetPointer(Memory::VirtualAddressFromPhysical_FCRAM(address)); | ||
| 76 | case FRAMEBUFFER_LOCATION_VRAM: | ||
| 77 | return (const u8*)Memory::GetPointer(Memory::VirtualAddressFromPhysical_VRAM(address)); | ||
| 78 | default: | ||
| 79 | ERROR_LOG(GPU, "unknown framebuffer location"); | ||
| 80 | } | ||
| 81 | return NULL; | ||
| 82 | } | 97 | } |
| 83 | 98 | ||
| 84 | template <typename T> | 99 | template <typename T> |
| 85 | inline void Read(T &var, const u32 addr) { | 100 | inline void Read(T &var, const u32 raw_addr) { |
| 86 | switch (addr) { | 101 | u32 addr = raw_addr - 0x1EF00000; |
| 87 | case Registers::FramebufferTopLeft1: | 102 | int index = addr / 4; |
| 88 | var = g_regs.framebuffer_top_left_1; | ||
| 89 | break; | ||
| 90 | 103 | ||
| 91 | case Registers::FramebufferTopLeft2: | 104 | // Reads other than u32 are untested, so I'd rather have them abort than silently fail |
| 92 | var = g_regs.framebuffer_top_left_2; | 105 | if (index >= Regs::NumIds || !std::is_same<T,u32>::value) |
| 93 | break; | 106 | { |
| 107 | ERROR_LOG(GPU, "unknown Read%d @ 0x%08X", sizeof(var) * 8, addr); | ||
| 108 | return; | ||
| 109 | } | ||
| 94 | 110 | ||
| 95 | case Registers::FramebufferTopRight1: | 111 | var = g_regs[static_cast<Regs::Id>(addr / 4)]; |
| 96 | var = g_regs.framebuffer_top_right_1; | 112 | } |
| 97 | break; | ||
| 98 | 113 | ||
| 99 | case Registers::FramebufferTopRight2: | 114 | template <typename T> |
| 100 | var = g_regs.framebuffer_top_right_2; | 115 | inline void Write(u32 addr, const T data) { |
| 101 | break; | 116 | addr -= 0x1EF00000; |
| 117 | int index = addr / 4; | ||
| 102 | 118 | ||
| 103 | case Registers::FramebufferSubLeft1: | 119 | // Writes other than u32 are untested, so I'd rather have them abort than silently fail |
| 104 | var = g_regs.framebuffer_sub_left_1; | 120 | if (index >= Regs::NumIds || !std::is_same<T,u32>::value) |
| 105 | break; | 121 | { |
| 122 | ERROR_LOG(GPU, "unknown Write%d 0x%08X @ 0x%08X", sizeof(data) * 8, data, addr); | ||
| 123 | return; | ||
| 124 | } | ||
| 106 | 125 | ||
| 107 | case Registers::FramebufferSubRight1: | 126 | g_regs[static_cast<Regs::Id>(index)] = data; |
| 108 | var = g_regs.framebuffer_sub_right_1; | ||
| 109 | break; | ||
| 110 | 127 | ||
| 111 | case Registers::CommandListSize: | 128 | switch (static_cast<Regs::Id>(index)) { |
| 112 | var = g_regs.command_list_size; | ||
| 113 | break; | ||
| 114 | 129 | ||
| 115 | case Registers::CommandListAddress: | 130 | // Memory fills are triggered once the fill value is written. |
| 116 | var = g_regs.command_list_address; | 131 | // NOTE: This is not verified. |
| 117 | break; | 132 | case Regs::MemoryFill + 3: |
| 133 | case Regs::MemoryFill + 7: | ||
| 134 | { | ||
| 135 | const auto& config = g_regs.Get<Regs::MemoryFill>(static_cast<Regs::Id>(index - 3)); | ||
| 118 | 136 | ||
| 119 | case Registers::ProcessCommandList: | 137 | // TODO: Not sure if this check should be done at GSP level instead |
| 120 | var = g_regs.command_processing_enabled; | 138 | if (config.address_start) { |
| 121 | break; | 139 | // TODO: Not sure if this algorithm is correct, particularly because it doesn't use the size member at all |
| 140 | u32* start = (u32*)Memory::GetPointer(config.GetStartAddress()); | ||
| 141 | u32* end = (u32*)Memory::GetPointer(config.GetEndAddress()); | ||
| 142 | for (u32* ptr = start; ptr < end; ++ptr) | ||
| 143 | *ptr = bswap32(config.value); // TODO: This is just a workaround to missing framebuffer format emulation | ||
| 122 | 144 | ||
| 123 | default: | 145 | DEBUG_LOG(GPU, "MemoryFill from 0x%08x to 0x%08x", config.GetStartAddress(), config.GetEndAddress()); |
| 124 | ERROR_LOG(GPU, "unknown Read%d @ 0x%08X", sizeof(var) * 8, addr); | 146 | } |
| 125 | break; | 147 | break; |
| 126 | } | 148 | } |
| 127 | } | ||
| 128 | |||
| 129 | template <typename T> | ||
| 130 | inline void Write(u32 addr, const T data) { | ||
| 131 | switch (static_cast<Registers::Id>(addr)) { | ||
| 132 | case Registers::CommandListSize: | ||
| 133 | g_regs.command_list_size = data; | ||
| 134 | break; | ||
| 135 | 149 | ||
| 136 | case Registers::CommandListAddress: | 150 | case Regs::DisplayTransfer + 6: |
| 137 | g_regs.command_list_address = data; | 151 | { |
| 152 | const auto& config = g_regs.Get<Regs::DisplayTransfer>(); | ||
| 153 | if (config.trigger & 1) { | ||
| 154 | u8* source_pointer = Memory::GetPointer(config.GetPhysicalInputAddress()); | ||
| 155 | u8* dest_pointer = Memory::GetPointer(config.GetPhysicalOutputAddress()); | ||
| 156 | |||
| 157 | for (int y = 0; y < config.output_height; ++y) { | ||
| 158 | // TODO: Why does the register seem to hold twice the framebuffer width? | ||
| 159 | for (int x = 0; x < config.output_width / 2; ++x) { | ||
| 160 | struct { | ||
| 161 | int r, g, b, a; | ||
| 162 | } source_color = { 0, 0, 0, 0 }; | ||
| 163 | |||
| 164 | switch (config.input_format) { | ||
| 165 | case Regs::FramebufferFormat::RGBA8: | ||
| 166 | { | ||
| 167 | // TODO: Most likely got the component order messed up. | ||
| 168 | u8* srcptr = source_pointer + x * 4 + y * config.input_width * 4 / 2; | ||
| 169 | source_color.r = srcptr[0]; // blue | ||
| 170 | source_color.g = srcptr[1]; // green | ||
| 171 | source_color.b = srcptr[2]; // red | ||
| 172 | source_color.a = srcptr[3]; // alpha | ||
| 173 | break; | ||
| 174 | } | ||
| 175 | |||
| 176 | default: | ||
| 177 | ERROR_LOG(GPU, "Unknown source framebuffer format %x", config.input_format.Value()); | ||
| 178 | break; | ||
| 179 | } | ||
| 180 | |||
| 181 | switch (config.output_format) { | ||
| 182 | /*case Regs::FramebufferFormat::RGBA8: | ||
| 183 | { | ||
| 184 | // TODO: Untested | ||
| 185 | u8* dstptr = (u32*)(dest_pointer + x * 4 + y * config.output_width * 4); | ||
| 186 | dstptr[0] = source_color.r; | ||
| 187 | dstptr[1] = source_color.g; | ||
| 188 | dstptr[2] = source_color.b; | ||
| 189 | dstptr[3] = source_color.a; | ||
| 190 | break; | ||
| 191 | }*/ | ||
| 192 | |||
| 193 | case Regs::FramebufferFormat::RGB8: | ||
| 194 | { | ||
| 195 | // TODO: Most likely got the component order messed up. | ||
| 196 | u8* dstptr = dest_pointer + x * 3 + y * config.output_width * 3 / 2; | ||
| 197 | dstptr[0] = source_color.r; // blue | ||
| 198 | dstptr[1] = source_color.g; // green | ||
| 199 | dstptr[2] = source_color.b; // red | ||
| 200 | break; | ||
| 201 | } | ||
| 202 | |||
| 203 | default: | ||
| 204 | ERROR_LOG(GPU, "Unknown destination framebuffer format %x", config.output_format.Value()); | ||
| 205 | break; | ||
| 206 | } | ||
| 207 | } | ||
| 208 | } | ||
| 209 | |||
| 210 | DEBUG_LOG(GPU, "DisplayTriggerTransfer: 0x%08x bytes from 0x%08x(%dx%d)-> 0x%08x(%dx%d), dst format %x", | ||
| 211 | config.output_height * config.output_width * 4, | ||
| 212 | config.GetPhysicalInputAddress(), (int)config.input_width, (int)config.input_height, | ||
| 213 | config.GetPhysicalOutputAddress(), (int)config.output_width, (int)config.output_height, | ||
| 214 | config.output_format.Value()); | ||
| 215 | } | ||
| 138 | break; | 216 | break; |
| 217 | } | ||
| 139 | 218 | ||
| 140 | case Registers::ProcessCommandList: | 219 | case Regs::CommandProcessor + 4: |
| 141 | g_regs.command_processing_enabled = data; | 220 | { |
| 142 | if (g_regs.command_processing_enabled & 1) | 221 | const auto& config = g_regs.Get<Regs::CommandProcessor>(); |
| 222 | if (config.trigger & 1) | ||
| 143 | { | 223 | { |
| 144 | // u32* buffer = (u32*)Memory::GetPointer(g_regs.command_list_address << 3); | 224 | // u32* buffer = (u32*)Memory::GetPointer(config.address << 3); |
| 145 | ERROR_LOG(GPU, "Beginning %x bytes of commands from address %x", g_regs.command_list_size, g_regs.command_list_address << 3); | 225 | ERROR_LOG(GPU, "Beginning 0x%08x bytes of commands from address 0x%08x", config.size, config.address << 3); |
| 146 | // TODO: Process command list! | 226 | // TODO: Process command list! |
| 147 | } | 227 | } |
| 148 | break; | 228 | break; |
| 229 | } | ||
| 149 | 230 | ||
| 150 | default: | 231 | default: |
| 151 | ERROR_LOG(GPU, "unknown Write%d 0x%08X @ 0x%08X", sizeof(data) * 8, data, addr); | ||
| 152 | break; | 232 | break; |
| 153 | } | 233 | } |
| 154 | } | 234 | } |
| @@ -180,7 +260,24 @@ void Update() { | |||
| 180 | /// Initialize hardware | 260 | /// Initialize hardware |
| 181 | void Init() { | 261 | void Init() { |
| 182 | g_last_ticks = Core::g_app_core->GetTicks(); | 262 | g_last_ticks = Core::g_app_core->GetTicks(); |
| 183 | SetFramebufferLocation(FRAMEBUFFER_LOCATION_FCRAM); | 263 | // SetFramebufferLocation(FRAMEBUFFER_LOCATION_FCRAM); |
| 264 | SetFramebufferLocation(FRAMEBUFFER_LOCATION_VRAM); | ||
| 265 | |||
| 266 | auto& framebuffer_top = g_regs.Get<Regs::FramebufferTop>(); | ||
| 267 | auto& framebuffer_sub = g_regs.Get<Regs::FramebufferBottom>(); | ||
| 268 | // TODO: Width should be 240 instead? | ||
| 269 | framebuffer_top.width = 480; | ||
| 270 | framebuffer_top.height = 400; | ||
| 271 | framebuffer_top.stride = 480*3; | ||
| 272 | framebuffer_top.color_format = Regs::FramebufferFormat::RGB8; | ||
| 273 | framebuffer_top.active_fb = 0; | ||
| 274 | |||
| 275 | framebuffer_sub.width = 480; | ||
| 276 | framebuffer_sub.height = 400; | ||
| 277 | framebuffer_sub.stride = 480*3; | ||
| 278 | framebuffer_sub.color_format = Regs::FramebufferFormat::RGB8; | ||
| 279 | framebuffer_sub.active_fb = 0; | ||
| 280 | |||
| 184 | NOTICE_LOG(GPU, "initialized OK"); | 281 | NOTICE_LOG(GPU, "initialized OK"); |
| 185 | } | 282 | } |
| 186 | 283 | ||
diff --git a/src/core/hw/gpu.h b/src/core/hw/gpu.h index 3314ba989..42f18a0e7 100644 --- a/src/core/hw/gpu.h +++ b/src/core/hw/gpu.h | |||
| @@ -5,43 +5,168 @@ | |||
| 5 | #pragma once | 5 | #pragma once |
| 6 | 6 | ||
| 7 | #include "common/common_types.h" | 7 | #include "common/common_types.h" |
| 8 | #include "common/bit_field.h" | ||
| 9 | #include "common/register_set.h" | ||
| 8 | 10 | ||
| 9 | namespace GPU { | 11 | namespace GPU { |
| 10 | 12 | ||
| 11 | static const u32 kFrameCycles = 268123480 / 60; ///< 268MHz / 60 frames per second | 13 | static const u32 kFrameCycles = 268123480 / 60; ///< 268MHz / 60 frames per second |
| 12 | static const u32 kFrameTicks = kFrameCycles / 3; ///< Approximate number of instructions/frame | 14 | static const u32 kFrameTicks = kFrameCycles / 3; ///< Approximate number of instructions/frame |
| 13 | 15 | ||
| 14 | struct Registers { | 16 | // MMIO region 0x1EFxxxxx |
| 17 | struct Regs { | ||
| 15 | enum Id : u32 { | 18 | enum Id : u32 { |
| 16 | FramebufferTopLeft1 = 0x1EF00468, // Main LCD, first framebuffer for 3D left | 19 | MemoryFill = 0x00004, // + 5,6,7; second block at 8-11 |
| 17 | FramebufferTopLeft2 = 0x1EF0046C, // Main LCD, second framebuffer for 3D left | 20 | |
| 18 | FramebufferTopRight1 = 0x1EF00494, // Main LCD, first framebuffer for 3D right | 21 | FramebufferTop = 0x00117, // + 11a,11b,11c,11d(?),11e...126 |
| 19 | FramebufferTopRight2 = 0x1EF00498, // Main LCD, second framebuffer for 3D right | 22 | FramebufferBottom = 0x00157, // + 15a,15b,15c,15d(?),15e...166 |
| 20 | FramebufferSubLeft1 = 0x1EF00568, // Sub LCD, first framebuffer | 23 | |
| 21 | FramebufferSubLeft2 = 0x1EF0056C, // Sub LCD, second framebuffer | 24 | DisplayTransfer = 0x00300, // + 301,302,303,304,305,306 |
| 22 | FramebufferSubRight1 = 0x1EF00594, // Sub LCD, unused first framebuffer | 25 | |
| 23 | FramebufferSubRight2 = 0x1EF00598, // Sub LCD, unused second framebuffer | 26 | CommandProcessor = 0x00638, // + 63a,63c |
| 24 | 27 | ||
| 25 | CommandListSize = 0x1EF018E0, | 28 | NumIds = 0x01000 |
| 26 | CommandListAddress = 0x1EF018E8, | 29 | }; |
| 27 | ProcessCommandList = 0x1EF018F0, | 30 | |
| 31 | template<Id id> | ||
| 32 | struct Struct; | ||
| 33 | |||
| 34 | enum class FramebufferFormat : u32 { | ||
| 35 | RGBA8 = 0, | ||
| 36 | RGB8 = 1, | ||
| 37 | RGB565 = 2, | ||
| 38 | RGB5A1 = 3, | ||
| 39 | RGBA4 = 4, | ||
| 40 | }; | ||
| 41 | }; | ||
| 42 | |||
| 43 | template<> | ||
| 44 | struct Regs::Struct<Regs::MemoryFill> { | ||
| 45 | u32 address_start; | ||
| 46 | u32 address_end; // ? | ||
| 47 | u32 size; | ||
| 48 | u32 value; // ? | ||
| 49 | |||
| 50 | inline u32 GetStartAddress() const { | ||
| 51 | return address_start * 8; | ||
| 52 | } | ||
| 53 | |||
| 54 | inline u32 GetEndAddress() const { | ||
| 55 | return address_end * 8; | ||
| 56 | } | ||
| 57 | }; | ||
| 58 | static_assert(sizeof(Regs::Struct<Regs::MemoryFill>) == 0x10, "Structure size and register block length don't match"); | ||
| 59 | |||
| 60 | template<> | ||
| 61 | struct Regs::Struct<Regs::FramebufferTop> { | ||
| 62 | using Format = Regs::FramebufferFormat; | ||
| 63 | |||
| 64 | union { | ||
| 65 | u32 size; | ||
| 66 | |||
| 67 | BitField< 0, 16, u32> width; | ||
| 68 | BitField<16, 16, u32> height; | ||
| 69 | }; | ||
| 70 | |||
| 71 | u32 pad0[2]; | ||
| 72 | |||
| 73 | u32 address_left1; | ||
| 74 | u32 address_left2; | ||
| 75 | |||
| 76 | union { | ||
| 77 | u32 format; | ||
| 78 | |||
| 79 | BitField< 0, 3, Format> color_format; | ||
| 80 | }; | ||
| 81 | |||
| 82 | u32 pad1; | ||
| 83 | |||
| 84 | union { | ||
| 85 | u32 active_fb; | ||
| 86 | |||
| 87 | // 0: Use parameters ending with "1" | ||
| 88 | // 1: Use parameters ending with "2" | ||
| 89 | BitField<0, 1, u32> second_fb_active; | ||
| 90 | }; | ||
| 91 | |||
| 92 | u32 pad2[5]; | ||
| 93 | |||
| 94 | // Distance between two pixel rows, in bytes | ||
| 95 | u32 stride; | ||
| 96 | |||
| 97 | u32 address_right1; | ||
| 98 | u32 address_right2; | ||
| 99 | }; | ||
| 100 | |||
| 101 | template<> | ||
| 102 | struct Regs::Struct<Regs::FramebufferBottom> : public Regs::Struct<Regs::FramebufferTop> { | ||
| 103 | }; | ||
| 104 | static_assert(sizeof(Regs::Struct<Regs::FramebufferTop>) == 0x40, "Structure size and register block length don't match"); | ||
| 105 | |||
| 106 | template<> | ||
| 107 | struct Regs::Struct<Regs::DisplayTransfer> { | ||
| 108 | using Format = Regs::FramebufferFormat; | ||
| 109 | |||
| 110 | u32 input_address; | ||
| 111 | u32 output_address; | ||
| 112 | |||
| 113 | inline u32 GetPhysicalInputAddress() const { | ||
| 114 | return input_address * 8; | ||
| 115 | } | ||
| 116 | |||
| 117 | inline u32 GetPhysicalOutputAddress() const { | ||
| 118 | return output_address * 8; | ||
| 119 | } | ||
| 120 | |||
| 121 | union { | ||
| 122 | u32 output_size; | ||
| 123 | |||
| 124 | BitField< 0, 16, u32> output_width; | ||
| 125 | BitField<16, 16, u32> output_height; | ||
| 126 | }; | ||
| 127 | |||
| 128 | union { | ||
| 129 | u32 input_size; | ||
| 130 | |||
| 131 | BitField< 0, 16, u32> input_width; | ||
| 132 | BitField<16, 16, u32> input_height; | ||
| 28 | }; | 133 | }; |
| 29 | 134 | ||
| 30 | u32 framebuffer_top_left_1; | 135 | union { |
| 31 | u32 framebuffer_top_left_2; | 136 | u32 flags; |
| 32 | u32 framebuffer_top_right_1; | 137 | |
| 33 | u32 framebuffer_top_right_2; | 138 | BitField< 0, 1, u32> flip_data; // flips input data horizontally (TODO) if true |
| 34 | u32 framebuffer_sub_left_1; | 139 | BitField< 8, 3, Format> input_format; |
| 35 | u32 framebuffer_sub_left_2; | 140 | BitField<12, 3, Format> output_format; |
| 36 | u32 framebuffer_sub_right_1; | 141 | BitField<16, 1, u32> output_tiled; // stores output in a tiled format |
| 37 | u32 framebuffer_sub_right_2; | 142 | }; |
| 38 | 143 | ||
| 39 | u32 command_list_size; | 144 | u32 unknown; |
| 40 | u32 command_list_address; | 145 | |
| 41 | u32 command_processing_enabled; | 146 | // it seems that writing to this field triggers the display transfer |
| 147 | u32 trigger; | ||
| 42 | }; | 148 | }; |
| 149 | static_assert(sizeof(Regs::Struct<Regs::DisplayTransfer>) == 0x1C, "Structure size and register block length don't match"); | ||
| 150 | |||
| 151 | template<> | ||
| 152 | struct Regs::Struct<Regs::CommandProcessor> { | ||
| 153 | // command list size | ||
| 154 | u32 size; | ||
| 155 | |||
| 156 | u32 pad0; | ||
| 157 | |||
| 158 | // command list address | ||
| 159 | u32 address; | ||
| 43 | 160 | ||
| 44 | extern Registers g_regs; | 161 | u32 pad1; |
| 162 | |||
| 163 | // it seems that writing to this field triggers command list processing | ||
| 164 | u32 trigger; | ||
| 165 | }; | ||
| 166 | static_assert(sizeof(Regs::Struct<Regs::CommandProcessor>) == 0x14, "Structure size and register block length don't match"); | ||
| 167 | |||
| 168 | |||
| 169 | extern RegisterSet<u32, Regs> g_regs; | ||
| 45 | 170 | ||
| 46 | enum { | 171 | enum { |
| 47 | TOP_ASPECT_X = 0x5, | 172 | TOP_ASPECT_X = 0x5, |
| @@ -51,23 +176,35 @@ enum { | |||
| 51 | TOP_WIDTH = 400, | 176 | TOP_WIDTH = 400, |
| 52 | BOTTOM_WIDTH = 320, | 177 | BOTTOM_WIDTH = 320, |
| 53 | 178 | ||
| 54 | // Physical addresses in FCRAM used by ARM9 applications - these are correct for real hardware | 179 | // Physical addresses in FCRAM (chosen arbitrarily) |
| 55 | PADDR_FRAMEBUFFER_SEL = 0x20184E59, | 180 | PADDR_TOP_LEFT_FRAME1 = 0x201D4C00, |
| 56 | PADDR_TOP_LEFT_FRAME1 = 0x20184E60, | 181 | PADDR_TOP_LEFT_FRAME2 = 0x202D4C00, |
| 182 | PADDR_TOP_RIGHT_FRAME1 = 0x203D4C00, | ||
| 183 | PADDR_TOP_RIGHT_FRAME2 = 0x204D4C00, | ||
| 184 | PADDR_SUB_FRAME1 = 0x205D4C00, | ||
| 185 | PADDR_SUB_FRAME2 = 0x206D4C00, | ||
| 186 | // Physical addresses in FCRAM used by ARM9 applications | ||
| 187 | /* PADDR_TOP_LEFT_FRAME1 = 0x20184E60, | ||
| 57 | PADDR_TOP_LEFT_FRAME2 = 0x201CB370, | 188 | PADDR_TOP_LEFT_FRAME2 = 0x201CB370, |
| 58 | PADDR_TOP_RIGHT_FRAME1 = 0x20282160, | 189 | PADDR_TOP_RIGHT_FRAME1 = 0x20282160, |
| 59 | PADDR_TOP_RIGHT_FRAME2 = 0x202C8670, | 190 | PADDR_TOP_RIGHT_FRAME2 = 0x202C8670, |
| 60 | PADDR_SUB_FRAME1 = 0x202118E0, | 191 | PADDR_SUB_FRAME1 = 0x202118E0, |
| 61 | PADDR_SUB_FRAME2 = 0x20249CF0, | 192 | PADDR_SUB_FRAME2 = 0x20249CF0,*/ |
| 62 | 193 | ||
| 63 | // Physical addresses in VRAM - I'm not sure how these are actually allocated (so not real) | 194 | // Physical addresses in VRAM |
| 64 | PADDR_VRAM_FRAMEBUFFER_SEL = 0x18184E59, | 195 | // TODO: These should just be deduced from the ones above |
| 65 | PADDR_VRAM_TOP_LEFT_FRAME1 = 0x18184E60, | 196 | PADDR_VRAM_TOP_LEFT_FRAME1 = 0x181D4C00, |
| 66 | PADDR_VRAM_TOP_LEFT_FRAME2 = 0x181CB370, | 197 | PADDR_VRAM_TOP_LEFT_FRAME2 = 0x182D4C00, |
| 198 | PADDR_VRAM_TOP_RIGHT_FRAME1 = 0x183D4C00, | ||
| 199 | PADDR_VRAM_TOP_RIGHT_FRAME2 = 0x184D4C00, | ||
| 200 | PADDR_VRAM_SUB_FRAME1 = 0x185D4C00, | ||
| 201 | PADDR_VRAM_SUB_FRAME2 = 0x186D4C00, | ||
| 202 | // Physical addresses in VRAM used by ARM9 applications | ||
| 203 | /* PADDR_VRAM_TOP_LEFT_FRAME2 = 0x181CB370, | ||
| 67 | PADDR_VRAM_TOP_RIGHT_FRAME1 = 0x18282160, | 204 | PADDR_VRAM_TOP_RIGHT_FRAME1 = 0x18282160, |
| 68 | PADDR_VRAM_TOP_RIGHT_FRAME2 = 0x182C8670, | 205 | PADDR_VRAM_TOP_RIGHT_FRAME2 = 0x182C8670, |
| 69 | PADDR_VRAM_SUB_FRAME1 = 0x182118E0, | 206 | PADDR_VRAM_SUB_FRAME1 = 0x182118E0, |
| 70 | PADDR_VRAM_SUB_FRAME2 = 0x18249CF0, | 207 | PADDR_VRAM_SUB_FRAME2 = 0x18249CF0,*/ |
| 71 | }; | 208 | }; |
| 72 | 209 | ||
| 73 | /// Framebuffer location | 210 | /// Framebuffer location |
| @@ -79,7 +216,7 @@ enum FramebufferLocation { | |||
| 79 | 216 | ||
| 80 | /** | 217 | /** |
| 81 | * Sets whether the framebuffers are in the GSP heap (FCRAM) or VRAM | 218 | * Sets whether the framebuffers are in the GSP heap (FCRAM) or VRAM |
| 82 | * @param | 219 | * @param |
| 83 | */ | 220 | */ |
| 84 | void SetFramebufferLocation(const FramebufferLocation mode); | 221 | void SetFramebufferLocation(const FramebufferLocation mode); |
| 85 | 222 | ||
| @@ -90,16 +227,18 @@ void SetFramebufferLocation(const FramebufferLocation mode); | |||
| 90 | */ | 227 | */ |
| 91 | const u8* GetFramebufferPointer(const u32 address); | 228 | const u8* GetFramebufferPointer(const u32 address); |
| 92 | 229 | ||
| 230 | u32 GetFramebufferAddr(const u32 address); | ||
| 231 | |||
| 93 | /** | 232 | /** |
| 94 | * Gets the location of the framebuffers | 233 | * Gets the location of the framebuffers |
| 95 | */ | 234 | */ |
| 96 | const FramebufferLocation GetFramebufferLocation(); | 235 | FramebufferLocation GetFramebufferLocation(u32 address); |
| 97 | 236 | ||
| 98 | template <typename T> | 237 | template <typename T> |
| 99 | inline void Read(T &var, const u32 addr); | 238 | void Read(T &var, const u32 addr); |
| 100 | 239 | ||
| 101 | template <typename T> | 240 | template <typename T> |
| 102 | inline void Write(u32 addr, const T data); | 241 | void Write(u32 addr, const T data); |
| 103 | 242 | ||
| 104 | /// Update hardware | 243 | /// Update hardware |
| 105 | void Update(); | 244 | void Update(); |
diff --git a/src/core/hw/hw.h b/src/core/hw/hw.h index 92e9304ca..1055ed94f 100644 --- a/src/core/hw/hw.h +++ b/src/core/hw/hw.h | |||
| @@ -9,10 +9,10 @@ | |||
| 9 | namespace HW { | 9 | namespace HW { |
| 10 | 10 | ||
| 11 | template <typename T> | 11 | template <typename T> |
| 12 | inline void Read(T &var, const u32 addr); | 12 | void Read(T &var, const u32 addr); |
| 13 | 13 | ||
| 14 | template <typename T> | 14 | template <typename T> |
| 15 | inline void Write(u32 addr, const T data); | 15 | void Write(u32 addr, const T data); |
| 16 | 16 | ||
| 17 | /// Update hardware | 17 | /// Update hardware |
| 18 | void Update(); | 18 | void Update(); |