Skip to content

Commit

Permalink
Merge branch 'master' of https://github.com/Arisotura/melonDS into sw…
Browse files Browse the repository at this point in the history
…itch-new
  • Loading branch information
RSDuck committed Feb 12, 2021
2 parents efe38b1 + 295d60e commit 514e48e
Show file tree
Hide file tree
Showing 28 changed files with 1,288 additions and 1,076 deletions.
6 changes: 2 additions & 4 deletions .github/workflows/build-ubuntu-aarch64.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,9 @@ jobs:
- name: Upgrade system
shell: bash
working-directory: ${{runner.workspace}}
run: | #Fix grub installation error - https://github.com/actions/virtual-environments/issues/1605
run: |
sudo apt update
sudo apt-get install grub-efi
sudo update-grub
sudo apt full-upgrade
sudo ACCEPT_EULA=Y apt full-upgrade
- name: Install dependencies
shell: bash
working-directory: ${{runner.workspace}}
Expand Down
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,11 @@
<a href="http://melonds.kuribo64.net/downloads.php" alt="Release: 0.9.1"><img src="https://img.shields.io/badge/release-0.9.1-%235c913b.svg"></a>
<a href="https://www.gnu.org/licenses/gpl-3.0" alt="License: GPLv3"><img src="https://img.shields.io/badge/License-GPL%20v3-%23ff554d.svg"></a>
<a href="https://kiwiirc.com/client/irc.badnik.net/?nick=IRC-Source_?#melonds" alt="IRC channel: #melonds"><img src="https://img.shields.io/badge/IRC%20chat-%23melonds-%23dd2e44.svg"></a>
<br>
<a href="https://github.com/Arisotura/melonDS/actions?query=workflow%3A%22CMake+Build+%28Windows+x86-64%29%22+event%3Apush"><img src="https://img.shields.io/github/workflow/status/Arisotura/melonDS/CMake%20Build%20(Windows%20x86-64)?label=Windows%20x86-64&logo=GitHub"></img></a>
<a href="https://github.com/Arisotura/melonDS/actions?query=workflow%3A%22CMake+Build+%28Ubuntu+x86-64%29%22+event%3Apush"><img src="https://img.shields.io/github/workflow/status/Arisotura/melonDS/CMake%20Build%20(Ubuntu%20x86-64)?label=Linux%20x86-64&logo=GitHub"></img></a>
<a href="https://github.com/Arisotura/melonDS/actions?query=workflow%3A%22CMake+Build+%28macOS+x86-64%29%22+event%3Apush"><img src="https://img.shields.io/github/workflow/status/Arisotura/melonDS/CMake%20Build%20(macOS%20x86-64)?label=macOS%20x86-64&logo=GitHub"></img></a>
<a href="https://github.com/Arisotura/melonDS/actions?query=workflow%3A%22CMake+Build+%28Ubuntu+aarch64%29%22+event%3Apush"><img src="https://img.shields.io/github/workflow/status/Arisotura/melonDS/CMake%20Build%20(Ubuntu%20aarch64)?label=Linux%20ARM64&logo=GitHub"></img></a>
</p>
DS emulator, sorta

Expand Down
29 changes: 0 additions & 29 deletions flatpak/net.kuribo64.melonDS.yml

This file was deleted.

23 changes: 14 additions & 9 deletions src/ARMJIT_Memory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,8 @@ static void SigsegvHandler(int sig, siginfo_t* info, void* rawContext)
desc.FaultPC = (u8*)context->uc_mcontext->__ss.__rip;
#elif defined(__FreeBSD__)
desc.FaultPC = (u8*)context->uc_mcontext.mc_rip;
#elif defined(__NetBSD__)
desc.FaultPC = (u8*)context->uc_mcontext.__gregs[_REG_RIP];
#else
desc.FaultPC = (u8*)context->uc_mcontext.gregs[REG_RIP];
#endif
Expand All @@ -190,6 +192,8 @@ static void SigsegvHandler(int sig, siginfo_t* info, void* rawContext)
context->uc_mcontext->__ss.__rip = (u64)desc.FaultPC;
#elif defined(__FreeBSD__)
context->uc_mcontext.mc_rip = (u64)desc.FaultPC;
#elif defined(__NetBSD__)
context->uc_mcontext.__gregs[_REG_RIP] = (u64)desc.FaultPC;
#else
context->uc_mcontext.gregs[REG_RIP] = (u64)desc.FaultPC;
#endif
Expand Down Expand Up @@ -717,16 +721,17 @@ void Init()

MemoryFile = CreateFileMapping(INVALID_HANDLE_VALUE, NULL, PAGE_READWRITE, 0, MemoryTotalSize, NULL);

MemoryBase = (u8*)VirtualAlloc(NULL, MemoryTotalSize, MEM_RESERVE, PAGE_READWRITE);

FastMem9Start = VirtualAlloc(NULL, AddrSpaceSize, MEM_RESERVE, PAGE_READWRITE);
FastMem7Start = VirtualAlloc(NULL, AddrSpaceSize, MEM_RESERVE, PAGE_READWRITE);

// only free them after they have all been reserved
// so they can't overlap
MemoryBase = (u8*)VirtualAlloc(NULL, AddrSpaceSize*4, MEM_RESERVE, PAGE_READWRITE);
VirtualFree(MemoryBase, 0, MEM_RELEASE);
VirtualFree(FastMem9Start, 0, MEM_RELEASE);
VirtualFree(FastMem7Start, 0, MEM_RELEASE);
// this is incredible hacky
// but someone else is trying to go into our address space!
// Windows will very likely give them virtual memory starting at the same address
// as it is giving us now.
// That's why we don't use this address, but instead 4gb inwards
// I know this is terrible
FastMem9Start = MemoryBase + AddrSpaceSize;
FastMem7Start = MemoryBase + AddrSpaceSize*2;
MemoryBase = MemoryBase + AddrSpaceSize*3;

MapViewOfFileEx(MemoryFile, FILE_MAP_READ | FILE_MAP_WRITE, 0, 0, MemoryTotalSize, MemoryBase);

Expand Down
2 changes: 1 addition & 1 deletion src/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
project(core)

set (CMAKE_CXX_STANDARD 14)
set (CMAKE_CXX_STANDARD 17)

add_library(core STATIC
ARCodeFile.cpp
Expand Down
125 changes: 71 additions & 54 deletions src/GPU.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
#include "NDS.h"
#include "GPU.h"

#include "GPU2D_Soft.h"

namespace GPU
{
Expand Down Expand Up @@ -78,11 +79,10 @@ u8* VRAMPtr_BOBJ[0x8];

int FrontBuffer;
u32* Framebuffer[2][2];
int Renderer;
bool Accelerated;
int Renderer = 0;

GPU2D* GPU2D_A;
GPU2D* GPU2D_B;
std::unique_ptr<GPU2D> GPU2D_A = {};
std::unique_ptr<GPU2D> GPU2D_B = {};

/*
VRAM invalidation tracking
Expand Down Expand Up @@ -141,30 +141,33 @@ u32 PaletteDirty;

u8 AllPaletteMemory[2*1024+BGExtPalSize*2+OBJExtPalSize*2];

#ifdef OGLRENDERER_ENABLED
std::unique_ptr<GLCompositor> CurGLCompositor = {};
#endif

bool Init()
{
#ifndef NEONSOFTGPU_ENABLED
GPU2D_A = new GPU2D_Soft(0);
GPU2D_B = new GPU2D_Soft(1);
#ifdef NEONGPU_ENABLED
GPU2D_A = std::make_unique<GPU2D_Soft>(0);
GPU2D_B = std::make_unique<GPU2D_Soft>(1);
#else
GPU2D_A = new GPU2D_NeonSoft(0);
GPU2D_B = new GPU2D_NeonSoft(1);
GPU2D_A = std::make_unique<GPU2D_NeonSoft>(0);
GPU2D_B = std::make_unique<GPU2D_NeonSoft>(1);
#endif
if (!GPU3D::Init()) return false;

FrontBuffer = 0;
Framebuffer[0][0] = NULL; Framebuffer[0][1] = NULL;
Framebuffer[1][0] = NULL; Framebuffer[1][1] = NULL;
Renderer = 0;
Accelerated = false;

return true;
}

void DeInit()
{
delete GPU2D_A;
delete GPU2D_B;
GPU2D_A.reset();
GPU2D_B.reset();
GPU3D::DeInit();

if (Framebuffer[0][0]) delete[] Framebuffer[0][0];
Expand Down Expand Up @@ -254,9 +257,12 @@ void Reset()
memset(VRAMPtr_BBG, 0, sizeof(VRAMPtr_BBG));
memset(VRAMPtr_BOBJ, 0, sizeof(VRAMPtr_BOBJ));

int fbsize;
if (Accelerated) fbsize = (256*3 + 1) * 192;
else fbsize = 256 * 192;
size_t fbsize;
if (GPU3D::CurrentRenderer->Accelerated)
fbsize = (256*3 + 1) * 192;
else
fbsize = 256 * 192;

for (int i = 0; i < fbsize; i++)
{
Framebuffer[0][0][i] = 0xFFFFFFFF;
Expand Down Expand Up @@ -287,17 +293,22 @@ void Reset()
void Stop()
{
int fbsize;
if (Accelerated) fbsize = (256*3 + 1) * 192;
else fbsize = 256 * 192;
if (GPU3D::CurrentRenderer->Accelerated)
fbsize = (256*3 + 1) * 192;
else
fbsize = 256 * 192;

memset(Framebuffer[0][0], 0, fbsize*4);
memset(Framebuffer[0][1], 0, fbsize*4);
memset(Framebuffer[1][0], 0, fbsize*4);
memset(Framebuffer[1][1], 0, fbsize*4);

#ifdef OGLRENDERER_ENABLED
if (Accelerated)
GLCompositor::Stop();
#endif
// This needs a better way to know that we're
// using the OpenGL renderer specifically
if (GPU3D::CurrentRenderer->Accelerated)
CurGLCompositor->Stop();
#endif
}

void DoSavestate(Savestate* file)
Expand Down Expand Up @@ -386,37 +397,42 @@ void InitRenderer(int renderer)
#ifdef OGLRENDERER_ENABLED
if (renderer == 1)
{
if (!GLCompositor::Init())
CurGLCompositor = std::make_unique<GLCompositor>();
// Create opengl rendrerer
if (!CurGLCompositor->Init())
{
// Fallback on software renderer
renderer = 0;
GPU3D::CurrentRenderer = std::make_unique<GPU3D::SoftRenderer>();
GPU3D::CurrentRenderer->Init();
}
else if (!GPU3D::GLRenderer::Init())
GPU3D::CurrentRenderer = std::make_unique<GPU3D::GLRenderer>();
if (!GPU3D::CurrentRenderer->Init())
{
GLCompositor::DeInit();
// Fallback on software renderer
CurGLCompositor->DeInit();
CurGLCompositor.reset();
renderer = 0;
GPU3D::CurrentRenderer = std::make_unique<GPU3D::SoftRenderer>();
}
}
else
#endif
{
GPU3D::SoftRenderer::Init();
GPU3D::CurrentRenderer = std::make_unique<GPU3D::SoftRenderer>();
GPU3D::CurrentRenderer->Init();
}

Renderer = renderer;
Accelerated = renderer != 0;
}

void DeInitRenderer()
{
if (Renderer == 0)
{
GPU3D::SoftRenderer::DeInit();
}
GPU3D::CurrentRenderer->DeInit();
#ifdef OGLRENDERER_ENABLED
else
if (Renderer == 1)
{
GPU3D::GLRenderer::DeInit();
GLCompositor::DeInit();
CurGLCompositor->DeInit();
}
#endif
}
Expand All @@ -425,13 +441,13 @@ void ResetRenderer()
{
if (Renderer == 0)
{
GPU3D::SoftRenderer::Reset();
GPU3D::CurrentRenderer->Reset();
}
#ifdef OGLRENDERER_ENABLED
else
{
GLCompositor::Reset();
GPU3D::GLRenderer::Reset();
CurGLCompositor->Reset();
GPU3D::CurrentRenderer->Reset();
}
#endif
}
Expand All @@ -444,10 +460,12 @@ void SetRenderSettings(int renderer, RenderSettings& settings)
InitRenderer(renderer);
}

bool accel = Accelerated;
int fbsize;
if (accel) fbsize = (256*3 + 1) * 192;
else fbsize = 256 * 192;
if (GPU3D::CurrentRenderer->Accelerated)
fbsize = (256*3 + 1) * 192;
else
fbsize = 256 * 192;

if (Framebuffer[0][0]) { delete[] Framebuffer[0][0]; Framebuffer[0][0] = nullptr; }
if (Framebuffer[1][0]) { delete[] Framebuffer[1][0]; Framebuffer[1][0] = nullptr; }
if (Framebuffer[0][1]) { delete[] Framebuffer[0][1]; Framebuffer[0][1] = nullptr; }
Expand All @@ -465,18 +483,15 @@ void SetRenderSettings(int renderer, RenderSettings& settings)

AssignFramebuffers();

GPU2D_A->SetRenderSettings(accel);
GPU2D_B->SetRenderSettings(accel);

if (Renderer == 0)
{
GPU3D::SoftRenderer::SetRenderSettings(settings);
GPU3D::CurrentRenderer->SetRenderSettings(settings);
}
#ifdef OGLRENDERER_ENABLED
else
{
GLCompositor::SetRenderSettings(settings);
GPU3D::GLRenderer::SetRenderSettings(settings);
CurGLCompositor->SetRenderSettings(settings);
GPU3D::CurrentRenderer->SetRenderSettings(settings);
}
#endif
}
Expand Down Expand Up @@ -1153,7 +1168,9 @@ void StartScanline(u32 line)
GPU3D::VBlank();

#ifdef OGLRENDERER_ENABLED
if (Accelerated) GLCompositor::RenderFrame();
// Need a better way to identify the openGL renderer in particular
if (GPU3D::CurrentRenderer->Accelerated)
CurGLCompositor->RenderFrame();
#endif
}
}
Expand Down Expand Up @@ -1191,7 +1208,7 @@ NonStupidBitField<Size/VRAMDirtyGranularity> VRAMTrackingSet<Size, MappingGranul
{
if (currentMappings[i] != Mapping[i])
{
result |= NonStupidBitField<Size/VRAMDirtyGranularity>(i*VRAMBitsPerMapping, VRAMBitsPerMapping);
result.SetRange(i*VRAMBitsPerMapping, VRAMBitsPerMapping);
banksToBeZeroed |= currentMappings[i];
Mapping[i] = currentMappings[i];
}
Expand All @@ -1213,19 +1230,19 @@ NonStupidBitField<Size/VRAMDirtyGranularity> VRAMTrackingSet<Size, MappingGranul
if (MappingGranularity == 16*1024)
{
u32 dirty = ((u32*)VRAMDirty[num].Data)[i & (VRAMMask[num] >> 14)];
((u32*)result.Data)[i] |= dirty;
result.Data[i / 2] |= (u64)dirty << ((i&1)*32);
}
else if (MappingGranularity == 8*1024)
{
u16 dirty = ((u16*)VRAMDirty[num].Data)[i & (VRAMMask[num] >> 13)];
((u16*)result.Data)[i] |= dirty;
result.Data[i / 4] |= (u64)dirty << ((i&3)*16);
}
else if (MappingGranularity == 128*1024)
{
((u64*)result.Data)[i * 4 + 0] |= ((u64*)VRAMDirty[num].Data)[0];
((u64*)result.Data)[i * 4 + 1] |= ((u64*)VRAMDirty[num].Data)[1];
((u64*)result.Data)[i * 4 + 2] |= ((u64*)VRAMDirty[num].Data)[2];
((u64*)result.Data)[i * 4 + 3] |= ((u64*)VRAMDirty[num].Data)[3];
result.Data[i * 4 + 0] |= VRAMDirty[num].Data[0];
result.Data[i * 4 + 1] |= VRAMDirty[num].Data[1];
result.Data[i * 4 + 2] |= VRAMDirty[num].Data[2];
result.Data[i * 4 + 3] |= VRAMDirty[num].Data[3];
}
else
{
Expand All @@ -1240,7 +1257,7 @@ NonStupidBitField<Size/VRAMDirtyGranularity> VRAMTrackingSet<Size, MappingGranul
{
u32 num = __builtin_ctz(banksToBeZeroed);
banksToBeZeroed &= ~(1 << num);
memset(VRAMDirty[num].Data, 0, sizeof(VRAMDirty[num].Data));
VRAMDirty[num].Clear();
}

return result;
Expand Down Expand Up @@ -1270,7 +1287,7 @@ void SyncDirtyFlags(u32* mappings, NonStupidBitField<Size>& writtenFlags)
mapping &= ~(1 << num);
}
}
memset(writtenFlags.Data, 0, sizeof(writtenFlags.Data));
writtenFlags.Clear();
}

void SyncDirtyFlags()
Expand Down
Loading

0 comments on commit 514e48e

Please sign in to comment.