@@ -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. 
7745add_executable (
7846    {{projectName}}
7947    src/font.c
@@ -83,8 +51,28 @@ add_executable(
8351)
8452target_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)
0 commit comments