|
|
| version 1.4, 2004/08/14 12:16:17 | version 1.8, 2008/06/02 20:07:30 |
|---|---|
| Line 15 | Line 15 |
| #include "palettes.h" | #include "palettes.h" |
| #include "makescrn.h" | #include "makescrn.h" |
| #include "sound.h" | #include "sound.h" |
| // #include "sndctrl.h" | |
| // #include "font.h" | |
| #include "fddfile.h" | #include "fddfile.h" |
| // #include "fdd_mtr.h" | |
| #if defined(MACOS) | #if defined(MACOS) |
| #define CRCONST str_cr | #define CRCONST str_cr |
| Line 64 typedef struct { | Line 60 typedef struct { |
| #include "statsave.tbl" | #include "statsave.tbl" |
| // ---- | /* ---- */ |
| // 関数ポインタを intに変更。 | /* 関数ポインタを intに変更。 */ |
| static UINT32 proc2id(INTPTR func, const PROCTBL *tbl, UINT count) { | static UINT32 proc2id(INTPTR func, const PROCTBL *tbl, UINT count) { |
| while(count) { | while(count) { |
| Line 92 static INTPTR id2proc(UINT32 id, const P | Line 88 static INTPTR id2proc(UINT32 id, const P |
| } | } |
| // ---- | /* ---- */ |
| enum { | enum { |
| SFFILEH_WRITE = 0x0001, | SFFILEH_WRITE = 0x0001, |
| Line 324 void statflag_seterr(STFLAGH sfh, const | Line 320 void statflag_seterr(STFLAGH sfh, const |
| } | } |
| // ---- common | /* common */ |
| static int flagsave_common(STFLAGH sfh, const SFENTRY *tbl) { | static int flagsave_common(STFLAGH sfh, const SFENTRY *tbl) { |
| Line 337 static int flagload_common(STFLAGH sfh, | Line 333 static int flagload_common(STFLAGH sfh, |
| } | } |
| // ---- event | /* event */ |
| typedef struct { | typedef struct { |
| UINT32 next; | |
| SINT32 clock; | SINT32 clock; |
| SINT32 base; | SINT32 baseclock; |
| UINT32 param; | |
| UINT32 proc; | UINT32 proc; |
| } NEVTITEM; | } NEVTITEM; |
| typedef struct { | typedef struct { |
| UINT readys; | NEVTITEM item[NEVENT_MAXEVENTS]; |
| UINT events; | UINT32 first; |
| UINT32 ready[NEVENT_MAXEVENTS]; | |
| UINT32 event[NEVENT_MAXEVENTS]; | |
| } NEVTSAVE; | } NEVTSAVE; |
| static UINT32 evt2id(UINT evt) { | static UINT32 evt2id(NEVENTITEM next) { |
| UINT i; | |
| for (i=0; i<sizeof(evtnum)/sizeof(ENUMTBL); i++) { | if (next == NEVENTITEM_NONE) { |
| if (evtnum[i].evt == evt) { | return((UINT32)-2); |
| return(evtnum[i].id); | } |
| } | else if (next == NEVENTITEM_TERM) { |
| return((UINT32)-1); | |
| } | |
| else { | |
| return(next - nevent.item); | |
| } | } |
| return(0); | |
| } | } |
| static int nevent_write(STFLAGH sfh, const _NEVENTITEM *ne) { | static NEVENTITEM id2evt(UINT32 n) { |
| NEVTITEM nit; | |
| nit.clock = ne->clock; | if (n == (UINT32)-2) { |
| nit.base = ne->baseclock; | return(NEVENTITEM_NONE); |
| nit.proc = proc2id((INTPTR)ne->proc, evtproc, NELEMENTS(evtproc)); | } |
| nit.param = ne->param; | else if (n == (UINT32)-1) { |
| return(statflag_write(sfh, &nit, sizeof(nit))); | return(NEVENTITEM_TERM); |
| } | |
| else if (n < NEVENT_MAXEVENTS) { | |
| return(nevent.item + n); | |
| } | |
| else { | |
| /* error! */ | |
| return(NEVENTITEM_TERM); | |
| } | |
| } | } |
| static int flagsave_evt(STFLAGH sfh, const SFENTRY *tbl) { | static int flagsave_evt(STFLAGH sfh, const SFENTRY *tbl) { |
| NEVTSAVE nevt; | NEVTSAVE nevt; |
| UINT i; | UINT i; |
| UINT32 id; | |
| UINT eventid[NEVENT_MAXEVENTS]; | |
| int ret; | |
| ZeroMemory(&nevt, sizeof(nevt)); | |
| for (i=0; i<nevent.readyevents; i++) { | |
| id = evt2id(nevent.level[i]); | |
| if (id) { | |
| nevt.ready[nevt.readys++] = id; | |
| } | |
| } | |
| for (i=0; i<NEVENT_MAXEVENTS; i++) { | for (i=0; i<NEVENT_MAXEVENTS; i++) { |
| id = evt2id(i); | nevt.item[i].next = evt2id(nevent.item[i].next); |
| if (id) { | nevt.item[i].clock = nevent.item[i].clock; |
| eventid[i] = i; | nevt.item[i].baseclock = nevent.item[i].baseclock; |
| nevt.event[nevt.events++] = id; | nevt.item[i].proc = proc2id((INTPTR)nevent.item[i].proc, |
| } | evtproc, NELEMENTS(evtproc)); |
| } | |
| ret = statflag_write(sfh, &nevt, sizeof(nevt)); | |
| for (i=0; i<nevt.events; i++) { | |
| ret |= nevent_write(sfh, nevent.item + eventid[i]); | |
| } | } |
| nevt.first = evt2id(nevent.first); | |
| (void)tbl; | (void)tbl; |
| return(ret); | return(statflag_write(sfh, &nevt, sizeof(nevt))); |
| } | |
| static UINT id2evt(UINT32 id) { | |
| UINT i; | |
| for (i=0; i<sizeof(evtnum)/sizeof(ENUMTBL); i++) { | |
| if (evtnum[i].id == id) { | |
| return(evtnum[i].evt); | |
| } | |
| } | |
| return(NEVENT_MAXEVENTS); | |
| } | |
| static int nevent_read(STFLAGH sfh, UINT32 id) { | |
| int ret; | |
| NEVTITEM nit; | |
| UINT evt; | |
| _NEVENTITEM *ne; | |
| ret = statflag_read(sfh, &nit, sizeof(nit)); | |
| evt = id2evt(id); | |
| if (evt >= NEVENT_MAXEVENTS) { | |
| return(STATFLAG_FAILURE); | |
| } | |
| ne = nevent.item + evt; | |
| ne->clock = nit.clock; | |
| ne->baseclock = nit.base; | |
| ne->proc = (NEVENTCB)id2proc(nit.proc, evtproc, NELEMENTS(evtproc)); | |
| ne->param = nit.param; | |
| return(ret); | |
| } | } |
| static int flagload_evt(STFLAGH sfh, const SFENTRY *tbl) { | static int flagload_evt(STFLAGH sfh, const SFENTRY *tbl) { |
| int ret; | |
| NEVTSAVE nevt; | NEVTSAVE nevt; |
| int ret; | |
| UINT i; | UINT i; |
| UINT evt; | |
| UINT readyevents; | |
| ret = statflag_read(sfh, &nevt, sizeof(nevt)); | ret = statflag_read(sfh, &nevt, sizeof(nevt)); |
| readyevents = 0; | for (i=0; i<NEVENT_MAXEVENTS; i++) { |
| for (i=0; i<nevt.readys; i++) { | nevent.item[i].next = id2evt(nevt.item[i].next); |
| evt = id2evt(nevt.ready[i]); | nevent.item[i].clock = nevt.item[i].clock; |
| if (evt < NEVENT_MAXEVENTS) { | nevent.item[i].baseclock = nevt.item[i].baseclock; |
| nevent.level[readyevents++] = evt; | nevent.item[i].proc = (NEVENTCB)id2proc(nevt.item[i].proc, |
| } | evtproc, NELEMENTS(evtproc)); |
| } | |
| nevent.readyevents = readyevents; | |
| for (i=0; i<nevt.events; i++) { | |
| ret |= nevent_read(sfh, nevt.event[i]); | |
| } | } |
| nevent.first = id2evt(nevt.first); | |
| (void)tbl; | (void)tbl; |
| return(ret); | return(ret); |
| } | } |
| // ---- disk | /* disk */ |
| typedef struct { | typedef struct { |
| OEMCHAR path[MAX_PATH]; | OEMCHAR fname[MAX_PATH]; |
| int readonly; | UINT32 ftype; |
| UINT readonly; | |
| DOSDATE date; | DOSDATE date; |
| DOSTIME time; | DOSTIME time; |
| } STATDISK; | } STATDISK; |
| Line 477 static const OEMCHAR str_fddx[] = OEMTEX | Line 429 static const OEMCHAR str_fddx[] = OEMTEX |
| static const OEMCHAR str_updated[] = OEMTEXT("%s: updated"); | static const OEMCHAR str_updated[] = OEMTEXT("%s: updated"); |
| static const OEMCHAR str_notfound[] = OEMTEXT("%s: not found"); | static const OEMCHAR str_notfound[] = OEMTEXT("%s: not found"); |
| static int disksave(STFLAGH sfh, const OEMCHAR *path, int readonly) { | static int disksave(STFLAGH sfh, const _FDDFILE *fdd) { |
| STATDISK st; | STATDISK st; |
| FILEH fh; | FILEH fh; |
| ZeroMemory(&st, sizeof(st)); | ZeroMemory(&st, sizeof(st)); |
| if ((path) && (path[0])) { | if (fdd->type != DISKTYPE_NOTREADY) { |
| file_cpyname(st.path, path, sizeof(st.path)); | file_cpyname(st.fname, fdd->fname, NELEMENTS(st.fname)); |
| st.readonly = readonly; | st.ftype = fdd->ftype; |
| fh = file_open_rb(path); | st.readonly = fdd->protect; |
| fh = file_open_rb(st.fname); | |
| if (fh != FILEH_INVALID) { | if (fh != FILEH_INVALID) { |
| file_getdatetime(fh, &st.date, &st.time); | file_getdatetime(fh, &st.date, &st.time); |
| file_close(fh); | file_close(fh); |
| Line 501 static int flagsave_disk(STFLAGH sfh, co | Line 454 static int flagsave_disk(STFLAGH sfh, co |
| REG8 i; | REG8 i; |
| ret = STATFLAG_SUCCESS; | ret = STATFLAG_SUCCESS; |
| for (i=0; i<4; i++) { | for (i=0; i<MAX_FDDFILE; i++) { |
| ret |= disksave(sfh, fddfile_diskname(i), fddfile_diskprotect(i)); | ret |= disksave(sfh, fddfile + i); |
| } | } |
| (void)tbl; | (void)tbl; |
| return(ret); | return(ret); |
| Line 518 static int diskcheck(STFLAGH sfh, const | Line 471 static int diskcheck(STFLAGH sfh, const |
| DOSTIME time; | DOSTIME time; |
| ret = statflag_read(sfh, &st, sizeof(st)); | ret = statflag_read(sfh, &st, sizeof(st)); |
| if (st.path[0]) { | if (st.fname[0]) { |
| fh = file_open_rb(st.path); | fh = file_open_rb(st.fname); |
| if (fh != FILEH_INVALID) { | if (fh != FILEH_INVALID) { |
| file_getdatetime(fh, &date, &time); | file_getdatetime(fh, &date, &time); |
| file_close(fh); | file_close(fh); |
| Line 546 static int flagcheck_disk(STFLAGH sfh, c | Line 499 static int flagcheck_disk(STFLAGH sfh, c |
| OEMCHAR buf[8]; | OEMCHAR buf[8]; |
| ret = 0; | ret = 0; |
| for (i=0; i<4; i++) { | for (i=0; i<MAX_FDDFILE; i++) { |
| OEMSPRINTF(buf, str_fddx, i+1); | OEMSPRINTF(buf, str_fddx, i+1); |
| ret |= diskcheck(sfh, buf); | ret |= diskcheck(sfh, buf); |
| } | } |
| Line 561 static int flagload_disk(STFLAGH sfh, co | Line 514 static int flagload_disk(STFLAGH sfh, co |
| STATDISK st; | STATDISK st; |
| ret = STATFLAG_SUCCESS; | ret = STATFLAG_SUCCESS; |
| for (i=0; i<4; i++) { | for (i=0; i<MAX_FDDFILE; i++) { |
| ret |= statflag_read(sfh, &st, sizeof(st)); | ret |= statflag_read(sfh, &st, sizeof(st)); |
| if (st.path[0]) { | if (st.fname[0]) { |
| fddfile_set(i, st.path, FTYPE_NONE, st.readonly); | fddfile_set(i, st.fname, st.ftype, st.readonly); |
| } | } |
| } | } |
| (void)tbl; | (void)tbl; |
| Line 572 static int flagload_disk(STFLAGH sfh, co | Line 525 static int flagload_disk(STFLAGH sfh, co |
| } | } |
| // ---- | /* checker */ |
| static int flagcheck_versize(STFLAGH sfh, const SFENTRY *tbl) { | static int flagcheck_versize(STFLAGH sfh, const SFENTRY *tbl) { |
| Line 591 static int flagcheck_veronly(STFLAGH sfh | Line 544 static int flagcheck_veronly(STFLAGH sfh |
| } | } |
| // ---- | /* interface */ |
| int statsave_save(const OEMCHAR *filename) { | int statsave_save(const OEMCHAR *filename) { |
| Line 634 int statsave_check(const OEMCHAR *filena | Line 587 int statsave_check(const OEMCHAR *filena |
| SFFILEH sffh; | SFFILEH sffh; |
| int ret; | int ret; |
| BOOL done; | BRESULT done; |
| const SFENTRY *tbl; | const SFENTRY *tbl; |
| const SFENTRY *tblterm; | const SFENTRY *tblterm; |
| Line 690 int statsave_load(const OEMCHAR *filenam | Line 643 int statsave_load(const OEMCHAR *filenam |
| SFFILEH sffh; | SFFILEH sffh; |
| int ret; | int ret; |
| BOOL done; | BRESULT done; |
| const SFENTRY *tbl; | const SFENTRY *tbl; |
| const SFENTRY *tblterm; | const SFENTRY *tblterm; |
| Line 699 const SFENTRY *tblterm; | Line 652 const SFENTRY *tblterm; |
| return(STATFLAG_FAILURE); | return(STATFLAG_FAILURE); |
| } | } |
| // PCCORE read! | /* PCCORE read! */ |
| ret = statflag_readsection(sffh); | ret = statflag_readsection(sffh); |
| if ((ret != STATFLAG_SUCCESS) || | if ((ret != STATFLAG_SUCCESS) || |
| (memcmp(sffh->sfh.hdr.index, xmiltbl[0].index, 10))) { | (memcmp(sffh->sfh.hdr.index, xmiltbl[0].index, 10))) { |