Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Switch port #71

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -179,3 +179,6 @@ gba emulator witten in c++23.
- ocornut for imgui <https://github.com/ocornut/imgui>
- ocornut for imgui_club <https://github.com/ocornut/imgui_club>
- everyone that has contributed to the bios decomp <https://github.com/Gericom/gba_bios>
- [ftpd](https://github.com/mtheall/ftpd) and [nxshell](https://github.com/joel16/NX-Shell) for the deko3d backend for switch.
- <a target="_blank" href="https://icons8.com/icon/38359/visual-game-boy">Visual Game Boy</a> icon by <a target="_blank" href="https://icons8.com">Icons8</a>
- <a target="_blank" href="https://icons8.com/icon/71cUHRMvCNMk/mac-folder">Mac Folder</a> icon by <a target="_blank" href="https://icons8.com">Icons8</a>
Binary file added assets/icons/icon.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/icons/icons8-mac-folder-64.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/icons/icons8-visual-game-boy-48.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
48 changes: 48 additions & 0 deletions assets/shaders/nx/imgui_fsh.glsl
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
// ftpd is a server implementation based on the following:
// - RFC 959 (https://tools.ietf.org/html/rfc959)
// - RFC 3659 (https://tools.ietf.org/html/rfc3659)
// - suggested implementation details from https://cr.yp.to/ftp/filesystem.html
//
// The MIT License (MIT)
//
// Copyright (C) 2020 Michael Theall
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in all
// copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
// SOFTWARE.

#version 460

layout (location = 0) in vec2 vtxUv;
layout (location = 1) in vec4 vtxColor;

layout (binding = 0) uniform sampler2D tex;

layout (std140, binding = 0) uniform FragUBO {
uint font;
} ubo;

layout (location = 0) out vec4 outColor;

void main()
{
// font texture is single-channel (alpha)
if (ubo.font != 0)
outColor = vtxColor * vec4 (vec3 (1.0), texture (tex, vtxUv).r);
else
outColor = vtxColor * texture (tex, vtxUv);
}
47 changes: 47 additions & 0 deletions assets/shaders/nx/imgui_vsh.glsl
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
// ftpd is a server implementation based on the following:
// - RFC 959 (https://tools.ietf.org/html/rfc959)
// - RFC 3659 (https://tools.ietf.org/html/rfc3659)
// - suggested implementation details from https://cr.yp.to/ftp/filesystem.html
//
// The MIT License (MIT)
//
// Copyright (C) 2020 Michael Theall
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in all
// copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
// SOFTWARE.

#version 460

layout (location = 0) in vec2 inPos;
layout (location = 1) in vec2 inUv;
layout (location = 2) in vec4 inColor;

layout (location = 0) out vec2 vtxUv;
layout (location = 1) out vec4 vtxColor;

layout (std140, binding = 0) uniform VertUBO
{
mat4 projMtx;
} ubo;

void main()
{
gl_Position = ubo.projMtx * vec4 (inPos, 0.0, 1.0);
vtxUv = inUv;
vtxColor = inColor;
}
3 changes: 2 additions & 1 deletion src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,8 @@ list(APPEND gcc_flags
-Wmissing-requires
)

if (CMAKE_BUILD_TYPE STREQUAL "Debug")
# for switch build, always enable full optimisations, even in debug
if (CMAKE_BUILD_TYPE STREQUAL "Debug" AND NOT NINTENDO_SWITCH)
list(APPEND gcc_flags -Og) # always enable otherwise debug builds would be too slow
else()
list(APPEND gcc_flags -fno-rtti -Ofast)
Expand Down
59 changes: 57 additions & 2 deletions src/frontend/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,17 @@ FetchContent_Declare(minizip
BUILD_COMMAND ""
)

FetchContent_Declare(stb
GIT_REPOSITORY https://github.com/nothings/stb.git
GIT_TAG af1a5bc352164740c1cc1354942b1c6b72eacb8a
GIT_PROGRESS TRUE
CONFIGURE_COMMAND ""
BUILD_COMMAND ""
)

FetchContent_MakeAvailable(imgui)
FetchContent_MakeAvailable(imgui_club)
FetchContent_MakeAvailable(stb)

add_library(imgui
${imgui_SOURCE_DIR}/imgui.cpp
Expand All @@ -45,9 +54,12 @@ target_include_directories(imgui PUBLIC ${imgui_SOURCE_DIR})

# memory editor
add_library(imgui_club INTERFACE)
target_include_directories(imgui INTERFACE ${imgui_club_SOURCE_DIR}/imgui_memory_editor)
target_include_directories(imgui_club INTERFACE ${imgui_club_SOURCE_DIR}/imgui_memory_editor)
# fetch imgui is done!

add_library(stb INTERFACE)
target_include_directories(stb INTERFACE ${stb_SOURCE_DIR})

# always include backend after fetching imgui
add_subdirectory(backend)

Expand Down Expand Up @@ -82,8 +94,13 @@ else()
target_link_libraries(main PRIVATE ${minizip_lib})
target_include_directories(main PRIVATE ${minizip_inc})

# on switch, i need to manually link against
# zlib as well, and has to be linked after minizip!
find_package(ZLIB REQUIRED)
target_link_libraries(main PRIVATE ZLIB::ZLIB)

set(FOUND_MINIZIP TRUE)
message(STATUS "using system minizip")
message(STATUS "using system minizip lib: ${minizip_lib} inc: ${minizip_inc}")
endif()
endif()

Expand Down Expand Up @@ -127,3 +144,41 @@ target_compile_definitions(main PRIVATE
DUMP_AUDIO=$<BOOL:${DUMP_AUDIO}>
DEBUGGER=$<BOOL:${DEBUGGER}>
)

if (NINTENDO_SWITCH)
set(ASSETS ${CMAKE_SOURCE_DIR}/assets)

# create romfs folder
dkp_add_asset_target(main_romfs ${CMAKE_CURRENT_BINARY_DIR}/romfs)

configure_file(${ASSETS}/icons/icons8-mac-folder-64.png ${CMAKE_CURRENT_BINARY_DIR}/romfs/icons/icons8-mac-folder-64.png COPYONLY)
configure_file(${ASSETS}/icons/icons8-visual-game-boy-48.png ${CMAKE_CURRENT_BINARY_DIR}/romfs/icons/icons8-visual-game-boy-48.png COPYONLY)

# setup nacp
nx_generate_nacp(main.nacp
NAME "Notorious BEEG"
AUTHOR TotalJustice
VERSION 0.0.3
)

# create nro (final binary)
nx_create_nro(main
ICON ${ASSETS}/icons/icon.jpg
NACP main.nacp
ROMFS main_romfs
)

# compile and add shaders to romfs
set(SHADER_FOLDER ${ASSETS}/shaders/nx)

nx_add_shader_program(imgui_fsh ${SHADER_FOLDER}/imgui_fsh.glsl frag)
nx_add_shader_program(imgui_vsh ${SHADER_FOLDER}/imgui_vsh.glsl vert)

dkp_install_assets(main_romfs
DESTINATION shaders
TARGETS
imgui_fsh
imgui_vsh
)

endif()
6 changes: 5 additions & 1 deletion src/frontend/backend/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
cmake_minimum_required(VERSION 3.20.0)

add_subdirectory(sdl2)
if (NINTENDO_SWITCH)
add_subdirectory(nx)
else()
add_subdirectory(sdl2)
endif()
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,22 @@
// SPDX-License-Identifier: GPL-3.0-only
#pragma once

#include "../../system.hpp"
#include "../system.hpp"
#include <cstdint>
#include <span>
#include <utility>

namespace sys::backend::sdl2 {
namespace sys::backend {

[[nodiscard]] auto init() -> bool;
auto quit() -> void;

auto poll_events() -> void;
// used for setup
auto render_begin() -> void;
// render anything specific to the backend
auto render() -> void;
// flip the screen
auto render_end() -> void;

auto get_texture(TextureID id) -> void*;
Expand All @@ -28,4 +32,4 @@ auto toggle_fullscreen() -> void;

auto open_url(const char* url) -> void;

} // sys::backend::sdl2
} // sys::backend
20 changes: 20 additions & 0 deletions src/frontend/backend/nx/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
cmake_minimum_required(VERSION 3.20.0)

add_library(backend
backend_nx.cpp
ftpd_imgui/imgui_deko3d.cpp
ftpd_imgui/imgui_nx.cpp

audio/audio.cpp
fs.cpp
)

target_link_libraries(backend PRIVATE imgui)
target_link_libraries(backend PRIVATE GBA)
target_link_libraries(backend PRIVATE deko3d)
target_link_libraries(backend PRIVATE stb)

# why is this even needed???
target_include_directories(backend PRIVATE ${DEVKITPRO}/portlibs/switch/include)

target_apply_lto_in_release(backend)
Loading