--- np2/macos9/np2.cpp 2003/10/23 19:31:58 1.5 +++ np2/macos9/np2.cpp 2003/11/15 07:10:02 1.17 @@ -3,6 +3,8 @@ #include "strres.h" #include "np2.h" #include "dosio.h" +#include "commng.h" +#include "mousemng.h" #include "scrnmng.h" #include "soundmng.h" #include "sysmng.h" @@ -10,6 +12,7 @@ #include "mackbd.h" #include "ini.h" #include "menu.h" +#include "np2open.h" #include "dialog.h" #include "memory.h" #include "pccore.h" @@ -27,14 +30,11 @@ #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, 2, 0, 0, 0, 0, 0}; WindowPtr hWndMain; BOOL np2running; @@ -98,23 +98,37 @@ 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'); } InsertMenu(GetMenu(IDM_SASI1), -1); InsertMenu(GetMenu(IDM_SASI2), -1); 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), kMenuOptionModifier); + SetItemCmd(hmenu, LoWord(IDM_FDD2EJECT), 'E'); + SetMenuItemModifiers(hmenu, LoWord(IDM_FDD2EJECT), kMenuOptionModifier); + hmenu = GetMenuHandle(IDM_SASI2); + SetItemCmd(hmenu, LoWord(IDM_FDD2OPEN), 'O'); + SetMenuItemModifiers(hmenu, LoWord(IDM_SASI2OPEN), kMenuOptionModifier); +#else + EnableItem(GetMenuHandle(IDM_DEVICE), LoWord(IDM_MOUSE)); + EnableItem(GetMenuHandle(IDM_KEYBOARD), LoWord(IDM_F12MOUSE)); +#endif DrawMenuBar(); } @@ -244,65 +258,80 @@ static void HandleMenuChoice(long wParam update |= SYS_UPDATECFG; break; -#if defined(NP2GCC) - case IDM_MOUSE: - mouse_running(MOUSE_XOR); - menu_setmouse(np2oscfg.MOUSE_SW ^ 1); - sysmng_update(SYS_UPDATECFG); + case IDM_SCREENOPT: + dialog_scropt(); + break; + + case IDM_MOUSE: + mousemng_toggle(MOUSEPROC_SYSTEM); + menu_setmouse(np2oscfg.MOUSE_SW ^ 1); + update |= SYS_UPDATECFG; + 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_F12MOUSE: menu_setf12copy(0); keystat_resetcopyhelp(); - update |= SYS_UPDATECFG; + update |= SYS_UPDATEOSCFG; break; case IDM_F12COPY: menu_setf12copy(1); keystat_resetcopyhelp(); - update |= SYS_UPDATECFG; + update |= SYS_UPDATEOSCFG; break; case IDM_F12STOP: menu_setf12copy(2); keystat_resetcopyhelp(); - update |= SYS_UPDATECFG; + update |= SYS_UPDATEOSCFG; break; case IDM_BEEPOFF: @@ -374,6 +403,11 @@ static void HandleMenuChoice(long wParam update |= SYS_UPDATECFG; break; + case IDM_AMD98: + menu_setsound(0x80); + update |= SYS_UPDATECFG; + break; + case IDM_SEEKSND: menu_setmotorflg(np2cfg.MOTOR ^ 1); update |= SYS_UPDATECFG; @@ -447,7 +481,12 @@ static void HandleUpdateEvent(EventRecor hWnd = (WindowPtr)pevent->message; BeginUpdate(hWnd); - scrndraw_redraw(); + if (np2running) { + scrndraw_redraw(); + } + else { + np2open(); + } EndUpdate(hWnd); } @@ -458,8 +497,13 @@ static void HandleMouseDown(EventRecord switch(FindWindow(pevent->where, &hWnd)) { case inMenuBar: - soundmng_stop(); - HandleMenuChoice(MenuSelect(pevent->where)); + if (np2running) { + soundmng_stop(); + mousemng_disable(MOUSEPROC_MACUI); + HandleMenuChoice(MenuSelect(pevent->where)); + mousemng_enable(MOUSEPROC_MACUI); + soundmng_play(); + } break; case inDrag: @@ -479,14 +523,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: @@ -498,6 +536,9 @@ static void HandleMouseDown(EventRecord static void eventproc(EventRecord *event) { + int keycode; + + keycode = (event->message & keyCodeMask) >> 8; switch(event->what) { case mouseDown: HandleMouseDown(event); @@ -509,42 +550,60 @@ static void eventproc(EventRecord *event case keyDown: case autoKey: - mackbd_f12down(((event->message) & keyCodeMask) >> 8); + if (!np2running) { + break; + } +#if !TARGET_API_MAC_CARBON + if ((keycode == 0x6f) && (np2oscfg.F12COPY == 0)) { + HandleMenuChoice(IDM_MOUSE); + break; + } +#endif if (event->modifiers & cmdKey) { + soundmng_stop(); + mousemng_disable(MOUSEPROC_MACUI); HandleMenuChoice(MenuKey(event->message & charCodeMask)); + mousemng_enable(MOUSEPROC_MACUI); + soundmng_play(); + } + else { + mackbd_keydown(keycode); } 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 framereset(void) { + + framecnt = 0; + if (np2oscfg.DISPCLK & 3) { + if (sysmng_workclockrenewal()) { + sysmng_updatecaption(3); + } + } +} + static void processwait(UINT waitcnt) { if (timing_getcount() >= waitcnt) { timing_setcount(0); - framecnt = 0; - if (np2oscfg.DISPCLK & 3) { - if (sysmng_workclockrenewal()) { - sysmng_updatecaption(3); - } - } + framereset(); } } @@ -598,6 +657,9 @@ int main(int argc, char *argv[]) { Rect wRect; EventRecord event; + UINT t; + GrafPtr saveport; + Point pt; dosio_init(); file_setcd(target); @@ -610,7 +672,7 @@ int main(int argc, char *argv[]) { TRACEINIT(); - SetRect(&wRect, 100, 100, 100, 100); + SetRect(&wRect, np2oscfg.posx, np2oscfg.posy, 100, 100); hWndMain = NewWindow(0, &wRect, "\pNeko Project II", FALSE, noGrowDocProc, (WindowPtr)-1, TRUE, 0); if (!hWndMain) { @@ -647,17 +709,25 @@ int main(int argc, char *argv[]) { return(0); } + np2open(); + t = GETTICK(); + while((GETTICK() - t) < 100) { + if (WaitNextEvent(everyEvent, &event, 0, 0)) { + eventproc(&event); + } + } + + commng_initialize(); sysmng_initialize(); mackbd_initialize(); 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(); +// scrndraw_redraw(); pccore_reset(); if (np2oscfg.resume) { @@ -673,11 +743,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++; @@ -694,11 +761,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++; } @@ -709,11 +773,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(); @@ -733,7 +794,7 @@ int main(int argc, char *argv[]) { else { timing_setcount(cnt - framecnt); } - framecnt = 0; + framereset(); } } else { @@ -743,6 +804,23 @@ 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(); @@ -757,9 +835,7 @@ int main(int argc, char *argv[]) { pccore_term(); S98_trash(); -#if defined(NP2GCC) - mouse_running(MOUSE_OFF); -#endif + mousemng_disable(MOUSEPROC_SYSTEM); scrnmng_destroy();