-
Notifications
You must be signed in to change notification settings - Fork 1
/
CMakeLists.txt
291 lines (264 loc) · 7.06 KB
/
CMakeLists.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
# 573in1 - Copyright (C) 2022-2024 spicyjpeg
#
# 573in1 is free software: you can redistribute it and/or modify it under the
# terms of the GNU General Public License as published by the Free Software
# Foundation, either version 3 of the License, or (at your option) any later
# version.
#
# 573in1 is distributed in the hope that it will be useful, but WITHOUT ANY
# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
# A PARTICULAR PURPOSE. See the GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License along with
# 573in1. If not, see <https://www.gnu.org/licenses/>.
cmake_minimum_required(VERSION 3.25)
set(CMAKE_TOOLCHAIN_FILE "${CMAKE_CURRENT_LIST_DIR}/cmake/toolchain.cmake")
project(
573in1
LANGUAGES C CXX ASM
VERSION 1.0.0
DESCRIPTION "Konami System 573 maintenance tool"
HOMEPAGE_URL "https://github.com/spicyjpeg/573in1"
)
set(
RELEASE_INFO "${PROJECT_NAME} ${PROJECT_VERSION} - (C) 2022-2024 spicyjpeg"
CACHE STRING "Executable description and version string (optional)"
)
set(
RELEASE_NAME "${PROJECT_NAME}-${PROJECT_VERSION}"
CACHE STRING "CD-ROM image and release package file name"
)
string(TOUPPER "${RELEASE_NAME}" _cdVolumeName)
string(REGEX REPLACE "[^0-9A-Z_]" "_" _cdVolumeName "${_cdVolumeName}")
set(
CD_VOLUME_NAME "${_cdVolumeName}"
CACHE STRING "CD-ROM image volume label"
)
find_package(Python3 REQUIRED COMPONENTS Interpreter)
find_program(
CHDMAN_PATH chdman
PATHS
"C:/Program Files/MAME"
"C:/Program Files (x86)/MAME"
"/opt/mame"
DOC "Path to MAME chdman tool (optional)"
)
## Files common to all executables
add_library(
common OBJECT
#src/libc/crt0.c
src/libc/cxxsupport.cpp
src/libc/malloc.c
src/libc/memset.s
src/libc/misc.c
src/libc/misc.s
src/libc/string.c
src/ps1/pcdrv.s
src/ps1/system.c
src/ps1/system.s
src/ps1/unhandledexc.c
)
target_include_directories(
common PUBLIC
src
src/libc
)
target_compile_options(
common PUBLIC
-Wall
-Wextra
-Wno-unused-parameter
$<$<COMPILE_LANGUAGE:CXX>:
-Wno-pmf-conversions
>
)
target_compile_definitions(
common PUBLIC
VERSION="${PROJECT_VERSION}"
EXTERNAL_DATA_DIR="hdd:/${PROJECT_NAME}"
)
link_libraries(common)
function(addExecutable name address stackTop)
add_executable(${name} ${ARGN})
target_link_options(${name} PRIVATE -Ttext=0x${address})
add_custom_command(
TARGET ${name} POST_BUILD
BYPRODUCTS "${name}.psexe"
COMMAND
"${Python3_EXECUTABLE}"
"${PROJECT_SOURCE_DIR}/tools/convertExecutable.py"
-r "${RELEASE_INFO}"
-s 0x${stackTop}
"$<TARGET_FILE:${name}>"
"${name}.psexe"
VERBATIM
)
endfunction()
## Main executable
# IMPORTANT: these addresses assume the boot executable's size (including code,
# heap and stack allocations as well as the resource archive) is <576 KB
# (0x90000 bytes).
addExecutable(
main 800a0000 801dfff0
src/common/file/fat.cpp
src/common/file/file.cpp
src/common/file/iso9660.cpp
src/common/file/misc.cpp
src/common/file/zip.cpp
src/common/args.cpp
src/common/gpu.cpp
src/common/gpufont.cpp
src/common/ide.cpp
src/common/io.cpp
src/common/pad.cpp
src/common/rom.cpp
src/common/romdrivers.cpp
src/common/spu.cpp
src/common/util.cpp
src/libc/crt0.c
src/main/app/app.cpp
src/main/app/cartactions.cpp
src/main/app/cartunlock.cpp
src/main/app/cartworkers.cpp
src/main/app/main.cpp
src/main/app/misc.cpp
src/main/app/miscworkers.cpp
src/main/app/modals.cpp
src/main/app/romactions.cpp
src/main/app/romworkers.cpp
src/main/app/tests.cpp
src/main/cart/cart.cpp
src/main/cart/cartdata.cpp
src/main/cart/cartio.cpp
src/main/cart/zs01.cpp
src/main/main.cpp
src/main/uibase.cpp
src/main/uicommon.cpp
src/main/uimodals.cpp
src/vendor/ff.c
src/vendor/ffunicode.c
src/vendor/miniz.c
src/vendor/printf.c
src/vendor/qrcodegen.c
)
target_compile_definitions(
main PRIVATE
# Logging options
ENABLE_APP_LOGGING=1
ENABLE_CART_IO_LOGGING=1
ENABLE_CART_DATA_LOGGING=1
ENABLE_ROM_LOGGING=1
ENABLE_IDE_LOGGING=1
ENABLE_FS_LOGGING=1
# Security cartridge driver options
#ENABLE_DUMMY_CART_DRIVER=1
ENABLE_X76F041_CART_DRIVER=1
#ENABLE_X76F100_CART_DRIVER=1
ENABLE_ZS01_CART_DRIVER=1
# Misc. options
ENABLE_FULL_IDE_DRIVER=1
ENABLE_LOG_BUFFER=1
#ENABLE_ARGV=1
#ENABLE_PCDRV=1
ENABLE_PS1_CONTROLLER=1
ENABLE_AUTOBOOT=1
)
## Boot stub and executable launchers
# NOTE: in order to make sure -Os is passed after -Og or -O3 (see
# cmake/setup.cmake) and thus overrides it, it must be added to a separate
# target rather than directly to the executables.
add_library(bootFlags INTERFACE)
target_compile_options(bootFlags INTERFACE -Os)
target_compile_definitions(
bootFlags INTERFACE
$<$<CONFIG:Debug>:
#ENABLE_ARGV=1
#ENABLE_LOGGING=1
>
)
function(addLauncher address stackTop)
addExecutable(
launcher${address} ${address} ${stackTop}
src/common/args.cpp
src/common/ide.cpp
src/common/io.cpp
src/common/util.cpp
src/launcher/main.cpp
src/libc/crt0.c
src/vendor/printf.c
)
target_link_libraries(launcher${address} PRIVATE bootFlags)
endfunction()
# IMPORTANT: these addresses assume the launcher's total size (including code,
# heap and stack allocations, but excluding the executable header) is <12 KB
# (0x3000 bytes).
addLauncher(801fd000 801ffff0)
addLauncher(803fd000 803ffff0)
## Boot stub and resource archive
configure_file(assets/about.txt about.txt NEWLINE_STYLE LF)
function(addBootStub name resourceName)
configure_file(${resourceName}.json ${resourceName}.json ESCAPE_QUOTES)
add_custom_command(
COMMAND
"${Python3_EXECUTABLE}"
"${PROJECT_SOURCE_DIR}/tools/buildResourceArchive.py"
${resourceName}.json
${resourceName}.zip
OUTPUT ${resourceName}.zip
DEPENDS
${resourceName}.json
assets/app.palette.json
assets/app.strings.json
main.psexe
launcher801fd000.psexe
launcher803fd000.psexe
COMMENT "Building ${name} resource archive"
VERBATIM
)
addExecutable(
${name} 80010000 0
src/boot/crt0.s
src/boot/main.cpp
src/common/io.cpp
src/common/util.cpp
)
addBinaryFile(
${name} _resourceArchive _resourceArchiveLength
"${PROJECT_BINARY_DIR}/${resourceName}.zip"
)
target_link_libraries(${name} PRIVATE bootFlags)
endfunction()
addBootStub("${RELEASE_NAME}" resources)
addBootStub("${RELEASE_NAME}-tiny" resourcestiny)
## CD-ROM image
configure_file(cdrom.json cdrom.json ESCAPE_QUOTES)
configure_file(assets/cdreadme.txt readme.txt NEWLINE_STYLE CRLF)
configure_file(LICENSE license.txt NEWLINE_STYLE CRLF)
add_custom_command(
COMMAND
"${Python3_EXECUTABLE}"
"${PROJECT_SOURCE_DIR}/tools/buildCDImage.py"
cdrom.json
"${RELEASE_NAME}.iso"
OUTPUT "${RELEASE_NAME}.iso"
DEPENDS
cdrom.json
"${RELEASE_NAME}"
COMMENT "Building CD-ROM image"
VERBATIM
)
if(EXISTS "${CHDMAN_PATH}")
add_custom_command(
COMMAND
"${CHDMAN_PATH}" createcd -f
-i "${RELEASE_NAME}.iso"
-o "${RELEASE_NAME}.chd"
OUTPUT "${RELEASE_NAME}.chd"
DEPENDS "${RELEASE_NAME}.iso"
COMMENT "Building MAME CHD image"
VERBATIM
)
add_custom_target(cdrom ALL DEPENDS "${RELEASE_NAME}.chd")
else()
add_custom_target(cdrom ALL DEPENDS "${RELEASE_NAME}.iso")
endif()