Add cdrom.bgm.c and use it when DRIFILE_BGM exists

This enables BGM playback in the download edition of Daiakuji, where S*
commands are plumbed to the music system (*BA.ald).
This commit is contained in:
kichikuou
2023-01-28 13:06:38 +09:00
parent b1ac106057
commit 4785c8c77c
6 changed files with 94 additions and 11 deletions
+1
View File
@@ -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")
+6 -5
View File
@@ -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;
}
+4 -3
View File
@@ -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__ */
+72
View File
@@ -0,0 +1,72 @@
/*
* cdrom.bgm.c CD->bgm bridge
*
* Copyright (C) 2023 <KichikuouChrome@gmail.com>
*
* 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 <stdio.h>
#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
};
+2
View File
@@ -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
+9 -3
View File
@@ -25,6 +25,7 @@
#include <string.h>
#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;