--- np2/statsave.c 2004/02/03 08:24:40 1.35 +++ np2/statsave.c 2005/05/20 13:59:45 1.50 @@ -8,7 +8,9 @@ #include "cpucore.h" #include "pccore.h" #include "iocore.h" +#include "gdc_sub.h" #include "cbuscore.h" +#include "ideio.h" #include "sasiio.h" #include "scsiio.h" #include "pc9861k.h" @@ -29,6 +31,7 @@ #include "keydisp.h" #include "hostdrv.h" #include "calendar.h" +#include "keystat.h" #if defined(MACOS) #define CRCONST str_cr @@ -58,18 +61,19 @@ enum { STATFLAG_CGW, #endif STATFLAG_COM, - STATFLAG_DISK, STATFLAG_DMA, STATFLAG_EGC, STATFLAG_EPSON, STATFLAG_EVT, STATFLAG_EXT, + STATFLAG_FDD, STATFLAG_FM, STATFLAG_GIJ, #if defined(SUPPORT_HOSTDRV) STATFLAG_HDRV, #endif - STATFLAG_MEM + STATFLAG_MEM, + STATFLAG_SXSI }; typedef struct { @@ -93,45 +97,13 @@ extern COMMNG cm_mpu98; extern COMMNG cm_rs232c; typedef struct { - char *buf; + OEMCHAR *buf; int remain; } ERR_BUF; // ---- -// 関数ポインタを intに変更。 -static BOOL proc2num(void *func, const PROCTBL *tbl, int size) { - - int i; - - for (i=0; iproc) { - *(long *)func = (long)tbl->id; - return(SUCCESS); - } - tbl++; - } - return(FAILURE); -} - -static BOOL num2proc(void *func, const PROCTBL *tbl, int size) { - - int i; - - for (i=0; iid) { - *(long *)func = (long)tbl->proc; - return(SUCCESS); - } - tbl++; - } - return(FAILURE); -} - - -// ---- - enum { SFFILEH_WRITE = 0x0001, SFFILEH_BLOCK = 0x0002, @@ -143,15 +115,10 @@ typedef struct { UINT stat; FILEH fh; UINT secpos; - -// long pos; -// long bak; -// long next; NP2FHDR f; -// NP2FENT p; -} _NP2FFILE, *NP2FFILE, _SFFILEH, *SFFILEH; +} _SFFILEH, *SFFILEH; -static SFFILEH statflag_open(const char *filename, char *err, int errlen) { +static SFFILEH statflag_open(const OEMCHAR *filename, OEMCHAR *err, int errlen) { FILEH fh; SFFILEH ret; @@ -188,7 +155,7 @@ sfo_err1: static int statflag_closesection(SFFILEH sffh) { UINT leng; - BYTE zero[16]; + UINT8 zero[16]; if (sffh == NULL) { goto sfcs_err1; @@ -263,7 +230,7 @@ sfr_err: return(STATFLAG_FAILURE); } -static SFFILEH statflag_create(const char *filename) { +static SFFILEH statflag_create(const OEMCHAR *filename) { SFFILEH ret; FILEH fh; @@ -357,7 +324,7 @@ static void statflag_close(SFFILEH sffh) } } -void statflag_seterr(STFLAGH sfh, const char *str) { +void statflag_seterr(STFLAGH sfh, const OEMCHAR *str) { if ((sfh) && (sfh->errlen)) { milstr_ncat(sfh->err, str, sfh->errlen); @@ -366,173 +333,101 @@ void statflag_seterr(STFLAGH sfh, const } +// ---- function +// 関数ポインタを intに変更。 +static BRESULT proc2num(void *func, const PROCTBL *tbl, int size) { -#if 0 -static int flagopen(NP2FFILE f, const char *filename, ERR_BUF *e) { + int i; - if (f) { - f->fh = file_open(filename); - if (f->fh == FILEH_INVALID) { - return(STATFLAG_FAILURE); - } - if (file_read(f->fh, &f->f, sizeof(NP2FHDR)) - != sizeof(NP2FHDR)) { - file_close(f->fh); - return(STATFLAG_FAILURE); - } - f->pos = sizeof(NP2FHDR); - if (strcmp(f->f.name, np2flagdef.name)) { - file_close(f->fh); - return(STATFLAG_FAILURE); - } - if (strcmp(f->f.vername, np2flagdef.vername)) { -#if 1 - file_close(f->fh); - return(STATFLAG_FAILURE); -#else - return(STATFLAG_VERSION); // 他形式を読むのであれば… -#endif - } - if (f->f.ver != np2flagdef.ver) { -#if 1 - file_close(f->fh); - return(STATFLAG_FAILURE); -#else - return(STATFLAG_VERSION); // 他verを読むのであれば… -#endif + for (i=0; iproc) { + *(long *)func = (long)tbl->id; + return(SUCCESS); } - return(STATFLAG_SUCCESS); + tbl++; } - (void)e; - return(STATFLAG_FAILURE); + return(FAILURE); } -static int flagcreate(NP2FFILE f, const char *filename) { - - if (f) { - f->fh = file_create(filename); - if (f->fh == FILEH_INVALID) { - return(STATFLAG_FAILURE); - } - if (file_write(f->fh, &np2flagdef, sizeof(NP2FHDR)) - != sizeof(NP2FHDR)) { - file_close(f->fh); - return(STATFLAG_FAILURE); - } - f->pos = sizeof(NP2FHDR); - return(STATFLAG_SUCCESS); - } - return(STATFLAG_FAILURE); -} +static BRESULT num2proc(void *func, const PROCTBL *tbl, int size) { -static int flagload_create(NP2FFILE f) { + int i; - if (f) { - ZeroMemory(&f->p, sizeof(NP2FENT)); - if (f->pos & 15) { - f->pos += 15; - f->pos &= ~0xf; - if (file_seek(f->fh, f->pos, 0) != f->pos) { - return(STATFLAG_FAILURE); - } - } - if (file_read(f->fh, &f->p, sizeof(NP2FENT)) != sizeof(NP2FENT)) { - return(STATFLAG_FAILURE); + for (i=0; iid) { + *(long *)func = (long)tbl->proc; + return(SUCCESS); } - f->pos += sizeof(NP2FENT); - f->next = f->pos + f->p.size; - return(STATFLAG_SUCCESS); + tbl++; } - return(STATFLAG_FAILURE); + return(FAILURE); } -static int flagload_load(NP2FFILE f, void *buf, UINT size) { - if (f && buf && size && (file_read(f->fh, buf, size) == size)) { - f->pos += size; - return(STATFLAG_SUCCESS); - } - return(STATFLAG_FAILURE); -} +// ---- file -static int flagload_close(NP2FFILE f) { +typedef struct { + OEMCHAR path[MAX_PATH]; + UINT ftype; + int readonly; + DOSDATE date; + DOSTIME time; +} STATPATH; - if (file_seek(f->fh, f->next, 0) != f->next) { - return(STATFLAG_FAILURE); - } - f->pos = f->next; - return(STATFLAG_SUCCESS); -} +static const OEMCHAR str_updated[] = OEMTEXT("%s: updated"); +static const OEMCHAR str_notfound[] = OEMTEXT("%s: not found"); -static int flagsave_create(NP2FFILE f, const SFENTRY *t) { +static int statflag_writepath(STFLAGH sfh, const OEMCHAR *path, + UINT ftype, int readonly) { - if (f && t) { - int len; - ZeroMemory(&f->p, sizeof(NP2FENT)); - if (f->pos & 15) { - UINT rem; - rem = 16 - (f->pos & 15); - if (file_write(f->fh, &f->p, rem) != rem) { - return(STATFLAG_FAILURE); - } - f->pos += rem; - } - f->bak = f->pos; + STATPATH sp; + FILEH fh; - len = strlen(t->index); - if (len >= 10) { - len = 10; - } - if (len) { - CopyMemory(f->p.index, t->index, len); - } - f->p.ver = t->ver; - if (file_write(f->fh, &f->p, sizeof(NP2FENT)) != sizeof(NP2FENT)) { - return(STATFLAG_FAILURE); + ZeroMemory(&sp, sizeof(sp)); + if ((path) && (path[0])) { + file_cpyname(sp.path, path, NELEMENTS(sp.path)); + sp.ftype = ftype; + sp.readonly = readonly; + fh = file_open_rb(path); + if (fh != FILEH_INVALID) { + file_getdatetime(fh, &sp.date, &sp.time); + file_close(fh); } - f->pos += sizeof(NP2FENT); - return(STATFLAG_SUCCESS); } - return(STATFLAG_FAILURE); + return(statflag_write(sfh, &sp, sizeof(sp))); } -static int flagsave_save(NP2FFILE f, void *buf, UINT size) { - - if (f && buf && size && (file_write(f->fh, buf, size) == size)) { - f->pos += size; - f->p.size += size; - return(STATFLAG_SUCCESS); - } - return(STATFLAG_FAILURE); -} - -static int flagsave_close(NP2FFILE f) { - - if (!f) { - goto fs_closeerr; - } - if (file_seek(f->fh, f->bak, 0) != f->bak) { - goto fs_closeerr; - } - if (file_write(f->fh, &f->p, sizeof(NP2FENT)) != sizeof(NP2FENT)) { - goto fs_closeerr; - } - if (file_seek(f->fh, f->pos, 0) == f->pos) { - return(STATFLAG_SUCCESS); - } - -fs_closeerr: - return(STATFLAG_FAILURE); -} +static int statflag_checkpath(STFLAGH sfh, const OEMCHAR *devname) { -static void flagclose(NP2FFILE f) { + int ret; + STATPATH sp; + FILEH fh; + OEMCHAR buf[256]; + DOSDATE date; + DOSTIME time; - if (f) { - file_close(f->fh); + ret = statflag_read(sfh, &sp, sizeof(sp)); + if (sp.path[0]) { + fh = file_open_rb(sp.path); + if (fh != FILEH_INVALID) { + file_getdatetime(fh, &date, &time); + file_close(fh); + if ((memcmp(&sp.date, &date, sizeof(date))) || + (memcmp(&sp.time, &time, sizeof(time)))) { + ret |= STATFLAG_DISKCHG; + OEMSPRINTF(buf, str_updated, devname); + statflag_seterr(sfh, buf); + } + } + else { + ret |= STATFLAG_DISKCHG; + OEMSPRINTF(buf, str_notfound, devname); + statflag_seterr(sfh, buf); + } } + return(ret); } -#endif // ---- common @@ -718,7 +613,7 @@ static int nevent_write(STFLAGH sfh, int UINT i; ZeroMemory(&nit, sizeof(nit)); - for (i=0; i> 4]; } // 復元。 これ移動すること! - rhythm_update(&rhythm); adpcm_update(&adpcm); pcm86gen_update(); if (saveflg & FLAG_PCM86) { @@ -1093,139 +988,156 @@ static int flagload_fm(STFLAGH sfh, cons (void)t; return(ret); } +#endif -// ---- disk - -typedef struct { - char path[MAX_PATH]; - int readonly; - DOSDATE date; - DOSTIME time; -} STATDISK; +// ---- fdd -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"; -static const char str_notfound[] = "%s: not found"; +static const OEMCHAR str_fddx[] = OEMTEXT("FDD%u"); -static int disksave(STFLAGH sfh, const char *path, int readonly) { +static int flagsave_fdd(STFLAGH sfh, const SFENTRY *tbl) { - STATDISK st; - FILEH fh; + int ret; + UINT8 i; +const OEMCHAR *path; + UINT ftype; + int ro; - ZeroMemory(&st, sizeof(st)); - if ((path) && (path[0])) { - file_cpyname(st.path, path, sizeof(st.path)); - st.readonly = readonly; - fh = file_open_rb(path); - if (fh != FILEH_INVALID) { - file_getdatetime(fh, &st.date, &st.time); - file_close(fh); - } + ret = STATFLAG_SUCCESS; + for (i=0; i<4; i++) { + path = fdd_getfileex(i, &ftype, &ro); + ret |= statflag_writepath(sfh, path, ftype, ro); } - return(statflag_write(sfh, &st, sizeof(st))); + (void)tbl; + return(ret); } -static int flagsave_disk(STFLAGH sfh, const SFENTRY *tbl) { +static int flagcheck_fdd(STFLAGH sfh, const SFENTRY *tbl) { int ret; - BYTE i; + int i; + OEMCHAR buf[8]; - sxsi_flash(); ret = STATFLAG_SUCCESS; for (i=0; i<4; i++) { - ret |= disksave(sfh, fdd_diskname(i), fdd_diskprotect(i)); - } - for (i=0x00; i<0x02; i++) { - ret |= disksave(sfh, sxsi_getname(i), 0); - } - for (i=0x20; i<0x24; i++) { - ret |= disksave(sfh, sxsi_getname(i), 0); + OEMSPRINTF(buf, str_fddx, i+1); + ret |= statflag_checkpath(sfh, buf); } (void)tbl; return(ret); } -static int diskcheck(STFLAGH sfh, const char *name) { +static int flagload_fdd(STFLAGH sfh, const SFENTRY *tbl) { int ret; - FILEH fh; - STATDISK st; - char buf[256]; - DOSDATE date; - DOSTIME time; + UINT8 i; + STATPATH sp; - ret = statflag_read(sfh, &st, sizeof(st)); - if (st.path[0]) { - fh = file_open_rb(st.path); - if (fh != FILEH_INVALID) { - file_getdatetime(fh, &date, &time); - file_close(fh); - if ((memcmp(&st.date, &date, sizeof(date))) || - (memcmp(&st.time, &time, sizeof(time)))) { - ret |= STATFLAG_DISKCHG; - SPRINTF(buf, str_updated, name); - statflag_seterr(sfh, buf); - } - } - else { - ret |= STATFLAG_DISKCHG; - SPRINTF(buf, str_notfound, name); - statflag_seterr(sfh, buf); + ret = STATFLAG_SUCCESS; + for (i=0; i<4; i++) { + ret |= statflag_read(sfh, &sp, sizeof(sp)); + if (sp.path[0]) { + fdd_set(i, sp.path, sp.ftype, sp.readonly); } } + (void)tbl; return(ret); } -static int flagcheck_disk(STFLAGH sfh, const SFENTRY *tbl) { - int ret; - int i; - char buf[8]; +// ---- sxsi - ret = 0; - for (i=0; i<4; i++) { - SPRINTF(buf, str_fddx, i+1); - ret |= diskcheck(sfh, buf); +typedef struct { + UINT8 ide[4]; + UINT8 scsi[8]; +} SXSIDEVS; + +static const OEMCHAR str_sasix[] = OEMTEXT("SASI%u"); +static const OEMCHAR str_scsix[] = OEMTEXT("SCSI%u"); + +static int flagsave_sxsi(STFLAGH sfh, const SFENTRY *tbl) { + + int ret; + UINT i; + SXSIDEVS sds; +const OEMCHAR *path; + + sxsi_allflash(); + ret = STATFLAG_SUCCESS; + for (i=0; itype) { @@ -1376,10 +1288,6 @@ const SFENTRY *tblterm; ret |= flagsave_com(&sffh->sfh, tbl); break; - case STATFLAG_DISK: - ret |= flagsave_disk(&sffh->sfh, tbl); - break; - case STATFLAG_DMA: ret |= flagsave_dma(&sffh->sfh, tbl); break; @@ -1400,9 +1308,15 @@ const SFENTRY *tblterm; ret |= flagsave_ext(&sffh->sfh, tbl); break; + case STATFLAG_FDD: + ret |= flagsave_fdd(&sffh->sfh, tbl); + break; + +#if !defined(DISABLE_SOUND) case STATFLAG_FM: ret |= flagsave_fm(&sffh->sfh, tbl); break; +#endif case STATFLAG_GIJ: ret |= flagsave_gij(&sffh->sfh, tbl); @@ -1417,6 +1331,10 @@ const SFENTRY *tblterm; case STATFLAG_MEM: ret |= flagsave_mem(&sffh->sfh, tbl); break; + + case STATFLAG_SXSI: + ret |= flagsave_sxsi(&sffh->sfh, tbl); + break; } tbl++; } @@ -1424,7 +1342,7 @@ const SFENTRY *tblterm; return(ret); } -int statsave_check(const char *filename, char *buf, int size) { +int statsave_check(const OEMCHAR *filename, OEMCHAR *buf, int size) { SFFILEH sffh; int ret; @@ -1442,7 +1360,7 @@ const SFENTRY *tblterm; while((!done) && (ret != STATFLAG_FAILURE)) { ret |= statflag_readsection(sffh); tbl = np2tbl; - tblterm = tbl + (sizeof(np2tbl)/sizeof(SFENTRY)); + tblterm = tbl + NELEMENTS(np2tbl); while(tbl < tblterm) { if (!memcmp(sffh->sfh.hdr.index, tbl->index, 10)) { break; @@ -1470,15 +1388,21 @@ const SFENTRY *tblterm; case STATFLAG_EVT: case STATFLAG_EXT: case STATFLAG_GIJ: +#if !defined(DISABLE_SOUND) case STATFLAG_FM: +#endif #if defined(SUPPORT_HOSTDRV) case STATFLAG_HDRV: #endif ret |= flagcheck_veronly(&sffh->sfh, tbl); break; - case STATFLAG_DISK: - ret |= flagcheck_disk(&sffh->sfh, tbl); + case STATFLAG_FDD: + ret |= flagcheck_fdd(&sffh->sfh, tbl); + break; + + case STATFLAG_SXSI: + ret |= flagcheck_sxsi(&sffh->sfh, tbl); break; default: @@ -1494,7 +1418,7 @@ const SFENTRY *tblterm; return(ret); } -int statsave_load(const char *filename) { +int statsave_load(const OEMCHAR *filename) { SFFILEH sffh; int ret; @@ -1519,20 +1443,18 @@ const SFENTRY *tblterm; rs232c_midipanic(); mpu98ii_midipanic(); pc9861k_midipanic(); - sxsi_trash(); + sxsi_alltrash(); ret |= flagload_common(&sffh->sfh, np2tbl); - nevent_init(); CPU_RESET(); CPU_SETEXTSIZE((UINT32)pccore.extmem); + nevent_allreset(); sound_changeclock(); beep_changeclock(); sound_reset(); -#if defined(SUPPORT_WAVEMIX) - wavemix_bind(); -#endif + fddmtrsnd_bind(); iocore_reset(); // サウンドでpicを呼ぶので… cbuscore_reset(); @@ -1542,7 +1464,7 @@ const SFENTRY *tblterm; while((!done) && (ret != STATFLAG_FAILURE)) { ret |= statflag_readsection(sffh); tbl = np2tbl + 1; - tblterm = np2tbl + (sizeof(np2tbl)/sizeof(SFENTRY)); + tblterm = np2tbl + NELEMENTS(np2tbl); while(tbl < tblterm) { if (!memcmp(sffh->sfh.hdr.index, tbl->index, 10)) { break; @@ -1569,10 +1491,6 @@ const SFENTRY *tblterm; ret |= flagload_com(&sffh->sfh, tbl); break; - case STATFLAG_DISK: - ret |= flagload_disk(&sffh->sfh, tbl); - break; - case STATFLAG_DMA: ret |= flagload_dma(&sffh->sfh, tbl); break; @@ -1593,9 +1511,15 @@ const SFENTRY *tblterm; ret |= flagload_ext(&sffh->sfh, tbl); break; + case STATFLAG_FDD: + ret |= flagload_fdd(&sffh->sfh, tbl); + break; + +#if !defined(DISABLE_SOUND) case STATFLAG_FM: ret |= flagload_fm(&sffh->sfh, tbl); break; +#endif case STATFLAG_GIJ: ret |= flagload_gij(&sffh->sfh, tbl); @@ -1611,6 +1535,10 @@ const SFENTRY *tblterm; ret |= flagload_mem(&sffh->sfh, tbl); break; + case STATFLAG_SXSI: + ret |= flagload_sxsi(&sffh->sfh, tbl); + break; + default: ret |= STATFLAG_WARNING; break; @@ -1623,7 +1551,7 @@ const SFENTRY *tblterm; statflag_close(sffh); // I/O作り直し - i286_memorymap((pccore.model & PCMODEL_EPSON)?1:0); + MEMM_ARCH((pccore.model & PCMODEL_EPSON)?1:0); iocore_build(); iocore_bind(); cbuscore_bind(); @@ -1640,7 +1568,8 @@ const SFENTRY *tblterm; FONTPTR_LOW = fontrom + cgwindow.low; FONTPTR_HIGH = fontrom + cgwindow.high; #endif - i286_vram_dispatch(vramop.operate); + MEMM_VRAM(vramop.operate); + fddmtr_reset(); soundmng_play(); return(ret);