--- np2/macosx/np2.cpp 2003/10/22 19:57:39 1.11 +++ np2/macosx/np2.cpp 2003/10/24 20:46:13 1.17 @@ -26,21 +26,23 @@ #include "diskdrv.h" #include "fddfile.h" #include "statsave.h" - -#if defined(NP2GCC) #include "mousemng.h" -#endif #include "configure.h" +#include "screenopt.h" -#define USE_RESUME +#define USE_RESUME +#define NP2OPENING -#if defined(NP2GCC) - NP2OSCFG np2oscfg = {0, 2, 0, 0, 0, 0}; -#else - NP2OSCFG np2oscfg = {0, 2, 0, 0, 0}; +#ifdef NP2OPENING +#include +#define OPENING_WAIT 1500 #endif + + + NP2OSCFG np2oscfg = {0, 2, 0, 0, 0, 0, 1, 0}; + WindowPtr hWndMain; BOOL np2running; static UINT framecnt = 0; @@ -167,6 +169,11 @@ static void HandleMenuChoice(long wParam newhdddisk(); break; #endif + + case IDM_FONT: + dialog_font(); + break; + case IDM_EXIT: np2running = FALSE; break; @@ -261,6 +268,10 @@ static void HandleMenuChoice(long wParam break; #if defined(NP2GCC) + case IDM_SCREENOPT: + initScreenOpt(); + break; + case IDM_MOUSE: mouse_running(MOUSE_XOR); menu_setmouse(np2oscfg.MOUSE_SW ^ 1); @@ -453,6 +464,7 @@ static void HandleMenuChoice(long wParam HiliteMenu(0); } +#if 0 static void HandleUpdateEvent(EventRecord *pevent) { WindowPtr hWnd; @@ -462,12 +474,14 @@ static void HandleUpdateEvent(EventRecor scrndraw_redraw(); EndUpdate(hWnd); } +#endif static void HandleMouseDown(EventRecord *pevent) { WindowPtr hWnd; Rect rDrag; + soundmng_stop(); switch(FindWindow(pevent->where, &hWnd)) { case inMenuBar: HandleMenuChoice(MenuSelect(pevent->where)); @@ -500,11 +514,14 @@ static void HandleMouseDown(EventRecord #endif break; +#ifndef NP2GCC case inGoAway: if (TrackGoAway(hWnd, pevent->where)) { } np2running = FALSE; break; +#endif } + soundmng_play(); } #if 0 @@ -588,6 +605,55 @@ static void flagload(const char *ext) { } } +#ifdef NP2OPENING +static void openingNP2(void) { + Rect srt, bounds; + GrafPtr port; + CFURLRef openingURL; + CFStringRef path; + char buffer[1024]; + FSRef fsr; + FSSpec fsc; + PicHandle pict; + GraphicsImportComponent gi; + + GetPort(&port); + SetPortWindowPort(hWndMain); + const RGBColor col = {0, 0, 0}; + SetRect(&bounds, 0, 0, 640, 400); + RGBBackColor(&col); + EraseRect(&bounds); + + openingURL=CFURLCopyAbsoluteURL(CFBundleCopyResourcesDirectoryURL(CFBundleGetMainBundle())); + if (openingURL) { + path = CFURLCopyFileSystemPath(openingURL, kCFURLPOSIXPathStyle); + if (path) { + if (CFStringGetCString(path, buffer, 1024, CFStringGetSystemEncoding())) { + strcat(buffer, "/nekop2.bmp"); + FSPathMakeRef((const UInt8*)buffer, &fsr, NULL); + FSGetCatalogInfo(&fsr, kFSCatInfoNone, NULL, NULL, &fsc, NULL); + if (!GetGraphicsImporterForFile(&fsc, &gi)) { + if (!GraphicsImportGetNaturalBounds(gi, &srt)) { + OffsetRect( &srt, -srt.left, -srt.top); + GraphicsImportSetBoundsRect(gi, &srt); + GraphicsImportGetAsPicture(gi, &pict); + OffsetRect(&srt, (640-srt.right)/2, (400-srt.bottom)/2); + DrawPicture(pict,&srt); + QDFlushPortBuffer(GetWindowPort(hWndMain), NULL); + KillPicture(pict); + } + CloseComponent(gi); + } + } + if (path) CFRelease(path); + } + if (openingURL) CFRelease(openingURL); + } + SetPort(port); +} +#endif + + int main(int argc, char *argv[]) { Rect wRect; @@ -596,6 +662,9 @@ int main(int argc, char *argv[]) { #endif EventRef theEvent; EventTargetRef theTarget; +#ifdef OPENING_WAIT + UINT32 tick; +#endif dosio_init(); file_setcd(target); @@ -621,6 +690,12 @@ int main(int argc, char *argv[]) { SizeWindow(hWndMain, 640, 400, TRUE); setUpCarbonEvent(); ShowWindow(hWndMain); +#ifdef NP2OPENING + openingNP2(); +#endif +#ifdef OPENING_WAIT + tick = GETTICK(); +#endif menu_setrotate(0); menu_setdispmode(np2cfg.DISPSYNC); @@ -656,11 +731,16 @@ int main(int argc, char *argv[]) { mouse_running(MOUSE_ON); } #endif +#ifdef OPENING_WAIT + while((GETTICK() - tick) < OPENING_WAIT); +#endif scrndraw_redraw(); pccore_reset(); #if defined(USE_RESUME) - flagload(np2resume); + if (np2oscfg.resume) { + flagload(np2resume); + } #endif #if 0 @@ -682,10 +762,7 @@ int main(int argc, char *argv[]) { #endif else { if (np2oscfg.NOWAIT) { -#if defined(NP2GCC) && 0 - mouse_callback(); -#endif -#if 1 +#if 0 mackbd_callback(); #endif pccore_exec(framecnt == 0); @@ -704,10 +781,7 @@ int main(int argc, char *argv[]) { } else if (np2oscfg.DRAW_SKIP) { // frame skip if (framecnt < np2oscfg.DRAW_SKIP) { -#if defined(NP2GCC) && 0 - mouse_callback(); -#endif -#if 1 +#if 0 mackbd_callback(); #endif pccore_exec(framecnt == 0); @@ -720,15 +794,11 @@ int main(int argc, char *argv[]) { else { // auto skip if (!waitcnt) { UINT cnt; -#if defined(NP2GCC) && 0 - mouse_callback(); -#endif -#if 1 +#if 0 mackbd_callback(); #endif pccore_exec(framecnt == 0); framecnt++; - // テスト cnt = timing_getcount(); if (framecnt > cnt) { waitcnt = framecnt; @@ -741,7 +811,7 @@ int main(int argc, char *argv[]) { framemax++; } if (cnt >= 12) { - timing_init(); + timing_reset(); } else { timing_setcount(cnt - framecnt); @@ -761,7 +831,9 @@ int main(int argc, char *argv[]) { pccore_cfgupdate(); #if defined(USE_RESUME) - flagsave(np2resume); + if (np2oscfg.resume) { + flagsave(np2resume); + } #endif pccore_term(); @@ -773,7 +845,7 @@ int main(int argc, char *argv[]) { scrnmng_destroy(); - if (sys_updates & (SYS_UPDATECFG | SYS_UPDATEOSCFG)) { + if (sys_updates & (SYS_UPDATECFG | SYS_UPDATEOSCFG)) { initsave(); } TRACETERM(); @@ -788,7 +860,7 @@ int main(int argc, char *argv[]) { } //以下、ごっそりIIxからマージ -static pascal OSStatus MyAppEventHandler (EventHandlerCallRef myHandlerChain, EventRef event, void* userData) +static pascal OSStatus np2appevent (EventHandlerCallRef myHandlerChain, EventRef event, void* userData) { UInt32 whatHappened; OSStatus result = eventNotHandledErr; @@ -804,10 +876,15 @@ static pascal OSStatus MyAppEventHandler if (IsDialogEvent(&eve)) return result; UInt32 modif; - EventMouseButton buttonKind; GetEventParameter (event, kEventParamKeyModifiers, typeUInt32, NULL, sizeof(UInt32), NULL, &modif); + +#if defined(NP2GCC) + HIPoint delta; + EventMouseButton buttonKind; GetEventParameter (event, kEventParamMouseButton, typeMouseButton, NULL, sizeof(EventMouseButton), NULL, &buttonKind); - BYTE ret; + + BYTE ret; +#endif switch (eventClass) { @@ -816,27 +893,16 @@ static pascal OSStatus MyAppEventHandler AEProcessAppleEvent(&eve); } break; + case kEventClassMouse: +#if defined(NP2GCC) switch (whatHappened) { case kEventMouseMoved: -#if 0 - if (isFullScreen) - { - HIPoint delta; - Point pt; - GetEventParameter (event, kEventParamMouseDelta, typeHIPoint, NULL, sizeof(HIPoint), NULL, &delta); - pt.h=(short)delta.x; - pt.v=(short)delta.y; - mouse_callback(pt); - } - else { - mouse_callback(eve.where); - } -#endif - mouse_callback(); - result = noErr; - break; + GetEventParameter (event, kEventParamMouseDelta, typeHIPoint, NULL, sizeof(HIPoint), NULL, &delta); + mouse_callback(delta); + result = noErr; + break; case kEventMouseDown: if (buttonKind == kEventMouseButtonSecondary | modif & controlKey) { ret=mouse_btn(MOUSE_RIGHTDOWN); @@ -847,30 +913,42 @@ static pascal OSStatus MyAppEventHandler result=noErr; break; case kEventMouseUp: - { - if (buttonKind == kEventMouseButtonSecondary | modif & cmdKey) { - ret=mouse_btn(MOUSE_RIGHTUP); - } - else { - ret=mouse_btn(MOUSE_LEFTUP); - } - result=noErr; - break; - } + if (buttonKind == kEventMouseButtonSecondary | modif & controlKey) { + ret=mouse_btn(MOUSE_RIGHTUP); + } + else if (buttonKind == kEventMouseButtonTertiary) { + mouse_running(MOUSE_XOR); + menu_setmouse(np2oscfg.MOUSE_SW ^ 1); + sysmng_update(SYS_UPDATECFG); + } + else { + ret=mouse_btn(MOUSE_LEFTUP); + } + result=noErr; + break; } +#else + if (whatHappened == kEventMouseDown) { + HandleMouseDown(&eve); + } +#endif break; default: break; } + + (void)myHandlerChain; + (void)userData; return result; } -static pascal OSStatus MyWindowEventHandler(EventHandlerCallRef myHandler, EventRef event, void* userData) +static pascal OSStatus np2windowevent(EventHandlerCallRef myHandler, EventRef event, void* userData) { WindowRef window; UInt32 whatHappened; OSStatus result = eventNotHandledErr; long eventClass; + static UInt32 backup = 0; GetEventParameter(event, kEventParamDirectObject, typeWindowRef, NULL, sizeof(window), NULL, &window); @@ -893,26 +971,21 @@ static pascal OSStatus MyWindowEventHand switch (whatHappened) { case kEventRawKeyUp: - //mackeyup((int)key); mackbd_f12up(key); result = noErr; break; case kEventRawKeyRepeat: - //mackeydown(0, (int)key); mackbd_f12down(key); result = noErr; break; case kEventRawKeyDown: - mackbd_f12down(key); if (modif & cmdKey) { - //if (!mackeydown(1, (int)key)) { - char para; - GetEventParameter (event, kEventParamKeyMacCharCodes, typeChar, NULL, sizeof(char), NULL, ¶); - HandleMenuChoice(MenuKey(para)); - //} + EventRecord eve; + ConvertEventRefToEventRecord( event,&eve ); + HandleMenuChoice(MenuEvent(&eve)); } else { - //mackeydown(0, (int)key); + mackbd_f12down(key); } result = noErr; break; @@ -923,8 +996,10 @@ static pascal OSStatus MyWindowEventHand else keystat_senddata(0x73 | 0x80); if (modif & controlKey) keystat_senddata(0x74); else keystat_senddata(0x74 | 0x80); - if (modif & alphaLock) keystat_senddata(0x79); - else keystat_senddata(0x79 | 0x80); + if ((modif & alphaLock) != (backup & alphaLock)) { + keystat_senddata(0x71); + backup = modif; + } result = noErr; break; default: @@ -934,24 +1009,37 @@ static pascal OSStatus MyWindowEventHand break; } + (void)myHandler; + (void)userData; return result; } -static void setUpCarbonEvent(void) -{ - InstallStandardEventHandler(GetWindowEventTarget(hWndMain)); - EventTypeSpec appEventList[] ={ { kEventClassAppleEvent, kEventAppleEvent }, - { kEventClassMouse, kEventMouseDown}, - { kEventClassMouse, kEventMouseMoved}, - { kEventClassMouse, kEventMouseUp} - }; - EventTypeSpec windEventList[] ={ { kEventClassWindow, kEventWindowClose}, - { kEventClassKeyboard, kEventRawKeyDown}, - { kEventClassKeyboard, kEventRawKeyUp}, - { kEventClassKeyboard, kEventRawKeyRepeat}, - { kEventClassKeyboard, kEventRawKeyModifiersChanged} - }; - InstallApplicationEventHandler(NewEventHandlerUPP(MyAppEventHandler), 4, appEventList, 0, NULL); - InstallWindowEventHandler(hWndMain, NewEventHandlerUPP(MyWindowEventHandler), 5, windEventList, 0, NULL); +static const EventTypeSpec appEventList[] = { + {kEventClassAppleEvent, kEventAppleEvent}, + {kEventClassMouse, kEventMouseDown}, +#if defined(NP2GCC) + {kEventClassMouse, kEventMouseMoved}, + {kEventClassMouse, kEventMouseUp}, +#endif + }; +static const EventTypeSpec windEventList[] = { + {kEventClassWindow, kEventWindowClose}, + {kEventClassKeyboard, kEventRawKeyDown}, + {kEventClassKeyboard, kEventRawKeyUp}, + {kEventClassKeyboard, kEventRawKeyRepeat}, + {kEventClassKeyboard, kEventRawKeyModifiersChanged}, + }; + + +static void setUpCarbonEvent(void) { + + InstallStandardEventHandler(GetWindowEventTarget(hWndMain)); + InstallApplicationEventHandler(NewEventHandlerUPP(np2appevent), + GetEventTypeCount(appEventList), + appEventList, 0, NULL); + InstallWindowEventHandler(hWndMain, NewEventHandlerUPP(np2windowevent), + GetEventTypeCount(windEventList), + windEventList, 0, NULL); } +