diff options
| author | 2014-04-27 12:39:57 -0400 | |
|---|---|---|
| committer | 2014-04-27 12:39:57 -0400 | |
| commit | f0525a1eb4bc133f43c6dd10166965467a34dd45 (patch) | |
| tree | a9514ac3f3b062da41a170861991d8a5d57fd7af /src | |
| parent | - changed HW IO map to use virtual addresses (diff) | |
| download | yuzu-f0525a1eb4bc133f43c6dd10166965467a34dd45.tar.gz yuzu-f0525a1eb4bc133f43c6dd10166965467a34dd45.tar.xz yuzu-f0525a1eb4bc133f43c6dd10166965467a34dd45.zip | |
added code to LCD modules keep track of framebuffer location in FCRAM or VRAM
Diffstat (limited to 'src')
| -rw-r--r-- | src/core/hw/lcd.cpp | 91 | ||||
| -rw-r--r-- | src/core/hw/lcd.h | 77 |
2 files changed, 153 insertions, 15 deletions
diff --git a/src/core/hw/lcd.cpp b/src/core/hw/lcd.cpp index 822cd1647..6468053f2 100644 --- a/src/core/hw/lcd.cpp +++ b/src/core/hw/lcd.cpp | |||
| @@ -6,19 +6,107 @@ | |||
| 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) { |
| 21 | ERROR_LOG(LCD, "unknown Read%d @ 0x%08X", sizeof(var) * 8, 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 | |||
| 22 | } | 110 | } |
| 23 | 111 | ||
| 24 | template <typename T> | 112 | template <typename T> |
| @@ -51,6 +139,7 @@ void Update() { | |||
| 51 | /// Initialize hardware | 139 | /// Initialize hardware |
| 52 | void Init() { | 140 | void Init() { |
| 53 | g_last_ticks = Core::g_app_core->GetTicks(); | 141 | g_last_ticks = Core::g_app_core->GetTicks(); |
| 142 | SetFramebufferLocation(FRAMEBUFFER_LOCATION_FCRAM); | ||
| 54 | NOTICE_LOG(LCD, "initialized OK"); | 143 | NOTICE_LOG(LCD, "initialized OK"); |
| 55 | } | 144 | } |
| 56 | 145 | ||
diff --git a/src/core/hw/lcd.h b/src/core/hw/lcd.h index b047e7cea..2dd3b4adc 100644 --- a/src/core/hw/lcd.h +++ b/src/core/hw/lcd.h | |||
| @@ -8,6 +8,19 @@ | |||
| 8 | 8 | ||
| 9 | namespace LCD { | 9 | namespace LCD { |
| 10 | 10 | ||
| 11 | struct Registers { | ||
| 12 | u32 framebuffer_top_left_1; | ||
| 13 | u32 framebuffer_top_left_2; | ||
| 14 | u32 framebuffer_top_right_1; | ||
| 15 | u32 framebuffer_top_right_2; | ||
| 16 | u32 framebuffer_sub_left_1; | ||
| 17 | u32 framebuffer_sub_left_2; | ||
| 18 | u32 framebuffer_sub_right_1; | ||
| 19 | u32 framebuffer_sub_right_2; | ||
| 20 | }; | ||
| 21 | |||
| 22 | extern Registers g_regs; | ||
| 23 | |||
| 11 | enum { | 24 | enum { |
| 12 | TOP_ASPECT_X = 0x5, | 25 | TOP_ASPECT_X = 0x5, |
| 13 | TOP_ASPECT_Y = 0x3, | 26 | TOP_ASPECT_Y = 0x3, |
| @@ -17,24 +30,60 @@ enum { | |||
| 17 | BOTTOM_WIDTH = 320, | 30 | BOTTOM_WIDTH = 320, |
| 18 | 31 | ||
| 19 | // Physical addresses in FCRAM used by ARM9 applications - these are correct for real hardware | 32 | // Physical addresses in FCRAM used by ARM9 applications - these are correct for real hardware |
| 20 | FRAMEBUFFER_SEL = 0x20184E59, | 33 | PADDR_FRAMEBUFFER_SEL = 0x20184E59, |
| 21 | TOP_LEFT_FRAME1 = 0x20184E60, | 34 | PADDR_TOP_LEFT_FRAME1 = 0x20184E60, |
| 22 | TOP_LEFT_FRAME2 = 0x201CB370, | 35 | PADDR_TOP_LEFT_FRAME2 = 0x201CB370, |
| 23 | TOP_RIGHT_FRAME1 = 0x20282160, | 36 | PADDR_TOP_RIGHT_FRAME1 = 0x20282160, |
| 24 | TOP_RIGHT_FRAME2 = 0x202C8670, | 37 | PADDR_TOP_RIGHT_FRAME2 = 0x202C8670, |
| 25 | SUB_FRAME1 = 0x202118E0, | 38 | PADDR_SUB_FRAME1 = 0x202118E0, |
| 26 | SUB_FRAME2 = 0x20249CF0, | 39 | PADDR_SUB_FRAME2 = 0x20249CF0, |
| 27 | 40 | ||
| 28 | // Physical addresses in VRAM - I'm not sure how these are actually allocated (so not real) | 41 | // Physical addresses in VRAM - I'm not sure how these are actually allocated (so not real) |
| 29 | VRAM_FRAMEBUFFER_SEL = 0x18184E59, | 42 | PADDR_VRAM_FRAMEBUFFER_SEL = 0x18184E59, |
| 30 | VRAM_TOP_LEFT_FRAME1 = 0x18184E60, | 43 | PADDR_VRAM_TOP_LEFT_FRAME1 = 0x18184E60, |
| 31 | VRAM_TOP_LEFT_FRAME2 = 0x181CB370, | 44 | PADDR_VRAM_TOP_LEFT_FRAME2 = 0x181CB370, |
| 32 | VRAM_TOP_RIGHT_FRAME1 = 0x18282160, | 45 | PADDR_VRAM_TOP_RIGHT_FRAME1 = 0x18282160, |
| 33 | VRAM_TOP_RIGHT_FRAME2 = 0x182C8670, | 46 | PADDR_VRAM_TOP_RIGHT_FRAME2 = 0x182C8670, |
| 34 | VRAM_SUB_FRAME1 = 0x182118E0, | 47 | PADDR_VRAM_SUB_FRAME1 = 0x182118E0, |
| 35 | VRAM_SUB_FRAME2 = 0x18249CF0, | 48 | PADDR_VRAM_SUB_FRAME2 = 0x18249CF0, |
| 49 | }; | ||
| 50 | |||
| 51 | enum { | ||
| 52 | REG_FRAMEBUFFER_TOP_LEFT_1 = 0x1EF00468, // Main LCD, first framebuffer for 3D left | ||
| 53 | REG_FRAMEBUFFER_TOP_LEFT_2 = 0x1EF0046C, // Main LCD, second framebuffer for 3D left | ||
| 54 | REG_FRAMEBUFFER_TOP_RIGHT_1 = 0x1EF00494, // Main LCD, first framebuffer for 3D right | ||
| 55 | REG_FRAMEBUFFER_TOP_RIGHT_2 = 0x1EF00498, // Main LCD, second framebuffer for 3D right | ||
| 56 | REG_FRAMEBUFFER_SUB_LEFT_1 = 0x1EF00568, // Sub LCD, first framebuffer | ||
| 57 | REG_FRAMEBUFFER_SUB_LEFT_2 = 0x1EF0056C, // Sub LCD, second framebuffer | ||
| 58 | REG_FRAMEBUFFER_SUB_RIGHT_1 = 0x1EF00594, // Sub LCD, unused first framebuffer | ||
| 59 | REG_FRAMEBUFFER_SUB_RIGHT_2 = 0x1EF00598, // Sub LCD, unused second framebuffer | ||
| 36 | }; | 60 | }; |
| 37 | 61 | ||
| 62 | /// Framebuffer location | ||
| 63 | enum FramebufferLocation { | ||
| 64 | FRAMEBUFFER_LOCATION_UNKNOWN, ///< Framebuffer location is unknown | ||
| 65 | FRAMEBUFFER_LOCATION_FCRAM, ///< Framebuffer is in the GSP heap | ||
| 66 | FRAMEBUFFER_LOCATION_VRAM, ///< Framebuffer is in VRAM | ||
| 67 | }; | ||
| 68 | |||
| 69 | /** | ||
| 70 | * Sets whether the framebuffers are in the GSP heap (FCRAM) or VRAM | ||
| 71 | * @param | ||
| 72 | */ | ||
| 73 | void SetFramebufferLocation(const FramebufferLocation mode); | ||
| 74 | |||
| 75 | /** | ||
| 76 | * Gets a read-only pointer to a framebuffer in memory | ||
| 77 | * @param address Physical address of framebuffer | ||
| 78 | * @return Returns const pointer to raw framebuffer | ||
| 79 | */ | ||
| 80 | const u8* GetFramebufferPointer(const u32 address); | ||
| 81 | |||
| 82 | /** | ||
| 83 | * Gets the location of the framebuffers | ||
| 84 | */ | ||
| 85 | const FramebufferLocation GetFramebufferLocation(); | ||
| 86 | |||
| 38 | template <typename T> | 87 | template <typename T> |
| 39 | inline void Read(T &var, const u32 addr); | 88 | inline void Read(T &var, const u32 addr); |
| 40 | 89 | ||