diff options
Diffstat (limited to 'fmdriver')
-rw-r--r-- | fmdriver/fmdriver.h | 18 | ||||
-rw-r--r-- | fmdriver/fmdriver_fmp.c | 55 | ||||
-rw-r--r-- | fmdriver/fmdriver_fmp.h | 6 | ||||
-rw-r--r-- | fmdriver/fmdriver_pmd.c | 12 |
4 files changed, 89 insertions, 2 deletions
diff --git a/fmdriver/fmdriver.h b/fmdriver/fmdriver.h index b31c31e..ba36c3e 100644 --- a/fmdriver/fmdriver.h +++ b/fmdriver/fmdriver.h @@ -89,9 +89,23 @@ struct fmdriver_work { const struct ppz8_functbl *ppz8_functbl; struct ppz8 *ppz8; + // if false, 3 line comment + // if true, PMD memo mode + bool comment_mode_pmd; + // CP932 encoded - //const char *title; - char comment[3][FMDRIVER_TITLE_BUFLEN]; + // may contain ANSI escape sequences + // if !comment_mode_pmd: + // three lines, 0 <= line < 3 + // if comment_mode_pmd: + // line 0: #Title + // line 1: #Composer + // line 2: #Arranger + // line 3: #Memo 1st line + // : + // line n: NULL + const char *(*get_comment)(struct fmdriver_work *work, int line); + // only single-byte uppercase cp932 char filename[FMDRIVER_TITLE_BUFLEN]; // always 8 characters and pad with ' ' diff --git a/fmdriver/fmdriver_fmp.c b/fmdriver/fmdriver_fmp.c index c57b975..54f6753 100644 --- a/fmdriver/fmdriver_fmp.c +++ b/fmdriver/fmdriver_fmp.c @@ -1,5 +1,6 @@ #include "fmdriver_fmp.h"
#include "fmdriver_common.h"
+#include <string.h>
static uint8_t fmp_rand71(struct driver_fmp *fmp) {
// on real PC-98, read from I/O port 0x71 (8253 Timer)
@@ -3200,6 +3201,48 @@ static void fmp_opna_interrupt(struct fmdriver_work *work) { }
}
+static void fmp_title(
+ struct fmdriver_work *work,
+ struct driver_fmp *fmp,
+ uint16_t offset) {
+ int l = 0;
+ int li = 0;
+ for (int si = 0;; si++) {
+ if (l >= 3) {
+ // Z8X
+ fmp->pdzf.mode = 1;
+ return;
+ }
+ if ((offset + si) >= fmp->datalen) {
+ fmp->comment[l][0] = 0;
+ return;
+ }
+ if (li >= FMP_COMMENT_BUFLEN) {
+ fmp->comment[l][0] = 0;
+ return;
+ }
+ uint8_t c = fmp->data[offset+si];
+ if (c == '\r') {
+ continue;
+ } else if (c == '\n') {
+ fmp->comment[l][li] = 0;
+ li = 0;
+ l++;
+ } else {
+ fmp->comment[l][li] = c;
+ if (!c) return;
+ li++;
+ }
+ }
+}
+
+static void fmp_check_pdzf(struct driver_fmp *fmp) {
+ for (int l = 0; l < 3; l++) {
+ if (strstr((const char *)fmp->comment[l], "using PDZF")) fmp->pdzf.mode = 2;
+ }
+}
+
+/*
// copy title string (CP932) to fmdriver_work struct,
// and detect which PDZF(/Z8X) mode to use
static void fmp_title(struct fmdriver_work *work,
@@ -3289,6 +3332,7 @@ static void fmp_title(struct fmdriver_work *work, }
}
}
+*/
bool fmp_load(struct driver_fmp *fmp,
uint8_t *data, uint16_t datalen)
@@ -3525,8 +3569,19 @@ bool fmp_load(struct driver_fmp *fmp, return true;
}
+static const char *fmp_get_comment(struct fmdriver_work *work, int line) {
+ if (line < 0) return 0;
+ if (line >= 3) return 0;
+ struct driver_fmp *fmp = work->driver;
+ if (!fmp->comment[line][0]) return 0;
+ return (const char *)fmp->comment[line];
+}
+
void fmp_init(struct fmdriver_work *work, struct driver_fmp *fmp) {
fmp_title(work, fmp, read16le(fmp->data)+4);
+ fmp_check_pdzf(fmp);
+ work->comment_mode_pmd = false;
+ work->get_comment = fmp_get_comment;
fmp_struct_init(work, fmp);
fmp_init_parts(work, fmp);
uint16_t fmtoneptr = fmp->datainfo.fmtoneptr;
diff --git a/fmdriver/fmdriver_fmp.h b/fmdriver/fmdriver_fmp.h index ead8074..eb89b0b 100644 --- a/fmdriver/fmdriver_fmp.h +++ b/fmdriver/fmdriver_fmp.h @@ -39,6 +39,10 @@ enum { }; enum { + FMP_COMMENT_BUFLEN = 256, +}; + +enum { FMP_DATA_FM_1, FMP_DATA_FM_2, FMP_DATA_FM_3, @@ -536,6 +540,8 @@ struct driver_fmp { } rhythm[2]; uint8_t rhythm_current_note; } pdzf; + + uint8_t comment[3][FMP_COMMENT_BUFLEN]; }; // first: call fmp_load with zero_initialized struct driver_fmp and data diff --git a/fmdriver/fmdriver_pmd.c b/fmdriver/fmdriver_pmd.c index a57a916..343152b 100644 --- a/fmdriver/fmdriver_pmd.c +++ b/fmdriver/fmdriver_pmd.c @@ -5872,16 +5872,27 @@ void pmd_filenamecopy(char *dest, const char *src) { dest[0] = 0; } +static const char *pmd_get_comment(struct fmdriver_work *work, int line) { + struct driver_pmd *pmd = work->driver; + if (line < 0) return 0; + const char *str = pmd_get_memo(pmd, line + 1); + if (str && !*str) return 0; + return str; +} + void pmd_init(struct fmdriver_work *work, struct driver_pmd *pmd) { // TODO: reset ppz8 // 0f99 work->driver = pmd; + work->comment_mode_pmd = true; + work->get_comment = pmd_get_comment; pmd_reset_opna(work, pmd); pmd_reset_timer(work, pmd); pmd->playing = true; work->driver_opna_interrupt = pmd_opna_interrupt; + /* static const int memotable[3] = {1, 4, 5}; for (int i = 0; i < 3; i++) { const char *title = pmd_get_memo(pmd, memotable[i]); @@ -5894,6 +5905,7 @@ void pmd_init(struct fmdriver_work *work, } work->comment[i][c] = 0; } + */ const char *pcmfile = pmd_get_memo(pmd, -2); if (pcmfile) { pmd_filenamecopy(pmd->ppzfile, pcmfile); |