From 082f3175f0b4ba26244777f6cd25fa8a0d38247b Mon Sep 17 00:00:00 2001 From: Jeff Epler Date: Thu, 27 Mar 2025 11:47:12 -0500 Subject: [PATCH] Move building the disk image & patching rom into cmake This fixes a problem I kept causing myself: the patched ROM files were not per build directory, meaning that I'd build a wrong ROM and wonder why nothing was working. --- CMakeLists.txt | 23 +++++++++++++++++++++-- external/umac | 2 +- fetch-rom-dsk.sh | 20 ++++++-------------- fruitjam-build.sh | 22 +++++++--------------- 4 files changed, 35 insertions(+), 32 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index c8f1eb4..83e1c1c 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -73,6 +73,8 @@ set(PIN_AUDIO_PWM 41 CACHE STRING "Pin for PWM audio") # overriding defaults. set(MEMSIZE 128 CACHE STRING "Memory size, in KB") +set(DISC_IMAGE ${CMAKE_CURRENT_SOURCE_DIR}/umac0ro.img CACHE FILEPATH "Built-in disk image") + if (USE_HSTX) add_compile_definitions(USE_VGA_RES=1) add_compile_definitions(HSTX_CKP=${HSTX_CKP} HSTX_D0P=${HSTX_D0P} HSTX_D1P=${HSTX_D1P} HSTX_D2P=${HSTX_D2P}) @@ -87,10 +89,12 @@ if (USE_VGA_RES) add_compile_definitions(DISP_WIDTH=640) add_compile_definitions(DISP_HEIGHT=480) set(RES "640x480") + set(RESFLAG "-v") else() add_compile_definitions(DISP_WIDTH=512) add_compile_definitions(DISP_HEIGHT=342) set(RES "512x342") + set(RESFLAG "") endif() if (USE_PSRAM) @@ -187,6 +191,21 @@ if (TARGET tinyusb_device) ) # The umac sources need to prepare Musashi (some sources are generated): + add_custom_command(OUTPUT incbin/umac-rom.h + COMMAND echo "*** Patching ROM ***" + COMMAND set -xe && mkdir -p ${CMAKE_CURRENT_BINARY_DIR}/incbin && make -C ${UMAC_PATH} patcher && ${UMAC_PATH}/patcher ${RESFLAG} -m ${MEMSIZE} -r "${CMAKE_CURRENT_LIST_DIR}/rom.bin" -w ${CMAKE_CURRENT_BINARY_DIR}/incbin/umac-rom.h + ) + add_custom_target(prepare_rom + DEPENDS incbin/umac-rom.h + ) + + add_custom_command(OUTPUT incbin/umac-disc.h + COMMAND echo "DISC_IMAGE is ${DISC_IMAGE}" && mkdir -p ${CMAKE_CURRENT_BINARY_DIR}/incbin && xxd -i < "${DISC_IMAGE}" > ${CMAKE_CURRENT_BINARY_DIR}/incbin/umac-disc.h + ) + add_custom_target(prepare_disc + DEPENDS incbin/umac-disc.h + ) + add_custom_command(OUTPUT ${UMAC_MUSASHI_PATH}/m68kops.c COMMAND echo "*** Preparing umac source ***" COMMAND make -C ${UMAC_PATH} prepare @@ -194,7 +213,7 @@ if (TARGET tinyusb_device) add_custom_target(prepare_umac DEPENDS ${UMAC_MUSASHI_PATH}/m68kops.c ) - add_dependencies(${FIRMWARE} prepare_umac) + add_dependencies(${FIRMWARE} prepare_umac prepare_rom prepare_disc) target_link_libraries(${FIRMWARE} pico_stdlib @@ -214,7 +233,7 @@ if (TARGET tinyusb_device) ${PICO_TINYUSB_PATH}/src ${UMAC_INCLUDE_PATHS} ${PIOUSB_PATH}/src - incbin + ${CMAKE_CURRENT_BINARY_DIR}/incbin ${CMAKE_CURRENT_LIST_DIR} ) diff --git a/external/umac b/external/umac index ce55830..431e905 160000 --- a/external/umac +++ b/external/umac @@ -1 +1 @@ -Subproject commit ce55830a1babd681d0e9a639c9b23f10cd9e3c96 +Subproject commit 431e905354e975cd942eb4c1c5ea5a39237691ab diff --git a/fetch-rom-dsk.sh b/fetch-rom-dsk.sh index b0b67b3..519e1df 100755 --- a/fetch-rom-dsk.sh +++ b/fetch-rom-dsk.sh @@ -1,21 +1,13 @@ #!/bin/sh -mkdir -p incbin +set -xe if ! [ -f rom.bin ]; then - if ! [ -f '4D1F8172 - MacPlus v3.ROM' ]; then - curl -L 'https://ia902205.us.archive.org/view_archive.php?archive=/18/items/mac_rom_archive_-_as_of_8-19-2011/mac_rom_archive_-_as_of_8-19-2011.zip&file=4D1F8172%20-%20MacPlus%20v3.ROM' > '4D1F8172 - MacPlus v3.ROM' - fi - make -C external/umac clean - make -C external/umac DISP_WIDTH=512 DISP_HEIGHT=342 - ./external/umac/main -r '4D1F8172 - MacPlus v3.ROM' -W rom.bin + curl -L 'https://ia902205.us.archive.org/view_archive.php?archive=/18/items/mac_rom_archive_-_as_of_8-19-2011/mac_rom_archive_-_as_of_8-19-2011.zip&file=4D1F8172%20-%20MacPlus%20v3.ROM' > rom.bin fi -xxd -i < rom.bin > incbin/umac-rom.h - if ! [ -f umac0ro.img ]; then - curl -L 'https://archive.org/download/apple-mac-os-system-3.2-finder-5.3-system-tools-1.0-512-ke-jun-1986-3.5-800k.-7z/Apple%20Mac%20OS%20%28System%203.2%20Finder%205.3%29%20%28System%20Tools%201.0%20Mac%20128%2C%20512K%29%20%28Jun%201986%29%20%283.5-400k%29.7z' > 'Apple Mac OS (System 3.2 Finder 5.3) (System Tools 1.1 Mac Plus) (Jun 1986) (3.5-800k).7z' - 7z x -so 'Apple Mac OS (System 3.2 Finder 5.3) (System Tools 1.1 Mac Plus) (Jun 1986) (3.5-800k).7z' 'Apple Mac OS (System 3.2 Finder 5.3) (System Tools 1.0 Mac 128, 512K) (Jun 1986) (3.5-400k)/System Installation.img' > umac0ro.img + if ! [ -f os.7z ]; then + curl -L 'https://archive.org/download/apple-mac-os-system-3.2-finder-5.3-system-tools-1.0-512-ke-jun-1986-3.5-800k.-7z/Apple%20Mac%20OS%20%28System%203.2%20Finder%205.3%29%20%28System%20Tools%201.0%20Mac%20128%2C%20512K%29%20%28Jun%201986%29%20%283.5-400k%29.7z' > 'os.7z' + fi + 7z x -so 'os.7z' 'Apple Mac OS (System 3.2 Finder 5.3) (System Tools 1.0 Mac 128, 512K) (Jun 1986) (3.5-400k)/System Installation.img' > umac0ro.img fi - -xxd -i < umac0ro.img > incbin/umac-disc.h - diff --git a/fruitjam-build.sh b/fruitjam-build.sh index eaee774..6a1ca40 100755 --- a/fruitjam-build.sh +++ b/fruitjam-build.sh @@ -10,7 +10,7 @@ set -e DISP_WIDTH=512 DISP_HEIGHT=342 MEMSIZE=400 -DISK_IMAGE="" +DISC_IMAGE= CMAKE_ARGS="" while getopts "hvd:m:" o; do @@ -24,14 +24,14 @@ while getopts "hvd:m:" o; do MEMSIZE=$OPTARG ;; (d) - DISK_IMAGE=$OPTARG + DISC_IMAGE=$OPTARG ;; (h|?) echo "Usage: $0 [-v] [-m KiB] [-d diskimage]" echo "" echo " -v: Use framebuffer resolution 640x480 instead of 512x342" echo " -m: Set memory size in KiB" - echo " -d: Specify disk image to include" + echo " -d: Specify disc image to include" echo "" echo "PSRAM is automatically set depending on memory & framebuffer details" exit @@ -54,22 +54,14 @@ if [ "$MIRROR_FRAMEBUFFER" -eq 0 ]; then fi # Append disk name to build directory if disk image is specified -if [ -n "$DISK_IMAGE" ] && [ -f "$DISK_IMAGE" ]; then +if [ -n "$DISC_IMAGE" ] && [ -f "$DISC_IMAGE" ]; then # Extract filename without extension - DISK_NAME=$(basename "$DISK_IMAGE" | sed 's/\.[^.]*$//') - TAG=${TAG}_${DISK_NAME} + DISC_IMAGE=$(basename "$DISC_IMAGE" | sed 's/\.[^.]*$//') + CMAKE_ARGS="$CMAKE_ARGS -DDISK_IMAGE=${DISC_IMAGE}" + TAG=${TAG}_${DISC_IMAGE} fi set -x -make -C external/umac clean -make -C external/umac DISP_WIDTH=${DISP_WIDTH} DISP_HEIGHT=${DISP_HEIGHT} MEMSIZE=${MEMSIZE} -rm -f rom.bin -./external/umac/main -r '4D1F8172 - MacPlus v3.ROM' -W rom.bin || true -[ -f rom.bin ] -xxd -i < rom.bin > incbin/umac-rom.h -if [ -n "$DISK_IMAGE" ] && [ -f "$DISK_IMAGE" ]; then - xxd -i < "$DISK_IMAGE" > incbin/umac-disc.h -fi rm -rf build_${TAG} cmake -S . -B build_${TAG} \ -DPICO_SDK_PATH=../pico-sdk \