diff options
Diffstat (limited to 'src/core/hw/lcd.cpp')
| -rw-r--r-- | src/core/hw/lcd.cpp | 103 |
1 files changed, 103 insertions, 0 deletions
diff --git a/src/core/hw/lcd.cpp b/src/core/hw/lcd.cpp index 3013673f8..6468053f2 100644 --- a/src/core/hw/lcd.cpp +++ b/src/core/hw/lcd.cpp | |||
| @@ -6,24 +6,126 @@ | |||
| 6 | #include "common/log.h" | 6 | #include "common/log.h" |
| 7 | 7 | ||
| 8 | #include "core/core.h" | 8 | #include "core/core.h" |
| 9 | #include "core/mem_map.h" | ||
| 9 | #include "core/hw/lcd.h" | 10 | #include "core/hw/lcd.h" |
| 10 | 11 | ||
| 11 | #include "video_core/video_core.h" | 12 | #include "video_core/video_core.h" |
| 12 | 13 | ||
| 13 | namespace LCD { | 14 | namespace LCD { |
| 14 | 15 | ||
| 16 | Registers g_regs; | ||
| 17 | |||
| 15 | static const u32 kFrameTicks = 268123480 / 60; ///< 268MHz / 60 frames per second | 18 | static const u32 kFrameTicks = 268123480 / 60; ///< 268MHz / 60 frames per second |
| 16 | 19 | ||
| 17 | u64 g_last_ticks = 0; ///< Last CPU ticks | 20 | u64 g_last_ticks = 0; ///< Last CPU ticks |
| 18 | 21 | ||
| 22 | /** | ||
| 23 | * Sets whether the framebuffers are in the GSP heap (FCRAM) or VRAM | ||
| 24 | * @param | ||
| 25 | */ | ||
| 26 | void SetFramebufferLocation(const FramebufferLocation mode) { | ||
| 27 | switch (mode) { | ||
| 28 | case FRAMEBUFFER_LOCATION_FCRAM: | ||
| 29 | g_regs.framebuffer_top_left_1 = PADDR_TOP_LEFT_FRAME1; | ||
| 30 | g_regs.framebuffer_top_left_2 = PADDR_TOP_LEFT_FRAME2; | ||
| 31 | g_regs.framebuffer_top_right_1 = PADDR_TOP_RIGHT_FRAME1; | ||
| 32 | g_regs.framebuffer_top_right_2 = PADDR_TOP_RIGHT_FRAME2; | ||
| 33 | g_regs.framebuffer_sub_left_1 = PADDR_SUB_FRAME1; | ||
| 34 | //g_regs.framebuffer_sub_left_2 = unknown; | ||
| 35 | g_regs.framebuffer_sub_right_1 = PADDR_SUB_FRAME2; | ||
| 36 | //g_regs.framebufferr_sub_right_2 = unknown; | ||
| 37 | break; | ||
| 38 | |||
| 39 | case FRAMEBUFFER_LOCATION_VRAM: | ||
| 40 | g_regs.framebuffer_top_left_1 = PADDR_VRAM_TOP_LEFT_FRAME1; | ||
| 41 | g_regs.framebuffer_top_left_2 = PADDR_VRAM_TOP_LEFT_FRAME2; | ||
| 42 | g_regs.framebuffer_top_right_1 = PADDR_VRAM_TOP_RIGHT_FRAME1; | ||
| 43 | g_regs.framebuffer_top_right_2 = PADDR_VRAM_TOP_RIGHT_FRAME2; | ||
| 44 | g_regs.framebuffer_sub_left_1 = PADDR_VRAM_SUB_FRAME1; | ||
| 45 | //g_regs.framebuffer_sub_left_2 = unknown; | ||
| 46 | g_regs.framebuffer_sub_right_1 = PADDR_VRAM_SUB_FRAME2; | ||
| 47 | //g_regs.framebufferr_sub_right_2 = unknown; | ||
| 48 | break; | ||
| 49 | } | ||
| 50 | } | ||
| 51 | |||
| 52 | /** | ||
| 53 | * Gets the location of the framebuffers | ||
| 54 | * @return Location of framebuffers as FramebufferLocation enum | ||
| 55 | */ | ||
| 56 | const FramebufferLocation GetFramebufferLocation() { | ||
| 57 | if ((g_regs.framebuffer_top_right_1 & ~Memory::VRAM_MASK) == Memory::VRAM_PADDR) { | ||
| 58 | return FRAMEBUFFER_LOCATION_VRAM; | ||
| 59 | } else if ((g_regs.framebuffer_top_right_1 & ~Memory::FCRAM_MASK) == Memory::FCRAM_PADDR) { | ||
| 60 | return FRAMEBUFFER_LOCATION_FCRAM; | ||
| 61 | } else { | ||
| 62 | ERROR_LOG(LCD, "unknown framebuffer location!"); | ||
| 63 | } | ||
| 64 | return FRAMEBUFFER_LOCATION_UNKNOWN; | ||
| 65 | } | ||
| 66 | |||
| 67 | /** | ||
| 68 | * Gets a read-only pointer to a framebuffer in memory | ||
| 69 | * @param address Physical address of framebuffer | ||
| 70 | * @return Returns const pointer to raw framebuffer | ||
| 71 | */ | ||
| 72 | const u8* GetFramebufferPointer(const u32 address) { | ||
| 73 | switch (GetFramebufferLocation()) { | ||
| 74 | case FRAMEBUFFER_LOCATION_FCRAM: | ||
| 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(LCD, "unknown framebuffer location"); | ||
| 80 | } | ||
| 81 | return NULL; | ||
| 82 | } | ||
| 83 | |||
| 19 | template <typename T> | 84 | template <typename T> |
| 20 | inline void Read(T &var, const u32 addr) { | 85 | inline void Read(T &var, const u32 addr) { |
| 86 | switch (addr) { | ||
| 87 | case REG_FRAMEBUFFER_TOP_LEFT_1: | ||
| 88 | var = g_regs.framebuffer_top_left_1; | ||
| 89 | break; | ||
| 90 | case REG_FRAMEBUFFER_TOP_LEFT_2: | ||
| 91 | var = g_regs.framebuffer_top_left_2; | ||
| 92 | break; | ||
| 93 | case REG_FRAMEBUFFER_TOP_RIGHT_1: | ||
| 94 | var = g_regs.framebuffer_top_right_1; | ||
| 95 | break; | ||
| 96 | case REG_FRAMEBUFFER_TOP_RIGHT_2: | ||
| 97 | var = g_regs.framebuffer_top_right_2; | ||
| 98 | break; | ||
| 99 | case REG_FRAMEBUFFER_SUB_LEFT_1: | ||
| 100 | var = g_regs.framebuffer_sub_left_1; | ||
| 101 | break; | ||
| 102 | case REG_FRAMEBUFFER_SUB_RIGHT_1: | ||
| 103 | var = g_regs.framebuffer_sub_right_1; | ||
| 104 | break; | ||
| 105 | default: | ||
| 106 | ERROR_LOG(LCD, "unknown Read%d @ 0x%08X", sizeof(var) * 8, addr); | ||
| 107 | break; | ||
| 108 | } | ||
| 109 | |||
| 21 | } | 110 | } |
| 22 | 111 | ||
| 23 | template <typename T> | 112 | template <typename T> |
| 24 | inline void Write(u32 addr, const T data) { | 113 | inline void Write(u32 addr, const T data) { |
| 114 | ERROR_LOG(LCD, "unknown Write%d 0x%08X @ 0x%08X", sizeof(data) * 8, data, addr); | ||
| 25 | } | 115 | } |
| 26 | 116 | ||
| 117 | // Explicitly instantiate template functions because we aren't defining this in the header: | ||
| 118 | |||
| 119 | template void Read<u64>(u64 &var, const u32 addr); | ||
| 120 | template void Read<u32>(u32 &var, const u32 addr); | ||
| 121 | template void Read<u16>(u16 &var, const u32 addr); | ||
| 122 | template void Read<u8>(u8 &var, const u32 addr); | ||
| 123 | |||
| 124 | template void Write<u64>(u32 addr, const u64 data); | ||
| 125 | template void Write<u32>(u32 addr, const u32 data); | ||
| 126 | template void Write<u16>(u32 addr, const u16 data); | ||
| 127 | template void Write<u8>(u32 addr, const u8 data); | ||
| 128 | |||
| 27 | /// Update hardware | 129 | /// Update hardware |
| 28 | void Update() { | 130 | void Update() { |
| 29 | u64 current_ticks = Core::g_app_core->GetTicks(); | 131 | u64 current_ticks = Core::g_app_core->GetTicks(); |
| @@ -37,6 +139,7 @@ void Update() { | |||
| 37 | /// Initialize hardware | 139 | /// Initialize hardware |
| 38 | void Init() { | 140 | void Init() { |
| 39 | g_last_ticks = Core::g_app_core->GetTicks(); | 141 | g_last_ticks = Core::g_app_core->GetTicks(); |
| 142 | SetFramebufferLocation(FRAMEBUFFER_LOCATION_FCRAM); | ||
| 40 | NOTICE_LOG(LCD, "initialized OK"); | 143 | NOTICE_LOG(LCD, "initialized OK"); |
| 41 | } | 144 | } |
| 42 | 145 | ||