--- np2/statsave.c 2003/10/29 10:09:37 1.14 +++ np2/statsave.c 2004/01/05 07:48:22 1.24 @@ -4,14 +4,14 @@ #include "scrnmng.h" #include "soundmng.h" #include "timemng.h" -#include "i286.h" -#include "memory.h" +#include "cpucore.h" #include "pccore.h" #include "iocore.h" #include "cbuscore.h" #include "pc9861k.h" #include "mpu98ii.h" #include "board14.h" +#include "amd98.h" #include "bios.h" #include "vram.h" #include "palettes.h" @@ -28,6 +28,18 @@ #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 { char name[16]; char vername[28]; @@ -43,15 +55,20 @@ typedef struct { enum { NP2FLAG_BIN = 0, NP2FLAG_TERM, +#if defined(CGWND_FONTPTR) + NP2FLAG_CGW, +#endif NP2FLAG_CLOCK, + NP2FLAG_COM, + NP2FLAG_DISK, NP2FLAG_DMA, NP2FLAG_EGC, - NP2FLAG_EXT, + NP2FLAG_EPSON, NP2FLAG_EVT, - NP2FLAG_GIJ, + NP2FLAG_EXT, NP2FLAG_FM, - NP2FLAG_COM, - NP2FLAG_DISK + NP2FLAG_GIJ, + NP2FLAG_MEM }; typedef struct { @@ -89,9 +106,10 @@ typedef struct { static void err_append(ERR_BUF *e, char *buf) { + int len; + if ((e) && (buf)) { if (e->buf) { - int len; len = strlen(buf); if (e->remain >= len) { CopyMemory(e->buf, buf, len); @@ -323,7 +341,7 @@ static int flagsave_term(NP2FFILE f, con } -// ---- +// ---- common static int flagsave_common(NP2FFILE f, const STENTRY *t) { @@ -343,7 +361,7 @@ static int flagload_common(NP2FFILE f, c } -// ----- +// ----- clock static int flagload_clock(NP2FFILE f, const STENTRY *t) { @@ -356,7 +374,118 @@ static int flagload_clock(NP2FFILE f, co } -// ----- +// ---- memory + +static int flagsave_mem(NP2FFILE f, const STENTRY *t) { + + int ret; + + ret = flagsave_create(f, t); + if (ret != NP2FLAG_FAILURE) { + ret |= flagsave_save(f, mem, 0x110000); + ret |= flagsave_save(f, mem + VRAM1_B, 0x18000); + ret |= flagsave_save(f, mem + VRAM1_E, 0x8000); + ret |= flagsave_close(f); + } + return(ret); +} + +static int flagload_mem(NP2FFILE f, const STENTRY *t) { + + int ret; + + ret = flagload_load(f, mem, 0x110000); + ret |= flagload_load(f, mem + VRAM1_B, 0x18000); + ret |= flagload_load(f, mem + VRAM1_E, 0x8000); + (void)t; + return(ret); +} + + +// ---- ext memory + +static int flagsave_ext(NP2FFILE f, const STENTRY *t) { + + int ret; + + ret = flagsave_create(f, t); + if (ret != NP2FLAG_FAILURE) { + ret |= flagsave_save(f, &extmem, sizeof(extmem)); + if (CPU_EXTMEM) { + ret |= flagsave_save(f, CPU_EXTMEM, CPU_EXTMEMSIZE); + } + ret |= flagsave_close(f); + } + return(ret); +} + +static int flagload_ext(NP2FFILE f, const STENTRY *t) { + + int ret; + int i; + UINT pagemax = 0; + + ret = flagload_load(f, &extmem, sizeof(extmem)); + if (extmem.maxmem) { + if (extmem.maxmem > (13+1)) { + extmem.maxmem = (13+1); + } + if (!extmemmng_realloc(extmem.maxmem - 1)) { + pagemax = (extmem.maxmem - 1) << 8; + if (CPU_EXTMEM) { + ret |= flagload_load(f, CPU_EXTMEM, CPU_EXTMEMSIZE); + } + } + else { + extmem.maxmem = 0; + } + } + for (i=0; i<4; i++) { + if (extmem.page[i] < pagemax) { + extmem.pageptr[i] = CPU_EXTMEM + (extmem.page[i] << 12); + } + else { + extmem.pageptr[i] = mem + 0xc0000 + (i << 14); + } + } + (void)t; + return(ret); +} + + +// ---- cg window + +#if defined(CGWND_FONTPTR) +static int flagsave_cgwnd(NP2FFILE f, const STENTRY *t) { + + int ret; + _CGWINDOW cgwnd; + + cgwnd = cgwindow; + cgwnd.fontlow -= (long)fontrom; + cgwnd.fonthigh -= (long)fontrom; + ret = flagsave_create(f, t); + if (ret != NP2FLAG_FAILURE) { + ret |= flagsave_save(f, &cgwindow, sizeof(cgwindow)); + ret |= flagsave_close(f); + } + return(ret); +} + +static int flagload_cgwnd(NP2FFILE f, const STENTRY *t) { + + int ret; + + ret = flagload_load(f, &cgwindow, sizeof(cgwindow)); + cgwindow.fontlow += (long)fontrom; + cgwindow.fonthigh += (long)fontrom; + (void)t; + return(ret); +} +#endif + + +// ---- dma static int flagsave_dma(NP2FFILE f, const STENTRY *t) { @@ -406,7 +535,7 @@ static int flagload_dma(NP2FFILE f, cons } -// ----- +// ---- egc static int flagsave_egc(NP2FFILE f, const STENTRY *t) { @@ -437,58 +566,38 @@ static int flagload_egc(NP2FFILE f, cons } -// ----- +// ---- epson -static int flagsave_ext(NP2FFILE f, const STENTRY *t) { +static int flagsave_epson(NP2FFILE f, const STENTRY *t) { int ret; + if (!(pc.model & PCMODEL_EPSON)) { + return(NP2FLAG_SUCCESS); + } ret = flagsave_create(f, t); if (ret != NP2FLAG_FAILURE) { - ret |= flagsave_save(f, &extmem, sizeof(extmem)); - if (extmemmng_size) { - ret |= flagsave_save(f, extmemmng_ptr, extmemmng_size); - } + ret |= flagsave_save(f, &epsonio, sizeof(epsonio)); + ret |= flagsave_save(f, mem + 0x1c0000, 0x8000); + ret |= flagsave_save(f, mem + 0x1e8000, 0x18000); ret |= flagsave_close(f); } return(ret); } -static int flagload_ext(NP2FFILE f, const STENTRY *t) { +static int flagload_epson(NP2FFILE f, const STENTRY *t) { int ret; - int i; - UINT pagemax = 0; - ret = flagload_load(f, &extmem, sizeof(extmem)); - if (extmem.maxmem) { - if (extmem.maxmem > (13+1)) { - extmem.maxmem = (13+1); - } - if (!extmemmng_realloc(extmem.maxmem - 1)) { - pagemax = (extmem.maxmem - 1) << 8; - if (extmemmng_size) { - ret |= flagload_load(f, extmemmng_ptr, extmemmng_size); - } - } - else { - extmem.maxmem = 0; - } - } - for (i=0; i<4; i++) { - if (extmem.page[i] < pagemax) { - extmem.pageptr[i] = extmemmng_ptr + (extmem.page[i] << 12); - } - else { - extmem.pageptr[i] = mem + 0xc0000 + (i << 14); - } - } + ret = flagload_load(f, &epsonio, sizeof(epsonio)); + ret |= flagload_load(f, mem + 0x1c0000, 0x8000); + ret |= flagload_load(f, mem + 0x1e8000, 0x18000); (void)t; return(ret); } -// ----- +// ---- event typedef struct { UINT readyevents; @@ -601,7 +710,7 @@ static int flagload_evt(NP2FFILE f, cons } -// ---- +// ---- gaiji static int flagsave_gij(NP2FFILE f, const STENTRY *t) { @@ -613,7 +722,7 @@ static int flagsave_gij(NP2FFILE f, cons ret = flagsave_create(f, t); if (ret != NP2FLAG_FAILURE) { for (i=0; i<2; i++) { - fnt = font + ((0x56 + (i << 7)) << 4); + fnt = fontrom + ((0x56 + (i << 7)) << 4); for (j=0; j<0x80; j++) { ret |= flagsave_save(f, fnt, 32); fnt += 0x1000; @@ -633,7 +742,7 @@ static int flagload_gij(NP2FFILE f, cons ret = 0; for (i=0; i<2; i++) { - fnt = font + ((0x56 + (i << 7)) << 4); + fnt = fontrom + ((0x56 + (i << 7)) << 4); for (j=0; j<0x80; j++) { ret |= flagload_load(f, fnt, 32); fnt += 0x1000; @@ -644,7 +753,7 @@ static int flagload_gij(NP2FFILE f, cons } -// ----- +// ---- FM enum { FLAG_MG = 0x0001, @@ -654,10 +763,11 @@ enum { FLAG_FM2B = 0x0010, FLAG_PSG1 = 0x0020, FLAG_PSG2 = 0x0040, - FLAG_RHYTHM = 0x0080, - FLAG_ADPCM = 0x0100, - FLAG_PCM86 = 0x0200, - FLAG_CS4231 = 0x0400 + FLAG_PSG3 = 0x0080, + FLAG_RHYTHM = 0x0100, + FLAG_ADPCM = 0x0200, + FLAG_PCM86 = 0x0400, + FLAG_CS4231 = 0x0800 }; typedef struct { @@ -710,6 +820,10 @@ static int flagsave_fm(NP2FFILE f, const FLAG_PSG1 | FLAG_RHYTHM | FLAG_ADPCM; break; + case 0x80: + saveflg = FLAG_PSG1 | FLAG_PSG2 | FLAG_PSG3; + break; + default: saveflg = 0; break; @@ -738,6 +852,9 @@ static int flagsave_fm(NP2FFILE f, const if (saveflg & FLAG_PSG2) { ret |= flagsave_save(f, &psg2.reg, sizeof(PSGREG)); } + if (saveflg & FLAG_PSG3) { + ret |= flagsave_save(f, &psg3.reg, sizeof(PSGREG)); + } if (saveflg & FLAG_ADPCM) { ret |= flagsave_save(f, &adpcm, sizeof(adpcm)); } @@ -846,6 +963,10 @@ static int flagload_fm(NP2FFILE f, const FLAG_PSG1 | FLAG_RHYTHM | FLAG_ADPCM; break; + case 0x80: + saveflg = FLAG_PSG1 | FLAG_PSG2 | FLAG_PSG3; + break; + default: saveflg = 0; break; @@ -872,6 +993,9 @@ static int flagload_fm(NP2FFILE f, const if (saveflg & FLAG_PSG2) { ret |= flagload_load(f, &psg2.reg, sizeof(PSGREG)); } + if (saveflg & FLAG_PSG3) { + ret |= flagload_load(f, &psg3.reg, sizeof(PSGREG)); + } if (saveflg & FLAG_ADPCM) { ret |= flagload_load(f, &adpcm, sizeof(adpcm)); } @@ -912,6 +1036,9 @@ static int flagload_fm(NP2FFILE f, const if (saveflg & FLAG_PSG2) { play_psgreg(&psg2); } + if (saveflg & FLAG_PSG3) { + play_psgreg(&psg3); + } (void)t; return(ret); } @@ -926,6 +1053,12 @@ typedef struct { DOSTIME time; } 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) { STATDISK st; @@ -984,13 +1117,13 @@ static int diskcheck(NP2FFILE f, const c if ((memcmp(&st.date, &date, sizeof(date))) || (memcmp(&st.time, &time, sizeof(time)))) { ret |= NP2FLAG_DISKCHG; - SPRINTF(buf, "%s: updated\n", name); + SPRINTF(buf, str_updated, name); err_append(e, buf); } } else { ret |= NP2FLAG_DISKCHG; - SPRINTF(buf, "%s: not found\n", name); + SPRINTF(buf, str_notfound, name); err_append(e, buf); } } @@ -1005,16 +1138,16 @@ static int flagcheck_disk(NP2FFILE f, co ret = 0; for (i=0; i<4; i++) { - SPRINTF(buf, "FDD%d", i+1); + SPRINTF(buf, str_fddx, i+1); ret |= diskcheck(f, buf, e); } sxsi_flash(); for (i=0; i<2; i++) { - SPRINTF(buf, "SASI%u", i+1); + SPRINTF(buf, str_sasix, i+1); ret |= diskcheck(f, buf, e); } for (i=0; i<2; i++) { - SPRINTF(buf, "SCSI%d", i+1); + SPRINTF(buf, str_scsix, i+1); ret |= diskcheck(f, buf, e); } (void)t; @@ -1054,7 +1187,7 @@ static int flagload_disk(NP2FFILE f, con } -// ----- +// ---- com static int flagsave_com(NP2FFILE f, const STENTRY *t) { @@ -1180,55 +1313,73 @@ int statsave_save(const char *filename) _NP2FFILE f; int ret; - UINT i; +const STENTRY *tbl; +const STENTRY *tblterm; ret = flagcreate(&f, filename); if (ret == NP2FLAG_FAILURE) { return(ret); } - for (i=0; itype) { case NP2FLAG_BIN: case NP2FLAG_CLOCK: - ret |= flagsave_common(&f, &np2tbl[i]); + ret |= flagsave_common(&f, tbl); break; case NP2FLAG_TERM: - ret |= flagsave_term(&f, &np2tbl[i]); + ret |= flagsave_term(&f, tbl); + break; + +#if defined(CGWND_FONTPTR) + case NP2FLAG_CGW: + ret |= flagsave_cgwnd(&f, tbl); + break; +#endif + + case NP2FLAG_COM: + ret |= flagsave_com(&f, tbl); + break; + + case NP2FLAG_DISK: + ret |= flagsave_disk(&f, tbl); break; case NP2FLAG_DMA: - ret |= flagsave_dma(&f, &np2tbl[i]); + ret |= flagsave_dma(&f, tbl); break; case NP2FLAG_EGC: - ret |= flagsave_egc(&f, &np2tbl[i]); + ret |= flagsave_egc(&f, tbl); break; - case NP2FLAG_EXT: - ret |= flagsave_ext(&f, &np2tbl[i]); + case NP2FLAG_EPSON: + ret |= flagsave_epson(&f, tbl); break; case NP2FLAG_EVT: - ret |= flagsave_evt(&f, &np2tbl[i]); + ret |= flagsave_evt(&f, tbl); break; - case NP2FLAG_GIJ: - ret |= flagsave_gij(&f, &np2tbl[i]); + case NP2FLAG_EXT: + ret |= flagsave_ext(&f, tbl); break; case NP2FLAG_FM: - ret |= flagsave_fm(&f, &np2tbl[i]); + ret |= flagsave_fm(&f, tbl); break; - case NP2FLAG_DISK: - ret |= flagsave_disk(&f, &np2tbl[i]); + case NP2FLAG_GIJ: + ret |= flagsave_gij(&f, tbl); break; - case NP2FLAG_COM: - ret |= flagsave_com(&f, &np2tbl[i]); + case NP2FLAG_MEM: + ret |= flagsave_mem(&f, tbl); break; } + tbl++; } flagclose(&f); return(ret); @@ -1236,11 +1387,12 @@ int statsave_save(const char *filename) int statsave_check(const char *filename, char *buf, int size) { + ERR_BUF e; _NP2FFILE f; int ret; - UINT i; BOOL done; - ERR_BUF e; +const STENTRY *tbl; +const STENTRY *tblterm; e.buf = buf; e.remain = size; @@ -1262,36 +1414,42 @@ int statsave_check(const char *filename, ret |= flagload_create(&f); CopyMemory(index, f.p.index, sizeof(f.p.index)); index[10] = 0; - for (i=0; iindex)) { break; } + tbl++; } - if (i < (sizeof(np2tbl)/sizeof(STENTRY))) { - switch(np2tbl[i].type) { + if (tbl < tblterm) { + switch(tbl->type) { case NP2FLAG_BIN: +#if defined(CGWND_FONTPTR) + case NP2FLAG_CGW: +#endif case NP2FLAG_CLOCK: - ret |= flagcheck_versize(&f, &np2tbl[i], &e); + case NP2FLAG_MEM: + ret |= flagcheck_versize(&f, tbl, &e); break; case NP2FLAG_TERM: done = TRUE; break; + case NP2FLAG_COM: case NP2FLAG_DMA: case NP2FLAG_EGC: - case NP2FLAG_EXT: + case NP2FLAG_EPSON: case NP2FLAG_EVT: + case NP2FLAG_EXT: case NP2FLAG_GIJ: - case NP2FLAG_COM: - ret |= flagcheck_veronly(&f, &np2tbl[i], &e); + case NP2FLAG_FM: + ret |= flagcheck_veronly(&f, tbl, &e); break; case NP2FLAG_DISK: - ret |= flagcheck_disk(&f, &np2tbl[i], &e); - break; - - case NP2FLAG_FM: // ver0.31 + ret |= flagcheck_disk(&f, tbl, &e); break; default: @@ -1316,8 +1474,9 @@ int statsave_load(const char *filename) _NP2FFILE f; int ret; - UINT i; BOOL done; +const STENTRY *tbl; +const STENTRY *tblterm; ret = flagopen(&f, filename, NULL); if (ret == NP2FLAG_FAILURE) { @@ -1337,55 +1496,72 @@ int statsave_load(const char *filename) ret |= flagload_create(&f); CopyMemory(index, f.p.index, sizeof(f.p.index)); index[10] = 0; - for (i=0; iindex)) { break; } + tbl++; } - if (i < (sizeof(np2tbl)/sizeof(STENTRY))) { - switch(np2tbl[i].type) { + if (tbl < tblterm) { + switch(tbl->type) { case NP2FLAG_BIN: - ret |= flagload_common(&f, &np2tbl[i]); + ret |= flagload_common(&f, tbl); break; case NP2FLAG_TERM: done = TRUE; break; +#if defined(CGWND_FONTPTR) + case NP2FLAG_CGW: + ret |= flagload_cgwnd(&f, tbl); + break; +#endif + case NP2FLAG_CLOCK: - ret |= flagload_clock(&f, &np2tbl[i]); + ret |= flagload_clock(&f, tbl); + break; + + case NP2FLAG_COM: + ret |= flagload_com(&f, tbl); + break; + + case NP2FLAG_DISK: + ret |= flagload_disk(&f, tbl); break; case NP2FLAG_DMA: - ret |= flagload_dma(&f, &np2tbl[i]); + ret |= flagload_dma(&f, tbl); break; case NP2FLAG_EGC: - ret |= flagload_egc(&f, &np2tbl[i]); + ret |= flagload_egc(&f, tbl); break; - case NP2FLAG_EXT: - ret |= flagload_ext(&f, &np2tbl[i]); + case NP2FLAG_EPSON: + ret |= flagload_epson(&f, tbl); break; case NP2FLAG_EVT: - ret |= flagload_evt(&f, &np2tbl[i]); + ret |= flagload_evt(&f, tbl); break; - case NP2FLAG_GIJ: - ret |= flagload_gij(&f, &np2tbl[i]); + case NP2FLAG_EXT: + ret |= flagload_ext(&f, tbl); break; case NP2FLAG_FM: - ret |= flagload_fm(&f, &np2tbl[i]); + ret |= flagload_fm(&f, tbl); break; - case NP2FLAG_DISK: - ret |= flagload_disk(&f, &np2tbl[i]); + case NP2FLAG_GIJ: + ret |= flagload_gij(&f, tbl); break; - case NP2FLAG_COM: - ret |= flagload_com(&f, &np2tbl[i]); + case NP2FLAG_MEM: + ret |= flagload_mem(&f, tbl); break; default: @@ -1401,6 +1577,7 @@ int statsave_load(const char *filename) flagclose(&f); // I/Oºî¤êľ¤· + i286_memorymap((pc.model & PCMODEL_EPSON)?1:0); iocore_build(); iocore_bind(); cbuscore_bind(); @@ -1413,6 +1590,10 @@ int statsave_load(const char *filename) gdcs.palchange = GDCSCRN_REDRAW; tramflag.renewal = 1; cgwindow.writable |= 0x80; +#if defined(CPUSTRUC_FONTPTR) + FONTPTR_LOW = fontrom + cgwindow.low; + FONTPTR_HIGH = fontrom + cgwindow.high; +#endif i286_vram_dispatch(vramop.operate); soundmng_play();