summaryrefslogtreecommitdiffstats
path: root/src/core/hw/gpu.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/core/hw/gpu.cpp')
-rw-r--r--src/core/hw/gpu.cpp41
1 files changed, 23 insertions, 18 deletions
diff --git a/src/core/hw/gpu.cpp b/src/core/hw/gpu.cpp
index 8709b8eb7..3ad801c63 100644
--- a/src/core/hw/gpu.cpp
+++ b/src/core/hw/gpu.cpp
@@ -3,14 +3,13 @@
// Refer to the license.txt file included.
#include "common/common_types.h"
-#include "common/log.h"
+#include "core/settings.h"
#include "core/core.h"
#include "core/mem_map.h"
#include "core/hle/hle.h"
-#include "core/hle/kernel/thread.h"
-#include "core/hle/service/gsp.h"
+#include "core/hle/service/gsp_gpu.h"
#include "core/hw/gpu.h"
@@ -26,14 +25,17 @@ u32 g_cur_line = 0; ///< Current vertical screen line
u64 g_last_line_ticks = 0; ///< CPU tick count from last vertical screen line
u64 g_last_frame_ticks = 0; ///< CPU tick count from last frame
+static u32 kFrameCycles = 0; ///< 268MHz / 60 frames per second
+static u32 kFrameTicks = 0; ///< Approximate number of instructions/frame
+
template <typename T>
inline void Read(T &var, const u32 raw_addr) {
u32 addr = raw_addr - 0x1EF00000;
- int index = addr / 4;
+ u32 index = addr / 4;
// Reads other than u32 are untested, so I'd rather have them abort than silently fail
if (index >= Regs::NumIds() || !std::is_same<T,u32>::value) {
- ERROR_LOG(GPU, "unknown Read%d @ 0x%08X", sizeof(var) * 8, addr);
+ ERROR_LOG(GPU, "unknown Read%lu @ 0x%08X", sizeof(var) * 8, addr);
return;
}
@@ -43,15 +45,15 @@ inline void Read(T &var, const u32 raw_addr) {
template <typename T>
inline void Write(u32 addr, const T data) {
addr -= 0x1EF00000;
- int index = addr / 4;
+ u32 index = addr / 4;
// Writes other than u32 are untested, so I'd rather have them abort than silently fail
if (index >= Regs::NumIds() || !std::is_same<T,u32>::value) {
- ERROR_LOG(GPU, "unknown Write%d 0x%08X @ 0x%08X", sizeof(data) * 8, data, addr);
+ ERROR_LOG(GPU, "unknown Write%lu 0x%08X @ 0x%08X", sizeof(data) * 8, data, addr);
return;
}
- g_regs[index] = data;
+ g_regs[index] = static_cast<u32>(data);
switch (index) {
@@ -83,15 +85,15 @@ inline void Write(u32 addr, const T data) {
u8* source_pointer = Memory::GetPointer(Memory::PhysicalToVirtualAddress(config.GetPhysicalInputAddress()));
u8* dest_pointer = Memory::GetPointer(Memory::PhysicalToVirtualAddress(config.GetPhysicalOutputAddress()));
- for (int y = 0; y < config.output_height; ++y) {
+ for (u32 y = 0; y < config.output_height; ++y) {
// TODO: Why does the register seem to hold twice the framebuffer width?
- for (int x = 0; x < config.output_width; ++x) {
+ for (u32 x = 0; x < config.output_width; ++x) {
struct {
int r, g, b, a;
} source_color = { 0, 0, 0, 0 };
switch (config.input_format) {
- case Regs::FramebufferFormat::RGBA8:
+ case Regs::PixelFormat::RGBA8:
{
// TODO: Most likely got the component order messed up.
u8* srcptr = source_pointer + x * 4 + y * config.input_width * 4;
@@ -108,7 +110,7 @@ inline void Write(u32 addr, const T data) {
}
switch (config.output_format) {
- /*case Regs::FramebufferFormat::RGBA8:
+ /*case Regs::PixelFormat::RGBA8:
{
// TODO: Untested
u8* dstptr = (u32*)(dest_pointer + x * 4 + y * config.output_width * 4);
@@ -119,7 +121,7 @@ inline void Write(u32 addr, const T data) {
break;
}*/
- case Regs::FramebufferFormat::RGB8:
+ case Regs::PixelFormat::RGB8:
{
// TODO: Most likely got the component order messed up.
u8* dstptr = dest_pointer + x * 3 + y * config.output_width * 3;
@@ -136,10 +138,10 @@ inline void Write(u32 addr, const T data) {
}
}
- DEBUG_LOG(GPU, "DisplayTriggerTransfer: 0x%08x bytes from 0x%08x(%dx%d)-> 0x%08x(%dx%d), dst format %x",
+ DEBUG_LOG(GPU, "DisplayTriggerTransfer: 0x%08x bytes from 0x%08x(%ux%u)-> 0x%08x(%ux%u), dst format %x",
config.output_height * config.output_width * 4,
- config.GetPhysicalInputAddress(), (int)config.input_width, (int)config.input_height,
- config.GetPhysicalOutputAddress(), (int)config.output_width, (int)config.output_height,
+ config.GetPhysicalInputAddress(), config.input_width, config.input_height,
+ config.GetPhysicalOutputAddress(), config.output_width, config.output_height,
config.output_format.Value());
}
break;
@@ -216,6 +218,9 @@ void Update() {
/// Initialize hardware
void Init() {
+ kFrameCycles = 268123480 / Settings::values.gpu_refresh_rate;
+ kFrameTicks = kFrameCycles / 3;
+
g_cur_line = 0;
g_last_frame_ticks = g_last_line_ticks = Core::g_app_core->GetTicks();
@@ -238,13 +243,13 @@ void Init() {
framebuffer_top.width = 240;
framebuffer_top.height = 400;
framebuffer_top.stride = 3 * 240;
- framebuffer_top.color_format = Regs::FramebufferFormat::RGB8;
+ framebuffer_top.color_format = Regs::PixelFormat::RGB8;
framebuffer_top.active_fb = 0;
framebuffer_sub.width = 240;
framebuffer_sub.height = 320;
framebuffer_sub.stride = 3 * 240;
- framebuffer_sub.color_format = Regs::FramebufferFormat::RGB8;
+ framebuffer_sub.color_format = Regs::PixelFormat::RGB8;
framebuffer_sub.active_fb = 0;
NOTICE_LOG(GPU, "initialized OK");