From 4bb0b70ec8af8dffadd47cae8a83f3f1d31cda98 Mon Sep 17 00:00:00 2001 From: kub Date: Mon, 8 Mar 2021 23:02:55 +0100 Subject: [PATCH] core, chd support --- .gitmodules | 3 +++ Makefile | 34 +++++++++++++++++++++++++++++++++- Makefile.libretro | 2 -- configure | 9 +++++---- pico/cart.c | 5 +++-- pico/cd/libchdr | 1 + platform/psp/emu.c | 2 +- platform/psp/mp3.c | 18 ------------------ platform/psp/plat.c | 11 +++++++++++ 9 files changed, 57 insertions(+), 28 deletions(-) create mode 160000 pico/cd/libchdr diff --git a/.gitmodules b/.gitmodules index fc412564..1c07eb7d 100644 --- a/.gitmodules +++ b/.gitmodules @@ -7,6 +7,9 @@ [submodule "pico/sound/emu2413"] path = pico/sound/emu2413 url = https://github.com/digital-sound-antiques/emu2413.git +[submodule "pico/cd/libchdr"] + path = pico/cd/libchdr + url = https://github.com/rtissera/libchdr [submodule "platform/common/minimp3"] path = platform/common/minimp3 url = https://github.com/lieff/minimp3 diff --git a/Makefile b/Makefile index 7a40eb14..87257926 100644 --- a/Makefile +++ b/Makefile @@ -57,6 +57,7 @@ CFLAGS += -fno-common -fno-stack-protector -fno-guess-branch-probability -fno-ca endif # default settings +use_libchdr ?= 1 ifeq "$(ARCH)" "arm" use_cyclone ?= 1 use_drz80 ?= 1 @@ -236,8 +237,39 @@ OBJS += platform/common/mp3_minimp3.o endif endif -ifneq (,$(HAVE_LIBCHDR)) +ifeq (1,$(use_libchdr)) +# yuck, cmake looks like a nightmare to embed in a multi-platform make env :-/ +# Moreover, static library linking isn't working. +# Reference all source files directly and hope for the best. Tested on linux, +# might not work on other platforms, and misses autodetected optimizations. CFLAGS += -DUSE_LIBCHDR + +# chdr +CHDR = pico/cd/libchdr +CHDR_OBJS += $(CHDR)/src/libchdr_chd.o $(CHDR)/src/libchdr_cdrom.o +CHDR_OBJS += $(CHDR)/src/libchdr_flac.o +CHDR_OBJS += $(CHDR)/src/libchdr_bitstream.o $(CHDR)/src/libchdr_huffman.o + +# flac +FLAC = $(CHDR)/deps/flac-1.3.3 +FLAC_OBJS += $(FLAC)/src/format.o $(FLAC)/src/lpc.o $(FLAC)/src/cpu.o +FLAC_OBJS += $(FLAC)/src/metadata_object.o $(FLAC)/src/metadata_iterators.o +FLAC_OBJS += $(FLAC)/src/bitmath.o $(FLAC)/src/bitreader.o $(FLAC)/src/md5.o +FLAC_OBJS += $(FLAC)/src/memory.o $(FLAC)/src/fixed.o $(FLAC)/src/crc.o +FLAC_OBJS += $(FLAC)/src/window.o $(FLAC)/src/stream_decoder.o +$(FLAC_OBJS): CFLAGS += -DPACKAGE_VERSION=\"1.3.3\" -DFLAC__HAS_OGG=0 +$(FLAC_OBJS): CFLAGS += -DHAVE_LROUND -DHAVE_STDINT_H -DHAVE_STDLIB_H # ugh... + +# lzma +LZMA = $(CHDR)/deps/lzma-19.00 +LZMA_OBJS += $(LZMA)/src/CpuArch.o $(LZMA)/src/Alloc.o $(LZMA)/src/LzmaEnc.o +LZMA_OBJS += $(LZMA)/src/Sort.o $(LZMA)/src/LzmaDec.o $(LZMA)/src/LzFind.o +LZMA_OBJS += $(LZMA)/src/Delta.o +$(LZMA_OBJS): CFLAGS += -D_7ZIP_ST + +OBJS += $(CHDR_OBJS) $(FLAC_OBJS) $(LZMA_OBJS) +CHDR_I = $(shell find $(CHDR) -name 'include') +CFLAGS += $(patsubst %, -I%, $(CHDR_I)) # tsk... endif ifeq "$(PLATFORM_ZLIB)" "1" diff --git a/Makefile.libretro b/Makefile.libretro index a7ef0085..e1d4414d 100644 --- a/Makefile.libretro +++ b/Makefile.libretro @@ -564,8 +564,6 @@ asm_32xdraw = 0 asm_32xmemory = 0 endif -#HAVE_LIBCHDR = 1 - CFLAGS += $(fpic) ifeq ($(findstring Haiku,$(shell uname -a)),) diff --git a/configure b/configure index df0a61b1..32ff0b44 100755 --- a/configure +++ b/configure @@ -372,9 +372,10 @@ if check_libavcodec; then esac fi -if check_libchdr; then - have_libchdr="yes" -fi +#if check_libchdr; then +# have_libchdr="yes" +# MAIN_LDLIBS="-lchdr $MAIN_LDLIBS" +#fi # find what audio support we can compile if [ "x$sound_drivers" = "x" ]; then @@ -426,7 +427,7 @@ echo "C compiler flags $CFLAGS" echo "libraries $MAIN_LDLIBS" echo "linker flags $LDFLAGS" echo "libavcodec (mp3) $have_libavcodec" -echo "libchdr $have_libchdr" +#echo "libchdr $have_libchdr" # echo "ARMv7 optimizations $have_armv7" echo "# Automatically generated by configure" > $config_mak diff --git a/pico/cart.c b/pico/cart.c index 702947c5..81fc7fb0 100644 --- a/pico/cart.c +++ b/pico/cart.c @@ -9,8 +9,6 @@ #include "pico_int.h" #include -#include -#include #ifdef USE_LIBRETRO_VFS #include "file_stream_transforms.h" @@ -21,6 +19,9 @@ #include "libchdr/cdrom.h" #endif +#include +#include + static int rom_alloc_size; static const char *rom_exts[] = { "bin", "gen", "smd", "iso", "sms", "gg", "sg" }; diff --git a/pico/cd/libchdr b/pico/cd/libchdr new file mode 160000 index 00000000..cecbe84e --- /dev/null +++ b/pico/cd/libchdr @@ -0,0 +1 @@ +Subproject commit cecbe84eb7ee1b0e5e558d15c2882a9d9be37794 diff --git a/platform/psp/emu.c b/platform/psp/emu.c index 179bf960..fa32175a 100644 --- a/platform/psp/emu.c +++ b/platform/psp/emu.c @@ -754,7 +754,7 @@ void emu_handle_resume(void) mp3_reopen_file(); #if 0 // TODO - if (!(Pico_mcd->s68k_regs[0x36] & 1)/* && (Pico_mcd->scd.Status_CDC & 1)*/) + if (!(Pico_mcd->s68k_regs[0x36] & 1)) cdd_change_track(cdd.index, cdd.lba); #endif } diff --git a/platform/psp/mp3.c b/platform/psp/mp3.c index cc4fc1be..dc948ed6 100644 --- a/platform/psp/mp3.c +++ b/platform/psp/mp3.c @@ -452,24 +452,6 @@ void mp3_update(int *buffer, int length, int stereo) } -int mp3_get_offset(void) // 0-1023 -{ - unsigned int offs1024 = 0; - int cdda_on; - - cdda_on = (PicoIn.AHW & PAHW_MCD) && (PicoIn.opt & POPT_EN_MCD_CDDA) && !(Pico_mcd->s68k_regs[0x36] & 1) && - /* TODO (Pico_mcd->scd.Status_CDC & 1) &&*/ mp3_handle >= 0; - - if (cdda_on) { - offs1024 = mp3_src_pos << 7; - offs1024 /= mp3_src_size >> 3; - } - lprintf("offs1024=%u (%i/%i)\n", offs1024, mp3_src_pos, mp3_src_size); - - return offs1024; -} - - void mp3_reopen_file(void) { if (mp3_fname == NULL) return; diff --git a/platform/psp/plat.c b/platform/psp/plat.c index 86b82a82..b1e7c612 100644 --- a/platform/psp/plat.c +++ b/platform/psp/plat.c @@ -326,3 +326,14 @@ int _flush_cache (char *addr, const int size, const int op) sceKernelIcacheInvalidateRange(addr, size); return 0; } + +/* stubs for libflac (embedded in libchdr) */ +int chown(const char *pathname, uid_t owner, gid_t group) { return -1; } +int chmod(const char *pathname, mode_t mode) { return -1; } +int utime(const char *filename, const struct utimbuf *times) { return -1; } +int fseeko64(FILE *stream, _off64_t offset, int whence) + { return fseeko(stream, offset, whence); } +_off64_t ftello64(FILE *stream) + { return ftello(stream); } +int posix_memalign(void **memptr, size_t alignment, size_t size) + { *memptr = memalign(alignment, size); return 0; } -- 2.39.2