Skip to content

Commit 065c7a1

Browse files
committed
More updates to CMake bare metal templates
1 parent ba5c080 commit 065c7a1

File tree

5 files changed

+36
-45
lines changed

5 files changed

+36
-45
lines changed

tools/vscode-extension/templates/bare-metal/cmake-cube/CMakeLists.txt

Lines changed: 26 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -40,40 +40,8 @@ target_include_directories(
4040
ps1-bare-metal/src/libc
4141
)
4242

43-
# Define a helper function to embed the contents of a file into the executable.
44-
function(addBinaryFile target name path)
45-
set(_file "${PROJECT_BINARY_DIR}/includes/${target}_${name}.s")
46-
cmake_path(ABSOLUTE_PATH path OUTPUT_VARIABLE _path)
47-
48-
# Generate an assembly listing that uses the .incbin directive to embed the
49-
# file and add it to the executable's list of source files. This may look
50-
# hacky, but it works and lets us easily customize the symbol name (i.e. the
51-
# name of the "array" that will contain the file's data).
52-
file(
53-
CONFIGURE
54-
OUTPUT "${_file}"
55-
CONTENT [[
56-
.section .data.${name}, "aw"
57-
.balign 8
58-
59-
.global ${name}
60-
.type ${name}, @object
61-
.size ${name}, (${name}_end - ${name})
62-
63-
${name}:
64-
.incbin "${_path}"
65-
${name}_end:
66-
]]
67-
ESCAPE_QUOTES
68-
NEWLINE_STYLE LF
69-
)
70-
71-
target_sources(${target} PRIVATE "${_file}")
72-
set_source_files_properties("${_file}" PROPERTIES OBJECT_DEPENDS "${_path}")
73-
endfunction()
74-
75-
# Create the main executable. You may add more source files by listing them
76-
# here, or other images or files by adding calls to addBinaryFile().
43+
# Compile the main executable. You may add more source files by listing them
44+
# here.
7745
add_executable(
7846
{{projectName}}
7947
src/font.c
@@ -83,8 +51,28 @@ add_executable(
8351
)
8452
target_link_libraries({{projectName}} PRIVATE common)
8553

86-
addBinaryFile({{projectName}} fontTexture assets/fontTexture.dat)
87-
addBinaryFile({{projectName}} fontPalette assets/fontPalette.dat)
54+
# Define a CMake macro that invokes convertImage.py in order to generate VRAM
55+
# texture data from an image file.
56+
function(convertImage input bpp)
57+
add_custom_command(
58+
OUTPUT ${ARGN}
59+
DEPENDS "${PROJECT_SOURCE_DIR}/${input}"
60+
COMMAND
61+
"${Python3_EXECUTABLE}"
62+
"${PROJECT_SOURCE_DIR}/ps1-bare-metal/tools/convertImage.py"
63+
-b ${bpp}
64+
"${PROJECT_SOURCE_DIR}/${input}"
65+
${ARGN}
66+
VERBATIM
67+
)
68+
endfunction()
69+
70+
# Convert the font spritesheet to a 4bpp texture and palette, then embed them
71+
# into the executable. The addBinaryFile() macro is defined in setup.cmake; you
72+
# may call it multiple times to embed other data into the binary.
73+
convertImage(assets/font.png 4 fontTexture.dat fontPalette.dat)
74+
addBinaryFile({{projectName}} fontTexture "${PROJECT_BINARY_DIR}/fontTexture.dat")
75+
addBinaryFile({{projectName}} fontPalette "${PROJECT_BINARY_DIR}/fontPalette.dat")
8876

8977
# Add a step to run convertExecutable.py after the executable is compiled in
9078
# order to convert it into a PS1 executable. By default all custom commands run
@@ -96,6 +84,7 @@ add_custom_command(
9684
COMMAND
9785
"${Python3_EXECUTABLE}"
9886
"${PROJECT_SOURCE_DIR}/ps1-bare-metal/tools/convertExecutable.py"
99-
"$<TARGET_FILE:{{projectName}}>" {{projectName}}.psexe
87+
"$<TARGET_FILE:{{projectName}}>"
88+
{{projectName}}.psexe
10089
VERBATIM
10190
)
Binary file not shown.
Binary file not shown.

tools/vscode-extension/templates/bare-metal/cmake-cube/src/main.c

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,12 @@
11
/*
2-
* This template is based on the following examples:
2+
* This program is a simple demo that displays a 3D cube and some text (using
3+
* the font spritesheet in the assets directory), based on the following
4+
* examples:
35
* https://github.com/spicyjpeg/ps1-bare-metal/blob/main/src/06_fonts/main.c
46
* https://github.com/spicyjpeg/ps1-bare-metal/blob/main/src/08_spinningCube/main.c
57
*
6-
* If you wish to modify the font image in the assets directory or add more
7-
* images, you may use the ps1-bare-metal/tools/convertImage.py script to
8-
* generate the texture and palette files to embed into the executable. Note
9-
* that the script requires additional dependencies to run; see
10-
* ps1-bare-metal/tools/requirements.txt for information on how to install them.
8+
* For further information on the contents of the ps1-bare-metal submodule, see:
9+
* https://github.com/spicyjpeg/ps1-bare-metal
1110
*/
1211

1312
#include <stdbool.h>

tools/vscode-extension/templates/bare-metal/empty-cmake/src/main.c

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,12 @@
66
* back of the console or to another interface. Additionally, most emulators can
77
* log calls to printf() and display the output in their log window.
88
*
9-
* For a variant of this project that prints directly to the PS1's serial port
10-
* instead of using the kernel, see:
9+
* A variant of this project that prints directly to the PS1's serial port
10+
* instead of using the kernel is available here:
1111
* https://github.com/spicyjpeg/ps1-bare-metal/blob/main/src/00_helloWorld/main.c
12+
*
13+
* For further information on the contents of the ps1-bare-metal submodule, see:
14+
* https://github.com/spicyjpeg/ps1-bare-metal
1215
*/
1316

1417
#define BIOS_API_TABLE ((void **) 0x80000200)

0 commit comments

Comments
 (0)