Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
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
Original file line number Diff line number Diff line change
Expand Up @@ -16,75 +16,49 @@ project(
HOMEPAGE_URL "https://github.com/grumpycoders/pcsx-redux"
)

# Set up compiler flags and initialize the Python environment used to run the
# scripts in the tools directory.
# Set up compiler flags, initialize the Python environment used to run the
# scripts in the tools directory and define some helper macros.
include(ps1-bare-metal/cmake/setup.cmake)
include(ps1-bare-metal/cmake/virtualenv.cmake)
include(ps1-bare-metal/cmake/tools.cmake)

# Build a "common" library containing basic support code. We are going to link
# this library into our executable.
# Build a "common" library containing basic support code and link it by default
# into every executable.
add_library(
common OBJECT
ps1-bare-metal/src/libc/clz.s
ps1-bare-metal/src/libc/crt0.c
ps1-bare-metal/src/libc/cxxsupport.cpp
ps1-bare-metal/src/libc/malloc.c
ps1-bare-metal/src/libc/memset.s
ps1-bare-metal/src/libc/misc.c
ps1-bare-metal/src/libc/misc.s
ps1-bare-metal/src/libc/setjmp.s
ps1-bare-metal/src/libc/string.c
ps1-bare-metal/src/libc/string.s
ps1-bare-metal/src/ps1/cache.s
ps1-bare-metal/src/vendor/printf.c
)
target_include_directories(
common PUBLIC
ps1-bare-metal/src
ps1-bare-metal/src/libc
)
link_libraries(common)

# Compile the main executable. You may add more source files by listing them
# here.
add_executable(
# Compile the main executable; you may add more source files by listing them
# here. The addPS1Executable() macro is defined in tools.cmake and automatically
# takes care of converting the built ELF file into a PS1 executable (.psexe)
# which can run be run on emulators or real hardware.
addPS1Executable(
{{projectName}}
src/font.c
src/gpu.c
src/main.c
src/trig.c
)
target_link_libraries({{projectName}} PRIVATE common)

# Define a CMake macro that invokes convertImage.py in order to generate VRAM
# texture data from an image file.
function(convertImage input bpp)
add_custom_command(
OUTPUT ${ARGN}
DEPENDS "${PROJECT_SOURCE_DIR}/${input}"
COMMAND
"${Python3_EXECUTABLE}"
"${PROJECT_SOURCE_DIR}/ps1-bare-metal/tools/convertImage.py"
-b ${bpp}
"${PROJECT_SOURCE_DIR}/${input}"
${ARGN}
VERBATIM
)
endfunction()

# Convert the font spritesheet to a 4bpp texture and palette, then embed them
# into the executable. The addBinaryFile() macro is defined in setup.cmake; you
# may call it multiple times to embed other data into the binary.
# into the executable. The convertImage() and addBinaryFile() macros are defined
# in tools.cmake and setup.cmake respectively. You may call them multiple times
# to embed other images or data into the binary.
convertImage(assets/font.png 4 fontTexture.dat fontPalette.dat)
addBinaryFile({{projectName}} fontTexture "${PROJECT_BINARY_DIR}/fontTexture.dat")
addBinaryFile({{projectName}} fontPalette "${PROJECT_BINARY_DIR}/fontPalette.dat")

# Add a step to run convertExecutable.py after the executable is compiled in
# order to convert it into a PS1 executable. By default all custom commands run
# from the build directory, so paths to files in the source directory must be
# prefixed with ${PROJECT_SOURCE_DIR}.
add_custom_command(
TARGET {{projectName}} POST_BUILD
BYPRODUCTS {{projectName}}.psexe
COMMAND
"${Python3_EXECUTABLE}"
"${PROJECT_SOURCE_DIR}/ps1-bare-metal/tools/convertExecutable.py"
"$<TARGET_FILE:{{projectName}}>"
{{projectName}}.psexe
VERBATIM
)
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
// Ensure the GTE, which is coprocessor 2, is enabled. MIPS coprocessors are
// enabled through the status register in coprocessor 0, which is always
// accessible.
cop0_setReg(COP0_SR, cop0_getReg(COP0_SR) | COP0_SR_CU2);
cop0_setReg(COP0_STATUS, cop0_getReg(COP0_STATUS) | COP0_STATUS_CU2);

// Set the offset to be added to all calculated screen space coordinates (we
// want our cube to appear at the center of the screen) Note that OFX and
Expand Down Expand Up @@ -192,8 +192,9 @@

setupGTE(SCREEN_WIDTH, SCREEN_HEIGHT);

DMA_DPCR |= DMA_DPCR_ENABLE << (DMA_GPU * 4);
DMA_DPCR |= DMA_DPCR_ENABLE << (DMA_OTC * 4);
DMA_DPCR |= 0
| DMA_DPCR_CH_ENABLE(DMA_GPU)
| DMA_DPCR_CH_ENABLE(DMA_OTC);

Check warning on line 197 in tools/vscode-extension/templates/bare-metal/cmake-cube/src/main.c

View check run for this annotation

CodeScene Delta Analysis / CodeScene Code Health Review (main)

❌ Getting worse: Complex Method

main already has high cyclomatic complexity, and now it increases in Lines of Code from 87 to 88. This function has many conditional statements (e.g. if, for, while), leading to lower code health. Avoid adding more conditionals and code to it without refactoring.

GPU_GP1 = gp1_dmaRequestMode(GP1_DREQ_GP0_WRITE);
GPU_GP1 = gp1_dispBlank(false);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,48 +16,35 @@ project(
HOMEPAGE_URL "https://github.com/grumpycoders/pcsx-redux"
)

# Set up compiler flags and initialize the Python environment used to run the
# scripts in the tools directory.
# Set up compiler flags, initialize the Python environment used to run the
# scripts in the tools directory and define some helper macros.
include(ps1-bare-metal/cmake/setup.cmake)
include(ps1-bare-metal/cmake/virtualenv.cmake)
include(ps1-bare-metal/cmake/tools.cmake)

# Build a "common" library containing basic support code. We are going to link
# this library into our executable.
# Build a "common" library containing basic support code and link it by default
# into every executable.
add_library(
common OBJECT
ps1-bare-metal/src/libc/clz.s
ps1-bare-metal/src/libc/crt0.c
ps1-bare-metal/src/libc/cxxsupport.cpp
ps1-bare-metal/src/libc/malloc.c
ps1-bare-metal/src/libc/memset.s
ps1-bare-metal/src/libc/misc.c
ps1-bare-metal/src/libc/misc.s
ps1-bare-metal/src/libc/setjmp.s
ps1-bare-metal/src/libc/string.c
ps1-bare-metal/src/libc/string.s
ps1-bare-metal/src/ps1/cache.s
ps1-bare-metal/src/vendor/printf.c
)
target_include_directories(
common PUBLIC
ps1-bare-metal/src
ps1-bare-metal/src/libc
)
link_libraries(common)

# Create the main executable. You may add more source files by listing them
# after main.c.
add_executable(
{{projectName}}
src/main.c
)
target_link_libraries({{projectName}} PRIVATE common)

# Add a step to run convertExecutable.py after the executable is compiled in
# order to convert it into a PS1 executable. By default all custom commands run
# from the build directory, so paths to files in the source directory must be
# prefixed with ${PROJECT_SOURCE_DIR}.
add_custom_command(
TARGET {{projectName}} POST_BUILD
BYPRODUCTS {{projectName}}.psexe
COMMAND
"${Python3_EXECUTABLE}"
"${PROJECT_SOURCE_DIR}/ps1-bare-metal/tools/convertExecutable.py"
"$<TARGET_FILE:{{projectName}}>" {{projectName}}.psexe
VERBATIM
)
# Compile the main executable; you may add more source files by listing them
# here. The addPS1Executable() macro is defined in tools.cmake and automatically
# takes care of converting the built ELF file into a PS1 executable (.psexe)
# which can run be run on emulators or real hardware.
addPS1Executable({{projectName}} src/main.c)
Loading