From 590f294d8e66ee534e6ecb475a62b61e5a0dea84 Mon Sep 17 00:00:00 2001 From: bunnei Date: Fri, 4 Apr 2014 22:47:10 -0400 Subject: renamed some functions --- src/core/src/mem_map_funcs.cpp | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) (limited to 'src/core') diff --git a/src/core/src/mem_map_funcs.cpp b/src/core/src/mem_map_funcs.cpp index 18959dc70..446d3ac97 100644 --- a/src/core/src/mem_map_funcs.cpp +++ b/src/core/src/mem_map_funcs.cpp @@ -29,7 +29,7 @@ namespace Memory { template -inline void ReadFromHardware(T &var, const u32 addr) { +inline void _Read(T &var, const u32 addr) { // TODO: Figure out the fastest order of tests for both read and write (they are probably different). // TODO: Make sure this represents the mirrors in a correct way. @@ -55,12 +55,12 @@ inline void ReadFromHardware(T &var, const u32 addr) { } else { _assert_msg_(MEMMAP, false, "unknown hardware read"); - // WARN_LOG(MEMMAP, "ReadFromHardware: Invalid addr %08x PC %08x LR %08x", addr, currentMIPS->pc, currentMIPS->r[MIPS_REG_RA]); + // WARN_LOG(MEMMAP, "_Read: Invalid addr %08x PC %08x LR %08x", addr, currentMIPS->pc, currentMIPS->r[MIPS_REG_RA]); } } template -inline void WriteToHardware(u32 addr, const T data) { +inline void _Write(u32 addr, const T data) { // ExeFS:/.code is loaded here: if ((addr & 0xFFF00000) == 0x00100000) { // TODO(ShizZy): This is dumb... handle correctly. From 3DBrew: @@ -151,25 +151,25 @@ u8 *GetPointer(const u32 addr) { u8 Read8(const u32 addr) { u8 _var = 0; - ReadFromHardware(_var, addr); + _Read(_var, addr); return (u8)_var; } u16 Read16(const u32 addr) { u16_le _var = 0; - ReadFromHardware(_var, addr); + _Read(_var, addr); return (u16)_var; } u32 Read32(const u32 addr) { u32_le _var = 0; - ReadFromHardware(_var, addr); + _Read(_var, addr); return _var; } u64 Read64(const u32 addr) { u64_le _var = 0; - ReadFromHardware(_var, addr); + _Read(_var, addr); return _var; } @@ -182,19 +182,19 @@ u32 Read16_ZX(const u32 addr) { } void Write8(const u32 addr, const u8 data) { - WriteToHardware(addr, data); + _Write(addr, data); } void Write16(const u32 addr, const u16 data) { - WriteToHardware(addr, data); + _Write(addr, data); } void Write32(const u32 addr, const u32 data) { - WriteToHardware(addr, data); + _Write(addr, data); } void Write64(const u32 addr, const u64 data) { - WriteToHardware(addr, data); + _Write(addr, data); } } // namespace -- cgit v1.2.3 From 670ac5643a7cda55b7c5d68c99495ade0d14e6e4 Mon Sep 17 00:00:00 2001 From: bunnei Date: Fri, 4 Apr 2014 23:02:59 -0400 Subject: added hw module to interface h/w register reads/writes --- src/core/core.vcxproj | 2 ++ src/core/core.vcxproj.filters | 9 ++++++ src/core/src/hw/hw.cpp | 70 ++++++++++++++++++++++++++++++++++++++++++ src/core/src/hw/hw.h | 35 +++++++++++++++++++++ src/core/src/mem_map_funcs.cpp | 5 ++- 5 files changed, 118 insertions(+), 3 deletions(-) create mode 100644 src/core/src/hw/hw.cpp create mode 100644 src/core/src/hw/hw.h (limited to 'src/core') diff --git a/src/core/core.vcxproj b/src/core/core.vcxproj index bee9f3046..eb1272b23 100644 --- a/src/core/core.vcxproj +++ b/src/core/core.vcxproj @@ -152,6 +152,7 @@ + @@ -180,6 +181,7 @@ + diff --git a/src/core/core.vcxproj.filters b/src/core/core.vcxproj.filters index 45ddf8cf6..f3237ed05 100644 --- a/src/core/core.vcxproj.filters +++ b/src/core/core.vcxproj.filters @@ -46,6 +46,9 @@ arm\interpreter + + hw + @@ -69,6 +72,9 @@ {cca8b763-8a80-4478-9bcc-3c979293c357} + + {d1158fc4-3e0f-431f-9d3b-f30bbfeb4ad5} + @@ -136,6 +142,9 @@ arm\interpreter + + hw + diff --git a/src/core/src/hw/hw.cpp b/src/core/src/hw/hw.cpp new file mode 100644 index 000000000..7250bc237 --- /dev/null +++ b/src/core/src/hw/hw.cpp @@ -0,0 +1,70 @@ +/** + * Copyright (C) 2013 Citrus Emulator + * + * @file hw.cpp + * @author bunnei + * @date 2014-04-04 + * @brief Hardware interface + * + * @section LICENSE + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License as + * published by the Free Software Foundation; either version 2 of + * the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details at + * http://www.gnu.org/copyleft/gpl.html + * + * Official project repository can be found at: + * http://code.google.com/p/gekko-gc-emu/ + */ + +#include "log.h" +#include "hw/hw.h" + +namespace HW { + +template +inline void Read(T &var, const u32 addr) { + // TODO: Figure out the fastest order of tests for both read and write (they are probably different). + // TODO: Make sure this represents the mirrors in a correct way. + + // Could just do a base-relative read, too.... TODO + + //if ((addr & 0x3E000000) == 0x08000000) { + // var = *((const T*)&g_fcram[addr & MEM_FCRAM_MASK]); + + //} else { + // _assert_msg_(HW, false, "unknown hardware read"); + //} +} + +template +inline void Write(u32 addr, const T data) { + //// ExeFS:/.code is loaded here: + //if ((addr & 0xFFF00000) == 0x00100000) { + // // TODO(ShizZy): This is dumb... handle correctly. From 3DBrew: + // // http://3dbrew.org/wiki/Memory_layout#ARM11_User-land_memory_regions + // // The ExeFS:/.code is loaded here, executables must be loaded to the 0x00100000 region when + // // the exheader "special memory" flag is clear. The 0x03F00000-byte size restriction only + // // applies when this flag is clear. Executables are usually loaded to 0x14000000 when the + // // exheader "special memory" flag is set, however this address can be arbitrary. + // *(T*)&g_fcram[addr & MEM_FCRAM_MASK] = data; + + //// Error out... + //} else { + // _assert_msg_(HW, false, "unknown hardware write"); + //} +} + + +void Init() { +} + +void Shutdown() { +} + +} \ 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..dacad4924 --- /dev/null +++ b/src/core/src/hw/hw.h @@ -0,0 +1,35 @@ +/** + * Copyright (C) 2013 Citrus Emulator + * + * @file hw.h + * @author bunnei + * @date 2014-04-04 + * @brief Hardware interface + * + * @section LICENSE + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License as + * published by the Free Software Foundation; either version 2 of + * the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details at + * http://www.gnu.org/copyleft/gpl.html + * + * Official project repository can be found at: + * http://code.google.com/p/gekko-gc-emu/ + */ + +#include "common_types.h" + +namespace HW { + +template +inline void Read(T &var, const u32 addr); + +template +inline void Write(u32 addr, const T data); + +} // namespace diff --git a/src/core/src/mem_map_funcs.cpp b/src/core/src/mem_map_funcs.cpp index 446d3ac97..b000571e5 100644 --- a/src/core/src/mem_map_funcs.cpp +++ b/src/core/src/mem_map_funcs.cpp @@ -54,8 +54,7 @@ inline void _Read(T &var, const u32 addr) { var = *((const T*)&g_fcram[addr & MEM_FCRAM_MASK]); } else { - _assert_msg_(MEMMAP, false, "unknown hardware read"); - // WARN_LOG(MEMMAP, "_Read: Invalid addr %08x PC %08x LR %08x", addr, currentMIPS->pc, currentMIPS->r[MIPS_REG_RA]); + _assert_msg_(MEMMAP, false, "unknown memory read"); } } @@ -104,7 +103,7 @@ inline void _Write(u32 addr, const T data) { // Error out... } else { - _assert_msg_(MEMMAP, false, "unknown hardware write"); + _assert_msg_(MEMMAP, false, "unknown memory write"); } } -- cgit v1.2.3 From 31abc42d3dd8ea6ba23b14afa276bae684d694ef Mon Sep 17 00:00:00 2001 From: bunnei Date: Sat, 5 Apr 2014 00:01:07 -0400 Subject: added initial support for hw.cpp module --- src/core/core.vcxproj | 2 +- src/core/core.vcxproj.filters | 2 +- src/core/src/arm/interpreter/arm_interpreter.cpp | 44 ++++++++++++------------ src/core/src/core.h | 3 ++ src/core/src/hw/hw.cpp | 42 +++++++++------------- src/core/src/hw/hw.h | 6 ++++ src/core/src/mem_map_funcs.cpp | 18 ++++++++-- src/core/src/system.cpp | 4 +++ 8 files changed, 69 insertions(+), 52 deletions(-) (limited to 'src/core') diff --git a/src/core/core.vcxproj b/src/core/core.vcxproj index eb1272b23..60ce2427d 100644 --- a/src/core/core.vcxproj +++ b/src/core/core.vcxproj @@ -152,7 +152,7 @@ - + diff --git a/src/core/core.vcxproj.filters b/src/core/core.vcxproj.filters index f3237ed05..7b47f5cbf 100644 --- a/src/core/core.vcxproj.filters +++ b/src/core/core.vcxproj.filters @@ -46,7 +46,7 @@ arm\interpreter - + hw 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 @@ /** -* Copyright (C) 2013 Citrus Emulator -* -* @file arm_interpreter.h -* @author bunnei -* @date 2014-04-04 -* @brief ARM interface instance for SkyEye interprerer -* -* @section LICENSE -* This program is free software; you can redistribute it and/or -* modify it under the terms of the GNU General Public License as -* published by the Free Software Foundation; either version 2 of -* the License, or (at your option) any later version. -* -* This program is distributed in the hope that it will be useful, but -* WITHOUT ANY WARRANTY; without even the implied warranty of -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -* General Public License for more details at -* http://www.gnu.org/copyleft/gpl.html -* -* Official project repository can be found at: -* http://code.google.com/p/gekko-gc-emu/ -*/ + * Copyright (C) 2013 Citrus Emulator + * + * @file arm_interpreter.h + * @author bunnei + * @date 2014-04-04 + * @brief ARM interface instance for SkyEye interprerer + * + * @section LICENSE + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License as + * published by the Free Software Foundation; either version 2 of + * the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details at + * http://www.gnu.org/copyleft/gpl.html + * + * Official project repository can be found at: + * http://code.google.com/p/gekko-gc-emu/ + */ #include "arm_interpreter.h" diff --git a/src/core/src/core.h b/src/core/src/core.h index f41daca6a..a7d96e4a4 100644 --- a/src/core/src/core.h +++ b/src/core/src/core.h @@ -55,6 +55,9 @@ void Stop(); /// Initialize the core int Init(); +/// Shutdown the core +void Shutdown(); + ARMul_State* GetState(); } // namespace diff --git a/src/core/src/hw/hw.cpp b/src/core/src/hw/hw.cpp index 7250bc237..3e4f2c435 100644 --- a/src/core/src/hw/hw.cpp +++ b/src/core/src/hw/hw.cpp @@ -29,42 +29,34 @@ namespace HW { template inline void Read(T &var, const u32 addr) { - // TODO: Figure out the fastest order of tests for both read and write (they are probably different). - // TODO: Make sure this represents the mirrors in a correct way. - - // Could just do a base-relative read, too.... TODO - - //if ((addr & 0x3E000000) == 0x08000000) { - // var = *((const T*)&g_fcram[addr & MEM_FCRAM_MASK]); - - //} else { - // _assert_msg_(HW, false, "unknown hardware read"); - //} + NOTICE_LOG(HW, "Hardware read from address %08X", addr); } template inline void Write(u32 addr, const T data) { - //// ExeFS:/.code is loaded here: - //if ((addr & 0xFFF00000) == 0x00100000) { - // // TODO(ShizZy): This is dumb... handle correctly. From 3DBrew: - // // http://3dbrew.org/wiki/Memory_layout#ARM11_User-land_memory_regions - // // The ExeFS:/.code is loaded here, executables must be loaded to the 0x00100000 region when - // // the exheader "special memory" flag is clear. The 0x03F00000-byte size restriction only - // // applies when this flag is clear. Executables are usually loaded to 0x14000000 when the - // // exheader "special memory" flag is set, however this address can be arbitrary. - // *(T*)&g_fcram[addr & MEM_FCRAM_MASK] = data; - - //// Error out... - //} else { - // _assert_msg_(HW, false, "unknown hardware write"); - //} + NOTICE_LOG(HW, "Hardware write to address %08X", addr); } +// Explicitly instantiate template functions because we aren't defining this in the header: + +template void Read(u64 &var, const u32 addr); +template void Read(u32 &var, const u32 addr); +template void Read(u16 &var, const u32 addr); +template void Read(u8 &var, const u32 addr); + +template void Write(u32 addr, const u64 data); +template void Write(u32 addr, const u32 data); +template void Write(u32 addr, const u16 data); +template void Write(u32 addr, const u8 data); +/// Initialize hardware void Init() { + NOTICE_LOG(HW, "Hardware initialized OK"); } +/// Shutdown hardware void Shutdown() { + NOTICE_LOG(HW, "Hardware shutdown OK"); } } \ No newline at end of file diff --git a/src/core/src/hw/hw.h b/src/core/src/hw/hw.h index dacad4924..c69d6525f 100644 --- a/src/core/src/hw/hw.h +++ b/src/core/src/hw/hw.h @@ -32,4 +32,10 @@ inline void Read(T &var, const u32 addr); template inline void Write(u32 addr, const T data); +/// Initialize hardware +void Init(); + +/// Shutdown hardware +void Shutdown(); + } // namespace diff --git a/src/core/src/mem_map_funcs.cpp b/src/core/src/mem_map_funcs.cpp index b000571e5..dc4c2381d 100644 --- a/src/core/src/mem_map_funcs.cpp +++ b/src/core/src/mem_map_funcs.cpp @@ -25,6 +25,7 @@ #include "common.h" #include "mem_map.h" +#include "hw/hw.h" namespace Memory { @@ -32,10 +33,15 @@ template inline void _Read(T &var, const u32 addr) { // TODO: Figure out the fastest order of tests for both read and write (they are probably different). // TODO: Make sure this represents the mirrors in a correct way. - // Could just do a base-relative read, too.... TODO - if ((addr & 0x3E000000) == 0x08000000) { + // Hardware I/O register reads + // 0x10XXXXXX- is physical address space, 0x1EXXXXXX is virtual address space + if ((addr & 0xFF000000) == 0x10000000 || (addr & 0xFF000000) == 0x1E000000) { + HW::Read(var, addr); + + // FCRAM virtual address reads + } else if ((addr & 0x3E000000) == 0x08000000) { var = *((const T*)&g_fcram[addr & MEM_FCRAM_MASK]); // Scratchpad memory @@ -60,8 +66,14 @@ inline void _Read(T &var, const u32 addr) { template inline void _Write(u32 addr, const T data) { + + // Hardware I/O register writes + // 0x10XXXXXX- is physical address space, 0x1EXXXXXX is virtual address space + if ((addr & 0xFF000000) == 0x10000000 || (addr & 0xFF000000) == 0x1E000000) { + HW::Write(addr, data); + // ExeFS:/.code is loaded here: - if ((addr & 0xFFF00000) == 0x00100000) { + } else if ((addr & 0xFFF00000) == 0x00100000) { // TODO(ShizZy): This is dumb... handle correctly. From 3DBrew: // http://3dbrew.org/wiki/Memory_layout#ARM11_User-land_memory_regions // The ExeFS:/.code is loaded here, executables must be loaded to the 0x00100000 region when diff --git a/src/core/src/system.cpp b/src/core/src/system.cpp index 6a2c13c96..1477bab32 100644 --- a/src/core/src/system.cpp +++ b/src/core/src/system.cpp @@ -23,6 +23,7 @@ */ #include "core.h" +#include "hw/hw.h" #include "core_timing.h" #include "mem_map.h" #include "system.h" @@ -38,6 +39,7 @@ void UpdateState(State state) { void Init(EmuWindow* emu_window) { Core::Init(); Memory::Init(); + HW::Init(); CoreTiming::Init(); } @@ -49,6 +51,8 @@ void RunLoopUntil(u64 global_cycles) { } void Shutdown() { + Core::Shutdown(); + HW::Shutdown(); g_ctr_file_system.Shutdown(); } -- cgit v1.2.3 From c1dfa75845b32d622f145879a9deed4c3e45b754 Mon Sep 17 00:00:00 2001 From: bunnei Date: Sat, 5 Apr 2014 01:23:28 -0400 Subject: added a tick counter --- src/core/src/arm/arm_interface.h | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) (limited to 'src/core') diff --git a/src/core/src/arm/arm_interface.h b/src/core/src/arm/arm_interface.h index 785234396..80518a779 100644 --- a/src/core/src/arm/arm_interface.h +++ b/src/core/src/arm/arm_interface.h @@ -35,13 +35,21 @@ public: ~ARM_Interface() { } - virtual void ExecuteInstruction() = 0; + void Step() { + ExecuteInstruction(); + ticks_++; + } virtual void SetPC(u32 pc) = 0; - virtual u32 PC() = 0; - virtual u32 Reg(int index) = 0; + virtual u32 CPSR() = 0; + + u64 ticks() { return ticks_; } + +private: + + virtual void ExecuteInstruction() = 0; - virtual u32 CPSR() = 0; + u64 ticks_; }; -- cgit v1.2.3 From 9c2355ba4f37585cd0054b3f05251a814ccbc0eb Mon Sep 17 00:00:00 2001 From: bunnei Date: Sat, 5 Apr 2014 01:23:51 -0400 Subject: added a module for interfacing to hardware LCD --- src/core/src/hw/hw_lcd.cpp | 65 ++++++++++++++++++++++++++++++++++++++++++++++ src/core/src/hw/hw_lcd.h | 64 +++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 129 insertions(+) create mode 100644 src/core/src/hw/hw_lcd.cpp create mode 100644 src/core/src/hw/hw_lcd.h (limited to 'src/core') diff --git a/src/core/src/hw/hw_lcd.cpp b/src/core/src/hw/hw_lcd.cpp new file mode 100644 index 000000000..19e3b4ab4 --- /dev/null +++ b/src/core/src/hw/hw_lcd.cpp @@ -0,0 +1,65 @@ +/** + * Copyright (C) 2013 Citrus Emulator + * + * @file hw_lcd.cpp + * @author bunnei + * @date 2014-04-05 + * @brief Hardware LCD interface + * + * @section LICENSE + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License as + * published by the Free Software Foundation; either version 2 of + * the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details at + * http://www.gnu.org/copyleft/gpl.html + * + * Official project repository can be found at: + * http://code.google.com/p/gekko-gc-emu/ + */ + +#include "log.h" +#include "core.h" +#include "hw_lcd.h" + +namespace LCD { + +static const u32 kFrameTicks = 268123480 / 30; // 268MHz / 30 frames per second + +u64 g_last_ticks = 0; ///< Last CPU ticks + +template +inline void Read(T &var, const u32 addr) { +} + +template +inline void Write(u32 addr, const T data) { +} + +/// Update hardware +void Update() { + u64 current_ticks = Core::g_app_core->ticks(); + + if ((current_ticks - g_last_ticks) >= kFrameTicks) { + g_last_ticks = current_ticks; + NOTICE_LOG(LCD, "Update frame"); + } +} + +/// Initialize hardware +void Init() { + g_last_ticks = Core::g_app_core->ticks(); + + NOTICE_LOG(LCD, "LCD initialized OK"); +} + +/// Shutdown hardware +void Shutdown() { + NOTICE_LOG(LCD, "LCD shutdown OK"); +} + +} // 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 @@ +/** + * Copyright (C) 2013 Citrus Emulator + * + * @file hw_lcd.h + * @author bunnei + * @date 2014-04-05 + * @brief Hardware LCD interface + * + * @section LICENSE + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License as + * published by the Free Software Foundation; either version 2 of + * the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details at + * http://www.gnu.org/copyleft/gpl.html + * + * Official project repository can be found at: + * http://code.google.com/p/gekko-gc-emu/ + */ + +#pragma once + +#include "common_types.h" + +namespace LCD { + +enum { + TOP_ASPECT_X = 0x5, + TOP_ASPECT_Y = 0x3, + + TOP_HEIGHT = 240, + TOP_WIDTH = 400, + BOTTOM_WIDTH = 320, + + FRAMEBUFFER_SEL = 0x20184E59, + TOP_LEFT_FRAME1 = 0x20184E60, + TOP_LEFT_FRAME2 = 0x201CB370, + TOP_RIGHT_FRAME1 = 0x20282160, + TOP_RIGHT_FRAME2 = 0x202C8670, + SUB_FRAME1 = 0x202118E0, + SUB_FRAME2 = 0x20249CF0, +}; + +template +inline void Read(T &var, const u32 addr); + +template +inline void Write(u32 addr, const T data); + +/// Update hardware +void Update(); + +/// Initialize hardware +void Init(); + +/// Shutdown hardware +void Shutdown(); + + +} // namespace -- cgit v1.2.3 From 6433f4d6f9c1fd0af4eb5689fe1e363584bb9d38 Mon Sep 17 00:00:00 2001 From: bunnei Date: Sat, 5 Apr 2014 01:24:14 -0400 Subject: added an "Update" method to update all hardware --- src/core/src/hw/hw.cpp | 7 +++++++ src/core/src/hw/hw.h | 3 +++ 2 files changed, 10 insertions(+) (limited to 'src/core') diff --git a/src/core/src/hw/hw.cpp b/src/core/src/hw/hw.cpp index 3e4f2c435..50001c87a 100644 --- a/src/core/src/hw/hw.cpp +++ b/src/core/src/hw/hw.cpp @@ -24,6 +24,7 @@ #include "log.h" #include "hw/hw.h" +#include "hw/hw_lcd.h" namespace HW { @@ -49,8 +50,14 @@ template void Write(u32 addr, const u32 data); template void Write(u32 addr, const u16 data); template void Write(u32 addr, const u8 data); +/// Update hardware +void Update() { + LCD::Update(); +} + /// Initialize hardware void Init() { + LCD::Init(); NOTICE_LOG(HW, "Hardware initialized OK"); } diff --git a/src/core/src/hw/hw.h b/src/core/src/hw/hw.h index c69d6525f..245822423 100644 --- a/src/core/src/hw/hw.h +++ b/src/core/src/hw/hw.h @@ -32,6 +32,9 @@ inline void Read(T &var, const u32 addr); template inline void Write(u32 addr, const T data); +/// Update hardware +void Update(); + /// Initialize hardware void Init(); -- cgit v1.2.3 From c874c1d06cf94f3b02e60d1ba74b2bad3206b211 Mon Sep 17 00:00:00 2001 From: bunnei Date: Sat, 5 Apr 2014 01:24:54 -0400 Subject: add hw_lcd.* to VS project files --- src/core/core.vcxproj | 2 ++ src/core/core.vcxproj.filters | 6 ++++++ 2 files changed, 8 insertions(+) (limited to 'src/core') diff --git a/src/core/core.vcxproj b/src/core/core.vcxproj index 60ce2427d..2edb51214 100644 --- a/src/core/core.vcxproj +++ b/src/core/core.vcxproj @@ -153,6 +153,7 @@ + @@ -182,6 +183,7 @@ + diff --git a/src/core/core.vcxproj.filters b/src/core/core.vcxproj.filters index 7b47f5cbf..0cd208dd6 100644 --- a/src/core/core.vcxproj.filters +++ b/src/core/core.vcxproj.filters @@ -49,6 +49,9 @@ hw + + hw + @@ -145,6 +148,9 @@ hw + + hw + -- cgit v1.2.3 From ed15feebf1cc60356e374e3492e6086066a7d09e Mon Sep 17 00:00:00 2001 From: bunnei Date: Sat, 5 Apr 2014 15:23:59 -0400 Subject: changed hw_lcd to use ARM core correct tick counter instead of [what was actually] just an instruction count. this seems to fix timing issues with the 3DS_Homebrew_Pong3Dv2 demo. --- src/core/src/arm/arm_interface.h | 43 +++++++++++++++++++++++--- src/core/src/arm/interpreter/arm_interpreter.h | 7 +++++ src/core/src/hw/hw_lcd.cpp | 6 ++-- 3 files changed, 48 insertions(+), 8 deletions(-) (limited to 'src/core') diff --git a/src/core/src/arm/arm_interface.h b/src/core/src/arm/arm_interface.h index 80518a779..daf35b51d 100644 --- a/src/core/src/arm/arm_interface.h +++ b/src/core/src/arm/arm_interface.h @@ -24,32 +24,65 @@ #pragma once +#include "common.h" #include "common_types.h" /// Generic ARM11 CPU interface class ARM_Interface { public: ARM_Interface() { + num_instructions_ = 0; } ~ARM_Interface() { } + /// Step CPU by one instruction void Step() { ExecuteInstruction(); - ticks_++; + num_instructions_++; } - - virtual void SetPC(u32 pc) = 0; + + /** + * Set the Program Counter to an address + * @param addr Address to set PC to + */ + virtual void SetPC(u32 addr) = 0; + + /* + * Get the current Program Counter + * @return Returns current PC + */ virtual u32 PC() = 0; + + /** + * Get an ARM register + * @param index Register index (0-15) + * @return Returns the value in the register + */ virtual u32 Reg(int index) = 0; + + /** + * Get the current CPSR register + * @return Returns the value of the CPSR register + */ virtual u32 CPSR() = 0; - u64 ticks() { return ticks_; } + /** + * Returns the number of clock ticks since the last rese + * @return Returns number of clock ticks + */ + virtual u64 GetTicks() = 0; + + /// Getter for num_instructions_ + u64 num_instructions() { return num_instructions_; } private: + /// Execture next instruction virtual void ExecuteInstruction() = 0; - u64 ticks_; + u64 num_instructions_; ///< Number of instructions executed + + DISALLOW_COPY_AND_ASSIGN(ARM_Interface); }; 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 @@ #pragma once +#include "common.h" #include "common_types.h" #include "arm/arm_interface.h" @@ -45,6 +46,12 @@ public: u32 CPSR(); + u64 GetTicks() { + return ARMul_Time(state); + } + private: ARMul_State* state; + + DISALLOW_COPY_AND_ASSIGN(ARM_Interpreter); }; diff --git a/src/core/src/hw/hw_lcd.cpp b/src/core/src/hw/hw_lcd.cpp index 19e3b4ab4..7e3728346 100644 --- a/src/core/src/hw/hw_lcd.cpp +++ b/src/core/src/hw/hw_lcd.cpp @@ -28,7 +28,7 @@ namespace LCD { -static const u32 kFrameTicks = 268123480 / 30; // 268MHz / 30 frames per second +static const u32 kFrameTicks = 268123480 / 60; ///< 268MHz / 60 frames per second u64 g_last_ticks = 0; ///< Last CPU ticks @@ -42,7 +42,7 @@ inline void Write(u32 addr, const T data) { /// Update hardware void Update() { - u64 current_ticks = Core::g_app_core->ticks(); + u64 current_ticks = Core::g_app_core->GetTicks(); if ((current_ticks - g_last_ticks) >= kFrameTicks) { g_last_ticks = current_ticks; @@ -52,7 +52,7 @@ void Update() { /// Initialize hardware void Init() { - g_last_ticks = Core::g_app_core->ticks(); + g_last_ticks = Core::g_app_core->GetTicks(); NOTICE_LOG(LCD, "LCD initialized OK"); } -- cgit v1.2.3 From e022717477184df1268901ee097ed0b358f5a38a Mon Sep 17 00:00:00 2001 From: bunnei Date: Sat, 5 Apr 2014 15:26:03 -0400 Subject: added g_app_core->Step and HW::Update to Core::SingleStep to be consistent with other changes made --- src/core/src/core.cpp | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'src/core') 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 @@ #include "log.h" #include "core.h" #include "mem_map.h" +#include "hw/hw.h" #include "arm/disassembler/arm_disasm.h" #include "arm/interpreter/arm_interpreter.h" @@ -41,7 +42,8 @@ void RunLoop() { /// Step the CPU one instruction void SingleStep() { - g_app_core->ExecuteInstruction(); + g_app_core->Step(); + HW::Update(); } /// Halt the core @@ -69,6 +71,8 @@ void Shutdown() { delete g_disasm; delete g_app_core; delete g_sys_core; + + NOTICE_LOG(MASTER_LOG, "Core shutdown OK"); } } // namespace -- cgit v1.2.3 From 551b2a52e0c36613a3ce459dcd8b2aac39de707b Mon Sep 17 00:00:00 2001 From: bunnei Date: Sun, 6 Apr 2014 16:55:54 -0400 Subject: initialize VideoCore --- src/core/src/system.cpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'src/core') diff --git a/src/core/src/system.cpp b/src/core/src/system.cpp index 1477bab32..7c829d609 100644 --- a/src/core/src/system.cpp +++ b/src/core/src/system.cpp @@ -27,6 +27,7 @@ #include "core_timing.h" #include "mem_map.h" #include "system.h" +#include "video_core.h" namespace System { @@ -41,6 +42,7 @@ void Init(EmuWindow* emu_window) { Memory::Init(); HW::Init(); CoreTiming::Init(); + VideoCore::Init(emu_window); } void RunLoopFor(int cycles) { @@ -53,9 +55,8 @@ void RunLoopUntil(u64 global_cycles) { void Shutdown() { Core::Shutdown(); HW::Shutdown(); + VideoCore::Shutdown(); g_ctr_file_system.Shutdown(); } - - } // namespace -- cgit v1.2.3 From f0d49253e438dc7e39a2a95598c5ebac59d9ef3c Mon Sep 17 00:00:00 2001 From: bunnei Date: Sun, 6 Apr 2014 16:56:13 -0400 Subject: calling SwapBuffers from hw_lcd.cpp --- src/core/src/hw/hw_lcd.cpp | 2 ++ 1 file changed, 2 insertions(+) (limited to 'src/core') diff --git a/src/core/src/hw/hw_lcd.cpp b/src/core/src/hw/hw_lcd.cpp index 7e3728346..072eede32 100644 --- a/src/core/src/hw/hw_lcd.cpp +++ b/src/core/src/hw/hw_lcd.cpp @@ -25,6 +25,7 @@ #include "log.h" #include "core.h" #include "hw_lcd.h" +#include "video_core.h" namespace LCD { @@ -47,6 +48,7 @@ void Update() { if ((current_ticks - g_last_ticks) >= kFrameTicks) { g_last_ticks = current_ticks; NOTICE_LOG(LCD, "Update frame"); + VideoCore::g_renderer->SwapBuffers(); } } -- cgit v1.2.3 From aae52e3f8fbf3538c20ca4ab4a5f182ef4c9ac93 Mon Sep 17 00:00:00 2001 From: bunnei Date: Sun, 6 Apr 2014 22:56:08 -0400 Subject: added hack physical memory reads with Memory::GetPointer --- src/core/src/mem_map_funcs.cpp | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) (limited to 'src/core') diff --git a/src/core/src/mem_map_funcs.cpp b/src/core/src/mem_map_funcs.cpp index dc4c2381d..ee2f79278 100644 --- a/src/core/src/mem_map_funcs.cpp +++ b/src/core/src/mem_map_funcs.cpp @@ -137,14 +137,21 @@ u8 *GetPointer(const u32 addr) { // TODO(bunnei): Just a stub for now... ImplementMe! if ((addr & 0x3E000000) == 0x08000000) { return g_fcram + (addr & MEM_FCRAM_MASK); - } + + // HACK(bunnei): There is no layer yet to translate virtual addresses to physical addresses. + // Until we progress far enough along, we'll accept all physical address reads here. I think + // that this is typically a corner-case from usermode software unless they are trying to do + // bare-metal things (e.g. early 3DS homebrew writes directly to the FB @ 0x20184E60, etc. + } else if (((addr & 0xF0000000) == MEM_FCRAM_PADDR) && (addr < (MEM_FCRAM_PADDR_END))) { + return g_fcram + (addr & MEM_FCRAM_MASK); + //else if ((addr & 0x3F800000) == 0x04000000) { // return g_vram + (addr & MEM_VRAM_MASK); //} //else if ((addr & 0x3F000000) >= 0x08000000 && (addr & 0x3F000000) < 0x08000000 + g_MemorySize) { // return m_pRAM + (addr & g_MemoryMask); //} - else { + } else { //ERROR_LOG(MEMMAP, "Unknown GetPointer %08x PC %08x LR %08x", addr, currentMIPS->pc, currentMIPS->r[MIPS_REG_RA]); ERROR_LOG(MEMMAP, "Unknown GetPointer %08x", addr); static bool reported = false; -- cgit v1.2.3 From 6f7fd741db1b2716753bae2aea75e7dabde92e9f Mon Sep 17 00:00:00 2001 From: bunnei Date: Sun, 6 Apr 2014 22:56:25 -0400 Subject: removed log message from hw_lcd --- src/core/src/hw/hw_lcd.cpp | 2 -- 1 file changed, 2 deletions(-) (limited to 'src/core') diff --git a/src/core/src/hw/hw_lcd.cpp b/src/core/src/hw/hw_lcd.cpp index 072eede32..ee806d5dc 100644 --- a/src/core/src/hw/hw_lcd.cpp +++ b/src/core/src/hw/hw_lcd.cpp @@ -47,7 +47,6 @@ void Update() { if ((current_ticks - g_last_ticks) >= kFrameTicks) { g_last_ticks = current_ticks; - NOTICE_LOG(LCD, "Update frame"); VideoCore::g_renderer->SwapBuffers(); } } @@ -55,7 +54,6 @@ void Update() { /// Initialize hardware void Init() { g_last_ticks = Core::g_app_core->GetTicks(); - NOTICE_LOG(LCD, "LCD initialized OK"); } -- cgit v1.2.3