diff --git a/CMakeLists.txt b/CMakeLists.txt index 8e7d0fe..83ffe15 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -26,11 +26,29 @@ elseif(TANG_BOARD STREQUAL "nano20k") add_definitions(-DTANG_NANO20K) endif() +# libchdr: LOWRAM_TARGET on (real ~365KB free SRAM budget on this board, see +# project memory - whole-hunk decode does not fit, streaming-decode design does) +add_definitions( + -DLOWRAM_TARGET=1 + -DWANT_RAW_DATA_SECTOR=1 + -DWANT_SUBCODE=1 + -DVERIFY_BLOCK_CRC=1 + -DCHDR_FLAC_BACKEND_MICROFLAC + -DMICRO_FLAC_DISABLE_OGG + -DMINIZ_NO_ARCHIVE_APIS + -DMINIZ_NO_DEFLATE_APIS + -DMINIZ_NO_STDIO + -DMINIZ_NO_TIME +) + find_package(bouffalo_sdk REQUIRED HINTS $ENV{BL_SDK_BASE}) # Add include directories sdk_add_include_directories( - . usb fpga ui core utils + . usb fpga ui core utils chd + thirdparty/libchdr/include + thirdparty/libchdr/src + thirdparty/micro-flac/include ) # Add source files @@ -42,7 +60,37 @@ file(GLOB_RECURSE MY_SOURCES "utils/*.cpp" ) -target_sources(app PRIVATE ${MY_SOURCES}) +file(GLOB LIBCHDR_SOURCES + "chd/*.c" + "thirdparty/libchdr/src/*.c" + "thirdparty/libchdr/deps/lzma-26.02/src/LzmaDec.c" + "thirdparty/libchdr/deps/miniz-3.1.2/miniz.c" + "thirdparty/libchdr/deps/zstd-1.5.7/zstddeclib.c" +) + +# libchdr_flac.c is the dr_flac backend; exactly one backend is compiled, so +# it goes when micro-flac comes in. +list(REMOVE_ITEM LIBCHDR_SOURCES + "${CMAKE_CURRENT_SOURCE_DIR}/thirdparty/libchdr/src/libchdr_flac.c") + +set(LIBCHDR_MICROFLAC_SOURCES + "thirdparty/libchdr/src/libchdr_flac_microflac.cpp" + "thirdparty/micro-flac/src/flac_decoder.cpp" + "thirdparty/micro-flac/src/decorrelation.cpp" + "thirdparty/micro-flac/src/frame_header.cpp" + "thirdparty/micro-flac/src/pcm_packing.cpp" + "thirdparty/micro-flac/src/crc.cpp" + "thirdparty/micro-flac/src/lpc.cpp" +) + +# -fno-exceptions/-fno-rtti keep libstdc++'s exception and RTTI machinery out +# of a bare-metal link, -fno-threadsafe-statics drops the __cxa_guard_* +# dependency, and -fno-use-cxa-atexit is what ESP-IDF does here - newlib does +# provide __cxa_atexit, so it links either way. +set_source_files_properties(${LIBCHDR_MICROFLAC_SOURCES} PROPERTIES + COMPILE_OPTIONS "-fno-exceptions;-fno-rtti;-fno-threadsafe-statics;-fno-use-cxa-atexit") + +target_sources(app PRIVATE ${MY_SOURCES} ${LIBCHDR_SOURCES} ${LIBCHDR_MICROFLAC_SOURCES}) sdk_set_main_file(main.cpp) project(tangcore CXX) diff --git a/main.cpp b/main.cpp index e349734..c24c645 100644 --- a/main.cpp +++ b/main.cpp @@ -31,6 +31,7 @@ extern "C" { #include "utils.h" #include "cores.h" #include "overlay.h" +#include "chd_fatfs.h" #include "init.h" #include "menu_manager.h" @@ -554,6 +555,21 @@ static void print_system_info(void) { } // Initialize things, then start main_task and uart1_rx_task to do actual work +// TEMPORARY link-verification probe: forces the linker to fully pull in and +// resolve libchdr against this toolchain/libc (LOWRAM_TARGET codec paths +// included). Not a real feature - no SD card is mounted yet at this point in +// boot, so this always fails to open and returns cleanly. Remove once real +// CHD loading is wired into a core loader. +static void chd_link_probe(void) +{ + FIL fil; + chd_file *chd = NULL; + chd_error err = chd_fatfs_open("sd:/__chd_link_probe__.chd", &fil, &chd); + DEBUG("chd_link_probe: chd_fatfs_open -> %d\n", (int)err); + if (chd) + chd_close(chd); +} + int main(void) { /* Board init */ @@ -565,6 +581,8 @@ int main(void) print_system_info(); + chd_link_probe(); + // Create mutex for joypad states state_mutex = xSemaphoreCreateMutex();