Skip to content

Commit

Permalink
Use cmake instead of batch and make scripts
Browse files Browse the repository at this point in the history
  • Loading branch information
igor725 committed Oct 25, 2024
1 parent 6b2eb9c commit 9403845
Show file tree
Hide file tree
Showing 11 changed files with 118 additions and 254 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
input/x64/
build/
.cache/
eboot.bin
param.sfo
pkg.gp4
Expand Down
10 changes: 10 additions & 0 deletions .vscode/extensions.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"recommendations": [
"jeff-hykin.better-cpp-syntax",
"ms-vscode.cpptools",
"ms-vscode.cpptools-extension-pack",
"twxs.cmake",
"llvm-vs-code-extensions.vscode-clangd",
"ms-vscode.cmake-tools"
]
}
12 changes: 9 additions & 3 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,14 @@
{
"C_Cpp.formatting": "clangFormat",
"C_Cpp.clang_format_fallbackStyle": "LLVM",
"C_Cpp.default.cppStandard": "c++20",
"C_Cpp.autoAddFileAssociations": false,
"editor.tabSize": 2,
"editor.insertSpaces": true,
"cmake.configureSettings": {
"CMAKE_TOOLCHAIN_FILE": "OpenOrbis-tc.cmake"
},
"clangd.arguments": [
"--compile-commands-dir=./build/",
"--header-insertion=never"
],
"C_Cpp.intelliSenseEngine": "disabled",
"C_Cpp.formatting": "disabled",
}
35 changes: 35 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
cmake_minimum_required(VERSION 3.24)

set(PKG_TITLE "PS4 Test Input System")
set(PKG_VERSION "1.2")
set(PKG_TITLE_ID "DDRM00001")
set(PKG_CONTENT_ID "IV0000-${PKG_TITLE_ID}_00-PS4INPUTSY000000")

project(eboot VERSION 0.0.1)
set(PRJ_ADD_LIBS SceVideoOut SceAudioOut ScePad SceUserService)

add_subdirectory(input)

add_executable(eboot
$<TARGET_OBJECTS:eboot_obj>
${OO_PS4_TOOLCHAIN}/lib/crt1.o
)

set_target_properties(eboot PROPERTIES OUTPUT_NAME "eboot" SUFFIX ".elf" PREFIX "")
target_link_libraries(eboot PRIVATE ${PRJ_ADD_LIBS})

# Create param.sfo

if(CMAKE_HOST_WIN32)
install(CODE "execute_process(WORKING_DIRECTORY \"${PROJECT_SOURCE_DIR}\" COMMAND \".\\\\package.bat\" \"${PKG_TITLE}\" \"${PKG_VERSION}\" \"${PKG_TITLE_ID}\" \"${PKG_CONTENT_ID}\")")
set(ORBIS_BIN_PATH ${OO_PS4_TOOLCHAIN}/bin/windows)
elseif(CMAKE_HOST_LINUX)
install(CODE "execute_process(WORKING_DIRECTORY \"${PROJECT_SOURCE_DIR}\" COMMAND \"./package.sh\" \"${PKG_TITLE}\" \"${PKG_VERSION}\" \"${PKG_TITLE_ID}\" \"${PKG_CONTENT_ID}\")")
set(ORBIS_BIN_PATH ${OO_PS4_TOOLCHAIN}/bin/linux)
else()
message(FATAL_ERROR "Unsupported OS")
endif()

# Create eboot.bin from generated elf file

add_custom_command(TARGET eboot POST_BUILD COMMAND ${ORBIS_BIN_PATH}/create-fself -in "${CMAKE_BINARY_DIR}/eboot.elf" --out "${CMAKE_BINARY_DIR}/eboot.oelf" --eboot "${PROJECT_SOURCE_DIR}/eboot.bin" --paid 0x3800000000000011)
86 changes: 0 additions & 86 deletions Makefile

This file was deleted.

29 changes: 29 additions & 0 deletions OpenOrbis-tc.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
if(NOT DEFINED ENV{OO_PS4_TOOLCHAIN})
message(FATAL_ERROR "Missing OpenOrbis toolchain environment variable!")
endif()
STRING(REGEX REPLACE "\\\\" "/" OO_PS4_TOOLCHAIN "$ENV{OO_PS4_TOOLCHAIN}")

set(CMAKE_SYSTEM_NAME FreeBSD)
set(CMAKE_C_COMPILER_TARGET "x86_64-pc-freebsd12-elf")
set(CMAKE_C_FLAGS "-fPIC -funwind-tables -fshort-wchar")
set(CMAKE_CXX_COMPILER_TARGET "${CMAKE_C_COMPILER_TARGET}")
set(CMAKE_CXX_FLAGS "${CMAKE_C_FLAGS}")
set(CMAKE_TRY_COMPILE_TARGET_TYPE "STATIC_LIBRARY")
set(CMAKE_SYSROOT ${OO_PS4_TOOLCHAIN})

include_directories(SYSTEM
${OO_PS4_TOOLCHAIN}/include
${OO_PS4_TOOLCHAIN}/include/c++/v1
)

link_directories(
${OO_PS4_TOOLCHAIN}/lib
)

add_link_options(-pie -nostartfiles -nodefaultlibs -lc -lc++ -lkernel -fuse-ld=lld -Wl,-m,elf_x86_64 -Wl,--eh-frame-hdr "-Wl,--script,${OO_PS4_TOOLCHAIN}/link.x")

if(CMAKE_BUILD_TYPE STREQUAL "Debug")
add_compile_options(-O0 -g)
else()
add_compile_options(-O3)
endif()
11 changes: 3 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,17 +28,12 @@ This application allows you to test your PS4 gamepads (or your input system impl
To build this project, the developer will need clang, which is provided in the toolchain. The `OO_PS4_TOOLCHAIN` environment variable will also need to be set to the root directory of the SDK installation.

__Windows__
Run the batch file from command prompt or powershell with the following command:
To build the project use following CMake:
```
.\build.bat .\x64\Debug
cmake -Bbuild -S. -DCMAKE_TOOLCHAIN_FILE=OpenOrbis-tc.cmake
```

__Linux__
Run the makefile.
```
make
```
You can use VS Code with recomended extensions aswell. CMake extension is already configured in project directory.


## Author(s)
Expand Down
11 changes: 11 additions & 0 deletions input/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
project(eboot_obj LANGUAGES CXX)

add_library(eboot_obj OBJECT
# Entry
main.cpp
controller.cpp
graphics.cpp
png.cpp
)

target_include_directories(eboot_obj PRIVATE ../padpatch)
91 changes: 0 additions & 91 deletions input/build.bat

This file was deleted.

57 changes: 4 additions & 53 deletions input/controller.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,9 @@ bool Controller::Init(int controllerUserID) {
// Open a handle for the controller
this->userID = controllerUserID;
this->pad = scePadOpen(this->userID, 0, 0, NULL);
this->padSpeaker = sceAudioOutOpen(controllerUserID, 4 /* PADSPK */, 0, 1024,
48000, 0 /* S16_MONO */);
this->padSpeaker =
sceAudioOutOpen(controllerUserID, ORBIS_AUDIO_OUT_PORT_TYPE_PADSPK, 0,
1024, 48000, 0 /* S16_MONO */);

if (this->pad < 1) {
DEBUGLOG << "[DEBUG] [ERROR] Failed to open pad!";
Expand Down Expand Up @@ -72,57 +73,7 @@ void Controller::ResetTriggersFeedback() {
bool Controller::CheckButtonsPressed(int stateToCheck) {
scePadReadState(this->pad, &this->padData);
setButtonState(this->padData.buttons);

if (stateToCheck & ORBIS_PAD_BUTTON_TRIANGLE &&
!(this->buttonState & ORBIS_PAD_BUTTON_TRIANGLE))
return false;
if (stateToCheck & ORBIS_PAD_BUTTON_CIRCLE &&
!(this->buttonState & ORBIS_PAD_BUTTON_CIRCLE))
return false;
if (stateToCheck & ORBIS_PAD_BUTTON_CROSS &&
!(this->buttonState & ORBIS_PAD_BUTTON_CROSS))
return false;
if (stateToCheck & ORBIS_PAD_BUTTON_SQUARE &&
!(this->buttonState & ORBIS_PAD_BUTTON_SQUARE))
return false;
if (stateToCheck & ORBIS_PAD_BUTTON_L1 &&
!(this->buttonState & ORBIS_PAD_BUTTON_L1))
return false;
if (stateToCheck & ORBIS_PAD_BUTTON_R1 &&
!(this->buttonState & ORBIS_PAD_BUTTON_R1))
return false;
if (stateToCheck & ORBIS_PAD_BUTTON_L2 &&
!(this->buttonState & ORBIS_PAD_BUTTON_L2))
return false;
if (stateToCheck & ORBIS_PAD_BUTTON_R2 &&
!(this->buttonState & ORBIS_PAD_BUTTON_R2))
return false;
if (stateToCheck & ORBIS_PAD_BUTTON_L3 &&
!(this->buttonState & ORBIS_PAD_BUTTON_L3))
return false;
if (stateToCheck & ORBIS_PAD_BUTTON_R3 &&
!(this->buttonState & ORBIS_PAD_BUTTON_R3))
return false;
if (stateToCheck & ORBIS_PAD_BUTTON_OPTIONS &&
!(this->buttonState & ORBIS_PAD_BUTTON_OPTIONS))
return false;
if (stateToCheck & ORBIS_PAD_BUTTON_UP &&
!(this->buttonState & ORBIS_PAD_BUTTON_UP))
return false;
if (stateToCheck & ORBIS_PAD_BUTTON_RIGHT &&
!(this->buttonState & ORBIS_PAD_BUTTON_RIGHT))
return false;
if (stateToCheck & ORBIS_PAD_BUTTON_DOWN &&
!(this->buttonState & ORBIS_PAD_BUTTON_DOWN))
return false;
if (stateToCheck & ORBIS_PAD_BUTTON_LEFT &&
!(this->buttonState & ORBIS_PAD_BUTTON_LEFT))
return false;
if (stateToCheck & ORBIS_PAD_BUTTON_TOUCH_PAD &&
!(this->buttonState & ORBIS_PAD_BUTTON_TOUCH_PAD))
return false;

return true;
return (this->buttonState & stateToCheck) > 0;
}

bool Controller::TrianglePressed() {
Expand Down
Loading

0 comments on commit 9403845

Please sign in to comment.