|
|
| version 1.12, 2003/10/24 10:58:47 | version 1.17, 2003/11/15 07:10:02 |
|---|---|
| Line 12 | Line 12 |
| #include "pc9861k.h" | #include "pc9861k.h" |
| #include "mpu98ii.h" | #include "mpu98ii.h" |
| #include "board14.h" | #include "board14.h" |
| #include "amd98.h" | |
| #include "bios.h" | #include "bios.h" |
| #include "vram.h" | #include "vram.h" |
| #include "palettes.h" | #include "palettes.h" |
| Line 28 | Line 29 |
| #include "keydisp.h" | #include "keydisp.h" |
| #if defined(MACOS) | |
| #define CRLITERAL "\r" | |
| #define CRCONST str_cr | |
| #elif defined(WIN32) || defined(X11) || defined(SLZAURUS) | |
| #define CRLITERAL "\n" | |
| #define CRCONST str_lf | |
| #else | |
| #define CRLITERAL "\r\n" | |
| #define CRCONST str_crlf | |
| #endif | |
| typedef struct { | typedef struct { |
| char name[16]; | char name[16]; |
| char vername[28]; | char vername[28]; |
| Line 50 enum { | Line 63 enum { |
| NP2FLAG_EVT, | NP2FLAG_EVT, |
| NP2FLAG_GIJ, | NP2FLAG_GIJ, |
| NP2FLAG_FM, | NP2FLAG_FM, |
| NP2FLAG_MIDI, | NP2FLAG_COM, |
| NP2FLAG_DISK | NP2FLAG_DISK |
| }; | }; |
| Line 89 typedef struct { | Line 102 typedef struct { |
| static void err_append(ERR_BUF *e, char *buf) { | static void err_append(ERR_BUF *e, char *buf) { |
| int len; | |
| if ((e) && (buf)) { | if ((e) && (buf)) { |
| if (e->buf) { | if (e->buf) { |
| int len; | |
| len = strlen(buf); | len = strlen(buf); |
| if (e->remain >= len) { | if (e->remain >= len) { |
| CopyMemory(e->buf, buf, len); | CopyMemory(e->buf, buf, len); |
| Line 613 static int flagsave_gij(NP2FFILE f, cons | Line 627 static int flagsave_gij(NP2FFILE f, cons |
| ret = flagsave_create(f, t); | ret = flagsave_create(f, t); |
| if (ret != NP2FLAG_FAILURE) { | if (ret != NP2FLAG_FAILURE) { |
| for (i=0; i<2; i++) { | for (i=0; i<2; i++) { |
| fnt = font + ((0x56 + (i << 7)) << 4); | fnt = fontrom + ((0x56 + (i << 7)) << 4); |
| for (j=0; j<0x80; j++) { | for (j=0; j<0x80; j++) { |
| ret |= flagsave_save(f, fnt, 32); | ret |= flagsave_save(f, fnt, 32); |
| fnt += 0x1000; | fnt += 0x1000; |
| Line 633 static int flagload_gij(NP2FFILE f, cons | Line 647 static int flagload_gij(NP2FFILE f, cons |
| ret = 0; | ret = 0; |
| for (i=0; i<2; i++) { | for (i=0; i<2; i++) { |
| fnt = font + ((0x56 + (i << 7)) << 4); | fnt = fontrom + ((0x56 + (i << 7)) << 4); |
| for (j=0; j<0x80; j++) { | for (j=0; j<0x80; j++) { |
| ret |= flagload_load(f, fnt, 32); | ret |= flagload_load(f, fnt, 32); |
| fnt += 0x1000; | fnt += 0x1000; |
| Line 654 enum { | Line 668 enum { |
| FLAG_FM2B = 0x0010, | FLAG_FM2B = 0x0010, |
| FLAG_PSG1 = 0x0020, | FLAG_PSG1 = 0x0020, |
| FLAG_PSG2 = 0x0040, | FLAG_PSG2 = 0x0040, |
| FLAG_RHYTHM = 0x0080, | FLAG_PSG3 = 0x0080, |
| FLAG_ADPCM = 0x0100, | FLAG_RHYTHM = 0x0100, |
| FLAG_PCM86 = 0x0200, | FLAG_ADPCM = 0x0200, |
| FLAG_CS4231 = 0x0400 | FLAG_PCM86 = 0x0400, |
| FLAG_CS4231 = 0x0800 | |
| }; | }; |
| typedef struct { | typedef struct { |
| Line 710 static int flagsave_fm(NP2FFILE f, const | Line 725 static int flagsave_fm(NP2FFILE f, const |
| FLAG_PSG1 | FLAG_RHYTHM | FLAG_ADPCM; | FLAG_PSG1 | FLAG_RHYTHM | FLAG_ADPCM; |
| break; | break; |
| case 0x80: | |
| saveflg = FLAG_PSG1 | FLAG_PSG2 | FLAG_PSG3; | |
| break; | |
| default: | default: |
| saveflg = 0; | saveflg = 0; |
| break; | break; |
| Line 738 static int flagsave_fm(NP2FFILE f, const | Line 757 static int flagsave_fm(NP2FFILE f, const |
| if (saveflg & FLAG_PSG2) { | if (saveflg & FLAG_PSG2) { |
| ret |= flagsave_save(f, &psg2.reg, sizeof(PSGREG)); | ret |= flagsave_save(f, &psg2.reg, sizeof(PSGREG)); |
| } | } |
| if (saveflg & FLAG_PSG3) { | |
| ret |= flagsave_save(f, &psg3.reg, sizeof(PSGREG)); | |
| } | |
| if (saveflg & FLAG_ADPCM) { | if (saveflg & FLAG_ADPCM) { |
| ret |= flagsave_save(f, &adpcm, sizeof(adpcm)); | ret |= flagsave_save(f, &adpcm, sizeof(adpcm)); |
| } | } |
| Line 752 static int flagsave_fm(NP2FFILE f, const | Line 774 static int flagsave_fm(NP2FFILE f, const |
| return(ret); | return(ret); |
| } | } |
| static void play_fmreg(BYTE num) { | static void play_fmreg(BYTE num, UINT reg) { |
| UINT chbase; | UINT chbase; |
| UINT reg; | |
| UINT i; | UINT i; |
| chbase = num * 3; | chbase = num * 3; |
| reg = num * 0x100; | |
| for (i=0x30; i<0xa0; i++) { | for (i=0x30; i<0xa0; i++) { |
| opngen_setreg((BYTE)chbase, (BYTE)i, opn.reg[reg + i]); | opngen_setreg((BYTE)chbase, (BYTE)i, opn.reg[reg + i]); |
| } | } |
| Line 785 static int flagload_fm(NP2FFILE f, const | Line 805 static int flagload_fm(NP2FFILE f, const |
| int ret; | int ret; |
| UINT saveflg; | UINT saveflg; |
| OPNKEY opnkey; | OPNKEY opnkey; |
| UINT fmreg1a; | |
| UINT fmreg1b; | |
| UINT fmreg2a; | |
| UINT fmreg2b; | |
| opngen_reset(); | opngen_reset(); |
| psggen_reset(&psg1); | psggen_reset(&psg1); |
| Line 798 static int flagload_fm(NP2FFILE f, const | Line 822 static int flagload_fm(NP2FFILE f, const |
| ret = flagload_load(f, &usesound, sizeof(usesound)); | ret = flagload_load(f, &usesound, sizeof(usesound)); |
| fmboard_reset((BYTE)usesound); | fmboard_reset((BYTE)usesound); |
| fmreg1a = 0x000; | |
| fmreg1b = 0x100; | |
| fmreg2a = 0x200; | |
| fmreg2b = 0x300; | |
| switch(usesound) { | switch(usesound) { |
| case 0x01: | case 0x01: |
| saveflg = FLAG_MG; | saveflg = FLAG_MG; |
| Line 815 static int flagload_fm(NP2FFILE f, const | Line 843 static int flagload_fm(NP2FFILE f, const |
| case 0x06: | case 0x06: |
| saveflg = FLAG_FM1A | FLAG_FM1B | FLAG_FM2A | FLAG_PSG1 | | saveflg = FLAG_FM1A | FLAG_FM1B | FLAG_FM2A | FLAG_PSG1 | |
| FLAG_PSG2 | FLAG_RHYTHM | FLAG_PCM86; | FLAG_PSG2 | FLAG_RHYTHM | FLAG_PCM86; |
| fmreg1a = 0x200; // 逆転してるのん… | |
| fmreg1b = 0x000; | |
| fmreg2a = 0x100; | |
| break; | break; |
| case 0x08: | case 0x08: |
| Line 837 static int flagload_fm(NP2FFILE f, const | Line 868 static int flagload_fm(NP2FFILE f, const |
| FLAG_PSG1 | FLAG_RHYTHM | FLAG_ADPCM; | FLAG_PSG1 | FLAG_RHYTHM | FLAG_ADPCM; |
| break; | break; |
| case 0x80: | |
| saveflg = FLAG_PSG1 | FLAG_PSG2 | FLAG_PSG3; | |
| break; | |
| default: | default: |
| saveflg = 0; | saveflg = 0; |
| break; | break; |
| Line 863 static int flagload_fm(NP2FFILE f, const | Line 898 static int flagload_fm(NP2FFILE f, const |
| if (saveflg & FLAG_PSG2) { | if (saveflg & FLAG_PSG2) { |
| ret |= flagload_load(f, &psg2.reg, sizeof(PSGREG)); | ret |= flagload_load(f, &psg2.reg, sizeof(PSGREG)); |
| } | } |
| if (saveflg & FLAG_PSG3) { | |
| ret |= flagload_load(f, &psg3.reg, sizeof(PSGREG)); | |
| } | |
| if (saveflg & FLAG_ADPCM) { | if (saveflg & FLAG_ADPCM) { |
| ret |= flagload_load(f, &adpcm, sizeof(adpcm)); | ret |= flagload_load(f, &adpcm, sizeof(adpcm)); |
| } | } |
| Line 886 static int flagload_fm(NP2FFILE f, const | Line 924 static int flagload_fm(NP2FFILE f, const |
| } | } |
| if (saveflg & FLAG_FM1A) { | if (saveflg & FLAG_FM1A) { |
| play_fmreg(0); | play_fmreg(0, fmreg1a); |
| } | } |
| if (saveflg & FLAG_FM1B) { | if (saveflg & FLAG_FM1B) { |
| play_fmreg(1); | play_fmreg(1, fmreg1b); |
| } | } |
| if (saveflg & FLAG_FM2A) { | if (saveflg & FLAG_FM2A) { |
| play_fmreg(2); | play_fmreg(2, fmreg2a); |
| } | } |
| if (saveflg & FLAG_FM2B) { | if (saveflg & FLAG_FM2B) { |
| play_fmreg(3); | play_fmreg(3, fmreg2b); |
| } | } |
| if (saveflg & FLAG_PSG1) { | if (saveflg & FLAG_PSG1) { |
| play_psgreg(&psg1); | play_psgreg(&psg1); |
| Line 903 static int flagload_fm(NP2FFILE f, const | Line 941 static int flagload_fm(NP2FFILE f, const |
| if (saveflg & FLAG_PSG2) { | if (saveflg & FLAG_PSG2) { |
| play_psgreg(&psg2); | play_psgreg(&psg2); |
| } | } |
| if (saveflg & FLAG_PSG3) { | |
| play_psgreg(&psg3); | |
| } | |
| (void)t; | (void)t; |
| return(ret); | return(ret); |
| } | } |
| Line 917 typedef struct { | Line 958 typedef struct { |
| DOSTIME time; | DOSTIME time; |
| } STATDISK; | } STATDISK; |
| static const char str_fddx[] = "FDD%u"; | |
| static const char str_sasix[] = "SASI%u"; | |
| static const char str_scsix[] = "SCSI%u"; | |
| static const char str_updated[] = "%s: updated" CRLITERAL; | |
| static const char str_notfound[] = "%s: not found" CRLITERAL; | |
| static int disksave(NP2FFILE f, const char *path, int readonly) { | static int disksave(NP2FFILE f, const char *path, int readonly) { |
| STATDISK st; | STATDISK st; |
| Line 975 static int diskcheck(NP2FFILE f, const c | Line 1022 static int diskcheck(NP2FFILE f, const c |
| if ((memcmp(&st.date, &date, sizeof(date))) || | if ((memcmp(&st.date, &date, sizeof(date))) || |
| (memcmp(&st.time, &time, sizeof(time)))) { | (memcmp(&st.time, &time, sizeof(time)))) { |
| ret |= NP2FLAG_DISKCHG; | ret |= NP2FLAG_DISKCHG; |
| SPRINTF(buf, "%s: updated\n", name); | SPRINTF(buf, str_updated, name); |
| err_append(e, buf); | err_append(e, buf); |
| } | } |
| } | } |
| else { | else { |
| ret |= NP2FLAG_DISKCHG; | ret |= NP2FLAG_DISKCHG; |
| SPRINTF(buf, "%s: not found\n", name); | SPRINTF(buf, str_notfound, name); |
| err_append(e, buf); | err_append(e, buf); |
| } | } |
| } | } |
| Line 996 static int flagcheck_disk(NP2FFILE f, co | Line 1043 static int flagcheck_disk(NP2FFILE f, co |
| ret = 0; | ret = 0; |
| for (i=0; i<4; i++) { | for (i=0; i<4; i++) { |
| SPRINTF(buf, "FDD%d", i+1); | SPRINTF(buf, str_fddx, i+1); |
| ret |= diskcheck(f, buf, e); | ret |= diskcheck(f, buf, e); |
| } | } |
| sxsi_flash(); | sxsi_flash(); |
| for (i=0; i<2; i++) { | for (i=0; i<2; i++) { |
| SPRINTF(buf, "SASI%u", i+1); | SPRINTF(buf, str_sasix, i+1); |
| ret |= diskcheck(f, buf, e); | ret |= diskcheck(f, buf, e); |
| } | } |
| for (i=0; i<2; i++) { | for (i=0; i<2; i++) { |
| SPRINTF(buf, "SCSI%d", i+1); | SPRINTF(buf, str_scsix, i+1); |
| ret |= diskcheck(f, buf, e); | ret |= diskcheck(f, buf, e); |
| } | } |
| (void)t; | (void)t; |
| Line 1047 static int flagload_disk(NP2FFILE f, con | Line 1094 static int flagload_disk(NP2FFILE f, con |
| // ----- | // ----- |
| #ifdef _MIDICH | static int flagsave_com(NP2FFILE f, const STENTRY *t) { |
| static int flagsave_midi(NP2FFILE f, const STENTRY *t) { | |
| UINT device; | UINT device; |
| COMMNG cm; | COMMNG cm; |
| int ret; | int ret; |
| _MIDICH mch[16]; | COMFLAG flag; |
| device = (UINT)t->arg1; | device = (UINT)t->arg1; |
| switch(device) { | switch(device) { |
| Line 1070 static int flagsave_midi(NP2FFILE f, con | Line 1116 static int flagsave_midi(NP2FFILE f, con |
| break; | break; |
| } | } |
| ret = NP2FLAG_SUCCESS; | ret = NP2FLAG_SUCCESS; |
| if ((cm != NULL) && (cm->msg(cm, COMMSG_MIDISTATGET, (long)mch))) { | if (cm) { |
| ret = flagsave_create(f, t); | flag = (COMFLAG)cm->msg(cm, COMMSG_GETFLAG, 0); |
| if (ret != NP2FLAG_FAILURE) { | if (flag) { |
| ret |= flagsave_save(f, mch, sizeof(mch)); | ret = flagsave_create(f, t); |
| ret |= flagsave_close(f); | if (ret != NP2FLAG_FAILURE) { |
| ret |= flagsave_save(f, flag, flag->size); | |
| ret |= flagsave_close(f); | |
| } | |
| _MFREE(flag); | |
| } | } |
| } | } |
| return(ret); | return(ret); |
| } | } |
| static int flagload_midi(NP2FFILE f, const STENTRY *t) { | static int flagload_com(NP2FFILE f, const STENTRY *t) { |
| _MIDICH mch[16]; | UINT device; |
| UINT device; | COMMNG cm; |
| COMMNG cm; | int ret; |
| int ret; | _COMFLAG fhdr; |
| COMFLAG flag; | |
| ret = flagload_load(f, mch, sizeof(mch)); | ret = flagload_load(f, &fhdr, sizeof(fhdr)); |
| if (ret != NP2FLAG_FAILURE) { | if (ret != NP2FLAG_SUCCESS) { |
| device = (UINT)t->arg1; | goto flcom_err1; |
| switch(device) { | } |
| case 0: | if (fhdr.size < sizeof(fhdr)) { |
| commng_destroy(cm_mpu98); | goto flcom_err1; |
| cm = commng_create(COMCREATE_MPU98II); | } |
| cm_mpu98 = cm; | flag = (COMFLAG)_MALLOC(fhdr.size, "com stat flag"); |
| break; | if (flag == NULL) { |
| goto flcom_err1; | |
| } | |
| CopyMemory(flag, &fhdr, sizeof(fhdr)); | |
| ret |= flagload_load(f, flag + 1, fhdr.size - sizeof(fhdr)); | |
| if (ret != NP2FLAG_SUCCESS) { | |
| goto flcom_err2; | |
| } | |
| case 1: | device = (UINT)t->arg1; |
| commng_destroy(cm_rs232c); | switch(device) { |
| cm = commng_create(COMCREATE_SERIAL); | case 0: |
| cm_rs232c = cm; | commng_destroy(cm_mpu98); |
| break; | cm = commng_create(COMCREATE_MPU98II); |
| cm_mpu98 = cm; | |
| break; | |
| default: | case 1: |
| cm = NULL; | commng_destroy(cm_rs232c); |
| break; | cm = commng_create(COMCREATE_SERIAL); |
| } | cm_rs232c = cm; |
| if (cm) { | break; |
| cm->msg(cm, COMMSG_MIDISTATSET, (long)mch); | |
| } | default: |
| cm = NULL; | |
| break; | |
| } | } |
| if (cm) { | |
| cm->msg(cm, COMMSG_SETFLAG, (long)flag); | |
| } | |
| flcom_err2: | |
| _MFREE(flag); | |
| flcom_err1: | |
| return(ret); | return(ret); |
| } | } |
| #endif | |
| // ---- | // ---- |
| Line 1194 int statsave_save(const char *filename) | Line 1263 int statsave_save(const char *filename) |
| ret |= flagsave_disk(&f, &np2tbl[i]); | ret |= flagsave_disk(&f, &np2tbl[i]); |
| break; | break; |
| #if defined(MIDICH) | case NP2FLAG_COM: |
| case NP2FLAG_MIDI: | ret |= flagsave_com(&f, &np2tbl[i]); |
| ret |= flagsave_midi(&f, &np2tbl[i]); | |
| break; | break; |
| #endif | |
| } | } |
| } | } |
| flagclose(&f); | flagclose(&f); |
| Line 1254 int statsave_check(const char *filename, | Line 1321 int statsave_check(const char *filename, |
| case NP2FLAG_EXT: | case NP2FLAG_EXT: |
| case NP2FLAG_EVT: | case NP2FLAG_EVT: |
| case NP2FLAG_GIJ: | case NP2FLAG_GIJ: |
| #if defined(MIDICH) | case NP2FLAG_COM: |
| case NP2FLAG_MIDI: | |
| #endif | |
| ret |= flagcheck_veronly(&f, &np2tbl[i], &e); | ret |= flagcheck_veronly(&f, &np2tbl[i], &e); |
| break; | break; |
| Line 1357 int statsave_load(const char *filename) | Line 1422 int statsave_load(const char *filename) |
| ret |= flagload_disk(&f, &np2tbl[i]); | ret |= flagload_disk(&f, &np2tbl[i]); |
| break; | break; |
| #if defined(MIDICH) | case NP2FLAG_COM: |
| case NP2FLAG_MIDI: | ret |= flagload_com(&f, &np2tbl[i]); |
| ret |= flagload_midi(&f, &np2tbl[i]); | |
| break; | break; |
| #endif | |
| default: | default: |
| ret |= NP2FLAG_WARNING; | ret |= NP2FLAG_WARNING; |