diff --git a/CMakeLists.txt b/CMakeLists.txt index 62dddd0..15351bf 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -110,6 +110,7 @@ endif() # CDROM +list(APPEND SRC_CDROM cdrom.bgm.c) if (CMAKE_SYSTEM_NAME STREQUAL "Linux") list(APPEND SRC_CDROM cdrom.Linux.c) list(APPEND SUMMARY_CDROM "Linux ioctl") diff --git a/src/ald_manager.c b/src/ald_manager.c index 702f758..33859c6 100644 --- a/src/ald_manager.c +++ b/src/ald_manager.c @@ -36,11 +36,6 @@ static drifiles *dri[DRIFILETYPEMAX]; /* cache handler for dri file */ static cacher *cacheid; -/* - * static maethods -*/ -static void ald_free(dridata *dfile); - /* * free dridata * dfile: dridata to be free @@ -109,3 +104,9 @@ void ald_init(int type, const char **file, int cnt, boolean use_mmap) { cacheid = cache_new(ald_free); } } + +int ald_get_maxno(DRIFILETYPE type) { + if (type >= DRIFILETYPEMAX || !dri[type]) + return 0; + return dri[type]->nr_files; +} diff --git a/src/ald_manager.h b/src/ald_manager.h index ceefeb0..eea99eb 100644 --- a/src/ald_manager.h +++ b/src/ald_manager.h @@ -38,9 +38,10 @@ typedef enum { DRIFILE_BGM =6 /* stream music data */ } DRIFILETYPE; -extern void ald_init(int type, const char **file, int cnt, boolean use_mmap); -extern dridata *ald_getdata(DRIFILETYPE type, int no); -extern void ald_freedata(dridata *data); +void ald_init(int type, const char **file, int cnt, boolean use_mmap); +dridata *ald_getdata(DRIFILETYPE type, int no); +void ald_freedata(dridata *data); +int ald_get_maxno(DRIFILETYPE type); #endif /* !__ALD_MANAGER__ */ diff --git a/src/cdrom.bgm.c b/src/cdrom.bgm.c new file mode 100644 index 0000000..2091bef --- /dev/null +++ b/src/cdrom.bgm.c @@ -0,0 +1,72 @@ +/* + * cdrom.bgm.c CD->bgm bridge + * + * Copyright (C) 2023 + * + * This program 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 2 of the License, or + * (at your option) any later version. + * + * This program 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 this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + */ + +#include + +#include "cdrom.h" +#include "music.h" + +static int current_track; + +static int cdrom_bgm_init(char *dev) { + return OK; +} + +static int cdrom_bgm_exit(void) { + return OK; +} + +static int cdrom_bgm_reset(void) { + return OK; +} + +static int cdrom_bgm_start(int trk, int loop) { + if (musbgm_play(trk, 0, 100) != OK) + return NG; + current_track = trk; + return OK; +} + +static int cdrom_bgm_stop(void) { + return musbgm_stop(current_track, 0); +} + +static int cdrom_bgm_getPlayingInfo(cd_time *info) { + int t = musbgm_getpos(current_track); // in 10ms + if (!t) + return NG; + info->t = current_track; + info->m = t / (60*100); t %= (60*100); + info->s = t / 100; t %= 100; + info->f = t * CD_FPS / 100; + return OK; +} + +cdromdevice_t cdrom_bgm = { + cdrom_bgm_init, + cdrom_bgm_exit, + cdrom_bgm_reset, + cdrom_bgm_start, + cdrom_bgm_stop, + cdrom_bgm_getPlayingInfo, + NULL, + NULL +}; diff --git a/src/cdrom.h b/src/cdrom.h index 5122f96..c3584f5 100644 --- a/src/cdrom.h +++ b/src/cdrom.h @@ -49,6 +49,8 @@ struct _cdromdevice { }; typedef struct _cdromdevice cdromdevice_t; +extern cdromdevice_t cdrom_bgm; + extern cdromdevice_t *cd_init(const char *dev); #define CD_FPS 75 diff --git a/src/music_cdrom.c b/src/music_cdrom.c index 2116291..5abae18 100644 --- a/src/music_cdrom.c +++ b/src/music_cdrom.c @@ -25,6 +25,7 @@ #include #include "portab.h" +#include "ald_manager.h" #include "music_private.h" #include "music_cdrom.h" #include "cdrom.h" @@ -37,9 +38,14 @@ void muscd_set_devicename(char *name) { } int muscd_init(void) { - prv.cddev = cd_init(dev); - if (!prv.cddev) { - return NG; + // In the download edition of Daiakuji, SS command plays music from *BA.ald. + if (ald_get_maxno(DRIFILE_BGM) > 0) { + prv.cddev = &cdrom_bgm; + } else { + prv.cddev = cd_init(dev); + if (!prv.cddev) { + return NG; + } } prv.cddev->init(dev); prv.cd_current_track = 0;