summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGravatar bunnei2014-04-07 00:57:37 -0400
committerGravatar bunnei2014-04-07 00:57:37 -0400
commitf446f79da27d8c75b85772654152ea8e67a2214d (patch)
treecf3924876405ed5244fc8ee72c8615cc74e51267
parentRemove Core::GetState(). Use new ARM_Interface instead. (diff)
parentremoved unused comments, changed main processing loop to be infinite (diff)
downloadyuzu-f446f79da27d8c75b85772654152ea8e67a2214d.tar.gz
yuzu-f446f79da27d8c75b85772654152ea8e67a2214d.tar.xz
yuzu-f446f79da27d8c75b85772654152ea8e67a2214d.zip
Merge branch 'hardware-interface'
Conflicts: src/core/src/core.h
-rw-r--r--citra.sln13
-rw-r--r--src/citra/citra.vcxproj3
-rw-r--r--src/citra/src/citra.cpp36
-rw-r--r--src/citra/src/emu_window/emu_window_glfw.cpp4
-rw-r--r--src/citra/src/emu_window/emu_window_glfw.h5
-rw-r--r--src/common/src/common.h5
-rw-r--r--src/common/src/common_types.h133
-rw-r--r--src/common/src/emu_window.h2
-rw-r--r--src/common/src/log.h6
-rw-r--r--src/common/src/log_manager.cpp94
-rw-r--r--src/core/core.vcxproj4
-rw-r--r--src/core/core.vcxproj.filters15
-rw-r--r--src/core/src/arm/arm_interface.h49
-rw-r--r--src/core/src/arm/interpreter/arm_interpreter.cpp44
-rw-r--r--src/core/src/arm/interpreter/arm_interpreter.h7
-rw-r--r--src/core/src/core.cpp6
-rw-r--r--src/core/src/core.h3
-rw-r--r--src/core/src/hw/hw.cpp69
-rw-r--r--src/core/src/hw/hw.h44
-rw-r--r--src/core/src/hw/hw_lcd.cpp65
-rw-r--r--src/core/src/hw/hw_lcd.h64
-rw-r--r--src/core/src/mem_map_funcs.cpp54
-rw-r--r--src/core/src/system.cpp9
-rw-r--r--src/video_core/CMakeLists.txt19
-rw-r--r--src/video_core/src/renderer_base.h132
-rw-r--r--src/video_core/src/renderer_opengl/renderer_opengl.cpp461
-rw-r--r--src/video_core/src/renderer_opengl/renderer_opengl.h153
-rw-r--r--src/video_core/src/utils.cpp66
-rw-r--r--src/video_core/src/utils.h83
-rw-r--r--src/video_core/src/video_core.cpp88
-rw-r--r--src/video_core/src/video_core.h59
-rw-r--r--src/video_core/video_core.vcxproj131
-rw-r--r--src/video_core/video_core.vcxproj.filters26
-rw-r--r--vsprops/base.props2
34 files changed, 1786 insertions, 168 deletions
diff --git a/citra.sln b/citra.sln
index ebba4c2f0..af1f1ee55 100644
--- a/citra.sln
+++ b/citra.sln
@@ -1,5 +1,5 @@
1Microsoft Visual Studio Solution File, Format Version 12.00 1Microsoft Visual Studio Solution File, Format Version 12.00
2# Visual Studio Express 2013 for Windows Desktop 2# Visual Studio 2013
3VisualStudioVersion = 12.0.21005.1 3VisualStudioVersion = 12.0.21005.1
4MinimumVisualStudioVersion = 10.0.40219.1 4MinimumVisualStudioVersion = 10.0.40219.1
5Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "common", "src\common\common.vcxproj", "{DFE335FC-755D-4BAA-8452-94434F8A1EDB}" 5Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "common", "src\common\common.vcxproj", "{DFE335FC-755D-4BAA-8452-94434F8A1EDB}"
@@ -10,6 +10,7 @@ EndProject
10Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "citra", "src\citra\citra.vcxproj", "{CE7D2C07-21CE-4590-81AB-2ADA88A2B85F}" 10Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "citra", "src\citra\citra.vcxproj", "{CE7D2C07-21CE-4590-81AB-2ADA88A2B85F}"
11 ProjectSection(ProjectDependencies) = postProject 11 ProjectSection(ProjectDependencies) = postProject
12 {69F00340-5C3D-449F-9A80-958435C6CF06} = {69F00340-5C3D-449F-9A80-958435C6CF06} 12 {69F00340-5C3D-449F-9A80-958435C6CF06} = {69F00340-5C3D-449F-9A80-958435C6CF06}
13 {6678D1A3-33A6-48A9-878B-48E5D2903D27} = {6678D1A3-33A6-48A9-878B-48E5D2903D27}
13 EndProjectSection 14 EndProjectSection
14EndProject 15EndProject
15Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "core", "src\core\core.vcxproj", "{8AEA7F29-3466-4786-A10D-6A4BD0610977}" 16Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "core", "src\core\core.vcxproj", "{8AEA7F29-3466-4786-A10D-6A4BD0610977}"
@@ -21,6 +22,8 @@ Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "scm_rev_gen", "src\common\s
21EndProject 22EndProject
22Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "citra_qt", "src\citra_qt\citra_qt.vcxproj", "{A587F714-490F-407A-9E36-7AB7FA0D7BAB}" 23Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "citra_qt", "src\citra_qt\citra_qt.vcxproj", "{A587F714-490F-407A-9E36-7AB7FA0D7BAB}"
23EndProject 24EndProject
25Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "video_core", "src\video_core\video_core.vcxproj", "{6678D1A3-33A6-48A9-878B-48E5D2903D27}"
26EndProject
24Global 27Global
25 GlobalSection(SolutionConfigurationPlatforms) = preSolution 28 GlobalSection(SolutionConfigurationPlatforms) = preSolution
26 Debug|Win32 = Debug|Win32 29 Debug|Win32 = Debug|Win32
@@ -69,6 +72,14 @@ Global
69 {A587F714-490F-407A-9E36-7AB7FA0D7BAB}.Release|Win32.Build.0 = Release|Win32 72 {A587F714-490F-407A-9E36-7AB7FA0D7BAB}.Release|Win32.Build.0 = Release|Win32
70 {A587F714-490F-407A-9E36-7AB7FA0D7BAB}.Release|x64.ActiveCfg = Release|x64 73 {A587F714-490F-407A-9E36-7AB7FA0D7BAB}.Release|x64.ActiveCfg = Release|x64
71 {A587F714-490F-407A-9E36-7AB7FA0D7BAB}.Release|x64.Build.0 = Release|x64 74 {A587F714-490F-407A-9E36-7AB7FA0D7BAB}.Release|x64.Build.0 = Release|x64
75 {6678D1A3-33A6-48A9-878B-48E5D2903D27}.Debug|Win32.ActiveCfg = Debug|Win32
76 {6678D1A3-33A6-48A9-878B-48E5D2903D27}.Debug|Win32.Build.0 = Debug|Win32
77 {6678D1A3-33A6-48A9-878B-48E5D2903D27}.Debug|x64.ActiveCfg = Debug|x64
78 {6678D1A3-33A6-48A9-878B-48E5D2903D27}.Debug|x64.Build.0 = Debug|x64
79 {6678D1A3-33A6-48A9-878B-48E5D2903D27}.Release|Win32.ActiveCfg = Release|Win32
80 {6678D1A3-33A6-48A9-878B-48E5D2903D27}.Release|Win32.Build.0 = Release|Win32
81 {6678D1A3-33A6-48A9-878B-48E5D2903D27}.Release|x64.ActiveCfg = Release|x64
82 {6678D1A3-33A6-48A9-878B-48E5D2903D27}.Release|x64.Build.0 = Release|x64
72 EndGlobalSection 83 EndGlobalSection
73 GlobalSection(SolutionProperties) = preSolution 84 GlobalSection(SolutionProperties) = preSolution
74 HideSolutionNode = FALSE 85 HideSolutionNode = FALSE
diff --git a/src/citra/citra.vcxproj b/src/citra/citra.vcxproj
index 8f29e3e63..16157ad04 100644
--- a/src/citra/citra.vcxproj
+++ b/src/citra/citra.vcxproj
@@ -194,6 +194,9 @@
194 <LinkLibraryDependencies>true</LinkLibraryDependencies> 194 <LinkLibraryDependencies>true</LinkLibraryDependencies>
195 <UseLibraryDependencyInputs>false</UseLibraryDependencyInputs> 195 <UseLibraryDependencyInputs>false</UseLibraryDependencyInputs>
196 </ProjectReference> 196 </ProjectReference>
197 <ProjectReference Include="..\video_core\video_core.vcxproj">
198 <Project>{6678d1a3-33a6-48a9-878b-48e5d2903d27}</Project>
199 </ProjectReference>
197 </ItemGroup> 200 </ItemGroup>
198 <ItemGroup> 201 <ItemGroup>
199 <ClCompile Include="src\citra.cpp" /> 202 <ClCompile Include="src\citra.cpp" />
diff --git a/src/citra/src/citra.cpp b/src/citra/src/citra.cpp
index 26f5a74eb..746cf083d 100644
--- a/src/citra/src/citra.cpp
+++ b/src/citra/src/citra.cpp
@@ -52,39 +52,6 @@ int __cdecl main(int argc, char **argv) {
52 52
53 System::Init(emu_window); 53 System::Init(emu_window);
54 54
55 //if (E_OK != Core::Init(emu_window)) {
56 // LOG_ERROR(TMASTER, "core initialization failed, exiting...");
57 // core::Kill();
58 // exit(1);
59 //}
60
61 //// Load a game or die...
62 //if (E_OK == dvd::LoadBootableFile(common::g_config->default_boot_file())) {
63 // if (common::g_config->enable_auto_boot()) {
64 // core::Start();
65 // } else {
66 // LOG_ERROR(TMASTER, "Autoboot required in no-GUI mode... Exiting!\n");
67 // }
68 //} else {
69 // LOG_ERROR(TMASTER, "Failed to load a bootable file... Exiting!\n");
70 // exit(E_ERR);
71 //}
72 //// run the game
73 //while(core::SYS_DIE != core::g_state) {
74 // if (core::SYS_RUNNING == core::g_state) {
75 // if(!(cpu->is_on)) {
76 // cpu->Start(); // Initialize and start CPU.
77 // } else {
78 // for(tight_loop = 0; tight_loop < 10000; ++tight_loop) {
79 // cpu->execStep();
80 // }
81 // }
82 // } else if (core::SYS_HALTED == core::g_state) {
83 // core::Stop();
84 // }
85 //}
86 //core::Kill();
87
88 std::string boot_filename = "homebrew.elf"; 55 std::string boot_filename = "homebrew.elf";
89 std::string error_str; 56 std::string error_str;
90 57
@@ -93,7 +60,8 @@ int __cdecl main(int argc, char **argv) {
93 if (!res) { 60 if (!res) {
94 ERROR_LOG(BOOT, "Failed to load ROM: %s", error_str.c_str()); 61 ERROR_LOG(BOOT, "Failed to load ROM: %s", error_str.c_str());
95 } 62 }
96 for (int tight_loop = 0; tight_loop < 10000; ++tight_loop) { 63
64 for (;;) {
97 Core::SingleStep(); 65 Core::SingleStep();
98 } 66 }
99 67
diff --git a/src/citra/src/emu_window/emu_window_glfw.cpp b/src/citra/src/emu_window/emu_window_glfw.cpp
index 8edc745b7..4cdb7fbb0 100644
--- a/src/citra/src/emu_window/emu_window_glfw.cpp
+++ b/src/citra/src/emu_window/emu_window_glfw.cpp
@@ -23,6 +23,7 @@
23 */ 23 */
24 24
25#include "common.h" 25#include "common.h"
26#include "video_core.h"
26#include "emu_window_glfw.h" 27#include "emu_window_glfw.h"
27 28
28static void OnKeyEvent(GLFWwindow* win, int key, int action) { 29static void OnKeyEvent(GLFWwindow* win, int key, int action) {
@@ -54,7 +55,8 @@ EmuWindow_GLFW::EmuWindow_GLFW() {
54 } 55 }
55 glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3); 56 glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3);
56 glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 1); 57 glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 1);
57 render_window_ = glfwCreateWindow(640, 480, "citra", NULL, NULL); 58 render_window_ = glfwCreateWindow(VideoCore::kScreenTopWidth,
59 (VideoCore::kScreenTopHeight + VideoCore::kScreenBottomHeight), "citra", NULL, NULL);
58 60
59 // Setup callbacks 61 // Setup callbacks
60 glfwSetWindowUserPointer(render_window_, this); 62 glfwSetWindowUserPointer(render_window_, this);
diff --git a/src/citra/src/emu_window/emu_window_glfw.h b/src/citra/src/emu_window/emu_window_glfw.h
index 0339b5d68..abca9faa8 100644
--- a/src/citra/src/emu_window/emu_window_glfw.h
+++ b/src/citra/src/emu_window/emu_window_glfw.h
@@ -22,8 +22,7 @@
22 * http://code.google.com/p/gekko-gc-emu/ 22 * http://code.google.com/p/gekko-gc-emu/
23 */ 23 */
24 24
25#ifndef CITRA_EMUWINDOW_GLFW_ 25#pragma once
26#define CITRA_EMUWINDOW_GLFW_
27 26
28#include <GL/glew.h> 27#include <GL/glew.h>
29#include <GLFW/glfw3.h> 28#include <GLFW/glfw3.h>
@@ -52,5 +51,3 @@ public:
52private: 51private:
53 52
54}; 53};
55
56#endif // CITRA_EMUWINDOW_GLFW_
diff --git a/src/common/src/common.h b/src/common/src/common.h
index 1ca34e467..3b71d9b3d 100644
--- a/src/common/src/common.h
+++ b/src/common/src/common.h
@@ -163,4 +163,9 @@ enum EMUSTATE_CHANGE
163 EMUSTATE_CHANGE_STOP 163 EMUSTATE_CHANGE_STOP
164}; 164};
165 165
166// This should be used in the private: declarations for a class
167#define DISALLOW_COPY_AND_ASSIGN(TypeName) \
168 TypeName(const TypeName&); \
169 void operator=(const TypeName&)
170
166#endif // _COMMON_H_ 171#endif // _COMMON_H_
diff --git a/src/common/src/common_types.h b/src/common/src/common_types.h
index cbe556c7e..af1cd0e21 100644
--- a/src/common/src/common_types.h
+++ b/src/common/src/common_types.h
@@ -1,50 +1,125 @@
1// Copyright 2013 Dolphin Emulator Project 1/**
2// Licensed under GPLv2 2 * Copyright (C) 2005-2012 Gekko Emulator
3// Refer to the license.txt file included. 3 *
4 * @file common_types.h
5 * @author ShizZy <shizzy247@gmail.com>
6 * @date 2012-02-11
7 * @brief Common types used throughout the project
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 */
4 24
25#pragma once
5 26
6// This header contains type definitions that are shared between the Dolphin core and 27#include <math.h>
7// other parts of the code. Any definitions that are only used by the core should be 28#include <xmmintrin.h> // data_types__m128.cpp
8// placed in "common.h" instead.
9
10#ifndef _COMMONTYPES_H_
11#define _COMMONTYPES_H_
12 29
13#ifdef _WIN32 30#ifdef _WIN32
14 31
15#include <tchar.h> 32#include <tchar.h>
16 33
17typedef unsigned __int8 u8; 34typedef unsigned __int8 u8; ///< 8-bit unsigned byte
18typedef unsigned __int16 u16; 35typedef unsigned __int16 u16; ///< 16-bit unsigned short
19typedef unsigned __int32 u32; 36typedef unsigned __int32 u32; ///< 32-bit unsigned word
20typedef unsigned __int64 u64; 37typedef unsigned __int64 u64; ///< 64-bit unsigned int
21 38
22typedef signed __int8 s8; 39typedef signed __int8 s8; ///< 8-bit signed byte
23typedef signed __int16 s16; 40typedef signed __int16 s16; ///< 16-bit signed short
24typedef signed __int32 s32; 41typedef signed __int32 s32; ///< 32-bit signed word
25typedef signed __int64 s64; 42typedef signed __int64 s64; ///< 64-bit signed int
26 43
27#else 44#else
28 45
29#ifndef GEKKO 46typedef unsigned char u8; ///< 8-bit unsigned byte
30 47typedef unsigned short u16; ///< 16-bit unsigned short
31typedef unsigned char u8; 48typedef unsigned int u32; ///< 32-bit unsigned word
32typedef unsigned short u16; 49typedef unsigned long long u64; ///< 64-bit unsigned int
33typedef unsigned int u32;
34typedef unsigned long long u64;
35 50
36typedef signed char s8; 51typedef signed char s8; ///< 8-bit signed byte
37typedef signed short s16; 52typedef signed short s16; ///< 16-bit signed short
38typedef signed int s32; 53typedef signed int s32; ///< 32-bit signed word
39typedef signed long long s64; 54typedef signed long long s64; ///< 64-bit signed int
40 55
41#endif
42// For using windows lock code 56// For using windows lock code
43#define TCHAR char 57#define TCHAR char
44#define LONG int 58#define LONG int
45 59
46#endif // _WIN32 60#endif // _WIN32
47 61
62typedef float f32; ///< 32-bit floating point
63typedef double f64; ///< 64-bit floating point
64
48#include "swap.h" 65#include "swap.h"
49 66
50#endif // _COMMONTYPES_H_ 67/// Union for fast 16-bit type casting
68union t16 {
69 u8 _u8[2]; ///< 8-bit unsigned char(s)
70 u16 _u16; ///< 16-bit unsigned shorts(s)
71};
72
73/// Union for fast 32-bit type casting
74union t32 {
75 f32 _f32; ///< 32-bit floating point(s)
76 u32 _u32; ///< 32-bit unsigned int(s)
77 s32 _s32; ///< 32-bit signed int(s)
78 u16 _u16[2]; ///< 16-bit unsigned shorts(s)
79 u8 _u8[4]; ///< 8-bit unsigned char(s)
80};
81
82/// Union for fast 64-bit type casting
83union t64 {
84 f64 _f64; ///< 64-bit floating point
85 u64 _u64; ///< 64-bit unsigned long
86 f32 _f32[2]; ///< 32-bit floating point(s)
87 u32 _u32[2]; ///< 32-bit unsigned int(s)
88 s32 _s32[2]; ///< 32-bit signed int(s)
89 u16 _u16[4]; ///< 16-bit unsigned shorts(s)
90 u8 _u8[8]; ///< 8-bit unsigned char(s)
91};
92
93/// Union for fast 128-bit type casting
94union t128 {
95 struct
96 {
97 t64 ps0; ///< 64-bit paired single 0
98 t64 ps1; ///< 64-bit paired single 1
99 };
100 __m128 a; ///< 128-bit floating point (__m128 maps to the XMM[0-7] registers)
101};
102
103/// Rectangle data structure
104class Rect {
105public:
106 Rect(int x0=0, int y0=0, int x1=0, int y1=0) {
107 x0_ = x0;
108 y0_ = y0;
109 x1_ = x1;
110 y1_ = y1;
111 }
112 ~Rect() { }
113
114 int x0_; ///< Rect top left X-coordinate
115 int y0_; ///< Rect top left Y-coordinate
116 int x1_; ///< Rect bottom left X-coordinate
117 int y1_; ///< Rect bottom right Y-coordinate
118
119 inline u32 width() const { return abs(x1_ - x0_); }
120 inline u32 height() const { return abs(y1_ - y0_); }
121
122 inline bool operator == (const Rect& val) const {
123 return (x0_ == val.x0_ && y0_ == val.y0_ && x1_ == val.x1_ && y1_ == val.y1_);
124 }
125};
diff --git a/src/common/src/emu_window.h b/src/common/src/emu_window.h
index 66de75574..f49367057 100644
--- a/src/common/src/emu_window.h
+++ b/src/common/src/emu_window.h
@@ -81,7 +81,7 @@ public:
81protected: 81protected:
82 EmuWindow() : client_area_width_(640), client_area_height_(480) { 82 EmuWindow() : client_area_width_(640), client_area_height_(480) {
83 char window_title[255]; 83 char window_title[255];
84 sprintf(window_title, "emu [%s|%s] - %s", 84 sprintf(window_title, "citra [%s|%s] - %s",
85 "null-cpu", 85 "null-cpu",
86 "null-renderer", 86 "null-renderer",
87 __DATE__); 87 __DATE__);
diff --git a/src/common/src/log.h b/src/common/src/log.h
index 9b2da5016..432a307f0 100644
--- a/src/common/src/log.h
+++ b/src/common/src/log.h
@@ -57,9 +57,9 @@ enum LOG_TYPE {
57 WII_IPC_NET, 57 WII_IPC_NET,
58 WII_IPC_WC24, 58 WII_IPC_WC24,
59 WII_IPC_SSL, 59 WII_IPC_SSL,
60 WII_IPC_SD, 60 RENDER,
61 WII_IPC_STM, 61 LCD,
62 WII_IPC_WIIMOTE, 62 HW,
63 TIME, 63 TIME,
64 NETPLAY, 64 NETPLAY,
65 65
diff --git a/src/common/src/log_manager.cpp b/src/common/src/log_manager.cpp
index 8c8828e8c..b5b034846 100644
--- a/src/common/src/log_manager.cpp
+++ b/src/common/src/log_manager.cpp
@@ -29,53 +29,53 @@ LogManager *LogManager::m_logManager = NULL;
29LogManager::LogManager() 29LogManager::LogManager()
30{ 30{
31 // create log files 31 // create log files
32 m_Log[LogTypes::MASTER_LOG] = new LogContainer("*", "Master Log"); 32 m_Log[LogTypes::MASTER_LOG] = new LogContainer("*", "Master Log");
33 m_Log[LogTypes::BOOT] = new LogContainer("BOOT", "Boot"); 33 m_Log[LogTypes::BOOT] = new LogContainer("BOOT", "Boot");
34 m_Log[LogTypes::COMMON] = new LogContainer("COMMON", "Common"); 34 m_Log[LogTypes::COMMON] = new LogContainer("COMMON", "Common");
35 m_Log[LogTypes::DISCIO] = new LogContainer("DIO", "Disc IO"); 35 m_Log[LogTypes::DISCIO] = new LogContainer("DIO", "Disc IO");
36 m_Log[LogTypes::FILEMON] = new LogContainer("FileMon", "File Monitor"); 36 m_Log[LogTypes::FILEMON] = new LogContainer("FileMon", "File Monitor");
37 m_Log[LogTypes::PAD] = new LogContainer("PAD", "Pad"); 37 m_Log[LogTypes::PAD] = new LogContainer("PAD", "Pad");
38 m_Log[LogTypes::PIXELENGINE] = new LogContainer("PE", "PixelEngine"); 38 m_Log[LogTypes::PIXELENGINE] = new LogContainer("PE", "PixelEngine");
39 m_Log[LogTypes::COMMANDPROCESSOR] = new LogContainer("CP", "CommandProc"); 39 m_Log[LogTypes::COMMANDPROCESSOR] = new LogContainer("CP", "CommandProc");
40 m_Log[LogTypes::VIDEOINTERFACE] = new LogContainer("VI", "VideoInt"); 40 m_Log[LogTypes::VIDEOINTERFACE] = new LogContainer("VI", "VideoInt");
41 m_Log[LogTypes::SERIALINTERFACE] = new LogContainer("SI", "SerialInt"); 41 m_Log[LogTypes::SERIALINTERFACE] = new LogContainer("SI", "SerialInt");
42 m_Log[LogTypes::PROCESSORINTERFACE] = new LogContainer("PI", "ProcessorInt"); 42 m_Log[LogTypes::PROCESSORINTERFACE] = new LogContainer("PI", "ProcessorInt");
43 m_Log[LogTypes::MEMMAP] = new LogContainer("MI", "MI & memmap"); 43 m_Log[LogTypes::MEMMAP] = new LogContainer("MI", "MI & memmap");
44 m_Log[LogTypes::SP1] = new LogContainer("SP1", "Serial Port 1"); 44 m_Log[LogTypes::SP1] = new LogContainer("SP1", "Serial Port 1");
45 m_Log[LogTypes::STREAMINGINTERFACE] = new LogContainer("Stream", "StreamingInt"); 45 m_Log[LogTypes::STREAMINGINTERFACE] = new LogContainer("Stream", "StreamingInt");
46 m_Log[LogTypes::DSPINTERFACE] = new LogContainer("DSP", "DSPInterface"); 46 m_Log[LogTypes::DSPINTERFACE] = new LogContainer("DSP", "DSPInterface");
47 m_Log[LogTypes::DVDINTERFACE] = new LogContainer("DVD", "DVDInterface"); 47 m_Log[LogTypes::DVDINTERFACE] = new LogContainer("DVD", "DVDInterface");
48 m_Log[LogTypes::GPFIFO] = new LogContainer("GP", "GPFifo"); 48 m_Log[LogTypes::GPFIFO] = new LogContainer("GP", "GPFifo");
49 m_Log[LogTypes::EXPANSIONINTERFACE] = new LogContainer("EXI", "ExpansionInt"); 49 m_Log[LogTypes::EXPANSIONINTERFACE] = new LogContainer("EXI", "ExpansionInt");
50 m_Log[LogTypes::GDB_STUB] = new LogContainer("GDB_STUB", "GDB Stub"); 50 m_Log[LogTypes::GDB_STUB] = new LogContainer("GDB_STUB", "GDB Stub");
51 m_Log[LogTypes::AUDIO_INTERFACE] = new LogContainer("AI", "AudioInt"); 51 m_Log[LogTypes::AUDIO_INTERFACE] = new LogContainer("AI", "AudioInt");
52 m_Log[LogTypes::ARM11] = new LogContainer("ARM11", "ARM11"); 52 m_Log[LogTypes::ARM11] = new LogContainer("ARM11", "ARM11");
53 m_Log[LogTypes::OSHLE] = new LogContainer("HLE", "HLE"); 53 m_Log[LogTypes::OSHLE] = new LogContainer("HLE", "HLE");
54 m_Log[LogTypes::DSPHLE] = new LogContainer("DSPHLE", "DSP HLE"); 54 m_Log[LogTypes::DSPHLE] = new LogContainer("DSPHLE", "DSP HLE");
55 m_Log[LogTypes::DSPLLE] = new LogContainer("DSPLLE", "DSP LLE"); 55 m_Log[LogTypes::DSPLLE] = new LogContainer("DSPLLE", "DSP LLE");
56 m_Log[LogTypes::DSP_MAIL] = new LogContainer("DSPMails", "DSP Mails"); 56 m_Log[LogTypes::DSP_MAIL] = new LogContainer("DSPMails", "DSP Mails");
57 m_Log[LogTypes::VIDEO] = new LogContainer("Video", "Video Backend"); 57 m_Log[LogTypes::VIDEO] = new LogContainer("Video", "Video Backend");
58 m_Log[LogTypes::AUDIO] = new LogContainer("Audio", "Audio Emulator"); 58 m_Log[LogTypes::AUDIO] = new LogContainer("Audio", "Audio Emulator");
59 m_Log[LogTypes::DYNA_REC] = new LogContainer("JIT", "Dynamic Recompiler"); 59 m_Log[LogTypes::DYNA_REC] = new LogContainer("JIT", "JIT");
60 m_Log[LogTypes::CONSOLE] = new LogContainer("CONSOLE", "Dolphin Console"); 60 m_Log[LogTypes::CONSOLE] = new LogContainer("CONSOLE", "Dolphin Console");
61 m_Log[LogTypes::OSREPORT] = new LogContainer("OSREPORT", "OSReport"); 61 m_Log[LogTypes::OSREPORT] = new LogContainer("OSREPORT", "OSReport");
62 m_Log[LogTypes::TIME] = new LogContainer("Time", "Core Timing"); 62 m_Log[LogTypes::TIME] = new LogContainer("Time", "Core Timing");
63 m_Log[LogTypes::LOADER] = new LogContainer("Loader", "Loader"); 63 m_Log[LogTypes::LOADER] = new LogContainer("Loader", "Loader");
64 m_Log[LogTypes::FILESYS] = new LogContainer("FileSys", "File System"); 64 m_Log[LogTypes::FILESYS] = new LogContainer("FileSys", "File System");
65 m_Log[LogTypes::WII_IPC_HID] = new LogContainer("WII_IPC_HID", "WII IPC HID"); 65 m_Log[LogTypes::WII_IPC_HID] = new LogContainer("WII_IPC_HID", "WII IPC HID");
66 m_Log[LogTypes::WII_IPC_HLE] = new LogContainer("WII_IPC_HLE", "WII IPC HLE"); 66 m_Log[LogTypes::WII_IPC_HLE] = new LogContainer("WII_IPC_HLE", "WII IPC HLE");
67 m_Log[LogTypes::WII_IPC_DVD] = new LogContainer("WII_IPC_DVD", "WII IPC DVD"); 67 m_Log[LogTypes::WII_IPC_DVD] = new LogContainer("WII_IPC_DVD", "WII IPC DVD");
68 m_Log[LogTypes::WII_IPC_ES] = new LogContainer("WII_IPC_ES", "WII IPC ES"); 68 m_Log[LogTypes::WII_IPC_ES] = new LogContainer("WII_IPC_ES", "WII IPC ES");
69 m_Log[LogTypes::WII_IPC_FILEIO] = new LogContainer("WII_IPC_FILEIO","WII IPC FILEIO"); 69 m_Log[LogTypes::WII_IPC_FILEIO] = new LogContainer("WII_IPC_FILEIO", "WII IPC FILEIO");
70 m_Log[LogTypes::WII_IPC_SD] = new LogContainer("WII_IPC_SD", "WII IPC SD"); 70 m_Log[LogTypes::RENDER] = new LogContainer("RENDER", "RENDER");
71 m_Log[LogTypes::WII_IPC_STM] = new LogContainer("WII_IPC_STM", "WII IPC STM"); 71 m_Log[LogTypes::LCD] = new LogContainer("LCD", "LCD");
72 m_Log[LogTypes::WII_IPC_NET] = new LogContainer("WII_IPC_NET", "WII IPC NET"); 72 m_Log[LogTypes::WII_IPC_NET] = new LogContainer("WII_IPC_NET", "WII IPC NET");
73 m_Log[LogTypes::WII_IPC_WC24] = new LogContainer("WII_IPC_WC24", "WII IPC WC24"); 73 m_Log[LogTypes::WII_IPC_WC24] = new LogContainer("WII_IPC_WC24", "WII IPC WC24");
74 m_Log[LogTypes::WII_IPC_SSL] = new LogContainer("WII_IPC_SSL", "WII IPC SSL"); 74 m_Log[LogTypes::WII_IPC_SSL] = new LogContainer("WII_IPC_SSL", "WII IPC SSL");
75 m_Log[LogTypes::WII_IPC_WIIMOTE] = new LogContainer("WII_IPC_WIIMOTE","WII IPC WIIMOTE"); 75 m_Log[LogTypes::HW] = new LogContainer("HARDWARE", "HARDWARE");
76 m_Log[LogTypes::ACTIONREPLAY] = new LogContainer("ActionReplay", "ActionReplay"); 76 m_Log[LogTypes::ACTIONREPLAY] = new LogContainer("ActionReplay", "ActionReplay");
77 m_Log[LogTypes::MEMCARD_MANAGER] = new LogContainer("MemCard Manager", "MemCard Manager"); 77 m_Log[LogTypes::MEMCARD_MANAGER] = new LogContainer("MemCard Manager", "MemCard Manager");
78 m_Log[LogTypes::NETPLAY] = new LogContainer("NETPLAY", "Netplay"); 78 m_Log[LogTypes::NETPLAY] = new LogContainer("NETPLAY", "Netplay");
79 79
80 m_fileLog = new FileLogListener(File::GetUserPath(F_MAINLOG_IDX).c_str()); 80 m_fileLog = new FileLogListener(File::GetUserPath(F_MAINLOG_IDX).c_str());
81 m_consoleLog = new ConsoleListener(); 81 m_consoleLog = new ConsoleListener();
diff --git a/src/core/core.vcxproj b/src/core/core.vcxproj
index bee9f3046..2edb51214 100644
--- a/src/core/core.vcxproj
+++ b/src/core/core.vcxproj
@@ -152,6 +152,8 @@
152 <ClCompile Include="src\elf\elf_reader.cpp" /> 152 <ClCompile Include="src\elf\elf_reader.cpp" />
153 <ClCompile Include="src\file_sys\directory_file_system.cpp" /> 153 <ClCompile Include="src\file_sys\directory_file_system.cpp" />
154 <ClCompile Include="src\file_sys\meta_file_system.cpp" /> 154 <ClCompile Include="src\file_sys\meta_file_system.cpp" />
155 <ClCompile Include="src\hw\hw.cpp" />
156 <ClCompile Include="src\hw\hw_lcd.cpp" />
155 <ClCompile Include="src\loader.cpp" /> 157 <ClCompile Include="src\loader.cpp" />
156 <ClCompile Include="src\mem_map.cpp" /> 158 <ClCompile Include="src\mem_map.cpp" />
157 <ClCompile Include="src\mem_map_funcs.cpp" /> 159 <ClCompile Include="src\mem_map_funcs.cpp" />
@@ -180,6 +182,8 @@
180 <ClInclude Include="src\file_sys\directory_file_system.h" /> 182 <ClInclude Include="src\file_sys\directory_file_system.h" />
181 <ClInclude Include="src\file_sys\file_sys.h" /> 183 <ClInclude Include="src\file_sys\file_sys.h" />
182 <ClInclude Include="src\file_sys\meta_file_system.h" /> 184 <ClInclude Include="src\file_sys\meta_file_system.h" />
185 <ClInclude Include="src\hw\hw.h" />
186 <ClInclude Include="src\hw\hw_lcd.h" />
183 <ClInclude Include="src\loader.h" /> 187 <ClInclude Include="src\loader.h" />
184 <ClInclude Include="src\mem_map.h" /> 188 <ClInclude Include="src\mem_map.h" />
185 <ClInclude Include="src\system.h" /> 189 <ClInclude Include="src\system.h" />
diff --git a/src/core/core.vcxproj.filters b/src/core/core.vcxproj.filters
index 45ddf8cf6..0cd208dd6 100644
--- a/src/core/core.vcxproj.filters
+++ b/src/core/core.vcxproj.filters
@@ -46,6 +46,12 @@
46 <ClCompile Include="src\arm\interpreter\arm_interpreter.cpp"> 46 <ClCompile Include="src\arm\interpreter\arm_interpreter.cpp">
47 <Filter>arm\interpreter</Filter> 47 <Filter>arm\interpreter</Filter>
48 </ClCompile> 48 </ClCompile>
49 <ClCompile Include="src\hw\hw.cpp">
50 <Filter>hw</Filter>
51 </ClCompile>
52 <ClCompile Include="src\hw\hw_lcd.cpp">
53 <Filter>hw</Filter>
54 </ClCompile>
49 </ItemGroup> 55 </ItemGroup>
50 <ItemGroup> 56 <ItemGroup>
51 <Filter Include="arm"> 57 <Filter Include="arm">
@@ -69,6 +75,9 @@
69 <Filter Include="arm\interpreter"> 75 <Filter Include="arm\interpreter">
70 <UniqueIdentifier>{cca8b763-8a80-4478-9bcc-3c979293c357}</UniqueIdentifier> 76 <UniqueIdentifier>{cca8b763-8a80-4478-9bcc-3c979293c357}</UniqueIdentifier>
71 </Filter> 77 </Filter>
78 <Filter Include="hw">
79 <UniqueIdentifier>{d1158fc4-3e0f-431f-9d3b-f30bbfeb4ad5}</UniqueIdentifier>
80 </Filter>
72 </ItemGroup> 81 </ItemGroup>
73 <ItemGroup> 82 <ItemGroup>
74 <ClInclude Include="src\arm\disassembler\arm_disasm.h"> 83 <ClInclude Include="src\arm\disassembler\arm_disasm.h">
@@ -136,6 +145,12 @@
136 <ClInclude Include="src\arm\interpreter\arm_interpreter.h"> 145 <ClInclude Include="src\arm\interpreter\arm_interpreter.h">
137 <Filter>arm\interpreter</Filter> 146 <Filter>arm\interpreter</Filter>
138 </ClInclude> 147 </ClInclude>
148 <ClInclude Include="src\hw\hw.h">
149 <Filter>hw</Filter>
150 </ClInclude>
151 <ClInclude Include="src\hw\hw_lcd.h">
152 <Filter>hw</Filter>
153 </ClInclude>
139 </ItemGroup> 154 </ItemGroup>
140 <ItemGroup> 155 <ItemGroup>
141 <None Include="CMakeLists.txt" /> 156 <None Include="CMakeLists.txt" />
diff --git a/src/core/src/arm/arm_interface.h b/src/core/src/arm/arm_interface.h
index 785234396..daf35b51d 100644
--- a/src/core/src/arm/arm_interface.h
+++ b/src/core/src/arm/arm_interface.h
@@ -24,24 +24,65 @@
24 24
25#pragma once 25#pragma once
26 26
27#include "common.h"
27#include "common_types.h" 28#include "common_types.h"
28 29
29/// Generic ARM11 CPU interface 30/// Generic ARM11 CPU interface
30class ARM_Interface { 31class ARM_Interface {
31public: 32public:
32 ARM_Interface() { 33 ARM_Interface() {
34 num_instructions_ = 0;
33 } 35 }
34 36
35 ~ARM_Interface() { 37 ~ARM_Interface() {
36 } 38 }
37 39
38 virtual void ExecuteInstruction() = 0; 40 /// Step CPU by one instruction
39 41 void Step() {
40 virtual void SetPC(u32 pc) = 0; 42 ExecuteInstruction();
43 num_instructions_++;
44 }
45
46 /**
47 * Set the Program Counter to an address
48 * @param addr Address to set PC to
49 */
50 virtual void SetPC(u32 addr) = 0;
41 51
52 /*
53 * Get the current Program Counter
54 * @return Returns current PC
55 */
42 virtual u32 PC() = 0; 56 virtual u32 PC() = 0;
43 57
58 /**
59 * Get an ARM register
60 * @param index Register index (0-15)
61 * @return Returns the value in the register
62 */
44 virtual u32 Reg(int index) = 0; 63 virtual u32 Reg(int index) = 0;
45 64
46 virtual u32 CPSR() = 0; 65 /**
66 * Get the current CPSR register
67 * @return Returns the value of the CPSR register
68 */
69 virtual u32 CPSR() = 0;
70
71 /**
72 * Returns the number of clock ticks since the last rese
73 * @return Returns number of clock ticks
74 */
75 virtual u64 GetTicks() = 0;
76
77 /// Getter for num_instructions_
78 u64 num_instructions() { return num_instructions_; }
79
80private:
81
82 /// Execture next instruction
83 virtual void ExecuteInstruction() = 0;
84
85 u64 num_instructions_; ///< Number of instructions executed
86
87 DISALLOW_COPY_AND_ASSIGN(ARM_Interface);
47}; 88};
diff --git a/src/core/src/arm/interpreter/arm_interpreter.cpp b/src/core/src/arm/interpreter/arm_interpreter.cpp
index 930506963..a74aa26cc 100644
--- a/src/core/src/arm/interpreter/arm_interpreter.cpp
+++ b/src/core/src/arm/interpreter/arm_interpreter.cpp
@@ -1,26 +1,26 @@
1/** 1/**
2* Copyright (C) 2013 Citrus Emulator 2 * Copyright (C) 2013 Citrus Emulator
3* 3 *
4* @file arm_interpreter.h 4 * @file arm_interpreter.h
5* @author bunnei 5 * @author bunnei
6* @date 2014-04-04 6 * @date 2014-04-04
7* @brief ARM interface instance for SkyEye interprerer 7 * @brief ARM interface instance for SkyEye interprerer
8* 8 *
9* @section LICENSE 9 * @section LICENSE
10* This program is free software; you can redistribute it and/or 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 11 * modify it under the terms of the GNU General Public License as
12* published by the Free Software Foundation; either version 2 of 12 * published by the Free Software Foundation; either version 2 of
13* the License, or (at your option) any later version. 13 * the License, or (at your option) any later version.
14* 14 *
15* This program is distributed in the hope that it will be useful, but 15 * This program is distributed in the hope that it will be useful, but
16* WITHOUT ANY WARRANTY; without even the implied warranty of 16 * WITHOUT ANY WARRANTY; without even the implied warranty of
17* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18* General Public License for more details at 18 * General Public License for more details at
19* http://www.gnu.org/copyleft/gpl.html 19 * http://www.gnu.org/copyleft/gpl.html
20* 20 *
21* Official project repository can be found at: 21 * Official project repository can be found at:
22* http://code.google.com/p/gekko-gc-emu/ 22 * http://code.google.com/p/gekko-gc-emu/
23*/ 23 */
24 24
25#include "arm_interpreter.h" 25#include "arm_interpreter.h"
26 26
diff --git a/src/core/src/arm/interpreter/arm_interpreter.h b/src/core/src/arm/interpreter/arm_interpreter.h
index 89f871fa9..074149f1b 100644
--- a/src/core/src/arm/interpreter/arm_interpreter.h
+++ b/src/core/src/arm/interpreter/arm_interpreter.h
@@ -24,6 +24,7 @@
24 24
25#pragma once 25#pragma once
26 26
27#include "common.h"
27#include "common_types.h" 28#include "common_types.h"
28#include "arm/arm_interface.h" 29#include "arm/arm_interface.h"
29 30
@@ -45,6 +46,12 @@ public:
45 46
46 u32 CPSR(); 47 u32 CPSR();
47 48
49 u64 GetTicks() {
50 return ARMul_Time(state);
51 }
52
48private: 53private:
49 ARMul_State* state; 54 ARMul_State* state;
55
56 DISALLOW_COPY_AND_ASSIGN(ARM_Interpreter);
50}; 57};
diff --git a/src/core/src/core.cpp b/src/core/src/core.cpp
index 592805134..4261ff3ef 100644
--- a/src/core/src/core.cpp
+++ b/src/core/src/core.cpp
@@ -25,6 +25,7 @@
25#include "log.h" 25#include "log.h"
26#include "core.h" 26#include "core.h"
27#include "mem_map.h" 27#include "mem_map.h"
28#include "hw/hw.h"
28#include "arm/disassembler/arm_disasm.h" 29#include "arm/disassembler/arm_disasm.h"
29#include "arm/interpreter/arm_interpreter.h" 30#include "arm/interpreter/arm_interpreter.h"
30 31
@@ -41,7 +42,8 @@ void RunLoop() {
41 42
42/// Step the CPU one instruction 43/// Step the CPU one instruction
43void SingleStep() { 44void SingleStep() {
44 g_app_core->ExecuteInstruction(); 45 g_app_core->Step();
46 HW::Update();
45} 47}
46 48
47/// Halt the core 49/// Halt the core
@@ -69,6 +71,8 @@ void Shutdown() {
69 delete g_disasm; 71 delete g_disasm;
70 delete g_app_core; 72 delete g_app_core;
71 delete g_sys_core; 73 delete g_sys_core;
74
75 NOTICE_LOG(MASTER_LOG, "Core shutdown OK");
72} 76}
73 77
74} // namespace 78} // namespace
diff --git a/src/core/src/core.h b/src/core/src/core.h
index 2e7b355f2..a71e4ed8d 100644
--- a/src/core/src/core.h
+++ b/src/core/src/core.h
@@ -55,6 +55,9 @@ void Stop();
55/// Initialize the core 55/// Initialize the core
56int Init(); 56int Init();
57 57
58/// Shutdown the core
59void Shutdown();
60
58} // namespace 61} // namespace
59 62
60//////////////////////////////////////////////////////////////////////////////////////////////////// 63////////////////////////////////////////////////////////////////////////////////////////////////////
diff --git a/src/core/src/hw/hw.cpp b/src/core/src/hw/hw.cpp
new file mode 100644
index 000000000..50001c87a
--- /dev/null
+++ b/src/core/src/hw/hw.cpp
@@ -0,0 +1,69 @@
1/**
2 * Copyright (C) 2013 Citrus Emulator
3 *
4 * @file hw.cpp
5 * @author bunnei
6 * @date 2014-04-04
7 * @brief Hardware interface
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 "log.h"
26#include "hw/hw.h"
27#include "hw/hw_lcd.h"
28
29namespace HW {
30
31template <typename T>
32inline void Read(T &var, const u32 addr) {
33 NOTICE_LOG(HW, "Hardware read from address %08X", addr);
34}
35
36template <typename T>
37inline void Write(u32 addr, const T data) {
38 NOTICE_LOG(HW, "Hardware write to address %08X", addr);
39}
40
41// Explicitly instantiate template functions because we aren't defining this in the header:
42
43template void Read<u64>(u64 &var, const u32 addr);
44template void Read<u32>(u32 &var, const u32 addr);
45template void Read<u16>(u16 &var, const u32 addr);
46template void Read<u8>(u8 &var, const u32 addr);
47
48template void Write<const u64>(u32 addr, const u64 data);
49template void Write<const u32>(u32 addr, const u32 data);
50template void Write<const u16>(u32 addr, const u16 data);
51template void Write<const u8>(u32 addr, const u8 data);
52
53/// Update hardware
54void Update() {
55 LCD::Update();
56}
57
58/// Initialize hardware
59void Init() {
60 LCD::Init();
61 NOTICE_LOG(HW, "Hardware initialized OK");
62}
63
64/// Shutdown hardware
65void Shutdown() {
66 NOTICE_LOG(HW, "Hardware shutdown OK");
67}
68
69} \ No newline at end of file
diff --git a/src/core/src/hw/hw.h b/src/core/src/hw/hw.h
new file mode 100644
index 000000000..245822423
--- /dev/null
+++ b/src/core/src/hw/hw.h
@@ -0,0 +1,44 @@
1/**
2 * Copyright (C) 2013 Citrus Emulator
3 *
4 * @file hw.h
5 * @author bunnei
6 * @date 2014-04-04
7 * @brief Hardware interface
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_types.h"
26
27namespace HW {
28
29template <typename T>
30inline void Read(T &var, const u32 addr);
31
32template <typename T>
33inline void Write(u32 addr, const T data);
34
35/// Update hardware
36void Update();
37
38/// Initialize hardware
39void Init();
40
41/// Shutdown hardware
42void Shutdown();
43
44} // namespace
diff --git a/src/core/src/hw/hw_lcd.cpp b/src/core/src/hw/hw_lcd.cpp
new file mode 100644
index 000000000..ee806d5dc
--- /dev/null
+++ b/src/core/src/hw/hw_lcd.cpp
@@ -0,0 +1,65 @@
1/**
2 * Copyright (C) 2013 Citrus Emulator
3 *
4 * @file hw_lcd.cpp
5 * @author bunnei
6 * @date 2014-04-05
7 * @brief Hardware LCD interface
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 "log.h"
26#include "core.h"
27#include "hw_lcd.h"
28#include "video_core.h"
29
30namespace LCD {
31
32static const u32 kFrameTicks = 268123480 / 60; ///< 268MHz / 60 frames per second
33
34u64 g_last_ticks = 0; ///< Last CPU ticks
35
36template <typename T>
37inline void Read(T &var, const u32 addr) {
38}
39
40template <typename T>
41inline void Write(u32 addr, const T data) {
42}
43
44/// Update hardware
45void Update() {
46 u64 current_ticks = Core::g_app_core->GetTicks();
47
48 if ((current_ticks - g_last_ticks) >= kFrameTicks) {
49 g_last_ticks = current_ticks;
50 VideoCore::g_renderer->SwapBuffers();
51 }
52}
53
54/// Initialize hardware
55void Init() {
56 g_last_ticks = Core::g_app_core->GetTicks();
57 NOTICE_LOG(LCD, "LCD initialized OK");
58}
59
60/// Shutdown hardware
61void Shutdown() {
62 NOTICE_LOG(LCD, "LCD shutdown OK");
63}
64
65} // namespace
diff --git a/src/core/src/hw/hw_lcd.h b/src/core/src/hw/hw_lcd.h
new file mode 100644
index 000000000..fa19b1cd4
--- /dev/null
+++ b/src/core/src/hw/hw_lcd.h
@@ -0,0 +1,64 @@
1/**
2 * Copyright (C) 2013 Citrus Emulator
3 *
4 * @file hw_lcd.h
5 * @author bunnei
6 * @date 2014-04-05
7 * @brief Hardware LCD interface
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#pragma once
26
27#include "common_types.h"
28
29namespace LCD {
30
31enum {
32 TOP_ASPECT_X = 0x5,
33 TOP_ASPECT_Y = 0x3,
34
35 TOP_HEIGHT = 240,
36 TOP_WIDTH = 400,
37 BOTTOM_WIDTH = 320,
38
39 FRAMEBUFFER_SEL = 0x20184E59,
40 TOP_LEFT_FRAME1 = 0x20184E60,
41 TOP_LEFT_FRAME2 = 0x201CB370,
42 TOP_RIGHT_FRAME1 = 0x20282160,
43 TOP_RIGHT_FRAME2 = 0x202C8670,
44 SUB_FRAME1 = 0x202118E0,
45 SUB_FRAME2 = 0x20249CF0,
46};
47
48template <typename T>
49inline void Read(T &var, const u32 addr);
50
51template <typename T>
52inline void Write(u32 addr, const T data);
53
54/// Update hardware
55void Update();
56
57/// Initialize hardware
58void Init();
59
60/// Shutdown hardware
61void Shutdown();
62
63
64} // namespace
diff --git a/src/core/src/mem_map_funcs.cpp b/src/core/src/mem_map_funcs.cpp
index 18959dc70..ee2f79278 100644
--- a/src/core/src/mem_map_funcs.cpp
+++ b/src/core/src/mem_map_funcs.cpp
@@ -25,17 +25,23 @@
25#include "common.h" 25#include "common.h"
26 26
27#include "mem_map.h" 27#include "mem_map.h"
28#include "hw/hw.h"
28 29
29namespace Memory { 30namespace Memory {
30 31
31template <typename T> 32template <typename T>
32inline void ReadFromHardware(T &var, const u32 addr) { 33inline void _Read(T &var, const u32 addr) {
33 // TODO: Figure out the fastest order of tests for both read and write (they are probably different). 34 // TODO: Figure out the fastest order of tests for both read and write (they are probably different).
34 // TODO: Make sure this represents the mirrors in a correct way. 35 // TODO: Make sure this represents the mirrors in a correct way.
35
36 // Could just do a base-relative read, too.... TODO 36 // Could just do a base-relative read, too.... TODO
37 37
38 if ((addr & 0x3E000000) == 0x08000000) { 38 // Hardware I/O register reads
39 // 0x10XXXXXX- is physical address space, 0x1EXXXXXX is virtual address space
40 if ((addr & 0xFF000000) == 0x10000000 || (addr & 0xFF000000) == 0x1E000000) {
41 HW::Read<T>(var, addr);
42
43 // FCRAM virtual address reads
44 } else if ((addr & 0x3E000000) == 0x08000000) {
39 var = *((const T*)&g_fcram[addr & MEM_FCRAM_MASK]); 45 var = *((const T*)&g_fcram[addr & MEM_FCRAM_MASK]);
40 46
41 // Scratchpad memory 47 // Scratchpad memory
@@ -54,15 +60,20 @@ inline void ReadFromHardware(T &var, const u32 addr) {
54 var = *((const T*)&g_fcram[addr & MEM_FCRAM_MASK]); 60 var = *((const T*)&g_fcram[addr & MEM_FCRAM_MASK]);
55 61
56 } else { 62 } else {
57 _assert_msg_(MEMMAP, false, "unknown hardware read"); 63 _assert_msg_(MEMMAP, false, "unknown memory read");
58 // WARN_LOG(MEMMAP, "ReadFromHardware: Invalid addr %08x PC %08x LR %08x", addr, currentMIPS->pc, currentMIPS->r[MIPS_REG_RA]);
59 } 64 }
60} 65}
61 66
62template <typename T> 67template <typename T>
63inline void WriteToHardware(u32 addr, const T data) { 68inline void _Write(u32 addr, const T data) {
69
70 // Hardware I/O register writes
71 // 0x10XXXXXX- is physical address space, 0x1EXXXXXX is virtual address space
72 if ((addr & 0xFF000000) == 0x10000000 || (addr & 0xFF000000) == 0x1E000000) {
73 HW::Write<const T>(addr, data);
74
64 // ExeFS:/.code is loaded here: 75 // ExeFS:/.code is loaded here:
65 if ((addr & 0xFFF00000) == 0x00100000) { 76 } else if ((addr & 0xFFF00000) == 0x00100000) {
66 // TODO(ShizZy): This is dumb... handle correctly. From 3DBrew: 77 // TODO(ShizZy): This is dumb... handle correctly. From 3DBrew:
67 // http://3dbrew.org/wiki/Memory_layout#ARM11_User-land_memory_regions 78 // http://3dbrew.org/wiki/Memory_layout#ARM11_User-land_memory_regions
68 // The ExeFS:/.code is loaded here, executables must be loaded to the 0x00100000 region when 79 // The ExeFS:/.code is loaded here, executables must be loaded to the 0x00100000 region when
@@ -104,7 +115,7 @@ inline void WriteToHardware(u32 addr, const T data) {
104 115
105 // Error out... 116 // Error out...
106 } else { 117 } else {
107 _assert_msg_(MEMMAP, false, "unknown hardware write"); 118 _assert_msg_(MEMMAP, false, "unknown memory write");
108 } 119 }
109} 120}
110 121
@@ -126,14 +137,21 @@ u8 *GetPointer(const u32 addr) {
126 // TODO(bunnei): Just a stub for now... ImplementMe! 137 // TODO(bunnei): Just a stub for now... ImplementMe!
127 if ((addr & 0x3E000000) == 0x08000000) { 138 if ((addr & 0x3E000000) == 0x08000000) {
128 return g_fcram + (addr & MEM_FCRAM_MASK); 139 return g_fcram + (addr & MEM_FCRAM_MASK);
129 } 140
141 // HACK(bunnei): There is no layer yet to translate virtual addresses to physical addresses.
142 // Until we progress far enough along, we'll accept all physical address reads here. I think
143 // that this is typically a corner-case from usermode software unless they are trying to do
144 // bare-metal things (e.g. early 3DS homebrew writes directly to the FB @ 0x20184E60, etc.
145 } else if (((addr & 0xF0000000) == MEM_FCRAM_PADDR) && (addr < (MEM_FCRAM_PADDR_END))) {
146 return g_fcram + (addr & MEM_FCRAM_MASK);
147
130 //else if ((addr & 0x3F800000) == 0x04000000) { 148 //else if ((addr & 0x3F800000) == 0x04000000) {
131 // return g_vram + (addr & MEM_VRAM_MASK); 149 // return g_vram + (addr & MEM_VRAM_MASK);
132 //} 150 //}
133 //else if ((addr & 0x3F000000) >= 0x08000000 && (addr & 0x3F000000) < 0x08000000 + g_MemorySize) { 151 //else if ((addr & 0x3F000000) >= 0x08000000 && (addr & 0x3F000000) < 0x08000000 + g_MemorySize) {
134 // return m_pRAM + (addr & g_MemoryMask); 152 // return m_pRAM + (addr & g_MemoryMask);
135 //} 153 //}
136 else { 154 } else {
137 //ERROR_LOG(MEMMAP, "Unknown GetPointer %08x PC %08x LR %08x", addr, currentMIPS->pc, currentMIPS->r[MIPS_REG_RA]); 155 //ERROR_LOG(MEMMAP, "Unknown GetPointer %08x PC %08x LR %08x", addr, currentMIPS->pc, currentMIPS->r[MIPS_REG_RA]);
138 ERROR_LOG(MEMMAP, "Unknown GetPointer %08x", addr); 156 ERROR_LOG(MEMMAP, "Unknown GetPointer %08x", addr);
139 static bool reported = false; 157 static bool reported = false;
@@ -151,25 +169,25 @@ u8 *GetPointer(const u32 addr) {
151 169
152u8 Read8(const u32 addr) { 170u8 Read8(const u32 addr) {
153 u8 _var = 0; 171 u8 _var = 0;
154 ReadFromHardware<u8>(_var, addr); 172 _Read<u8>(_var, addr);
155 return (u8)_var; 173 return (u8)_var;
156} 174}
157 175
158u16 Read16(const u32 addr) { 176u16 Read16(const u32 addr) {
159 u16_le _var = 0; 177 u16_le _var = 0;
160 ReadFromHardware<u16_le>(_var, addr); 178 _Read<u16_le>(_var, addr);
161 return (u16)_var; 179 return (u16)_var;
162} 180}
163 181
164u32 Read32(const u32 addr) { 182u32 Read32(const u32 addr) {
165 u32_le _var = 0; 183 u32_le _var = 0;
166 ReadFromHardware<u32_le>(_var, addr); 184 _Read<u32_le>(_var, addr);
167 return _var; 185 return _var;
168} 186}
169 187
170u64 Read64(const u32 addr) { 188u64 Read64(const u32 addr) {
171 u64_le _var = 0; 189 u64_le _var = 0;
172 ReadFromHardware<u64_le>(_var, addr); 190 _Read<u64_le>(_var, addr);
173 return _var; 191 return _var;
174} 192}
175 193
@@ -182,19 +200,19 @@ u32 Read16_ZX(const u32 addr) {
182} 200}
183 201
184void Write8(const u32 addr, const u8 data) { 202void Write8(const u32 addr, const u8 data) {
185 WriteToHardware<u8>(addr, data); 203 _Write<u8>(addr, data);
186} 204}
187 205
188void Write16(const u32 addr, const u16 data) { 206void Write16(const u32 addr, const u16 data) {
189 WriteToHardware<u16_le>(addr, data); 207 _Write<u16_le>(addr, data);
190} 208}
191 209
192void Write32(const u32 addr, const u32 data) { 210void Write32(const u32 addr, const u32 data) {
193 WriteToHardware<u32_le>(addr, data); 211 _Write<u32_le>(addr, data);
194} 212}
195 213
196void Write64(const u32 addr, const u64 data) { 214void Write64(const u32 addr, const u64 data) {
197 WriteToHardware<u64_le>(addr, data); 215 _Write<u64_le>(addr, data);
198} 216}
199 217
200} // namespace 218} // namespace
diff --git a/src/core/src/system.cpp b/src/core/src/system.cpp
index 6a2c13c96..7c829d609 100644
--- a/src/core/src/system.cpp
+++ b/src/core/src/system.cpp
@@ -23,9 +23,11 @@
23*/ 23*/
24 24
25#include "core.h" 25#include "core.h"
26#include "hw/hw.h"
26#include "core_timing.h" 27#include "core_timing.h"
27#include "mem_map.h" 28#include "mem_map.h"
28#include "system.h" 29#include "system.h"
30#include "video_core.h"
29 31
30namespace System { 32namespace System {
31 33
@@ -38,7 +40,9 @@ void UpdateState(State state) {
38void Init(EmuWindow* emu_window) { 40void Init(EmuWindow* emu_window) {
39 Core::Init(); 41 Core::Init();
40 Memory::Init(); 42 Memory::Init();
43 HW::Init();
41 CoreTiming::Init(); 44 CoreTiming::Init();
45 VideoCore::Init(emu_window);
42} 46}
43 47
44void RunLoopFor(int cycles) { 48void RunLoopFor(int cycles) {
@@ -49,9 +53,10 @@ void RunLoopUntil(u64 global_cycles) {
49} 53}
50 54
51void Shutdown() { 55void Shutdown() {
56 Core::Shutdown();
57 HW::Shutdown();
58 VideoCore::Shutdown();
52 g_ctr_file_system.Shutdown(); 59 g_ctr_file_system.Shutdown();
53} 60}
54 61
55
56
57} // namespace 62} // namespace
diff --git a/src/video_core/CMakeLists.txt b/src/video_core/CMakeLists.txt
new file mode 100644
index 000000000..3f486b8fe
--- /dev/null
+++ b/src/video_core/CMakeLists.txt
@@ -0,0 +1,19 @@
1set(SRCS
2 src/bp_mem.cpp
3 src/cp_mem.cpp
4 src/xf_mem.cpp
5 src/fifo.cpp
6 src/fifo_player.cpp
7 src/vertex_loader.cpp
8 src/vertex_manager.cpp
9 src/video_core.cpp
10 src/shader_manager.cpp
11 src/texture_decoder.cpp
12 src/texture_manager.cpp
13 src/utils.cpp
14 src/renderer_gl3/renderer_gl3.cpp
15 src/renderer_gl3/shader_interface.cpp
16 src/renderer_gl3/texture_interface.cpp
17 src/renderer_gl3/uniform_manager.cpp)
18
19add_library(video_core STATIC ${SRCS})
diff --git a/src/video_core/src/renderer_base.h b/src/video_core/src/renderer_base.h
new file mode 100644
index 000000000..50f1475b2
--- /dev/null
+++ b/src/video_core/src/renderer_base.h
@@ -0,0 +1,132 @@
1/**
2 * Copyright (C) 2014 Citra Emulator
3 *
4 * @file renderer_base.h
5 * @author bunnei
6 * @date 2014-04-05
7 * @brief Renderer base class for new video core
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#pragma once
26
27#include "common.h"
28#include "hash.h"
29
30class RendererBase {
31public:
32
33 /// Used to reference a framebuffer
34 enum kFramebuffer {
35 kFramebuffer_VirtualXFB = 0,
36 kFramebuffer_EFB,
37 kFramebuffer_Texture
38 };
39
40 /// Used for referencing the render modes
41 enum kRenderMode {
42 kRenderMode_None = 0,
43 kRenderMode_Multipass = 1,
44 kRenderMode_ZComp = 2,
45 kRenderMode_UseDstAlpha = 4
46 };
47
48 RendererBase() : current_fps_(0), current_frame_(0) {
49 }
50
51 ~RendererBase() {
52 }
53
54 /// Swap buffers (render frame)
55 virtual void SwapBuffers() = 0;
56
57 /**
58 * Blits the EFB to the external framebuffer (XFB)
59 * @param src_rect Source rectangle in EFB to copy
60 * @param dst_rect Destination rectangle in EFB to copy to
61 * @param dest_height Destination height in pixels
62 */
63 virtual void CopyToXFB(const Rect& src_rect, const Rect& dst_rect) = 0;
64
65 /**
66 * Clear the screen
67 * @param rect Screen rectangle to clear
68 * @param enable_color Enable color clearing
69 * @param enable_alpha Enable alpha clearing
70 * @param enable_z Enable depth clearing
71 * @param color Clear color
72 * @param z Clear depth
73 */
74 virtual void Clear(const Rect& rect, bool enable_color, bool enable_alpha, bool enable_z,
75 u32 color, u32 z) = 0;
76
77 /// Sets the renderer viewport location, width, and height
78 virtual void SetViewport(int x, int y, int width, int height) = 0;
79
80 /// Sets the renderer depthrange, znear and zfar
81 virtual void SetDepthRange(double znear, double zfar) = 0;
82
83 /* Sets the scissor box
84 * @param rect Renderer rectangle to set scissor box to
85 */
86 virtual void SetScissorBox(const Rect& rect) = 0;
87
88 /**
89 * Sets the line and point size
90 * @param line_width Line width to use
91 * @param point_size Point size to use
92 */
93 virtual void SetLinePointSize(f32 line_width, f32 point_size) = 0;
94
95 /**
96 * Set a specific render mode
97 * @param flag Render flags mode to enable
98 */
99 virtual void SetMode(kRenderMode flags) = 0;
100
101 /// Reset the full renderer API to the NULL state
102 virtual void ResetRenderState() = 0;
103
104 /// Restore the full renderer API state - As the game set it
105 virtual void RestoreRenderState() = 0;
106
107 /**
108 * Set the emulator window to use for renderer
109 * @param window EmuWindow handle to emulator window to use for rendering
110 */
111 virtual void SetWindow(EmuWindow* window) = 0;
112
113 /// Initialize the renderer
114 virtual void Init() = 0;
115
116 /// Shutdown the renderer
117 virtual void ShutDown() = 0;
118
119 // Getter/setter functions:
120 // ------------------------
121
122 f32 current_fps() const { return current_fps_; }
123
124 int current_frame() const { return current_frame_; }
125
126protected:
127 f32 current_fps_; ///< Current framerate, should be set by the renderer
128 int current_frame_; ///< Current frame, should be set by the renderer
129
130private:
131 DISALLOW_COPY_AND_ASSIGN(RendererBase);
132};
diff --git a/src/video_core/src/renderer_opengl/renderer_opengl.cpp b/src/video_core/src/renderer_opengl/renderer_opengl.cpp
new file mode 100644
index 000000000..27917a5a2
--- /dev/null
+++ b/src/video_core/src/renderer_opengl/renderer_opengl.cpp
@@ -0,0 +1,461 @@
1/**
2 * Copyright (C) 2014 Citra Emulator
3 *
4 * @file renderer_opengl.cpp
5 * @author bunnei
6 * @date 2014-04-05
7 * @brief Renderer for OpenGL 3.x
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 "mem_map.h"
26#include "video_core.h"
27#include "renderer_opengl/renderer_opengl.h"
28
29/**
30 * Helper function to flip framebuffer from left-to-right to top-to-bottom
31 * @param addr Address of framebuffer in RAM
32 * @param out Pointer to output buffer with flipped framebuffer
33 * @todo Early on hack... I'd like to find a more efficient way of doing this /bunnei
34 */
35inline void _flip_framebuffer(u32 addr, u8* out) {
36 u8* in = Memory::GetPointer(addr);
37 for (int y = 0; y < VideoCore::kScreenTopHeight; y++) {
38 for (int x = 0; x < VideoCore::kScreenTopWidth; x++) {
39 int in_coord = (VideoCore::kScreenTopHeight * 3 * x) + (VideoCore::kScreenTopHeight * 3)
40 - (3 * y + 3);
41 int out_coord = (VideoCore::kScreenTopWidth * y * 3) + (x * 3);
42
43 out[out_coord + 0] = in[in_coord + 0];
44 out[out_coord + 1] = in[in_coord + 1];
45 out[out_coord + 2] = in[in_coord + 2];
46 }
47 }
48}
49
50/// RendererOpenGL constructor
51RendererOpenGL::RendererOpenGL() {
52 memset(fbo_, 0, sizeof(fbo_));
53 memset(fbo_rbo_, 0, sizeof(fbo_rbo_));
54 memset(fbo_depth_buffers_, 0, sizeof(fbo_depth_buffers_));
55
56 resolution_width_ = max(VideoCore::kScreenTopWidth, VideoCore::kScreenBottomWidth);
57 resolution_height_ = VideoCore::kScreenTopHeight + VideoCore::kScreenBottomHeight;
58
59 xfb_texture_top_ = 0;
60 xfb_texture_bottom_ = 0;
61
62 xfb_top_ = 0;
63 xfb_bottom_ = 0;
64}
65
66/// RendererOpenGL destructor
67RendererOpenGL::~RendererOpenGL() {
68}
69
70/// Swap buffers (render frame)
71void RendererOpenGL::SwapBuffers() {
72
73 ResetRenderState();
74
75 // EFB->XFB copy
76 // TODO(bunnei): This is a hack and does not belong here. The copy should be triggered by some
77 // register write We're also treating both framebuffers as a single one in OpenGL.
78 Rect framebuffer_size(0, 0, resolution_width_, resolution_height_);
79 RenderXFB(framebuffer_size, framebuffer_size);
80
81 // XFB->Window copy
82 RenderFramebuffer();
83
84 // Swap buffers
85 render_window_->PollEvents();
86 render_window_->SwapBuffers();
87
88 // Switch back to EFB and clear
89 glBindFramebuffer(GL_DRAW_FRAMEBUFFER, fbo_[kFramebuffer_EFB]);
90
91 RestoreRenderState();
92}
93
94/**
95 * Renders external framebuffer (XFB)
96 * @param src_rect Source rectangle in XFB to copy
97 * @param dst_rect Destination rectangle in output framebuffer to copy to
98 */
99void RendererOpenGL::RenderXFB(const Rect& src_rect, const Rect& dst_rect) {
100 static u8 xfb_top_flipped[VideoCore::kScreenTopWidth * VideoCore::kScreenTopWidth *3];
101 static u8 xfb_bottom_flipped[VideoCore::kScreenTopWidth * VideoCore::kScreenTopWidth *3];
102
103 _flip_framebuffer(0x20282160, xfb_top_flipped);
104 _flip_framebuffer(0x202118E0, xfb_bottom_flipped);
105
106 ResetRenderState();
107
108 // Blit the top framebuffer
109 // ------------------------
110
111 // Update textures with contents of XFB in RAM - top
112 glBindTexture(GL_TEXTURE_2D, xfb_texture_top_);
113 glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, VideoCore::kScreenTopWidth, VideoCore::kScreenTopHeight,
114 GL_RGB, GL_UNSIGNED_BYTE, xfb_top_flipped);
115 glBindTexture(GL_TEXTURE_2D, 0);
116
117 // Render target is destination framebuffer
118 glBindFramebuffer(GL_DRAW_FRAMEBUFFER, fbo_[kFramebuffer_VirtualXFB]);
119 glViewport(0, 0, VideoCore::kScreenTopWidth, VideoCore::kScreenTopHeight);
120
121 // Render source is our EFB
122 glBindFramebuffer(GL_READ_FRAMEBUFFER, xfb_top_);
123 glReadBuffer(GL_COLOR_ATTACHMENT0);
124
125 // Blit
126 glBlitFramebuffer(src_rect.x0_, src_rect.y0_, src_rect.x1_, src_rect.y1_,
127 dst_rect.x0_, dst_rect.y1_, dst_rect.x1_, dst_rect.y0_,
128 GL_COLOR_BUFFER_BIT, GL_LINEAR);
129
130 glBindFramebuffer(GL_READ_FRAMEBUFFER, 0);
131
132 // Blit the bottom framebuffer
133 // ---------------------------
134
135 // Update textures with contents of XFB in RAM - bottom
136 glBindTexture(GL_TEXTURE_2D, xfb_texture_bottom_);
137 glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, VideoCore::kScreenTopWidth, VideoCore::kScreenTopHeight,
138 GL_RGB, GL_UNSIGNED_BYTE, xfb_bottom_flipped);
139 glBindTexture(GL_TEXTURE_2D, 0);
140
141 // Render target is destination framebuffer
142 glBindFramebuffer(GL_DRAW_FRAMEBUFFER, fbo_[kFramebuffer_VirtualXFB]);
143 glViewport(0, 0,
144 VideoCore::kScreenBottomWidth, VideoCore::kScreenBottomHeight);
145
146 // Render source is our EFB
147 glBindFramebuffer(GL_READ_FRAMEBUFFER, xfb_bottom_);
148 glReadBuffer(GL_COLOR_ATTACHMENT0);
149
150 // Blit
151 int offset = (VideoCore::kScreenTopWidth - VideoCore::kScreenBottomWidth) / 2;
152 glBlitFramebuffer(0,0, VideoCore::kScreenBottomWidth, VideoCore::kScreenBottomHeight,
153 offset, VideoCore::kScreenBottomHeight, VideoCore::kScreenBottomWidth + offset, 0,
154 GL_COLOR_BUFFER_BIT, GL_LINEAR);
155
156 glBindFramebuffer(GL_READ_FRAMEBUFFER, 0);
157
158 RestoreRenderState();
159}
160
161/**
162 * Blits the EFB to the external framebuffer (XFB)
163 * @param src_rect Source rectangle in EFB to copy
164 * @param dst_rect Destination rectangle in EFB to copy to
165 */
166void RendererOpenGL::CopyToXFB(const Rect& src_rect, const Rect& dst_rect) {
167 ERROR_LOG(RENDER, "CopyToXFB not implemented! No EFB support yet!");
168 //ResetRenderState();
169
170 //// Render target is destination framebuffer
171 //glBindFramebuffer(GL_DRAW_FRAMEBUFFER, fbo_[kFramebuffer_VirtualXFB]);
172 //glViewport(0, 0, VideoCore::kScreenTopWidth, VideoCore::kScreenTopHeight);
173
174 //// Render source is our EFB
175 //glBindFramebuffer(GL_READ_FRAMEBUFFER, fbo_[kFramebuffer_EFB]);
176 //glReadBuffer(GL_COLOR_ATTACHMENT0);
177
178 //// Blit
179 //glBlitFramebuffer(src_rect.x0_, src_rect.y0_, src_rect.x1_, src_rect.y1_,
180 // dst_rect.x0_, dst_rect.y1_, dst_rect.x1_, dst_rect.y0_,
181 // GL_COLOR_BUFFER_BIT, GL_LINEAR);
182
183 //glBindFramebuffer(GL_READ_FRAMEBUFFER, 0);
184
185 //RestoreRenderState();
186}
187
188/**
189 * Clear the screen
190 * @param rect Screen rectangle to clear
191 * @param enable_color Enable color clearing
192 * @param enable_alpha Enable alpha clearing
193 * @param enable_z Enable depth clearing
194 * @param color Clear color
195 * @param z Clear depth
196 */
197void RendererOpenGL::Clear(const Rect& rect, bool enable_color, bool enable_alpha, bool enable_z,
198 u32 color, u32 z) {
199 GLboolean const color_mask = enable_color ? GL_TRUE : GL_FALSE;
200 GLboolean const alpha_mask = enable_alpha ? GL_TRUE : GL_FALSE;
201
202 ResetRenderState();
203
204 // Clear color
205 glColorMask(color_mask, color_mask, color_mask, alpha_mask);
206 glClearColor(float((color >> 16) & 0xFF) / 255.0f, float((color >> 8) & 0xFF) / 255.0f,
207 float((color >> 0) & 0xFF) / 255.0f, float((color >> 24) & 0xFF) / 255.0f);
208
209 // Clear depth
210 glDepthMask(enable_z ? GL_TRUE : GL_FALSE);
211 glClearDepth(float(z & 0xFFFFFF) / float(0xFFFFFF));
212
213 // Specify the rectangle of the EFB to clear
214 glEnable(GL_SCISSOR_TEST);
215 glScissor(rect.x0_, rect.y1_, rect.width(), rect.height());
216
217 // Clear it!
218 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
219
220 RestoreRenderState();
221}
222
223/// Sets the renderer viewport location, width, and height
224void RendererOpenGL::SetViewport(int x, int y, int width, int height) {
225 glViewport(x, y, width, height);
226}
227
228/// Sets the renderer depthrange, znear and zfar
229void RendererOpenGL::SetDepthRange(double znear, double zfar) {
230 glDepthRange(znear, zfar);
231}
232
233/* Sets the scissor box
234 * @param rect Renderer rectangle to set scissor box to
235 */
236void RendererOpenGL::SetScissorBox(const Rect& rect) {
237 glScissor(rect.x0_, rect.y1_, rect.width(), rect.height());
238}
239
240/**
241 * Sets the line and point size
242 * @param line_width Line width to use
243 * @param point_size Point size to use
244 */
245void RendererOpenGL::SetLinePointSize(f32 line_width, f32 point_size) {
246 glLineWidth((GLfloat)line_width);
247 glPointSize((GLfloat)point_size);
248}
249
250/**
251 * Set a specific render mode
252 * @param flag Render flags mode to enable
253 */
254void RendererOpenGL::SetMode(kRenderMode flags) {
255 if(flags & kRenderMode_ZComp) {
256 glColorMask(GL_FALSE, GL_FALSE, GL_FALSE, GL_FALSE);
257 }
258 if(flags & kRenderMode_Multipass) {
259 glEnable(GL_DEPTH_TEST);
260 glDepthMask(GL_FALSE);
261 glDepthFunc(GL_EQUAL);
262 }
263 if (flags & kRenderMode_UseDstAlpha) {
264 glColorMask(GL_FALSE, GL_FALSE, GL_FALSE, GL_TRUE);
265 glDisable(GL_BLEND);
266 }
267 last_mode_ |= flags;
268}
269
270/// Reset the full renderer API to the NULL state
271void RendererOpenGL::ResetRenderState() {
272 glDisable(GL_SCISSOR_TEST);
273 glDisable(GL_DEPTH_TEST);
274 glDisable(GL_CULL_FACE);
275 glDisable(GL_BLEND);
276 glDepthMask(GL_FALSE);
277 glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE);
278}
279
280/// Restore the full renderer API state - As the game set it
281void RendererOpenGL::RestoreRenderState() {
282
283 glBindFramebuffer(GL_DRAW_FRAMEBUFFER, fbo_[kFramebuffer_EFB]);
284
285 //gp::XF_UpdateViewport();
286 SetViewport(0, 0, resolution_width_, resolution_height_);
287 SetDepthRange(0.0f, 1.0f);
288
289 //SetGenerationMode();
290 glEnable(GL_CULL_FACE);
291 glFrontFace(GL_CCW);
292
293 //glEnable(GL_SCISSOR_TEST);
294 //gp::BP_SetScissorBox();
295 glDisable(GL_SCISSOR_TEST);
296
297 //SetColorMask(gp::g_bp_regs.cmode0);
298 glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE);
299
300 //SetDepthMode();
301 glDisable(GL_DEPTH_TEST);
302 glDepthMask(GL_FALSE);
303
304 //SetBlendMode(gp::g_bp_regs.cmode0, gp::g_bp_regs.cmode1, true);
305 //if (common::g_config->current_renderer_config().enable_wireframe) {
306 // glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
307 //} else {
308 // glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
309 //}
310}
311
312/// Initialize the FBO
313void RendererOpenGL::InitFramebuffer() {
314 // TODO(en): This should probably be implemented with the top screen and bottom screen as
315 // separate framebuffers
316
317 // Init the FBOs
318 // -------------
319
320 glGenFramebuffers(kMaxFramebuffers, fbo_); // Generate primary framebuffer
321 glGenRenderbuffers(kMaxFramebuffers, fbo_rbo_); // Generate primary RBOs
322 glGenRenderbuffers(kMaxFramebuffers, fbo_depth_buffers_); // Generate primary depth buffer
323
324 for (int i = 0; i < kMaxFramebuffers; i++) {
325 // Generate color buffer storage
326 glBindRenderbuffer(GL_RENDERBUFFER, fbo_rbo_[i]);
327 glRenderbufferStorage(GL_RENDERBUFFER, GL_RGBA8, VideoCore::kScreenTopWidth,
328 VideoCore::kScreenTopHeight + VideoCore::kScreenBottomHeight);
329
330 // Generate depth buffer storage
331 glBindRenderbuffer(GL_RENDERBUFFER, fbo_depth_buffers_[i]);
332 glRenderbufferStorage(GL_RENDERBUFFER, GL_DEPTH_COMPONENT32, VideoCore::kScreenTopWidth,
333 VideoCore::kScreenTopHeight + VideoCore::kScreenBottomHeight);
334
335 // Attach the buffers
336 glBindFramebuffer(GL_DRAW_FRAMEBUFFER, fbo_[i]);
337 glFramebufferRenderbuffer(GL_DRAW_FRAMEBUFFER, GL_DEPTH_ATTACHMENT,
338 GL_RENDERBUFFER, fbo_depth_buffers_[i]);
339 glFramebufferRenderbuffer(GL_DRAW_FRAMEBUFFER, GL_COLOR_ATTACHMENT0,
340 GL_RENDERBUFFER, fbo_rbo_[i]);
341
342 // Check for completeness
343 if (GL_FRAMEBUFFER_COMPLETE == glCheckFramebufferStatus(GL_DRAW_FRAMEBUFFER)) {
344 NOTICE_LOG(RENDER, "framebuffer(%d) initialized ok", i);
345 } else {
346 ERROR_LOG(RENDER, "couldn't create OpenGL frame buffer");
347 exit(1);
348 }
349 }
350 glBindFramebuffer(GL_FRAMEBUFFER, 0); // Unbind our frame buffer(s)
351
352 // Initialize framebuffer textures
353 // -------------------------------
354
355 // Create XFB textures
356 glGenTextures(1, &xfb_texture_top_);
357 glGenTextures(1, &xfb_texture_bottom_);
358
359 // Alocate video memorry for XFB textures
360 glBindTexture(GL_TEXTURE_2D, xfb_texture_top_);
361 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, VideoCore::kScreenTopWidth, VideoCore::kScreenTopHeight,
362 0, GL_RGB, GL_UNSIGNED_BYTE, NULL);
363 glBindTexture(GL_TEXTURE_2D, 0);
364
365 glBindTexture(GL_TEXTURE_2D, xfb_texture_bottom_);
366 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, VideoCore::kScreenTopWidth, VideoCore::kScreenTopHeight,
367 0, GL_RGB, GL_UNSIGNED_BYTE, NULL);
368 glBindTexture(GL_TEXTURE_2D, 0);
369
370 // Create the FBO and attach color/depth textures
371 glGenFramebuffers(1, &xfb_top_); // Generate framebuffer
372 glBindFramebuffer(GL_DRAW_FRAMEBUFFER, xfb_top_);
373 glFramebufferTexture2D(GL_DRAW_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D,
374 xfb_texture_top_, 0);
375 glBindFramebuffer(GL_FRAMEBUFFER, 0);
376
377 glGenFramebuffers(1, &xfb_bottom_); // Generate framebuffer
378 glBindFramebuffer(GL_DRAW_FRAMEBUFFER, xfb_bottom_);
379 glFramebufferTexture2D(GL_DRAW_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D,
380 xfb_texture_bottom_, 0);
381 glBindFramebuffer(GL_FRAMEBUFFER, 0);
382}
383
384/// Blit the FBO to the OpenGL default framebuffer
385void RendererOpenGL::RenderFramebuffer() {
386
387 // Render target is default framebuffer
388 glBindFramebuffer(GL_DRAW_FRAMEBUFFER, 0);
389 glViewport(0, 0, resolution_width_, resolution_height_);
390
391 // Render source is our XFB
392 glBindFramebuffer(GL_READ_FRAMEBUFFER, fbo_[kFramebuffer_VirtualXFB]);
393 glReadBuffer(GL_COLOR_ATTACHMENT0);
394
395 // Blit
396 glBlitFramebuffer(0, 0, resolution_width_, resolution_height_, 0, 0,
397 resolution_width_, resolution_height_, GL_COLOR_BUFFER_BIT, GL_LINEAR);
398
399 // Update the FPS count
400 UpdateFramerate();
401
402 // Rebind EFB
403 glBindFramebuffer(GL_DRAW_FRAMEBUFFER, fbo_[kFramebuffer_EFB]);
404
405 current_frame_++;
406}
407
408/// Updates the framerate
409void RendererOpenGL::UpdateFramerate() {
410}
411
412/**
413 * Set the emulator window to use for renderer
414 * @param window EmuWindow handle to emulator window to use for rendering
415 */
416void RendererOpenGL::SetWindow(EmuWindow* window) {
417 render_window_ = window;
418}
419
420/// Initialize the renderer
421void RendererOpenGL::Init() {
422 render_window_->MakeCurrent();
423 glShadeModel(GL_SMOOTH);
424
425
426 glStencilFunc(GL_ALWAYS, 0, 0);
427 glBlendFunc(GL_ONE, GL_ONE);
428
429 glViewport(0, 0, resolution_width_, resolution_height_);
430
431 glClearDepth(1.0f);
432 glEnable(GL_DEPTH_TEST);
433 glDisable(GL_LIGHTING);
434 glDepthFunc(GL_LEQUAL);
435
436 glPixelStorei(GL_UNPACK_ALIGNMENT, 4);
437
438 glDisable(GL_STENCIL_TEST);
439 glEnable(GL_SCISSOR_TEST);
440
441 glScissor(0, 0, resolution_width_, resolution_height_);
442 glClearDepth(1.0f);
443
444 GLenum err = glewInit();
445 if (GLEW_OK != err) {
446 ERROR_LOG(RENDER, " Failed to initialize GLEW! Error message: \"%s\". Exiting...",
447 glewGetErrorString(err));
448 exit(-1);
449 }
450
451 // Initialize everything else
452 // --------------------------
453
454 InitFramebuffer();
455
456 NOTICE_LOG(RENDER, "GL_VERSION: %s\n", glGetString(GL_VERSION));
457}
458
459/// Shutdown the renderer
460void RendererOpenGL::ShutDown() {
461}
diff --git a/src/video_core/src/renderer_opengl/renderer_opengl.h b/src/video_core/src/renderer_opengl/renderer_opengl.h
new file mode 100644
index 000000000..b84afc5d2
--- /dev/null
+++ b/src/video_core/src/renderer_opengl/renderer_opengl.h
@@ -0,0 +1,153 @@
1/**
2 * Copyright (C) 2014 Citra Emulator
3 *
4 * @file renderer_opengl.h
5 * @author bunnei
6 * @date 2014-04-05
7 * @brief Renderer for OpenGL 3.x
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#pragma once
26
27#include <GL/glew.h>
28
29
30#include "common.h"
31#include "emu_window.h"
32
33#include "renderer_base.h"
34
35
36class RendererOpenGL : virtual public RendererBase {
37public:
38
39 static const int kMaxFramebuffers = 2; ///< Maximum number of framebuffers
40
41 RendererOpenGL();
42 ~RendererOpenGL();
43
44 /// Swap buffers (render frame)
45 void SwapBuffers();
46
47 /**
48 * Renders external framebuffer (XFB)
49 * @param src_rect Source rectangle in XFB to copy
50 * @param dst_rect Destination rectangle in output framebuffer to copy to
51 */
52 void RenderXFB(const Rect& src_rect, const Rect& dst_rect);
53
54 /**
55 * Blits the EFB to the external framebuffer (XFB)
56 * @param src_rect Source rectangle in EFB to copy
57 * @param dst_rect Destination rectangle in EFB to copy to
58 */
59 void CopyToXFB(const Rect& src_rect, const Rect& dst_rect);
60
61 /**
62 * Clear the screen
63 * @param rect Screen rectangle to clear
64 * @param enable_color Enable color clearing
65 * @param enable_alpha Enable alpha clearing
66 * @param enable_z Enable depth clearing
67 * @param color Clear color
68 * @param z Clear depth
69 */
70 void Clear(const Rect& rect, bool enable_color, bool enable_alpha, bool enable_z,
71 u32 color, u32 z);
72
73 /// Sets the renderer viewport location, width, and height
74 void SetViewport(int x, int y, int width, int height);
75
76 /// Sets the renderer depthrange, znear and zfar
77 void SetDepthRange(double znear, double zfar);
78
79 /* Sets the scissor box
80 * @param rect Renderer rectangle to set scissor box to
81 */
82 void SetScissorBox(const Rect& rect);
83
84 /**
85 * Sets the line and point size
86 * @param line_width Line width to use
87 * @param point_size Point size to use
88 */
89 void SetLinePointSize(f32 line_width, f32 point_size);
90
91 /**
92 * Set a specific render mode
93 * @param flag Render flags mode to enable
94 */
95 void SetMode(kRenderMode flags);
96
97 /// Reset the full renderer API to the NULL state
98 void ResetRenderState();
99
100 /// Restore the full renderer API state - As the game set it
101 void RestoreRenderState();
102
103 /**
104 * Set the emulator window to use for renderer
105 * @param window EmuWindow handle to emulator window to use for rendering
106 */
107 void SetWindow(EmuWindow* window);
108
109 /// Initialize the renderer
110 void Init();
111
112 /// Shutdown the renderer
113 void ShutDown();
114
115 // Framebuffer object(s)
116 // ---------------------
117
118 GLuint fbo_[kMaxFramebuffers]; ///< Framebuffer objects
119
120private:
121
122 /// Initialize the FBO
123 void InitFramebuffer();
124
125 // Blit the FBO to the OpenGL default framebuffer
126 void RenderFramebuffer();
127
128 /// Updates the framerate
129 void UpdateFramerate();
130
131 EmuWindow* render_window_;
132 u32 last_mode_; ///< Last render mode
133
134 int resolution_width_;
135 int resolution_height_;
136
137 // Render buffers
138 // --------------
139
140 GLuint fbo_rbo_[kMaxFramebuffers]; ///< Render buffer objects
141 GLuint fbo_depth_buffers_[kMaxFramebuffers]; ///< Depth buffers objects
142
143 // External framebuffers
144 // ---------------------
145
146 GLuint xfb_texture_top_; ///< GL handle to top framebuffer texture
147 GLuint xfb_texture_bottom_; ///< GL handle to bottom framebuffer texture
148
149 GLuint xfb_top_;
150 GLuint xfb_bottom_;
151
152 DISALLOW_COPY_AND_ASSIGN(RendererOpenGL);
153}; \ No newline at end of file
diff --git a/src/video_core/src/utils.cpp b/src/video_core/src/utils.cpp
new file mode 100644
index 000000000..a5e702f67
--- /dev/null
+++ b/src/video_core/src/utils.cpp
@@ -0,0 +1,66 @@
1/**
2 * Copyright (C) 2005-2012 Gekko Emulator
3 *
4 * @file utils.cpp
5 * @author ShizZy <shizzy247@gmail.com>
6 * @date 2012-12-28
7 * @brief Utility functions (in general, not related to emulation) useful for video core
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 <stdio.h>
26#include <string.h>
27
28#include "utils.h"
29
30namespace VideoCore {
31
32/**
33 * Dumps a texture to TGA
34 * @param filename String filename to dump texture to
35 * @param width Width of texture in pixels
36 * @param height Height of texture in pixels
37 * @param raw_data Raw RGBA8 texture data to dump
38 * @todo This should be moved to some general purpose/common code
39 */
40void DumpTGA(std::string filename, int width, int height, u8* raw_data) {
41 TGAHeader hdr;
42 FILE* fout;
43 u8 r, g, b;
44
45 memset(&hdr, 0, sizeof(hdr));
46 hdr.datatypecode = 2; // uncompressed RGB
47 hdr.bitsperpixel = 24; // 24 bpp
48 hdr.width = width;
49 hdr.height = height;
50
51 fout = fopen(filename.c_str(), "wb");
52 fwrite(&hdr, sizeof(TGAHeader), 1, fout);
53 for (int i = 0; i < height; i++) {
54 for (int j = 0; j < width; j++) {
55 r = raw_data[(4 * (i * width)) + (4 * j) + 0];
56 g = raw_data[(4 * (i * width)) + (4 * j) + 1];
57 b = raw_data[(4 * (i * width)) + (4 * j) + 2];
58 putc(b, fout);
59 putc(g, fout);
60 putc(r, fout);
61 }
62 }
63 fclose(fout);
64}
65
66} // namespace
diff --git a/src/video_core/src/utils.h b/src/video_core/src/utils.h
new file mode 100644
index 000000000..2d7fa4a3a
--- /dev/null
+++ b/src/video_core/src/utils.h
@@ -0,0 +1,83 @@
1/**
2 * Copyright (C) 2005-2012 Gekko Emulator
3 *
4 * @file utils.h
5 * @author ShizZy <shizzy247@gmail.com>
6 * @date 2012-12-28
7 * @brief Utility functions (in general, not related to emulation) useful for video core
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#pragma once
26
27#include "common_types.h"
28#include <string>
29
30namespace FormatPrecision {
31
32/// Adjust RGBA8 color with RGBA6 precision
33static inline u32 rgba8_with_rgba6(u32 src) {
34 u32 color = src;
35 color &= 0xFCFCFCFC;
36 color |= (color >> 6) & 0x03030303;
37 return color;
38}
39
40/// Adjust RGBA8 color with RGB565 precision
41static inline u32 rgba8_with_rgb565(u32 src) {
42 u32 color = (src & 0xF8FCF8);
43 color |= (color >> 5) & 0x070007;
44 color |= (color >> 6) & 0x000300;
45 color |= 0xFF000000;
46 return color;
47}
48
49/// Adjust Z24 depth value with Z16 precision
50static inline u32 z24_with_z16(u32 src) {
51 return (src & 0xFFFF00) | (src >> 16);
52}
53
54} // namespace
55
56namespace VideoCore {
57
58/// Structure for the TGA texture format (for dumping)
59struct TGAHeader {
60 char idlength;
61 char colourmaptype;
62 char datatypecode;
63 short int colourmaporigin;
64 short int colourmaplength;
65 short int x_origin;
66 short int y_origin;
67 short width;
68 short height;
69 char bitsperpixel;
70 char imagedescriptor;
71};
72
73/**
74 * Dumps a texture to TGA
75 * @param filename String filename to dump texture to
76 * @param width Width of texture in pixels
77 * @param height Height of texture in pixels
78 * @param raw_data Raw RGBA8 texture data to dump
79 * @todo This should be moved to some general purpose/common code
80 */
81void DumpTGA(std::string filename, int width, int height, u8* raw_data);
82
83} // namespace
diff --git a/src/video_core/src/video_core.cpp b/src/video_core/src/video_core.cpp
new file mode 100644
index 000000000..52ff90488
--- /dev/null
+++ b/src/video_core/src/video_core.cpp
@@ -0,0 +1,88 @@
1/**
2 * Copyright (C) 2014 Citra Emulator
3 *
4 * @file video_core.cpp
5 * @author bunnei
6 * @date 2014-04-05
7 * @brief Main module for new video core
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#include "emu_window.h"
27#include "log.h"
28
29#include "core.h"
30
31#include "video_core.h"
32#include "renderer_base.h"
33#include "renderer_opengl/renderer_opengl.h"
34
35////////////////////////////////////////////////////////////////////////////////////////////////////
36// Video Core namespace
37
38namespace VideoCore {
39
40EmuWindow* g_emu_window = NULL; ///< Frontend emulator window
41RendererBase* g_renderer = NULL; ///< Renderer plugin
42int g_current_frame = 0;
43
44int VideoEntry(void*) {
45 if (g_emu_window == NULL) {
46 ERROR_LOG(VIDEO, "VideoCore::VideoEntry called without calling Init()!");
47 }
48 g_emu_window->MakeCurrent();
49 //for(;;) {
50 // gp::Fifo_DecodeCommand();
51 //}
52 return 0;
53}
54
55/// Start the video core
56void Start() {
57 if (g_emu_window == NULL) {
58 ERROR_LOG(VIDEO, "VideoCore::Start called without calling Init()!");
59 }
60 //if (common::g_config->enable_multicore()) {
61 // g_emu_window->DoneCurrent();
62 // g_video_thread = SDL_CreateThread(VideoEntry, NULL, NULL);
63 // if (g_video_thread == NULL) {
64 // LOG_ERROR(TVIDEO, "Unable to create thread: %s... Exiting\n", SDL_GetError());
65 // exit(1);
66 // }
67 //}
68}
69
70/// Initialize the video core
71void Init(EmuWindow* emu_window) {
72 g_emu_window = emu_window;
73 g_emu_window->MakeCurrent();
74 g_renderer = new RendererOpenGL();
75 g_renderer->SetWindow(g_emu_window);
76 g_renderer->Init();
77
78 g_current_frame = 0;
79
80 NOTICE_LOG(VIDEO, "initialized ok");
81}
82
83/// Shutdown the video core
84void Shutdown() {
85 delete g_renderer;
86}
87
88} // namespace
diff --git a/src/video_core/src/video_core.h b/src/video_core/src/video_core.h
new file mode 100644
index 000000000..10b8f1105
--- /dev/null
+++ b/src/video_core/src/video_core.h
@@ -0,0 +1,59 @@
1/*!
2 * Copyright (C) 2014 Citra Emulator
3 *
4 * @file video_core.h
5 * @author bunnei
6 * @date 2014-04-05
7 * @brief Main module for new video core
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#pragma once
26
27#include "common.h"
28#include "emu_window.h"
29#include "renderer_base.h"
30
31////////////////////////////////////////////////////////////////////////////////////////////////////
32// Video Core namespace
33
34namespace VideoCore {
35
36// 3DS Video Constants
37// -------------------
38
39static const int kScreenTopWidth = 400; ///< 3DS top screen width
40static const int kScreenTopHeight = 240; ///< 3DS top screen height
41static const int kScreenBottomWidth = 320; ///< 3DS bottom screen width
42static const int kScreenBottomHeight = 240; ///< 3DS bottom screen height
43
44// Video core renderer
45// ---------------------
46
47extern RendererBase* g_renderer; ///< Renderer plugin
48extern int g_current_frame; ///< Current frame
49
50/// Start the video core
51void Start();
52
53/// Initialize the video core
54void Init(EmuWindow* emu_window);
55
56/// Shutdown the video core
57void Shutdown();
58
59} // namespace
diff --git a/src/video_core/video_core.vcxproj b/src/video_core/video_core.vcxproj
new file mode 100644
index 000000000..5c56e9b71
--- /dev/null
+++ b/src/video_core/video_core.vcxproj
@@ -0,0 +1,131 @@
1<?xml version="1.0" encoding="utf-8"?>
2<Project DefaultTargets="Build" ToolsVersion="12.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
3 <ItemGroup Label="ProjectConfigurations">
4 <ProjectConfiguration Include="Debug|Win32">
5 <Configuration>Debug</Configuration>
6 <Platform>Win32</Platform>
7 </ProjectConfiguration>
8 <ProjectConfiguration Include="Debug|x64">
9 <Configuration>Debug</Configuration>
10 <Platform>x64</Platform>
11 </ProjectConfiguration>
12 <ProjectConfiguration Include="Release|Win32">
13 <Configuration>Release</Configuration>
14 <Platform>Win32</Platform>
15 </ProjectConfiguration>
16 <ProjectConfiguration Include="Release|x64">
17 <Configuration>Release</Configuration>
18 <Platform>x64</Platform>
19 </ProjectConfiguration>
20 </ItemGroup>
21 <ItemGroup>
22 <ClCompile Include="src\renderer_opengl\renderer_opengl.cpp" />
23 <ClCompile Include="src\utils.cpp" />
24 <ClCompile Include="src\video_core.cpp" />
25 </ItemGroup>
26 <ItemGroup>
27 <ClInclude Include="src\renderer_base.h" />
28 <ClInclude Include="src\renderer_opengl\renderer_opengl.h" />
29 <ClInclude Include="src\utils.h" />
30 <ClInclude Include="src\video_core.h" />
31 </ItemGroup>
32 <ItemGroup>
33 <Text Include="CMakeLists.txt" />
34 </ItemGroup>
35 <PropertyGroup Label="Globals">
36 <ProjectGuid>{6678D1A3-33A6-48A9-878B-48E5D2903D27}</ProjectGuid>
37 <RootNamespace>input_common</RootNamespace>
38 <ProjectName>video_core</ProjectName>
39 </PropertyGroup>
40 <Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
41 <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
42 <ConfigurationType>StaticLibrary</ConfigurationType>
43 <UseDebugLibraries>true</UseDebugLibraries>
44 <PlatformToolset>v120</PlatformToolset>
45 </PropertyGroup>
46 <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration">
47 <ConfigurationType>StaticLibrary</ConfigurationType>
48 <UseDebugLibraries>true</UseDebugLibraries>
49 <PlatformToolset>v120</PlatformToolset>
50 </PropertyGroup>
51 <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
52 <ConfigurationType>StaticLibrary</ConfigurationType>
53 <UseDebugLibraries>false</UseDebugLibraries>
54 <PlatformToolset>v120</PlatformToolset>
55 </PropertyGroup>
56 <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
57 <ConfigurationType>StaticLibrary</ConfigurationType>
58 <UseDebugLibraries>false</UseDebugLibraries>
59 <PlatformToolset>v120</PlatformToolset>
60 </PropertyGroup>
61 <Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
62 <ImportGroup Label="ExtensionSettings">
63 </ImportGroup>
64 <ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
65 <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
66 <Import Project="..\..\vsprops\Base.props" />
67 <Import Project="..\..\vsprops\code_generation_debug.props" />
68 <Import Project="..\..\vsprops\optimization_debug.props" />
69 <Import Project="..\..\vsprops\externals.props" />
70 </ImportGroup>
71 <ImportGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="PropertySheets">
72 <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
73 <Import Project="..\..\vsprops\Base.props" />
74 <Import Project="..\..\vsprops\code_generation_debug.props" />
75 <Import Project="..\..\vsprops\optimization_debug.props" />
76 <Import Project="..\..\vsprops\externals.props" />
77 </ImportGroup>
78 <ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
79 <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
80 <Import Project="..\..\vsprops\Base.props" />
81 <Import Project="..\..\vsprops\code_generation_release.props" />
82 <Import Project="..\..\vsprops\optimization_release.props" />
83 <Import Project="..\..\vsprops\externals.props" />
84 </ImportGroup>
85 <ImportGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="PropertySheets">
86 <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
87 <Import Project="..\..\vsprops\Base.props" />
88 <Import Project="..\..\vsprops\code_generation_release.props" />
89 <Import Project="..\..\vsprops\optimization_release.props" />
90 <Import Project="..\..\vsprops\externals.props" />
91 </ImportGroup>
92 <PropertyGroup Label="UserMacros" />
93 <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" />
94 <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" />
95 <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" />
96 <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" />
97 <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
98 <ClCompile />
99 <Link>
100 <GenerateDebugInformation>true</GenerateDebugInformation>
101 </Link>
102 </ItemDefinitionGroup>
103 <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
104 <ClCompile />
105 <Link>
106 <GenerateDebugInformation>true</GenerateDebugInformation>
107 </Link>
108 </ItemDefinitionGroup>
109 <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
110 <ClCompile />
111 <Link>
112 <GenerateDebugInformation>true</GenerateDebugInformation>
113 <EnableCOMDATFolding>true</EnableCOMDATFolding>
114 <OptimizeReferences>true</OptimizeReferences>
115 </Link>
116 <ClCompile />
117 <ClCompile />
118 <ClCompile />
119 </ItemDefinitionGroup>
120 <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
121 <ClCompile />
122 <Link>
123 <GenerateDebugInformation>true</GenerateDebugInformation>
124 <EnableCOMDATFolding>true</EnableCOMDATFolding>
125 <OptimizeReferences>true</OptimizeReferences>
126 </Link>
127 </ItemDefinitionGroup>
128 <Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
129 <ImportGroup Label="ExtensionTargets">
130 </ImportGroup>
131</Project> \ No newline at end of file
diff --git a/src/video_core/video_core.vcxproj.filters b/src/video_core/video_core.vcxproj.filters
new file mode 100644
index 000000000..e796fbe21
--- /dev/null
+++ b/src/video_core/video_core.vcxproj.filters
@@ -0,0 +1,26 @@
1<?xml version="1.0" encoding="utf-8"?>
2<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
3 <ItemGroup>
4 <ClCompile Include="src\video_core.cpp" />
5 <ClCompile Include="src\utils.cpp" />
6 <ClCompile Include="src\renderer_opengl\renderer_opengl.cpp">
7 <Filter>renderer_opengl</Filter>
8 </ClCompile>
9 </ItemGroup>
10 <ItemGroup>
11 <ClInclude Include="src\renderer_base.h" />
12 <ClInclude Include="src\video_core.h" />
13 <ClInclude Include="src\utils.h" />
14 <ClInclude Include="src\renderer_opengl\renderer_opengl.h">
15 <Filter>renderer_opengl</Filter>
16 </ClInclude>
17 </ItemGroup>
18 <ItemGroup>
19 <Text Include="CMakeLists.txt" />
20 </ItemGroup>
21 <ItemGroup>
22 <Filter Include="renderer_opengl">
23 <UniqueIdentifier>{e0245557-dbd4-423e-9399-513d5e99f1e4}</UniqueIdentifier>
24 </Filter>
25 </ItemGroup>
26</Project> \ No newline at end of file
diff --git a/vsprops/base.props b/vsprops/base.props
index 0f59b512b..6241bd44b 100644
--- a/vsprops/base.props
+++ b/vsprops/base.props
@@ -12,7 +12,7 @@
12 <StructMemberAlignment>16Bytes</StructMemberAlignment> 12 <StructMemberAlignment>16Bytes</StructMemberAlignment>
13 <FunctionLevelLinking>true</FunctionLevelLinking> 13 <FunctionLevelLinking>true</FunctionLevelLinking>
14 <MultiProcessorCompilation>true</MultiProcessorCompilation> 14 <MultiProcessorCompilation>true</MultiProcessorCompilation>
15 <AdditionalIncludeDirectories>$(SolutionDir)src\common\src;$(SolutionDir)src\core\src;$(SolutionDir)src\citra\src;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories> 15 <AdditionalIncludeDirectories>$(SolutionDir)src\common\src;$(SolutionDir)src\core\src;$(SolutionDir)src\video_core\src;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
16 <PreprocessorDefinitions> 16 <PreprocessorDefinitions>
17 </PreprocessorDefinitions> 17 </PreprocessorDefinitions>
18 <RuntimeTypeInfo>false</RuntimeTypeInfo> 18 <RuntimeTypeInfo>false</RuntimeTypeInfo>