--- np2/macos9/np2.cpp 2003/10/25 09:08:24 1.8 +++ np2/macos9/np2.cpp 2005/03/21 02:24:23 1.39 @@ -4,6 +4,7 @@ #include "np2.h" #include "dosio.h" #include "commng.h" +#include "mousemng.h" #include "scrnmng.h" #include "soundmng.h" #include "sysmng.h" @@ -19,6 +20,7 @@ #include "pc9861k.h" #include "mpu98ii.h" #include "timing.h" +#include "keystat.h" #include "debugsub.h" #include "bios.h" #include "scrndraw.h" @@ -27,16 +29,18 @@ #include "s98.h" #include "diskdrv.h" #include "fddfile.h" -#include "statsave.h" - -#if defined(NP2GCC) -#include "mousemng.h" -#endif -#define USE_RESUME - - NP2OSCFG np2oscfg = {0, 2, 0, 0, 0, 0}; + NP2OSCFG np2oscfg = {100, 100, + 0, 0, 0, 0, + 0, 0, +#if defined(SUPPORT_RESUME) + 0, +#endif +#if defined(SUPPORT_STATSAVE) + 0, +#endif + 0, 0}; WindowPtr hWndMain; BOOL np2running; @@ -55,8 +59,70 @@ static BYTE scrnmode; #endif static char target[MAX_PATH] = DEFAULTPATH; +#if !defined(SUPPORT_PC9821) +static const char np2app[] = "np2"; +#else +static const char np2app[] = "np21"; +#endif + + +// ---- + +#if defined(SUPPORT_RESUME) +static const char np2resumeext[] = ".sav"; +#endif +#if defined(SUPPORT_STATSAVE) +static const char np2flagext[] = ".sv%u"; +#endif -static const char np2resume[] = "sav"; +#if defined(SUPPORT_RESUME) || defined(SUPPORT_STATSAVE) +static void getstatfilename(char *path, const char *ext, UINT size) { + + file_cpyname(path, file_getcd(np2app), size); + file_catname(path, ext, size); +} + +static void flagsave(const char *ext) { + + char path[MAX_PATH]; + + getstatfilename(path, ext, sizeof(path)); + statsave_save(path); +} + +static void flagdelete(const char *ext) { + + char path[MAX_PATH]; + + getstatfilename(path, ext, sizeof(path)); + file_delete(path); +} + +static int flagload(const char *ext, BOOL force) { + + char path[MAX_PATH]; + char buf[1024]; + int r; + int ret; + + getstatfilename(path, ext, sizeof(path)); + r = statsave_check(path, buf, sizeof(buf)); + if (r & (~STATFLAG_DISKCHG)) { + ResumeErrorDialogProc(); + ret = IDCANCEL; + } + else if ((!force) && (r & STATFLAG_DISKCHG)) { + ret = ResumeWarningDialogProc(buf); + } + else { + ret = IDOK; + } + if (ret == IDOK) { + statsave_load(path); + } + return(ret); +} +#endif // ---- おまじない @@ -100,23 +166,81 @@ static void InitToolBox(void) { static void MenuBarInit(void) { - Handle hMenu; - MenuHandle happlemenu; + Handle hdl; + MenuHandle hmenu; - hMenu = GetNewMBar(IDM_MAINMENU); - if (!hMenu) { + hdl = GetNewMBar(IDM_MAINMENU); + if (hdl == NULL) { ExitToShell(); } - SetMenuBar(hMenu); - happlemenu = GetMenuHandle(IDM_APPLE); - if (happlemenu) { - AppendResMenu(happlemenu, 'DRVR'); + SetMenuBar(hdl); + hmenu = GetMenuHandle(IDM_APPLE); + if (hmenu) { + AppendResMenu(hmenu, 'DRVR'); + } +#if !defined(SUPPORT_SCSI) + hmenu = GetMenuHandle(IDM_HARDDISK); + if (hmenu) { + DeleteMenuItem(hmenu, 7); + DeleteMenuItem(hmenu, 6); + DeleteMenuItem(hmenu, 5); + DeleteMenuItem(hmenu, 4); + DeleteMenuItem(hmenu, 3); + } +#endif + if (!np2oscfg.I286SAVE) { + hmenu = GetMenuHandle(IDM_OTHER); + if (hmenu) { + DeleteMenuItem(hmenu, 9); + } } InsertMenu(GetMenu(IDM_SASI1), -1); InsertMenu(GetMenu(IDM_SASI2), -1); +#if defined(SUPPORT_SCSI) + InsertMenu(GetMenu(IDM_SCSI0), -1); + InsertMenu(GetMenu(IDM_SCSI1), -1); + InsertMenu(GetMenu(IDM_SCSI2), -1); + InsertMenu(GetMenu(IDM_SCSI3), -1); +#endif InsertMenu(GetMenu(IDM_KEYBOARD), -1); InsertMenu(GetMenu(IDM_SOUND), -1); InsertMenu(GetMenu(IDM_MEMORY), -1); + +#if TARGET_API_MAC_CARBON + hmenu = GetMenuHandle(IDM_FDD2); + SetItemCmd(hmenu, LoWord(IDM_FDD2OPEN), 'D'); + SetMenuItemModifiers(hmenu, LoWord(IDM_FDD2OPEN), kMenuShiftModifier); + SetItemCmd(hmenu, LoWord(IDM_FDD2EJECT), 'E'); + SetMenuItemModifiers(hmenu, LoWord(IDM_FDD2EJECT), kMenuShiftModifier); + hmenu = GetMenuHandle(IDM_SASI2); + SetItemCmd(hmenu, LoWord(IDM_SASI2OPEN), 'O'); + SetMenuItemModifiers(hmenu, LoWord(IDM_SASI2OPEN), kMenuShiftModifier); +#else + EnableItem(GetMenuHandle(IDM_DEVICE), LoWord(IDM_MOUSE)); + EnableItem(GetMenuHandle(IDM_KEYBOARD), LoWord(IDM_F12MOUSE)); +#endif + + if (!(np2cfg.fddequip & 1)) { + DeleteMenu(IDM_FDD1); + } + if (!(np2cfg.fddequip & 2)) { + DeleteMenu(IDM_FDD2); + } + if (!(np2cfg.fddequip & 4)) { + DeleteMenu(IDM_FDD3); + } + if (!(np2cfg.fddequip & 8)) { + DeleteMenu(IDM_FDD4); + } + +#if defined(SUPPORT_STATSAVE) + if (!np2oscfg.statsave) { +#endif + DeleteMenu(IDM_STATSAVE); +#if defined(SUPPORT_STATSAVE) + } +#endif + DrawMenuBar(); } @@ -129,6 +253,10 @@ static void HandleMenuChoice(long wParam UINT update; Str255 applname; +#if defined(SUPPORT_STATSAVE) + UINT num; + char ext[16]; +#endif update = 0; switch(wParam) { @@ -173,20 +301,68 @@ static void HandleMenuChoice(long wParam diskdrv_setfdd(1, NULL, 0); break; + case IDM_FDD3OPEN: + dialog_changefdd(2); + break; + + case IDM_FDD3EJECT: + diskdrv_setfdd(2, NULL, 0); + break; + + case IDM_FDD4OPEN: + dialog_changefdd(3); + break; + + case IDM_FDD4EJECT: + diskdrv_setfdd(3, NULL, 0); + break; + case IDM_SASI1OPEN: - dialog_changehdd(0); + dialog_changehdd(0x00); break; case IDM_SASI1REMOVE: - diskdrv_sethdd(0, NULL); + diskdrv_sethdd(0x00, NULL); break; case IDM_SASI2OPEN: - dialog_changehdd(1); + dialog_changehdd(0x01); break; case IDM_SASI2REMOVE: - diskdrv_sethdd(1, NULL); + diskdrv_sethdd(0x01, NULL); + break; + + case IDM_SCSI0OPEN: + dialog_changehdd(0x20); + break; + + case IDM_SCSI0REMOVE: + diskdrv_sethdd(0x20, NULL); + break; + + case IDM_SCSI1OPEN: + dialog_changehdd(0x21); + break; + + case IDM_SCSI1REMOVE: + diskdrv_sethdd(0x21, NULL); + break; + + case IDM_SCSI2OPEN: + dialog_changehdd(0x22); + break; + + case IDM_SCSI2REMOVE: + diskdrv_sethdd(0x22, NULL); + break; + + case IDM_SCSI3OPEN: + dialog_changehdd(0x23); + break; + + case IDM_SCSI3REMOVE: + diskdrv_sethdd(0x23, NULL); break; case IDM_ROLNORMAL: @@ -250,65 +426,110 @@ static void HandleMenuChoice(long wParam dialog_scropt(); break; -#if defined(NP2GCC) - case IDM_MOUSE: - mouse_running(MOUSE_XOR); - menu_setmouse(np2oscfg.MOUSE_SW ^ 1); - sysmng_update(SYS_UPDATECFG); + case IDM_MOUSE: + mousemng_toggle(MOUSEPROC_SYSTEM); + menu_setmouse(np2oscfg.MOUSE_SW ^ 1); + update |= SYS_UPDATECFG; + break; + + case IDM_MIDIOPT: + MPU98DialogProc(); + break; + + case IDM_MIDIPANIC: + rs232c_midipanic(); + mpu98ii_midipanic(); + pc9861k_midipanic(); break; -#endif case IDM_KEY: menu_setkey(0); keystat_resetjoykey(); + update |= SYS_UPDATECFG; break; case IDM_JOY1: menu_setkey(1); keystat_resetjoykey(); + update |= SYS_UPDATECFG; break; case IDM_JOY2: menu_setkey(2); keystat_resetjoykey(); + update |= SYS_UPDATECFG; break; case IDM_MOUSEKEY: menu_setkey(3); keystat_resetjoykey(); + update |= SYS_UPDATECFG; break; case IDM_XSHIFT: menu_setxshift(np2cfg.XSHIFT ^ 1); keystat_forcerelease(0x70); + update |= SYS_UPDATECFG; break; case IDM_XCTRL: menu_setxshift(np2cfg.XSHIFT ^ 2); keystat_forcerelease(0x74); + update |= SYS_UPDATECFG; break; case IDM_XGRPH: menu_setxshift(np2cfg.XSHIFT ^ 4); keystat_forcerelease(0x73); + update |= SYS_UPDATECFG; + break; + + case IDM_F11KANA: + menu_setf11key(0); + mackbd_resetf11(); + update |= SYS_UPDATEOSCFG; + break; + + case IDM_F11STOP: + menu_setf11key(1); + mackbd_resetf11(); + update |= SYS_UPDATEOSCFG; + break; + + case IDM_F11NFER: + menu_setf11key(3); + mackbd_resetf11(); + update |= SYS_UPDATEOSCFG; + break; + + case IDM_F11USER: + menu_setf11key(4); + mackbd_resetf11(); + update |= SYS_UPDATEOSCFG; break; case IDM_F12MOUSE: - menu_setf12copy(0); - keystat_resetcopyhelp(); - update |= SYS_UPDATECFG; + menu_setf12key(0); + mackbd_resetf12(); + update |= SYS_UPDATEOSCFG; break; case IDM_F12COPY: - menu_setf12copy(1); - keystat_resetcopyhelp(); - update |= SYS_UPDATECFG; + menu_setf12key(1); + mackbd_resetf12(); + update |= SYS_UPDATEOSCFG; break; - case IDM_F12STOP: - menu_setf12copy(2); - keystat_resetcopyhelp(); - update |= SYS_UPDATECFG; + case IDM_F12XFER: + menu_setf12key(3); + mackbd_resetf12(); + update |= SYS_UPDATEOSCFG; + break; + + case IDM_F12USER: + menu_setf12key(4); + mackbd_resetf12(); + update |= SYS_UPDATEOSCFG; break; case IDM_BEEPOFF: @@ -380,6 +601,16 @@ static void HandleMenuChoice(long wParam update |= SYS_UPDATECFG; break; + case IDM_AMD98: + menu_setsound(0x80); + update |= SYS_UPDATECFG; + break; + + case IDM_JASTSND: + menu_setjastsnd(np2oscfg.jastsnd ^ 1); + update |= SYS_UPDATEOSCFG; + break; + case IDM_SEEKSND: menu_setmotorflg(np2cfg.MOTOR ^ 1); update |= SYS_UPDATECFG; @@ -405,10 +636,24 @@ static void HandleMenuChoice(long wParam update |= SYS_UPDATECFG; break; + case IDM_MEM116: + menu_setextmem(11); + update |= SYS_UPDATECFG; + break; + + case IDM_MEM136: + menu_setextmem(13); + update |= SYS_UPDATECFG; + break; + case IDM_BMPSAVE: dialog_writebmp(); break; + case IDM_CALENDAR: + CalendarDialogProc(); + break; + case IDM_DISPCLOCK: menu_setdispclk(np2oscfg.DISPCLK ^ 1); update |= SYS_UPDATECFG; @@ -441,6 +686,19 @@ static void HandleMenuChoice(long wParam (void)OpenDeskAcc(applname); #endif } +#if defined(SUPPORT_STATSAVE) + else if (HiWord(wParam) == IDM_STATSAVE) { + num = LoWord(wParam); + if ((num >= 1) && (num < (1 + 10))) { + SPRINTF(ext, np2flagext, num - 1); + flagsave(ext); + } + else if ((num >= 12) && (num < (12 + 10))) { + SPRINTF(ext, np2flagext, num - 12); + flagload(ext, TRUE); + } + } +#endif break; } sysmng_update(update); @@ -471,7 +729,10 @@ static void HandleMouseDown(EventRecord case inMenuBar: if (np2running) { soundmng_stop(); + mousemng_disable(MOUSEPROC_MACUI); HandleMenuChoice(MenuSelect(pevent->where)); + mousemng_enable(MOUSEPROC_MACUI); + soundmng_play(); } break; @@ -492,14 +753,8 @@ static void HandleMouseDown(EventRecord break; case inContent: -#if defined(NP2GCC) - if (controlKey & GetCurrentKeyModifiers() ) { - mouse_btn(MOUSE_RIGHTDOWN); - } - else { - mouse_btn(MOUSE_LEFTDOWN); - } -#endif + mousemng_buttonevent((pevent->modifiers & (1 << 12)) + ?MOUSEMNG_RIGHTDOWN:MOUSEMNG_LEFTDOWN); break; case inGoAway: @@ -511,6 +766,9 @@ static void HandleMouseDown(EventRecord static void eventproc(EventRecord *event) { + int keycode; + + keycode = (event->message & keyCodeMask) >> 8; switch(event->what) { case mouseDown: HandleMouseDown(event); @@ -522,91 +780,70 @@ static void eventproc(EventRecord *event case keyDown: case autoKey: - if (np2running) { - mackbd_f12down(((event->message) & keyCodeMask) >> 8); - if (event->modifiers & cmdKey) { - HandleMenuChoice(MenuKey(event->message & charCodeMask)); + if (!np2running) { + break; + } +#if !TARGET_API_MAC_CARBON + if ((keycode == 0x6f) && (np2oscfg.F12KEY == 0)) { + HandleMenuChoice(IDM_MOUSE); + break; + } +#endif + if (event->modifiers & cmdKey) { +#if !TARGET_API_MAC_CARBON + if (mackbd_keydown(keycode, TRUE)) { + break; } +#endif + soundmng_stop(); + mousemng_disable(MOUSEPROC_MACUI); +#if TARGET_API_MAC_CARBON + HandleMenuChoice(MenuEvent(event)); +#else + HandleMenuChoice(MenuKey(event->message & charCodeMask)); +#endif + mousemng_enable(MOUSEPROC_MACUI); + soundmng_play(); + } + else { + mackbd_keydown(keycode, FALSE); } break; case keyUp: - mackbd_f12up(((event->message) & keyCodeMask) >> 8); + mackbd_keyup(keycode); break; -#if defined(NP2GCC) - case mouseUp: - if (controlKey & GetCurrentKeyModifiers()) { - mouse_btn(MOUSE_RIGHTUP); - } - else { - mouse_btn(MOUSE_LEFTUP); - } + case mouseUp: + mousemng_buttonevent(MOUSEMNG_LEFTUP); + mousemng_buttonevent(MOUSEMNG_RIGHTUP); + break; + + case activateEvt: + mackbd_activate((event->modifiers & activeFlag)?TRUE:FALSE); break; -#endif } } // ---- -static void processwait(UINT waitcnt) { +static void framereset(void) { - if (timing_getcount() >= waitcnt) { - timing_setcount(0); - framecnt = 0; - if (np2oscfg.DISPCLK & 3) { - if (sysmng_workclockrenewal()) { - sysmng_updatecaption(3); - } + framecnt = 0; + if (np2oscfg.DISPCLK & 3) { + if (sysmng_workclockrenewal()) { + sysmng_updatecaption(3); } } } -static void getstatfilename(char *path, const char *ext, int size) { - - file_cpyname(path, file_getcd("np2"), size); - file_catname(path, str_dot, size); - file_catname(path, ext, size); -} - -static void flagsave(const char *ext) { - - char path[MAX_PATH]; - - getstatfilename(path, ext, sizeof(path)); - statsave_save(path); -} - -static void flagdelete(const char *ext) { - - char path[MAX_PATH]; - - getstatfilename(path, ext, sizeof(path)); - file_delete(path); -} - -static int flagload(const char *ext) { - - int ret; - char path[MAX_PATH]; - char buf[1024]; - int r; +static void processwait(UINT waitcnt) { - ret = IDOK; - getstatfilename(path, ext, sizeof(path)); - r = statsave_check(path, buf, sizeof(buf)); - if (r & (~NP2FLAG_DISKCHG)) { - ResumeErrorDialogProc(); - ret = IDCANCEL; - } - else if (r & NP2FLAG_DISKCHG) { - ret = ResumeWarningDialogProc(buf); - } - if (ret == IDOK) { - statsave_load(path); + if (timing_getcount() >= waitcnt) { + timing_setcount(0); + framereset(); } - return(ret); } int main(int argc, char *argv[]) { @@ -614,21 +851,30 @@ int main(int argc, char *argv[]) { Rect wRect; EventRecord event; UINT t; + GrafPtr saveport; + Point pt; dosio_init(); file_setcd(target); InitToolBox(); macossub_init(); - MenuBarInit(); - initload(); + MenuBarInit(); + TRACEINIT(); - SetRect(&wRect, 100, 100, 100, 100); + keystat_initialize(); + + SetRect(&wRect, np2oscfg.posx, np2oscfg.posy, 100, 100); +#if !defined(SUPPORT_PC9821) hWndMain = NewWindow(0, &wRect, "\pNeko Project II", FALSE, noGrowDocProc, (WindowPtr)-1, TRUE, 0); +#else + hWndMain = NewWindow(0, &wRect, "\pNeko Project 21", FALSE, + noGrowDocProc, (WindowPtr)-1, TRUE, 0); +#endif if (!hWndMain) { TRACETERM(); macossub_term(); @@ -641,15 +887,20 @@ int main(int argc, char *argv[]) { menu_setrotate(0); menu_setdispmode(np2cfg.DISPSYNC); + menu_setraster(np2cfg.RASTER); menu_setwaitflg(np2oscfg.NOWAIT); menu_setframe(np2oscfg.DRAW_SKIP); + menu_setkey(0); menu_setxshift(0); - menu_setf12copy(np2oscfg.F12COPY); + menu_setf11key(np2oscfg.F11KEY); + menu_setf12key(np2oscfg.F12KEY); menu_setbeepvol(np2cfg.BEEP_VOL); menu_setsound(np2cfg.SOUND_SW); + menu_setjastsnd(np2oscfg.jastsnd); menu_setmotorflg(np2cfg.MOTOR); menu_setextmem(np2cfg.EXTMEM); + menu_setdispclk(np2oscfg.DISPCLK); menu_setbtnrapid(np2cfg.BTN_RAPID); menu_setbtnmode(np2cfg.BTN_MODE); @@ -677,17 +928,18 @@ int main(int argc, char *argv[]) { pccore_init(); S98_init(); -#if defined(NP2GCC) + mousemng_initialize(); if (np2oscfg.MOUSE_SW) { // ver0.30 - mouse_running(MOUSE_ON); + mousemng_enable(MOUSEPROC_SYSTEM); } -#endif // scrndraw_redraw(); pccore_reset(); +#if defined(SUPPORT_RESUME) if (np2oscfg.resume) { - flagload(np2resume); + flagload(np2resumeext, FALSE); } +#endif SetEventMask(everyEvent); @@ -698,11 +950,8 @@ int main(int argc, char *argv[]) { } else { if (np2oscfg.NOWAIT) { -#if defined(NP2GCC) - mouse_callback(); -#endif - soundmng_play(); mackbd_callback(); + mousemng_callback(); pccore_exec(framecnt == 0); if (np2oscfg.DRAW_SKIP) { // nowait frame skip framecnt++; @@ -719,11 +968,8 @@ int main(int argc, char *argv[]) { } else if (np2oscfg.DRAW_SKIP) { // frame skip if (framecnt < np2oscfg.DRAW_SKIP) { -#if defined(NP2GCC) - mouse_callback(); -#endif - soundmng_play(); mackbd_callback(); + mousemng_callback(); pccore_exec(framecnt == 0); framecnt++; } @@ -734,11 +980,8 @@ int main(int argc, char *argv[]) { else { // auto skip if (!waitcnt) { UINT cnt; -#if defined(NP2GCC) - mouse_callback(); -#endif - soundmng_play(); mackbd_callback(); + mousemng_callback(); pccore_exec(framecnt == 0); framecnt++; cnt = timing_getcount(); @@ -758,7 +1001,7 @@ int main(int argc, char *argv[]) { else { timing_setcount(cnt - framecnt); } - framecnt = 0; + framereset(); } } else { @@ -768,23 +1011,40 @@ int main(int argc, char *argv[]) { } } } + + GetPort(&saveport); +#if TARGET_API_MAC_CARBON + SetPortWindowPort(hWndMain); +#else + SetPort(hWndMain); +#endif + pt.h = 0; + pt.v = 0; + LocalToGlobal(&pt); + SetPort(saveport); + if ((np2oscfg.posx != pt.h) || (np2oscfg.posy != pt.v)) { + np2oscfg.posx = pt.h; + np2oscfg.posy = pt.v; + sysmng_update(SYS_UPDATEOSCFG); + } + np2running = FALSE; pccore_cfgupdate(); +#if defined(SUPPORT_RESUME) if (np2oscfg.resume) { - flagsave(np2resume); + flagsave(np2resumeext); } else { - flagdelete(np2resume); + flagdelete(np2resumeext); } +#endif pccore_term(); S98_trash(); -#if defined(NP2GCC) - mouse_running(MOUSE_OFF); -#endif + mousemng_disable(MOUSEPROC_SYSTEM); scrnmng_destroy();